diff options
author | John Reck <jreck@google.com> | 2012-05-18 21:38:59 -0700 |
---|---|---|
committer | John Reck <jreck@google.com> | 2012-05-18 22:35:21 -0700 |
commit | 2711fab2fa2eb798e3aea90368f7ac5af1fbe523 (patch) | |
tree | bcabbd102e26fceaaa2ddf5eb971db3f1eacb679 /src/com | |
parent | aae2c1308c81bf8a3dd900e2aeccb0e43da45fd7 (diff) | |
download | packages_apps_browser-2711fab2fa2eb798e3aea90368f7ac5af1fbe523.zip packages_apps_browser-2711fab2fa2eb798e3aea90368f7ac5af1fbe523.tar.gz packages_apps_browser-2711fab2fa2eb798e3aea90368f7ac5af1fbe523.tar.bz2 |
Fix portrait's fixed title bar
Bug: 6468013
Change-Id: Ia6ee9645df9ebb8aa98734efef45b57db94651f7
Diffstat (limited to 'src/com')
-rw-r--r-- | src/com/android/browser/BaseUi.java | 16 | ||||
-rw-r--r-- | src/com/android/browser/TitleBar.java | 75 | ||||
-rw-r--r-- | src/com/android/browser/view/CustomScreenLinearLayout.java | 48 |
3 files changed, 115 insertions, 24 deletions
diff --git a/src/com/android/browser/BaseUi.java b/src/com/android/browser/BaseUi.java index bb44336..e3f5986 100644 --- a/src/com/android/browser/BaseUi.java +++ b/src/com/android/browser/BaseUi.java @@ -91,6 +91,7 @@ public abstract class BaseUi implements UI { protected FrameLayout mContentView; protected FrameLayout mCustomViewContainer; protected FrameLayout mFullscreenContainer; + private FrameLayout mFixedTitlebarContainer; private View mCustomView; private WebChromeClient.CustomViewCallback mCustomViewCallback; @@ -126,6 +127,8 @@ public abstract class BaseUi implements UI { .getDecorView().findViewById(android.R.id.content); LayoutInflater.from(mActivity) .inflate(R.layout.custom_screen, frameLayout); + mFixedTitlebarContainer = (FrameLayout) frameLayout.findViewById( + R.id.fixed_titlebar_container); mContentView = (FrameLayout) frameLayout.findViewById( R.id.main_content); mCustomViewContainer = (FrameLayout) frameLayout.findViewById( @@ -844,4 +847,17 @@ public abstract class BaseUi implements UI { } } + + public void addFixedTitleBar(View view) { + mFixedTitlebarContainer.addView(view); + } + + public void setContentViewMarginTop(int margin) { + LinearLayout.LayoutParams params = + (LinearLayout.LayoutParams) mContentView.getLayoutParams(); + if (params.topMargin != margin) { + params.topMargin = margin; + mContentView.setLayoutParams(params); + } + } } diff --git a/src/com/android/browser/TitleBar.java b/src/com/android/browser/TitleBar.java index 479b62e..9b2a947 100644 --- a/src/com/android/browser/TitleBar.java +++ b/src/com/android/browser/TitleBar.java @@ -45,7 +45,7 @@ public class TitleBar extends RelativeLayout { private UiController mUiController; private BaseUi mBaseUi; - private FrameLayout mParent; + private FrameLayout mContentView; private PageProgressView mProgress; private AutologinBar mAutoLogin; @@ -58,15 +58,16 @@ public class TitleBar extends RelativeLayout { private boolean mInLoad; private boolean mSkipTitleBarAnimations; private Animator mTitleBarAnimator; + private boolean mIsFixedTitleBar; public TitleBar(Context context, UiController controller, BaseUi ui, - FrameLayout parent) { + FrameLayout contentView) { super(context, null); mUiController = controller; mBaseUi = ui; - mParent = parent; + mContentView = contentView; initLayout(context); - mParent.addView(this, makeLayoutParams()); + setFixedTitleBar(!mContext.getResources().getBoolean(R.bool.hide_title)); } private void initLayout(Context context) { @@ -100,10 +101,34 @@ public class TitleBar extends RelativeLayout { @Override protected void onConfigurationChanged(Configuration config) { super.onConfigurationChanged(config); - if (config.orientation == Configuration.ORIENTATION_PORTRAIT) { - if (!mContext.getResources().getBoolean(R.bool.hide_title)) { - show(); - } + setFixedTitleBar(!mContext.getResources().getBoolean(R.bool.hide_title)); + } + + @Override + protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { + super.onMeasure(widthMeasureSpec, heightMeasureSpec); + if (mIsFixedTitleBar) { + int margin = getMeasuredHeight() - calculateEmbeddedHeight(); + mBaseUi.setContentViewMarginTop(-margin); + } + } + + private void setFixedTitleBar(boolean isFixed) { + // If getParent() returns null, we are initializing + ViewGroup parent = (ViewGroup)getParent(); + if (mIsFixedTitleBar == isFixed && parent != null) return; + mIsFixedTitleBar = isFixed; + setSkipTitleBarAnimations(true); + show(); + setSkipTitleBarAnimations(false); + if (parent != null) { + parent.removeView(this); + } + if (mIsFixedTitleBar) { + mBaseUi.addFixedTitleBar(this); + } else { + mContentView.addView(this, makeLayoutParams()); + mBaseUi.setContentViewMarginTop(0); } } @@ -145,23 +170,21 @@ public class TitleBar extends RelativeLayout { } void show() { - if (mUseQuickControls) { + cancelTitleBarAnimation(false); + if (mUseQuickControls || mSkipTitleBarAnimations) { this.setVisibility(View.VISIBLE); this.setTranslationY(0); } else { - if (!mSkipTitleBarAnimations) { - cancelTitleBarAnimation(false); - int visibleHeight = getVisibleTitleHeight(); - float startPos = (-getEmbeddedHeight() + visibleHeight); - if (getTranslationY() != 0) { - startPos = Math.max(startPos, getTranslationY()); - } - mTitleBarAnimator = ObjectAnimator.ofFloat(this, - "translationY", - startPos, 0); - setupTitleBarAnimator(mTitleBarAnimator); - mTitleBarAnimator.start(); + int visibleHeight = getVisibleTitleHeight(); + float startPos = (-getEmbeddedHeight() + visibleHeight); + if (getTranslationY() != 0) { + startPos = Math.max(startPos, getTranslationY()); } + mTitleBarAnimator = ObjectAnimator.ofFloat(this, + "translationY", + startPos, 0); + setupTitleBarAnimator(mTitleBarAnimator); + mTitleBarAnimator.start(); } mShowing = true; } @@ -170,7 +193,7 @@ public class TitleBar extends RelativeLayout { if (mUseQuickControls) { this.setVisibility(View.GONE); } else { - if (!mContext.getResources().getBoolean(R.bool.hide_title)) return; + if (mIsFixedTitleBar) return; if (!mSkipTitleBarAnimations) { cancelTitleBarAnimation(false); int visibleHeight = getVisibleTitleHeight(); @@ -263,7 +286,11 @@ public class TitleBar extends RelativeLayout { } public int getEmbeddedHeight() { - if (mUseQuickControls) return 0; + if (mUseQuickControls || mIsFixedTitleBar) return 0; + return calculateEmbeddedHeight(); + } + + private int calculateEmbeddedHeight() { int height = mNavBar.getHeight(); if (mAutoLogin != null && mAutoLogin.getVisibility() == View.VISIBLE) { height += mAutoLogin.getHeight(); @@ -397,7 +424,7 @@ public class TitleBar extends RelativeLayout { } public void onScrollChanged() { - if (!mShowing) { + if (!mShowing && !mIsFixedTitleBar) { setTranslationY(getVisibleTitleHeight() - getEmbeddedHeight()); } } diff --git a/src/com/android/browser/view/CustomScreenLinearLayout.java b/src/com/android/browser/view/CustomScreenLinearLayout.java new file mode 100644 index 0000000..f5341e8 --- /dev/null +++ b/src/com/android/browser/view/CustomScreenLinearLayout.java @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +package com.android.browser.view; + +import android.content.Context; +import android.util.AttributeSet; +import android.widget.LinearLayout; + + +public class CustomScreenLinearLayout extends LinearLayout { + + public CustomScreenLinearLayout(Context context) { + super(context); + setChildrenDrawingOrderEnabled(true); + } + + public CustomScreenLinearLayout(Context context, AttributeSet attrs) { + super(context, attrs); + setChildrenDrawingOrderEnabled(true); + } + + public CustomScreenLinearLayout(Context context, AttributeSet attrs, + int defStyle) { + super(context, attrs, defStyle); + setChildrenDrawingOrderEnabled(true); + } + + @Override + protected int getChildDrawingOrder(int childCount, int i) { + return childCount - i - 1; + } + +} |