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:edu.stanford.mobisocial.dungbeetle.AppFinderActivity.java
@Override public boolean onKeyDown(int keyCode, KeyEvent event) { // Check if the key event was the BACK key and if there's history if ((keyCode == KeyEvent.KEYCODE_BACK) && mWebView.canGoBack()) { mWebView.goBack();/*from w w w. j a va2 s .c om*/ return true; } // If it wasn't the BACK key or there's no web page history, bubble up to the default // system behavior (probably exit the activity) return super.onKeyDown(keyCode, event); }
From source file:com.libreteam.driver.Driver_RideOffer.java
@SuppressLint("InflateParams") @SuppressWarnings({ "unchecked", "rawtypes" }) @Override//from ww w . j ava 2 s . c om public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { super.onCreate(savedInstanceState); View view = inflater.inflate(R.layout.driver_rideoffer, null); context = view.getContext(); ride_id = getArguments().getStringArray("rideid")[0]; customer_id = getArguments().getStringArray("rideid")[1]; address = getArguments().getStringArray("rideid")[2]; latlng = getArguments().getStringArray("rideid")[3]; ArrayList aList = new ArrayList(Arrays.asList(latlng.split(","))); driverLatLng = new LatLng(Driver_Status.getLatitude(), Driver_Status.getLongitude()); customerLatLng = 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 (((Driver_Fragment_Activity) getActivity()).isMenu) { ((Driver_Fragment_Activity) getActivity()).didHideMenu(); return true; } didSendMessage(); ((Driver_Fragment_Activity) getActivity()).didFinish(); return false; } else { return false; } } }); return view; }
From source file:com.zhihuigu.sosoOffice.LoadActivity.java
private void startProgressDialog() { if (progressDialog == null) { progressDialog = CustomProgressDialog.createDialog(this); progressDialog.setMessage("..."); }//from w w w. j a va 2 s . c o m progressDialog.setCanceledOnTouchOutside(false); progressDialog.setOnKeyListener(new OnKeyListener() { public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { return true; } return false; } }); progressDialog.show(); }
From source file:com.blogspot.ksoichiro.android.sample.transition.test.NormalTransitionTest.java
public void testNormalTransition() { // Activity?/*from w w w . j ava2 s. c o m*/ ActivityMonitor monitorMain = new ActivityMonitor(MainActivity.class.getCanonicalName(), null, false); ActivityMonitor monitorSecond = new ActivityMonitor(SecondActivity.class.getCanonicalName(), null, false); getInstrumentation().addMonitor(monitorMain); getInstrumentation().addMonitor(monitorSecond); // ??Fragment?BackStack?????? FragmentActivity activity = (FragmentActivity) getActivity(); FragmentManager fm = activity.getSupportFragmentManager(); assertEquals(0, fm.getBackStackEntryCount()); // ??Fragment? Fragment frag = fm.findFragmentByTag("tag"); assertNotNull(frag); assertEquals(Fragment1.class, frag.getClass()); // ??(Fragment)? TouchUtils.tapView(this, getActivity().findViewById(R.id.btnFrag1)); getInstrumentation().waitForIdleSync(); // BackStack?Fragment???(?)??? assertEquals(1, fm.getBackStackEntryCount()); // ??(Fragment)????? frag = fm.findFragmentByTag("tag"); assertNotNull(frag); assertEquals(Fragment2.class, frag.getClass()); // ??(Activity)? TouchUtils.tapView(this, getActivity().findViewById(R.id.btnFrag2)); getInstrumentation().waitForMonitorWithTimeout(monitorSecond, 2000); // ?Activity??????? assertEquals(1, monitorSecond.getHits()); // ? sendKeys(KeyEvent.KEYCODE_BACK); getInstrumentation().waitForIdleSync(); // ??(Activity)?????? assertEquals(1, monitorMain.getHits()); // ???Fragment?BackStack???????? activity = (FragmentActivity) monitorMain.getLastActivity(); fm = activity.getSupportFragmentManager(); assertEquals(1, fm.getBackStackEntryCount()); frag = fm.findFragmentByTag("tag"); assertNotNull(frag); assertEquals(Fragment2.class, frag.getClass()); // ? sendKeys(KeyEvent.KEYCODE_BACK); getInstrumentation().waitForIdleSync(); // ???Fragment????BackStack????????? assertEquals(0, fm.getBackStackEntryCount()); frag = fm.findFragmentByTag("tag"); assertNotNull(frag); assertEquals(Fragment1.class, frag.getClass()); }
From source file:illab.nabal.proxy.AuthWebDialog.java
/** * Override hardware back key to close this dialog. * //from w w w .j a v a2s. c o m * @deprecated */ public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN) { //Log.d(TAG, "keyCode : " + keyCode + " | event.getAction() : " + event.getAction()); Log.d(TAG, "BACK key has been pressed on WebView"); mNetworkWebViewClient.onCancel(); } return true; }
From source file:com.gotraveling.insthub.BeeFramework.activity.MainActivity.java
@Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { if (isExit == false) { isExit = true;/*from w w w .j a va 2 s . c om*/ Resources resource = (Resources) getBaseContext().getResources(); String exi = resource.getString(R.string.exit); Toast.makeText(getApplicationContext(), exi, Toast.LENGTH_SHORT).show(); handler.sendEmptyMessageDelayed(0, 3000); if (BeeQuery.environment() == BeeQuery.ENVIROMENT_DEVELOPMENT) { BeeFrameworkApp.getInstance().showBug(this); } return true; } else { finish(); return false; } } return true; }
From source file:com.BeeFramework.activity.MainActivity.java
@Override public boolean onKeyDown(int keyCode, KeyEvent event) { // TODO Auto-generated method stub if (keyCode == KeyEvent.KEYCODE_BACK) { if (isExit == false) { isExit = true;/*from w ww . j av a2s.c om*/ Toast.makeText(getApplicationContext(), "?", Toast.LENGTH_SHORT).show(); handler.sendEmptyMessageDelayed(0, 3000); if (BeeQuery.environment() == BeeQuery.ENVIROMENT_DEVELOPMENT) { BeeFrameworkApp.getInstance().showBug(this); } return true; } else { finish(); return false; } } return true; }
From source file:com.github.yuukis.businessmap.app.MainActivity.java
@Override public boolean dispatchKeyEvent(KeyEvent event) { if (event.getAction() == KeyEvent.ACTION_DOWN) { switch (event.getKeyCode()) { case KeyEvent.KEYCODE_BACK: // ?/*www . jav a 2 s .c o m*/ ContactsListFragment listFragment = (ContactsListFragment) getSupportFragmentManager() .findFragmentById(R.id.contacts_list); if (listFragment != null && listFragment.getVisibility()) { // ???????? listFragment.setVisibility(false); return true; } } } return super.dispatchKeyEvent(event); }
From source file:com.tedx.alcatraz.SpeakerResultActivity.java
@Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.ECLAIR && keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) { // Take care of calling this method on earlier versions of // the platform where it doesn't exist. onBackPressed();//from w ww . ja va 2s .c o m } return super.onKeyDown(keyCode, event); }
From source file:org.lol.reddit.fragments.AddAccountDialog.java
@Override public Dialog onCreateDialog(final Bundle savedInstanceState) { if (alreadyCreated) return getDialog(); alreadyCreated = true;//from w ww . j ava 2 s . c o m super.onCreateDialog(savedInstanceState); final Activity activity = getSupportActivity(); final Context appContext = activity.getApplicationContext(); final AlertDialog.Builder builder = new AlertDialog.Builder(activity); builder.setTitle(R.string.accounts_add); final View view = activity.getLayoutInflater().inflate(R.layout.dialog_login); 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(activity); 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(appContext, username, password, new DefaultHttpClient()); General.UI_THREAD_HANDLER.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(activity); alertBuilder.setNeutralButton(R.string.dialog_close, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { new AccountListDialog().show(activity); } }); // TODO handle errors better switch (result.result) { case CONNECTION_ERROR: alertBuilder.setTitle(appContext.getString(R.string.error_connection_title)); alertBuilder.setMessage(appContext.getString(R.string.message_cannotlogin)); break; case INTERNAL_ERROR: alertBuilder.setTitle(appContext.getString(R.string.error_unknown_title)); alertBuilder.setMessage(appContext.getString(R.string.message_cannotlogin)); break; case JSON_ERROR: alertBuilder.setTitle(appContext.getString(R.string.error_parse_title)); alertBuilder.setMessage(appContext.getString(R.string.message_cannotlogin)); break; case REQUEST_ERROR: alertBuilder.setTitle(appContext.getString(R.string.error_connection_title)); alertBuilder.setMessage(appContext.getString(R.string.message_cannotlogin)); break; case UNKNOWN_REDDIT_ERROR: alertBuilder.setTitle(appContext.getString(R.string.error_unknown_title)); alertBuilder.setMessage(appContext.getString(R.string.message_cannotlogin)); break; case WRONG_PASSWORD: alertBuilder .setTitle(appContext.getString(R.string.error_invalid_password_title)); alertBuilder.setMessage( appContext.getString(R.string.error_invalid_password_message)); break; case RATELIMIT: alertBuilder.setTitle(appContext.getString(R.string.error_ratelimit_title)); alertBuilder.setMessage(String.format("%s \"%s\"", appContext.getString(R.string.error_ratelimit_message), result.extraMessage)); break; case SUCCESS: RedditAccountManager.getInstance(appContext).addAccount(result.account); RedditAccountManager.getInstance(appContext).setDefaultAccount(result.account); alertBuilder.setTitle(appContext.getString(R.string.general_success)); alertBuilder.setMessage(appContext.getString(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(); }