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 | |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 19 | import java.util.ArrayList; |
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.Animatable; |
| 22 | import android.animation.AnimatableListenerAdapter; |
| 23 | import android.animation.Animator; |
| 24 | import android.animation.PropertyAnimator; |
Patrick Dubroy | 558654c | 2010-07-23 16:48:11 -0700 | [diff] [blame] | 25 | import android.content.Context; |
| 26 | import android.content.res.Resources; |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 27 | import android.graphics.Color; |
Patrick Dubroy | 558654c | 2010-07-23 16:48:11 -0700 | [diff] [blame] | 28 | import android.util.AttributeSet; |
| 29 | import android.util.Log; |
| 30 | import android.view.View; |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 31 | import android.widget.RelativeLayout; |
Patrick Dubroy | 558654c | 2010-07-23 16:48:11 -0700 | [diff] [blame] | 32 | import android.widget.TabHost; |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [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 | |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 36 | import com.android.launcher.R; |
Patrick Dubroy | 558654c | 2010-07-23 16:48:11 -0700 | [diff] [blame] | 37 | |
| 38 | /** |
| 39 | * Implements a tabbed version of AllApps2D. |
| 40 | */ |
| 41 | public class AllAppsTabbed extends TabHost implements AllAppsView { |
| 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"; |
| 46 | private static final String TAG_APPS = "APPS"; |
| 47 | private static final String TAG_GAMES = "GAMES"; |
| 48 | private static final String TAG_DOWNLOADED = "DOWNLOADED"; |
| 49 | |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 50 | private AllAppsPagedView mAllApps; |
Patrick Dubroy | 3d605d5 | 2010-07-29 13:59:29 -0700 | [diff] [blame] | 51 | private Context mContext; |
Patrick Dubroy | 558654c | 2010-07-23 16:48:11 -0700 | [diff] [blame] | 52 | |
| 53 | public AllAppsTabbed(Context context, AttributeSet attrs) { |
| 54 | super(context, attrs); |
Patrick Dubroy | 3d605d5 | 2010-07-29 13:59:29 -0700 | [diff] [blame] | 55 | mContext = context; |
Patrick Dubroy | 558654c | 2010-07-23 16:48:11 -0700 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | @Override |
| 59 | protected void onFinishInflate() { |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 60 | // setup the tab host |
| 61 | setup(); |
| 62 | |
Patrick Dubroy | 558654c | 2010-07-23 16:48:11 -0700 | [diff] [blame] | 63 | try { |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 64 | mAllApps = (AllAppsPagedView) findViewById(R.id.all_apps_paged_view); |
| 65 | if (mAllApps == null) throw new Resources.NotFoundException(); |
Patrick Dubroy | 558654c | 2010-07-23 16:48:11 -0700 | [diff] [blame] | 66 | } catch (Resources.NotFoundException e) { |
| 67 | Log.e(TAG, "Can't find necessary layout elements for AllAppsTabbed"); |
| 68 | } |
Patrick Dubroy | 558654c | 2010-07-23 16:48:11 -0700 | [diff] [blame] | 69 | |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 70 | // share the same AllApps workspace across all the tabs |
Patrick Dubroy | 558654c | 2010-07-23 16:48:11 -0700 | [diff] [blame] | 71 | TabContentFactory contentFactory = new TabContentFactory() { |
| 72 | public View createTabContent(String tag) { |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 73 | return mAllApps; |
Patrick Dubroy | 558654c | 2010-07-23 16:48:11 -0700 | [diff] [blame] | 74 | } |
| 75 | }; |
| 76 | |
Patrick Dubroy | 3d605d5 | 2010-07-29 13:59:29 -0700 | [diff] [blame] | 77 | String label = mContext.getString(R.string.all_apps_tab_all); |
| 78 | addTab(newTabSpec(TAG_ALL).setIndicator(label).setContent(contentFactory)); |
| 79 | |
| 80 | label = mContext.getString(R.string.all_apps_tab_apps); |
| 81 | addTab(newTabSpec(TAG_APPS).setIndicator(label).setContent(contentFactory)); |
| 82 | |
| 83 | label = mContext.getString(R.string.all_apps_tab_games); |
| 84 | addTab(newTabSpec(TAG_GAMES).setIndicator(label).setContent(contentFactory)); |
| 85 | |
| 86 | label = mContext.getString(R.string.all_apps_tab_downloaded); |
| 87 | addTab(newTabSpec(TAG_DOWNLOADED).setIndicator(label).setContent(contentFactory)); |
| 88 | |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 89 | // TEMP: just styling the tab widget to be a bit nicer until we get the actual |
| 90 | // new assets |
| 91 | TabWidget tabWidget = getTabWidget(); |
| 92 | for (int i = 0; i < tabWidget.getChildCount(); ++i) { |
| 93 | RelativeLayout tab = (RelativeLayout) tabWidget.getChildTabViewAt(i); |
| 94 | TextView text = (TextView) tab.getChildAt(1); |
| 95 | text.setTextSize(20.0f); |
| 96 | text.setPadding(20, 0, 20, 0); |
| 97 | text.setShadowLayer(1.0f, 0.0f, 1.0f, Color.BLACK); |
| 98 | tab.setBackgroundDrawable(null); |
| 99 | } |
| 100 | |
Patrick Dubroy | 3d605d5 | 2010-07-29 13:59:29 -0700 | [diff] [blame] | 101 | setOnTabChangedListener(new OnTabChangeListener() { |
| 102 | public void onTabChanged(String tabId) { |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame^] | 103 | // animate the changing of the tab content by fading pages in and out |
| 104 | final int duration = 150; |
| 105 | final float alpha = mAllApps.getAlpha(); |
| 106 | Animator alphaAnim = new PropertyAnimator(duration, mAllApps, "alpha", alpha, 0.0f); |
| 107 | alphaAnim.addListener(new AnimatableListenerAdapter() { |
| 108 | public void onAnimationEnd(Animatable animation) { |
| 109 | String tag = getCurrentTabTag(); |
| 110 | if (tag == TAG_ALL) { |
| 111 | mAllApps.setAppFilter(AllAppsPagedView.ALL_APPS_FLAG); |
| 112 | } else if (tag == TAG_APPS) { |
| 113 | mAllApps.setAppFilter(ApplicationInfo.APP_FLAG); |
| 114 | } else if (tag == TAG_GAMES) { |
| 115 | mAllApps.setAppFilter(ApplicationInfo.GAME_FLAG); |
| 116 | } else if (tag == TAG_DOWNLOADED) { |
| 117 | mAllApps.setAppFilter(ApplicationInfo.DOWNLOADED_FLAG); |
| 118 | } |
| 119 | |
| 120 | final float alpha = mAllApps.getAlpha(); |
| 121 | Animator alphaAnim = |
| 122 | new PropertyAnimator(duration, mAllApps, "alpha", alpha, 1.0f); |
| 123 | alphaAnim.start(); |
| 124 | } |
| 125 | }); |
| 126 | alphaAnim.start(); |
Patrick Dubroy | 3d605d5 | 2010-07-29 13:59:29 -0700 | [diff] [blame] | 127 | } |
| 128 | }); |
Patrick Dubroy | 558654c | 2010-07-23 16:48:11 -0700 | [diff] [blame] | 129 | |
| 130 | setCurrentTab(0); |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 131 | |
| 132 | // It needs to be INVISIBLE so that it will be measured in the layout. |
| 133 | // Otherwise the animations is messed up when we show it for the first time. |
| 134 | setVisibility(INVISIBLE); |
Patrick Dubroy | 558654c | 2010-07-23 16:48:11 -0700 | [diff] [blame] | 135 | } |
| 136 | |
| 137 | @Override |
| 138 | public void setLauncher(Launcher launcher) { |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 139 | mAllApps.setLauncher(launcher); |
Patrick Dubroy | 558654c | 2010-07-23 16:48:11 -0700 | [diff] [blame] | 140 | } |
| 141 | |
| 142 | @Override |
| 143 | public void setDragController(DragController dragger) { |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 144 | mAllApps.setDragController(dragger); |
Patrick Dubroy | 558654c | 2010-07-23 16:48:11 -0700 | [diff] [blame] | 145 | } |
| 146 | |
| 147 | @Override |
| 148 | public void zoom(float zoom, boolean animate) { |
| 149 | // NOTE: animate parameter is ignored for the TabHost itself |
| 150 | setVisibility((zoom == 0.0f) ? View.GONE : View.VISIBLE); |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 151 | mAllApps.zoom(zoom, animate); |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 152 | } |
| 153 | |
| 154 | @Override |
| 155 | public void setVisibility(int visibility) { |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame^] | 156 | final boolean isVisible = (visibility == View.VISIBLE); |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 157 | super.setVisibility(visibility); |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame^] | 158 | float zoom = (isVisible ? 1.0f : 0.0f); |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 159 | mAllApps.zoom(zoom, false); |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame^] | 160 | if (!isVisible) |
| 161 | mAllApps.cleanup(); |
Patrick Dubroy | 558654c | 2010-07-23 16:48:11 -0700 | [diff] [blame] | 162 | } |
| 163 | |
| 164 | @Override |
| 165 | public boolean isVisible() { |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 166 | return mAllApps.isVisible(); |
Patrick Dubroy | 558654c | 2010-07-23 16:48:11 -0700 | [diff] [blame] | 167 | } |
| 168 | |
| 169 | @Override |
Patrick Dubroy | ff5f040 | 2010-07-26 15:23:26 -0700 | [diff] [blame] | 170 | public boolean isAnimating() { |
| 171 | return (getAnimation() != null); |
| 172 | } |
| 173 | |
| 174 | @Override |
Patrick Dubroy | 558654c | 2010-07-23 16:48:11 -0700 | [diff] [blame] | 175 | public void setApps(ArrayList<ApplicationInfo> list) { |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 176 | mAllApps.setApps(list); |
Patrick Dubroy | 558654c | 2010-07-23 16:48:11 -0700 | [diff] [blame] | 177 | } |
| 178 | |
| 179 | @Override |
| 180 | public void addApps(ArrayList<ApplicationInfo> list) { |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 181 | mAllApps.addApps(list); |
Patrick Dubroy | 558654c | 2010-07-23 16:48:11 -0700 | [diff] [blame] | 182 | } |
| 183 | |
| 184 | @Override |
| 185 | public void removeApps(ArrayList<ApplicationInfo> list) { |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 186 | mAllApps.removeApps(list); |
Patrick Dubroy | 558654c | 2010-07-23 16:48:11 -0700 | [diff] [blame] | 187 | } |
| 188 | |
| 189 | @Override |
| 190 | public void updateApps(ArrayList<ApplicationInfo> list) { |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 191 | mAllApps.updateApps(list); |
Patrick Dubroy | 558654c | 2010-07-23 16:48:11 -0700 | [diff] [blame] | 192 | } |
| 193 | |
| 194 | @Override |
| 195 | public void dumpState() { |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 196 | mAllApps.dumpState(); |
Patrick Dubroy | 558654c | 2010-07-23 16:48:11 -0700 | [diff] [blame] | 197 | } |
| 198 | |
| 199 | @Override |
| 200 | public void surrender() { |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 201 | mAllApps.surrender(); |
Patrick Dubroy | 558654c | 2010-07-23 16:48:11 -0700 | [diff] [blame] | 202 | } |
Patrick Dubroy | 558654c | 2010-07-23 16:48:11 -0700 | [diff] [blame] | 203 | } |