blob: 3aa70f49e62575dd72705c90f00248a7d26d94d7 [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 Dubroy7247f632010-08-04 16:02:59 -070095
96 // It needs to be INVISIBLE so that it will be measured in the layout.
97 // Otherwise the animations is messed up when we show it for the first time.
98 setVisibility(INVISIBLE);
Patrick Dubroy558654c2010-07-23 16:48:11 -070099 }
100
101 @Override
102 public void setLauncher(Launcher launcher) {
103 mAllApps2D.setLauncher(launcher);
104 }
105
106 @Override
107 public void setDragController(DragController dragger) {
108 mAllApps2D.setDragController(dragger);
109 }
110
111 @Override
112 public void zoom(float zoom, boolean animate) {
113 // NOTE: animate parameter is ignored for the TabHost itself
114 setVisibility((zoom == 0.0f) ? View.GONE : View.VISIBLE);
115 mAllApps2D.zoom(zoom, animate);
116 bringChildToFront((View)mAllApps2D);
117 getParent().bringChildToFront(this);
118 }
119
120 @Override
121 public boolean isVisible() {
122 return mAllApps2D.isVisible();
123 }
124
125 @Override
Patrick Dubroyff5f0402010-07-26 15:23:26 -0700126 public boolean isAnimating() {
127 return (getAnimation() != null);
128 }
129
130 @Override
Patrick Dubroy558654c2010-07-23 16:48:11 -0700131 public void setApps(ArrayList<ApplicationInfo> list) {
132 mAllApps2D.setApps(list);
133 }
134
135 @Override
136 public void addApps(ArrayList<ApplicationInfo> list) {
137 mAllApps2D.addApps(list);
138 }
139
140 @Override
141 public void removeApps(ArrayList<ApplicationInfo> list) {
142 mAllApps2D.removeApps(list);
143 }
144
145 @Override
146 public void updateApps(ArrayList<ApplicationInfo> list) {
147 mAllApps2D.updateApps(list);
148 }
149
150 @Override
151 public void dumpState() {
152 mAllApps2D.dumpState();
153 }
154
155 @Override
156 public void surrender() {
157 mAllApps2D.surrender();
158 }
Patrick Dubroy558654c2010-07-23 16:48:11 -0700159}