blob: e0ff1a8548be0b9f573f3c28a63b76005751709a [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
79 final int duration = 150;
80 final float alpha = mAllApps.getAlpha();
Chet Haase472b2812010-10-14 07:02:04 -070081 ValueAnimator alphaAnim = ObjectAnimator.ofFloat(mAllApps, "alpha", alpha, 0.0f).
82 setDuration(duration);
Michael Jurka3c4c20f2010-10-28 15:36:06 -070083 alphaAnim.addListener(new LauncherAnimatorListenerAdapter() {
Gilles Debunnedd6c9922010-10-25 11:23:41 -070084 @Override
Michael Jurka3c4c20f2010-10-28 15:36:06 -070085 public void onAnimationEndOrCancel(Animator animation) {
Winson Chung80baf5a2010-08-09 16:03:15 -070086 String tag = getCurrentTabTag();
87 if (tag == TAG_ALL) {
88 mAllApps.setAppFilter(AllAppsPagedView.ALL_APPS_FLAG);
Winson Chung80baf5a2010-08-09 16:03:15 -070089 } else if (tag == TAG_DOWNLOADED) {
90 mAllApps.setAppFilter(ApplicationInfo.DOWNLOADED_FLAG);
91 }
92
93 final float alpha = mAllApps.getAlpha();
Chet Haase472b2812010-10-14 07:02:04 -070094 ObjectAnimator.ofFloat(mAllApps, "alpha", alpha, 1.0f).
95 setDuration(duration).start();
Winson Chung80baf5a2010-08-09 16:03:15 -070096 }
97 });
98 alphaAnim.start();
Patrick Dubroy3d605d52010-07-29 13:59:29 -070099 }
100 });
Patrick Dubroy558654c2010-07-23 16:48:11 -0700101
Winson Chung321e9ee2010-08-09 13:37:56 -0700102 // It needs to be INVISIBLE so that it will be measured in the layout.
103 // Otherwise the animations is messed up when we show it for the first time.
104 setVisibility(INVISIBLE);
Patrick Dubroy558654c2010-07-23 16:48:11 -0700105 }
106
107 @Override
108 public void setLauncher(Launcher launcher) {
Winson Chung321e9ee2010-08-09 13:37:56 -0700109 mAllApps.setLauncher(launcher);
Patrick Dubroy558654c2010-07-23 16:48:11 -0700110 }
111
112 @Override
113 public void setDragController(DragController dragger) {
Winson Chung321e9ee2010-08-09 13:37:56 -0700114 mAllApps.setDragController(dragger);
Patrick Dubroy558654c2010-07-23 16:48:11 -0700115 }
116
117 @Override
118 public void zoom(float zoom, boolean animate) {
119 // NOTE: animate parameter is ignored for the TabHost itself
120 setVisibility((zoom == 0.0f) ? View.GONE : View.VISIBLE);
Winson Chung321e9ee2010-08-09 13:37:56 -0700121 mAllApps.zoom(zoom, animate);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -0700122 }
123
124 @Override
125 public void setVisibility(int visibility) {
Winson Chung80baf5a2010-08-09 16:03:15 -0700126 final boolean isVisible = (visibility == View.VISIBLE);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -0700127 super.setVisibility(visibility);
Winson Chung80baf5a2010-08-09 16:03:15 -0700128 float zoom = (isVisible ? 1.0f : 0.0f);
Winson Chung321e9ee2010-08-09 13:37:56 -0700129 mAllApps.zoom(zoom, false);
Patrick Dubroy558654c2010-07-23 16:48:11 -0700130 }
131
132 @Override
133 public boolean isVisible() {
Winson Chung321e9ee2010-08-09 13:37:56 -0700134 return mAllApps.isVisible();
Patrick Dubroy558654c2010-07-23 16:48:11 -0700135 }
136
137 @Override
Patrick Dubroyff5f0402010-07-26 15:23:26 -0700138 public boolean isAnimating() {
139 return (getAnimation() != null);
140 }
141
142 @Override
Patrick Dubroy558654c2010-07-23 16:48:11 -0700143 public void setApps(ArrayList<ApplicationInfo> list) {
Winson Chung321e9ee2010-08-09 13:37:56 -0700144 mAllApps.setApps(list);
Patrick Dubroy558654c2010-07-23 16:48:11 -0700145 }
146
147 @Override
148 public void addApps(ArrayList<ApplicationInfo> list) {
Winson Chung321e9ee2010-08-09 13:37:56 -0700149 mAllApps.addApps(list);
Patrick Dubroy558654c2010-07-23 16:48:11 -0700150 }
151
152 @Override
153 public void removeApps(ArrayList<ApplicationInfo> list) {
Winson Chung321e9ee2010-08-09 13:37:56 -0700154 mAllApps.removeApps(list);
Patrick Dubroy558654c2010-07-23 16:48:11 -0700155 }
156
157 @Override
158 public void updateApps(ArrayList<ApplicationInfo> list) {
Winson Chung321e9ee2010-08-09 13:37:56 -0700159 mAllApps.updateApps(list);
Patrick Dubroy558654c2010-07-23 16:48:11 -0700160 }
161
162 @Override
163 public void dumpState() {
Winson Chung321e9ee2010-08-09 13:37:56 -0700164 mAllApps.dumpState();
Patrick Dubroy558654c2010-07-23 16:48:11 -0700165 }
166
167 @Override
168 public void surrender() {
Winson Chung321e9ee2010-08-09 13:37:56 -0700169 mAllApps.surrender();
Patrick Dubroy558654c2010-07-23 16:48:11 -0700170 }
Patrick Dubroy558654c2010-07-23 16:48:11 -0700171}