List of usage examples for android.app AlertDialog.Builder create
public void create()
From source file:com.nbos.phonebook.sync.authenticator.AuthenticatorActivity.java
void createAccountWithFbId() { mPrefs = getPreferences(MODE_PRIVATE); SharedPreferences.Editor editor = mPrefs.edit(); editor.putString("access_token", facebook.getAccessToken()); editor.putLong("access_expires", facebook.getAccessExpires()); editor.commit();/*from www .j a v a 2s . c o m*/ String access_token = mPrefs.getString("access_token", null); long expires = mPrefs.getLong("access_expires", 0); if (access_token != null) { facebook.setAccessToken(access_token); } if (expires != 0) { facebook.setAccessExpires(expires); } /* * Only call authorize if the access_token has expired. */ if (facebook.isSessionValid()) { Log.i(tag, "Session is valid"); JSONObject json; try { json = Util.parseJson(facebook.request("me", new Bundle())); Log.i(tag, "json: " + json); fbId = json.getString("id"); String username = json.getString("id"); JSONArray existingUser = new Cloud(getApplicationContext(), fbId, null).findExistingFbUser(fbId, countryCode + mPhone); Log.i(tag, "existingUser: " + existingUser.getString(0)); LayoutInflater factory = LayoutInflater.from(this); textEntryView = factory.inflate(R.layout.facebook_email_layout, null); TextView fbUsername = (TextView) textEntryView.findViewById(R.id.facebookLogin_email); TextView fbPassword = (TextView) textEntryView.findViewById(R.id.facebookLogin_password); Button fbAccountButton = (Button) textEntryView.findViewById(R.id.facebookLogin); if (existingUser.getString(0).trim().length() == 0) { Log.i(tag, "email: " + Text.isEmail(username)); if (!(Text.isEmail(username))) { AlertDialog.Builder newBuilder = new AlertDialog.Builder(this); newBuilder.setTitle("FbLogin to Phonebook"); newBuilder.setView(textEntryView); Button existingFbAccount = (Button) textEntryView .findViewById(R.id.existingAccountfacebookLogin); existingFbAccount.setVisibility(View.GONE); AlertDialog newAlert = newBuilder.create(); newAlert.show(); } } else { fbAccountButton.setVisibility(View.GONE); fbUsername.setText(existingUser.getString(0)); fbUsername.setEnabled(false); fbPassword.requestFocus(); AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle("FbLogin to Phonebook"); builder.setView(textEntryView); AlertDialog alert = builder.create(); alert.show(); } //mPhone = mPhoneEdit.getText().toString(); //new Cloud(getApplicationContext(), userId, userId).loginWithFacebook(countryCode + mPhone); /*mUsername = userName; mPassword = userId;*/ //finishLogin(); // mUsernameEdit.setText(userName); // mPasswordEdit.setText(userId); Log.i(tag, "userName: " + username + " userId: " + fbId); Log.i(tag, "response:" + json); } catch (Exception e1) { Log.e(tag, "Exception logging on with Facebook: " + e1); e1.printStackTrace(); } catch (FacebookError e) { Log.e(tag, "Facebook error logging on with Facebook: " + e); e.printStackTrace(); } } }
From source file:ota.otaupdates.MainActivity.java
private void allow_write_sd() { AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle(getString(R.string.write_access)); builder.setMessage(getString(R.string.write_access_message)); builder.setPositiveButton(getString(R.string.button_ok), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { if (Build.VERSION.SDK_INT >= 23 && !checkPermission()) { // If user hasn't allowed yet, request the permission. requestPermission();//from w w w . j a v a 2s .c o m } } }); AlertDialog alert = builder.create(); alert.setCancelable(false); if (!checkPermission()) { // If user hasn't allowed yet, show requester dialog. alert.show(); } }
From source file:com.lepin.activity.CarDriverVerify.java
/** * TODO ?// w ww . j ava 2s . c o m * * @author {author wangxiaohong} */ private void selectImage() { // TODO Auto-generated method stub String state = Environment.getExternalStorageState(); if (!state.equals(Environment.MEDIA_MOUNTED)) { Util.showToast(this, getResources().getString(R.string.check_sd)); return; } AlertDialog.Builder builder = new AlertDialog.Builder(CarDriverVerify.this); builder.setTitle(R.string.pick_image).setItems(image, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { if (image[which].equals(getString(R.string.my_data_image_way_photo))) { getImageByPhoto(); } else { getImageByGallery(); } } }); builder.create().show(); }
From source file:de.teunito.android.cyclelife.RennradNewsShare.java
/** Called when the activity is first created. */ @Override// ww w . j a va 2s .c o m public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.share_rennradnews); Bundle data = new Bundle(); data = getIntent().getExtras(); trackId = data.getLong("trackId"); mTrackDb = TrackDb.getInstance(getApplicationContext()); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); APIKey = prefs.getString(Preferences.RENNRADNEWS_API_KEY, ""); bikeId = prefs.getString(Preferences.RENNRADNEWS_BIKE_ID, ""); weight = prefs.getString(Preferences.WEIGHT, ""); tv = (TextView) findViewById(R.id.rnsShareTitle); tv.setText("Share your track " + trackId + " to rennrad-news.de community!"); bt = (Button) findViewById(R.id.rnsShareBtn); etTemp = (EditText) findViewById(R.id.rnsShareTemp); spSports = (Spinner) findViewById(R.id.rnsShareSports); spZone = (Spinner) findViewById(R.id.rnsShareZone); spWeather = (Spinner) findViewById(R.id.rnsShareWeather); spMood = (Spinner) findViewById(R.id.rnsShareMood); sportsAdapter = ArrayAdapter.createFromResource(this, R.array.sports, android.R.layout.simple_spinner_item); zoneAdapter = ArrayAdapter.createFromResource(this, R.array.zone, android.R.layout.simple_spinner_item); weatherAdapter = ArrayAdapter.createFromResource(this, R.array.weather, android.R.layout.simple_spinner_item); moodAdapter = ArrayAdapter.createFromResource(this, R.array.mood, android.R.layout.simple_spinner_item); sportsAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); zoneAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); weatherAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); moodAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spSports.setAdapter(sportsAdapter); spZone.setAdapter(zoneAdapter); spWeather.setAdapter(weatherAdapter); spMood.setAdapter(moodAdapter); bt.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { dialog = ProgressDialog.show(RennradNewsShare.this, "", "Uploading. Please wait...", true); sportsID = String.valueOf(spSports.getSelectedItemPosition() + 1); zoneId = String.valueOf(spZone.getSelectedItemPosition() + 1); weatherId = String.valueOf(spWeather.getSelectedItemPosition() + 1); moodId = String.valueOf(spMood.getSelectedItemPosition() + 1); temperature = etTemp.getText().toString(); // execute is a blocking call, it's best to call this code in a thread separate from the ui's uploadThread.start(); } }); handler = new Handler() { public void handleMessage(Message msg) { String result = msg.getData().getString("result"); if (result.contains("success")) { Toast.makeText(getApplicationContext(), "Uploaded: " + result, Toast.LENGTH_LONG).show(); finish(); } else Toast.makeText(getApplicationContext(), "Error: " + result, Toast.LENGTH_LONG).show(); } }; if (APIKey.length() < 20) { AlertDialog.Builder builder = new AlertDialog.Builder(RennradNewsShare.this); builder.setMessage("Please enter first the rennrad-news.de API-key in the Settings!") .setCancelable(false).setIcon(android.R.drawable.ic_dialog_alert) .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { RennradNewsShare.this.finish(); startActivity(new Intent(RennradNewsShare.this, Preferences.class)); } }); builder.create().show(); } }
From source file:de.tap.easy_xkcd.fragments.comics.ComicBrowserFragment.java
/******************* * Sharing/* w w w . j ava 2 s. c o m*/ **************************/ protected boolean shareComic() { if (prefHelper.shareImage()) { shareComicImage(); return true; } AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); builder.setItems(R.array.share_dialog, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { switch (which) { case 0: shareComicImage(); break; case 1: shareComicUrl(comicMap.get(lastComicNumber)); break; } } }); AlertDialog alert = builder.create(); alert.show(); return true; }
From source file:com.bt.heliniumstudentapp.UpdateClass.java
@Override protected void onPostExecute(String html) { if (html != null) { try {// ww w .j a v a 2 s . c o m final JSONObject json = (JSONObject) new JSONTokener(html).nextValue(); versionName = json.optString("version_name"); final int versionCode = json.optInt("version_code"); try { final int currentVersionCode = context.getPackageManager() .getPackageInfo(context.getPackageName(), 0).versionCode; if (versionCode > currentVersionCode) { if (!settings) updateDialog.show(); updateDialog.setTitle(context.getString(R.string.update) + ' ' + versionName); final TextView contentTV = (TextView) updateDialog.findViewById(R.id.tv_content_du); contentTV.setTextColor(ContextCompat.getColor(context, MainActivity.themePrimaryTextColor)); contentTV.setText(Html.fromHtml(json.optString("content"), null, new Html.TagHandler() { @Override public void handleTag(boolean opening, String tag, Editable output, XMLReader xmlReader) { if ("li".equals(tag)) if (opening) output.append(" \u2022 "); else output.append("\n"); } })); updateDialog.setCanceledOnTouchOutside(true); updateDialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(true); updateDialog.getButton(AlertDialog.BUTTON_POSITIVE) .setTextColor(ContextCompat.getColor(context, MainActivity.accentSecondaryColor)); } else if (settings) { updateDialog.setTitle(context.getString(R.string.update_no)); final TextView contentTV = (TextView) updateDialog.findViewById(R.id.tv_content_du); contentTV.setTextColor(ContextCompat.getColor(context, MainActivity.themePrimaryTextColor)); contentTV.setText(Html.fromHtml(json.optString("content"), null, new Html.TagHandler() { @Override public void handleTag(boolean opening, String tag, Editable output, XMLReader xmlReader) { if ("li".equals(tag)) if (opening) output.append(" \u2022 "); else output.append("\n"); } })); updateDialog.setCanceledOnTouchOutside(true); } } catch (NameNotFoundException e) { Toast.makeText(context, R.string.error, Toast.LENGTH_SHORT).show(); } } catch (JSONException e) { Toast.makeText(context, R.string.error, Toast.LENGTH_SHORT).show(); } } else if (settings) { updateDialog.cancel(); final AlertDialog.Builder updateDialogBuilder = new AlertDialog.Builder( new ContextThemeWrapper(context, MainActivity.themeDialog)); updateDialogBuilder.setTitle(context.getString(R.string.update)); updateDialogBuilder.setMessage(R.string.error_update); updateDialogBuilder.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { downloadAPK(); } }); updateDialogBuilder.setNegativeButton(android.R.string.no, null); final AlertDialog updateDialog = updateDialogBuilder.create(); updateDialog.setCanceledOnTouchOutside(true); updateDialog.show(); updateDialog.getButton(AlertDialog.BUTTON_POSITIVE) .setTextColor(ContextCompat.getColor(context, MainActivity.accentSecondaryColor)); updateDialog.getButton(AlertDialog.BUTTON_NEGATIVE) .setTextColor(ContextCompat.getColor(context, MainActivity.accentSecondaryColor)); } }
From source file:com.kircherelectronics.fusedgyroscopeexplorer.sensor.GyroscopeSensor.java
private void showGyroscopeNotAvailableAlert() { AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context); // set title// ww w . j av a2 s. c om alertDialogBuilder.setTitle("Gyroscope Not Available"); // set dialog message alertDialogBuilder.setMessage("Your device is not equipped with a gyroscope or it is not responding...") .setCancelable(false) .setNegativeButton("I'll look around...", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { // if this button is clicked, just close // the dialog box and do nothing dialog.cancel(); } }); // create alert dialog AlertDialog alertDialog = alertDialogBuilder.create(); // show it alertDialog.show(); }
From source file:com.citrus.sdk.fragments.SavedOptions.java
private void showPopup() { final String email = OneClicksignup.getDefaultGmail(getActivity()); final BooleanTask ontask = new BooleanTask() { @Override/*from w w w . j a v a 2s . c o m*/ public void ontaskComplete(boolean result) { if (result) { Toast.makeText(getActivity().getApplicationContext(), "An Email has been sent to you", Toast.LENGTH_SHORT).show(); } } }; final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); builder.setTitle("Reset Password?"); builder.setMessage("An email will be sent to " + email); builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { new ResetPassword(getActivity(), email, ontask).execute(); } }); builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { } }); builder.create(); builder.show(); }
From source file:com.dipesan.miniatm.miniatm.services.RiskManagementTask.java
@Override public void execute(ITaskMonitor monitor) { this.monitor = monitor; activity.runOnUiThread(new Runnable() { @Override/* w w w . j av a2s . c o m*/ public void run() { AlertDialog.Builder builder = new AlertDialog.Builder(activity); builder.setTitle("Risk management"); builder.setCancelable(false); builder.setMessage("Is card stolen ?"); builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); end(new byte[] { 0, 0b10000, 0, 0, 0 }); } }); builder.setNegativeButton("No", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); end(new byte[] { 0, 0, 0, 0, 0 }); } }); builder.create().show(); } }); }
From source file:net.reichholf.dreamdroid.activities.TimerListActivity.java
/** * Confirmation dialog before timer deletion *//* w w w . j a v a2s . c o m*/ private void deleteTimerConfirm() { AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle(mTimer.getString(Timer.NAME)).setMessage(getText(R.string.delete_confirm)) .setCancelable(false) .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { deleteTimer(mTimer); dialog.dismiss(); } }).setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.dismiss(); } }); AlertDialog alert = builder.create(); alert.show(); }