commit 9911202d5b2a5f07ba2050176f72c3642a34a8c6 Author: Joe Bowser <bowserj@bowserj-nitobi.(none)> 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 @@ +<?xml version="1.0" encoding="UTF-8"?> +<classpath> + <classpathentry kind="src" path="src"/> + <classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/> + <classpathentry kind="output" path="bin"/> +</classpath> diff --git a/.project b/.project new file mode 100644 index 00000000..37920991 --- /dev/null +++ b/.project @@ -0,0 +1,33 @@ +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>DroidGap</name> + <comment></comment> + <projects> + </projects> + <buildSpec> + <buildCommand> + <name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>com.android.ide.eclipse.adt.PreCompilerBuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.jdt.core.javabuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>com.android.ide.eclipse.adt.ApkBuilder</name> + <arguments> + </arguments> + </buildCommand> + </buildSpec> + <natures> + <nature>com.android.ide.eclipse.adt.AndroidNature</nature> + <nature>org.eclipse.jdt.core.javanature</nature> + </natures> +</projectDescription> diff --git a/AndroidManifest.xml b/AndroidManifest.xml new file mode 100644 index 00000000..326dab12 --- /dev/null +++ b/AndroidManifest.xml @@ -0,0 +1,15 @@ +<?xml version="1.0" encoding="utf-8"?> +<manifest xmlns:android="http://schemas.android.com/apk/res/android" + package="com.android.droidgap" + android:versionCode="1" + android:versionName="1.0.0"> + <application android:icon="@drawable/icon" android:label="@string/app_name"> + <activity android:name=".DroidGap" + android:label="@string/app_name"> + <intent-filter> + <action android:name="android.intent.action.MAIN" /> + <category android:name="android.intent.category.LAUNCHER" /> + </intent-filter> + </activity> + </application> +</manifest> \ 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 @@ +<?xml version="1.0" encoding="utf-8"?> +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:orientation="vertical" + android:layout_width="fill_parent" + android:layout_height="fill_parent" + > + <WebView android:id="@+id/appView" + android:layout_height="wrap_content" + android:layout_width="fill_parent" + /> +</LinearLayout> 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 @@ +<?xml version="1.0" encoding="utf-8"?> +<resources> + <string name="hello">Hello World, DroidGap</string> + <string name="app_name">Droid Gap</string> +</resources> 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 = "<p>Test</p>"; + 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; + } +}