blob: 0e324615464ef7cc3f506434694886155954bc75 [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.ObjectAnimator;
Gilles Debunnedd6c9922010-10-25 11:23:41 -070023import android.animation.ValueAnimator;
Patrick Dubroy558654c2010-07-23 16:48:11 -070024import android.content.Context;
25import android.content.res.Resources;
26import android.util.AttributeSet;
27import android.util.Log;
Adam Lesinski6b879f02010-11-04 16:15:23 -070028import android.view.MotionEvent;
Patrick Dubroy558654c2010-07-23 16:48:11 -070029import 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";
Patrick Dubroy3d605d52010-07-29 13:59:29 -070042 private static final String TAG_DOWNLOADED = "DOWNLOADED";
43
Winson Chung321e9ee2010-08-09 13:37:56 -070044 private AllAppsPagedView mAllApps;
Patrick Dubroy3d605d52010-07-29 13:59:29 -070045 private Context mContext;
Patrick Dubroy558654c2010-07-23 16:48:11 -070046
47 public AllAppsTabbed(Context context, AttributeSet attrs) {
48 super(context, attrs);
Patrick Dubroy3d605d52010-07-29 13:59:29 -070049 mContext = context;
Patrick Dubroy558654c2010-07-23 16:48:11 -070050 }
51
52 @Override
53 protected void onFinishInflate() {
Winson Chung321e9ee2010-08-09 13:37:56 -070054 // setup the tab host
55 setup();
56
Patrick Dubroy558654c2010-07-23 16:48:11 -070057 try {
Winson Chung321e9ee2010-08-09 13:37:56 -070058 mAllApps = (AllAppsPagedView) findViewById(R.id.all_apps_paged_view);
59 if (mAllApps == null) throw new Resources.NotFoundException();
Patrick Dubroy558654c2010-07-23 16:48:11 -070060 } catch (Resources.NotFoundException e) {
61 Log.e(TAG, "Can't find necessary layout elements for AllAppsTabbed");
62 }
Patrick Dubroy558654c2010-07-23 16:48:11 -070063
Winson Chung321e9ee2010-08-09 13:37:56 -070064 // share the same AllApps workspace across all the tabs
Patrick Dubroy558654c2010-07-23 16:48:11 -070065 TabContentFactory contentFactory = new TabContentFactory() {
66 public View createTabContent(String tag) {
Winson Chung321e9ee2010-08-09 13:37:56 -070067 return mAllApps;
Patrick Dubroy558654c2010-07-23 16:48:11 -070068 }
69 };
70
Patrick Dubroy3d605d52010-07-29 13:59:29 -070071 String label = mContext.getString(R.string.all_apps_tab_all);
72 addTab(newTabSpec(TAG_ALL).setIndicator(label).setContent(contentFactory));
73
Patrick Dubroy3d605d52010-07-29 13:59:29 -070074 label = mContext.getString(R.string.all_apps_tab_downloaded);
75 addTab(newTabSpec(TAG_DOWNLOADED).setIndicator(label).setContent(contentFactory));
76
77 setOnTabChangedListener(new OnTabChangeListener() {
78 public void onTabChanged(String tabId) {
Winson Chung80baf5a2010-08-09 16:03:15 -070079 // animate the changing of the tab content by fading pages in and out
Winson Chungbbc60d82010-11-11 16:34:41 -080080 final Resources res = getResources();
81 final int duration = res.getInteger(R.integer.config_tabTransitionTime);
Winson Chung80baf5a2010-08-09 16:03:15 -070082 final float alpha = mAllApps.getAlpha();
Chet Haase472b2812010-10-14 07:02:04 -070083 ValueAnimator alphaAnim = ObjectAnimator.ofFloat(mAllApps, "alpha", alpha, 0.0f).
84 setDuration(duration);
Michael Jurka3c4c20f2010-10-28 15:36:06 -070085 alphaAnim.addListener(new LauncherAnimatorListenerAdapter() {
Gilles Debunnedd6c9922010-10-25 11:23:41 -070086 @Override
Michael Jurka3c4c20f2010-10-28 15:36:06 -070087 public void onAnimationEndOrCancel(Animator animation) {
Winson Chung80baf5a2010-08-09 16:03:15 -070088 String tag = getCurrentTabTag();
89 if (tag == TAG_ALL) {
90 mAllApps.setAppFilter(AllAppsPagedView.ALL_APPS_FLAG);
Winson Chung80baf5a2010-08-09 16:03:15 -070091 } else if (tag == TAG_DOWNLOADED) {
92 mAllApps.setAppFilter(ApplicationInfo.DOWNLOADED_FLAG);
93 }
94
95 final float alpha = mAllApps.getAlpha();
Chet Haase472b2812010-10-14 07:02:04 -070096 ObjectAnimator.ofFloat(mAllApps, "alpha", alpha, 1.0f).
97 setDuration(duration).start();
Winson Chung80baf5a2010-08-09 16:03:15 -070098 }
99 });
100 alphaAnim.start();
Patrick Dubroy3d605d52010-07-29 13:59:29 -0700101 }
102 });
Patrick Dubroy558654c2010-07-23 16:48:11 -0700103
Winson Chung321e9ee2010-08-09 13:37:56 -0700104 // It needs to be INVISIBLE so that it will be measured in the layout.
105 // Otherwise the animations is messed up when we show it for the first time.
106 setVisibility(INVISIBLE);
Patrick Dubroy558654c2010-07-23 16:48:11 -0700107 }
108
109 @Override
110 public void setLauncher(Launcher launcher) {
Winson Chung321e9ee2010-08-09 13:37:56 -0700111 mAllApps.setLauncher(launcher);
Patrick Dubroy558654c2010-07-23 16:48:11 -0700112 }
113
114 @Override
115 public void setDragController(DragController dragger) {
Winson Chung321e9ee2010-08-09 13:37:56 -0700116 mAllApps.setDragController(dragger);
Patrick Dubroy558654c2010-07-23 16:48:11 -0700117 }
118
119 @Override
120 public void zoom(float zoom, boolean animate) {
121 // NOTE: animate parameter is ignored for the TabHost itself
122 setVisibility((zoom == 0.0f) ? View.GONE : View.VISIBLE);
Winson Chung321e9ee2010-08-09 13:37:56 -0700123 mAllApps.zoom(zoom, animate);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -0700124 }
125
126 @Override
127 public void setVisibility(int visibility) {
Winson Chung80baf5a2010-08-09 16:03:15 -0700128 final boolean isVisible = (visibility == View.VISIBLE);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -0700129 super.setVisibility(visibility);
Winson Chung80baf5a2010-08-09 16:03:15 -0700130 float zoom = (isVisible ? 1.0f : 0.0f);
Winson Chung321e9ee2010-08-09 13:37:56 -0700131 mAllApps.zoom(zoom, false);
Patrick Dubroy558654c2010-07-23 16:48:11 -0700132 }
133
134 @Override
135 public boolean isVisible() {
Winson Chung321e9ee2010-08-09 13:37:56 -0700136 return mAllApps.isVisible();
Patrick Dubroy558654c2010-07-23 16:48:11 -0700137 }
138
139 @Override
Patrick Dubroyff5f0402010-07-26 15:23:26 -0700140 public boolean isAnimating() {
141 return (getAnimation() != null);
142 }
143
144 @Override
Patrick Dubroy558654c2010-07-23 16:48:11 -0700145 public void setApps(ArrayList<ApplicationInfo> list) {
Winson Chung321e9ee2010-08-09 13:37:56 -0700146 mAllApps.setApps(list);
Patrick Dubroy558654c2010-07-23 16:48:11 -0700147 }
148
149 @Override
150 public void addApps(ArrayList<ApplicationInfo> list) {
Winson Chung321e9ee2010-08-09 13:37:56 -0700151 mAllApps.addApps(list);
Patrick Dubroy558654c2010-07-23 16:48:11 -0700152 }
153
154 @Override
155 public void removeApps(ArrayList<ApplicationInfo> list) {
Winson Chung321e9ee2010-08-09 13:37:56 -0700156 mAllApps.removeApps(list);
Patrick Dubroy558654c2010-07-23 16:48:11 -0700157 }
158
159 @Override
160 public void updateApps(ArrayList<ApplicationInfo> list) {
Winson Chung321e9ee2010-08-09 13:37:56 -0700161 mAllApps.updateApps(list);
Patrick Dubroy558654c2010-07-23 16:48:11 -0700162 }
163
164 @Override
165 public void dumpState() {
Winson Chung321e9ee2010-08-09 13:37:56 -0700166 mAllApps.dumpState();
Patrick Dubroy558654c2010-07-23 16:48:11 -0700167 }
168
169 @Override
170 public void surrender() {
Winson Chung321e9ee2010-08-09 13:37:56 -0700171 mAllApps.surrender();
Patrick Dubroy558654c2010-07-23 16:48:11 -0700172 }
Adam Lesinski6b879f02010-11-04 16:15:23 -0700173
174 @Override
175 public boolean onTouchEvent(MotionEvent ev) {
176 if (ev.getY() > mAllApps.getBottom()) {
177 return false;
178 }
179 return true;
180 }
Patrick Dubroy558654c2010-07-23 16:48:11 -0700181}