use of android.widget.TabHost in project android_packages_apps_Launcher2 by CyanogenMod.
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 PagedViewCellLayoutChildren) {
itemContainer = (ViewGroup) v.getParent();
parentLayout = (ViewGroup) itemContainer.getParent();
countX = ((PagedViewCellLayout) parentLayout).getCellCountX();
countY = ((PagedViewCellLayout) parentLayout).getCellCountY();
} 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;
}
use of android.widget.TabHost in project fdroidclient by f-droid.
the class InstallConfirmActivity method startInstallConfirm.
private void startInstallConfirm() {
View appSnippet = findViewById(R.id.app_snippet);
TextView appName = (TextView) appSnippet.findViewById(R.id.app_name);
ImageView appIcon = (ImageView) appSnippet.findViewById(R.id.app_icon);
TabHost tabHost = (TabHost) findViewById(android.R.id.tabhost);
appName.setText(app.name);
ImageLoader.getInstance().displayImage(app.iconUrl, appIcon, Utils.getRepoAppDisplayImageOptions());
tabHost.setup();
ViewPager viewPager = (ViewPager) findViewById(R.id.pager);
TabsAdapter adapter = new TabsAdapter(this, tabHost, viewPager);
adapter.setOnTabChangedListener(new TabHost.OnTabChangeListener() {
@Override
public void onTabChanged(String tabId) {
}
});
boolean permVisible = false;
scrollView = null;
okCanInstall = false;
int msg = 0;
AppSecurityPermissions perms = new AppSecurityPermissions(this, appDiff.pkgInfo);
if (appDiff.installedAppInfo != null) {
msg = (appDiff.installedAppInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0 ? R.string.install_confirm_update_system : R.string.install_confirm_update;
scrollView = new CaffeinatedScrollView(this);
scrollView.setFillViewport(true);
final boolean newPermissionsFound = perms.getPermissionCount(AppSecurityPermissions.WHICH_NEW) > 0;
if (newPermissionsFound) {
permVisible = true;
scrollView.addView(perms.getPermissionsView(AppSecurityPermissions.WHICH_NEW));
} else {
throw new RuntimeException("This should not happen. No new permissions were found" + " but InstallConfirmActivity has been started!");
}
adapter.addTab(tabHost.newTabSpec(TAB_ID_NEW).setIndicator(getText(R.string.newPerms)), scrollView);
} else {
findViewById(R.id.tabscontainer).setVisibility(View.GONE);
findViewById(R.id.divider).setVisibility(View.VISIBLE);
}
final int n = perms.getPermissionCount(AppSecurityPermissions.WHICH_ALL);
if (n > 0) {
permVisible = true;
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View root = inflater.inflate(R.layout.permissions_list, null);
if (scrollView == null) {
scrollView = (CaffeinatedScrollView) root.findViewById(R.id.scrollview);
}
final ViewGroup permList = (ViewGroup) root.findViewById(R.id.permission_list);
permList.addView(perms.getPermissionsView(AppSecurityPermissions.WHICH_ALL));
adapter.addTab(tabHost.newTabSpec(TAB_ID_ALL).setIndicator(getText(R.string.allPerms)), root);
}
if (!permVisible) {
if (appDiff.installedAppInfo != null) {
// This is an update to an application, but there are no
// permissions at all.
msg = (appDiff.installedAppInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0 ? R.string.install_confirm_update_system_no_perms : R.string.install_confirm_update_no_perms;
} else {
// This is a new application with no permissions.
throw new RuntimeException("no permissions requested. This screen should not appear!");
}
tabHost.setVisibility(View.GONE);
findViewById(R.id.filler).setVisibility(View.VISIBLE);
findViewById(R.id.divider).setVisibility(View.GONE);
scrollView = null;
}
if (msg != 0) {
((TextView) findViewById(R.id.install_confirm)).setText(msg);
}
installConfirm.setVisibility(View.VISIBLE);
okButton = (Button) findViewById(R.id.ok_button);
cancelButton = (Button) findViewById(R.id.cancel_button);
okButton.setOnClickListener(this);
cancelButton.setOnClickListener(this);
if (scrollView == null) {
// There is nothing to scroll view, so the ok button is immediately
// set to install.
okButton.setText(R.string.menu_install);
okCanInstall = true;
} else {
scrollView.setFullScrollAction(new Runnable() {
@Override
public void run() {
okButton.setText(R.string.menu_install);
okCanInstall = true;
}
});
}
}
use of android.widget.TabHost in project LiveSDK-for-Android by liveservices.
the class MainActivity method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
LiveSdkSampleApplication app = (LiveSdkSampleApplication) getApplication();
mAuthClient = app.getAuthClient();
TabHost tabHost = getTabHost();
TabHost.TabSpec spec;
Intent intent;
intent = new Intent(this, ViewProfileActivity.class);
spec = tabHost.newTabSpec("profile").setIndicator("Profile").setContent(intent);
tabHost.addTab(spec);
intent = new Intent(this, ContactsActivity.class);
spec = tabHost.newTabSpec("contacts").setIndicator("Contacts").setContent(intent);
tabHost.addTab(spec);
intent = new Intent(this, SkyDriveActivity.class);
spec = tabHost.newTabSpec("skydrive").setIndicator("SkyDrive").setContent(intent);
tabHost.addTab(spec);
intent = new Intent(this, ExplorerActivity.class);
spec = tabHost.newTabSpec("explorer").setIndicator("Explorer").setContent(intent);
tabHost.addTab(spec);
tabHost.setCurrentTab(0);
}
use of android.widget.TabHost in project standup-timer by jwood.
the class TeamDetails method createTabs.
private void createTabs() {
TabHost tabHost = getTabHost();
tabHost.addTab(tabHost.newTabSpec("stats_tab").setIndicator(this.getString(R.string.stats)).setContent(createMeetingDetails(team)));
tabHost.addTab(tabHost.newTabSpec("meetings_tab").setIndicator(this.getString(R.string.meetings)).setContent(createMeetingList()));
getTabHost().setCurrentTab(0);
findViewById(R.id.team_stats).bringToFront();
}
use of android.widget.TabHost in project android-viewbadger by jgilfelt.
the class DemoActivity method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final TabHost tabHost = getTabHost();
tabHost.addTab(tabHost.newTabSpec("demos").setIndicator("Badge Demos").setContent(R.id.tab1));
tabHost.addTab(tabHost.newTabSpec("adapter").setIndicator("List Adapter").setContent(R.id.tab2));
tabHost.addTab(tabHost.newTabSpec("tests").setIndicator("Layout Tests").setContent(R.id.tab3));
// *** default badge ***
View target = findViewById(R.id.default_target);
BadgeView badge = new BadgeView(this, target);
badge.setText("1");
badge.show();
// *** set position ***
btnPosition = (Button) findViewById(R.id.position_target);
badge1 = new BadgeView(this, btnPosition);
badge1.setText("12");
badge1.setBadgePosition(BadgeView.POSITION_CENTER);
btnPosition.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
badge1.toggle();
}
});
// *** badge/text size & colour ***
btnColour = (Button) findViewById(R.id.colour_target);
badge2 = new BadgeView(this, btnColour);
badge2.setText("New!");
badge2.setTextColor(Color.BLUE);
badge2.setBadgeBackgroundColor(Color.YELLOW);
badge2.setTextSize(12);
btnColour.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
badge2.toggle();
}
});
// *** default animation ***
btnAnim1 = (Button) findViewById(R.id.anim1_target);
badge3 = new BadgeView(this, btnAnim1);
badge3.setText("84");
btnAnim1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
badge3.toggle(true);
}
});
// *** custom animation ***
btnAnim2 = (Button) findViewById(R.id.anim2_target);
badge4 = new BadgeView(this, btnAnim2);
badge4.setText("123");
badge4.setBadgePosition(BadgeView.POSITION_TOP_LEFT);
badge4.setBadgeMargin(15, 10);
badge4.setBadgeBackgroundColor(Color.parseColor("#A4C639"));
btnAnim2.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
TranslateAnimation anim = new TranslateAnimation(-100, 0, 0, 0);
anim.setInterpolator(new BounceInterpolator());
anim.setDuration(1000);
badge4.toggle(anim, null);
}
});
// *** custom background ***
btnCustom = (Button) findViewById(R.id.custom_target);
badge5 = new BadgeView(this, btnCustom);
badge5.setText("37");
badge5.setBackgroundResource(R.drawable.badge_ifaux);
badge5.setTextSize(16);
btnCustom.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
badge5.toggle(true);
}
});
// *** clickable badge ***
btnClick = (Button) findViewById(R.id.click_target);
badge6 = new BadgeView(this, btnClick);
badge6.setText("click me");
badge6.setBadgeBackgroundColor(Color.BLUE);
badge6.setTextSize(16);
badge6.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(DemoActivity.this, "clicked badge", Toast.LENGTH_SHORT).show();
}
});
btnClick.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
badge6.toggle();
}
});
// *** tab ***
TabWidget tabs = (TabWidget) findViewById(android.R.id.tabs);
btnTab = (Button) findViewById(R.id.tab_btn);
badge7 = new BadgeView(this, tabs, 0);
badge7.setText("5");
btnTab.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
badge7.toggle();
}
});
// *** increment ***
btnIncrement = (Button) findViewById(R.id.increment_target);
badge8 = new BadgeView(this, btnIncrement);
badge8.setText("0");
btnIncrement.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (badge8.isShown()) {
badge8.increment(1);
} else {
badge8.show();
}
}
});
// *** list adapter ****
listDemo = (ListView) findViewById(R.id.tab2);
listDemo.setAdapter(new BadgeAdapter(this));
}
Aggregations