blob: ac6484db81acb9014bb8a5513572a1c890864215 [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
Gilles Debunnedd6c9922010-10-25 11:23:41 -070019import com.android.launcher.R;
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;
Chet Haaseb1254a62010-09-07 13:35:00 -070023import android.animation.ObjectAnimator;
Gilles Debunnedd6c9922010-10-25 11:23:41 -070024import android.animation.ValueAnimator;
Patrick Dubroy558654c2010-07-23 16:48:11 -070025import android.content.Context;
26import android.content.res.Resources;
27import android.util.AttributeSet;
28import android.util.Log;
29import android.view.View;
30import android.widget.TabHost;
31
Gilles Debunnedd6c9922010-10-25 11:23:41 -070032import java.util.ArrayList;
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
85 setOnTabChangedListener(new OnTabChangeListener() {
86 public void onTabChanged(String tabId) {
Winson Chung80baf5a2010-08-09 16:03:15 -070087 // animate the changing of the tab content by fading pages in and out
88 final int duration = 150;
89 final float alpha = mAllApps.getAlpha();
Chet Haase472b2812010-10-14 07:02:04 -070090 ValueAnimator alphaAnim = ObjectAnimator.ofFloat(mAllApps, "alpha", alpha, 0.0f).
91 setDuration(duration);
Chet Haaseb1254a62010-09-07 13:35:00 -070092 alphaAnim.addListener(new AnimatorListenerAdapter() {
Gilles Debunnedd6c9922010-10-25 11:23:41 -070093 @Override
Chet Haaseb1254a62010-09-07 13:35:00 -070094 public void onAnimationEnd(Animator animation) {
Winson Chung80baf5a2010-08-09 16:03:15 -070095 String tag = getCurrentTabTag();
96 if (tag == TAG_ALL) {
97 mAllApps.setAppFilter(AllAppsPagedView.ALL_APPS_FLAG);
98 } else if (tag == TAG_APPS) {
99 mAllApps.setAppFilter(ApplicationInfo.APP_FLAG);
100 } else if (tag == TAG_GAMES) {
101 mAllApps.setAppFilter(ApplicationInfo.GAME_FLAG);
102 } else if (tag == TAG_DOWNLOADED) {
103 mAllApps.setAppFilter(ApplicationInfo.DOWNLOADED_FLAG);
104 }
105
106 final float alpha = mAllApps.getAlpha();
Chet Haase472b2812010-10-14 07:02:04 -0700107 ObjectAnimator.ofFloat(mAllApps, "alpha", alpha, 1.0f).
108 setDuration(duration).start();
Winson Chung80baf5a2010-08-09 16:03:15 -0700109 }
110 });
111 alphaAnim.start();
Patrick Dubroy3d605d52010-07-29 13:59:29 -0700112 }
113 });
Patrick Dubroy558654c2010-07-23 16:48:11 -0700114
Winson Chung321e9ee2010-08-09 13:37:56 -0700115 // It needs to be INVISIBLE so that it will be measured in the layout.
116 // Otherwise the animations is messed up when we show it for the first time.
117 setVisibility(INVISIBLE);
Patrick Dubroy558654c2010-07-23 16:48:11 -0700118 }
119
120 @Override
121 public void setLauncher(Launcher launcher) {
Winson Chung321e9ee2010-08-09 13:37:56 -0700122 mAllApps.setLauncher(launcher);
Patrick Dubroy558654c2010-07-23 16:48:11 -0700123 }
124
125 @Override
126 public void setDragController(DragController dragger) {
Winson Chung321e9ee2010-08-09 13:37:56 -0700127 mAllApps.setDragController(dragger);
Patrick Dubroy558654c2010-07-23 16:48:11 -0700128 }
129
130 @Override
131 public void zoom(float zoom, boolean animate) {
132 // NOTE: animate parameter is ignored for the TabHost itself
133 setVisibility((zoom == 0.0f) ? View.GONE : View.VISIBLE);
Winson Chung321e9ee2010-08-09 13:37:56 -0700134 mAllApps.zoom(zoom, animate);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -0700135 }
136
137 @Override
138 public void setVisibility(int visibility) {
Winson Chung80baf5a2010-08-09 16:03:15 -0700139 final boolean isVisible = (visibility == View.VISIBLE);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -0700140 super.setVisibility(visibility);
Winson Chung80baf5a2010-08-09 16:03:15 -0700141 float zoom = (isVisible ? 1.0f : 0.0f);
Winson Chung321e9ee2010-08-09 13:37:56 -0700142 mAllApps.zoom(zoom, false);
Patrick Dubroy558654c2010-07-23 16:48:11 -0700143 }
144
145 @Override
146 public boolean isVisible() {
Winson Chung321e9ee2010-08-09 13:37:56 -0700147 return mAllApps.isVisible();
Patrick Dubroy558654c2010-07-23 16:48:11 -0700148 }
149
150 @Override
Patrick Dubroyff5f0402010-07-26 15:23:26 -0700151 public boolean isAnimating() {
152 return (getAnimation() != null);
153 }
154
155 @Override
Patrick Dubroy558654c2010-07-23 16:48:11 -0700156 public void setApps(ArrayList<ApplicationInfo> list) {
Winson Chung321e9ee2010-08-09 13:37:56 -0700157 mAllApps.setApps(list);
Patrick Dubroy558654c2010-07-23 16:48:11 -0700158 }
159
160 @Override
161 public void addApps(ArrayList<ApplicationInfo> list) {
Winson Chung321e9ee2010-08-09 13:37:56 -0700162 mAllApps.addApps(list);
Patrick Dubroy558654c2010-07-23 16:48:11 -0700163 }
164
165 @Override
166 public void removeApps(ArrayList<ApplicationInfo> list) {
Winson Chung321e9ee2010-08-09 13:37:56 -0700167 mAllApps.removeApps(list);
Patrick Dubroy558654c2010-07-23 16:48:11 -0700168 }
169
170 @Override
171 public void updateApps(ArrayList<ApplicationInfo> list) {
Winson Chung321e9ee2010-08-09 13:37:56 -0700172 mAllApps.updateApps(list);
Patrick Dubroy558654c2010-07-23 16:48:11 -0700173 }
174
175 @Override
176 public void dumpState() {
Winson Chung321e9ee2010-08-09 13:37:56 -0700177 mAllApps.dumpState();
Patrick Dubroy558654c2010-07-23 16:48:11 -0700178 }
179
180 @Override
181 public void surrender() {
Winson Chung321e9ee2010-08-09 13:37:56 -0700182 mAllApps.surrender();
Patrick Dubroy558654c2010-07-23 16:48:11 -0700183 }
Patrick Dubroy558654c2010-07-23 16:48:11 -0700184}