blob: cc6a14907d29a40b20632d809c4e6c61c1e808ee [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
Winson Chung321e9ee2010-08-09 13:37:56 -070019import java.util.ArrayList;
Patrick Dubroy558654c2010-07-23 16:48:11 -070020
Winson Chung80baf5a2010-08-09 16:03:15 -070021import android.animation.Animator;
Chet Haaseb1254a62010-09-07 13:35:00 -070022import android.animation.AnimatorListenerAdapter;
23import android.animation.ValueAnimator;
24import android.animation.ObjectAnimator;
Patrick Dubroy558654c2010-07-23 16:48:11 -070025import android.content.Context;
26import android.content.res.Resources;
Winson Chung321e9ee2010-08-09 13:37:56 -070027import android.graphics.Color;
Patrick Dubroy558654c2010-07-23 16:48:11 -070028import android.util.AttributeSet;
29import android.util.Log;
30import android.view.View;
Winson Chung321e9ee2010-08-09 13:37:56 -070031import android.widget.RelativeLayout;
Patrick Dubroy558654c2010-07-23 16:48:11 -070032import android.widget.TabHost;
Winson Chung321e9ee2010-08-09 13:37:56 -070033import android.widget.TabWidget;
34import android.widget.TextView;
Patrick Dubroy558654c2010-07-23 16:48:11 -070035
Winson Chung321e9ee2010-08-09 13:37:56 -070036import com.android.launcher.R;
Patrick Dubroy558654c2010-07-23 16:48:11 -070037
38/**
39 * Implements a tabbed version of AllApps2D.
40 */
41public class AllAppsTabbed extends TabHost implements AllAppsView {
42
43 private static final String TAG = "Launcher.AllAppsTabbed";
44
Patrick Dubroy3d605d52010-07-29 13:59:29 -070045 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 Chung321e9ee2010-08-09 13:37:56 -070050 private AllAppsPagedView mAllApps;
Patrick Dubroy3d605d52010-07-29 13:59:29 -070051 private Context mContext;
Patrick Dubroy558654c2010-07-23 16:48:11 -070052
53 public AllAppsTabbed(Context context, AttributeSet attrs) {
54 super(context, attrs);
Patrick Dubroy3d605d52010-07-29 13:59:29 -070055 mContext = context;
Patrick Dubroy558654c2010-07-23 16:48:11 -070056 }
57
58 @Override
59 protected void onFinishInflate() {
Winson Chung321e9ee2010-08-09 13:37:56 -070060 // setup the tab host
61 setup();
62
Patrick Dubroy558654c2010-07-23 16:48:11 -070063 try {
Winson Chung321e9ee2010-08-09 13:37:56 -070064 mAllApps = (AllAppsPagedView) findViewById(R.id.all_apps_paged_view);
65 if (mAllApps == null) throw new Resources.NotFoundException();
Patrick Dubroy558654c2010-07-23 16:48:11 -070066 } catch (Resources.NotFoundException e) {
67 Log.e(TAG, "Can't find necessary layout elements for AllAppsTabbed");
68 }
Patrick Dubroy558654c2010-07-23 16:48:11 -070069
Winson Chung321e9ee2010-08-09 13:37:56 -070070 // share the same AllApps workspace across all the tabs
Patrick Dubroy558654c2010-07-23 16:48:11 -070071 TabContentFactory contentFactory = new TabContentFactory() {
72 public View createTabContent(String tag) {
Winson Chung321e9ee2010-08-09 13:37:56 -070073 return mAllApps;
Patrick Dubroy558654c2010-07-23 16:48:11 -070074 }
75 };
76
Patrick Dubroy3d605d52010-07-29 13:59:29 -070077 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 Chung321e9ee2010-08-09 13:37:56 -070089 // 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 Dubroy3d605d52010-07-29 13:59:29 -0700101 setOnTabChangedListener(new OnTabChangeListener() {
102 public void onTabChanged(String tabId) {
Winson Chung80baf5a2010-08-09 16:03:15 -0700103 // animate the changing of the tab content by fading pages in and out
104 final int duration = 150;
105 final float alpha = mAllApps.getAlpha();
Chet Haase472b2812010-10-14 07:02:04 -0700106 ValueAnimator alphaAnim = ObjectAnimator.ofFloat(mAllApps, "alpha", alpha, 0.0f).
107 setDuration(duration);
Chet Haaseb1254a62010-09-07 13:35:00 -0700108 alphaAnim.addListener(new AnimatorListenerAdapter() {
109 public void onAnimationEnd(Animator animation) {
Winson Chung80baf5a2010-08-09 16:03:15 -0700110 String tag = getCurrentTabTag();
111 if (tag == TAG_ALL) {
112 mAllApps.setAppFilter(AllAppsPagedView.ALL_APPS_FLAG);
113 } else if (tag == TAG_APPS) {
114 mAllApps.setAppFilter(ApplicationInfo.APP_FLAG);
115 } else if (tag == TAG_GAMES) {
116 mAllApps.setAppFilter(ApplicationInfo.GAME_FLAG);
117 } else if (tag == TAG_DOWNLOADED) {
118 mAllApps.setAppFilter(ApplicationInfo.DOWNLOADED_FLAG);
119 }
120
121 final float alpha = mAllApps.getAlpha();
Chet Haase472b2812010-10-14 07:02:04 -0700122 ObjectAnimator.ofFloat(mAllApps, "alpha", alpha, 1.0f).
123 setDuration(duration).start();
Winson Chung80baf5a2010-08-09 16:03:15 -0700124 }
125 });
126 alphaAnim.start();
Patrick Dubroy3d605d52010-07-29 13:59:29 -0700127 }
128 });
Patrick Dubroy558654c2010-07-23 16:48:11 -0700129
Winson Chungb0b2e6f2010-10-12 17:49:56 -0700130 // TEMP: Working around a bug in tab host where the current tab does not initially have a
131 // highlight on it by selecting something else, then selecting the actual tab we want..
132 setCurrentTab(1);
Patrick Dubroy558654c2010-07-23 16:48:11 -0700133 setCurrentTab(0);
Winson Chung321e9ee2010-08-09 13:37:56 -0700134
135 // It needs to be INVISIBLE so that it will be measured in the layout.
136 // Otherwise the animations is messed up when we show it for the first time.
137 setVisibility(INVISIBLE);
Patrick Dubroy558654c2010-07-23 16:48:11 -0700138 }
139
140 @Override
141 public void setLauncher(Launcher launcher) {
Winson Chung321e9ee2010-08-09 13:37:56 -0700142 mAllApps.setLauncher(launcher);
Patrick Dubroy558654c2010-07-23 16:48:11 -0700143 }
144
145 @Override
146 public void setDragController(DragController dragger) {
Winson Chung321e9ee2010-08-09 13:37:56 -0700147 mAllApps.setDragController(dragger);
Patrick Dubroy558654c2010-07-23 16:48:11 -0700148 }
149
150 @Override
151 public void zoom(float zoom, boolean animate) {
152 // NOTE: animate parameter is ignored for the TabHost itself
153 setVisibility((zoom == 0.0f) ? View.GONE : View.VISIBLE);
Winson Chung321e9ee2010-08-09 13:37:56 -0700154 mAllApps.zoom(zoom, animate);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -0700155 }
156
157 @Override
158 public void setVisibility(int visibility) {
Winson Chung80baf5a2010-08-09 16:03:15 -0700159 final boolean isVisible = (visibility == View.VISIBLE);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -0700160 super.setVisibility(visibility);
Winson Chung80baf5a2010-08-09 16:03:15 -0700161 float zoom = (isVisible ? 1.0f : 0.0f);
Winson Chung321e9ee2010-08-09 13:37:56 -0700162 mAllApps.zoom(zoom, false);
Patrick Dubroy558654c2010-07-23 16:48:11 -0700163 }
164
165 @Override
166 public boolean isVisible() {
Winson Chung321e9ee2010-08-09 13:37:56 -0700167 return mAllApps.isVisible();
Patrick Dubroy558654c2010-07-23 16:48:11 -0700168 }
169
170 @Override
Patrick Dubroyff5f0402010-07-26 15:23:26 -0700171 public boolean isAnimating() {
172 return (getAnimation() != null);
173 }
174
175 @Override
Patrick Dubroy558654c2010-07-23 16:48:11 -0700176 public void setApps(ArrayList<ApplicationInfo> list) {
Winson Chung321e9ee2010-08-09 13:37:56 -0700177 mAllApps.setApps(list);
Patrick Dubroy558654c2010-07-23 16:48:11 -0700178 }
179
180 @Override
181 public void addApps(ArrayList<ApplicationInfo> list) {
Winson Chung321e9ee2010-08-09 13:37:56 -0700182 mAllApps.addApps(list);
Patrick Dubroy558654c2010-07-23 16:48:11 -0700183 }
184
185 @Override
186 public void removeApps(ArrayList<ApplicationInfo> list) {
Winson Chung321e9ee2010-08-09 13:37:56 -0700187 mAllApps.removeApps(list);
Patrick Dubroy558654c2010-07-23 16:48:11 -0700188 }
189
190 @Override
191 public void updateApps(ArrayList<ApplicationInfo> list) {
Winson Chung321e9ee2010-08-09 13:37:56 -0700192 mAllApps.updateApps(list);
Patrick Dubroy558654c2010-07-23 16:48:11 -0700193 }
194
195 @Override
196 public void dumpState() {
Winson Chung321e9ee2010-08-09 13:37:56 -0700197 mAllApps.dumpState();
Patrick Dubroy558654c2010-07-23 16:48:11 -0700198 }
199
200 @Override
201 public void surrender() {
Winson Chung321e9ee2010-08-09 13:37:56 -0700202 mAllApps.surrender();
Patrick Dubroy558654c2010-07-23 16:48:11 -0700203 }
Patrick Dubroy558654c2010-07-23 16:48:11 -0700204}