blob: 152b215882a6efa822e81ec8b95ff0a01c157b02 [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;
58
Winson Chung785d2eb2011-04-14 16:08:02 -070059 public AppsCustomizeTabHost(Context context, AttributeSet attrs) {
60 super(context, attrs);
61 mLayoutInflater = LayoutInflater.from(context);
62 }
63
Winson Chungf0ea4d32011-06-06 14:27:16 -070064 /**
Winson Chung5a808352011-06-27 19:08:49 -070065 * Convenience methods to select specific tabs. We want to set the content type immediately
66 * in these cases, but we note that we still call setCurrentTabByTag() so that the tab view
67 * reflects the new content (but doesn't do the animation and logic associated with changing
68 * tabs manually).
Winson Chungf0ea4d32011-06-06 14:27:16 -070069 */
Winson Chung5a808352011-06-27 19:08:49 -070070 private void setContentTypeImmediate(AppsCustomizePagedView.ContentType type) {
71 onTabChangedStart();
72 onTabChangedEnd(type);
73 }
Winson Chung55b65502011-05-26 12:03:43 -070074 void selectAppsTab() {
Winson Chung5a808352011-06-27 19:08:49 -070075 setContentTypeImmediate(AppsCustomizePagedView.ContentType.Applications);
Winson Chung55b65502011-05-26 12:03:43 -070076 setCurrentTabByTag(APPS_TAB_TAG);
77 }
78 void selectWidgetsTab() {
Winson Chung5a808352011-06-27 19:08:49 -070079 setContentTypeImmediate(AppsCustomizePagedView.ContentType.Widgets);
Winson Chung5a808352011-06-27 19:08:49 -070080 setCurrentTabByTag(WIDGETS_TAB_TAG);
81 }
Winson Chung55b65502011-05-26 12:03:43 -070082
Winson Chung785d2eb2011-04-14 16:08:02 -070083 /**
84 * Setup the tab host and create all necessary tabs.
85 */
86 @Override
87 protected void onFinishInflate() {
88 // Setup the tab host
89 setup();
90
Winson Chungfd3385f2011-06-15 19:51:24 -070091 final ViewGroup tabsContainer = (ViewGroup) findViewById(R.id.tabs_container);
Winson Chungfaa13252011-06-13 18:15:54 -070092 final TabWidget tabs = (TabWidget) findViewById(com.android.internal.R.id.tabs);
Winson Chung4179b4e2011-05-31 17:28:12 -070093 final AppsCustomizePagedView appsCustomizePane = (AppsCustomizePagedView)
Winson Chung785d2eb2011-04-14 16:08:02 -070094 findViewById(R.id.apps_customize_pane_content);
Winson Chungf0ea4d32011-06-06 14:27:16 -070095 mTabs = tabs;
Winson Chungfd3385f2011-06-15 19:51:24 -070096 mTabsContainer = tabsContainer;
Winson Chung4179b4e2011-05-31 17:28:12 -070097 mAppsCustomizePane = appsCustomizePane;
Michael Jurka141dbd02011-11-03 13:50:45 -070098 mAnimationBuffer = (FrameLayout) findViewById(R.id.animation_buffer);
Michael Jurka1899a362011-11-03 13:50:45 -070099 mContent = (LinearLayout) findViewById(R.id.apps_customize_content);
Winson Chung4179b4e2011-05-31 17:28:12 -0700100 if (tabs == null || mAppsCustomizePane == null) throw new Resources.NotFoundException();
Winson Chung785d2eb2011-04-14 16:08:02 -0700101
102 // Configure the tabs content factory to return the same paged view (that we change the
103 // content filter on)
104 TabContentFactory contentFactory = new TabContentFactory() {
105 public View createTabContent(String tag) {
Winson Chung4179b4e2011-05-31 17:28:12 -0700106 return appsCustomizePane;
Winson Chung785d2eb2011-04-14 16:08:02 -0700107 }
108 };
109
110 // Create the tabs
111 TextView tabView;
Winson Chungd2c1f802011-10-14 12:26:54 -0700112 String label;
113 label = mContext.getString(R.string.all_apps_button_label);
Winson Chung785d2eb2011-04-14 16:08:02 -0700114 tabView = (TextView) mLayoutInflater.inflate(R.layout.tab_widget_indicator, tabs, false);
Winson Chungd2c1f802011-10-14 12:26:54 -0700115 tabView.setText(label);
116 tabView.setContentDescription(label);
Winson Chung785d2eb2011-04-14 16:08:02 -0700117 addTab(newTabSpec(APPS_TAB_TAG).setIndicator(tabView).setContent(contentFactory));
Winson Chungd2c1f802011-10-14 12:26:54 -0700118 label = mContext.getString(R.string.widgets_tab_label);
Winson Chung785d2eb2011-04-14 16:08:02 -0700119 tabView = (TextView) mLayoutInflater.inflate(R.layout.tab_widget_indicator, tabs, false);
Winson Chungd2c1f802011-10-14 12:26:54 -0700120 tabView.setText(label);
121 tabView.setContentDescription(label);
Winson Chung785d2eb2011-04-14 16:08:02 -0700122 addTab(newTabSpec(WIDGETS_TAB_TAG).setIndicator(tabView).setContent(contentFactory));
Winson Chung785d2eb2011-04-14 16:08:02 -0700123 setOnTabChangedListener(this);
Winson Chungfaa13252011-06-13 18:15:54 -0700124
125 // Setup the key listener to jump between the last tab view and the market icon
126 AppsCustomizeTabKeyEventListener keyListener = new AppsCustomizeTabKeyEventListener();
127 View lastTab = tabs.getChildTabViewAt(tabs.getTabCount() - 1);
128 lastTab.setOnKeyListener(keyListener);
129 View shopButton = findViewById(R.id.market_button);
130 shopButton.setOnKeyListener(keyListener);
Winson Chungfd3385f2011-06-15 19:51:24 -0700131
132 // Hide the tab bar until we measure
133 mTabsContainer.setAlpha(0f);
Winson Chungf0ea4d32011-06-06 14:27:16 -0700134 }
Winson Chung785d2eb2011-04-14 16:08:02 -0700135
Winson Chungf0ea4d32011-06-06 14:27:16 -0700136 @Override
137 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
138 boolean remeasureTabWidth = (mTabs.getLayoutParams().width <= 0);
139 super.onMeasure(widthMeasureSpec, heightMeasureSpec);
140
141 // Set the width of the tab list to the content width
142 if (remeasureTabWidth) {
Winson Chungfd3385f2011-06-15 19:51:24 -0700143 int contentWidth = mAppsCustomizePane.getPageContentWidth();
Michael Jurka141dbd02011-11-03 13:50:45 -0700144 if (contentWidth > 0 && mTabs.getLayoutParams().width != contentWidth) {
145 // Set the width and show the tab bar
Winson Chungfd3385f2011-06-15 19:51:24 -0700146 mTabs.getLayoutParams().width = contentWidth;
Michael Jurkac57b7a82011-08-09 22:02:20 -0700147 post(new Runnable() {
148 public void run() {
149 mTabs.requestLayout();
Winson Chung7ed37742011-09-08 15:45:51 -0700150 mTabsContainer.setAlpha(1f);
Michael Jurkac57b7a82011-08-09 22:02:20 -0700151 }
152 });
Winson Chungfd3385f2011-06-15 19:51:24 -0700153 }
Winson Chungf0ea4d32011-06-06 14:27:16 -0700154 }
Winson Chungfd3385f2011-06-15 19:51:24 -0700155 super.onMeasure(widthMeasureSpec, heightMeasureSpec);
Winson Chung4179b4e2011-05-31 17:28:12 -0700156 }
157
Winson Chung70442722012-02-10 15:43:22 -0800158 public boolean onInterceptTouchEvent(MotionEvent ev) {
159 // If we are mid transition then intercept touch events here so we can ignore them
160 if (mInTransition) {
161 return true;
162 }
163 return super.onInterceptTouchEvent(ev);
164 };
165
Winson Chung4179b4e2011-05-31 17:28:12 -0700166 @Override
167 public boolean onTouchEvent(MotionEvent event) {
Winson Chung70442722012-02-10 15:43:22 -0800168 // Allow touch events to fall through if we are transitioning to the workspace
169 if (mInTransition) {
170 if (mTransitioningToWorkspace) {
171 return super.onTouchEvent(event);
172 }
173 }
174
Winson Chung4179b4e2011-05-31 17:28:12 -0700175 // Intercept all touch events up to the bottom of the AppsCustomizePane so they do not fall
176 // through to the workspace and trigger showWorkspace()
177 if (event.getY() < mAppsCustomizePane.getBottom()) {
178 return true;
179 }
180 return super.onTouchEvent(event);
Winson Chung785d2eb2011-04-14 16:08:02 -0700181 }
182
Winson Chung5a808352011-06-27 19:08:49 -0700183 private void onTabChangedStart() {
184 mAppsCustomizePane.hideScrollingIndicator(false);
185 }
Adam Cohen0cd3b642011-10-14 14:58:00 -0700186
Winson Chung097e6c72011-10-20 13:58:30 -0700187 private void reloadCurrentPage() {
188 if (!LauncherApplication.isScreenLarge()) {
Michael Jurkab737ee62011-11-15 15:57:22 -0800189 mAppsCustomizePane.flashScrollingIndicator(true);
Winson Chung097e6c72011-10-20 13:58:30 -0700190 }
191 mAppsCustomizePane.loadAssociatedPages(mAppsCustomizePane.getCurrentPage());
192 mAppsCustomizePane.requestFocus();
193 }
194
Winson Chung5a808352011-06-27 19:08:49 -0700195 private void onTabChangedEnd(AppsCustomizePagedView.ContentType type) {
196 mAppsCustomizePane.setContentType(type);
197 }
198
Winson Chung785d2eb2011-04-14 16:08:02 -0700199 @Override
200 public void onTabChanged(String tabId) {
Winson Chungb44b5242011-06-13 11:32:14 -0700201 final AppsCustomizePagedView.ContentType type = getContentTypeForTabTag(tabId);
Adam Cohen0cd3b642011-10-14 14:58:00 -0700202 if (mSuppressContentCallback) {
203 mSuppressContentCallback = false;
204 return;
Winson Chungb44b5242011-06-13 11:32:14 -0700205 }
Adam Cohen0cd3b642011-10-14 14:58:00 -0700206
207 // Animate the changing of the tab content by fading pages in and out
208 final Resources res = getResources();
209 final int duration = res.getInteger(R.integer.config_tabTransitionDuration);
210
211 // We post a runnable here because there is a delay while the first page is loading and
212 // the feedback from having changed the tab almost feels better than having it stick
213 post(new Runnable() {
214 @Override
215 public void run() {
Winson Chung097e6c72011-10-20 13:58:30 -0700216 if (mAppsCustomizePane.getMeasuredWidth() <= 0 ||
217 mAppsCustomizePane.getMeasuredHeight() <= 0) {
218 reloadCurrentPage();
219 return;
220 }
221
Michael Jurka141dbd02011-11-03 13:50:45 -0700222 // Take the visible pages and re-parent them temporarily to mAnimatorBuffer
223 // and then cross fade to the new pages
Winson Chungc6f10b92011-11-14 11:39:07 -0800224 int[] visiblePageRange = new int[2];
225 mAppsCustomizePane.getVisiblePages(visiblePageRange);
226 if (visiblePageRange[0] == -1 && visiblePageRange[1] == -1) {
227 // If we can't get the visible page ranges, then just skip the animation
228 reloadCurrentPage();
229 return;
230 }
231 ArrayList<View> visiblePages = new ArrayList<View>();
232 for (int i = visiblePageRange[0]; i <= visiblePageRange[1]; i++) {
233 visiblePages.add(mAppsCustomizePane.getPageAt(i));
234 }
Michael Jurka141dbd02011-11-03 13:50:45 -0700235
236 // We want the pages to be rendered in exactly the same way as they were when
237 // their parent was mAppsCustomizePane -- so set the scroll on mAnimationBuffer
238 // to be exactly the same as mAppsCustomizePane, and below, set the left/top
239 // parameters to be correct for each of the pages
240 mAnimationBuffer.scrollTo(mAppsCustomizePane.getScrollX(), 0);
241
Michael Jurka141dbd02011-11-03 13:50:45 -0700242 // mAppsCustomizePane renders its children in reverse order, so
243 // add the pages to mAnimationBuffer in reverse order to match that behavior
244 for (int i = visiblePages.size() - 1; i >= 0; i--) {
245 View child = visiblePages.get(i);
Winson Chungc6f10b92011-11-14 11:39:07 -0800246 if (child instanceof PagedViewCellLayout) {
247 ((PagedViewCellLayout) child).resetChildrenOnKeyListeners();
248 } else if (child instanceof PagedViewGridLayout) {
249 ((PagedViewGridLayout) child).resetChildrenOnKeyListeners();
250 }
Michael Jurka141dbd02011-11-03 13:50:45 -0700251 PagedViewWidget.setDeletePreviewsWhenDetachedFromWindow(false);
252 mAppsCustomizePane.removeView(child);
253 PagedViewWidget.setDeletePreviewsWhenDetachedFromWindow(true);
254 mAnimationBuffer.setAlpha(1f);
255 mAnimationBuffer.setVisibility(View.VISIBLE);
256 LayoutParams p = new FrameLayout.LayoutParams(child.getWidth(),
257 child.getHeight());
258 p.setMargins((int) child.getLeft(), (int) child.getTop(), 0, 0);
259 mAnimationBuffer.addView(child, p);
260 }
Adam Cohen0cd3b642011-10-14 14:58:00 -0700261
262 // Toggle the new content
263 onTabChangedStart();
264 onTabChangedEnd(type);
265
266 // Animate the transition
267 ObjectAnimator outAnim = ObjectAnimator.ofFloat(mAnimationBuffer, "alpha", 0f);
268 outAnim.addListener(new AnimatorListenerAdapter() {
269 @Override
270 public void onAnimationEnd(Animator animation) {
271 mAnimationBuffer.setVisibility(View.GONE);
Michael Jurka141dbd02011-11-03 13:50:45 -0700272 mAnimationBuffer.removeAllViews();
273 }
274 @Override
275 public void onAnimationCancel(Animator animation) {
276 mAnimationBuffer.setVisibility(View.GONE);
277 mAnimationBuffer.removeAllViews();
Adam Cohen0cd3b642011-10-14 14:58:00 -0700278 }
279 });
280 ObjectAnimator inAnim = ObjectAnimator.ofFloat(mAppsCustomizePane, "alpha", 1f);
281 inAnim.addListener(new AnimatorListenerAdapter() {
282 @Override
283 public void onAnimationEnd(Animator animation) {
Winson Chung097e6c72011-10-20 13:58:30 -0700284 reloadCurrentPage();
Adam Cohen0cd3b642011-10-14 14:58:00 -0700285 }
286 });
287 AnimatorSet animSet = new AnimatorSet();
288 animSet.playTogether(outAnim, inAnim);
289 animSet.setDuration(duration);
290 animSet.start();
291 }
292 });
293 }
294
295 public void setCurrentTabFromContent(AppsCustomizePagedView.ContentType type) {
296 mSuppressContentCallback = true;
297 setCurrentTabByTag(getTabTagForContentType(type));
Winson Chung785d2eb2011-04-14 16:08:02 -0700298 }
299
300 /**
301 * Returns the content type for the specified tab tag.
302 */
303 public AppsCustomizePagedView.ContentType getContentTypeForTabTag(String tag) {
304 if (tag.equals(APPS_TAB_TAG)) {
305 return AppsCustomizePagedView.ContentType.Applications;
306 } else if (tag.equals(WIDGETS_TAB_TAG)) {
307 return AppsCustomizePagedView.ContentType.Widgets;
308 }
309 return AppsCustomizePagedView.ContentType.Applications;
310 }
311
312 /**
Winson Chungfc79c802011-05-02 13:35:34 -0700313 * Returns the tab tag for a given content type.
314 */
315 public String getTabTagForContentType(AppsCustomizePagedView.ContentType type) {
316 if (type == AppsCustomizePagedView.ContentType.Applications) {
317 return APPS_TAB_TAG;
318 } else if (type == AppsCustomizePagedView.ContentType.Widgets) {
319 return WIDGETS_TAB_TAG;
320 }
321 return APPS_TAB_TAG;
322 }
323
324 /**
Winson Chung785d2eb2011-04-14 16:08:02 -0700325 * Disable focus on anything under this view in the hierarchy if we are not visible.
326 */
327 @Override
328 public int getDescendantFocusability() {
329 if (getVisibility() != View.VISIBLE) {
330 return ViewGroup.FOCUS_BLOCK_DESCENDANTS;
331 }
332 return super.getDescendantFocusability();
333 }
334
Winson Chungc100e8e2011-08-09 16:02:43 -0700335 void reset() {
336 if (mInTransition) {
337 // Defer to after the transition to reset
338 mResetAfterTransition = true;
339 } else {
340 // Reset immediately
341 mAppsCustomizePane.reset();
342 }
343 }
344
Michael Jurka1899a362011-11-03 13:50:45 -0700345 private void enableAndBuildHardwareLayer() {
Michael Jurka19e0fc52011-07-22 18:00:21 -0700346 // isHardwareAccelerated() checks if we're attached to a window and if that
347 // window is HW accelerated-- we were sometimes not attached to a window
348 // and buildLayer was throwing an IllegalStateException
Michael Jurka1899a362011-11-03 13:50:45 -0700349 if (isHardwareAccelerated()) {
Winson Chungf0ea4d32011-06-06 14:27:16 -0700350 // Turn on hardware layers for performance
351 setLayerType(LAYER_TYPE_HARDWARE, null);
352
Michael Jurka1899a362011-11-03 13:50:45 -0700353 // force building the layer, so you don't get a blip early in an animation
354 // when the layer is created layer
Winson Chungf0ea4d32011-06-06 14:27:16 -0700355 buildLayer();
356 }
Michael Jurka1899a362011-11-03 13:50:45 -0700357 }
358
Michael Jurka2a4b1a82011-12-07 14:00:02 -0800359 @Override
360 public View getContent() {
361 return mContent;
Michael Jurka1899a362011-11-03 13:50:45 -0700362 }
363
364 /* LauncherTransitionable overrides */
365 @Override
Michael Jurkabed61d22012-02-14 22:51:29 -0800366 public void onLauncherTransitionStart(Launcher l, boolean animated, boolean toWorkspace) {
Michael Jurka1899a362011-11-03 13:50:45 -0700367 mInTransition = true;
Winson Chung70442722012-02-10 15:43:22 -0800368 mTransitioningToWorkspace = toWorkspace;
Michael Jurka1899a362011-11-03 13:50:45 -0700369
Michael Jurkabed61d22012-02-14 22:51:29 -0800370 if (toWorkspace) {
371 // Going from All Apps -> Workspace
372 setVisibilityOfSiblingsWithLowerZOrder(VISIBLE);
Michael Jurkaa8352d22012-02-23 16:28:37 -0800373 // Stop the scrolling indicator - we don't want All Apps to be invalidating itself
374 // during the transition, especially since it has a hardware layer set on it
375 mAppsCustomizePane.cancelScrollingIndicatorAnimations();
Michael Jurkabed61d22012-02-14 22:51:29 -0800376 } else {
377 // Going from Workspace -> All Apps
378 mContent.setVisibility(VISIBLE);
Michael Jurka3d845e82011-11-15 17:04:31 -0800379
Michael Jurkae326f182011-11-21 14:05:46 -0800380 // Make sure the current page is loaded (we start loading the side pages after the
381 // transition to prevent slowing down the animation)
382 mAppsCustomizePane.loadAssociatedPages(mAppsCustomizePane.getCurrentPage(), true);
Michael Jurkabed61d22012-02-14 22:51:29 -0800383
384 if (!LauncherApplication.isScreenLarge()) {
385 mAppsCustomizePane.showScrollingIndicator(true);
386 }
Michael Jurka1899a362011-11-03 13:50:45 -0700387 }
388
Winson Chungc100e8e2011-08-09 16:02:43 -0700389 if (mResetAfterTransition) {
390 mAppsCustomizePane.reset();
391 mResetAfterTransition = false;
392 }
Michael Jurkabed61d22012-02-14 22:51:29 -0800393
394 if (animated) {
395 enableAndBuildHardwareLayer();
396 }
Winson Chung785d2eb2011-04-14 16:08:02 -0700397 }
Winson Chungf0ea4d32011-06-06 14:27:16 -0700398
Winson Chung785d2eb2011-04-14 16:08:02 -0700399 @Override
Winson Chung70442722012-02-10 15:43:22 -0800400 public void onLauncherTransitionStep(Launcher l, float t) {
401 // Do nothing
402 }
403
404 @Override
Michael Jurkabed61d22012-02-14 22:51:29 -0800405 public void onLauncherTransitionEnd(Launcher l, boolean animated, boolean toWorkspace) {
Winson Chungc100e8e2011-08-09 16:02:43 -0700406 mInTransition = false;
Michael Jurkabed61d22012-02-14 22:51:29 -0800407 if (animated) {
Winson Chungf0ea4d32011-06-06 14:27:16 -0700408 setLayerType(LAYER_TYPE_NONE, null);
409 }
Winson Chung3ac74c52011-06-30 17:39:37 -0700410
Winson Chung7d7541e2011-09-16 20:14:36 -0700411 if (!toWorkspace) {
Michael Jurkabed61d22012-02-14 22:51:29 -0800412 // Going from Workspace -> All Apps
413 setVisibilityOfSiblingsWithLowerZOrder(INVISIBLE);
414
Winson Chung3f4e1422011-11-17 14:58:51 -0800415 // Dismiss the workspace cling and show the all apps cling (if not already shown)
Winson Chung7d7541e2011-09-16 20:14:36 -0700416 l.dismissWorkspaceCling(null);
Winson Chung3f4e1422011-11-17 14:58:51 -0800417 mAppsCustomizePane.showAllAppsCling();
Michael Jurkae326f182011-11-21 14:05:46 -0800418 // Make sure adjacent pages are loaded (we wait until after the transition to
419 // prevent slowing down the animation)
420 mAppsCustomizePane.loadAssociatedPages(mAppsCustomizePane.getCurrentPage());
Winson Chung7d7541e2011-09-16 20:14:36 -0700421
422 if (!LauncherApplication.isScreenLarge()) {
423 mAppsCustomizePane.hideScrollingIndicator(false);
424 }
Winson Chung5a808352011-06-27 19:08:49 -0700425 }
Winson Chung785d2eb2011-04-14 16:08:02 -0700426 }
Winson Chung70d72102011-08-12 11:24:35 -0700427
Michael Jurkabed61d22012-02-14 22:51:29 -0800428 private void setVisibilityOfSiblingsWithLowerZOrder(int visibility) {
429 ViewGroup parent = (ViewGroup) getParent();
430 final int count = parent.getChildCount();
431 if (!isChildrenDrawingOrderEnabled()) {
432 for (int i = 0; i < count; i++) {
433 final View child = parent.getChildAt(i);
434 if (child == this) {
435 break;
436 } else {
437 if (child.getVisibility() == GONE) {
438 continue;
439 }
440 child.setVisibility(visibility);
441 }
442 }
443 } else {
444 throw new RuntimeException("Failed; can't get z-order of views");
445 }
446 }
447
Michael Jurka2a4b1a82011-12-07 14:00:02 -0800448 public void onWindowVisible() {
Michael Jurkae326f182011-11-21 14:05:46 -0800449 if (getVisibility() == VISIBLE) {
450 mContent.setVisibility(VISIBLE);
451 // We unload the widget previews when the UI is hidden, so need to reload pages
452 // Load the current page synchronously, and the neighboring pages asynchronously
453 mAppsCustomizePane.loadAssociatedPages(mAppsCustomizePane.getCurrentPage(), true);
454 mAppsCustomizePane.loadAssociatedPages(mAppsCustomizePane.getCurrentPage());
455 }
456 }
457
458 public void onTrimMemory() {
459 mContent.setVisibility(GONE);
460 // Clear the widget pages of all their subviews - this will trigger the widget previews
461 // to delete their bitmaps
462 mAppsCustomizePane.clearAllWidgetPages();
463 }
464
Winson Chung70d72102011-08-12 11:24:35 -0700465 boolean isTransitioning() {
466 return mInTransition;
467 }
Winson Chung785d2eb2011-04-14 16:08:02 -0700468}