Add ability to swipe from apps to widgets in AllAppsCustomize (issue 5453016)

Change-Id: I4d725cf1ee11d67f5149dbd0edbcb2e0af3b80ee
This commit is contained in:
Adam Cohen
2011-10-14 14:58:00 -07:00
parent 3f74f0cbc6
commit 0cd3b64e60
3 changed files with 157 additions and 186 deletions

View File

@@ -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));
}
/**