List of usage examples for android.view KeyEvent KeyEvent
private KeyEvent(KeyEvent origEvent, int action)
From source file:hku.fyp14017.blencode.ui.fragment.FormulaEditorListFragment.java
@Override public void onListItemClick(ListView listView, View view, int position, long id) { if (position >= itemsIds.length) { SensorTagFragment sensorTagFragment; FragmentManager fm = getSherlockActivity().getSupportFragmentManager(); sensorTagFragment = (SensorTagFragment) fm.findFragmentByTag(SensorTagFragment.SENSOR_TAG_FRAGMENT_TAG); if (sensorTagFragment == null) { sensorTagFragment = new SensorTagFragment(); Bundle bundle = new Bundle(); bundle.putInt("Tag number", position - (itemsIds.length - 1)); sensorTagFragment.setArguments(bundle); FragmentTransaction ft = fm.beginTransaction(); ft.add(hku.fyp14017.blencode.R.id.script_fragment_container, sensorTagFragment, SensorTagFragment.SENSOR_TAG_FRAGMENT_TAG); ft.hide(this); ft.commit();/*w w w . j a va2 s .co m*/ } else { /*Bundle bundle = new Bundle(); bundle.putInt("Tag number", position - (itemsIds.length-1)); sensorTagFragment.setArguments(bundle);*/ FragmentTransaction ft = fm.beginTransaction(); ft.hide(this).show(sensorTagFragment).commit(); } } else { FormulaEditorFragment formulaEditor = (FormulaEditorFragment) getSherlockActivity() .getSupportFragmentManager() .findFragmentByTag(FormulaEditorFragment.FORMULA_EDITOR_FRAGMENT_TAG); if (formulaEditor != null) { formulaEditor.addResourceToActiveFormula(itemsIds[position]); formulaEditor.updateButtonViewOnKeyboard(); KeyEvent keyEvent = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_BACK); onKey(null, keyEvent.getKeyCode(), keyEvent); } } }
From source file:com.android.tv.TvApplication.java
/** * Handles the global key KEYCODE_TV_INPUT. *///from w w w . ja v a 2 s .co m public void handleTvInputKey() { TvInputManager tvInputManager = (TvInputManager) getSystemService(Context.TV_INPUT_SERVICE); List<TvInputInfo> tvInputs = tvInputManager.getTvInputList(); int inputCount = 0; boolean hasTunerInput = false; for (TvInputInfo input : tvInputs) { if (input.isPassthroughInput()) { if (!input.isHidden(this)) { ++inputCount; } } else if (!hasTunerInput) { hasTunerInput = true; ++inputCount; } } if (inputCount < 2) { return; } Activity activityToHandle = mMainActivityWrapper.isResumed() ? mMainActivityWrapper.getMainActivity() : mSelectInputActivity; if (activityToHandle != null) { // If startActivity is called, MainActivity.onPause is unnecessarily called. To // prevent it, MainActivity.dispatchKeyEvent is directly called. activityToHandle.dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_TV_INPUT)); activityToHandle.dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_TV_INPUT)); } else if (mMainActivityWrapper.isStarted()) { Bundle extras = new Bundle(); extras.putString(Utils.EXTRA_KEY_ACTION, Utils.EXTRA_ACTION_SHOW_TV_INPUT); startMainActivity(extras); } else { startActivity(new Intent(this, SelectInputActivity.class).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)); } }
From source file:com.volosyukivan.WiFiInputMethod.java
void sendKey(int code, boolean down, boolean resetModifiers) { long time = System.currentTimeMillis(); if (time - lastWake > 5000) { wakeLock.acquire();/*from ww w .j a v a2s .co m*/ wakeLock.release(); lastWake = time; } InputConnection conn = getCurrentInputConnection(); if (conn == null) { // Debug.d("connection closed"); return; } if (code < 0) { if (down == false) return; switch (code) { case KEY_HOME: keyHome(conn); break; case KEY_END: keyEnd(conn); break; case KEY_DEL: keyDel(conn); break; } return; } if (code == KeyEvent.KEYCODE_DPAD_LEFT && pressedKeys.contains(KEY_CONTROL)) { if (down == false) return; wordLeft(conn); return; } else if (code == KeyEvent.KEYCODE_DPAD_RIGHT && pressedKeys.contains(KEY_CONTROL)) { if (down == false) return; wordRight(conn); return; } else if (code == KeyEvent.KEYCODE_DPAD_CENTER) { if (pressedKeys.contains(KEY_CONTROL)) { if (!down) return; copy(conn); return; } if (pressedKeys.contains(KeyEvent.KEYCODE_SHIFT_LEFT)) { if (!down) return; paste(conn); return; } } // if (pressedKeys.contains(KEY_CONTROL)) { // if (down == false) return; // switch (code) { // case KeyEvent.KEYCODE_A: selectAll(conn); break; // case KeyEvent.KEYCODE_X: cut(conn); break; // case KeyEvent.KEYCODE_C: copy(conn); break; // case KeyEvent.KEYCODE_V: paste(conn); break; // } // return; // } conn.sendKeyEvent(new KeyEvent(down ? KeyEvent.ACTION_DOWN : KeyEvent.ACTION_UP, code)); if (resetModifiers) { conn.clearMetaKeyStates(KeyEvent.META_ALT_ON | KeyEvent.META_SHIFT_ON | KeyEvent.META_SYM_ON); } }
From source file:androidx.media.session.MediaButtonReceiver.java
/** * Creates a broadcast pending intent that will send a media button event. The {@code action} * will be translated to the appropriate {@link KeyEvent}, and sent to the provided media * button receiver via the pending intent. The {@code action} should be one of the following: * <ul>/*w w w . j a v a2s .c o m*/ * <li>{@link PlaybackStateCompat#ACTION_PLAY}</li> * <li>{@link PlaybackStateCompat#ACTION_PAUSE}</li> * <li>{@link PlaybackStateCompat#ACTION_SKIP_TO_NEXT}</li> * <li>{@link PlaybackStateCompat#ACTION_SKIP_TO_PREVIOUS}</li> * <li>{@link PlaybackStateCompat#ACTION_STOP}</li> * <li>{@link PlaybackStateCompat#ACTION_FAST_FORWARD}</li> * <li>{@link PlaybackStateCompat#ACTION_REWIND}</li> * <li>{@link PlaybackStateCompat#ACTION_PLAY_PAUSE}</li> * </ul> * * @param context The context of the application. * @param mbrComponent The full component name of a media button receiver where you want to send * this intent. * @param action The action to be sent via the pending intent. * @return Created pending intent, or null if the given component name is null or the * {@code action} is unsupported/invalid. */ public static PendingIntent buildMediaButtonPendingIntent(Context context, ComponentName mbrComponent, @MediaKeyAction long action) { if (mbrComponent == null) { Log.w(TAG, "The component name of media button receiver should be provided."); return null; } int keyCode = PlaybackStateCompat.toKeyCode(action); if (keyCode == KeyEvent.KEYCODE_UNKNOWN) { Log.w(TAG, "Cannot build a media button pending intent with the given action: " + action); return null; } Intent intent = new Intent(Intent.ACTION_MEDIA_BUTTON); intent.setComponent(mbrComponent); intent.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_DOWN, keyCode)); return PendingIntent.getBroadcast(context, keyCode, intent, 0); }
From source file:org.connectbot.TerminalView.java
@Override public InputConnection onCreateInputConnection(EditorInfo outAttrs) { outAttrs.imeOptions |= EditorInfo.IME_FLAG_NO_EXTRACT_UI | EditorInfo.IME_FLAG_NO_ENTER_ACTION | EditorInfo.IME_ACTION_NONE; outAttrs.inputType = EditorInfo.TYPE_NULL; return new BaseInputConnection(this, false) { @Override//from www.ja v a2 s .c om public boolean deleteSurroundingText(int leftLength, int rightLength) { if (rightLength == 0 && leftLength == 0) { return this.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DEL)); } for (int i = 0; i < leftLength; i++) { this.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DEL)); } // TODO: forward delete return true; } }; }
From source file:org.tigase.messenger.phone.pro.conversations.chat.ChatItemFragment.java
@Override public void onEmojiDelete() { String text = this.message.getText().toString(); if (text.isEmpty()) { return;/*from w w w . j av a2 s . c o m*/ } if ("]".equals(text.substring(text.length() - 1, text.length()))) { int index = text.lastIndexOf("["); if (index == -1) { int action = KeyEvent.ACTION_DOWN; int code = KeyEvent.KEYCODE_DEL; KeyEvent event = new KeyEvent(action, code); this.message.onKeyDown(KeyEvent.KEYCODE_DEL, event); displayTextView(); return; } Editable s = message.getText().delete(index, text.length()); displayTextView(); return; } int action = KeyEvent.ACTION_DOWN; int code = KeyEvent.KEYCODE_DEL; KeyEvent event = new KeyEvent(action, code); this.message.onKeyDown(KeyEvent.KEYCODE_DEL, event); displayTextView(); }
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 w w w . ja va 2 s .c o m 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:org.easyaccess.phonedialer.CallStateService.java
@Override public void onShake(float force) { if (Utils.ringing == 1) { // answer call Intent buttonUp = new Intent(Intent.ACTION_MEDIA_BUTTON); buttonUp.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_HEADSETHOOK)); cxt.sendOrderedBroadcast(buttonUp, "android.permission.CALL_PRIVILEGED"); }/*from w w w . j a v a 2 s. c o m*/ }
From source file:com.iiordanov.runsoft.bVNC.RemoteCanvasActivity.java
void continueConnecting() { // TODO: Implement left-icon //requestWindowFeature(Window.FEATURE_LEFT_ICON); //setFeatureDrawableResource(Window.FEATURE_LEFT_ICON, R.drawable.icon); setContentView(R.layout.canvas);//from ww w .j ava 2 s .c om canvas = (RemoteCanvas) findViewById(R.id.vnc_canvas); zoomer = (ZoomControls) findViewById(R.id.zoomer); // Initialize and define actions for on-screen keys. initializeOnScreenKeys(); canvas.initializeCanvas(connection, database, new Runnable() { public void run() { try { setModes(); } catch (NullPointerException e) { } } }); canvas.setOnKeyListener(this); canvas.setFocusableInTouchMode(true); canvas.setDrawingCacheEnabled(false); // This code detects when the soft keyboard is up and sets an appropriate visibleHeight in vncCanvas. // When the keyboard is gone, it resets visibleHeight and pans zero distance to prevent us from being // below the desktop image (if we scrolled all the way down when the keyboard was up). // TODO: Move this into a separate thread, and post the visibility changes to the handler. // to avoid occupying the UI thread with this. final View rootView = ((ViewGroup) findViewById(android.R.id.content)).getChildAt(0); rootView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() { @Override public void onGlobalLayout() { Rect r = new Rect(); rootView.getWindowVisibleDisplayFrame(r); // To avoid setting the visible height to a wrong value after an screen unlock event // (when r.bottom holds the width of the screen rather than the height due to a rotation) // we make sure r.top is zero (i.e. there is no notification bar and we are in full-screen mode) // It's a bit of a hack. if (r.top == 0) { if (canvas.bitmapData != null) { canvas.setVisibleHeight(r.bottom); canvas.pan(0, 0); } } // Enable/show the zoomer if the keyboard is gone, and disable/hide otherwise. // We detect the keyboard if more than 19% of the screen is covered. int offset = 0; int rootViewHeight = rootView.getHeight(); if (r.bottom > rootViewHeight * 0.81) { offset = rootViewHeight - r.bottom; // Soft Kbd gone, shift the meta keys and arrows down. if (layoutKeys != null) { layoutKeys.offsetTopAndBottom(offset); keyStow.offsetTopAndBottom(offset); if (prevBottomOffset != offset) { setExtraKeysVisibility(View.GONE, false); canvas.invalidate(); zoomer.enable(); } } } else { offset = r.bottom - rootViewHeight; // Soft Kbd up, shift the meta keys and arrows up. if (layoutKeys != null) { layoutKeys.offsetTopAndBottom(offset); keyStow.offsetTopAndBottom(offset); if (prevBottomOffset != offset) { setExtraKeysVisibility(View.VISIBLE, true); canvas.invalidate(); zoomer.hide(); zoomer.disable(); } } } setKeyStowDrawableAndVisibility(); prevBottomOffset = offset; } }); zoomer.hide(); zoomer.setOnZoomKeyboardClickListener(new View.OnClickListener() { @Override public void onClick(View v) { //TODO zoomer keypad canvas.getKeyboard().processLocalKeyEvent(144, new KeyEvent(144, 0)); keyKor.setVisibility(View.GONE); keypad.setVisibility(View.VISIBLE); keypad.setTag("1"); } }); zoomer.setOnShowMenuClickListener(new View.OnClickListener() { @Override public void onClick(View v) { RemoteCanvasActivity.this.openOptionsMenu(); } }); panner = new Panner(this, canvas.handler); inputHandler = getInputHandlerById(R.id.itemInputTouchPanZoomMouse); }
From source file:com.iiordanov.bVNC.RemoteCanvasActivity.java
/** * Initializes the on-screen keys for meta keys and arrow keys. *///from w w w.ja v a 2s. c om private void initializeOnScreenKeys() { layoutKeys = (RelativeLayout) findViewById(R.id.layoutKeys); keyStow = (ImageButton) findViewById(R.id.keyStow); setKeyStowDrawableAndVisibility(); keyStow.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { if (layoutKeys.getVisibility() == View.VISIBLE) { extraKeysHidden = true; setExtraKeysVisibility(View.GONE, false); } else { extraKeysHidden = false; setExtraKeysVisibility(View.VISIBLE, true); } layoutKeys.offsetTopAndBottom(prevBottomOffset); setKeyStowDrawableAndVisibility(); } }); // Define action of tab key and meta keys. keyTab = (ImageButton) findViewById(R.id.keyTab); keyTab.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View arg0, MotionEvent e) { RemoteKeyboard k = canvas.getKeyboard(); int key = KeyEvent.KEYCODE_TAB; if (e.getAction() == MotionEvent.ACTION_DOWN) { BCFactory.getInstance().getBCHaptic().performLongPressHaptic(canvas); keyTab.setImageResource(R.drawable.tabon); k.repeatKeyEvent(key, new KeyEvent(e.getAction(), key)); return true; } else if (e.getAction() == MotionEvent.ACTION_UP) { keyTab.setImageResource(R.drawable.taboff); resetOnScreenKeys(0); k.stopRepeatingKeyEvent(); return true; } return false; } }); keyEsc = (ImageButton) findViewById(R.id.keyEsc); keyEsc.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View arg0, MotionEvent e) { RemoteKeyboard k = canvas.getKeyboard(); int key = 111; /* KEYCODE_ESCAPE */ if (e.getAction() == MotionEvent.ACTION_DOWN) { BCFactory.getInstance().getBCHaptic().performLongPressHaptic(canvas); keyEsc.setImageResource(R.drawable.escon); k.repeatKeyEvent(key, new KeyEvent(e.getAction(), key)); return true; } else if (e.getAction() == MotionEvent.ACTION_UP) { keyEsc.setImageResource(R.drawable.escoff); resetOnScreenKeys(0); k.stopRepeatingKeyEvent(); return true; } return false; } }); keyCtrl = (ImageButton) findViewById(R.id.keyCtrl); keyCtrl.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { boolean on = canvas.getKeyboard().onScreenCtrlToggle(); keyCtrlToggled = false; if (on) keyCtrl.setImageResource(R.drawable.ctrlon); else keyCtrl.setImageResource(R.drawable.ctrloff); } }); keyCtrl.setOnLongClickListener(new OnLongClickListener() { @Override public boolean onLongClick(View arg0) { BCFactory.getInstance().getBCHaptic().performLongPressHaptic(canvas); boolean on = canvas.getKeyboard().onScreenCtrlToggle(); keyCtrlToggled = true; if (on) keyCtrl.setImageResource(R.drawable.ctrlon); else keyCtrl.setImageResource(R.drawable.ctrloff); return true; } }); keySuper = (ImageButton) findViewById(R.id.keySuper); keySuper.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { boolean on = canvas.getKeyboard().onScreenSuperToggle(); keySuperToggled = false; if (on) keySuper.setImageResource(R.drawable.superon); else keySuper.setImageResource(R.drawable.superoff); } }); keySuper.setOnLongClickListener(new OnLongClickListener() { @Override public boolean onLongClick(View arg0) { BCFactory.getInstance().getBCHaptic().performLongPressHaptic(canvas); boolean on = canvas.getKeyboard().onScreenSuperToggle(); keySuperToggled = true; if (on) keySuper.setImageResource(R.drawable.superon); else keySuper.setImageResource(R.drawable.superoff); return true; } }); keyAlt = (ImageButton) findViewById(R.id.keyAlt); keyAlt.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { boolean on = canvas.getKeyboard().onScreenAltToggle(); keyAltToggled = false; if (on) keyAlt.setImageResource(R.drawable.alton); else keyAlt.setImageResource(R.drawable.altoff); } }); keyAlt.setOnLongClickListener(new OnLongClickListener() { @Override public boolean onLongClick(View arg0) { BCFactory.getInstance().getBCHaptic().performLongPressHaptic(canvas); boolean on = canvas.getKeyboard().onScreenAltToggle(); keyAltToggled = true; if (on) keyAlt.setImageResource(R.drawable.alton); else keyAlt.setImageResource(R.drawable.altoff); return true; } }); keyShift = (ImageButton) findViewById(R.id.keyShift); keyShift.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { boolean on = canvas.getKeyboard().onScreenShiftToggle(); keyShiftToggled = false; if (on) keyShift.setImageResource(R.drawable.shifton); else keyShift.setImageResource(R.drawable.shiftoff); } }); keyShift.setOnLongClickListener(new OnLongClickListener() { @Override public boolean onLongClick(View arg0) { BCFactory.getInstance().getBCHaptic().performLongPressHaptic(canvas); boolean on = canvas.getKeyboard().onScreenShiftToggle(); keyShiftToggled = true; if (on) keyShift.setImageResource(R.drawable.shifton); else keyShift.setImageResource(R.drawable.shiftoff); return true; } }); // TODO: Evaluate whether I should instead be using: // vncCanvas.sendMetaKey(MetaKeyBean.keyArrowLeft); // Define action of arrow keys. keyUp = (ImageButton) findViewById(R.id.keyUpArrow); keyUp.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View arg0, MotionEvent e) { RemoteKeyboard k = canvas.getKeyboard(); int key = KeyEvent.KEYCODE_DPAD_UP; if (e.getAction() == MotionEvent.ACTION_DOWN) { BCFactory.getInstance().getBCHaptic().performLongPressHaptic(canvas); keyUp.setImageResource(R.drawable.upon); k.repeatKeyEvent(key, new KeyEvent(e.getAction(), key)); return true; } else if (e.getAction() == MotionEvent.ACTION_UP) { keyUp.setImageResource(R.drawable.upoff); resetOnScreenKeys(0); k.stopRepeatingKeyEvent(); return true; } return false; } }); keyDown = (ImageButton) findViewById(R.id.keyDownArrow); keyDown.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View arg0, MotionEvent e) { RemoteKeyboard k = canvas.getKeyboard(); int key = KeyEvent.KEYCODE_DPAD_DOWN; if (e.getAction() == MotionEvent.ACTION_DOWN) { BCFactory.getInstance().getBCHaptic().performLongPressHaptic(canvas); keyDown.setImageResource(R.drawable.downon); k.repeatKeyEvent(key, new KeyEvent(e.getAction(), key)); return true; } else if (e.getAction() == MotionEvent.ACTION_UP) { keyDown.setImageResource(R.drawable.downoff); resetOnScreenKeys(0); k.stopRepeatingKeyEvent(); return true; } return false; } }); keyLeft = (ImageButton) findViewById(R.id.keyLeftArrow); keyLeft.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View arg0, MotionEvent e) { RemoteKeyboard k = canvas.getKeyboard(); int key = KeyEvent.KEYCODE_DPAD_LEFT; if (e.getAction() == MotionEvent.ACTION_DOWN) { BCFactory.getInstance().getBCHaptic().performLongPressHaptic(canvas); keyLeft.setImageResource(R.drawable.lefton); k.repeatKeyEvent(key, new KeyEvent(e.getAction(), key)); return true; } else if (e.getAction() == MotionEvent.ACTION_UP) { keyLeft.setImageResource(R.drawable.leftoff); resetOnScreenKeys(0); k.stopRepeatingKeyEvent(); return true; } return false; } }); keyRight = (ImageButton) findViewById(R.id.keyRightArrow); keyRight.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View arg0, MotionEvent e) { RemoteKeyboard k = canvas.getKeyboard(); int key = KeyEvent.KEYCODE_DPAD_RIGHT; if (e.getAction() == MotionEvent.ACTION_DOWN) { BCFactory.getInstance().getBCHaptic().performLongPressHaptic(canvas); keyRight.setImageResource(R.drawable.righton); k.repeatKeyEvent(key, new KeyEvent(e.getAction(), key)); return true; } else if (e.getAction() == MotionEvent.ACTION_UP) { keyRight.setImageResource(R.drawable.rightoff); resetOnScreenKeys(0); k.stopRepeatingKeyEvent(); return true; } return false; } }); }