blob: d3afc3bf033faf3a4fa234dbc2eafdc20619f3a2 [file] [log] [blame]
Winson Chung785d2eb2011-04-14 16:08:02 -07001/*
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
17package com.android.launcher2;
18
Winson Chungf0ea4d32011-06-06 14:27:16 -070019import android.animation.Animator;
Winson Chungb44b5242011-06-13 11:32:14 -070020import android.animation.AnimatorListenerAdapter;
Winson Chungf314b0e2011-08-16 11:54:27 -070021import android.animation.AnimatorSet;
Winson Chungb44b5242011-06-13 11:32:14 -070022import android.animation.ObjectAnimator;
Winson Chung785d2eb2011-04-14 16:08:02 -070023import android.content.Context;
24import android.content.res.Resources;
25import android.util.AttributeSet;
26import android.view.LayoutInflater;
Winson Chung4179b4e2011-05-31 17:28:12 -070027import android.view.MotionEvent;
Winson Chung785d2eb2011-04-14 16:08:02 -070028import android.view.View;
29import android.view.ViewGroup;
Michael Jurka141dbd02011-11-03 13:50:45 -070030import android.widget.FrameLayout;
Michael Jurka1899a362011-11-03 13:50:45 -070031import android.widget.LinearLayout;
Winson Chung785d2eb2011-04-14 16:08:02 -070032import android.widget.TabHost;
Winson Chungfaa13252011-06-13 18:15:54 -070033import android.widget.TabWidget;
Winson Chung785d2eb2011-04-14 16:08:02 -070034import android.widget.TextView;
35
36import com.android.launcher.R;
37
Michael Jurka141dbd02011-11-03 13:50:45 -070038import java.util.ArrayList;
39
Winson Chung785d2eb2011-04-14 16:08:02 -070040public 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 Chungf0ea4d32011-06-06 14:27:16 -070048 private ViewGroup mTabs;
Winson Chungfd3385f2011-06-15 19:51:24 -070049 private ViewGroup mTabsContainer;
Winson Chung4179b4e2011-05-31 17:28:12 -070050 private AppsCustomizePagedView mAppsCustomizePane;
Adam Cohen0cd3b642011-10-14 14:58:00 -070051 private boolean mSuppressContentCallback = false;
Michael Jurka141dbd02011-11-03 13:50:45 -070052 private FrameLayout mAnimationBuffer;
Michael Jurka1899a362011-11-03 13:50:45 -070053 private LinearLayout mContent;
Winson Chung785d2eb2011-04-14 16:08:02 -070054
Winson Chungc100e8e2011-08-09 16:02:43 -070055 private boolean mInTransition;
Winson Chung70442722012-02-10 15:43:22 -080056 private boolean mTransitioningToWorkspace;
Winson Chungc100e8e2011-08-09 16:02:43 -070057 private boolean mResetAfterTransition;
Michael Jurka6cfafb92012-02-23 18:25:43 -080058 private Runnable mRelayoutAndMakeVisible;
Winson Chungc100e8e2011-08-09 16:02:43 -070059
Winson Chungc7450e32012-04-17 17:34:08 -070060 private Launcher mLauncher;
61
Winson Chung785d2eb2011-04-14 16:08:02 -070062 public AppsCustomizeTabHost(Context context, AttributeSet attrs) {
63 super(context, attrs);
64 mLayoutInflater = LayoutInflater.from(context);
Michael Jurka6cfafb92012-02-23 18:25:43 -080065 mRelayoutAndMakeVisible = new Runnable() {
66 public void run() {
67 mTabs.requestLayout();
68 mTabsContainer.setAlpha(1f);
69 }
70 };
Winson Chung785d2eb2011-04-14 16:08:02 -070071 }
72
Winson Chungc7450e32012-04-17 17:34:08 -070073 public void setup(Launcher launcher) {
74 mLauncher = launcher;
75 }
76
Winson Chungf0ea4d32011-06-06 14:27:16 -070077 /**
Winson Chung5a808352011-06-27 19:08:49 -070078 * Convenience methods to select specific tabs. We want to set the content type immediately
79 * in these cases, but we note that we still call setCurrentTabByTag() so that the tab view
80 * reflects the new content (but doesn't do the animation and logic associated with changing
81 * tabs manually).
Winson Chungf0ea4d32011-06-06 14:27:16 -070082 */
Winson Chung5a808352011-06-27 19:08:49 -070083 private void setContentTypeImmediate(AppsCustomizePagedView.ContentType type) {
84 onTabChangedStart();
85 onTabChangedEnd(type);
86 }
Winson Chung55b65502011-05-26 12:03:43 -070087 void selectAppsTab() {
Winson Chung5a808352011-06-27 19:08:49 -070088 setContentTypeImmediate(AppsCustomizePagedView.ContentType.Applications);
Winson Chung55b65502011-05-26 12:03:43 -070089 setCurrentTabByTag(APPS_TAB_TAG);
90 }
91 void selectWidgetsTab() {
Winson Chung5a808352011-06-27 19:08:49 -070092 setContentTypeImmediate(AppsCustomizePagedView.ContentType.Widgets);
Winson Chung5a808352011-06-27 19:08:49 -070093 setCurrentTabByTag(WIDGETS_TAB_TAG);
94 }
Winson Chung55b65502011-05-26 12:03:43 -070095
Winson Chung785d2eb2011-04-14 16:08:02 -070096 /**
97 * Setup the tab host and create all necessary tabs.
98 */
99 @Override
100 protected void onFinishInflate() {
101 // Setup the tab host
102 setup();
103
Winson Chungfd3385f2011-06-15 19:51:24 -0700104 final ViewGroup tabsContainer = (ViewGroup) findViewById(R.id.tabs_container);
Michael Jurka8b805b12012-04-18 14:23:14 -0700105 final TabWidget tabs = getTabWidget();
Winson Chung4179b4e2011-05-31 17:28:12 -0700106 final AppsCustomizePagedView appsCustomizePane = (AppsCustomizePagedView)
Winson Chung785d2eb2011-04-14 16:08:02 -0700107 findViewById(R.id.apps_customize_pane_content);
Winson Chungf0ea4d32011-06-06 14:27:16 -0700108 mTabs = tabs;
Winson Chungfd3385f2011-06-15 19:51:24 -0700109 mTabsContainer = tabsContainer;
Winson Chung4179b4e2011-05-31 17:28:12 -0700110 mAppsCustomizePane = appsCustomizePane;
Michael Jurka141dbd02011-11-03 13:50:45 -0700111 mAnimationBuffer = (FrameLayout) findViewById(R.id.animation_buffer);
Michael Jurka1899a362011-11-03 13:50:45 -0700112 mContent = (LinearLayout) findViewById(R.id.apps_customize_content);
Winson Chung4179b4e2011-05-31 17:28:12 -0700113 if (tabs == null || mAppsCustomizePane == null) throw new Resources.NotFoundException();
Winson Chung785d2eb2011-04-14 16:08:02 -0700114
115 // Configure the tabs content factory to return the same paged view (that we change the
116 // content filter on)
117 TabContentFactory contentFactory = new TabContentFactory() {
118 public View createTabContent(String tag) {
Winson Chung4179b4e2011-05-31 17:28:12 -0700119 return appsCustomizePane;
Winson Chung785d2eb2011-04-14 16:08:02 -0700120 }
121 };
122
123 // Create the tabs
124 TextView tabView;
Winson Chungd2c1f802011-10-14 12:26:54 -0700125 String label;
Michael Jurka8b805b12012-04-18 14:23:14 -0700126 label = getContext().getString(R.string.all_apps_button_label);
Winson Chung785d2eb2011-04-14 16:08:02 -0700127 tabView = (TextView) mLayoutInflater.inflate(R.layout.tab_widget_indicator, tabs, false);
Winson Chungd2c1f802011-10-14 12:26:54 -0700128 tabView.setText(label);
129 tabView.setContentDescription(label);
Winson Chung785d2eb2011-04-14 16:08:02 -0700130 addTab(newTabSpec(APPS_TAB_TAG).setIndicator(tabView).setContent(contentFactory));
Michael Jurka8b805b12012-04-18 14:23:14 -0700131 label = getContext().getString(R.string.widgets_tab_label);
Winson Chung785d2eb2011-04-14 16:08:02 -0700132 tabView = (TextView) mLayoutInflater.inflate(R.layout.tab_widget_indicator, tabs, false);
Winson Chungd2c1f802011-10-14 12:26:54 -0700133 tabView.setText(label);
134 tabView.setContentDescription(label);
Winson Chung785d2eb2011-04-14 16:08:02 -0700135 addTab(newTabSpec(WIDGETS_TAB_TAG).setIndicator(tabView).setContent(contentFactory));
Winson Chung785d2eb2011-04-14 16:08:02 -0700136 setOnTabChangedListener(this);
Winson Chungfaa13252011-06-13 18:15:54 -0700137
138 // Setup the key listener to jump between the last tab view and the market icon
139 AppsCustomizeTabKeyEventListener keyListener = new AppsCustomizeTabKeyEventListener();
140 View lastTab = tabs.getChildTabViewAt(tabs.getTabCount() - 1);
141 lastTab.setOnKeyListener(keyListener);
142 View shopButton = findViewById(R.id.market_button);
143 shopButton.setOnKeyListener(keyListener);
Winson Chungfd3385f2011-06-15 19:51:24 -0700144
145 // Hide the tab bar until we measure
146 mTabsContainer.setAlpha(0f);
Winson Chungf0ea4d32011-06-06 14:27:16 -0700147 }
Winson Chung785d2eb2011-04-14 16:08:02 -0700148
Winson Chungf0ea4d32011-06-06 14:27:16 -0700149 @Override
150 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
151 boolean remeasureTabWidth = (mTabs.getLayoutParams().width <= 0);
152 super.onMeasure(widthMeasureSpec, heightMeasureSpec);
153
154 // Set the width of the tab list to the content width
155 if (remeasureTabWidth) {
Winson Chungfd3385f2011-06-15 19:51:24 -0700156 int contentWidth = mAppsCustomizePane.getPageContentWidth();
Michael Jurka141dbd02011-11-03 13:50:45 -0700157 if (contentWidth > 0 && mTabs.getLayoutParams().width != contentWidth) {
158 // Set the width and show the tab bar
Winson Chungfd3385f2011-06-15 19:51:24 -0700159 mTabs.getLayoutParams().width = contentWidth;
Michael Jurka6cfafb92012-02-23 18:25:43 -0800160 post(mRelayoutAndMakeVisible);
Winson Chungfd3385f2011-06-15 19:51:24 -0700161 }
Winson Chungf0ea4d32011-06-06 14:27:16 -0700162 }
Winson Chungfd3385f2011-06-15 19:51:24 -0700163 super.onMeasure(widthMeasureSpec, heightMeasureSpec);
Winson Chung4179b4e2011-05-31 17:28:12 -0700164 }
165
Winson Chung70442722012-02-10 15:43:22 -0800166 public boolean onInterceptTouchEvent(MotionEvent ev) {
Winson Chungac08f4b2012-04-27 15:41:00 -0700167 // If we are mid transitioning to the workspace, then intercept touch events here so we
168 // can ignore them, otherwise we just let all apps handle the touch events.
169 if (mInTransition && mTransitioningToWorkspace) {
Winson Chung70442722012-02-10 15:43:22 -0800170 return true;
171 }
172 return super.onInterceptTouchEvent(ev);
173 };
174
Winson Chung4179b4e2011-05-31 17:28:12 -0700175 @Override
176 public boolean onTouchEvent(MotionEvent event) {
Winson Chungac08f4b2012-04-27 15:41:00 -0700177 // Allow touch events to fall through to the workspace if we are transitioning there
178 if (mInTransition && mTransitioningToWorkspace) {
Winson Chung21fadea2012-04-27 15:59:55 -0700179 return super.onTouchEvent(event);
Winson Chung70442722012-02-10 15:43:22 -0800180 }
181
Winson Chung4179b4e2011-05-31 17:28:12 -0700182 // Intercept all touch events up to the bottom of the AppsCustomizePane so they do not fall
183 // through to the workspace and trigger showWorkspace()
184 if (event.getY() < mAppsCustomizePane.getBottom()) {
185 return true;
186 }
187 return super.onTouchEvent(event);
Winson Chung785d2eb2011-04-14 16:08:02 -0700188 }
189
Winson Chung5a808352011-06-27 19:08:49 -0700190 private void onTabChangedStart() {
191 mAppsCustomizePane.hideScrollingIndicator(false);
192 }
Adam Cohen0cd3b642011-10-14 14:58:00 -0700193
Winson Chung097e6c72011-10-20 13:58:30 -0700194 private void reloadCurrentPage() {
195 if (!LauncherApplication.isScreenLarge()) {
Michael Jurkab737ee62011-11-15 15:57:22 -0800196 mAppsCustomizePane.flashScrollingIndicator(true);
Winson Chung097e6c72011-10-20 13:58:30 -0700197 }
198 mAppsCustomizePane.loadAssociatedPages(mAppsCustomizePane.getCurrentPage());
199 mAppsCustomizePane.requestFocus();
200 }
201
Winson Chung5a808352011-06-27 19:08:49 -0700202 private void onTabChangedEnd(AppsCustomizePagedView.ContentType type) {
203 mAppsCustomizePane.setContentType(type);
204 }
205
Winson Chung785d2eb2011-04-14 16:08:02 -0700206 @Override
207 public void onTabChanged(String tabId) {
Winson Chungb44b5242011-06-13 11:32:14 -0700208 final AppsCustomizePagedView.ContentType type = getContentTypeForTabTag(tabId);
Adam Cohen0cd3b642011-10-14 14:58:00 -0700209 if (mSuppressContentCallback) {
210 mSuppressContentCallback = false;
211 return;
Winson Chungb44b5242011-06-13 11:32:14 -0700212 }
Adam Cohen0cd3b642011-10-14 14:58:00 -0700213
214 // Animate the changing of the tab content by fading pages in and out
215 final Resources res = getResources();
216 final int duration = res.getInteger(R.integer.config_tabTransitionDuration);
217
218 // We post a runnable here because there is a delay while the first page is loading and
219 // the feedback from having changed the tab almost feels better than having it stick
220 post(new Runnable() {
221 @Override
222 public void run() {
Winson Chung097e6c72011-10-20 13:58:30 -0700223 if (mAppsCustomizePane.getMeasuredWidth() <= 0 ||
224 mAppsCustomizePane.getMeasuredHeight() <= 0) {
225 reloadCurrentPage();
226 return;
227 }
228
Michael Jurka141dbd02011-11-03 13:50:45 -0700229 // Take the visible pages and re-parent them temporarily to mAnimatorBuffer
230 // and then cross fade to the new pages
Winson Chungc6f10b92011-11-14 11:39:07 -0800231 int[] visiblePageRange = new int[2];
232 mAppsCustomizePane.getVisiblePages(visiblePageRange);
233 if (visiblePageRange[0] == -1 && visiblePageRange[1] == -1) {
234 // If we can't get the visible page ranges, then just skip the animation
235 reloadCurrentPage();
236 return;
237 }
238 ArrayList<View> visiblePages = new ArrayList<View>();
239 for (int i = visiblePageRange[0]; i <= visiblePageRange[1]; i++) {
240 visiblePages.add(mAppsCustomizePane.getPageAt(i));
241 }
Michael Jurka141dbd02011-11-03 13:50:45 -0700242
243 // We want the pages to be rendered in exactly the same way as they were when
244 // their parent was mAppsCustomizePane -- so set the scroll on mAnimationBuffer
245 // to be exactly the same as mAppsCustomizePane, and below, set the left/top
246 // parameters to be correct for each of the pages
247 mAnimationBuffer.scrollTo(mAppsCustomizePane.getScrollX(), 0);
248
Michael Jurka141dbd02011-11-03 13:50:45 -0700249 // mAppsCustomizePane renders its children in reverse order, so
250 // add the pages to mAnimationBuffer in reverse order to match that behavior
251 for (int i = visiblePages.size() - 1; i >= 0; i--) {
252 View child = visiblePages.get(i);
Winson Chungc6f10b92011-11-14 11:39:07 -0800253 if (child instanceof PagedViewCellLayout) {
254 ((PagedViewCellLayout) child).resetChildrenOnKeyListeners();
255 } else if (child instanceof PagedViewGridLayout) {
256 ((PagedViewGridLayout) child).resetChildrenOnKeyListeners();
257 }
Michael Jurka141dbd02011-11-03 13:50:45 -0700258 PagedViewWidget.setDeletePreviewsWhenDetachedFromWindow(false);
259 mAppsCustomizePane.removeView(child);
260 PagedViewWidget.setDeletePreviewsWhenDetachedFromWindow(true);
261 mAnimationBuffer.setAlpha(1f);
262 mAnimationBuffer.setVisibility(View.VISIBLE);
Winson Chung6e3cf902012-03-30 16:36:53 -0700263 LayoutParams p = new FrameLayout.LayoutParams(child.getMeasuredWidth(),
264 child.getMeasuredHeight());
Michael Jurka141dbd02011-11-03 13:50:45 -0700265 p.setMargins((int) child.getLeft(), (int) child.getTop(), 0, 0);
266 mAnimationBuffer.addView(child, p);
267 }
Adam Cohen0cd3b642011-10-14 14:58:00 -0700268
269 // Toggle the new content
270 onTabChangedStart();
271 onTabChangedEnd(type);
272
273 // Animate the transition
274 ObjectAnimator outAnim = ObjectAnimator.ofFloat(mAnimationBuffer, "alpha", 0f);
275 outAnim.addListener(new AnimatorListenerAdapter() {
276 @Override
277 public void onAnimationEnd(Animator animation) {
278 mAnimationBuffer.setVisibility(View.GONE);
Michael Jurka141dbd02011-11-03 13:50:45 -0700279 mAnimationBuffer.removeAllViews();
280 }
281 @Override
282 public void onAnimationCancel(Animator animation) {
283 mAnimationBuffer.setVisibility(View.GONE);
284 mAnimationBuffer.removeAllViews();
Adam Cohen0cd3b642011-10-14 14:58:00 -0700285 }
286 });
287 ObjectAnimator inAnim = ObjectAnimator.ofFloat(mAppsCustomizePane, "alpha", 1f);
288 inAnim.addListener(new AnimatorListenerAdapter() {
289 @Override
290 public void onAnimationEnd(Animator animation) {
Winson Chung097e6c72011-10-20 13:58:30 -0700291 reloadCurrentPage();
Adam Cohen0cd3b642011-10-14 14:58:00 -0700292 }
293 });
294 AnimatorSet animSet = new AnimatorSet();
295 animSet.playTogether(outAnim, inAnim);
296 animSet.setDuration(duration);
297 animSet.start();
298 }
299 });
300 }
301
302 public void setCurrentTabFromContent(AppsCustomizePagedView.ContentType type) {
303 mSuppressContentCallback = true;
304 setCurrentTabByTag(getTabTagForContentType(type));
Winson Chung785d2eb2011-04-14 16:08:02 -0700305 }
306
307 /**
308 * Returns the content type for the specified tab tag.
309 */
310 public AppsCustomizePagedView.ContentType getContentTypeForTabTag(String tag) {
311 if (tag.equals(APPS_TAB_TAG)) {
312 return AppsCustomizePagedView.ContentType.Applications;
313 } else if (tag.equals(WIDGETS_TAB_TAG)) {
314 return AppsCustomizePagedView.ContentType.Widgets;
315 }
316 return AppsCustomizePagedView.ContentType.Applications;
317 }
318
319 /**
Winson Chungfc79c802011-05-02 13:35:34 -0700320 * Returns the tab tag for a given content type.
321 */
322 public String getTabTagForContentType(AppsCustomizePagedView.ContentType type) {
323 if (type == AppsCustomizePagedView.ContentType.Applications) {
324 return APPS_TAB_TAG;
325 } else if (type == AppsCustomizePagedView.ContentType.Widgets) {
326 return WIDGETS_TAB_TAG;
327 }
328 return APPS_TAB_TAG;
329 }
330
331 /**
Winson Chung785d2eb2011-04-14 16:08:02 -0700332 * Disable focus on anything under this view in the hierarchy if we are not visible.
333 */
334 @Override
335 public int getDescendantFocusability() {
336 if (getVisibility() != View.VISIBLE) {
337 return ViewGroup.FOCUS_BLOCK_DESCENDANTS;
338 }
339 return super.getDescendantFocusability();
340 }
341
Winson Chungc100e8e2011-08-09 16:02:43 -0700342 void reset() {
343 if (mInTransition) {
344 // Defer to after the transition to reset
345 mResetAfterTransition = true;
346 } else {
347 // Reset immediately
348 mAppsCustomizePane.reset();
349 }
350 }
351
Michael Jurka1899a362011-11-03 13:50:45 -0700352 private void enableAndBuildHardwareLayer() {
Michael Jurka19e0fc52011-07-22 18:00:21 -0700353 // isHardwareAccelerated() checks if we're attached to a window and if that
354 // window is HW accelerated-- we were sometimes not attached to a window
355 // and buildLayer was throwing an IllegalStateException
Michael Jurka1899a362011-11-03 13:50:45 -0700356 if (isHardwareAccelerated()) {
Winson Chungf0ea4d32011-06-06 14:27:16 -0700357 // Turn on hardware layers for performance
358 setLayerType(LAYER_TYPE_HARDWARE, null);
359
Michael Jurka1899a362011-11-03 13:50:45 -0700360 // force building the layer, so you don't get a blip early in an animation
361 // when the layer is created layer
Winson Chungf0ea4d32011-06-06 14:27:16 -0700362 buildLayer();
Michael Jurka39e5d172012-03-12 18:36:12 -0700363
364 // Let the GC system know that now is a good time to do any garbage
365 // collection; makes it less likely we'll get a GC during the all apps
366 // to workspace animation
367 System.gc();
Winson Chungf0ea4d32011-06-06 14:27:16 -0700368 }
Michael Jurka1899a362011-11-03 13:50:45 -0700369 }
370
Michael Jurka2a4b1a82011-12-07 14:00:02 -0800371 @Override
372 public View getContent() {
373 return mContent;
Michael Jurka1899a362011-11-03 13:50:45 -0700374 }
375
376 /* LauncherTransitionable overrides */
377 @Override
Michael Jurkaa35e35a2012-04-26 15:04:28 -0700378 public void onLauncherTransitionPrepare(Launcher l, boolean animated, boolean toWorkspace) {
379 mAppsCustomizePane.onLauncherTransitionPrepare(l, animated, toWorkspace);
Michael Jurka1899a362011-11-03 13:50:45 -0700380 mInTransition = true;
Winson Chung70442722012-02-10 15:43:22 -0800381 mTransitioningToWorkspace = toWorkspace;
Michael Jurka1899a362011-11-03 13:50:45 -0700382
Michael Jurkabed61d22012-02-14 22:51:29 -0800383 if (toWorkspace) {
384 // Going from All Apps -> Workspace
385 setVisibilityOfSiblingsWithLowerZOrder(VISIBLE);
Michael Jurkaa8352d22012-02-23 16:28:37 -0800386 // Stop the scrolling indicator - we don't want All Apps to be invalidating itself
387 // during the transition, especially since it has a hardware layer set on it
388 mAppsCustomizePane.cancelScrollingIndicatorAnimations();
Michael Jurkabed61d22012-02-14 22:51:29 -0800389 } else {
390 // Going from Workspace -> All Apps
391 mContent.setVisibility(VISIBLE);
Michael Jurka3d845e82011-11-15 17:04:31 -0800392
Michael Jurkae326f182011-11-21 14:05:46 -0800393 // Make sure the current page is loaded (we start loading the side pages after the
394 // transition to prevent slowing down the animation)
395 mAppsCustomizePane.loadAssociatedPages(mAppsCustomizePane.getCurrentPage(), true);
Michael Jurkabed61d22012-02-14 22:51:29 -0800396
397 if (!LauncherApplication.isScreenLarge()) {
398 mAppsCustomizePane.showScrollingIndicator(true);
399 }
Michael Jurka1899a362011-11-03 13:50:45 -0700400 }
401
Winson Chungc100e8e2011-08-09 16:02:43 -0700402 if (mResetAfterTransition) {
403 mAppsCustomizePane.reset();
404 mResetAfterTransition = false;
405 }
Michael Jurkaa35e35a2012-04-26 15:04:28 -0700406 }
Michael Jurkabed61d22012-02-14 22:51:29 -0800407
Michael Jurkaa35e35a2012-04-26 15:04:28 -0700408 @Override
409 public void onLauncherTransitionStart(Launcher l, boolean animated, boolean toWorkspace) {
Michael Jurkabed61d22012-02-14 22:51:29 -0800410 if (animated) {
411 enableAndBuildHardwareLayer();
412 }
Winson Chung785d2eb2011-04-14 16:08:02 -0700413 }
Winson Chungf0ea4d32011-06-06 14:27:16 -0700414
Winson Chung785d2eb2011-04-14 16:08:02 -0700415 @Override
Winson Chung70442722012-02-10 15:43:22 -0800416 public void onLauncherTransitionStep(Launcher l, float t) {
417 // Do nothing
418 }
419
420 @Override
Michael Jurkabed61d22012-02-14 22:51:29 -0800421 public void onLauncherTransitionEnd(Launcher l, boolean animated, boolean toWorkspace) {
Michael Jurka39e5d172012-03-12 18:36:12 -0700422 mAppsCustomizePane.onLauncherTransitionEnd(l, animated, toWorkspace);
Winson Chungc100e8e2011-08-09 16:02:43 -0700423 mInTransition = false;
Michael Jurkabed61d22012-02-14 22:51:29 -0800424 if (animated) {
Winson Chungf0ea4d32011-06-06 14:27:16 -0700425 setLayerType(LAYER_TYPE_NONE, null);
426 }
Winson Chung3ac74c52011-06-30 17:39:37 -0700427
Winson Chung7d7541e2011-09-16 20:14:36 -0700428 if (!toWorkspace) {
Michael Jurkabed61d22012-02-14 22:51:29 -0800429 // Going from Workspace -> All Apps
430 setVisibilityOfSiblingsWithLowerZOrder(INVISIBLE);
431
Winson Chung3f4e1422011-11-17 14:58:51 -0800432 // Dismiss the workspace cling and show the all apps cling (if not already shown)
Winson Chung7d7541e2011-09-16 20:14:36 -0700433 l.dismissWorkspaceCling(null);
Winson Chung3f4e1422011-11-17 14:58:51 -0800434 mAppsCustomizePane.showAllAppsCling();
Michael Jurkae326f182011-11-21 14:05:46 -0800435 // Make sure adjacent pages are loaded (we wait until after the transition to
436 // prevent slowing down the animation)
437 mAppsCustomizePane.loadAssociatedPages(mAppsCustomizePane.getCurrentPage());
Winson Chung7d7541e2011-09-16 20:14:36 -0700438
439 if (!LauncherApplication.isScreenLarge()) {
440 mAppsCustomizePane.hideScrollingIndicator(false);
441 }
Winson Chung5a808352011-06-27 19:08:49 -0700442 }
Winson Chung785d2eb2011-04-14 16:08:02 -0700443 }
Winson Chung70d72102011-08-12 11:24:35 -0700444
Michael Jurkabed61d22012-02-14 22:51:29 -0800445 private void setVisibilityOfSiblingsWithLowerZOrder(int visibility) {
446 ViewGroup parent = (ViewGroup) getParent();
Michael Jurkaaea1ce52012-04-12 11:23:21 -0700447 if (parent == null) return;
448
Michael Jurkabed61d22012-02-14 22:51:29 -0800449 final int count = parent.getChildCount();
450 if (!isChildrenDrawingOrderEnabled()) {
451 for (int i = 0; i < count; i++) {
452 final View child = parent.getChildAt(i);
453 if (child == this) {
454 break;
455 } else {
456 if (child.getVisibility() == GONE) {
457 continue;
458 }
459 child.setVisibility(visibility);
460 }
461 }
462 } else {
463 throw new RuntimeException("Failed; can't get z-order of views");
464 }
465 }
466
Michael Jurka2a4b1a82011-12-07 14:00:02 -0800467 public void onWindowVisible() {
Michael Jurkae326f182011-11-21 14:05:46 -0800468 if (getVisibility() == VISIBLE) {
469 mContent.setVisibility(VISIBLE);
470 // We unload the widget previews when the UI is hidden, so need to reload pages
471 // Load the current page synchronously, and the neighboring pages asynchronously
472 mAppsCustomizePane.loadAssociatedPages(mAppsCustomizePane.getCurrentPage(), true);
473 mAppsCustomizePane.loadAssociatedPages(mAppsCustomizePane.getCurrentPage());
474 }
475 }
476
477 public void onTrimMemory() {
478 mContent.setVisibility(GONE);
479 // Clear the widget pages of all their subviews - this will trigger the widget previews
480 // to delete their bitmaps
481 mAppsCustomizePane.clearAllWidgetPages();
482 }
483
Winson Chung70d72102011-08-12 11:24:35 -0700484 boolean isTransitioning() {
485 return mInTransition;
486 }
Winson Chung785d2eb2011-04-14 16:08:02 -0700487}