List of usage examples for android.view KeyEvent getKeyCode
public final int getKeyCode()
From source file:android.support.v7.app.AppCompatDelegateImplV7.java
@Override boolean dispatchKeyEvent(KeyEvent event) { final int keyCode = event.getKeyCode(); final int action = event.getAction(); final boolean isDown = action == KeyEvent.ACTION_DOWN; return isDown ? onKeyDown(keyCode, event) : onKeyUp(keyCode, event); }
From source file:de.danoeh.antennapod.core.cast.CastManager.java
/** * Clients can call this method to delegate handling of the volume. Clients should override * {@code dispatchEvent} and call this method: * <pre>/*from w ww .ja v a 2s . co m*/ public boolean dispatchKeyEvent(KeyEvent event) { if (mCastManager.onDispatchVolumeKeyEvent(event, VOLUME_DELTA)) { return true; } return super.dispatchKeyEvent(event); } * </pre> * @param event The dispatched event. * @param volumeDelta The amount by which volume should be increased or decreased in each step * @return <code>true</code> if volume is handled by the library, <code>false</code> otherwise. */ public boolean onDispatchVolumeKeyEvent(KeyEvent event, double volumeDelta) { if (isConnected()) { boolean isKeyDown = event.getAction() == KeyEvent.ACTION_DOWN; switch (event.getKeyCode()) { case KeyEvent.KEYCODE_VOLUME_UP: return changeVolume(volumeDelta, isKeyDown); case KeyEvent.KEYCODE_VOLUME_DOWN: return changeVolume(-volumeDelta, isKeyDown); } } return false; }
From source file:com.dwdesign.tweetings.activity.ComposeActivity.java
@Override public boolean onEditorAction(final TextView view, final int actionId, final KeyEvent event) { if (event == null) return false; switch (event.getKeyCode()) { case KeyEvent.KEYCODE_ENTER: { if (event.getAction() == KeyEvent.ACTION_UP) { send();/*from ww w .j av a 2 s .c om*/ } return true; } } return false; }
From source file:bw.com.yunifangstore.view.LazyViewPager.java
/** * You can call this function yourself to have the scroll view perform * scrolling from a key event, just as if the event had been dispatched to * it by the view hierarchy./*from w w w . jav a 2 s . c o m*/ * * @param event The key event to execute. * @return Return true if the event was handled, else false. */ public boolean executeKeyEvent(KeyEvent event) { boolean handled = false; if (event.getAction() == KeyEvent.ACTION_DOWN) { switch (event.getKeyCode()) { case KeyEvent.KEYCODE_DPAD_LEFT: handled = arrowScroll(FOCUS_LEFT); break; case KeyEvent.KEYCODE_DPAD_RIGHT: handled = arrowScroll(FOCUS_RIGHT); break; case KeyEvent.KEYCODE_TAB: if (KeyEventCompat.hasNoModifiers(event)) { handled = arrowScroll(FOCUS_FORWARD); } else if (KeyEventCompat.hasModifiers(event, KeyEvent.META_SHIFT_ON)) { handled = arrowScroll(FOCUS_BACKWARD); } break; } } return handled; }
From source file:com.efithealth.app.activity.ChatActivity.java
/** * /*from w ww .j a v a 2 s .co m*/ */ @Override public boolean dispatchKeyEvent(KeyEvent event) { if (event.getAction() == KeyEvent.ACTION_UP && event.getKeyCode() == KeyEvent.KEYCODE_BACK) { if (panel_root.getVisibility() != View.GONE) { KPSwitchConflictUtil.hidePanelAndKeyboard(panel_root); panel_root.setVisibility(View.GONE); return true; } } return super.dispatchKeyEvent(event); }
From source file:com.hxqc.mall.thirdshop.views.CustomScrollView.java
/** * You can call this function yourself to have the scroll view perform * scrolling from a key event, just as if the event had been dispatched to * it by the view hierarchy./* w w w . j a va 2 s.c om*/ * * @param event The key event to execute. * @return Return true if the event was handled, else false. */ public boolean executeKeyEvent(KeyEvent event) { mTempRect.setEmpty(); if (!canScroll()) { if (isFocused() && event.getKeyCode() != KeyEvent.KEYCODE_BACK) { View currentFocused = findFocus(); if (currentFocused == this) currentFocused = null; View nextFocused = FocusFinder.getInstance().findNextFocus(this, currentFocused, View.FOCUS_DOWN); return nextFocused != null && nextFocused != this && nextFocused.requestFocus(View.FOCUS_DOWN); } return false; } boolean handled = false; if (event.getAction() == KeyEvent.ACTION_DOWN) { switch (event.getKeyCode()) { case KeyEvent.KEYCODE_DPAD_UP: if (!event.isAltPressed()) { handled = arrowScroll(View.FOCUS_UP); } else { handled = fullScroll(View.FOCUS_UP); } break; case KeyEvent.KEYCODE_DPAD_DOWN: if (!event.isAltPressed()) { handled = arrowScroll(View.FOCUS_DOWN); } else { handled = fullScroll(View.FOCUS_DOWN); } break; case KeyEvent.KEYCODE_SPACE: pageScroll(event.isShiftPressed() ? View.FOCUS_UP : View.FOCUS_DOWN); break; default: break; } } return handled; }
From source file:com.fvd.nimbus.PaintActivity.java
@Override public boolean dispatchKeyEvent(KeyEvent event) { int action = event.getAction(); int keyCode = event.getKeyCode(); switch (keyCode) { case KeyEvent.KEYCODE_VOLUME_UP: if (action == KeyEvent.ACTION_DOWN) { drawView.zoom(1.25f);//from w ww. j ava2 s . co m } return true; case KeyEvent.KEYCODE_VOLUME_DOWN: if (action == KeyEvent.ACTION_DOWN) { drawView.zoom(0.75f); } return true; case KeyEvent.KEYCODE_BACK: if (action == KeyEvent.ACTION_DOWN) { if (drawer.isDrawerOpen(GravityCompat.START)) { drawer.closeDrawer(GravityCompat.START); return true; } else if (findViewById(R.id.text_field).getVisibility() != View.GONE) { findViewById(R.id.text_field).setVisibility(View.GONE); drawView.hideCrop(); drawView.startEdit(); setSelectedFoot(0); return true; } else if (findViewById(R.id.color_menu).getVisibility() != View.GONE) { findViewById(R.id.color_menu).setVisibility(View.GONE); drawView.hideCrop(); drawView.startEdit(); setSelectedFoot(0); return true; } else if (findViewById(R.id.draw_tools).getVisibility() != View.GONE) { findViewById(R.id.draw_tools).setVisibility(View.GONE); drawView.hideCrop(); drawView.startEdit(); setSelectedFoot(0); return false; } else if (!drawView.hideCrop()) { if (!saved && storePath.length() == 0) showDialog(0); else { drawView.recycle(); finish(); return true; } } else { ((ImageButton) findViewById(R.id.bToolCrop)).setSelected(false); drawView.startEdit(); setSelectedFoot(0); return true; } } default: return super.dispatchKeyEvent(event); } }
From source file:com.apptentive.android.sdk.view.ApptentiveNestedScrollView.java
/** * You can call this function yourself to have the scroll view perform * scrolling from a key event, just as if the event had been dispatched to * it by the view hierarchy./* ww w .j a v a 2 s . com*/ * * @param event The key event to execute. * @return Return true if the event was handled, else false. */ public boolean executeKeyEvent(KeyEvent event) { mTempRect.setEmpty(); if (!canScroll()) { if (isFocused() && event.getKeyCode() != KeyEvent.KEYCODE_BACK) { View currentFocused = findFocus(); if (currentFocused == this) currentFocused = null; View nextFocused = FocusFinder.getInstance().findNextFocus(this, currentFocused, View.FOCUS_DOWN); return nextFocused != null && nextFocused != this && nextFocused.requestFocus(View.FOCUS_DOWN); } return false; } boolean handled = false; if (event.getAction() == KeyEvent.ACTION_DOWN) { switch (event.getKeyCode()) { case KeyEvent.KEYCODE_DPAD_UP: if (!event.isAltPressed()) { handled = arrowScroll(View.FOCUS_UP); } else { handled = fullScroll(View.FOCUS_UP); } break; case KeyEvent.KEYCODE_DPAD_DOWN: if (!event.isAltPressed()) { handled = arrowScroll(View.FOCUS_DOWN); } else { handled = fullScroll(View.FOCUS_DOWN); } break; case KeyEvent.KEYCODE_SPACE: pageScroll(event.isShiftPressed() ? View.FOCUS_UP : View.FOCUS_DOWN); break; } } return handled; }
From source file:android.support.v7ox.app.AppCompatDelegateImplV7.java
@Override boolean dispatchKeyEvent(KeyEvent event) { if (event.getKeyCode() == KeyEvent.KEYCODE_MENU) { // If this is a MENU event, let the Activity have a go. if (mOriginalWindowCallback.dispatchKeyEvent(event)) { return true; }/*from w w w . j a v a 2 s . c om*/ } final int keyCode = event.getKeyCode(); final int action = event.getAction(); final boolean isDown = action == KeyEvent.ACTION_DOWN; return isDown ? onKeyDown(keyCode, event) : onKeyUp(keyCode, event); }
From source file:at.alladin.rmbt.android.main.RMBTMainActivity.java
/** * *///ww w .j av a 2 s . c om @Override public void onCreate(final Bundle savedInstanceState) { //Log.i("MAIN ACTIVITY", "onCreate"); restoreInstance(savedInstanceState); super.onCreate(savedInstanceState); NetworkInfoCollector.init(this); networkInfoCollector = NetworkInfoCollector.getInstance(); preferencesUpdate(); setContentView(R.layout.main_with_navigation_drawer); if (VIEW_HIERARCHY_SERVER_ENABLED) { ViewServer.get(this).addWindow(this); } ActionBar actionBar = getActionBar(); actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_SHOW_TITLE); actionBar.setDisplayUseLogoEnabled(true); // initialize the navigation drawer with the main menu list adapter: String[] mainTitles = getResources().getStringArray(R.array.navigation_main_titles); int[] navIcons = new int[] { R.drawable.ic_action_home, R.drawable.ic_action_history, R.drawable.ic_action_map, R.drawable.ic_action_stat, R.drawable.ic_action_help, R.drawable.ic_action_about, R.drawable.ic_action_settings, R.drawable.ic_action_about }; MainMenuListAdapter mainMenuAdapter = new MainMenuListAdapter(this, mainTitles, navIcons); drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); drawerList = (ListView) findViewById(R.id.left_drawer); drawerLayout.setBackgroundResource(R.drawable.ic_drawer); drawerToggle = new ActionBarDrawerToggle(this, drawerLayout, R.drawable.ic_drawer, R.string.page_title_title_page, R.string.page_title_title_page) { /** Called when a drawer has settled in a completely closed state. */ public void onDrawerClosed(View view) { super.onDrawerClosed(view); //refreshActionBar(null); exitAfterDrawerClose = false; } /** Called when a drawer has settled in a completely open state. */ public void onDrawerOpened(View drawerView) { super.onDrawerOpened(drawerView); } }; drawerLayout.setOnKeyListener(new OnKeyListener() { @Override public boolean onKey(View v, int keyCode, KeyEvent event) { if (KeyEvent.KEYCODE_BACK == event.getKeyCode() && exitAfterDrawerClose) { onBackPressed(); return true; } return false; } }); drawerLayout.setDrawerListener(drawerToggle); drawerList.setAdapter(mainMenuAdapter); drawerList.setOnItemClickListener(new OnItemClickListener() { final int[] menuIds = new int[] { R.id.action_title_page, R.id.action_history, R.id.action_map, R.id.action_stats, R.id.action_help, R.id.action_info, R.id.action_settings, R.id.action_netstat, R.id.action_log }; @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { selectMenuItem(menuIds[position]); drawerLayout.closeDrawers(); } }); actionBar.setDisplayHomeAsUpEnabled(true); actionBar.setHomeButtonEnabled(true); // Do something against banding effect in gradients // Dither flag might mess up on certain devices?? final Window window = getWindow(); window.setFormat(PixelFormat.RGBA_8888); window.addFlags(WindowManager.LayoutParams.FLAG_DITHER); // Setzt Default-Werte, wenn noch keine Werte vorhanden PreferenceManager.setDefaultValues(this, R.xml.preferences, false); final String uuid = ConfigHelper.getUUID(getApplicationContext()); fm = getFragmentManager(); final Fragment fragment = fm.findFragmentById(R.id.fragment_content); if (!ConfigHelper.isTCAccepted(this)) { if (fragment != null && fm.getBackStackEntryCount() >= 1) // clear fragment back stack fm.popBackStack(fm.getBackStackEntryAt(0).getId(), FragmentManager.POP_BACK_STACK_INCLUSIVE); getActionBar().hide(); setLockNavigationDrawer(true); showTermsCheck(); } else { currentMapOptions.put("highlight", uuid); if (fragment == null) { if (false) // deactivated for si // ! ConfigHelper.isNDTDecisionMade(this)) { showTermsCheck(); showNdtCheck(); } else initApp(true); } } geoLocation = new MainGeoLocation(getApplicationContext()); mNetworkStateChangedFilter = new IntentFilter(); mNetworkStateChangedFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION); mNetworkStateIntentReceiver = new BroadcastReceiver() { @Override public void onReceive(final Context context, final Intent intent) { if (intent.getAction().equals(ConnectivityManager.CONNECTIVITY_ACTION)) { final boolean connected = !intent.getBooleanExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY, false); final boolean isFailover = intent.getBooleanExtra(ConnectivityManager.EXTRA_IS_FAILOVER, false); if (connected) { if (networkInfoCollector != null) { networkInfoCollector.setHasConnectionFromAndroidApi(true); } } else { if (networkInfoCollector != null) { networkInfoCollector.setHasConnectionFromAndroidApi(false); } } Log.i(DEBUG_TAG, "CONNECTED: " + connected + " FAILOVER: " + isFailover); } } }; }