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