Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.launcher2; |
| 18 | |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 19 | import android.animation.Animator; |
Winson Chung | b44b524 | 2011-06-13 11:32:14 -0700 | [diff] [blame] | 20 | import android.animation.AnimatorListenerAdapter; |
Winson Chung | f314b0e | 2011-08-16 11:54:27 -0700 | [diff] [blame] | 21 | import android.animation.AnimatorSet; |
Winson Chung | b44b524 | 2011-06-13 11:32:14 -0700 | [diff] [blame] | 22 | import android.animation.ObjectAnimator; |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 23 | import android.content.Context; |
| 24 | import android.content.res.Resources; |
| 25 | import android.util.AttributeSet; |
| 26 | import android.view.LayoutInflater; |
Winson Chung | 4179b4e | 2011-05-31 17:28:12 -0700 | [diff] [blame] | 27 | import android.view.MotionEvent; |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 28 | import android.view.View; |
| 29 | import android.view.ViewGroup; |
Michael Jurka | 141dbd0 | 2011-11-03 13:50:45 -0700 | [diff] [blame] | 30 | import android.widget.FrameLayout; |
Michael Jurka | 1899a36 | 2011-11-03 13:50:45 -0700 | [diff] [blame] | 31 | import android.widget.LinearLayout; |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 32 | import android.widget.TabHost; |
Winson Chung | faa1325 | 2011-06-13 18:15:54 -0700 | [diff] [blame] | 33 | import android.widget.TabWidget; |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 34 | import android.widget.TextView; |
| 35 | |
| 36 | import com.android.launcher.R; |
| 37 | |
Michael Jurka | 141dbd0 | 2011-11-03 13:50:45 -0700 | [diff] [blame] | 38 | import java.util.ArrayList; |
| 39 | |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 40 | public class AppsCustomizeTabHost extends TabHost implements LauncherTransitionable, |
| 41 | TabHost.OnTabChangeListener { |
| 42 | static final String LOG_TAG = "AppsCustomizeTabHost"; |
| 43 | |
| 44 | private static final String APPS_TAB_TAG = "APPS"; |
| 45 | private static final String WIDGETS_TAB_TAG = "WIDGETS"; |
| 46 | |
| 47 | private final LayoutInflater mLayoutInflater; |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 48 | private ViewGroup mTabs; |
Winson Chung | fd3385f | 2011-06-15 19:51:24 -0700 | [diff] [blame] | 49 | private ViewGroup mTabsContainer; |
Winson Chung | 4179b4e | 2011-05-31 17:28:12 -0700 | [diff] [blame] | 50 | private AppsCustomizePagedView mAppsCustomizePane; |
Adam Cohen | 0cd3b64 | 2011-10-14 14:58:00 -0700 | [diff] [blame] | 51 | private boolean mSuppressContentCallback = false; |
Michael Jurka | 141dbd0 | 2011-11-03 13:50:45 -0700 | [diff] [blame] | 52 | private FrameLayout mAnimationBuffer; |
Michael Jurka | 1899a36 | 2011-11-03 13:50:45 -0700 | [diff] [blame] | 53 | private LinearLayout mContent; |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 54 | |
Winson Chung | c100e8e | 2011-08-09 16:02:43 -0700 | [diff] [blame] | 55 | private boolean mInTransition; |
Winson Chung | 7044272 | 2012-02-10 15:43:22 -0800 | [diff] [blame] | 56 | private boolean mTransitioningToWorkspace; |
Winson Chung | c100e8e | 2011-08-09 16:02:43 -0700 | [diff] [blame] | 57 | private boolean mResetAfterTransition; |
Michael Jurka | 6cfafb9 | 2012-02-23 18:25:43 -0800 | [diff] [blame] | 58 | private Runnable mRelayoutAndMakeVisible; |
Winson Chung | c100e8e | 2011-08-09 16:02:43 -0700 | [diff] [blame] | 59 | |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 60 | public AppsCustomizeTabHost(Context context, AttributeSet attrs) { |
| 61 | super(context, attrs); |
| 62 | mLayoutInflater = LayoutInflater.from(context); |
Michael Jurka | 6cfafb9 | 2012-02-23 18:25:43 -0800 | [diff] [blame] | 63 | mRelayoutAndMakeVisible = new Runnable() { |
| 64 | public void run() { |
| 65 | mTabs.requestLayout(); |
| 66 | mTabsContainer.setAlpha(1f); |
| 67 | } |
| 68 | }; |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 69 | } |
| 70 | |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 71 | /** |
Winson Chung | 5a80835 | 2011-06-27 19:08:49 -0700 | [diff] [blame] | 72 | * Convenience methods to select specific tabs. We want to set the content type immediately |
| 73 | * in these cases, but we note that we still call setCurrentTabByTag() so that the tab view |
| 74 | * reflects the new content (but doesn't do the animation and logic associated with changing |
| 75 | * tabs manually). |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 76 | */ |
Winson Chung | 5a80835 | 2011-06-27 19:08:49 -0700 | [diff] [blame] | 77 | private void setContentTypeImmediate(AppsCustomizePagedView.ContentType type) { |
| 78 | onTabChangedStart(); |
| 79 | onTabChangedEnd(type); |
| 80 | } |
Winson Chung | 55b6550 | 2011-05-26 12:03:43 -0700 | [diff] [blame] | 81 | void selectAppsTab() { |
Winson Chung | 5a80835 | 2011-06-27 19:08:49 -0700 | [diff] [blame] | 82 | setContentTypeImmediate(AppsCustomizePagedView.ContentType.Applications); |
Winson Chung | 55b6550 | 2011-05-26 12:03:43 -0700 | [diff] [blame] | 83 | setCurrentTabByTag(APPS_TAB_TAG); |
| 84 | } |
| 85 | void selectWidgetsTab() { |
Winson Chung | 5a80835 | 2011-06-27 19:08:49 -0700 | [diff] [blame] | 86 | setContentTypeImmediate(AppsCustomizePagedView.ContentType.Widgets); |
Winson Chung | 5a80835 | 2011-06-27 19:08:49 -0700 | [diff] [blame] | 87 | setCurrentTabByTag(WIDGETS_TAB_TAG); |
| 88 | } |
Winson Chung | 55b6550 | 2011-05-26 12:03:43 -0700 | [diff] [blame] | 89 | |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 90 | /** |
| 91 | * Setup the tab host and create all necessary tabs. |
| 92 | */ |
| 93 | @Override |
| 94 | protected void onFinishInflate() { |
| 95 | // Setup the tab host |
| 96 | setup(); |
| 97 | |
Winson Chung | fd3385f | 2011-06-15 19:51:24 -0700 | [diff] [blame] | 98 | final ViewGroup tabsContainer = (ViewGroup) findViewById(R.id.tabs_container); |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 99 | final TabWidget tabs = getTabWidget(); |
Winson Chung | 4179b4e | 2011-05-31 17:28:12 -0700 | [diff] [blame] | 100 | final AppsCustomizePagedView appsCustomizePane = (AppsCustomizePagedView) |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 101 | findViewById(R.id.apps_customize_pane_content); |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 102 | mTabs = tabs; |
Winson Chung | fd3385f | 2011-06-15 19:51:24 -0700 | [diff] [blame] | 103 | mTabsContainer = tabsContainer; |
Winson Chung | 4179b4e | 2011-05-31 17:28:12 -0700 | [diff] [blame] | 104 | mAppsCustomizePane = appsCustomizePane; |
Michael Jurka | 141dbd0 | 2011-11-03 13:50:45 -0700 | [diff] [blame] | 105 | mAnimationBuffer = (FrameLayout) findViewById(R.id.animation_buffer); |
Michael Jurka | 1899a36 | 2011-11-03 13:50:45 -0700 | [diff] [blame] | 106 | mContent = (LinearLayout) findViewById(R.id.apps_customize_content); |
Winson Chung | 4179b4e | 2011-05-31 17:28:12 -0700 | [diff] [blame] | 107 | if (tabs == null || mAppsCustomizePane == null) throw new Resources.NotFoundException(); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 108 | |
| 109 | // Configure the tabs content factory to return the same paged view (that we change the |
| 110 | // content filter on) |
| 111 | TabContentFactory contentFactory = new TabContentFactory() { |
| 112 | public View createTabContent(String tag) { |
Winson Chung | 4179b4e | 2011-05-31 17:28:12 -0700 | [diff] [blame] | 113 | return appsCustomizePane; |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 114 | } |
| 115 | }; |
| 116 | |
| 117 | // Create the tabs |
| 118 | TextView tabView; |
Winson Chung | d2c1f80 | 2011-10-14 12:26:54 -0700 | [diff] [blame] | 119 | String label; |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 120 | label = getContext().getString(R.string.all_apps_button_label); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 121 | tabView = (TextView) mLayoutInflater.inflate(R.layout.tab_widget_indicator, tabs, false); |
Winson Chung | d2c1f80 | 2011-10-14 12:26:54 -0700 | [diff] [blame] | 122 | tabView.setText(label); |
| 123 | tabView.setContentDescription(label); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 124 | addTab(newTabSpec(APPS_TAB_TAG).setIndicator(tabView).setContent(contentFactory)); |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 125 | label = getContext().getString(R.string.widgets_tab_label); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 126 | tabView = (TextView) mLayoutInflater.inflate(R.layout.tab_widget_indicator, tabs, false); |
Winson Chung | d2c1f80 | 2011-10-14 12:26:54 -0700 | [diff] [blame] | 127 | tabView.setText(label); |
| 128 | tabView.setContentDescription(label); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 129 | addTab(newTabSpec(WIDGETS_TAB_TAG).setIndicator(tabView).setContent(contentFactory)); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 130 | setOnTabChangedListener(this); |
Winson Chung | faa1325 | 2011-06-13 18:15:54 -0700 | [diff] [blame] | 131 | |
| 132 | // Setup the key listener to jump between the last tab view and the market icon |
| 133 | AppsCustomizeTabKeyEventListener keyListener = new AppsCustomizeTabKeyEventListener(); |
| 134 | View lastTab = tabs.getChildTabViewAt(tabs.getTabCount() - 1); |
| 135 | lastTab.setOnKeyListener(keyListener); |
| 136 | View shopButton = findViewById(R.id.market_button); |
| 137 | shopButton.setOnKeyListener(keyListener); |
Winson Chung | fd3385f | 2011-06-15 19:51:24 -0700 | [diff] [blame] | 138 | |
| 139 | // Hide the tab bar until we measure |
| 140 | mTabsContainer.setAlpha(0f); |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 141 | } |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 142 | |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 143 | @Override |
| 144 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { |
| 145 | boolean remeasureTabWidth = (mTabs.getLayoutParams().width <= 0); |
| 146 | super.onMeasure(widthMeasureSpec, heightMeasureSpec); |
| 147 | |
| 148 | // Set the width of the tab list to the content width |
| 149 | if (remeasureTabWidth) { |
Winson Chung | fd3385f | 2011-06-15 19:51:24 -0700 | [diff] [blame] | 150 | int contentWidth = mAppsCustomizePane.getPageContentWidth(); |
Michael Jurka | 141dbd0 | 2011-11-03 13:50:45 -0700 | [diff] [blame] | 151 | if (contentWidth > 0 && mTabs.getLayoutParams().width != contentWidth) { |
| 152 | // Set the width and show the tab bar |
Winson Chung | fd3385f | 2011-06-15 19:51:24 -0700 | [diff] [blame] | 153 | mTabs.getLayoutParams().width = contentWidth; |
Michael Jurka | 6cfafb9 | 2012-02-23 18:25:43 -0800 | [diff] [blame] | 154 | post(mRelayoutAndMakeVisible); |
Winson Chung | fd3385f | 2011-06-15 19:51:24 -0700 | [diff] [blame] | 155 | } |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 156 | } |
Winson Chung | fd3385f | 2011-06-15 19:51:24 -0700 | [diff] [blame] | 157 | super.onMeasure(widthMeasureSpec, heightMeasureSpec); |
Winson Chung | 4179b4e | 2011-05-31 17:28:12 -0700 | [diff] [blame] | 158 | } |
| 159 | |
Winson Chung | 7044272 | 2012-02-10 15:43:22 -0800 | [diff] [blame] | 160 | public boolean onInterceptTouchEvent(MotionEvent ev) { |
Winson Chung | ac08f4b | 2012-04-27 15:41:00 -0700 | [diff] [blame] | 161 | // If we are mid transitioning to the workspace, then intercept touch events here so we |
| 162 | // can ignore them, otherwise we just let all apps handle the touch events. |
| 163 | if (mInTransition && mTransitioningToWorkspace) { |
Winson Chung | 7044272 | 2012-02-10 15:43:22 -0800 | [diff] [blame] | 164 | return true; |
| 165 | } |
| 166 | return super.onInterceptTouchEvent(ev); |
| 167 | }; |
| 168 | |
Winson Chung | 4179b4e | 2011-05-31 17:28:12 -0700 | [diff] [blame] | 169 | @Override |
| 170 | public boolean onTouchEvent(MotionEvent event) { |
Winson Chung | ac08f4b | 2012-04-27 15:41:00 -0700 | [diff] [blame] | 171 | // Allow touch events to fall through to the workspace if we are transitioning there |
| 172 | if (mInTransition && mTransitioningToWorkspace) { |
Winson Chung | 21fadea | 2012-04-27 15:59:55 -0700 | [diff] [blame] | 173 | return super.onTouchEvent(event); |
Winson Chung | 7044272 | 2012-02-10 15:43:22 -0800 | [diff] [blame] | 174 | } |
| 175 | |
Winson Chung | 4179b4e | 2011-05-31 17:28:12 -0700 | [diff] [blame] | 176 | // Intercept all touch events up to the bottom of the AppsCustomizePane so they do not fall |
| 177 | // through to the workspace and trigger showWorkspace() |
| 178 | if (event.getY() < mAppsCustomizePane.getBottom()) { |
| 179 | return true; |
| 180 | } |
| 181 | return super.onTouchEvent(event); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 182 | } |
| 183 | |
Winson Chung | 5a80835 | 2011-06-27 19:08:49 -0700 | [diff] [blame] | 184 | private void onTabChangedStart() { |
| 185 | mAppsCustomizePane.hideScrollingIndicator(false); |
| 186 | } |
Adam Cohen | 0cd3b64 | 2011-10-14 14:58:00 -0700 | [diff] [blame] | 187 | |
Winson Chung | 097e6c7 | 2011-10-20 13:58:30 -0700 | [diff] [blame] | 188 | private void reloadCurrentPage() { |
| 189 | if (!LauncherApplication.isScreenLarge()) { |
Michael Jurka | b737ee6 | 2011-11-15 15:57:22 -0800 | [diff] [blame] | 190 | mAppsCustomizePane.flashScrollingIndicator(true); |
Winson Chung | 097e6c7 | 2011-10-20 13:58:30 -0700 | [diff] [blame] | 191 | } |
| 192 | mAppsCustomizePane.loadAssociatedPages(mAppsCustomizePane.getCurrentPage()); |
| 193 | mAppsCustomizePane.requestFocus(); |
| 194 | } |
| 195 | |
Winson Chung | 5a80835 | 2011-06-27 19:08:49 -0700 | [diff] [blame] | 196 | private void onTabChangedEnd(AppsCustomizePagedView.ContentType type) { |
| 197 | mAppsCustomizePane.setContentType(type); |
| 198 | } |
| 199 | |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 200 | @Override |
| 201 | public void onTabChanged(String tabId) { |
Winson Chung | b44b524 | 2011-06-13 11:32:14 -0700 | [diff] [blame] | 202 | final AppsCustomizePagedView.ContentType type = getContentTypeForTabTag(tabId); |
Adam Cohen | 0cd3b64 | 2011-10-14 14:58:00 -0700 | [diff] [blame] | 203 | if (mSuppressContentCallback) { |
| 204 | mSuppressContentCallback = false; |
| 205 | return; |
Winson Chung | b44b524 | 2011-06-13 11:32:14 -0700 | [diff] [blame] | 206 | } |
Adam Cohen | 0cd3b64 | 2011-10-14 14:58:00 -0700 | [diff] [blame] | 207 | |
| 208 | // Animate the changing of the tab content by fading pages in and out |
| 209 | final Resources res = getResources(); |
| 210 | final int duration = res.getInteger(R.integer.config_tabTransitionDuration); |
| 211 | |
| 212 | // We post a runnable here because there is a delay while the first page is loading and |
| 213 | // the feedback from having changed the tab almost feels better than having it stick |
| 214 | post(new Runnable() { |
| 215 | @Override |
| 216 | public void run() { |
Winson Chung | 097e6c7 | 2011-10-20 13:58:30 -0700 | [diff] [blame] | 217 | if (mAppsCustomizePane.getMeasuredWidth() <= 0 || |
| 218 | mAppsCustomizePane.getMeasuredHeight() <= 0) { |
| 219 | reloadCurrentPage(); |
| 220 | return; |
| 221 | } |
| 222 | |
Michael Jurka | 141dbd0 | 2011-11-03 13:50:45 -0700 | [diff] [blame] | 223 | // Take the visible pages and re-parent them temporarily to mAnimatorBuffer |
| 224 | // and then cross fade to the new pages |
Winson Chung | c6f10b9 | 2011-11-14 11:39:07 -0800 | [diff] [blame] | 225 | int[] visiblePageRange = new int[2]; |
| 226 | mAppsCustomizePane.getVisiblePages(visiblePageRange); |
| 227 | if (visiblePageRange[0] == -1 && visiblePageRange[1] == -1) { |
| 228 | // If we can't get the visible page ranges, then just skip the animation |
| 229 | reloadCurrentPage(); |
| 230 | return; |
| 231 | } |
| 232 | ArrayList<View> visiblePages = new ArrayList<View>(); |
| 233 | for (int i = visiblePageRange[0]; i <= visiblePageRange[1]; i++) { |
| 234 | visiblePages.add(mAppsCustomizePane.getPageAt(i)); |
| 235 | } |
Michael Jurka | 141dbd0 | 2011-11-03 13:50:45 -0700 | [diff] [blame] | 236 | |
| 237 | // We want the pages to be rendered in exactly the same way as they were when |
| 238 | // their parent was mAppsCustomizePane -- so set the scroll on mAnimationBuffer |
| 239 | // to be exactly the same as mAppsCustomizePane, and below, set the left/top |
| 240 | // parameters to be correct for each of the pages |
| 241 | mAnimationBuffer.scrollTo(mAppsCustomizePane.getScrollX(), 0); |
| 242 | |
Michael Jurka | 141dbd0 | 2011-11-03 13:50:45 -0700 | [diff] [blame] | 243 | // mAppsCustomizePane renders its children in reverse order, so |
| 244 | // add the pages to mAnimationBuffer in reverse order to match that behavior |
| 245 | for (int i = visiblePages.size() - 1; i >= 0; i--) { |
| 246 | View child = visiblePages.get(i); |
Winson Chung | c6f10b9 | 2011-11-14 11:39:07 -0800 | [diff] [blame] | 247 | if (child instanceof PagedViewCellLayout) { |
| 248 | ((PagedViewCellLayout) child).resetChildrenOnKeyListeners(); |
| 249 | } else if (child instanceof PagedViewGridLayout) { |
| 250 | ((PagedViewGridLayout) child).resetChildrenOnKeyListeners(); |
| 251 | } |
Michael Jurka | 141dbd0 | 2011-11-03 13:50:45 -0700 | [diff] [blame] | 252 | PagedViewWidget.setDeletePreviewsWhenDetachedFromWindow(false); |
| 253 | mAppsCustomizePane.removeView(child); |
| 254 | PagedViewWidget.setDeletePreviewsWhenDetachedFromWindow(true); |
| 255 | mAnimationBuffer.setAlpha(1f); |
| 256 | mAnimationBuffer.setVisibility(View.VISIBLE); |
Winson Chung | 6e3cf90 | 2012-03-30 16:36:53 -0700 | [diff] [blame] | 257 | LayoutParams p = new FrameLayout.LayoutParams(child.getMeasuredWidth(), |
| 258 | child.getMeasuredHeight()); |
Michael Jurka | 141dbd0 | 2011-11-03 13:50:45 -0700 | [diff] [blame] | 259 | p.setMargins((int) child.getLeft(), (int) child.getTop(), 0, 0); |
| 260 | mAnimationBuffer.addView(child, p); |
| 261 | } |
Adam Cohen | 0cd3b64 | 2011-10-14 14:58:00 -0700 | [diff] [blame] | 262 | |
| 263 | // Toggle the new content |
| 264 | onTabChangedStart(); |
| 265 | onTabChangedEnd(type); |
| 266 | |
| 267 | // Animate the transition |
| 268 | ObjectAnimator outAnim = ObjectAnimator.ofFloat(mAnimationBuffer, "alpha", 0f); |
| 269 | outAnim.addListener(new AnimatorListenerAdapter() { |
| 270 | @Override |
| 271 | public void onAnimationEnd(Animator animation) { |
| 272 | mAnimationBuffer.setVisibility(View.GONE); |
Michael Jurka | 141dbd0 | 2011-11-03 13:50:45 -0700 | [diff] [blame] | 273 | mAnimationBuffer.removeAllViews(); |
| 274 | } |
| 275 | @Override |
| 276 | public void onAnimationCancel(Animator animation) { |
| 277 | mAnimationBuffer.setVisibility(View.GONE); |
| 278 | mAnimationBuffer.removeAllViews(); |
Adam Cohen | 0cd3b64 | 2011-10-14 14:58:00 -0700 | [diff] [blame] | 279 | } |
| 280 | }); |
| 281 | ObjectAnimator inAnim = ObjectAnimator.ofFloat(mAppsCustomizePane, "alpha", 1f); |
| 282 | inAnim.addListener(new AnimatorListenerAdapter() { |
| 283 | @Override |
| 284 | public void onAnimationEnd(Animator animation) { |
Winson Chung | 097e6c7 | 2011-10-20 13:58:30 -0700 | [diff] [blame] | 285 | reloadCurrentPage(); |
Adam Cohen | 0cd3b64 | 2011-10-14 14:58:00 -0700 | [diff] [blame] | 286 | } |
| 287 | }); |
| 288 | AnimatorSet animSet = new AnimatorSet(); |
| 289 | animSet.playTogether(outAnim, inAnim); |
| 290 | animSet.setDuration(duration); |
| 291 | animSet.start(); |
| 292 | } |
| 293 | }); |
| 294 | } |
| 295 | |
| 296 | public void setCurrentTabFromContent(AppsCustomizePagedView.ContentType type) { |
| 297 | mSuppressContentCallback = true; |
| 298 | setCurrentTabByTag(getTabTagForContentType(type)); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 299 | } |
| 300 | |
| 301 | /** |
| 302 | * Returns the content type for the specified tab tag. |
| 303 | */ |
| 304 | public AppsCustomizePagedView.ContentType getContentTypeForTabTag(String tag) { |
| 305 | if (tag.equals(APPS_TAB_TAG)) { |
| 306 | return AppsCustomizePagedView.ContentType.Applications; |
| 307 | } else if (tag.equals(WIDGETS_TAB_TAG)) { |
| 308 | return AppsCustomizePagedView.ContentType.Widgets; |
| 309 | } |
| 310 | return AppsCustomizePagedView.ContentType.Applications; |
| 311 | } |
| 312 | |
| 313 | /** |
Winson Chung | fc79c80 | 2011-05-02 13:35:34 -0700 | [diff] [blame] | 314 | * Returns the tab tag for a given content type. |
| 315 | */ |
| 316 | public String getTabTagForContentType(AppsCustomizePagedView.ContentType type) { |
| 317 | if (type == AppsCustomizePagedView.ContentType.Applications) { |
| 318 | return APPS_TAB_TAG; |
| 319 | } else if (type == AppsCustomizePagedView.ContentType.Widgets) { |
| 320 | return WIDGETS_TAB_TAG; |
| 321 | } |
| 322 | return APPS_TAB_TAG; |
| 323 | } |
| 324 | |
| 325 | /** |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 326 | * Disable focus on anything under this view in the hierarchy if we are not visible. |
| 327 | */ |
| 328 | @Override |
| 329 | public int getDescendantFocusability() { |
| 330 | if (getVisibility() != View.VISIBLE) { |
| 331 | return ViewGroup.FOCUS_BLOCK_DESCENDANTS; |
| 332 | } |
| 333 | return super.getDescendantFocusability(); |
| 334 | } |
| 335 | |
Winson Chung | c100e8e | 2011-08-09 16:02:43 -0700 | [diff] [blame] | 336 | void reset() { |
| 337 | if (mInTransition) { |
| 338 | // Defer to after the transition to reset |
| 339 | mResetAfterTransition = true; |
| 340 | } else { |
| 341 | // Reset immediately |
| 342 | mAppsCustomizePane.reset(); |
| 343 | } |
| 344 | } |
| 345 | |
Michael Jurka | 1899a36 | 2011-11-03 13:50:45 -0700 | [diff] [blame] | 346 | private void enableAndBuildHardwareLayer() { |
Michael Jurka | 19e0fc5 | 2011-07-22 18:00:21 -0700 | [diff] [blame] | 347 | // isHardwareAccelerated() checks if we're attached to a window and if that |
| 348 | // window is HW accelerated-- we were sometimes not attached to a window |
| 349 | // and buildLayer was throwing an IllegalStateException |
Michael Jurka | 1899a36 | 2011-11-03 13:50:45 -0700 | [diff] [blame] | 350 | if (isHardwareAccelerated()) { |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 351 | // Turn on hardware layers for performance |
| 352 | setLayerType(LAYER_TYPE_HARDWARE, null); |
| 353 | |
Michael Jurka | 1899a36 | 2011-11-03 13:50:45 -0700 | [diff] [blame] | 354 | // force building the layer, so you don't get a blip early in an animation |
| 355 | // when the layer is created layer |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 356 | buildLayer(); |
Michael Jurka | 39e5d17 | 2012-03-12 18:36:12 -0700 | [diff] [blame] | 357 | |
| 358 | // Let the GC system know that now is a good time to do any garbage |
| 359 | // collection; makes it less likely we'll get a GC during the all apps |
| 360 | // to workspace animation |
| 361 | System.gc(); |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 362 | } |
Michael Jurka | 1899a36 | 2011-11-03 13:50:45 -0700 | [diff] [blame] | 363 | } |
| 364 | |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 365 | @Override |
| 366 | public View getContent() { |
| 367 | return mContent; |
Michael Jurka | 1899a36 | 2011-11-03 13:50:45 -0700 | [diff] [blame] | 368 | } |
| 369 | |
| 370 | /* LauncherTransitionable overrides */ |
| 371 | @Override |
Michael Jurka | a35e35a | 2012-04-26 15:04:28 -0700 | [diff] [blame] | 372 | public void onLauncherTransitionPrepare(Launcher l, boolean animated, boolean toWorkspace) { |
| 373 | mAppsCustomizePane.onLauncherTransitionPrepare(l, animated, toWorkspace); |
Michael Jurka | 1899a36 | 2011-11-03 13:50:45 -0700 | [diff] [blame] | 374 | mInTransition = true; |
Winson Chung | 7044272 | 2012-02-10 15:43:22 -0800 | [diff] [blame] | 375 | mTransitioningToWorkspace = toWorkspace; |
Michael Jurka | 1899a36 | 2011-11-03 13:50:45 -0700 | [diff] [blame] | 376 | |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 377 | if (toWorkspace) { |
| 378 | // Going from All Apps -> Workspace |
| 379 | setVisibilityOfSiblingsWithLowerZOrder(VISIBLE); |
Michael Jurka | a8352d2 | 2012-02-23 16:28:37 -0800 | [diff] [blame] | 380 | // Stop the scrolling indicator - we don't want All Apps to be invalidating itself |
| 381 | // during the transition, especially since it has a hardware layer set on it |
| 382 | mAppsCustomizePane.cancelScrollingIndicatorAnimations(); |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 383 | } else { |
| 384 | // Going from Workspace -> All Apps |
| 385 | mContent.setVisibility(VISIBLE); |
Michael Jurka | 3d845e8 | 2011-11-15 17:04:31 -0800 | [diff] [blame] | 386 | |
Michael Jurka | e326f18 | 2011-11-21 14:05:46 -0800 | [diff] [blame] | 387 | // Make sure the current page is loaded (we start loading the side pages after the |
| 388 | // transition to prevent slowing down the animation) |
| 389 | mAppsCustomizePane.loadAssociatedPages(mAppsCustomizePane.getCurrentPage(), true); |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 390 | |
| 391 | if (!LauncherApplication.isScreenLarge()) { |
| 392 | mAppsCustomizePane.showScrollingIndicator(true); |
| 393 | } |
Michael Jurka | 1899a36 | 2011-11-03 13:50:45 -0700 | [diff] [blame] | 394 | } |
| 395 | |
Winson Chung | c100e8e | 2011-08-09 16:02:43 -0700 | [diff] [blame] | 396 | if (mResetAfterTransition) { |
| 397 | mAppsCustomizePane.reset(); |
| 398 | mResetAfterTransition = false; |
| 399 | } |
Michael Jurka | a35e35a | 2012-04-26 15:04:28 -0700 | [diff] [blame] | 400 | } |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 401 | |
Michael Jurka | a35e35a | 2012-04-26 15:04:28 -0700 | [diff] [blame] | 402 | @Override |
| 403 | public void onLauncherTransitionStart(Launcher l, boolean animated, boolean toWorkspace) { |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 404 | if (animated) { |
| 405 | enableAndBuildHardwareLayer(); |
| 406 | } |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 407 | } |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 408 | |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 409 | @Override |
Winson Chung | 7044272 | 2012-02-10 15:43:22 -0800 | [diff] [blame] | 410 | public void onLauncherTransitionStep(Launcher l, float t) { |
| 411 | // Do nothing |
| 412 | } |
| 413 | |
| 414 | @Override |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 415 | public void onLauncherTransitionEnd(Launcher l, boolean animated, boolean toWorkspace) { |
Michael Jurka | 39e5d17 | 2012-03-12 18:36:12 -0700 | [diff] [blame] | 416 | mAppsCustomizePane.onLauncherTransitionEnd(l, animated, toWorkspace); |
Winson Chung | c100e8e | 2011-08-09 16:02:43 -0700 | [diff] [blame] | 417 | mInTransition = false; |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 418 | if (animated) { |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 419 | setLayerType(LAYER_TYPE_NONE, null); |
| 420 | } |
Winson Chung | 3ac74c5 | 2011-06-30 17:39:37 -0700 | [diff] [blame] | 421 | |
Winson Chung | 7d7541e | 2011-09-16 20:14:36 -0700 | [diff] [blame] | 422 | if (!toWorkspace) { |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 423 | // Going from Workspace -> All Apps |
| 424 | setVisibilityOfSiblingsWithLowerZOrder(INVISIBLE); |
| 425 | |
Winson Chung | 3f4e142 | 2011-11-17 14:58:51 -0800 | [diff] [blame] | 426 | // Dismiss the workspace cling and show the all apps cling (if not already shown) |
Winson Chung | 7d7541e | 2011-09-16 20:14:36 -0700 | [diff] [blame] | 427 | l.dismissWorkspaceCling(null); |
Winson Chung | 3f4e142 | 2011-11-17 14:58:51 -0800 | [diff] [blame] | 428 | mAppsCustomizePane.showAllAppsCling(); |
Michael Jurka | e326f18 | 2011-11-21 14:05:46 -0800 | [diff] [blame] | 429 | // Make sure adjacent pages are loaded (we wait until after the transition to |
| 430 | // prevent slowing down the animation) |
| 431 | mAppsCustomizePane.loadAssociatedPages(mAppsCustomizePane.getCurrentPage()); |
Winson Chung | 7d7541e | 2011-09-16 20:14:36 -0700 | [diff] [blame] | 432 | |
| 433 | if (!LauncherApplication.isScreenLarge()) { |
| 434 | mAppsCustomizePane.hideScrollingIndicator(false); |
| 435 | } |
Winson Chung | 5a80835 | 2011-06-27 19:08:49 -0700 | [diff] [blame] | 436 | } |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 437 | } |
Winson Chung | 70d7210 | 2011-08-12 11:24:35 -0700 | [diff] [blame] | 438 | |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 439 | private void setVisibilityOfSiblingsWithLowerZOrder(int visibility) { |
| 440 | ViewGroup parent = (ViewGroup) getParent(); |
Michael Jurka | aea1ce5 | 2012-04-12 11:23:21 -0700 | [diff] [blame] | 441 | if (parent == null) return; |
| 442 | |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 443 | final int count = parent.getChildCount(); |
| 444 | if (!isChildrenDrawingOrderEnabled()) { |
| 445 | for (int i = 0; i < count; i++) { |
| 446 | final View child = parent.getChildAt(i); |
| 447 | if (child == this) { |
| 448 | break; |
| 449 | } else { |
| 450 | if (child.getVisibility() == GONE) { |
| 451 | continue; |
| 452 | } |
| 453 | child.setVisibility(visibility); |
| 454 | } |
| 455 | } |
| 456 | } else { |
| 457 | throw new RuntimeException("Failed; can't get z-order of views"); |
| 458 | } |
| 459 | } |
| 460 | |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 461 | public void onWindowVisible() { |
Michael Jurka | e326f18 | 2011-11-21 14:05:46 -0800 | [diff] [blame] | 462 | if (getVisibility() == VISIBLE) { |
| 463 | mContent.setVisibility(VISIBLE); |
| 464 | // We unload the widget previews when the UI is hidden, so need to reload pages |
| 465 | // Load the current page synchronously, and the neighboring pages asynchronously |
| 466 | mAppsCustomizePane.loadAssociatedPages(mAppsCustomizePane.getCurrentPage(), true); |
| 467 | mAppsCustomizePane.loadAssociatedPages(mAppsCustomizePane.getCurrentPage()); |
| 468 | } |
| 469 | } |
| 470 | |
| 471 | public void onTrimMemory() { |
| 472 | mContent.setVisibility(GONE); |
| 473 | // Clear the widget pages of all their subviews - this will trigger the widget previews |
| 474 | // to delete their bitmaps |
| 475 | mAppsCustomizePane.clearAllWidgetPages(); |
| 476 | } |
| 477 | |
Winson Chung | 70d7210 | 2011-08-12 11:24:35 -0700 | [diff] [blame] | 478 | boolean isTransitioning() { |
| 479 | return mInTransition; |
| 480 | } |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 481 | } |