commit 9911202d5b2a5f07ba2050176f72c3642a34a8c6 Author: Joe Bowser Date: Wed Oct 15 14:24:39 2008 -0700 Initial commit of the Android PhoneGap Code diff --git a/.classpath b/.classpath new file mode 100644 index 00000000..ef7c361c --- /dev/null +++ b/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/.project b/.project new file mode 100644 index 00000000..37920991 --- /dev/null +++ b/.project @@ -0,0 +1,33 @@ + + + DroidGap + + + + + + com.android.ide.eclipse.adt.ResourceManagerBuilder + + + + + com.android.ide.eclipse.adt.PreCompilerBuilder + + + + + org.eclipse.jdt.core.javabuilder + + + + + com.android.ide.eclipse.adt.ApkBuilder + + + + + + com.android.ide.eclipse.adt.AndroidNature + org.eclipse.jdt.core.javanature + + diff --git a/AndroidManifest.xml b/AndroidManifest.xml new file mode 100644 index 00000000..326dab12 --- /dev/null +++ b/AndroidManifest.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/res/drawable/icon.png b/res/drawable/icon.png new file mode 100644 index 00000000..75024841 Binary files /dev/null and b/res/drawable/icon.png differ diff --git a/res/layout/main.xml b/res/layout/main.xml new file mode 100644 index 00000000..4a019a49 --- /dev/null +++ b/res/layout/main.xml @@ -0,0 +1,11 @@ + + + + diff --git a/res/values/strings.xml b/res/values/strings.xml new file mode 100644 index 00000000..1c8e1e8f --- /dev/null +++ b/res/values/strings.xml @@ -0,0 +1,5 @@ + + + Hello World, DroidGap + Droid Gap + diff --git a/src/com/android/droidgap/AccelTuple.java b/src/com/android/droidgap/AccelTuple.java new file mode 100644 index 00000000..5073a236 --- /dev/null +++ b/src/com/android/droidgap/AccelTuple.java @@ -0,0 +1,7 @@ +package com.android.droidgap; + +public class AccelTuple { + public long accelX; + public long accelY; + public long accelZ; +} diff --git a/src/com/android/droidgap/DroidGap.java b/src/com/android/droidgap/DroidGap.java new file mode 100644 index 00000000..9ce4d3e9 --- /dev/null +++ b/src/com/android/droidgap/DroidGap.java @@ -0,0 +1,65 @@ +package com.android.droidgap; + +import java.io.IOException; +import java.io.InputStream; + +import android.app.Activity; +import android.os.Bundle; +import android.webkit.WebView; + +public class DroidGap extends Activity { + + private WebView appView; + + /** Called when the activity is first created. */ + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.main); + + appView = (WebView) findViewById(R.id.appView); + appView.getSettings().setJavaScriptEnabled(true); + appView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true); + + /* Bind the appView object to the gap class methods */ + bindBrowser(appView); + + /* + * We need to decide whether this is a local or a remote app. For the sake of clarity + * 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/"); + + } + + private void loadFile(WebView appView){ + try { + InputStream is = getAssets().open("index.html"); + + int size = is.available(); + + // Read the entire asset into a local byte buffer. + byte[] buffer = new byte[size]; + is.read(buffer); + is.close(); + + // Convert the buffer into a Java string. + String text = new String(buffer); + + // Load the local file into the webview + appView.loadData(text, "text/html", "UTF-8"); + + } catch (IOException e) { + // Should never happen! + throw new RuntimeException(e); + } + } + + private void bindBrowser(WebView appView) + { + PhoneGap gap = new PhoneGap(this); + appView.addJavascriptInterface(gap, "DroidGap"); + } + +} \ No newline at end of file diff --git a/src/com/android/droidgap/GeoTuple.java b/src/com/android/droidgap/GeoTuple.java new file mode 100644 index 00000000..350ea5f6 --- /dev/null +++ b/src/com/android/droidgap/GeoTuple.java @@ -0,0 +1,7 @@ +package com.android.droidgap; + +public class GeoTuple { + public double lat; + public double lng; + public double ele; +} diff --git a/src/com/android/droidgap/PhoneGap.java b/src/com/android/droidgap/PhoneGap.java new file mode 100644 index 00000000..5cca01a0 --- /dev/null +++ b/src/com/android/droidgap/PhoneGap.java @@ -0,0 +1,52 @@ +package com.android.droidgap; + +import android.content.Context; +import android.hardware.SensorManager; +import android.location.Location; +import android.location.LocationManager; +import android.os.Vibrator; + +public class PhoneGap { + + public GeoTuple location; + public AccelTuple accel; + + private Context mCtx; + + public PhoneGap(Context ctx) { + this.mCtx = ctx; + } + + public void updateAccel(AccelTuple accel){ + accel.accelX = SensorManager.DATA_X; + accel.accelY = SensorManager.DATA_Y; + accel.accelZ = SensorManager.DATA_Z; + } + + public void takePhoto(){ + + } + + public void playSound(){ + + } + + public void vibrate(long pattern){ + // Start the vibration + Vibrator vibrator = (Vibrator) mCtx.getSystemService(Context.VIBRATOR_SERVICE); + vibrator.vibrate(pattern); + } + + public void getLocation(String provider){ + LocationManager locMan = (LocationManager) mCtx.getSystemService(Context.LOCATION_SERVICE); + Location myLoc = (Location) locMan.getLastKnownLocation(provider); + location.lat = myLoc.getLatitude(); + location.lng = myLoc.getLongitude(); + location.ele = myLoc.getAltitude(); + } + + public String outputText(){ + String test = "

Test

"; + return test; + } +} diff --git a/src/com/android/droidgap/R.java b/src/com/android/droidgap/R.java new file mode 100644 index 00000000..61d94116 --- /dev/null +++ b/src/com/android/droidgap/R.java @@ -0,0 +1,26 @@ +/* AUTO-GENERATED FILE. DO NOT MODIFY. + * + * This class was automatically generated by the + * aapt tool from the resource data it found. It + * should not be modified by hand. + */ + +package com.android.droidgap; + +public final class R { + public static final class attr { + } + public static final class drawable { + public static final int icon=0x7f020000; + } + public static final class id { + public static final int appView=0x7f050000; + } + public static final class layout { + public static final int main=0x7f030000; + } + public static final class string { + public static final int app_name=0x7f040001; + public static final int hello=0x7f040000; + } +}