blob: bb7f045cecc68cdc67dba35677873cf587998147 [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;
Winson Chung2d75f122013-09-23 16:53:31 -070025import android.graphics.Color;
John Spurlock77e1f472013-09-11 10:09:51 -040026import android.graphics.Rect;
Winson Chung785d2eb2011-04-14 16:08:02 -070027import android.util.AttributeSet;
28import android.view.LayoutInflater;
Winson Chung4179b4e2011-05-31 17:28:12 -070029import android.view.MotionEvent;
Winson Chung785d2eb2011-04-14 16:08:02 -070030import android.view.View;
31import android.view.ViewGroup;
Michael Jurka141dbd02011-11-03 13:50:45 -070032import android.widget.FrameLayout;
Michael Jurka1899a362011-11-03 13:50:45 -070033import android.widget.LinearLayout;
Winson Chung785d2eb2011-04-14 16:08:02 -070034import android.widget.TabHost;
Winson Chungfaa13252011-06-13 18:15:54 -070035import android.widget.TabWidget;
Winson Chung785d2eb2011-04-14 16:08:02 -070036import android.widget.TextView;
37
Michael Jurka141dbd02011-11-03 13:50:45 -070038import java.util.ArrayList;
39
Winson Chung785d2eb2011-04-14 16:08:02 -070040public class AppsCustomizeTabHost extends TabHost implements LauncherTransitionable,
John Spurlock77e1f472013-09-11 10:09:51 -040041 TabHost.OnTabChangeListener, Insettable {
Winson Chung785d2eb2011-04-14 16:08:02 -070042 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;
John Spurlock77e1f472013-09-11 10:09:51 -040058 private final Rect mInsets = new Rect();
Winson Chungc100e8e2011-08-09 16:02:43 -070059
Winson Chung785d2eb2011-04-14 16:08:02 -070060 public AppsCustomizeTabHost(Context context, AttributeSet attrs) {
61 super(context, attrs);
62 mLayoutInflater = LayoutInflater.from(context);
Michael Jurka6cfafb92012-02-23 18:25:43 -080063 mRelayoutAndMakeVisible = new Runnable() {
64 public void run() {
65 mTabs.requestLayout();
66 mTabsContainer.setAlpha(1f);
67 }
68 };
Winson Chung785d2eb2011-04-14 16:08:02 -070069 }
70
Winson Chungf0ea4d32011-06-06 14:27:16 -070071 /**
Winson Chung5a808352011-06-27 19:08:49 -070072 * Convenience methods to select specific tabs. We want to set the content type immediately
73 * in these cases, but we note that we still call setCurrentTabByTag() so that the tab view
74 * reflects the new content (but doesn't do the animation and logic associated with changing
75 * tabs manually).
Winson Chungf0ea4d32011-06-06 14:27:16 -070076 */
Winson Chungc93e5ae2012-07-23 20:48:26 -070077 void setContentTypeImmediate(AppsCustomizePagedView.ContentType type) {
Winson Chungfa4086d2012-07-25 16:18:49 -070078 setOnTabChangedListener(null);
Winson Chung5a808352011-06-27 19:08:49 -070079 onTabChangedStart();
80 onTabChangedEnd(type);
Winson Chungfa4086d2012-07-25 16:18:49 -070081 setCurrentTabByTag(getTabTagForContentType(type));
82 setOnTabChangedListener(this);
Winson Chung5a808352011-06-27 19:08:49 -070083 }
Adam Cohen947dc542013-06-06 22:43:33 -070084
John Spurlock77e1f472013-09-11 10:09:51 -040085 @Override
86 public void setInsets(Rect insets) {
87 mInsets.set(insets);
88 FrameLayout.LayoutParams flp = (LayoutParams) mContent.getLayoutParams();
89 flp.topMargin = insets.top;
90 flp.bottomMargin = insets.bottom;
91 flp.leftMargin = insets.left;
92 flp.rightMargin = insets.right;
93 mContent.setLayoutParams(flp);
94 }
95
Winson Chung785d2eb2011-04-14 16:08:02 -070096 /**
97 * Setup the tab host and create all necessary tabs.
98 */
99 @Override
100 protected void onFinishInflate() {
101 // Setup the tab host
102 setup();
103
Winson Chungfd3385f2011-06-15 19:51:24 -0700104 final ViewGroup tabsContainer = (ViewGroup) findViewById(R.id.tabs_container);
Michael Jurka8b805b12012-04-18 14:23:14 -0700105 final TabWidget tabs = getTabWidget();
Winson Chung4179b4e2011-05-31 17:28:12 -0700106 final AppsCustomizePagedView appsCustomizePane = (AppsCustomizePagedView)
Winson Chung785d2eb2011-04-14 16:08:02 -0700107 findViewById(R.id.apps_customize_pane_content);
Winson Chungf0ea4d32011-06-06 14:27:16 -0700108 mTabs = tabs;
Winson Chungfd3385f2011-06-15 19:51:24 -0700109 mTabsContainer = tabsContainer;
Winson Chung4179b4e2011-05-31 17:28:12 -0700110 mAppsCustomizePane = appsCustomizePane;
Michael Jurka141dbd02011-11-03 13:50:45 -0700111 mAnimationBuffer = (FrameLayout) findViewById(R.id.animation_buffer);
Michael Jurka1899a362011-11-03 13:50:45 -0700112 mContent = (LinearLayout) findViewById(R.id.apps_customize_content);
Winson Chung4179b4e2011-05-31 17:28:12 -0700113 if (tabs == null || mAppsCustomizePane == null) throw new Resources.NotFoundException();
Winson Chung785d2eb2011-04-14 16:08:02 -0700114
115 // Configure the tabs content factory to return the same paged view (that we change the
116 // content filter on)
117 TabContentFactory contentFactory = new TabContentFactory() {
118 public View createTabContent(String tag) {
Winson Chung4179b4e2011-05-31 17:28:12 -0700119 return appsCustomizePane;
Winson Chung785d2eb2011-04-14 16:08:02 -0700120 }
121 };
122
123 // Create the tabs
124 TextView tabView;
Winson Chungd2c1f802011-10-14 12:26:54 -0700125 String label;
Michael Jurka8b805b12012-04-18 14:23:14 -0700126 label = getContext().getString(R.string.all_apps_button_label);
Winson Chung785d2eb2011-04-14 16:08:02 -0700127 tabView = (TextView) mLayoutInflater.inflate(R.layout.tab_widget_indicator, tabs, false);
Winson Chungd2c1f802011-10-14 12:26:54 -0700128 tabView.setText(label);
129 tabView.setContentDescription(label);
Winson Chungc58497e2013-09-03 17:48:37 -0700130 addTab(newTabSpec(APPS_TAB_TAG).setIndicator(tabView).setContent(contentFactory));
Michael Jurka8b805b12012-04-18 14:23:14 -0700131 label = getContext().getString(R.string.widgets_tab_label);
Winson Chung785d2eb2011-04-14 16:08:02 -0700132 tabView = (TextView) mLayoutInflater.inflate(R.layout.tab_widget_indicator, tabs, false);
Winson Chungd2c1f802011-10-14 12:26:54 -0700133 tabView.setText(label);
134 tabView.setContentDescription(label);
Winson Chung785d2eb2011-04-14 16:08:02 -0700135 addTab(newTabSpec(WIDGETS_TAB_TAG).setIndicator(tabView).setContent(contentFactory));
Winson Chung785d2eb2011-04-14 16:08:02 -0700136 setOnTabChangedListener(this);
Winson Chungfaa13252011-06-13 18:15:54 -0700137
138 // Setup the key listener to jump between the last tab view and the market icon
139 AppsCustomizeTabKeyEventListener keyListener = new AppsCustomizeTabKeyEventListener();
140 View lastTab = tabs.getChildTabViewAt(tabs.getTabCount() - 1);
141 lastTab.setOnKeyListener(keyListener);
142 View shopButton = findViewById(R.id.market_button);
143 shopButton.setOnKeyListener(keyListener);
Winson Chungfd3385f2011-06-15 19:51:24 -0700144
145 // Hide the tab bar until we measure
146 mTabsContainer.setAlpha(0f);
Winson Chungf0ea4d32011-06-06 14:27:16 -0700147 }
Winson Chung785d2eb2011-04-14 16:08:02 -0700148
Winson Chungf0ea4d32011-06-06 14:27:16 -0700149 @Override
150 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
151 boolean remeasureTabWidth = (mTabs.getLayoutParams().width <= 0);
152 super.onMeasure(widthMeasureSpec, heightMeasureSpec);
153
154 // Set the width of the tab list to the content width
155 if (remeasureTabWidth) {
Winson Chungfd3385f2011-06-15 19:51:24 -0700156 int contentWidth = mAppsCustomizePane.getPageContentWidth();
Michael Jurka141dbd02011-11-03 13:50:45 -0700157 if (contentWidth > 0 && mTabs.getLayoutParams().width != contentWidth) {
158 // Set the width and show the tab bar
Winson Chungfd3385f2011-06-15 19:51:24 -0700159 mTabs.getLayoutParams().width = contentWidth;
Winson Chungc93e5ae2012-07-23 20:48:26 -0700160 mRelayoutAndMakeVisible.run();
Winson Chungfd3385f2011-06-15 19:51:24 -0700161 }
Winson Chungc93e5ae2012-07-23 20:48:26 -0700162
163 super.onMeasure(widthMeasureSpec, heightMeasureSpec);
Winson Chungf0ea4d32011-06-06 14:27:16 -0700164 }
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() {
Winson Chung5a808352011-06-27 19:08:49 -0700192 }
Adam Cohen0cd3b642011-10-14 14:58:00 -0700193
Winson Chung097e6c72011-10-20 13:58:30 -0700194 private void reloadCurrentPage() {
Winson Chung097e6c72011-10-20 13:58:30 -0700195 mAppsCustomizePane.loadAssociatedPages(mAppsCustomizePane.getCurrentPage());
196 mAppsCustomizePane.requestFocus();
197 }
198
Winson Chung5a808352011-06-27 19:08:49 -0700199 private void onTabChangedEnd(AppsCustomizePagedView.ContentType type) {
Winson Chung2d75f122013-09-23 16:53:31 -0700200 int bgAlpha = (int) (255 * (getResources().getInteger(
201 R.integer.config_appsCustomizeSpringLoadedBgAlpha) / 100f));
202 setBackgroundColor(Color.argb(bgAlpha, 0, 0, 0));
Winson Chung5a808352011-06-27 19:08:49 -0700203 mAppsCustomizePane.setContentType(type);
204 }
205
Winson Chung785d2eb2011-04-14 16:08:02 -0700206 @Override
207 public void onTabChanged(String tabId) {
Winson Chungb44b5242011-06-13 11:32:14 -0700208 final AppsCustomizePagedView.ContentType type = getContentTypeForTabTag(tabId);
Adam Cohen0cd3b642011-10-14 14:58:00 -0700209
210 // Animate the changing of the tab content by fading pages in and out
211 final Resources res = getResources();
212 final int duration = res.getInteger(R.integer.config_tabTransitionDuration);
213
214 // We post a runnable here because there is a delay while the first page is loading and
215 // the feedback from having changed the tab almost feels better than having it stick
216 post(new Runnable() {
217 @Override
218 public void run() {
Winson Chung097e6c72011-10-20 13:58:30 -0700219 if (mAppsCustomizePane.getMeasuredWidth() <= 0 ||
220 mAppsCustomizePane.getMeasuredHeight() <= 0) {
221 reloadCurrentPage();
222 return;
223 }
224
Michael Jurka141dbd02011-11-03 13:50:45 -0700225 // Take the visible pages and re-parent them temporarily to mAnimatorBuffer
226 // and then cross fade to the new pages
Winson Chungc6f10b92011-11-14 11:39:07 -0800227 int[] visiblePageRange = new int[2];
228 mAppsCustomizePane.getVisiblePages(visiblePageRange);
229 if (visiblePageRange[0] == -1 && visiblePageRange[1] == -1) {
230 // If we can't get the visible page ranges, then just skip the animation
231 reloadCurrentPage();
232 return;
233 }
234 ArrayList<View> visiblePages = new ArrayList<View>();
235 for (int i = visiblePageRange[0]; i <= visiblePageRange[1]; i++) {
236 visiblePages.add(mAppsCustomizePane.getPageAt(i));
237 }
Michael Jurka141dbd02011-11-03 13:50:45 -0700238
239 // We want the pages to be rendered in exactly the same way as they were when
240 // their parent was mAppsCustomizePane -- so set the scroll on mAnimationBuffer
241 // to be exactly the same as mAppsCustomizePane, and below, set the left/top
242 // parameters to be correct for each of the pages
243 mAnimationBuffer.scrollTo(mAppsCustomizePane.getScrollX(), 0);
244
Michael Jurka141dbd02011-11-03 13:50:45 -0700245 // mAppsCustomizePane renders its children in reverse order, so
246 // add the pages to mAnimationBuffer in reverse order to match that behavior
247 for (int i = visiblePages.size() - 1; i >= 0; i--) {
248 View child = visiblePages.get(i);
Winson Chungc58497e2013-09-03 17:48:37 -0700249 if (child instanceof AppsCustomizeCellLayout) {
250 ((AppsCustomizeCellLayout) child).resetChildrenOnKeyListeners();
Winson Chungc6f10b92011-11-14 11:39:07 -0800251 } else if (child instanceof PagedViewGridLayout) {
252 ((PagedViewGridLayout) child).resetChildrenOnKeyListeners();
253 }
Michael Jurka141dbd02011-11-03 13:50:45 -0700254 PagedViewWidget.setDeletePreviewsWhenDetachedFromWindow(false);
255 mAppsCustomizePane.removeView(child);
256 PagedViewWidget.setDeletePreviewsWhenDetachedFromWindow(true);
257 mAnimationBuffer.setAlpha(1f);
258 mAnimationBuffer.setVisibility(View.VISIBLE);
Winson Chung6e3cf902012-03-30 16:36:53 -0700259 LayoutParams p = new FrameLayout.LayoutParams(child.getMeasuredWidth(),
260 child.getMeasuredHeight());
Michael Jurka141dbd02011-11-03 13:50:45 -0700261 p.setMargins((int) child.getLeft(), (int) child.getTop(), 0, 0);
262 mAnimationBuffer.addView(child, p);
263 }
Adam Cohen0cd3b642011-10-14 14:58:00 -0700264
265 // Toggle the new content
266 onTabChangedStart();
267 onTabChangedEnd(type);
268
269 // Animate the transition
Michael Jurka2ecf9952012-06-18 12:52:28 -0700270 ObjectAnimator outAnim = LauncherAnimUtils.ofFloat(mAnimationBuffer, "alpha", 0f);
Adam Cohen0cd3b642011-10-14 14:58:00 -0700271 outAnim.addListener(new AnimatorListenerAdapter() {
Michael Jurkaee8e99f2013-02-07 13:27:06 +0100272 private void clearAnimationBuffer() {
273 mAnimationBuffer.setVisibility(View.GONE);
274 PagedViewWidget.setRecyclePreviewsWhenDetachedFromWindow(false);
275 mAnimationBuffer.removeAllViews();
276 PagedViewWidget.setRecyclePreviewsWhenDetachedFromWindow(true);
277 }
Adam Cohen0cd3b642011-10-14 14:58:00 -0700278 @Override
279 public void onAnimationEnd(Animator animation) {
Michael Jurkaee8e99f2013-02-07 13:27:06 +0100280 clearAnimationBuffer();
Michael Jurka141dbd02011-11-03 13:50:45 -0700281 }
282 @Override
283 public void onAnimationCancel(Animator animation) {
Michael Jurkaee8e99f2013-02-07 13:27:06 +0100284 clearAnimationBuffer();
Adam Cohen0cd3b642011-10-14 14:58:00 -0700285 }
286 });
Michael Jurka2ecf9952012-06-18 12:52:28 -0700287 ObjectAnimator inAnim = LauncherAnimUtils.ofFloat(mAppsCustomizePane, "alpha", 1f);
Adam Cohen0cd3b642011-10-14 14:58:00 -0700288 inAnim.addListener(new AnimatorListenerAdapter() {
289 @Override
290 public void onAnimationEnd(Animator animation) {
Winson Chung097e6c72011-10-20 13:58:30 -0700291 reloadCurrentPage();
Adam Cohen0cd3b642011-10-14 14:58:00 -0700292 }
293 });
Michael Jurka7f9ddd82012-11-19 16:15:24 -0800294
295 final AnimatorSet animSet = LauncherAnimUtils.createAnimatorSet();
Adam Cohen0cd3b642011-10-14 14:58:00 -0700296 animSet.playTogether(outAnim, inAnim);
297 animSet.setDuration(duration);
Michael Jurkaf1ad6082013-03-13 12:55:46 +0100298 animSet.start();
Adam Cohen0cd3b642011-10-14 14:58:00 -0700299 }
300 });
301 }
302
303 public void setCurrentTabFromContent(AppsCustomizePagedView.ContentType type) {
Winson Chungfa4086d2012-07-25 16:18:49 -0700304 setOnTabChangedListener(null);
Adam Cohen0cd3b642011-10-14 14:58:00 -0700305 setCurrentTabByTag(getTabTagForContentType(type));
Winson Chungfa4086d2012-07-25 16:18:49 -0700306 setOnTabChangedListener(this);
Winson Chung785d2eb2011-04-14 16:08:02 -0700307 }
308
309 /**
310 * Returns the content type for the specified tab tag.
311 */
312 public AppsCustomizePagedView.ContentType getContentTypeForTabTag(String tag) {
313 if (tag.equals(APPS_TAB_TAG)) {
314 return AppsCustomizePagedView.ContentType.Applications;
315 } else if (tag.equals(WIDGETS_TAB_TAG)) {
316 return AppsCustomizePagedView.ContentType.Widgets;
317 }
318 return AppsCustomizePagedView.ContentType.Applications;
319 }
320
321 /**
Winson Chungfc79c802011-05-02 13:35:34 -0700322 * Returns the tab tag for a given content type.
323 */
324 public String getTabTagForContentType(AppsCustomizePagedView.ContentType type) {
325 if (type == AppsCustomizePagedView.ContentType.Applications) {
326 return APPS_TAB_TAG;
327 } else if (type == AppsCustomizePagedView.ContentType.Widgets) {
328 return WIDGETS_TAB_TAG;
329 }
330 return APPS_TAB_TAG;
331 }
332
333 /**
Winson Chung785d2eb2011-04-14 16:08:02 -0700334 * Disable focus on anything under this view in the hierarchy if we are not visible.
335 */
336 @Override
337 public int getDescendantFocusability() {
338 if (getVisibility() != View.VISIBLE) {
339 return ViewGroup.FOCUS_BLOCK_DESCENDANTS;
340 }
341 return super.getDescendantFocusability();
342 }
343
Winson Chungc100e8e2011-08-09 16:02:43 -0700344 void reset() {
345 if (mInTransition) {
346 // Defer to after the transition to reset
347 mResetAfterTransition = true;
348 } else {
349 // Reset immediately
350 mAppsCustomizePane.reset();
351 }
352 }
353
Michael Jurka1899a362011-11-03 13:50:45 -0700354 private void enableAndBuildHardwareLayer() {
Michael Jurka19e0fc52011-07-22 18:00:21 -0700355 // isHardwareAccelerated() checks if we're attached to a window and if that
356 // window is HW accelerated-- we were sometimes not attached to a window
357 // and buildLayer was throwing an IllegalStateException
Michael Jurka1899a362011-11-03 13:50:45 -0700358 if (isHardwareAccelerated()) {
Winson Chungf0ea4d32011-06-06 14:27:16 -0700359 // Turn on hardware layers for performance
360 setLayerType(LAYER_TYPE_HARDWARE, null);
361
Michael Jurka1899a362011-11-03 13:50:45 -0700362 // force building the layer, so you don't get a blip early in an animation
363 // when the layer is created layer
Winson Chungf0ea4d32011-06-06 14:27:16 -0700364 buildLayer();
365 }
Michael Jurka1899a362011-11-03 13:50:45 -0700366 }
367
Michael Jurka2a4b1a82011-12-07 14:00:02 -0800368 @Override
369 public View getContent() {
Winson Chung7bb37522013-10-28 11:07:57 -0700370 View appsCustomizeContent = mAppsCustomizePane.getContent();
371 if (appsCustomizeContent != null) {
372 return appsCustomizeContent;
373 }
Michael Jurka2a4b1a82011-12-07 14:00:02 -0800374 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);
387 } else {
388 // Going from Workspace -> All Apps
389 mContent.setVisibility(VISIBLE);
Michael Jurka3d845e82011-11-15 17:04:31 -0800390
Michael Jurkae326f182011-11-21 14:05:46 -0800391 // Make sure the current page is loaded (we start loading the side pages after the
392 // transition to prevent slowing down the animation)
393 mAppsCustomizePane.loadAssociatedPages(mAppsCustomizePane.getCurrentPage(), true);
Michael Jurka1899a362011-11-03 13:50:45 -0700394 }
395
Winson Chungc100e8e2011-08-09 16:02:43 -0700396 if (mResetAfterTransition) {
397 mAppsCustomizePane.reset();
398 mResetAfterTransition = false;
399 }
Michael Jurkaa35e35a2012-04-26 15:04:28 -0700400 }
Michael Jurkabed61d22012-02-14 22:51:29 -0800401
Michael Jurkaa35e35a2012-04-26 15:04:28 -0700402 @Override
403 public void onLauncherTransitionStart(Launcher l, boolean animated, boolean toWorkspace) {
Winson Chung7bb37522013-10-28 11:07:57 -0700404 mAppsCustomizePane.onLauncherTransitionStart(l, animated, toWorkspace);
Michael Jurkabed61d22012-02-14 22:51:29 -0800405 if (animated) {
406 enableAndBuildHardwareLayer();
407 }
Winson Chungaf40f202013-09-18 18:26:31 -0700408
409 // Dismiss the workspace cling
Winson Chunga6945242014-01-08 14:04:34 -0800410 l.getLauncherClings().dismissWorkspaceCling(null);
Winson Chung785d2eb2011-04-14 16:08:02 -0700411 }
Winson Chungf0ea4d32011-06-06 14:27:16 -0700412
Winson Chung785d2eb2011-04-14 16:08:02 -0700413 @Override
Winson Chung70442722012-02-10 15:43:22 -0800414 public void onLauncherTransitionStep(Launcher l, float t) {
Winson Chung7bb37522013-10-28 11:07:57 -0700415 mAppsCustomizePane.onLauncherTransitionStep(l, t);
Winson Chung70442722012-02-10 15:43:22 -0800416 }
417
418 @Override
Michael Jurkabed61d22012-02-14 22:51:29 -0800419 public void onLauncherTransitionEnd(Launcher l, boolean animated, boolean toWorkspace) {
Michael Jurka39e5d172012-03-12 18:36:12 -0700420 mAppsCustomizePane.onLauncherTransitionEnd(l, animated, toWorkspace);
Winson Chungc100e8e2011-08-09 16:02:43 -0700421 mInTransition = false;
Michael Jurkabed61d22012-02-14 22:51:29 -0800422 if (animated) {
Winson Chungf0ea4d32011-06-06 14:27:16 -0700423 setLayerType(LAYER_TYPE_NONE, null);
424 }
Winson Chung3ac74c52011-06-30 17:39:37 -0700425
Winson Chung7d7541e2011-09-16 20:14:36 -0700426 if (!toWorkspace) {
Winson Chung7819abd2012-11-29 14:29:38 -0800427 // Show the all apps cling (if not already shown)
Winson Chung3f4e1422011-11-17 14:58:51 -0800428 mAppsCustomizePane.showAllAppsCling();
Michael Jurkae326f182011-11-21 14:05:46 -0800429 // Make sure adjacent pages are loaded (we wait until after the transition to
430 // prevent slowing down the animation)
431 mAppsCustomizePane.loadAssociatedPages(mAppsCustomizePane.getCurrentPage());
Winson Chung7d7541e2011-09-16 20:14:36 -0700432
Winson Chung7819abd2012-11-29 14:29:38 -0800433 // Going from Workspace -> All Apps
434 // NOTE: We should do this at the end since we check visibility state in some of the
435 // cling initialization/dismiss code above.
436 setVisibilityOfSiblingsWithLowerZOrder(INVISIBLE);
Winson Chung5a808352011-06-27 19:08:49 -0700437 }
Winson Chung785d2eb2011-04-14 16:08:02 -0700438 }
Winson Chung70d72102011-08-12 11:24:35 -0700439
Michael Jurkabed61d22012-02-14 22:51:29 -0800440 private void setVisibilityOfSiblingsWithLowerZOrder(int visibility) {
441 ViewGroup parent = (ViewGroup) getParent();
Michael Jurkaaea1ce52012-04-12 11:23:21 -0700442 if (parent == null) return;
443
Adam Cohen3d411982013-09-24 17:02:06 -0700444 View overviewPanel = ((Launcher) getContext()).getOverviewPanel();
Michael Jurkabed61d22012-02-14 22:51:29 -0800445 final int count = parent.getChildCount();
446 if (!isChildrenDrawingOrderEnabled()) {
447 for (int i = 0; i < count; i++) {
448 final View child = parent.getChildAt(i);
449 if (child == this) {
450 break;
451 } else {
Adam Cohen3d411982013-09-24 17:02:06 -0700452 if (child.getVisibility() == GONE || child == overviewPanel) {
Michael Jurkabed61d22012-02-14 22:51:29 -0800453 continue;
454 }
455 child.setVisibility(visibility);
456 }
457 }
458 } else {
459 throw new RuntimeException("Failed; can't get z-order of views");
460 }
461 }
462
Michael Jurka2a4b1a82011-12-07 14:00:02 -0800463 public void onWindowVisible() {
Michael Jurkae326f182011-11-21 14:05:46 -0800464 if (getVisibility() == VISIBLE) {
465 mContent.setVisibility(VISIBLE);
466 // We unload the widget previews when the UI is hidden, so need to reload pages
467 // Load the current page synchronously, and the neighboring pages asynchronously
468 mAppsCustomizePane.loadAssociatedPages(mAppsCustomizePane.getCurrentPage(), true);
469 mAppsCustomizePane.loadAssociatedPages(mAppsCustomizePane.getCurrentPage());
470 }
471 }
472
473 public void onTrimMemory() {
474 mContent.setVisibility(GONE);
475 // Clear the widget pages of all their subviews - this will trigger the widget previews
476 // to delete their bitmaps
477 mAppsCustomizePane.clearAllWidgetPages();
478 }
479
Winson Chung70d72102011-08-12 11:24:35 -0700480 boolean isTransitioning() {
481 return mInTransition;
482 }
Winson Chung785d2eb2011-04-14 16:08:02 -0700483}