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 | |
| 19 | import android.content.Context; |
John Spurlock | 77e1f47 | 2013-09-11 10:09:51 -0400 | [diff] [blame] | 20 | import android.graphics.Rect; |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 21 | import android.util.AttributeSet; |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 22 | import android.view.View; |
| 23 | import android.view.ViewGroup; |
Jason Monk | ed05f09 | 2014-04-24 10:13:05 -0400 | [diff] [blame] | 24 | import android.view.accessibility.AccessibilityManager; |
Michael Jurka | 141dbd0 | 2011-11-03 13:50:45 -0700 | [diff] [blame] | 25 | import android.widget.FrameLayout; |
Michael Jurka | 141dbd0 | 2011-11-03 13:50:45 -0700 | [diff] [blame] | 26 | |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 27 | public class AppsCustomizeTabHost extends FrameLayout implements LauncherTransitionable, Insettable { |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 28 | static final String LOG_TAG = "AppsCustomizeTabHost"; |
| 29 | |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 30 | private static final String WIDGETS_TAB_TAG = "WIDGETS"; |
| 31 | |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 32 | private AppsCustomizePagedView mPagedView; |
| 33 | private View mContent; |
| 34 | private boolean mInTransition = false; |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 35 | |
John Spurlock | 77e1f47 | 2013-09-11 10:09:51 -0400 | [diff] [blame] | 36 | private final Rect mInsets = new Rect(); |
Winson Chung | c100e8e | 2011-08-09 16:02:43 -0700 | [diff] [blame] | 37 | |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 38 | public AppsCustomizeTabHost(Context context, AttributeSet attrs) { |
| 39 | super(context, attrs); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 40 | } |
| 41 | |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 42 | /** |
Winson Chung | 5a80835 | 2011-06-27 19:08:49 -0700 | [diff] [blame] | 43 | * Convenience methods to select specific tabs. We want to set the content type immediately |
| 44 | * in these cases, but we note that we still call setCurrentTabByTag() so that the tab view |
| 45 | * reflects the new content (but doesn't do the animation and logic associated with changing |
| 46 | * tabs manually). |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 47 | */ |
Winson Chung | c93e5ae | 2012-07-23 20:48:26 -0700 | [diff] [blame] | 48 | void setContentTypeImmediate(AppsCustomizePagedView.ContentType type) { |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 49 | mPagedView.setContentType(type); |
| 50 | } |
| 51 | |
John Spurlock | 77e1f47 | 2013-09-11 10:09:51 -0400 | [diff] [blame] | 52 | @Override |
| 53 | public void setInsets(Rect insets) { |
| 54 | mInsets.set(insets); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 55 | LayoutParams flp = (LayoutParams) mContent.getLayoutParams(); |
John Spurlock | 77e1f47 | 2013-09-11 10:09:51 -0400 | [diff] [blame] | 56 | flp.topMargin = insets.top; |
| 57 | flp.bottomMargin = insets.bottom; |
| 58 | flp.leftMargin = insets.left; |
| 59 | flp.rightMargin = insets.right; |
| 60 | mContent.setLayoutParams(flp); |
| 61 | } |
| 62 | |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 63 | /** |
| 64 | * Setup the tab host and create all necessary tabs. |
| 65 | */ |
| 66 | @Override |
| 67 | protected void onFinishInflate() { |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 68 | mPagedView = (AppsCustomizePagedView) findViewById(R.id.apps_customize_pane_content); |
| 69 | mContent = findViewById(R.id.content); |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 70 | } |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 71 | |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 72 | public String getContentTag() { |
| 73 | return getTabTagForContentType(mPagedView.getContentType()); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | /** |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 77 | * Returns the content view used for the launcher transitions. |
| 78 | */ |
| 79 | public View getContentView() { |
| 80 | return findViewById(R.id.apps_customize_pane_content); |
| 81 | } |
| 82 | |
| 83 | /** |
| 84 | * Returns the reveal view used for the launcher transitions. |
| 85 | */ |
| 86 | public View getRevealView() { |
| 87 | return findViewById(R.id.fake_page); |
| 88 | } |
| 89 | |
| 90 | /** |
| 91 | * Returns the page indicators view. |
| 92 | */ |
| 93 | public View getPageIndicators() { |
| 94 | return findViewById(R.id.apps_customize_page_indicator); |
| 95 | } |
| 96 | |
| 97 | /** |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 98 | * Returns the content type for the specified tab tag. |
| 99 | */ |
| 100 | public AppsCustomizePagedView.ContentType getContentTypeForTabTag(String tag) { |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 101 | return AppsCustomizePagedView.ContentType.Widgets; |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 102 | } |
| 103 | |
| 104 | /** |
Winson Chung | fc79c80 | 2011-05-02 13:35:34 -0700 | [diff] [blame] | 105 | * Returns the tab tag for a given content type. |
| 106 | */ |
| 107 | public String getTabTagForContentType(AppsCustomizePagedView.ContentType type) { |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 108 | return WIDGETS_TAB_TAG; |
Winson Chung | fc79c80 | 2011-05-02 13:35:34 -0700 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | /** |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 112 | * Disable focus on anything under this view in the hierarchy if we are not visible. |
| 113 | */ |
| 114 | @Override |
| 115 | public int getDescendantFocusability() { |
| 116 | if (getVisibility() != View.VISIBLE) { |
| 117 | return ViewGroup.FOCUS_BLOCK_DESCENDANTS; |
| 118 | } |
| 119 | return super.getDescendantFocusability(); |
| 120 | } |
| 121 | |
Winson Chung | c100e8e | 2011-08-09 16:02:43 -0700 | [diff] [blame] | 122 | void reset() { |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 123 | // Reset immediately |
| 124 | mPagedView.reset(); |
| 125 | } |
| 126 | |
Adam Cohen | c8f4e1b | 2014-11-19 16:03:20 -0800 | [diff] [blame] | 127 | void trimMemory() { |
| 128 | mPagedView.trimMemory(); |
| 129 | } |
| 130 | |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 131 | public void onWindowVisible() { |
| 132 | if (getVisibility() == VISIBLE) { |
| 133 | mContent.setVisibility(VISIBLE); |
| 134 | // We unload the widget previews when the UI is hidden, so need to reload pages |
| 135 | // Load the current page synchronously, and the neighboring pages asynchronously |
| 136 | mPagedView.loadAssociatedPages(mPagedView.getCurrentPage(), true); |
| 137 | mPagedView.loadAssociatedPages(mPagedView.getCurrentPage()); |
Winson Chung | c100e8e | 2011-08-09 16:02:43 -0700 | [diff] [blame] | 138 | } |
| 139 | } |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 140 | @Override |
Adam Cohen | c956cba | 2014-07-24 09:17:37 -0700 | [diff] [blame] | 141 | public ViewGroup getContent() { |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 142 | return mPagedView; |
| 143 | } |
| 144 | |
| 145 | public boolean isInTransition() { |
| 146 | return mInTransition; |
Michael Jurka | 1899a36 | 2011-11-03 13:50:45 -0700 | [diff] [blame] | 147 | } |
| 148 | |
| 149 | /* LauncherTransitionable overrides */ |
| 150 | @Override |
Michael Jurka | a35e35a | 2012-04-26 15:04:28 -0700 | [diff] [blame] | 151 | public void onLauncherTransitionPrepare(Launcher l, boolean animated, boolean toWorkspace) { |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 152 | mPagedView.onLauncherTransitionPrepare(l, animated, toWorkspace); |
Michael Jurka | 1899a36 | 2011-11-03 13:50:45 -0700 | [diff] [blame] | 153 | mInTransition = true; |
Michael Jurka | 1899a36 | 2011-11-03 13:50:45 -0700 | [diff] [blame] | 154 | |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 155 | if (toWorkspace) { |
| 156 | // Going from All Apps -> Workspace |
| 157 | setVisibilityOfSiblingsWithLowerZOrder(VISIBLE); |
| 158 | } else { |
| 159 | // Going from Workspace -> All Apps |
| 160 | mContent.setVisibility(VISIBLE); |
Michael Jurka | 3d845e8 | 2011-11-15 17:04:31 -0800 | [diff] [blame] | 161 | |
Michael Jurka | e326f18 | 2011-11-21 14:05:46 -0800 | [diff] [blame] | 162 | // Make sure the current page is loaded (we start loading the side pages after the |
| 163 | // transition to prevent slowing down the animation) |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 164 | // TODO: revisit this |
Adam Cohen | 63f1ec0 | 2014-08-12 09:23:13 -0700 | [diff] [blame] | 165 | mPagedView.loadAssociatedPages(mPagedView.getCurrentPage()); |
Winson Chung | c100e8e | 2011-08-09 16:02:43 -0700 | [diff] [blame] | 166 | } |
Michael Jurka | a35e35a | 2012-04-26 15:04:28 -0700 | [diff] [blame] | 167 | } |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 168 | |
Michael Jurka | a35e35a | 2012-04-26 15:04:28 -0700 | [diff] [blame] | 169 | @Override |
| 170 | public void onLauncherTransitionStart(Launcher l, boolean animated, boolean toWorkspace) { |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 171 | mPagedView.onLauncherTransitionStart(l, animated, toWorkspace); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 172 | } |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 173 | |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 174 | @Override |
Winson Chung | 7044272 | 2012-02-10 15:43:22 -0800 | [diff] [blame] | 175 | public void onLauncherTransitionStep(Launcher l, float t) { |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 176 | mPagedView.onLauncherTransitionStep(l, t); |
Winson Chung | 7044272 | 2012-02-10 15:43:22 -0800 | [diff] [blame] | 177 | } |
| 178 | |
| 179 | @Override |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 180 | public void onLauncherTransitionEnd(Launcher l, boolean animated, boolean toWorkspace) { |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 181 | mPagedView.onLauncherTransitionEnd(l, animated, toWorkspace); |
Winson Chung | c100e8e | 2011-08-09 16:02:43 -0700 | [diff] [blame] | 182 | mInTransition = false; |
Winson Chung | 3ac74c5 | 2011-06-30 17:39:37 -0700 | [diff] [blame] | 183 | |
Winson Chung | 7d7541e | 2011-09-16 20:14:36 -0700 | [diff] [blame] | 184 | if (!toWorkspace) { |
Michael Jurka | e326f18 | 2011-11-21 14:05:46 -0800 | [diff] [blame] | 185 | // Make sure adjacent pages are loaded (we wait until after the transition to |
| 186 | // prevent slowing down the animation) |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 187 | mPagedView.loadAssociatedPages(mPagedView.getCurrentPage()); |
Winson Chung | 7d7541e | 2011-09-16 20:14:36 -0700 | [diff] [blame] | 188 | |
Jason Monk | ed05f09 | 2014-04-24 10:13:05 -0400 | [diff] [blame] | 189 | // Opening apps, need to announce what page we are on. |
| 190 | AccessibilityManager am = (AccessibilityManager) |
| 191 | getContext().getSystemService(Context.ACCESSIBILITY_SERVICE); |
| 192 | if (am.isEnabled()) { |
| 193 | // Notify the user when the page changes |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 194 | announceForAccessibility(mPagedView.getCurrentPageDescription()); |
Jason Monk | ed05f09 | 2014-04-24 10:13:05 -0400 | [diff] [blame] | 195 | } |
| 196 | |
Winson Chung | 7819abd | 2012-11-29 14:29:38 -0800 | [diff] [blame] | 197 | // Going from Workspace -> All Apps |
| 198 | // NOTE: We should do this at the end since we check visibility state in some of the |
| 199 | // cling initialization/dismiss code above. |
| 200 | setVisibilityOfSiblingsWithLowerZOrder(INVISIBLE); |
Winson Chung | 5a80835 | 2011-06-27 19:08:49 -0700 | [diff] [blame] | 201 | } |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 202 | } |
Winson Chung | 70d7210 | 2011-08-12 11:24:35 -0700 | [diff] [blame] | 203 | |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 204 | private void setVisibilityOfSiblingsWithLowerZOrder(int visibility) { |
| 205 | ViewGroup parent = (ViewGroup) getParent(); |
Michael Jurka | aea1ce5 | 2012-04-12 11:23:21 -0700 | [diff] [blame] | 206 | if (parent == null) return; |
| 207 | |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 208 | View appsView = ((Launcher) getContext()).getAppsView(); |
Adam Cohen | 3d41198 | 2013-09-24 17:02:06 -0700 | [diff] [blame] | 209 | View overviewPanel = ((Launcher) getContext()).getOverviewPanel(); |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 210 | final int count = parent.getChildCount(); |
| 211 | if (!isChildrenDrawingOrderEnabled()) { |
| 212 | for (int i = 0; i < count; i++) { |
| 213 | final View child = parent.getChildAt(i); |
| 214 | if (child == this) { |
| 215 | break; |
| 216 | } else { |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 217 | if (child.getVisibility() == GONE || child == overviewPanel || |
| 218 | child == appsView) { |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 219 | continue; |
| 220 | } |
| 221 | child.setVisibility(visibility); |
| 222 | } |
| 223 | } |
| 224 | } else { |
| 225 | throw new RuntimeException("Failed; can't get z-order of views"); |
| 226 | } |
| 227 | } |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 228 | } |