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/android/browser/TitleBar.java | |
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/android/browser/TitleBar.java')
-rw-r--r-- | src/com/android/browser/TitleBar.java | 75 |
1 files changed, 51 insertions, 24 deletions
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()); } } |