mirror of
https://github.com/apache/cordova-android.git
synced 2025-02-01 01:53:00 +08:00
Merge commit 'HEAD'; branch 'droidgap'
Conflicts: android/src/com/android/droidgap/PhoneGap.java
This commit is contained in:
commit
4820f7c030
@ -5,12 +5,19 @@ import java.io.InputStream;
|
|||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.os.Handler;
|
||||||
|
import android.util.Log;
|
||||||
|
import android.webkit.JsResult;
|
||||||
|
import android.webkit.WebChromeClient;
|
||||||
import android.webkit.WebView;
|
import android.webkit.WebView;
|
||||||
|
|
||||||
public class DroidGap extends Activity {
|
public class DroidGap extends Activity {
|
||||||
|
|
||||||
|
private static final String LOG_TAG = "DroidGap";
|
||||||
private WebView appView;
|
private WebView appView;
|
||||||
|
|
||||||
|
private Handler mHandler = new Handler();
|
||||||
|
|
||||||
/** Called when the activity is first created. */
|
/** Called when the activity is first created. */
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
@ -18,6 +25,10 @@ public class DroidGap extends Activity {
|
|||||||
setContentView(R.layout.main);
|
setContentView(R.layout.main);
|
||||||
|
|
||||||
appView = (WebView) findViewById(R.id.appView);
|
appView = (WebView) findViewById(R.id.appView);
|
||||||
|
|
||||||
|
/* This changes the setWebChromeClient to log alerts to LogCat! Important for Javascript Debugging */
|
||||||
|
|
||||||
|
appView.setWebChromeClient(new MyWebChromeClient());
|
||||||
appView.getSettings().setJavaScriptEnabled(true);
|
appView.getSettings().setJavaScriptEnabled(true);
|
||||||
appView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
|
appView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
|
||||||
|
|
||||||
@ -29,7 +40,7 @@ public class DroidGap extends Activity {
|
|||||||
* we can use HTML with both local and remote applications, but it means that we have to open the local file
|
* we can use HTML with both local and remote applications, but it means that we have to open the local file
|
||||||
*/
|
*/
|
||||||
|
|
||||||
appView.loadUrl("http://infil00p.org/gap/");
|
appView.loadUrl("http://www.infil00p.org/gap/demo/");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -58,8 +69,21 @@ public class DroidGap extends Activity {
|
|||||||
|
|
||||||
private void bindBrowser(WebView appView)
|
private void bindBrowser(WebView appView)
|
||||||
{
|
{
|
||||||
PhoneGap gap = new PhoneGap(this);
|
PhoneGap gap = new PhoneGap(this, mHandler, appView);
|
||||||
appView.addJavascriptInterface(gap, "DroidGap");
|
appView.addJavascriptInterface(gap, "DroidGap");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides a hook for calling "alert" from javascript. Useful for
|
||||||
|
* debugging your javascript.
|
||||||
|
*/
|
||||||
|
final class MyWebChromeClient extends WebChromeClient {
|
||||||
|
@Override
|
||||||
|
public boolean onJsAlert(WebView view, String url, String message, JsResult result) {
|
||||||
|
Log.d(LOG_TAG, message);
|
||||||
|
result.confirm();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -4,34 +4,47 @@ 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.telephony.TelephonyManager;
|
||||||
|
import android.webkit.WebView;
|
||||||
|
|
||||||
public class PhoneGap {
|
public class PhoneGap {
|
||||||
|
|
||||||
public static GeoTuple location;
|
/*
|
||||||
public static AccelTuple accel;
|
* UUID, version and availability
|
||||||
public String uuid = getDeviceId();
|
*/
|
||||||
public static String version = "0.1";
|
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() {
|
|
||||||
accel.accelX = SensorManager.DATA_X;
|
public void updateAccel(){
|
||||||
accel.accelY = SensorManager.DATA_Y;
|
mHandler.post(new Runnable() {
|
||||||
accel.accelZ = SensorManager.DATA_Z;
|
public void run() {
|
||||||
|
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(){
|
||||||
|
// TO-DO: Figure out what this should do
|
||||||
}
|
}
|
||||||
|
|
||||||
public void playSound(){
|
public void playSound(){
|
||||||
|
// TO-DO: Figure out what this should do
|
||||||
}
|
}
|
||||||
|
|
||||||
public void vibrate(long pattern){
|
public void vibrate(long pattern){
|
||||||
@ -40,12 +53,22 @@ public class PhoneGap {
|
|||||||
vibrator.vibrate(pattern);
|
vibrator.vibrate(pattern);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void getLocation(String provider){
|
/*
|
||||||
|
* Android requires a provider, since it can fall back on triangulation and other means as well as GPS
|
||||||
|
*/
|
||||||
|
|
||||||
|
public void getLocation(final String provider){
|
||||||
|
mHandler.post(new Runnable() {
|
||||||
|
public void run() {
|
||||||
LocationManager locMan = (LocationManager) mCtx.getSystemService(Context.LOCATION_SERVICE);
|
LocationManager locMan = (LocationManager) mCtx.getSystemService(Context.LOCATION_SERVICE);
|
||||||
Location myLoc = (Location) locMan.getLastKnownLocation(provider);
|
Location myLoc = (Location) locMan.getLastKnownLocation(provider);
|
||||||
location.lat = myLoc.getLatitude();
|
GeoTuple geoloc = new GeoTuple();
|
||||||
location.lng = myLoc.getLongitude();
|
geoloc.lat = myLoc.getLatitude();
|
||||||
location.ele = myLoc.getAltitude();
|
geoloc.lng = myLoc.getLongitude();
|
||||||
|
geoloc.ele = myLoc.getAltitude();
|
||||||
|
mAppView.loadUrl("javascript:gotLocation(" + geoloc.lat + ", " + geoloc.lng + ")");
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public String outputText(){
|
public String outputText(){
|
||||||
@ -53,9 +76,23 @@ public class PhoneGap {
|
|||||||
return test;
|
return test;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getDeviceId(){
|
|
||||||
|
public String getUuid()
|
||||||
|
{
|
||||||
|
|
||||||
TelephonyManager operator = (TelephonyManager) mCtx.getSystemService(Context.TELEPHONY_SERVICE);
|
TelephonyManager operator = (TelephonyManager) mCtx.getSystemService(Context.TELEPHONY_SERVICE);
|
||||||
String uniqueId = operator.getDeviceId();
|
String uuid = operator.getDeviceId();
|
||||||
return uniqueId;
|
return uuid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getVersion()
|
||||||
|
{
|
||||||
|
return version;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean exists()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user