List of usage examples for android.widget TabHost setOnTabChangedListener
public void setOnTabChangedListener(OnTabChangeListener l)
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();// ww w . j a v a2 s .co 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:com.dream.freightapp.app.ui.tool.TabManager.java
public TabManager(FragmentActivity fragmentActivity, TabHost tabHost, int containerId) { this.fragmentActivity = fragmentActivity; this.tabHost = tabHost; this.containerId = containerId; tabHost.setOnTabChangedListener(this); }
From source file:com.google.android.apps.mytracks.TabManager.java
public TabManager(FragmentActivity fragmentActivity, TabHost tabHost, int containerId) { this.fragmentActivity = fragmentActivity; this.tabHost = tabHost; this.containerId = containerId; tabHost.setOnTabChangedListener(this); }
From source file:com.ecml.ChooseSongActivity.java
@Override public void onCreate(Bundle state) { globalActivity = this; super.onCreate(state); // Set the Action Bar Title of the Activity (corresponding to the first Tab) setTitle("ECML: Choose Song"); Bitmap allFilesIcon = BitmapFactory.decodeResource(this.getResources(), R.drawable.allfilesicon); Bitmap recentFilesIcon = BitmapFactory.decodeResource(this.getResources(), R.drawable.recentfilesicon); Bitmap browseFilesIcon = BitmapFactory.decodeResource(this.getResources(), R.drawable.browsefilesicon); final TabHost tabHost = getTabHost(); tabHost.addTab(tabHost.newTabSpec("All").setIndicator("All", new BitmapDrawable(allFilesIcon)) .setContent(new Intent(this, AllSongsActivity.class))); tabHost.addTab(tabHost.newTabSpec("Recent").setIndicator("Recent", new BitmapDrawable(recentFilesIcon)) .setContent(new Intent(this, RecentSongsActivity.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP))); tabHost.addTab(tabHost.newTabSpec("Browse").setIndicator("Browse", new BitmapDrawable(browseFilesIcon)) .setContent(new Intent(this, FileBrowserActivity.class))); tabHost.setOnTabChangedListener(this); }
From source file:org.geometerplus.android.fbreader.bookmark.EditBookmarkActivity.java
@Override public void onCreate(Bundle bundle) { super.onCreate(bundle); requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.edit_bookmark); myBookmark = FBReaderIntents.getBookmarkExtra(getIntent()); if (myBookmark == null) { finish();// w ww . j a v a 2 s .c om return; } final DisplayMetrics dm = getResources().getDisplayMetrics(); final int width = Math.min((int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 500, dm), dm.widthPixels * 9 / 10); final int height = Math.min((int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 350, dm), dm.heightPixels * 9 / 10); final TabHost tabHost = (TabHost) findViewById(R.id.edit_bookmark_tabhost); tabHost.setLayoutParams(new FrameLayout.LayoutParams(new ViewGroup.LayoutParams(width, height))); tabHost.setup(); addTab(tabHost, "text", R.id.edit_bookmark_content_text); addTab(tabHost, "style", R.id.edit_bookmark_content_style); addTab(tabHost, "delete", R.id.edit_bookmark_content_delete); final ZLStringOption currentTabOption = new ZLStringOption("LookNFeel", "EditBookmark", "text"); tabHost.setCurrentTabByTag(currentTabOption.getValue()); tabHost.setOnTabChangedListener(new TabHost.OnTabChangeListener() { public void onTabChanged(String tag) { if (!"delete".equals(tag)) { currentTabOption.setValue(tag); } } }); final EditText editor = (EditText) findViewById(R.id.edit_bookmark_text); editor.setText(myBookmark.getText()); final int len = editor.getText().length(); editor.setSelection(len, len); final Button saveTextButton = (Button) findViewById(R.id.edit_bookmark_save_text_button); saveTextButton.setEnabled(false); saveTextButton.setText(myResource.getResource("saveText").getValue()); saveTextButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { myCollection.bindToService(EditBookmarkActivity.this, new Runnable() { public void run() { myBookmark.setText(editor.getText().toString()); myCollection.saveBookmark(myBookmark); saveTextButton.setEnabled(false); } }); } }); editor.addTextChangedListener(new TextWatcher() { @Override public void onTextChanged(CharSequence sequence, int start, int before, int count) { final String originalText = myBookmark.getText(); saveTextButton.setEnabled(!originalText.equals(editor.getText().toString())); } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void afterTextChanged(Editable s) { } }); final Button deleteButton = (Button) findViewById(R.id.edit_bookmark_delete_button); deleteButton.setText(myResource.getResource("deleteBookmark").getValue()); deleteButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { myCollection.bindToService(EditBookmarkActivity.this, new Runnable() { public void run() { myCollection.deleteBookmark(myBookmark); finish(); } }); } }); }
From source file:com.tutor.fragment.ViewPageFragment.java
private void initialMainTabHost(LayoutInflater inflater, View mView) { View sgTab = inflater.inflate(R.layout.tab_main_widebg, null); TextView sgtv = (TextView) sgTab.findViewById(R.id.mainTabTv); sgtv.setText("3G"); View yxTab = inflater.inflate(R.layout.tab_main_widebg, null); TextView yxtv = (TextView) yxTab.findViewById(R.id.mainTabTv); yxtv.setText(""); TabHost yxTabHost = (TabHost) mView.findViewById(R.id.yxTabHost); yxTabHost.setup();/* www .j av a2s.c om*/ yxTabHost.addTab(yxTabHost.newTabSpec("3GTab").setIndicator(sgTab).setContent(R.id.tab_3gfudao)); yxTabHost.addTab(yxTabHost.newTabSpec("YXJifen").setIndicator(yxTab).setContent(R.id.tab_yxjifen)); yxTabHost.setOnTabChangedListener(new OnTabChangeListener() { @Override public void onTabChanged(String tabId) { if (tabId.equals("3GTab")) { // ListView myTabLst = (ListView) // findViewById(R.id.myTabLst); } else { } } }); }
From source file:com.swiftnav.piksidroid.MainActivity.java
private void setupUI() { TabHost tabHost = (TabHost) findViewById(R.id.tabHost); tabHost.setup();//from w w w . java 2 s. c o m TabHost.TabSpec tabSpec = tabHost.newTabSpec("Piksi"); tabSpec.setContent(R.id.piksi); tabSpec.setIndicator("Piksi"); tabHost.addTab(tabSpec); tabSpec = tabHost.newTabSpec("Tracking"); tabSpec.setContent(R.id.tracking); tabSpec.setIndicator("Tracking"); tabHost.addTab(tabSpec); tabSpec = tabHost.newTabSpec("Map"); tabSpec.setContent(R.id.map); tabSpec.setIndicator("Map"); tabHost.addTab(tabSpec); tabSpec = tabHost.newTabSpec("Observation"); tabSpec.setContent(R.id.observation); tabSpec.setIndicator("Observation"); tabHost.addTab(tabSpec); tabSpec = tabHost.newTabSpec("RTK"); tabSpec.setContent(R.id.rtk); tabSpec.setIndicator("RTK"); tabHost.addTab(tabSpec); tabHost.setOnTabChangedListener(tabChanger); ((EditText) findViewById(R.id.console)).setText("Piksi not connected!"); ((EditText) findViewById(R.id.console)).setTextIsSelectable(false); findViewById(R.id.console).setClickable(false); findViewById(R.id.scrollView).setClickable(false); findViewById(R.id.scrollView).setFocusable(false); findViewById(R.id.scrollView).setOnTouchListener(null); findViewById(R.id.scrollView).setPressed(false); com.swiftnav.piksidroid.MapFragment mFrag = ((com.swiftnav.piksidroid.MapFragment) getFragmentManager() .findFragmentById(R.id.map_fragment)); com.google.android.gms.maps.MapFragment mGFrag = (com.google.android.gms.maps.MapFragment) mFrag .getChildFragmentManager().findFragmentById(R.id.gmap_fragment); mGFrag.getMapAsync(mFrag); View decorView = getWindow().getDecorView(); int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN; decorView.setSystemUiVisibility(uiOptions); }
From source file:com.vuze.android.remote.dialog.DialogFragmentFilterByTags.java
@NonNull @Override/* ww w .j a v a 2s . c om*/ public Dialog onCreateDialog(Bundle savedInstanceState) { SessionInfo sessionInfo = getSessionInfo(); List<Map<?, ?>> tags = sessionInfo == null ? null : sessionInfo.getTags(); if (tags != null && tags.size() > 0) { TreeMap<String, Long> map = new TreeMap<>(); for (Object o : tags) { if (o instanceof Map) { Map<?, ?> mapTag = (Map<?, ?>) o; long uid = MapUtils.getMapLong(mapTag, "uid", 0); String name = MapUtils.getMapString(mapTag, "name", "??"); int type = MapUtils.getMapInt(mapTag, "type", 0); if (type == 3) { // type-name will be "Manual" :( name = "Tag: " + name; } else { String typeName = MapUtils.getMapString(mapTag, "type-name", null); if (typeName != null) { name = typeName + ": " + name; } } map.put(name, uid); } } long[] vals = new long[map.size()]; String[] strings = map.keySet().toArray(new String[map.keySet().size()]); for (int i = 0; i < vals.length; i++) { vals[i] = map.get(strings[i]); } filterByList = new ValueStringArray(vals, strings); } if (filterByList == null) { filterByList = AndroidUtils.getValueStringArray(getResources(), R.array.filterby_list); } AndroidUtils.AlertDialogBuilder alertDialogBuilder = AndroidUtils.createAlertDialogBuilder(getActivity(), R.layout.dialog_filter_by); View view = alertDialogBuilder.view; AlertDialog.Builder builder = alertDialogBuilder.builder; // get our tabHost from the xml TabHost tabHost = (TabHost) view.findViewById(R.id.filterby_tabhost); tabHost.setup(); // create tab 1 TabHost.TabSpec spec1 = tabHost.newTabSpec("tab1"); spec1.setIndicator("States"); spec1.setContent(R.id.filterby_sv_state); tabHost.addTab(spec1); //create tab2 TabHost.TabSpec spec2 = tabHost.newTabSpec("tab2"); spec2.setIndicator("Tags"); spec2.setContent(R.id.filterby_tv_tags); tabHost.addTab(spec2); int height = AndroidUtilsUI.dpToPx(32); tabHost.getTabWidget().getChildAt(0).getLayoutParams().height = height; tabHost.getTabWidget().getChildAt(1).getLayoutParams().height = height; TextView tvState = (TextView) view.findViewById(R.id.filterby_tv_state); tvState.setMovementMethod(LinkMovementMethod.getInstance()); final TextView tvTags = (TextView) view.findViewById(R.id.filterby_tv_tags); tvTags.setMovementMethod(LinkMovementMethod.getInstance()); // for API <= 10 (maybe 11?), otherwise tags will display on one line tabHost.setOnTabChangedListener(new TabHost.OnTabChangeListener() { @Override public void onTabChanged(String tabId) { if (!tabId.equals("tab2")) { return; } tvTags.post(new Runnable() { @Override public void run() { spanTags.updateTags(); } }); } }); builder.setTitle(R.string.filterby_title); // Add action buttons builder.setPositiveButton(R.string.action_filterby, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { if (mapSelectedTag == null) { return; } long uidSelected = MapUtils.getMapLong(mapSelectedTag, "uid", -1); String name = MapUtils.getMapString(mapSelectedTag, "name", "??"); mListener.filterBy(uidSelected, name, true); } }); builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { DialogFragmentFilterByTags.this.getDialog().cancel(); } }); List<Map<?, ?>> manualTags = new ArrayList<>(); List<Map<?, ?>> stateTags = new ArrayList<>(); if (sessionInfo != null) { // Dialog never gets called wehn getTags has no tags List<Map<?, ?>> allTags = sessionInfo.getTags(); if (allTags != null) { for (Map<?, ?> mapTag : allTags) { int type = MapUtils.getMapInt(mapTag, "type", 0); switch (type) { case 0: case 1: case 2: stateTags.add(mapTag); break; case 3: // manual manualTags.add(mapTag); break; } } } } SpanTagsListener l = new SpanTagsListener() { @Override public void tagClicked(Map mapTag, String name) { mapSelectedTag = mapTag; // todo: long click, don't exit long uidSelected = MapUtils.getMapLong(mapSelectedTag, "uid", -1); mListener.filterBy(uidSelected, name, true); DialogFragmentFilterByTags.this.getDialog().dismiss(); } @Override public int getTagState(Map mapTag, String name) { if (mapSelectedTag == null) { return SpanTags.TAG_STATE_UNSELECTED; } long uidSelected = MapUtils.getMapLong(mapSelectedTag, "uid", -1); if (uidSelected == -1) { return SpanTags.TAG_STATE_UNSELECTED; } long uidQuery = MapUtils.getMapLong(mapTag, "uid", -1); return uidQuery == uidSelected ? SpanTags.TAG_STATE_SELECTED : SpanTags.TAG_STATE_UNSELECTED; } }; spanTags = new SpanTags(getActivity(), sessionInfo, tvTags, l); spanTags.setTagMaps(manualTags); spanTags.setShowIcon(false); spanTags.updateTags(); SpanTags spanState = new SpanTags(getActivity(), sessionInfo, tvState, l); spanState.setTagMaps(stateTags); spanState.setShowIcon(false); spanState.updateTags(); return builder.create(); }
From source file:com.example.mydemos.view.RingtonePickerActivity.java
/** Called when the activity is first created. */ @Override//from w w w . j a v a2 s.c om public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.ringtone_picker); CharSequence sysTitle = (CharSequence) getResources().getText(R.string.sys_tone); CharSequence MusicTitle = (CharSequence) getResources().getText(R.string.sd_music); CharSequence RecordTitle = (CharSequence) getResources().getText(R.string.record_tone); Intent intent = getIntent(); toneType = intent.getIntExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, -1); Log.e("duwenhua", "ringPick get toneType:" + toneType); //! by duwenhua //if(toneType == RingtoneManager.TYPE_RINGTONE_SECOND) // toneType = RINGTONE_TYPE; //! by duwenhua mHasDefaultItem = intent.getBooleanExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, true); mUriForDefaultItem = intent.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI); //Log.i("lys", "mUriForDefaultItem == " + mUriForDefaultItem); if (savedInstanceState != null) { mSelectedId = savedInstanceState.getLong(SAVE_CLICKED_POS, -1); } //Log.i("lys", "mUriForDefaultItem 1== " + mUriForDefaultItem+", mSelectedId =="+mSelectedId); mHasSilentItem = intent.getBooleanExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, true); mExistingUri = intent.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI); //if(mUriForDefaultItem != null) //{ // mSelectedId = ContentUris.parseId(mUriForDefaultItem); //} //Log.i("lys", "RingtonePickerActivity.java onCreate mExistingUri == " + mExistingUri); //String action = getIntent().getAction(); //Log.i("lys", "PT Intent action == " + action); if (toneType == NOTIFICATION_TYPE) { mUriForDefaultItem = Settings.System.DEFAULT_NOTIFICATION_URI; } else if (toneType == RINGTONE_TYPE) { mUriForDefaultItem = Settings.System.DEFAULT_RINGTONE_URI; } else if (toneType == ALARM_TYPE) { mUriForDefaultItem = Settings.System.DEFAULT_ALARM_ALERT_URI; } if (isAvailableToCheckRingtone() == true) { Ringtone ringtone_DefaultItem = checkRingtone_reflect(this, mUriForDefaultItem, toneType); if (ringtone_DefaultItem != null && ringtone_DefaultItem.getUri() != null) { mUriForDefaultItem = ringtone_DefaultItem.getUri(); Log.i("lys", "RingtoneManager.getRingtone mUriForDefaultItem== " + mUriForDefaultItem); } else { //mUriForDefaultItem = 'content/medial/'; /*ZTE_AUDIO_LIYANG 2014/06/30 fix bug for ringtone when remove sdcard start */ String originalRingtone = Settings.System.getString(getApplicationContext().getContentResolver(), "ringtone_original"); if (originalRingtone != null && !TextUtils.isEmpty(originalRingtone)) { mUriForDefaultItem = Uri.parse(originalRingtone); Log.e("liyang", "select riongtone error ,change to originalRingtone == " + mExistingUri); } /*ZTE_AUDIO_LIYANG 2014/06/30 fix bug for ringtone when remove sdcard end */ Log.i("lys", "mUriForDefaultItem set as default mUriForDefaultItem== 222"); } if (mExistingUri != null) { Ringtone ringtone = checkRingtone_reflect(this, mExistingUri, toneType); if (ringtone != null && ringtone.getUri() != null) { //mUriForDefaultItem = ringtone.getUri(); mExistingUri = ringtone.getUri(); Log.i("lys", "RingtoneManager.getRingtone mExistingUri== " + mExistingUri); } else { mExistingUri = mUriForDefaultItem; Log.i("lys", "mExistingUri set as default mExistingUri== " + mExistingUri); } } } boolean includeDrm = intent.getBooleanExtra(RingtoneManager.EXTRA_RINGTONE_INCLUDE_DRM, false); Log.e("lys", "includeDrm ==" + includeDrm); mRingtoneManager = new RingtoneManager(this); mRingtoneManager.setIncludeDrm(includeDrm); if (toneType != -1) { mRingtoneManager.setType(toneType); } setVolumeControlStream(mRingtoneManager.inferStreamType()); // toneActivityType = mRingtoneManager.getActivityType(); if (toneType == ALARM_TYPE) { sysTitle = (CharSequence) getResources().getText(R.string.alarm_tone); } else if (toneType == NOTIFICATION_TYPE) { sysTitle = (CharSequence) getResources().getText(R.string.notification_tone); } listView = new ListView(this); listView.setOnItemClickListener(this); //listView.setBackgroundColor(#ff5a5a5a); listView.setFastScrollEnabled(true); //listView.setFastScrollAlwaysVisible(true); listView.setEmptyView(findViewById(android.R.id.empty)); //mHasSilentItem = intent.getBooleanExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, true); //mHasDefaultItem = true; //temp if (mHasDefaultItem) { //chengcheng addDefaultStaticItem(listView, com.android.internal.R.string.ringtone_default); } setDefaultRingtone(); if (mHasSilentItem) { // chengcheng addSilendStaticItem(listView, com.android.internal.R.string.ringtone_silent); } audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); mAudioFocusListener = new OnAudioFocusChangeListener() { public void onAudioFocusChange(int focusChange) { } }; okBtn = (Button) findViewById(R.id.ok); okBtn.setOnClickListener(this); cancelBtn = (Button) findViewById(R.id.cancel); cancelBtn.setOnClickListener(this); TabHost mTabHost = (TabHost) findViewById(android.R.id.tabhost); mTabHost.setup(); mTabHost.addTab(mTabHost.newTabSpec("tab_system").setIndicator(sysTitle, null).setContent(this)); mTabHost.addTab(mTabHost.newTabSpec("tab_music").setIndicator(MusicTitle, null).setContent(this)); mTabHost.addTab(mTabHost.newTabSpec("tab_record").setIndicator(RecordTitle, null).setContent(this)); mTabHost.setCurrentTab(0); mTabHost.setOnTabChangedListener(new OnTabChangeListener() { @Override public void onTabChanged(String tabId) { // stopMediaPlayer(); createTabContent(tabId); } }); }
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"); }/*from w w w.j a v a 2 s . com*/ // 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(); }