Hecl and GPS on Android

Единая страна

Hecl and GPS on Android

Hecl and GPS on Android

The Hecl Programming Language is a high-level scripting language implemented in Java, created by David N. Welton.

This are sources using with hecl for gpsmta - GPS tracker / GPS monitoring for Android

Sorry, I do not know java. This code for the specialist may seem strange :-)

Hecl and GPS on Android

1. Create file hecl/android/src/org/hecl/android/MyLocation.java

-----------------------------------------------------
package org.hecl.android;

import android.content.Context;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.util.Log;

import java.util.Vector;
import java.lang.reflect.Method;
import java.lang.reflect.Field;

import org.hecl.DoubleThing;
import org.hecl.HeclException;
import org.hecl.Interp;
import org.hecl.IntThing;
import org.hecl.ListThing;
import org.hecl.LongThing;
import org.hecl.ObjectThing;
import org.hecl.Properties;
import org.hecl.StringThing;
import org.hecl.Thing;

public class MyLocation implements LocationListener {
  private final LocationManager mLocationManager;
  private Location mLocation;
  
  public static Interp interp;
  public static Thing onLocationChangedCallBack = null;
  public static Thing onStatusChangedCallBack = null;
  public static Thing onProviderEnabledCallBack = null;
  public static Thing onProviderDisabledCallBack = null;

  private long mLocationUpdateMinTime = 1000;
  private float mLocationUpdateMinDistance = 0;

  public MyLocation(Context context) {
    mLocationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
  }

  public long getLocationUpdateMinTime() {
    return mLocationUpdateMinTime;
  }
  public void setLocationUpdateMinTime(final long milliSeconds) {
    mLocationUpdateMinTime = milliSeconds;
  }

  public float getLocationUpdateMinDistance() {
    return mLocationUpdateMinDistance;
  }
  public void setLocationUpdateMinDistance(final float meters) {
    mLocationUpdateMinDistance = meters;
  }
  
  public LocationListener getLocationListener() {
    return this;
  }
  
  public LocationManager getLocationManager() {
    return mLocationManager;
  }

  public void startLocationProvider() {
    try {
      mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, mLocationUpdateMinTime, mLocationUpdateMinDistance, this);
    } catch (Exception e) {
      Log.v(">>>>> gpsmta ERROR Start GPS_PROVIDER", e.toString());
    }
    
    try {
      mLocationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, mLocationUpdateMinTime, mLocationUpdateMinDistance, this);
    } catch (Exception e) {
      Log.v(">>>>> gpsmta ERROR Start NETWORK_PROVIDER", e.toString());
    }
  }
  
  public void startLocationProviderNetwork() {
    try {
      mLocationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, mLocationUpdateMinTime, mLocationUpdateMinDistance, this);
    } catch (Exception e) {
      Log.v(">>>>> gpsmta ERROR Start NETWORK_PROVIDER", e.toString());
    }
  }
  
  public void startLocationProviderGPS() {
    try {
      mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, mLocationUpdateMinTime, mLocationUpdateMinDistance, this);
    } catch (Exception e) {
      Log.v(">>>>> gpsmta ERROR Start GPS_PROVIDER", e.toString());
    }
  }

  public void stopLocationProvider() {
    mLocationManager.removeUpdates(this);
  }
  
  public Boolean isProviderEnabled(String provider) {
    return mLocationManager.isProviderEnabled(provider);
  }

  @Override
  public void onLocationChanged(final Location location) {
    if (onLocationChangedCallBack != null) {
      try {
        Vector vec = ListThing.get(onLocationChangedCallBack.deepcopy());
        vec.add(ObjectThing.create(location));
        interp.eval(ListThing.create(vec));
      } catch (Exception e) {
        Log.v(">>>>> gpsmta ERROR onLocationChangeCallBack", e.toString());
      }
    }
  }

  @Override
  public void onProviderDisabled(final String provider) {
    if (onProviderDisabledCallBack != null) {
      try {
        Vector vec = ListThing.get(onProviderDisabledCallBack.deepcopy());
        vec.add(ObjectThing.create(provider));
        interp.eval(ListThing.create(vec));
      } catch (Exception e) {
        Log.v(">>>>> gpsmta ERROR onProviderDisabledCallBack", e.toString());
      }
    }
  }

  @Override
  public void onProviderEnabled(final String provider) {
    if (onProviderEnabledCallBack != null) {
      try {
        Vector vec = ListThing.get(onProviderEnabledCallBack.deepcopy());
        vec.add(ObjectThing.create(provider));
        interp.eval(ListThing.create(vec));
      } catch (Exception e) {
        Log.v(">>>>> gpsmta ERROR onProviderEnabledCallBack", e.toString());
      }
    }
  }

  @Override
  public void onStatusChanged(final String provider, final int status, final Bundle extras) {
    if (onStatusChangedCallBack != null) {
      try {
        Vector vec = ListThing.get(onStatusChangedCallBack.deepcopy());
        vec.add(ObjectThing.create(provider));
        vec.add(ObjectThing.create(status));
        interp.eval(ListThing.create(vec));
      } catch (Exception e) {
        Log.v(">>>>> gpsmta ERROR onStatusChangeCallBack", e.toString());
      }
    }
  }
}

2. Recompile Hecl

ant packageAndroidBuilder

3. Using with Hecl

java android.location.Location location
java org.hecl.android.MyLocation MyLocation

global locationCurr myLocation
set context [activity]

set myLocation [MyLocation -new $context]
set i [thisinterp]
$myLocation -field interp $i
$myLocation -field onLocationChangedCallBack GPS:onLocationChanged

set locationCurr [location -new gps]
$locationCurr reset

proc GPS:onLocationChanged { location } {
  global locationCurr

    $locationCurr set $location
    set provider     [$locationCurr getprovider]
    set milliseconds [$locationCurr gettime]
    set lon          [$locationCurr getlongitude]
    set lat          [$locationCurr getlatitude]
    set speed        [$locationCurr getspeed]
    set height       [$locationCurr getaltitude]
    set azimuth      [$locationCurr getbearing]
    set accuracy     [$locationCurr getaccuracy]
}
Главная
Программные продукты
Freesource программные продукты
Статьи
Контакт
GPSMTA - GPS трекер / GPS мониторинг для Android
GPSM - программно-аппаратный комплекс GPS мониторинга
MapTour - GPS навигация для Туристов
MapSurfing - просмотрщик географических карт
DGraf - визуализация графов
ViCer - домашняя система видеонаблюдения
FPS - бесплатная система GPS мониторинга
Jeans - Финансово-складской учёт
Cerber - Финансовый учёт игорного зала
Visimap - Визуальная карта
BIB - Картотека книг
2DO - Учёт рабочего времени
Выписка - склад
Расчёт зарплаты
Krp - визуализатор связанных структур
Xboat - проэктировщик малых судов
XSQLite - visualisator DB SQLite
Текстовый редактор XEdJ
Copyright © Эдуард Зозуля
Проверка PR и ТИЦ