blob: 89e74b21869f3f98285f81174d440f0ed1677701 [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;
John Spurlock77e1f472013-09-11 10:09:51 -040025import android.graphics.Rect;
Winson Chung785d2eb2011-04-14 16:08:02 -070026import android.util.AttributeSet;
27import 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
Michael Jurka141dbd02011-11-03 13:50:45 -070037import java.util.ArrayList;
38
Winson Chung785d2eb2011-04-14 16:08:02 -070039public class AppsCustomizeTabHost extends TabHost implements LauncherTransitionable,
John Spurlock77e1f472013-09-11 10:09:51 -040040 TabHost.OnTabChangeListener, Insettable {
Winson Chung785d2eb2011-04-14 16:08:02 -070041 static final String LOG_TAG = "AppsCustomizeTabHost";
42
43 private static final String APPS_TAB_TAG = "APPS";
44 private static final String WIDGETS_TAB_TAG = "WIDGETS";
45
46 private final LayoutInflater mLayoutInflater;
Winson Chungf0ea4d32011-06-06 14:27:16 -070047 private ViewGroup mTabs;
Winson Chungfd3385f2011-06-15 19:51:24 -070048 private ViewGroup mTabsContainer;
Winson Chung4179b4e2011-05-31 17:28:12 -070049 private AppsCustomizePagedView mAppsCustomizePane;
Michael Jurka141dbd02011-11-03 13:50:45 -070050 private FrameLayout mAnimationBuffer;
Michael Jurka1899a362011-11-03 13:50:45 -070051 private LinearLayout mContent;
Winson Chung785d2eb2011-04-14 16:08:02 -070052
Winson Chungc100e8e2011-08-09 16:02:43 -070053 private boolean mInTransition;
Winson Chung70442722012-02-10 15:43:22 -080054 private boolean mTransitioningToWorkspace;
Winson Chungc100e8e2011-08-09 16:02:43 -070055 private boolean mResetAfterTransition;
Michael Jurka6cfafb92012-02-23 18:25:43 -080056 private Runnable mRelayoutAndMakeVisible;
John Spurlock77e1f472013-09-11 10:09:51 -040057 private final Rect mInsets = new Rect();
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 Chungc58497e2013-09-03 17:48:37 -070084 void selectAppsTab() {
85 setContentTypeImmediate(AppsCustomizePagedView.ContentType.Applications);
86 }
Winson Chung55b65502011-05-26 12:03:43 -070087 void selectWidgetsTab() {
Winson Chung5a808352011-06-27 19:08:49 -070088 setContentTypeImmediate(AppsCustomizePagedView.ContentType.Widgets);
Winson Chung5a808352011-06-27 19:08:49 -070089 }
Winson Chung55b65502011-05-26 12:03:43 -070090
John Spurlock77e1f472013-09-11 10:09:51 -040091 @Override
92 public void setInsets(Rect insets) {
93 mInsets.set(insets);
94 FrameLayout.LayoutParams flp = (LayoutParams) mContent.getLayoutParams();
95 flp.topMargin = insets.top;
96 flp.bottomMargin = insets.bottom;
97 flp.leftMargin = insets.left;
98 flp.rightMargin = insets.right;
99 mContent.setLayoutParams(flp);
100 }
101
Winson Chung785d2eb2011-04-14 16:08:02 -0700102 /**
103 * Setup the tab host and create all necessary tabs.
104 */
105 @Override
106 protected void onFinishInflate() {
107 // Setup the tab host
108 setup();
109
Winson Chungfd3385f2011-06-15 19:51:24 -0700110 final ViewGroup tabsContainer = (ViewGroup) findViewById(R.id.tabs_container);
Michael Jurka8b805b12012-04-18 14:23:14 -0700111 final TabWidget tabs = getTabWidget();
Winson Chung4179b4e2011-05-31 17:28:12 -0700112 final AppsCustomizePagedView appsCustomizePane = (AppsCustomizePagedView)
Winson Chung785d2eb2011-04-14 16:08:02 -0700113 findViewById(R.id.apps_customize_pane_content);
Winson Chungf0ea4d32011-06-06 14:27:16 -0700114 mTabs = tabs;
Winson Chungfd3385f2011-06-15 19:51:24 -0700115 mTabsContainer = tabsContainer;
Winson Chung4179b4e2011-05-31 17:28:12 -0700116 mAppsCustomizePane = appsCustomizePane;
Michael Jurka141dbd02011-11-03 13:50:45 -0700117 mAnimationBuffer = (FrameLayout) findViewById(R.id.animation_buffer);
Michael Jurka1899a362011-11-03 13:50:45 -0700118 mContent = (LinearLayout) findViewById(R.id.apps_customize_content);
Winson Chung4179b4e2011-05-31 17:28:12 -0700119 if (tabs == null || mAppsCustomizePane == null) throw new Resources.NotFoundException();
Winson Chung785d2eb2011-04-14 16:08:02 -0700120
121 // Configure the tabs content factory to return the same paged view (that we change the
122 // content filter on)
123 TabContentFactory contentFactory = new TabContentFactory() {
124 public View createTabContent(String tag) {
Winson Chung4179b4e2011-05-31 17:28:12 -0700125 return appsCustomizePane;
Winson Chung785d2eb2011-04-14 16:08:02 -0700126 }
127 };
128
129 // Create the tabs
130 TextView tabView;
Winson Chungd2c1f802011-10-14 12:26:54 -0700131 String label;
Michael Jurka8b805b12012-04-18 14:23:14 -0700132 label = getContext().getString(R.string.all_apps_button_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 Chungc58497e2013-09-03 17:48:37 -0700136 addTab(newTabSpec(APPS_TAB_TAG).setIndicator(tabView).setContent(contentFactory));
Michael Jurka8b805b12012-04-18 14:23:14 -0700137 label = getContext().getString(R.string.widgets_tab_label);
Winson Chung785d2eb2011-04-14 16:08:02 -0700138 tabView = (TextView) mLayoutInflater.inflate(R.layout.tab_widget_indicator, tabs, false);
Winson Chungd2c1f802011-10-14 12:26:54 -0700139 tabView.setText(label);
140 tabView.setContentDescription(label);
Winson Chung785d2eb2011-04-14 16:08:02 -0700141 addTab(newTabSpec(WIDGETS_TAB_TAG).setIndicator(tabView).setContent(contentFactory));
Winson Chung785d2eb2011-04-14 16:08:02 -0700142 setOnTabChangedListener(this);
Winson Chungfaa13252011-06-13 18:15:54 -0700143
144 // Setup the key listener to jump between the last tab view and the market icon
145 AppsCustomizeTabKeyEventListener keyListener = new AppsCustomizeTabKeyEventListener();
146 View lastTab = tabs.getChildTabViewAt(tabs.getTabCount() - 1);
147 lastTab.setOnKeyListener(keyListener);
148 View shopButton = findViewById(R.id.market_button);
149 shopButton.setOnKeyListener(keyListener);
Winson Chungfd3385f2011-06-15 19:51:24 -0700150
151 // Hide the tab bar until we measure
152 mTabsContainer.setAlpha(0f);
Winson Chungf0ea4d32011-06-06 14:27:16 -0700153 }
Winson Chung785d2eb2011-04-14 16:08:02 -0700154
Winson Chungf0ea4d32011-06-06 14:27:16 -0700155 @Override
156 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
157 boolean remeasureTabWidth = (mTabs.getLayoutParams().width <= 0);
158 super.onMeasure(widthMeasureSpec, heightMeasureSpec);
159
160 // Set the width of the tab list to the content width
161 if (remeasureTabWidth) {
Winson Chungfd3385f2011-06-15 19:51:24 -0700162 int contentWidth = mAppsCustomizePane.getPageContentWidth();
Michael Jurka141dbd02011-11-03 13:50:45 -0700163 if (contentWidth > 0 && mTabs.getLayoutParams().width != contentWidth) {
164 // Set the width and show the tab bar
Winson Chungfd3385f2011-06-15 19:51:24 -0700165 mTabs.getLayoutParams().width = contentWidth;
Winson Chungc93e5ae2012-07-23 20:48:26 -0700166 mRelayoutAndMakeVisible.run();
Winson Chungfd3385f2011-06-15 19:51:24 -0700167 }
Winson Chungc93e5ae2012-07-23 20:48:26 -0700168
169 super.onMeasure(widthMeasureSpec, heightMeasureSpec);
Winson Chungf0ea4d32011-06-06 14:27:16 -0700170 }
Winson Chung4179b4e2011-05-31 17:28:12 -0700171 }
172
Winson Chung70442722012-02-10 15:43:22 -0800173 public boolean onInterceptTouchEvent(MotionEvent ev) {
Winson Chungac08f4b2012-04-27 15:41:00 -0700174 // If we are mid transitioning to the workspace, then intercept touch events here so we
175 // can ignore them, otherwise we just let all apps handle the touch events.
176 if (mInTransition && mTransitioningToWorkspace) {
Winson Chung70442722012-02-10 15:43:22 -0800177 return true;
178 }
179 return super.onInterceptTouchEvent(ev);
180 };
181
Winson Chung4179b4e2011-05-31 17:28:12 -0700182 @Override
183 public boolean onTouchEvent(MotionEvent event) {
Winson Chungac08f4b2012-04-27 15:41:00 -0700184 // Allow touch events to fall through to the workspace if we are transitioning there
185 if (mInTransition && mTransitioningToWorkspace) {
Winson Chung21fadea2012-04-27 15:59:55 -0700186 return super.onTouchEvent(event);
Winson Chung70442722012-02-10 15:43:22 -0800187 }
188
Winson Chung4179b4e2011-05-31 17:28:12 -0700189 // Intercept all touch events up to the bottom of the AppsCustomizePane so they do not fall
190 // through to the workspace and trigger showWorkspace()
191 if (event.getY() < mAppsCustomizePane.getBottom()) {
192 return true;
193 }
194 return super.onTouchEvent(event);
Winson Chung785d2eb2011-04-14 16:08:02 -0700195 }
196
Winson Chung5a808352011-06-27 19:08:49 -0700197 private void onTabChangedStart() {
Winson Chung5a808352011-06-27 19:08:49 -0700198 }
Adam Cohen0cd3b642011-10-14 14:58:00 -0700199
Winson Chung097e6c72011-10-20 13:58:30 -0700200 private void reloadCurrentPage() {
Winson Chung097e6c72011-10-20 13:58:30 -0700201 mAppsCustomizePane.loadAssociatedPages(mAppsCustomizePane.getCurrentPage());
202 mAppsCustomizePane.requestFocus();
203 }
204
Winson Chung5a808352011-06-27 19:08:49 -0700205 private void onTabChangedEnd(AppsCustomizePagedView.ContentType type) {
206 mAppsCustomizePane.setContentType(type);
207 }
208
Winson Chung785d2eb2011-04-14 16:08:02 -0700209 @Override
210 public void onTabChanged(String tabId) {
Winson Chungb44b5242011-06-13 11:32:14 -0700211 final AppsCustomizePagedView.ContentType type = getContentTypeForTabTag(tabId);
Adam Cohen0cd3b642011-10-14 14:58:00 -0700212
213 // Animate the changing of the tab content by fading pages in and out
214 final Resources res = getResources();
215 final int duration = res.getInteger(R.integer.config_tabTransitionDuration);
216
217 // We post a runnable here because there is a delay while the first page is loading and
218 // the feedback from having changed the tab almost feels better than having it stick
219 post(new Runnable() {
220 @Override
221 public void run() {
Winson Chung097e6c72011-10-20 13:58:30 -0700222 if (mAppsCustomizePane.getMeasuredWidth() <= 0 ||
223 mAppsCustomizePane.getMeasuredHeight() <= 0) {
224 reloadCurrentPage();
225 return;
226 }
227
Michael Jurka141dbd02011-11-03 13:50:45 -0700228 // Take the visible pages and re-parent them temporarily to mAnimatorBuffer
229 // and then cross fade to the new pages
Winson Chungc6f10b92011-11-14 11:39:07 -0800230 int[] visiblePageRange = new int[2];
231 mAppsCustomizePane.getVisiblePages(visiblePageRange);
232 if (visiblePageRange[0] == -1 && visiblePageRange[1] == -1) {
233 // If we can't get the visible page ranges, then just skip the animation
234 reloadCurrentPage();
235 return;
236 }
237 ArrayList<View> visiblePages = new ArrayList<View>();
238 for (int i = visiblePageRange[0]; i <= visiblePageRange[1]; i++) {
239 visiblePages.add(mAppsCustomizePane.getPageAt(i));
240 }
Michael Jurka141dbd02011-11-03 13:50:45 -0700241
242 // We want the pages to be rendered in exactly the same way as they were when
243 // their parent was mAppsCustomizePane -- so set the scroll on mAnimationBuffer
244 // to be exactly the same as mAppsCustomizePane, and below, set the left/top
245 // parameters to be correct for each of the pages
246 mAnimationBuffer.scrollTo(mAppsCustomizePane.getScrollX(), 0);
247
Michael Jurka141dbd02011-11-03 13:50:45 -0700248 // mAppsCustomizePane renders its children in reverse order, so
249 // add the pages to mAnimationBuffer in reverse order to match that behavior
250 for (int i = visiblePages.size() - 1; i >= 0; i--) {
251 View child = visiblePages.get(i);
Winson Chungc58497e2013-09-03 17:48:37 -0700252 if (child instanceof AppsCustomizeCellLayout) {
253 ((AppsCustomizeCellLayout) child).resetChildrenOnKeyListeners();
Winson Chungc6f10b92011-11-14 11:39:07 -0800254 } else if (child instanceof PagedViewGridLayout) {
255 ((PagedViewGridLayout) child).resetChildrenOnKeyListeners();
256 }
Michael Jurka141dbd02011-11-03 13:50:45 -0700257 PagedViewWidget.setDeletePreviewsWhenDetachedFromWindow(false);
258 mAppsCustomizePane.removeView(child);
259 PagedViewWidget.setDeletePreviewsWhenDetachedFromWindow(true);
260 mAnimationBuffer.setAlpha(1f);
261 mAnimationBuffer.setVisibility(View.VISIBLE);
Winson Chung6e3cf902012-03-30 16:36:53 -0700262 LayoutParams p = new FrameLayout.LayoutParams(child.getMeasuredWidth(),
263 child.getMeasuredHeight());
Michael Jurka141dbd02011-11-03 13:50:45 -0700264 p.setMargins((int) child.getLeft(), (int) child.getTop(), 0, 0);
265 mAnimationBuffer.addView(child, p);
266 }
Adam Cohen0cd3b642011-10-14 14:58:00 -0700267
268 // Toggle the new content
269 onTabChangedStart();
270 onTabChangedEnd(type);
271
272 // Animate the transition
Michael Jurka2ecf9952012-06-18 12:52:28 -0700273 ObjectAnimator outAnim = LauncherAnimUtils.ofFloat(mAnimationBuffer, "alpha", 0f);
Adam Cohen0cd3b642011-10-14 14:58:00 -0700274 outAnim.addListener(new AnimatorListenerAdapter() {
Michael Jurkaee8e99f2013-02-07 13:27:06 +0100275 private void clearAnimationBuffer() {
276 mAnimationBuffer.setVisibility(View.GONE);
277 PagedViewWidget.setRecyclePreviewsWhenDetachedFromWindow(false);
278 mAnimationBuffer.removeAllViews();
279 PagedViewWidget.setRecyclePreviewsWhenDetachedFromWindow(true);
280 }
Adam Cohen0cd3b642011-10-14 14:58:00 -0700281 @Override
282 public void onAnimationEnd(Animator animation) {
Michael Jurkaee8e99f2013-02-07 13:27:06 +0100283 clearAnimationBuffer();
Michael Jurka141dbd02011-11-03 13:50:45 -0700284 }
285 @Override
286 public void onAnimationCancel(Animator animation) {
Michael Jurkaee8e99f2013-02-07 13:27:06 +0100287 clearAnimationBuffer();
Adam Cohen0cd3b642011-10-14 14:58:00 -0700288 }
289 });
Michael Jurka2ecf9952012-06-18 12:52:28 -0700290 ObjectAnimator inAnim = LauncherAnimUtils.ofFloat(mAppsCustomizePane, "alpha", 1f);
Adam Cohen0cd3b642011-10-14 14:58:00 -0700291 inAnim.addListener(new AnimatorListenerAdapter() {
292 @Override
293 public void onAnimationEnd(Animator animation) {
Winson Chung097e6c72011-10-20 13:58:30 -0700294 reloadCurrentPage();
Adam Cohen0cd3b642011-10-14 14:58:00 -0700295 }
296 });
Michael Jurka7f9ddd82012-11-19 16:15:24 -0800297
298 final AnimatorSet animSet = LauncherAnimUtils.createAnimatorSet();
Adam Cohen0cd3b642011-10-14 14:58:00 -0700299 animSet.playTogether(outAnim, inAnim);
300 animSet.setDuration(duration);
Michael Jurkaf1ad6082013-03-13 12:55:46 +0100301 animSet.start();
Adam Cohen0cd3b642011-10-14 14:58:00 -0700302 }
303 });
304 }
305
306 public void setCurrentTabFromContent(AppsCustomizePagedView.ContentType type) {
Winson Chungfa4086d2012-07-25 16:18:49 -0700307 setOnTabChangedListener(null);
Adam Cohen0cd3b642011-10-14 14:58:00 -0700308 setCurrentTabByTag(getTabTagForContentType(type));
Winson Chungfa4086d2012-07-25 16:18:49 -0700309 setOnTabChangedListener(this);
Winson Chung785d2eb2011-04-14 16:08:02 -0700310 }
311
312 /**
313 * Returns the content type for the specified tab tag.
314 */
315 public AppsCustomizePagedView.ContentType getContentTypeForTabTag(String tag) {
316 if (tag.equals(APPS_TAB_TAG)) {
317 return AppsCustomizePagedView.ContentType.Applications;
318 } else if (tag.equals(WIDGETS_TAB_TAG)) {
319 return AppsCustomizePagedView.ContentType.Widgets;
320 }
321 return AppsCustomizePagedView.ContentType.Applications;
322 }
323
324 /**
Winson Chungfc79c802011-05-02 13:35:34 -0700325 * Returns the tab tag for a given content type.
326 */
327 public String getTabTagForContentType(AppsCustomizePagedView.ContentType type) {
328 if (type == AppsCustomizePagedView.ContentType.Applications) {
329 return APPS_TAB_TAG;
330 } else if (type == AppsCustomizePagedView.ContentType.Widgets) {
331 return WIDGETS_TAB_TAG;
332 }
333 return APPS_TAB_TAG;
334 }
335
336 /**
Winson Chung785d2eb2011-04-14 16:08:02 -0700337 * Disable focus on anything under this view in the hierarchy if we are not visible.
338 */
339 @Override
340 public int getDescendantFocusability() {
341 if (getVisibility() != View.VISIBLE) {
342 return ViewGroup.FOCUS_BLOCK_DESCENDANTS;
343 }
344 return super.getDescendantFocusability();
345 }
346
Winson Chungc100e8e2011-08-09 16:02:43 -0700347 void reset() {
348 if (mInTransition) {
349 // Defer to after the transition to reset
350 mResetAfterTransition = true;
351 } else {
352 // Reset immediately
353 mAppsCustomizePane.reset();
354 }
355 }
356
Michael Jurka1899a362011-11-03 13:50:45 -0700357 private void enableAndBuildHardwareLayer() {
Michael Jurka19e0fc52011-07-22 18:00:21 -0700358 // isHardwareAccelerated() checks if we're attached to a window and if that
359 // window is HW accelerated-- we were sometimes not attached to a window
360 // and buildLayer was throwing an IllegalStateException
Michael Jurka1899a362011-11-03 13:50:45 -0700361 if (isHardwareAccelerated()) {
Winson Chungf0ea4d32011-06-06 14:27:16 -0700362 // Turn on hardware layers for performance
363 setLayerType(LAYER_TYPE_HARDWARE, null);
364
Michael Jurka1899a362011-11-03 13:50:45 -0700365 // force building the layer, so you don't get a blip early in an animation
366 // when the layer is created layer
Winson Chungf0ea4d32011-06-06 14:27:16 -0700367 buildLayer();
368 }
Michael Jurka1899a362011-11-03 13:50:45 -0700369 }
370
Michael Jurka2a4b1a82011-12-07 14:00:02 -0800371 @Override
372 public View getContent() {
373 return mContent;
Michael Jurka1899a362011-11-03 13:50:45 -0700374 }
375
376 /* LauncherTransitionable overrides */
377 @Override
Michael Jurkaa35e35a2012-04-26 15:04:28 -0700378 public void onLauncherTransitionPrepare(Launcher l, boolean animated, boolean toWorkspace) {
379 mAppsCustomizePane.onLauncherTransitionPrepare(l, animated, toWorkspace);
Michael Jurka1899a362011-11-03 13:50:45 -0700380 mInTransition = true;
Winson Chung70442722012-02-10 15:43:22 -0800381 mTransitioningToWorkspace = toWorkspace;
Michael Jurka1899a362011-11-03 13:50:45 -0700382
Michael Jurkabed61d22012-02-14 22:51:29 -0800383 if (toWorkspace) {
384 // Going from All Apps -> Workspace
385 setVisibilityOfSiblingsWithLowerZOrder(VISIBLE);
386 } else {
387 // Going from Workspace -> All Apps
388 mContent.setVisibility(VISIBLE);
Michael Jurka3d845e82011-11-15 17:04:31 -0800389
Michael Jurkae326f182011-11-21 14:05:46 -0800390 // Make sure the current page is loaded (we start loading the side pages after the
391 // transition to prevent slowing down the animation)
392 mAppsCustomizePane.loadAssociatedPages(mAppsCustomizePane.getCurrentPage(), true);
Michael Jurka1899a362011-11-03 13:50:45 -0700393 }
394
Winson Chungc100e8e2011-08-09 16:02:43 -0700395 if (mResetAfterTransition) {
396 mAppsCustomizePane.reset();
397 mResetAfterTransition = false;
398 }
Michael Jurkaa35e35a2012-04-26 15:04:28 -0700399 }
Michael Jurkabed61d22012-02-14 22:51:29 -0800400
Michael Jurkaa35e35a2012-04-26 15:04:28 -0700401 @Override
402 public void onLauncherTransitionStart(Launcher l, boolean animated, boolean toWorkspace) {
Michael Jurkabed61d22012-02-14 22:51:29 -0800403 if (animated) {
404 enableAndBuildHardwareLayer();
405 }
Winson Chungaf40f202013-09-18 18:26:31 -0700406
407 // Dismiss the workspace cling
408 l.dismissWorkspaceCling(null);
Winson Chung785d2eb2011-04-14 16:08:02 -0700409 }
Winson Chungf0ea4d32011-06-06 14:27:16 -0700410
Winson Chung785d2eb2011-04-14 16:08:02 -0700411 @Override
Winson Chung70442722012-02-10 15:43:22 -0800412 public void onLauncherTransitionStep(Launcher l, float t) {
413 // Do nothing
414 }
415
416 @Override
Michael Jurkabed61d22012-02-14 22:51:29 -0800417 public void onLauncherTransitionEnd(Launcher l, boolean animated, boolean toWorkspace) {
Michael Jurka39e5d172012-03-12 18:36:12 -0700418 mAppsCustomizePane.onLauncherTransitionEnd(l, animated, toWorkspace);
Winson Chungc100e8e2011-08-09 16:02:43 -0700419 mInTransition = false;
Michael Jurkabed61d22012-02-14 22:51:29 -0800420 if (animated) {
Winson Chungf0ea4d32011-06-06 14:27:16 -0700421 setLayerType(LAYER_TYPE_NONE, null);
422 }
Winson Chung3ac74c52011-06-30 17:39:37 -0700423
Winson Chung7d7541e2011-09-16 20:14:36 -0700424 if (!toWorkspace) {
Winson Chung7819abd2012-11-29 14:29:38 -0800425 // Show the all apps cling (if not already shown)
Winson Chung3f4e1422011-11-17 14:58:51 -0800426 mAppsCustomizePane.showAllAppsCling();
Michael Jurkae326f182011-11-21 14:05:46 -0800427 // Make sure adjacent pages are loaded (we wait until after the transition to
428 // prevent slowing down the animation)
429 mAppsCustomizePane.loadAssociatedPages(mAppsCustomizePane.getCurrentPage());
Winson Chung7d7541e2011-09-16 20:14:36 -0700430
Winson Chung7819abd2012-11-29 14:29:38 -0800431 // Going from Workspace -> All Apps
432 // NOTE: We should do this at the end since we check visibility state in some of the
433 // cling initialization/dismiss code above.
434 setVisibilityOfSiblingsWithLowerZOrder(INVISIBLE);
Winson Chung5a808352011-06-27 19:08:49 -0700435 }
Winson Chung785d2eb2011-04-14 16:08:02 -0700436 }
Winson Chung70d72102011-08-12 11:24:35 -0700437
Michael Jurkabed61d22012-02-14 22:51:29 -0800438 private void setVisibilityOfSiblingsWithLowerZOrder(int visibility) {
439 ViewGroup parent = (ViewGroup) getParent();
Michael Jurkaaea1ce52012-04-12 11:23:21 -0700440 if (parent == null) return;
441
Michael Jurkabed61d22012-02-14 22:51:29 -0800442 final int count = parent.getChildCount();
443 if (!isChildrenDrawingOrderEnabled()) {
444 for (int i = 0; i < count; i++) {
445 final View child = parent.getChildAt(i);
446 if (child == this) {
447 break;
448 } else {
449 if (child.getVisibility() == GONE) {
450 continue;
451 }
452 child.setVisibility(visibility);
453 }
454 }
455 } else {
456 throw new RuntimeException("Failed; can't get z-order of views");
457 }
458 }
459
Michael Jurka2a4b1a82011-12-07 14:00:02 -0800460 public void onWindowVisible() {
Michael Jurkae326f182011-11-21 14:05:46 -0800461 if (getVisibility() == VISIBLE) {
462 mContent.setVisibility(VISIBLE);
463 // We unload the widget previews when the UI is hidden, so need to reload pages
464 // Load the current page synchronously, and the neighboring pages asynchronously
465 mAppsCustomizePane.loadAssociatedPages(mAppsCustomizePane.getCurrentPage(), true);
466 mAppsCustomizePane.loadAssociatedPages(mAppsCustomizePane.getCurrentPage());
467 }
468 }
469
470 public void onTrimMemory() {
471 mContent.setVisibility(GONE);
472 // Clear the widget pages of all their subviews - this will trigger the widget previews
473 // to delete their bitmaps
474 mAppsCustomizePane.clearAllWidgetPages();
475 }
476
Winson Chung70d72102011-08-12 11:24:35 -0700477 boolean isTransitioning() {
478 return mInTransition;
479 }
Winson Chung785d2eb2011-04-14 16:08:02 -0700480}