mirror of
https://github.com/apache/cordova-android.git
synced 2025-02-22 00:32:55 +08:00
Fix formatting and rearrange method order.
This commit is contained in:
parent
4b2398b487
commit
e8b85f6cf7
@ -102,39 +102,39 @@ public class DroidGap extends PhonegapActivity {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
getWindow().requestFeature(Window.FEATURE_NO_TITLE);
|
getWindow().requestFeature(Window.FEATURE_NO_TITLE);
|
||||||
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN,
|
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN,
|
||||||
WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
|
WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
|
||||||
// This builds the view. We could probably get away with NOT having a LinearLayout, but I like having a bucket!
|
// This builds the view. We could probably get away with NOT having a LinearLayout, but I like having a bucket!
|
||||||
|
|
||||||
root = new LinearLayout(this);
|
root = new LinearLayout(this);
|
||||||
root.setOrientation(LinearLayout.VERTICAL);
|
root.setOrientation(LinearLayout.VERTICAL);
|
||||||
root.setBackgroundColor(Color.BLACK);
|
root.setBackgroundColor(Color.BLACK);
|
||||||
root.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
|
root.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
|
||||||
ViewGroup.LayoutParams.FILL_PARENT, 0.0F));
|
ViewGroup.LayoutParams.FILL_PARENT, 0.0F));
|
||||||
|
|
||||||
/*
|
/*
|
||||||
splashScreen = new ImageView(this);
|
splashScreen = new ImageView(this);
|
||||||
splashScreen.setLayoutParams(new LinearLayout.LayoutParams(
|
splashScreen.setLayoutParams(new LinearLayout.LayoutParams(
|
||||||
ViewGroup.LayoutParams.FILL_PARENT,
|
ViewGroup.LayoutParams.FILL_PARENT,
|
||||||
ViewGroup.LayoutParams.FILL_PARENT,
|
ViewGroup.LayoutParams.FILL_PARENT,
|
||||||
1.0F));
|
1.0F));
|
||||||
splashScreen.setImageResource(R.drawable.splash);
|
splashScreen.setImageResource(R.drawable.splash);
|
||||||
|
|
||||||
root.addView(splashScreen);
|
root.addView(splashScreen);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// If url was passed in to intent, then init webview, which will load the url
|
// If url was passed in to intent, then init webview, which will load the url
|
||||||
Bundle bundle = this.getIntent().getExtras();
|
Bundle bundle = this.getIntent().getExtras();
|
||||||
if (bundle != null) {
|
if (bundle != null) {
|
||||||
String url = bundle.getString("url");
|
String url = bundle.getString("url");
|
||||||
if (url != null) {
|
if (url != null) {
|
||||||
this.init();
|
this.init();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create and initialize web container.
|
* Create and initialize web container.
|
||||||
*/
|
*/
|
||||||
@ -191,34 +191,102 @@ public class DroidGap extends PhonegapActivity {
|
|||||||
this.handleActivityParameters();
|
this.handleActivityParameters();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Bind PhoneGap objects to JavaScript.
|
||||||
|
*
|
||||||
|
* @param appView
|
||||||
|
*/
|
||||||
|
private void bindBrowser(WebView appView) {
|
||||||
|
|
||||||
|
this.callbackServer = new CallbackServer();
|
||||||
|
this.pluginManager = new PluginManager(appView, this);
|
||||||
|
this.mKey = new BrowserKey(appView, this);
|
||||||
|
|
||||||
|
// This creates the new javascript interfaces for PhoneGap
|
||||||
|
appView.addJavascriptInterface(this.pluginManager, "PluginManager");
|
||||||
|
|
||||||
|
appView.addJavascriptInterface(this.mKey, "BackButton");
|
||||||
|
|
||||||
|
appView.addJavascriptInterface(this.callbackServer, "CallbackServer");
|
||||||
|
appView.addJavascriptInterface(new SplashScreen(this), "SplashScreen");
|
||||||
|
|
||||||
|
this.addService("Geolocation", "com.phonegap.GeoBroker");
|
||||||
|
this.addService("Device", "com.phonegap.Device");
|
||||||
|
this.addService("Accelerometer", "com.phonegap.AccelListener");
|
||||||
|
this.addService("Compass", "com.phonegap.CompassListener");
|
||||||
|
this.addService("Media", "com.phonegap.AudioHandler");
|
||||||
|
this.addService("Camera", "com.phonegap.CameraLauncher");
|
||||||
|
this.addService("Contacts", "com.phonegap.ContactManager");
|
||||||
|
this.addService("Crypto", "com.phonegap.CryptoHandler");
|
||||||
|
this.addService("File", "com.phonegap.FileUtils");
|
||||||
|
this.addService("Location", "com.phonegap.GeoBroker"); // Always add Location, even though it is built-in on 2.x devices. Let JavaScript decide which one to use.
|
||||||
|
this.addService("Network Status", "com.phonegap.NetworkManager");
|
||||||
|
this.addService("Notification", "com.phonegap.Notification");
|
||||||
|
this.addService("Storage", "com.phonegap.Storage");
|
||||||
|
this.addService("Temperature", "com.phonegap.TempListener");
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Look at activity parameters and process them.
|
* Look at activity parameters and process them.
|
||||||
*/
|
*/
|
||||||
private void handleActivityParameters() {
|
private void handleActivityParameters() {
|
||||||
|
|
||||||
// If loadingDialog, then show the App loading dialog
|
// If loadingDialog, then show the App loading dialog
|
||||||
if (this.getProperty("loadingDialog", true)) {
|
if (this.getProperty("loadingDialog", true)) {
|
||||||
this.pluginManager.exec("Notification", "activityStart", null, "[\"Wait\",\"Loading Application...\"]", false);
|
this.pluginManager.exec("Notification", "activityStart", null, "[\"Wait\",\"Loading Application...\"]", false);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If hideLoadingDialogOnPageLoad
|
|
||||||
this.hideLoadingDialogOnPageLoad = this.getProperty("hideLoadingDialogOnPageLoad", false);
|
|
||||||
|
|
||||||
// If loadInWebView
|
// If hideLoadingDialogOnPageLoad
|
||||||
this.loadInWebView = this.getProperty("loadInWebView", false);
|
this.hideLoadingDialogOnPageLoad = this.getProperty("hideLoadingDialogOnPageLoad", false);
|
||||||
|
|
||||||
// If spashscreen
|
// If loadInWebView
|
||||||
String splashscreen = this.getProperty("splashscreen", null);
|
this.loadInWebView = this.getProperty("loadInWebView", false);
|
||||||
if (splashscreen != null) {
|
|
||||||
// TODO:
|
|
||||||
}
|
|
||||||
|
|
||||||
// If url specified, then load it
|
// If spashscreen
|
||||||
String url = this.getProperty("url", null);
|
String splashscreen = this.getProperty("splashscreen", null);
|
||||||
if (url != null) {
|
if (splashscreen != null) {
|
||||||
System.out.println("Loading initial URL="+url);
|
// TODO:
|
||||||
this.loadUrl(url);
|
}
|
||||||
}
|
|
||||||
|
// If url specified, then load it
|
||||||
|
String url = this.getProperty("url", null);
|
||||||
|
if (url != null) {
|
||||||
|
System.out.println("Loading initial URL="+url);
|
||||||
|
this.loadUrl(url);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load the url into the webview.
|
||||||
|
*
|
||||||
|
* @param url
|
||||||
|
*/
|
||||||
|
public void loadUrl(final String url) {
|
||||||
|
System.out.println("loadUrl("+url+")");
|
||||||
|
this.url = url;
|
||||||
|
int i = url.lastIndexOf('/');
|
||||||
|
if (i > 0) {
|
||||||
|
this.baseUrl = url.substring(0, i);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this.baseUrl = this.url;
|
||||||
|
}
|
||||||
|
System.out.println("url="+url+" baseUrl="+baseUrl);
|
||||||
|
|
||||||
|
// Init web view if not already done
|
||||||
|
if (this.appView == null) {
|
||||||
|
this.init();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Initialize callback server
|
||||||
|
this.callbackServer.init(url);
|
||||||
|
|
||||||
|
// Load URL on UI thread
|
||||||
|
this.runOnUiThread(new Runnable() {
|
||||||
|
public void run() {
|
||||||
|
DroidGap.this.appView.loadUrl(url);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -228,8 +296,8 @@ public class DroidGap extends PhonegapActivity {
|
|||||||
* @param Configuration newConfig
|
* @param Configuration newConfig
|
||||||
*/
|
*/
|
||||||
public void onConfigurationChanged(Configuration newConfig) {
|
public void onConfigurationChanged(Configuration newConfig) {
|
||||||
//don't reload the current page when the orientation is changed
|
//don't reload the current page when the orientation is changed
|
||||||
super.onConfigurationChanged(newConfig);
|
super.onConfigurationChanged(newConfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -428,73 +496,6 @@ public class DroidGap extends PhonegapActivity {
|
|||||||
public void addService(String serviceType, String className) {
|
public void addService(String serviceType, String className) {
|
||||||
this.pluginManager.addService(serviceType, className);
|
this.pluginManager.addService(serviceType, className);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Bind PhoneGap objects to JavaScript.
|
|
||||||
*
|
|
||||||
* @param appView
|
|
||||||
*/
|
|
||||||
private void bindBrowser(WebView appView) {
|
|
||||||
this.callbackServer = new CallbackServer();
|
|
||||||
this.pluginManager = new PluginManager(appView, this);
|
|
||||||
this.mKey = new BrowserKey(appView, this);
|
|
||||||
|
|
||||||
// This creates the new javascript interfaces for PhoneGap
|
|
||||||
appView.addJavascriptInterface(this.pluginManager, "PluginManager");
|
|
||||||
|
|
||||||
appView.addJavascriptInterface(this.mKey, "BackButton");
|
|
||||||
|
|
||||||
appView.addJavascriptInterface(this.callbackServer, "CallbackServer");
|
|
||||||
appView.addJavascriptInterface(new SplashScreen(this), "SplashScreen");
|
|
||||||
|
|
||||||
|
|
||||||
this.addService("Geolocation", "com.phonegap.GeoBroker");
|
|
||||||
this.addService("Device", "com.phonegap.Device");
|
|
||||||
this.addService("Accelerometer", "com.phonegap.AccelListener");
|
|
||||||
this.addService("Compass", "com.phonegap.CompassListener");
|
|
||||||
this.addService("Media", "com.phonegap.AudioHandler");
|
|
||||||
this.addService("Camera", "com.phonegap.CameraLauncher");
|
|
||||||
this.addService("Contacts", "com.phonegap.ContactManager");
|
|
||||||
this.addService("Crypto", "com.phonegap.CryptoHandler");
|
|
||||||
this.addService("File", "com.phonegap.FileUtils");
|
|
||||||
this.addService("Location", "com.phonegap.GeoBroker"); // Always add Location, even though it is built-in on 2.x devices. Let JavaScript decide which one to use.
|
|
||||||
this.addService("Network Status", "com.phonegap.NetworkManager");
|
|
||||||
this.addService("Notification", "com.phonegap.Notification");
|
|
||||||
this.addService("Storage", "com.phonegap.Storage");
|
|
||||||
this.addService("Temperature", "com.phonegap.TempListener");
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Load the url into the webview.
|
|
||||||
*
|
|
||||||
* @param url
|
|
||||||
*/
|
|
||||||
public void loadUrl(final String url) {
|
|
||||||
this.url = url;
|
|
||||||
int i = url.lastIndexOf('/');
|
|
||||||
if (i > 0) {
|
|
||||||
this.baseUrl = url.substring(0, i);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
this.baseUrl = this.url;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Init web view if not already done
|
|
||||||
if (this.appView == null) {
|
|
||||||
this.init();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Initialize callback server
|
|
||||||
this.callbackServer.init(url);
|
|
||||||
|
|
||||||
// Load URL on UI thread
|
|
||||||
this.runOnUiThread(new Runnable() {
|
|
||||||
public void run() {
|
|
||||||
DroidGap.this.appView.loadUrl(url);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send JavaScript statement back to JavaScript.
|
* Send JavaScript statement back to JavaScript.
|
||||||
@ -595,67 +596,67 @@ public class DroidGap extends PhonegapActivity {
|
|||||||
* WebChromeClient that extends GapClient with additional support for Android 2.X
|
* WebChromeClient that extends GapClient with additional support for Android 2.X
|
||||||
*/
|
*/
|
||||||
public final class EclairClient extends GapClient {
|
public final class EclairClient extends GapClient {
|
||||||
|
|
||||||
private String TAG = "PhoneGapLog";
|
|
||||||
private long MAX_QUOTA = 100 * 1024 * 1024;
|
|
||||||
|
|
||||||
/**
|
private String TAG = "PhoneGapLog";
|
||||||
* Constructor.
|
private long MAX_QUOTA = 100 * 1024 * 1024;
|
||||||
*
|
|
||||||
* @param ctx
|
/**
|
||||||
*/
|
* Constructor.
|
||||||
public EclairClient(Context ctx) {
|
*
|
||||||
super(ctx);
|
* @param ctx
|
||||||
}
|
*/
|
||||||
|
public EclairClient(Context ctx) {
|
||||||
|
super(ctx);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle database quota exceeded notification.
|
||||||
|
*
|
||||||
|
* @param url
|
||||||
|
* @param databaseIdentifier
|
||||||
|
* @param currentQuota
|
||||||
|
* @param estimatedSize
|
||||||
|
* @param totalUsedQuota
|
||||||
|
* @param quotaUpdater
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void onExceededDatabaseQuota(String url, String databaseIdentifier, long currentQuota, long estimatedSize,
|
||||||
|
long totalUsedQuota, WebStorage.QuotaUpdater quotaUpdater)
|
||||||
|
{
|
||||||
|
Log.d(TAG, "event raised onExceededDatabaseQuota estimatedSize: " + Long.toString(estimatedSize) + " currentQuota: " + Long.toString(currentQuota) + " totalUsedQuota: " + Long.toString(totalUsedQuota));
|
||||||
|
|
||||||
|
if( estimatedSize < MAX_QUOTA)
|
||||||
|
{
|
||||||
|
//increase for 1Mb
|
||||||
|
long newQuota = estimatedSize;
|
||||||
|
Log.d(TAG, "calling quotaUpdater.updateQuota newQuota: " + Long.toString(newQuota) );
|
||||||
|
quotaUpdater.updateQuota(newQuota);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Set the quota to whatever it is and force an error
|
||||||
|
// TODO: get docs on how to handle this properly
|
||||||
|
quotaUpdater.updateQuota(currentQuota);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// console.log in api level 7: http://developer.android.com/guide/developing/debug-tasks.html
|
||||||
|
@Override
|
||||||
|
public void onConsoleMessage(String message, int lineNumber, String sourceID)
|
||||||
|
{
|
||||||
|
// This is a kludgy hack!!!!
|
||||||
|
Log.d(TAG, sourceID + ": Line " + Integer.toString(lineNumber) + " : " + message);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onGeolocationPermissionsShowPrompt(String origin, Callback callback) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
super.onGeolocationPermissionsShowPrompt(origin, callback);
|
||||||
|
callback.invoke(origin, true, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Handle database quota exceeded notification.
|
|
||||||
*
|
|
||||||
* @param url
|
|
||||||
* @param databaseIdentifier
|
|
||||||
* @param currentQuota
|
|
||||||
* @param estimatedSize
|
|
||||||
* @param totalUsedQuota
|
|
||||||
* @param quotaUpdater
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void onExceededDatabaseQuota(String url, String databaseIdentifier, long currentQuota, long estimatedSize,
|
|
||||||
long totalUsedQuota, WebStorage.QuotaUpdater quotaUpdater)
|
|
||||||
{
|
|
||||||
Log.d(TAG, "event raised onExceededDatabaseQuota estimatedSize: " + Long.toString(estimatedSize) + " currentQuota: " + Long.toString(currentQuota) + " totalUsedQuota: " + Long.toString(totalUsedQuota));
|
|
||||||
|
|
||||||
if( estimatedSize < MAX_QUOTA)
|
|
||||||
{
|
|
||||||
//increase for 1Mb
|
|
||||||
long newQuota = estimatedSize;
|
|
||||||
Log.d(TAG, "calling quotaUpdater.updateQuota newQuota: " + Long.toString(newQuota) );
|
|
||||||
quotaUpdater.updateQuota(newQuota);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Set the quota to whatever it is and force an error
|
|
||||||
// TODO: get docs on how to handle this properly
|
|
||||||
quotaUpdater.updateQuota(currentQuota);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// console.log in api level 7: http://developer.android.com/guide/developing/debug-tasks.html
|
|
||||||
@Override
|
|
||||||
public void onConsoleMessage(String message, int lineNumber, String sourceID)
|
|
||||||
{
|
|
||||||
// This is a kludgy hack!!!!
|
|
||||||
Log.d(TAG, sourceID + ": Line " + Integer.toString(lineNumber) + " : " + message);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onGeolocationPermissionsShowPrompt(String origin, Callback callback) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
super.onGeolocationPermissionsShowPrompt(origin, callback);
|
|
||||||
callback.invoke(origin, true, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The webview client receives notifications about appView
|
* The webview client receives notifications about appView
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user