List of usage examples for android.widget TabHost addTab
public void addTab(TabSpec tabSpec)
From source file:eu.operando.operandoapp.OperandoProxyStatus.java
@Override protected void onCreate(Bundle savedInstanceState) { MainUtil.initializeMainContext(getApplicationContext()); Settings settings = mainContext.getSettings(); settings.initializeDefaultValues();/*from w ww . ja v a 2 s .c om*/ setCurrentThemeStyle(settings.getThemeStyle()); setTheme(getCurrentThemeStyle().themeAppCompatStyle()); super.onCreate(savedInstanceState); setContentView(R.layout.main_activity); settings.registerOnSharedPreferenceChangeListener(this); webView = (WebView) findViewById(R.id.webView); webView.getSettings().setJavaScriptEnabled(true); //region Floating Action Button fab = (FloatingActionButton) findViewById(R.id.fab); fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (MainUtil.isServiceRunning(mainContext.getContext(), ProxyService.class) && !MainUtil.isProxyPaused(mainContext)) { //Update Preferences to BypassProxy MainUtil.setProxyPaused(mainContext, true); fab.setImageResource(android.R.drawable.ic_media_play); //Toast.makeText(mainContext.getContext(), "-- bypass (disable) proxy --", Toast.LENGTH_SHORT).show(); } else if (MainUtil.isServiceRunning(mainContext.getContext(), ProxyService.class) && MainUtil.isProxyPaused(mainContext)) { MainUtil.setProxyPaused(mainContext, false); fab.setImageResource(android.R.drawable.ic_media_pause); //Toast.makeText(mainContext.getContext(), "-- re-enable proxy --", Toast.LENGTH_SHORT).show(); } else if (!mainContext.getAuthority() .aliasFile(BouncyCastleSslEngineSource.KEY_STORE_FILE_EXTENSION).exists()) { try { installCert(); } catch (RootCertificateException | GeneralSecurityException | OperatorCreationException | IOException ex) { Logger.error(this, ex.getMessage(), ex.getCause()); } } } }); //endregion //region TabHost final TabHost tabHost = (TabHost) findViewById(R.id.tabHost2); tabHost.setup(); TabHost.TabSpec tabSpec = tabHost.newTabSpec("wifi_ap"); tabSpec.setContent(R.id.WifiAndAccessPointsScrollView); tabSpec.setIndicator("", getResources().getDrawable(R.drawable.ic_home)); tabHost.addTab(tabSpec); tabSpec = tabHost.newTabSpec("response_domain_filters"); tabSpec.setContent(R.id.ResponseAndDomainFiltersScrollView); tabSpec.setIndicator("", getResources().getDrawable(R.drawable.ic_filter)); tabHost.addTab(tabSpec); tabSpec = tabHost.newTabSpec("pending_notifications"); tabSpec.setContent(R.id.PendingNotificationsScrollView); tabSpec.setIndicator("", getResources().getDrawable(R.drawable.ic_pending_notification)); tabHost.addTab(tabSpec); tabSpec = tabHost.newTabSpec("logs"); tabSpec.setContent(R.id.LogsScrollView); tabSpec.setIndicator("", getResources().getDrawable(R.drawable.ic_report)); tabHost.addTab(tabSpec); tabHost.setOnTabChangedListener(new TabHost.OnTabChangeListener() { @Override public void onTabChanged(String tabId) { switch (tabId) { case "pending_notifications": //region Load Tab3 ((TableLayout) ((LinearLayout) ((ScrollView) findViewById(R.id.PendingNotificationsScrollView)) .getChildAt(0)).getChildAt(1)).removeAllViews(); LoadPendingNotificationsTab(); //endregion break; case "logs": //region Load Tab 4 //because it is a heavy task it is being loaded asynchronously ((TableLayout) ((LinearLayout) ((ScrollView) findViewById(R.id.LogsScrollView)).getChildAt(0)) .getChildAt(1)).removeAllViews(); new AsyncTask() { private ProgressDialog mProgress; private List<String[]> apps; @Override protected void onPreExecute() { super.onPreExecute(); mProgress = new ProgressDialog(MainActivity.this); mProgress.setCancelable(false); mProgress.setCanceledOnTouchOutside(false); mProgress.setTitle("Fetching Application Data Logs"); mProgress.show(); } @Override protected Object doInBackground(Object[] params) { apps = new ArrayList(); for (String[] app : getInstalledApps(false)) { apps.add(new String[] { app[0], GetDataForApp(Integer.parseInt(app[1])) }); } return null; } @Override protected void onPostExecute(Object o) { super.onPostExecute(o); mProgress.dismiss(); for (String[] app : apps) { if (app[0].contains(".")) { continue; } TextView tv = new TextView(MainActivity.this); tv.setTextSize(18); tv.setText(app[0] + " || " + app[1]); ((TableLayout) ((LinearLayout) ((ScrollView) findViewById(R.id.LogsScrollView)) .getChildAt(0)).getChildAt(1)).addView(tv); View separator = new View(MainActivity.this); separator.setBackgroundColor(Color.BLACK); separator.setLayoutParams( new TableRow.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 5)); ((TableLayout) ((LinearLayout) ((ScrollView) findViewById(R.id.LogsScrollView)) .getChildAt(0)).getChildAt(1)).addView(separator); } } }.execute(); //endregion break; } } }); //endregion //region Buttons WiFiAPButton = (Button) findViewById(R.id.WiFiAPButton); WiFiAPButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub Intent i = new Intent(mainContext.getContext(), AccessPointsActivity.class); startActivity(i); } }); responseFiltersButton = (Button) findViewById(R.id.responseFiltersButton); responseFiltersButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent i = new Intent(mainContext.getContext(), ResponseFiltersActivity.class); startActivity(i); } }); domainFiltersButton = (Button) findViewById(R.id.domainFiltersButton); domainFiltersButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent i = new Intent(mainContext.getContext(), DomainFiltersActivity.class); startActivity(i); } }); domainManagerButton = (Button) findViewById(R.id.domainManagerButton); domainManagerButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent i = new Intent(mainContext.getContext(), DomainManagerActivity.class); startActivity(i); } }); permissionsPerDomainButton = (Button) findViewById(R.id.permissionsPerDomainButton); permissionsPerDomainButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent i = new Intent(mainContext.getContext(), PermissionsPerDomainActivity.class); startActivity(i); } }); trustedAccessPointsButton = (Button) findViewById(R.id.trustedAccessPointsButton); trustedAccessPointsButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent i = new Intent(mainContext.getContext(), TrustedAccessPointsActivity.class); startActivity(i); } }); updateButton = (Button) findViewById(R.id.updateButton); updateButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // mark first time has not runned and update like it's initial . final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(MainActivity.this); SharedPreferences.Editor editor = prefs.edit(); editor.putBoolean("firstTime", true); editor.commit(); DownloadInitialSettings(); } }); statisticsButton = (Button) findViewById(R.id.statisticsButton); statisticsButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent i = new Intent(mainContext.getContext(), StatisticsActivity.class); startActivity(i); } }); //endregion //region Action Bar Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); ActionBar actionBar = getSupportActionBar(); if (actionBar != null) { setTitle(R.string.app_name); } //endregion //region Send Cached Settings //send cached settings if exist... BufferedReader br = null; try { File file = new File(MainContext.INSTANCE.getContext().getFilesDir(), "resend.inf"); StringBuilder content = new StringBuilder(); br = new BufferedReader(new FileReader(file)); String line; while ((line = br.readLine()) != null) { content.append(line); } if (content.toString().equals("1")) { File f = new File(file.getCanonicalPath()); f.delete(); new DatabaseHelper(MainActivity.this) .sendSettingsToServer(new RequestFilterUtil(MainActivity.this).getIMEI()); } } catch (Exception ex) { ex.getMessage(); } finally { try { br.close(); } catch (Exception ex) { ex.getMessage(); } } //endregion initializeProxyService(); }
From source file:com.example.android.mediarouter.player.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { // Be sure to call the super class. super.onCreate(savedInstanceState); if (savedInstanceState != null) { mPlayer = (Player) savedInstanceState.getSerializable("mPlayer"); }/* w ww. j a v a 2 s. c o m*/ // Get the media router service. mMediaRouter = MediaRouter.getInstance(this); // Create a route selector for the type of routes that we care about. mSelector = new MediaRouteSelector.Builder().addControlCategory(MediaControlIntent.CATEGORY_LIVE_AUDIO) .addControlCategory(MediaControlIntent.CATEGORY_LIVE_VIDEO) .addControlCategory(MediaControlIntent.CATEGORY_REMOTE_PLAYBACK) .addControlCategory(SampleMediaRouteProvider.CATEGORY_SAMPLE_ROUTE).build(); // Add a fragment to take care of media route discovery. // This fragment automatically adds or removes a callback whenever the activity // is started or stopped. FragmentManager fm = getSupportFragmentManager(); DiscoveryFragment fragment = (DiscoveryFragment) fm.findFragmentByTag(DISCOVERY_FRAGMENT_TAG); if (fragment == null) { fragment = new DiscoveryFragment(mMediaRouterCB); fragment.setRouteSelector(mSelector); fm.beginTransaction().add(fragment, DISCOVERY_FRAGMENT_TAG).commit(); } else { fragment.setCallback(mMediaRouterCB); fragment.setRouteSelector(mSelector); } // Populate an array adapter with streaming media items. String[] mediaNames = getResources().getStringArray(R.array.media_names); String[] mediaUris = getResources().getStringArray(R.array.media_uris); mLibraryItems = new LibraryAdapter(); for (int i = 0; i < mediaNames.length; i++) { mLibraryItems.add(new MediaItem("[streaming] " + mediaNames[i], Uri.parse(mediaUris[i]), "video/mp4")); } // Scan local external storage directory for media files. File externalDir = Environment.getExternalStorageDirectory(); if (externalDir != null) { File list[] = externalDir.listFiles(); if (list != null) { for (int i = 0; i < list.length; i++) { String filename = list[i].getName(); if (filename.matches(".*\\.(m4v|mp4)")) { mLibraryItems.add(new MediaItem("[local] " + filename, Uri.fromFile(list[i]), "video/mp4")); } } } } mPlayListItems = new PlaylistAdapter(); // Initialize the layout. setContentView(R.layout.sample_media_router); TabHost tabHost = (TabHost) findViewById(R.id.tabHost); tabHost.setup(); String tabName = getResources().getString(R.string.library_tab_text); TabSpec spec1 = tabHost.newTabSpec(tabName); spec1.setContent(R.id.tab1); spec1.setIndicator(tabName); tabName = getResources().getString(R.string.playlist_tab_text); TabSpec spec2 = tabHost.newTabSpec(tabName); spec2.setIndicator(tabName); spec2.setContent(R.id.tab2); tabName = getResources().getString(R.string.statistics_tab_text); TabSpec spec3 = tabHost.newTabSpec(tabName); spec3.setIndicator(tabName); spec3.setContent(R.id.tab3); tabHost.addTab(spec1); tabHost.addTab(spec2); tabHost.addTab(spec3); tabHost.setOnTabChangedListener(new OnTabChangeListener() { @Override public void onTabChanged(String arg0) { updateUi(); } }); mLibraryView = (ListView) findViewById(R.id.media); mLibraryView.setAdapter(mLibraryItems); mLibraryView.setChoiceMode(ListView.CHOICE_MODE_SINGLE); mLibraryView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { updateButtons(); } }); mPlayListView = (ListView) findViewById(R.id.playlist); mPlayListView.setAdapter(mPlayListItems); mPlayListView.setChoiceMode(ListView.CHOICE_MODE_SINGLE); mPlayListView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { updateButtons(); } }); mInfoTextView = (TextView) findViewById(R.id.info); mPauseResumeButton = (ImageButton) findViewById(R.id.pause_resume_button); mPauseResumeButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { mPaused = !mPaused; if (mPaused) { mSessionManager.pause(); } else { mSessionManager.resume(); } } }); mStopButton = (ImageButton) findViewById(R.id.stop_button); mStopButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { mPaused = false; mSessionManager.stop(); } }); mSeekBar = (SeekBar) findViewById(R.id.seekbar); mSeekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { PlaylistItem item = getCheckedPlaylistItem(); if (fromUser && item != null && item.getDuration() > 0) { long pos = progress * item.getDuration() / 100; mSessionManager.seek(item.getItemId(), pos); item.setPosition(pos); item.setTimestamp(SystemClock.elapsedRealtime()); } } @Override public void onStartTrackingTouch(SeekBar seekBar) { mSeeking = true; } @Override public void onStopTrackingTouch(SeekBar seekBar) { mSeeking = false; updateUi(); } }); // Schedule Ui update mHandler.postDelayed(mUpdateSeekRunnable, 1000); // Build the PendingIntent for the remote control client mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); mEventReceiver = new ComponentName(getPackageName(), SampleMediaButtonReceiver.class.getName()); Intent mediaButtonIntent = new Intent(Intent.ACTION_MEDIA_BUTTON); mediaButtonIntent.setComponent(mEventReceiver); mMediaPendingIntent = PendingIntent.getBroadcast(this, 0, mediaButtonIntent, 0); // Create and register the remote control client registerRemoteControlClient(); // Set up playback manager and player mPlayer = Player.create(MainActivity.this, mMediaRouter.getSelectedRoute()); mSessionManager.setPlayer(mPlayer); mSessionManager.setCallback(new SessionManager.Callback() { @Override public void onStatusChanged() { updateUi(); } @Override public void onItemChanged(PlaylistItem item) { } }); updateUi(); }
From source file:com.example.android.mediarouter.player.RadioActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { // Be sure to call the super class. super.onCreate(savedInstanceState); if (savedInstanceState != null) { mPlayer = (RadioPlayer) savedInstanceState.getSerializable("mPlayer"); }/* w w w .j av a2s .c o m*/ // Get the media router service. mMediaRouter = MediaRouter.getInstance(this); // Create a route selector for the type of routes that we care about. mSelector = new MediaRouteSelector.Builder().addControlCategory(MediaControlIntent.CATEGORY_LIVE_AUDIO) .addControlCategory(MediaControlIntent.CATEGORY_LIVE_VIDEO) .addControlCategory(MediaControlIntent.CATEGORY_REMOTE_PLAYBACK) .addControlCategory(SampleMediaRouteProvider.CATEGORY_SAMPLE_ROUTE).build(); // Add a fragment to take care of media route discovery. // This fragment automatically adds or removes a callback whenever the activity // is started or stopped. FragmentManager fm = getSupportFragmentManager(); DiscoveryFragment fragment = (DiscoveryFragment) fm.findFragmentByTag(DISCOVERY_FRAGMENT_TAG); if (fragment == null) { fragment = new DiscoveryFragment(mMediaRouterCB); fragment.setRouteSelector(mSelector); fm.beginTransaction().add(fragment, DISCOVERY_FRAGMENT_TAG).commit(); } else { fragment.setCallback(mMediaRouterCB); fragment.setRouteSelector(mSelector); } // Populate an array adapter with streaming media items. String[] mediaNames = getResources().getStringArray(R.array.media_names); String[] mediaUris = getResources().getStringArray(R.array.media_uris); mLibraryItems = new LibraryAdapter(); for (int i = 0; i < mediaNames.length; i++) { mLibraryItems.add(new MediaItem("[streaming] " + mediaNames[i], Uri.parse(mediaUris[i]), "video/mp4")); } // Scan local external storage directory for media files. File externalDir = Environment.getExternalStorageDirectory(); if (externalDir != null) { File list[] = externalDir.listFiles(); if (list != null) { for (int i = 0; i < list.length; i++) { String filename = list[i].getName(); if (filename.matches(".*\\.(m4v|mp4)")) { mLibraryItems.add(new MediaItem("[local] " + filename, Uri.fromFile(list[i]), "video/mp4")); } } } } mPlayListItems = new PlaylistAdapter(); // Initialize the layout. setContentView(R.layout.sample_radio_router); TabHost tabHost = (TabHost) findViewById(R.id.tabHost); tabHost.setup(); String tabName = getResources().getString(R.string.library_tab_text); TabSpec spec1 = tabHost.newTabSpec(tabName); spec1.setContent(R.id.tab1); spec1.setIndicator(tabName); tabName = getResources().getString(R.string.playlist_tab_text); TabSpec spec2 = tabHost.newTabSpec(tabName); spec2.setIndicator(tabName); spec2.setContent(R.id.tab2); tabName = getResources().getString(R.string.statistics_tab_text); TabSpec spec3 = tabHost.newTabSpec(tabName); spec3.setIndicator(tabName); spec3.setContent(R.id.tab3); tabHost.addTab(spec1); tabHost.addTab(spec2); tabHost.addTab(spec3); tabHost.setOnTabChangedListener(new OnTabChangeListener() { @Override public void onTabChanged(String arg0) { updateUi(); } }); mLibraryView = (ListView) findViewById(R.id.media); mLibraryView.setAdapter(mLibraryItems); mLibraryView.setChoiceMode(ListView.CHOICE_MODE_SINGLE); mLibraryView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { updateButtons(); } }); mPlayListView = (ListView) findViewById(R.id.playlist); mPlayListView.setAdapter(mPlayListItems); mPlayListView.setChoiceMode(ListView.CHOICE_MODE_SINGLE); mPlayListView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { updateButtons(); } }); mInfoTextView = (TextView) findViewById(R.id.info); mPauseResumeButton = (ImageButton) findViewById(R.id.pause_resume_button); mPauseResumeButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { mPaused = !mPaused; if (mPaused) { mSessionManager.pause(); } else { mSessionManager.resume(); } } }); mStopButton = (ImageButton) findViewById(R.id.stop_button); mStopButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { mPaused = false; mSessionManager.stop(); } }); mSeekBar = (SeekBar) findViewById(R.id.seekbar); mSeekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { PlaylistItem item = getCheckedPlaylistItem(); if (fromUser && item != null && item.getDuration() > 0) { long pos = progress * item.getDuration() / 100; mSessionManager.seek(item.getItemId(), pos); item.setPosition(pos); item.setTimestamp(SystemClock.elapsedRealtime()); } } @Override public void onStartTrackingTouch(SeekBar seekBar) { mSeeking = true; } @Override public void onStopTrackingTouch(SeekBar seekBar) { mSeeking = false; updateUi(); } }); // Schedule Ui update mHandler.postDelayed(mUpdateSeekRunnable, 1000); // Build the PendingIntent for the remote control client mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); mEventReceiver = new ComponentName(getPackageName(), SampleMediaButtonReceiver.class.getName()); Intent mediaButtonIntent = new Intent(Intent.ACTION_MEDIA_BUTTON); mediaButtonIntent.setComponent(mEventReceiver); mMediaPendingIntent = PendingIntent.getBroadcast(this, 0, mediaButtonIntent, 0); // Create and register the remote control client registerRemoteControlClient(); // Set up playback manager and player mPlayer = RadioPlayer.create(RadioActivity.this, mMediaRouter.getSelectedRoute()); mSessionManager.setPlayer(mPlayer); mSessionManager.setCallback(new RadioSessionManager.Callback() { @Override public void onStatusChanged() { updateUi(); } @Override public void onItemChanged(PlaylistItem item) { } }); updateUi(); }
From source file:org.runnerup.view.DetailActivity.java
/** Called when the activity is first created. */ @Override//ww w .j a v a 2 s . co m public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.detail); WidgetUtil.addLegacyOverflowButton(getWindow()); Intent intent = getIntent(); mID = intent.getLongExtra("ID", -1); String mode = intent.getStringExtra("mode"); mDBHelper = new DBHelper(this); mDB = mDBHelper.getReadableDatabase(); uploadManager = new UploadManager(this); formatter = new Formatter(this); if (mode.contentEquals("save")) { this.mode = MODE_SAVE; } else if (mode.contentEquals("details")) { this.mode = MODE_DETAILS; } else { assert (false); } saveButton = (Button) findViewById(R.id.save_button); discardButton = (Button) findViewById(R.id.discard_button); resumeButton = (Button) findViewById(R.id.resume_button); uploadButton = (Button) findViewById(R.id.upload_button); activityTime = (TextView) findViewById(R.id.activity_time); activityDistance = (TextView) findViewById(R.id.activity_distance); activityPace = (TextView) findViewById(R.id.activity_pace); sport = (TitleSpinner) findViewById(R.id.summary_sport); notes = (EditText) findViewById(R.id.notes_text); notes.setHint("Notes about your workout"); map = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap(); if (map != null) { map.setOnCameraChangeListener(new OnCameraChangeListener() { @Override public void onCameraChange(CameraPosition arg0) { if (mapBounds != null) { // Move camera. map.moveCamera(CameraUpdateFactory.newLatLngBounds(mapBounds, 5)); // Remove listener to prevent position reset on camera // move. map.setOnCameraChangeListener(null); } } }); } saveButton.setOnClickListener(saveButtonClick); uploadButton.setOnClickListener(uploadButtonClick); if (this.mode == MODE_SAVE) { resumeButton.setOnClickListener(resumeButtonClick); discardButton.setOnClickListener(discardButtonClick); setEdit(true); } else if (this.mode == MODE_DETAILS) { resumeButton.setVisibility(View.GONE); discardButton.setVisibility(View.GONE); setEdit(false); } uploadButton.setVisibility(View.GONE); fillHeaderData(); requery(); loadRoute(); TabHost th = (TabHost) findViewById(R.id.tabhost); th.setup(); TabSpec tabSpec = th.newTabSpec("notes"); tabSpec.setIndicator(WidgetUtil.createHoloTabIndicator(this, "Notes")); tabSpec.setContent(R.id.tab_main); th.addTab(tabSpec); tabSpec = th.newTabSpec("laps"); tabSpec.setIndicator(WidgetUtil.createHoloTabIndicator(this, "Laps")); tabSpec.setContent(R.id.tab_lap); th.addTab(tabSpec); tabSpec = th.newTabSpec("map"); tabSpec.setIndicator(WidgetUtil.createHoloTabIndicator(this, "Map")); tabSpec.setContent(R.id.tab_map); th.addTab(tabSpec); tabSpec = th.newTabSpec("graph"); tabSpec.setIndicator(WidgetUtil.createHoloTabIndicator(this, "Graph")); tabSpec.setContent(R.id.tab_graph); th.addTab(tabSpec); tabSpec = th.newTabSpec("share"); tabSpec.setIndicator(WidgetUtil.createHoloTabIndicator(this, "Upload")); tabSpec.setContent(R.id.tab_upload); th.addTab(tabSpec); th.getTabWidget().setBackgroundColor(Color.DKGRAY); { ListView lv = (ListView) findViewById(R.id.laplist); LapListAdapter adapter = new LapListAdapter(); adapters.add(adapter); lv.setAdapter(adapter); } { ListView lv = (ListView) findViewById(R.id.report_list); ReportListAdapter adapter = new ReportListAdapter(); adapters.add(adapter); lv.setAdapter(adapter); } graphTab = (LinearLayout) findViewById(R.id.tab_graph); { graphView = new LineGraphView(this, "Pace") { @Override protected String formatLabel(double value, boolean isValueX) { if (!isValueX) { return formatter.formatPace(Formatter.TXT_SHORT, value); } else return formatter.formatDistance(Formatter.TXT_SHORT, (long) value); } }; graphView2 = new LineGraphView(this, "HRM") { @Override protected String formatLabel(double value, boolean isValueX) { if (!isValueX) { return Integer.toString((int) Math.round(value)); } else { return formatter.formatDistance(Formatter.TXT_SHORT, (long) value); } } }; } hrzonesBarLayout = (LinearLayout) findViewById(R.id.hrzonesBarLayout); hrzonesBar = new HRZonesBar(this); }
From source file:com.android.inputmethod.keyboard.EmojiPalettesView.java
private void addTab(final TabHost host, final int categoryId) { final String tabId = mEmojiCategory.getCategoryName(categoryId, 0 /* categoryPageId */); final TabHost.TabSpec tspec = host.newTabSpec(tabId); tspec.setContent(R.id.emoji_keyboard_dummy); if (mEmojiCategory.getCategoryIcon(categoryId) != 0) { final ImageView iconView = (ImageView) LayoutInflater.from(getContext()) .inflate(R.layout.emoji_keyboard_tab_icon, null); iconView.setImageResource(mEmojiCategory.getCategoryIcon(categoryId)); tspec.setIndicator(iconView);/*from w ww . j a v a2s .c o m*/ } if (mEmojiCategory.getCategoryLabel(categoryId) != null) { final TextView textView = (TextView) LayoutInflater.from(getContext()) .inflate(R.layout.emoji_keyboard_tab_label, null); textView.setText(mEmojiCategory.getCategoryLabel(categoryId)); textView.setTextColor(mTabLabelColor); tspec.setIndicator(textView); } host.addTab(tspec); }
From source file:com.mibr.android.intelligentreminder.INeedToo.java
/** Called when the activity is first created. */ @Override//from ww w . j a v a 2 s . c o 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:com.github.colorchief.colorchief.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); final TabHost tabHost = (TabHost) findViewById(R.id.tabHost); tabHost.setup();// w w w. j a v a2s. co m final TabHost.TabSpec tabImageView = tabHost.newTabSpec("Image View"); final TabHost.TabSpec tabSettings = tabHost.newTabSpec("Settings"); final TabHost.TabSpec tabAbout = tabHost.newTabSpec("About"); tabImageView.setIndicator("", ContextCompat.getDrawable(this, R.drawable.ic_action_picture)); tabImageView.setContent(R.id.tabImageView); tabSettings.setIndicator("", ContextCompat.getDrawable(this, R.drawable.ic_action_gear)); tabSettings.setContent(R.id.tabSettings); tabAbout.setIndicator("", ContextCompat.getDrawable(this, R.drawable.ic_action_help)); tabAbout.setContent(R.id.tabAbout); /** Add the tabs to the TabHost to display. */ tabHost.addTab(tabImageView); tabHost.addTab(tabSettings); tabHost.addTab(tabAbout); colorLUT.initLUT(LUT_SIZE, LUT_SIZE, LUT_SIZE); //check savedInstance // for Tab state and set active tab accordingly // for LUT values and update (restore) accordingly if (savedInstanceState != null) { tabHost.setCurrentTab(savedInstanceState.getInt("Active Tab")); colorLUT.setColorLutArray(savedInstanceState.getIntArray("Color LUT")); } ((SeekBar) findViewById(R.id.seekBarChromaPowerFactor)).setMax(POWER_FACTOR_SEEK_BAR_MAX); ((SeekBar) findViewById(R.id.seekBarChromaPowerFactor)).setProgress(getSeekPosition(powerFactor)); if (Lselect == LutCalculate.L_SELECT_IN) { ((RadioButton) findViewById(R.id.radioButtonLin)).setChecked(true); ((RadioButton) findViewById(R.id.radioButtonLout)).setChecked(false); } else if (Lselect == LutCalculate.L_SELECT_OUT) { ((RadioButton) findViewById(R.id.radioButtonLin)).setChecked(false); ((RadioButton) findViewById(R.id.radioButtonLout)).setChecked(true); } if (Cselect == LutCalculate.C_SELECT_ABSOLUTE) { ((RadioButton) findViewById(R.id.radioButtonCin)).setChecked(true); ((RadioButton) findViewById(R.id.radioButtonCrelative)).setChecked(false); ((SeekBar) findViewById(R.id.seekBarChromaPowerFactor)).setEnabled(false); } else if (Cselect == LutCalculate.C_SELECT_RELATIVE) { ((RadioButton) findViewById(R.id.radioButtonCin)).setChecked(false); ((RadioButton) findViewById(R.id.radioButtonCrelative)).setChecked(true); ((SeekBar) findViewById(R.id.seekBarChromaPowerFactor)).setEnabled(true); } if (uriIccProfileIn != null) iccProfileIn.loadFromFile(uriIccProfileIn); if (uriIccProfileOut != null) iccProfileOut.loadFromFile(uriIccProfileOut); if (bitmapLoaded) { transformImage(); updateImageViewer(); } else { ((ImageView) findViewById(R.id.imageView)).setImageBitmap( BitmapFactory.decodeResource(getResources(), R.drawable.ic_action_folder_open_blue)); } ((ImageView) findViewById(R.id.imageView)).addOnLayoutChangeListener(new View.OnLayoutChangeListener() { @Override public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) { // if layout is not complete we will get all zero values for the positions, so ignore the event if (left == 0 && top == 0 && right == 0 && bottom == 0) { return; } else { if (bitmapLoaded) { try { decodeImageUri(uriBitmapOriginal, (ImageView) findViewById(R.id.imageView)); } catch (FileNotFoundException e) { Log.e(TAG, "Failed to grab Bitmap: " + e); } //if (iccProfileOut.isValidProfile() && iccProfileIn.isValidProfile()) transformImage(); updateImageViewer(); } } } }); ((SeekBar) findViewById(R.id.seekBarChromaPowerFactor)) .setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { } @Override public void onStartTrackingTouch(SeekBar seekBar) { } @Override public void onStopTrackingTouch(SeekBar seekBar) { powerFactor = getPowerFactor(seekBar.getProgress()); //convertImage(seekBar); //updateImageViewer(); } }); //when switching tabs, make sure: //a: update the image when switching to the imageview tab in case any settings changes were made //b: hide the color controls overlay if we are not on the imageview tab tabHost.setOnTabChangedListener(new TabHost.OnTabChangeListener() { @Override public void onTabChanged(String tabId) { if (tabId.equals(tabImageView.getTag())) { //Log.d(TAG,"Tab changed to image view"); if (iccProfileIn.isValidProfile() && iccProfileOut.isValidProfile() && bitmapLoaded) { recalculateTransform(); transformImage(); updateImageViewer(); } } else if (tabId.equals(tabAbout.getTag())) { ((LinearLayout) findViewById(R.id.overlayColorControl)).setVisibility(View.INVISIBLE); InputStream inputStream = getResources().openRawResource(R.raw.about); ByteArrayOutputStream byteArrayStream = new ByteArrayOutputStream(); try { int bytesRead = inputStream.read(); while (bytesRead != -1) { byteArrayStream.write(bytesRead); bytesRead = inputStream.read(); } } catch (IOException e) { e.printStackTrace(); } //TextView textViewAbout = (TextView) findViewById(R.id.textViewAbout); //textViewAbout.setText(Html.fromHtml(byteArrayStream.toString())); WebView webViewAbout = (WebView) findViewById(R.id.webViewAbout); webViewAbout.loadDataWithBaseURL(null, byteArrayStream.toString(), "text/html", "utf-8", null); } else { ((LinearLayout) findViewById(R.id.overlayColorControl)).setVisibility(View.INVISIBLE); } } }); }
From source file:fr.vassela.acrrd.Main.java
@Override protected void onCreate(Bundle savedInstanceState) { try {/*from w w w.j ava 2 s.co m*/ localizerManager.setPreferencesLocale(getApplicationContext()); themeManager.setPreferencesTheme(getApplicationContext(), this); delegate = AppCompatDelegate.create(this, this); delegate.installViewFactory(); super.onCreate(savedInstanceState); delegate.onCreate(savedInstanceState); delegate.setContentView(R.layout.main); SharedPreferences sharedPreferences = PreferenceManager .getDefaultSharedPreferences(getApplicationContext()); int currentLocaleIndex = Integer.parseInt(sharedPreferences.getString("preferences_locale_set", "0")); String currentLocale = localizerManager.getLocale(getApplicationContext()).toString(); ArrayList<String> slideMenuTitles = new ArrayList<String>(); slideMenuTitles.add(getApplicationContext().getString(R.string.preferences_locale).toString()); //slideMenuTitles.add(getApplicationContext().getString(R.string.main_toolbar_test).toString()); slideMenuTitles.add(getApplicationContext().getString(R.string.main_toolbar_preferences).toString()); slideMenuTitles.add(getApplicationContext().getString(R.string.main_toolbar_log).toString()); slideMenuTitles.add(getApplicationContext().getString(R.string.main_toolbar_about).toString()); slideMenuTitles.add(getApplicationContext().getString(R.string.main_toolbar_exit).toString()); ArrayList<String> slideMenuSubtitles = new ArrayList<String>(); slideMenuSubtitles.add(currentLocale); //slideMenuSubtitles.add(getApplicationContext().getString(R.string.main_toolbar_test_description).toString()); slideMenuSubtitles.add( getApplicationContext().getString(R.string.main_toolbar_preferences_description).toString()); slideMenuSubtitles .add(getApplicationContext().getString(R.string.main_toolbar_log_description).toString()); slideMenuSubtitles .add(getApplicationContext().getString(R.string.main_toolbar_about_description).toString()); slideMenuSubtitles .add(getApplicationContext().getString(R.string.main_toolbar_exit_description).toString()); ArrayList<Integer> slideMenuIcons = new ArrayList<Integer>(); slideMenuIcons.add(themeManager.getLocaleFlag(getApplicationContext(), currentLocaleIndex)); slideMenuIcons.add(R.drawable.ic_menu_preferences); //slideMenuIcons.add(R.drawable.ic_menu_preferences); slideMenuIcons.add(R.drawable.ic_menu_archive); slideMenuIcons.add(R.drawable.ic_menu_info_details); slideMenuIcons.add(R.drawable.ic_menu_revert); drawerList = (ListView) findViewById(R.id.drawer_list); drawerLayout = (DrawerLayout) findViewById(R.id.drawerLayout); SlidingMenuAdapter slidingMenuAdapter = new SlidingMenuAdapter(this, slideMenuTitles, slideMenuSubtitles, slideMenuIcons); drawerList.setAdapter(slidingMenuAdapter); drawerList.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { switch (position) { case 0: break; /*case 0 : drawerLayout.closeDrawers(); startActivity(new Intent(getApplicationContext(), Test.class)); break;*/ case 1: drawerLayout.closeDrawers(); startActivity(new Intent(getApplicationContext(), Preferences.class)); break; case 2: drawerLayout.closeDrawers(); startActivity(new Intent(getApplicationContext(), TelephoneCallLogger.class)); break; case 3: drawerLayout.closeDrawers(); startActivity(new Intent(getApplicationContext(), About.class)); break; case 4: drawerLayout.closeDrawers(); RecordServiceManager recordServiceManager = new RecordServiceManager(); boolean isRecordServiceRunning = recordServiceManager.isRunning(getApplicationContext()); if (isRecordServiceRunning == false) { MonitoringServiceManager monitoringServiceManager = new MonitoringServiceManager(); monitoringServiceManager.stopService(getApplicationContext()); PurgeServiceManager purgeServiceManager = new PurgeServiceManager(); purgeServiceManager.stopService(getApplicationContext()); } moveTaskToBack(true); onBackPressed(); break; } } }); toolbar = (Toolbar) findViewById(R.id.main_toolbar); delegate.setSupportActionBar(toolbar); delegate.setTitle(getString(R.string.main_toolbar)); delegate.getSupportActionBar().setDisplayHomeAsUpEnabled(true); delegate.getSupportActionBar().setDisplayShowHomeEnabled(true); delegate.getSupportActionBar().setHomeButtonEnabled(true); TabHost tabhost = (TabHost) findViewById(android.R.id.tabhost); TabWidget tabwidget = tabhost.getTabWidget(); TabSpec tab_home = tabhost.newTabSpec(getString(R.string.main_tab_home)); TabSpec tab_records = tabhost.newTabSpec(getString(R.string.main_tab_records)); TabSpec tab_preferences = tabhost.newTabSpec(getString(R.string.main_tab_preferences)); TabSpec tab_about = tabhost.newTabSpec(getString(R.string.main_tab_about)); TabSpec tab_test = tabhost.newTabSpec("test"); tab_home.setIndicator(getString(R.string.main_tab_home), this.getResources().getDrawable(R.drawable.ic_menu_home)); tab_home.setContent(new Intent(this, Home.class)); tab_records.setIndicator(getString(R.string.main_tab_records), this.getResources().getDrawable(R.drawable.ic_voice_search)); tab_records.setContent(new Intent(this, Records.class)); tab_preferences.setIndicator(getString(R.string.main_tab_preferences), this.getResources().getDrawable(R.drawable.ic_menu_preferences)); tab_preferences.setContent(new Intent(this, Preferences.class)); tab_about.setIndicator(getString(R.string.main_tab_about), this.getResources().getDrawable(R.drawable.ic_menu_info_details)); tab_about.setContent(new Intent(this, About.class)); tab_test.setIndicator("test", this.getResources().getDrawable(R.drawable.ic_menu_preferences)); tab_test.setContent(new Intent(this, Test.class)); tabhost.addTab(tab_home); tabhost.addTab(tab_records); Intent intent = getIntent(); /*String setCurrentTab; if (savedInstanceState == null) { Bundle extras = getIntent().getExtras(); if(extras == null) { setCurrentTab = null; } else { setCurrentTab = extras.getString("setCurrentTab"); } } else { setCurrentTab = (String) savedInstanceState.getSerializable("setCurrentTab"); } getIntent().removeExtra("setCurrentTab"); if(setCurrentTab.equals("home")) { tabhost.setCurrentTab(0); } else if(setCurrentTab.equals("records")) { tabhost.setCurrentTab(1); } else { tabhost.setCurrentTab(0); }*/ if (SHOW_RECORDS.equals(intent.getAction())) { tabhost.setCurrentTab(1); } else { tabhost.setCurrentTab(0); } initDrawer(); themeManager.setTabWidget(getApplicationContext(), tabwidget); } catch (Exception e) { Log.e("Main", "onCreate : " + getApplicationContext().getString(R.string.log_main_error_create) + " : " + e); databaseManager.insertLog(getApplicationContext(), "" + getApplicationContext().getString(R.string.log_main_error_create), new Date().getTime(), 1, false); } }
From source file:com.momock.outlet.tab.FragmentTabOutlet.java
public void attach(FragmentTabHolder tabHolder) { Logger.check(tabHolder != null, "Parameter tabHolder cannot be null!"); this.target = tabHolder; TabHost tabHost = target.getTabHost(); final IDataList<IPlug> plugs = getPlugs(); tabHost.setup();// w w w . j a v a 2 s.c o m tabHost.setOnTabChangedListener(new TabHost.OnTabChangeListener() { @Override public void onTabChanged(String tabId) { new Handler().post(new Runnable() { @Override public void run() { int index = target.getTabHost().getCurrentTab(); int id = target.getTabContentId(); ITabPlug plug = (ITabPlug) plugs.getItem(index); setActivePlug(plug); FragmentManager fm = target.getFragmentManager(); if (fm != null && plug.getContent() instanceof FragmentHolder) { try { FragmentTransaction ft = fm.beginTransaction(); FragmentHolder fh = (FragmentHolder) plug.getContent(); ft.replace(id, fh.getFragment()); ft.commit(); fm.executePendingTransactions(); } catch (Exception e) { Logger.error(e); } } } }); } }); for (int i = 0; i < plugs.getItemCount(); i++) { final ITabPlug plug = (ITabPlug) plugs.getItem(i); if (plug.getContent() instanceof FragmentHolder) { TabHost.TabSpec spec = tabHost.newTabSpec("" + i); target.setTabIndicator(spec, plug); spec.setContent(new TabContentFactory() { @Override public View createTabContent(String tag) { View v = new View(target.getTabHost().getContext()); v.setMinimumWidth(0); v.setMinimumHeight(0); return v; } }); tabHost.addTab(spec); if (getActivePlug() == plug) tabHost.setCurrentTab(i); } } }
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);//from ww w .ja va 2s . c o m tabHost.addTab(tabSpec); }