blob: 47a5bf7fc9d3b62f3e3c3ae19ea924c90f3b4039 [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
Michael Jurka8edd75c2010-12-17 20:15:06 -080019import com.android.launcher.R;
Patrick Dubroy558654c2010-07-23 16:48:11 -070020
Winson Chung80baf5a2010-08-09 16:03:15 -070021import android.animation.Animator;
Michael Jurka8edd75c2010-12-17 20:15:06 -080022import 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;
Winson Chung49767ae2010-11-29 14:48:30 -080029import android.view.LayoutInflater;
Adam Lesinski6b879f02010-11-04 16:15:23 -070030import android.view.MotionEvent;
Patrick Dubroy558654c2010-07-23 16:48:11 -070031import android.view.View;
32import android.widget.TabHost;
Winson Chung49767ae2010-11-29 14:48:30 -080033import android.widget.TabWidget;
34import android.widget.TextView;
Patrick Dubroy558654c2010-07-23 16:48:11 -070035
Michael Jurka8edd75c2010-12-17 20:15:06 -080036import java.util.ArrayList;
Patrick Dubroy558654c2010-07-23 16:48:11 -070037
38/**
39 * Implements a tabbed version of AllApps2D.
40 */
41public class AllAppsTabbed extends TabHost implements AllAppsView {
42
43 private static final String TAG = "Launcher.AllAppsTabbed";
44
Patrick Dubroy3d605d52010-07-29 13:59:29 -070045 private static final String TAG_ALL = "ALL";
Patrick Dubroy3d605d52010-07-29 13:59:29 -070046 private static final String TAG_DOWNLOADED = "DOWNLOADED";
47
Winson Chung321e9ee2010-08-09 13:37:56 -070048 private AllAppsPagedView mAllApps;
Patrick Dubroy3d605d52010-07-29 13:59:29 -070049 private Context mContext;
Winson Chung49767ae2010-11-29 14:48:30 -080050 private final LayoutInflater mInflater;
Michael Jurka6c7a03a2011-01-16 18:43:58 -080051 private boolean mFirstLayout = true;
Patrick Dubroy558654c2010-07-23 16:48:11 -070052
53 public AllAppsTabbed(Context context, AttributeSet attrs) {
54 super(context, attrs);
Patrick Dubroy3d605d52010-07-29 13:59:29 -070055 mContext = context;
Winson Chung49767ae2010-11-29 14:48:30 -080056 mInflater = LayoutInflater.from(context);
Patrick Dubroy558654c2010-07-23 16:48:11 -070057 }
58
59 @Override
60 protected void onFinishInflate() {
Winson Chung321e9ee2010-08-09 13:37:56 -070061 // setup the tab host
62 setup();
63
Patrick Dubroy558654c2010-07-23 16:48:11 -070064 try {
Winson Chung321e9ee2010-08-09 13:37:56 -070065 mAllApps = (AllAppsPagedView) findViewById(R.id.all_apps_paged_view);
66 if (mAllApps == null) throw new Resources.NotFoundException();
Patrick Dubroy558654c2010-07-23 16:48:11 -070067 } catch (Resources.NotFoundException e) {
68 Log.e(TAG, "Can't find necessary layout elements for AllAppsTabbed");
69 }
Patrick Dubroy558654c2010-07-23 16:48:11 -070070
Winson Chung321e9ee2010-08-09 13:37:56 -070071 // share the same AllApps workspace across all the tabs
Patrick Dubroy558654c2010-07-23 16:48:11 -070072 TabContentFactory contentFactory = new TabContentFactory() {
73 public View createTabContent(String tag) {
Winson Chung321e9ee2010-08-09 13:37:56 -070074 return mAllApps;
Patrick Dubroy558654c2010-07-23 16:48:11 -070075 }
76 };
77
Winson Chung49767ae2010-11-29 14:48:30 -080078 TextView tabView;
79 TabWidget tabWidget = (TabWidget) findViewById(com.android.internal.R.id.tabs);
80 tabView = (TextView) mInflater.inflate(R.layout.tab_widget_indicator, tabWidget, false);
81 tabView.setText(mContext.getString(R.string.all_apps_tab_all));
82 addTab(newTabSpec(TAG_ALL).setIndicator(tabView).setContent(contentFactory));
Patrick Dubroy3d605d52010-07-29 13:59:29 -070083
Winson Chung49767ae2010-11-29 14:48:30 -080084 tabView = (TextView) mInflater.inflate(R.layout.tab_widget_indicator, tabWidget, false);
85 tabView.setText(mContext.getString(R.string.all_apps_tab_downloaded));
86 addTab(newTabSpec(TAG_DOWNLOADED).setIndicator(tabView).setContent(contentFactory));
Patrick Dubroy3d605d52010-07-29 13:59:29 -070087
88 setOnTabChangedListener(new OnTabChangeListener() {
89 public void onTabChanged(String tabId) {
Winson Chung80baf5a2010-08-09 16:03:15 -070090 // animate the changing of the tab content by fading pages in and out
Winson Chungbbc60d82010-11-11 16:34:41 -080091 final Resources res = getResources();
92 final int duration = res.getInteger(R.integer.config_tabTransitionTime);
Winson Chung80baf5a2010-08-09 16:03:15 -070093 final float alpha = mAllApps.getAlpha();
Chet Haase472b2812010-10-14 07:02:04 -070094 ValueAnimator alphaAnim = ObjectAnimator.ofFloat(mAllApps, "alpha", alpha, 0.0f).
95 setDuration(duration);
Michael Jurka8edd75c2010-12-17 20:15:06 -080096 alphaAnim.addListener(new AnimatorListenerAdapter() {
Gilles Debunnedd6c9922010-10-25 11:23:41 -070097 @Override
Michael Jurka8edd75c2010-12-17 20:15:06 -080098 public void onAnimationEnd(Animator animation) {
Winson Chung80baf5a2010-08-09 16:03:15 -070099 String tag = getCurrentTabTag();
100 if (tag == TAG_ALL) {
101 mAllApps.setAppFilter(AllAppsPagedView.ALL_APPS_FLAG);
Winson Chung80baf5a2010-08-09 16:03:15 -0700102 } 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) {
Michael Jurka6c7a03a2011-01-16 18:43:58 -0800139 if (visibility == View.GONE && mFirstLayout) {
140 // It needs to be INVISIBLE so that it will be measured in the layout.
141 // Otherwise the animations is messed up when we show it for the first time.
142 visibility = View.INVISIBLE;
143 }
Winson Chung80baf5a2010-08-09 16:03:15 -0700144 final boolean isVisible = (visibility == View.VISIBLE);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -0700145 super.setVisibility(visibility);
Winson Chung80baf5a2010-08-09 16:03:15 -0700146 float zoom = (isVisible ? 1.0f : 0.0f);
Winson Chung321e9ee2010-08-09 13:37:56 -0700147 mAllApps.zoom(zoom, false);
Patrick Dubroy558654c2010-07-23 16:48:11 -0700148 }
149
150 @Override
151 public boolean isVisible() {
Winson Chung321e9ee2010-08-09 13:37:56 -0700152 return mAllApps.isVisible();
Patrick Dubroy558654c2010-07-23 16:48:11 -0700153 }
154
155 @Override
Michael Jurka6c7a03a2011-01-16 18:43:58 -0800156 protected void onLayout(boolean changed, int l, int t, int r, int b) {
157 mFirstLayout = false;
158 super.onLayout(changed, l, t, r, b);
159 }
160
161 @Override
Patrick Dubroyff5f0402010-07-26 15:23:26 -0700162 public boolean isAnimating() {
163 return (getAnimation() != null);
164 }
165
166 @Override
Patrick Dubroy558654c2010-07-23 16:48:11 -0700167 public void setApps(ArrayList<ApplicationInfo> list) {
Winson Chung321e9ee2010-08-09 13:37:56 -0700168 mAllApps.setApps(list);
Patrick Dubroy558654c2010-07-23 16:48:11 -0700169 }
170
171 @Override
172 public void addApps(ArrayList<ApplicationInfo> list) {
Winson Chung321e9ee2010-08-09 13:37:56 -0700173 mAllApps.addApps(list);
Patrick Dubroy558654c2010-07-23 16:48:11 -0700174 }
175
176 @Override
177 public void removeApps(ArrayList<ApplicationInfo> list) {
Winson Chung321e9ee2010-08-09 13:37:56 -0700178 mAllApps.removeApps(list);
Patrick Dubroy558654c2010-07-23 16:48:11 -0700179 }
180
181 @Override
182 public void updateApps(ArrayList<ApplicationInfo> list) {
Winson Chung321e9ee2010-08-09 13:37:56 -0700183 mAllApps.updateApps(list);
Patrick Dubroy558654c2010-07-23 16:48:11 -0700184 }
185
186 @Override
187 public void dumpState() {
Winson Chung321e9ee2010-08-09 13:37:56 -0700188 mAllApps.dumpState();
Patrick Dubroy558654c2010-07-23 16:48:11 -0700189 }
190
191 @Override
192 public void surrender() {
Winson Chung321e9ee2010-08-09 13:37:56 -0700193 mAllApps.surrender();
Patrick Dubroy558654c2010-07-23 16:48:11 -0700194 }
Adam Lesinski6b879f02010-11-04 16:15:23 -0700195
196 @Override
197 public boolean onTouchEvent(MotionEvent ev) {
198 if (ev.getY() > mAllApps.getBottom()) {
199 return false;
200 }
201 return true;
202 }
Patrick Dubroy558654c2010-07-23 16:48:11 -0700203}