diff options
author | Michael Kolb <kolby@google.com> | 2011-03-02 15:38:01 -0800 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2011-03-02 15:38:01 -0800 |
commit | ab8f269f8158b887735b2feceb392df65b035e27 (patch) | |
tree | df11f5a266581a5df2a5dab46eebb20fc9b21301 | |
parent | 386442409f4e2336d388d4d090c5f3fcb79db7e2 (diff) | |
parent | 377ea31324391e7878f6f5b7a991c74988c18403 (diff) | |
download | packages_apps_Browser-ab8f269f8158b887735b2feceb392df65b035e27.zip packages_apps_Browser-ab8f269f8158b887735b2feceb392df65b035e27.tar.gz packages_apps_Browser-ab8f269f8158b887735b2feceb392df65b035e27.tar.bz2 |
Merge "add tab switch animations"
-rw-r--r-- | res/values/integers.xml | 2 | ||||
-rw-r--r-- | src/com/android/browser/BaseUi.java | 16 | ||||
-rw-r--r-- | src/com/android/browser/ScrollWebView.java | 71 | ||||
-rw-r--r-- | src/com/android/browser/XLargeUi.java | 62 |
4 files changed, 123 insertions, 28 deletions
diff --git a/res/values/integers.xml b/res/values/integers.xml index a899a14..ad0ed90 100644 --- a/res/values/integers.xml +++ b/res/values/integers.xml @@ -25,4 +25,6 @@ <integer name="most_visits_limit">10</integer> <!-- Animation durations --> <integer name="comboViewFadeInDuration">400</integer> + <!-- fade between tabs duration --> + <integer name="tabFadeDuration">300</integer> </resources> diff --git a/src/com/android/browser/BaseUi.java b/src/com/android/browser/BaseUi.java index bca999d..93b0ec8 100644 --- a/src/com/android/browser/BaseUi.java +++ b/src/com/android/browser/BaseUi.java @@ -18,6 +18,8 @@ package com.android.browser; import com.android.browser.Tab.LockIcon; +import android.animation.Animator; +import android.animation.Animator.AnimatorListener; import android.animation.ObjectAnimator; import android.app.Activity; import android.content.res.Configuration; @@ -67,7 +69,7 @@ public abstract class BaseUi implements UI, WebViewFactory { Activity mActivity; UiController mUiController; TabControl mTabControl; - private Tab mActiveTab; + protected Tab mActiveTab; private InputMethodManager mInputManager; private Drawable mSecLockIcon; @@ -220,12 +222,18 @@ public abstract class BaseUi implements UI, WebViewFactory { } @Override - public void setActiveTab(Tab tab) { + public void setActiveTab(final Tab tab) { + setActiveTab(tab, true); + } + + void setActiveTab(Tab tab, boolean needsAttaching) { if ((tab != mActiveTab) && (mActiveTab != null)) { removeTabFromContentView(mActiveTab); } mActiveTab = tab; - attachTabToContentView(tab); + if (needsAttaching) { + attachTabToContentView(tab); + } setShouldShowErrorConsole(tab, mUiController.shouldShowErrorConsole()); onTabDataChanged(tab); onProgressChanged(tab); @@ -259,7 +267,7 @@ public abstract class BaseUi implements UI, WebViewFactory { attachTabToContentView(tab); } - private void attachTabToContentView(Tab tab) { + protected void attachTabToContentView(Tab tab) { if ((tab == null) || (tab.getWebView() == null)) { return; } diff --git a/src/com/android/browser/ScrollWebView.java b/src/com/android/browser/ScrollWebView.java index 2bf07e1..d1dc25b 100644 --- a/src/com/android/browser/ScrollWebView.java +++ b/src/com/android/browser/ScrollWebView.java @@ -1,22 +1,24 @@ /* * Copyright (C) 2010 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 + * 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 + * 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. + * 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; import android.content.Context; +import android.graphics.Bitmap; +import android.graphics.Paint; import android.util.AttributeSet; import android.view.MotionEvent; import android.view.View; @@ -25,7 +27,7 @@ import android.webkit.WebView; import java.util.Map; /** - * Manage WebView scroll events + * Manage WebView scroll events */ public class ScrollWebView extends WebView implements Runnable { @@ -34,6 +36,9 @@ public class ScrollWebView extends WebView implements Runnable { private boolean mBackgroundRemoved = false; private boolean mUserInitiated = false; private TitleBarBase mTitleBar; + private boolean mDrawCached = false; + private Bitmap mBitmap; + private Paint mCachePaint = new Paint(); /** * @param context @@ -51,8 +56,8 @@ public class ScrollWebView extends WebView implements Runnable { * @param attrs * @param defStyle */ - public ScrollWebView(Context context, AttributeSet attrs, int defStyle, - boolean privateBrowsing) { + public ScrollWebView( + Context context, AttributeSet attrs, int defStyle, boolean privateBrowsing) { super(context, attrs, defStyle, privateBrowsing); } @@ -97,6 +102,10 @@ public class ScrollWebView extends WebView implements Runnable { } } + public boolean hasTitleBar() { + return (mTitleBar != null); + } + @Override public boolean onTouchEvent(MotionEvent evt) { if (MotionEvent.ACTION_DOWN == evt.getActionMasked()) { @@ -128,22 +137,46 @@ public class ScrollWebView extends WebView implements Runnable { mScrollListener = l; } + @Override + public void invalidate() { + if (!mDrawCached) { + super.invalidate(); + } + } + // callback for scroll events interface ScrollListener { public void onScroll(int visibleTitleHeight, boolean userInitiated); } + void setDrawCached(boolean cached) { + if (cached) { + buildDrawingCache(); + mBitmap = getDrawingCache(false); + mDrawCached = (mBitmap != null); + } else { + mBitmap = null; + destroyDrawingCache(); + mDrawCached = false; + } + } + @Override protected void onDraw(android.graphics.Canvas c) { - super.onDraw(c); - if (!mBackgroundRemoved && getRootView().getBackground() != null) { - mBackgroundRemoved = true; - post(new Runnable() { - public void run() { - getRootView().setBackgroundDrawable(null); - } - }); + if (mDrawCached) { + c.drawBitmap(mBitmap, getScrollX(), getScrollY(), mCachePaint); + } else { + super.onDraw(c); + if (!mBackgroundRemoved && getRootView().getBackground() != null) { + mBackgroundRemoved = true; + post(new Runnable() { + public void run() { + getRootView().setBackgroundDrawable(null); + } + }); + } } } + } diff --git a/src/com/android/browser/XLargeUi.java b/src/com/android/browser/XLargeUi.java index f914183..8c7756b 100644 --- a/src/com/android/browser/XLargeUi.java +++ b/src/com/android/browser/XLargeUi.java @@ -18,6 +18,9 @@ package com.android.browser; import com.android.browser.ScrollWebView.ScrollListener; +import android.animation.Animator; +import android.animation.Animator.AnimatorListener; +import android.animation.ObjectAnimator; import android.app.ActionBar; import android.app.Activity; import android.content.pm.PackageManager; @@ -204,11 +207,57 @@ public class XLargeUi extends BaseUi implements ScrollListener { } @Override - public void setActiveTab(Tab tab) { - if (mTitleBar.isEditingUrl()) { - mTitleBar.stopEditingUrl(); + public void setActiveTab(final Tab tab) { + if ((tab != mActiveTab) && (mActiveTab != null)) { + // animate between the two + final ScrollWebView fromWV = (ScrollWebView) mActiveTab.getWebView(); + fromWV.setDrawCached(true); + fromWV.setEmbeddedTitleBar(null); + final ScrollWebView toWV = (ScrollWebView) tab.getWebView(); + if (!mUseQuickControls) { + if (mTitleBar.getParent() == null) { + toWV.setEmbeddedTitleBar(mTitleBar); + } + } + toWV.setDrawCached(true); + attachTabToContentView(tab); + super.setActiveTab(tab, false); + ObjectAnimator transition = ObjectAnimator.ofFloat( + toWV, "alpha", 0f, 1f); + transition.setDuration(mActivity.getResources() + .getInteger(R.integer.tabFadeDuration)); + transition.addListener(new AnimatorListener() { + @Override + public void onAnimationCancel(Animator animation) { + fromWV.setDrawCached(false); + toWV.setDrawCached(false); + setActiveTab(tab, false); + } + + @Override + public void onAnimationEnd(Animator animation) { + fromWV.setDrawCached(false); + toWV.setDrawCached(false); + setActiveTab(tab, false); + } + + @Override + public void onAnimationRepeat(Animator animation) { + } + + @Override + public void onAnimationStart(Animator animation) { + } + }); + transition.start(); + } else { + super.setActiveTab(tab, true); + setActiveTab(tab, true); } - super.setActiveTab(tab); + } + + @Override + void setActiveTab(Tab tab, boolean needsAttaching) { ScrollWebView view = (ScrollWebView) tab.getWebView(); // TabControl.setCurrentTab has been called before this, // so the tab is guaranteed to have a webview @@ -222,7 +271,10 @@ public class XLargeUi extends BaseUi implements ScrollListener { view.setScrollListener(null); mTabBar.showTitleBarIndicator(false); } else { - view.setEmbeddedTitleBar(mTitleBar); + // check if title bar is already attached by animation + if (mTitleBar.getParent() == null) { + view.setEmbeddedTitleBar(mTitleBar); + } view.setScrollListener(this); } mTabBar.onSetActiveTab(tab); |