forked from github/cordova-android
refactored the Command stuff a bit more, added a spashscreen
This commit is contained in:
@@ -38,6 +38,7 @@ import android.content.res.Configuration;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Color;
|
||||
import android.net.Uri;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
import android.util.Log;
|
||||
@@ -53,6 +54,7 @@ import android.webkit.WebView;
|
||||
import android.webkit.WebViewClient;
|
||||
import android.webkit.GeolocationPermissions.Callback;
|
||||
import android.webkit.WebSettings.LayoutAlgorithm;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.os.Build.*;
|
||||
import android.provider.MediaStore;
|
||||
@@ -61,6 +63,7 @@ public class DroidGap extends Activity {
|
||||
|
||||
private static final String LOG_TAG = "DroidGap";
|
||||
protected WebView appView;
|
||||
protected ImageView splashScreen;
|
||||
private LinearLayout root;
|
||||
|
||||
private Device gap;
|
||||
@@ -77,39 +80,53 @@ public class DroidGap extends Activity {
|
||||
private AudioHandler audio;
|
||||
private CallbackServer callbackServer;
|
||||
private CommandManager commandManager;
|
||||
|
||||
|
||||
private Uri imageUri;
|
||||
|
||||
/** Called when the activity is first created. */
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
getWindow().requestFeature(Window.FEATURE_NO_TITLE);
|
||||
getWindow().setFlags(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!
|
||||
|
||||
LinearLayout.LayoutParams containerParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
|
||||
ViewGroup.LayoutParams.FILL_PARENT, 0.0F);
|
||||
|
||||
LinearLayout.LayoutParams webviewParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
|
||||
ViewGroup.LayoutParams.FILL_PARENT, 1.0F);
|
||||
|
||||
|
||||
root = new LinearLayout(this);
|
||||
root.setOrientation(LinearLayout.VERTICAL);
|
||||
root.setBackgroundColor(Color.BLACK);
|
||||
root.setLayoutParams(containerParams);
|
||||
|
||||
appView = new WebView(this);
|
||||
appView.setLayoutParams(webviewParams);
|
||||
|
||||
root.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
|
||||
ViewGroup.LayoutParams.FILL_PARENT, 0.0F));
|
||||
|
||||
splashScreen = new ImageView(this);
|
||||
splashScreen.setLayoutParams(new LinearLayout.LayoutParams(
|
||||
ViewGroup.LayoutParams.FILL_PARENT,
|
||||
ViewGroup.LayoutParams.FILL_PARENT,
|
||||
1.0F));
|
||||
splashScreen.setImageResource(R.drawable.splash);
|
||||
|
||||
root.addView(splashScreen);
|
||||
|
||||
initWebView();
|
||||
|
||||
setContentView(root);
|
||||
}
|
||||
|
||||
private void initWebView() {
|
||||
appView = new WebView(DroidGap.this);
|
||||
|
||||
appView.setLayoutParams(new LinearLayout.LayoutParams(
|
||||
ViewGroup.LayoutParams.FILL_PARENT,
|
||||
ViewGroup.LayoutParams.FILL_PARENT,
|
||||
1.0F));
|
||||
|
||||
WebViewReflect.checkCompatibility();
|
||||
|
||||
if (android.os.Build.VERSION.RELEASE.startsWith("2."))
|
||||
appView.setWebChromeClient(new EclairClient(this));
|
||||
else
|
||||
{
|
||||
appView.setWebChromeClient(new GapClient(this));
|
||||
|
||||
if (android.os.Build.VERSION.RELEASE.startsWith("2.")) {
|
||||
appView.setWebChromeClient(new EclairClient(DroidGap.this));
|
||||
} else {
|
||||
appView.setWebChromeClient(new GapClient(DroidGap.this));
|
||||
}
|
||||
|
||||
appView.setWebViewClient(new GapViewClient(this));
|
||||
@@ -131,23 +148,15 @@ public class DroidGap extends Activity {
|
||||
WebViewReflect.setDomStorage(settings);
|
||||
// Turn off native geolocation object in browser - we use our own :)
|
||||
WebViewReflect.setGeolocationEnabled(settings, true);
|
||||
/* Bind the appView object to the gap class methods */
|
||||
// Bind the appView object to the gap class methods
|
||||
bindBrowser(appView);
|
||||
if(cupcakeStorage != null)
|
||||
cupcakeStorage.setStorage(appPackage);
|
||||
|
||||
root.addView(appView);
|
||||
|
||||
// Try firing the onNativeReady event in JS. If it fails because the JS is
|
||||
// not loaded yet then just set a flag so that the onNativeReady can be fired
|
||||
// from the JS side when the JS gets to that code.
|
||||
appView.loadUrl("javascript:try{PhoneGap.onNativeReady.fire();}catch(e){_nativeReady = true;}");
|
||||
|
||||
setContentView(root);
|
||||
}
|
||||
|
||||
public void invoke(String origin, boolean allow, boolean remember) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -260,6 +269,7 @@ public class DroidGap extends Activity {
|
||||
appView.addJavascriptInterface(mKey, "BackButton");
|
||||
appView.addJavascriptInterface(audio, "GapAudio");
|
||||
appView.addJavascriptInterface(callbackServer, "CallbackServer");
|
||||
//appView.addJavascriptInterface(new SplashScreen(this), "SplashScreen");
|
||||
|
||||
if (android.os.Build.VERSION.RELEASE.startsWith("1."))
|
||||
{
|
||||
@@ -272,7 +282,7 @@ public class DroidGap extends Activity {
|
||||
|
||||
public void loadUrl(String url)
|
||||
{
|
||||
appView.loadUrl(url);
|
||||
this.appView.loadUrl(url);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -411,33 +421,39 @@ public class DroidGap extends Activity {
|
||||
|
||||
public boolean onKeyDown(int keyCode, KeyEvent event)
|
||||
{
|
||||
|
||||
if (keyCode == KeyEvent.KEYCODE_BACK) {
|
||||
if (mKey.isBound())
|
||||
{
|
||||
//We fire an event here!
|
||||
appView.loadUrl("javascript:document.keyEvent.backTrigger()");
|
||||
}
|
||||
else
|
||||
{
|
||||
String testUrl = appView.getUrl();
|
||||
appView.goBack();
|
||||
if(appView.getUrl().equals(testUrl))
|
||||
{
|
||||
return super.onKeyDown(keyCode, event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (keyCode == KeyEvent.KEYCODE_MENU)
|
||||
{
|
||||
// This is where we launch the menu
|
||||
appView.loadUrl("javascript:keyEvent.menuTrigger()");
|
||||
}
|
||||
|
||||
if (keyCode == KeyEvent.KEYCODE_BACK) {
|
||||
if (mKey.isBound())
|
||||
{
|
||||
//We fire an event here!
|
||||
appView.loadUrl("javascript:document.keyEvent.backTrigger()");
|
||||
}
|
||||
else
|
||||
{
|
||||
String testUrl = appView.getUrl();
|
||||
appView.goBack();
|
||||
if(appView.getUrl().equals(testUrl))
|
||||
{
|
||||
return super.onKeyDown(keyCode, event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (keyCode == KeyEvent.KEYCODE_MENU)
|
||||
{
|
||||
// This is where we launch the menu
|
||||
appView.loadUrl("javascript:keyEvent.menuTrigger()");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the splash screen from root view and adds the WebView
|
||||
*/
|
||||
public void hideSplashScreen() {
|
||||
root.removeView(splashScreen);
|
||||
root.addView(appView);
|
||||
}
|
||||
|
||||
// This is required to start the camera activity! It has to come from the previous activity
|
||||
public void startCamera()
|
||||
{
|
||||
@@ -469,11 +485,5 @@ public class DroidGap extends Activity {
|
||||
{
|
||||
launcher.failPicture("Did not complete!");
|
||||
}
|
||||
}
|
||||
|
||||
public WebView getView()
|
||||
{
|
||||
return this.appView;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user