blob: 20027032c8fd4dca1c5e2acadc61e66bd1541b85 [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);
95 setVisibility(GONE);
96 }
97
98 @Override
99 public void setLauncher(Launcher launcher) {
100 mAllApps2D.setLauncher(launcher);
101 }
102
103 @Override
104 public void setDragController(DragController dragger) {
105 mAllApps2D.setDragController(dragger);
106 }
107
108 @Override
109 public void zoom(float zoom, boolean animate) {
110 // NOTE: animate parameter is ignored for the TabHost itself
111 setVisibility((zoom == 0.0f) ? View.GONE : View.VISIBLE);
112 mAllApps2D.zoom(zoom, animate);
113 bringChildToFront((View)mAllApps2D);
114 getParent().bringChildToFront(this);
115 }
116
117 @Override
118 public boolean isVisible() {
119 return mAllApps2D.isVisible();
120 }
121
122 @Override
Patrick Dubroyff5f0402010-07-26 15:23:26 -0700123 public boolean isAnimating() {
124 return (getAnimation() != null);
125 }
126
127 @Override
Patrick Dubroy558654c2010-07-23 16:48:11 -0700128 public void setApps(ArrayList<ApplicationInfo> list) {
129 mAllApps2D.setApps(list);
130 }
131
132 @Override
133 public void addApps(ArrayList<ApplicationInfo> list) {
134 mAllApps2D.addApps(list);
135 }
136
137 @Override
138 public void removeApps(ArrayList<ApplicationInfo> list) {
139 mAllApps2D.removeApps(list);
140 }
141
142 @Override
143 public void updateApps(ArrayList<ApplicationInfo> list) {
144 mAllApps2D.updateApps(list);
145 }
146
147 @Override
148 public void dumpState() {
149 mAllApps2D.dumpState();
150 }
151
152 @Override
153 public void surrender() {
154 mAllApps2D.surrender();
155 }
Patrick Dubroy558654c2010-07-23 16:48:11 -0700156}