List of usage examples for android.content DialogInterface cancel
void cancel();
From source file:com.safecell.HomeScreenActivity.java
public void showGPSStatusAlert(String provider) { // Log.v("Safecell", "" + provider); String title = ""; String message = ""; if (LocationManager.GPS_PROVIDER.equals(provider)) { return;//from w ww .ja va 2 s . co m } if (provider == null) { title = "GPS is not enabled."; message = "GPS is not enabled. Please enable it."; } else { title = "GPS is not enabled."; message = "GPS is not enabled. Please enable it. \nMeanwhile, background trip tracking will be disabled."; } AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle(title); builder.setMessage(message); builder.setCancelable(false); builder.setPositiveButton("Launch Settings", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { launchGPSOptions(); } }); if (LocationManager.NETWORK_PROVIDER.equals(provider)) { builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }); } AlertDialog alert = builder.create(); alert.show(); }
From source file:com.IntimateCarCare.MainActivity.java
private void SetListenr() { // TODO Auto-generated method stub mall.setOnClickListener(new OnClickListener() { @Override/* ww w . j a va 2s . c o m*/ public void onClick(View v) { // TODO Auto-generated method stub Intent intent = new Intent(MainActivity.this, MyShopping.class); startActivity(intent); } }); mallhorizontalscrollview.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { // TODO Auto-generated method stub if (event.getAction() == MotionEvent.ACTION_UP) { mHandler.removeCallbacks(ScrollRunnable); mHandler.postDelayed(ScrollRunnable, 1000); } return false; } }); lin_weather.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub Intent intent = new Intent(MainActivity.this, MyweatherActivity.class); startActivity(intent); } }); lin_remotecheck.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub ToastUtil.show(MainActivity.this, "?"); } }); lin_my.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub Intent intent = new Intent(MainActivity.this, MyActivity.class); startActivityForResult(intent, 2); } }); tv_changecar.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub getPopupWindow(); // ??, popupview.showAsDropDown(lin0); } }); lin_GPS.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub if ((Boolean) SPUtils.get(MainActivity.this, "isBoxbind", false)) { Intent intent = new Intent(MainActivity.this, GPSActivity.class); startActivity(intent); } else { dialogredmain(MainActivity.this); } } }); lin_carcheck.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub if ((Boolean) SPUtils.get(MainActivity.this, "isBoxbind", false)) { Intent intent = new Intent(MainActivity.this, CarReportActivity.class); startActivity(intent); } else { dialogredmain(MainActivity.this); } } }); lin_consult.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub Intent intent = new Intent(MainActivity.this, ConsultActivity.class); startActivity(intent); } }); rel_remind.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub Intent intent = new Intent(MainActivity.this, RemindActivity.class); startActivityForResult(intent, 1); } }); carimg.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub final String[] arrayContestLevel = new String[] { "?", "" }; AlertDialog.Builder alertDialog = new AlertDialog.Builder(MainActivity.this) .setTitle("?") .setItems(arrayContestLevel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { switch (which) { case 0: choseHeadImageFromCameraCapture(); break; case 1: choseHeadImageFromGallery(); default: break; } dialog.cancel(); } }); alertDialog.create().show(); } }); }
From source file:com.example.android.contactslist.ui.groupsEditor.GroupsEditorFragment.java
private void specifyNewGroupToAdd() { AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); builder.setTitle(R.string.dialog_title_enter_group_name); // Set up the input final EditText input = new EditText(getActivity()); // Specify the type of input expected; this, for example, sets the input as a password, and will mask the text input.setInputType(InputType.TYPE_TEXT_FLAG_MULTI_LINE); builder.setView(input);//from w ww . ja v a2 s . c o m // Set up the buttons builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { final GoogleGroupMaker googleGroupMaker = new GoogleGroupMaker(getActivity()); name_of_new_group = input.getText().toString(); // create new group with the given name googleGroupMaker.makeContactGroup(name_of_new_group); } }); builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.cancel(); } }); builder.show(); }
From source file:br.com.GUI.perfil.MeuPersonal.java
public void adicionarRemoverMeuPersonal() { AlertDialog.Builder alertDialog = new AlertDialog.Builder(getActivity()); alertDialog.setTitle("Confirme esta ao"); alertDialog.setMessage("Voc realmente deseja remover seu treinador?"); alertDialog.setIcon(R.drawable.profile); alertDialog.setNegativeButton("Sim", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { if (a.getUsuarioPersonal().equals(p.getUsuario())) { if (a.removerAlunoWeb(a.getUsuario()) && a.removerAluno(b)) { Toast.makeText(getActivity(), "Removido com Sucesso", Toast.LENGTH_SHORT).show(); // Exclui todas as aulas marcadas com o personal ArrayList<Aula> aulasParaExcluir = new ArrayList<Aula>(); aulasParaExcluir = new Aula().buscarAulasPorAlunoWeb(a.getUsuario(), ""); for (Aula c : aulasParaExcluir) { if (c.excluirAulaWeb() && c.excluirAula(b)) { Log.i("INFORMAO", "Aulas excluidas com sucesso!"); }/* w w w. j a v a 2s.c o m*/ } atualizarMeuPersonal(); } else { Toast.makeText(getActivity(), "Falha ao Remover o aluno", Toast.LENGTH_SHORT).show(); } } atualizarMeuPersonal(); } }); alertDialog.setPositiveButton("No", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.cancel(); } }); // Showing Alert Message alertDialog.show(); }
From source file:de.baumann.hhsmoodle.data_random.Random_Fragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_screen_dice, container, false); ImageView imgHeader = (ImageView) rootView.findViewById(R.id.imageView_header); helper_main.setImageHeader(getActivity(), imgHeader); fab_dice = (FloatingActionButton) rootView.findViewById(R.id.fab_dice); lv = (ListView) rootView.findViewById(R.id.list); viewPager = (ViewPager) getActivity().findViewById(R.id.viewpager); lvItems = (ListView) rootView.findViewById(R.id.lvItems); fabLayout1 = (LinearLayout) rootView.findViewById(R.id.fabLayout1); fabLayout2 = (LinearLayout) rootView.findViewById(R.id.fabLayout2); fab = (FloatingActionButton) rootView.findViewById(R.id.fab); FloatingActionButton fab1 = (FloatingActionButton) rootView.findViewById(R.id.fab1); FloatingActionButton fab2 = (FloatingActionButton) rootView.findViewById(R.id.fab2); fab.setOnClickListener(new View.OnClickListener() { @Override/*www . j a v a 2s.co m*/ public void onClick(View view) { if (!isFABOpen) { showFABMenu(); } else { closeFABMenu(); } } }); fab1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { closeFABMenu(); android.app.AlertDialog.Builder builder = new android.app.AlertDialog.Builder(getActivity()); View dialogView = View.inflate(getActivity(), R.layout.dialog_edit_entry, null); final EditText edit_title = (EditText) dialogView.findViewById(R.id.note_title_input); edit_title.setHint(R.string.title_hint); final EditText edit_cont = (EditText) dialogView.findViewById(R.id.note_text_input); edit_cont.setHint(R.string.text_hint); 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 inputTitle = edit_title.getText().toString().trim(); String inputCont = edit_cont.getText().toString().trim(); if (db.isExist(inputTitle)) { Snackbar.make(lv, getString(R.string.toast_newTitle), Snackbar.LENGTH_LONG).show(); } else { db.insert(inputTitle, inputCont, "", "", helper_main.createDate()); dialog.dismiss(); setRandomList(); Snackbar.make(lv, R.string.bookmark_added, Snackbar.LENGTH_SHORT).show(); } } }); builder.setNegativeButton(R.string.toast_cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.cancel(); } }); final android.app.AlertDialog dialog2 = builder.create(); // Display the custom alert dialog on interface dialog2.show(); helper_main.showKeyboard(getActivity(), edit_title); } }); fab2.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { closeFABMenu(); Intent mainIntent = new Intent(getActivity(), Popup_courseList.class); mainIntent.setAction("courseList_random"); startActivity(mainIntent); } }); fab_dice.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { try { Random rand = new Random(); final int n = rand.nextInt(lvItems.getCount()); setAdapter(n); lvItems.setSelection(n - 1); } catch (NumberFormatException nfe) { nfe.printStackTrace(); } } }); //calling Notes_DbAdapter db = new Random_DbAdapter(getActivity()); db.open(); setRandomList(); setHasOptionsMenu(true); return rootView; }
From source file:com.piusvelte.taplock.client.core.TapLockSettings.java
@Override protected void onResume() { super.onResume(); Intent intent = getIntent();//from w w w . j a va2 s . c o m if (mInWriteMode) { if (intent != null) { String action = intent.getAction(); if (mInWriteMode && NfcAdapter.ACTION_TAG_DISCOVERED.equals(action) && intent.hasExtra(EXTRA_DEVICE_NAME)) { Tag tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG); String name = intent.getStringExtra(EXTRA_DEVICE_NAME); if ((tag != null) && (name != null)) { // write the device and address String lang = "en"; // don't write the passphrase! byte[] textBytes = name.getBytes(); byte[] langBytes = null; int langLength = 0; try { langBytes = lang.getBytes("US-ASCII"); langLength = langBytes.length; } catch (UnsupportedEncodingException e) { Log.e(TAG, e.toString()); } int textLength = textBytes.length; byte[] payload = new byte[1 + langLength + textLength]; // set status byte (see NDEF spec for actual bits) payload[0] = (byte) langLength; // copy langbytes and textbytes into payload if (langBytes != null) { System.arraycopy(langBytes, 0, payload, 1, langLength); } System.arraycopy(textBytes, 0, payload, 1 + langLength, textLength); NdefRecord record = new NdefRecord(NdefRecord.TNF_WELL_KNOWN, NdefRecord.RTD_TEXT, new byte[0], payload); NdefMessage message = new NdefMessage( new NdefRecord[] { record, NdefRecord.createApplicationRecord(getPackageName()) }); // Get an instance of Ndef for the tag. Ndef ndef = Ndef.get(tag); if (ndef != null) { try { ndef.connect(); if (ndef.isWritable()) { ndef.writeNdefMessage(message); } ndef.close(); Toast.makeText(this, "tag written", Toast.LENGTH_LONG).show(); } catch (IOException e) { Log.e(TAG, e.toString()); } catch (FormatException e) { Log.e(TAG, e.toString()); } } else { NdefFormatable format = NdefFormatable.get(tag); if (format != null) { try { format.connect(); format.format(message); format.close(); Toast.makeText(getApplicationContext(), "tag written", Toast.LENGTH_LONG); } catch (IOException e) { Log.e(TAG, e.toString()); } catch (FormatException e) { Log.e(TAG, e.toString()); } } } mNfcAdapter.disableForegroundDispatch(this); } } } mInWriteMode = false; } else { SharedPreferences sp = getSharedPreferences(KEY_PREFS, MODE_PRIVATE); onSharedPreferenceChanged(sp, KEY_DEVICES); // check if configuring a widget if (intent != null) { Bundle extras = intent.getExtras(); if (extras != null) { final String[] displayNames = TapLock.getDeviceNames(mDevices); final int appWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID); if (appWidgetId != AppWidgetManager.INVALID_APPWIDGET_ID) { mDialog = new AlertDialog.Builder(TapLockSettings.this).setTitle("Select device for widget") .setItems(displayNames, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // set the successful widget result Intent resultValue = new Intent(); resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); setResult(RESULT_OK, resultValue); // broadcast the new widget to update JSONObject deviceJObj = mDevices.get(which); dialog.cancel(); TapLockSettings.this.finish(); try { sendBroadcast(TapLock .getPackageIntent(TapLockSettings.this, TapLockWidget.class) .setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE) .putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId) .putExtra(EXTRA_DEVICE_NAME, deviceJObj.getString(KEY_NAME))); } catch (JSONException e) { Log.e(TAG, e.toString()); } } }).create(); mDialog.show(); } } } // start the service before binding so that the service stays around for faster future connections startService(TapLock.getPackageIntent(this, TapLockService.class)); bindService(TapLock.getPackageIntent(this, TapLockService.class), this, BIND_AUTO_CREATE); int serverVersion = sp.getInt(KEY_SERVER_VERSION, 0); if (mShowTapLockSettingsInfo && (mDevices.size() == 0)) { if (serverVersion < SERVER_VERSION) sp.edit().putInt(KEY_SERVER_VERSION, SERVER_VERSION).commit(); mShowTapLockSettingsInfo = false; Intent i = TapLock.getPackageIntent(this, TapLockInfo.class); i.putExtra(EXTRA_INFO, getString(R.string.info_taplocksettings)); startActivity(i); } else if (serverVersion < SERVER_VERSION) { // TapLockServer has been updated sp.edit().putInt(KEY_SERVER_VERSION, SERVER_VERSION).commit(); mDialog = new AlertDialog.Builder(TapLockSettings.this).setTitle(R.string.ttl_hasupdate) .setMessage(R.string.msg_hasupdate) .setNeutralButton(R.string.button_getserver, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.cancel(); mDialog = new AlertDialog.Builder(TapLockSettings.this) .setTitle(R.string.msg_pickinstaller) .setItems(R.array.installer_entries, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.cancel(); final String installer_file = getResources() .getStringArray(R.array.installer_values)[which]; mDialog = new AlertDialog.Builder(TapLockSettings.this) .setTitle(R.string.msg_pickdownloader) .setItems(R.array.download_entries, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.cancel(); String action = getResources() .getStringArray( R.array.download_values)[which]; if (ACTION_DOWNLOAD_SDCARD.equals(action) && copyFileToSDCard(installer_file)) Toast.makeText(TapLockSettings.this, "Done!", Toast.LENGTH_SHORT) .show(); else if (ACTION_DOWNLOAD_EMAIL .equals(action) && copyFileToSDCard( installer_file)) { Intent emailIntent = new Intent( android.content.Intent.ACTION_SEND); emailIntent.setType( "application/java-archive"); emailIntent.putExtra(Intent.EXTRA_TEXT, getString( R.string.email_instructions)); emailIntent.putExtra( Intent.EXTRA_SUBJECT, getString(R.string.app_name)); emailIntent.putExtra( Intent.EXTRA_STREAM, Uri.parse("file://" + Environment .getExternalStorageDirectory() .getPath() + "/" + installer_file)); startActivity(Intent.createChooser( emailIntent, getString( R.string.button_getserver))); } } }) .create(); mDialog.show(); } }).create(); mDialog.show(); } }).create(); mDialog.show(); } } }
From source file:de.baumann.hhsmoodle.activities.Activity_count.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); PreferenceManager.setDefaultValues(this, R.xml.user_settings, false); sharedPref = PreferenceManager.getDefaultSharedPreferences(this); toDo_title = sharedPref.getString("count_title", ""); String count_title = sharedPref.getString("count_content", ""); toDo_icon = sharedPref.getString("count_icon", ""); toDo_create = sharedPref.getString("count_create", ""); String todo_attachment = sharedPref.getString("count_attachment", ""); if (!sharedPref.getString("count_seqno", "").isEmpty()) { toDo_seqno = Integer.parseInt(sharedPref.getString("count_seqno", "")); }//from w ww .j a v a 2 s .c o m setContentView(R.layout.activity_count); setTitle(toDo_title); final EditText etNewItem = (EditText) findViewById(R.id.etNewItem); FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { String itemText = etNewItem.getText().toString(); if (itemText.isEmpty()) { Snackbar.make(lvItems, R.string.todo_enter, Snackbar.LENGTH_LONG).show(); } else { itemsTitle.add(0, itemText); itemsCount.add(0, "0"); etNewItem.setText(""); writeItemsTitle(); writeItemsCount(); lvItems.post(new Runnable() { public void run() { lvItems.setSelection(lvItems.getCount() - 1); } }); adapter.notifyDataSetChanged(); } } }); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); helper_main.onStart(Activity_count.this); final ActionBar actionBar = getSupportActionBar(); if (actionBar != null) { actionBar.setDisplayHomeAsUpEnabled(true); } try { FileOutputStream fOut = new FileOutputStream(newFileTitle()); OutputStreamWriter myOutWriter = new OutputStreamWriter(fOut); myOutWriter.append(count_title); myOutWriter.close(); fOut.flush(); fOut.close(); } catch (IOException e) { Log.e("Exception", "File write failed: " + e.toString()); } try { FileOutputStream fOut = new FileOutputStream(newFileCount()); OutputStreamWriter myOutWriter = new OutputStreamWriter(fOut); myOutWriter.append(todo_attachment); myOutWriter.close(); fOut.flush(); fOut.close(); } catch (IOException e) { Log.e("Exception", "File write failed: " + e.toString()); } lvItems = (ListView) findViewById(R.id.lvItems); itemsTitle = new ArrayList<>(); readItemsTitle(); readItemsCount(); adapter = new CustomListAdapter(Activity_count.this, itemsTitle, itemsCount) { @NonNull @Override public View getView(final int position, View convertView, @NonNull ViewGroup parent) { View v = super.getView(position, convertView, parent); ImageButton ib_plus = (ImageButton) v.findViewById(R.id.but_plus); ImageButton ib_minus = (ImageButton) v.findViewById(R.id.but_minus); TextView tv = (TextView) v.findViewById(R.id.count_count); int count = Integer.parseInt(itemsCount.get(position)); if (count < 0) { tv.setTextColor(ContextCompat.getColor(Activity_count.this, R.color.color_red)); } else if (count > 0) { tv.setTextColor(ContextCompat.getColor(Activity_count.this, R.color.color_green)); } else if (count == 0) { tv.setTextColor(ContextCompat.getColor(Activity_count.this, R.color.color_grey)); } ib_plus.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { int a = Integer.parseInt(itemsCount.get(position)) + 1; String plus = String.valueOf(a); itemsCount.remove(position); itemsCount.add(position, plus); // Refresh the adapter adapter.notifyDataSetChanged(); // Return true consumes the long click event (marks it handled) writeItemsTitle(); writeItemsCount(); } }); ib_minus.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { int a = Integer.parseInt(itemsCount.get(position)) - 1; String minus = String.valueOf(a); itemsCount.remove(position); itemsCount.add(position, minus); // Refresh the adapter adapter.notifyDataSetChanged(); // Return true consumes the long click event (marks it handled) writeItemsTitle(); writeItemsCount(); } }); return v; } }; lvItems.setAdapter(adapter); lvItems.setOnItemClickListener(new android.widget.AdapterView.OnItemClickListener() { @Override public void onItemClick(android.widget.AdapterView<?> parent, View view, final int position, long id) { final String title = itemsTitle.get(position); final String count = itemsCount.get(position); AlertDialog.Builder builder = new AlertDialog.Builder(Activity_count.this); View dialogView = View.inflate(Activity_count.this, R.layout.dialog_edit_text_singleline_count, null); final EditText edit_title = (EditText) dialogView.findViewById(R.id.pass_title); edit_title.setText(title); 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 itemsTitle.remove(position); itemsCount.remove(position); itemsTitle.add(position, inputTag); itemsCount.add(position, count); // Refresh the adapter adapter.notifyDataSetChanged(); // Return true consumes the long click event (marks it handled) writeItemsTitle(); writeItemsCount(); } }); 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_count.this, edit_title); } }); lvItems.setOnItemLongClickListener(new android.widget.AdapterView.OnItemLongClickListener() { @Override public boolean onItemLongClick(android.widget.AdapterView<?> parent, View view, final int position, long id) { final String title = itemsTitle.get(position); final String count = itemsCount.get(position); // Remove the item within array at position itemsTitle.remove(position); itemsCount.remove(position); // Refresh the adapter adapter.notifyDataSetChanged(); // Return true consumes the long click event (marks it handled) writeItemsTitle(); writeItemsCount(); 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) { itemsTitle.add(position, title); itemsCount.add(position, count); // Refresh the adapter adapter.notifyDataSetChanged(); // Return true consumes the long click event (marks it handled) writeItemsTitle(); writeItemsCount(); } }); snackbar.show(); return true; } }); }
From source file:com.appdupe.flamer.LoginUsingFacebook.java
private void showGPSDisabledAlertToUser() { AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this); alertDialogBuilder.setMessage("GPS is disabled in your device. Would you like to enable it?") .setCancelable(false).setPositiveButton(R.string.button_ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); Intent callGPSSettingIntent = new Intent( android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS); startActivity(callGPSSettingIntent); }//from w w w. ja v a2s . co m }); alertDialogBuilder.setNegativeButton(R.string.button_cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); finish(); } }); AlertDialog alert = alertDialogBuilder.create(); alert.show(); }
From source file:bander.notepad.About.java
@NonNull @Override//from ww w. j ava 2s . c o m public Dialog onCreateDialog(Bundle savedInstanceState) { return new AlertDialog.Builder(getActivity()) .setIcon(android.R.drawable.ic_dialog_info) .setTitle(R.string.about1) .setMessage(R.string.about2) .setOnKeyListener(new DialogInterface.OnKeyListener() { @Override public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) { if (event.getAction() == 1) { if (keyCode == 24) { Toast.makeText(getActivity(), "\u0057\u006f\u0077\u002c \u0079\u006f" + "\u0075\u0027\u0072\u0065 \u0067\u006f\u006f\u0064\u0021", Toast.LENGTH_LONG).show(); return true; } } return false; } }) .setPositiveButton(R.string.licences, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { // LGPLv3 is not included in the library, so we have to register it. LicenseResolver.registerLicense(new GnuLesserGeneralPublicLicense30()); final LicensesDialogFragment fragment = LicensesDialogFragment.newInstance(R.raw.notices, false); fragment.show(getActivity().getSupportFragmentManager(), null); } }) .setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.cancel(); } }).create(); }
From source file:com.shafiq.myfeedle.core.OAuthLogin.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setResult(RESULT_CANCELED);/*from w w w . j a v a 2 s . c o m*/ mHttpClient = MyfeedleHttpClient.getThreadSafeClient(getApplicationContext()); mLoadingDialog = new ProgressDialog(this); mLoadingDialog.setMessage(getString(R.string.loading)); mLoadingDialog.setCancelable(true); mLoadingDialog.setOnCancelListener(this); mLoadingDialog.setButton(ProgressDialog.BUTTON_NEGATIVE, getString(android.R.string.cancel), this); Intent intent = getIntent(); if (intent != null) { Bundle extras = intent.getExtras(); if (extras != null) { int service = extras.getInt(Myfeedle.Accounts.SERVICE, Myfeedle.INVALID_SERVICE); mServiceName = Myfeedle.getServiceName(getResources(), service); mWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID); mAccountId = extras.getLong(Myfeedle.EXTRA_ACCOUNT_ID, Myfeedle.INVALID_ACCOUNT_ID); mMyfeedleWebView = new MyfeedleWebView(); final ProgressDialog loadingDialog = new ProgressDialog(this); final AsyncTask<String, Void, String> asyncTask = new AsyncTask<String, Void, String>() { @Override protected String doInBackground(String... args) { try { return mMyfeedleOAuth.getAuthUrl(args[0], args[1], args[2], args[3], Boolean.parseBoolean(args[4]), mHttpClient); } catch (OAuthMessageSignerException e) { e.printStackTrace(); } catch (OAuthNotAuthorizedException e) { e.printStackTrace(); } catch (OAuthExpectationFailedException e) { e.printStackTrace(); } catch (OAuthCommunicationException e) { e.printStackTrace(); } return null; } @Override protected void onPostExecute(String url) { if (loadingDialog.isShowing()) loadingDialog.dismiss(); // load the webview if (url != null) { mMyfeedleWebView.open(url); } else { (Toast.makeText(OAuthLogin.this, String.format(getString(R.string.oauth_error), mServiceName), Toast.LENGTH_LONG)).show(); OAuthLogin.this.finish(); } } }; loadingDialog.setMessage(getString(R.string.loading)); loadingDialog.setCancelable(true); loadingDialog.setOnCancelListener(new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { if (!asyncTask.isCancelled()) asyncTask.cancel(true); dialog.cancel(); OAuthLogin.this.finish(); } }); loadingDialog.setButton(ProgressDialog.BUTTON_NEGATIVE, getString(android.R.string.cancel), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (!asyncTask.isCancelled()) asyncTask.cancel(true); dialog.cancel(); OAuthLogin.this.finish(); } }); switch (service) { case TWITTER: mMyfeedleOAuth = new MyfeedleOAuth(TWITTER_KEY, TWITTER_SECRET); asyncTask.execute(String.format(TWITTER_URL_REQUEST, TWITTER_BASE_URL), String.format(TWITTER_URL_ACCESS, TWITTER_BASE_URL), String.format(TWITTER_URL_AUTHORIZE, TWITTER_BASE_URL), TWITTER_CALLBACK.toString(), Boolean.toString(true)); loadingDialog.show(); break; case FACEBOOK: mMyfeedleWebView.open(String.format(FACEBOOK_URL_AUTHORIZE, FACEBOOK_BASE_URL, FACEBOOK_ID, FACEBOOK_CALLBACK.toString())); break; // case MYSPACE: // mMyfeedleOAuth = new MyfeedleOAuth(MYSPACE_KEY, MYSPACE_SECRET); // asyncTask.execute(MYSPACE_URL_REQUEST, MYSPACE_URL_ACCESS, MYSPACE_URL_AUTHORIZE, MYSPACE_CALLBACK.toString(), Boolean.toString(true)); // loadingDialog.show(); // break; case FOURSQUARE: mMyfeedleWebView.open(String.format(FOURSQUARE_URL_AUTHORIZE, FOURSQUARE_KEY, FOURSQUARE_CALLBACK.toString())); break; case LINKEDIN: mMyfeedleOAuth = new MyfeedleOAuth(LINKEDIN_KEY, LINKEDIN_SECRET); asyncTask.execute(LINKEDIN_URL_REQUEST, LINKEDIN_URL_ACCESS, LINKEDIN_URL_AUTHORIZE, LINKEDIN_CALLBACK.toString(), Boolean.toString(true)); loadingDialog.show(); break; case SMS: Cursor c = getContentResolver().query(Accounts.getContentUri(this), new String[] { Accounts._ID }, Accounts.SERVICE + "=?", new String[] { Integer.toString(SMS) }, null); if (c.moveToFirst()) { (Toast.makeText(OAuthLogin.this, "SMS has already been added.", Toast.LENGTH_LONG)).show(); } else { addAccount(getResources().getStringArray(R.array.service_entries)[SMS], null, null, 0, SMS, null); } c.close(); finish(); break; case RSS: // prompt for RSS url final EditText rss_url = new EditText(this); rss_url.setSingleLine(); new AlertDialog.Builder(OAuthLogin.this).setTitle(R.string.rss_url).setView(rss_url) .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(final DialogInterface dialog, int which) { // test the url and add if valid, else Toast error mLoadingDialog.show(); (new AsyncTask<String, Void, String>() { String url; @Override protected String doInBackground(String... params) { url = rss_url.getText().toString(); return MyfeedleHttpClient.httpResponse(mHttpClient, new HttpGet(url)); } @Override protected void onPostExecute(String response) { mLoadingDialog.dismiss(); if (response != null) { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db; try { db = dbf.newDocumentBuilder(); InputSource is = new InputSource(); is.setCharacterStream(new StringReader(response)); Document doc = db.parse(is); // test parsing... NodeList nodes = doc.getElementsByTagName(Sitem); if (nodes.getLength() > 0) { // check for an image NodeList images = doc.getElementsByTagName(Simage); if (images.getLength() > 0) { NodeList imageChildren = images.item(0).getChildNodes(); Node n = imageChildren.item(0); if (n.getNodeName().toLowerCase().equals(Surl)) { if (n.hasChildNodes()) { n.getChildNodes().item(0).getNodeValue(); } } } NodeList children = nodes.item(0).getChildNodes(); String date = null; String title = null; String description = null; String link = null; int values_count = 0; for (int child = 0, c2 = children.getLength(); (child < c2) && (values_count < 4); child++) { Node n = children.item(child); if (n.getNodeName().toLowerCase().equals(Spubdate)) { values_count++; if (n.hasChildNodes()) { date = n.getChildNodes().item(0).getNodeValue(); } } else if (n.getNodeName().toLowerCase() .equals(Stitle)) { values_count++; if (n.hasChildNodes()) { title = n.getChildNodes().item(0) .getNodeValue(); } } else if (n.getNodeName().toLowerCase() .equals(Sdescription)) { values_count++; if (n.hasChildNodes()) { StringBuilder sb = new StringBuilder(); NodeList descNodes = n.getChildNodes(); for (int dn = 0, dn2 = descNodes .getLength(); dn < dn2; dn++) { Node descNode = descNodes.item(dn); if (descNode .getNodeType() == Node.TEXT_NODE) { sb.append(descNode.getNodeValue()); } } // strip out the html tags description = sb.toString() .replaceAll("\\<(.|\n)*?>", ""); } } else if (n.getNodeName().toLowerCase() .equals(Slink)) { values_count++; if (n.hasChildNodes()) { link = n.getChildNodes().item(0).getNodeValue(); } } } if (Myfeedle.HasValues( new String[] { title, description, link, date })) { final EditText url_name = new EditText(OAuthLogin.this); url_name.setSingleLine(); new AlertDialog.Builder(OAuthLogin.this) .setTitle(R.string.rss_channel) .setView(url_name) .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick( DialogInterface dialog1, int which) { addAccount( url_name.getText() .toString(), null, null, 0, RSS, url); dialog1.dismiss(); dialog.dismiss(); finish(); } }) .setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick( DialogInterface dialog1, int which) { dialog1.dismiss(); dialog.dismiss(); finish(); } }) .show(); } else { (Toast.makeText(OAuthLogin.this, "Feed is missing standard fields", Toast.LENGTH_LONG)).show(); } } else { (Toast.makeText(OAuthLogin.this, "Invalid feed", Toast.LENGTH_LONG)).show(); dialog.dismiss(); finish(); } } catch (ParserConfigurationException e) { Log.e(TAG, e.toString()); (Toast.makeText(OAuthLogin.this, "Invalid feed", Toast.LENGTH_LONG)).show(); dialog.dismiss(); finish(); } catch (SAXException e) { Log.e(TAG, e.toString()); (Toast.makeText(OAuthLogin.this, "Invalid feed", Toast.LENGTH_LONG)).show(); dialog.dismiss(); finish(); } catch (IOException e) { Log.e(TAG, e.toString()); (Toast.makeText(OAuthLogin.this, "Invalid feed", Toast.LENGTH_LONG)).show(); dialog.dismiss(); finish(); } } else { (Toast.makeText(OAuthLogin.this, "Invalid URL", Toast.LENGTH_LONG)) .show(); dialog.dismiss(); finish(); } } }).execute(rss_url.getText().toString()); } }).setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); finish(); } }).show(); break; // case IDENTICA: // mMyfeedleOAuth = new MyfeedleOAuth(IDENTICA_KEY, IDENTICA_SECRET); // asyncTask.execute(String.format(IDENTICA_URL_REQUEST, IDENTICA_BASE_URL), String.format(IDENTICA_URL_ACCESS, IDENTICA_BASE_URL), String.format(IDENTICA_URL_AUTHORIZE, IDENTICA_BASE_URL), IDENTICA_CALLBACK.toString(), Boolean.toString(true)); // loadingDialog.show(); // break; case GOOGLEPLUS: mMyfeedleWebView.open( String.format(GOOGLEPLUS_AUTHORIZE, GOOGLE_CLIENTID, "urn:ietf:wg:oauth:2.0:oob")); break; // case CHATTER: // mMyfeedleWebView.open(String.format(CHATTER_URL_AUTHORIZE, CHATTER_KEY, CHATTER_CALLBACK.toString())); // break; case PINTEREST: Cursor pinterestAccount = getContentResolver().query(Accounts.getContentUri(this), new String[] { Accounts._ID }, Accounts.SERVICE + "=?", new String[] { Integer.toString(PINTEREST) }, null); if (pinterestAccount.moveToFirst()) { (Toast.makeText(OAuthLogin.this, "Pinterest has already been added.", Toast.LENGTH_LONG)) .show(); } else { (Toast.makeText(OAuthLogin.this, "Pinterest currently allows only public, non-authenticated viewing.", Toast.LENGTH_LONG)).show(); String[] values = getResources().getStringArray(R.array.service_values); String[] entries = getResources().getStringArray(R.array.service_entries); for (int i = 0, l = values.length; i < l; i++) { if (Integer.toString(PINTEREST).equals(values[i])) { addAccount(entries[i], null, null, 0, PINTEREST, null); break; } } } pinterestAccount.close(); finish(); break; default: this.finish(); } } } }