blob: cd8e7efb030267f917c7c4c12563260d49979264 [file] [log] [blame]
Winson Chung785d2eb2011-04-14 16:08:02 -07001/*
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
17package com.android.launcher2;
18
19import android.content.Context;
20import android.content.res.Resources;
21import android.util.AttributeSet;
22import android.view.LayoutInflater;
23import android.view.View;
24import android.view.ViewGroup;
25import android.widget.TabHost;
Winson Chung785d2eb2011-04-14 16:08:02 -070026import android.widget.TextView;
27
28import com.android.launcher.R;
29
30public 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";
Winson Chung46af2e82011-05-09 16:00:53 -070036 private static final String WALLPAPERS_TAB_TAG = "WALLPAPERS";
Winson Chung785d2eb2011-04-14 16:08:02 -070037
38 private final LayoutInflater mLayoutInflater;
39
40 public AppsCustomizeTabHost(Context context, AttributeSet attrs) {
41 super(context, attrs);
42 mLayoutInflater = LayoutInflater.from(context);
43 }
44
Winson Chung55b65502011-05-26 12:03:43 -070045 void selectAppsTab() {
46 setCurrentTabByTag(APPS_TAB_TAG);
47 }
48 void selectWidgetsTab() {
49 setCurrentTabByTag(WIDGETS_TAB_TAG);
50 }
51
Winson Chung785d2eb2011-04-14 16:08:02 -070052 /**
53 * Setup the tab host and create all necessary tabs.
54 */
55 @Override
56 protected void onFinishInflate() {
57 // Setup the tab host
58 setup();
59
60 final ViewGroup tabs = (ViewGroup) findViewById(com.android.internal.R.id.tabs);
61 final AppsCustomizePagedView content = (AppsCustomizePagedView)
62 findViewById(R.id.apps_customize_pane_content);
63 if (tabs == null || content == null) throw new Resources.NotFoundException();
64
65 // Configure the tabs content factory to return the same paged view (that we change the
66 // content filter on)
67 TabContentFactory contentFactory = new TabContentFactory() {
68 public View createTabContent(String tag) {
69 return content;
70 }
71 };
72
73 // Create the tabs
74 TextView tabView;
75 tabView = (TextView) mLayoutInflater.inflate(R.layout.tab_widget_indicator, tabs, false);
76 tabView.setText(mContext.getString(R.string.all_apps_button_label));
77 addTab(newTabSpec(APPS_TAB_TAG).setIndicator(tabView).setContent(contentFactory));
Winson Chung785d2eb2011-04-14 16:08:02 -070078 tabView = (TextView) mLayoutInflater.inflate(R.layout.tab_widget_indicator, tabs, false);
79 tabView.setText(mContext.getString(R.string.widgets_tab_label));
80 addTab(newTabSpec(WIDGETS_TAB_TAG).setIndicator(tabView).setContent(contentFactory));
Winson Chung46af2e82011-05-09 16:00:53 -070081 tabView = (TextView) mLayoutInflater.inflate(R.layout.tab_widget_indicator, tabs, false);
82 tabView.setText(mContext.getString(R.string.wallpapers_tab_label));
83 addTab(newTabSpec(WALLPAPERS_TAB_TAG).setIndicator(tabView).setContent(contentFactory));
Winson Chung785d2eb2011-04-14 16:08:02 -070084 setOnTabChangedListener(this);
85
86 // Set the width of the tab bar to match the content (for now)
87 tabs.getLayoutParams().width = content.getPageContentWidth();
88 }
89
90 @Override
91 public void onTabChanged(String tabId) {
92 final AppsCustomizePagedView content = (AppsCustomizePagedView)
93 findViewById(R.id.apps_customize_pane_content);
94 content.setContentType(getContentTypeForTabTag(tabId));
95 }
96
97 /**
98 * Returns the content type for the specified tab tag.
99 */
100 public AppsCustomizePagedView.ContentType getContentTypeForTabTag(String tag) {
101 if (tag.equals(APPS_TAB_TAG)) {
102 return AppsCustomizePagedView.ContentType.Applications;
103 } else if (tag.equals(WIDGETS_TAB_TAG)) {
104 return AppsCustomizePagedView.ContentType.Widgets;
Winson Chung46af2e82011-05-09 16:00:53 -0700105 } else if (tag.equals(WALLPAPERS_TAB_TAG)) {
106 return AppsCustomizePagedView.ContentType.Wallpapers;
Winson Chung785d2eb2011-04-14 16:08:02 -0700107 }
108 return AppsCustomizePagedView.ContentType.Applications;
109 }
110
111 /**
Winson Chungfc79c802011-05-02 13:35:34 -0700112 * Returns the tab tag for a given content type.
113 */
114 public String getTabTagForContentType(AppsCustomizePagedView.ContentType type) {
115 if (type == AppsCustomizePagedView.ContentType.Applications) {
116 return APPS_TAB_TAG;
117 } else if (type == AppsCustomizePagedView.ContentType.Widgets) {
118 return WIDGETS_TAB_TAG;
Winson Chung46af2e82011-05-09 16:00:53 -0700119 } else if (type == AppsCustomizePagedView.ContentType.Wallpapers) {
120 return WALLPAPERS_TAB_TAG;
Winson Chungfc79c802011-05-02 13:35:34 -0700121 }
122 return APPS_TAB_TAG;
123 }
124
125 /**
Winson Chung785d2eb2011-04-14 16:08:02 -0700126 * Disable focus on anything under this view in the hierarchy if we are not visible.
127 */
128 @Override
129 public int getDescendantFocusability() {
130 if (getVisibility() != View.VISIBLE) {
131 return ViewGroup.FOCUS_BLOCK_DESCENDANTS;
132 }
133 return super.getDescendantFocusability();
134 }
135
136 /* LauncherTransitionable overrides */
137 @Override
138 public void onLauncherTransitionStart(android.animation.Animator animation) {
139 // TODO-APPS_CUSTOMIZE: see AllAppsTabbed.onLauncherTransitionStart();
140 }
141 @Override
142 public void onLauncherTransitionEnd(android.animation.Animator animation) {
143 // TODO-APPS_CUSTOMIZE: see AllAppsTabbed.onLauncherTransitionEnd();
144 }
145}