blob: 7dbb1a5fa3dcd524f6212215bc691b86edd78b37 [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
19import com.android.launcher.R;
20
21import android.content.Context;
22import android.content.res.Resources;
23import android.util.AttributeSet;
24import android.util.Log;
25import android.view.View;
26import android.widget.TabHost;
27
28import java.util.ArrayList;
29
30/**
31 * Implements a tabbed version of AllApps2D.
32 */
33public class AllAppsTabbed extends TabHost implements AllAppsView {
34
35 private static final String TAG = "Launcher.AllAppsTabbed";
36
Patrick Dubroy3d605d52010-07-29 13:59:29 -070037 private static final String TAG_ALL = "ALL";
38 private static final String TAG_APPS = "APPS";
39 private static final String TAG_GAMES = "GAMES";
40 private static final String TAG_DOWNLOADED = "DOWNLOADED";
41
42 private AllApps2D mAllApps2D;
43 private Context mContext;
Patrick Dubroy558654c2010-07-23 16:48:11 -070044
45 public AllAppsTabbed(Context context, AttributeSet attrs) {
46 super(context, attrs);
Patrick Dubroy3d605d52010-07-29 13:59:29 -070047 mContext = context;
Patrick Dubroy558654c2010-07-23 16:48:11 -070048 }
49
50 @Override
51 protected void onFinishInflate() {
52 try {
Patrick Dubroy3d605d52010-07-29 13:59:29 -070053 mAllApps2D = (AllApps2D)findViewById(R.id.all_apps_2d);
Patrick Dubroy558654c2010-07-23 16:48:11 -070054 if (mAllApps2D == null) throw new Resources.NotFoundException();
55 } catch (Resources.NotFoundException e) {
56 Log.e(TAG, "Can't find necessary layout elements for AllAppsTabbed");
57 }
58 setup();
59
60 // This lets us share the same view between all tabs
61 TabContentFactory contentFactory = new TabContentFactory() {
62 public View createTabContent(String tag) {
Patrick Dubroy3d605d52010-07-29 13:59:29 -070063 return mAllApps2D;
Patrick Dubroy558654c2010-07-23 16:48:11 -070064 }
65 };
66
Patrick Dubroy3d605d52010-07-29 13:59:29 -070067 String label = mContext.getString(R.string.all_apps_tab_all);
68 addTab(newTabSpec(TAG_ALL).setIndicator(label).setContent(contentFactory));
69
70 label = mContext.getString(R.string.all_apps_tab_apps);
71 addTab(newTabSpec(TAG_APPS).setIndicator(label).setContent(contentFactory));
72
73 label = mContext.getString(R.string.all_apps_tab_games);
74 addTab(newTabSpec(TAG_GAMES).setIndicator(label).setContent(contentFactory));
75
76 label = mContext.getString(R.string.all_apps_tab_downloaded);
77 addTab(newTabSpec(TAG_DOWNLOADED).setIndicator(label).setContent(contentFactory));
78
79 setOnTabChangedListener(new OnTabChangeListener() {
80 public void onTabChanged(String tabId) {
81 String tag = getCurrentTabTag();
82 if (tag == TAG_ALL) {
83 mAllApps2D.filterApps(AllApps2D.AppType.ALL);
84 } else if (tag == TAG_APPS) {
85 mAllApps2D.filterApps(AllApps2D.AppType.APP);
86 } else if (tag == TAG_GAMES) {
87 mAllApps2D.filterApps(AllApps2D.AppType.GAME);
88 } else if (tag == TAG_DOWNLOADED) {
89 mAllApps2D.filterApps(AllApps2D.AppType.DOWNLOADED);
90 }
91 }
92 });
Patrick Dubroy558654c2010-07-23 16:48:11 -070093
94 setCurrentTab(0);
Patrick Dubroy558654c2010-07-23 16:48:11 -070095 }
96
97 @Override
98 public void setLauncher(Launcher launcher) {
99 mAllApps2D.setLauncher(launcher);
100 }
101
102 @Override
103 public void setDragController(DragController dragger) {
104 mAllApps2D.setDragController(dragger);
105 }
106
107 @Override
108 public void zoom(float zoom, boolean animate) {
109 // NOTE: animate parameter is ignored for the TabHost itself
110 setVisibility((zoom == 0.0f) ? View.GONE : View.VISIBLE);
111 mAllApps2D.zoom(zoom, animate);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -0700112 }
113
114 @Override
115 public void setVisibility(int visibility) {
116 super.setVisibility(visibility);
117 float zoom = visibility == View.VISIBLE ? 1.0f : 0.0f;
118 mAllApps2D.zoom(zoom, false);
Patrick Dubroy558654c2010-07-23 16:48:11 -0700119 }
120
121 @Override
122 public boolean isVisible() {
123 return mAllApps2D.isVisible();
124 }
125
126 @Override
Patrick Dubroyff5f0402010-07-26 15:23:26 -0700127 public boolean isAnimating() {
128 return (getAnimation() != null);
129 }
130
131 @Override
Patrick Dubroy558654c2010-07-23 16:48:11 -0700132 public void setApps(ArrayList<ApplicationInfo> list) {
133 mAllApps2D.setApps(list);
134 }
135
136 @Override
137 public void addApps(ArrayList<ApplicationInfo> list) {
138 mAllApps2D.addApps(list);
139 }
140
141 @Override
142 public void removeApps(ArrayList<ApplicationInfo> list) {
143 mAllApps2D.removeApps(list);
144 }
145
146 @Override
147 public void updateApps(ArrayList<ApplicationInfo> list) {
148 mAllApps2D.updateApps(list);
149 }
150
151 @Override
152 public void dumpState() {
153 mAllApps2D.dumpState();
154 }
155
156 @Override
157 public void surrender() {
158 mAllApps2D.surrender();
159 }
Patrick Dubroy558654c2010-07-23 16:48:11 -0700160}