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 | |
| 19 | import com.android.launcher.R; |
| 20 | |
| 21 | import android.content.Context; |
| 22 | import android.content.res.Resources; |
| 23 | import android.util.AttributeSet; |
| 24 | import android.util.Log; |
| 25 | import android.view.View; |
| 26 | import android.widget.TabHost; |
| 27 | |
| 28 | import java.util.ArrayList; |
| 29 | |
| 30 | /** |
| 31 | * Implements a tabbed version of AllApps2D. |
| 32 | */ |
| 33 | public class AllAppsTabbed extends TabHost implements AllAppsView { |
| 34 | |
| 35 | private static final String TAG = "Launcher.AllAppsTabbed"; |
| 36 | |
| 37 | private AllAppsView mAllApps2D; |
| 38 | |
| 39 | public AllAppsTabbed(Context context, AttributeSet attrs) { |
| 40 | super(context, attrs); |
| 41 | } |
| 42 | |
| 43 | @Override |
| 44 | protected void onFinishInflate() { |
| 45 | try { |
| 46 | mAllApps2D = (AllAppsView)findViewById(R.id.all_apps_2d); |
| 47 | if (mAllApps2D == null) throw new Resources.NotFoundException(); |
| 48 | } catch (Resources.NotFoundException e) { |
| 49 | Log.e(TAG, "Can't find necessary layout elements for AllAppsTabbed"); |
| 50 | } |
| 51 | setup(); |
| 52 | |
| 53 | // This lets us share the same view between all tabs |
| 54 | TabContentFactory contentFactory = new TabContentFactory() { |
| 55 | public View createTabContent(String tag) { |
| 56 | return (View)mAllApps2D; |
| 57 | } |
| 58 | }; |
| 59 | |
| 60 | // TODO: Make these tabs show the appropriate content (they're no-ops for now) |
| 61 | addTab(newTabSpec("apps").setIndicator("All").setContent(contentFactory)); |
| 62 | addTab(newTabSpec("apps").setIndicator("Apps").setContent(contentFactory)); |
| 63 | addTab(newTabSpec("apps").setIndicator("Games").setContent(contentFactory)); |
| 64 | addTab(newTabSpec("apps").setIndicator("Downloaded").setContent(contentFactory)); |
| 65 | |
| 66 | setCurrentTab(0); |
| 67 | setVisibility(GONE); |
| 68 | } |
| 69 | |
| 70 | @Override |
| 71 | public void setLauncher(Launcher launcher) { |
| 72 | mAllApps2D.setLauncher(launcher); |
| 73 | } |
| 74 | |
| 75 | @Override |
| 76 | public void setDragController(DragController dragger) { |
| 77 | mAllApps2D.setDragController(dragger); |
| 78 | } |
| 79 | |
| 80 | @Override |
| 81 | public void zoom(float zoom, boolean animate) { |
| 82 | // NOTE: animate parameter is ignored for the TabHost itself |
| 83 | setVisibility((zoom == 0.0f) ? View.GONE : View.VISIBLE); |
| 84 | mAllApps2D.zoom(zoom, animate); |
| 85 | bringChildToFront((View)mAllApps2D); |
| 86 | getParent().bringChildToFront(this); |
| 87 | } |
| 88 | |
| 89 | @Override |
| 90 | public boolean isVisible() { |
| 91 | return mAllApps2D.isVisible(); |
| 92 | } |
| 93 | |
| 94 | @Override |
| 95 | public void setApps(ArrayList<ApplicationInfo> list) { |
| 96 | mAllApps2D.setApps(list); |
| 97 | } |
| 98 | |
| 99 | @Override |
| 100 | public void addApps(ArrayList<ApplicationInfo> list) { |
| 101 | mAllApps2D.addApps(list); |
| 102 | } |
| 103 | |
| 104 | @Override |
| 105 | public void removeApps(ArrayList<ApplicationInfo> list) { |
| 106 | mAllApps2D.removeApps(list); |
| 107 | } |
| 108 | |
| 109 | @Override |
| 110 | public void updateApps(ArrayList<ApplicationInfo> list) { |
| 111 | mAllApps2D.updateApps(list); |
| 112 | } |
| 113 | |
| 114 | @Override |
| 115 | public void dumpState() { |
| 116 | mAllApps2D.dumpState(); |
| 117 | } |
| 118 | |
| 119 | @Override |
| 120 | public void surrender() { |
| 121 | mAllApps2D.surrender(); |
| 122 | } |
| 123 | |
| 124 | } |