List of usage examples for android.widget TabHost newTabSpec
@NonNull
public TabSpec newTabSpec(@NonNull String tag)
From source file:com.mibr.android.intelligentreminder.INeedToo.java
/** Called when the activity is first created. */ @Override/*from w w w .j a v a 2s. co m*/ public void onCreate(Bundle savedInstanceState) { /* this was just a test if(mLocationManager==null) { mLocationManager=(android.location.LocationManager) getSystemService(Context.LOCATION_SERVICE); } */ // TabHost host=this.getTabHost(); // host.setOnTabChangedListener(new TabHost.OnTabChangeListener() { // // @Override // public void onTabChanged(String tabId) { // if(INeedToo.this._doingCreatingTabs==false) { // if(tabId.equals("tab1")) { // INeedToo.this._forceNonCompany=true; // } // } // } // }); super.onCreate(savedInstanceState); mLocationClient = new LocationClient(this, this, this); mLocationClient.connect(); try { if (getIntent().getAction() != null && getIntent().getAction().equals("doPrimitiveDeletedNeed")) { transmitNetwork(getIntent().getStringExtra("phoneid")); return; } } catch (Exception eieio) { return; } try { /* putExtra("needId",needId). putExtra("foreignNeedId",foreignNeedId). putExtra("phoneid",phoneid). putExtra("foreignLocationId",foreignLocationId) */ if (getIntent().getAction() != null && getIntent().getAction().equals("transmitNetworkDeletedThisNeedByOnBehalfOf")) { long needId = getIntent().getLongExtra("needId", -11); long foreignNeedId = getIntent().getLongExtra("foreignNeedId", -11); String phoneId = getIntent().getStringExtra("phoneid"); long foreignLocationId = getIntent().getLongExtra("foreignLocationId", -11); if (needId != -11 && foreignNeedId != -11 && foreignLocationId != -11 && isNothingNot(phoneId)) transmitNetworkDeletedThisNeedByOnBehalfOf(needId, foreignNeedId, phoneId, foreignLocationId); return; } } catch (Exception ei3) { return; } /*bbhbb 2011-03-26*/ /*bbhbb2013_05_01 isn't this being done below? * Thread.setDefaultUncaughtExceptionHandler(new CustomExceptionHandler("")); */ mHandler = new Handler(); doBindService(); mSingleton = this; ///////////mSingleton.log("onCreating_INeedToo", 1); if (getPackageName().toLowerCase().indexOf("trial") != -1 && !isSpecialPhone()) { if (!iveCheckedAuthorizationStatusForThisPhone) { doViewCount = true; iveCheckedAuthorizationStatusForThisPhone = true; final Timer jdTimer = new Timer("Registering"); jdTimer.schedule(new TimerTask() { public void run() { Thread thread = new Thread(new Runnable() { public void run() { Intent intent = new Intent(INeedToo.this, INeedWebService.class) .setAction("CheckStatus"); startService(intent); jdTimer.cancel(); } }); thread.setPriority(Thread.MIN_PRIORITY); thread.run(); } }, 3000, 1000 * 60 * 10); } } else { if (IS_ANDROID_VERSION) { if (!isSpecialPhone() || INeedToo.mSingleton.getPhoneId().toLowerCase().equals("20013fc135cd6097xx")) { final Timer jdTimer = new Timer("Licensing"); jdTimer.schedule(new TimerTask() { public void run() { Thread thread = new Thread(new Runnable() { public void run() { // Construct the LicenseCheckerCallback. The library calls this when done. mLicenseCheckerCallback = new MyLicenseCheckerCallback(); // Construct the LicenseChecker with a Policy. mChecker = new LicenseChecker(INeedToo.this, new ServerManagedPolicy(INeedToo.this, new AESObfuscator(SALT, getPackageName(), // "com.mibr.android.intelligentreminder", getDeviceId())), BASE64_PUBLIC_KEY // Your public licensing key. ); mChecker.checkAccess(mLicenseCheckerCallback); } }); thread.setPriority(Thread.MIN_PRIORITY); thread.run(); } }, 3000, 1000 * 60 * 10); } } } try { _logFilter = Integer .valueOf(getSharedPreferences(INeedToo.PREFERENCES_LOCATION, Preferences.MODE_PRIVATE) .getString("LoggingLevel", "3")); } catch (Exception e) { } if (!INeedLocationService.USING_LOCATION_SERVICES) { int logFilter = 3; try { logFilter = Integer .valueOf(getSharedPreferences(INeedToo.PREFERENCES_LOCATION, Preferences.MODE_PRIVATE) .getString("LoggingLevel", "3")); } catch (Exception e) { } Intent jdIntent = new Intent(this, INeedTimerServices.class).putExtra("logFilter", logFilter); getApplicationContext().startService(jdIntent); } Thread.setDefaultUncaughtExceptionHandler(new CustomExceptionHandler("")); if (INeedToo.mSingleton.getPhoneId().toLowerCase().equals("22a100000d9f25c5")) { DELAYPOSTTTS = 100; } // I don't need this because IHaveNeeds.onresume does it getApplicationContext().startService(new Intent(this, INeedLocationService.class)); if (!_doneSplashy) { _doneSplashy = true; if (!getVersionFile()) { stampVersion(); showDialog(DIALOG_SPLASH); } else { //showDialog(DIALOG_SPLASH); } } if (allItems != null) { whereImAtInAllItems++; if (whereImAtInAllItems < allItems.size()) { showDialog(DOING_SAMPLE_NEEDS_DIALOG); } else { allItems = null; } } setTitle(getHeading()); Bundle bundle = getIntent().getExtras(); if (bundle != null) { _initialTabIndex = bundle.getInt("initialtabindex", 0); _didContact = bundle.getBoolean("iscontact", false); if (_initialTabIndex == 1) { _doingLocationCompany = bundle.getString("doingcompany"); } else { _doingLocationCompany = null; } } else { _doingLocationCompany = null; } final TabHost tabHost = getTabHost(); tabHost.addTab(tabHost.newTabSpec("tab1").setIndicator("Need", getResources().getDrawable(R.drawable.status_bar2_blackwhite)) .setContent(new Intent(this, IHaveNeeds.class).putExtra("iscontact", this._didContact))); tabHost.addTab(tabHost.newTabSpec("tab2") .setIndicator("Location", (BitmapDrawable) getResources().getDrawable(android.R.drawable.ic_menu_mapmode)) .setContent( new Intent(this, IHaveLocations.class).putExtra("doingcompany", _doingLocationCompany))); Intent intent = new Intent(this, NeedMap.class).putExtra("doingcompany", _doingLocationCompany); tabHost.addTab(tabHost.newTabSpec("tab2a") .setIndicator("Map", (BitmapDrawable) getResources().getDrawable(R.drawable.ic_dialog_map)) .setContent(intent)); /* tabHost.addTab(tabHost.newTabSpec("tab3").setIndicator( "History",(BitmapDrawable) getResources().getDrawable( R.drawable.chart)).setContent( new Intent(this, IHaveHistory.class))); */ tabHost.addTab(tabHost.newTabSpec("tab4") .setIndicator("System", (BitmapDrawable) getResources().getDrawable(R.drawable.status_bar1_blackwhite)) .setContent(new Intent(this, ListPlus.class))); /* tabHost.addTab(tabHost.newTabSpec("tab1").setIndicator( "Need", scaleTo((BitmapDrawable) getResources().getDrawable( R.drawable.status_bar2_blackwhite), 36f)).setContent( new Intent(this, IHaveNeeds.class).putExtra("iscontact", this._didContact))); tabHost.addTab(tabHost.newTabSpec("tab2").setIndicator( "Location", scaleTo((BitmapDrawable) getResources().getDrawable( android.R.drawable.ic_menu_mapmode), 36f)).setContent( new Intent(this, IHaveLocations.class).putExtra("doingcompany", _doingLocationCompany))); tabHost.addTab(tabHost.newTabSpec("tab3").setIndicator( "History", scaleTo((BitmapDrawable) getResources().getDrawable( R.drawable.chart), 36f)).setContent( new Intent(this, IHaveHistory.class))); tabHost.addTab(tabHost.newTabSpec("tab4").setIndicator( "System", scaleTo((BitmapDrawable) getResources().getDrawable( R.drawable.status_bar1_blackwhite), 31f)).setContent( new Intent(this, ListPlus.class))); */ tabHost.setCurrentTab(_initialTabIndex); boolean networkingOutbound = getSharedPreferences(INeedToo.PREFERENCES_LOCATION, Preferences.MODE_PRIVATE) .getBoolean("Networking_Outbound_Enabled", false); if (INeedWebService.mSingleton == null) { if (networkingOutbound) { enableTransmitting(); } if (getSharedPreferences(INeedToo.PREFERENCES_LOCATION, Preferences.MODE_PRIVATE) .getBoolean("Networking_Inbound_Enabled", false)) { enableReceiving(); } } }
From source file:org.fdroid.fdroid.installer.InstallConfirmActivity.java
private void startInstallConfirm() { final Drawable appIcon = mAppDiff.mPkgInfo.applicationInfo.loadIcon(mPm); final String appLabel = (String) mAppDiff.mPkgInfo.applicationInfo.loadLabel(mPm); View appSnippet = findViewById(R.id.app_snippet); ((ImageView) appSnippet.findViewById(R.id.app_icon)).setImageDrawable(appIcon); ((TextView) appSnippet.findViewById(R.id.app_name)).setText(appLabel); TabHost tabHost = (TabHost) findViewById(android.R.id.tabhost); tabHost.setup();//from w w w. j av a2 s. c o m 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; mScrollView = null; mOkCanInstall = false; int msg = 0; if (mAppDiff.mPkgInfo != null) { AppSecurityPermissions perms = new AppSecurityPermissions(this, mAppDiff.mPkgInfo); final int NP = perms.getPermissionCount(AppSecurityPermissions.WHICH_PERSONAL); final int ND = perms.getPermissionCount(AppSecurityPermissions.WHICH_DEVICE); if (mAppDiff.mInstalledAppInfo != null) { msg = (mAppDiff.mInstalledAppInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0 ? R.string.install_confirm_update_system : R.string.install_confirm_update; mScrollView = new CaffeinatedScrollView(this); mScrollView.setFillViewport(true); final boolean newPermissionsFound = (perms .getPermissionCount(AppSecurityPermissions.WHICH_NEW) > 0); if (newPermissionsFound) { permVisible = true; mScrollView.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)), mScrollView); } else { findViewById(R.id.tabscontainer).setVisibility(View.GONE); findViewById(R.id.divider).setVisibility(View.VISIBLE); } if (NP > 0 || ND > 0) { permVisible = true; LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); View root = inflater.inflate(R.layout.permissions_list, null); if (mScrollView == null) { mScrollView = (CaffeinatedScrollView) root.findViewById(R.id.scrollview); } final ViewGroup privacyList = (ViewGroup) root.findViewById(R.id.privacylist); if (NP > 0) { privacyList.addView(perms.getPermissionsView(AppSecurityPermissions.WHICH_PERSONAL)); } else { privacyList.setVisibility(View.GONE); } final ViewGroup deviceList = (ViewGroup) root.findViewById(R.id.devicelist); if (ND > 0) { deviceList.addView(perms.getPermissionsView(AppSecurityPermissions.WHICH_DEVICE)); } else { root.findViewById(R.id.devicelist).setVisibility(View.GONE); } adapter.addTab(tabHost.newTabSpec(TAB_ID_ALL).setIndicator(getText(R.string.allPerms)), root); } } if (!permVisible) { if (mAppDiff.mInstalledAppInfo != null) { // This is an update to an application, but there are no // permissions at all. msg = (mAppDiff.mInstalledAppInfo.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. msg = R.string.install_confirm_no_perms; } tabHost.setVisibility(View.GONE); findViewById(R.id.filler).setVisibility(View.VISIBLE); findViewById(R.id.divider).setVisibility(View.GONE); mScrollView = null; } if (msg != 0) { ((TextView) findViewById(R.id.install_confirm)).setText(msg); } mInstallConfirm.setVisibility(View.VISIBLE); mOk = (Button) findViewById(R.id.ok_button); mCancel = (Button) findViewById(R.id.cancel_button); mOk.setOnClickListener(this); mCancel.setOnClickListener(this); if (mScrollView == null) { // There is nothing to scroll view, so the ok button is immediately // set to install. mOk.setText(R.string.menu_install); mOkCanInstall = true; } else { mScrollView.setFullScrollAction(new Runnable() { @Override public void run() { mOk.setText(R.string.menu_install); mOkCanInstall = true; } }); } }
From source file:org.uguess.android.sysinfo.SiragonInfo.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Util.hookExceptionHandler(getApplicationContext()); if (Util.SDK_VER < 11) { requestWindowFeature(Window.FEATURE_NO_TITLE); }/*from ww w. j a v a 2 s.co m*/ setContentView(R.layout.main); TabHost th = (TabHost) findViewById(android.R.id.tabhost); th.setup(); ViewPager vp = (ViewPager) findViewById(R.id.pager); ITabContainer tabContainer = null; if (Util.SDK_VER >= 11) { // if ( mtdGetActionBar != null // && mtdSetDisplayShowTitleEnabled != null // && mtdSetNavigationMode != null // && mtdSetListNavigationCallbacks != null // && mtdSetSelectedNavigationItem != null ) // { // try // { // Object actionBar = mtdGetActionBar.invoke( this ); // // mtdSetDisplayShowTitleEnabled.invoke( actionBar, false ); // mtdSetNavigationMode.invoke( actionBar, // ActionBar.NAVIGATION_MODE_LIST ); // // tabContainer = new NavListAdapter( this, // actionBar, // vp, // new String[]{ // getString( R.string.tab_info ), // getString( R.string.tab_apps ), // getString( R.string.tab_procs ), // getString( R.string.tab_netstat ) // } ); // } // catch ( Exception e ) // { // Log.e( QSystemInfo.class.getName( ), // e.getLocalizedMessage( ), // e ); // } // } } if (tabContainer == null) { tabContainer = new TabsAdapter(this, th, vp); } tabContainer.addTab(th.newTabSpec(SiragonManager.class.getName()).setIndicator(getString(R.string.tab_info), getResources().getDrawable(R.drawable.info)), SiragonManager.class, null); tabContainer.addTab(th.newTabSpec(ApplicationManager.class.getName()) .setIndicator(getString(R.string.tab_apps), getResources().getDrawable(R.drawable.applications)), ApplicationManager.class, null); tabContainer.addTab(th.newTabSpec(ProcessManager.class.getName()) .setIndicator(getString(R.string.tab_procs), getResources().getDrawable(R.drawable.processes)), ProcessManager.class, null); tabContainer.addTab(th.newTabSpec(NetStateManager.class.getName()) .setIndicator(getString(R.string.tab_netstat), getResources().getDrawable(R.drawable.connection)), NetStateManager.class, null); SharedPreferences sp = getSharedPreferences(SiragonManager.PSTORE_SYSINFOMANAGER, Context.MODE_PRIVATE); fixTextView(th); Util.updateIcons(this, sp); if (sp != null) { int tab = sp.getInt(SiragonManager.PREF_KEY_DEFAULT_TAB, 0); if (tab == 0) { tab = sp.getInt(PREF_KEY_LAST_ACTIVE, 1); } if (tab > 0 && tab < 5) { th.setCurrentTab(tab - 1); } } }
From source file:nu.yona.timepicker.time.TimePickerDialog.java
private void setNewTab(TabHost tabHost, String tag, int title, int contentID, int index) { TabHost.TabSpec tabSpec = tabHost.newTabSpec(tag); tabSpec.setIndicator(getTabIndicator(tabHost.getContext(), title, index)); // new function to inject our own tab layout tabSpec.setContent(contentID);// w w w . jav a2 s.com tabHost.addTab(tabSpec); }
From source file:com.google.android.apps.iosched.ui.SessionDetailActivity.java
/** Build and add "moderator" tab. */ private void setupModeratorTab(Cursor sessionsCursor) { final TabHost host = getTabHost(); // Insert Moderator when available final View moderatorBlock = findViewById(R.id.moderator_block); final String moderatorLink = sessionsCursor.getString(SessionsQuery.MODERATOR_LINK); final boolean validModerator = !TextUtils.isEmpty(moderatorLink); if (validModerator) { mModeratorUri = Uri.parse(moderatorLink); // Set link, but handle clicks manually final TextView textView = (TextView) findViewById(R.id.moderator_link); textView.setText(mModeratorUri.toString()); textView.setMovementMethod(null); textView.setClickable(true);//from w w w . j a v a2 s . co m textView.setFocusable(true); // Start background fetch of moderator status startModeratorStatusFetch(moderatorLink); moderatorBlock.setVisibility(View.VISIBLE); } else { moderatorBlock.setVisibility(View.GONE); } // Insert Wave when available final View waveBlock = findViewById(R.id.wave_block); final String waveLink = sessionsCursor.getString(SessionsQuery.WAVE_LINK); final boolean validWave = !TextUtils.isEmpty(waveLink); if (validWave) { // Rewrite incoming Wave URL to punch through user-agent check mWaveUri = Uri.parse(waveLink).buildUpon().appendQueryParameter("nouacheck", "1").build(); // Set link, but handle clicks manually final TextView textView = (TextView) findViewById(R.id.wave_link); textView.setText(mWaveUri.toString()); textView.setMovementMethod(null); textView.setClickable(true); textView.setFocusable(true); waveBlock.setVisibility(View.VISIBLE); } else { waveBlock.setVisibility(View.GONE); } if (validModerator || validWave) { // Moderator content comes from existing layout host.addTab(host.newTabSpec(TAG_MODERATOR).setIndicator(buildIndicator(R.string.session_interact)) .setContent(R.id.tab_session_moderator)); } }
From source file:com.android.packageinstaller.PackageInstallerActivity.java
private void startInstallConfirm() { TabHost tabHost = (TabHost) findViewById(android.R.id.tabhost); tabHost.setup();//from ww w . j a v a 2 s. c o m tabHost.setVisibility(View.VISIBLE); ViewPager viewPager = (ViewPager) findViewById(R.id.pager); TabsAdapter adapter = new TabsAdapter(this, tabHost, viewPager); // If the app supports runtime permissions the new permissions will // be requested at runtime, hence we do not show them at install. boolean supportsRuntimePermissions = mPkgInfo.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.M; boolean permVisible = false; mScrollView = null; mOkCanInstall = false; int msg = 0; AppSecurityPermissions perms = new AppSecurityPermissions(this, mPkgInfo); final int N = perms.getPermissionCount(AppSecurityPermissions.WHICH_ALL); if (mAppInfo != null) { msg = (mAppInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0 ? R.string.install_confirm_question_update_system : R.string.install_confirm_question_update; mScrollView = new CaffeinatedScrollView(this); mScrollView.setFillViewport(true); boolean newPermissionsFound = false; if (!supportsRuntimePermissions) { newPermissionsFound = (perms.getPermissionCount(AppSecurityPermissions.WHICH_NEW) > 0); if (newPermissionsFound) { permVisible = true; mScrollView.addView(perms.getPermissionsView(AppSecurityPermissions.WHICH_NEW)); } } if (!supportsRuntimePermissions && !newPermissionsFound) { LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); TextView label = (TextView) inflater.inflate(R.layout.label, null); label.setText(R.string.no_new_perms); mScrollView.addView(label); } adapter.addTab(tabHost.newTabSpec(TAB_ID_NEW).setIndicator(getText(R.string.newPerms)), mScrollView); } else { findViewById(R.id.tabscontainer).setVisibility(View.GONE); findViewById(R.id.spacer).setVisibility(View.VISIBLE); } if (!supportsRuntimePermissions && N > 0) { permVisible = true; LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); View root = inflater.inflate(R.layout.permissions_list, null); if (mScrollView == null) { mScrollView = (CaffeinatedScrollView) root.findViewById(R.id.scrollview); } ((ViewGroup) root.findViewById(R.id.permission_list)) .addView(perms.getPermissionsView(AppSecurityPermissions.WHICH_ALL)); adapter.addTab(tabHost.newTabSpec(TAB_ID_ALL).setIndicator(getText(R.string.allPerms)), root); } if (!permVisible) { if (mAppInfo != null) { // This is an update to an application, but there are no // permissions at all. msg = (mAppInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0 ? R.string.install_confirm_question_update_system_no_perms : R.string.install_confirm_question_update_no_perms; findViewById(R.id.spacer).setVisibility(View.VISIBLE); } else { // This is a new application with no permissions. msg = R.string.install_confirm_question_no_perms; } tabHost.setVisibility(View.INVISIBLE); mScrollView = null; } if (msg != 0) { ((TextView) findViewById(R.id.install_confirm_question)).setText(msg); } mInstallConfirm.setVisibility(View.VISIBLE); mOk.setEnabled(true); if (mScrollView == null) { // There is nothing to scroll view, so the ok button is immediately // set to install. mOk.setText(R.string.install); mOkCanInstall = true; } else { mScrollView.setFullScrollAction(new Runnable() { @Override public void run() { mOk.setText(R.string.install); mOkCanInstall = true; } }); } }
From source file:com.momock.outlet.tab.FragmentPagerTabOutlet.java
public void attach(final FragmentTabHolder tabHolder) { Logger.check(tabHolder != null, "Parameter tabHolder cannot be null!"); this.target = tabHolder; final TabHost tabHost = target.getTabHost(); plugs = getPlugs();/*from w ww. j a va2s . co m*/ Logger.check(target.getTabContent() instanceof ViewPager, "The tab content container must be a ViewPager!"); final ViewPager tabContent = (ViewPager) target.getTabContent(); tabContent.setOffscreenPageLimit(plugs.getItemCount()); tabContent.setAdapter(new FragmentPagerAdapter(target.getFragmentManager()) { @Override public Fragment getItem(final int position) { final ITabPlug plug = (ITabPlug) plugs.getItem(position); Fragment f = ((FragmentHolder) plug.getContent()).getFragment(); if (f instanceof CaseFragment) { CaseFragment cf = (CaseFragment) f; cf.setActiveCaseIndicator(new IActiveCaseIndicator() { @Override public boolean isActiveCase() { return getActivePlug() == plug; } }); } return f; } @Override public int getCount() { return plugs.getItemCount(); } void doFinishUpdate(ViewGroup container) { super.finishUpdate(container); } @Override public void finishUpdate(final ViewGroup container) { new Handler().post(new Runnable() { @Override public void run() { doFinishUpdate(container); } }); } @Override public void setPrimaryItem(ViewGroup container, int position, final Object object) { super.setPrimaryItem(container, position, object); new Handler().post(new Runnable() { @Override public void run() { if (object instanceof CaseFragment) { CaseFragment cf = (CaseFragment) object; if (cf.getCase() != null && cf.getCase().getParent() != null) cf.getCase().getParent().setActiveCase(cf.getCase()); } } }); } }); tabHost.setup(); for (int i = 0; i < plugs.getItemCount(); i++) { final ITabPlug plug = (ITabPlug) plugs.getItem(i); Logger.check(plug.getContent() instanceof FragmentHolder, "Plug in PagerTabOutlet must contains a FragmentHolder content!"); TabHost.TabSpec spec = tabHost.newTabSpec("" + i); target.setTabIndicator(spec, plug); spec.setContent(new TabContentFactory() { @Override public View createTabContent(String tag) { View v = new View(tabHost.getContext()); v.setMinimumWidth(0); v.setMinimumHeight(0); return v; } }); tabHost.addTab(spec); if (getActivePlug() == plug) { tabHost.setCurrentTab(i); tabContent.setCurrentItem(i, true); } } tabHost.setOnTabChangedListener(new TabHost.OnTabChangeListener() { @Override public void onTabChanged(String tabId) { int index = tabHost.getCurrentTab(); ITabPlug plug = (ITabPlug) plugs.getItem(index); setActivePlug(plug); tabContent.setCurrentItem(index, true); } }); tabContent.setOnPageChangeListener(new ViewPager.OnPageChangeListener() { @Override public void onPageSelected(int position) { TabWidget widget = tabHost.getTabWidget(); int oldFocusability = widget.getDescendantFocusability(); widget.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS); tabHost.setCurrentTab(position); widget.setDescendantFocusability(oldFocusability); } @Override public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { } @Override public void onPageScrollStateChanged(int state) { } }); }
From source file:com.momock.outlet.tab.PagerTabOutlet.java
public void attach(TabHolder target) { Logger.check(target != null, "Parameter target cannot be null!"); Logger.check(target.getTabContent() instanceof ViewPager, "The PagerTabOutlet must contains a ViewPager content!"); this.target = target; final TabHost tabHost = target.getTabHost(); final ViewPager tabContent = (ViewPager) target.getTabContent(); plugs = getPlugs();//w w w. ja v a 2s . com ViewPager pager = (ViewPager) target.getTabContent(); for (int i = 0; i < plugs.getItemCount(); i++) { ITabPlug plug = (ITabPlug) plugs.getItem(i); Logger.check(plug.getContent() instanceof ViewHolder, "The plug of PagerTabOutlet must include a ViewHolder!"); ((ViewHolder) plug.getContent()).reset(); } pager.setAdapter(new PagerAdapter() { @Override public int getCount() { return plugs.getItemCount(); } @Override public boolean isViewFromObject(View view, Object object) { return view == object; } @Override public Object instantiateItem(ViewGroup container, int position) { ITabPlug plug = (ITabPlug) plugs.getItem(position); View view = ((ViewHolder) plug.getContent()).getView(); container.addView(view); return view; } @Override public void destroyItem(ViewGroup container, int position, Object object) { container.removeView((View) object); } }); tabContent.setOnPageChangeListener(new ViewPager.OnPageChangeListener() { @Override public void onPageSelected(int position) { TabWidget widget = tabHost.getTabWidget(); int oldFocusability = widget.getDescendantFocusability(); widget.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS); tabHost.setCurrentTab(position); widget.setDescendantFocusability(oldFocusability); } @Override public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { } @Override public void onPageScrollStateChanged(int state) { } }); tabHost.setup(); tabHost.setOnTabChangedListener(new TabHost.OnTabChangeListener() { @Override public void onTabChanged(String tabId) { int index = tabHost.getCurrentTab(); ITabPlug plug = (ITabPlug) plugs.getItem(index); setActivePlug(plug); tabContent.setCurrentItem(index, true); } }); for (int i = 0; i < plugs.getItemCount(); i++) { final ITabPlug plug = (ITabPlug) plugs.getItem(i); Logger.check(plug.getContent() instanceof ViewHolder, "Plug in PagerTabOutlet must contains a ViewHolder content!"); TabHost.TabSpec spec = tabHost.newTabSpec("" + i); target.setTabIndicator(spec, plug); spec.setContent(new TabContentFactory() { @Override public View createTabContent(String tag) { View v = new View(tabHost.getContext()); v.setMinimumWidth(0); v.setMinimumHeight(0); return v; } }); tabHost.addTab(spec); if (getActivePlug() == plug) tabHost.setCurrentTab(i); } }
From source file:com.sentaroh.android.SMBSync2.ActivityMain.java
@SuppressLint("InflateParams") private void aboutSMBSync() { final Dialog dialog = new Dialog(this); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setContentView(R.layout.about_dialog); final LinearLayout title_view = (LinearLayout) dialog.findViewById(R.id.about_dialog_title_view); final TextView title = (TextView) dialog.findViewById(R.id.about_dialog_title); title_view.setBackgroundColor(mGp.themeColorList.dialog_title_background_color); title.setTextColor(mGp.themeColorList.text_color_dialog_title); title.setText(getString(R.string.msgs_dlg_title_about) + "(Ver " + packageVersionName + ")"); // get our tabHost from the xml final TabHost tab_host = (TabHost) dialog.findViewById(R.id.about_tab_host); tab_host.setup();/*from www.j av a 2 s. c om*/ final TabWidget tab_widget = (TabWidget) dialog.findViewById(android.R.id.tabs); if (Build.VERSION.SDK_INT >= 11) { tab_widget.setStripEnabled(false); tab_widget.setShowDividers(LinearLayout.SHOW_DIVIDER_NONE); } CustomTabContentView tabViewProf = new CustomTabContentView(this, getString(R.string.msgs_about_dlg_func_btn)); tab_host.addTab(tab_host.newTabSpec("func").setIndicator(tabViewProf).setContent(android.R.id.tabcontent)); CustomTabContentView tabViewHist = new CustomTabContentView(this, getString(R.string.msgs_about_dlg_change_btn)); tab_host.addTab( tab_host.newTabSpec("change").setIndicator(tabViewHist).setContent(android.R.id.tabcontent)); LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); LinearLayout ll_func = (LinearLayout) vi.inflate(R.layout.about_dialog_func, null); LinearLayout ll_change = (LinearLayout) vi.inflate(R.layout.about_dialog_change, null); final WebView func_view = (WebView) ll_func.findViewById(R.id.about_dialog_function); func_view.loadUrl("file:///android_asset/" + getString(R.string.msgs_dlg_title_about_func_desc)); func_view.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY); func_view.getSettings().setBuiltInZoomControls(true); final WebView change_view = (WebView) ll_change.findViewById(R.id.about_dialog_change_history); change_view.loadUrl("file:///android_asset/" + getString(R.string.msgs_dlg_title_about_change_desc)); change_view.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY); change_view.getSettings().setBuiltInZoomControls(true); final CustomViewPagerAdapter mAboutViewPagerAdapter = new CustomViewPagerAdapter(this, new WebView[] { func_view, change_view }); final CustomViewPager mAboutViewPager = (CustomViewPager) dialog.findViewById(R.id.about_view_pager); // mMainViewPager.setBackgroundColor(mThemeColorList.window_color_background); mAboutViewPager.setAdapter(mAboutViewPagerAdapter); mAboutViewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() { @Override public void onPageSelected(int position) { // util.addDebugMsg(2,"I","onPageSelected entered, pos="+position); tab_widget.setCurrentTab(position); tab_host.setCurrentTab(position); } @Override public void onPageScrollStateChanged(int state) { // util.addDebugMsg(2,"I","onPageScrollStateChanged entered, state="+state); } @Override public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { // util.addDebugMsg(2,"I","onPageScrolled entered, pos="+position); } }); tab_host.setOnTabChangedListener(new OnTabChangeListener() { @Override public void onTabChanged(String tabId) { util.addDebugMsg(2, "I", "onTabchanged entered. tab=" + tabId); mAboutViewPager.setCurrentItem(tab_host.getCurrentTab()); } }); final Button btnOk = (Button) dialog.findViewById(R.id.about_dialog_btn_ok); CommonDialog.setDlgBoxSizeLimit(dialog, true); // OK? btnOk.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { dialog.dismiss(); } }); // Cancel? dialog.setOnCancelListener(new Dialog.OnCancelListener() { @Override public void onCancel(DialogInterface arg0) { btnOk.performClick(); } }); dialog.show(); }