incubator-callback-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From macdo...@apache.org
Subject [3/3] android commit: Refactor Android SplashScreen
Date Wed, 25 Apr 2012 15:53:52 GMT
Refactor Android SplashScreen


Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/commit/d7c8bc79
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/tree/d7c8bc79
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/diff/d7c8bc79

Branch: refs/heads/master
Commit: d7c8bc799d8ef61f8d1ace571406754ce4fb4ce1
Parents: 05192a9
Author: macdonst <simon.macdonald@gmail.com>
Authored: Mon Apr 23 14:32:37 2012 -0400
Committer: macdonst <simon.macdonald@gmail.com>
Committed: Tue Apr 24 15:14:37 2012 -0400

----------------------------------------------------------------------
 framework/src/org/apache/cordova/DroidGap.java     |   88 +++++++++------
 framework/src/org/apache/cordova/SplashScreen.java |   23 ++++
 2 files changed, 74 insertions(+), 37 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/d7c8bc79/framework/src/org/apache/cordova/DroidGap.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/DroidGap.java b/framework/src/org/apache/cordova/DroidGap.java
index 4e7e59e..107eb52 100755
--- a/framework/src/org/apache/cordova/DroidGap.java
+++ b/framework/src/org/apache/cordova/DroidGap.java
@@ -37,18 +37,18 @@ import org.xmlpull.v1.XmlPullParserException;
 
 import android.app.Activity;
 import android.app.AlertDialog;
+import android.app.Dialog;
 import android.app.ProgressDialog;
 import android.content.Context;
 import android.content.DialogInterface;
 import android.content.Intent;
 import android.content.res.Configuration;
 import android.content.res.XmlResourceParser;
-import android.database.Cursor;
 import android.graphics.Color;
 import android.media.AudioManager;
 import android.net.Uri;
 import android.os.Bundle;
-import android.util.Log;
+import android.os.Handler;
 import android.view.Display;
 import android.view.KeyEvent;
 import android.view.Menu;
@@ -434,9 +434,6 @@ public class DroidGap extends Activity implements CordovaInterface {
 
         // If spashscreen
         this.splashscreen = this.getIntegerProperty("splashscreen", 0);
-        if ((this.urls.size() == 0) && (this.splashscreen != 0)) {
-            root.setBackgroundResource(this.splashscreen);
-        }
 
         // If loadUrlTimeoutValue
         int timeout = this.getIntegerProperty("loadUrlTimeoutValue", 0);
@@ -609,38 +606,12 @@ public class DroidGap extends Activity implements CordovaInterface {
         if (!url.startsWith("javascript:")) {
             LOG.d(TAG, "DroidGap.loadUrl(%s, %d)", url, time);
         }
-        final DroidGap me = this;
-
-        // Handle activity parameters
-        this.runOnUiThread(new Runnable() {
-            public void run() {
-                if (me.appView == null) {
-                    me.init();
-                }
-                me.handleActivityParameters();
-            }
-        });
-
-        Runnable runnable = new Runnable() {
-            public void run() {
-                try {
-                    synchronized(this) {
-                        this.wait(time);
-                    }
-                } catch (InterruptedException e) {
-                    e.printStackTrace();
-                }
-                if (!me.cancelLoadUrl) {
-                    me.loadUrlIntoView(url);
-                }
-                else{
-                    me.cancelLoadUrl = false;
-                    LOG.d(TAG, "Aborting loadUrl(%s): Another URL was loaded before timer
expired.", url);
-                }
-            }
-        };
-        Thread thread = new Thread(runnable);
-        thread.start();
+        
+        this.handleActivityParameters();
+        if (this.splashscreen != 0) {
+            this.showSplashScreen(time);
+        }
+        this.loadUrlIntoView(url);
     }
     
     /**
@@ -1433,4 +1404,47 @@ public class DroidGap extends Activity implements CordovaInterface
{
       return this.bound;
     }
 
+    protected Dialog splashDialog;
+    
+    /**
+     * Removes the Dialog that displays the splash screen
+     */
+    public void removeSplashScreen() {
+        if (splashDialog != null) {
+            splashDialog.dismiss();
+            splashDialog = null;
+        }
+    }
+     
+    /**
+     * Shows the splash screen over the full Activity
+     */
+    protected void showSplashScreen(int time) {
+        // Get reference to display
+        Display display = getWindowManager().getDefaultDisplay();
+        
+        // Create the layout for the dialog
+        LinearLayout root = new LinearLayout(this);
+        root.setMinimumHeight(display.getHeight());
+        root.setMinimumWidth(display.getWidth());
+        root.setOrientation(LinearLayout.VERTICAL);
+        root.setBackgroundColor(this.getIntegerProperty("backgroundColor", Color.BLACK));
+        root.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,

+                ViewGroup.LayoutParams.FILL_PARENT, 0.0F));
+        root.setBackgroundResource(this.splashscreen);
+
+        // Create and show the dialog
+        splashDialog = new Dialog(this, android.R.style.Theme_Translucent_NoTitleBar);  
    
+        splashDialog.setContentView(root);
+        splashDialog.setCancelable(false);
+        splashDialog.show();
+     
+        // Set Runnable to remove splash screen just in case
+        final Handler handler = new Handler();
+        handler.postDelayed(new Runnable() {
+          public void run() {
+            removeSplashScreen();
+          }
+        }, time);
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/d7c8bc79/framework/src/org/apache/cordova/SplashScreen.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/SplashScreen.java b/framework/src/org/apache/cordova/SplashScreen.java
new file mode 100644
index 0000000..a8d3fc8
--- /dev/null
+++ b/framework/src/org/apache/cordova/SplashScreen.java
@@ -0,0 +1,23 @@
+package org.apache.cordova;
+
+import org.apache.cordova.api.Plugin;
+import org.apache.cordova.api.PluginResult;
+import org.json.JSONArray;
+
+public class SplashScreen extends Plugin {
+
+    @Override
+    public PluginResult execute(String action, JSONArray args, String callbackId) {
+        PluginResult.Status status = PluginResult.Status.OK;
+        String result = "";
+
+        if (action.equals("hide")) {
+            ((DroidGap)this.ctx).removeSplashScreen();
+        }
+        else {
+            status = PluginResult.Status.INVALID_ACTION;
+        }
+        return new PluginResult(status, result);
+    }
+
+}


Mime
View raw message