List of usage examples for android.app AlertDialog setButton
public void setButton(int whichButton, CharSequence text, OnClickListener listener)
From source file:net.fabiszewski.ulogger.MainActivity.java
/** * Display warning before deleting not synchronized track *//*from www . j a va2 s . co m*/ private void showNotSyncedWarning() { AlertDialog alertDialog = new AlertDialog.Builder(MainActivity.this).create(); alertDialog.setTitle(getString(R.string.warning)); alertDialog.setMessage(getString(R.string.notsync_warning)); alertDialog.setButton(AlertDialog.BUTTON_POSITIVE, getString(R.string.ok), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); showTrackDialog(); } }); alertDialog.setButton(AlertDialog.BUTTON_NEGATIVE, getString(R.string.cancel), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); alertDialog.show(); }
From source file:com.vk.sdk.VKCaptchaDialog.java
/** * Prepare, create and show dialog for displaying captcha */// w w w . j av a2s . c o m public void show() { Context context = VKUIHelper.getTopActivity(); View innerView = LayoutInflater.from(context).inflate(R.layout.dialog_vkcaptcha, null); assert innerView != null; mCaptchaAnswer = (EditText) innerView.findViewById(R.id.captchaAnswer); mCaptchaImage = (ImageView) innerView.findViewById(R.id.imageView); mProgressBar = (ProgressBar) innerView.findViewById(R.id.progressBar); mDensity = context.getResources().getDisplayMetrics().density; final AlertDialog dialog = new AlertDialog.Builder(context).setView(innerView).create(); mCaptchaAnswer.setOnFocusChangeListener(new View.OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { if (hasFocus) { dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE); } } }); mCaptchaAnswer.setOnEditorActionListener(new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView textView, int actionId, KeyEvent keyEvent) { if (actionId == EditorInfo.IME_ACTION_SEND) { sendAnswer(); return true; } return false; } }); dialog.setButton(AlertDialog.BUTTON_NEGATIVE, context.getString(android.R.string.ok), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { sendAnswer(); } }); dialog.setOnCancelListener(new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialogInterface) { mCaptchaError.request.cancel(); } }); loadImage(); dialog.show(); }
From source file:com.haibison.android.anhuu.utils.ui.bookmark.BookmarkFragment.java
/** * Shows a dialog to let the user enter new name or change current name of a * bookmark./*ww w .j a v a 2 s . c o m*/ * * @param context * {@link Context} * @param providerId * the provider ID. * @param id * the bookmark ID. * @param uri * the URI to the bookmark. * @param name * the name. To enter new name, this is the suggested name you * provide. To rename, this is the old name. */ public static void doEnterNewNameOrRenameBookmark(final Context context, final String providerId, final int id, final Uri uri, final String name) { final AlertDialog dialog = Dlg.newAlertDlg(context); View view = LayoutInflater.from(context).inflate(R.layout.anhuu_f5be488d_simple_text_input_view, null); final EditText textName = (EditText) view.findViewById(R.id.anhuu_f5be488d_text1); textName.setText(name); textName.selectAll(); textName.setHint(R.string.anhuu_f5be488d_hint_new_name); textName.setOnEditorActionListener(new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if (actionId == EditorInfo.IME_ACTION_DONE) { UI.showSoftKeyboard(textName, false); Button btn = dialog.getButton(DialogInterface.BUTTON_POSITIVE); if (btn.isEnabled()) btn.performClick(); return true; } return false; }// onEditorAction() }); dialog.setView(view); dialog.setIcon(R.drawable.anhuu_f5be488d_bookmarks_dark); dialog.setTitle(id < 0 ? R.string.anhuu_f5be488d_title_new_bookmark : R.string.anhuu_f5be488d_title_rename); dialog.setButton(DialogInterface.BUTTON_POSITIVE, context.getString(android.R.string.ok), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { String newName = textName.getText().toString().trim(); if (android.text.TextUtils.isEmpty(newName)) { Dlg.toast(context, R.string.anhuu_f5be488d_msg_bookmark_name_is_invalid, Dlg.LENGTH_SHORT); return; } UI.showSoftKeyboard(textName, false); ContentValues values = new ContentValues(); values.put(BookmarkContract.COLUMN_NAME, newName); if (id >= 0) { values.put(BookmarkContract.COLUMN_MODIFICATION_TIME, DbUtils.formatNumber(new Date().getTime())); context.getContentResolver().update( ContentUris.withAppendedId(BookmarkContract.genContentIdUriBase(context), id), values, null, null); } else { /* * Check if the URI exists or doesn't. If it exists, * update it instead of inserting the new one. */ Cursor cursor = context.getContentResolver().query( BookmarkContract.genContentUri(context), null, String.format("%s = %s AND %s LIKE %s", BookmarkContract.COLUMN_PROVIDER_ID, DatabaseUtils.sqlEscapeString(providerId), BookmarkContract.COLUMN_URI, DatabaseUtils.sqlEscapeString(uri.toString())), null, null); try { if (cursor != null && cursor.moveToFirst()) { values.put(BookmarkContract.COLUMN_MODIFICATION_TIME, DbUtils.formatNumber(new Date().getTime())); context.getContentResolver().update( Uri.withAppendedPath(BookmarkContract.genContentIdUriBase(context), Uri.encode(cursor.getString( cursor.getColumnIndex(BookmarkContract._ID)))), values, null, null); } else { values.put(BookmarkContract.COLUMN_PROVIDER_ID, providerId); values.put(BookmarkContract.COLUMN_URI, uri.toString()); context.getContentResolver().insert(BookmarkContract.genContentUri(context), values); } } finally { if (cursor != null) cursor.close(); } } Dlg.toast(context, context.getString(R.string.anhuu_f5be488d_msg_done), Dlg.LENGTH_SHORT); }// onClick() }); dialog.show(); UI.showSoftKeyboard(textName, true); final Button buttonOk = dialog.getButton(DialogInterface.BUTTON_POSITIVE); buttonOk.setEnabled(id < 0); textName.addTextChangedListener(new TextWatcher() { @Override public void onTextChanged(CharSequence s, int start, int before, int count) { // TODO Auto-generated method stub } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { // TODO Auto-generated method stub } @Override public void afterTextChanged(Editable s) { String newName = s.toString().trim(); boolean enabled = !android.text.TextUtils.isEmpty(newName); buttonOk.setEnabled(enabled); /* * If renaming, only enable button OK if new name is not equal * to the old one. */ if (enabled && id >= 0) buttonOk.setEnabled(!newName.equals(name)); } }); }
From source file:cm.aptoide.pt.ScheduledDownloads.java
private void continueLoading() { lv = (ListView) findViewById(android.R.id.list); db = Database.getInstance();/* w ww. ja va 2s .com*/ adapter = new CursorAdapter(this, null, CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER) { @Override public View newView(Context context, Cursor arg1, ViewGroup arg2) { return LayoutInflater.from(context).inflate(R.layout.row_sch_download, null); } @Override public void bindView(View convertView, Context arg1, Cursor c) { // Planet to display ScheduledDownload scheduledDownload = scheduledDownloadsHashMap.get(c.getString(0)); // The child views in each row. CheckBox checkBoxScheduled; TextView textViewName; TextView textViewVersion; ImageView imageViewIcon; // Create a new row view if (convertView.getTag() == null) { // Find the child views. textViewName = (TextView) convertView.findViewById(R.id.name); textViewVersion = (TextView) convertView.findViewById(R.id.appversion); checkBoxScheduled = (CheckBox) convertView.findViewById(R.id.schDwnChkBox); imageViewIcon = (ImageView) convertView.findViewById(R.id.appicon); // Optimization: Tag the row with it's child views, so we don't have to // call findViewById() later when we reuse the row. convertView.setTag(new Holder(textViewName, textViewVersion, checkBoxScheduled, imageViewIcon)); // If CheckBox is toggled, update the planet it is tagged with. checkBoxScheduled.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { CheckBox cb = (CheckBox) v; ScheduledDownload schDownload = (ScheduledDownload) cb.getTag(); schDownload.setChecked(cb.isChecked()); } }); } // Reuse existing row view else { // Because we use a ViewHolder, we avoid having to call findViewById(). Holder viewHolder = (Holder) convertView.getTag(); checkBoxScheduled = viewHolder.checkBoxScheduled; textViewVersion = viewHolder.textViewVersion; textViewName = viewHolder.textViewName; imageViewIcon = viewHolder.imageViewIcon; } // Tag the CheckBox with the Planet it is displaying, so that we can // access the planet in onClick() when the CheckBox is toggled. checkBoxScheduled.setTag(scheduledDownload); // Display planet data checkBoxScheduled.setChecked(scheduledDownload.isChecked()); textViewName.setText(scheduledDownload.getName()); textViewVersion.setText(scheduledDownload.getVername()); // Tag the CheckBox with the Planet it is displaying, so that we can // access the planet in onClick() when the CheckBox is toggled. checkBoxScheduled.setTag(scheduledDownload); // Display planet data checkBoxScheduled.setChecked(scheduledDownload.isChecked()); textViewName.setText(scheduledDownload.getName()); textViewVersion.setText("" + scheduledDownload.getVername()); ImageLoader.getInstance().displayImage(scheduledDownload.getIconPath(), imageViewIcon); } }; lv.setAdapter(adapter); getSupportLoaderManager().initLoader(0, null, this); lv.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> arg0, View item, int arg2, long arg3) { ScheduledDownload scheduledDownload = (ScheduledDownload) ((Holder) item.getTag()).checkBoxScheduled .getTag(); scheduledDownload.toggleChecked(); Holder viewHolder = (Holder) item.getTag(); viewHolder.checkBoxScheduled.setChecked(scheduledDownload.isChecked()); } }); IntentFilter filter = new IntentFilter("pt.caixamagica.aptoide.REDRAW"); registerReceiver(receiver, filter); Button installButton = (Button) findViewById(R.id.sch_down); // installButton.setText(getText(R.string.schDown_installselected)); installButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { if (isAllChecked()) { for (String scheduledDownload : scheduledDownloadsHashMap.keySet()) { if (scheduledDownloadsHashMap.get(scheduledDownload).checked) { ScheduledDownload schDown = scheduledDownloadsHashMap.get(scheduledDownload); ViewApk apk = new ViewApk(); apk.setApkid(schDown.getApkid()); apk.setName(schDown.getName()); apk.setVercode(schDown.getVercode()); apk.setIconPath(schDown.getIconPath()); apk.setVername(schDown.getVername()); apk.setRepoName(schDown.getRepoName()); serviceDownloadManager .startDownloadWithWebservice(serviceDownloadManager.getDownload(apk), apk); Toast toast = Toast.makeText(ScheduledDownloads.this, R.string.starting_download, Toast.LENGTH_SHORT); toast.show(); } } } else { Toast toast = Toast.makeText(ScheduledDownloads.this, R.string.schDown_nodownloadselect, Toast.LENGTH_SHORT); toast.show(); } } }); if (getIntent().hasExtra("downloadAll")) { Builder dialogBuilder = new AlertDialog.Builder(this); final AlertDialog scheduleDownloadDialog = dialogBuilder.create(); scheduleDownloadDialog.setTitle(getText(R.string.schDwnBtn)); scheduleDownloadDialog.setIcon(android.R.drawable.ic_dialog_alert); scheduleDownloadDialog.setCancelable(false); scheduleDownloadDialog.setMessage(getText(R.string.schDown_install)); scheduleDownloadDialog.setButton(Dialog.BUTTON_POSITIVE, getString(android.R.string.yes), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { for (String scheduledDownload : scheduledDownloadsHashMap.keySet()) { ScheduledDownload schDown = scheduledDownloadsHashMap.get(scheduledDownload); ViewApk apk = new ViewApk(); apk.setApkid(schDown.getApkid()); apk.setName(schDown.getName()); apk.setVercode(schDown.getVercode()); apk.setIconPath(schDown.getIconPath()); apk.setVername(schDown.getVername()); apk.setRepoName(schDown.getRepoName()); serviceDownloadManager .startDownloadWithWebservice(serviceDownloadManager.getDownload(apk), apk); Toast toast = Toast.makeText(ScheduledDownloads.this, R.string.starting_download, Toast.LENGTH_SHORT); toast.show(); } finish(); } }); scheduleDownloadDialog.setButton(Dialog.BUTTON_NEGATIVE, getString(android.R.string.no), new Dialog.OnClickListener() { @Override public void onClick(DialogInterface arg0, int arg1) { finish(); } }); scheduleDownloadDialog.show(); } }
From source file:net.fabiszewski.ulogger.MainActivity.java
/** * Display About dialog//from ww w.j ava2 s . c om */ private void showAbout() { @SuppressLint("InflateParams") View view = getLayoutInflater().inflate(R.layout.about, null, false); AlertDialog alertDialog = new AlertDialog.Builder(MainActivity.this).create(); alertDialog.setTitle(getString(R.string.app_name)); alertDialog.setView(view); alertDialog.setIcon(R.drawable.ic_ulogger_logo_24dp); alertDialog.setButton(AlertDialog.BUTTON_NEUTRAL, getString(R.string.ok), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); alertDialog.show(); final TextView versionLabel = (TextView) alertDialog.findViewById(R.id.about_version); versionLabel.setText(getString(R.string.about_version, BuildConfig.VERSION_NAME)); final TextView descriptionLabel = (TextView) alertDialog.findViewById(R.id.about_description); final TextView description2Label = (TextView) alertDialog.findViewById(R.id.about_description2); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) { descriptionLabel.setText(fromHtmlDepreciated(getString(R.string.about_description))); description2Label.setText(fromHtmlDepreciated(getString(R.string.about_description2))); } else { descriptionLabel.setText( Html.fromHtml(getString(R.string.about_description), android.text.Html.FROM_HTML_MODE_LEGACY)); description2Label.setText( Html.fromHtml(getString(R.string.about_description2), android.text.Html.FROM_HTML_MODE_LEGACY)); } }
From source file:org.trosnoth.serveradmin.UpgradeActivity.java
private void showUpgradeDialog(int position) { AlertDialog.Builder builder;//from w w w .j a va 2s . c om AlertDialog alertDialog; Context mContext = UpgradeActivity.this; LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(LAYOUT_INFLATER_SERVICE); View layout = inflater.inflate(R.layout.upgrade_dialog, (ViewGroup) findViewById(R.id.layout_root)); final Upgrade upgrade = adapter.getItem(position); final EditText stars = (EditText) layout.findViewById(R.id.editStars); stars.setText(Integer.toString(upgrade.starCost)); final EditText time = (EditText) layout.findViewById(R.id.editTime); time.setText(Double.toString(upgrade.timeLimit)); builder = new AlertDialog.Builder(mContext); builder.setView(layout); alertDialog = builder.create(); alertDialog.setTitle(upgrade.name); alertDialog.setButton(-1, getApplicationContext().getString(R.string.save), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { if (stars.getText().length() > 0) { telnet.send("getGame().setUpgradeCost('" + upgrade.id + "', " + stars.getText() + ")"); } if (time.getText().length() > 0) { telnet.send("getGame().setUpgradeTime('" + upgrade.id + "', " + time.getText() + ")"); } update(); } }); alertDialog.setButton(-2, getApplicationContext().getString(R.string.cancel), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }); alertDialog.show(); }
From source file:ch.bfh.instacircle.NetworkActiveActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { Intent intent = null;/*w w w.j a v a 2s . c o m*/ switch (item.getItemId()) { case R.id.display_qrcode: // displaying the QR code SharedPreferences preferences = getSharedPreferences(PREFS_NAME, 0); String config = preferences.getString("SSID", "N/A") + "||" + preferences.getString("password", "N/A"); try { intent = new Intent("com.google.zxing.client.android.ENCODE"); intent.putExtra("ENCODE_TYPE", "TEXT_TYPE"); intent.putExtra("ENCODE_DATA", config); intent.putExtra("ENCODE_FORMAT", "QR_CODE"); intent.putExtra("ENCODE_SHOW_CONTENTS", false); startActivity(intent); } catch (ActivityNotFoundException e) { // if the "Barcode Scanner" application is not installed ask the // user if he wants to install it AlertDialog alertDialog = new AlertDialog.Builder(this).create(); alertDialog.setTitle("InstaCircle - Barcode Scanner Required"); alertDialog.setMessage( "In order to use this feature, the Application \"Barcode Scanner\" must be installed. Install now?"); alertDialog.setButton(AlertDialog.BUTTON_POSITIVE, "Yes", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); // redirect to Google Play try { startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=com.google.zxing.client.android"))); } catch (Exception e) { Log.d(TAG, "Unable to find market. User will have to install ZXing himself"); } } }); alertDialog.setButton(AlertDialog.BUTTON_NEGATIVE, "No", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); alertDialog.show(); } return true; case R.id.leave_network: // Display a confirm dialog asking whether really to leave AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle("Leave Network?"); builder.setMessage("Do you really want to leave this conversation?"); builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { if (isServiceRunning()) { String identification = getSharedPreferences(PREFS_NAME, 0).getString("identification", "N/A"); Message message = new Message(identification, Message.MSG_MSGLEAVE, identification, NetworkDbHelper.getInstance(NetworkActiveActivity.this).getNextSequenceNumber()); Intent intent = new Intent("messageSend"); intent.putExtra("message", message); LocalBroadcastManager.getInstance(NetworkActiveActivity.this).sendBroadcast(intent); } else { NetworkDbHelper.getInstance(NetworkActiveActivity.this).closeConversation(); NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.cancelAll(); Intent intent = new Intent(NetworkActiveActivity.this, MainActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK); startActivity(intent); } } }); builder.setNegativeButton("No", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { return; } }); AlertDialog dialog = builder.create(); dialog.show(); return true; case R.id.write_nfc_tag: if (!nfcAdapter.isEnabled()) { // if nfc is available but deactivated ask the user whether he // wants to enable it. If yes, redirect to the settings. AlertDialog alertDialog = new AlertDialog.Builder(this).create(); alertDialog.setTitle("InstaCircle - NFC needs to be enabled"); alertDialog.setMessage("In order to use this feature, NFC must be enabled. Enable now?"); alertDialog.setButton(AlertDialog.BUTTON_POSITIVE, "Yes", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); startActivity(new Intent(android.provider.Settings.ACTION_WIRELESS_SETTINGS)); } }); alertDialog.setButton(AlertDialog.BUTTON_NEGATIVE, "No", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); alertDialog.show(); } else { // display a progress dialog waiting for the NFC tag to be // tapped writeNfcEnabled = true; writeNfcTagDialog = new ProgressDialog(this); writeNfcTagDialog.setTitle("InstaCircle - Share Networkconfiguration with NFC Tag"); writeNfcTagDialog.setMessage("Please tap a writeable NFC Tag on the back of your device..."); writeNfcTagDialog.setCancelable(false); writeNfcTagDialog.setButton(DialogInterface.BUTTON_NEGATIVE, "Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { writeNfcEnabled = false; dialog.dismiss(); } }); writeNfcTagDialog.show(); } default: return super.onOptionsItemSelected(item); } }
From source file:net.fabiszewski.ulogger.MainActivity.java
/** * Called when the user clicks the track text view * @param view View// w w w. ja va 2 s. com */ public void trackSummary(@SuppressWarnings("UnusedParameters") View view) { final TrackSummary summary = db.getTrackSummary(); if (summary == null) { showToast(getString(R.string.no_positions)); return; } @SuppressLint("InflateParams") View summaryView = getLayoutInflater().inflate(R.layout.summary, null, false); AlertDialog alertDialog = new AlertDialog.Builder(MainActivity.this).create(); alertDialog.setTitle(getString(R.string.track_summary)); alertDialog.setView(summaryView); alertDialog.setIcon(R.drawable.ic_equalizer_white_24dp); alertDialog.setButton(AlertDialog.BUTTON_NEUTRAL, getString(R.string.ok), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); alertDialog.show(); final TextView summaryDistance = (TextView) alertDialog.findViewById(R.id.summary_distance); final TextView summaryDuration = (TextView) alertDialog.findViewById(R.id.summary_duration); final TextView summaryPositions = (TextView) alertDialog.findViewById(R.id.summary_positions); double distance = (double) summary.getDistance() / 1000; String unitName = getString(R.string.unit_kilometer); if (pref_units.equals(getString(R.string.pref_units_imperial))) { distance *= KM_MILE; unitName = getString(R.string.unit_mile); } final NumberFormat nf = NumberFormat.getInstance(); nf.setMaximumFractionDigits(2); final String distanceString = nf.format(distance); summaryDistance.setText(getString(R.string.summary_distance, distanceString, unitName)); final long h = summary.getDuration() / 3600; final long m = summary.getDuration() % 3600 / 60; summaryDuration.setText(getString(R.string.summary_duration, h, m)); int positionsCount = (int) summary.getPositionsCount(); if (needsPluralFewHack(positionsCount)) { summaryPositions.setText(getResources().getString(R.string.summary_positions_few, positionsCount)); } else { summaryPositions.setText( getResources().getQuantityString(R.plurals.summary_positions, positionsCount, positionsCount)); } }
From source file:hr.foicore.varazdinlandmarksdemo.POIMapActivity.java
public void handleQRcodeScanRequest() { Intent intent = new Intent("com.google.zxing.client.android.SCAN"); intent.putExtra("SCAN_MODE", "QR_CODE_MODE"); intent.putExtra("SAVE_HISTORY", false); try {/*from w w w. ja va 2 s .c o m*/ startActivityForResult(intent, 0); // request code is 0 } catch (ActivityNotFoundException e) { // No application to view, ask to download one AlertDialog alertDialog = new AlertDialog.Builder(POIMapActivity.this).create();// context).create(); alertDialog.setTitle(getResources().getString(R.string.qr_scanner_not_found)); alertDialog.setMessage(getResources().getString(R.string.install_it_now_question)); alertDialog.setButton(Dialog.BUTTON_NEGATIVE, getResources().getString(R.string.no), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { } }); alertDialog.setButton(Dialog.BUTTON_POSITIVE, getResources().getString(R.string.yes), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { try { // TODO test this startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://search?q=qr+scanner&c=apps"))); } catch (android.content.ActivityNotFoundException anfe) { startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://play.google.com/store/search?q=qr+scanner&c=apps"))); } } }); alertDialog.show(); } }
From source file:au.com.wallaceit.reddinator.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); context = MainActivity.this; global = ((GlobalObjects) context.getApplicationContext()); prefs = PreferenceManager.getDefaultSharedPreferences(context); setContentView(R.layout.activity_main); // Setup actionbar appView = findViewById(R.id.appview); actionBar = getActionBar();/*www .ja va2 s.c o m*/ if (actionBar != null) { actionBar.setDisplayShowHomeEnabled(false); actionBar.setDisplayShowCustomEnabled(true); actionBar.setDisplayShowTitleEnabled(false); actionBar.setCustomView(R.layout.appheader); } // get actionBar Views loader = (ProgressBar) findViewById(R.id.appsrloader); errorIcon = (ImageView) findViewById(R.id.apperroricon); refreshbutton = (ImageButton) findViewById(R.id.apprefreshbutton); configbutton = (ImageButton) findViewById(R.id.appprefsbutton); srtext = (TextView) findViewById(R.id.appsubreddittxt); // set theme colors setThemeColors(); // setup button onclicks refreshbutton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { listAdapter.reloadReddits(); } }); View.OnClickListener srclick = new View.OnClickListener() { @Override public void onClick(View view) { Intent srintent = new Intent(context, SubredditSelectActivity.class); startActivityForResult(srintent, 0); } }; View.OnClickListener configclick = new View.OnClickListener() { @Override public void onClick(View view) { Intent prefsintent = new Intent(context, PrefsActivity.class); prefsintent.putExtra("fromapp", true); startActivityForResult(prefsintent, 0); } }; srtext.setOnClickListener(srclick); configbutton.setOnClickListener(configclick); findViewById(R.id.app_logo).setOnClickListener(srclick); // Setup list adapter listView = (ListView) findViewById(R.id.applistview); listAdapter = new ReddinatorListAdapter(global, prefs); listView.setAdapter(listAdapter); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) { openLink(position, 1); } }); listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> adapterView, View view, int i, long l) { final int position = i; AlertDialog linkDialog = new AlertDialog.Builder(context).create(); //Read Update linkDialog.setTitle("Open in browser"); linkDialog.setButton(DialogInterface.BUTTON_POSITIVE, "Comments", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { openLink(position, 3); } }); linkDialog.setButton(DialogInterface.BUTTON_NEUTRAL, "Content", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { openLink(position, 2); } }); linkDialog.show(); return true; } }); // set the current subreddit srtext.setText(prefs.getString("currentfeed-app", "technology")); // Trigger reload? if (prefs.getBoolean("appreloadpref", false) || listAdapter.getCount() < 2) listAdapter.reloadReddits(); }