Patrick Dubroy | 558654c | 2010-07-23 16:48:11 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.launcher2; |
| 18 | |
Gilles Debunne | dd6c992 | 2010-10-25 11:23:41 -0700 | [diff] [blame] | 19 | import com.android.launcher.R; |
Patrick Dubroy | 558654c | 2010-07-23 16:48:11 -0700 | [diff] [blame] | 20 | |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 21 | import android.animation.Animator; |
Chet Haase | b1254a6 | 2010-09-07 13:35:00 -0700 | [diff] [blame] | 22 | import android.animation.ObjectAnimator; |
Gilles Debunne | dd6c992 | 2010-10-25 11:23:41 -0700 | [diff] [blame] | 23 | import android.animation.ValueAnimator; |
Patrick Dubroy | 558654c | 2010-07-23 16:48:11 -0700 | [diff] [blame] | 24 | import android.content.Context; |
| 25 | import android.content.res.Resources; |
| 26 | import android.util.AttributeSet; |
| 27 | import android.util.Log; |
| 28 | import android.view.View; |
| 29 | import android.widget.TabHost; |
| 30 | |
Gilles Debunne | dd6c992 | 2010-10-25 11:23:41 -0700 | [diff] [blame] | 31 | import java.util.ArrayList; |
Patrick Dubroy | 558654c | 2010-07-23 16:48:11 -0700 | [diff] [blame] | 32 | |
| 33 | /** |
| 34 | * Implements a tabbed version of AllApps2D. |
| 35 | */ |
| 36 | public class AllAppsTabbed extends TabHost implements AllAppsView { |
| 37 | |
| 38 | private static final String TAG = "Launcher.AllAppsTabbed"; |
| 39 | |
Patrick Dubroy | 3d605d5 | 2010-07-29 13:59:29 -0700 | [diff] [blame] | 40 | private static final String TAG_ALL = "ALL"; |
Patrick Dubroy | 3d605d5 | 2010-07-29 13:59:29 -0700 | [diff] [blame] | 41 | private static final String TAG_DOWNLOADED = "DOWNLOADED"; |
| 42 | |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 43 | private AllAppsPagedView mAllApps; |
Patrick Dubroy | 3d605d5 | 2010-07-29 13:59:29 -0700 | [diff] [blame] | 44 | private Context mContext; |
Patrick Dubroy | 558654c | 2010-07-23 16:48:11 -0700 | [diff] [blame] | 45 | |
| 46 | public AllAppsTabbed(Context context, AttributeSet attrs) { |
| 47 | super(context, attrs); |
Patrick Dubroy | 3d605d5 | 2010-07-29 13:59:29 -0700 | [diff] [blame] | 48 | mContext = context; |
Patrick Dubroy | 558654c | 2010-07-23 16:48:11 -0700 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | @Override |
| 52 | protected void onFinishInflate() { |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 53 | // setup the tab host |
| 54 | setup(); |
| 55 | |
Patrick Dubroy | 558654c | 2010-07-23 16:48:11 -0700 | [diff] [blame] | 56 | try { |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 57 | mAllApps = (AllAppsPagedView) findViewById(R.id.all_apps_paged_view); |
| 58 | if (mAllApps == null) throw new Resources.NotFoundException(); |
Patrick Dubroy | 558654c | 2010-07-23 16:48:11 -0700 | [diff] [blame] | 59 | } catch (Resources.NotFoundException e) { |
| 60 | Log.e(TAG, "Can't find necessary layout elements for AllAppsTabbed"); |
| 61 | } |
Patrick Dubroy | 558654c | 2010-07-23 16:48:11 -0700 | [diff] [blame] | 62 | |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 63 | // share the same AllApps workspace across all the tabs |
Patrick Dubroy | 558654c | 2010-07-23 16:48:11 -0700 | [diff] [blame] | 64 | TabContentFactory contentFactory = new TabContentFactory() { |
| 65 | public View createTabContent(String tag) { |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 66 | return mAllApps; |
Patrick Dubroy | 558654c | 2010-07-23 16:48:11 -0700 | [diff] [blame] | 67 | } |
| 68 | }; |
| 69 | |
Patrick Dubroy | 3d605d5 | 2010-07-29 13:59:29 -0700 | [diff] [blame] | 70 | String label = mContext.getString(R.string.all_apps_tab_all); |
| 71 | addTab(newTabSpec(TAG_ALL).setIndicator(label).setContent(contentFactory)); |
| 72 | |
Patrick Dubroy | 3d605d5 | 2010-07-29 13:59:29 -0700 | [diff] [blame] | 73 | 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 Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 78 | // animate the changing of the tab content by fading pages in and out |
Winson Chung | bbc60d8 | 2010-11-11 16:34:41 -0800 | [diff] [blame^] | 79 | final Resources res = getResources(); |
| 80 | final int duration = res.getInteger(R.integer.config_tabTransitionTime); |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 81 | final float alpha = mAllApps.getAlpha(); |
Chet Haase | 472b281 | 2010-10-14 07:02:04 -0700 | [diff] [blame] | 82 | ValueAnimator alphaAnim = ObjectAnimator.ofFloat(mAllApps, "alpha", alpha, 0.0f). |
| 83 | setDuration(duration); |
Michael Jurka | 3c4c20f | 2010-10-28 15:36:06 -0700 | [diff] [blame] | 84 | alphaAnim.addListener(new LauncherAnimatorListenerAdapter() { |
Gilles Debunne | dd6c992 | 2010-10-25 11:23:41 -0700 | [diff] [blame] | 85 | @Override |
Michael Jurka | 3c4c20f | 2010-10-28 15:36:06 -0700 | [diff] [blame] | 86 | public void onAnimationEndOrCancel(Animator animation) { |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 87 | String tag = getCurrentTabTag(); |
| 88 | if (tag == TAG_ALL) { |
| 89 | mAllApps.setAppFilter(AllAppsPagedView.ALL_APPS_FLAG); |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 90 | } else if (tag == TAG_DOWNLOADED) { |
| 91 | mAllApps.setAppFilter(ApplicationInfo.DOWNLOADED_FLAG); |
| 92 | } |
| 93 | |
| 94 | final float alpha = mAllApps.getAlpha(); |
Chet Haase | 472b281 | 2010-10-14 07:02:04 -0700 | [diff] [blame] | 95 | ObjectAnimator.ofFloat(mAllApps, "alpha", alpha, 1.0f). |
| 96 | setDuration(duration).start(); |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 97 | } |
| 98 | }); |
| 99 | alphaAnim.start(); |
Patrick Dubroy | 3d605d5 | 2010-07-29 13:59:29 -0700 | [diff] [blame] | 100 | } |
| 101 | }); |
Patrick Dubroy | 558654c | 2010-07-23 16:48:11 -0700 | [diff] [blame] | 102 | |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 103 | // 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 Dubroy | 558654c | 2010-07-23 16:48:11 -0700 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | @Override |
| 109 | public void setLauncher(Launcher launcher) { |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 110 | mAllApps.setLauncher(launcher); |
Patrick Dubroy | 558654c | 2010-07-23 16:48:11 -0700 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | @Override |
| 114 | public void setDragController(DragController dragger) { |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 115 | mAllApps.setDragController(dragger); |
Patrick Dubroy | 558654c | 2010-07-23 16:48:11 -0700 | [diff] [blame] | 116 | } |
| 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 Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 122 | mAllApps.zoom(zoom, animate); |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 123 | } |
| 124 | |
| 125 | @Override |
| 126 | public void setVisibility(int visibility) { |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 127 | final boolean isVisible = (visibility == View.VISIBLE); |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 128 | super.setVisibility(visibility); |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 129 | float zoom = (isVisible ? 1.0f : 0.0f); |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 130 | mAllApps.zoom(zoom, false); |
Patrick Dubroy | 558654c | 2010-07-23 16:48:11 -0700 | [diff] [blame] | 131 | } |
| 132 | |
| 133 | @Override |
| 134 | public boolean isVisible() { |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 135 | return mAllApps.isVisible(); |
Patrick Dubroy | 558654c | 2010-07-23 16:48:11 -0700 | [diff] [blame] | 136 | } |
| 137 | |
| 138 | @Override |
Patrick Dubroy | ff5f040 | 2010-07-26 15:23:26 -0700 | [diff] [blame] | 139 | public boolean isAnimating() { |
| 140 | return (getAnimation() != null); |
| 141 | } |
| 142 | |
| 143 | @Override |
Patrick Dubroy | 558654c | 2010-07-23 16:48:11 -0700 | [diff] [blame] | 144 | public void setApps(ArrayList<ApplicationInfo> list) { |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 145 | mAllApps.setApps(list); |
Patrick Dubroy | 558654c | 2010-07-23 16:48:11 -0700 | [diff] [blame] | 146 | } |
| 147 | |
| 148 | @Override |
| 149 | public void addApps(ArrayList<ApplicationInfo> list) { |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 150 | mAllApps.addApps(list); |
Patrick Dubroy | 558654c | 2010-07-23 16:48:11 -0700 | [diff] [blame] | 151 | } |
| 152 | |
| 153 | @Override |
| 154 | public void removeApps(ArrayList<ApplicationInfo> list) { |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 155 | mAllApps.removeApps(list); |
Patrick Dubroy | 558654c | 2010-07-23 16:48:11 -0700 | [diff] [blame] | 156 | } |
| 157 | |
| 158 | @Override |
| 159 | public void updateApps(ArrayList<ApplicationInfo> list) { |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 160 | mAllApps.updateApps(list); |
Patrick Dubroy | 558654c | 2010-07-23 16:48:11 -0700 | [diff] [blame] | 161 | } |
| 162 | |
| 163 | @Override |
| 164 | public void dumpState() { |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 165 | mAllApps.dumpState(); |
Patrick Dubroy | 558654c | 2010-07-23 16:48:11 -0700 | [diff] [blame] | 166 | } |
| 167 | |
| 168 | @Override |
| 169 | public void surrender() { |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 170 | mAllApps.surrender(); |
Patrick Dubroy | 558654c | 2010-07-23 16:48:11 -0700 | [diff] [blame] | 171 | } |
Patrick Dubroy | 558654c | 2010-07-23 16:48:11 -0700 | [diff] [blame] | 172 | } |