blob: a6e21b9d78dd7e400c506becce1b49d8cf39daf6 [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;
28import android.view.View;
29import android.widget.TabHost;
30
Gilles Debunnedd6c9922010-10-25 11:23:41 -070031import java.util.ArrayList;
Patrick Dubroy558654c2010-07-23 16:48:11 -070032
33/**
34 * Implements a tabbed version of AllApps2D.
35 */
36public class AllAppsTabbed extends TabHost implements AllAppsView {
37
38 private static final String TAG = "Launcher.AllAppsTabbed";
39
Patrick Dubroy3d605d52010-07-29 13:59:29 -070040 private static final String TAG_ALL = "ALL";
Patrick Dubroy3d605d52010-07-29 13:59:29 -070041 private static final String TAG_DOWNLOADED = "DOWNLOADED";
42
Winson Chung321e9ee2010-08-09 13:37:56 -070043 private AllAppsPagedView mAllApps;
Patrick Dubroy3d605d52010-07-29 13:59:29 -070044 private Context mContext;
Patrick Dubroy558654c2010-07-23 16:48:11 -070045
46 public AllAppsTabbed(Context context, AttributeSet attrs) {
47 super(context, attrs);
Patrick Dubroy3d605d52010-07-29 13:59:29 -070048 mContext = context;
Patrick Dubroy558654c2010-07-23 16:48:11 -070049 }
50
51 @Override
52 protected void onFinishInflate() {
Winson Chung321e9ee2010-08-09 13:37:56 -070053 // setup the tab host
54 setup();
55
Patrick Dubroy558654c2010-07-23 16:48:11 -070056 try {
Winson Chung321e9ee2010-08-09 13:37:56 -070057 mAllApps = (AllAppsPagedView) findViewById(R.id.all_apps_paged_view);
58 if (mAllApps == null) throw new Resources.NotFoundException();
Patrick Dubroy558654c2010-07-23 16:48:11 -070059 } catch (Resources.NotFoundException e) {
60 Log.e(TAG, "Can't find necessary layout elements for AllAppsTabbed");
61 }
Patrick Dubroy558654c2010-07-23 16:48:11 -070062
Winson Chung321e9ee2010-08-09 13:37:56 -070063 // share the same AllApps workspace across all the tabs
Patrick Dubroy558654c2010-07-23 16:48:11 -070064 TabContentFactory contentFactory = new TabContentFactory() {
65 public View createTabContent(String tag) {
Winson Chung321e9ee2010-08-09 13:37:56 -070066 return mAllApps;
Patrick Dubroy558654c2010-07-23 16:48:11 -070067 }
68 };
69
Patrick Dubroy3d605d52010-07-29 13:59:29 -070070 String label = mContext.getString(R.string.all_apps_tab_all);
71 addTab(newTabSpec(TAG_ALL).setIndicator(label).setContent(contentFactory));
72
Patrick Dubroy3d605d52010-07-29 13:59:29 -070073 label = mContext.getString(R.string.all_apps_tab_downloaded);
74 addTab(newTabSpec(TAG_DOWNLOADED).setIndicator(label).setContent(contentFactory));
75
76 setOnTabChangedListener(new OnTabChangeListener() {
77 public void onTabChanged(String tabId) {
Winson Chung80baf5a2010-08-09 16:03:15 -070078 // animate the changing of the tab content by fading pages in and out
Winson Chungbbc60d82010-11-11 16:34:41 -080079 final Resources res = getResources();
80 final int duration = res.getInteger(R.integer.config_tabTransitionTime);
Winson Chung80baf5a2010-08-09 16:03:15 -070081 final float alpha = mAllApps.getAlpha();
Chet Haase472b2812010-10-14 07:02:04 -070082 ValueAnimator alphaAnim = ObjectAnimator.ofFloat(mAllApps, "alpha", alpha, 0.0f).
83 setDuration(duration);
Michael Jurka3c4c20f2010-10-28 15:36:06 -070084 alphaAnim.addListener(new LauncherAnimatorListenerAdapter() {
Gilles Debunnedd6c9922010-10-25 11:23:41 -070085 @Override
Michael Jurka3c4c20f2010-10-28 15:36:06 -070086 public void onAnimationEndOrCancel(Animator animation) {
Winson Chung80baf5a2010-08-09 16:03:15 -070087 String tag = getCurrentTabTag();
88 if (tag == TAG_ALL) {
89 mAllApps.setAppFilter(AllAppsPagedView.ALL_APPS_FLAG);
Winson Chung80baf5a2010-08-09 16:03:15 -070090 } else if (tag == TAG_DOWNLOADED) {
91 mAllApps.setAppFilter(ApplicationInfo.DOWNLOADED_FLAG);
92 }
93
94 final float alpha = mAllApps.getAlpha();
Chet Haase472b2812010-10-14 07:02:04 -070095 ObjectAnimator.ofFloat(mAllApps, "alpha", alpha, 1.0f).
96 setDuration(duration).start();
Winson Chung80baf5a2010-08-09 16:03:15 -070097 }
98 });
99 alphaAnim.start();
Patrick Dubroy3d605d52010-07-29 13:59:29 -0700100 }
101 });
Patrick Dubroy558654c2010-07-23 16:48:11 -0700102
Winson Chung321e9ee2010-08-09 13:37:56 -0700103 // It needs to be INVISIBLE so that it will be measured in the layout.
104 // Otherwise the animations is messed up when we show it for the first time.
105 setVisibility(INVISIBLE);
Patrick Dubroy558654c2010-07-23 16:48:11 -0700106 }
107
108 @Override
109 public void setLauncher(Launcher launcher) {
Winson Chung321e9ee2010-08-09 13:37:56 -0700110 mAllApps.setLauncher(launcher);
Patrick Dubroy558654c2010-07-23 16:48:11 -0700111 }
112
113 @Override
114 public void setDragController(DragController dragger) {
Winson Chung321e9ee2010-08-09 13:37:56 -0700115 mAllApps.setDragController(dragger);
Patrick Dubroy558654c2010-07-23 16:48:11 -0700116 }
117
118 @Override
119 public void zoom(float zoom, boolean animate) {
120 // NOTE: animate parameter is ignored for the TabHost itself
121 setVisibility((zoom == 0.0f) ? View.GONE : View.VISIBLE);
Winson Chung321e9ee2010-08-09 13:37:56 -0700122 mAllApps.zoom(zoom, animate);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -0700123 }
124
125 @Override
126 public void setVisibility(int visibility) {
Winson Chung80baf5a2010-08-09 16:03:15 -0700127 final boolean isVisible = (visibility == View.VISIBLE);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -0700128 super.setVisibility(visibility);
Winson Chung80baf5a2010-08-09 16:03:15 -0700129 float zoom = (isVisible ? 1.0f : 0.0f);
Winson Chung321e9ee2010-08-09 13:37:56 -0700130 mAllApps.zoom(zoom, false);
Patrick Dubroy558654c2010-07-23 16:48:11 -0700131 }
132
133 @Override
134 public boolean isVisible() {
Winson Chung321e9ee2010-08-09 13:37:56 -0700135 return mAllApps.isVisible();
Patrick Dubroy558654c2010-07-23 16:48:11 -0700136 }
137
138 @Override
Patrick Dubroyff5f0402010-07-26 15:23:26 -0700139 public boolean isAnimating() {
140 return (getAnimation() != null);
141 }
142
143 @Override
Patrick Dubroy558654c2010-07-23 16:48:11 -0700144 public void setApps(ArrayList<ApplicationInfo> list) {
Winson Chung321e9ee2010-08-09 13:37:56 -0700145 mAllApps.setApps(list);
Patrick Dubroy558654c2010-07-23 16:48:11 -0700146 }
147
148 @Override
149 public void addApps(ArrayList<ApplicationInfo> list) {
Winson Chung321e9ee2010-08-09 13:37:56 -0700150 mAllApps.addApps(list);
Patrick Dubroy558654c2010-07-23 16:48:11 -0700151 }
152
153 @Override
154 public void removeApps(ArrayList<ApplicationInfo> list) {
Winson Chung321e9ee2010-08-09 13:37:56 -0700155 mAllApps.removeApps(list);
Patrick Dubroy558654c2010-07-23 16:48:11 -0700156 }
157
158 @Override
159 public void updateApps(ArrayList<ApplicationInfo> list) {
Winson Chung321e9ee2010-08-09 13:37:56 -0700160 mAllApps.updateApps(list);
Patrick Dubroy558654c2010-07-23 16:48:11 -0700161 }
162
163 @Override
164 public void dumpState() {
Winson Chung321e9ee2010-08-09 13:37:56 -0700165 mAllApps.dumpState();
Patrick Dubroy558654c2010-07-23 16:48:11 -0700166 }
167
168 @Override
169 public void surrender() {
Winson Chung321e9ee2010-08-09 13:37:56 -0700170 mAllApps.surrender();
Patrick Dubroy558654c2010-07-23 16:48:11 -0700171 }
Patrick Dubroy558654c2010-07-23 16:48:11 -0700172}