Patrick Dubroy | 558654c | 2010-07-23 16:48:11 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 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 | |
| 17 | package com.android.launcher2; |
| 18 | |
Michael Jurka | 8edd75c | 2010-12-17 20:15:06 -0800 | [diff] [blame] | 19 | import com.android.launcher.R; |
Patrick Dubroy | 558654c | 2010-07-23 16:48:11 -0700 | [diff] [blame] | 20 | |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 21 | import android.animation.Animator; |
Michael Jurka | 8edd75c | 2010-12-17 20:15:06 -0800 | [diff] [blame] | 22 | import android.animation.AnimatorListenerAdapter; |
Chet Haase | b1254a6 | 2010-09-07 13:35:00 -0700 | [diff] [blame] | 23 | import android.animation.ObjectAnimator; |
Gilles Debunne | dd6c992 | 2010-10-25 11:23:41 -0700 | [diff] [blame] | 24 | import android.animation.ValueAnimator; |
Patrick Dubroy | 558654c | 2010-07-23 16:48:11 -0700 | [diff] [blame] | 25 | import android.content.Context; |
| 26 | import android.content.res.Resources; |
| 27 | import android.util.AttributeSet; |
| 28 | import android.util.Log; |
Winson Chung | 49767ae | 2010-11-29 14:48:30 -0800 | [diff] [blame] | 29 | import android.view.LayoutInflater; |
Adam Lesinski | 6b879f0 | 2010-11-04 16:15:23 -0700 | [diff] [blame] | 30 | import android.view.MotionEvent; |
Patrick Dubroy | 558654c | 2010-07-23 16:48:11 -0700 | [diff] [blame] | 31 | import android.view.View; |
| 32 | import android.widget.TabHost; |
Winson Chung | 49767ae | 2010-11-29 14:48:30 -0800 | [diff] [blame] | 33 | import android.widget.TabWidget; |
| 34 | import android.widget.TextView; |
Patrick Dubroy | 558654c | 2010-07-23 16:48:11 -0700 | [diff] [blame] | 35 | |
Michael Jurka | 8edd75c | 2010-12-17 20:15:06 -0800 | [diff] [blame] | 36 | import java.util.ArrayList; |
Patrick Dubroy | 558654c | 2010-07-23 16:48:11 -0700 | [diff] [blame] | 37 | |
| 38 | /** |
| 39 | * Implements a tabbed version of AllApps2D. |
| 40 | */ |
Michael Jurka | abded66 | 2011-03-04 12:06:57 -0800 | [diff] [blame] | 41 | public class AllAppsTabbed extends TabHost implements AllAppsView, LauncherTransitionable { |
Patrick Dubroy | 558654c | 2010-07-23 16:48:11 -0700 | [diff] [blame] | 42 | |
| 43 | private static final String TAG = "Launcher.AllAppsTabbed"; |
| 44 | |
Patrick Dubroy | 3d605d5 | 2010-07-29 13:59:29 -0700 | [diff] [blame] | 45 | private static final String TAG_ALL = "ALL"; |
Patrick Dubroy | 3d605d5 | 2010-07-29 13:59:29 -0700 | [diff] [blame] | 46 | private static final String TAG_DOWNLOADED = "DOWNLOADED"; |
| 47 | |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 48 | private AllAppsPagedView mAllApps; |
Michael Jurka | 9c6fbed | 2011-03-02 17:41:34 -0800 | [diff] [blame] | 49 | private AllAppsBackground mBackground; |
| 50 | private Launcher mLauncher; |
Patrick Dubroy | 3d605d5 | 2010-07-29 13:59:29 -0700 | [diff] [blame] | 51 | private Context mContext; |
Winson Chung | 49767ae | 2010-11-29 14:48:30 -0800 | [diff] [blame] | 52 | private final LayoutInflater mInflater; |
Michael Jurka | 6c7a03a | 2011-01-16 18:43:58 -0800 | [diff] [blame] | 53 | private boolean mFirstLayout = true; |
Patrick Dubroy | 558654c | 2010-07-23 16:48:11 -0700 | [diff] [blame] | 54 | |
| 55 | public AllAppsTabbed(Context context, AttributeSet attrs) { |
| 56 | super(context, attrs); |
Patrick Dubroy | 3d605d5 | 2010-07-29 13:59:29 -0700 | [diff] [blame] | 57 | mContext = context; |
Winson Chung | 49767ae | 2010-11-29 14:48:30 -0800 | [diff] [blame] | 58 | mInflater = LayoutInflater.from(context); |
Patrick Dubroy | 558654c | 2010-07-23 16:48:11 -0700 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | @Override |
| 62 | protected void onFinishInflate() { |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 63 | // setup the tab host |
| 64 | setup(); |
| 65 | |
Patrick Dubroy | 558654c | 2010-07-23 16:48:11 -0700 | [diff] [blame] | 66 | try { |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 67 | mAllApps = (AllAppsPagedView) findViewById(R.id.all_apps_paged_view); |
| 68 | if (mAllApps == null) throw new Resources.NotFoundException(); |
Michael Jurka | 9c6fbed | 2011-03-02 17:41:34 -0800 | [diff] [blame] | 69 | mBackground = (AllAppsBackground) findViewById(R.id.all_apps_background); |
| 70 | if (mBackground == null) throw new Resources.NotFoundException(); |
Patrick Dubroy | 558654c | 2010-07-23 16:48:11 -0700 | [diff] [blame] | 71 | } catch (Resources.NotFoundException e) { |
| 72 | Log.e(TAG, "Can't find necessary layout elements for AllAppsTabbed"); |
| 73 | } |
Patrick Dubroy | 558654c | 2010-07-23 16:48:11 -0700 | [diff] [blame] | 74 | |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 75 | // share the same AllApps workspace across all the tabs |
Patrick Dubroy | 558654c | 2010-07-23 16:48:11 -0700 | [diff] [blame] | 76 | TabContentFactory contentFactory = new TabContentFactory() { |
| 77 | public View createTabContent(String tag) { |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 78 | return mAllApps; |
Patrick Dubroy | 558654c | 2010-07-23 16:48:11 -0700 | [diff] [blame] | 79 | } |
| 80 | }; |
| 81 | |
Michael Jurka | 12ac0d6 | 2011-02-23 11:48:32 -0800 | [diff] [blame] | 82 | // Create the tabs and wire them up properly |
Winson Chung | 49767ae | 2010-11-29 14:48:30 -0800 | [diff] [blame] | 83 | TextView tabView; |
| 84 | TabWidget tabWidget = (TabWidget) findViewById(com.android.internal.R.id.tabs); |
| 85 | tabView = (TextView) mInflater.inflate(R.layout.tab_widget_indicator, tabWidget, false); |
| 86 | tabView.setText(mContext.getString(R.string.all_apps_tab_all)); |
| 87 | addTab(newTabSpec(TAG_ALL).setIndicator(tabView).setContent(contentFactory)); |
Patrick Dubroy | 3d605d5 | 2010-07-29 13:59:29 -0700 | [diff] [blame] | 88 | |
Winson Chung | 49767ae | 2010-11-29 14:48:30 -0800 | [diff] [blame] | 89 | tabView = (TextView) mInflater.inflate(R.layout.tab_widget_indicator, tabWidget, false); |
| 90 | tabView.setText(mContext.getString(R.string.all_apps_tab_downloaded)); |
| 91 | addTab(newTabSpec(TAG_DOWNLOADED).setIndicator(tabView).setContent(contentFactory)); |
Patrick Dubroy | 3d605d5 | 2010-07-29 13:59:29 -0700 | [diff] [blame] | 92 | |
| 93 | setOnTabChangedListener(new OnTabChangeListener() { |
| 94 | public void onTabChanged(String tabId) { |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 95 | // animate the changing of the tab content by fading pages in and out |
Winson Chung | bbc60d8 | 2010-11-11 16:34:41 -0800 | [diff] [blame] | 96 | final Resources res = getResources(); |
| 97 | final int duration = res.getInteger(R.integer.config_tabTransitionTime); |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 98 | final float alpha = mAllApps.getAlpha(); |
Chet Haase | 472b281 | 2010-10-14 07:02:04 -0700 | [diff] [blame] | 99 | ValueAnimator alphaAnim = ObjectAnimator.ofFloat(mAllApps, "alpha", alpha, 0.0f). |
| 100 | setDuration(duration); |
Michael Jurka | 8edd75c | 2010-12-17 20:15:06 -0800 | [diff] [blame] | 101 | alphaAnim.addListener(new AnimatorListenerAdapter() { |
Gilles Debunne | dd6c992 | 2010-10-25 11:23:41 -0700 | [diff] [blame] | 102 | @Override |
Michael Jurka | 8edd75c | 2010-12-17 20:15:06 -0800 | [diff] [blame] | 103 | public void onAnimationEnd(Animator animation) { |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 104 | String tag = getCurrentTabTag(); |
| 105 | if (tag == TAG_ALL) { |
| 106 | mAllApps.setAppFilter(AllAppsPagedView.ALL_APPS_FLAG); |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 107 | } else if (tag == TAG_DOWNLOADED) { |
| 108 | mAllApps.setAppFilter(ApplicationInfo.DOWNLOADED_FLAG); |
| 109 | } |
| 110 | |
| 111 | final float alpha = mAllApps.getAlpha(); |
Chet Haase | 472b281 | 2010-10-14 07:02:04 -0700 | [diff] [blame] | 112 | ObjectAnimator.ofFloat(mAllApps, "alpha", alpha, 1.0f). |
| 113 | setDuration(duration).start(); |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 114 | } |
| 115 | }); |
| 116 | alphaAnim.start(); |
Patrick Dubroy | 3d605d5 | 2010-07-29 13:59:29 -0700 | [diff] [blame] | 117 | } |
| 118 | }); |
Patrick Dubroy | 558654c | 2010-07-23 16:48:11 -0700 | [diff] [blame] | 119 | |
Michael Jurka | 12ac0d6 | 2011-02-23 11:48:32 -0800 | [diff] [blame] | 120 | |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 121 | // It needs to be INVISIBLE so that it will be measured in the layout. |
| 122 | // Otherwise the animations is messed up when we show it for the first time. |
| 123 | setVisibility(INVISIBLE); |
Patrick Dubroy | 558654c | 2010-07-23 16:48:11 -0700 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | @Override |
| 127 | public void setLauncher(Launcher launcher) { |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 128 | mAllApps.setLauncher(launcher); |
Michael Jurka | 9c6fbed | 2011-03-02 17:41:34 -0800 | [diff] [blame] | 129 | mLauncher = launcher; |
Patrick Dubroy | 558654c | 2010-07-23 16:48:11 -0700 | [diff] [blame] | 130 | } |
| 131 | |
| 132 | @Override |
| 133 | public void setDragController(DragController dragger) { |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 134 | mAllApps.setDragController(dragger); |
Patrick Dubroy | 558654c | 2010-07-23 16:48:11 -0700 | [diff] [blame] | 135 | } |
| 136 | |
| 137 | @Override |
| 138 | public void zoom(float zoom, boolean animate) { |
| 139 | // NOTE: animate parameter is ignored for the TabHost itself |
| 140 | setVisibility((zoom == 0.0f) ? View.GONE : View.VISIBLE); |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 141 | mAllApps.zoom(zoom, animate); |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 142 | } |
| 143 | |
| 144 | @Override |
| 145 | public void setVisibility(int visibility) { |
Michael Jurka | 6c7a03a | 2011-01-16 18:43:58 -0800 | [diff] [blame] | 146 | if (visibility == View.GONE && mFirstLayout) { |
| 147 | // It needs to be INVISIBLE so that it will be measured in the layout. |
| 148 | // Otherwise the animations is messed up when we show it for the first time. |
| 149 | visibility = View.INVISIBLE; |
| 150 | } |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 151 | final boolean isVisible = (visibility == View.VISIBLE); |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 152 | super.setVisibility(visibility); |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 153 | float zoom = (isVisible ? 1.0f : 0.0f); |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 154 | mAllApps.zoom(zoom, false); |
Patrick Dubroy | 558654c | 2010-07-23 16:48:11 -0700 | [diff] [blame] | 155 | } |
| 156 | |
| 157 | @Override |
| 158 | public boolean isVisible() { |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 159 | return mAllApps.isVisible(); |
Patrick Dubroy | 558654c | 2010-07-23 16:48:11 -0700 | [diff] [blame] | 160 | } |
| 161 | |
| 162 | @Override |
Michael Jurka | 6c7a03a | 2011-01-16 18:43:58 -0800 | [diff] [blame] | 163 | protected void onLayout(boolean changed, int l, int t, int r, int b) { |
Michael Jurka | ea2daff | 2011-05-17 18:21:03 -0700 | [diff] [blame^] | 164 | if (mFirstLayout) { |
| 165 | mFirstLayout = false; |
| 166 | // Set the width of the tab bar properly |
| 167 | int pageWidth = mAllApps.getPageContentWidth(); |
| 168 | TabWidget tabWidget = (TabWidget) findViewById(com.android.internal.R.id.tabs); |
| 169 | View allAppsTabBar = (View) findViewById(R.id.all_apps_tab_bar); |
| 170 | if (allAppsTabBar == null) throw new Resources.NotFoundException(); |
| 171 | int tabWidgetPadding = 0; |
| 172 | final int childCount = tabWidget.getChildCount(); |
| 173 | if (childCount > 0) { |
| 174 | tabWidgetPadding += tabWidget.getChildAt(0).getPaddingLeft() * 2; |
| 175 | } |
| 176 | allAppsTabBar.getLayoutParams().width = pageWidth + tabWidgetPadding; |
| 177 | } |
Michael Jurka | 6c7a03a | 2011-01-16 18:43:58 -0800 | [diff] [blame] | 178 | super.onLayout(changed, l, t, r, b); |
| 179 | } |
| 180 | |
| 181 | @Override |
Patrick Dubroy | ff5f040 | 2010-07-26 15:23:26 -0700 | [diff] [blame] | 182 | public boolean isAnimating() { |
| 183 | return (getAnimation() != null); |
| 184 | } |
| 185 | |
| 186 | @Override |
Michael Jurka | abded66 | 2011-03-04 12:06:57 -0800 | [diff] [blame] | 187 | public void onLauncherTransitionStart(Animator animation) { |
| 188 | if (animation != null) { |
| 189 | // Turn on hardware layers for performance |
| 190 | setLayerType(LAYER_TYPE_HARDWARE, null); |
| 191 | // Re-enable the rendering of the dimmed background in All Apps for performance reasons |
Michael Jurka | cc6c884 | 2011-03-09 14:38:14 -0800 | [diff] [blame] | 192 | // if we're fading it in |
| 193 | if (mLauncher.getWorkspace().getBackgroundAlpha() == 0f) { |
| 194 | mLauncher.getWorkspace().disableBackground(); |
| 195 | mBackground.setVisibility(VISIBLE); |
| 196 | } |
Michael Jurka | abded66 | 2011-03-04 12:06:57 -0800 | [diff] [blame] | 197 | // just a sanity check that we don't build a layer before a call to onLayout |
| 198 | if (!mFirstLayout) { |
| 199 | // force building the layer at the beginning of the animation, so you don't get a |
| 200 | // blip early in the animation |
| 201 | buildLayer(); |
| 202 | } |
| 203 | } |
Michael Jurka | 2763be3 | 2011-02-24 11:19:57 -0800 | [diff] [blame] | 204 | } |
| 205 | |
| 206 | @Override |
Michael Jurka | abded66 | 2011-03-04 12:06:57 -0800 | [diff] [blame] | 207 | public void onLauncherTransitionEnd(Animator animation) { |
| 208 | if (animation != null) { |
| 209 | setLayerType(LAYER_TYPE_NONE, null); |
| 210 | // To improve the performance of the first time All Apps is run, we initially keep |
| 211 | // hardware layers in AllAppsPagedView disabled since AllAppsTabbed itself is drawn in a |
| 212 | // hardware layer, and creating additional hardware layers slows down the animation. We |
| 213 | // create them here, after the animation is over. |
| 214 | } |
Michael Jurka | 9c6fbed | 2011-03-02 17:41:34 -0800 | [diff] [blame] | 215 | // Move the rendering of the dimmed background to workspace after the all apps animation |
| 216 | // is done, so that the background is not rendered *above* the mini workspace screens |
Michael Jurka | cc6c884 | 2011-03-09 14:38:14 -0800 | [diff] [blame] | 217 | if (mBackground.getVisibility() != GONE) { |
| 218 | mLauncher.getWorkspace().enableBackground(); |
| 219 | mBackground.setVisibility(GONE); |
| 220 | } |
Michael Jurka | abded66 | 2011-03-04 12:06:57 -0800 | [diff] [blame] | 221 | mAllApps.allowHardwareLayerCreation(); |
Michael Jurka | 2763be3 | 2011-02-24 11:19:57 -0800 | [diff] [blame] | 222 | } |
| 223 | |
| 224 | @Override |
Patrick Dubroy | 558654c | 2010-07-23 16:48:11 -0700 | [diff] [blame] | 225 | public void setApps(ArrayList<ApplicationInfo> list) { |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 226 | mAllApps.setApps(list); |
Patrick Dubroy | 558654c | 2010-07-23 16:48:11 -0700 | [diff] [blame] | 227 | } |
| 228 | |
| 229 | @Override |
| 230 | public void addApps(ArrayList<ApplicationInfo> list) { |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 231 | mAllApps.addApps(list); |
Patrick Dubroy | 558654c | 2010-07-23 16:48:11 -0700 | [diff] [blame] | 232 | } |
| 233 | |
| 234 | @Override |
| 235 | public void removeApps(ArrayList<ApplicationInfo> list) { |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 236 | mAllApps.removeApps(list); |
Patrick Dubroy | 558654c | 2010-07-23 16:48:11 -0700 | [diff] [blame] | 237 | } |
| 238 | |
| 239 | @Override |
| 240 | public void updateApps(ArrayList<ApplicationInfo> list) { |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 241 | mAllApps.updateApps(list); |
Patrick Dubroy | 558654c | 2010-07-23 16:48:11 -0700 | [diff] [blame] | 242 | } |
| 243 | |
| 244 | @Override |
| 245 | public void dumpState() { |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 246 | mAllApps.dumpState(); |
Patrick Dubroy | 558654c | 2010-07-23 16:48:11 -0700 | [diff] [blame] | 247 | } |
| 248 | |
| 249 | @Override |
| 250 | public void surrender() { |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 251 | mAllApps.surrender(); |
Patrick Dubroy | 558654c | 2010-07-23 16:48:11 -0700 | [diff] [blame] | 252 | } |
Adam Lesinski | 6b879f0 | 2010-11-04 16:15:23 -0700 | [diff] [blame] | 253 | |
| 254 | @Override |
| 255 | public boolean onTouchEvent(MotionEvent ev) { |
| 256 | if (ev.getY() > mAllApps.getBottom()) { |
| 257 | return false; |
| 258 | } |
| 259 | return true; |
| 260 | } |
Patrick Dubroy | 558654c | 2010-07-23 16:48:11 -0700 | [diff] [blame] | 261 | } |