Initial commit of the Android PhoneGap Code

This commit is contained in:
Joe Bowser
2008-10-15 14:24:39 -07:00
commit 9911202d5b
11 changed files with 227 additions and 0 deletions
+7
View File
@@ -0,0 +1,7 @@
package com.android.droidgap;
public class AccelTuple {
public long accelX;
public long accelY;
public long accelZ;
}
+65
View File
@@ -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");
}
}
+7
View File
@@ -0,0 +1,7 @@
package com.android.droidgap;
public class GeoTuple {
public double lat;
public double lng;
public double ele;
}
+52
View File
@@ -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;
}
}
+26
View File
@@ -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;
}
}