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