mirror of
https://github.com/apache/cordova-android.git
synced 2025-03-17 01:11:02 +08:00
Update classes to use module, and make constructors consistent.
This commit is contained in:
parent
5d83a44ec3
commit
40997b4cb8
@ -13,7 +13,7 @@ import android.webkit.WebView;
|
|||||||
* This class listens to the accelerometer sensor and stores the latest
|
* This class listens to the accelerometer sensor and stores the latest
|
||||||
* acceleration values x,y,z.
|
* acceleration values x,y,z.
|
||||||
*/
|
*/
|
||||||
public class AccelListener implements SensorEventListener{
|
public class AccelListener extends Module implements SensorEventListener{
|
||||||
|
|
||||||
public static int STOPPED = 0;
|
public static int STOPPED = 0;
|
||||||
public static int STARTING = 1;
|
public static int STARTING = 1;
|
||||||
@ -40,6 +40,7 @@ public class AccelListener implements SensorEventListener{
|
|||||||
* @param appView
|
* @param appView
|
||||||
*/
|
*/
|
||||||
public AccelListener(WebView appView, DroidGap ctx) {
|
public AccelListener(WebView appView, DroidGap ctx) {
|
||||||
|
super(appView, ctx);
|
||||||
this.mCtx = ctx;
|
this.mCtx = ctx;
|
||||||
this.mAppView = appView;
|
this.mAppView = appView;
|
||||||
this.sensorManager = (SensorManager) mCtx.getSystemService(Context.SENSOR_SERVICE);
|
this.sensorManager = (SensorManager) mCtx.getSystemService(Context.SENSOR_SERVICE);
|
||||||
@ -95,7 +96,9 @@ public class AccelListener implements SensorEventListener{
|
|||||||
* Called by AccelBroker when listener is to be shut down.
|
* Called by AccelBroker when listener is to be shut down.
|
||||||
* Stop listener.
|
* Stop listener.
|
||||||
*/
|
*/
|
||||||
public void destroy() {
|
@Override
|
||||||
|
public void onDestroy() {
|
||||||
|
super.onDestroy();
|
||||||
this.stop();
|
this.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@ import android.webkit.WebView;
|
|||||||
* android_asset: file name must start with /android_asset/sound.mp3
|
* android_asset: file name must start with /android_asset/sound.mp3
|
||||||
* sdcard: file name is just sound.mp3
|
* sdcard: file name is just sound.mp3
|
||||||
*/
|
*/
|
||||||
public class AudioHandler {
|
public class AudioHandler extends Module {
|
||||||
|
|
||||||
HashMap<String,AudioPlayer> players; // Audio player object
|
HashMap<String,AudioPlayer> players; // Audio player object
|
||||||
WebView mAppView; // Webview object
|
WebView mAppView; // Webview object
|
||||||
@ -30,7 +30,8 @@ public class AudioHandler {
|
|||||||
* @param view
|
* @param view
|
||||||
* @param ctx
|
* @param ctx
|
||||||
*/
|
*/
|
||||||
AudioHandler(WebView view, DroidGap ctx) {
|
public AudioHandler(WebView view, DroidGap ctx) {
|
||||||
|
super(view, ctx);
|
||||||
this.mAppView = view;
|
this.mAppView = view;
|
||||||
this.mCtx = ctx;
|
this.mCtx = ctx;
|
||||||
this.players = new HashMap<String,AudioPlayer>();
|
this.players = new HashMap<String,AudioPlayer>();
|
||||||
@ -39,7 +40,9 @@ public class AudioHandler {
|
|||||||
/**
|
/**
|
||||||
* Stop all audio players and recorders.
|
* Stop all audio players and recorders.
|
||||||
*/
|
*/
|
||||||
public void destroy() {
|
@Override
|
||||||
|
public void onDestroy() {
|
||||||
|
super.onDestroy();
|
||||||
java.util.Set<Entry<String,AudioPlayer>> s = this.players.entrySet();
|
java.util.Set<Entry<String,AudioPlayer>> s = this.players.entrySet();
|
||||||
java.util.Iterator<Entry<String,AudioPlayer>> it = s.iterator();
|
java.util.Iterator<Entry<String,AudioPlayer>> it = s.iterator();
|
||||||
while(it.hasNext()) {
|
while(it.hasNext()) {
|
||||||
|
@ -12,7 +12,7 @@ import android.webkit.WebView;
|
|||||||
/**
|
/**
|
||||||
* This class listens to the compass sensor and stores the latest heading value.
|
* This class listens to the compass sensor and stores the latest heading value.
|
||||||
*/
|
*/
|
||||||
public class CompassListener implements SensorEventListener{
|
public class CompassListener extends Module implements SensorEventListener{
|
||||||
|
|
||||||
public static int STOPPED = 0;
|
public static int STOPPED = 0;
|
||||||
public static int STARTING = 1;
|
public static int STARTING = 1;
|
||||||
@ -38,8 +38,8 @@ public class CompassListener implements SensorEventListener{
|
|||||||
* @param appView
|
* @param appView
|
||||||
* @param ctx The Activity (DroidGap) object
|
* @param ctx The Activity (DroidGap) object
|
||||||
*/
|
*/
|
||||||
CompassListener(WebView appView, DroidGap ctx)
|
public CompassListener(WebView appView, DroidGap ctx) {
|
||||||
{
|
super(appView, ctx);
|
||||||
this.mCtx = ctx;
|
this.mCtx = ctx;
|
||||||
this.mAppView = appView;
|
this.mAppView = appView;
|
||||||
this.sensorManager = (SensorManager) mCtx.getSystemService(Context.SENSOR_SERVICE);
|
this.sensorManager = (SensorManager) mCtx.getSystemService(Context.SENSOR_SERVICE);
|
||||||
@ -91,7 +91,8 @@ public class CompassListener implements SensorEventListener{
|
|||||||
/**
|
/**
|
||||||
* Called when listener is to be shut down and object is being destroyed.
|
* Called when listener is to be shut down and object is being destroyed.
|
||||||
*/
|
*/
|
||||||
public void destroy() {
|
@Override
|
||||||
|
public void onDestroy() {
|
||||||
this.stop();
|
this.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,7 +11,7 @@ import android.database.Cursor;
|
|||||||
import android.database.sqlite.SQLiteException;
|
import android.database.sqlite.SQLiteException;
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
public class ContactManager {
|
public class ContactManager extends Module {
|
||||||
|
|
||||||
public class ContactTriplet
|
public class ContactTriplet
|
||||||
{
|
{
|
||||||
@ -27,8 +27,9 @@ public class ContactManager {
|
|||||||
Uri mPhone = android.provider.Contacts.Phones.CONTENT_URI;
|
Uri mPhone = android.provider.Contacts.Phones.CONTENT_URI;
|
||||||
Uri mEmail = android.provider.Contacts.ContactMethods.CONTENT_URI;
|
Uri mEmail = android.provider.Contacts.ContactMethods.CONTENT_URI;
|
||||||
|
|
||||||
ContactManager(WebView view, DroidGap app)
|
public ContactManager(WebView view, DroidGap app)
|
||||||
{
|
{
|
||||||
|
super(view, app);
|
||||||
mApp = app;
|
mApp = app;
|
||||||
mView = view;
|
mView = view;
|
||||||
}
|
}
|
||||||
|
@ -2,12 +2,13 @@ package com.phonegap;
|
|||||||
|
|
||||||
import android.webkit.WebView;
|
import android.webkit.WebView;
|
||||||
|
|
||||||
public class CryptoHandler {
|
public class CryptoHandler extends Module {
|
||||||
|
|
||||||
WebView mView;
|
WebView mView;
|
||||||
|
|
||||||
CryptoHandler(WebView view)
|
public CryptoHandler(WebView view, DroidGap gap)
|
||||||
{
|
{
|
||||||
|
super(view, gap);
|
||||||
mView = view;
|
mView = view;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,16 +86,7 @@ public class DroidGap extends Activity {
|
|||||||
private LinearLayout root;
|
private LinearLayout root;
|
||||||
|
|
||||||
private Device gap;
|
private Device gap;
|
||||||
private GeoBroker geo;
|
|
||||||
private AccelListener accel;
|
|
||||||
private ContactManager mContacts;
|
|
||||||
private FileUtils fs;
|
|
||||||
private NetworkManager netMan;
|
|
||||||
private CompassListener mCompass;
|
|
||||||
private Storage cupcakeStorage;
|
|
||||||
private CryptoHandler crypto;
|
|
||||||
private BrowserKey mKey;
|
private BrowserKey mKey;
|
||||||
private AudioHandler audio;
|
|
||||||
public CallbackServer callbackServer;
|
public CallbackServer callbackServer;
|
||||||
private CommandManager commandManager;
|
private CommandManager commandManager;
|
||||||
|
|
||||||
@ -186,7 +177,8 @@ public class DroidGap extends Activity {
|
|||||||
WebViewReflect.setGeolocationEnabled(settings, true);
|
WebViewReflect.setGeolocationEnabled(settings, true);
|
||||||
// Bind the appView object to the gap class methods
|
// Bind the appView object to the gap class methods
|
||||||
bindBrowser(appView);
|
bindBrowser(appView);
|
||||||
if (cupcakeStorage != null) {
|
if (this.getModule("com.phonegap.Storage") != null) {
|
||||||
|
Storage cupcakeStorage = (Storage)this.getModule("com.phonegap.Storage");
|
||||||
cupcakeStorage.setStorage(appPackage);
|
cupcakeStorage.setStorage(appPackage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -262,30 +254,9 @@ public class DroidGap extends Activity {
|
|||||||
appView.loadUrl("about:blank");
|
appView.loadUrl("about:blank");
|
||||||
|
|
||||||
// Clean up objects
|
// Clean up objects
|
||||||
if (accel != null) {
|
|
||||||
accel.destroy();
|
|
||||||
}
|
|
||||||
if (mContacts != null) {
|
|
||||||
|
|
||||||
}
|
|
||||||
if (fs != null) {
|
|
||||||
|
|
||||||
}
|
|
||||||
if (netMan != null) {
|
|
||||||
|
|
||||||
}
|
|
||||||
if (mCompass != null) {
|
|
||||||
mCompass.destroy();
|
|
||||||
}
|
|
||||||
if (crypto != null) {
|
|
||||||
|
|
||||||
}
|
|
||||||
if (mKey != null) {
|
if (mKey != null) {
|
||||||
|
|
||||||
}
|
}
|
||||||
if (audio != null) {
|
|
||||||
audio.destroy();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Clean up modules
|
// Clean up modules
|
||||||
java.util.Set<Entry<String,Module>> s = this.modules.entrySet();
|
java.util.Set<Entry<String,Module>> s = this.modules.entrySet();
|
||||||
@ -305,36 +276,27 @@ public class DroidGap extends Activity {
|
|||||||
callbackServer = new CallbackServer();
|
callbackServer = new CallbackServer();
|
||||||
commandManager = new CommandManager(appView, this);
|
commandManager = new CommandManager(appView, this);
|
||||||
gap = new Device(appView, this);
|
gap = new Device(appView, this);
|
||||||
accel = new AccelListener(appView, this);
|
|
||||||
mContacts = new ContactManager(appView, this);
|
|
||||||
fs = new FileUtils(appView);
|
|
||||||
netMan = new NetworkManager(appView, this);
|
|
||||||
mCompass = new CompassListener(appView, this);
|
|
||||||
crypto = new CryptoHandler(appView);
|
|
||||||
mKey = new BrowserKey(appView, this);
|
mKey = new BrowserKey(appView, this);
|
||||||
audio = new AudioHandler(appView, this);
|
|
||||||
|
|
||||||
// This creates the new javascript interfaces for PhoneGap
|
// This creates the new javascript interfaces for PhoneGap
|
||||||
appView.addJavascriptInterface(commandManager, "CommandManager");
|
appView.addJavascriptInterface(commandManager, "CommandManager");
|
||||||
appView.addJavascriptInterface(gap, "DroidGap");
|
appView.addJavascriptInterface(gap, "DroidGap");
|
||||||
appView.addJavascriptInterface(accel, "Accel");
|
this.addModule("com.phonegap.AccelListener", "Accel");
|
||||||
this.addModule("com.phonegap.CameraLauncher", "GapCam");
|
this.addModule("com.phonegap.CameraLauncher", "GapCam");
|
||||||
appView.addJavascriptInterface(mContacts, "ContactHook");
|
this.addModule("com.phonegap.ContactManager", "ContactHook");
|
||||||
appView.addJavascriptInterface(fs, "FileUtil");
|
this.addModule("com.phonegap.FileUtils", "FileUtil");
|
||||||
appView.addJavascriptInterface(netMan, "NetworkManager");
|
this.addModule("com.phonegap.NetworkManager", "NetworkManager");
|
||||||
appView.addJavascriptInterface(mCompass, "CompassHook");
|
this.addModule("com.phonegap.CompassListener", "CompassHook");
|
||||||
appView.addJavascriptInterface(crypto, "GapCrypto");
|
this.addModule("com.phonegap.CryptoHandler", "GapCrypto");
|
||||||
appView.addJavascriptInterface(mKey, "BackButton");
|
appView.addJavascriptInterface(mKey, "BackButton");
|
||||||
appView.addJavascriptInterface(audio, "GapAudio");
|
this.addModule("com.phonegap.AudioHandler", "GapAudio");
|
||||||
appView.addJavascriptInterface(callbackServer, "CallbackServer");
|
appView.addJavascriptInterface(callbackServer, "CallbackServer");
|
||||||
appView.addJavascriptInterface(new SplashScreen(this), "SplashScreen");
|
appView.addJavascriptInterface(new SplashScreen(this), "SplashScreen");
|
||||||
|
|
||||||
if (android.os.Build.VERSION.RELEASE.startsWith("1."))
|
if (android.os.Build.VERSION.RELEASE.startsWith("1."))
|
||||||
{
|
{
|
||||||
cupcakeStorage = new Storage(appView, this);
|
this.addModule("com.phonegap.Storage", "droidStorage");
|
||||||
geo = new GeoBroker(appView, this);
|
this.addModule("com.phonegap.GeoBroker", "Geo");
|
||||||
appView.addJavascriptInterface(cupcakeStorage, "droidStorage");
|
|
||||||
appView.addJavascriptInterface(geo, "Geo");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -346,7 +308,7 @@ public class DroidGap extends Activity {
|
|||||||
* @param javascriptInterface Bind the object to Javascript so that the methods can be
|
* @param javascriptInterface Bind the object to Javascript so that the methods can be
|
||||||
* accessed from Javascript using this variable name.
|
* accessed from Javascript using this variable name.
|
||||||
*/
|
*/
|
||||||
public void addModule(String className, String javascriptInterface) {
|
public Object addModule(String className, String javascriptInterface) {
|
||||||
System.out.println("DroidGap.addModule("+className+", "+javascriptInterface+")");
|
System.out.println("DroidGap.addModule("+className+", "+javascriptInterface+")");
|
||||||
try {
|
try {
|
||||||
Class cl = Class.forName(className);
|
Class cl = Class.forName(className);
|
||||||
@ -362,11 +324,24 @@ public class DroidGap extends Activity {
|
|||||||
if (javascriptInterface != null) {
|
if (javascriptInterface != null) {
|
||||||
this.appView.addJavascriptInterface(module, javascriptInterface);
|
this.appView.addJavascriptInterface(module, javascriptInterface);
|
||||||
}
|
}
|
||||||
|
return module;
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
System.out.println("Error adding module "+className+".");
|
System.out.println("Error adding module "+className+".");
|
||||||
}
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the loaded module.
|
||||||
|
*
|
||||||
|
* @param className The class of the loaded module.
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public Object getModule(String className) {
|
||||||
|
Object module = this.modules.get(className);
|
||||||
|
return module;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -4,15 +4,16 @@ import java.io.*;
|
|||||||
|
|
||||||
import android.webkit.WebView;
|
import android.webkit.WebView;
|
||||||
|
|
||||||
public class FileUtils {
|
public class FileUtils extends Module {
|
||||||
|
|
||||||
|
|
||||||
WebView mView;
|
WebView mView;
|
||||||
FileReader f_in;
|
FileReader f_in;
|
||||||
FileWriter f_out;
|
FileWriter f_out;
|
||||||
|
|
||||||
public FileUtils(WebView view)
|
public FileUtils(WebView view, DroidGap gap)
|
||||||
{
|
{
|
||||||
|
super(view, gap);
|
||||||
mView = view;
|
mView = view;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@ import android.webkit.WebView;
|
|||||||
* This class only starts and stops various GeoListeners, which consist of a GPS and a Network Listener
|
* This class only starts and stops various GeoListeners, which consist of a GPS and a Network Listener
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class GeoBroker {
|
public class GeoBroker extends Module {
|
||||||
private WebView mAppView;
|
private WebView mAppView;
|
||||||
private DroidGap mCtx;
|
private DroidGap mCtx;
|
||||||
private HashMap<String, GeoListener> geoListeners;
|
private HashMap<String, GeoListener> geoListeners;
|
||||||
@ -20,6 +20,7 @@ public class GeoBroker {
|
|||||||
|
|
||||||
public GeoBroker(WebView view, DroidGap ctx)
|
public GeoBroker(WebView view, DroidGap ctx)
|
||||||
{
|
{
|
||||||
|
super(view, ctx);
|
||||||
mCtx = ctx;
|
mCtx = ctx;
|
||||||
mAppView = view;
|
mAppView = view;
|
||||||
geoListeners = new HashMap<String, GeoListener>();
|
geoListeners = new HashMap<String, GeoListener>();
|
||||||
|
@ -7,14 +7,15 @@ import android.content.Context;
|
|||||||
import android.net.*;
|
import android.net.*;
|
||||||
import android.webkit.WebView;
|
import android.webkit.WebView;
|
||||||
|
|
||||||
public class NetworkManager {
|
public class NetworkManager extends Module {
|
||||||
|
|
||||||
Context mCtx;
|
DroidGap mCtx;
|
||||||
WebView mView;
|
WebView mView;
|
||||||
ConnectivityManager sockMan;
|
ConnectivityManager sockMan;
|
||||||
|
|
||||||
NetworkManager(WebView view, Context ctx)
|
public NetworkManager(WebView view, DroidGap ctx)
|
||||||
{
|
{
|
||||||
|
super(view, ctx);
|
||||||
mCtx = ctx;
|
mCtx = ctx;
|
||||||
mView = view;
|
mView = view;
|
||||||
sockMan = (ConnectivityManager) mCtx.getSystemService(Context.CONNECTIVITY_SERVICE);
|
sockMan = (ConnectivityManager) mCtx.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||||
|
@ -5,7 +5,7 @@ import android.database.sqlite.*;
|
|||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.webkit.WebView;
|
import android.webkit.WebView;
|
||||||
|
|
||||||
public class Storage {
|
public class Storage extends Module {
|
||||||
|
|
||||||
private static final String LOG_TAG = "SQLite Storage:";
|
private static final String LOG_TAG = "SQLite Storage:";
|
||||||
SQLiteDatabase myDb;
|
SQLiteDatabase myDb;
|
||||||
@ -14,7 +14,8 @@ public class Storage {
|
|||||||
WebView appView;
|
WebView appView;
|
||||||
DroidGap mCtx;
|
DroidGap mCtx;
|
||||||
|
|
||||||
Storage(WebView view, DroidGap ctx) {
|
public Storage(WebView view, DroidGap ctx) {
|
||||||
|
super(view, ctx);
|
||||||
appView = view;
|
appView = view;
|
||||||
mCtx = ctx;
|
mCtx = ctx;
|
||||||
}
|
}
|
||||||
|
@ -9,14 +9,15 @@ import android.hardware.SensorManager;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.webkit.WebView;
|
import android.webkit.WebView;
|
||||||
|
|
||||||
public class TempListener implements SensorEventListener {
|
public class TempListener extends Module implements SensorEventListener {
|
||||||
WebView mAppView;
|
WebView mAppView;
|
||||||
DroidGap mCtx;
|
DroidGap mCtx;
|
||||||
Sensor mSensor;
|
Sensor mSensor;
|
||||||
|
|
||||||
private SensorManager sensorManager;
|
private SensorManager sensorManager;
|
||||||
|
|
||||||
TempListener(DroidGap ctx, WebView appView) {
|
public TempListener(WebView appView, DroidGap ctx) {
|
||||||
|
super(appView, ctx);
|
||||||
mCtx = ctx;
|
mCtx = ctx;
|
||||||
mAppView = appView;
|
mAppView = appView;
|
||||||
sensorManager = (SensorManager) mCtx.getSystemService(Context.SENSOR_SERVICE);
|
sensorManager = (SensorManager) mCtx.getSystemService(Context.SENSOR_SERVICE);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user