Change TitleBar RelativeLayout to LinearLayout
Moving from RelativeLayout to LinearLayout improves
the UI layout time by 50%
This change also contains lazy initialization of
some of the Drawables in BaseUi.
Change-Id: Ie6d3f845098a79bc47e21a0d21f2a8d3ab97237a
diff --git a/res/layout/title_bar.xml b/res/layout/title_bar.xml
index 6a62894..485892a 100644
--- a/res/layout/title_bar.xml
+++ b/res/layout/title_bar.xml
@@ -14,9 +14,10 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
-<RelativeLayout
+<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/titlebar"
+ android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<include
@@ -34,8 +35,8 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@null"
- android:layout_below="@id/taburlbar"
+ android:layout_gravity="bottom"
android:src="@drawable/progress"
android:layout_marginTop="@dimen/progress_bar_margin"
android:visibility="gone" />
-</RelativeLayout>
+</LinearLayout>
diff --git a/src/com/android/browser/BaseUi.java b/src/com/android/browser/BaseUi.java
index 354e901..fbb5ad0 100644
--- a/src/com/android/browser/BaseUi.java
+++ b/src/com/android/browser/BaseUi.java
@@ -87,7 +87,7 @@
private Drawable mLockIconSecure;
private Drawable mLockIconMixed;
- protected Drawable mGenericFavicon;
+ private Drawable mGenericFavicon;
protected FrameLayout mContentView;
protected FrameLayout mCustomViewContainer;
@@ -121,8 +121,6 @@
Resources res = mActivity.getResources();
mInputManager = (InputMethodManager)
browser.getSystemService(Activity.INPUT_METHOD_SERVICE);
- mLockIconSecure = res.getDrawable(R.drawable.ic_secure_holo_dark);
- mLockIconMixed = res.getDrawable(R.drawable.ic_secure_partial_holo_dark);
FrameLayout frameLayout = (FrameLayout) mActivity.getWindow()
.getDecorView().findViewById(android.R.id.content);
LayoutInflater.from(mActivity)
@@ -136,8 +134,6 @@
mErrorConsoleContainer = (LinearLayout) frameLayout
.findViewById(R.id.error_console);
setFullscreen(BrowserSettings.getInstance().useFullscreen());
- mGenericFavicon = res.getDrawable(
- R.drawable.app_web_browser_sm);
mTitleBar = new TitleBar(mActivity, mUiController, this,
mContentView);
mTitleBar.setProgress(100);
@@ -152,6 +148,27 @@
}
}
+ private Drawable getLockIconSecure() {
+ if (mLockIconSecure == null) {
+ mLockIconSecure = mActivity.getResources().getDrawable(R.drawable.ic_secure_holo_dark);
+ }
+ return mLockIconSecure;
+ }
+
+ private Drawable getLockIconMixed() {
+ if (mLockIconMixed == null) {
+ mLockIconMixed = mActivity.getResources().getDrawable(R.drawable.ic_secure_partial_holo_dark);
+ }
+ return mLockIconMixed;
+ }
+
+ protected Drawable getGenericFavicon() {
+ if (mGenericFavicon == null) {
+ mGenericFavicon = mActivity.getResources().getDrawable(R.drawable.app_web_browser_sm);
+ }
+ return mGenericFavicon;
+ }
+
// lifecycle
public void onPause() {
@@ -631,12 +648,12 @@
private void updateLockIconImage(SecurityState securityState) {
Drawable d = null;
if (securityState == SecurityState.SECURITY_STATE_SECURE) {
- d = mLockIconSecure;
+ d = getLockIconSecure();
} else if (securityState == SecurityState.SECURITY_STATE_MIXED
|| securityState == SecurityState.SECURITY_STATE_BAD_CERTIFICATE) {
// TODO: It would be good to have different icons for insecure vs mixed content.
// See http://b/5403800
- d = mLockIconMixed;
+ d = getLockIconMixed();
}
mNavigationBar.setLock(d);
}
@@ -813,7 +830,7 @@
PaintDrawable p = new PaintDrawable(Color.WHITE);
array[1] = p;
if (icon == null) {
- array[2] = mGenericFavicon;
+ array[2] = getGenericFavicon();
} else {
array[2] = new BitmapDrawable(icon);
}
diff --git a/src/com/android/browser/XLargeUi.java b/src/com/android/browser/XLargeUi.java
index 08d742e..83d7439 100644
--- a/src/com/android/browser/XLargeUi.java
+++ b/src/com/android/browser/XLargeUi.java
@@ -265,7 +265,7 @@
Drawable[] array = new Drawable[2];
array[0] = getFaviconBackground();
if (icon == null) {
- array[1] = mGenericFavicon;
+ array[1] = getGenericFavicon();
} else {
array[1] = new BitmapDrawable(mActivity.getResources(), icon);
}