List of usage examples for android.view KeyEvent getKeyCode
public final int getKeyCode()
From source file:com.darly.im.ui.LauncherActivity.java
@Override public boolean dispatchKeyEvent(KeyEvent event) { LogUtil.d(LogUtil.getLogUtilsTag(LauncherActivity.class), " onKeyDown"); if ((event.getKeyCode() == KeyEvent.KEYCODE_BACK) && event.getAction() == KeyEvent.ACTION_UP) { // dismiss PlusSubMenuHelper if (mOverflowHelper != null && mOverflowHelper.isOverflowShowing()) { mOverflowHelper.dismiss();//from w w w. ja v a2 s. c o m return true; } } // ?menu?? if ((event.getKeyCode() == KeyEvent.KEYCODE_BACK) && event.getAction() == KeyEvent.ACTION_DOWN) { doTaskToBackEvent(); } try { return super.dispatchKeyEvent(event); } catch (Exception e) { LogUtil.e(LogUtil.getLogUtilsTag(LauncherActivity.class), "dispatch key event catch exception " + e.getMessage()); } return false; }
From source file:nl.mpcjanssen.simpletask.AddTask.java
@Override public void onCreate(Bundle savedInstanceState) { Log.v(TAG, "onCreate()"); m_app = (TodoApplication) getApplication(); m_app.setActionBarStyle(getWindow()); requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); super.onCreate(savedInstanceState); IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction(Constants.BROADCAST_UPDATE_UI); intentFilter.addAction(Constants.BROADCAST_SYNC_START); intentFilter.addAction(Constants.BROADCAST_SYNC_DONE); localBroadcastManager = m_app.getLocalBroadCastManager(); m_broadcastReceiver = new BroadcastReceiver() { @Override/*from ww w.ja v a 2 s .c o m*/ public void onReceive(Context context, @NotNull Intent intent) { if (intent.getAction().equals(Constants.BROADCAST_SYNC_START)) { setProgressBarIndeterminateVisibility(true); } else if (intent.getAction().equals(Constants.BROADCAST_SYNC_DONE)) { setProgressBarIndeterminateVisibility(false); } } }; localBroadcastManager.registerReceiver(m_broadcastReceiver, intentFilter); ActionBar actionBar = getActionBar(); if (actionBar != null) { actionBar.setDisplayHomeAsUpEnabled(true); } final Intent intent = getIntent(); ActiveFilter mFilter = new ActiveFilter(); mFilter.initFromIntent(intent); final String action = intent.getAction(); // create shortcut and exit if (Intent.ACTION_CREATE_SHORTCUT.equals(action)) { Log.d(TAG, "Setting up shortcut icon"); setupShortcut(); finish(); return; } else if (Intent.ACTION_SEND.equals(action)) { Log.d(TAG, "Share"); if (intent.hasExtra(Intent.EXTRA_TEXT)) { share_text = intent.getCharSequenceExtra(Intent.EXTRA_TEXT).toString(); } else { share_text = ""; } if (!m_app.hasShareTaskShowsEdit()) { if (!share_text.equals("")) { addBackgroundTask(share_text); } finish(); return; } } else if ("com.google.android.gm.action.AUTO_SEND".equals(action)) { // Called as note to self from google search/now noteToSelf(intent); finish(); return; } else if (Constants.INTENT_BACKGROUND_TASK.equals(action)) { Log.v(TAG, "Adding background task"); if (intent.hasExtra(Constants.EXTRA_BACKGROUND_TASK)) { addBackgroundTask(intent.getStringExtra(Constants.EXTRA_BACKGROUND_TASK)); } else { Log.w(TAG, "Task was not in extras"); } finish(); return; } getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED); setContentView(R.layout.add_task); // text textInputField = (EditText) findViewById(R.id.taskText); m_app.setEditTextHint(textInputField, R.string.tasktexthint); if (share_text != null) { textInputField.setText(share_text); } Task iniTask = null; setTitle(R.string.addtask); m_backup = m_app.getTaskCache(this).getTasksToUpdate(); if (m_backup != null && m_backup.size() > 0) { ArrayList<String> prefill = new ArrayList<String>(); for (Task t : m_backup) { prefill.add(t.inFileFormat()); } String sPrefill = Util.join(prefill, "\n"); textInputField.setText(sPrefill); setTitle(R.string.updatetask); } else { if (textInputField.getText().length() == 0) { iniTask = new Task(1, ""); iniTask.initWithFilter(mFilter); } if (iniTask != null && iniTask.getTags().size() == 1) { List<String> ps = iniTask.getTags(); String project = ps.get(0); if (!project.equals("-")) { textInputField.append(" +" + project); } } if (iniTask != null && iniTask.getLists().size() == 1) { List<String> cs = iniTask.getLists(); String context = cs.get(0); if (!context.equals("-")) { textInputField.append(" @" + context); } } } // Listen to enter events, use IME_ACTION_NEXT for soft keyboards // like Swype where ENTER keyCode is not generated. int inputFlags = InputType.TYPE_CLASS_TEXT; if (m_app.hasCapitalizeTasks()) { inputFlags |= InputType.TYPE_TEXT_FLAG_CAP_SENTENCES; } textInputField.setRawInputType(inputFlags); textInputField.setImeOptions(EditorInfo.IME_ACTION_NEXT); textInputField.setOnEditorActionListener(new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView textView, int actionId, @Nullable KeyEvent keyEvent) { boolean hardwareEnterUp = keyEvent != null && keyEvent.getAction() == KeyEvent.ACTION_UP && keyEvent.getKeyCode() == KeyEvent.KEYCODE_ENTER; boolean hardwareEnterDown = keyEvent != null && keyEvent.getAction() == KeyEvent.ACTION_DOWN && keyEvent.getKeyCode() == KeyEvent.KEYCODE_ENTER; boolean imeActionNext = (actionId == EditorInfo.IME_ACTION_NEXT); if (imeActionNext || hardwareEnterUp) { // Move cursor to end of line int position = textInputField.getSelectionStart(); String remainingText = textInputField.getText().toString().substring(position); int endOfLineDistance = remainingText.indexOf('\n'); int endOfLine; if (endOfLineDistance == -1) { endOfLine = textInputField.length(); } else { endOfLine = position + endOfLineDistance; } textInputField.setSelection(endOfLine); replaceTextAtSelection("\n", false); if (hasCloneTags()) { String precedingText = textInputField.getText().toString().substring(0, endOfLine); int lineStart = precedingText.lastIndexOf('\n'); String line; if (lineStart != -1) { line = precedingText.substring(lineStart, endOfLine); } else { line = precedingText; } Task t = new Task(0, line); LinkedHashSet<String> tags = new LinkedHashSet<String>(); for (String ctx : t.getLists()) { tags.add("@" + ctx); } for (String prj : t.getTags()) { tags.add("+" + prj); } replaceTextAtSelection(Util.join(tags, " "), true); } endOfLine++; textInputField.setSelection(endOfLine); } return (imeActionNext || hardwareEnterDown || hardwareEnterUp); } }); setCloneTags(m_app.isAddTagsCloneTags()); setWordWrap(m_app.isWordWrap()); findViewById(R.id.cb_wrap).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { setWordWrap(hasWordWrap()); } }); int textIndex = 0; textInputField.setSelection(textIndex); // Set button callbacks findViewById(R.id.btnContext).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { showContextMenu(); } }); findViewById(R.id.btnProject).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { showTagMenu(); } }); findViewById(R.id.btnPrio).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { showPrioMenu(); } }); findViewById(R.id.btnDue).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { insertDate(Task.DUE_DATE); } }); findViewById(R.id.btnThreshold).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { insertDate(Task.THRESHOLD_DATE); } }); if (m_backup != null && m_backup.size() > 0) { textInputField.setSelection(textInputField.getText().length()); } }
From source file:org.ulteo.ovd.AndRdpActivity.java
@Override public boolean dispatchKeyEvent(KeyEvent event) { AudioManager audioManager;//from w w w.j a v a2s. c o m if (Config.DEBUG) Log.i(Config.TAG, "AndRdpActivity.dispatchKeyEvent " + event); // Disable keypress if it is from a mouse or touchpad. if (event.getDeviceId() >= 0) { InputDevice dev = InputDevice.getDevice(event.getDeviceId()); if (dev.getSources() == InputDevice.SOURCE_MOUSE || dev.getSources() == InputDevice.SOURCE_TOUCHPAD) return true; } if (event.getAction() == KeyEvent.ACTION_DOWN) { switch (event.getKeyCode()) { case KeyEvent.KEYCODE_MENU: OnThreeFingers(null); return true; case KeyEvent.KEYCODE_BACK: Log.i(Config.TAG, "Back key pressed"); askLogoutDialog(); return true; case KeyEvent.KEYCODE_VOLUME_UP: audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); audioManager.adjustStreamVolume(AudioManager.STREAM_MUSIC, AudioManager.ADJUST_RAISE, AudioManager.FLAG_SHOW_UI); return true; case KeyEvent.KEYCODE_VOLUME_DOWN: audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); audioManager.adjustStreamVolume(AudioManager.STREAM_MUSIC, AudioManager.ADJUST_LOWER, AudioManager.FLAG_SHOW_UI); return true; } } else if (event.getAction() == KeyEvent.ACTION_UP) { switch (event.getKeyCode()) { case KeyEvent.KEYCODE_MENU: case KeyEvent.KEYCODE_BACK: case KeyEvent.KEYCODE_VOLUME_UP: case KeyEvent.KEYCODE_VOLUME_DOWN: return true; } } if (isLoggedIn() && rdp.dispatchKeyEvent(event)) return true; return super.dispatchKeyEvent(event); }
From source file:org.mortbay.ijetty.IJetty.java
License:asdf
@Override public boolean dispatchKeyEvent(KeyEvent event) { Log.w(TAG, "onKeyDown"); if (event.getKeyCode() == KeyEvent.KEYCODE_BACK) { Log.w(TAG, "onKeyDown, KEYCODE_BACK"); if (event.getAction() == KeyEvent.ACTION_DOWN && event.getRepeatCount() == 0) { //?? if (MyFloatView.mPlayViewPrepareStatus) { Log.e("smallstar", "MyFloatView.mPlayViewPrepareStatus is true!"); MyFloatView.mPlayViewStatus = false; MyFloatView.onExit();//from w w w .j av a2 s. c o m } if (mWebView.getOriginalUrl().equals("http://localhost:8080/console/settings/basicsettings.html")) { stopService(new Intent(this, DaemonService.class)); stopService(new Intent(this, IJettyService.class)); finish(); } else { //mWebView.loadUrl("http://localhost:8080/console/settings/index.html"); mWebView.loadUrl("http://localhost:8080/console/settings/basicsettings.html"); } } return true; } return super.dispatchKeyEvent(event); }
From source file:org.telegram.ui.Components.NumberPicker.java
@Override public boolean dispatchKeyEvent(KeyEvent event) { final int keyCode = event.getKeyCode(); switch (keyCode) { case KeyEvent.KEYCODE_DPAD_CENTER: case KeyEvent.KEYCODE_ENTER: removeAllCallbacks();/*from ww w .j a v a 2 s. c om*/ break; case KeyEvent.KEYCODE_DPAD_DOWN: case KeyEvent.KEYCODE_DPAD_UP: switch (event.getAction()) { case KeyEvent.ACTION_DOWN: if (mWrapSelectorWheel || (keyCode == KeyEvent.KEYCODE_DPAD_DOWN) ? getValue() < getMaxValue() : getValue() > getMinValue()) { requestFocus(); mLastHandledDownDpadKeyCode = keyCode; removeAllCallbacks(); if (mFlingScroller.isFinished()) { changeValueByOne(keyCode == KeyEvent.KEYCODE_DPAD_DOWN); } return true; } break; case KeyEvent.ACTION_UP: if (mLastHandledDownDpadKeyCode == keyCode) { mLastHandledDownDpadKeyCode = -1; return true; } break; } } return super.dispatchKeyEvent(event); }
From source file:org.uoyabause.android.YabauseHandler.java
@Override public boolean dispatchKeyEvent(KeyEvent event) { int action = event.getAction(); int keyCode = event.getKeyCode(); if (keyCode == KeyEvent.KEYCODE_BACK) { if (event.getAction() == KeyEvent.ACTION_DOWN && event.getRepeatCount() == 0) { Fragment fg = getSupportFragmentManager().findFragmentByTag(StateListFragment.TAG); if (fg != null) { this.cancelStateLoad(); FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); transaction.remove(fg);/*w ww . j a v a 2 s.co m*/ transaction.commit(); View mainv = findViewById(R.id.yabause_view); mainv.setActivated(true); mainv.requestFocus(); waiting_reault = false; YabauseRunnable.resume(); audio.unmute(audio.SYSTEM); return true; } fg = getSupportFragmentManager().findFragmentByTag(TabBackupFragment.TAG); if (fg != null) { FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); transaction.remove(fg); transaction.commit(); View mainv = findViewById(R.id.yabause_view); mainv.setActivated(true); mainv.requestFocus(); waiting_reault = false; YabauseRunnable.resume(); audio.unmute(audio.SYSTEM); return true; } showBottomMenu(); } return true; } if (menu_showing) { return super.dispatchKeyEvent(event); } if (this.waiting_reault) { return super.dispatchKeyEvent(event); } //Log.d("dispatchKeyEvent","device:" + event.getDeviceId() + ",action:" + action +",keyCoe:" + keyCode ); if (action == KeyEvent.ACTION_UP) { int rtn = padm.onKeyUp(keyCode, event); if (rtn != 0) { return true; } } else if (action == KeyEvent.ACTION_MULTIPLE) { } else if (action == KeyEvent.ACTION_DOWN && event.getRepeatCount() == 0) { int rtn = padm.onKeyDown(keyCode, event); if (rtn != 0) { return true; } } return super.dispatchKeyEvent(event); }
From source file:com.fatelon.flyingphotobooth.fragments.CaptureFragment.java
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); final LaunchActivity activity = (LaunchActivity) getActivity(); SharedPreferences preferences = PreferenceManager .getDefaultSharedPreferences(activity.getApplicationContext()); /*//from www.j a va 2 s . c om * Reset frames. */ String numPhotosPref = preferences.getString(getString(R.string.pref__number_of_photos_key), getString(R.string.pref__number_of_photos_default)); mFramesTotal = Integer.parseInt(numPhotosPref); mFrameIndex = 0; mFramesData = new byte[mFramesTotal][]; /* * Initialize and set key event handlers. */ mBackPressedHandler = new LaunchActivity.BackPressedHandler() { @Override public boolean onBackPressed() { // If capture sequence is running, exit capture sequence on back pressed event. if (mIsCaptureSequenceRunning) { activity.replaceFragment(CaptureFragment.newInstance(mUseFrontFacing), false, true); } return mIsCaptureSequenceRunning; } }; activity.setBackPressedHandler(mBackPressedHandler); mKeyEventHandler = new LaunchActivity.KeyEventHandler() { @Override public boolean onKeyEvent(KeyEvent event) { final int keyCode = event.getKeyCode(); if (keyCode == KeyEvent.KEYCODE_ENTER || keyCode == KeyEvent.KEYCODE_VOLUME_UP) { mStartButton.dispatchKeyEvent(event); return true; } return false; } }; activity.setKeyEventHandler(mKeyEventHandler); /* * Functionalize views. */ mPreferencesButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent preferencesIntent = new Intent(activity, MyPreferenceActivity.class); startActivity(preferencesIntent); } }); // Show switch button only if more than one camera is available. if (mNumCameras > 1) { mSwitchButton.setVisibility(View.VISIBLE); mSwitchButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // Switch camera. boolean useFrontFacing = false; CameraInfo cameraInfo = new CameraInfo(); if (mCameraId != INVALID_CAMERA_ID) { Camera.getCameraInfo(mCameraId, cameraInfo); if (cameraInfo.facing == CameraInfo.CAMERA_FACING_BACK) { useFrontFacing = true; } // Relaunch fragment with new camera. activity.replaceFragment(CaptureFragment.newInstance(useFrontFacing), false, true); } } }); } // Get trigger mode preference. String triggerPref = preferences.getString(getString(R.string.pref__trigger_key), getString(R.string.pref__trigger_default)); if (triggerPref.equals(getString(R.string.pref__trigger_countdown))) { mTriggerMode = TRIGGER_MODE_COUNTDOWN; } else if (triggerPref.equals(getString(R.string.pref__trigger_burst))) { mTriggerMode = TRIGGER_MODE_BURST; } else { mTriggerMode = TRIGGER_MODE_MANUAL; } // Configure title and start button text. mTitle.setText(String.format(getString(R.string.capture__title_frame), mFrameIndex + 1, mFramesTotal)); if (mTriggerMode == TRIGGER_MODE_MANUAL) { // Update title. mStartButton.setText(getString(R.string.capture__start_manual_button_text)); } else { mStartButton.setText(getString(R.string.capture__start_countdown_button_text)); } // Configure start button behaviour. mStartButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { onStartButtonPressedImpl(); } }); mStartButton.setOnKeyListener(new View.OnKeyListener() { @Override public boolean onKey(View v, int keyCode, KeyEvent event) { onStartButtonPressedImpl(); return true; } }); }
From source file:com.app.blockydemo.ui.ScriptActivity.java
@Override public boolean dispatchKeyEvent(KeyEvent event) { //Dismiss ActionMode without effecting checked items FormulaEditorVariableListFragment formulaEditorVariableListFragment = (FormulaEditorVariableListFragment) getSupportFragmentManager() .findFragmentByTag(FormulaEditorVariableListFragment.VARIABLE_TAG); if (formulaEditorVariableListFragment != null) { if (formulaEditorVariableListFragment.isVisible()) { ListAdapter adapter = formulaEditorVariableListFragment.getListAdapter(); ((ScriptActivityAdapterInterface) adapter).clearCheckedItems(); return super.dispatchKeyEvent(event); }//from w w w . ja v a2 s . c o m } if (currentFragment != null && currentFragment.getActionModeActive()) { if (event.getKeyCode() == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_UP) { ListAdapter adapter = null; if (currentFragment instanceof ScriptFragment) { adapter = ((ScriptFragment) currentFragment).getAdapter(); } else { adapter = currentFragment.getListAdapter(); } ((ScriptActivityAdapterInterface) adapter).clearCheckedItems(); } } return super.dispatchKeyEvent(event); }
From source file:com.arthurtimberly.fragments.CaptureFragment.java
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); final LaunchActivity activity = (LaunchActivity) getActivity(); SharedPreferences preferences = PreferenceManager .getDefaultSharedPreferences(activity.getApplicationContext()); /*//from w ww. j a v a 2 s .c om * Reset frames. */ // force to use 4 photos /* String numPhotosPref = preferences.getString(getString(R.string.pref__number_of_photos_key), getString(R.string.pref__number_of_photos_default)); */ mFramesTotal = 4;//Integer.parseInt(numPhotosPref); mFrameIndex = 0; mFramesData = new byte[mFramesTotal][]; /* * Initialize and set key event handlers. */ mBackPressedHandler = new LaunchActivity.BackPressedHandler() { @Override public boolean onBackPressed() { // If capture sequence is running, exit capture sequence on back pressed event. if (mIsCaptureSequenceRunning) { activity.replaceFragment(CaptureFragment.newInstance(mUseFrontFacing), false, true); } return mIsCaptureSequenceRunning; } }; activity.setBackPressedHandler(mBackPressedHandler); mKeyEventHandler = new LaunchActivity.KeyEventHandler() { @Override public boolean onKeyEvent(KeyEvent event) { final int keyCode = event.getKeyCode(); if (keyCode == KeyEvent.KEYCODE_ENTER || keyCode == KeyEvent.KEYCODE_VOLUME_UP) { mStartButton.dispatchKeyEvent(event); return true; } return false; } }; activity.setKeyEventHandler(mKeyEventHandler); /* * Functionalize views. */ mPreferencesButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent preferencesIntent = new Intent(activity, MyPreferenceActivity.class); startActivity(preferencesIntent); } }); // Show switch button only if more than one camera is available. if (mNumCameras > 1) { mSwitchButton.setVisibility(View.VISIBLE); mSwitchButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // Switch camera. boolean useFrontFacing = false; CameraInfo cameraInfo = new CameraInfo(); if (mCameraId != INVALID_CAMERA_ID) { Camera.getCameraInfo(mCameraId, cameraInfo); if (cameraInfo.facing == CameraInfo.CAMERA_FACING_BACK) { useFrontFacing = true; } // Relaunch fragment with new camera. activity.replaceFragment(CaptureFragment.newInstance(useFrontFacing), false, true); } } }); } // Get trigger mode preference. /* String triggerPref = preferences.getString(getString(R.string.pref__trigger_key), getString(R.string.pref__trigger_default)); if (triggerPref.equals(getString(R.string.pref__trigger_countdown))) { mTriggerMode = TRIGGER_MODE_COUNTDOWN; } else if (triggerPref.equals(getString(R.string.pref__trigger_burst))) { mTriggerMode = TRIGGER_MODE_BURST; } else { mTriggerMode = TRIGGER_MODE_MANUAL; } */ // force to use countdown mode mTriggerMode = TRIGGER_MODE_COUNTDOWN; // Configure title and start button text. mTitle.setText(String.format(getString(R.string.capture__title_frame), mFrameIndex + 1, mFramesTotal)); if (mTriggerMode == TRIGGER_MODE_MANUAL) { // Update title. mStartButton.setText(getString(R.string.capture__start_manual_button_text)); } else { mStartButton.setText(getString(R.string.capture__start_countdown_button_text)); } // Configure start button behaviour. mStartButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { onStartButtonPressedImpl(); } }); mStartButton.setOnKeyListener(new View.OnKeyListener() { @Override public boolean onKey(View v, int keyCode, KeyEvent event) { onStartButtonPressedImpl(); return true; } }); }
From source file:com.aretha.slidemenu.SlideMenu.java
@Override public boolean dispatchKeyEvent(KeyEvent event) { if (KeyEvent.ACTION_UP == event.getAction()) { final boolean isOpen = isOpen(); switch (event.getKeyCode()) { case KeyEvent.KEYCODE_BACK: if (isOpen) { close(true);// w w w . j a v a 2 s . co m return true; } break; case KeyEvent.KEYCODE_DPAD_LEFT: if (STATE_OPEN_LEFT == mCurrentState) { close(true); return true; } else if (!isOpen) { open(true, true); return true; } break; case KeyEvent.KEYCODE_DPAD_RIGHT: if (STATE_OPEN_RIGHT == mCurrentState) { close(true); return true; } else if (!isOpen) { open(false, true); return true; } break; } } return super.dispatchKeyEvent(event); }