blob: 4feb9984cfd5ddaf0d8f98466446f051bff1b26b [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
Winson Chung49767ae2010-11-29 14:48:30 -080019import java.util.ArrayList;
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;
Winson Chung49767ae2010-11-29 14:48:30 -080028import android.view.LayoutInflater;
Adam Lesinski6b879f02010-11-04 16:15:23 -070029import android.view.MotionEvent;
Patrick Dubroy558654c2010-07-23 16:48:11 -070030import android.view.View;
31import android.widget.TabHost;
Winson Chung49767ae2010-11-29 14:48:30 -080032import android.widget.TabWidget;
33import android.widget.TextView;
Patrick Dubroy558654c2010-07-23 16:48:11 -070034
Winson Chung49767ae2010-11-29 14:48:30 -080035import com.android.launcher.R;
Patrick Dubroy558654c2010-07-23 16:48:11 -070036
37/**
38 * Implements a tabbed version of AllApps2D.
39 */
40public class AllAppsTabbed extends TabHost implements AllAppsView {
41
42 private static final String TAG = "Launcher.AllAppsTabbed";
43
Patrick Dubroy3d605d52010-07-29 13:59:29 -070044 private static final String TAG_ALL = "ALL";
Patrick Dubroy3d605d52010-07-29 13:59:29 -070045 private static final String TAG_DOWNLOADED = "DOWNLOADED";
46
Winson Chung321e9ee2010-08-09 13:37:56 -070047 private AllAppsPagedView mAllApps;
Patrick Dubroy3d605d52010-07-29 13:59:29 -070048 private Context mContext;
Winson Chung49767ae2010-11-29 14:48:30 -080049 private final LayoutInflater mInflater;
Patrick Dubroy558654c2010-07-23 16:48:11 -070050
51 public AllAppsTabbed(Context context, AttributeSet attrs) {
52 super(context, attrs);
Patrick Dubroy3d605d52010-07-29 13:59:29 -070053 mContext = context;
Winson Chung49767ae2010-11-29 14:48:30 -080054 mInflater = LayoutInflater.from(context);
Patrick Dubroy558654c2010-07-23 16:48:11 -070055 }
56
57 @Override
58 protected void onFinishInflate() {
Winson Chung321e9ee2010-08-09 13:37:56 -070059 // setup the tab host
60 setup();
61
Patrick Dubroy558654c2010-07-23 16:48:11 -070062 try {
Winson Chung321e9ee2010-08-09 13:37:56 -070063 mAllApps = (AllAppsPagedView) findViewById(R.id.all_apps_paged_view);
64 if (mAllApps == null) throw new Resources.NotFoundException();
Patrick Dubroy558654c2010-07-23 16:48:11 -070065 } catch (Resources.NotFoundException e) {
66 Log.e(TAG, "Can't find necessary layout elements for AllAppsTabbed");
67 }
Patrick Dubroy558654c2010-07-23 16:48:11 -070068
Winson Chung321e9ee2010-08-09 13:37:56 -070069 // share the same AllApps workspace across all the tabs
Patrick Dubroy558654c2010-07-23 16:48:11 -070070 TabContentFactory contentFactory = new TabContentFactory() {
71 public View createTabContent(String tag) {
Winson Chung321e9ee2010-08-09 13:37:56 -070072 return mAllApps;
Patrick Dubroy558654c2010-07-23 16:48:11 -070073 }
74 };
75
Winson Chung49767ae2010-11-29 14:48:30 -080076 TextView tabView;
77 TabWidget tabWidget = (TabWidget) findViewById(com.android.internal.R.id.tabs);
78 tabView = (TextView) mInflater.inflate(R.layout.tab_widget_indicator, tabWidget, false);
79 tabView.setText(mContext.getString(R.string.all_apps_tab_all));
80 addTab(newTabSpec(TAG_ALL).setIndicator(tabView).setContent(contentFactory));
Patrick Dubroy3d605d52010-07-29 13:59:29 -070081
Winson Chung49767ae2010-11-29 14:48:30 -080082 tabView = (TextView) mInflater.inflate(R.layout.tab_widget_indicator, tabWidget, false);
83 tabView.setText(mContext.getString(R.string.all_apps_tab_downloaded));
84 addTab(newTabSpec(TAG_DOWNLOADED).setIndicator(tabView).setContent(contentFactory));
Patrick Dubroy3d605d52010-07-29 13:59:29 -070085
86 setOnTabChangedListener(new OnTabChangeListener() {
87 public void onTabChanged(String tabId) {
Winson Chung80baf5a2010-08-09 16:03:15 -070088 // animate the changing of the tab content by fading pages in and out
Winson Chungbbc60d82010-11-11 16:34:41 -080089 final Resources res = getResources();
90 final int duration = res.getInteger(R.integer.config_tabTransitionTime);
Winson Chung80baf5a2010-08-09 16:03:15 -070091 final float alpha = mAllApps.getAlpha();
Chet Haase472b2812010-10-14 07:02:04 -070092 ValueAnimator alphaAnim = ObjectAnimator.ofFloat(mAllApps, "alpha", alpha, 0.0f).
93 setDuration(duration);
Michael Jurka3c4c20f2010-10-28 15:36:06 -070094 alphaAnim.addListener(new LauncherAnimatorListenerAdapter() {
Gilles Debunnedd6c9922010-10-25 11:23:41 -070095 @Override
Michael Jurka3c4c20f2010-10-28 15:36:06 -070096 public void onAnimationEndOrCancel(Animator animation) {
Winson Chung80baf5a2010-08-09 16:03:15 -070097 String tag = getCurrentTabTag();
98 if (tag == TAG_ALL) {
99 mAllApps.setAppFilter(AllAppsPagedView.ALL_APPS_FLAG);
Winson Chung80baf5a2010-08-09 16:03:15 -0700100 } else if (tag == TAG_DOWNLOADED) {
101 mAllApps.setAppFilter(ApplicationInfo.DOWNLOADED_FLAG);
102 }
103
104 final float alpha = mAllApps.getAlpha();
Chet Haase472b2812010-10-14 07:02:04 -0700105 ObjectAnimator.ofFloat(mAllApps, "alpha", alpha, 1.0f).
106 setDuration(duration).start();
Winson Chung80baf5a2010-08-09 16:03:15 -0700107 }
108 });
109 alphaAnim.start();
Patrick Dubroy3d605d52010-07-29 13:59:29 -0700110 }
111 });
Patrick Dubroy558654c2010-07-23 16:48:11 -0700112
Winson Chung321e9ee2010-08-09 13:37:56 -0700113 // It needs to be INVISIBLE so that it will be measured in the layout.
114 // Otherwise the animations is messed up when we show it for the first time.
115 setVisibility(INVISIBLE);
Patrick Dubroy558654c2010-07-23 16:48:11 -0700116 }
117
118 @Override
119 public void setLauncher(Launcher launcher) {
Winson Chung321e9ee2010-08-09 13:37:56 -0700120 mAllApps.setLauncher(launcher);
Patrick Dubroy558654c2010-07-23 16:48:11 -0700121 }
122
123 @Override
124 public void setDragController(DragController dragger) {
Winson Chung321e9ee2010-08-09 13:37:56 -0700125 mAllApps.setDragController(dragger);
Patrick Dubroy558654c2010-07-23 16:48:11 -0700126 }
127
128 @Override
129 public void zoom(float zoom, boolean animate) {
130 // NOTE: animate parameter is ignored for the TabHost itself
131 setVisibility((zoom == 0.0f) ? View.GONE : View.VISIBLE);
Winson Chung321e9ee2010-08-09 13:37:56 -0700132 mAllApps.zoom(zoom, animate);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -0700133 }
134
135 @Override
136 public void setVisibility(int visibility) {
Winson Chung80baf5a2010-08-09 16:03:15 -0700137 final boolean isVisible = (visibility == View.VISIBLE);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -0700138 super.setVisibility(visibility);
Winson Chung80baf5a2010-08-09 16:03:15 -0700139 float zoom = (isVisible ? 1.0f : 0.0f);
Winson Chung321e9ee2010-08-09 13:37:56 -0700140 mAllApps.zoom(zoom, false);
Patrick Dubroy558654c2010-07-23 16:48:11 -0700141 }
142
143 @Override
144 public boolean isVisible() {
Winson Chung321e9ee2010-08-09 13:37:56 -0700145 return mAllApps.isVisible();
Patrick Dubroy558654c2010-07-23 16:48:11 -0700146 }
147
148 @Override
Patrick Dubroyff5f0402010-07-26 15:23:26 -0700149 public boolean isAnimating() {
150 return (getAnimation() != null);
151 }
152
153 @Override
Patrick Dubroy558654c2010-07-23 16:48:11 -0700154 public void setApps(ArrayList<ApplicationInfo> list) {
Winson Chung321e9ee2010-08-09 13:37:56 -0700155 mAllApps.setApps(list);
Patrick Dubroy558654c2010-07-23 16:48:11 -0700156 }
157
158 @Override
159 public void addApps(ArrayList<ApplicationInfo> list) {
Winson Chung321e9ee2010-08-09 13:37:56 -0700160 mAllApps.addApps(list);
Patrick Dubroy558654c2010-07-23 16:48:11 -0700161 }
162
163 @Override
164 public void removeApps(ArrayList<ApplicationInfo> list) {
Winson Chung321e9ee2010-08-09 13:37:56 -0700165 mAllApps.removeApps(list);
Patrick Dubroy558654c2010-07-23 16:48:11 -0700166 }
167
168 @Override
169 public void updateApps(ArrayList<ApplicationInfo> list) {
Winson Chung321e9ee2010-08-09 13:37:56 -0700170 mAllApps.updateApps(list);
Patrick Dubroy558654c2010-07-23 16:48:11 -0700171 }
172
173 @Override
174 public void dumpState() {
Winson Chung321e9ee2010-08-09 13:37:56 -0700175 mAllApps.dumpState();
Patrick Dubroy558654c2010-07-23 16:48:11 -0700176 }
177
178 @Override
179 public void surrender() {
Winson Chung321e9ee2010-08-09 13:37:56 -0700180 mAllApps.surrender();
Patrick Dubroy558654c2010-07-23 16:48:11 -0700181 }
Adam Lesinski6b879f02010-11-04 16:15:23 -0700182
183 @Override
184 public boolean onTouchEvent(MotionEvent ev) {
185 if (ev.getY() > mAllApps.getBottom()) {
186 return false;
187 }
188 return true;
189 }
Patrick Dubroy558654c2010-07-23 16:48:11 -0700190}