blob: 0470cee3ebda6434bdc3a0f155581de2081d9724 [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
21import android.content.Context;
22import android.content.res.Resources;
Winson Chung321e9ee2010-08-09 13:37:56 -070023import android.graphics.Color;
Patrick Dubroy558654c2010-07-23 16:48:11 -070024import android.util.AttributeSet;
25import android.util.Log;
26import android.view.View;
Winson Chung321e9ee2010-08-09 13:37:56 -070027import android.widget.RelativeLayout;
Patrick Dubroy558654c2010-07-23 16:48:11 -070028import android.widget.TabHost;
Winson Chung321e9ee2010-08-09 13:37:56 -070029import android.widget.TabWidget;
30import android.widget.TextView;
Patrick Dubroy558654c2010-07-23 16:48:11 -070031
Winson Chung321e9ee2010-08-09 13:37:56 -070032import com.android.launcher.R;
Patrick Dubroy558654c2010-07-23 16:48:11 -070033
34/**
35 * Implements a tabbed version of AllApps2D.
36 */
37public class AllAppsTabbed extends TabHost implements AllAppsView {
38
39 private static final String TAG = "Launcher.AllAppsTabbed";
40
Patrick Dubroy3d605d52010-07-29 13:59:29 -070041 private static final String TAG_ALL = "ALL";
42 private static final String TAG_APPS = "APPS";
43 private static final String TAG_GAMES = "GAMES";
44 private static final String TAG_DOWNLOADED = "DOWNLOADED";
45
Winson Chung321e9ee2010-08-09 13:37:56 -070046 private AllAppsPagedView mAllApps;
Patrick Dubroy3d605d52010-07-29 13:59:29 -070047 private Context mContext;
Patrick Dubroy558654c2010-07-23 16:48:11 -070048
49 public AllAppsTabbed(Context context, AttributeSet attrs) {
50 super(context, attrs);
Patrick Dubroy3d605d52010-07-29 13:59:29 -070051 mContext = context;
Patrick Dubroy558654c2010-07-23 16:48:11 -070052 }
53
54 @Override
55 protected void onFinishInflate() {
Winson Chung321e9ee2010-08-09 13:37:56 -070056 // setup the tab host
57 setup();
58
Patrick Dubroy558654c2010-07-23 16:48:11 -070059 try {
Winson Chung321e9ee2010-08-09 13:37:56 -070060 mAllApps = (AllAppsPagedView) findViewById(R.id.all_apps_paged_view);
61 if (mAllApps == null) throw new Resources.NotFoundException();
Patrick Dubroy558654c2010-07-23 16:48:11 -070062 } catch (Resources.NotFoundException e) {
63 Log.e(TAG, "Can't find necessary layout elements for AllAppsTabbed");
64 }
Patrick Dubroy558654c2010-07-23 16:48:11 -070065
Winson Chung321e9ee2010-08-09 13:37:56 -070066 // share the same AllApps workspace across all the tabs
Patrick Dubroy558654c2010-07-23 16:48:11 -070067 TabContentFactory contentFactory = new TabContentFactory() {
68 public View createTabContent(String tag) {
Winson Chung321e9ee2010-08-09 13:37:56 -070069 return mAllApps;
Patrick Dubroy558654c2010-07-23 16:48:11 -070070 }
71 };
72
Patrick Dubroy3d605d52010-07-29 13:59:29 -070073 String label = mContext.getString(R.string.all_apps_tab_all);
74 addTab(newTabSpec(TAG_ALL).setIndicator(label).setContent(contentFactory));
75
76 label = mContext.getString(R.string.all_apps_tab_apps);
77 addTab(newTabSpec(TAG_APPS).setIndicator(label).setContent(contentFactory));
78
79 label = mContext.getString(R.string.all_apps_tab_games);
80 addTab(newTabSpec(TAG_GAMES).setIndicator(label).setContent(contentFactory));
81
82 label = mContext.getString(R.string.all_apps_tab_downloaded);
83 addTab(newTabSpec(TAG_DOWNLOADED).setIndicator(label).setContent(contentFactory));
84
Winson Chung321e9ee2010-08-09 13:37:56 -070085 // TEMP: just styling the tab widget to be a bit nicer until we get the actual
86 // new assets
87 TabWidget tabWidget = getTabWidget();
88 for (int i = 0; i < tabWidget.getChildCount(); ++i) {
89 RelativeLayout tab = (RelativeLayout) tabWidget.getChildTabViewAt(i);
90 TextView text = (TextView) tab.getChildAt(1);
91 text.setTextSize(20.0f);
92 text.setPadding(20, 0, 20, 0);
93 text.setShadowLayer(1.0f, 0.0f, 1.0f, Color.BLACK);
94 tab.setBackgroundDrawable(null);
95 }
96
Patrick Dubroy3d605d52010-07-29 13:59:29 -070097 setOnTabChangedListener(new OnTabChangeListener() {
98 public void onTabChanged(String tabId) {
99 String tag = getCurrentTabTag();
100 if (tag == TAG_ALL) {
Winson Chung321e9ee2010-08-09 13:37:56 -0700101 mAllApps.setAppFilter(AllAppsPagedView.ALL_APPS_FLAG);
Patrick Dubroy3d605d52010-07-29 13:59:29 -0700102 } else if (tag == TAG_APPS) {
Winson Chung321e9ee2010-08-09 13:37:56 -0700103 mAllApps.setAppFilter(ApplicationInfo.APP_FLAG);
Patrick Dubroy3d605d52010-07-29 13:59:29 -0700104 } else if (tag == TAG_GAMES) {
Winson Chung321e9ee2010-08-09 13:37:56 -0700105 mAllApps.setAppFilter(ApplicationInfo.GAME_FLAG);
Patrick Dubroy3d605d52010-07-29 13:59:29 -0700106 } else if (tag == TAG_DOWNLOADED) {
Winson Chung321e9ee2010-08-09 13:37:56 -0700107 mAllApps.setAppFilter(ApplicationInfo.DOWNLOADED_FLAG);
Patrick Dubroy3d605d52010-07-29 13:59:29 -0700108 }
109 }
110 });
Patrick Dubroy558654c2010-07-23 16:48:11 -0700111
112 setCurrentTab(0);
Winson Chung321e9ee2010-08-09 13:37:56 -0700113
114 // It needs to be INVISIBLE so that it will be measured in the layout.
115 // Otherwise the animations is messed up when we show it for the first time.
116 setVisibility(INVISIBLE);
Patrick Dubroy558654c2010-07-23 16:48:11 -0700117 }
118
119 @Override
120 public void setLauncher(Launcher launcher) {
Winson Chung321e9ee2010-08-09 13:37:56 -0700121 mAllApps.setLauncher(launcher);
Patrick Dubroy558654c2010-07-23 16:48:11 -0700122 }
123
124 @Override
125 public void setDragController(DragController dragger) {
Winson Chung321e9ee2010-08-09 13:37:56 -0700126 mAllApps.setDragController(dragger);
Patrick Dubroy558654c2010-07-23 16:48:11 -0700127 }
128
129 @Override
130 public void zoom(float zoom, boolean animate) {
131 // NOTE: animate parameter is ignored for the TabHost itself
132 setVisibility((zoom == 0.0f) ? View.GONE : View.VISIBLE);
Winson Chung321e9ee2010-08-09 13:37:56 -0700133 mAllApps.zoom(zoom, animate);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -0700134 }
135
136 @Override
137 public void setVisibility(int visibility) {
138 super.setVisibility(visibility);
139 float zoom = visibility == View.VISIBLE ? 1.0f : 0.0f;
Winson Chung321e9ee2010-08-09 13:37:56 -0700140 mAllApps.zoom(zoom, false);
Patrick Dubroy558654c2010-07-23 16:48:11 -0700141 }
142
143 @Override
144 public boolean isVisible() {
Winson Chung321e9ee2010-08-09 13:37:56 -0700145 return mAllApps.isVisible();
Patrick Dubroy558654c2010-07-23 16:48:11 -0700146 }
147
148 @Override
Patrick Dubroyff5f0402010-07-26 15:23:26 -0700149 public boolean isAnimating() {
150 return (getAnimation() != null);
151 }
152
153 @Override
Patrick Dubroy558654c2010-07-23 16:48:11 -0700154 public void setApps(ArrayList<ApplicationInfo> list) {
Winson Chung321e9ee2010-08-09 13:37:56 -0700155 mAllApps.setApps(list);
Patrick Dubroy558654c2010-07-23 16:48:11 -0700156 }
157
158 @Override
159 public void addApps(ArrayList<ApplicationInfo> list) {
Winson Chung321e9ee2010-08-09 13:37:56 -0700160 mAllApps.addApps(list);
Patrick Dubroy558654c2010-07-23 16:48:11 -0700161 }
162
163 @Override
164 public void removeApps(ArrayList<ApplicationInfo> list) {
Winson Chung321e9ee2010-08-09 13:37:56 -0700165 mAllApps.removeApps(list);
Patrick Dubroy558654c2010-07-23 16:48:11 -0700166 }
167
168 @Override
169 public void updateApps(ArrayList<ApplicationInfo> list) {
Winson Chung321e9ee2010-08-09 13:37:56 -0700170 mAllApps.updateApps(list);
Patrick Dubroy558654c2010-07-23 16:48:11 -0700171 }
172
173 @Override
174 public void dumpState() {
Winson Chung321e9ee2010-08-09 13:37:56 -0700175 mAllApps.dumpState();
Patrick Dubroy558654c2010-07-23 16:48:11 -0700176 }
177
178 @Override
179 public void surrender() {
Winson Chung321e9ee2010-08-09 13:37:56 -0700180 mAllApps.surrender();
Patrick Dubroy558654c2010-07-23 16:48:11 -0700181 }
Patrick Dubroy558654c2010-07-23 16:48:11 -0700182}