resolving merge changes

This commit is contained in:
Igor Faletski 2008-11-17 14:47:02 -08:00
commit ab6df0d5cf
8 changed files with 392 additions and 2 deletions

View File

@ -1,16 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.android.droidgap"
package="com.nitobi.droidgap"
android:versionCode="1"
android:versionName="1.0.0">
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.ACCESS_GPS" />
<uses-permission android:name="android.permission.ACCESS_ASSISTED_GPS" />
<uses-permission android:name="android.permission.ACCESS_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<application android:icon="@drawable/icon" android:debuggable="false">
<application android:icon="@drawable/icon" android:label="@string/app_name"
android:debuggable="true">
<activity android:name=".DroidGap"
android:label="@string/app_name">
<intent-filter>

View File

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

View File

@ -0,0 +1,89 @@
package com.nitobi.droidgap;
import java.io.IOException;
import java.io.InputStream;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.webkit.JsResult;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
public class DroidGap extends Activity {
private static final String LOG_TAG = "DroidGap";
private WebView appView;
private Handler mHandler = new Handler();
/** 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);
/* This changes the setWebChromeClient to log alerts to LogCat! Important for Javascript Debugging */
appView.setWebChromeClient(new MyWebChromeClient());
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://www.infil00p.org/gap/demo/");
}
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, mHandler, appView);
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;
}
}
}

View File

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

View File

@ -0,0 +1,73 @@
package com.nitobi.droidgap;
import android.content.Context;
import android.hardware.SensorManager;
import android.location.Location;
import android.location.LocationManager;
import android.location.LocationListener;
import android.os.Bundle;
import android.os.Handler;
import android.os.Vibrator;
import android.telephony.TelephonyManager;
import android.util.Log;
import android.webkit.WebView;
public class GpsListener implements LocationListener {
private Context mCtx;
private Location cLoc;
private LocationManager mLocMan;
private static final String LOG_TAG = "PhoneGap";
public GpsListener(Context ctx)
{
mCtx = ctx;
mLocMan = (LocationManager) mCtx.getSystemService(Context.LOCATION_SERVICE);
mLocMan.requestLocationUpdates(LocationManager.GPS_PROVIDER, 60000, 0, this);
cLoc = mLocMan.getLastKnownLocation(LocationManager.GPS_PROVIDER);
}
public Location getLocation()
{
return cLoc;
}
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub
Log.d(LOG_TAG, "The provider " + provider + " is disabled");
}
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub
Log.d(LOG_TAG, "The provider "+ provider + " is enabled");
}
public void onStatusChanged(String provider, int status, Bundle extras) {
// TODO Auto-generated method stub
Log.d(LOG_TAG, "The status of the provider " + provider + " has changed");
if(status == 0)
{
Log.d(LOG_TAG, provider + " is OUT OF SERVICE");
}
else if(status == 1)
{
Log.d(LOG_TAG, provider + " is TEMPORARILY_UNAVAILABLE");
}
else
{
Log.d(LOG_TAG, provider + " is Available");
}
}
public void onLocationChanged(Location location) {
Log.d(LOG_TAG, "The location has been updated!");
cLoc = location;
}
public boolean hasLocation() {
return (cLoc != null);
}
}

View File

@ -0,0 +1,69 @@
package com.nitobi.droidgap;
import android.content.Context;
import android.hardware.SensorManager;
import android.location.Location;
import android.location.LocationManager;
import android.location.LocationListener;
import android.os.Bundle;
import android.os.Handler;
import android.os.Vibrator;
import android.telephony.TelephonyManager;
import android.util.Log;
import android.webkit.WebView;
public class NetworkListener implements LocationListener {
private Context mCtx;
private Location cLoc;
private LocationManager mLocMan;
private static final String LOG_TAG = "PhoneGap";
public NetworkListener(Context ctx)
{
mCtx = ctx;
mLocMan = (LocationManager) mCtx.getSystemService(Context.LOCATION_SERVICE);
mLocMan.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 60000, 0, this);
cLoc = mLocMan.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
}
public Location getLocation()
{
return cLoc;
}
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub
Log.d(LOG_TAG, "The provider " + provider + " is disabled");
}
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub
Log.d(LOG_TAG, "The provider "+ provider + " is enabled");
}
public void onStatusChanged(String provider, int status, Bundle extras) {
// TODO Auto-generated method stub
Log.d(LOG_TAG, "The status of the provider " + provider + " has changed");
if(status == 0)
{
Log.d(LOG_TAG, provider + " is OUT OF SERVICE");
}
else if(status == 1)
{
Log.d(LOG_TAG, provider + " is TEMPORARILY_UNAVAILABLE");
}
else
{
Log.d(LOG_TAG, provider + " is Available");
}
}
public void onLocationChanged(Location location) {
Log.d(LOG_TAG, "The location has been updated!");
cLoc = location;
}
}

View File

@ -0,0 +1,115 @@
package com.nitobi.droidgap;
import android.content.Context;
import android.hardware.SensorManager;
import android.location.Location;
import android.location.LocationManager;
import android.location.LocationListener;
import android.os.Bundle;
import android.os.Handler;
import android.os.Vibrator;
import android.telephony.TelephonyManager;
import android.util.Log;
import android.webkit.WebView;
public class PhoneGap{
private static final String LOG_TAG = "PhoneGap";
/*
* UUID, version and availability
*/
public boolean droid = true;
private String version = "0.1";
private Context mCtx;
private Handler mHandler;
private WebView mAppView;
private GpsListener mGps;
private NetworkListener mNetwork;
public PhoneGap(Context ctx, Handler handler, WebView appView) {
this.mCtx = ctx;
this.mHandler = handler;
this.mAppView = appView;
mGps = new GpsListener(ctx);
mNetwork = new NetworkListener(ctx);
}
public void updateAccel(){
mHandler.post(new Runnable() {
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(){
// TO-DO: Figure out what this should do
}
public void playSound(){
// TO-DO: Figure out what this should do
}
public void vibrate(long pattern){
// Start the vibration
Vibrator vibrator = (Vibrator) mCtx.getSystemService(Context.VIBRATOR_SERVICE);
vibrator.vibrate(pattern);
}
/*
* 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() {
GeoTuple geoloc = new GeoTuple();
Location loc = mGps.hasLocation() ? mGps.getLocation() : mNetwork.getLocation();
if (loc != null)
{
geoloc.lat = loc.getLatitude();
geoloc.lng = loc.getLongitude();
geoloc.ele = loc.getAltitude();
}
else
{
geoloc.lat = 0;
geoloc.lng = 0;
geoloc.ele = 0;
}
mAppView.loadUrl("javascript:gotLocation(" + geoloc.lat + ", " + geoloc.lng + ")");
}
});
}
public String outputText(){
String test = "<p>Test</p>";
return test;
}
public String getUuid()
{
TelephonyManager operator = (TelephonyManager) mCtx.getSystemService(Context.TELEPHONY_SERVICE);
String uuid = operator.getDeviceId();
return uuid;
}
public String getVersion()
{
return version;
}
public boolean exists()
{
return true;
}
}

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