List of usage examples for android.app AlertDialog setCanceledOnTouchOutside
public void setCanceledOnTouchOutside(boolean cancel)
From source file:no.barentswatch.fiskinfo.BaseActivity.java
/** * This function creates a pop up dialog which takes in the context of the * current activity//from ww w .j a v a2s . co m * * @param activityContext * the context of the current activity * @param rPathToTitleOfPopup * The R.path to the title * @param customView * the custom view for the dialog */ public void ShowLoginDialog(Context activityContext, int rPathToTitleOfPopup, View customView) { LayoutInflater layoutInflater = getLayoutInflater(); View view = layoutInflater.inflate(R.layout.dialog_login, null); AlertDialog.Builder builder = new AlertDialog.Builder(activityContext); builder.setTitle(rPathToTitleOfPopup); final EditText usernameEditText = (EditText) view.findViewById(R.id.LoginDialogEmailField); final EditText passwordEditText = (EditText) view.findViewById(R.id.loginDialogPasswordField); final TextView incorrectCredentialsTextView = (TextView) view .findViewById(R.id.loginIncorrectCredentialsTextView); Button loginButton = (Button) view.findViewById(R.id.loginDialogButton); Button cancelButton = (Button) view.findViewById(R.id.cancel_login_button); builder.setView(view); final AlertDialog dialog = builder.create(); dialog.setCanceledOnTouchOutside(false); loginButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { if (incorrectCredentialsTextView.getVisibility() == 0) { incorrectCredentialsTextView.setVisibility(android.view.View.INVISIBLE); } if (!isNetworkAvailable()) { incorrectCredentialsTextView.setText(getString(R.string.no_internet_access)); incorrectCredentialsTextView.setVisibility(android.view.View.VISIBLE); return; } String usernameText = usernameEditText.getText().toString(); String passwordText = passwordEditText.getText().toString(); if (!validateEmail(usernameText)) { usernameEditText.requestFocus(); usernameEditText.setError(getString(R.string.login_invalid_email)); return; } usernameEditText.setError(null); if (passwordText.length() == 0) { passwordEditText.requestFocus(); passwordEditText.setError(getString(R.string.login_password_field_empty_string)); return; } passwordEditText.setError(null); try { authenticateUserCredentials(usernameText, passwordText); } catch (Exception e) { e.printStackTrace(); } if (userIsAuthenticated) { loadView(MyPageActivity.class); } else { incorrectCredentialsTextView.setText(getString(R.string.login_incorrect_credentials)); incorrectCredentialsTextView.setVisibility(android.view.View.VISIBLE); return; } } }); cancelButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { dialog.dismiss(); } }); dialog.setOnDismissListener(new DialogInterface.OnDismissListener() { @Override public void onDismiss(DialogInterface dialog) { // TODO Auto-generated method stub actionBar.setSelectedNavigationItem(adapter.getCount()); } }); dialog.show(); }
From source file:no.barentswatch.fiskinfo.BaseActivity.java
/** * This function creates a dialog which gives a description of the symbols * that populate the map.//from w ww . ja v a2 s. com * * @param ActivityContext * The context of the current activity. */ public void displaySymbolExplanation(Context ActivityContext) { LayoutInflater layoutInflater = getLayoutInflater(); View view = layoutInflater.inflate(R.layout.symbol_explanation, (null)); final AlertDialog builder = new AlertDialog.Builder(ActivityContext).create(); builder.setTitle(R.string.map_symbol_explanation); builder.setCanceledOnTouchOutside(false); builder.setView(view); Button okButton = (Button) view.findViewById(R.id.symbolOkButton); okButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { builder.dismiss(); } }); builder.show(); }
From source file:de.tum.frm2.nicos_android.gui.MainActivity.java
@Override public void handleSignal(String signal, Object data, Object args) { switch (signal) { case "broken": final String error = (String) data; // Connection is broken. Try to disconnect what's left and go back to login screen. NicosClient.getClient().unregisterCallbackHandler(this); NicosClient.getClient().disconnect(); if (!_visible) return; // Activity is still visible, user probably didn't intend to shut down connection. // We display an error. runOnUiThread(new Runnable() { @Override//from www .j a v a2 s .c o m public void run() { AlertDialog alertDialog; try { alertDialog = new AlertDialog.Builder(MainActivity.this).create(); alertDialog.setTitle("Disconnected"); alertDialog.setMessage(error); alertDialog.setButton(AlertDialog.BUTTON_NEGATIVE, "Okay", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); finish(); } }); alertDialog.setCancelable(false); alertDialog.setCanceledOnTouchOutside(false); alertDialog.show(); } catch (Exception e) { try { finish(); } catch (Exception e2) { // User probably quit the application. } // Activity isn't running anymore // (user probably put application in background). } } }); break; case "cache": on_client_cache((Object[]) data); break; case "status": // data = tuple of (status, linenumber) _current_status = (int) ((Object[]) data)[0]; break; case "message": final ArrayList msgList = (ArrayList) data; if ((int) msgList.get(2) == NicosMessageLevel.ERROR) { runOnUiThread(new Runnable() { @Override public void run() { Toast.makeText(getApplicationContext(), NicosMessageLevel.level2name(NicosMessageLevel.ERROR) + ": " + msgList.get(3), Toast.LENGTH_SHORT).show(); } }); } break; case "error": final String msg = (String) data; runOnUiThread(new Runnable() { @Override public void run() { Toast.makeText(getApplicationContext(), msg, Toast.LENGTH_SHORT).show(); } }); break; } }
From source file:com.happysanta.vkspy.Fragments.MainFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { context = getActivity();//from w w w. j a v a 2 s . com if (savedInstanceState != null && UberFunktion.loading) { ProgressDialog dialog = new ProgressDialog(context); dialog.setMessage(context.getString(R.string.durov_function_activating_message)); UberFunktion.putNewDialogWindow(dialog); dialog.show(); } View rootView = inflater.inflate(R.layout.fragment_main, null); View happySanta = inflater.inflate(R.layout.main_santa, null); TextView happySantaText = (TextView) happySanta.findViewById(R.id.happySantaText); happySantaText.setText(Html.fromHtml(context.getString(R.string.app_description))); TextView happySantaLink = (TextView) happySanta.findViewById(R.id.happySantaLink); happySantaLink.setText(Html.fromHtml("vk.com/<b>happysanta</b>")); happySantaLink.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://vk.com/happysanta")); startActivity(browserIntent); } }); happySanta.setOnClickListener(new View.OnClickListener() { int i = 1; @Override public void onClick(View v) { if (i < 10) i++; else { i = 0; File F = Logs.getFile(); Uri U = Uri.fromFile(F); Intent i = new Intent(Intent.ACTION_SEND); i.setType("text/plain"); i.putExtra(Intent.EXTRA_STREAM, U); startActivity(Intent.createChooser(i, "What should we do with logs?")); } } }); SharedPreferences longpollPreferences = context.getSharedPreferences("longpoll", Context.MODE_MULTI_PROCESS); boolean longpollStatus = longpollPreferences.getBoolean("status", true); /*Bitmap tile = BitmapFactory.decodeResource(context.getResources(), R.drawable.underline); BitmapDrawable tiledBitmapDrawable = new BitmapDrawable(context.getResources(), tile); tiledBitmapDrawable.setTileModeX(Shader.TileMode.REPEAT); //tiledBitmapDrawable.setTileModeY(Shader.TileMode.REPEAT); santaGroundView.setBackgroundDrawable(tiledBitmapDrawable); BitmapDrawable bitmap = new BitmapDrawable(BitmapFactory.decodeResource( getResources(), R.drawable.underline2)); bitmap.setTileModeX(Shader.TileMode.REPEAT); */ LinearLayout layout = (LinearLayout) happySanta.findViewById(R.id.line); Display display = ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay(); int width = display.getWidth(); // deprecated for (int i = 0; width % (341 * i + 1) < width; i++) { layout.addView(new ImageView(context) { { setImageResource(R.drawable.underline2); setLayoutParams(new ViewGroup.LayoutParams(341, Helper.convertToDp(4))); setScaleType(ScaleType.CENTER_CROP); } }); } ListView preferencesView = (ListView) rootView.findViewById(R.id.preference); preferencesView.addHeaderView(happySanta, null, false); ArrayList<PreferenceItem> preferences = new ArrayList<PreferenceItem>(); /* preferences.add(new PreferenceItem(getUberfunction(), getUberfunctionDescription()) { @Override public void onClick() { if(UberFunktion.loading) { ProgressDialog dialog = new ProgressDialog(context); dialog.setMessage(context.getString(R.string.durov_function_activating_message)); UberFunktion.putNewDialogWindow(dialog); dialog.show(); return; } AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); final AlertDialog selector; View durov = getActivity().getLayoutInflater().inflate(R.layout.durov, null); SharedPreferences durovPreferences = context.getSharedPreferences("durov", Context.MODE_MULTI_PROCESS); boolean updateOnly = durovPreferences.getBoolean("loaded", false); if(updateOnly) ((TextView)durov.findViewById(R.id.description)).setText(R.string.durov_function_activated); if(Memory.users.getById(1)!=null && !updateOnly) { builder.setTitle(R.string.durov_joke_title); ((TextView)durov.findViewById(R.id.description)).setText(R.string.durov_joke_message); ( durov.findViewById(R.id.cat)).setVisibility(View.VISIBLE); builder.setNegativeButton(R.string.durov_joke_button, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { BugSenseHandler.sendEvent("? ? "); } }); BugSenseHandler.sendEvent("DUROV FRIEND CATCHED!!1"); }else{ builder.setTitle(R.string.durov_start_title); ( durov.findViewById(R.id.photo)).setVisibility(View.VISIBLE); ImageLoader.getInstance().displayImage("http://cs9591.vk.me/v9591001/70/VPSmUR954fQ.jpg",(ImageView) durov.findViewById(R.id.photo)); builder. setPositiveButton(updateOnly ? R.string.durov_start_update : R.string.durov_start_ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { BugSenseHandler.sendEvent(" "); ProgressDialog uberfunctionDialog = ProgressDialog.show(getActivity(), context.getString(R.string.durov_function_activating_title), context.getString(R.string.durov_function_activating_message), true, false); UberFunktion.initialize(uberfunctionDialog); } }); builder.setNegativeButton(R.string.durov_start_cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { try { Intent browserIntent = new Intent( Intent.ACTION_VIEW, Uri.parse("https://vk.com/id1") ); startActivity(browserIntent); }catch(Exception exp){ AlertDialog.Builder errorShower = new AlertDialog.Builder(getActivity()); if (exp instanceof ActivityNotFoundException) { errorShower.setTitle(R.string.error); errorShower.setMessage(R.string.no_browser); } else { errorShower.setTitle(R.string.error); errorShower.setMessage(R.string.unknown_error); } errorShower.show(); } BugSenseHandler.sendEvent("? ? "); } }); } builder.setView(durov); selector = builder.create(); selector.show(); } }); */ preferences.add(new ToggleablePreferenceItem(getEnableSpy(), null, longpollStatus) { @Override public void onToggle(Boolean isChecked) { longpollToggle(isChecked); } }); preferences.add(new PreferenceItem(getAdvancedSettings()) { @Override public void onClick() { startActivity(new Intent(context, SettingsActivity.class)); } }); preferences.add(new PreferenceItem(getAbout()) { @Override public void onClick() { AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); final AlertDialog aboutDialog; builder.setTitle(R.string.app_about).setCancelable(true) .setPositiveButton(R.string.app_about_button, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { } }); View aboutView = getActivity().getLayoutInflater().inflate(R.layout.about, null); TextView aboutDescription = (TextView) aboutView.findViewById(R.id.description); aboutDescription.setText(Html.fromHtml(getResources().getString(R.string.app_about_description))); aboutDescription.setMovementMethod(LinkMovementMethod.getInstance()); aboutView.findViewById(R.id.license).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent browserIntent = new Intent(context, InfoActivity.class); startActivity(browserIntent); } }); builder.setView(aboutView); aboutDialog = builder.create(); aboutDialog.setCanceledOnTouchOutside(true); aboutDialog.show(); } }); preferencesView.setAdapter(new PreferenceAdapter(context, preferences)); return rootView; }
From source file:emu.project64.GalleryActivity.java
public void ShowSupportWindow() { final Context context = this; final Activity activity = this; AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle(getText(R.string.GetSaveSupport_title)); builder.setMessage(getText(R.string.GetSaveSupport_message)); builder.setNeutralButton("Not now", null); builder.setNegativeButton("Support Project64", null); builder.setCancelable(false);// w w w.jav a2 s . c om final AlertDialog dialog = builder.create(); dialog.show(); dialog.getButton(AlertDialog.BUTTON_NEUTRAL).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { dialog.dismiss(); StartGameMenu(false); } }); dialog.getButton(AlertDialog.BUTTON_NEGATIVE).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { setWaitScreen(true); //Purchase save support try { String payload = NativeExports.appVersion(); mIabHelper.launchPurchaseFlow(activity, SKU_SAVESUPPORT, RC_REQUEST, mPurchaseFinishedListener, payload); } catch (IabAsyncInProgressException e) { setWaitScreen(false); } dialog.dismiss(); } }); dialog.setCanceledOnTouchOutside(false); }
From source file:com.mrchandler.disableprox.ui.TaskerSensorSettingsActivity.java
private void initInAppBilling() { final IabHelper helper = new IabHelper(this, getString(R.string.google_billing_public_key)); //Has the user purchased the Tasker IAP? if (!ProUtil.isPro(this)) { helper.startSetup(new IabHelper.OnIabSetupFinishedListener() { @Override/*from w ww.j a va 2 s. c om*/ public void onIabSetupFinished(IabResult result) { if (result.isFailure()) { Log.d(TAG, "Unable to get up In-App Billing. Oh well."); return; } helper.queryInventoryAsync(new IabHelper.QueryInventoryFinishedListener() { @Override public void onQueryInventoryFinished(IabResult result, Inventory inv) { if (result.isFailure()) { ProUtil.setProStatus(TaskerSensorSettingsActivity.this, false); return; } if (inv.hasPurchase(Constants.SKU_TASKER)) { ProUtil.setProStatus(TaskerSensorSettingsActivity.this, true); } else { ProUtil.setProStatus(TaskerSensorSettingsActivity.this, false); if (!ProUtil.isFreeloaded(TaskerSensorSettingsActivity.this)) { AlertDialog dialog = new AlertDialog.Builder(TaskerSensorSettingsActivity.this) .setTitle(R.string.iap_dialog_title) .setMessage(R.string.iap_dialog_message) .setNegativeButton("Not Right Now", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { doNotSave = true; finish(); } }) .setPositiveButton("Yes", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { helper.launchPurchaseFlow(TaskerSensorSettingsActivity.this, Constants.SKU_TASKER, PURCHASE_RESULT_CODE, new IabHelper.OnIabPurchaseFinishedListener() { @Override public void onIabPurchaseFinished(IabResult result, Purchase info) { if (result.isFailure()) { Toast.makeText( TaskerSensorSettingsActivity.this, "Error getting purchase details.", Toast.LENGTH_SHORT).show(); doNotSave = true; finish(); return; } if (info.getSku() .equals(Constants.SKU_TASKER)) { ProUtil.setProStatus( TaskerSensorSettingsActivity.this, true); } } }); } }).setNeutralButton("More Information", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { AlertDialog oldDialog = (AlertDialog) dialog; oldDialog.dismiss(); AlertDialog newDialog = new AlertDialog.Builder( TaskerSensorSettingsActivity.this).setTitle( getString(R.string.iap_dialog_title)) .setMessage(getString( R.string.iap_dialog_more_information)) .setOnCancelListener( new DialogInterface.OnCancelListener() { @Override public void onCancel( DialogInterface dialog) { doNotSave = true; finish(); } }) .setCancelable(true).create(); newDialog.setCanceledOnTouchOutside(true); newDialog.show(); } }) .setOnCancelListener(new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { doNotSave = true; finish(); } }).setCancelable(true).create(); dialog.setCanceledOnTouchOutside(true); dialog.show(); } } } }); } }); } }
From source file:com.romanenco.gitt.BrowserActivity.java
/** * When pull from origin there are several case. * 1. We are in TAG (detached head): will inform user to * checkout a branch first./* w w w. jav a2 s .co m*/ * 2. Authentication required: ask for password (no passwd save). * 3. Anonymous user: just poll. */ private void pullFromOrigin() { if (current.getUserName() == null) { //no authentication required current.setState(Repo.State.Busy); DAO dao = new DAO(BrowserActivity.this); dao.open(true); dao.update(current); dao.close(); Intent pull = new Intent(this, GitService.class); pull.putExtra(GitService.COMMAND, GitService.Command.Pull); pull.putExtra(GitService.REPO, current); startService(pull); Intent main = new Intent(this, MainActivity.class); main.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(main); } else { String req = getString(R.string.passwd_request, current.getUserName()); final EditText passwd = new EditText(this); passwd.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD); AlertDialog dlg = new AlertDialog.Builder(this).setMessage(req) .setPositiveButton(getString(android.R.string.ok), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { String password = passwd.getText().toString(); if (TextUtils.isEmpty(password)) { pullFromOrigin(); } else { current.setState(Repo.State.Busy); DAO dao = new DAO(BrowserActivity.this); dao.open(true); dao.update(current); dao.close(); Intent pull = new Intent(BrowserActivity.this, GitService.class); pull.putExtra(GitService.COMMAND, GitService.Command.Pull); pull.putExtra(GitService.REPO, current); pull.putExtra(GitService.AUTH_PASSWD, password); startService(pull); Intent main = new Intent(BrowserActivity.this, MainActivity.class); main.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(main); } } }).setNegativeButton(getString(android.R.string.cancel), null).create(); dlg.setCanceledOnTouchOutside(false); dlg.setView(passwd); dlg.show(); } }
From source file:com.mishiranu.dashchan.ui.navigator.NavigatorActivity.java
private void showRestartDialogIfNeeded() { if (ChanManager.getInstance().checkNewExtensionsInstalled() && mayShowRestartDialog) { mayShowRestartDialog = false;// www . j ava 2 s .com AlertDialog dialog = new AlertDialog.Builder(this).setMessage(R.string.message_packages_installed) .setPositiveButton(R.string.action_restart, (d, which) -> { Bundle outState = new Bundle(); writePagesState(outState); pageManager.writeToStorage(outState); NavigationUtils.restartApplication(this); }).setNegativeButton(android.R.string.cancel, null).create(); dialog.setOnDismissListener(d -> mayShowRestartDialog = true); dialog.setCanceledOnTouchOutside(false); dialog.show(); uiManager.dialog().notifySwitchBackground(); } }
From source file:com.android.cabapp.fragments.MyAccountFragment.java
void LogOutDialog() { final AlertDialog logOutDialog = new AlertDialog.Builder(mContext).setTitle("Logout") .setMessage("Are you sure you want to logout?") .setNegativeButton("Yes", new DialogInterface.OnClickListener() { @Override/*from w w w .ja va2s . c o m*/ public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated if (NetworkUtil.isNetworkOn(Util.mContext)) { LogOutTask logoutTask = new LogOutTask(); logoutTask.execute(); } else { Util.showToastMessage(getActivity(), getResources().getString(R.string.no_network_error), Toast.LENGTH_LONG); } } }).setPositiveButton("No", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface argDialog, int argWhich) { // TODO Auto-generated } }).create(); logOutDialog.setCanceledOnTouchOutside(false); logOutDialog.show(); }
From source file:no.barentswatch.fiskinfo.BaseActivity.java
/** * Displays a dialog which informs the user of polar low information in their current position. *///from w ww .ja v a 2 s.co m public void showPolarLowDialog() { boolean success = false; GpsLocationTracker mGpsLocationTracker = new GpsLocationTracker(getContext()); double latitude, longitude = 0; if (mGpsLocationTracker.canGetLocation()) { latitude = mGpsLocationTracker.getLatitude(); longitude = mGpsLocationTracker.getLongitude(); System.out.println("This is lat: " + latitude + "\nThis is lon: " + longitude); } else { mGpsLocationTracker.showSettingsAlert(); return; } // TODO: add polar low API call using current position here. AlertDialog.Builder builder = new AlertDialog.Builder(getContext()); AlertDialog dialog; builder.setTitle(R.string.polar_low); if (success) { // TODO: add results from API call here. builder.setMessage(getText(R.string.check_polar_low_info) + ""); } else { builder.setMessage(R.string.check_polar_low_error); } builder.setPositiveButton("OK", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); dialog = builder.create(); dialog.show(); dialog.setCanceledOnTouchOutside(false); }