blob: 36594dd3401889e2d764b93201c738c37cb754b4 [file] [log] [blame]
Patrick Dubroy558654c2010-07-23 16:48:11 -07001/*
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
17package com.android.launcher2;
18
Michael Jurka8edd75c2010-12-17 20:15:06 -080019import com.android.launcher.R;
Patrick Dubroy558654c2010-07-23 16:48:11 -070020
Winson Chung80baf5a2010-08-09 16:03:15 -070021import android.animation.Animator;
Michael Jurka8edd75c2010-12-17 20:15:06 -080022import android.animation.AnimatorListenerAdapter;
Chet Haaseb1254a62010-09-07 13:35:00 -070023import android.animation.ObjectAnimator;
Gilles Debunnedd6c9922010-10-25 11:23:41 -070024import android.animation.ValueAnimator;
Patrick Dubroy558654c2010-07-23 16:48:11 -070025import android.content.Context;
26import android.content.res.Resources;
27import android.util.AttributeSet;
28import android.util.Log;
Winson Chung49767ae2010-11-29 14:48:30 -080029import android.view.LayoutInflater;
Adam Lesinski6b879f02010-11-04 16:15:23 -070030import android.view.MotionEvent;
Patrick Dubroy558654c2010-07-23 16:48:11 -070031import android.view.View;
Michael Jurka2763be32011-02-24 11:19:57 -080032import android.view.ViewGroup;
Patrick Dubroy558654c2010-07-23 16:48:11 -070033import android.widget.TabHost;
Winson Chung49767ae2010-11-29 14:48:30 -080034import android.widget.TabWidget;
35import android.widget.TextView;
Michael Jurka2763be32011-02-24 11:19:57 -080036import android.widget.TabHost.OnTabChangeListener;
37import android.widget.TabHost.TabContentFactory;
Patrick Dubroy558654c2010-07-23 16:48:11 -070038
Michael Jurka8edd75c2010-12-17 20:15:06 -080039import java.util.ArrayList;
Patrick Dubroy558654c2010-07-23 16:48:11 -070040
41/**
42 * Implements a tabbed version of AllApps2D.
43 */
Michael Jurka2763be32011-02-24 11:19:57 -080044public class AllAppsTabbed extends TabHost implements AllAppsView, LauncherAnimatable {
Patrick Dubroy558654c2010-07-23 16:48:11 -070045
46 private static final String TAG = "Launcher.AllAppsTabbed";
47
Patrick Dubroy3d605d52010-07-29 13:59:29 -070048 private static final String TAG_ALL = "ALL";
Patrick Dubroy3d605d52010-07-29 13:59:29 -070049 private static final String TAG_DOWNLOADED = "DOWNLOADED";
50
Winson Chung321e9ee2010-08-09 13:37:56 -070051 private AllAppsPagedView mAllApps;
Michael Jurka2763be32011-02-24 11:19:57 -080052 private View mTabBar;
Patrick Dubroy3d605d52010-07-29 13:59:29 -070053 private Context mContext;
Winson Chung49767ae2010-11-29 14:48:30 -080054 private final LayoutInflater mInflater;
Michael Jurka6c7a03a2011-01-16 18:43:58 -080055 private boolean mFirstLayout = true;
Patrick Dubroy558654c2010-07-23 16:48:11 -070056
57 public AllAppsTabbed(Context context, AttributeSet attrs) {
58 super(context, attrs);
Patrick Dubroy3d605d52010-07-29 13:59:29 -070059 mContext = context;
Winson Chung49767ae2010-11-29 14:48:30 -080060 mInflater = LayoutInflater.from(context);
Patrick Dubroy558654c2010-07-23 16:48:11 -070061 }
62
63 @Override
64 protected void onFinishInflate() {
Winson Chung321e9ee2010-08-09 13:37:56 -070065 // setup the tab host
66 setup();
67
Patrick Dubroy558654c2010-07-23 16:48:11 -070068 try {
Winson Chung321e9ee2010-08-09 13:37:56 -070069 mAllApps = (AllAppsPagedView) findViewById(R.id.all_apps_paged_view);
70 if (mAllApps == null) throw new Resources.NotFoundException();
Michael Jurka2763be32011-02-24 11:19:57 -080071 mTabBar = findViewById(R.id.all_apps_tab_bar);
72 if (mTabBar == null) throw new Resources.NotFoundException();
Patrick Dubroy558654c2010-07-23 16:48:11 -070073 } catch (Resources.NotFoundException e) {
74 Log.e(TAG, "Can't find necessary layout elements for AllAppsTabbed");
75 }
Patrick Dubroy558654c2010-07-23 16:48:11 -070076
Winson Chung321e9ee2010-08-09 13:37:56 -070077 // share the same AllApps workspace across all the tabs
Patrick Dubroy558654c2010-07-23 16:48:11 -070078 TabContentFactory contentFactory = new TabContentFactory() {
79 public View createTabContent(String tag) {
Winson Chung321e9ee2010-08-09 13:37:56 -070080 return mAllApps;
Patrick Dubroy558654c2010-07-23 16:48:11 -070081 }
82 };
83
Winson Chung49767ae2010-11-29 14:48:30 -080084 TextView tabView;
85 TabWidget tabWidget = (TabWidget) findViewById(com.android.internal.R.id.tabs);
86 tabView = (TextView) mInflater.inflate(R.layout.tab_widget_indicator, tabWidget, false);
87 tabView.setText(mContext.getString(R.string.all_apps_tab_all));
88 addTab(newTabSpec(TAG_ALL).setIndicator(tabView).setContent(contentFactory));
Patrick Dubroy3d605d52010-07-29 13:59:29 -070089
Winson Chung49767ae2010-11-29 14:48:30 -080090 tabView = (TextView) mInflater.inflate(R.layout.tab_widget_indicator, tabWidget, false);
91 tabView.setText(mContext.getString(R.string.all_apps_tab_downloaded));
92 addTab(newTabSpec(TAG_DOWNLOADED).setIndicator(tabView).setContent(contentFactory));
Patrick Dubroy3d605d52010-07-29 13:59:29 -070093
94 setOnTabChangedListener(new OnTabChangeListener() {
95 public void onTabChanged(String tabId) {
Winson Chung80baf5a2010-08-09 16:03:15 -070096 // animate the changing of the tab content by fading pages in and out
Winson Chungbbc60d82010-11-11 16:34:41 -080097 final Resources res = getResources();
98 final int duration = res.getInteger(R.integer.config_tabTransitionTime);
Winson Chung80baf5a2010-08-09 16:03:15 -070099 final float alpha = mAllApps.getAlpha();
Chet Haase472b2812010-10-14 07:02:04 -0700100 ValueAnimator alphaAnim = ObjectAnimator.ofFloat(mAllApps, "alpha", alpha, 0.0f).
101 setDuration(duration);
Michael Jurka8edd75c2010-12-17 20:15:06 -0800102 alphaAnim.addListener(new AnimatorListenerAdapter() {
Gilles Debunnedd6c9922010-10-25 11:23:41 -0700103 @Override
Michael Jurka8edd75c2010-12-17 20:15:06 -0800104 public void onAnimationEnd(Animator animation) {
Winson Chung80baf5a2010-08-09 16:03:15 -0700105 String tag = getCurrentTabTag();
106 if (tag == TAG_ALL) {
107 mAllApps.setAppFilter(AllAppsPagedView.ALL_APPS_FLAG);
Winson Chung80baf5a2010-08-09 16:03:15 -0700108 } else if (tag == TAG_DOWNLOADED) {
109 mAllApps.setAppFilter(ApplicationInfo.DOWNLOADED_FLAG);
110 }
111
112 final float alpha = mAllApps.getAlpha();
Chet Haase472b2812010-10-14 07:02:04 -0700113 ObjectAnimator.ofFloat(mAllApps, "alpha", alpha, 1.0f).
114 setDuration(duration).start();
Winson Chung80baf5a2010-08-09 16:03:15 -0700115 }
116 });
117 alphaAnim.start();
Patrick Dubroy3d605d52010-07-29 13:59:29 -0700118 }
119 });
Patrick Dubroy558654c2010-07-23 16:48:11 -0700120
Winson Chung321e9ee2010-08-09 13:37:56 -0700121 // 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 Dubroy558654c2010-07-23 16:48:11 -0700124 }
125
126 @Override
127 public void setLauncher(Launcher launcher) {
Winson Chung321e9ee2010-08-09 13:37:56 -0700128 mAllApps.setLauncher(launcher);
Patrick Dubroy558654c2010-07-23 16:48:11 -0700129 }
130
131 @Override
132 public void setDragController(DragController dragger) {
Winson Chung321e9ee2010-08-09 13:37:56 -0700133 mAllApps.setDragController(dragger);
Patrick Dubroy558654c2010-07-23 16:48:11 -0700134 }
135
136 @Override
137 public void zoom(float zoom, boolean animate) {
138 // NOTE: animate parameter is ignored for the TabHost itself
139 setVisibility((zoom == 0.0f) ? View.GONE : View.VISIBLE);
Winson Chung321e9ee2010-08-09 13:37:56 -0700140 mAllApps.zoom(zoom, animate);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -0700141 }
142
143 @Override
144 public void setVisibility(int visibility) {
Michael Jurka6c7a03a2011-01-16 18:43:58 -0800145 if (visibility == View.GONE && mFirstLayout) {
146 // It needs to be INVISIBLE so that it will be measured in the layout.
147 // Otherwise the animations is messed up when we show it for the first time.
148 visibility = View.INVISIBLE;
149 }
Winson Chung80baf5a2010-08-09 16:03:15 -0700150 final boolean isVisible = (visibility == View.VISIBLE);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -0700151 super.setVisibility(visibility);
Winson Chung80baf5a2010-08-09 16:03:15 -0700152 float zoom = (isVisible ? 1.0f : 0.0f);
Winson Chung321e9ee2010-08-09 13:37:56 -0700153 mAllApps.zoom(zoom, false);
Patrick Dubroy558654c2010-07-23 16:48:11 -0700154 }
155
156 @Override
157 public boolean isVisible() {
Winson Chung321e9ee2010-08-09 13:37:56 -0700158 return mAllApps.isVisible();
Patrick Dubroy558654c2010-07-23 16:48:11 -0700159 }
160
161 @Override
Michael Jurka6c7a03a2011-01-16 18:43:58 -0800162 protected void onLayout(boolean changed, int l, int t, int r, int b) {
163 mFirstLayout = false;
164 super.onLayout(changed, l, t, r, b);
165 }
166
167 @Override
Patrick Dubroyff5f0402010-07-26 15:23:26 -0700168 public boolean isAnimating() {
169 return (getAnimation() != null);
170 }
171
172 @Override
Michael Jurka2763be32011-02-24 11:19:57 -0800173 public void setFastAlpha(float alpha) {
174 final ViewGroup allAppsParent = (ViewGroup) mAllApps.getParent();
175 final ViewGroup tabBarParent = (ViewGroup) mAllApps.getParent();
176 mAllApps.setFastAlpha(alpha);
177 allAppsParent.fastInvalidate();
178 mTabBar.setFastAlpha(alpha);
179 tabBarParent.fastInvalidate();
180 }
181
182 @Override
183 public void onLauncherAnimationStart() {
184 mTabBar.setLayerType(LAYER_TYPE_HARDWARE, null);
185 mAllApps.setLayerType(LAYER_TYPE_HARDWARE, null);
186 }
187
188 @Override
189 public void onLauncherAnimationEnd() {
190 mTabBar.setLayerType(LAYER_TYPE_NONE, null);
191 mAllApps.setLayerType(LAYER_TYPE_NONE, null);
192 }
193
194 @Override
Patrick Dubroy558654c2010-07-23 16:48:11 -0700195 public void setApps(ArrayList<ApplicationInfo> list) {
Winson Chung321e9ee2010-08-09 13:37:56 -0700196 mAllApps.setApps(list);
Patrick Dubroy558654c2010-07-23 16:48:11 -0700197 }
198
199 @Override
200 public void addApps(ArrayList<ApplicationInfo> list) {
Winson Chung321e9ee2010-08-09 13:37:56 -0700201 mAllApps.addApps(list);
Patrick Dubroy558654c2010-07-23 16:48:11 -0700202 }
203
204 @Override
205 public void removeApps(ArrayList<ApplicationInfo> list) {
Winson Chung321e9ee2010-08-09 13:37:56 -0700206 mAllApps.removeApps(list);
Patrick Dubroy558654c2010-07-23 16:48:11 -0700207 }
208
209 @Override
210 public void updateApps(ArrayList<ApplicationInfo> list) {
Winson Chung321e9ee2010-08-09 13:37:56 -0700211 mAllApps.updateApps(list);
Patrick Dubroy558654c2010-07-23 16:48:11 -0700212 }
213
214 @Override
215 public void dumpState() {
Winson Chung321e9ee2010-08-09 13:37:56 -0700216 mAllApps.dumpState();
Patrick Dubroy558654c2010-07-23 16:48:11 -0700217 }
218
219 @Override
220 public void surrender() {
Winson Chung321e9ee2010-08-09 13:37:56 -0700221 mAllApps.surrender();
Patrick Dubroy558654c2010-07-23 16:48:11 -0700222 }
Adam Lesinski6b879f02010-11-04 16:15:23 -0700223
224 @Override
225 public boolean onTouchEvent(MotionEvent ev) {
226 if (ev.getY() > mAllApps.getBottom()) {
227 return false;
228 }
229 return true;
230 }
Patrick Dubroy558654c2010-07-23 16:48:11 -0700231}