blob: 71219cd57539b2ba0bc32e977049595fa1d5e0d7 [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
Michael Jurka141dbd02011-11-03 13:50:45 -070036import java.util.ArrayList;
37
Winson Chung785d2eb2011-04-14 16:08:02 -070038public class AppsCustomizeTabHost extends TabHost implements LauncherTransitionable,
39 TabHost.OnTabChangeListener {
40 static final String LOG_TAG = "AppsCustomizeTabHost";
41
42 private static final String APPS_TAB_TAG = "APPS";
43 private static final String WIDGETS_TAB_TAG = "WIDGETS";
44
45 private final LayoutInflater mLayoutInflater;
Winson Chungf0ea4d32011-06-06 14:27:16 -070046 private ViewGroup mTabs;
Winson Chungfd3385f2011-06-15 19:51:24 -070047 private ViewGroup mTabsContainer;
Winson Chung4179b4e2011-05-31 17:28:12 -070048 private AppsCustomizePagedView mAppsCustomizePane;
Michael Jurka141dbd02011-11-03 13:50:45 -070049 private FrameLayout mAnimationBuffer;
Michael Jurka1899a362011-11-03 13:50:45 -070050 private LinearLayout mContent;
Winson Chung785d2eb2011-04-14 16:08:02 -070051
Winson Chungc100e8e2011-08-09 16:02:43 -070052 private boolean mInTransition;
Winson Chung70442722012-02-10 15:43:22 -080053 private boolean mTransitioningToWorkspace;
Winson Chungc100e8e2011-08-09 16:02:43 -070054 private boolean mResetAfterTransition;
Michael Jurka6cfafb92012-02-23 18:25:43 -080055 private Runnable mRelayoutAndMakeVisible;
Winson Chungc100e8e2011-08-09 16:02:43 -070056
Winson Chung785d2eb2011-04-14 16:08:02 -070057 public AppsCustomizeTabHost(Context context, AttributeSet attrs) {
58 super(context, attrs);
59 mLayoutInflater = LayoutInflater.from(context);
Michael Jurka6cfafb92012-02-23 18:25:43 -080060 mRelayoutAndMakeVisible = new Runnable() {
61 public void run() {
62 mTabs.requestLayout();
63 mTabsContainer.setAlpha(1f);
64 }
65 };
Winson Chung785d2eb2011-04-14 16:08:02 -070066 }
67
Winson Chungf0ea4d32011-06-06 14:27:16 -070068 /**
Winson Chung5a808352011-06-27 19:08:49 -070069 * Convenience methods to select specific tabs. We want to set the content type immediately
70 * in these cases, but we note that we still call setCurrentTabByTag() so that the tab view
71 * reflects the new content (but doesn't do the animation and logic associated with changing
72 * tabs manually).
Winson Chungf0ea4d32011-06-06 14:27:16 -070073 */
Winson Chungc93e5ae2012-07-23 20:48:26 -070074 void setContentTypeImmediate(AppsCustomizePagedView.ContentType type) {
Winson Chungfa4086d2012-07-25 16:18:49 -070075 setOnTabChangedListener(null);
Winson Chung5a808352011-06-27 19:08:49 -070076 onTabChangedStart();
77 onTabChangedEnd(type);
Winson Chungfa4086d2012-07-25 16:18:49 -070078 setCurrentTabByTag(getTabTagForContentType(type));
79 setOnTabChangedListener(this);
Winson Chung5a808352011-06-27 19:08:49 -070080 }
Adam Cohen947dc542013-06-06 22:43:33 -070081
Winson Chungc58497e2013-09-03 17:48:37 -070082 void selectAppsTab() {
83 setContentTypeImmediate(AppsCustomizePagedView.ContentType.Applications);
84 }
Winson Chung55b65502011-05-26 12:03:43 -070085 void selectWidgetsTab() {
Winson Chung5a808352011-06-27 19:08:49 -070086 setContentTypeImmediate(AppsCustomizePagedView.ContentType.Widgets);
Winson Chung5a808352011-06-27 19:08:49 -070087 }
Winson Chung55b65502011-05-26 12:03:43 -070088
Winson Chung785d2eb2011-04-14 16:08:02 -070089 /**
90 * Setup the tab host and create all necessary tabs.
91 */
92 @Override
93 protected void onFinishInflate() {
94 // Setup the tab host
95 setup();
96
Winson Chungfd3385f2011-06-15 19:51:24 -070097 final ViewGroup tabsContainer = (ViewGroup) findViewById(R.id.tabs_container);
Michael Jurka8b805b12012-04-18 14:23:14 -070098 final TabWidget tabs = getTabWidget();
Winson Chung4179b4e2011-05-31 17:28:12 -070099 final AppsCustomizePagedView appsCustomizePane = (AppsCustomizePagedView)
Winson Chung785d2eb2011-04-14 16:08:02 -0700100 findViewById(R.id.apps_customize_pane_content);
Winson Chungf0ea4d32011-06-06 14:27:16 -0700101 mTabs = tabs;
Winson Chungfd3385f2011-06-15 19:51:24 -0700102 mTabsContainer = tabsContainer;
Winson Chung4179b4e2011-05-31 17:28:12 -0700103 mAppsCustomizePane = appsCustomizePane;
Michael Jurka141dbd02011-11-03 13:50:45 -0700104 mAnimationBuffer = (FrameLayout) findViewById(R.id.animation_buffer);
Michael Jurka1899a362011-11-03 13:50:45 -0700105 mContent = (LinearLayout) findViewById(R.id.apps_customize_content);
Winson Chung4179b4e2011-05-31 17:28:12 -0700106 if (tabs == null || mAppsCustomizePane == null) throw new Resources.NotFoundException();
Winson Chung785d2eb2011-04-14 16:08:02 -0700107
108 // Configure the tabs content factory to return the same paged view (that we change the
109 // content filter on)
110 TabContentFactory contentFactory = new TabContentFactory() {
111 public View createTabContent(String tag) {
Winson Chung4179b4e2011-05-31 17:28:12 -0700112 return appsCustomizePane;
Winson Chung785d2eb2011-04-14 16:08:02 -0700113 }
114 };
115
116 // Create the tabs
117 TextView tabView;
Winson Chungd2c1f802011-10-14 12:26:54 -0700118 String label;
Michael Jurka8b805b12012-04-18 14:23:14 -0700119 label = getContext().getString(R.string.all_apps_button_label);
Winson Chung785d2eb2011-04-14 16:08:02 -0700120 tabView = (TextView) mLayoutInflater.inflate(R.layout.tab_widget_indicator, tabs, false);
Winson Chungd2c1f802011-10-14 12:26:54 -0700121 tabView.setText(label);
122 tabView.setContentDescription(label);
Winson Chungc58497e2013-09-03 17:48:37 -0700123 addTab(newTabSpec(APPS_TAB_TAG).setIndicator(tabView).setContent(contentFactory));
Michael Jurka8b805b12012-04-18 14:23:14 -0700124 label = getContext().getString(R.string.widgets_tab_label);
Winson Chung785d2eb2011-04-14 16:08:02 -0700125 tabView = (TextView) mLayoutInflater.inflate(R.layout.tab_widget_indicator, tabs, false);
Winson Chungd2c1f802011-10-14 12:26:54 -0700126 tabView.setText(label);
127 tabView.setContentDescription(label);
Winson Chung785d2eb2011-04-14 16:08:02 -0700128 addTab(newTabSpec(WIDGETS_TAB_TAG).setIndicator(tabView).setContent(contentFactory));
Winson Chung785d2eb2011-04-14 16:08:02 -0700129 setOnTabChangedListener(this);
Winson Chungfaa13252011-06-13 18:15:54 -0700130
131 // Setup the key listener to jump between the last tab view and the market icon
132 AppsCustomizeTabKeyEventListener keyListener = new AppsCustomizeTabKeyEventListener();
133 View lastTab = tabs.getChildTabViewAt(tabs.getTabCount() - 1);
134 lastTab.setOnKeyListener(keyListener);
135 View shopButton = findViewById(R.id.market_button);
136 shopButton.setOnKeyListener(keyListener);
Winson Chungfd3385f2011-06-15 19:51:24 -0700137
138 // Hide the tab bar until we measure
139 mTabsContainer.setAlpha(0f);
Winson Chungf0ea4d32011-06-06 14:27:16 -0700140 }
Winson Chung785d2eb2011-04-14 16:08:02 -0700141
Winson Chungf0ea4d32011-06-06 14:27:16 -0700142 @Override
143 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
144 boolean remeasureTabWidth = (mTabs.getLayoutParams().width <= 0);
145 super.onMeasure(widthMeasureSpec, heightMeasureSpec);
146
147 // Set the width of the tab list to the content width
148 if (remeasureTabWidth) {
Winson Chungfd3385f2011-06-15 19:51:24 -0700149 int contentWidth = mAppsCustomizePane.getPageContentWidth();
Michael Jurka141dbd02011-11-03 13:50:45 -0700150 if (contentWidth > 0 && mTabs.getLayoutParams().width != contentWidth) {
151 // Set the width and show the tab bar
Winson Chungfd3385f2011-06-15 19:51:24 -0700152 mTabs.getLayoutParams().width = contentWidth;
Winson Chungc93e5ae2012-07-23 20:48:26 -0700153 mRelayoutAndMakeVisible.run();
Winson Chungfd3385f2011-06-15 19:51:24 -0700154 }
Winson Chungc93e5ae2012-07-23 20:48:26 -0700155
156 super.onMeasure(widthMeasureSpec, heightMeasureSpec);
Winson Chungf0ea4d32011-06-06 14:27:16 -0700157 }
Winson Chung4179b4e2011-05-31 17:28:12 -0700158 }
159
Winson Chung70442722012-02-10 15:43:22 -0800160 public boolean onInterceptTouchEvent(MotionEvent ev) {
Winson Chungac08f4b2012-04-27 15:41:00 -0700161 // If we are mid transitioning to the workspace, then intercept touch events here so we
162 // can ignore them, otherwise we just let all apps handle the touch events.
163 if (mInTransition && mTransitioningToWorkspace) {
Winson Chung70442722012-02-10 15:43:22 -0800164 return true;
165 }
166 return super.onInterceptTouchEvent(ev);
167 };
168
Winson Chung4179b4e2011-05-31 17:28:12 -0700169 @Override
170 public boolean onTouchEvent(MotionEvent event) {
Winson Chungac08f4b2012-04-27 15:41:00 -0700171 // Allow touch events to fall through to the workspace if we are transitioning there
172 if (mInTransition && mTransitioningToWorkspace) {
Winson Chung21fadea2012-04-27 15:59:55 -0700173 return super.onTouchEvent(event);
Winson Chung70442722012-02-10 15:43:22 -0800174 }
175
Winson Chung4179b4e2011-05-31 17:28:12 -0700176 // Intercept all touch events up to the bottom of the AppsCustomizePane so they do not fall
177 // through to the workspace and trigger showWorkspace()
178 if (event.getY() < mAppsCustomizePane.getBottom()) {
179 return true;
180 }
181 return super.onTouchEvent(event);
Winson Chung785d2eb2011-04-14 16:08:02 -0700182 }
183
Winson Chung5a808352011-06-27 19:08:49 -0700184 private void onTabChangedStart() {
Winson Chung5a808352011-06-27 19:08:49 -0700185 }
Adam Cohen0cd3b642011-10-14 14:58:00 -0700186
Winson Chung097e6c72011-10-20 13:58:30 -0700187 private void reloadCurrentPage() {
Winson Chung097e6c72011-10-20 13:58:30 -0700188 mAppsCustomizePane.loadAssociatedPages(mAppsCustomizePane.getCurrentPage());
189 mAppsCustomizePane.requestFocus();
190 }
191
Winson Chung5a808352011-06-27 19:08:49 -0700192 private void onTabChangedEnd(AppsCustomizePagedView.ContentType type) {
193 mAppsCustomizePane.setContentType(type);
194 }
195
Winson Chung785d2eb2011-04-14 16:08:02 -0700196 @Override
197 public void onTabChanged(String tabId) {
Winson Chungb44b5242011-06-13 11:32:14 -0700198 final AppsCustomizePagedView.ContentType type = getContentTypeForTabTag(tabId);
Adam Cohen0cd3b642011-10-14 14:58:00 -0700199
200 // Animate the changing of the tab content by fading pages in and out
201 final Resources res = getResources();
202 final int duration = res.getInteger(R.integer.config_tabTransitionDuration);
203
204 // We post a runnable here because there is a delay while the first page is loading and
205 // the feedback from having changed the tab almost feels better than having it stick
206 post(new Runnable() {
207 @Override
208 public void run() {
Winson Chung097e6c72011-10-20 13:58:30 -0700209 if (mAppsCustomizePane.getMeasuredWidth() <= 0 ||
210 mAppsCustomizePane.getMeasuredHeight() <= 0) {
211 reloadCurrentPage();
212 return;
213 }
214
Michael Jurka141dbd02011-11-03 13:50:45 -0700215 // Take the visible pages and re-parent them temporarily to mAnimatorBuffer
216 // and then cross fade to the new pages
Winson Chungc6f10b92011-11-14 11:39:07 -0800217 int[] visiblePageRange = new int[2];
218 mAppsCustomizePane.getVisiblePages(visiblePageRange);
219 if (visiblePageRange[0] == -1 && visiblePageRange[1] == -1) {
220 // If we can't get the visible page ranges, then just skip the animation
221 reloadCurrentPage();
222 return;
223 }
224 ArrayList<View> visiblePages = new ArrayList<View>();
225 for (int i = visiblePageRange[0]; i <= visiblePageRange[1]; i++) {
226 visiblePages.add(mAppsCustomizePane.getPageAt(i));
227 }
Michael Jurka141dbd02011-11-03 13:50:45 -0700228
229 // We want the pages to be rendered in exactly the same way as they were when
230 // their parent was mAppsCustomizePane -- so set the scroll on mAnimationBuffer
231 // to be exactly the same as mAppsCustomizePane, and below, set the left/top
232 // parameters to be correct for each of the pages
233 mAnimationBuffer.scrollTo(mAppsCustomizePane.getScrollX(), 0);
234
Michael Jurka141dbd02011-11-03 13:50:45 -0700235 // mAppsCustomizePane renders its children in reverse order, so
236 // add the pages to mAnimationBuffer in reverse order to match that behavior
237 for (int i = visiblePages.size() - 1; i >= 0; i--) {
238 View child = visiblePages.get(i);
Winson Chungc58497e2013-09-03 17:48:37 -0700239 if (child instanceof AppsCustomizeCellLayout) {
240 ((AppsCustomizeCellLayout) child).resetChildrenOnKeyListeners();
Winson Chungc6f10b92011-11-14 11:39:07 -0800241 } else if (child instanceof PagedViewGridLayout) {
242 ((PagedViewGridLayout) child).resetChildrenOnKeyListeners();
243 }
Michael Jurka141dbd02011-11-03 13:50:45 -0700244 PagedViewWidget.setDeletePreviewsWhenDetachedFromWindow(false);
245 mAppsCustomizePane.removeView(child);
246 PagedViewWidget.setDeletePreviewsWhenDetachedFromWindow(true);
247 mAnimationBuffer.setAlpha(1f);
248 mAnimationBuffer.setVisibility(View.VISIBLE);
Winson Chung6e3cf902012-03-30 16:36:53 -0700249 LayoutParams p = new FrameLayout.LayoutParams(child.getMeasuredWidth(),
250 child.getMeasuredHeight());
Michael Jurka141dbd02011-11-03 13:50:45 -0700251 p.setMargins((int) child.getLeft(), (int) child.getTop(), 0, 0);
252 mAnimationBuffer.addView(child, p);
253 }
Adam Cohen0cd3b642011-10-14 14:58:00 -0700254
255 // Toggle the new content
256 onTabChangedStart();
257 onTabChangedEnd(type);
258
259 // Animate the transition
Michael Jurka2ecf9952012-06-18 12:52:28 -0700260 ObjectAnimator outAnim = LauncherAnimUtils.ofFloat(mAnimationBuffer, "alpha", 0f);
Adam Cohen0cd3b642011-10-14 14:58:00 -0700261 outAnim.addListener(new AnimatorListenerAdapter() {
Michael Jurkaee8e99f2013-02-07 13:27:06 +0100262 private void clearAnimationBuffer() {
263 mAnimationBuffer.setVisibility(View.GONE);
264 PagedViewWidget.setRecyclePreviewsWhenDetachedFromWindow(false);
265 mAnimationBuffer.removeAllViews();
266 PagedViewWidget.setRecyclePreviewsWhenDetachedFromWindow(true);
267 }
Adam Cohen0cd3b642011-10-14 14:58:00 -0700268 @Override
269 public void onAnimationEnd(Animator animation) {
Michael Jurkaee8e99f2013-02-07 13:27:06 +0100270 clearAnimationBuffer();
Michael Jurka141dbd02011-11-03 13:50:45 -0700271 }
272 @Override
273 public void onAnimationCancel(Animator animation) {
Michael Jurkaee8e99f2013-02-07 13:27:06 +0100274 clearAnimationBuffer();
Adam Cohen0cd3b642011-10-14 14:58:00 -0700275 }
276 });
Michael Jurka2ecf9952012-06-18 12:52:28 -0700277 ObjectAnimator inAnim = LauncherAnimUtils.ofFloat(mAppsCustomizePane, "alpha", 1f);
Adam Cohen0cd3b642011-10-14 14:58:00 -0700278 inAnim.addListener(new AnimatorListenerAdapter() {
279 @Override
280 public void onAnimationEnd(Animator animation) {
Winson Chung097e6c72011-10-20 13:58:30 -0700281 reloadCurrentPage();
Adam Cohen0cd3b642011-10-14 14:58:00 -0700282 }
283 });
Michael Jurka7f9ddd82012-11-19 16:15:24 -0800284
285 final AnimatorSet animSet = LauncherAnimUtils.createAnimatorSet();
Adam Cohen0cd3b642011-10-14 14:58:00 -0700286 animSet.playTogether(outAnim, inAnim);
287 animSet.setDuration(duration);
Michael Jurkaf1ad6082013-03-13 12:55:46 +0100288 animSet.start();
Adam Cohen0cd3b642011-10-14 14:58:00 -0700289 }
290 });
291 }
292
293 public void setCurrentTabFromContent(AppsCustomizePagedView.ContentType type) {
Winson Chungfa4086d2012-07-25 16:18:49 -0700294 setOnTabChangedListener(null);
Adam Cohen0cd3b642011-10-14 14:58:00 -0700295 setCurrentTabByTag(getTabTagForContentType(type));
Winson Chungfa4086d2012-07-25 16:18:49 -0700296 setOnTabChangedListener(this);
Winson Chung785d2eb2011-04-14 16:08:02 -0700297 }
298
299 /**
300 * Returns the content type for the specified tab tag.
301 */
302 public AppsCustomizePagedView.ContentType getContentTypeForTabTag(String tag) {
303 if (tag.equals(APPS_TAB_TAG)) {
304 return AppsCustomizePagedView.ContentType.Applications;
305 } else if (tag.equals(WIDGETS_TAB_TAG)) {
306 return AppsCustomizePagedView.ContentType.Widgets;
307 }
308 return AppsCustomizePagedView.ContentType.Applications;
309 }
310
311 /**
Winson Chungfc79c802011-05-02 13:35:34 -0700312 * Returns the tab tag for a given content type.
313 */
314 public String getTabTagForContentType(AppsCustomizePagedView.ContentType type) {
315 if (type == AppsCustomizePagedView.ContentType.Applications) {
316 return APPS_TAB_TAG;
317 } else if (type == AppsCustomizePagedView.ContentType.Widgets) {
318 return WIDGETS_TAB_TAG;
319 }
320 return APPS_TAB_TAG;
321 }
322
323 /**
Winson Chung785d2eb2011-04-14 16:08:02 -0700324 * Disable focus on anything under this view in the hierarchy if we are not visible.
325 */
326 @Override
327 public int getDescendantFocusability() {
328 if (getVisibility() != View.VISIBLE) {
329 return ViewGroup.FOCUS_BLOCK_DESCENDANTS;
330 }
331 return super.getDescendantFocusability();
332 }
333
Winson Chungc100e8e2011-08-09 16:02:43 -0700334 void reset() {
335 if (mInTransition) {
336 // Defer to after the transition to reset
337 mResetAfterTransition = true;
338 } else {
339 // Reset immediately
340 mAppsCustomizePane.reset();
341 }
342 }
343
Michael Jurka1899a362011-11-03 13:50:45 -0700344 private void enableAndBuildHardwareLayer() {
Michael Jurka19e0fc52011-07-22 18:00:21 -0700345 // isHardwareAccelerated() checks if we're attached to a window and if that
346 // window is HW accelerated-- we were sometimes not attached to a window
347 // and buildLayer was throwing an IllegalStateException
Michael Jurka1899a362011-11-03 13:50:45 -0700348 if (isHardwareAccelerated()) {
Winson Chungf0ea4d32011-06-06 14:27:16 -0700349 // Turn on hardware layers for performance
350 setLayerType(LAYER_TYPE_HARDWARE, null);
351
Michael Jurka1899a362011-11-03 13:50:45 -0700352 // force building the layer, so you don't get a blip early in an animation
353 // when the layer is created layer
Winson Chungf0ea4d32011-06-06 14:27:16 -0700354 buildLayer();
355 }
Michael Jurka1899a362011-11-03 13:50:45 -0700356 }
357
Michael Jurka2a4b1a82011-12-07 14:00:02 -0800358 @Override
359 public View getContent() {
360 return mContent;
Michael Jurka1899a362011-11-03 13:50:45 -0700361 }
362
363 /* LauncherTransitionable overrides */
364 @Override
Michael Jurkaa35e35a2012-04-26 15:04:28 -0700365 public void onLauncherTransitionPrepare(Launcher l, boolean animated, boolean toWorkspace) {
366 mAppsCustomizePane.onLauncherTransitionPrepare(l, animated, 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);
373 } else {
374 // Going from Workspace -> All Apps
375 mContent.setVisibility(VISIBLE);
Michael Jurka3d845e82011-11-15 17:04:31 -0800376
Michael Jurkae326f182011-11-21 14:05:46 -0800377 // Make sure the current page is loaded (we start loading the side pages after the
378 // transition to prevent slowing down the animation)
379 mAppsCustomizePane.loadAssociatedPages(mAppsCustomizePane.getCurrentPage(), true);
Michael Jurka1899a362011-11-03 13:50:45 -0700380 }
381
Winson Chungc100e8e2011-08-09 16:02:43 -0700382 if (mResetAfterTransition) {
383 mAppsCustomizePane.reset();
384 mResetAfterTransition = false;
385 }
Michael Jurkaa35e35a2012-04-26 15:04:28 -0700386 }
Michael Jurkabed61d22012-02-14 22:51:29 -0800387
Michael Jurkaa35e35a2012-04-26 15:04:28 -0700388 @Override
389 public void onLauncherTransitionStart(Launcher l, boolean animated, boolean toWorkspace) {
Michael Jurkabed61d22012-02-14 22:51:29 -0800390 if (animated) {
391 enableAndBuildHardwareLayer();
392 }
Winson Chung785d2eb2011-04-14 16:08:02 -0700393 }
Winson Chungf0ea4d32011-06-06 14:27:16 -0700394
Winson Chung785d2eb2011-04-14 16:08:02 -0700395 @Override
Winson Chung70442722012-02-10 15:43:22 -0800396 public void onLauncherTransitionStep(Launcher l, float t) {
397 // Do nothing
398 }
399
400 @Override
Michael Jurkabed61d22012-02-14 22:51:29 -0800401 public void onLauncherTransitionEnd(Launcher l, boolean animated, boolean toWorkspace) {
Michael Jurka39e5d172012-03-12 18:36:12 -0700402 mAppsCustomizePane.onLauncherTransitionEnd(l, animated, toWorkspace);
Winson Chungc100e8e2011-08-09 16:02:43 -0700403 mInTransition = false;
Michael Jurkabed61d22012-02-14 22:51:29 -0800404 if (animated) {
Winson Chungf0ea4d32011-06-06 14:27:16 -0700405 setLayerType(LAYER_TYPE_NONE, null);
406 }
Winson Chung3ac74c52011-06-30 17:39:37 -0700407
Winson Chung7d7541e2011-09-16 20:14:36 -0700408 if (!toWorkspace) {
Winson Chung7819abd2012-11-29 14:29:38 -0800409 // Dismiss the workspace cling
Winson Chung7d7541e2011-09-16 20:14:36 -0700410 l.dismissWorkspaceCling(null);
Winson Chung7819abd2012-11-29 14:29:38 -0800411 // Show the all apps cling (if not already shown)
Winson Chung3f4e1422011-11-17 14:58:51 -0800412 mAppsCustomizePane.showAllAppsCling();
Michael Jurkae326f182011-11-21 14:05:46 -0800413 // Make sure adjacent pages are loaded (we wait until after the transition to
414 // prevent slowing down the animation)
415 mAppsCustomizePane.loadAssociatedPages(mAppsCustomizePane.getCurrentPage());
Winson Chung7d7541e2011-09-16 20:14:36 -0700416
Winson Chung7819abd2012-11-29 14:29:38 -0800417 // Going from Workspace -> All Apps
418 // NOTE: We should do this at the end since we check visibility state in some of the
419 // cling initialization/dismiss code above.
420 setVisibilityOfSiblingsWithLowerZOrder(INVISIBLE);
Winson Chung5a808352011-06-27 19:08:49 -0700421 }
Winson Chung785d2eb2011-04-14 16:08:02 -0700422 }
Winson Chung70d72102011-08-12 11:24:35 -0700423
Michael Jurkabed61d22012-02-14 22:51:29 -0800424 private void setVisibilityOfSiblingsWithLowerZOrder(int visibility) {
425 ViewGroup parent = (ViewGroup) getParent();
Michael Jurkaaea1ce52012-04-12 11:23:21 -0700426 if (parent == null) return;
427
Michael Jurkabed61d22012-02-14 22:51:29 -0800428 final int count = parent.getChildCount();
429 if (!isChildrenDrawingOrderEnabled()) {
430 for (int i = 0; i < count; i++) {
431 final View child = parent.getChildAt(i);
432 if (child == this) {
433 break;
434 } else {
435 if (child.getVisibility() == GONE) {
436 continue;
437 }
438 child.setVisibility(visibility);
439 }
440 }
441 } else {
442 throw new RuntimeException("Failed; can't get z-order of views");
443 }
444 }
445
Michael Jurka2a4b1a82011-12-07 14:00:02 -0800446 public void onWindowVisible() {
Michael Jurkae326f182011-11-21 14:05:46 -0800447 if (getVisibility() == VISIBLE) {
448 mContent.setVisibility(VISIBLE);
449 // We unload the widget previews when the UI is hidden, so need to reload pages
450 // Load the current page synchronously, and the neighboring pages asynchronously
451 mAppsCustomizePane.loadAssociatedPages(mAppsCustomizePane.getCurrentPage(), true);
452 mAppsCustomizePane.loadAssociatedPages(mAppsCustomizePane.getCurrentPage());
453 }
454 }
455
456 public void onTrimMemory() {
457 mContent.setVisibility(GONE);
458 // Clear the widget pages of all their subviews - this will trigger the widget previews
459 // to delete their bitmaps
460 mAppsCustomizePane.clearAllWidgetPages();
461 }
462
Winson Chung70d72102011-08-12 11:24:35 -0700463 boolean isTransitioning() {
464 return mInTransition;
465 }
Winson Chung785d2eb2011-04-14 16:08:02 -0700466}