mirror of
https://github.com/apache/cordova-android.git
synced 2025-03-16 16:51:02 +08:00
Added helpers to make life easier
This commit is contained in:
parent
c42a0ae5e2
commit
2337509c15
@ -4,23 +4,39 @@ import android.content.Context;
|
|||||||
import android.hardware.SensorManager;
|
import android.hardware.SensorManager;
|
||||||
import android.location.Location;
|
import android.location.Location;
|
||||||
import android.location.LocationManager;
|
import android.location.LocationManager;
|
||||||
|
import android.os.Handler;
|
||||||
import android.os.Vibrator;
|
import android.os.Vibrator;
|
||||||
|
import android.telephony.TelephonyManager;
|
||||||
|
import android.webkit.WebView;
|
||||||
|
|
||||||
public class PhoneGap {
|
public class PhoneGap {
|
||||||
|
|
||||||
public GeoTuple location;
|
/*
|
||||||
public AccelTuple accel;
|
* UUID, version and availability
|
||||||
|
*/
|
||||||
|
public boolean droid = true;
|
||||||
|
private String version = "0.1";
|
||||||
|
|
||||||
private Context mCtx;
|
private Context mCtx;
|
||||||
|
private Handler mHandler;
|
||||||
|
private WebView mAppView;
|
||||||
|
|
||||||
public PhoneGap(Context ctx) {
|
public PhoneGap(Context ctx, Handler handler, WebView appView) {
|
||||||
this.mCtx = ctx;
|
this.mCtx = ctx;
|
||||||
|
this.mHandler = handler;
|
||||||
|
this.mAppView = appView;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateAccel(AccelTuple accel){
|
public void updateAccel(AccelTuple accel){
|
||||||
accel.accelX = SensorManager.DATA_X;
|
mHandler.post(new Runnable() {
|
||||||
accel.accelY = SensorManager.DATA_Y;
|
public void run() {
|
||||||
accel.accelZ = SensorManager.DATA_Z;
|
int accelX = SensorManager.DATA_X;
|
||||||
|
int accelY = SensorManager.DATA_Y;
|
||||||
|
int accelZ = SensorManager.DATA_Z;
|
||||||
|
mAppView.loadUrl("javascript:gotAcceleration(" + accelX + ", " + accelY + "," + accelZ + ")");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void takePhoto(){
|
public void takePhoto(){
|
||||||
@ -41,16 +57,40 @@ public class PhoneGap {
|
|||||||
* Android requires a provider, since it can fall back on triangulation and other means as well as GPS
|
* Android requires a provider, since it can fall back on triangulation and other means as well as GPS
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public void getLocation(String provider){
|
public void getLocation(final String provider){
|
||||||
LocationManager locMan = (LocationManager) mCtx.getSystemService(Context.LOCATION_SERVICE);
|
mHandler.post(new Runnable() {
|
||||||
Location myLoc = (Location) locMan.getLastKnownLocation(provider);
|
public void run() {
|
||||||
location.lat = myLoc.getLatitude();
|
LocationManager locMan = (LocationManager) mCtx.getSystemService(Context.LOCATION_SERVICE);
|
||||||
location.lng = myLoc.getLongitude();
|
Location myLoc = (Location) locMan.getLastKnownLocation(provider);
|
||||||
location.ele = myLoc.getAltitude();
|
GeoTuple geoloc = new GeoTuple();
|
||||||
|
geoloc.lat = myLoc.getLatitude();
|
||||||
|
geoloc.lng = myLoc.getLongitude();
|
||||||
|
geoloc.ele = myLoc.getAltitude();
|
||||||
|
mAppView.loadUrl("javascript:gotLocation(" + geoloc.lat + ", " + geoloc.lng + ")");
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public String outputText(){
|
public String outputText(){
|
||||||
String test = "<p>Test</p>";
|
String test = "<p>Test</p>";
|
||||||
return test;
|
return test;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getUuid()
|
||||||
|
{
|
||||||
|
TelephonyManager operator = (TelephonyManager) mCtx.getSystemService(Context.TELEPHONY_SERVICE);
|
||||||
|
String uuid = operator.getDeviceId();
|
||||||
|
return uuid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getVersion()
|
||||||
|
{
|
||||||
|
return version;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean exists()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user