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

6
.classpath Normal file
View File

@ -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>

33
.project Normal file
View File

@ -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>

15
AndroidManifest.xml Normal file
View File

@ -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>

BIN
res/drawable/icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

11
res/layout/main.xml Normal file
View File

@ -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>

5
res/values/strings.xml Normal file
View File

@ -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>

View File

@ -0,0 +1,7 @@
package com.android.droidgap;
public class AccelTuple {
public long accelX;
public long accelY;
public long accelZ;
}

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");
}
}

View File

@ -0,0 +1,7 @@
package com.android.droidgap;
public class GeoTuple {
public double lat;
public double lng;
public double ele;
}

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;
}
}

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;
}
}