Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 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 android.content.Context; |
| 20 | import android.content.res.Resources; |
| 21 | import android.util.AttributeSet; |
| 22 | import android.view.LayoutInflater; |
| 23 | import android.view.View; |
| 24 | import android.view.ViewGroup; |
| 25 | import android.widget.TabHost; |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 26 | import android.widget.TextView; |
| 27 | |
| 28 | import com.android.launcher.R; |
| 29 | |
| 30 | public class AppsCustomizeTabHost extends TabHost implements LauncherTransitionable, |
| 31 | TabHost.OnTabChangeListener { |
| 32 | static final String LOG_TAG = "AppsCustomizeTabHost"; |
| 33 | |
| 34 | private static final String APPS_TAB_TAG = "APPS"; |
| 35 | private static final String WIDGETS_TAB_TAG = "WIDGETS"; |
| 36 | |
| 37 | private final LayoutInflater mLayoutInflater; |
| 38 | |
| 39 | public AppsCustomizeTabHost(Context context, AttributeSet attrs) { |
| 40 | super(context, attrs); |
| 41 | mLayoutInflater = LayoutInflater.from(context); |
| 42 | } |
| 43 | |
| 44 | /** |
| 45 | * Setup the tab host and create all necessary tabs. |
| 46 | */ |
| 47 | @Override |
| 48 | protected void onFinishInflate() { |
| 49 | // Setup the tab host |
| 50 | setup(); |
| 51 | |
| 52 | final ViewGroup tabs = (ViewGroup) findViewById(com.android.internal.R.id.tabs); |
| 53 | final AppsCustomizePagedView content = (AppsCustomizePagedView) |
| 54 | findViewById(R.id.apps_customize_pane_content); |
| 55 | if (tabs == null || content == null) throw new Resources.NotFoundException(); |
| 56 | |
| 57 | // Configure the tabs content factory to return the same paged view (that we change the |
| 58 | // content filter on) |
| 59 | TabContentFactory contentFactory = new TabContentFactory() { |
| 60 | public View createTabContent(String tag) { |
| 61 | return content; |
| 62 | } |
| 63 | }; |
| 64 | |
| 65 | // Create the tabs |
| 66 | TextView tabView; |
| 67 | tabView = (TextView) mLayoutInflater.inflate(R.layout.tab_widget_indicator, tabs, false); |
| 68 | tabView.setText(mContext.getString(R.string.all_apps_button_label)); |
| 69 | addTab(newTabSpec(APPS_TAB_TAG).setIndicator(tabView).setContent(contentFactory)); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 70 | tabView = (TextView) mLayoutInflater.inflate(R.layout.tab_widget_indicator, tabs, false); |
| 71 | tabView.setText(mContext.getString(R.string.widgets_tab_label)); |
| 72 | addTab(newTabSpec(WIDGETS_TAB_TAG).setIndicator(tabView).setContent(contentFactory)); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 73 | setOnTabChangedListener(this); |
| 74 | |
| 75 | // Set the width of the tab bar to match the content (for now) |
| 76 | tabs.getLayoutParams().width = content.getPageContentWidth(); |
| 77 | } |
| 78 | |
| 79 | @Override |
| 80 | public void onTabChanged(String tabId) { |
| 81 | final AppsCustomizePagedView content = (AppsCustomizePagedView) |
| 82 | findViewById(R.id.apps_customize_pane_content); |
| 83 | content.setContentType(getContentTypeForTabTag(tabId)); |
| 84 | } |
| 85 | |
| 86 | /** |
| 87 | * Returns the content type for the specified tab tag. |
| 88 | */ |
| 89 | public AppsCustomizePagedView.ContentType getContentTypeForTabTag(String tag) { |
| 90 | if (tag.equals(APPS_TAB_TAG)) { |
| 91 | return AppsCustomizePagedView.ContentType.Applications; |
| 92 | } else if (tag.equals(WIDGETS_TAB_TAG)) { |
| 93 | return AppsCustomizePagedView.ContentType.Widgets; |
| 94 | } |
| 95 | return AppsCustomizePagedView.ContentType.Applications; |
| 96 | } |
| 97 | |
| 98 | /** |
Winson Chung | fc79c80 | 2011-05-02 13:35:34 -0700 | [diff] [blame^] | 99 | * Returns the tab tag for a given content type. |
| 100 | */ |
| 101 | public String getTabTagForContentType(AppsCustomizePagedView.ContentType type) { |
| 102 | if (type == AppsCustomizePagedView.ContentType.Applications) { |
| 103 | return APPS_TAB_TAG; |
| 104 | } else if (type == AppsCustomizePagedView.ContentType.Widgets) { |
| 105 | return WIDGETS_TAB_TAG; |
| 106 | } |
| 107 | return APPS_TAB_TAG; |
| 108 | } |
| 109 | |
| 110 | /** |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 111 | * Disable focus on anything under this view in the hierarchy if we are not visible. |
| 112 | */ |
| 113 | @Override |
| 114 | public int getDescendantFocusability() { |
| 115 | if (getVisibility() != View.VISIBLE) { |
| 116 | return ViewGroup.FOCUS_BLOCK_DESCENDANTS; |
| 117 | } |
| 118 | return super.getDescendantFocusability(); |
| 119 | } |
| 120 | |
| 121 | /* LauncherTransitionable overrides */ |
| 122 | @Override |
| 123 | public void onLauncherTransitionStart(android.animation.Animator animation) { |
| 124 | // TODO-APPS_CUSTOMIZE: see AllAppsTabbed.onLauncherTransitionStart(); |
| 125 | } |
| 126 | @Override |
| 127 | public void onLauncherTransitionEnd(android.animation.Animator animation) { |
| 128 | // TODO-APPS_CUSTOMIZE: see AllAppsTabbed.onLauncherTransitionEnd(); |
| 129 | } |
| 130 | } |