blob: 9fa2f32374b11bab7e49948b008555870f28c6d3 [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;
Winson Chungbfeac062012-06-06 15:56:08 -070026import android.util.Log;
Winson Chung785d2eb2011-04-14 16:08:02 -070027import android.view.LayoutInflater;
Winson Chung4179b4e2011-05-31 17:28:12 -070028import android.view.MotionEvent;
Winson Chung785d2eb2011-04-14 16:08:02 -070029import android.view.View;
30import android.view.ViewGroup;
Michael Jurka141dbd02011-11-03 13:50:45 -070031import android.widget.FrameLayout;
Michael Jurka1899a362011-11-03 13:50:45 -070032import android.widget.LinearLayout;
Winson Chung785d2eb2011-04-14 16:08:02 -070033import android.widget.TabHost;
Winson Chungfaa13252011-06-13 18:15:54 -070034import android.widget.TabWidget;
Winson Chung785d2eb2011-04-14 16:08:02 -070035import android.widget.TextView;
36
37import com.android.launcher.R;
38
Michael Jurka141dbd02011-11-03 13:50:45 -070039import java.util.ArrayList;
40
Winson Chung785d2eb2011-04-14 16:08:02 -070041public class AppsCustomizeTabHost extends TabHost implements LauncherTransitionable,
42 TabHost.OnTabChangeListener {
43 static final String LOG_TAG = "AppsCustomizeTabHost";
44
45 private static final String APPS_TAB_TAG = "APPS";
46 private static final String WIDGETS_TAB_TAG = "WIDGETS";
47
48 private final LayoutInflater mLayoutInflater;
Winson Chungf0ea4d32011-06-06 14:27:16 -070049 private ViewGroup mTabs;
Winson Chungfd3385f2011-06-15 19:51:24 -070050 private ViewGroup mTabsContainer;
Winson Chung4179b4e2011-05-31 17:28:12 -070051 private AppsCustomizePagedView mAppsCustomizePane;
Adam Cohen0cd3b642011-10-14 14:58:00 -070052 private boolean mSuppressContentCallback = false;
Michael Jurka141dbd02011-11-03 13:50:45 -070053 private FrameLayout mAnimationBuffer;
Michael Jurka1899a362011-11-03 13:50:45 -070054 private LinearLayout mContent;
Winson Chung785d2eb2011-04-14 16:08:02 -070055
Winson Chungc100e8e2011-08-09 16:02:43 -070056 private boolean mInTransition;
Winson Chung70442722012-02-10 15:43:22 -080057 private boolean mTransitioningToWorkspace;
Winson Chungc100e8e2011-08-09 16:02:43 -070058 private boolean mResetAfterTransition;
Michael Jurka6cfafb92012-02-23 18:25:43 -080059 private Runnable mRelayoutAndMakeVisible;
Winson Chungc100e8e2011-08-09 16:02:43 -070060
Winson Chungc7450e32012-04-17 17:34:08 -070061 private Launcher mLauncher;
62
Winson Chung785d2eb2011-04-14 16:08:02 -070063 public AppsCustomizeTabHost(Context context, AttributeSet attrs) {
64 super(context, attrs);
65 mLayoutInflater = LayoutInflater.from(context);
Michael Jurka6cfafb92012-02-23 18:25:43 -080066 mRelayoutAndMakeVisible = new Runnable() {
67 public void run() {
68 mTabs.requestLayout();
69 mTabsContainer.setAlpha(1f);
70 }
71 };
Winson Chung785d2eb2011-04-14 16:08:02 -070072 }
73
Winson Chungc7450e32012-04-17 17:34:08 -070074 public void setup(Launcher launcher) {
75 mLauncher = launcher;
76 }
77
Winson Chungf0ea4d32011-06-06 14:27:16 -070078 /**
Winson Chung5a808352011-06-27 19:08:49 -070079 * Convenience methods to select specific tabs. We want to set the content type immediately
80 * in these cases, but we note that we still call setCurrentTabByTag() so that the tab view
81 * reflects the new content (but doesn't do the animation and logic associated with changing
82 * tabs manually).
Winson Chungf0ea4d32011-06-06 14:27:16 -070083 */
Winson Chung5a808352011-06-27 19:08:49 -070084 private void setContentTypeImmediate(AppsCustomizePagedView.ContentType type) {
85 onTabChangedStart();
86 onTabChangedEnd(type);
87 }
Winson Chung55b65502011-05-26 12:03:43 -070088 void selectAppsTab() {
Winson Chung5a808352011-06-27 19:08:49 -070089 setContentTypeImmediate(AppsCustomizePagedView.ContentType.Applications);
Winson Chung55b65502011-05-26 12:03:43 -070090 setCurrentTabByTag(APPS_TAB_TAG);
91 }
92 void selectWidgetsTab() {
Winson Chung5a808352011-06-27 19:08:49 -070093 setContentTypeImmediate(AppsCustomizePagedView.ContentType.Widgets);
Winson Chung5a808352011-06-27 19:08:49 -070094 setCurrentTabByTag(WIDGETS_TAB_TAG);
95 }
Winson Chung55b65502011-05-26 12:03:43 -070096
Winson Chung785d2eb2011-04-14 16:08:02 -070097 /**
98 * Setup the tab host and create all necessary tabs.
99 */
100 @Override
101 protected void onFinishInflate() {
102 // Setup the tab host
103 setup();
104
Winson Chungfd3385f2011-06-15 19:51:24 -0700105 final ViewGroup tabsContainer = (ViewGroup) findViewById(R.id.tabs_container);
Michael Jurka8b805b12012-04-18 14:23:14 -0700106 final TabWidget tabs = getTabWidget();
Winson Chung4179b4e2011-05-31 17:28:12 -0700107 final AppsCustomizePagedView appsCustomizePane = (AppsCustomizePagedView)
Winson Chung785d2eb2011-04-14 16:08:02 -0700108 findViewById(R.id.apps_customize_pane_content);
Winson Chungf0ea4d32011-06-06 14:27:16 -0700109 mTabs = tabs;
Winson Chungfd3385f2011-06-15 19:51:24 -0700110 mTabsContainer = tabsContainer;
Winson Chung4179b4e2011-05-31 17:28:12 -0700111 mAppsCustomizePane = appsCustomizePane;
Michael Jurka141dbd02011-11-03 13:50:45 -0700112 mAnimationBuffer = (FrameLayout) findViewById(R.id.animation_buffer);
Michael Jurka1899a362011-11-03 13:50:45 -0700113 mContent = (LinearLayout) findViewById(R.id.apps_customize_content);
Winson Chung4179b4e2011-05-31 17:28:12 -0700114 if (tabs == null || mAppsCustomizePane == null) throw new Resources.NotFoundException();
Winson Chung785d2eb2011-04-14 16:08:02 -0700115
116 // Configure the tabs content factory to return the same paged view (that we change the
117 // content filter on)
118 TabContentFactory contentFactory = new TabContentFactory() {
119 public View createTabContent(String tag) {
Winson Chung4179b4e2011-05-31 17:28:12 -0700120 return appsCustomizePane;
Winson Chung785d2eb2011-04-14 16:08:02 -0700121 }
122 };
123
124 // Create the tabs
125 TextView tabView;
Winson Chungd2c1f802011-10-14 12:26:54 -0700126 String label;
Michael Jurka8b805b12012-04-18 14:23:14 -0700127 label = getContext().getString(R.string.all_apps_button_label);
Winson Chung785d2eb2011-04-14 16:08:02 -0700128 tabView = (TextView) mLayoutInflater.inflate(R.layout.tab_widget_indicator, tabs, false);
Winson Chungd2c1f802011-10-14 12:26:54 -0700129 tabView.setText(label);
130 tabView.setContentDescription(label);
Winson Chung785d2eb2011-04-14 16:08:02 -0700131 addTab(newTabSpec(APPS_TAB_TAG).setIndicator(tabView).setContent(contentFactory));
Michael Jurka8b805b12012-04-18 14:23:14 -0700132 label = getContext().getString(R.string.widgets_tab_label);
Winson Chung785d2eb2011-04-14 16:08:02 -0700133 tabView = (TextView) mLayoutInflater.inflate(R.layout.tab_widget_indicator, tabs, false);
Winson Chungd2c1f802011-10-14 12:26:54 -0700134 tabView.setText(label);
135 tabView.setContentDescription(label);
Winson Chung785d2eb2011-04-14 16:08:02 -0700136 addTab(newTabSpec(WIDGETS_TAB_TAG).setIndicator(tabView).setContent(contentFactory));
Winson Chung785d2eb2011-04-14 16:08:02 -0700137 setOnTabChangedListener(this);
Winson Chungfaa13252011-06-13 18:15:54 -0700138
139 // Setup the key listener to jump between the last tab view and the market icon
140 AppsCustomizeTabKeyEventListener keyListener = new AppsCustomizeTabKeyEventListener();
141 View lastTab = tabs.getChildTabViewAt(tabs.getTabCount() - 1);
142 lastTab.setOnKeyListener(keyListener);
143 View shopButton = findViewById(R.id.market_button);
144 shopButton.setOnKeyListener(keyListener);
Winson Chungfd3385f2011-06-15 19:51:24 -0700145
146 // Hide the tab bar until we measure
147 mTabsContainer.setAlpha(0f);
Winson Chungf0ea4d32011-06-06 14:27:16 -0700148 }
Winson Chung785d2eb2011-04-14 16:08:02 -0700149
Winson Chungf0ea4d32011-06-06 14:27:16 -0700150 @Override
151 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
152 boolean remeasureTabWidth = (mTabs.getLayoutParams().width <= 0);
153 super.onMeasure(widthMeasureSpec, heightMeasureSpec);
154
155 // Set the width of the tab list to the content width
156 if (remeasureTabWidth) {
Winson Chungfd3385f2011-06-15 19:51:24 -0700157 int contentWidth = mAppsCustomizePane.getPageContentWidth();
Michael Jurka141dbd02011-11-03 13:50:45 -0700158 if (contentWidth > 0 && mTabs.getLayoutParams().width != contentWidth) {
159 // Set the width and show the tab bar
Winson Chungfd3385f2011-06-15 19:51:24 -0700160 mTabs.getLayoutParams().width = contentWidth;
Michael Jurka6cfafb92012-02-23 18:25:43 -0800161 post(mRelayoutAndMakeVisible);
Winson Chungfd3385f2011-06-15 19:51:24 -0700162 }
Winson Chungf0ea4d32011-06-06 14:27:16 -0700163 }
Winson Chungfd3385f2011-06-15 19:51:24 -0700164 super.onMeasure(widthMeasureSpec, heightMeasureSpec);
Winson Chung4179b4e2011-05-31 17:28:12 -0700165 }
166
Winson Chung70442722012-02-10 15:43:22 -0800167 public boolean onInterceptTouchEvent(MotionEvent ev) {
Winson Chungac08f4b2012-04-27 15:41:00 -0700168 // If we are mid transitioning to the workspace, then intercept touch events here so we
169 // can ignore them, otherwise we just let all apps handle the touch events.
170 if (mInTransition && mTransitioningToWorkspace) {
Winson Chung70442722012-02-10 15:43:22 -0800171 return true;
172 }
173 return super.onInterceptTouchEvent(ev);
174 };
175
Winson Chung4179b4e2011-05-31 17:28:12 -0700176 @Override
177 public boolean onTouchEvent(MotionEvent event) {
Winson Chungac08f4b2012-04-27 15:41:00 -0700178 // Allow touch events to fall through to the workspace if we are transitioning there
179 if (mInTransition && mTransitioningToWorkspace) {
Winson Chung21fadea2012-04-27 15:59:55 -0700180 return super.onTouchEvent(event);
Winson Chung70442722012-02-10 15:43:22 -0800181 }
182
Winson Chung4179b4e2011-05-31 17:28:12 -0700183 // Intercept all touch events up to the bottom of the AppsCustomizePane so they do not fall
184 // through to the workspace and trigger showWorkspace()
185 if (event.getY() < mAppsCustomizePane.getBottom()) {
186 return true;
187 }
188 return super.onTouchEvent(event);
Winson Chung785d2eb2011-04-14 16:08:02 -0700189 }
190
Winson Chung5a808352011-06-27 19:08:49 -0700191 private void onTabChangedStart() {
192 mAppsCustomizePane.hideScrollingIndicator(false);
193 }
Adam Cohen0cd3b642011-10-14 14:58:00 -0700194
Winson Chung097e6c72011-10-20 13:58:30 -0700195 private void reloadCurrentPage() {
196 if (!LauncherApplication.isScreenLarge()) {
Michael Jurkab737ee62011-11-15 15:57:22 -0800197 mAppsCustomizePane.flashScrollingIndicator(true);
Winson Chung097e6c72011-10-20 13:58:30 -0700198 }
199 mAppsCustomizePane.loadAssociatedPages(mAppsCustomizePane.getCurrentPage());
200 mAppsCustomizePane.requestFocus();
201 }
202
Winson Chung5a808352011-06-27 19:08:49 -0700203 private void onTabChangedEnd(AppsCustomizePagedView.ContentType type) {
204 mAppsCustomizePane.setContentType(type);
205 }
206
Winson Chung785d2eb2011-04-14 16:08:02 -0700207 @Override
208 public void onTabChanged(String tabId) {
Winson Chungb44b5242011-06-13 11:32:14 -0700209 final AppsCustomizePagedView.ContentType type = getContentTypeForTabTag(tabId);
Adam Cohen0cd3b642011-10-14 14:58:00 -0700210 if (mSuppressContentCallback) {
211 mSuppressContentCallback = false;
212 return;
Winson Chungb44b5242011-06-13 11:32:14 -0700213 }
Adam Cohen0cd3b642011-10-14 14:58:00 -0700214
215 // Animate the changing of the tab content by fading pages in and out
216 final Resources res = getResources();
217 final int duration = res.getInteger(R.integer.config_tabTransitionDuration);
218
219 // We post a runnable here because there is a delay while the first page is loading and
220 // the feedback from having changed the tab almost feels better than having it stick
221 post(new Runnable() {
222 @Override
223 public void run() {
Winson Chung097e6c72011-10-20 13:58:30 -0700224 if (mAppsCustomizePane.getMeasuredWidth() <= 0 ||
225 mAppsCustomizePane.getMeasuredHeight() <= 0) {
226 reloadCurrentPage();
227 return;
228 }
229
Michael Jurka141dbd02011-11-03 13:50:45 -0700230 // Take the visible pages and re-parent them temporarily to mAnimatorBuffer
231 // and then cross fade to the new pages
Winson Chungc6f10b92011-11-14 11:39:07 -0800232 int[] visiblePageRange = new int[2];
233 mAppsCustomizePane.getVisiblePages(visiblePageRange);
234 if (visiblePageRange[0] == -1 && visiblePageRange[1] == -1) {
235 // If we can't get the visible page ranges, then just skip the animation
236 reloadCurrentPage();
237 return;
238 }
239 ArrayList<View> visiblePages = new ArrayList<View>();
240 for (int i = visiblePageRange[0]; i <= visiblePageRange[1]; i++) {
241 visiblePages.add(mAppsCustomizePane.getPageAt(i));
242 }
Michael Jurka141dbd02011-11-03 13:50:45 -0700243
244 // We want the pages to be rendered in exactly the same way as they were when
245 // their parent was mAppsCustomizePane -- so set the scroll on mAnimationBuffer
246 // to be exactly the same as mAppsCustomizePane, and below, set the left/top
247 // parameters to be correct for each of the pages
248 mAnimationBuffer.scrollTo(mAppsCustomizePane.getScrollX(), 0);
249
Michael Jurka141dbd02011-11-03 13:50:45 -0700250 // mAppsCustomizePane renders its children in reverse order, so
251 // add the pages to mAnimationBuffer in reverse order to match that behavior
252 for (int i = visiblePages.size() - 1; i >= 0; i--) {
253 View child = visiblePages.get(i);
Winson Chungc6f10b92011-11-14 11:39:07 -0800254 if (child instanceof PagedViewCellLayout) {
255 ((PagedViewCellLayout) child).resetChildrenOnKeyListeners();
256 } else if (child instanceof PagedViewGridLayout) {
257 ((PagedViewGridLayout) child).resetChildrenOnKeyListeners();
258 }
Michael Jurka141dbd02011-11-03 13:50:45 -0700259 PagedViewWidget.setDeletePreviewsWhenDetachedFromWindow(false);
260 mAppsCustomizePane.removeView(child);
261 PagedViewWidget.setDeletePreviewsWhenDetachedFromWindow(true);
262 mAnimationBuffer.setAlpha(1f);
263 mAnimationBuffer.setVisibility(View.VISIBLE);
Winson Chung6e3cf902012-03-30 16:36:53 -0700264 LayoutParams p = new FrameLayout.LayoutParams(child.getMeasuredWidth(),
265 child.getMeasuredHeight());
Michael Jurka141dbd02011-11-03 13:50:45 -0700266 p.setMargins((int) child.getLeft(), (int) child.getTop(), 0, 0);
267 mAnimationBuffer.addView(child, p);
268 }
Adam Cohen0cd3b642011-10-14 14:58:00 -0700269
270 // Toggle the new content
271 onTabChangedStart();
272 onTabChangedEnd(type);
273
274 // Animate the transition
275 ObjectAnimator outAnim = ObjectAnimator.ofFloat(mAnimationBuffer, "alpha", 0f);
276 outAnim.addListener(new AnimatorListenerAdapter() {
277 @Override
278 public void onAnimationEnd(Animator animation) {
279 mAnimationBuffer.setVisibility(View.GONE);
Michael Jurka141dbd02011-11-03 13:50:45 -0700280 mAnimationBuffer.removeAllViews();
281 }
282 @Override
283 public void onAnimationCancel(Animator animation) {
284 mAnimationBuffer.setVisibility(View.GONE);
285 mAnimationBuffer.removeAllViews();
Adam Cohen0cd3b642011-10-14 14:58:00 -0700286 }
287 });
288 ObjectAnimator inAnim = ObjectAnimator.ofFloat(mAppsCustomizePane, "alpha", 1f);
289 inAnim.addListener(new AnimatorListenerAdapter() {
290 @Override
291 public void onAnimationEnd(Animator animation) {
Winson Chung097e6c72011-10-20 13:58:30 -0700292 reloadCurrentPage();
Adam Cohen0cd3b642011-10-14 14:58:00 -0700293 }
294 });
295 AnimatorSet animSet = new AnimatorSet();
296 animSet.playTogether(outAnim, inAnim);
297 animSet.setDuration(duration);
298 animSet.start();
299 }
300 });
301 }
302
303 public void setCurrentTabFromContent(AppsCustomizePagedView.ContentType type) {
304 mSuppressContentCallback = true;
305 setCurrentTabByTag(getTabTagForContentType(type));
Winson Chung785d2eb2011-04-14 16:08:02 -0700306 }
307
308 /**
309 * Returns the content type for the specified tab tag.
310 */
311 public AppsCustomizePagedView.ContentType getContentTypeForTabTag(String tag) {
312 if (tag.equals(APPS_TAB_TAG)) {
313 return AppsCustomizePagedView.ContentType.Applications;
314 } else if (tag.equals(WIDGETS_TAB_TAG)) {
315 return AppsCustomizePagedView.ContentType.Widgets;
316 }
317 return AppsCustomizePagedView.ContentType.Applications;
318 }
319
320 /**
Winson Chungfc79c802011-05-02 13:35:34 -0700321 * Returns the tab tag for a given content type.
322 */
323 public String getTabTagForContentType(AppsCustomizePagedView.ContentType type) {
324 if (type == AppsCustomizePagedView.ContentType.Applications) {
325 return APPS_TAB_TAG;
326 } else if (type == AppsCustomizePagedView.ContentType.Widgets) {
327 return WIDGETS_TAB_TAG;
328 }
329 return APPS_TAB_TAG;
330 }
331
332 /**
Winson Chung785d2eb2011-04-14 16:08:02 -0700333 * Disable focus on anything under this view in the hierarchy if we are not visible.
334 */
335 @Override
336 public int getDescendantFocusability() {
337 if (getVisibility() != View.VISIBLE) {
338 return ViewGroup.FOCUS_BLOCK_DESCENDANTS;
339 }
340 return super.getDescendantFocusability();
341 }
342
Winson Chungc100e8e2011-08-09 16:02:43 -0700343 void reset() {
344 if (mInTransition) {
345 // Defer to after the transition to reset
346 mResetAfterTransition = true;
347 } else {
348 // Reset immediately
349 mAppsCustomizePane.reset();
350 }
351 }
352
Michael Jurka1899a362011-11-03 13:50:45 -0700353 private void enableAndBuildHardwareLayer() {
Michael Jurka19e0fc52011-07-22 18:00:21 -0700354 // isHardwareAccelerated() checks if we're attached to a window and if that
355 // window is HW accelerated-- we were sometimes not attached to a window
356 // and buildLayer was throwing an IllegalStateException
Michael Jurka1899a362011-11-03 13:50:45 -0700357 if (isHardwareAccelerated()) {
Winson Chungf0ea4d32011-06-06 14:27:16 -0700358 // Turn on hardware layers for performance
359 setLayerType(LAYER_TYPE_HARDWARE, null);
360
Michael Jurka1899a362011-11-03 13:50:45 -0700361 // force building the layer, so you don't get a blip early in an animation
362 // when the layer is created layer
Winson Chungf0ea4d32011-06-06 14:27:16 -0700363 buildLayer();
Michael Jurka39e5d172012-03-12 18:36:12 -0700364
365 // Let the GC system know that now is a good time to do any garbage
366 // collection; makes it less likely we'll get a GC during the all apps
367 // to workspace animation
368 System.gc();
Winson Chungf0ea4d32011-06-06 14:27:16 -0700369 }
Michael Jurka1899a362011-11-03 13:50:45 -0700370 }
371
Michael Jurka2a4b1a82011-12-07 14:00:02 -0800372 @Override
373 public View getContent() {
374 return mContent;
Michael Jurka1899a362011-11-03 13:50:45 -0700375 }
376
377 /* LauncherTransitionable overrides */
378 @Override
Michael Jurkaa35e35a2012-04-26 15:04:28 -0700379 public void onLauncherTransitionPrepare(Launcher l, boolean animated, boolean toWorkspace) {
380 mAppsCustomizePane.onLauncherTransitionPrepare(l, animated, toWorkspace);
Michael Jurka1899a362011-11-03 13:50:45 -0700381 mInTransition = true;
Winson Chung70442722012-02-10 15:43:22 -0800382 mTransitioningToWorkspace = toWorkspace;
Michael Jurka1899a362011-11-03 13:50:45 -0700383
Michael Jurkabed61d22012-02-14 22:51:29 -0800384 if (toWorkspace) {
385 // Going from All Apps -> Workspace
386 setVisibilityOfSiblingsWithLowerZOrder(VISIBLE);
Michael Jurkaa8352d22012-02-23 16:28:37 -0800387 // Stop the scrolling indicator - we don't want All Apps to be invalidating itself
388 // during the transition, especially since it has a hardware layer set on it
389 mAppsCustomizePane.cancelScrollingIndicatorAnimations();
Michael Jurkabed61d22012-02-14 22:51:29 -0800390 } else {
391 // Going from Workspace -> All Apps
392 mContent.setVisibility(VISIBLE);
Michael Jurka3d845e82011-11-15 17:04:31 -0800393
Michael Jurkae326f182011-11-21 14:05:46 -0800394 // Make sure the current page is loaded (we start loading the side pages after the
395 // transition to prevent slowing down the animation)
396 mAppsCustomizePane.loadAssociatedPages(mAppsCustomizePane.getCurrentPage(), true);
Michael Jurkabed61d22012-02-14 22:51:29 -0800397
398 if (!LauncherApplication.isScreenLarge()) {
399 mAppsCustomizePane.showScrollingIndicator(true);
400 }
Michael Jurka1899a362011-11-03 13:50:45 -0700401 }
402
Winson Chungc100e8e2011-08-09 16:02:43 -0700403 if (mResetAfterTransition) {
404 mAppsCustomizePane.reset();
405 mResetAfterTransition = false;
406 }
Michael Jurkaa35e35a2012-04-26 15:04:28 -0700407 }
Michael Jurkabed61d22012-02-14 22:51:29 -0800408
Michael Jurkaa35e35a2012-04-26 15:04:28 -0700409 @Override
410 public void onLauncherTransitionStart(Launcher l, boolean animated, boolean toWorkspace) {
Michael Jurkabed61d22012-02-14 22:51:29 -0800411 if (animated) {
412 enableAndBuildHardwareLayer();
413 }
Winson Chung785d2eb2011-04-14 16:08:02 -0700414 }
Winson Chungf0ea4d32011-06-06 14:27:16 -0700415
Winson Chung785d2eb2011-04-14 16:08:02 -0700416 @Override
Winson Chung70442722012-02-10 15:43:22 -0800417 public void onLauncherTransitionStep(Launcher l, float t) {
418 // Do nothing
419 }
420
421 @Override
Michael Jurkabed61d22012-02-14 22:51:29 -0800422 public void onLauncherTransitionEnd(Launcher l, boolean animated, boolean toWorkspace) {
Michael Jurka39e5d172012-03-12 18:36:12 -0700423 mAppsCustomizePane.onLauncherTransitionEnd(l, animated, toWorkspace);
Winson Chungc100e8e2011-08-09 16:02:43 -0700424 mInTransition = false;
Michael Jurkabed61d22012-02-14 22:51:29 -0800425 if (animated) {
Winson Chungf0ea4d32011-06-06 14:27:16 -0700426 setLayerType(LAYER_TYPE_NONE, null);
427 }
Winson Chung3ac74c52011-06-30 17:39:37 -0700428
Winson Chung7d7541e2011-09-16 20:14:36 -0700429 if (!toWorkspace) {
Michael Jurkabed61d22012-02-14 22:51:29 -0800430 // Going from Workspace -> All Apps
431 setVisibilityOfSiblingsWithLowerZOrder(INVISIBLE);
432
Winson Chung3f4e1422011-11-17 14:58:51 -0800433 // Dismiss the workspace cling and show the all apps cling (if not already shown)
Winson Chung7d7541e2011-09-16 20:14:36 -0700434 l.dismissWorkspaceCling(null);
Winson Chung3f4e1422011-11-17 14:58:51 -0800435 mAppsCustomizePane.showAllAppsCling();
Michael Jurkae326f182011-11-21 14:05:46 -0800436 // Make sure adjacent pages are loaded (we wait until after the transition to
437 // prevent slowing down the animation)
438 mAppsCustomizePane.loadAssociatedPages(mAppsCustomizePane.getCurrentPage());
Winson Chung7d7541e2011-09-16 20:14:36 -0700439
440 if (!LauncherApplication.isScreenLarge()) {
441 mAppsCustomizePane.hideScrollingIndicator(false);
442 }
Winson Chung5a808352011-06-27 19:08:49 -0700443 }
Winson Chung785d2eb2011-04-14 16:08:02 -0700444 }
Winson Chung70d72102011-08-12 11:24:35 -0700445
Michael Jurkabed61d22012-02-14 22:51:29 -0800446 private void setVisibilityOfSiblingsWithLowerZOrder(int visibility) {
447 ViewGroup parent = (ViewGroup) getParent();
Michael Jurkaaea1ce52012-04-12 11:23:21 -0700448 if (parent == null) return;
449
Michael Jurkabed61d22012-02-14 22:51:29 -0800450 final int count = parent.getChildCount();
451 if (!isChildrenDrawingOrderEnabled()) {
452 for (int i = 0; i < count; i++) {
453 final View child = parent.getChildAt(i);
454 if (child == this) {
455 break;
456 } else {
457 if (child.getVisibility() == GONE) {
458 continue;
459 }
460 child.setVisibility(visibility);
461 }
462 }
463 } else {
464 throw new RuntimeException("Failed; can't get z-order of views");
465 }
466 }
467
Michael Jurka2a4b1a82011-12-07 14:00:02 -0800468 public void onWindowVisible() {
Michael Jurkae326f182011-11-21 14:05:46 -0800469 if (getVisibility() == VISIBLE) {
470 mContent.setVisibility(VISIBLE);
471 // We unload the widget previews when the UI is hidden, so need to reload pages
472 // Load the current page synchronously, and the neighboring pages asynchronously
473 mAppsCustomizePane.loadAssociatedPages(mAppsCustomizePane.getCurrentPage(), true);
474 mAppsCustomizePane.loadAssociatedPages(mAppsCustomizePane.getCurrentPage());
475 }
476 }
477
478 public void onTrimMemory() {
479 mContent.setVisibility(GONE);
480 // Clear the widget pages of all their subviews - this will trigger the widget previews
481 // to delete their bitmaps
482 mAppsCustomizePane.clearAllWidgetPages();
483 }
484
Winson Chung70d72102011-08-12 11:24:35 -0700485 boolean isTransitioning() {
486 return mInTransition;
487 }
Winson Chung785d2eb2011-04-14 16:08:02 -0700488}