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.krayzk9s.imgurholo.activities.MainActivity.java
@Override public boolean onKeyDown(int keyCode, KeyEvent event) { //Handle the back button SharedPreferences settings = getSettings(); FragmentManager fragmentManager = getSupportFragmentManager(); if (keyCode == KeyEvent.KEYCODE_BACK) { if (getActionBar() != null) getActionBar().show();//from w ww . j a v a 2s. co m } if (keyCode == KeyEvent.KEYCODE_BACK && settings.getBoolean("ConfirmExit", false) && isTaskRoot() && fragmentManager.getBackStackEntryCount() == 0) { //Ask the user if they want to quit new AlertDialog.Builder(this).setTitle(R.string.dialog_quit_title) .setMessage(R.string.dialog_quit_summary) .setPositiveButton(R.string.dialog_answer_yes, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { //Stop the activity MainActivity.this.finish(); } }).setNegativeButton(R.string.no, null).show(); return true; } else { return super.onKeyDown(keyCode, event); } }
From source file:com.alivenet.dmvtaxi.fragment.Fragment_ride_list.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_ride_list, container, false); mPref = getActivity().getSharedPreferences(MYPREF, Context.MODE_PRIVATE); mUserId = mPref.getString("userId", null); progressDialog = new ProgressDialog(getActivity()); progressDialog.setMessage("Please wait..."); progressDialog.setCancelable(false); recyclerView = (RecyclerView) view.findViewById(R.id.recycler_view); recyclerView.setHasFixedSize(true);/*from w w w.j av a2 s . c o m*/ LinearLayoutManager llm = new LinearLayoutManager(getActivity()); llm.setOrientation(LinearLayoutManager.VERTICAL); recyclerView.addItemDecoration(new SpacesItemDecoration(VERTICAL_ITEM_SPACE)); recyclerView.setLayoutManager(llm); recyclerView.setItemAnimator(new DefaultItemAnimator()); mnorides = (TextView) view.findViewById(R.id.tv_norides); RequestParams params = new RequestParams(); params.put("userId", mUserId); rideListWs(params); view.setFocusableInTouchMode(true); view.requestFocus(); view.setOnKeyListener(new View.OnKeyListener() { @Override public boolean onKey(View v, int keyCode, KeyEvent event) { if (event.getAction() == KeyEvent.ACTION_UP && keyCode == KeyEvent.KEYCODE_BACK) { // handle back button's click listener if (keyCode == KeyEvent.KEYCODE_BACK) { Fragment homeFragment = new FragmentMainScreen(); FragmentManager frgManager; frgManager = getFragmentManager(); frgManager.beginTransaction().replace(R.id.fragment_switch, homeFragment).commit(); return true; } return true; } return false; } }); return view; }
From source file:com.github.snowdream.android.app.books.BookFragment.java
private void initUI(View rootview) { webView = (WebView) rootview.findViewById(R.id.webView); // progressbar = (SmoothProgressBar) rootview.findViewById(R.id.progressbar); WebSettings webSettings = webView.getSettings(); webSettings.setJavaScriptEnabled(true); webSettings.setDomStorageEnabled(true); webSettings.setAllowFileAccess(true); webSettings.setSupportZoom(true);//from w ww. j a v a 2 s . c o m webSettings.setBuiltInZoomControls(true); webSettings.setUseWideViewPort(true); String appCachePath = getActivity().getApplicationContext().getCacheDir().getAbsolutePath(); webSettings.setAppCachePath(appCachePath); webSettings.setAppCacheEnabled(true); webView.setWebViewClient(new WebViewClient() { @Override public void onPageStarted(WebView view, String url, Bitmap favicon) { super.onPageStarted(view, url, favicon); // progressbar.setVisibility(View.VISIBLE); } @Override public void onPageFinished(WebView view, String url) { super.onPageFinished(view, url); // progressbar.setVisibility(View.INVISIBLE); } @Override public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { super.onReceivedError(view, errorCode, description, failingUrl); // progressbar.setVisibility(View.INVISIBLE); } }); webView.setWebChromeClient(new WebChromeClient() { @Override public boolean onJsAlert(WebView view, String url, String message, JsResult result) { return super.onJsAlert(view, url, message, result); } }); // The "loadAdOnCreate" and "testDevices" XML attributes no longer available. AdView adView = (AdView) rootview.findViewById(R.id.adView); AdRequest adRequest = new AdRequest.Builder().addTestDevice(AdRequest.DEVICE_ID_EMULATOR) .addTestDevice(TEST_DEVICE_ID).build(); adView.loadAd(adRequest); getView().setFocusableInTouchMode(true); getView().setOnKeyListener(new View.OnKeyListener() { @Override public boolean onKey(View v, int keyCode, KeyEvent event) { if (webView.canGoBack() && keyCode == KeyEvent.KEYCODE_BACK) { webView.goBack(); return true; } return false; } }); }
From source file:com.ryan.ryanreader.fragments.AddAccountDialog.java
@Override public Dialog onCreateDialog(final Bundle savedInstanceState) { if (alreadyCreated) return getDialog(); alreadyCreated = true;/*from w w w . ja v a2 s . c o m*/ super.onCreateDialog(savedInstanceState); final AlertDialog.Builder builder = new AlertDialog.Builder(getSupportActivity()); builder.setTitle(R.string.accounts_add); final View view = getSupportActivity().getLayoutInflater().inflate(R.layout.dialog_login, null); builder.setView(view); builder.setCancelable(true); final EditText usernameBox = ((EditText) view.findViewById(R.id.login_username)); usernameBox.setText(lastUsername); usernameBox.requestFocus(); usernameBox.requestFocusFromTouch(); builder.setPositiveButton(R.string.accounts_login, new DialogInterface.OnClickListener() { public void onClick(final DialogInterface dialogInterface, final int i) { final String username = ((EditText) getDialog().findViewById(R.id.login_username)).getText() .toString().trim(); final String password = ((EditText) getDialog().findViewById(R.id.login_password)).getText() .toString(); lastUsername = username; final ProgressDialog progressDialog = new ProgressDialog(getSupportActivity()); final Thread thread; progressDialog.setTitle(R.string.accounts_loggingin); progressDialog.setMessage(getString(R.string.accounts_loggingin_msg)); progressDialog.setIndeterminate(true); final AtomicBoolean cancelled = new AtomicBoolean(false); progressDialog.setCancelable(true); progressDialog.setCanceledOnTouchOutside(false); progressDialog.show(); progressDialog.setOnCancelListener(new DialogInterface.OnCancelListener() { public void onCancel(final DialogInterface dialogInterface) { cancelled.set(true); progressDialog.dismiss(); } }); progressDialog.setOnKeyListener(new DialogInterface.OnKeyListener() { public boolean onKey(final DialogInterface dialogInterface, final int keyCode, final KeyEvent keyEvent) { if (keyCode == KeyEvent.KEYCODE_BACK) { cancelled.set(true); progressDialog.dismiss(); } return true; } }); thread = new Thread() { @Override public void run() { // TODO better HTTP client final RedditAccount.LoginResultPair result = RedditAccount.login(getSupportActivity(), username, password, new DefaultHttpClient()); new Handler(Looper.getMainLooper()).post(new Runnable() { public void run() { if (cancelled.get()) return; // safe, since we're in the UI thread progressDialog.dismiss(); final AlertDialog.Builder alertBuilder = new AlertDialog.Builder( getSupportActivity()); alertBuilder.setNeutralButton(R.string.dialog_close, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { new AccountListDialog().show(getSupportActivity()); } }); // TODO handle errors better switch (result.result) { case CONNECTION_ERROR: alertBuilder.setTitle(R.string.error_connection_title); alertBuilder.setMessage(R.string.message_cannotlogin); break; case INTERNAL_ERROR: alertBuilder.setTitle(R.string.error_unknown_title); alertBuilder.setMessage(R.string.message_cannotlogin); break; case JSON_ERROR: alertBuilder.setTitle(R.string.error_parse_title); alertBuilder.setMessage(R.string.message_cannotlogin); break; case REQUEST_ERROR: alertBuilder.setTitle(R.string.error_connection_title); alertBuilder.setMessage(R.string.message_cannotlogin); break; case UNKNOWN_REDDIT_ERROR: alertBuilder.setTitle(R.string.error_unknown_title); alertBuilder.setMessage(R.string.message_cannotlogin); break; case WRONG_PASSWORD: alertBuilder.setTitle(R.string.error_invalid_password_title); alertBuilder.setMessage(R.string.error_invalid_password_message); break; case RATELIMIT: alertBuilder.setTitle(R.string.error_ratelimit_title); alertBuilder.setMessage(String.format("%s \"%s\"", getString(R.string.error_ratelimit_message), result.extraMessage)); break; case SUCCESS: RedditAccountManager.getInstance(getSupportActivity()) .addAccount(result.account); RedditAccountManager.getInstance(getSupportActivity()) .setDefaultAccount(result.account); alertBuilder.setTitle(R.string.general_success); alertBuilder.setMessage(R.string.message_nowloggedin); lastUsername = ""; break; default: throw new RuntimeException(); } final AlertDialog alertDialog = alertBuilder.create(); alertDialog.show(); } }); } }; thread.start(); } }); builder.setNegativeButton(R.string.dialog_cancel, null); return builder.create(); }
From source file:com.example.android.contactslist.ui.eventEntry.EventEntryActivity.java
public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { Toast.makeText(this, R.string.entry_discarded, Toast.LENGTH_SHORT).show(); //Return to last activity this.finish(); // same as hitting back button //TODO: do other stuff for tablet }/*from w ww .j a v a 2s . c o m*/ // Call super code so we dont limit default interaction //super.onKeyDown(keyCode, event); return true; }
From source file:com.example.nq.journalism_master.innerbrowser.InnerBrowserFragment.java
@Nullable @Override// w w w .j a va 2 s. c o m public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_inner_browser, container, false); initViews(view); initWebViewSettings(webView); // if not set this, click the back arrow will call nothing setHasOptionsMenu(true); webView.setWebChromeClient(new WebChromeClient() { @Override public void onProgressChanged(WebView view, int newProgress) { changeToolbarAndProgressBar(newProgress); } }); webView.setWebViewClient(new WebViewClient() { @Override public void onReceivedError(WebView view1, WebResourceRequest request, WebResourceError error) { webView.setVisibility(View.GONE); imageView.setVisibility(View.VISIBLE); textView.setVisibility(View.VISIBLE); imageView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (NetworkState.networkConnected(getContext())) { webView.loadUrl(url); webView.setVisibility(View.VISIBLE); imageView.setVisibility(View.GONE); textView.setVisibility(View.GONE); } } }); } @Override public void onPageFinished(WebView view, String url) { super.onPageFinished(view, url); progressBar.setVisibility(View.GONE); } }); // WebView?html? 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; } }); webView.loadUrl(url); return view; }
From source file:ayushi.view.fragment.SettingsFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.frag_settings, container, false); getActivity().setTitle("About App"); mToolbar = (Toolbar) rootView.findViewById(R.id.htab_toolbar); if (mToolbar != null) { ((ECartHomeActivity) getActivity()).setSupportActionBar(mToolbar); }/* ww w .ja v a 2 s . c o m*/ if (mToolbar != null) { ((ECartHomeActivity) getActivity()).getSupportActionBar().setDisplayHomeAsUpEnabled(true); mToolbar.setNavigationIcon(R.drawable.ic_drawer); } mToolbar.setNavigationOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { ((ECartHomeActivity) getActivity()).getmDrawerLayout().openDrawer(GravityCompat.START); } }); mToolbar.setTitleTextColor(Color.WHITE); submitLog = (TextView) rootView.findViewById(R.id.submit_log_txt); if (PreferenceHelper.getPrefernceHelperInstace().getBoolean(getActivity(), PreferenceHelper.SUBMIT_LOGS, true)) { submitLog.setText("Disable"); } else { submitLog.setText("Enable"); } rootView.findViewById(R.id.submit_log).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (PreferenceHelper.getPrefernceHelperInstace().getBoolean(getActivity(), PreferenceHelper.SUBMIT_LOGS, true)) { PreferenceHelper.getPrefernceHelperInstace().setBoolean(getActivity(), PreferenceHelper.SUBMIT_LOGS, false); submitLog.setText("Disable"); } else { PreferenceHelper.getPrefernceHelperInstace().setBoolean(getActivity(), PreferenceHelper.SUBMIT_LOGS, true); submitLog.setText("Enable"); } } }); rootView.setFocusableInTouchMode(true); rootView.requestFocus(); rootView.setOnKeyListener(new View.OnKeyListener() { @Override public boolean onKey(View v, int keyCode, KeyEvent event) { if (event.getAction() == KeyEvent.ACTION_UP && keyCode == KeyEvent.KEYCODE_BACK) { Utils.switchContent(R.id.frag_container, Utils.HOME_FRAGMENT, ((ECartHomeActivity) (getContext())), AnimationType.SLIDE_UP); } return true; } }); rootView.findViewById(R.id.picasso).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://github.com/square/picasso")); startActivity(browserIntent); } }); rootView.findViewById(R.id.acra).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://github.com/ACRA/acra")); startActivity(browserIntent); } }); rootView.findViewById(R.id.pull_zoom_view).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://github.com/Frank-Zhu/PullZoomView")); startActivity(browserIntent); } }); rootView.findViewById(R.id.list_buddies).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://github.com/jpardogo/ListBuddies")); startActivity(browserIntent); } }); rootView.findViewById(R.id.list_jazzy).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://github.com/twotoasters/JazzyListView")); startActivity(browserIntent); } }); rootView.findViewById(R.id.email_dev).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND); emailIntent.setType("text/plain"); emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[] { "serveroverloadofficial@gmail.com" }); emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Hello There"); emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "Add Message here"); emailIntent.setType("message/rfc822"); try { startActivity(Intent.createChooser(emailIntent, "Send email using...")); } catch (android.content.ActivityNotFoundException ex) { Toast.makeText(getActivity(), "No email clients installed.", Toast.LENGTH_SHORT).show(); } } }); return rootView; }
From source file:com.libreteam.taxi.Customer_Boarding.java
@SuppressLint("InflateParams") @SuppressWarnings({ "unchecked", "rawtypes" }) @Override//from w w w . ja v a 2 s. c o m public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { super.onCreate(savedInstanceState); View view = inflater.inflate(R.layout.customer_boarding_, null); context = view.getContext(); isTracking = false; ride_id = getArguments().getStringArray("rideid")[0]; customer_id = getArguments().getStringArray("rideid")[1]; address = getArguments().getStringArray("rideid")[2]; latlng = getArguments().getStringArray("rideid")[3]; car_model = getArguments().getStringArray("rideid")[4]; time = getArguments().getStringArray("rideid")[5]; // username= getArguments().getStringArray("rideid")[6]; username = Customer_Constants.selected_taxi_appname; //jin taxi_company = getArguments().getStringArray("rideid")[7]; // license_plate = getArguments().getStringArray("rideid")[8]; license_plate = Customer_Constants.selected_plate_number; // avatar = getArguments().getStringArray("rideid")[9]; Taxi_System.testLog(address); ArrayList aList = new ArrayList(Arrays.asList(latlng.split(","))); ArrayList d_aList = new ArrayList(Arrays.asList(getArguments().getStringArray("rideid")[12].split(","))); customerLatLng = new LatLng(Double.parseDouble(d_aList.get(0).toString()), Double.parseDouble(d_aList.get(1).toString())); driverLatLng = new LatLng(Double.parseDouble(aList.get(0).toString()), Double.parseDouble(aList.get(1).toString())); if (savedInstanceState == null) initComponents(view); view.setFocusableInTouchMode(true); view.requestFocus(); view.setOnKeyListener(new View.OnKeyListener() { @Override public boolean onKey(View v, int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { if (((Customer_Fragment_Activity) getActivity()).isMenu) { ((Customer_Fragment_Activity) getActivity()).didHideMenu(); return true; } didRejectRide(); ((Customer_Fragment_Activity) getActivity()).didFinish(); return true; } else return false; } }); return view; }
From source file:it.unipr.ce.dsg.gamidroid.activities.BuildingLookupActivity.java
/** * When back button is pressed to get back to the map, stop listening for * the updates related to the building/*from ww w . jav a 2 s . c o m*/ */ @Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { GamiNode.getAndroidGamiNode(mContext).getRfm().stopBuildingNotificationLookup(); onBackPressed(); } return super.onKeyDown(keyCode, event); }
From source file:de.trier.infsec.koch.droidsheep.activities.HijackActivity.java
@Override public boolean onKeyDown(int keyCode, KeyEvent event) { if ((keyCode == KeyEvent.KEYCODE_BACK) && webview.canGoBack()) { webview.goBack();// w ww . j av a 2 s . c om return true; } return super.onKeyDown(keyCode, event); }