Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 1 | /* |
| 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 Sandler | 325dc23 | 2013-06-05 22:57:57 -0400 | [diff] [blame] | 17 | package com.android.launcher3; |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 18 | |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 19 | import android.animation.Animator; |
Winson Chung | b44b524 | 2011-06-13 11:32:14 -0700 | [diff] [blame] | 20 | import android.animation.AnimatorListenerAdapter; |
Winson Chung | f314b0e | 2011-08-16 11:54:27 -0700 | [diff] [blame] | 21 | import android.animation.AnimatorSet; |
Winson Chung | b44b524 | 2011-06-13 11:32:14 -0700 | [diff] [blame] | 22 | import android.animation.ObjectAnimator; |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 23 | import android.content.Context; |
| 24 | import android.content.res.Resources; |
Winson Chung | 2d75f12 | 2013-09-23 16:53:31 -0700 | [diff] [blame] | 25 | import android.graphics.Color; |
John Spurlock | 77e1f47 | 2013-09-11 10:09:51 -0400 | [diff] [blame] | 26 | import android.graphics.Rect; |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 27 | import android.util.AttributeSet; |
| 28 | import android.view.LayoutInflater; |
Winson Chung | 4179b4e | 2011-05-31 17:28:12 -0700 | [diff] [blame] | 29 | import android.view.MotionEvent; |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 30 | import android.view.View; |
| 31 | import android.view.ViewGroup; |
Jason Monk | ed05f09 | 2014-04-24 10:13:05 -0400 | [diff] [blame] | 32 | import android.view.accessibility.AccessibilityManager; |
Michael Jurka | 141dbd0 | 2011-11-03 13:50:45 -0700 | [diff] [blame] | 33 | import android.widget.FrameLayout; |
Michael Jurka | 1899a36 | 2011-11-03 13:50:45 -0700 | [diff] [blame] | 34 | import android.widget.LinearLayout; |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 35 | import android.widget.TabHost; |
Winson Chung | faa1325 | 2011-06-13 18:15:54 -0700 | [diff] [blame] | 36 | import android.widget.TabWidget; |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 37 | import android.widget.TextView; |
| 38 | |
Michael Jurka | 141dbd0 | 2011-11-03 13:50:45 -0700 | [diff] [blame] | 39 | import java.util.ArrayList; |
| 40 | |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 41 | public class AppsCustomizeTabHost extends TabHost implements LauncherTransitionable, |
John Spurlock | 77e1f47 | 2013-09-11 10:09:51 -0400 | [diff] [blame] | 42 | TabHost.OnTabChangeListener, Insettable { |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 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 Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 49 | private ViewGroup mTabs; |
Winson Chung | fd3385f | 2011-06-15 19:51:24 -0700 | [diff] [blame] | 50 | private ViewGroup mTabsContainer; |
Winson Chung | 4179b4e | 2011-05-31 17:28:12 -0700 | [diff] [blame] | 51 | private AppsCustomizePagedView mAppsCustomizePane; |
Michael Jurka | 141dbd0 | 2011-11-03 13:50:45 -0700 | [diff] [blame] | 52 | private FrameLayout mAnimationBuffer; |
Michael Jurka | 1899a36 | 2011-11-03 13:50:45 -0700 | [diff] [blame] | 53 | private LinearLayout mContent; |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 54 | |
Winson Chung | c100e8e | 2011-08-09 16:02:43 -0700 | [diff] [blame] | 55 | private boolean mInTransition; |
Winson Chung | 7044272 | 2012-02-10 15:43:22 -0800 | [diff] [blame] | 56 | private boolean mTransitioningToWorkspace; |
Winson Chung | c100e8e | 2011-08-09 16:02:43 -0700 | [diff] [blame] | 57 | private boolean mResetAfterTransition; |
Michael Jurka | 6cfafb9 | 2012-02-23 18:25:43 -0800 | [diff] [blame] | 58 | private Runnable mRelayoutAndMakeVisible; |
John Spurlock | 77e1f47 | 2013-09-11 10:09:51 -0400 | [diff] [blame] | 59 | private final Rect mInsets = new Rect(); |
Winson Chung | c100e8e | 2011-08-09 16:02:43 -0700 | [diff] [blame] | 60 | |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 61 | public AppsCustomizeTabHost(Context context, AttributeSet attrs) { |
| 62 | super(context, attrs); |
| 63 | mLayoutInflater = LayoutInflater.from(context); |
Michael Jurka | 6cfafb9 | 2012-02-23 18:25:43 -0800 | [diff] [blame] | 64 | mRelayoutAndMakeVisible = new Runnable() { |
| 65 | public void run() { |
| 66 | mTabs.requestLayout(); |
| 67 | mTabsContainer.setAlpha(1f); |
| 68 | } |
| 69 | }; |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 70 | } |
| 71 | |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 72 | /** |
Winson Chung | 5a80835 | 2011-06-27 19:08:49 -0700 | [diff] [blame] | 73 | * Convenience methods to select specific tabs. We want to set the content type immediately |
| 74 | * in these cases, but we note that we still call setCurrentTabByTag() so that the tab view |
| 75 | * reflects the new content (but doesn't do the animation and logic associated with changing |
| 76 | * tabs manually). |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 77 | */ |
Winson Chung | c93e5ae | 2012-07-23 20:48:26 -0700 | [diff] [blame] | 78 | void setContentTypeImmediate(AppsCustomizePagedView.ContentType type) { |
Winson Chung | fa4086d | 2012-07-25 16:18:49 -0700 | [diff] [blame] | 79 | setOnTabChangedListener(null); |
Winson Chung | 5a80835 | 2011-06-27 19:08:49 -0700 | [diff] [blame] | 80 | onTabChangedStart(); |
| 81 | onTabChangedEnd(type); |
Winson Chung | fa4086d | 2012-07-25 16:18:49 -0700 | [diff] [blame] | 82 | setCurrentTabByTag(getTabTagForContentType(type)); |
| 83 | setOnTabChangedListener(this); |
Winson Chung | 5a80835 | 2011-06-27 19:08:49 -0700 | [diff] [blame] | 84 | } |
Adam Cohen | 947dc54 | 2013-06-06 22:43:33 -0700 | [diff] [blame] | 85 | |
John Spurlock | 77e1f47 | 2013-09-11 10:09:51 -0400 | [diff] [blame] | 86 | @Override |
| 87 | public void setInsets(Rect insets) { |
| 88 | mInsets.set(insets); |
| 89 | FrameLayout.LayoutParams flp = (LayoutParams) mContent.getLayoutParams(); |
| 90 | flp.topMargin = insets.top; |
| 91 | flp.bottomMargin = insets.bottom; |
| 92 | flp.leftMargin = insets.left; |
| 93 | flp.rightMargin = insets.right; |
| 94 | mContent.setLayoutParams(flp); |
| 95 | } |
| 96 | |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 97 | /** |
| 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 Chung | fd3385f | 2011-06-15 19:51:24 -0700 | [diff] [blame] | 105 | final ViewGroup tabsContainer = (ViewGroup) findViewById(R.id.tabs_container); |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 106 | final TabWidget tabs = getTabWidget(); |
Winson Chung | 4179b4e | 2011-05-31 17:28:12 -0700 | [diff] [blame] | 107 | final AppsCustomizePagedView appsCustomizePane = (AppsCustomizePagedView) |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 108 | findViewById(R.id.apps_customize_pane_content); |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 109 | mTabs = tabs; |
Winson Chung | fd3385f | 2011-06-15 19:51:24 -0700 | [diff] [blame] | 110 | mTabsContainer = tabsContainer; |
Winson Chung | 4179b4e | 2011-05-31 17:28:12 -0700 | [diff] [blame] | 111 | mAppsCustomizePane = appsCustomizePane; |
Michael Jurka | 141dbd0 | 2011-11-03 13:50:45 -0700 | [diff] [blame] | 112 | mAnimationBuffer = (FrameLayout) findViewById(R.id.animation_buffer); |
Michael Jurka | 1899a36 | 2011-11-03 13:50:45 -0700 | [diff] [blame] | 113 | mContent = (LinearLayout) findViewById(R.id.apps_customize_content); |
Winson Chung | 4179b4e | 2011-05-31 17:28:12 -0700 | [diff] [blame] | 114 | if (tabs == null || mAppsCustomizePane == null) throw new Resources.NotFoundException(); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 115 | |
| 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 Chung | 4179b4e | 2011-05-31 17:28:12 -0700 | [diff] [blame] | 120 | return appsCustomizePane; |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 121 | } |
| 122 | }; |
| 123 | |
| 124 | // Create the tabs |
| 125 | TextView tabView; |
Winson Chung | d2c1f80 | 2011-10-14 12:26:54 -0700 | [diff] [blame] | 126 | String label; |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 127 | label = getContext().getString(R.string.all_apps_button_label); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 128 | tabView = (TextView) mLayoutInflater.inflate(R.layout.tab_widget_indicator, tabs, false); |
Winson Chung | d2c1f80 | 2011-10-14 12:26:54 -0700 | [diff] [blame] | 129 | tabView.setText(label); |
| 130 | tabView.setContentDescription(label); |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 131 | addTab(newTabSpec(APPS_TAB_TAG).setIndicator(tabView).setContent(contentFactory)); |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 132 | label = getContext().getString(R.string.widgets_tab_label); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 133 | tabView = (TextView) mLayoutInflater.inflate(R.layout.tab_widget_indicator, tabs, false); |
Winson Chung | d2c1f80 | 2011-10-14 12:26:54 -0700 | [diff] [blame] | 134 | tabView.setText(label); |
| 135 | tabView.setContentDescription(label); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 136 | addTab(newTabSpec(WIDGETS_TAB_TAG).setIndicator(tabView).setContent(contentFactory)); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 137 | setOnTabChangedListener(this); |
Winson Chung | faa1325 | 2011-06-13 18:15:54 -0700 | [diff] [blame] | 138 | |
| 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 Chung | fd3385f | 2011-06-15 19:51:24 -0700 | [diff] [blame] | 145 | |
| 146 | // Hide the tab bar until we measure |
| 147 | mTabsContainer.setAlpha(0f); |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 148 | } |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 149 | |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 150 | @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 Chung | fd3385f | 2011-06-15 19:51:24 -0700 | [diff] [blame] | 157 | int contentWidth = mAppsCustomizePane.getPageContentWidth(); |
Michael Jurka | 141dbd0 | 2011-11-03 13:50:45 -0700 | [diff] [blame] | 158 | if (contentWidth > 0 && mTabs.getLayoutParams().width != contentWidth) { |
| 159 | // Set the width and show the tab bar |
Winson Chung | fd3385f | 2011-06-15 19:51:24 -0700 | [diff] [blame] | 160 | mTabs.getLayoutParams().width = contentWidth; |
Winson Chung | c93e5ae | 2012-07-23 20:48:26 -0700 | [diff] [blame] | 161 | mRelayoutAndMakeVisible.run(); |
Winson Chung | fd3385f | 2011-06-15 19:51:24 -0700 | [diff] [blame] | 162 | } |
Winson Chung | c93e5ae | 2012-07-23 20:48:26 -0700 | [diff] [blame] | 163 | |
| 164 | super.onMeasure(widthMeasureSpec, heightMeasureSpec); |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 165 | } |
Winson Chung | 4179b4e | 2011-05-31 17:28:12 -0700 | [diff] [blame] | 166 | } |
| 167 | |
Winson Chung | 7044272 | 2012-02-10 15:43:22 -0800 | [diff] [blame] | 168 | public boolean onInterceptTouchEvent(MotionEvent ev) { |
Winson Chung | ac08f4b | 2012-04-27 15:41:00 -0700 | [diff] [blame] | 169 | // If we are mid transitioning to the workspace, then intercept touch events here so we |
| 170 | // can ignore them, otherwise we just let all apps handle the touch events. |
| 171 | if (mInTransition && mTransitioningToWorkspace) { |
Winson Chung | 7044272 | 2012-02-10 15:43:22 -0800 | [diff] [blame] | 172 | return true; |
| 173 | } |
| 174 | return super.onInterceptTouchEvent(ev); |
| 175 | }; |
| 176 | |
Winson Chung | 4179b4e | 2011-05-31 17:28:12 -0700 | [diff] [blame] | 177 | @Override |
| 178 | public boolean onTouchEvent(MotionEvent event) { |
Winson Chung | ac08f4b | 2012-04-27 15:41:00 -0700 | [diff] [blame] | 179 | // Allow touch events to fall through to the workspace if we are transitioning there |
| 180 | if (mInTransition && mTransitioningToWorkspace) { |
Winson Chung | 21fadea | 2012-04-27 15:59:55 -0700 | [diff] [blame] | 181 | return super.onTouchEvent(event); |
Winson Chung | 7044272 | 2012-02-10 15:43:22 -0800 | [diff] [blame] | 182 | } |
| 183 | |
Winson Chung | 4179b4e | 2011-05-31 17:28:12 -0700 | [diff] [blame] | 184 | // Intercept all touch events up to the bottom of the AppsCustomizePane so they do not fall |
| 185 | // through to the workspace and trigger showWorkspace() |
| 186 | if (event.getY() < mAppsCustomizePane.getBottom()) { |
| 187 | return true; |
| 188 | } |
| 189 | return super.onTouchEvent(event); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 190 | } |
| 191 | |
Winson Chung | 5a80835 | 2011-06-27 19:08:49 -0700 | [diff] [blame] | 192 | private void onTabChangedStart() { |
Winson Chung | 5a80835 | 2011-06-27 19:08:49 -0700 | [diff] [blame] | 193 | } |
Adam Cohen | 0cd3b64 | 2011-10-14 14:58:00 -0700 | [diff] [blame] | 194 | |
Winson Chung | 097e6c7 | 2011-10-20 13:58:30 -0700 | [diff] [blame] | 195 | private void reloadCurrentPage() { |
Winson Chung | 097e6c7 | 2011-10-20 13:58:30 -0700 | [diff] [blame] | 196 | mAppsCustomizePane.loadAssociatedPages(mAppsCustomizePane.getCurrentPage()); |
| 197 | mAppsCustomizePane.requestFocus(); |
| 198 | } |
| 199 | |
Winson Chung | 5a80835 | 2011-06-27 19:08:49 -0700 | [diff] [blame] | 200 | private void onTabChangedEnd(AppsCustomizePagedView.ContentType type) { |
Winson Chung | 2d75f12 | 2013-09-23 16:53:31 -0700 | [diff] [blame] | 201 | int bgAlpha = (int) (255 * (getResources().getInteger( |
| 202 | R.integer.config_appsCustomizeSpringLoadedBgAlpha) / 100f)); |
| 203 | setBackgroundColor(Color.argb(bgAlpha, 0, 0, 0)); |
Winson Chung | 5a80835 | 2011-06-27 19:08:49 -0700 | [diff] [blame] | 204 | mAppsCustomizePane.setContentType(type); |
| 205 | } |
| 206 | |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 207 | @Override |
| 208 | public void onTabChanged(String tabId) { |
Winson Chung | b44b524 | 2011-06-13 11:32:14 -0700 | [diff] [blame] | 209 | final AppsCustomizePagedView.ContentType type = getContentTypeForTabTag(tabId); |
Adam Cohen | 0cd3b64 | 2011-10-14 14:58:00 -0700 | [diff] [blame] | 210 | |
| 211 | // Animate the changing of the tab content by fading pages in and out |
| 212 | final Resources res = getResources(); |
| 213 | final int duration = res.getInteger(R.integer.config_tabTransitionDuration); |
| 214 | |
| 215 | // We post a runnable here because there is a delay while the first page is loading and |
| 216 | // the feedback from having changed the tab almost feels better than having it stick |
| 217 | post(new Runnable() { |
| 218 | @Override |
| 219 | public void run() { |
Winson Chung | 097e6c7 | 2011-10-20 13:58:30 -0700 | [diff] [blame] | 220 | if (mAppsCustomizePane.getMeasuredWidth() <= 0 || |
| 221 | mAppsCustomizePane.getMeasuredHeight() <= 0) { |
| 222 | reloadCurrentPage(); |
| 223 | return; |
| 224 | } |
| 225 | |
Michael Jurka | 141dbd0 | 2011-11-03 13:50:45 -0700 | [diff] [blame] | 226 | // Take the visible pages and re-parent them temporarily to mAnimatorBuffer |
| 227 | // and then cross fade to the new pages |
Winson Chung | c6f10b9 | 2011-11-14 11:39:07 -0800 | [diff] [blame] | 228 | int[] visiblePageRange = new int[2]; |
| 229 | mAppsCustomizePane.getVisiblePages(visiblePageRange); |
| 230 | if (visiblePageRange[0] == -1 && visiblePageRange[1] == -1) { |
| 231 | // If we can't get the visible page ranges, then just skip the animation |
| 232 | reloadCurrentPage(); |
| 233 | return; |
| 234 | } |
| 235 | ArrayList<View> visiblePages = new ArrayList<View>(); |
| 236 | for (int i = visiblePageRange[0]; i <= visiblePageRange[1]; i++) { |
| 237 | visiblePages.add(mAppsCustomizePane.getPageAt(i)); |
| 238 | } |
Michael Jurka | 141dbd0 | 2011-11-03 13:50:45 -0700 | [diff] [blame] | 239 | |
| 240 | // We want the pages to be rendered in exactly the same way as they were when |
| 241 | // their parent was mAppsCustomizePane -- so set the scroll on mAnimationBuffer |
| 242 | // to be exactly the same as mAppsCustomizePane, and below, set the left/top |
| 243 | // parameters to be correct for each of the pages |
| 244 | mAnimationBuffer.scrollTo(mAppsCustomizePane.getScrollX(), 0); |
| 245 | |
Michael Jurka | 141dbd0 | 2011-11-03 13:50:45 -0700 | [diff] [blame] | 246 | // mAppsCustomizePane renders its children in reverse order, so |
| 247 | // add the pages to mAnimationBuffer in reverse order to match that behavior |
| 248 | for (int i = visiblePages.size() - 1; i >= 0; i--) { |
| 249 | View child = visiblePages.get(i); |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 250 | if (child instanceof AppsCustomizeCellLayout) { |
| 251 | ((AppsCustomizeCellLayout) child).resetChildrenOnKeyListeners(); |
Winson Chung | c6f10b9 | 2011-11-14 11:39:07 -0800 | [diff] [blame] | 252 | } else if (child instanceof PagedViewGridLayout) { |
| 253 | ((PagedViewGridLayout) child).resetChildrenOnKeyListeners(); |
| 254 | } |
Michael Jurka | 141dbd0 | 2011-11-03 13:50:45 -0700 | [diff] [blame] | 255 | PagedViewWidget.setDeletePreviewsWhenDetachedFromWindow(false); |
| 256 | mAppsCustomizePane.removeView(child); |
| 257 | PagedViewWidget.setDeletePreviewsWhenDetachedFromWindow(true); |
| 258 | mAnimationBuffer.setAlpha(1f); |
| 259 | mAnimationBuffer.setVisibility(View.VISIBLE); |
Winson Chung | 6e3cf90 | 2012-03-30 16:36:53 -0700 | [diff] [blame] | 260 | LayoutParams p = new FrameLayout.LayoutParams(child.getMeasuredWidth(), |
| 261 | child.getMeasuredHeight()); |
Michael Jurka | 141dbd0 | 2011-11-03 13:50:45 -0700 | [diff] [blame] | 262 | p.setMargins((int) child.getLeft(), (int) child.getTop(), 0, 0); |
| 263 | mAnimationBuffer.addView(child, p); |
| 264 | } |
Adam Cohen | 0cd3b64 | 2011-10-14 14:58:00 -0700 | [diff] [blame] | 265 | |
| 266 | // Toggle the new content |
| 267 | onTabChangedStart(); |
| 268 | onTabChangedEnd(type); |
| 269 | |
| 270 | // Animate the transition |
Michael Jurka | 2ecf995 | 2012-06-18 12:52:28 -0700 | [diff] [blame] | 271 | ObjectAnimator outAnim = LauncherAnimUtils.ofFloat(mAnimationBuffer, "alpha", 0f); |
Adam Cohen | 0cd3b64 | 2011-10-14 14:58:00 -0700 | [diff] [blame] | 272 | outAnim.addListener(new AnimatorListenerAdapter() { |
Michael Jurka | ee8e99f | 2013-02-07 13:27:06 +0100 | [diff] [blame] | 273 | private void clearAnimationBuffer() { |
| 274 | mAnimationBuffer.setVisibility(View.GONE); |
| 275 | PagedViewWidget.setRecyclePreviewsWhenDetachedFromWindow(false); |
| 276 | mAnimationBuffer.removeAllViews(); |
| 277 | PagedViewWidget.setRecyclePreviewsWhenDetachedFromWindow(true); |
| 278 | } |
Adam Cohen | 0cd3b64 | 2011-10-14 14:58:00 -0700 | [diff] [blame] | 279 | @Override |
| 280 | public void onAnimationEnd(Animator animation) { |
Michael Jurka | ee8e99f | 2013-02-07 13:27:06 +0100 | [diff] [blame] | 281 | clearAnimationBuffer(); |
Michael Jurka | 141dbd0 | 2011-11-03 13:50:45 -0700 | [diff] [blame] | 282 | } |
| 283 | @Override |
| 284 | public void onAnimationCancel(Animator animation) { |
Michael Jurka | ee8e99f | 2013-02-07 13:27:06 +0100 | [diff] [blame] | 285 | clearAnimationBuffer(); |
Adam Cohen | 0cd3b64 | 2011-10-14 14:58:00 -0700 | [diff] [blame] | 286 | } |
| 287 | }); |
Michael Jurka | 2ecf995 | 2012-06-18 12:52:28 -0700 | [diff] [blame] | 288 | ObjectAnimator inAnim = LauncherAnimUtils.ofFloat(mAppsCustomizePane, "alpha", 1f); |
Adam Cohen | 0cd3b64 | 2011-10-14 14:58:00 -0700 | [diff] [blame] | 289 | inAnim.addListener(new AnimatorListenerAdapter() { |
| 290 | @Override |
| 291 | public void onAnimationEnd(Animator animation) { |
Winson Chung | 097e6c7 | 2011-10-20 13:58:30 -0700 | [diff] [blame] | 292 | reloadCurrentPage(); |
Adam Cohen | 0cd3b64 | 2011-10-14 14:58:00 -0700 | [diff] [blame] | 293 | } |
| 294 | }); |
Michael Jurka | 7f9ddd8 | 2012-11-19 16:15:24 -0800 | [diff] [blame] | 295 | |
| 296 | final AnimatorSet animSet = LauncherAnimUtils.createAnimatorSet(); |
Adam Cohen | 0cd3b64 | 2011-10-14 14:58:00 -0700 | [diff] [blame] | 297 | animSet.playTogether(outAnim, inAnim); |
| 298 | animSet.setDuration(duration); |
Michael Jurka | f1ad608 | 2013-03-13 12:55:46 +0100 | [diff] [blame] | 299 | animSet.start(); |
Adam Cohen | 0cd3b64 | 2011-10-14 14:58:00 -0700 | [diff] [blame] | 300 | } |
| 301 | }); |
| 302 | } |
| 303 | |
| 304 | public void setCurrentTabFromContent(AppsCustomizePagedView.ContentType type) { |
Winson Chung | fa4086d | 2012-07-25 16:18:49 -0700 | [diff] [blame] | 305 | setOnTabChangedListener(null); |
Adam Cohen | 0cd3b64 | 2011-10-14 14:58:00 -0700 | [diff] [blame] | 306 | setCurrentTabByTag(getTabTagForContentType(type)); |
Winson Chung | fa4086d | 2012-07-25 16:18:49 -0700 | [diff] [blame] | 307 | setOnTabChangedListener(this); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 308 | } |
| 309 | |
| 310 | /** |
| 311 | * Returns the content type for the specified tab tag. |
| 312 | */ |
| 313 | public AppsCustomizePagedView.ContentType getContentTypeForTabTag(String tag) { |
| 314 | if (tag.equals(APPS_TAB_TAG)) { |
| 315 | return AppsCustomizePagedView.ContentType.Applications; |
| 316 | } else if (tag.equals(WIDGETS_TAB_TAG)) { |
| 317 | return AppsCustomizePagedView.ContentType.Widgets; |
| 318 | } |
| 319 | return AppsCustomizePagedView.ContentType.Applications; |
| 320 | } |
| 321 | |
| 322 | /** |
Winson Chung | fc79c80 | 2011-05-02 13:35:34 -0700 | [diff] [blame] | 323 | * Returns the tab tag for a given content type. |
| 324 | */ |
| 325 | public String getTabTagForContentType(AppsCustomizePagedView.ContentType type) { |
| 326 | if (type == AppsCustomizePagedView.ContentType.Applications) { |
| 327 | return APPS_TAB_TAG; |
| 328 | } else if (type == AppsCustomizePagedView.ContentType.Widgets) { |
| 329 | return WIDGETS_TAB_TAG; |
| 330 | } |
| 331 | return APPS_TAB_TAG; |
| 332 | } |
| 333 | |
| 334 | /** |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 335 | * Disable focus on anything under this view in the hierarchy if we are not visible. |
| 336 | */ |
| 337 | @Override |
| 338 | public int getDescendantFocusability() { |
| 339 | if (getVisibility() != View.VISIBLE) { |
| 340 | return ViewGroup.FOCUS_BLOCK_DESCENDANTS; |
| 341 | } |
| 342 | return super.getDescendantFocusability(); |
| 343 | } |
| 344 | |
Winson Chung | c100e8e | 2011-08-09 16:02:43 -0700 | [diff] [blame] | 345 | void reset() { |
| 346 | if (mInTransition) { |
| 347 | // Defer to after the transition to reset |
| 348 | mResetAfterTransition = true; |
| 349 | } else { |
| 350 | // Reset immediately |
| 351 | mAppsCustomizePane.reset(); |
| 352 | } |
| 353 | } |
| 354 | |
Michael Jurka | 1899a36 | 2011-11-03 13:50:45 -0700 | [diff] [blame] | 355 | private void enableAndBuildHardwareLayer() { |
Michael Jurka | 19e0fc5 | 2011-07-22 18:00:21 -0700 | [diff] [blame] | 356 | // isHardwareAccelerated() checks if we're attached to a window and if that |
| 357 | // window is HW accelerated-- we were sometimes not attached to a window |
| 358 | // and buildLayer was throwing an IllegalStateException |
Michael Jurka | 1899a36 | 2011-11-03 13:50:45 -0700 | [diff] [blame] | 359 | if (isHardwareAccelerated()) { |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 360 | // Turn on hardware layers for performance |
| 361 | setLayerType(LAYER_TYPE_HARDWARE, null); |
| 362 | |
Michael Jurka | 1899a36 | 2011-11-03 13:50:45 -0700 | [diff] [blame] | 363 | // force building the layer, so you don't get a blip early in an animation |
| 364 | // when the layer is created layer |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 365 | buildLayer(); |
| 366 | } |
Michael Jurka | 1899a36 | 2011-11-03 13:50:45 -0700 | [diff] [blame] | 367 | } |
| 368 | |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 369 | @Override |
| 370 | public View getContent() { |
Winson Chung | 7bb3752 | 2013-10-28 11:07:57 -0700 | [diff] [blame] | 371 | View appsCustomizeContent = mAppsCustomizePane.getContent(); |
| 372 | if (appsCustomizeContent != null) { |
| 373 | return appsCustomizeContent; |
| 374 | } |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 375 | return mContent; |
Michael Jurka | 1899a36 | 2011-11-03 13:50:45 -0700 | [diff] [blame] | 376 | } |
| 377 | |
| 378 | /* LauncherTransitionable overrides */ |
| 379 | @Override |
Michael Jurka | a35e35a | 2012-04-26 15:04:28 -0700 | [diff] [blame] | 380 | public void onLauncherTransitionPrepare(Launcher l, boolean animated, boolean toWorkspace) { |
| 381 | mAppsCustomizePane.onLauncherTransitionPrepare(l, animated, toWorkspace); |
Michael Jurka | 1899a36 | 2011-11-03 13:50:45 -0700 | [diff] [blame] | 382 | mInTransition = true; |
Winson Chung | 7044272 | 2012-02-10 15:43:22 -0800 | [diff] [blame] | 383 | mTransitioningToWorkspace = toWorkspace; |
Michael Jurka | 1899a36 | 2011-11-03 13:50:45 -0700 | [diff] [blame] | 384 | |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 385 | if (toWorkspace) { |
| 386 | // Going from All Apps -> Workspace |
| 387 | setVisibilityOfSiblingsWithLowerZOrder(VISIBLE); |
| 388 | } else { |
| 389 | // Going from Workspace -> All Apps |
| 390 | mContent.setVisibility(VISIBLE); |
Michael Jurka | 3d845e8 | 2011-11-15 17:04:31 -0800 | [diff] [blame] | 391 | |
Michael Jurka | e326f18 | 2011-11-21 14:05:46 -0800 | [diff] [blame] | 392 | // Make sure the current page is loaded (we start loading the side pages after the |
| 393 | // transition to prevent slowing down the animation) |
| 394 | mAppsCustomizePane.loadAssociatedPages(mAppsCustomizePane.getCurrentPage(), true); |
Michael Jurka | 1899a36 | 2011-11-03 13:50:45 -0700 | [diff] [blame] | 395 | } |
| 396 | |
Winson Chung | c100e8e | 2011-08-09 16:02:43 -0700 | [diff] [blame] | 397 | if (mResetAfterTransition) { |
| 398 | mAppsCustomizePane.reset(); |
| 399 | mResetAfterTransition = false; |
| 400 | } |
Michael Jurka | a35e35a | 2012-04-26 15:04:28 -0700 | [diff] [blame] | 401 | } |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 402 | |
Michael Jurka | a35e35a | 2012-04-26 15:04:28 -0700 | [diff] [blame] | 403 | @Override |
| 404 | public void onLauncherTransitionStart(Launcher l, boolean animated, boolean toWorkspace) { |
Winson Chung | 7bb3752 | 2013-10-28 11:07:57 -0700 | [diff] [blame] | 405 | mAppsCustomizePane.onLauncherTransitionStart(l, animated, toWorkspace); |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 406 | if (animated) { |
| 407 | enableAndBuildHardwareLayer(); |
| 408 | } |
Winson Chung | af40f20 | 2013-09-18 18:26:31 -0700 | [diff] [blame] | 409 | |
| 410 | // Dismiss the workspace cling |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 411 | l.getLauncherClings().dismissWorkspaceCling(null); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 412 | } |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 413 | |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 414 | @Override |
Winson Chung | 7044272 | 2012-02-10 15:43:22 -0800 | [diff] [blame] | 415 | public void onLauncherTransitionStep(Launcher l, float t) { |
Winson Chung | 7bb3752 | 2013-10-28 11:07:57 -0700 | [diff] [blame] | 416 | mAppsCustomizePane.onLauncherTransitionStep(l, t); |
Winson Chung | 7044272 | 2012-02-10 15:43:22 -0800 | [diff] [blame] | 417 | } |
| 418 | |
| 419 | @Override |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 420 | public void onLauncherTransitionEnd(Launcher l, boolean animated, boolean toWorkspace) { |
Michael Jurka | 39e5d17 | 2012-03-12 18:36:12 -0700 | [diff] [blame] | 421 | mAppsCustomizePane.onLauncherTransitionEnd(l, animated, toWorkspace); |
Winson Chung | c100e8e | 2011-08-09 16:02:43 -0700 | [diff] [blame] | 422 | mInTransition = false; |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 423 | if (animated) { |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 424 | setLayerType(LAYER_TYPE_NONE, null); |
| 425 | } |
Winson Chung | 3ac74c5 | 2011-06-30 17:39:37 -0700 | [diff] [blame] | 426 | |
Winson Chung | 7d7541e | 2011-09-16 20:14:36 -0700 | [diff] [blame] | 427 | if (!toWorkspace) { |
Winson Chung | 7819abd | 2012-11-29 14:29:38 -0800 | [diff] [blame] | 428 | // Show the all apps cling (if not already shown) |
Winson Chung | 3f4e142 | 2011-11-17 14:58:51 -0800 | [diff] [blame] | 429 | mAppsCustomizePane.showAllAppsCling(); |
Michael Jurka | e326f18 | 2011-11-21 14:05:46 -0800 | [diff] [blame] | 430 | // Make sure adjacent pages are loaded (we wait until after the transition to |
| 431 | // prevent slowing down the animation) |
| 432 | mAppsCustomizePane.loadAssociatedPages(mAppsCustomizePane.getCurrentPage()); |
Winson Chung | 7d7541e | 2011-09-16 20:14:36 -0700 | [diff] [blame] | 433 | |
Jason Monk | ed05f09 | 2014-04-24 10:13:05 -0400 | [diff] [blame] | 434 | // Opening apps, need to announce what page we are on. |
| 435 | AccessibilityManager am = (AccessibilityManager) |
| 436 | getContext().getSystemService(Context.ACCESSIBILITY_SERVICE); |
| 437 | if (am.isEnabled()) { |
| 438 | // Notify the user when the page changes |
| 439 | announceForAccessibility(mAppsCustomizePane.getCurrentPageDescription()); |
| 440 | } |
| 441 | |
Winson Chung | 7819abd | 2012-11-29 14:29:38 -0800 | [diff] [blame] | 442 | // Going from Workspace -> All Apps |
| 443 | // NOTE: We should do this at the end since we check visibility state in some of the |
| 444 | // cling initialization/dismiss code above. |
| 445 | setVisibilityOfSiblingsWithLowerZOrder(INVISIBLE); |
Winson Chung | 5a80835 | 2011-06-27 19:08:49 -0700 | [diff] [blame] | 446 | } |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 447 | } |
Winson Chung | 70d7210 | 2011-08-12 11:24:35 -0700 | [diff] [blame] | 448 | |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 449 | private void setVisibilityOfSiblingsWithLowerZOrder(int visibility) { |
| 450 | ViewGroup parent = (ViewGroup) getParent(); |
Michael Jurka | aea1ce5 | 2012-04-12 11:23:21 -0700 | [diff] [blame] | 451 | if (parent == null) return; |
| 452 | |
Adam Cohen | 3d41198 | 2013-09-24 17:02:06 -0700 | [diff] [blame] | 453 | View overviewPanel = ((Launcher) getContext()).getOverviewPanel(); |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 454 | final int count = parent.getChildCount(); |
| 455 | if (!isChildrenDrawingOrderEnabled()) { |
| 456 | for (int i = 0; i < count; i++) { |
| 457 | final View child = parent.getChildAt(i); |
| 458 | if (child == this) { |
| 459 | break; |
| 460 | } else { |
Adam Cohen | 3d41198 | 2013-09-24 17:02:06 -0700 | [diff] [blame] | 461 | if (child.getVisibility() == GONE || child == overviewPanel) { |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 462 | continue; |
| 463 | } |
| 464 | child.setVisibility(visibility); |
| 465 | } |
| 466 | } |
| 467 | } else { |
| 468 | throw new RuntimeException("Failed; can't get z-order of views"); |
| 469 | } |
| 470 | } |
| 471 | |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 472 | public void onWindowVisible() { |
Michael Jurka | e326f18 | 2011-11-21 14:05:46 -0800 | [diff] [blame] | 473 | if (getVisibility() == VISIBLE) { |
| 474 | mContent.setVisibility(VISIBLE); |
| 475 | // We unload the widget previews when the UI is hidden, so need to reload pages |
| 476 | // Load the current page synchronously, and the neighboring pages asynchronously |
| 477 | mAppsCustomizePane.loadAssociatedPages(mAppsCustomizePane.getCurrentPage(), true); |
| 478 | mAppsCustomizePane.loadAssociatedPages(mAppsCustomizePane.getCurrentPage()); |
| 479 | } |
| 480 | } |
| 481 | |
| 482 | public void onTrimMemory() { |
| 483 | mContent.setVisibility(GONE); |
| 484 | // Clear the widget pages of all their subviews - this will trigger the widget previews |
| 485 | // to delete their bitmaps |
| 486 | mAppsCustomizePane.clearAllWidgetPages(); |
| 487 | } |
| 488 | |
Winson Chung | 70d7210 | 2011-08-12 11:24:35 -0700 | [diff] [blame] | 489 | boolean isTransitioning() { |
| 490 | return mInTransition; |
| 491 | } |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 492 | } |