List of usage examples for android.view KeyEvent KEYCODE_BACK
int KEYCODE_BACK
To view the source code for android.view KeyEvent KEYCODE_BACK.
Click Source Link
From source file:com.android.firewall.FirewallListPage.java
@Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { if (isQuit == false) { isQuit = true;//from w ww . ja va 2s . c o m Toast.makeText(getBaseContext(), "click back again to close", Toast.LENGTH_SHORT).show(); TimerTask task = null; task = new TimerTask() { @Override public void run() { isQuit = false; } }; timer.schedule(task, 2000); } else { finish(); } } else { } return false; }
From source file:ch.gianulli.trelloapi.ui.AuthenticationDialogFragment.java
@Nullable @Override/*ww w . j a va2 s .c om*/ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { if (getDialog() != null) { getDialog().requestWindowFeature(Window.FEATURE_NO_TITLE); } View v = inflater.inflate(R.layout.dialog_authentication, container, false); mProgressIndicator = (ProgressBar) v.findViewById(R.id.progress_indicator); mWebView = (WebView) v.findViewById(R.id.webview); // Catch token mWebView.setWebViewClient(new WebViewClient() { @Override public void onPageStarted(WebView view, String url, Bitmap favicon) { setProgressIndicatorVisibility(true); } @Override public void onPageFinished(WebView view, String url) { setProgressIndicatorVisibility(false); if (url.equals(URL_TOKEN)) { // Get token and close dialog mWebView.loadUrl("javascript:window.HTMLOUT.parseHTML('<html>'+document" + ".getElementsByTagName('html')[0].innerHTML+'</html>');"); } else { super.onPageFinished(view, url); } } }); WebSettings webSettings = mWebView.getSettings(); webSettings.setJavaScriptEnabled(true); mWebView.addJavascriptInterface(new MyJavaScriptInterface(), "HTMLOUT"); mWebView.setVisibility(View.GONE); mWebView.setOnKeyListener(new View.OnKeyListener() { @Override public boolean onKey(View v, int keyCode, KeyEvent event) { if (event.getAction() == KeyEvent.ACTION_UP) { switch (keyCode) { case KeyEvent.KEYCODE_BACK: if (mWebView.canGoBack()) { mWebView.goBack(); return true; } } } return false; } }); // Load first page setProgressIndicatorVisibility(true); try { mWebView.loadUrl(URL_AUTHORIZATION + "key=" + mApi.getAppKey() + "&name=" + URLEncoder.encode(getString(R.string.app_name), "UTF-8") + "&expiration=never&response_type=token&scope=read,write"); } catch (UnsupportedEncodingException e) { // never happens } return v; }
From source file:org.lol.reddit.activities.CommentEditActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { if (item.getTitle().equals(getString(R.string.comment_edit_save))) { final ProgressDialog progressDialog = new ProgressDialog(this); progressDialog.setTitle(getString(R.string.comment_reply_submitting_title)); progressDialog.setMessage(getString(R.string.comment_reply_submitting_message)); progressDialog.setIndeterminate(true); progressDialog.setCancelable(true); progressDialog.setCanceledOnTouchOutside(false); progressDialog.setOnCancelListener(new DialogInterface.OnCancelListener() { public void onCancel(final DialogInterface dialogInterface) { General.quickToast(CommentEditActivity.this, R.string.comment_reply_oncancel); progressDialog.dismiss(); }/*from www .j a v a 2s. c om*/ }); progressDialog.setOnKeyListener(new DialogInterface.OnKeyListener() { public boolean onKey(final DialogInterface dialogInterface, final int keyCode, final KeyEvent keyEvent) { if (keyCode == KeyEvent.KEYCODE_BACK) { General.quickToast(CommentEditActivity.this, R.string.comment_reply_oncancel); progressDialog.dismiss(); } return true; } }); final APIResponseHandler.ActionResponseHandler handler = new APIResponseHandler.ActionResponseHandler( this) { @Override protected void onSuccess() { General.UI_THREAD_HANDLER.post(new Runnable() { public void run() { if (progressDialog.isShowing()) progressDialog.dismiss(); General.quickToast(CommentEditActivity.this, R.string.comment_edit_done); finish(); } }); } @Override protected void onCallbackException(Throwable t) { BugReportActivity.handleGlobalError(CommentEditActivity.this, t); } @Override protected void onFailure(RequestFailureType type, Throwable t, StatusLine status, String readableMessage) { final RRError error = General.getGeneralErrorForFailure(context, type, t, status, null); General.UI_THREAD_HANDLER.post(new Runnable() { public void run() { General.showResultDialog(CommentEditActivity.this, error); if (progressDialog.isShowing()) progressDialog.dismiss(); } }); } @Override protected void onFailure(final APIFailureType type) { final RRError error = General.getGeneralErrorForFailure(context, type); General.UI_THREAD_HANDLER.post(new Runnable() { public void run() { General.showResultDialog(CommentEditActivity.this, error); if (progressDialog.isShowing()) progressDialog.dismiss(); } }); } }; final CacheManager cm = CacheManager.getInstance(this); final RedditAccount selectedAccount = RedditAccountManager.getInstance(this).getDefaultAccount(); RedditAPI.editComment(cm, handler, selectedAccount, commentIdAndType, textEdit.getText().toString(), this); progressDialog.show(); } else if (item.getTitle().equals(getString(R.string.comment_reply_preview))) { MarkdownPreviewDialog.newInstance(textEdit.getText().toString()).show(getSupportFragmentManager()); } return true; }
From source file:com.github.fielddb.storybook.ui.StoryBookSubExperiment.java
@Override public boolean onKeyDown(int keyCode, KeyEvent event) { if ((keyCode == KeyEvent.KEYCODE_BACK)) { Intent intent = new Intent(Config.INTENT_FINISHED_SUB_EXPERIMENT); intent.putExtra(Config.EXTRA_STIMULI, this.mStimuli); this.setResult(Config.CODE_EXPERIMENT_COMPLETED, intent); this.finish(); }//from ww w. java2s.c o m return super.onKeyDown(keyCode, event); }
From source file:com.flan.stock.activity.HomeActivity.java
@Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { exitBy2Click();/*from w ww. j a v a 2 s .c o m*/ } return false; }
From source file:com.johnny.gank.ui.activity.WebviewActivity.java
@Override public boolean onKeyDown(int keyCode, KeyEvent event) { if ((keyCode == KeyEvent.KEYCODE_BACK) && vWebView.canGoBack()) { vWebView.goBack();/*w w w .j a v a2 s . co m*/ return true; } return super.onKeyDown(keyCode, event); }
From source file:com.longle1.facedetection.MainActivity.java
@Override public boolean onKeyDown(int keycode, KeyEvent event) { if (keycode == KeyEvent.KEYCODE_BACK) { this.finish(); return true; }//ww w . j a v a 2 s .c o m return super.onKeyDown(keycode, event); }
From source file:com.app.blockydemo.ui.fragment.FormulaEditorScriptListFragment.java
@Override public void onListItemClick(int position) { Log.d("catroid", "onListItemClick"); if (!inContextMode) { FormulaEditorFragment formulaEditor = (FormulaEditorFragment) getActivity().getSupportFragmentManager() .findFragmentByTag(FormulaEditorFragment.FORMULA_EDITOR_FRAGMENT_TAG); if (formulaEditor != null) { formulaEditor.addUserVariableToActiveFormula(adapter.getItem(position).getName()); formulaEditor.updateButtonViewOnKeyboard(); }/*from ww w. j a v a 2 s . c o m*/ KeyEvent keyEvent = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_BACK); onKey(null, keyEvent.getKeyCode(), keyEvent); } }
From source file:com.example.android.animationsdemo.ListViewDraggingAnimation.java
@Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { TextView tv = (TextView) listView.getChildAt(0); Log.v("settingspage", "Text from textview" + tv.getText()); int k = listView.getCount(); Log.v("settingspage", "Number of views" + String.valueOf(k)); String[] libraries = new String[k]; for (int i = 0; i < k; i++) { tv = (TextView) listView.getChildAt(i); libraries[i] = (String) tv.getText(); Log.v("settingspage", "valueoflib" + libraries[i]); SharedPreferences settings3 = getApplicationContext() .getSharedPreferences("com.example.android.animationsdemo", 0); SharedPreferences.Editor editor3 = settings3.edit(); editor3.putString(String.valueOf(i), libraries[i]); editor3.putString(libraries[i] + "new", String.valueOf(i)); editor3.apply();//from w w w . ja v a2 s. c o m } Intent i = new Intent(ListViewDraggingAnimation.this, ScreenSlideActivity.class); startActivity(i); finish(); } return false; }
From source file:com.deadpixels.light.clipper.Settings.java
@Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK && shouldRestartHome) { Log.v(Home.TAG, "Restarting home"); NavUtils.navigateUpFromSameTask(this); return true; }/* w w w .j a va 2s . c o m*/ return super.onKeyDown(keyCode, event); }