From 0cd3b64e607cc1f81ed49b00ef7398c2a2b7a48d Mon Sep 17 00:00:00 2001 From: Adam Cohen Date: Fri, 14 Oct 2011 14:58:00 -0700 Subject: Add ability to swipe from apps to widgets in AllAppsCustomize (issue 5453016) Change-Id: I4d725cf1ee11d67f5149dbd0edbcb2e0af3b80ee --- .../android/launcher2/AppsCustomizeTabHost.java | 114 +++++++++++---------- 1 file changed, 62 insertions(+), 52 deletions(-) (limited to 'src/com/android/launcher2/AppsCustomizeTabHost.java') diff --git a/src/com/android/launcher2/AppsCustomizeTabHost.java b/src/com/android/launcher2/AppsCustomizeTabHost.java index 8b7b95612..25f67cb48 100644 --- a/src/com/android/launcher2/AppsCustomizeTabHost.java +++ b/src/com/android/launcher2/AppsCustomizeTabHost.java @@ -48,6 +48,7 @@ public class AppsCustomizeTabHost extends TabHost implements LauncherTransitiona private ViewGroup mTabs; private ViewGroup mTabsContainer; private AppsCustomizePagedView mAppsCustomizePane; + private boolean mSuppressContentCallback = false; private ImageView mAnimationBuffer; private boolean mInTransition; @@ -162,6 +163,7 @@ public class AppsCustomizeTabHost extends TabHost implements LauncherTransitiona private void onTabChangedStart() { mAppsCustomizePane.hideScrollingIndicator(false); } + private void onTabChangedEnd(AppsCustomizePagedView.ContentType type) { mAppsCustomizePane.setContentType(type); } @@ -169,59 +171,67 @@ public class AppsCustomizeTabHost extends TabHost implements LauncherTransitiona @Override public void onTabChanged(String tabId) { final AppsCustomizePagedView.ContentType type = getContentTypeForTabTag(tabId); - if (!mAppsCustomizePane.isContentType(type)) { - // Animate the changing of the tab content by fading pages in and out - final Resources res = getResources(); - final int duration = res.getInteger(R.integer.config_tabTransitionDuration); - - // We post a runnable here because there is a delay while the first page is loading and - // the feedback from having changed the tab almost feels better than having it stick - post(new Runnable() { - @Override - public void run() { - // Setup the animation buffer - Bitmap b = Bitmap.createBitmap(mAppsCustomizePane.getMeasuredWidth(), - mAppsCustomizePane.getMeasuredHeight(), Bitmap.Config.ARGB_8888); - Canvas c = new Canvas(b); - mAppsCustomizePane.draw(c); - mAppsCustomizePane.setAlpha(0f); - mAnimationBuffer.setImageBitmap(b); - mAnimationBuffer.setAlpha(1f); - mAnimationBuffer.setVisibility(View.VISIBLE); - c.setBitmap(null); - b = null; - - // Toggle the new content - onTabChangedStart(); - onTabChangedEnd(type); - - // Animate the transition - ObjectAnimator outAnim = ObjectAnimator.ofFloat(mAnimationBuffer, "alpha", 0f); - outAnim.addListener(new AnimatorListenerAdapter() { - @Override - public void onAnimationEnd(Animator animation) { - mAnimationBuffer.setVisibility(View.GONE); - mAnimationBuffer.setImageBitmap(null); - } - }); - ObjectAnimator inAnim = ObjectAnimator.ofFloat(mAppsCustomizePane, "alpha", 1f); - inAnim.addListener(new AnimatorListenerAdapter() { - @Override - public void onAnimationEnd(Animator animation) { - if (!LauncherApplication.isScreenLarge()) { - mAppsCustomizePane.flashScrollingIndicator(); - } - mAppsCustomizePane.loadAssociatedPages( - mAppsCustomizePane.getCurrentPage()); - } - }); - AnimatorSet animSet = new AnimatorSet(); - animSet.playTogether(outAnim, inAnim); - animSet.setDuration(duration); - animSet.start(); - } - }); + if (mSuppressContentCallback) { + mSuppressContentCallback = false; + return; } + + // Animate the changing of the tab content by fading pages in and out + final Resources res = getResources(); + final int duration = res.getInteger(R.integer.config_tabTransitionDuration); + + // We post a runnable here because there is a delay while the first page is loading and + // the feedback from having changed the tab almost feels better than having it stick + post(new Runnable() { + @Override + public void run() { + // Setup the animation buffer + Bitmap b = Bitmap.createBitmap(mAppsCustomizePane.getMeasuredWidth(), + mAppsCustomizePane.getMeasuredHeight(), Bitmap.Config.ARGB_8888); + Canvas c = new Canvas(b); + mAppsCustomizePane.draw(c); + mAppsCustomizePane.setAlpha(0f); + mAnimationBuffer.setImageBitmap(b); + mAnimationBuffer.setAlpha(1f); + mAnimationBuffer.setVisibility(View.VISIBLE); + c.setBitmap(null); + b = null; + + // Toggle the new content + onTabChangedStart(); + onTabChangedEnd(type); + + // Animate the transition + ObjectAnimator outAnim = ObjectAnimator.ofFloat(mAnimationBuffer, "alpha", 0f); + outAnim.addListener(new AnimatorListenerAdapter() { + @Override + public void onAnimationEnd(Animator animation) { + mAnimationBuffer.setVisibility(View.GONE); + mAnimationBuffer.setImageBitmap(null); + } + }); + ObjectAnimator inAnim = ObjectAnimator.ofFloat(mAppsCustomizePane, "alpha", 1f); + inAnim.addListener(new AnimatorListenerAdapter() { + @Override + public void onAnimationEnd(Animator animation) { + if (!LauncherApplication.isScreenLarge()) { + mAppsCustomizePane.flashScrollingIndicator(); + } + mAppsCustomizePane.loadAssociatedPages( + mAppsCustomizePane.getCurrentPage()); + } + }); + AnimatorSet animSet = new AnimatorSet(); + animSet.playTogether(outAnim, inAnim); + animSet.setDuration(duration); + animSet.start(); + } + }); + } + + public void setCurrentTabFromContent(AppsCustomizePagedView.ContentType type) { + mSuppressContentCallback = true; + setCurrentTabByTag(getTabTagForContentType(type)); } /** -- cgit v1.2.3