List of usage examples for android.view KeyEvent KeyEvent
private KeyEvent(KeyEvent origEvent, int action)
From source file:org.deviceconnect.android.deviceplugin.host.activity.KeyEventProfileActivity.java
@Override public boolean onTouch(final View v, final MotionEvent event) { int action = event.getAction(); // Emulate ten key down/up event. switch (action) { case MotionEvent.ACTION_DOWN: case MotionEvent.ACTION_UP: KeyEvent keyevent = null; int i = v.getId(); if (i == R.id.button_0) { keyevent = new KeyEvent(action, KeyEvent.KEYCODE_NUMPAD_0); } else if (i == R.id.button_1) { keyevent = new KeyEvent(action, KeyEvent.KEYCODE_NUMPAD_1); } else if (i == R.id.button_2) { keyevent = new KeyEvent(action, KeyEvent.KEYCODE_NUMPAD_2); } else if (i == R.id.button_3) { keyevent = new KeyEvent(action, KeyEvent.KEYCODE_NUMPAD_3); } else if (i == R.id.button_4) { keyevent = new KeyEvent(action, KeyEvent.KEYCODE_NUMPAD_4); } else if (i == R.id.button_5) { keyevent = new KeyEvent(action, KeyEvent.KEYCODE_NUMPAD_5); } else if (i == R.id.button_6) { keyevent = new KeyEvent(action, KeyEvent.KEYCODE_NUMPAD_6); } else if (i == R.id.button_7) { keyevent = new KeyEvent(action, KeyEvent.KEYCODE_NUMPAD_7); } else if (i == R.id.button_8) { keyevent = new KeyEvent(action, KeyEvent.KEYCODE_NUMPAD_8); } else if (i == R.id.button_9) { keyevent = new KeyEvent(action, KeyEvent.KEYCODE_NUMPAD_9); } else if (i == R.id.button_dot) { keyevent = new KeyEvent(action, KeyEvent.KEYCODE_NUMPAD_DOT); } else if (i == R.id.button_enter) { keyevent = new KeyEvent(action, KeyEvent.KEYCODE_NUMPAD_ENTER); } else if (i == R.id.button_keyevent_close) { finish();//from ww w . ja va 2 s.c o m } if (keyevent != null) { dispatchKeyEvent(keyevent); } break; default: break; } return false; }
From source file:net.sourceforge.kalimbaradio.androidapp.util.NotificationUtil.java
private static Notification createCustomNotification(Context context, MusicDirectory.Entry song, boolean playing) { Bitmap albumArt;// ww w.j a v a 2 s . c o m try { albumArt = FileUtil.getUnscaledAlbumArtBitmap(context, song); if (albumArt == null) { albumArt = Util.decodeBitmap(context, R.drawable.unknown_album_large); } } catch (Exception x) { LOG.warn("Failed to get notification cover art", x); albumArt = Util.decodeBitmap(context, R.drawable.unknown_album_large); } RemoteViews contentView = new RemoteViews(context.getPackageName(), R.layout.notification); contentView.setTextViewText(R.id.notification_title, song.getTitle()); contentView.setTextViewText(R.id.notification_artist, song.getArtist()); contentView.setImageViewBitmap(R.id.notification_image, albumArt); contentView.setImageViewResource(R.id.notification_playpause, playing ? R.drawable.media_pause : R.drawable.media_start); Intent intent = new Intent("1"); intent.setComponent(new ComponentName(context, DownloadServiceImpl.class)); intent.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE)); contentView.setOnClickPendingIntent(R.id.notification_playpause, PendingIntent.getService(context, 0, intent, 0)); intent = new Intent("2"); intent.setComponent(new ComponentName(context, DownloadServiceImpl.class)); intent.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_NEXT)); contentView.setOnClickPendingIntent(R.id.notification_next, PendingIntent.getService(context, 0, intent, 0)); intent = new Intent("4"); intent.setComponent(new ComponentName(context, DownloadServiceImpl.class)); intent.putExtra(Constants.INTENT_EXTRA_NAME_HIDE_NOTIFICATION, true); contentView.setOnClickPendingIntent(R.id.notification_close, PendingIntent.getService(context, 0, intent, 0)); Intent notificationIntent = new Intent(context, DownloadActivity.class); Notification notification = new NotificationCompat.Builder(context).setOngoing(true) .setSmallIcon(R.drawable.stat_notify_playing).setContent(contentView) .setContentIntent(PendingIntent.getActivity(context, 0, notificationIntent, 0)).build(); if (Build.VERSION.SDK_INT >= 16) { notification.bigContentView = createBigContentView(context, song, albumArt, playing); } return notification; }
From source file:hku.fyp14017.blencode.ui.fragment.FormulaEditorVariableListFragment.java
@Override public void onListItemClick(int position) { Log.d("catroid", "onListItemClick"); if (!inContextMode) { FormulaEditorFragment formulaEditor = (FormulaEditorFragment) getSherlockActivity() .getSupportFragmentManager() .findFragmentByTag(FormulaEditorFragment.FORMULA_EDITOR_FRAGMENT_TAG); if (formulaEditor != null) { formulaEditor.addUserVariableToActiveFormula(adapter.getItem(position).getName()); formulaEditor.updateButtonViewOnKeyboard(); }//from w w w.ja v a 2 s . com KeyEvent keyEvent = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_BACK); onKey(null, keyEvent.getKeyCode(), keyEvent); } }
From source file:org.catrobat.catroid.ui.fragment.FormulaEditorDataFragment.java
@Override public void onListItemClick(int position) { if (!inContextMode) { FormulaEditorFragment formulaEditor = (FormulaEditorFragment) getSherlockActivity() .getSupportFragmentManager() .findFragmentByTag(FormulaEditorFragment.FORMULA_EDITOR_FRAGMENT_TAG); if (formulaEditor != null) { Object itemToAdd = adapter.getItem(position); if (itemToAdd instanceof UserVariable) { formulaEditor.addUserVariableToActiveFormula(((UserVariable) itemToAdd).getName()); } else if (itemToAdd instanceof UserList) { formulaEditor.addUserListToActiveFormula(((UserList) itemToAdd).getName()); }//from w ww . j a v a2 s. c o m formulaEditor.updateButtonsOnKeyboardAndInvalidateOptionsMenu(); } KeyEvent keyEvent = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_BACK); onKey(null, keyEvent.getKeyCode(), keyEvent); } }
From source file:com.bullmobi.message.services.media.MediaController2KitKat.java
/** * {@inheritDoc}//from w w w . ja v a2s. c o m */ public void sendMediaAction(int action) { int keyCode; switch (action) { case ACTION_PLAY_PAUSE: keyCode = KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE; break; case ACTION_STOP: keyCode = KeyEvent.KEYCODE_MEDIA_STOP; break; case ACTION_SKIP_TO_NEXT: keyCode = KeyEvent.KEYCODE_MEDIA_NEXT; break; case ACTION_SKIP_TO_PREVIOUS: keyCode = KeyEvent.KEYCODE_MEDIA_PREVIOUS; break; default: throw new IllegalArgumentException(); } // TODO We should think about sending these up/down events accurately with touch up/down // on the buttons, but in the near term this will interfere with the long press behavior. RemoteController rc = mService.getRemoteController(); rc.sendMediaKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, keyCode)); rc.sendMediaKeyEvent(new KeyEvent(KeyEvent.ACTION_UP, keyCode)); }
From source file:com.achep.acdisplay.services.media.MediaController2KitKat.java
/** * {@inheritDoc}// w w w . j a v a2 s . co m */ public void sendMediaAction(int action) { if (mService == null) { Log.w(TAG, "Sending a media action on stopped controller."); return; } int keyCode; switch (action) { case ACTION_PLAY_PAUSE: keyCode = KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE; break; case ACTION_STOP: keyCode = KeyEvent.KEYCODE_MEDIA_STOP; break; case ACTION_SKIP_TO_NEXT: keyCode = KeyEvent.KEYCODE_MEDIA_NEXT; break; case ACTION_SKIP_TO_PREVIOUS: keyCode = KeyEvent.KEYCODE_MEDIA_PREVIOUS; break; default: throw new IllegalArgumentException(); } // TODO We should think about sending these up/down events accurately with touch up/down // on the buttons, but in the near term this will interfere with the long press behavior. RemoteController rc = mService.getRemoteController(); rc.sendMediaKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, keyCode)); rc.sendMediaKeyEvent(new KeyEvent(KeyEvent.ACTION_UP, keyCode)); }
From source file:com.vmihalachi.turboeditor.fragment.EditorFragment.java
/** * {@inheritDoc}//from w ww. ja v a2s. c o m */ @Override public boolean onOptionsItemSelected(MenuItem item) { int i = item.getItemId(); if (i == R.id.im_save) { new SaveFile().execute(); } else if (i == R.id.im_undo) { this.mEditor.onKeyShortcut(KeyEvent.KEYCODE_Z, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_Z)); } else if (i == R.id.im_redo) { this.mEditor.onKeyShortcut(KeyEvent.KEYCODE_Y, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_Y)); } else if (i == R.id.im_editor_encoding) { EditDialogFragment dialogFrag = EditDialogFragment.newInstance(EditDialogFragment.Actions.Encoding, this.mCurrentEncoding); dialogFrag.setTargetFragment(this, 0); dialogFrag.show(getFragmentManager().beginTransaction(), "dialog"); } else if (i == R.id.im_text_size) { int fontMax = 36; float scaledDensity = getResources().getDisplayMetrics().scaledDensity; int fontCurrent = (int) (mEditor.getTextSize() / scaledDensity); SeekbarDialogFragment dialogFrag = SeekbarDialogFragment .newInstance(SeekbarDialogFragment.Actions.FileSize, fontCurrent, fontMax); dialogFrag.setTargetFragment(this, 0); dialogFrag.show(getFragmentManager().beginTransaction(), "dialog"); } else if (i == R.id.im_syntax_highlight) { item.setChecked(!item.isChecked()); PreferenceHelper.setSyntaxHiglight(getActivity(), item.isChecked()); updateTextEditor(); } else if (i == R.id.im_line_numbers) { item.setChecked(!item.isChecked()); PreferenceHelper.setLineNumbers(getActivity(), item.isChecked()); updateTextEditor(); } else if (i == R.id.im_use_monospace) { item.setChecked(!item.isChecked()); PreferenceHelper.setUseMonospace(getActivity(), item.isChecked()); updateTextEditor(); } return super.onOptionsItemSelected(item); }
From source file:org.catrobat.catroid.ui.fragment.FormulaEditorListFragment.java
@Override public void onListItemClick(ListView listView, View view, int position, long id) { FormulaEditorFragment formulaEditor = (FormulaEditorFragment) getSherlockActivity() .getSupportFragmentManager().findFragmentByTag(FormulaEditorFragment.FORMULA_EDITOR_FRAGMENT_TAG); if (formulaEditor != null) { formulaEditor.addResourceToActiveFormula(itemsIds[position]); formulaEditor.updateButtonsOnKeyboardAndInvalidateOptionsMenu(); }/*from w w w .j a v a 2s . com*/ KeyEvent keyEvent = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_BACK); onKey(null, keyEvent.getKeyCode(), keyEvent); }
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 ww w .jav a 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:net.sourceforge.kalimbaradio.androidapp.util.NotificationUtil.java
private static RemoteViews createBigContentView(Context context, MusicDirectory.Entry song, Bitmap albumArt, boolean playing) { RemoteViews contentView = new RemoteViews(context.getPackageName(), R.layout.notification_expanded); contentView.setTextViewText(R.id.notification_title, song.getTitle()); contentView.setTextViewText(R.id.notification_artist, song.getArtist()); contentView.setTextViewText(R.id.notification_album, song.getAlbum()); contentView.setImageViewBitmap(R.id.notification_image, albumArt); contentView.setImageViewResource(R.id.notification_playpause, playing ? R.drawable.media_pause : R.drawable.media_start); Intent intent = new Intent("1"); intent.setComponent(new ComponentName(context, DownloadServiceImpl.class)); intent.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE)); contentView.setOnClickPendingIntent(R.id.notification_playpause, PendingIntent.getService(context, 0, intent, 0)); intent = new Intent("2"); intent.setComponent(new ComponentName(context, DownloadServiceImpl.class)); intent.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_NEXT)); contentView.setOnClickPendingIntent(R.id.notification_next, PendingIntent.getService(context, 0, intent, 0)); intent = new Intent("3"); intent.setComponent(new ComponentName(context, DownloadServiceImpl.class)); intent.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_PREVIOUS)); contentView.setOnClickPendingIntent(R.id.notification_prev, PendingIntent.getService(context, 0, intent, 0)); intent = new Intent("4"); intent.setComponent(new ComponentName(context, DownloadServiceImpl.class)); intent.putExtra(Constants.INTENT_EXTRA_NAME_HIDE_NOTIFICATION, true); contentView.setOnClickPendingIntent(R.id.notification_close, PendingIntent.getService(context, 0, intent, 0)); return contentView; }