blob: c1f6733f4e05c53b5d1b64d8a50460945aa5fd26 [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
Daniel Sandler325dc232013-06-05 22:57:57 -040017package com.android.launcher3;
Winson Chung785d2eb2011-04-14 16:08:02 -070018
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
Daniel Sandler325dc232013-06-05 22:57:57 -040036import com.android.launcher3.R;
Winson Chung785d2eb2011-04-14 16:08:02 -070037
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;
Michael Jurka141dbd02011-11-03 13:50:45 -070051 private FrameLayout mAnimationBuffer;
Michael Jurka1899a362011-11-03 13:50:45 -070052 private LinearLayout mContent;
Winson Chung785d2eb2011-04-14 16:08:02 -070053
Winson Chungc100e8e2011-08-09 16:02:43 -070054 private boolean mInTransition;
Winson Chung70442722012-02-10 15:43:22 -080055 private boolean mTransitioningToWorkspace;
Winson Chungc100e8e2011-08-09 16:02:43 -070056 private boolean mResetAfterTransition;
Michael Jurka6cfafb92012-02-23 18:25:43 -080057 private Runnable mRelayoutAndMakeVisible;
Winson Chungc100e8e2011-08-09 16:02:43 -070058
Winson Chung785d2eb2011-04-14 16:08:02 -070059 public AppsCustomizeTabHost(Context context, AttributeSet attrs) {
60 super(context, attrs);
61 mLayoutInflater = LayoutInflater.from(context);
Michael Jurka6cfafb92012-02-23 18:25:43 -080062 mRelayoutAndMakeVisible = new Runnable() {
63 public void run() {
64 mTabs.requestLayout();
65 mTabsContainer.setAlpha(1f);
66 }
67 };
Winson Chung785d2eb2011-04-14 16:08:02 -070068 }
69
Winson Chungf0ea4d32011-06-06 14:27:16 -070070 /**
Winson Chung5a808352011-06-27 19:08:49 -070071 * Convenience methods to select specific tabs. We want to set the content type immediately
72 * in these cases, but we note that we still call setCurrentTabByTag() so that the tab view
73 * reflects the new content (but doesn't do the animation and logic associated with changing
74 * tabs manually).
Winson Chungf0ea4d32011-06-06 14:27:16 -070075 */
Winson Chungc93e5ae2012-07-23 20:48:26 -070076 void setContentTypeImmediate(AppsCustomizePagedView.ContentType type) {
Winson Chungfa4086d2012-07-25 16:18:49 -070077 setOnTabChangedListener(null);
Winson Chung5a808352011-06-27 19:08:49 -070078 onTabChangedStart();
79 onTabChangedEnd(type);
Winson Chungfa4086d2012-07-25 16:18:49 -070080 setCurrentTabByTag(getTabTagForContentType(type));
81 setOnTabChangedListener(this);
Winson Chung5a808352011-06-27 19:08:49 -070082 }
Adam Cohen947dc542013-06-06 22:43:33 -070083
Winson Chung55b65502011-05-26 12:03:43 -070084 void selectWidgetsTab() {
Winson Chung5a808352011-06-27 19:08:49 -070085 setContentTypeImmediate(AppsCustomizePagedView.ContentType.Widgets);
Winson Chung5a808352011-06-27 19:08:49 -070086 }
Winson Chung55b65502011-05-26 12:03:43 -070087
Winson Chung785d2eb2011-04-14 16:08:02 -070088 /**
89 * Setup the tab host and create all necessary tabs.
90 */
91 @Override
92 protected void onFinishInflate() {
93 // Setup the tab host
94 setup();
95
Winson Chungfd3385f2011-06-15 19:51:24 -070096 final ViewGroup tabsContainer = (ViewGroup) findViewById(R.id.tabs_container);
Michael Jurka8b805b12012-04-18 14:23:14 -070097 final TabWidget tabs = getTabWidget();
Winson Chung4179b4e2011-05-31 17:28:12 -070098 final AppsCustomizePagedView appsCustomizePane = (AppsCustomizePagedView)
Winson Chung785d2eb2011-04-14 16:08:02 -070099 findViewById(R.id.apps_customize_pane_content);
Winson Chungf0ea4d32011-06-06 14:27:16 -0700100 mTabs = tabs;
Winson Chungfd3385f2011-06-15 19:51:24 -0700101 mTabsContainer = tabsContainer;
Winson Chung4179b4e2011-05-31 17:28:12 -0700102 mAppsCustomizePane = appsCustomizePane;
Michael Jurka141dbd02011-11-03 13:50:45 -0700103 mAnimationBuffer = (FrameLayout) findViewById(R.id.animation_buffer);
Michael Jurka1899a362011-11-03 13:50:45 -0700104 mContent = (LinearLayout) findViewById(R.id.apps_customize_content);
Winson Chung4179b4e2011-05-31 17:28:12 -0700105 if (tabs == null || mAppsCustomizePane == null) throw new Resources.NotFoundException();
Winson Chung785d2eb2011-04-14 16:08:02 -0700106
107 // Configure the tabs content factory to return the same paged view (that we change the
108 // content filter on)
109 TabContentFactory contentFactory = new TabContentFactory() {
110 public View createTabContent(String tag) {
Winson Chung4179b4e2011-05-31 17:28:12 -0700111 return appsCustomizePane;
Winson Chung785d2eb2011-04-14 16:08:02 -0700112 }
113 };
114
115 // Create the tabs
116 TextView tabView;
Winson Chungd2c1f802011-10-14 12:26:54 -0700117 String label;
Michael Jurka8b805b12012-04-18 14:23:14 -0700118 label = getContext().getString(R.string.all_apps_button_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);
Michael Jurka8b805b12012-04-18 14:23:14 -0700122 label = getContext().getString(R.string.widgets_tab_label);
Winson Chung785d2eb2011-04-14 16:08:02 -0700123 tabView = (TextView) mLayoutInflater.inflate(R.layout.tab_widget_indicator, tabs, false);
Winson Chungd2c1f802011-10-14 12:26:54 -0700124 tabView.setText(label);
125 tabView.setContentDescription(label);
Winson Chung785d2eb2011-04-14 16:08:02 -0700126 addTab(newTabSpec(WIDGETS_TAB_TAG).setIndicator(tabView).setContent(contentFactory));
Winson Chung785d2eb2011-04-14 16:08:02 -0700127 setOnTabChangedListener(this);
Winson Chungfaa13252011-06-13 18:15:54 -0700128
129 // Setup the key listener to jump between the last tab view and the market icon
130 AppsCustomizeTabKeyEventListener keyListener = new AppsCustomizeTabKeyEventListener();
131 View lastTab = tabs.getChildTabViewAt(tabs.getTabCount() - 1);
132 lastTab.setOnKeyListener(keyListener);
133 View shopButton = findViewById(R.id.market_button);
134 shopButton.setOnKeyListener(keyListener);
Winson Chungfd3385f2011-06-15 19:51:24 -0700135
136 // Hide the tab bar until we measure
137 mTabsContainer.setAlpha(0f);
Winson Chungf0ea4d32011-06-06 14:27:16 -0700138 }
Winson Chung785d2eb2011-04-14 16:08:02 -0700139
Winson Chungf0ea4d32011-06-06 14:27:16 -0700140 @Override
141 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
142 boolean remeasureTabWidth = (mTabs.getLayoutParams().width <= 0);
143 super.onMeasure(widthMeasureSpec, heightMeasureSpec);
144
145 // Set the width of the tab list to the content width
146 if (remeasureTabWidth) {
Winson Chungfd3385f2011-06-15 19:51:24 -0700147 int contentWidth = mAppsCustomizePane.getPageContentWidth();
Michael Jurka141dbd02011-11-03 13:50:45 -0700148 if (contentWidth > 0 && mTabs.getLayoutParams().width != contentWidth) {
149 // Set the width and show the tab bar
Winson Chungfd3385f2011-06-15 19:51:24 -0700150 mTabs.getLayoutParams().width = contentWidth;
Winson Chungc93e5ae2012-07-23 20:48:26 -0700151 mRelayoutAndMakeVisible.run();
Winson Chungfd3385f2011-06-15 19:51:24 -0700152 }
Winson Chungc93e5ae2012-07-23 20:48:26 -0700153
154 super.onMeasure(widthMeasureSpec, heightMeasureSpec);
Winson Chungf0ea4d32011-06-06 14:27:16 -0700155 }
Winson Chung4179b4e2011-05-31 17:28:12 -0700156 }
157
Winson Chung70442722012-02-10 15:43:22 -0800158 public boolean onInterceptTouchEvent(MotionEvent ev) {
Winson Chungac08f4b2012-04-27 15:41:00 -0700159 // If we are mid transitioning to the workspace, then intercept touch events here so we
160 // can ignore them, otherwise we just let all apps handle the touch events.
161 if (mInTransition && mTransitioningToWorkspace) {
Winson Chung70442722012-02-10 15:43:22 -0800162 return true;
163 }
164 return super.onInterceptTouchEvent(ev);
165 };
166
Winson Chung4179b4e2011-05-31 17:28:12 -0700167 @Override
168 public boolean onTouchEvent(MotionEvent event) {
Winson Chungac08f4b2012-04-27 15:41:00 -0700169 // Allow touch events to fall through to the workspace if we are transitioning there
170 if (mInTransition && mTransitioningToWorkspace) {
Winson Chung21fadea2012-04-27 15:59:55 -0700171 return super.onTouchEvent(event);
Winson Chung70442722012-02-10 15:43:22 -0800172 }
173
Winson Chung4179b4e2011-05-31 17:28:12 -0700174 // Intercept all touch events up to the bottom of the AppsCustomizePane so they do not fall
175 // through to the workspace and trigger showWorkspace()
176 if (event.getY() < mAppsCustomizePane.getBottom()) {
177 return true;
178 }
179 return super.onTouchEvent(event);
Winson Chung785d2eb2011-04-14 16:08:02 -0700180 }
181
Winson Chung5a808352011-06-27 19:08:49 -0700182 private void onTabChangedStart() {
183 mAppsCustomizePane.hideScrollingIndicator(false);
184 }
Adam Cohen0cd3b642011-10-14 14:58:00 -0700185
Winson Chung097e6c72011-10-20 13:58:30 -0700186 private void reloadCurrentPage() {
187 if (!LauncherApplication.isScreenLarge()) {
Michael Jurkab737ee62011-11-15 15:57:22 -0800188 mAppsCustomizePane.flashScrollingIndicator(true);
Winson Chung097e6c72011-10-20 13:58:30 -0700189 }
190 mAppsCustomizePane.loadAssociatedPages(mAppsCustomizePane.getCurrentPage());
191 mAppsCustomizePane.requestFocus();
192 }
193
Winson Chung5a808352011-06-27 19:08:49 -0700194 private void onTabChangedEnd(AppsCustomizePagedView.ContentType type) {
195 mAppsCustomizePane.setContentType(type);
196 }
197
Winson Chung785d2eb2011-04-14 16:08:02 -0700198 @Override
199 public void onTabChanged(String tabId) {
Winson Chungb44b5242011-06-13 11:32:14 -0700200 final AppsCustomizePagedView.ContentType type = getContentTypeForTabTag(tabId);
Adam Cohen0cd3b642011-10-14 14:58:00 -0700201
202 // Animate the changing of the tab content by fading pages in and out
203 final Resources res = getResources();
204 final int duration = res.getInteger(R.integer.config_tabTransitionDuration);
205
206 // We post a runnable here because there is a delay while the first page is loading and
207 // the feedback from having changed the tab almost feels better than having it stick
208 post(new Runnable() {
209 @Override
210 public void run() {
Winson Chung097e6c72011-10-20 13:58:30 -0700211 if (mAppsCustomizePane.getMeasuredWidth() <= 0 ||
212 mAppsCustomizePane.getMeasuredHeight() <= 0) {
213 reloadCurrentPage();
214 return;
215 }
216
Michael Jurka141dbd02011-11-03 13:50:45 -0700217 // Take the visible pages and re-parent them temporarily to mAnimatorBuffer
218 // and then cross fade to the new pages
Winson Chungc6f10b92011-11-14 11:39:07 -0800219 int[] visiblePageRange = new int[2];
220 mAppsCustomizePane.getVisiblePages(visiblePageRange);
221 if (visiblePageRange[0] == -1 && visiblePageRange[1] == -1) {
222 // If we can't get the visible page ranges, then just skip the animation
223 reloadCurrentPage();
224 return;
225 }
226 ArrayList<View> visiblePages = new ArrayList<View>();
227 for (int i = visiblePageRange[0]; i <= visiblePageRange[1]; i++) {
228 visiblePages.add(mAppsCustomizePane.getPageAt(i));
229 }
Michael Jurka141dbd02011-11-03 13:50:45 -0700230
231 // We want the pages to be rendered in exactly the same way as they were when
232 // their parent was mAppsCustomizePane -- so set the scroll on mAnimationBuffer
233 // to be exactly the same as mAppsCustomizePane, and below, set the left/top
234 // parameters to be correct for each of the pages
235 mAnimationBuffer.scrollTo(mAppsCustomizePane.getScrollX(), 0);
236
Michael Jurka141dbd02011-11-03 13:50:45 -0700237 // mAppsCustomizePane renders its children in reverse order, so
238 // add the pages to mAnimationBuffer in reverse order to match that behavior
239 for (int i = visiblePages.size() - 1; i >= 0; i--) {
240 View child = visiblePages.get(i);
Winson Chungc6f10b92011-11-14 11:39:07 -0800241 if (child instanceof PagedViewCellLayout) {
242 ((PagedViewCellLayout) child).resetChildrenOnKeyListeners();
243 } else if (child instanceof PagedViewGridLayout) {
244 ((PagedViewGridLayout) child).resetChildrenOnKeyListeners();
245 }
Michael Jurka141dbd02011-11-03 13:50:45 -0700246 PagedViewWidget.setDeletePreviewsWhenDetachedFromWindow(false);
247 mAppsCustomizePane.removeView(child);
248 PagedViewWidget.setDeletePreviewsWhenDetachedFromWindow(true);
249 mAnimationBuffer.setAlpha(1f);
250 mAnimationBuffer.setVisibility(View.VISIBLE);
Winson Chung6e3cf902012-03-30 16:36:53 -0700251 LayoutParams p = new FrameLayout.LayoutParams(child.getMeasuredWidth(),
252 child.getMeasuredHeight());
Michael Jurka141dbd02011-11-03 13:50:45 -0700253 p.setMargins((int) child.getLeft(), (int) child.getTop(), 0, 0);
254 mAnimationBuffer.addView(child, p);
255 }
Adam Cohen0cd3b642011-10-14 14:58:00 -0700256
257 // Toggle the new content
258 onTabChangedStart();
259 onTabChangedEnd(type);
260
261 // Animate the transition
Michael Jurka2ecf9952012-06-18 12:52:28 -0700262 ObjectAnimator outAnim = LauncherAnimUtils.ofFloat(mAnimationBuffer, "alpha", 0f);
Adam Cohen0cd3b642011-10-14 14:58:00 -0700263 outAnim.addListener(new AnimatorListenerAdapter() {
Michael Jurkaee8e99f2013-02-07 13:27:06 +0100264 private void clearAnimationBuffer() {
265 mAnimationBuffer.setVisibility(View.GONE);
266 PagedViewWidget.setRecyclePreviewsWhenDetachedFromWindow(false);
267 mAnimationBuffer.removeAllViews();
268 PagedViewWidget.setRecyclePreviewsWhenDetachedFromWindow(true);
269 }
Adam Cohen0cd3b642011-10-14 14:58:00 -0700270 @Override
271 public void onAnimationEnd(Animator animation) {
Michael Jurkaee8e99f2013-02-07 13:27:06 +0100272 clearAnimationBuffer();
Michael Jurka141dbd02011-11-03 13:50:45 -0700273 }
274 @Override
275 public void onAnimationCancel(Animator animation) {
Michael Jurkaee8e99f2013-02-07 13:27:06 +0100276 clearAnimationBuffer();
Adam Cohen0cd3b642011-10-14 14:58:00 -0700277 }
278 });
Michael Jurka2ecf9952012-06-18 12:52:28 -0700279 ObjectAnimator inAnim = LauncherAnimUtils.ofFloat(mAppsCustomizePane, "alpha", 1f);
Adam Cohen0cd3b642011-10-14 14:58:00 -0700280 inAnim.addListener(new AnimatorListenerAdapter() {
281 @Override
282 public void onAnimationEnd(Animator animation) {
Winson Chung097e6c72011-10-20 13:58:30 -0700283 reloadCurrentPage();
Adam Cohen0cd3b642011-10-14 14:58:00 -0700284 }
285 });
Michael Jurka7f9ddd82012-11-19 16:15:24 -0800286
287 final AnimatorSet animSet = LauncherAnimUtils.createAnimatorSet();
Adam Cohen0cd3b642011-10-14 14:58:00 -0700288 animSet.playTogether(outAnim, inAnim);
289 animSet.setDuration(duration);
Michael Jurkaf1ad6082013-03-13 12:55:46 +0100290 animSet.start();
Adam Cohen0cd3b642011-10-14 14:58:00 -0700291 }
292 });
293 }
294
295 public void setCurrentTabFromContent(AppsCustomizePagedView.ContentType type) {
Winson Chungfa4086d2012-07-25 16:18:49 -0700296 setOnTabChangedListener(null);
Adam Cohen0cd3b642011-10-14 14:58:00 -0700297 setCurrentTabByTag(getTabTagForContentType(type));
Winson Chungfa4086d2012-07-25 16:18:49 -0700298 setOnTabChangedListener(this);
Winson Chung785d2eb2011-04-14 16:08:02 -0700299 }
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 Chungfc79c802011-05-02 13:35:34 -0700314 * 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 Chung785d2eb2011-04-14 16:08:02 -0700326 * 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 Chungc100e8e2011-08-09 16:02:43 -0700336 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 Jurka1899a362011-11-03 13:50:45 -0700346 private void enableAndBuildHardwareLayer() {
Michael Jurka19e0fc52011-07-22 18:00:21 -0700347 // 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 Jurka1899a362011-11-03 13:50:45 -0700350 if (isHardwareAccelerated()) {
Winson Chungf0ea4d32011-06-06 14:27:16 -0700351 // Turn on hardware layers for performance
352 setLayerType(LAYER_TYPE_HARDWARE, null);
353
Michael Jurka1899a362011-11-03 13:50:45 -0700354 // force building the layer, so you don't get a blip early in an animation
355 // when the layer is created layer
Winson Chungf0ea4d32011-06-06 14:27:16 -0700356 buildLayer();
357 }
Michael Jurka1899a362011-11-03 13:50:45 -0700358 }
359
Michael Jurka2a4b1a82011-12-07 14:00:02 -0800360 @Override
361 public View getContent() {
362 return mContent;
Michael Jurka1899a362011-11-03 13:50:45 -0700363 }
364
365 /* LauncherTransitionable overrides */
366 @Override
Michael Jurkaa35e35a2012-04-26 15:04:28 -0700367 public void onLauncherTransitionPrepare(Launcher l, boolean animated, boolean toWorkspace) {
368 mAppsCustomizePane.onLauncherTransitionPrepare(l, animated, toWorkspace);
Michael Jurka1899a362011-11-03 13:50:45 -0700369 mInTransition = true;
Winson Chung70442722012-02-10 15:43:22 -0800370 mTransitioningToWorkspace = toWorkspace;
Michael Jurka1899a362011-11-03 13:50:45 -0700371
Michael Jurkabed61d22012-02-14 22:51:29 -0800372 if (toWorkspace) {
373 // Going from All Apps -> Workspace
374 setVisibilityOfSiblingsWithLowerZOrder(VISIBLE);
Michael Jurkaa8352d22012-02-23 16:28:37 -0800375 // Stop the scrolling indicator - we don't want All Apps to be invalidating itself
376 // during the transition, especially since it has a hardware layer set on it
377 mAppsCustomizePane.cancelScrollingIndicatorAnimations();
Michael Jurkabed61d22012-02-14 22:51:29 -0800378 } else {
379 // Going from Workspace -> All Apps
380 mContent.setVisibility(VISIBLE);
Michael Jurka3d845e82011-11-15 17:04:31 -0800381
Michael Jurkae326f182011-11-21 14:05:46 -0800382 // Make sure the current page is loaded (we start loading the side pages after the
383 // transition to prevent slowing down the animation)
384 mAppsCustomizePane.loadAssociatedPages(mAppsCustomizePane.getCurrentPage(), true);
Michael Jurkabed61d22012-02-14 22:51:29 -0800385
386 if (!LauncherApplication.isScreenLarge()) {
387 mAppsCustomizePane.showScrollingIndicator(true);
388 }
Michael Jurka1899a362011-11-03 13:50:45 -0700389 }
390
Winson Chungc100e8e2011-08-09 16:02:43 -0700391 if (mResetAfterTransition) {
392 mAppsCustomizePane.reset();
393 mResetAfterTransition = false;
394 }
Michael Jurkaa35e35a2012-04-26 15:04:28 -0700395 }
Michael Jurkabed61d22012-02-14 22:51:29 -0800396
Michael Jurkaa35e35a2012-04-26 15:04:28 -0700397 @Override
398 public void onLauncherTransitionStart(Launcher l, boolean animated, boolean toWorkspace) {
Michael Jurkabed61d22012-02-14 22:51:29 -0800399 if (animated) {
400 enableAndBuildHardwareLayer();
401 }
Winson Chung785d2eb2011-04-14 16:08:02 -0700402 }
Winson Chungf0ea4d32011-06-06 14:27:16 -0700403
Winson Chung785d2eb2011-04-14 16:08:02 -0700404 @Override
Winson Chung70442722012-02-10 15:43:22 -0800405 public void onLauncherTransitionStep(Launcher l, float t) {
406 // Do nothing
407 }
408
409 @Override
Michael Jurkabed61d22012-02-14 22:51:29 -0800410 public void onLauncherTransitionEnd(Launcher l, boolean animated, boolean toWorkspace) {
Michael Jurka39e5d172012-03-12 18:36:12 -0700411 mAppsCustomizePane.onLauncherTransitionEnd(l, animated, toWorkspace);
Winson Chungc100e8e2011-08-09 16:02:43 -0700412 mInTransition = false;
Michael Jurkabed61d22012-02-14 22:51:29 -0800413 if (animated) {
Winson Chungf0ea4d32011-06-06 14:27:16 -0700414 setLayerType(LAYER_TYPE_NONE, null);
415 }
Winson Chung3ac74c52011-06-30 17:39:37 -0700416
Winson Chung7d7541e2011-09-16 20:14:36 -0700417 if (!toWorkspace) {
Winson Chung7819abd2012-11-29 14:29:38 -0800418 // Dismiss the workspace cling
Winson Chung7d7541e2011-09-16 20:14:36 -0700419 l.dismissWorkspaceCling(null);
Winson Chung7819abd2012-11-29 14:29:38 -0800420 // Show the all apps cling (if not already shown)
Winson Chung3f4e1422011-11-17 14:58:51 -0800421 mAppsCustomizePane.showAllAppsCling();
Michael Jurkae326f182011-11-21 14:05:46 -0800422 // Make sure adjacent pages are loaded (we wait until after the transition to
423 // prevent slowing down the animation)
424 mAppsCustomizePane.loadAssociatedPages(mAppsCustomizePane.getCurrentPage());
Winson Chung7d7541e2011-09-16 20:14:36 -0700425
426 if (!LauncherApplication.isScreenLarge()) {
427 mAppsCustomizePane.hideScrollingIndicator(false);
428 }
Winson Chung7819abd2012-11-29 14:29:38 -0800429
430 // Going from Workspace -> All Apps
431 // NOTE: We should do this at the end since we check visibility state in some of the
432 // cling initialization/dismiss code above.
433 setVisibilityOfSiblingsWithLowerZOrder(INVISIBLE);
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();
Michael Jurkaaea1ce52012-04-12 11:23:21 -0700439 if (parent == null) return;
440
Michael Jurkabed61d22012-02-14 22:51:29 -0800441 final int count = parent.getChildCount();
442 if (!isChildrenDrawingOrderEnabled()) {
443 for (int i = 0; i < count; i++) {
444 final View child = parent.getChildAt(i);
445 if (child == this) {
446 break;
447 } else {
448 if (child.getVisibility() == GONE) {
449 continue;
450 }
451 child.setVisibility(visibility);
452 }
453 }
454 } else {
455 throw new RuntimeException("Failed; can't get z-order of views");
456 }
457 }
458
Michael Jurka2a4b1a82011-12-07 14:00:02 -0800459 public void onWindowVisible() {
Michael Jurkae326f182011-11-21 14:05:46 -0800460 if (getVisibility() == VISIBLE) {
461 mContent.setVisibility(VISIBLE);
462 // We unload the widget previews when the UI is hidden, so need to reload pages
463 // Load the current page synchronously, and the neighboring pages asynchronously
464 mAppsCustomizePane.loadAssociatedPages(mAppsCustomizePane.getCurrentPage(), true);
465 mAppsCustomizePane.loadAssociatedPages(mAppsCustomizePane.getCurrentPage());
466 }
467 }
468
469 public void onTrimMemory() {
470 mContent.setVisibility(GONE);
471 // Clear the widget pages of all their subviews - this will trigger the widget previews
472 // to delete their bitmaps
473 mAppsCustomizePane.clearAllWidgetPages();
474 }
475
Winson Chung70d72102011-08-12 11:24:35 -0700476 boolean isTransitioning() {
477 return mInTransition;
478 }
Winson Chung785d2eb2011-04-14 16:08:02 -0700479}