List of usage examples for android.view KeyEvent KEYCODE_MEDIA_PLAY
int KEYCODE_MEDIA_PLAY
To view the source code for android.view KeyEvent KEYCODE_MEDIA_PLAY.
Click Source Link
From source file:singh.amandeep.musicplayer.MediaButtonIntentReceiver.java
/** * {@inheritDoc}//www. j av a2 s . co m */ @Override public void onReceive(final Context context, final Intent intent) { final String intentAction = intent.getAction(); if (AudioManager.ACTION_AUDIO_BECOMING_NOISY.equals(intentAction)) { startService(context, MusicService.CMDPAUSE); } else if (Intent.ACTION_MEDIA_BUTTON.equals(intentAction)) { final KeyEvent event = intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT); if (event == null) { return; } final int keycode = event.getKeyCode(); final int action = event.getAction(); final long eventtime = event.getEventTime(); String command = null; switch (keycode) { case KeyEvent.KEYCODE_MEDIA_STOP: command = MusicService.CMDSTOP; break; case KeyEvent.KEYCODE_HEADSETHOOK: case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE: command = MusicService.CMDTOGGLEPAUSE; break; case KeyEvent.KEYCODE_MEDIA_NEXT: command = MusicService.CMDNEXT; break; case KeyEvent.KEYCODE_MEDIA_PREVIOUS: command = MusicService.CMDPREVIOUS; break; case KeyEvent.KEYCODE_MEDIA_PAUSE: command = MusicService.CMDPAUSE; break; case KeyEvent.KEYCODE_MEDIA_PLAY: command = MusicService.CMDPLAY; break; } if (command != null) { if (action == KeyEvent.ACTION_DOWN) { if (mDown) { if (MusicService.CMDTOGGLEPAUSE.equals(command) || MusicService.CMDPLAY.equals(command)) { if (mLastClickTime != 0 && eventtime - mLastClickTime > LONG_PRESS_DELAY) { acquireWakeLockAndSendMessage(context, mHandler.obtainMessage(MSG_LONGPRESS_TIMEOUT, context), 0); } } } else if (event.getRepeatCount() == 0) { // Only consider the first event in a sequence, not the repeat events, // so that we don't trigger in cases where the first event went to // a different app (e.g. when the user ends a phone call by // long pressing the headset button) // The service may or may not be running, but we need to send it // a command. if (keycode == KeyEvent.KEYCODE_HEADSETHOOK) { if (eventtime - mLastClickTime >= DOUBLE_CLICK) { mClickCounter = 0; } mClickCounter++; mHandler.removeMessages(MSG_HEADSET_DOUBLE_CLICK_TIMEOUT); Message msg = mHandler.obtainMessage(MSG_HEADSET_DOUBLE_CLICK_TIMEOUT, mClickCounter, 0, context); long delay = mClickCounter < 3 ? DOUBLE_CLICK : 0; if (mClickCounter >= 3) { mClickCounter = 0; } mLastClickTime = eventtime; acquireWakeLockAndSendMessage(context, msg, delay); } else { startService(context, command); } mLaunched = false; mDown = true; } } else { mHandler.removeMessages(MSG_LONGPRESS_TIMEOUT); mDown = false; } if (isOrderedBroadcast()) { abortBroadcast(); } releaseWakeLockIfHandlerIdle(); } } }
From source file:us.nineworlds.serenity.ui.browser.tv.TVShowBrowserActivity.java
@Override public boolean onKeyDown(int keyCode, KeyEvent event) { SerenityGallery gallery = (SerenityGallery) findViewById(R.id.tvShowBannerGallery); boolean menuKeySlidingMenu = preferences.getBoolean("remote_control_menu", true); if (menuKeySlidingMenu) { if (keyCode == KeyEvent.KEYCODE_MENU) { if (drawerLayout.isDrawerOpen(linearDrawerLayout)) { drawerLayout.closeDrawers(); } else { drawerLayout.openDrawer(linearDrawerLayout); }//from w ww. j av a 2 s . c om return true; } } if (keyCode == KeyEvent.KEYCODE_BACK && drawerLayout.isDrawerOpen(linearDrawerLayout)) { drawerLayout.closeDrawers(); if (gallery != null) { gallery.requestFocusFromTouch(); } return true; } if (gallery == null) { return super.onKeyDown(keyCode, event); } AbstractPosterImageGalleryAdapter adapter = (AbstractPosterImageGalleryAdapter) gallery.getAdapter(); if (adapter != null) { int itemsCount = adapter.getCount(); if (contextMenuRequested(keyCode)) { View view = gallery.getSelectedView(); view.performLongClick(); return true; } if (isKeyCodeSkipBack(keyCode)) { int selectedItem = gallery.getSelectedItemPosition(); int newPosition = selectedItem - 10; if (newPosition < 0) { newPosition = 0; } gallery.setSelection(newPosition); gallery.requestFocusFromTouch(); return true; } if (isKeyCodeSkipForward(keyCode)) { int selectedItem = gallery.getSelectedItemPosition(); int newPosition = selectedItem + 10; if (newPosition > itemsCount) { newPosition = itemsCount - 1; } gallery.setSelection(newPosition); gallery.requestFocusFromTouch(); return true; } if (keyCode == KeyEvent.KEYCODE_MEDIA_PLAY || keyCode == KeyEvent.KEYCODE_BUTTON_R1) { SeriesContentInfo info = (SeriesContentInfo) gallery.getSelectedItem(); new FindUnwatchedAsyncTask(this).execute(info); return true; } } return super.onKeyDown(keyCode, event); }
From source file:com.av.remusic.receiver.MediaButtonIntentReceiver.java
@Override public void onReceive(final Context context, final Intent intent) { final String intentAction = intent.getAction(); if (AudioManager.ACTION_AUDIO_BECOMING_NOISY.equals(intentAction)) { if (true) startService(context, MediaService.CMDPAUSE); } else if (Intent.ACTION_MEDIA_BUTTON.equals(intentAction)) { final KeyEvent event = intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT); if (event == null) { return; }/*from www. jav a2 s . c o m*/ final int keycode = event.getKeyCode(); final int action = event.getAction(); final long eventtime = event.getEventTime(); String command = null; switch (keycode) { case KeyEvent.KEYCODE_MEDIA_STOP: command = MediaService.CMDSTOP; break; case KeyEvent.KEYCODE_HEADSETHOOK: case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE: command = MediaService.CMDTOGGLEPAUSE; break; case KeyEvent.KEYCODE_MEDIA_NEXT: command = MediaService.CMDNEXT; break; case KeyEvent.KEYCODE_MEDIA_PREVIOUS: command = MediaService.CMDPREVIOUS; break; case KeyEvent.KEYCODE_MEDIA_PAUSE: command = MediaService.CMDPAUSE; break; case KeyEvent.KEYCODE_MEDIA_PLAY: command = MediaService.CMDPLAY; break; } if (command != null) { if (action == KeyEvent.ACTION_DOWN) { if (mDown) { if (MediaService.CMDTOGGLEPAUSE.equals(command) || MediaService.CMDPLAY.equals(command)) { if (mLastClickTime != 0 && eventtime - mLastClickTime > LONG_PRESS_DELAY) { acquireWakeLockAndSendMessage(context, mHandler.obtainMessage(MSG_LONGPRESS_TIMEOUT, context), 0); } } } else if (event.getRepeatCount() == 0) { if (keycode == KeyEvent.KEYCODE_HEADSETHOOK) { if (eventtime - mLastClickTime >= DOUBLE_CLICK) { mClickCounter = 0; } mClickCounter++; if (DEBUG) Log.v(TAG, "Got headset click, count = " + mClickCounter); mHandler.removeMessages(MSG_HEADSET_DOUBLE_CLICK_TIMEOUT); Message msg = mHandler.obtainMessage(MSG_HEADSET_DOUBLE_CLICK_TIMEOUT, mClickCounter, 0, context); long delay = mClickCounter < 3 ? DOUBLE_CLICK : 0; if (mClickCounter >= 3) { mClickCounter = 0; } mLastClickTime = eventtime; acquireWakeLockAndSendMessage(context, msg, delay); } else { startService(context, command); } mLaunched = false; mDown = true; } } else { mHandler.removeMessages(MSG_LONGPRESS_TIMEOUT); mDown = false; } if (isOrderedBroadcast()) { abortBroadcast(); } releaseWakeLockIfHandlerIdle(); } } }
From source file:com.bluros.music.helpers.MediaButtonIntentReceiver.java
@Override public void onReceive(final Context context, final Intent intent) { final String intentAction = intent.getAction(); if (AudioManager.ACTION_AUDIO_BECOMING_NOISY.equals(intentAction)) { if (PreferencesUtility.getInstance(context).pauseEnabledOnDetach()) startService(context, MusicService.CMDPAUSE); } else if (Intent.ACTION_MEDIA_BUTTON.equals(intentAction)) { final KeyEvent event = intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT); if (event == null) { return; }//from w w w . j a v a2 s . co m final int keycode = event.getKeyCode(); final int action = event.getAction(); final long eventtime = event.getEventTime(); String command = null; switch (keycode) { case KeyEvent.KEYCODE_MEDIA_STOP: command = MusicService.CMDSTOP; break; case KeyEvent.KEYCODE_HEADSETHOOK: case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE: command = MusicService.CMDTOGGLEPAUSE; break; case KeyEvent.KEYCODE_MEDIA_NEXT: command = MusicService.CMDNEXT; break; case KeyEvent.KEYCODE_MEDIA_PREVIOUS: command = MusicService.CMDPREVIOUS; break; case KeyEvent.KEYCODE_MEDIA_PAUSE: command = MusicService.CMDPAUSE; break; case KeyEvent.KEYCODE_MEDIA_PLAY: command = MusicService.CMDPLAY; break; } if (command != null) { if (action == KeyEvent.ACTION_DOWN) { if (mDown) { if (MusicService.CMDTOGGLEPAUSE.equals(command) || MusicService.CMDPLAY.equals(command)) { if (mLastClickTime != 0 && eventtime - mLastClickTime > LONG_PRESS_DELAY) { acquireWakeLockAndSendMessage(context, mHandler.obtainMessage(MSG_LONGPRESS_TIMEOUT, context), 0); } } } else if (event.getRepeatCount() == 0) { if (keycode == KeyEvent.KEYCODE_HEADSETHOOK) { if (eventtime - mLastClickTime >= DOUBLE_CLICK) { mClickCounter = 0; } mClickCounter++; if (DEBUG) Log.v(TAG, "Got headset click, count = " + mClickCounter); mHandler.removeMessages(MSG_HEADSET_DOUBLE_CLICK_TIMEOUT); Message msg = mHandler.obtainMessage(MSG_HEADSET_DOUBLE_CLICK_TIMEOUT, mClickCounter, 0, context); long delay = mClickCounter < 3 ? DOUBLE_CLICK : 0; if (mClickCounter >= 3) { mClickCounter = 0; } mLastClickTime = eventtime; acquireWakeLockAndSendMessage(context, msg, delay); } else { startService(context, command); } mLaunched = false; mDown = true; } } else { mHandler.removeMessages(MSG_LONGPRESS_TIMEOUT); mDown = false; } if (isOrderedBroadcast()) { abortBroadcast(); } releaseWakeLockIfHandlerIdle(); } } }
From source file:com.cw.litenote.note.Note.java
@Override public boolean onKeyDown(int keyCode, KeyEvent event) { int newPos;/*w w w. j ava2 s. c o m*/ System.out.println("Note / _onKeyDown / keyCode = " + keyCode); switch (keyCode) { case KeyEvent.KEYCODE_MEDIA_PREVIOUS: //88 if (viewPager.getCurrentItem() == 0) newPos = mPagerAdapter.getCount() - 1;//back to last one else newPos = NoteUi.getFocus_notePos() - 1; NoteUi.setFocus_notePos(newPos); viewPager.setCurrentItem(newPos); BackgroundAudioService.mIsPrepared = false; BackgroundAudioService.mMediaPlayer = null; Audio_manager.isRunnableOn_page = false; findViewById(R.id.pager_btn_audio_play).performClick(); return true; case KeyEvent.KEYCODE_MEDIA_NEXT: //87 if (viewPager.getCurrentItem() == (mPagerAdapter.getCount() - 1)) newPos = 0; else newPos = NoteUi.getFocus_notePos() + 1; NoteUi.setFocus_notePos(newPos); viewPager.setCurrentItem(newPos); BackgroundAudioService.mIsPrepared = false; BackgroundAudioService.mMediaPlayer = null; Audio_manager.isRunnableOn_page = false; AudioUi_note.mPager_audio_play_button.performClick(); return true; case KeyEvent.KEYCODE_MEDIA_PLAY: //126 AudioUi_note.mPager_audio_play_button.performClick(); return true; case KeyEvent.KEYCODE_MEDIA_PAUSE: //127 AudioUi_note.mPager_audio_play_button.performClick(); return true; case KeyEvent.KEYCODE_BACK: onBackPressed(); return true; case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD: return true; case KeyEvent.KEYCODE_MEDIA_REWIND: return true; case KeyEvent.KEYCODE_MEDIA_STOP: return true; } return false; }
From source file:github.daneren2005.dsub.util.Notifications.java
private static void setupViews(RemoteViews rv, Context context, MusicDirectory.Entry song, boolean expanded, boolean playing, boolean remote) { // Use the same text for the ticker and the expanded notification String title = song.getTitle(); String arist = song.getArtist(); String album = song.getAlbum(); // Set the album art. try {/*from w w w. j a va 2 s . c om*/ ImageLoader imageLoader = SubsonicActivity.getStaticImageLoader(context); Bitmap bitmap = null; if (imageLoader != null) { bitmap = imageLoader.getCachedImage(context, song, false); } if (bitmap == null) { // set default album art rv.setImageViewResource(R.id.notification_image, R.drawable.unknown_album); } else { rv.setImageViewBitmap(R.id.notification_image, bitmap); } } catch (Exception x) { Log.w(TAG, "Failed to get notification cover art", x); rv.setImageViewResource(R.id.notification_image, R.drawable.unknown_album); } // set the text for the notifications rv.setTextViewText(R.id.notification_title, title); rv.setTextViewText(R.id.notification_artist, arist); rv.setTextViewText(R.id.notification_album, album); boolean persistent = Util.getPreferences(context) .getBoolean(Constants.PREFERENCES_KEY_PERSISTENT_NOTIFICATION, false); if (persistent) { if (expanded) { rv.setImageViewResource(R.id.control_pause, playing ? R.drawable.notification_pause : R.drawable.notification_start); } else { rv.setImageViewResource(R.id.control_previous, playing ? R.drawable.notification_pause : R.drawable.notification_start); rv.setImageViewResource(R.id.control_pause, R.drawable.notification_forward); rv.setImageViewResource(R.id.control_next, R.drawable.notification_close); } } // Create actions for media buttons PendingIntent pendingIntent; int previous = 0, pause = 0, next = 0, close = 0; if (persistent && !expanded) { pause = R.id.control_previous; next = R.id.control_pause; close = R.id.control_next; } else { previous = R.id.control_previous; pause = R.id.control_pause; next = R.id.control_next; } if ((remote || persistent) && close == 0 && expanded) { close = R.id.notification_close; rv.setViewVisibility(close, View.VISIBLE); } if (previous > 0) { Intent prevIntent = new Intent("KEYCODE_MEDIA_PREVIOUS"); prevIntent.setComponent(new ComponentName(context, DownloadService.class)); prevIntent.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_PREVIOUS)); pendingIntent = PendingIntent.getService(context, 0, prevIntent, 0); rv.setOnClickPendingIntent(previous, pendingIntent); } if (pause > 0) { if (playing) { Intent pauseIntent = new Intent("KEYCODE_MEDIA_PLAY_PAUSE"); pauseIntent.setComponent(new ComponentName(context, DownloadService.class)); pauseIntent.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE)); pendingIntent = PendingIntent.getService(context, 0, pauseIntent, 0); rv.setOnClickPendingIntent(pause, pendingIntent); } else { Intent prevIntent = new Intent("KEYCODE_MEDIA_START"); prevIntent.setComponent(new ComponentName(context, DownloadService.class)); prevIntent.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_PLAY)); pendingIntent = PendingIntent.getService(context, 0, prevIntent, 0); rv.setOnClickPendingIntent(pause, pendingIntent); } } if (next > 0) { Intent nextIntent = new Intent("KEYCODE_MEDIA_NEXT"); nextIntent.setComponent(new ComponentName(context, DownloadService.class)); nextIntent.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_NEXT)); pendingIntent = PendingIntent.getService(context, 0, nextIntent, 0); rv.setOnClickPendingIntent(next, pendingIntent); } if (close > 0) { Intent prevIntent = new Intent("KEYCODE_MEDIA_STOP"); prevIntent.setComponent(new ComponentName(context, DownloadService.class)); prevIntent.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_STOP)); pendingIntent = PendingIntent.getService(context, 0, prevIntent, 0); rv.setOnClickPendingIntent(close, pendingIntent); } }
From source file:com.oakesville.mythling.MediaPagerActivity.java
@Override public boolean dispatchKeyEvent(KeyEvent event) { if (event.getAction() == KeyEvent.ACTION_DOWN) { if (event.getKeyCode() == KeyEvent.KEYCODE_DPAD_DOWN) { if ((getCurrentFocus().getParent() instanceof View && ((View) getCurrentFocus().getParent()).getId() == R.id.button_bar) || getCurrentFocus().getId() == R.id.title_text) { findViewById(R.id.pager_position).requestFocus(); return true; }// ww w . j a va2s . c o m } else if (event.getKeyCode() == KeyEvent.KEYCODE_DPAD_RIGHT) { if (getCurrentFocus().getId() == R.id.pager_position) { if (pager.getCurrentItem() < getListables().size() - 1) { pager.setCurrentItem(pager.getCurrentItem() + 1); positionBar.setProgress(pager.getCurrentItem()); return true; } } } else if (event.getKeyCode() == KeyEvent.KEYCODE_DPAD_LEFT) { if (getCurrentFocus().getId() == R.id.pager_position) { if (pager.getCurrentItem() > 0) { pager.setCurrentItem(pager.getCurrentItem() - 1); positionBar.setProgress(pager.getCurrentItem()); return true; } } } else if (event.getKeyCode() == KeyEvent.KEYCODE_MEDIA_FAST_FORWARD) { pager.setCurrentItem(getListables().size() - 1); positionBar.setProgress(getListables().size() - 1); return true; } else if (event.getKeyCode() == KeyEvent.KEYCODE_MEDIA_REWIND) { pager.setCurrentItem(0); positionBar.setProgress(0); return true; } else if (event.getKeyCode() == KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE || event.getKeyCode() == KeyEvent.KEYCODE_MEDIA_PLAY) { Listable listable = getListables().get(pager.getCurrentItem()); if (listable instanceof Item) { playItem((Item) listable); return true; } } } return super.dispatchKeyEvent(event); }
From source file:com.vuze.android.remote.fragment.FilesFragment.java
public View onCreateView(android.view.LayoutInflater inflater, android.view.ViewGroup container, Bundle savedInstanceState) {//w ww.ja va 2 s .c o m if (AndroidUtils.DEBUG) { Log.d(TAG, "onCreateview " + this); } View view = inflater.inflate(R.layout.frag_torrent_files, container, false); FragmentActivity activity = getActivity(); progressBar = (ProgressBar) activity.findViewById(R.id.details_progress_bar); viewAreaToggleEditMode = view.findViewById(R.id.files_area_toggleditmode); tvScrollTitle = (TextView) view.findViewById(R.id.files_scrolltitle); btnEditMode = (CompoundButton) view.findViewById(R.id.files_editmode); if (btnEditMode != null) { btnEditMode.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (adapter == null) { return; } adapter.setInEditMode(btnEditMode.isChecked()); } }); } final SwipeRefreshLayoutExtra swipeRefresh = (SwipeRefreshLayoutExtra) view .findViewById(R.id.swipe_container); if (swipeRefresh != null) { swipeRefresh.setExtraLayout(R.layout.swipe_layout_extra); swipeRefresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { @Override public void onRefresh() { if (sessionInfo == null) { return; } showProgressBar(); sessionInfo.executeRpc(new RpcExecuter() { @Override public void executeRpc(TransmissionRPC rpc) { rpc.getTorrentFileInfo(TAG, torrentID, null, new TorrentListReceivedListener() { @Override public void rpcTorrentListReceived(String callID, List<?> addedTorrentMaps, List<?> removedTorrentIDs) { AndroidUtils.runOnUIThread(FilesFragment.this, new Runnable() { @Override public void run() { swipeRefresh.setRefreshing(false); } }); } }); } }); } }); swipeRefresh.setOnExtraViewVisibilityChange(this); } listview = (RecyclerView) view.findViewById(R.id.files_list); listview.setLayoutManager(new PreCachingLayoutManager(getContext())); listview.setAdapter(adapter); listview.setOnKeyListener(new View.OnKeyListener() { @Override public boolean onKey(View v, int keyCode, KeyEvent event) { { if (event.getAction() != KeyEvent.ACTION_DOWN) { return false; } switch (keyCode) { case KeyEvent.KEYCODE_DPAD_RIGHT: { // expand int i = adapter.getSelectedPosition(); FilesAdapterDisplayObject item = adapter.getItem(i); if (item instanceof FilesAdapterDisplayFolder) { if (!((FilesAdapterDisplayFolder) item).expand) { ((FilesAdapterDisplayFolder) item).expand = true; adapter.getFilter().filter(""); return true; } } break; } case KeyEvent.KEYCODE_DPAD_LEFT: { // collapse int i = adapter.getSelectedPosition(); FilesAdapterDisplayObject item = adapter.getItem(i); if (item instanceof FilesAdapterDisplayFolder) { if (((FilesAdapterDisplayFolder) item).expand) { ((FilesAdapterDisplayFolder) item).expand = false; adapter.getFilter().filter(""); return true; } } break; } case KeyEvent.KEYCODE_MEDIA_PLAY: case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE: { launchOrStreamFile(); return true; } } return false; } } }); listview.setOnScrollListener(new RecyclerView.OnScrollListener() { int firstVisibleItem = 0; @Override public void onScrolled(RecyclerView recyclerView, int dx, int dy) { super.onScrolled(recyclerView, dx, dy); LinearLayoutManager lm = (LinearLayoutManager) listview.getLayoutManager(); int firstVisibleItem = lm.findFirstCompletelyVisibleItemPosition(); if (firstVisibleItem != this.firstVisibleItem) { this.firstVisibleItem = firstVisibleItem; FilesAdapterDisplayObject itemAtPosition = adapter.getItem(firstVisibleItem); // Log.d(TAG, "itemAt" + firstVisibleItem + " is " + itemAtPosition); // Log.d(TAG, "tvScrollTitle=" + tvScrollTitle); // Log.d(TAG, "viewAreaToggleEditMode=" + viewAreaToggleEditMode); if (itemAtPosition == null) { return; } if (itemAtPosition.parent != null) { if (viewAreaToggleEditMode != null) { viewAreaToggleEditMode.setVisibility(View.GONE); } if (tvScrollTitle != null) { tvScrollTitle.setVisibility(View.VISIBLE); tvScrollTitle.setText(itemAtPosition.parent.folder); } } else { if (viewAreaToggleEditMode != null) { viewAreaToggleEditMode.setVisibility(View.VISIBLE); } if (tvScrollTitle != null) { if (viewAreaToggleEditMode != null) { tvScrollTitle.setVisibility(View.INVISIBLE); } tvScrollTitle.setText(""); } } } } }); FlexibleRecyclerSelectionListener rs = new FlexibleRecyclerSelectionListener<FilesTreeAdapter, FilesAdapterDisplayObject>() { @Override public void onItemSelected(FilesTreeAdapter adapter, final int position, boolean isChecked) { } @Override public void onItemClick(FilesTreeAdapter adapter, int position) { if (AndroidUtils.usesNavigationControl()) { FilesAdapterDisplayObject oItem = adapter.getItem(position); if (adapter.isInEditMode()) { adapter.flipWant(oItem); return; } if (oItem instanceof FilesAdapterDisplayFolder) { FilesAdapterDisplayFolder oFolder = (FilesAdapterDisplayFolder) oItem; oFolder.expand = !oFolder.expand; adapter.getFilter().filter(""); } else { showFileContextMenu(); } } } @Override public boolean onItemLongClick(FilesTreeAdapter adapter, int position) { if (AndroidUtils.usesNavigationControl()) { if (showFileContextMenu()) { return true; } } return false; } @Override public void onItemCheckedChanged(FilesTreeAdapter adapter, FilesAdapterDisplayObject item, boolean isChecked) { if (adapter.getCheckedItemCount() == 0) { finishActionMode(); } else { // Update the subtitle with file name showContextualActions(); } AndroidUtils.invalidateOptionsMenuHC(getActivity(), mActionMode); } }; adapter = new FilesTreeAdapter(this.getActivity(), rs); adapter.setSessionInfo(sessionInfo); adapter.setMultiCheckModeAllowed(false); adapter.setCheckOnSelectedAfterMS(100); listview.setAdapter(adapter); return view; }
From source file:github.popeen.dsub.util.Notifications.java
private static void setupViews(RemoteViews rv, Context context, MusicDirectory.Entry song, boolean expanded, boolean playing, boolean remote, boolean isSingleFile, boolean shouldFastForward) { // Use the same text for the ticker and the expanded notification String title = song.getTitle(); String arist = song.getArtist(); String album = song.getAlbum(); // Set the album art. try {//from ww w .ja v a2 s . c om ImageLoader imageLoader = SubsonicActivity.getStaticImageLoader(context); Bitmap bitmap = null; if (imageLoader != null) { bitmap = imageLoader.getCachedImage(context, song, false); } if (bitmap == null) { // set default album art rv.setImageViewResource(R.id.notification_image, R.drawable.unknown_album); } else { imageLoader.setNowPlayingSmall(bitmap); rv.setImageViewBitmap(R.id.notification_image, bitmap); } } catch (Exception x) { Log.w(TAG, "Failed to get notification cover art", x); rv.setImageViewResource(R.id.notification_image, R.drawable.unknown_album); } // set the text for the notifications rv.setTextViewText(R.id.notification_title, title); rv.setTextViewText(R.id.notification_artist, arist); rv.setTextViewText(R.id.notification_album, album); boolean persistent = Util.getPreferences(context) .getBoolean(Constants.PREFERENCES_KEY_PERSISTENT_NOTIFICATION, false); if (persistent) { if (expanded) { rv.setImageViewResource(R.id.control_pause, playing ? R.drawable.notification_pause : R.drawable.notification_start); if (shouldFastForward) { rv.setImageViewResource(R.id.control_previous, R.drawable.notification_rewind); rv.setImageViewResource(R.id.control_next, R.drawable.notification_fastforward); } else { rv.setImageViewResource(R.id.control_previous, R.drawable.notification_backward); rv.setImageViewResource(R.id.control_next, R.drawable.notification_forward); } } else { rv.setImageViewResource(R.id.control_previous, playing ? R.drawable.notification_pause : R.drawable.notification_start); if (shouldFastForward) { rv.setImageViewResource(R.id.control_pause, R.drawable.notification_fastforward); } else { rv.setImageViewResource(R.id.control_pause, R.drawable.notification_forward); } rv.setImageViewResource(R.id.control_next, R.drawable.notification_close); } } else if (shouldFastForward) { rv.setImageViewResource(R.id.control_previous, R.drawable.notification_rewind); rv.setImageViewResource(R.id.control_next, R.drawable.notification_fastforward); } else { // Necessary for switching back since it appears to re-use the same layout rv.setImageViewResource(R.id.control_previous, R.drawable.notification_backward); rv.setImageViewResource(R.id.control_next, R.drawable.notification_forward); } // Create actions for media buttons int previous = 0, pause = 0, next = 0, close = 0, rewind = 0, fastForward = 0; if (expanded) { pause = R.id.control_pause; if (shouldFastForward) { rewind = R.id.control_previous; fastForward = R.id.control_next; } else { previous = R.id.control_previous; next = R.id.control_next; } if (remote || persistent) { close = R.id.notification_close; rv.setViewVisibility(close, View.VISIBLE); } } else { if (persistent) { pause = R.id.control_previous; if (shouldFastForward) { fastForward = R.id.control_pause; } else { next = R.id.control_pause; } close = R.id.control_next; } else { if (shouldFastForward) { rewind = R.id.control_previous; fastForward = R.id.control_next; } else { previous = R.id.control_previous; next = R.id.control_next; } pause = R.id.control_pause; } } if (isSingleFile) { if (previous > 0) { rv.setViewVisibility(previous, View.GONE); previous = 0; } if (rewind > 0) { rv.setViewVisibility(rewind, View.GONE); rewind = 0; } if (next > 0) { rv.setViewVisibility(next, View.GONE); next = 0; } if (fastForward > 0) { rv.setViewVisibility(fastForward, View.GONE); fastForward = 0; } } PendingIntent pendingIntent; if (previous > 0) { Intent prevIntent = new Intent("KEYCODE_MEDIA_PREVIOUS"); prevIntent.setComponent(new ComponentName(context, DownloadService.class)); prevIntent.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_MEDIA_PREVIOUS)); pendingIntent = PendingIntent.getService(context, 0, prevIntent, 0); rv.setOnClickPendingIntent(previous, pendingIntent); } if (rewind > 0) { Intent rewindIntent = new Intent("KEYCODE_MEDIA_REWIND"); rewindIntent.setComponent(new ComponentName(context, DownloadService.class)); rewindIntent.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_MEDIA_REWIND)); pendingIntent = PendingIntent.getService(context, 0, rewindIntent, 0); rv.setOnClickPendingIntent(rewind, pendingIntent); } if (pause > 0) { if (playing) { Intent pauseIntent = new Intent("KEYCODE_MEDIA_PLAY_PAUSE"); pauseIntent.setComponent(new ComponentName(context, DownloadService.class)); pauseIntent.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE)); pendingIntent = PendingIntent.getService(context, 0, pauseIntent, 0); rv.setOnClickPendingIntent(pause, pendingIntent); } else { Intent prevIntent = new Intent("KEYCODE_MEDIA_START"); prevIntent.setComponent(new ComponentName(context, DownloadService.class)); prevIntent.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_MEDIA_PLAY)); pendingIntent = PendingIntent.getService(context, 0, prevIntent, 0); rv.setOnClickPendingIntent(pause, pendingIntent); } } if (next > 0) { Intent nextIntent = new Intent("KEYCODE_MEDIA_NEXT"); nextIntent.setComponent(new ComponentName(context, DownloadService.class)); nextIntent.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_MEDIA_NEXT)); pendingIntent = PendingIntent.getService(context, 0, nextIntent, 0); rv.setOnClickPendingIntent(next, pendingIntent); } if (fastForward > 0) { Intent fastForwardIntent = new Intent("KEYCODE_MEDIA_FAST_FORWARD"); fastForwardIntent.setComponent(new ComponentName(context, DownloadService.class)); fastForwardIntent.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_MEDIA_FAST_FORWARD)); pendingIntent = PendingIntent.getService(context, 0, fastForwardIntent, 0); rv.setOnClickPendingIntent(fastForward, pendingIntent); } if (close > 0) { Intent prevIntent = new Intent("KEYCODE_MEDIA_STOP"); prevIntent.setComponent(new ComponentName(context, DownloadService.class)); prevIntent.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_MEDIA_STOP)); pendingIntent = PendingIntent.getService(context, 0, prevIntent, 0); rv.setOnClickPendingIntent(close, pendingIntent); } }
From source file:com.example.android.mediarouter.player.MainActivity.java
public boolean handleMediaKey(KeyEvent event) { if (event.getAction() == KeyEvent.ACTION_DOWN && event.getRepeatCount() == 0) { switch (event.getKeyCode()) { case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE: { Log.d(TAG, "Received Play/Pause event from RemoteControlClient"); mPaused = !mPaused;//from www . j av a 2 s . c o m if (mPaused) { mSessionManager.pause(); } else { mSessionManager.resume(); } return true; } case KeyEvent.KEYCODE_MEDIA_PLAY: { Log.d(TAG, "Received Play event from RemoteControlClient"); if (mPaused) { mPaused = false; mSessionManager.resume(); } return true; } case KeyEvent.KEYCODE_MEDIA_PAUSE: { Log.d(TAG, "Received Pause event from RemoteControlClient"); if (!mPaused) { mPaused = true; mSessionManager.pause(); } return true; } case KeyEvent.KEYCODE_MEDIA_STOP: { Log.d(TAG, "Received Stop event from RemoteControlClient"); mPaused = false; mSessionManager.stop(); return true; } default: break; } } return false; }