List of usage examples for android.view KeyEvent getAction
public final int getAction()
From source file:com.phonegap.plugin.ChildBrowser.java
/** * Display a new browser with the specified URL. * * @param url The url to load. * @param jsonObject /*w w w . j a va 2 s . c o m*/ */ public String showWebPage(final String url, JSONObject options) { // Determine if we should hide the location bar. if (options != null) { showLocationBar = options.optBoolean("showLocationBar", true); } // Create dialog in new thread Runnable runnable = new Runnable() { public void run() { dialog = new Dialog(ctx.getContext(), android.R.style.Theme_Translucent_NoTitleBar); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setCancelable(true); dialog.setOnDismissListener(new DialogInterface.OnDismissListener() { public void onDismiss(DialogInterface dialog) { try { JSONObject obj = new JSONObject(); obj.put("type", CLOSE_EVENT); sendUpdate(obj, false); } catch (JSONException e) { Log.d(LOG_TAG, "Should never happen"); } } }); LinearLayout.LayoutParams backParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); LinearLayout.LayoutParams forwardParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); LinearLayout.LayoutParams editParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 1.0f); LinearLayout.LayoutParams closeParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); LinearLayout.LayoutParams wvParams = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT); LinearLayout main = new LinearLayout(ctx.getContext()); main.setOrientation(LinearLayout.VERTICAL); LinearLayout toolbar = new LinearLayout(ctx.getContext()); toolbar.setLayoutParams( new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); toolbar.setOrientation(LinearLayout.HORIZONTAL); ImageButton back = new ImageButton(ctx.getContext()); back.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { goBack(); } }); back.setId(1); try { back.setImageBitmap(loadDrawable("www/childbrowser/icon_arrow_left.png")); } catch (IOException e) { Log.e(LOG_TAG, e.getMessage(), e); } back.setLayoutParams(backParams); ImageButton forward = new ImageButton(ctx.getContext()); forward.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { goForward(); } }); forward.setId(2); try { forward.setImageBitmap(loadDrawable("www/childbrowser/icon_arrow_right.png")); } catch (IOException e) { Log.e(LOG_TAG, e.getMessage(), e); } forward.setLayoutParams(forwardParams); edittext = new EditText(ctx.getContext()); edittext.setOnKeyListener(new View.OnKeyListener() { public boolean onKey(View v, int keyCode, KeyEvent event) { // If the event is a key-down event on the "enter" button if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) { navigate(edittext.getText().toString()); return true; } return false; } }); edittext.setId(3); edittext.setSingleLine(true); edittext.setText(url); edittext.setLayoutParams(editParams); ImageButton close = new ImageButton(ctx.getContext()); close.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { closeDialog(); } }); close.setId(4); try { close.setImageBitmap(loadDrawable("www/childbrowser/icon_close.png")); } catch (IOException e) { Log.e(LOG_TAG, e.getMessage(), e); } close.setLayoutParams(closeParams); webview = new WebView(ctx.getContext()); webview.setWebChromeClient(new WebChromeClient()); WebViewClient client = new ChildBrowserClient(edittext); webview.setWebViewClient(client); WebSettings settings = webview.getSettings(); settings.setJavaScriptEnabled(true); settings.setJavaScriptCanOpenWindowsAutomatically(true); settings.setBuiltInZoomControls(true); settings.setPluginsEnabled(true); settings.setDomStorageEnabled(true); webview.loadUrl(url); webview.setId(5); webview.setInitialScale(0); webview.setLayoutParams(wvParams); webview.requestFocus(); webview.requestFocusFromTouch(); toolbar.addView(back); toolbar.addView(forward); toolbar.addView(edittext); toolbar.addView(close); if (getShowLocationBar()) { main.addView(toolbar); } main.addView(webview); WindowManager.LayoutParams lp = new WindowManager.LayoutParams(); lp.copyFrom(dialog.getWindow().getAttributes()); lp.width = WindowManager.LayoutParams.FILL_PARENT; lp.height = WindowManager.LayoutParams.FILL_PARENT; dialog.setContentView(main); dialog.show(); dialog.getWindow().setAttributes(lp); } private Bitmap loadDrawable(String filename) throws java.io.IOException { InputStream input = ctx.getAssets().open(filename); return BitmapFactory.decodeStream(input); } }; this.ctx.runOnUiThread(runnable); return ""; }
From source file:com.taobao.wuzhong.plugins.ChildBrowser.java
/** * Display a new browser with the specified URL. * * @param url The url to load. * @param jsonObject/* ww w. ja v a 2 s . com*/ */ public String showWebPage(final String url, JSONObject options) { // Determine if we should hide the location bar. if (options != null) { showLocationBar = options.optBoolean("showLocationBar", true); } // Create dialog in new thread Runnable runnable = new Runnable() { public void run() { dialog = new Dialog(ctx.getContext(), android.R.style.Theme_Translucent_NoTitleBar); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setCancelable(true); dialog.setOnDismissListener(new DialogInterface.OnDismissListener() { public void onDismiss(DialogInterface dialog) { try { JSONObject obj = new JSONObject(); obj.put("type", CLOSE_EVENT); sendUpdate(obj, false); } catch (JSONException e) { Log.d(LOG_TAG, "Should never happen"); } } }); LinearLayout.LayoutParams backParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); LinearLayout.LayoutParams forwardParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); LinearLayout.LayoutParams editParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 1.0f); LinearLayout.LayoutParams closeParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); LinearLayout.LayoutParams wvParams = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT); LinearLayout main = new LinearLayout(ctx.getContext()); main.setOrientation(LinearLayout.VERTICAL); LinearLayout toolbar = new LinearLayout(ctx.getContext()); toolbar.setLayoutParams( new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); toolbar.setOrientation(LinearLayout.HORIZONTAL); ImageButton back = new ImageButton(ctx.getContext()); back.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { goBack(); } }); back.setId(1); try { back.setImageBitmap(loadDrawable("www/childbrowser/icon_arrow_left.png")); } catch (IOException e) { Log.e(LOG_TAG, e.getMessage(), e); } back.setLayoutParams(backParams); ImageButton forward = new ImageButton(ctx.getContext()); forward.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { goForward(); } }); forward.setId(2); try { forward.setImageBitmap(loadDrawable("www/childbrowser/icon_arrow_right.png")); } catch (IOException e) { Log.e(LOG_TAG, e.getMessage(), e); } forward.setLayoutParams(forwardParams); edittext = new EditText(ctx.getContext()); edittext.setOnKeyListener(new View.OnKeyListener() { public boolean onKey(View v, int keyCode, KeyEvent event) { // If the event is a key-down event on the "enter" button if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) { navigate(edittext.getText().toString()); return true; } return false; } }); edittext.setId(3); edittext.setSingleLine(true); edittext.setText(url); edittext.setLayoutParams(editParams); ImageButton close = new ImageButton(ctx.getContext()); close.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { closeDialog(); } }); close.setId(4); try { close.setImageBitmap(loadDrawable("www/childbrowser/icon_close.png")); } catch (IOException e) { Log.e(LOG_TAG, e.getMessage(), e); } close.setLayoutParams(closeParams); webview = new WebView(ctx.getContext()); webview.setWebChromeClient(new WebChromeClient()); WebViewClient client = new ChildBrowserClient(edittext); webview.setWebViewClient(client); WebSettings settings = webview.getSettings(); settings.setJavaScriptEnabled(true); settings.setJavaScriptCanOpenWindowsAutomatically(true); settings.setBuiltInZoomControls(true); settings.setPluginsEnabled(true); settings.setDomStorageEnabled(true); webview.loadUrl(url); webview.setId(5); webview.setInitialScale(0); webview.setLayoutParams(wvParams); webview.requestFocus(); webview.requestFocusFromTouch(); toolbar.addView(back); toolbar.addView(forward); toolbar.addView(edittext); toolbar.addView(close); if (getShowLocationBar()) { main.addView(toolbar); } main.addView(webview); WindowManager.LayoutParams lp = new WindowManager.LayoutParams(); lp.copyFrom(dialog.getWindow().getAttributes()); lp.width = WindowManager.LayoutParams.FILL_PARENT; lp.height = WindowManager.LayoutParams.FILL_PARENT; dialog.setContentView(main); dialog.show(); dialog.getWindow().setAttributes(lp); } private Bitmap loadDrawable(String filename) throws java.io.IOException { InputStream input = ctx.getAssets().open(filename); return BitmapFactory.decodeStream(input); } }; this.ctx.runOnUiThread(runnable); return ""; }
From source file:org.ligi.gobandroid_hd.ui.GoActivity.java
@Override public boolean onKey(View v, int keyCode, KeyEvent event) { if (event.getAction() == KeyEvent.ACTION_DOWN) { final Cell ensuredTouchPosition = interaction_scope.getEnsuredTouchPosition(); final BoardCell boardCell = getGame().getCalcBoard().getCell(ensuredTouchPosition); switch (keyCode) { case KeyEvent.KEYCODE_DPAD_UP: if (boardCell.up != null) { interaction_scope.touch_position = boardCell.up; } else { return false; }//from w w w .jav a 2 s . c o m break; case KeyEvent.KEYCODE_DPAD_LEFT: if (boardCell.left != null) { interaction_scope.touch_position = boardCell.left; } else { return false; } break; case KeyEvent.KEYCODE_DPAD_DOWN: if (boardCell.down != null) { interaction_scope.touch_position = boardCell.down; } else { return false; } break; case KeyEvent.KEYCODE_DPAD_RIGHT: if (boardCell.right != null) { interaction_scope.touch_position = boardCell.right; } else { return false; } break; case KeyEvent.KEYCODE_DPAD_CENTER: doMoveWithUIFeedback(boardCell); break; default: return false; } go_board.postInvalidate(); refreshZoomFragment(); return true; } return false; }
From source file:com.notepadlite.MainActivity.java
@TargetApi(Build.VERSION_CODES.HONEYCOMB) @Override// w w w . j ava 2s.c om public boolean dispatchKeyShortcutEvent(KeyEvent event) { super.dispatchKeyShortcutEvent(event); if (event.getAction() == KeyEvent.ACTION_DOWN && event.isCtrlPressed()) { if (getSupportFragmentManager().findFragmentById(R.id.noteViewEdit) instanceof NoteListFragment) { NoteListFragment fragment = (NoteListFragment) getSupportFragmentManager() .findFragmentByTag("NoteListFragment"); fragment.dispatchKeyShortcutEvent(event.getKeyCode()); } else if (getSupportFragmentManager() .findFragmentById(R.id.noteViewEdit) instanceof NoteViewFragment) { NoteViewFragment fragment = (NoteViewFragment) getSupportFragmentManager() .findFragmentByTag("NoteViewFragment"); fragment.dispatchKeyShortcutEvent(event.getKeyCode()); } else if (getSupportFragmentManager() .findFragmentById(R.id.noteViewEdit) instanceof NoteEditFragment) { NoteEditFragment fragment = (NoteEditFragment) getSupportFragmentManager() .findFragmentByTag("NoteEditFragment"); fragment.dispatchKeyShortcutEvent(event.getKeyCode()); } else if (getSupportFragmentManager().findFragmentById(R.id.noteViewEdit) instanceof WelcomeFragment) { WelcomeFragment fragment = (WelcomeFragment) getSupportFragmentManager() .findFragmentByTag("NoteListFragment"); fragment.dispatchKeyShortcutEvent(event.getKeyCode()); } return true; } return super.dispatchKeyShortcutEvent(event); }
From source file:com.ruesga.rview.BaseActivity.java
@Override public boolean dispatchKeyEvent(KeyEvent event) { if (event.getAction() == KeyEvent.ACTION_DOWN) { switch (event.getKeyCode()) { case KeyEvent.KEYCODE_MENU: if (getContentBinding().drawerLayout != null && getContentBinding().drawerLayout .getDrawerLockMode(GravityCompat.START) != DrawerLayout.LOCK_MODE_LOCKED_CLOSED) { if (getContentBinding().drawerLayout.isDrawerOpen(GravityCompat.START)) { getContentBinding().drawerLayout.closeDrawer(GravityCompat.START); } else { getContentBinding().drawerLayout.openDrawer(GravityCompat.START); }//from w w w. j av a 2s . c o m return true; } else if (getOptionsMenu() != null && getOptionsMenu().getMenu() != null && getOptionsMenu().getMenu().size() > 0) { if (getContentBinding().drawerLayout.isDrawerOpen(GravityCompat.END)) { closeOptionsDrawer(); } else { openOptionsDrawer(); } return true; } break; } } return super.dispatchKeyEvent(event); }
From source file:com.lemon.lime.MainActivity.java
@Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (event.getAction() == KeyEvent.ACTION_DOWN) { switch (keyCode) { case KeyEvent.KEYCODE_BACK: if (mWebView.canGoBack()) { getSupportActionBar().show(); mWebView.goBack();/*from w w w .j a va2 s . co m*/ } else { finish(); } return true; } } return super.onKeyDown(keyCode, event); }
From source file:com.app.azza.ocr.OcrCaptureActivity.java
@Override public boolean dispatchKeyEvent(KeyEvent event) { int action = event.getAction(); int keyCode = event.getKeyCode(); Text text = null;/*from w w w . jav a 2 s .c o m*/ List mtextList = getAllGraphicsText(); switch (keyCode) { case KeyEvent.KEYCODE_VOLUME_UP: if (action == KeyEvent.ACTION_DOWN) { Toast toast = Toast.makeText(this, "volume up pressed", Toast.LENGTH_SHORT); toast.show(); Log.v("upVolume", "up " + lineNumberToSpeak); // for(Object block:textList){ // text=(Text)block; // // tts.speak(text.getValue(), TextToSpeech.QUEUE_ADD, null, "DEFAULT"); // } if (mtextList.size() > 0) { // for (int i = 0; i < textList.size(); i++) { if (lineNumberToSpeak < mtextList.size()) { text = (Text) mtextList.get(lineNumberToSpeak); if (text != null && text.getValue() != null) { tts.speak(text.getValue(), TextToSpeech.QUEUE_ADD, null, "DEFAULT"); if (lineNumberToSpeak < mtextList.size()) lineNumberToSpeak++; } else { Log.d(TAG, "text data is null"); } // } } else { // al list al gdeda lines feha 22al lineNumberToSpeak = 0; } } else { Log.d(TAG, "no text detected"); } } return true; case KeyEvent.KEYCODE_VOLUME_DOWN: if (action == KeyEvent.ACTION_DOWN) { Toast toast = Toast.makeText(this, "volume down pressed", Toast.LENGTH_SHORT); toast.show(); if (mtextList.size() > 0) { // for (int i = 0; i < textList.size(); i++) { if (lineNumberToSpeak > -1) { text = (Text) mtextList.get(lineNumberToSpeak); if (text != null && text.getValue() != null) { tts.speak(text.getValue(), TextToSpeech.QUEUE_ADD, null, "DEFAULT"); if (lineNumberToSpeak > 0) lineNumberToSpeak--; } else { Log.d(TAG, "text data is null"); } } else { lineNumberToSpeak = 0; } } else { Log.d(TAG, "no text detected"); } } return true; default: return super.dispatchKeyEvent(event); } }
From source file:com.android.screenspeak.KeyboardSearchManager.java
@Override public boolean onKeyEvent(KeyEvent event) { // Only handle single-key events here. The KeyComboManager will pass us combos. if (event.getModifiers() != 0 || !mNodeSearch.isActive()) { return false; }// w w w . j a v a 2s .com if (event.getAction() == KeyEvent.ACTION_DOWN) { switch (event.getKeyCode()) { case KeyEvent.KEYCODE_ENTER: if (mHasNavigated || mNodeSearch.hasMatch()) { finishSearch(); mContext.getCursorController().clickCurrent(); } else { cancelSearch(); } return true; case KeyEvent.KEYCODE_DEL: resetHintTime(); final String queryText = mNodeSearch.getCurrentQuery(); if (queryText.isEmpty()) { cancelSearch(); } else { final String lastChar = queryText.substring(queryText.length() - 1); mNodeSearch.backspaceQueryText(); mSpeechController.speak(mContext.getString(R.string.template_text_removed, lastChar), SpeechController.QUEUE_MODE_FLUSH_ALL, FeedbackItem.FLAG_NO_HISTORY, null); } return true; case KeyEvent.KEYCODE_DPAD_UP: moveToEnd(NodeFocusFinder.SEARCH_BACKWARD); return true; case KeyEvent.KEYCODE_DPAD_LEFT: moveToNext(NodeFocusFinder.SEARCH_BACKWARD); return true; case KeyEvent.KEYCODE_DPAD_DOWN: moveToEnd(NodeFocusFinder.SEARCH_FORWARD); return true; case KeyEvent.KEYCODE_DPAD_RIGHT: moveToNext(NodeFocusFinder.SEARCH_FORWARD); return true; case KeyEvent.KEYCODE_SPACE: resetHintTime(); if (mNodeSearch.tryAddQueryText(" ")) { mSpeechController.speak(mContext.getString(R.string.symbol_space), SpeechController.QUEUE_MODE_FLUSH_ALL, FeedbackItem.FLAG_NO_HISTORY, null); } else { mContext.getFeedbackController().playAuditory(R.raw.complete); } return true; default: if (event.isPrintingKey()) { resetHintTime(); final String key = String.valueOf(event.getDisplayLabel()); if (mNodeSearch.tryAddQueryText(key)) { mSpeechController.speak(key.toLowerCase(), SpeechController.QUEUE_MODE_FLUSH_ALL, FeedbackItem.FLAG_NO_HISTORY, null); } else { mContext.getFeedbackController().playAuditory(R.raw.complete); } return true; } break; } } return false; }
From source file:com.hellofyc.base.app.activity.BaseActivity.java
@Override public boolean dispatchKeyEvent(@NonNull KeyEvent event) { final int keyCode = event.getKeyCode(); if (keyCode == KeyEvent.KEYCODE_BACK) { if (mPressTwoExit && mIsHighPriority) { final int action = event.getAction(); if (action == KeyEvent.ACTION_UP) { pressBackToExit();//from w ww .j a v a 2 s. co m return true; } } } return super.dispatchKeyEvent(event); }
From source file:com.jiandanbaoxian.fragment.DialogFragmentCreater.java
/** * Dialog ???/*from w ww .j ava2s. c o m*/ * @param mContext * @return */ private Dialog showLicenseChoiceDialog(final Context mContext) { View convertView = LayoutInflater.from(mContext).inflate(R.layout.dialog_license_choice, null); final Dialog dialog = new Dialog(mContext, R.style.mystyle); View.OnClickListener listener = new View.OnClickListener() { @Override public void onClick(View v) { switch (v.getId()) { case R.id.layout_rule: if (isAgree) { isAgree = false; ImageView imageView = (ImageView) v.findViewById(R.id.iv_choose); // TextView textView = (TextView)v.findViewById(R.id.tv_rule); imageView.setImageResource(R.drawable.icon_choose); // textView.setBackgroundColor(getResources().getColor(R.color.bg_gray_color_level_0)); // textView.setTextColor(getResources().getColor(R.color.tv_gray_color_level_3)); } else { isAgree = true; ImageView imageView = (ImageView) v.findViewById(R.id.iv_choose); // TextView textView = (TextView)v.findViewById(R.id.tv_rule); imageView.setImageResource(R.drawable.icon_choose_selected); // textView.setBackgroundResource(R.drawable.btn_select_base_shape_0); // textView.setTextColor(getResources().getColor(R.color.white_color)); } break; } if (onLicenseDialogClickListener != null) { onLicenseDialogClickListener.onClick(v, isAgree); } } }; TitleBar titleBar; SwipeRefreshLayout swipeLayout; final WebView webView; ProgressBar progressBar; LinearLayout layoutRule; LinearLayout layoutConfirm; titleBar = (TitleBar) convertView.findViewById(R.id.title_bar); swipeLayout = (SwipeRefreshLayout) convertView.findViewById(R.id.swipe_layout); webView = (WebView) convertView.findViewById(R.id.webView); progressBar = (ProgressBar) convertView.findViewById(R.id.progress_bar); layoutRule = (LinearLayout) convertView.findViewById(R.id.layout_rule); layoutConfirm = (LinearLayout) convertView.findViewById(R.id.layout_confirm); WebChromeClient client = new AppChromeWebClient(titleBar, progressBar, swipeLayout); webView.setWebChromeClient(client); webView.setWebViewClient(new AppWebClient()); webView.getSettings().setJavaScriptEnabled(true); webView.loadUrl(webViewURL); webView.setOnKeyListener(new View.OnKeyListener() { @Override public boolean onKey(View v, int keyCode, KeyEvent event) { if (event.getAction() == KeyEvent.ACTION_DOWN) { if (keyCode == KeyEvent.KEYCODE_BACK && webView.canGoBack()) { webView.goBack(); //? return true; //? } } return false; } }); titleBar.initTitleBarInfo("", R.drawable.arrow_left, -1, "", ""); titleBar.setOnTitleBarClickListener(new TitleBar.OnTitleBarClickListener() { @Override public void onLeftButtonClick(View v) { if (webView.canGoBack()) { webView.goBack(); //? return; //? } if (onLicenseDialogClickListener != null) { onLicenseDialogClickListener.onClick(v, isAgree); dismiss(); } } @Override public void onRightButtonClick(View v) { } }); UIUtils.initSwipeRefreshLayout(swipeLayout); swipeLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { @Override public void onRefresh() { webView.reload(); } }); layoutConfirm.setOnClickListener(listener); layoutRule.setOnClickListener(listener); dialog.setContentView(convertView); dialog.getWindow().setWindowAnimations(R.style.dialog_right_control_style); return dialog; }