use of android.widget.TabWidget in project android-viewbadger by jgilfelt.
the class BadgeView method applyTo.
private void applyTo(View target) {
LayoutParams lp = target.getLayoutParams();
ViewParent parent = target.getParent();
FrameLayout container = new FrameLayout(context);
if (target instanceof TabWidget) {
// set target to the relevant tab child container
target = ((TabWidget) target).getChildTabViewAt(targetTabIndex);
this.target = target;
((ViewGroup) target).addView(container, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
this.setVisibility(View.GONE);
container.addView(this);
} else {
// TODO verify that parent is indeed a ViewGroup
ViewGroup group = (ViewGroup) parent;
int index = group.indexOfChild(target);
group.removeView(target);
group.addView(container, index, lp);
container.addView(target);
this.setVisibility(View.GONE);
container.addView(this);
group.invalidate();
}
}
use of android.widget.TabWidget in project Fairphone by Kwamecorp.
the class AppsCustomizeTabHost method onFinishInflate.
/**
* Setup the tab host and create all necessary tabs.
*/
@Override
protected void onFinishInflate() {
// Setup the tab host
setup();
final ViewGroup tabsContainer = (ViewGroup) findViewById(R.id.tabs_container);
final TabWidget tabs = getTabWidget();
final AppsCustomizePagedView appsCustomizePane = (AppsCustomizePagedView) findViewById(R.id.apps_customize_pane_content);
mTabs = tabs;
mTabsContainer = tabsContainer;
mAppsCustomizePane = appsCustomizePane;
mAnimationBuffer = (FrameLayout) findViewById(R.id.animation_buffer);
mContent = (LinearLayout) findViewById(R.id.apps_customize_content);
if (tabs == null || mAppsCustomizePane == null)
throw new Resources.NotFoundException();
// Configure the tabs content factory to return the same paged view (that we change the
// content filter on)
TabContentFactory contentFactory = new TabContentFactory() {
public View createTabContent(String tag) {
return appsCustomizePane;
}
};
// Create the tabs
TextView tabView;
String label;
label = getContext().getString(R.string.all_apps_button_label);
tabView = (TextView) mLayoutInflater.inflate(R.layout.tab_widget_indicator, tabs, false);
tabView.setText(label);
tabView.setContentDescription(label);
addTab(newTabSpec(APPS_TAB_TAG).setIndicator(tabView).setContent(contentFactory));
label = getContext().getString(R.string.widgets_tab_label);
tabView = (TextView) mLayoutInflater.inflate(R.layout.tab_widget_indicator, tabs, false);
tabView.setText(label);
tabView.setContentDescription(label);
addTab(newTabSpec(WIDGETS_TAB_TAG).setIndicator(tabView).setContent(contentFactory));
setOnTabChangedListener(this);
// Setup the key listener to jump between the last tab view and the market icon
AppsCustomizeTabKeyEventListener keyListener = new AppsCustomizeTabKeyEventListener();
View lastTab = tabs.getChildTabViewAt(tabs.getTabCount() - 1);
lastTab.setOnKeyListener(keyListener);
View shopButton = findViewById(R.id.market_button);
shopButton.setOnKeyListener(keyListener);
// Hide the tab bar until we measure
mTabsContainer.setAlpha(0f);
}
use of android.widget.TabWidget in project smartmodule by carozhu.
the class BadgeView method applyTo.
private void applyTo(View target) {
LayoutParams lp = target.getLayoutParams();
ViewParent parent = target.getParent();
FrameLayout container = new FrameLayout(context);
if (target instanceof TabWidget) {
// set target to the relevant tab child container
target = ((TabWidget) target).getChildTabViewAt(targetTabIndex);
this.target = target;
((ViewGroup) target).addView(container, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
this.setVisibility(View.GONE);
container.addView(this);
} else {
// TODO verify that parent is indeed a ViewGroup
ViewGroup group = (ViewGroup) parent;
int index = group.indexOfChild(target);
group.removeView(target);
group.addView(container, index, lp);
container.addView(target);
this.setVisibility(View.GONE);
container.addView(this);
group.invalidate();
}
}
use of android.widget.TabWidget in project Launcher3 by chislon.
the class AppsCustomizeTabHost method onFinishInflate.
/**
* Setup the tab host and create all necessary tabs.
*/
@Override
protected void onFinishInflate() {
// Setup the tab host
setup();
final ViewGroup tabsContainer = (ViewGroup) findViewById(R.id.tabs_container);
final TabWidget tabs = getTabWidget();
final AppsCustomizePagedView appsCustomizePane = (AppsCustomizePagedView) findViewById(R.id.apps_customize_pane_content);
mTabs = tabs;
mTabsContainer = tabsContainer;
mAppsCustomizePane = appsCustomizePane;
mAnimationBuffer = (FrameLayout) findViewById(R.id.animation_buffer);
mContent = (LinearLayout) findViewById(R.id.apps_customize_content);
if (tabs == null || mAppsCustomizePane == null)
throw new Resources.NotFoundException();
// Configure the tabs content factory to return the same paged view (that we change the
// content filter on)
TabContentFactory contentFactory = new TabContentFactory() {
public View createTabContent(String tag) {
return appsCustomizePane;
}
};
// Create the tabs
TextView tabView;
String label;
label = getContext().getString(R.string.all_apps_button_label);
tabView = (TextView) mLayoutInflater.inflate(R.layout.tab_widget_indicator, tabs, false);
tabView.setText(label);
tabView.setContentDescription(label);
addTab(newTabSpec(APPS_TAB_TAG).setIndicator(tabView).setContent(contentFactory));
label = getContext().getString(R.string.widgets_tab_label);
tabView = (TextView) mLayoutInflater.inflate(R.layout.tab_widget_indicator, tabs, false);
tabView.setText(label);
tabView.setContentDescription(label);
addTab(newTabSpec(WIDGETS_TAB_TAG).setIndicator(tabView).setContent(contentFactory));
setOnTabChangedListener(this);
// Setup the key listener to jump between the last tab view and the market icon
AppsCustomizeTabKeyEventListener keyListener = new AppsCustomizeTabKeyEventListener();
View lastTab = tabs.getChildTabViewAt(tabs.getTabCount() - 1);
lastTab.setOnKeyListener(keyListener);
View shopButton = findViewById(R.id.market_button);
shopButton.setOnKeyListener(keyListener);
// Hide the tab bar until we measure
mTabsContainer.setAlpha(0f);
}
use of android.widget.TabWidget in project Launcher3 by chislon.
the class FocusHelper method handleAppsCustomizeKeyEvent.
/**
* Handles key events in a PageViewCellLayout containing PagedViewIcons.
*/
static boolean handleAppsCustomizeKeyEvent(View v, int keyCode, KeyEvent e) {
ViewGroup parentLayout;
ViewGroup itemContainer;
int countX;
int countY;
if (v.getParent() instanceof ShortcutAndWidgetContainer) {
itemContainer = (ViewGroup) v.getParent();
parentLayout = (ViewGroup) itemContainer.getParent();
countX = ((CellLayout) parentLayout).getCountX();
countY = ((CellLayout) parentLayout).getCountY();
} else {
itemContainer = parentLayout = (ViewGroup) v.getParent();
countX = ((PagedViewGridLayout) parentLayout).getCellCountX();
countY = ((PagedViewGridLayout) parentLayout).getCellCountY();
}
// Note we have an extra parent because of the
// PagedViewCellLayout/PagedViewCellLayoutChildren relationship
final PagedView container = (PagedView) parentLayout.getParent();
final TabHost tabHost = findTabHostParent(container);
final TabWidget tabs = tabHost.getTabWidget();
final int iconIndex = itemContainer.indexOfChild(v);
final int itemCount = itemContainer.getChildCount();
final int pageIndex = ((PagedView) container).indexToPage(container.indexOfChild(parentLayout));
final int pageCount = container.getChildCount();
final int x = iconIndex % countX;
final int y = iconIndex / countX;
final int action = e.getAction();
final boolean handleKeyEvent = (action != KeyEvent.ACTION_UP);
ViewGroup newParent = null;
// Side pages do not always load synchronously, so check before focusing child siblings
// willy-nilly
View child = null;
boolean wasHandled = false;
switch(keyCode) {
case KeyEvent.KEYCODE_DPAD_LEFT:
if (handleKeyEvent) {
// Select the previous icon or the last icon on the previous page
if (iconIndex > 0) {
itemContainer.getChildAt(iconIndex - 1).requestFocus();
} else {
if (pageIndex > 0) {
newParent = getAppsCustomizePage(container, pageIndex - 1);
if (newParent != null) {
container.snapToPage(pageIndex - 1);
child = newParent.getChildAt(newParent.getChildCount() - 1);
if (child != null)
child.requestFocus();
}
}
}
}
wasHandled = true;
break;
case KeyEvent.KEYCODE_DPAD_RIGHT:
if (handleKeyEvent) {
// Select the next icon or the first icon on the next page
if (iconIndex < (itemCount - 1)) {
itemContainer.getChildAt(iconIndex + 1).requestFocus();
} else {
if (pageIndex < (pageCount - 1)) {
newParent = getAppsCustomizePage(container, pageIndex + 1);
if (newParent != null) {
container.snapToPage(pageIndex + 1);
child = newParent.getChildAt(0);
if (child != null)
child.requestFocus();
}
}
}
}
wasHandled = true;
break;
case KeyEvent.KEYCODE_DPAD_UP:
if (handleKeyEvent) {
// Select the closest icon in the previous row, otherwise select the tab bar
if (y > 0) {
int newiconIndex = ((y - 1) * countX) + x;
itemContainer.getChildAt(newiconIndex).requestFocus();
} else {
tabs.requestFocus();
}
}
wasHandled = true;
break;
case KeyEvent.KEYCODE_DPAD_DOWN:
if (handleKeyEvent) {
// Select the closest icon in the previous row, otherwise do nothing
if (y < (countY - 1)) {
int newiconIndex = Math.min(itemCount - 1, ((y + 1) * countX) + x);
itemContainer.getChildAt(newiconIndex).requestFocus();
}
}
wasHandled = true;
break;
case KeyEvent.KEYCODE_ENTER:
case KeyEvent.KEYCODE_DPAD_CENTER:
if (handleKeyEvent) {
// Simulate a click on the icon
View.OnClickListener clickListener = (View.OnClickListener) container;
clickListener.onClick(v);
}
wasHandled = true;
break;
case KeyEvent.KEYCODE_PAGE_UP:
if (handleKeyEvent) {
// if there is no previous page
if (pageIndex > 0) {
newParent = getAppsCustomizePage(container, pageIndex - 1);
if (newParent != null) {
container.snapToPage(pageIndex - 1);
child = newParent.getChildAt(0);
if (child != null)
child.requestFocus();
}
} else {
itemContainer.getChildAt(0).requestFocus();
}
}
wasHandled = true;
break;
case KeyEvent.KEYCODE_PAGE_DOWN:
if (handleKeyEvent) {
// if there is no next page
if (pageIndex < (pageCount - 1)) {
newParent = getAppsCustomizePage(container, pageIndex + 1);
if (newParent != null) {
container.snapToPage(pageIndex + 1);
child = newParent.getChildAt(0);
if (child != null)
child.requestFocus();
}
} else {
itemContainer.getChildAt(itemCount - 1).requestFocus();
}
}
wasHandled = true;
break;
case KeyEvent.KEYCODE_MOVE_HOME:
if (handleKeyEvent) {
// Select the first icon on this page
itemContainer.getChildAt(0).requestFocus();
}
wasHandled = true;
break;
case KeyEvent.KEYCODE_MOVE_END:
if (handleKeyEvent) {
// Select the last icon on this page
itemContainer.getChildAt(itemCount - 1).requestFocus();
}
wasHandled = true;
break;
default:
break;
}
return wasHandled;
}
Aggregations