Bug 894077: Layout for history panel for tablets [r=sriram]

This commit is contained in:
Shilpan Bhagat 2013-08-07 00:11:31 -07:00
parent 044b712ad6
commit 18bfc97e04
29 changed files with 368 additions and 42 deletions

View File

@ -473,7 +473,7 @@ RES_LAYOUT = \
res/layout/home_history_page.xml \
res/layout/home_history_tabs_indicator.xml \
res/layout/home_last_tabs_page.xml \
res/layout/home_list_with_title.xml \
res/layout/home_history_list.xml \
res/layout/home_most_recent_page.xml \
res/layout/home_most_visited_page.xml \
res/layout/home_search_item_row.xml \
@ -523,6 +523,9 @@ RES_LAYOUT_LARGE_V11 = \
$(NULL)
RES_LAYOUT_LARGE_LAND_V11 = \
res/layout-large-land-v11/home_history_page.xml \
res/layout-large-land-v11/home_history_tabs_indicator.xml \
res/layout-large-land-v11/home_history_list.xml \
res/layout-large-land-v11/tabs_panel.xml \
res/layout-large-land-v11/tabs_panel_header.xml \
res/layout-large-land-v11/tabs_panel_footer.xml \
@ -530,6 +533,9 @@ RES_LAYOUT_LARGE_LAND_V11 = \
RES_LAYOUT_XLARGE_V11 = \
res/layout-xlarge-v11/font_size_preference.xml \
res/layout-xlarge-v11/home_history_page.xml \
res/layout-xlarge-v11/home_history_tabs_indicator.xml \
res/layout-xlarge-v11/home_history_list.xml \
res/layout-xlarge-v11/remote_tabs_child.xml \
res/layout-xlarge-v11/remote_tabs_group.xml \
$(NULL)
@ -569,6 +575,7 @@ RES_VALUES_LARGE_V11 = \
$(NULL)
RES_VALUES_LARGE_LAND_V11 = \
res/values-large-land-v11/dimens.xml \
res/values-large-land-v11/styles.xml \
$(NULL)
@ -579,6 +586,7 @@ RES_VALUES_XLARGE_V11 = \
$(NULL)
RES_VALUES_XLARGE_LAND_V11 = \
res/values-xlarge-land-v11/dimens.xml \
res/values-xlarge-land-v11/styles.xml \
$(NULL)
@ -993,6 +1001,10 @@ RES_DRAWABLE_XHDPI_V11 = \
res/drawable-xhdpi-v11/ic_status_logo.png \
$(NULL)
RES_DRAWABLE_LARGE_LAND_V11 = \
res/drawable-large-land-v11/home_history_tabs_indicator.xml \
$(NULL)
RES_DRAWABLE_LARGE_MDPI_V11 = \
res/drawable-large-mdpi-v11/arrow_popup_bg.9.png \
res/drawable-large-mdpi-v11/ic_menu_reload.png \
@ -1014,6 +1026,10 @@ RES_DRAWABLE_LARGE_XHDPI_V11 = \
res/drawable-large-xhdpi-v11/menu.png \
$(NULL)
RES_DRAWABLE_XLARGE_V11 = \
res/drawable-xlarge-v11/home_history_tabs_indicator.xml \
$(NULL)
RES_DRAWABLE_XLARGE_MDPI_V11 = \
res/drawable-xlarge-mdpi-v11/ic_menu_bookmark_add.png \
res/drawable-xlarge-mdpi-v11/ic_menu_bookmark_remove.png \
@ -1104,6 +1120,7 @@ RESOURCES = \
$(RES_DRAWABLE) \
$(RES_DRAWABLE_HDPI) \
$(RES_DRAWABLE_HDPI_V11) \
$(RES_DRAWABLE_LARGE_LAND_V11) \
$(RES_DRAWABLE_LARGE_HDPI_V11) \
$(RES_DRAWABLE_LARGE_MDPI_V11) \
$(RES_DRAWABLE_LARGE_XHDPI_V11) \
@ -1112,6 +1129,7 @@ RESOURCES = \
$(RES_DRAWABLE_MDPI_V11) \
$(RES_DRAWABLE_XHDPI) \
$(RES_DRAWABLE_XHDPI_V11) \
$(RES_DRAWABLE_XLARGE_V11) \
$(RES_DRAWABLE_XLARGE_HDPI_V11) \
$(RES_DRAWABLE_XLARGE_MDPI_V11) \
$(RES_DRAWABLE_XLARGE_XHDPI_V11) \
@ -1158,9 +1176,11 @@ RES_DIRS= \
res/drawable-mdpi-v11 \
res/drawable-hdpi-v11 \
res/drawable-xhdpi-v11 \
res/drawable-large-land-v11 \
res/drawable-large-mdpi-v11 \
res/drawable-large-hdpi-v11 \
res/drawable-large-xhdpi-v11 \
res/drawable-xlarge-v11 \
res/drawable-xlarge-mdpi-v11 \
res/drawable-xlarge-hdpi-v11 \
res/drawable-xlarge-xhdpi-v11 \

View File

@ -105,19 +105,11 @@ public class TabsPanel extends LinearLayout
}
});
ImageButton button;
Resources resources = getContext().getResources();
mTabWidget = (IconTabWidget) findViewById(R.id.tab_widget);
button = mTabWidget.addTab(R.drawable.tabs_normal);
button.setContentDescription(resources.getString(R.string.tabs_normal));
button = mTabWidget.addTab(R.drawable.tabs_private);
button.setContentDescription(resources.getString(R.string.tabs_private));
button = mTabWidget.addTab(R.drawable.tabs_synced);
button.setContentDescription(resources.getString(R.string.tabs_synced));
mTabWidget.addTab(R.drawable.tabs_normal, R.string.tabs_normal);
mTabWidget.addTab(R.drawable.tabs_private, R.string.tabs_private);
mTabWidget.addTab(R.drawable.tabs_synced, R.string.tabs_synced);
mTabWidget.setTabSelectionListener(this);
}

View File

@ -9,6 +9,7 @@ import org.mozilla.gecko.R;
import org.mozilla.gecko.widget.IconTabWidget;
import android.support.v4.app.Fragment;
import android.content.Context;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.os.Bundle;
import android.view.LayoutInflater;
@ -24,6 +25,7 @@ public class HistoryPage extends HomeFragment
private static final String LOGTAG = "GeckoHistoryPage";
private IconTabWidget mTabWidget;
private int mSelectedTab;
private boolean initializeVisitedPage;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
@ -36,20 +38,16 @@ public class HistoryPage extends HomeFragment
mTabWidget = (IconTabWidget) view.findViewById(R.id.tab_icon_widget);
ImageButton button;
final Resources resources = view.getContext().getResources();
mTabWidget.addTab(R.drawable.icon_most_visited, R.string.home_most_visited_title);
mTabWidget.addTab(R.drawable.icon_most_recent, R.string.home_most_recent_title);
mTabWidget.addTab(R.drawable.icon_last_tabs, R.string.home_last_tabs_title);
button = mTabWidget.addTab(R.drawable.icon_most_visited);
button.setContentDescription(resources.getString(R.string.home_most_visited_title));
button = mTabWidget.addTab(R.drawable.icon_most_recent);
button.setContentDescription(resources.getString(R.string.home_most_recent_title));
button = mTabWidget.addTab(R.drawable.icon_last_tabs);
button.setContentDescription(resources.getString(R.string.home_last_tabs_title));
//Show most visited page as the initial page
showMostVisitedPage();
// Show most visited page as the initial page.
// Since we detach/attach on config change, this prevents from replacing current fragment.
if (!initializeVisitedPage) {
showMostVisitedPage();
initializeVisitedPage = true;
}
mTabWidget.setTabSelectionListener(this);
mTabWidget.setCurrentTab(mSelectedTab);
@ -76,6 +74,19 @@ public class HistoryPage extends HomeFragment
mSelectedTab = index;
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
// Rotation should detach and re-attach to use a different layout.
if (isVisible()) {
getFragmentManager().beginTransaction()
.detach(this)
.attach(this)
.commitAllowingStateLoss();
}
}
private void showSubPage(Fragment subPage) {
getChildFragmentManager().beginTransaction()
.addToBackStack(null).replace(R.id.visited_page_container, subPage)

View File

@ -97,7 +97,9 @@ public class LastTabsPage extends HomeFragment {
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
mTitle = (TextView) view.findViewById(R.id.title);
mTitle.setText(R.string.home_last_tabs_title);
if (mTitle != null) {
mTitle.setText(R.string.home_last_tabs_title);
}
mList = (ListView) view.findViewById(R.id.list);
@ -149,13 +151,17 @@ public class LastTabsPage extends HomeFragment {
private void updateUiFromCursor(Cursor c) {
if (c != null && c.getCount() > 0) {
mTitle.setVisibility(View.VISIBLE);
if (mTitle != null) {
mTitle.setVisibility(View.VISIBLE);
}
mRestoreButton.setVisibility(View.VISIBLE);
return;
}
// Cursor is empty, so hide the title and set the empty view if it hasn't been set already.
mTitle.setVisibility(View.GONE);
if (mTitle != null) {
mTitle.setVisibility(View.VISIBLE);
}
mRestoreButton.setVisibility(View.GONE);
if (mEmptyView == null) {

View File

@ -93,7 +93,9 @@ public class MostRecentPage extends HomeFragment {
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
mTitle = (TextView) view.findViewById(R.id.title);
mTitle.setText(R.string.home_most_recent_title);
if (mTitle != null) {
mTitle.setText(R.string.home_most_recent_title);
}
mList = (ListView) view.findViewById(R.id.list);
mList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@ -154,12 +156,16 @@ public class MostRecentPage extends HomeFragment {
private void updateUiFromCursor(Cursor c) {
if (c != null && c.getCount() > 0) {
mTitle.setVisibility(View.VISIBLE);
if (mTitle != null) {
mTitle.setVisibility(View.VISIBLE);
}
return;
}
// Cursor is empty, so hide the title and set the empty view if it hasn't been set already.
mTitle.setVisibility(View.GONE);
if (mTitle != null) {
mTitle.setVisibility(View.VISIBLE);
}
if (mEmptyView == null) {
// Set empty page view. We delay this so that the empty view won't flash.
ViewStub emptyViewStub = (ViewStub) getActivity().findViewById(R.id.home_empty_view_stub);

View File

@ -84,7 +84,10 @@ public class MostVisitedPage extends HomeFragment {
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
final TextView title = (TextView) view.findViewById(R.id.title);
title.setText(R.string.home_most_visited_title);
if (title != null) {
title.setText(R.string.home_most_visited_title);
title.setVisibility(View.VISIBLE);
}
mList = (HomeListView) view.findViewById(R.id.list);

View File

@ -0,0 +1,48 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- This Source Code Form is subject to the terms of the Mozilla Public
- License, v. 2.0. If a copy of the MPL was not distributed with this
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="false"
android:state_selected="false"
android:state_pressed="false"
android:drawable="@android:color/transparent"/>
<item android:state_focused="false"
android:state_selected="true"
android:state_pressed="false"
android:drawable="@color/background_light"/>
<item android:state_focused="true"
android:state_selected="false"
android:state_pressed="false"
android:drawable="@color/highlight_dark_focused"/>
<item android:state_focused="true"
android:state_selected="true"
android:state_pressed="false"
android:drawable="@color/background_light"/>
<item android:state_focused="false"
android:state_selected="false"
android:state_pressed="true"
android:drawable="@color/highlight_dark"/>
<item android:state_focused="false"
android:state_selected="true"
android:state_pressed="true"
android:drawable="@color/highlight_dark"/>
<item android:state_focused="true"
android:state_selected="false"
android:state_pressed="true"
android:drawable="@color/highlight_dark"/>
<item android:state_focused="true"
android:state_selected="true"
android:state_pressed="true"
android:drawable="@color/highlight_dark"/>
</selector>

View File

@ -0,0 +1,48 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- This Source Code Form is subject to the terms of the Mozilla Public
- License, v. 2.0. If a copy of the MPL was not distributed with this
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="false"
android:state_selected="false"
android:state_pressed="false"
android:drawable="@android:color/transparent"/>
<item android:state_focused="false"
android:state_selected="true"
android:state_pressed="false"
android:drawable="@color/background_light"/>
<item android:state_focused="true"
android:state_selected="false"
android:state_pressed="false"
android:drawable="@color/highlight_dark_focused"/>
<item android:state_focused="true"
android:state_selected="true"
android:state_pressed="false"
android:drawable="@color/background_light"/>
<item android:state_focused="false"
android:state_selected="false"
android:state_pressed="true"
android:drawable="@color/highlight_dark"/>
<item android:state_focused="false"
android:state_selected="true"
android:state_pressed="true"
android:drawable="@color/highlight_dark"/>
<item android:state_focused="true"
android:state_selected="false"
android:state_pressed="true"
android:drawable="@color/highlight_dark"/>
<item android:state_focused="true"
android:state_selected="true"
android:state_pressed="true"
android:drawable="@color/highlight_dark"/>
</selector>

View File

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- This Source Code Form is subject to the terms of the Mozilla Public
- License, v. 2.0. If a copy of the MPL was not distributed with this
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
<merge xmlns:android="http://schemas.android.com/apk/res/android">
<ViewStub android:id="@+id/home_empty_view_stub"
android:layout="@layout/home_empty_page"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
<org.mozilla.gecko.home.HomeListView
android:id="@+id/list"
style="@style/Widget.Home.HistoryListView"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"/>
</merge>

View File

@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- This Source Code Form is subject to the terms of the Mozilla Public
- License, v. 2.0. If a copy of the MPL was not distributed with this
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:gecko="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<org.mozilla.gecko.widget.IconTabWidget android:id="@+id/tab_icon_widget"
style="@style/Widget.Home.HistoryTabWidget"
android:layout_width="@dimen/history_tab_widget_width"
android:layout_height="@dimen/history_tab_widget_height"
android:orientation="vertical"
android:layout="@layout/home_history_tabs_indicator"
gecko:display="text"/>
<FrameLayout android:id="@+id/visited_page_container"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1" />
</LinearLayout>

View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- This Source Code Form is subject to the terms of the Mozilla Public
- License, v. 2.0. If a copy of the MPL was not distributed with this
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
style="@style/Widget.Home.HistoryTabIndicator"
android:layout_width="fill_parent"
android:layout_height="@dimen/history_tab_indicator_height"
android:background="@drawable/home_history_tabs_indicator"/>

View File

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- This Source Code Form is subject to the terms of the Mozilla Public
- License, v. 2.0. If a copy of the MPL was not distributed with this
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
<merge xmlns:android="http://schemas.android.com/apk/res/android">
<ViewStub android:id="@+id/home_empty_view_stub"
android:layout="@layout/home_empty_page"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
<org.mozilla.gecko.home.HomeListView
android:id="@+id/list"
style="@style/Widget.Home.HistoryListView"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"/>
</merge>

View File

@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- This Source Code Form is subject to the terms of the Mozilla Public
- License, v. 2.0. If a copy of the MPL was not distributed with this
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:gecko="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<org.mozilla.gecko.widget.IconTabWidget android:id="@+id/tab_icon_widget"
style="@style/Widget.Home.HistoryTabWidget"
android:layout_width="@dimen/history_tab_widget_width"
android:layout_height="@dimen/history_tab_widget_height"
android:orientation="vertical"
android:layout="@layout/home_history_tabs_indicator"
gecko:display="text"/>
<FrameLayout android:id="@+id/visited_page_container"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1" />
</LinearLayout>

View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- This Source Code Form is subject to the terms of the Mozilla Public
- License, v. 2.0. If a copy of the MPL was not distributed with this
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
style="@style/Widget.Home.HistoryTabIndicator"
android:layout_width="fill_parent"
android:layout_height="@dimen/history_tab_indicator_height"
android:background="@drawable/home_history_tabs_indicator"/>

View File

@ -11,11 +11,12 @@
android:layout_height="fill_parent"/>
<TextView android:id="@+id/title"
style="@style/Widget.Home.PageTitle"
style="@style/Widget.Home.HistoryTabIndicator"
android:visibility="gone"/>
<org.mozilla.gecko.home.HomeListView
android:id="@+id/list"
style="@style/Widget.Home.HistoryListView"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"/>

View File

@ -4,6 +4,7 @@
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
<ImageButton xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="@drawable/home_history_tabs_indicator"/>

View File

@ -8,7 +8,7 @@
android:layout_height="fill_parent"
android:orientation="vertical">
<include layout="@layout/home_list_with_title"/>
<include layout="@layout/home_history_list"/>
<LinearLayout android:layout_width="fill_parent"
android:layout_height="wrap_content"

View File

@ -8,6 +8,6 @@
android:layout_height="fill_parent"
android:orientation="vertical">
<include layout="@layout/home_list_with_title"/>
<include layout="@layout/home_history_list"/>
</LinearLayout>

View File

@ -8,6 +8,6 @@
android:layout_height="fill_parent"
android:orientation="vertical">
<include layout="@layout/home_list_with_title"/>
<include layout="@layout/home_history_list"/>
</LinearLayout>

View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- This Source Code Form is subject to the terms of the Mozilla Public
- License, v. 2.0. If a copy of the MPL was not distributed with this
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
<resources>
<dimen name="history_tab_widget_width">360dp</dimen>
</resources>

View File

@ -35,4 +35,18 @@
<item name="android:verticalSpacing">20dp</item>
</style>
<style name="Widget.Home.HistoryListView">
<item name="android:paddingLeft">50dp</item>
<item name="android:paddingRight">100dp</item>
<item name="android:paddingTop">30dp</item>
<item name="android:scrollbarStyle">outsideOverlay</item>
</style>
<style name="Widget.Home.HistoryTabWidget">
<item name="android:showDividers">beginning|middle|end</item>
<item name="android:dividerPadding">0dp</item>
<item name="android:paddingLeft">100dp</item>
<item name="android:paddingTop">30dp</item>
</style>
</resources>

View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- This Source Code Form is subject to the terms of the Mozilla Public
- License, v. 2.0. If a copy of the MPL was not distributed with this
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
<resources>
<dimen name="history_tab_widget_width">480dp</dimen>
</resources>

View File

@ -14,4 +14,18 @@
<item name="android:verticalSpacing">20dp</item>
</style>
<style name="Widget.Home.HistoryListView">
<item name="android:paddingLeft">50dp</item>
<item name="android:paddingRight">100dp</item>
<item name="android:paddingTop">30dp</item>
<item name="android:scrollbarStyle">outsideOverlay</item>
</style>
<style name="Widget.Home.HistoryTabWidget">
<item name="android:showDividers">beginning|middle|end</item>
<item name="android:dividerPadding">0dp</item>
<item name="android:paddingLeft">100dp</item>
<item name="android:paddingTop">30dp</item>
</style>
</resources>

View File

@ -12,5 +12,6 @@
<dimen name="tabs_panel_indicator_width">60dp</dimen>
<dimen name="tabs_panel_list_padding">8dip</dimen>
<dimen name="url_bar_offset_left">84dip</dimen>
<dimen name="history_tab_widget_width">270dp</dimen>
</resources>

View File

@ -16,4 +16,17 @@
<item name="android:layout_height">48dip</item>
</style>
<style name="Widget.Home.HistoryListView">
<item name="android:paddingLeft">32dp</item>
<item name="android:paddingRight">32dp</item>
<item name="android:paddingTop">30dp</item>
<item name="android:scrollbarStyle">outsideOverlay</item>
</style>
<style name="Widget.Home.HistoryTabWidget">
<item name="android:showDividers">beginning|middle|end</item>
<item name="android:dividerPadding">0dp</item>
<item name="android:paddingTop">30dp</item>
</style>
</resources>

View File

@ -198,6 +198,12 @@
<declare-styleable name="IconTabWidget">
<attr name="android:layout"/>
<!-- Sets the tab's content type. Defaults to icon. -->
<attr name="display">
<enum name="icon" value="0x00" />
<enum name="text" value="0x01" />
</attr>
</declare-styleable>
<declare-styleable name="TopBookmarksView">

View File

@ -75,6 +75,13 @@
<dimen name="forward_default_offset">-13dip</dimen>
<dimen name="url_bar_offset_left">32dp</dimen>
<dimen name="toast_button_padding">8dp</dimen>
<dimen name="history_tab_indicator_height">50dp</dimen>
<!-- We need to maintain height for the tab widget on History Page
since android does not add footer/header divider height to its
calculation for wrap_content in LinearLayout.
50dp * 3 Views + 30dp padding + 4dp dividers-->
<dimen name="history_tab_widget_height">184dp</dimen>
<!-- PageActionButtons dimensions -->
<dimen name="page_action_button_width">32dp</dimen>

View File

@ -186,7 +186,7 @@
<item name="android:textAppearance">@style/TextAppearance.Widget.Home.PageAction</item>
</style>
<style name="Widget.Home.PageTitle">
<style name="Widget.Home.HistoryTabIndicator">
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">32dp</item>
<item name="android:textAppearance">@style/TextAppearance.Widget.Home.PageTitle</item>

View File

@ -12,11 +12,13 @@ import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageButton;
import android.widget.TextView;
import android.widget.TabWidget;
public class IconTabWidget extends TabWidget {
private OnTabChangedListener mListener;
private final int mButtonLayoutId;
private final boolean mIsIcon;
public static interface OnTabChangedListener {
public void onTabChanged(int tabIndex);
@ -27,6 +29,7 @@ public class IconTabWidget extends TabWidget {
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.IconTabWidget);
mButtonLayoutId = a.getResourceId(R.styleable.IconTabWidget_android_layout, 0);
mIsIcon = (a.getInt(R.styleable.IconTabWidget_display, 0x00) == 0x00);
a.recycle();
if (mButtonLayoutId == 0) {
@ -34,14 +37,18 @@ public class IconTabWidget extends TabWidget {
}
}
public ImageButton addTab(int resId) {
ImageButton button = (ImageButton) LayoutInflater.from(getContext()).inflate(mButtonLayoutId, null);
button.setImageResource(resId);
public void addTab(int imageResId, int stringResId) {
View button = LayoutInflater.from(getContext()).inflate(mButtonLayoutId, this, false);
if (mIsIcon) {
((ImageButton) button).setImageResource(imageResId);
button.setContentDescription(getContext().getString(stringResId));
} else {
((TextView) button).setText(getContext().getString(stringResId));
}
addView(button);
button.setOnClickListener(new TabClickListener(getTabCount() - 1));
button.setOnFocusChangeListener(this);
return button;
}
public void setTabSelectionListener(OnTabChangedListener listener) {