List of usage examples for android.app AlertDialog show
public void show()
From source file:org.openhab.habdroid.ui.OpenHABRoomSettingActivity.java
private void showAlertDialog(String alertMessage) { AlertDialog.Builder builder = new AlertDialog.Builder(OpenHABRoomSettingActivity.this); builder.setMessage(alertMessage).setPositiveButton("OK", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { }/*from w w w . ja v a 2 s. c o m*/ }); AlertDialog alert = builder.create(); alert.show(); }
From source file:abanoubm.dayra.main.Main.java
private void register() { LayoutInflater li = LayoutInflater.from(getApplicationContext()); final View view = li.inflate(R.layout.dialogue_create, null, false); final AlertDialog ad = new AlertDialog.Builder(Main.this).setCancelable(true).create(); ad.setView(view, 0, 0, 0, 0);// w w w . j a v a 2s.c o m ad.show(); view.findViewById(R.id.yesBtn).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { String str = ((EditText) view.findViewById(R.id.input)).getText().toString().trim(); if (Utility.isInvlaidDBName(str)) { Toast.makeText(getApplicationContext(), R.string.err_msg_dayra_name, Toast.LENGTH_SHORT).show(); } else { if (DB.isDBExists(getApplicationContext(), str)) { Toast.makeText(getApplicationContext(), R.string.err_msg_duplicate_dayra, Toast.LENGTH_SHORT).show(); } else { new RegisterTask().execute(str); ad.dismiss(); } } } }); }
From source file:info.snowhow.plugin.RecorderService.java
private void showNoGPSAlert() { Log.i(LOG_TAG, "No GPS available --- show Dialog"); AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this); alertDialogBuilder.setMessage("GPS is disabled on your device. Would you like to enable it?") .setCancelable(false).setPositiveButton("GPS Settings", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { Intent callGPSSettingIntent = new Intent( android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS); callGPSSettingIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(callGPSSettingIntent); }/*from ww w . ja v a 2 s . com*/ }); alertDialogBuilder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { stopRecording(); dialog.cancel(); } }); AlertDialog alert = alertDialogBuilder.create(); alert.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT); alert.show(); }
From source file:de.da_sense.moses.client.service.MosesService.java
/** * This function will be executed on first run and shows some welcome * dialog./*from w w w .ja va2 s . co m*/ * * @param context * The context under which the dialog is shown. */ private void showWelcomeDialog(final Context context) { AlertDialog.Builder builder = new AlertDialog.Builder(context); builder.setIcon(R.drawable.ic_launcher); builder.setCancelable(false); // This blocks the 'BACK' button builder.setMessage(getString(R.string.welcome_to_moses_string)); builder.setTitle(getString(R.string.welcome_to_moses_title_string)); builder.setNegativeButton("OK", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); AlertDialog alert = builder.create(); alert.show(); Log.d("MoSeS.SERVICE", "First login."); PreferenceManager.getDefaultSharedPreferences(this).edit().putBoolean("first_start", false).commit(); }
From source file:com.njlabs.amrita.aid.landing.Landing.java
public void checkForUpdates() { OkHttpClient client = new OkHttpClient.Builder().followRedirects(true).followSslRedirects(true).build(); Request.Builder request = new Request.Builder().url("https://api.codezero.xyz/aid/latest"); client.newCall(request.build()).enqueue(new Callback() { @Override//w w w .ja va 2s . c o m public void onFailure(Call call, IOException e) { Ln.e(e); } @Override public void onResponse(Call call, final Response rawResponse) throws IOException { final String responseString = rawResponse.body().string(); ((Activity) baseContext).runOnUiThread(new Runnable() { @Override public void run() { JSONObject response; try { response = new JSONObject(responseString); String status = ""; status = response.getString("status"); if (status.equals("ok")) { Double Latest = 0.0; String Description = null; try { Latest = response.getDouble("version"); Description = response.getString("description"); } catch (JSONException e) { FirebaseCrash.report(e); } if (Latest > BuildConfig.VERSION_CODE) { AlertDialog.Builder updateDialogBuilder = new AlertDialog.Builder(Landing.this); LayoutInflater factory = LayoutInflater.from(Landing.this); final View changelogView = factory.inflate(R.layout.webview_dialog, null); LinearLayout WebViewDialogLayout = (LinearLayout) changelogView .findViewById(R.id.WebViewDialogLayout); WebViewDialogLayout.setPadding(5, 5, 5, 5); WebView changelogWebView = (WebView) changelogView .findViewById(R.id.LicensesView); changelogWebView.loadData(String.format("%s", Description), "text/html", "utf-8"); changelogWebView.setPadding(5, 5, 5, 5); changelogWebView.setBackgroundColor(0); changelogWebView.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View v) { return true; } }); changelogWebView.setLongClickable(false); updateDialogBuilder.setView(changelogView).setCancelable(true) .setCancelable(false) .setNegativeButton("Dismiss", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }) .setPositiveButton("Update Now", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { Uri uri = Uri .parse("market://details?id=com.njlabs.amrita.aid"); Intent it = new Intent(Intent.ACTION_VIEW, uri); startActivity(it); } }); AlertDialog alert = updateDialogBuilder.create(); alert.setTitle("Update Available"); alert.setIcon(R.mipmap.ic_launcher); alert.show(); } } } catch (Exception e) { Ln.e(e); } } }); } }); }
From source file:de.baumann.hhsmoodle.activities.Activity_todo.java
private void setupListViewListener() { lvItems.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { @Override//w w w . ja v a 2 s .co m public boolean onItemLongClick(AdapterView<?> adapter, View item, final int pos, long id) { final String text = (String) adapter.getItemAtPosition(pos); // Remove the item within array at position items.remove(pos); // Refresh the adapter itemsAdapter.notifyDataSetChanged(); // Return true consumes the long click event (marks it handled) writeItems(); Snackbar snackbar = Snackbar.make(lvItems, R.string.todo_removed, Snackbar.LENGTH_LONG) .setAction(R.string.todo_removed_back, new View.OnClickListener() { @Override public void onClick(View view) { items.add(pos, text); // Refresh the adapter itemsAdapter.notifyDataSetChanged(); // Return true consumes the long click event (marks it handled) writeItems(); } }); snackbar.show(); return true; } }); lvItems.setOnItemClickListener(new AdapterView.OnItemClickListener() { public void onItemClick(AdapterView<?> adapter, View item, final int pos, long id) { AlertDialog.Builder builder = new AlertDialog.Builder(Activity_todo.this); View dialogView = View.inflate(Activity_todo.this, R.layout.dialog_edit_text_singleline, null); final EditText edit_title = (EditText) dialogView.findViewById(R.id.pass_title); ImageButton ib_paste = (ImageButton) dialogView.findViewById(R.id.imageButtonPaste); ib_paste.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { final CharSequence[] options = { getString(R.string.paste_date), getString(R.string.paste_time) }; new android.app.AlertDialog.Builder(Activity_todo.this) .setPositiveButton(R.string.toast_cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.dismiss(); } }).setItems(options, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int item) { if (options[item].equals(getString(R.string.paste_date))) { Date date = new Date(); SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault()); String dateNow = format.format(date); edit_title.getText().insert(edit_title.getSelectionStart(), dateNow); } if (options[item].equals(getString(R.string.paste_time))) { Date date = new Date(); SimpleDateFormat format = new SimpleDateFormat("HH:mm", Locale.getDefault()); String timeNow = format.format(date); edit_title.getText().insert(edit_title.getSelectionStart(), timeNow); } } }).show(); } }); String text = (String) adapter.getItemAtPosition(pos); edit_title.setText(text); builder.setView(dialogView); builder.setTitle(R.string.number_edit_entry); builder.setPositiveButton(R.string.toast_yes, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { String inputTag = edit_title.getText().toString().trim(); // Remove the item within array at position items.remove(pos); items.add(pos, inputTag); // Refresh the adapter itemsAdapter.notifyDataSetChanged(); // Return true consumes the long click event (marks it handled) writeItems(); } }); builder.setNegativeButton(R.string.toast_cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.cancel(); } }); final AlertDialog dialog2 = builder.create(); // Display the custom alert dialog on interface dialog2.show(); helper_main.showKeyboard(Activity_todo.this, edit_title); } }); }
From source file:net.reichholf.dreamdroid.activities.ServiceListActivity.java
@Override protected void onListItemClick(ListView l, View v, int position, long id) { mCurrentItem = mMapList.get(position); final String ref = mCurrentItem.getString(Event.SERVICE_REFERENCE); final String nam = mCurrentItem.getString(Event.SERVICE_NAME); final String title = mCurrentItem.getString(Event.EVENT_TITLE); if (isBouquetReference(ref)) { if (!isListTaskRunning()) { mIsBouquetList = true;//from ww w. j a v a2s . com // Second hierarchy level -> we get a List of Services now if (isBouquetReference(mReference)) { mIsBouquetList = false; } ExtendedHashMap map = new ExtendedHashMap(); map.put(Event.SERVICE_REFERENCE, String.valueOf(mReference)); map.put(Event.SERVICE_NAME, String.valueOf(mName)); mHistory.add(map); mReference = ref; mName = nam; reload(); } else { showToast(getText(R.string.wait_request_finished)); } } else { if (mPickMode) { ExtendedHashMap map = new ExtendedHashMap(); map.put(Event.SERVICE_REFERENCE, ref); map.put(Event.SERVICE_NAME, nam); Intent intent = new Intent(); intent.putExtra(sData, map); setResult(RESULT_OK, intent); finish(); } else { CharSequence[] actions = { getText(R.string.current_event), getText(R.string.browse_epg), getText(R.string.zap), getText(R.string.similar), getText(R.string.stream) }; AlertDialog.Builder adBuilder = new AlertDialog.Builder(this); adBuilder.setTitle(getText(R.string.pick_action)); adBuilder.setItems(actions, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { switch (which) { case 0: removeDialog(DIALOG_EPG_ITEM_ID); showDialog(DIALOG_EPG_ITEM_ID); break; case 1: openEpg(ref, nam); break; case 2: zapTo(ref); break; case 3: openSimilar(title); break; case 4: streamService(ref); break; } } }); AlertDialog alert = adBuilder.create(); alert.show(); } } }
From source file:org.xbmc.android.remote.presentation.controller.AbstractController.java
public void onWrongConnectionState(int state, final INotifiableManager manager, final Command<?> source) { final AlertDialog.Builder builder = new AlertDialog.Builder(mActivity); switch (state) { case WifiHelper.WIFI_STATE_DISABLED: builder.setTitle("Wifi disabled"); builder.setMessage("This host is Wifi only. Should I activate Wifi?"); builder.setNeutralButton("Activate Wifi", new OnClickListener() { public void onClick(DialogInterface dialog, int which) { final ProgressDialog pd = new ProgressDialog(mActivity); pd.setCancelable(true);//from w ww. j ava 2 s . c om pd.setTitle("Activating Wifi"); pd.setMessage("Please wait while Wifi is activated."); pd.show(); (new Thread() { public void run() { final WifiHelper helper = WifiHelper.getInstance(mActivity); helper.enableWifi(true); int wait = 0; while (wait <= MAX_WAIT_FOR_WIFI * 1000 && helper.getWifiState() != WifiHelper.WIFI_STATE_ENABLED) { try { sleep(500); wait += 500; } catch (InterruptedException e) { } } manager.retryAll(); pd.cancel(); mDialogShowing = false; } }).start(); } }); showDialog(builder); break; case WifiHelper.WIFI_STATE_ENABLED: final Host host = HostFactory.host; final WifiHelper helper = WifiHelper.getInstance(mActivity); final String msg; if (host != null && host.access_point != null && !host.access_point.equals("")) { helper.connect(host); msg = "Connecting to " + host.access_point + ". Please wait"; } else { msg = "Waiting for Wifi to connect to your LAN."; } final ProgressDialog pd = new ProgressDialog(mActivity); pd.setCancelable(true); pd.setTitle("Connecting"); pd.setMessage(msg); mWaitForWifi = new Thread() { public void run() { mDialogShowing = true; pd.show(); (new Thread() { public void run() { int wait = 0; while (wait <= MAX_WAIT_FOR_WIFI * 1000 && helper.getWifiState() != WifiHelper.WIFI_STATE_CONNECTED) { try { sleep(500); wait += 500; } catch (InterruptedException e) { } } pd.cancel(); mDialogShowing = false; } }).start(); pd.setOnDismissListener(new OnDismissListener() { public void onDismiss(DialogInterface dialog) { if (helper.getWifiState() != WifiHelper.WIFI_STATE_CONNECTED) { builder.setTitle("Wifi doesn't seem to connect"); builder.setMessage( "You can open the Wifi settings or wait " + MAX_WAIT_FOR_WIFI + " seconds"); builder.setNeutralButton("Wifi Settings", new OnClickListener() { public void onClick(DialogInterface dialog, int which) { mDialogShowing = false; mActivity.startActivity(new Intent(WifiManager.ACTION_PICK_WIFI_NETWORK)); } }); builder.setCancelable(true); builder.setNegativeButton("Wait", new OnClickListener() { public void onClick(DialogInterface dialog, int which) { mDialogShowing = false; mActivity.runOnUiThread(mWaitForWifi); //had to make the Thread a field because of this line } }); mActivity.runOnUiThread(new Runnable() { public void run() { final AlertDialog alert = builder.create(); try { if (!mDialogShowing) { alert.show(); mDialogShowing = true; } } catch (Exception e) { e.printStackTrace(); } } }); } } }); } }; mActivity.runOnUiThread(mWaitForWifi); } }
From source file:com.cypress.cysmart.RDKEmulatorView.MicrophoneEmulatorFragment.java
/** * Method to display a custom alert./*from w w w . jav a 2s. c om*/ * Option for entering the google key in the method for voice to * text conversion */ private void showCustumAlert(String storedKey, boolean changeNeeded) { LayoutInflater li = LayoutInflater.from(getActivity()); View promptsView = li.inflate(R.layout.api_key_dialog_alert, null); AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(getActivity()); // set api_key_dialog_alert.xml to alertdialog builder alertDialogBuilder.setView(promptsView); //User input Edittext final EditText userInput = (EditText) promptsView.findViewById(R.id.custom_alert_user_input); if (changeNeeded) { userInput.setText(storedKey); } // set dialog message alertDialogBuilder.setCancelable(false).setPositiveButton("OK", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { // get user input and set it to sharedpreferecne Logger.i("userInput.getText()--->" + userInput.getText()); Utils.setStringSharedPreference(getActivity(), Constants.PREF_GOOGLE_API_KEY, userInput.getText().toString()); } }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }); // create alert dialog AlertDialog alertDialog = alertDialogBuilder.create(); // show it alertDialog.show(); }
From source file:abanoubm.dayra.main.Main.java
private void sign() { String inpath;/*from www . j a va2s.c om*/ if (android.os.Build.VERSION.SDK_INT >= 17) { inpath = getApplicationContext().getApplicationInfo().dataDir + "/databases/"; } else { inpath = "/data/data/" + getApplicationContext().getPackageName() + "/databases/"; } File folder = new File(inpath); File[] listOfFiles = folder.listFiles(); if (listOfFiles == null || listOfFiles.length == 0) { Toast.makeText(getApplicationContext(), R.string.msg_no_dayra, Toast.LENGTH_SHORT).show(); } else { ArrayList<String> names = new ArrayList<>(listOfFiles.length); for (File file : listOfFiles) { if (!file.getName().contains("journal")) names.add(file.getName()); } LayoutInflater li = LayoutInflater.from(getApplicationContext()); View signView = li.inflate(R.layout.dialogue_signin, null, false); final AlertDialog ad = new AlertDialog.Builder(Main.this).setCancelable(true).create(); ad.setView(signView, 0, 0, 0, 0); ad.show(); ListView nameslv = (ListView) signView.findViewById(R.id.databases_lv); nameslv.setAdapter(new ArrayAdapter<>(getApplicationContext(), R.layout.item_string, R.id.item, names)); nameslv.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { String str = (String) parent.getItemAtPosition(position); new SignTask().execute(str); ad.dismiss(); } }); } }