diff options
author | Grace Kloba <klobag@google.com> | 2010-04-20 11:07:50 -0700 |
---|---|---|
committer | Grace Kloba <klobag@google.com> | 2010-04-20 11:07:50 -0700 |
commit | 50c241e6339c681c2427a57a31a357d35927c2ac (patch) | |
tree | f2747ec120a5fa04958f1cca42502e7d6668722d | |
parent | 8588d15a7c0b87049469fd80f9c53eb274cd837b (diff) | |
download | packages_apps_Browser-50c241e6339c681c2427a57a31a357d35927c2ac.zip packages_apps_Browser-50c241e6339c681c2427a57a31a357d35927c2ac.tar.gz packages_apps_Browser-50c241e6339c681c2427a57a31a357d35927c2ac.tar.bz2 |
Using ViewStub to defer the inflation of GeolocationPermissionsPrompt until we first show it.
This should shave 5% of Browser start up time.
Fix http://b/issue?id=2604295
-rwxr-xr-x | res/layout/geolocation_permissions_prompt.xml | 5 | ||||
-rwxr-xr-x | res/layout/tab.xml | 4 | ||||
-rwxr-xr-x | src/com/android/browser/GeolocationPermissionsPrompt.java | 34 | ||||
-rw-r--r-- | src/com/android/browser/Tab.java | 20 |
4 files changed, 32 insertions, 31 deletions
diff --git a/res/layout/geolocation_permissions_prompt.xml b/res/layout/geolocation_permissions_prompt.xml index cdb25d2..babde3a 100755 --- a/res/layout/geolocation_permissions_prompt.xml +++ b/res/layout/geolocation_permissions_prompt.xml @@ -16,7 +16,8 @@ This is the layout for the Geolocation permissions prompt. --> -<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" +<com.android.browser.GeolocationPermissionsPrompt + xmlns:android="http://schemas.android.com/apk/res/android" android:fitsSystemWindows="true" android:layout_width="match_parent" android:layout_height="wrap_content"> @@ -87,4 +88,4 @@ </LinearLayout> </LinearLayout> -</LinearLayout> +</com.android.browser.GeolocationPermissionsPrompt> diff --git a/res/layout/tab.xml b/res/layout/tab.xml index abef51d..69baf56 100755 --- a/res/layout/tab.xml +++ b/res/layout/tab.xml @@ -32,8 +32,8 @@ android:layout_weight="1" /> <!-- Geolocation permissions prompt --> - <com.android.browser.GeolocationPermissionsPrompt - android:id="@+id/geolocation_permissions_prompt" + <ViewStub android:id="@+id/geolocation_permissions_prompt" + android:layout="@layout/geolocation_permissions_prompt" android:layout_width="match_parent" android:layout_height="wrap_content" /> diff --git a/src/com/android/browser/GeolocationPermissionsPrompt.java b/src/com/android/browser/GeolocationPermissionsPrompt.java index 982aa89..95c5415 100755 --- a/src/com/android/browser/GeolocationPermissionsPrompt.java +++ b/src/com/android/browser/GeolocationPermissionsPrompt.java @@ -46,15 +46,26 @@ public class GeolocationPermissionsPrompt extends LinearLayout { public GeolocationPermissionsPrompt(Context context, AttributeSet attrs) { super(context, attrs); - LayoutInflater factory = LayoutInflater.from(context); - factory.inflate(R.layout.geolocation_permissions_prompt, this); + } + void init() { mInner = (LinearLayout) findViewById(R.id.inner); mMessage = (TextView) findViewById(R.id.message); mShareButton = (Button) findViewById(R.id.share_button); mDontShareButton = (Button) findViewById(R.id.dont_share_button); mRemember = (CheckBox) findViewById(R.id.remember); - setButtonClickListeners(); + + final GeolocationPermissionsPrompt me = this; + mShareButton.setOnClickListener(new View.OnClickListener() { + public void onClick(View v) { + me.handleButtonClick(true); + } + }); + mDontShareButton.setOnClickListener(new View.OnClickListener() { + public void onClick(View v) { + me.handleButtonClick(false); + } + }); } /** @@ -79,23 +90,6 @@ public class GeolocationPermissionsPrompt extends LinearLayout { } /** - * Sets the on click listeners for the buttons. - */ - private void setButtonClickListeners() { - final GeolocationPermissionsPrompt me = this; - mShareButton.setOnClickListener(new View.OnClickListener() { - public void onClick(View v) { - me.handleButtonClick(true); - } - }); - mDontShareButton.setOnClickListener(new View.OnClickListener() { - public void onClick(View v) { - me.handleButtonClick(false); - } - }); - } - - /** * Handles a click on one the buttons by invoking the callback. */ private void handleButtonClick(boolean allow) { diff --git a/src/com/android/browser/Tab.java b/src/com/android/browser/Tab.java index 8c2371a..01424e2 100644 --- a/src/com/android/browser/Tab.java +++ b/src/com/android/browser/Tab.java @@ -48,6 +48,7 @@ import android.view.KeyEvent; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.view.ViewStub; import android.view.View.OnClickListener; import android.webkit.ConsoleMessage; import android.webkit.CookieSyncManager; @@ -1097,7 +1098,7 @@ class Tab { public void onGeolocationPermissionsShowPrompt(String origin, GeolocationPermissions.Callback callback) { if (mInForeground) { - mGeolocationPermissionsPrompt.show(origin, callback); + getGeolocationPermissionsPrompt().show(origin, callback); } } @@ -1106,7 +1107,7 @@ class Tab { */ @Override public void onGeolocationPermissionsHidePrompt() { - if (mInForeground) { + if (mInForeground && mGeolocationPermissionsPrompt != null) { mGeolocationPermissionsPrompt.hide(); } } @@ -1309,10 +1310,6 @@ class Tab { // WebView, as well as any other UI elements associated with the tab. mContainer = mInflateService.inflate(R.layout.tab, null); - mGeolocationPermissionsPrompt = - (GeolocationPermissionsPrompt) mContainer.findViewById( - R.id.geolocation_permissions_prompt); - mDownloadListener = new DownloadListener() { public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, @@ -1362,7 +1359,9 @@ class Tab { } // If the WebView is changing, the page will be reloaded, so any ongoing // Geolocation permission requests are void. - mGeolocationPermissionsPrompt.hide(); + if (mGeolocationPermissionsPrompt != null) { + mGeolocationPermissionsPrompt.hide(); + } // Just remove the old one. FrameLayout wrapper = @@ -1661,6 +1660,13 @@ class Tab { * @return The geolocation permissions prompt for this tab. */ GeolocationPermissionsPrompt getGeolocationPermissionsPrompt() { + if (mGeolocationPermissionsPrompt == null) { + ViewStub stub = (ViewStub) mContainer + .findViewById(R.id.geolocation_permissions_prompt); + mGeolocationPermissionsPrompt = (GeolocationPermissionsPrompt) stub + .inflate(); + mGeolocationPermissionsPrompt.init(); + } return mGeolocationPermissionsPrompt; } |