blob: 0199d01c6121014d7777c1987ceb2f2887744092 [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 Chung785d2eb2011-04-14 16:08:02 -070060 public AppsCustomizeTabHost(Context context, AttributeSet attrs) {
61 super(context, attrs);
62 mLayoutInflater = LayoutInflater.from(context);
Michael Jurka6cfafb92012-02-23 18:25:43 -080063 mRelayoutAndMakeVisible = new Runnable() {
64 public void run() {
65 mTabs.requestLayout();
66 mTabsContainer.setAlpha(1f);
67 }
68 };
Winson Chung785d2eb2011-04-14 16:08:02 -070069 }
70
Winson Chungf0ea4d32011-06-06 14:27:16 -070071 /**
Winson Chung5a808352011-06-27 19:08:49 -070072 * 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 Chungf0ea4d32011-06-06 14:27:16 -070076 */
Winson Chung5a808352011-06-27 19:08:49 -070077 private void setContentTypeImmediate(AppsCustomizePagedView.ContentType type) {
78 onTabChangedStart();
79 onTabChangedEnd(type);
80 }
Winson Chung55b65502011-05-26 12:03:43 -070081 void selectAppsTab() {
Winson Chung5a808352011-06-27 19:08:49 -070082 setContentTypeImmediate(AppsCustomizePagedView.ContentType.Applications);
Winson Chung55b65502011-05-26 12:03:43 -070083 setCurrentTabByTag(APPS_TAB_TAG);
84 }
85 void selectWidgetsTab() {
Winson Chung5a808352011-06-27 19:08:49 -070086 setContentTypeImmediate(AppsCustomizePagedView.ContentType.Widgets);
Winson Chung5a808352011-06-27 19:08:49 -070087 setCurrentTabByTag(WIDGETS_TAB_TAG);
88 }
Winson Chung55b65502011-05-26 12:03:43 -070089
Winson Chung785d2eb2011-04-14 16:08:02 -070090 /**
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 Chungfd3385f2011-06-15 19:51:24 -070098 final ViewGroup tabsContainer = (ViewGroup) findViewById(R.id.tabs_container);
Winson Chungfaa13252011-06-13 18:15:54 -070099 final TabWidget tabs = (TabWidget) findViewById(com.android.internal.R.id.tabs);
Winson Chung4179b4e2011-05-31 17:28:12 -0700100 final AppsCustomizePagedView appsCustomizePane = (AppsCustomizePagedView)
Winson Chung785d2eb2011-04-14 16:08:02 -0700101 findViewById(R.id.apps_customize_pane_content);
Winson Chungf0ea4d32011-06-06 14:27:16 -0700102 mTabs = tabs;
Winson Chungfd3385f2011-06-15 19:51:24 -0700103 mTabsContainer = tabsContainer;
Winson Chung4179b4e2011-05-31 17:28:12 -0700104 mAppsCustomizePane = appsCustomizePane;
Michael Jurka141dbd02011-11-03 13:50:45 -0700105 mAnimationBuffer = (FrameLayout) findViewById(R.id.animation_buffer);
Michael Jurka1899a362011-11-03 13:50:45 -0700106 mContent = (LinearLayout) findViewById(R.id.apps_customize_content);
Winson Chung4179b4e2011-05-31 17:28:12 -0700107 if (tabs == null || mAppsCustomizePane == null) throw new Resources.NotFoundException();
Winson Chung785d2eb2011-04-14 16:08:02 -0700108
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 Chung4179b4e2011-05-31 17:28:12 -0700113 return appsCustomizePane;
Winson Chung785d2eb2011-04-14 16:08:02 -0700114 }
115 };
116
117 // Create the tabs
118 TextView tabView;
Winson Chungd2c1f802011-10-14 12:26:54 -0700119 String label;
120 label = mContext.getString(R.string.all_apps_button_label);
Winson Chung785d2eb2011-04-14 16:08:02 -0700121 tabView = (TextView) mLayoutInflater.inflate(R.layout.tab_widget_indicator, tabs, false);
Winson Chungd2c1f802011-10-14 12:26:54 -0700122 tabView.setText(label);
123 tabView.setContentDescription(label);
Winson Chung785d2eb2011-04-14 16:08:02 -0700124 addTab(newTabSpec(APPS_TAB_TAG).setIndicator(tabView).setContent(contentFactory));
Winson Chungd2c1f802011-10-14 12:26:54 -0700125 label = mContext.getString(R.string.widgets_tab_label);
Winson Chung785d2eb2011-04-14 16:08:02 -0700126 tabView = (TextView) mLayoutInflater.inflate(R.layout.tab_widget_indicator, tabs, false);
Winson Chungd2c1f802011-10-14 12:26:54 -0700127 tabView.setText(label);
128 tabView.setContentDescription(label);
Winson Chung785d2eb2011-04-14 16:08:02 -0700129 addTab(newTabSpec(WIDGETS_TAB_TAG).setIndicator(tabView).setContent(contentFactory));
Winson Chung785d2eb2011-04-14 16:08:02 -0700130 setOnTabChangedListener(this);
Winson Chungfaa13252011-06-13 18:15:54 -0700131
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 Chungfd3385f2011-06-15 19:51:24 -0700138
139 // Hide the tab bar until we measure
140 mTabsContainer.setAlpha(0f);
Winson Chungf0ea4d32011-06-06 14:27:16 -0700141 }
Winson Chung785d2eb2011-04-14 16:08:02 -0700142
Winson Chungf0ea4d32011-06-06 14:27:16 -0700143 @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 Chungfd3385f2011-06-15 19:51:24 -0700150 int contentWidth = mAppsCustomizePane.getPageContentWidth();
Michael Jurka141dbd02011-11-03 13:50:45 -0700151 if (contentWidth > 0 && mTabs.getLayoutParams().width != contentWidth) {
152 // Set the width and show the tab bar
Winson Chungfd3385f2011-06-15 19:51:24 -0700153 mTabs.getLayoutParams().width = contentWidth;
Michael Jurka6cfafb92012-02-23 18:25:43 -0800154 post(mRelayoutAndMakeVisible);
Winson Chungfd3385f2011-06-15 19:51:24 -0700155 }
Winson Chungf0ea4d32011-06-06 14:27:16 -0700156 }
Winson Chungfd3385f2011-06-15 19:51:24 -0700157 super.onMeasure(widthMeasureSpec, heightMeasureSpec);
Winson Chung4179b4e2011-05-31 17:28:12 -0700158 }
159
Winson Chung70442722012-02-10 15:43:22 -0800160 public boolean onInterceptTouchEvent(MotionEvent ev) {
161 // If we are mid transition then intercept touch events here so we can ignore them
162 if (mInTransition) {
163 return true;
164 }
165 return super.onInterceptTouchEvent(ev);
166 };
167
Winson Chung4179b4e2011-05-31 17:28:12 -0700168 @Override
169 public boolean onTouchEvent(MotionEvent event) {
Winson Chung70442722012-02-10 15:43:22 -0800170 // Allow touch events to fall through if we are transitioning to the workspace
171 if (mInTransition) {
172 if (mTransitioningToWorkspace) {
173 return super.onTouchEvent(event);
174 }
175 }
176
Winson Chung4179b4e2011-05-31 17:28:12 -0700177 // Intercept all touch events up to the bottom of the AppsCustomizePane so they do not fall
178 // through to the workspace and trigger showWorkspace()
179 if (event.getY() < mAppsCustomizePane.getBottom()) {
180 return true;
181 }
182 return super.onTouchEvent(event);
Winson Chung785d2eb2011-04-14 16:08:02 -0700183 }
184
Winson Chung5a808352011-06-27 19:08:49 -0700185 private void onTabChangedStart() {
186 mAppsCustomizePane.hideScrollingIndicator(false);
187 }
Adam Cohen0cd3b642011-10-14 14:58:00 -0700188
Winson Chung097e6c72011-10-20 13:58:30 -0700189 private void reloadCurrentPage() {
190 if (!LauncherApplication.isScreenLarge()) {
Michael Jurkab737ee62011-11-15 15:57:22 -0800191 mAppsCustomizePane.flashScrollingIndicator(true);
Winson Chung097e6c72011-10-20 13:58:30 -0700192 }
193 mAppsCustomizePane.loadAssociatedPages(mAppsCustomizePane.getCurrentPage());
194 mAppsCustomizePane.requestFocus();
195 }
196
Winson Chung5a808352011-06-27 19:08:49 -0700197 private void onTabChangedEnd(AppsCustomizePagedView.ContentType type) {
198 mAppsCustomizePane.setContentType(type);
199 }
200
Winson Chung785d2eb2011-04-14 16:08:02 -0700201 @Override
202 public void onTabChanged(String tabId) {
Winson Chungb44b5242011-06-13 11:32:14 -0700203 final AppsCustomizePagedView.ContentType type = getContentTypeForTabTag(tabId);
Adam Cohen0cd3b642011-10-14 14:58:00 -0700204 if (mSuppressContentCallback) {
205 mSuppressContentCallback = false;
206 return;
Winson Chungb44b5242011-06-13 11:32:14 -0700207 }
Adam Cohen0cd3b642011-10-14 14:58:00 -0700208
209 // Animate the changing of the tab content by fading pages in and out
210 final Resources res = getResources();
211 final int duration = res.getInteger(R.integer.config_tabTransitionDuration);
212
213 // We post a runnable here because there is a delay while the first page is loading and
214 // the feedback from having changed the tab almost feels better than having it stick
215 post(new Runnable() {
216 @Override
217 public void run() {
Winson Chung097e6c72011-10-20 13:58:30 -0700218 if (mAppsCustomizePane.getMeasuredWidth() <= 0 ||
219 mAppsCustomizePane.getMeasuredHeight() <= 0) {
220 reloadCurrentPage();
221 return;
222 }
223
Michael Jurka141dbd02011-11-03 13:50:45 -0700224 // Take the visible pages and re-parent them temporarily to mAnimatorBuffer
225 // and then cross fade to the new pages
Winson Chungc6f10b92011-11-14 11:39:07 -0800226 int[] visiblePageRange = new int[2];
227 mAppsCustomizePane.getVisiblePages(visiblePageRange);
228 if (visiblePageRange[0] == -1 && visiblePageRange[1] == -1) {
229 // If we can't get the visible page ranges, then just skip the animation
230 reloadCurrentPage();
231 return;
232 }
233 ArrayList<View> visiblePages = new ArrayList<View>();
234 for (int i = visiblePageRange[0]; i <= visiblePageRange[1]; i++) {
235 visiblePages.add(mAppsCustomizePane.getPageAt(i));
236 }
Michael Jurka141dbd02011-11-03 13:50:45 -0700237
238 // We want the pages to be rendered in exactly the same way as they were when
239 // their parent was mAppsCustomizePane -- so set the scroll on mAnimationBuffer
240 // to be exactly the same as mAppsCustomizePane, and below, set the left/top
241 // parameters to be correct for each of the pages
242 mAnimationBuffer.scrollTo(mAppsCustomizePane.getScrollX(), 0);
243
Michael Jurka141dbd02011-11-03 13:50:45 -0700244 // mAppsCustomizePane renders its children in reverse order, so
245 // add the pages to mAnimationBuffer in reverse order to match that behavior
246 for (int i = visiblePages.size() - 1; i >= 0; i--) {
247 View child = visiblePages.get(i);
Winson Chungc6f10b92011-11-14 11:39:07 -0800248 if (child instanceof PagedViewCellLayout) {
249 ((PagedViewCellLayout) child).resetChildrenOnKeyListeners();
250 } else if (child instanceof PagedViewGridLayout) {
251 ((PagedViewGridLayout) child).resetChildrenOnKeyListeners();
252 }
Michael Jurka141dbd02011-11-03 13:50:45 -0700253 PagedViewWidget.setDeletePreviewsWhenDetachedFromWindow(false);
254 mAppsCustomizePane.removeView(child);
255 PagedViewWidget.setDeletePreviewsWhenDetachedFromWindow(true);
256 mAnimationBuffer.setAlpha(1f);
257 mAnimationBuffer.setVisibility(View.VISIBLE);
Winson Chung6e3cf902012-03-30 16:36:53 -0700258 LayoutParams p = new FrameLayout.LayoutParams(child.getMeasuredWidth(),
259 child.getMeasuredHeight());
Michael Jurka141dbd02011-11-03 13:50:45 -0700260 p.setMargins((int) child.getLeft(), (int) child.getTop(), 0, 0);
261 mAnimationBuffer.addView(child, p);
262 }
Adam Cohen0cd3b642011-10-14 14:58:00 -0700263
264 // Toggle the new content
265 onTabChangedStart();
266 onTabChangedEnd(type);
267
268 // Animate the transition
269 ObjectAnimator outAnim = ObjectAnimator.ofFloat(mAnimationBuffer, "alpha", 0f);
270 outAnim.addListener(new AnimatorListenerAdapter() {
271 @Override
272 public void onAnimationEnd(Animator animation) {
273 mAnimationBuffer.setVisibility(View.GONE);
Michael Jurka141dbd02011-11-03 13:50:45 -0700274 mAnimationBuffer.removeAllViews();
275 }
276 @Override
277 public void onAnimationCancel(Animator animation) {
278 mAnimationBuffer.setVisibility(View.GONE);
279 mAnimationBuffer.removeAllViews();
Adam Cohen0cd3b642011-10-14 14:58:00 -0700280 }
281 });
282 ObjectAnimator inAnim = ObjectAnimator.ofFloat(mAppsCustomizePane, "alpha", 1f);
283 inAnim.addListener(new AnimatorListenerAdapter() {
284 @Override
285 public void onAnimationEnd(Animator animation) {
Winson Chung097e6c72011-10-20 13:58:30 -0700286 reloadCurrentPage();
Adam Cohen0cd3b642011-10-14 14:58:00 -0700287 }
288 });
289 AnimatorSet animSet = new AnimatorSet();
290 animSet.playTogether(outAnim, inAnim);
291 animSet.setDuration(duration);
292 animSet.start();
293 }
294 });
295 }
296
297 public void setCurrentTabFromContent(AppsCustomizePagedView.ContentType type) {
298 mSuppressContentCallback = true;
299 setCurrentTabByTag(getTabTagForContentType(type));
Winson Chung785d2eb2011-04-14 16:08:02 -0700300 }
301
302 /**
303 * Returns the content type for the specified tab tag.
304 */
305 public AppsCustomizePagedView.ContentType getContentTypeForTabTag(String tag) {
306 if (tag.equals(APPS_TAB_TAG)) {
307 return AppsCustomizePagedView.ContentType.Applications;
308 } else if (tag.equals(WIDGETS_TAB_TAG)) {
309 return AppsCustomizePagedView.ContentType.Widgets;
310 }
311 return AppsCustomizePagedView.ContentType.Applications;
312 }
313
314 /**
Winson Chungfc79c802011-05-02 13:35:34 -0700315 * Returns the tab tag for a given content type.
316 */
317 public String getTabTagForContentType(AppsCustomizePagedView.ContentType type) {
318 if (type == AppsCustomizePagedView.ContentType.Applications) {
319 return APPS_TAB_TAG;
320 } else if (type == AppsCustomizePagedView.ContentType.Widgets) {
321 return WIDGETS_TAB_TAG;
322 }
323 return APPS_TAB_TAG;
324 }
325
326 /**
Winson Chung785d2eb2011-04-14 16:08:02 -0700327 * Disable focus on anything under this view in the hierarchy if we are not visible.
328 */
329 @Override
330 public int getDescendantFocusability() {
331 if (getVisibility() != View.VISIBLE) {
332 return ViewGroup.FOCUS_BLOCK_DESCENDANTS;
333 }
334 return super.getDescendantFocusability();
335 }
336
Winson Chungc100e8e2011-08-09 16:02:43 -0700337 void reset() {
338 if (mInTransition) {
339 // Defer to after the transition to reset
340 mResetAfterTransition = true;
341 } else {
342 // Reset immediately
343 mAppsCustomizePane.reset();
344 }
345 }
346
Michael Jurka1899a362011-11-03 13:50:45 -0700347 private void enableAndBuildHardwareLayer() {
Michael Jurka19e0fc52011-07-22 18:00:21 -0700348 // isHardwareAccelerated() checks if we're attached to a window and if that
349 // window is HW accelerated-- we were sometimes not attached to a window
350 // and buildLayer was throwing an IllegalStateException
Michael Jurka1899a362011-11-03 13:50:45 -0700351 if (isHardwareAccelerated()) {
Winson Chungf0ea4d32011-06-06 14:27:16 -0700352 // Turn on hardware layers for performance
353 setLayerType(LAYER_TYPE_HARDWARE, null);
354
Michael Jurka1899a362011-11-03 13:50:45 -0700355 // force building the layer, so you don't get a blip early in an animation
356 // when the layer is created layer
Winson Chungf0ea4d32011-06-06 14:27:16 -0700357 buildLayer();
Michael Jurka39e5d172012-03-12 18:36:12 -0700358
359 // Let the GC system know that now is a good time to do any garbage
360 // collection; makes it less likely we'll get a GC during the all apps
361 // to workspace animation
362 System.gc();
Winson Chungf0ea4d32011-06-06 14:27:16 -0700363 }
Michael Jurka1899a362011-11-03 13:50:45 -0700364 }
365
Michael Jurka2a4b1a82011-12-07 14:00:02 -0800366 @Override
367 public View getContent() {
368 return mContent;
Michael Jurka1899a362011-11-03 13:50:45 -0700369 }
370
371 /* LauncherTransitionable overrides */
372 @Override
Michael Jurkabed61d22012-02-14 22:51:29 -0800373 public void onLauncherTransitionStart(Launcher l, boolean animated, boolean toWorkspace) {
Michael Jurka39e5d172012-03-12 18:36:12 -0700374 mAppsCustomizePane.onLauncherTransitionStart(l, animated, toWorkspace);
Michael Jurka1899a362011-11-03 13:50:45 -0700375 mInTransition = true;
Winson Chung70442722012-02-10 15:43:22 -0800376 mTransitioningToWorkspace = toWorkspace;
Michael Jurka1899a362011-11-03 13:50:45 -0700377
Michael Jurkabed61d22012-02-14 22:51:29 -0800378 if (toWorkspace) {
379 // Going from All Apps -> Workspace
380 setVisibilityOfSiblingsWithLowerZOrder(VISIBLE);
Michael Jurkaa8352d22012-02-23 16:28:37 -0800381 // Stop the scrolling indicator - we don't want All Apps to be invalidating itself
382 // during the transition, especially since it has a hardware layer set on it
383 mAppsCustomizePane.cancelScrollingIndicatorAnimations();
Michael Jurkabed61d22012-02-14 22:51:29 -0800384 } else {
385 // Going from Workspace -> All Apps
386 mContent.setVisibility(VISIBLE);
Michael Jurka3d845e82011-11-15 17:04:31 -0800387
Michael Jurkae326f182011-11-21 14:05:46 -0800388 // Make sure the current page is loaded (we start loading the side pages after the
389 // transition to prevent slowing down the animation)
390 mAppsCustomizePane.loadAssociatedPages(mAppsCustomizePane.getCurrentPage(), true);
Michael Jurkabed61d22012-02-14 22:51:29 -0800391
392 if (!LauncherApplication.isScreenLarge()) {
393 mAppsCustomizePane.showScrollingIndicator(true);
394 }
Michael Jurka1899a362011-11-03 13:50:45 -0700395 }
396
Winson Chungc100e8e2011-08-09 16:02:43 -0700397 if (mResetAfterTransition) {
398 mAppsCustomizePane.reset();
399 mResetAfterTransition = false;
400 }
Michael Jurkabed61d22012-02-14 22:51:29 -0800401
402 if (animated) {
403 enableAndBuildHardwareLayer();
404 }
Winson Chung785d2eb2011-04-14 16:08:02 -0700405 }
Winson Chungf0ea4d32011-06-06 14:27:16 -0700406
Winson Chung785d2eb2011-04-14 16:08:02 -0700407 @Override
Winson Chung70442722012-02-10 15:43:22 -0800408 public void onLauncherTransitionStep(Launcher l, float t) {
409 // Do nothing
410 }
411
412 @Override
Michael Jurkabed61d22012-02-14 22:51:29 -0800413 public void onLauncherTransitionEnd(Launcher l, boolean animated, boolean toWorkspace) {
Michael Jurka39e5d172012-03-12 18:36:12 -0700414 mAppsCustomizePane.onLauncherTransitionEnd(l, animated, toWorkspace);
Winson Chungc100e8e2011-08-09 16:02:43 -0700415 mInTransition = false;
Michael Jurkabed61d22012-02-14 22:51:29 -0800416 if (animated) {
Winson Chungf0ea4d32011-06-06 14:27:16 -0700417 setLayerType(LAYER_TYPE_NONE, null);
418 }
Winson Chung3ac74c52011-06-30 17:39:37 -0700419
Winson Chung7d7541e2011-09-16 20:14:36 -0700420 if (!toWorkspace) {
Michael Jurkabed61d22012-02-14 22:51:29 -0800421 // Going from Workspace -> All Apps
422 setVisibilityOfSiblingsWithLowerZOrder(INVISIBLE);
423
Winson Chung3f4e1422011-11-17 14:58:51 -0800424 // Dismiss the workspace cling and show the all apps cling (if not already shown)
Winson Chung7d7541e2011-09-16 20:14:36 -0700425 l.dismissWorkspaceCling(null);
Winson Chung3f4e1422011-11-17 14:58:51 -0800426 mAppsCustomizePane.showAllAppsCling();
Michael Jurkae326f182011-11-21 14:05:46 -0800427 // Make sure adjacent pages are loaded (we wait until after the transition to
428 // prevent slowing down the animation)
429 mAppsCustomizePane.loadAssociatedPages(mAppsCustomizePane.getCurrentPage());
Winson Chung7d7541e2011-09-16 20:14:36 -0700430
431 if (!LauncherApplication.isScreenLarge()) {
432 mAppsCustomizePane.hideScrollingIndicator(false);
433 }
Winson Chung5a808352011-06-27 19:08:49 -0700434 }
Winson Chung785d2eb2011-04-14 16:08:02 -0700435 }
Winson Chung70d72102011-08-12 11:24:35 -0700436
Michael Jurkabed61d22012-02-14 22:51:29 -0800437 private void setVisibilityOfSiblingsWithLowerZOrder(int visibility) {
438 ViewGroup parent = (ViewGroup) getParent();
439 final int count = parent.getChildCount();
440 if (!isChildrenDrawingOrderEnabled()) {
441 for (int i = 0; i < count; i++) {
442 final View child = parent.getChildAt(i);
443 if (child == this) {
444 break;
445 } else {
446 if (child.getVisibility() == GONE) {
447 continue;
448 }
449 child.setVisibility(visibility);
450 }
451 }
452 } else {
453 throw new RuntimeException("Failed; can't get z-order of views");
454 }
455 }
456
Michael Jurka2a4b1a82011-12-07 14:00:02 -0800457 public void onWindowVisible() {
Michael Jurkae326f182011-11-21 14:05:46 -0800458 if (getVisibility() == VISIBLE) {
459 mContent.setVisibility(VISIBLE);
460 // We unload the widget previews when the UI is hidden, so need to reload pages
461 // Load the current page synchronously, and the neighboring pages asynchronously
462 mAppsCustomizePane.loadAssociatedPages(mAppsCustomizePane.getCurrentPage(), true);
463 mAppsCustomizePane.loadAssociatedPages(mAppsCustomizePane.getCurrentPage());
464 }
465 }
466
467 public void onTrimMemory() {
468 mContent.setVisibility(GONE);
469 // Clear the widget pages of all their subviews - this will trigger the widget previews
470 // to delete their bitmaps
471 mAppsCustomizePane.clearAllWidgetPages();
472 }
473
Winson Chung70d72102011-08-12 11:24:35 -0700474 boolean isTransitioning() {
475 return mInTransition;
476 }
Winson Chung785d2eb2011-04-14 16:08:02 -0700477}