diff options
Diffstat (limited to 'src/com/android')
-rw-r--r-- | src/com/android/browser/BaseUi.java | 47 | ||||
-rw-r--r-- | src/com/android/browser/Controller.java | 6 | ||||
-rw-r--r-- | src/com/android/browser/PhoneUi.java | 48 | ||||
-rw-r--r-- | src/com/android/browser/PieControl.java | 4 | ||||
-rw-r--r-- | src/com/android/browser/TabBar.java | 2 | ||||
-rw-r--r-- | src/com/android/browser/TitleBarBase.java | 255 | ||||
-rw-r--r-- | src/com/android/browser/TitleBarPhone.java | 101 | ||||
-rw-r--r-- | src/com/android/browser/TitleBarXLarge.java | 129 | ||||
-rw-r--r-- | src/com/android/browser/UiController.java | 2 | ||||
-rw-r--r-- | src/com/android/browser/XLargeUi.java | 143 |
10 files changed, 295 insertions, 442 deletions
diff --git a/src/com/android/browser/BaseUi.java b/src/com/android/browser/BaseUi.java index 2a03893..5daf17a 100644 --- a/src/com/android/browser/BaseUi.java +++ b/src/com/android/browser/BaseUi.java @@ -87,8 +87,6 @@ public abstract class BaseUi implements UI, WebViewFactory { private Toast mStopToast; - private boolean mTitleShowing; - // the default <video> poster private Bitmap mDefaultVideoPoster; // the video progress view @@ -117,7 +115,6 @@ public abstract class BaseUi implements UI, WebViewFactory { mCustomViewContainer = (FrameLayout) mBrowserFrameLayout .findViewById(R.id.fullscreen_custom_content); frameLayout.addView(mBrowserFrameLayout, COVER_SCREEN_PARAMS); - mTitleShowing = false; } @Override @@ -183,8 +180,6 @@ public abstract class BaseUi implements UI, WebViewFactory { public void onConfigurationChanged(Configuration config) { } - public abstract void editUrl(boolean clearInput); - // key handling @Override @@ -413,39 +408,50 @@ public abstract class BaseUi implements UI, WebViewFactory { } protected void refreshWebView() { - Tab tab = getActiveTab(); - if ((tab != null) && (tab.getWebView() != null)) { - tab.getWebView().invalidate(); + WebView web = getWebView(); + if (web != null) { + web.invalidate(); + } + } + + public void editUrl(boolean clearInput) { + if (mUiController.isInCustomActionMode()) { + mUiController.endActionMode(); } + showTitleBar(); + getTitleBar().startEditingUrl(clearInput); } boolean canShowTitleBar() { return !isTitleBarShowing() && !isActivityPaused() && (getActiveTab() != null) - && (getActiveTab().getWebView() != null) + && (getWebView() != null) && !mUiController.isInCustomActionMode(); } void showTitleBar() { - mTitleShowing = true; + if (canShowTitleBar()) { + getTitleBar().show(); + } } protected void hideTitleBar() { - mTitleShowing = false; + if (getTitleBar().isShowing()) { + getTitleBar().hide(); + } } protected boolean isTitleBarShowing() { - return mTitleShowing; + return getTitleBar().isShowing(); } protected abstract TitleBarBase getTitleBar(); protected void setTitleGravity(int gravity) { - getTitleBar().setTitleGravity(gravity); - Tab tab = getActiveTab(); - if ((tab != null) && (tab.getWebView() != null)) { - tab.getWebView().setTitleBarGravity(gravity); + WebView web = getWebView(); + if (web != null) { + web.setTitleBarGravity(gravity); } } @@ -759,9 +765,12 @@ public abstract class BaseUi implements UI, WebViewFactory { tab.setScreenshot(sshot); } - void showTitleBarAndEdit() { - showTitleBar(); - getTitleBar().startEditingUrl(false); + protected WebView getWebView() { + if (mActiveTab != null) { + return mActiveTab.getWebView(); + } else { + return null; + } } } diff --git a/src/com/android/browser/Controller.java b/src/com/android/browser/Controller.java index 47b817c..e8e13d1 100644 --- a/src/com/android/browser/Controller.java +++ b/src/com/android/browser/Controller.java @@ -2420,12 +2420,6 @@ public class Controller startSearch(result, false, bundle, false); } - @Override - public void startSearch(String url) { - startSearch(mSettings.getHomePage().equals(url) ? null : url, true, - null, false); - } - private void startSearch(String initialQuery, boolean selectInitialQuery, Bundle appSearchData, boolean globalSearch) { if (appSearchData == null) { diff --git a/src/com/android/browser/PhoneUi.java b/src/com/android/browser/PhoneUi.java index 42e2aff..eb7ddc5 100644 --- a/src/com/android/browser/PhoneUi.java +++ b/src/com/android/browser/PhoneUi.java @@ -19,7 +19,6 @@ package com.android.browser; import android.app.Activity; import android.content.Context; import android.graphics.PixelFormat; -import android.os.Handler; import android.util.Log; import android.view.ActionMode; import android.view.Gravity; @@ -53,7 +52,8 @@ public class PhoneUi extends BaseUi { */ public PhoneUi(Activity browser, UiController controller) { super(browser, controller); - mTitleBar = new TitleBarPhone(mActivity, mUiController, this); + mTitleBar = new TitleBarPhone(mActivity, mUiController, this, + mContentView); // mTitleBar will be always be shown in the fully loaded mode on // phone mTitleBar.setProgress(100); @@ -88,8 +88,10 @@ public class PhoneUi extends BaseUi { @Override public void editUrl(boolean clearInput) { - String url = getActiveTab().getUrl(); - mUiController.startSearch(url); + if (mUseQuickControls) { + getTitleBar().setShowProgressOnly(false); + } + super.editUrl(clearInput); } @Override @@ -162,30 +164,6 @@ public class PhoneUi extends BaseUi { } @Override - protected void showTitleBar() { - if (canShowTitleBar()) { - if (mUseQuickControls) { - mContentView.addView(mTitleBar); - } else { - setTitleGravity(Gravity.TOP); - } - super.showTitleBar(); - } - } - - @Override - protected void hideTitleBar() { - if (isTitleBarShowing()) { - if (mUseQuickControls) { - mContentView.removeView(mTitleBar); - } else { - setTitleGravity(Gravity.NO_GRAVITY); - } - super.hideTitleBar(); - } - } - - @Override protected TitleBarBase getTitleBar() { return mTitleBar; } @@ -339,16 +317,16 @@ public class PhoneUi extends BaseUi { if (useQuickControls) { mPieControl = new PieControl(mActivity, mUiController, this); mPieControl.attachToContainer(mContentView); - Tab tab = getActiveTab(); - if ((tab != null) && (tab.getWebView() != null)) { - tab.getWebView().setEmbeddedTitleBar(null); + WebView web = getWebView(); + if (web != null) { + web.setEmbeddedTitleBar(null); } } else { mActivity.getActionBar().show(); if (mPieControl != null) { mPieControl.removeFromContainer(mContentView); } - WebView web = mTabControl.getCurrentWebView(); + WebView web = getWebView(); if (web != null) { web.setEmbeddedTitleBar(mTitleBar); } @@ -379,10 +357,4 @@ public class PhoneUi extends BaseUi { } } - @Override - void showTitleBarAndEdit() { - mTitleBar.setShowProgressOnly(false); - super.showTitleBarAndEdit(); - } - } diff --git a/src/com/android/browser/PieControl.java b/src/com/android/browser/PieControl.java index 846811d..81a6c1f 100644 --- a/src/com/android/browser/PieControl.java +++ b/src/com/android/browser/PieControl.java @@ -205,12 +205,12 @@ public class PieControl implements OnClickListener, PieMenu.PieController { web.reload(); } } else if (mUrl.getView() == v) { - mUi.showTitleBarAndEdit(); + mUi.editUrl(false); } else if (mBookmarks.getView() == v) { mUiController.bookmarksOrHistoryPicker(false); } else if (mNewTab.getView() == v) { mUiController.openTabToHomePage(); - mUi.showTitleBarAndEdit(); + mUi.editUrl(false); } else if (mClose.getView() == v) { mUiController.closeCurrentTab(); } diff --git a/src/com/android/browser/TabBar.java b/src/com/android/browser/TabBar.java index c97fc71..31c0740 100644 --- a/src/com/android/browser/TabBar.java +++ b/src/com/android/browser/TabBar.java @@ -202,7 +202,7 @@ public class TabBar extends LinearLayout mUi.hideTitleBar(); } else { mUi.stopWebViewScrolling(); - mUi.showTitleBarAndEdit(); + mUi.editUrl(false); } } else if (mUi.isTitleBarShowing() && !isLoading()) { mUi.stopEditingUrl(); diff --git a/src/com/android/browser/TitleBarBase.java b/src/com/android/browser/TitleBarBase.java index d34d18d..93610e2 100644 --- a/src/com/android/browser/TitleBarBase.java +++ b/src/com/android/browser/TitleBarBase.java @@ -20,6 +20,9 @@ import com.android.browser.UI.DropdownChangeListener; import com.android.browser.UrlInputView.UrlInputListener; import com.android.browser.autocomplete.SuggestedTextController.TextChangeWatcher; +import android.animation.Animator; +import android.animation.Animator.AnimatorListener; +import android.animation.ObjectAnimator; import android.app.SearchManager; import android.content.Context; import android.content.Intent; @@ -39,6 +42,7 @@ import android.view.LayoutInflater; import android.view.View; import android.view.View.OnClickListener; import android.view.View.OnFocusChangeListener; +import android.view.ViewGroup; import android.view.animation.Animation; import android.view.animation.Animation.AnimationListener; import android.view.animation.AnimationUtils; @@ -46,6 +50,7 @@ import android.webkit.WebView; import android.widget.AbsoluteLayout; import android.widget.ArrayAdapter; import android.widget.Button; +import android.widget.FrameLayout; import android.widget.ImageButton; import android.widget.ImageView; import android.widget.ProgressBar; @@ -71,9 +76,12 @@ public class TitleBarBase extends RelativeLayout protected Drawable mGenericFavicon; protected UiController mUiController; protected BaseUi mBaseUi; - + protected FrameLayout mParent; + protected PageProgressView mProgress; protected UrlInputView mUrlInput; protected boolean mInVoiceMode; + protected View mContainer; + // Auto-login UI protected View mAutoLogin; @@ -86,10 +94,18 @@ public class TitleBarBase extends RelativeLayout protected ArrayAdapter<String> mAccountsAdapter; protected boolean mUseQuickControls; - public TitleBarBase(Context context, UiController controller, BaseUi ui) { + //state + protected boolean mShowing; + protected boolean mInLoad; + protected boolean mSkipTitleBarAnimations; + private Animator mTitleBarAnimator; + + public TitleBarBase(Context context, UiController controller, BaseUi ui, + FrameLayout parent) { super(context, null); mUiController = controller; mBaseUi = ui; + mParent = parent; mGenericFavicon = context.getResources().getDrawable( R.drawable.app_web_browser_sm); } @@ -97,7 +113,8 @@ public class TitleBarBase extends RelativeLayout protected void initLayout(Context context, int layoutId) { LayoutInflater factory = LayoutInflater.from(context); factory.inflate(layoutId, this); - + mContainer = findViewById(R.id.taburlbar); + mProgress = (PageProgressView) findViewById(R.id.progress); mUrlInput = (UrlInputView) findViewById(R.id.url); mLockIcon = (ImageView) findViewById(R.id.lock); mUrlInput.setUrlInputListener(this); @@ -120,9 +137,145 @@ public class TitleBarBase extends RelativeLayout protected void setUseQuickControls(boolean use) { mUseQuickControls = use; + setLayoutParams(makeLayoutParams()); + } + + void setShowProgressOnly(boolean progress) { + if (progress && !inAutoLogin()) { + mContainer.setVisibility(View.GONE); + } else { + mContainer.setVisibility(View.VISIBLE); + } } - /* package */ void setProgress(int newProgress) {} + void setSkipTitleBarAnimations(boolean skip) { + mSkipTitleBarAnimations = skip; + } + + void show() { + if (mUseQuickControls) { + mParent.addView(this); + } 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); + mTitleBarAnimator.start(); + } + mBaseUi.setTitleGravity(Gravity.TOP); + } + mShowing = true; + } + + void hide() { + if (mUseQuickControls) { + mParent.removeView(this); + } else { + if (!mSkipTitleBarAnimations) { + cancelTitleBarAnimation(false); + int visibleHeight = getVisibleTitleHeight(); + mTitleBarAnimator = ObjectAnimator.ofFloat(this, + "translationY", getTranslationY(), + (-getEmbeddedHeight() + visibleHeight)); + mTitleBarAnimator.addListener(mHideTileBarAnimatorListener); + mTitleBarAnimator.start(); + } else { + mBaseUi.setTitleGravity(Gravity.NO_GRAVITY); + } + } + mShowing = false; + } + + boolean isShowing() { + return mShowing; + } + + void cancelTitleBarAnimation(boolean reset) { + if (mTitleBarAnimator != null) { + mTitleBarAnimator.cancel(); + mTitleBarAnimator = null; + } + if (reset) { + setTranslationY(0); + } + } + + private AnimatorListener mHideTileBarAnimatorListener = new AnimatorListener() { + + boolean mWasCanceled; + @Override + public void onAnimationStart(Animator animation) { + mWasCanceled = false; + } + + @Override + public void onAnimationRepeat(Animator animation) { + } + + @Override + public void onAnimationEnd(Animator animation) { + if (!mWasCanceled) { + setTranslationY(0); + } + mBaseUi.setTitleGravity(Gravity.NO_GRAVITY); + } + + @Override + public void onAnimationCancel(Animator animation) { + mWasCanceled = true; + } + }; + + private int getVisibleTitleHeight() { + Tab tab = mBaseUi.getActiveTab(); + WebView webview = tab != null ? tab.getWebView() : null; + return webview != null ? webview.getVisibleTitleHeight() : 0; + } + + /** + * Update the progress, from 0 to 100. + */ + void setProgress(int newProgress) { + if (newProgress >= PROGRESS_MAX) { + mProgress.setProgress(PageProgressView.MAX_PROGRESS); + mProgress.setVisibility(View.GONE); + mInLoad = false; + onProgressStopped(); + // check if needs to be hidden + if (!isEditingUrl() && !inAutoLogin()) { + hide(); + if (mUseQuickControls) { + setShowProgressOnly(false); + } + } + } else { + if (!mInLoad) { + mProgress.setVisibility(View.VISIBLE); + mInLoad = true; + onProgressStarted(); + } + mProgress.setProgress(newProgress * PageProgressView.MAX_PROGRESS + / PROGRESS_MAX); + if (!mShowing) { + if (mUseQuickControls && !isEditingUrl()) { + setShowProgressOnly(true); + } + show(); + } + } + } + + protected void onProgressStarted() { + } + + protected void onProgressStopped() { + } /* package */ void setLock(Drawable d) { assert mLockIcon != null; @@ -151,27 +304,12 @@ public class TitleBarBase extends RelativeLayout mFavicon.setImageDrawable(d); } - void setTitleGravity(int gravity) { - int newTop = 0; - if (gravity != Gravity.NO_GRAVITY) { - View parent = (View) getParent(); - if (parent != null) { - if (gravity == Gravity.TOP) { - newTop = parent.getScrollY(); - } else if (gravity == Gravity.BOTTOM) { - newTop = parent.getScrollY() + parent.getHeight() - getHeight(); - } - } - } - AbsoluteLayout.LayoutParams lp = (AbsoluteLayout.LayoutParams) getLayoutParams(); - if (lp != null) { - lp.y = newTop; - setLayoutParams(lp); - } - } - public int getEmbeddedHeight() { - return getHeight(); + int height = mContainer.getHeight(); + if (mAutoLogin.getVisibility() == View.VISIBLE) { + height += mAutoLogin.getHeight(); + } + return height; } protected void updateAutoLogin(Tab tab, boolean animate) { @@ -212,6 +350,9 @@ public class TitleBarBase extends RelativeLayout } protected void showAutoLogin(boolean animate) { + if (mUseQuickControls) { + mBaseUi.showTitleBar(); + } mAutoLogin.setVisibility(View.VISIBLE); if (animate) { mAutoLogin.startAnimation(AnimationUtils.loadAnimation( @@ -221,21 +362,34 @@ public class TitleBarBase extends RelativeLayout protected void hideAutoLogin(boolean animate) { mAutoLoginHandler = null; - if (animate) { - Animation anim = AnimationUtils.loadAnimation( - getContext(), R.anim.autologin_exit); - anim.setAnimationListener(new AnimationListener() { - @Override public void onAnimationEnd(Animation a) { - mAutoLogin.setVisibility(View.GONE); - mBaseUi.refreshWebView(); - } - @Override public void onAnimationStart(Animation a) {} - @Override public void onAnimationRepeat(Animation a) {} - }); - mAutoLogin.startAnimation(anim); - } else if (mAutoLogin.getAnimation() == null) { + if (mUseQuickControls) { + mBaseUi.hideTitleBar(); mAutoLogin.setVisibility(View.GONE); mBaseUi.refreshWebView(); + } else { + if (animate) { + Animation anim = AnimationUtils.loadAnimation(getContext(), + R.anim.autologin_exit); + anim.setAnimationListener(new AnimationListener() { + @Override + public void onAnimationEnd(Animation a) { + mAutoLogin.setVisibility(View.GONE); + mBaseUi.refreshWebView(); + } + + @Override + public void onAnimationStart(Animation a) { + } + + @Override + public void onAnimationRepeat(Animation a) { + } + }); + mAutoLogin.startAnimation(anim); + } else if (mAutoLogin.getAnimation() == null) { + mAutoLogin.setVisibility(View.GONE); + mBaseUi.refreshWebView(); + } } } @@ -437,6 +591,31 @@ public class TitleBarBase extends RelativeLayout * called from the Ui when the user wants to edit * @param clearInput clear the input field */ - void startEditingUrl(boolean clearInput) {}; + void startEditingUrl(boolean clearInput) { + // editing takes preference of progress + mContainer.setVisibility(View.VISIBLE); + if (mUseQuickControls) { + mProgress.setVisibility(View.GONE); + } + if (!mUrlInput.hasFocus()) { + mUrlInput.requestFocus(); + } + if (clearInput) { + mUrlInput.setText(""); + } else if (mInVoiceMode) { + mUrlInput.showDropDown(); + } + } + + private ViewGroup.LayoutParams makeLayoutParams() { + if (mUseQuickControls) { + return new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT, + LayoutParams.WRAP_CONTENT); + } else { + return new AbsoluteLayout.LayoutParams( + LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT, + 0, 0); + } + } } diff --git a/src/com/android/browser/TitleBarPhone.java b/src/com/android/browser/TitleBarPhone.java index 3edd831..875e4b5 100644 --- a/src/com/android/browser/TitleBarPhone.java +++ b/src/com/android/browser/TitleBarPhone.java @@ -17,7 +17,6 @@ package com.android.browser; import com.android.browser.autocomplete.SuggestedTextController.TextChangeWatcher; -import com.android.browser.view.StopProgressView; import android.app.Activity; import android.content.Context; @@ -26,11 +25,8 @@ import android.view.MenuInflater; import android.view.View; import android.view.View.OnClickListener; import android.view.View.OnFocusChangeListener; -import android.view.ViewGroup; -import android.widget.AbsoluteLayout; import android.widget.FrameLayout; import android.widget.ImageView; -import android.widget.RelativeLayout.LayoutParams; import java.util.List; @@ -43,14 +39,12 @@ public class TitleBarPhone extends TitleBarBase implements OnFocusChangeListener private Activity mActivity; private ImageView mStopButton; - private PageProgressView mProgress; private ImageView mVoiceButton; - private boolean mInLoad; - private View mContainer; private boolean mHasLockIcon; - public TitleBarPhone(Activity activity, UiController controller, PhoneUi ui) { - super(activity, controller, ui); + public TitleBarPhone(Activity activity, UiController controller, PhoneUi ui, + FrameLayout parent) { + super(activity, controller, ui, parent); mActivity = activity; initLayout(activity, R.layout.title_bar); } @@ -58,24 +52,16 @@ public class TitleBarPhone extends TitleBarBase implements OnFocusChangeListener @Override protected void initLayout(Context context, int layoutId) { super.initLayout(context, layoutId); - mContainer = findViewById(R.id.taburlbar); mLockIcon = (ImageView) findViewById(R.id.lock); mFavicon = (ImageView) findViewById(R.id.favicon); mStopButton = (ImageView) findViewById(R.id.stop); mStopButton.setOnClickListener(this); - mProgress = (PageProgressView) findViewById(R.id.progress); mVoiceButton = (ImageView) findViewById(R.id.voice); mVoiceButton.setOnClickListener(this); setFocusState(false); } @Override - public int getEmbeddedHeight() { - int height = mContainer.getHeight(); - return height; - } - - @Override public void createContextMenu(ContextMenu menu) { MenuInflater inflater = mActivity.getMenuInflater(); inflater.inflate(R.menu.title_context, menu); @@ -116,30 +102,14 @@ public class TitleBarPhone extends TitleBarBase implements OnFocusChangeListener } } - /** - * Update the progress, from 0 to 100. - */ @Override - void setProgress(int newProgress) { - boolean blockvisuals = mUseQuickControls && isEditingUrl(); - if (newProgress >= PROGRESS_MAX) { - mInLoad = false; - if (!blockvisuals) { - mProgress.setProgress(PageProgressView.MAX_PROGRESS); - mProgress.setVisibility(View.GONE); - } - setFocusState(mUrlInput.hasFocus()); - } else { - if (!mInLoad) { - mInLoad = true; - if (!blockvisuals) { - mProgress.setVisibility(View.VISIBLE); - } - setFocusState(mUrlInput.hasFocus()); - } - mProgress.setProgress(newProgress * PageProgressView.MAX_PROGRESS - / PROGRESS_MAX); - } + protected void onProgressStarted() { + setFocusState(mUrlInput.hasFocus()); + } + + @Override + protected void onProgressStopped() { + setFocusState(mUrlInput.hasFocus()); } /** @@ -180,55 +150,4 @@ public class TitleBarPhone extends TitleBarBase implements OnFocusChangeListener } } - @Override - void startEditingUrl(boolean clearInput) { - // editing takes preference of progress - mContainer.setVisibility(View.VISIBLE); - if (!mUrlInput.hasFocus()) { - mUrlInput.requestFocus(); - } - if (clearInput) { - mUrlInput.setText(""); - } else if (mInVoiceMode) { - mUrlInput.showDropDown(); - } - } - - @Override - void setTitleGravity(int gravity) { - if (mUseQuickControls) { - FrameLayout.LayoutParams lp = - (FrameLayout.LayoutParams) getLayoutParams(); - lp.gravity = gravity; - setLayoutParams(lp); - } else { - super.setTitleGravity(gravity); - } - } - - @Override - protected void setUseQuickControls(boolean useQuickControls) { - mUseQuickControls = useQuickControls; - setLayoutParams(makeLayoutParams()); - } - - void setShowProgressOnly(boolean progress) { - if (progress && !inAutoLogin()) { - mContainer.setVisibility(View.GONE); - } else { - mContainer.setVisibility(View.VISIBLE); - } - } - - private ViewGroup.LayoutParams makeLayoutParams() { - if (mUseQuickControls) { - return new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT, - LayoutParams.WRAP_CONTENT); - } else { - return new AbsoluteLayout.LayoutParams( - LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT, - 0, 0); - } - } - } diff --git a/src/com/android/browser/TitleBarXLarge.java b/src/com/android/browser/TitleBarXLarge.java index 4254046..567b35a 100644 --- a/src/com/android/browser/TitleBarXLarge.java +++ b/src/com/android/browser/TitleBarXLarge.java @@ -27,9 +27,7 @@ import android.text.TextUtils; import android.view.View; import android.view.View.OnClickListener; import android.view.View.OnFocusChangeListener; -import android.view.ViewGroup; import android.webkit.WebView; -import android.widget.AbsoluteLayout; import android.widget.FrameLayout; import android.widget.ImageButton; import android.widget.ImageView; @@ -54,21 +52,17 @@ public class TitleBarXLarge extends TitleBarBase private ImageView mStar; private ImageView mUrlIcon; private ImageView mSearchButton; - private View mContainer; private View mGoButton; private ImageView mStopButton; private View mAllButton; private View mClearButton; private ImageView mVoiceSearch; - private PageProgressView mProgressView; private Drawable mFocusDrawable; private Drawable mUnfocusDrawable; - private boolean mInLoad; - public TitleBarXLarge(Activity activity, UiController controller, - XLargeUi ui) { - super(activity, controller, ui); + XLargeUi ui, FrameLayout parent) { + super(activity, controller, ui, parent); mUi = ui; Resources resources = activity.getResources(); mStopDrawable = resources.getDrawable(R.drawable.ic_stop_holo_dark); @@ -82,22 +76,8 @@ public class TitleBarXLarge extends TitleBarBase } @Override - void setTitleGravity(int gravity) { - if (mUseQuickControls) { - FrameLayout.LayoutParams lp = - (FrameLayout.LayoutParams) getLayoutParams(); - lp.gravity = gravity; - setLayoutParams(lp); - } else { - super.setTitleGravity(gravity); - } - } - - @Override protected void initLayout(Context context, int layoutId) { super.initLayout(context, layoutId); - - mContainer = findViewById(R.id.taburlbar); mAllButton = findViewById(R.id.all_btn); // TODO: Change enabled states based on whether you can go // back/forward. Probably should be done inside onPageStarted. @@ -111,7 +91,6 @@ public class TitleBarXLarge extends TitleBarBase mGoButton = findViewById(R.id.go); mClearButton = findViewById(R.id.clear); mVoiceSearch = (ImageView) findViewById(R.id.voicesearch); - mProgressView = (PageProgressView) findViewById(R.id.progress); mUrlContainer = findViewById(R.id.urlbar_focused); mBackButton.setOnClickListener(this); mForwardButton.setOnClickListener(this); @@ -138,40 +117,6 @@ public class TitleBarXLarge extends TitleBarBase } } - private ViewGroup.LayoutParams makeLayoutParams() { - if (mUseQuickControls) { - return new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT, - LayoutParams.WRAP_CONTENT); - } else { - return new AbsoluteLayout.LayoutParams( - LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT, - 0, 0); - } - } - - @Override - public int getEmbeddedHeight() { - int height = mContainer.getHeight(); - if (mAutoLogin.getVisibility() == View.VISIBLE) { - height += mAutoLogin.getHeight(); - } - return height; - } - - @Override - protected void setUseQuickControls(boolean useQuickControls) { - mUseQuickControls = useQuickControls; - setLayoutParams(makeLayoutParams()); - } - - void setShowProgressOnly(boolean progress) { - if (progress && !inAutoLogin()) { - mContainer.setVisibility(View.GONE); - } else { - mContainer.setVisibility(View.VISIBLE); - } - } - @Override public void onFocusChange(View view, boolean hasFocus) { // if losing focus and not in touch mode, leave as is @@ -207,46 +152,6 @@ public class TitleBarXLarge extends TitleBarBase mStar.setActivated(isBookmark); } - /** - * called from the Ui when the user wants to edit - * @param clearInput clear the input field - */ - @Override - void startEditingUrl(boolean clearInput) { - // editing takes preference of progress - mContainer.setVisibility(View.VISIBLE); - if (mUseQuickControls) { - mProgressView.setVisibility(View.GONE); - } - if (!mUrlInput.hasFocus()) { - mUrlInput.requestFocus(); - } - if (clearInput) { - mUrlInput.setText(""); - } else if (mInVoiceMode) { - mUrlInput.showDropDown(); - } - } - - @Override - protected void showAutoLogin(boolean animate) { - if (mUseQuickControls) { - mUi.showTitleBar(); - } - super.showAutoLogin(animate); - } - - @Override - protected void hideAutoLogin(boolean animate) { - mAutoLoginHandler = null; - if (mUseQuickControls) { - mUi.hideTitleBar(); - mAutoLogin.setVisibility(View.GONE); - mUi.refreshWebView(); - } else { - super.hideAutoLogin(animate); - } - } @Override public void onClick(View v) { @@ -323,30 +228,14 @@ public class TitleBarXLarge extends TitleBarBase } } - /** - * Update the progress, from 0 to 100. - */ @Override - void setProgress(int newProgress) { - boolean blockvisuals = mUseQuickControls && isEditingUrl(); - if (newProgress >= PROGRESS_MAX) { - if (!blockvisuals) { - mProgressView.setProgress(PageProgressView.MAX_PROGRESS); - mProgressView.setVisibility(View.GONE); - mStopButton.setImageDrawable(mReloadDrawable); - } - mInLoad = false; - } else { - if (!mInLoad) { - if (!blockvisuals) { - mProgressView.setVisibility(View.VISIBLE); - mStopButton.setImageDrawable(mStopDrawable); - } - mInLoad = true; - } - mProgressView.setProgress(newProgress * PageProgressView.MAX_PROGRESS - / PROGRESS_MAX); - } + protected void onProgressStarted() { + mStopButton.setImageDrawable(mStopDrawable); + } + + @Override + protected void onProgressStopped() { + mStopButton.setImageDrawable(mReloadDrawable); } @Override diff --git a/src/com/android/browser/UiController.java b/src/com/android/browser/UiController.java index c22494b..ed5fa6a 100644 --- a/src/com/android/browser/UiController.java +++ b/src/com/android/browser/UiController.java @@ -56,8 +56,6 @@ public interface UiController extends BookmarksHistoryCallbacks { void bookmarksOrHistoryPicker(boolean openHistory); - void startSearch(String url); - void startVoiceSearch(); boolean supportsVoiceSearch(); diff --git a/src/com/android/browser/XLargeUi.java b/src/com/android/browser/XLargeUi.java index e19515e..4b06d28 100644 --- a/src/com/android/browser/XLargeUi.java +++ b/src/com/android/browser/XLargeUi.java @@ -18,9 +18,6 @@ package com.android.browser; import com.android.browser.BrowserWebView.ScrollListener; -import android.animation.Animator; -import android.animation.Animator.AnimatorListener; -import android.animation.ObjectAnimator; import android.app.ActionBar; import android.app.Activity; import android.os.Bundle; @@ -33,7 +30,6 @@ import android.view.Menu; import android.view.View; import android.webkit.WebChromeClient.CustomViewCallback; import android.webkit.WebView; -import android.widget.FrameLayout; import java.util.List; @@ -48,8 +44,6 @@ public class XLargeUi extends BaseUi implements ScrollListener { private TabBar mTabBar; private TitleBarXLarge mTitleBar; - private Animator mTitleBarAnimator; - private boolean mSkipTitleBarAnimations; private boolean mUseQuickControls; private PieControl mPieControl; @@ -62,7 +56,8 @@ public class XLargeUi extends BaseUi implements ScrollListener { public XLargeUi(Activity browser, UiController controller) { super(browser, controller); mHandler = new Handler(); - mTitleBar = new TitleBarXLarge(mActivity, mUiController, this); + mTitleBar = new TitleBarXLarge(mActivity, mUiController, this, + mContentView); mTitleBar.setProgress(100); mTabBar = new TabBar(mActivity, mUiController, this); mActionBar = mActivity.getActionBar(); @@ -101,16 +96,16 @@ public class XLargeUi extends BaseUi implements ScrollListener { checkTabCount(); mPieControl = new PieControl(mActivity, mUiController, this); mPieControl.attachToContainer(mContentView); - Tab tab = getActiveTab(); - if ((tab != null) && (tab.getWebView() != null)) { - tab.getWebView().setEmbeddedTitleBar(null); + WebView web = getWebView(); + if (web != null) { + web.setEmbeddedTitleBar(null); } } else { mActivity.getActionBar().show(); if (mPieControl != null) { mPieControl.removeFromContainer(mContentView); } - WebView web = mTabControl.getCurrentWebView(); + WebView web = getWebView(); if (web != null) { web.setEmbeddedTitleBar(mTitleBar); } @@ -177,22 +172,6 @@ public class XLargeUi extends BaseUi implements ScrollListener { mTabBar.onProgress(tab, progress); if (tab.inForeground()) { mTitleBar.setProgress(progress); - if (progress == 100) { - if (!mTitleBar.isEditingUrl() && !mTitleBar.inAutoLogin()) { - hideTitleBar(); - if (mUseQuickControls) { - mTitleBar.setShowProgressOnly(false); - } - } - } else { - if (!isTitleBarShowing()) { - if (mUseQuickControls && !mTitleBar.isEditingUrl()) { - mTitleBar.setShowProgressOnly(true); - setTitleGravity(Gravity.TOP); - } - showTitleBar(); - } - } } } @@ -212,8 +191,8 @@ public class XLargeUi extends BaseUi implements ScrollListener { @Override public void setActiveTab(final Tab tab) { - cancelTitleBarAnimation(true); - mSkipTitleBarAnimations = true; + mTitleBar.cancelTitleBarAnimation(true); + mTitleBar.setSkipTitleBarAnimations(true); if (mUseQuickControls) { if (mActiveTab != null) { captureTab(mActiveTab); @@ -221,7 +200,7 @@ public class XLargeUi extends BaseUi implements ScrollListener { } super.setActiveTab(tab, true); setActiveTab(tab, true); - mSkipTitleBarAnimations = false; + mTitleBar.setSkipTitleBarAnimations(false); } @Override @@ -255,7 +234,6 @@ public class XLargeUi extends BaseUi implements ScrollListener { tab.getTopWindow().requestFocus(); } - @Override public void updateTabs(List<Tab> tabs) { mTabBar.updateTabs(tabs); @@ -264,11 +242,11 @@ public class XLargeUi extends BaseUi implements ScrollListener { @Override public void removeTab(Tab tab) { - cancelTitleBarAnimation(true); - mSkipTitleBarAnimations = true; + mTitleBar.cancelTitleBarAnimation(true); + mTitleBar.setSkipTitleBarAnimations(true); super.removeTab(tab); mTabBar.onRemoveTab(tab); - mSkipTitleBarAnimations = false; + mTitleBar.setSkipTitleBarAnimations(false); } protected void onRemoveTabCompleted(Tab tab) { @@ -284,17 +262,10 @@ public class XLargeUi extends BaseUi implements ScrollListener { @Override public void editUrl(boolean clearInput) { - if (mUiController.isInCustomActionMode()) { - mUiController.endActionMode(); + if (mUseQuickControls) { + getTitleBar().setShowProgressOnly(false); } - showTitleBar(); - mTitleBar.startEditingUrl(clearInput); - } - - @Override - void showTitleBarAndEdit() { - mTitleBar.setShowProgressOnly(false); - super.showTitleBarAndEdit(); + super.editUrl(clearInput); } void stopEditingUrl() { @@ -304,24 +275,7 @@ public class XLargeUi extends BaseUi implements ScrollListener { @Override protected void showTitleBar() { if (canShowTitleBar()) { - if (mUseQuickControls) { - mContentView.addView(mTitleBar); - } else { - if (!mSkipTitleBarAnimations) { - cancelTitleBarAnimation(false); - int visibleHeight = getVisibleTitleHeight(); - float startPos = (-mTitleBar.getEmbeddedHeight() + visibleHeight); - if (mTitleBar.getTranslationY() != 0) { - startPos = Math.max(startPos, mTitleBar.getTranslationY()); - } - mTitleBarAnimator = ObjectAnimator.ofFloat(mTitleBar, - "translationY", - startPos, 0); - mTitleBarAnimator.start(); - } - setTitleGravity(Gravity.TOP); - } - super.showTitleBar(); + mTitleBar.show(); mTabBar.onShowTitleBar(); } } @@ -330,66 +284,10 @@ public class XLargeUi extends BaseUi implements ScrollListener { protected void hideTitleBar() { if (isTitleBarShowing()) { mTabBar.onHideTitleBar(); - if (mUseQuickControls) { - mContentView.removeView(mTitleBar); - } else { - if (!mSkipTitleBarAnimations) { - cancelTitleBarAnimation(false); - int visibleHeight = getVisibleTitleHeight(); - mTitleBarAnimator = ObjectAnimator.ofFloat(mTitleBar, - "translationY", mTitleBar.getTranslationY(), - (-mTitleBar.getEmbeddedHeight() + visibleHeight)); - mTitleBarAnimator.addListener(mHideTileBarAnimatorListener); - mTitleBarAnimator.start(); - } else { - setTitleGravity(Gravity.NO_GRAVITY); - } - } - super.hideTitleBar(); - } - } - - private void cancelTitleBarAnimation(boolean reset) { - if (mTitleBarAnimator != null) { - mTitleBarAnimator.cancel(); - mTitleBarAnimator = null; - } - if (reset) { - mTitleBar.setTranslationY(0); + mTitleBar.hide(); } } - private int getVisibleTitleHeight() { - WebView webview = mActiveTab != null ? mActiveTab.getWebView() : null; - return webview != null ? webview.getVisibleTitleHeight() : 0; - } - - private AnimatorListener mHideTileBarAnimatorListener = new AnimatorListener() { - - boolean mWasCanceled; - @Override - public void onAnimationStart(Animator animation) { - mWasCanceled = false; - } - - @Override - public void onAnimationRepeat(Animator animation) { - } - - @Override - public void onAnimationEnd(Animator animation) { - if (!mWasCanceled) { - mTitleBar.setTranslationY(0); - } - setTitleGravity(Gravity.NO_GRAVITY); - } - - @Override - public void onAnimationCancel(Animator animation) { - mWasCanceled = true; - } - }; - public boolean isEditingUrl() { return mTitleBar.isEditingUrl(); } @@ -401,12 +299,7 @@ public class XLargeUi extends BaseUi implements ScrollListener { @Override protected void setTitleGravity(int gravity) { - if (mUseQuickControls) { - FrameLayout.LayoutParams lp = - (FrameLayout.LayoutParams) mTitleBar.getLayoutParams(); - lp.gravity = gravity; - mTitleBar.setLayoutParams(lp); - } else { + if (!mUseQuickControls) { super.setTitleGravity(gravity); } } |