List of usage examples for android.view KeyEvent getKeyCode
public final int getKeyCode()
From source file:com.zld.ui.ZldNewActivity.java
@Override public boolean dispatchKeyEvent(KeyEvent event) { // TODO Auto-generated method stub if (event.getKeyCode() == KeyEvent.KEYCODE_SPACE) { cashFragment.setFocus();/*from w w w . j av a 2 s. c om*/ return true; } return event.getKeyCode() == KeyEvent.KEYCODE_ENTER || super.dispatchKeyEvent(event); }
From source file:com.chenglong.muscle.ui.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 ww. j a va2 s . co 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 (Build.VERSION.SDK_INT >= 11) { // The focus finder had a bug handling FOCUS_FORWARD and // FOCUS_BACKWARD // before Android 3.0. Ignore the include_tab key on those // devices. 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:android.support.v7.app.AppCompatDelegateImplV7.java
@Override boolean onKeyShortcut(int keyCode, KeyEvent ev) { // Let the Action Bar have a chance at handling the shortcut ActionBar ab = getSupportActionBar(); if (ab != null && ab.onKeyShortcut(keyCode, ev)) { return true; }/*from ww w . j a va 2 s. c om*/ // If the panel is already prepared, then perform the shortcut using it. boolean handled; if (mPreparedPanel != null) { handled = performPanelShortcut(mPreparedPanel, ev.getKeyCode(), ev, Menu.FLAG_PERFORM_NO_CLOSE); if (handled) { if (mPreparedPanel != null) { mPreparedPanel.isHandled = true; } return true; } } // If the panel is not prepared, then we may be trying to handle a shortcut key // combination such as Control+C. Temporarily prepare the panel then mark it // unprepared again when finished to ensure that the panel will again be prepared // the next time it is shown for real. if (mPreparedPanel == null) { PanelFeatureState st = getPanelState(FEATURE_OPTIONS_PANEL, true); preparePanel(st, ev); handled = performPanelShortcut(st, ev.getKeyCode(), ev, Menu.FLAG_PERFORM_NO_CLOSE); st.isPrepared = false; if (handled) { return true; } } return false; }
From source file:com.oakesville.mythling.MediaActivity.java
@Override public boolean dispatchKeyEvent(KeyEvent event) { if (event.getAction() == KeyEvent.ACTION_DOWN && getAppSettings().isTv()) { if (event.getKeyCode() == KeyEvent.KEYCODE_MENU) { setFocusOnActionBar();//from ww w . j a va2s . co m return true; } } return super.dispatchKeyEvent(event); }
From source file:com.oakesville.mythling.MediaActivity.java
void initListViewDpadHandler() { if (getAppSettings().isTv()) { getListView().setOnKeyListener(new OnKeyListener() { public boolean onKey(View v, int keyCode, KeyEvent event) { if (event.getAction() == KeyEvent.ACTION_DOWN) { if (event.getKeyCode() == KeyEvent.KEYCODE_DPAD_RIGHT) { Listable listable = getListables().get(getSelItemIndex()); if (listable instanceof Category) { getListView().performItemClick(getListAdapter().getView(selItemIndex, null, null), selItemIndex, getListAdapter().getItemId(selItemIndex)); return true; } else if (isSplitView()) { getListAdapter().setSelection(selItemIndex); getListView().setItemChecked(selItemIndex, true); showItemInDetailPane(selItemIndex, true); return true; }/*from w w w .ja v a 2 s .c o m*/ } else if (event.getKeyCode() == KeyEvent.KEYCODE_DPAD_LEFT && !"".equals(getPath())) { onBackPressed(); return true; } } return false; } }); } }
From source file:com.fvd.nimbus.BrowseActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //overridePendingTransition( R.anim.slide_in_up, R.anim.slide_out_up ); //overridePendingTransition(R.anim.carbon_slide_in,R.anim.carbon_slide_out); //overridePendingTransition(R.anim.activity_open_scale,R.anim.activity_close_translate); getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); try {/*from w w w .ja v a2s . c o m*/ requestWindowFeature(Window.FEATURE_NO_TITLE); } catch (Exception e) { e.printStackTrace(); } clipData = new DataExchange(); isInitNow = true; setContentView(R.layout.screen_browser); serverHelper.getInstance().setCallback(this, this); prefs = PreferenceManager.getDefaultSharedPreferences(this); lastUrl = prefs.getString("LAST_URL", ""); saveCSS = prefs.getString("clipStyle", "1").equals("1"); ctx = this; //adapter = new TextAdapter(this); /*Uri data = getIntent().getData(); if(data!=null){ lastUrl=data.toString(); }*/ Intent intent = getIntent(); String action = intent.getAction(); String type = intent.getType(); if (Intent.ACTION_VIEW.equals(action) /*&& type != null*/) { Uri data = intent.getData(); if (data != null) { lastUrl = data.toString(); appSettings.appendLog("browse:onCreate " + lastUrl); } } else if (Intent.ACTION_SEND.equals(action) /*&& type != null*/) { if ("text/plain".equals(type)) { String surl = intent.getStringExtra(Intent.EXTRA_TEXT); if (surl.contains(" ")) { String[] arr = surl.replace("\t", " ").split(" "); for (String s : arr) { if (s.contains("://")) { lastUrl = s.trim(); break; } } } else if (surl.contains("://")) lastUrl = surl.trim(); appSettings.appendLog("browse:onCreate " + lastUrl); } } drawer = (DrawerLayout) findViewById(R.id.root); View v = findViewById(R.id.wv); wv = (fvdWebView) findViewById(R.id.wv); wv.setEventsHandler(this); //registerForContextMenu(wv); urlField = (AutoCompleteTextView) findViewById(R.id.etAddess); urlField.setSelectAllOnFocus(true); urlField.setOnEditorActionListener(new EditText.OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if (actionId == EditorInfo.IME_ACTION_DONE) { /*InputMethodManager imm = (InputMethodManager)v.getContext().getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(v.getWindowToken(), 0);*/ onNavButtonClicked(); return true; } else if (event != null && event.getKeyCode() == KeyEvent.KEYCODE_ENTER) { onNavButtonClicked(); return true; } return false; } }); onViewCreated(); handler = new Handler() { @Override public void handleMessage(Message msg) { switch (msg.what) { case 0: findViewById(R.id.bZoomStack).setVisibility(View.VISIBLE); findViewById(R.id.bToggleMenu).setVisibility(View.GONE); break; default: break; } } }; navButton = (ImageButton) findViewById(R.id.ibReloadWebPage); navButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { //Toast.makeText(getApplicationContext(), "You made a mess", Toast.LENGTH_LONG).show(); onNavButtonClicked(); } }); findViewById(R.id.bSavePageFragment).setOnClickListener(new View.OnClickListener() { public void onClick(View v) { //toggleTools(); floatMenu.collapse(); if (!wv.getInjected()) Toast.makeText(ctx, getString(R.string.wait_load), Toast.LENGTH_LONG).show(); clipMode = 2; if (wv.getInjected()/* && !v.isSelected()*/) { wv.setCanClip(true); v.setSelected(true); Toast.makeText(ctx, ctx.getString(R.string.use_longtap), Toast.LENGTH_LONG).show(); } } }); (findViewById(R.id.bSaveFullPage)).setOnClickListener(new View.OnClickListener() { public void onClick(View v) { floatMenu.collapse(); if (wv.getInjected()) { wv.setCanClip(false); wv.saveArticle(); clipMode = 1; progressDialog = ProgressDialog.show(v.getContext(), "Nimbus Clipper", getString(R.string.please_wait), true, false); } else { Toast.makeText(ctx, getString(R.string.wait_load), Toast.LENGTH_LONG).show(); } } }); findViewById(R.id.bTakeScreenshot).setOnClickListener(new View.OnClickListener() { public void onClick(View v) { //toggleTools(); floatMenu.collapse(); findViewById(R.id.bSaveFullPage).setVisibility(View.GONE); findViewById(R.id.bSavePageFragment).setVisibility(View.GONE); findViewById(R.id.bTakeScreenshot).setVisibility(View.GONE); if (wv.getInjected()) { wv.setCanClip(false); } findViewById(R.id.bToggleMenu).setVisibility(View.GONE); /*screenCapture(); findViewById(R.id.bToggleMenu).setVisibility(View.VISIBLE);*/ findViewById(R.id.bTakeScreenshot).postDelayed(new Runnable() { @Override public void run() { // TODO Auto-generated method stub screenCapture(); findViewById(R.id.bToggleMenu).setVisibility(View.VISIBLE); finish(); } }, 10); //showDialog(DIALOG_CAPTURE); } }); (findViewById(R.id.bDone)).setOnClickListener(new View.OnClickListener() { public void onClick(View v) { { try { wv.setCanClip(false); wv.endSelectionMode(); //findViewById(R.id.bSavePageFragment).setSelected(false); clipMode = 2; wv.endSelectionMode(); String selHtml = clipData.getContent(); if (selHtml.length() > 0) { String ss = selHtml.substring(0, selHtml.indexOf(">") + 1).toLowerCase(); int j = ss.indexOf("<div"); if (j == 0) { j = ss.indexOf("style"); if (j > 0) { int k = ss.indexOf("\"", j + 11); if (k > 0) selHtml = selHtml.replace(selHtml.substring(j, k + 1), ""); } //selHtml="<DIV>"+selHtml.substring(ss.length()); } clipData.setContent(selHtml); clipData.setTitle(wv.getTitle()); /*if (true){ if(sessionId.length() == 0 || userPass.length()==0) showSettings(); else { if(prefs.getBoolean("check_fast", false)){ sendNote(wv.getTitle(), clipData.getContent(), parent, tag); clipData.setContent(""); } else { //serverHelper.getInstance().setCallback(this,this); if(appSettings.sessionId.length()>0) { serverHelper.getInstance().sendRequest("notes:getFolders", "",""); } } } wv.endSelectionMode(); } */ Intent i = new Intent(getApplicationContext(), previewActivity.class); i.putExtra("content", clipData); startActivityForResult(i, 5); //overridePendingTransition( R.anim.slide_in_up, R.anim.slide_out_up ); overridePendingTransition(R.anim.carbon_slide_in, R.anim.carbon_slide_out); } //clipData.setContent(""); } catch (Exception e) { BugReporter.Send("onEndSelection", e.getMessage()); } } //showDialog(DIALOG_CAPTURE); } }); findViewById(R.id.bZoomIn).setOnClickListener(new View.OnClickListener() { public void onClick(View v) { wv.ZoomInSelection(); } }); findViewById(R.id.bZoomOut).setOnClickListener(new View.OnClickListener() { public void onClick(View v) { wv.ZoomOutSelection(); } }); setNavButtonState(NavButtonState.NBS_GO); progressBar = (ProgressBar) findViewById(R.id.progressbar); //CookieSyncManager.createInstance(this); //webSettings.setLoadsImagesAutomatically(imgOn); userMail = prefs.getString("userMail", ""); userPass = prefs.getString("userPass", ""); sessionId = prefs.getString("sessionId", ""); appSettings.sessionId = sessionId; appSettings.userMail = userMail; appSettings.userPass = userPass; if ("1".equals(prefs.getString("userAgent", "1"))) { wv.setUserAgent(null); } else wv.setUserAgent(deskAgent); final Activity activity = this; //lastUrl="file:///android_asset/android.html"; if (lastUrl.length() > 0) { //wv.navigate(lastUrl); //if(!urlField.getText().toString().equals(wv.getUrl())) urlField.setText(lastUrl); openURL(); } isInitNow = false; urlField.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View v, int position, long id) { // TODO Auto-generated method stub /*String item = (String)parent.getItemAtPosition(position); Toast.makeText( getApplicationContext(), " " + item, Toast.LENGTH_SHORT).show();*/ openURL(); } }); urlField.addTextChangedListener(this); parent = prefs.getString("remFolderId", "default"); /*ListView listView = (ListView) findViewById(R.id.left_drawer); listView.setAdapter(new DrawerMenuAdapter(this,getResources().getStringArray(R.array.lmenu_browser))); listView.setOnItemClickListener(this);*/ }
From source file:study.tdcc.act.MainCalendar.java
/** * ??/*www. j a va 2 s . c o m*/ * * @param kEvent * @return ?????true */ @Override public boolean dispatchKeyEvent(KeyEvent kEvent) { Log.d("DEBUG", "MainCalendar dispatchKeyEvent Start"); //????? if (kEvent.getAction() == KeyEvent.ACTION_DOWN) { //????? if (kEvent.getKeyCode() == KeyEvent.KEYCODE_BACK) { //?yes/no? showYesNoDialog(this, R.string.mes1_dialog, R.string.mes2_dialog, new DialogInterface.OnClickListener() { //?? public void onClick(DialogInterface dialog, int whith) { if (whith == DialogInterface.BUTTON_POSITIVE) { // endActivity(); } else if (whith == DialogInterface.BUTTON_NEGATIVE) { // return; } } }); } } Log.d("DEBUG", "MainCalendar dispatchKeyEvent End"); return super.dispatchKeyEvent(kEvent); }
From source file:beichen.douban.ui.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 www . ja v a2s . com*/ * * @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 (Build.VERSION.SDK_INT >= 11) { // The focus finder had a bug handling FOCUS_FORWARD and // FOCUS_BACKWARD // before Android 3.0. Ignore the tab key on those // devices. 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:cn.xiaowen.news.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./* ww w . j a v 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 (Build.VERSION.SDK_INT >= 11) { // The focus finder had a bug handling FOCUS_FORWARD and // FOCUS_BACKWARD // before Android 3.0. Ignore the tab key on those devices. if (KeyEventCompat.hasNoModifiers(event)) { handled = arrowScroll(FOCUS_FORWARD); } else if (KeyEventCompat.hasModifiers(event, KeyEvent.META_SHIFT_ON)) { handled = arrowScroll(FOCUS_BACKWARD); } } break; } } return handled; }