mirror of
https://github.com/apache/cordova-android.git
synced 2025-02-20 23:56:20 +08:00
Changing the classname of the Android Branch. The package should be reflective of the company that wrote it.
(Note: This needs to be changed for every app on the android)
This commit is contained in:
parent
4820f7c030
commit
337acc92ea
7
src/com/nitobi/droidgap/AccelTuple.java
Normal file
7
src/com/nitobi/droidgap/AccelTuple.java
Normal file
@ -0,0 +1,7 @@
|
||||
package com.nitobi.droidgap;
|
||||
|
||||
public class AccelTuple {
|
||||
public long accelX;
|
||||
public long accelY;
|
||||
public long accelZ;
|
||||
}
|
89
src/com/nitobi/droidgap/DroidGap.java
Normal file
89
src/com/nitobi/droidgap/DroidGap.java
Normal 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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
7
src/com/nitobi/droidgap/GeoTuple.java
Normal file
7
src/com/nitobi/droidgap/GeoTuple.java
Normal file
@ -0,0 +1,7 @@
|
||||
package com.nitobi.droidgap;
|
||||
|
||||
public class GeoTuple {
|
||||
public double lat;
|
||||
public double lng;
|
||||
public double ele;
|
||||
}
|
107
src/com/nitobi/droidgap/PhoneGap.java
Normal file
107
src/com/nitobi/droidgap/PhoneGap.java
Normal file
@ -0,0 +1,107 @@
|
||||
package com.nitobi.droidgap;
|
||||
|
||||
import android.content.Context;
|
||||
import android.hardware.SensorManager;
|
||||
import android.location.Location;
|
||||
import android.location.LocationManager;
|
||||
import android.os.Handler;
|
||||
import android.os.Vibrator;
|
||||
import android.telephony.TelephonyManager;
|
||||
import android.webkit.WebView;
|
||||
|
||||
public class PhoneGap {
|
||||
|
||||
/*
|
||||
* UUID, version and availability
|
||||
*/
|
||||
public boolean droid = true;
|
||||
private String version = "0.1";
|
||||
private Context mCtx;
|
||||
private Handler mHandler;
|
||||
private WebView mAppView;
|
||||
|
||||
public PhoneGap(Context ctx, Handler handler, WebView appView) {
|
||||
this.mCtx = ctx;
|
||||
this.mHandler = handler;
|
||||
this.mAppView = appView;
|
||||
}
|
||||
|
||||
|
||||
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() {
|
||||
LocationManager locMan = (LocationManager) mCtx.getSystemService(Context.LOCATION_SERVICE);
|
||||
GeoTuple geoloc = new GeoTuple();
|
||||
if (locMan.isProviderEnabled(provider))
|
||||
{
|
||||
Location myLoc = (Location) locMan.getLastKnownLocation(provider);
|
||||
geoloc.lat = myLoc.getLatitude();
|
||||
geoloc.lng = myLoc.getLongitude();
|
||||
geoloc.ele = myLoc.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;
|
||||
}
|
||||
|
||||
}
|
26
src/com/nitobi/droidgap/R.java
Normal file
26
src/com/nitobi/droidgap/R.java
Normal 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;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user