blob: 28f2d2ebcaca6fc41644dc6fa0db934153f64743 [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;
Winson Chung4179b4e2011-05-31 17:28:12 -070023import android.view.MotionEvent;
Winson Chung785d2eb2011-04-14 16:08:02 -070024import android.view.View;
25import android.view.ViewGroup;
26import android.widget.TabHost;
Winson Chung785d2eb2011-04-14 16:08:02 -070027import android.widget.TextView;
28
29import com.android.launcher.R;
30
31public class AppsCustomizeTabHost extends TabHost implements LauncherTransitionable,
32 TabHost.OnTabChangeListener {
33 static final String LOG_TAG = "AppsCustomizeTabHost";
34
35 private static final String APPS_TAB_TAG = "APPS";
36 private static final String WIDGETS_TAB_TAG = "WIDGETS";
Winson Chung46af2e82011-05-09 16:00:53 -070037 private static final String WALLPAPERS_TAB_TAG = "WALLPAPERS";
Winson Chung785d2eb2011-04-14 16:08:02 -070038
39 private final LayoutInflater mLayoutInflater;
Winson Chung4179b4e2011-05-31 17:28:12 -070040 private AppsCustomizePagedView mAppsCustomizePane;
Winson Chung785d2eb2011-04-14 16:08:02 -070041
42 public AppsCustomizeTabHost(Context context, AttributeSet attrs) {
43 super(context, attrs);
44 mLayoutInflater = LayoutInflater.from(context);
45 }
46
Winson Chung55b65502011-05-26 12:03:43 -070047 void selectAppsTab() {
48 setCurrentTabByTag(APPS_TAB_TAG);
49 }
50 void selectWidgetsTab() {
51 setCurrentTabByTag(WIDGETS_TAB_TAG);
52 }
53
Winson Chung785d2eb2011-04-14 16:08:02 -070054 /**
55 * Setup the tab host and create all necessary tabs.
56 */
57 @Override
58 protected void onFinishInflate() {
59 // Setup the tab host
60 setup();
61
62 final ViewGroup tabs = (ViewGroup) findViewById(com.android.internal.R.id.tabs);
Winson Chung4179b4e2011-05-31 17:28:12 -070063 final AppsCustomizePagedView appsCustomizePane = (AppsCustomizePagedView)
Winson Chung785d2eb2011-04-14 16:08:02 -070064 findViewById(R.id.apps_customize_pane_content);
Winson Chung4179b4e2011-05-31 17:28:12 -070065 mAppsCustomizePane = appsCustomizePane;
66 if (tabs == null || mAppsCustomizePane == null) throw new Resources.NotFoundException();
Winson Chung785d2eb2011-04-14 16:08:02 -070067
68 // Configure the tabs content factory to return the same paged view (that we change the
69 // content filter on)
70 TabContentFactory contentFactory = new TabContentFactory() {
71 public View createTabContent(String tag) {
Winson Chung4179b4e2011-05-31 17:28:12 -070072 return appsCustomizePane;
Winson Chung785d2eb2011-04-14 16:08:02 -070073 }
74 };
75
76 // Create the tabs
77 TextView tabView;
78 tabView = (TextView) mLayoutInflater.inflate(R.layout.tab_widget_indicator, tabs, false);
79 tabView.setText(mContext.getString(R.string.all_apps_button_label));
80 addTab(newTabSpec(APPS_TAB_TAG).setIndicator(tabView).setContent(contentFactory));
Winson Chung785d2eb2011-04-14 16:08:02 -070081 tabView = (TextView) mLayoutInflater.inflate(R.layout.tab_widget_indicator, tabs, false);
82 tabView.setText(mContext.getString(R.string.widgets_tab_label));
83 addTab(newTabSpec(WIDGETS_TAB_TAG).setIndicator(tabView).setContent(contentFactory));
Winson Chung46af2e82011-05-09 16:00:53 -070084 tabView = (TextView) mLayoutInflater.inflate(R.layout.tab_widget_indicator, tabs, false);
85 tabView.setText(mContext.getString(R.string.wallpapers_tab_label));
86 addTab(newTabSpec(WALLPAPERS_TAB_TAG).setIndicator(tabView).setContent(contentFactory));
Winson Chung785d2eb2011-04-14 16:08:02 -070087 setOnTabChangedListener(this);
88
89 // Set the width of the tab bar to match the content (for now)
Winson Chung4179b4e2011-05-31 17:28:12 -070090 tabs.getLayoutParams().width = mAppsCustomizePane.getPageContentWidth();
91 }
92
93 @Override
94 public boolean onTouchEvent(MotionEvent event) {
95 // Intercept all touch events up to the bottom of the AppsCustomizePane so they do not fall
96 // through to the workspace and trigger showWorkspace()
97 if (event.getY() < mAppsCustomizePane.getBottom()) {
98 return true;
99 }
100 return super.onTouchEvent(event);
Winson Chung785d2eb2011-04-14 16:08:02 -0700101 }
102
103 @Override
104 public void onTabChanged(String tabId) {
Winson Chung4179b4e2011-05-31 17:28:12 -0700105 mAppsCustomizePane.setContentType(getContentTypeForTabTag(tabId));
Winson Chung785d2eb2011-04-14 16:08:02 -0700106 }
107
108 /**
109 * Returns the content type for the specified tab tag.
110 */
111 public AppsCustomizePagedView.ContentType getContentTypeForTabTag(String tag) {
112 if (tag.equals(APPS_TAB_TAG)) {
113 return AppsCustomizePagedView.ContentType.Applications;
114 } else if (tag.equals(WIDGETS_TAB_TAG)) {
115 return AppsCustomizePagedView.ContentType.Widgets;
Winson Chung46af2e82011-05-09 16:00:53 -0700116 } else if (tag.equals(WALLPAPERS_TAB_TAG)) {
117 return AppsCustomizePagedView.ContentType.Wallpapers;
Winson Chung785d2eb2011-04-14 16:08:02 -0700118 }
119 return AppsCustomizePagedView.ContentType.Applications;
120 }
121
122 /**
Winson Chungfc79c802011-05-02 13:35:34 -0700123 * Returns the tab tag for a given content type.
124 */
125 public String getTabTagForContentType(AppsCustomizePagedView.ContentType type) {
126 if (type == AppsCustomizePagedView.ContentType.Applications) {
127 return APPS_TAB_TAG;
128 } else if (type == AppsCustomizePagedView.ContentType.Widgets) {
129 return WIDGETS_TAB_TAG;
Winson Chung46af2e82011-05-09 16:00:53 -0700130 } else if (type == AppsCustomizePagedView.ContentType.Wallpapers) {
131 return WALLPAPERS_TAB_TAG;
Winson Chungfc79c802011-05-02 13:35:34 -0700132 }
133 return APPS_TAB_TAG;
134 }
135
136 /**
Winson Chung785d2eb2011-04-14 16:08:02 -0700137 * Disable focus on anything under this view in the hierarchy if we are not visible.
138 */
139 @Override
140 public int getDescendantFocusability() {
141 if (getVisibility() != View.VISIBLE) {
142 return ViewGroup.FOCUS_BLOCK_DESCENDANTS;
143 }
144 return super.getDescendantFocusability();
145 }
146
147 /* LauncherTransitionable overrides */
148 @Override
149 public void onLauncherTransitionStart(android.animation.Animator animation) {
150 // TODO-APPS_CUSTOMIZE: see AllAppsTabbed.onLauncherTransitionStart();
151 }
152 @Override
153 public void onLauncherTransitionEnd(android.animation.Animator animation) {
154 // TODO-APPS_CUSTOMIZE: see AllAppsTabbed.onLauncherTransitionEnd();
155 }
156}