List of usage examples for android.app AlertDialog.Builder setView
public void setView(View view)
From source file:com.entradahealth.entrada.android.app.personal.activities.job_list.JobListActivity.java
private void showLicensing() { LayoutInflater inflater = LayoutInflater.from(this); View view = inflater.inflate(R.layout.license_dialog, null); TextView textview = (TextView) view.findViewById(R.id.license_text); InputStream is = getResources().openRawResource(R.raw.licenses); try {//from w w w . j a v a 2 s . co m textview.setText(CharStreams.toString(new InputSupplier<InputStreamReader>() { public InputStreamReader getInput() throws IOException { return new InputStreamReader(getResources().openRawResource(R.raw.licenses)); } })); } catch (IOException ex) { Toast.makeText(this, "Sorry, error displaying licenses. Contact support for license details.", Toast.LENGTH_SHORT); } AlertDialog.Builder alertDialog = new AlertDialog.Builder(this); alertDialog.setTitle("License Information"); // alertDialog.setMessage("Here is a really long message."); alertDialog.setView(view); AlertDialog alert = alertDialog.create(); alert.show(); }
From source file:com.becapps.easydownloader.ShareActivity.java
void showGeneralInfoTutorial() { generalInfoCheckboxEnabled = settings.getBoolean("general_info", true); if (generalInfoCheckboxEnabled == true) { AlertDialog.Builder adb = new AlertDialog.Builder(boxThemeContextWrapper); LayoutInflater adbInflater = LayoutInflater.from(ShareActivity.this); View generalInfo = adbInflater.inflate(R.layout.dialog_general_info, null); generalInfoScrollview = (ScrollView) generalInfo.findViewById(R.id.generalInfoScrollview); showAgain1 = (CheckBox) generalInfo.findViewById(R.id.showAgain1); showAgain1.setChecked(true);/* w ww . j a v a 2 s . c o m*/ adb.setView(generalInfo); adb.setTitle(getString(R.string.tutorial_title)); //adb.setMessage(getString(R.string.tutorial_msg)); adb.setPositiveButton("OK", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { if (!showAgain1.isChecked()) { SharedPreferences.Editor editor = settings.edit(); editor.putBoolean("general_info", false); editor.commit(); sshInfoCheckboxEnabled = settings.getBoolean("general_info", true); Utils.logger("d", "generalInfoCheckboxEnabled: " + generalInfoCheckboxEnabled, DEBUG_TAG); } } }); if (!((Activity) this).isFinishing()) { adb.show(); } } }
From source file:com.elpstudio.player.EqualizerActivity.java
/** * Builds the "Save Preset" dialog. Does not call the show() method, so you * should do this manually when calling this method. * //from w w w . jav a 2 s . c o m * @return A fully built AlertDialog reference. */ private AlertDialog buildSavePresetDialog() { AlertDialog.Builder builder = new AlertDialog.Builder(this); View dialogView = getLayoutInflater().inflate(R.layout.add_new_equalizer_preset_dialog_layout, null); final EditText newPresetNameField = (EditText) dialogView.findViewById(R.id.new_preset_name_text_field); //newPresetNameField.setTypeface(TypefaceHelper.getTypeface(mContext, "Roboto-Light")); newPresetNameField.setPaintFlags( newPresetNameField.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG); //Set the dialog title. builder.setTitle("Save Preset"); builder.setView(dialogView); builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int arg1) { dialog.dismiss(); } }); builder.setPositiveButton("Done", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { //Get the preset name from the text field. if (newPresetNameField.getText().toString().trim().length() > 0) { String presetName = newPresetNameField.getText().toString(); //Add the preset and it's values to the DB. mApp.getDBAccessHelper().addNewEQPreset(presetName, fiftyHertzLevel, oneThirtyHertzLevel, threeTwentyHertzLevel, eightHundredHertzLevel, twoKilohertzLevel, fiveKilohertzLevel, twelvePointFiveKilohertzLevel, (short) virtualizerSeekBar.getProgress(), (short) bassBoostSeekBar.getProgress(), (short) reverbSpinner.getSelectedItemPosition()); Toast.makeText(mContext, "Saved .. commented", Toast.LENGTH_SHORT).show(); dialog.dismiss(); } } }); return builder.create(); }
From source file:com.mibr.android.intelligentreminder.INeedToo.java
@Override public Dialog onCreateDialog(int id) { switch (id) { case DIALOG_REMINDER_CONTACTS_SERVICE_FAILED_LICENSING: AlertDialog.Builder buildersvc = new AlertDialog.Builder(this); buildersvc.setMessage(//ww w . ja va 2 s .com "The Reminder Contact Service add-on that you've got installed is not a licensed version"); buildersvc.setCancelable(false) .setNeutralButton(R.string.msg_cus, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { String[] mailto = { "info@intelligentreminder.com", "" }; Intent sendIntent = new Intent(Intent.ACTION_SEND); sendIntent.putExtra(Intent.EXTRA_EMAIL, mailto); sendIntent.putExtra(Intent.EXTRA_SUBJECT, "".toString()); sendIntent.putExtra(Intent.EXTRA_TEXT, "".toString()); sendIntent.setType("text/plain"); startActivity(Intent.createChooser(sendIntent, "Send EMail...")); } }).setPositiveButton(R.string.msg_register, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { if (INeedToo.IS_ANDROID_VERSION) { String uri = getString(R.string.indeedtopayforservice); Intent ii3 = new Intent(Intent.ACTION_VIEW, Uri.parse(uri)); startActivity(ii3); } else { Uri uri = Uri.parse( "http://www.amazon.com/gp/mas/dl/android?p=com.mibr.android.remindercontacts"); Intent intent = new Intent(Intent.ACTION_VIEW, uri); startActivity(intent); } isReminderContactsAvailable = true; iDidReminderContacts = false; } }).setNegativeButton(R.string.msg_cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { } }); AlertDialog alert = buildersvc.create(); return alert; case DOING_SAMPLE_NEEDS_DIALOG: if (allItems == null) { return null; } dialogDoingSamples = new Dialog(this); dialogDoingSamples.setOwnerActivity(this); dialogDoingSamples.setContentView(R.layout.ineedvoiceprogress); dialogDoingSamples.setTitle("Working ..."); ((Button) dialogDoingSamples.findViewById(R.id.needvoiceprogress_cancel)).setEnabled(true); ((Button) dialogDoingSamples.findViewById(R.id.needvoiceprogress_ok)).setEnabled(false); ; // dialogDoingSamples.show(); ArrayList stuff = new ArrayList(); stuff.add(dialogDoingSamples); stuff.add(getApplicationContext()); stuff.add(this); stuff.add(getLocationManager()); stuff.add(getDbAdapter()); stuff.add(allItems.get(whereImAtInAllItems)); stuff.add(new Integer(1)); new NeedByVoiceProgress().execute(stuff); return dialogDoingSamples; case DIALOG_SAMPLES: Dialog aDialog = null; AlertDialog.Builder builder2; LayoutInflater inflater2 = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE); View layout2 = inflater2.inflate(R.layout.ineedsamples, (ViewGroup) findViewById(R.id.hijklmnop)); builder2 = new AlertDialog.Builder(this); builder2.setView(layout2); builder2.setTitle("Build Sample Data Set"); builder2.setPositiveButton("Okay", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { allItems = new ArrayList<ArrayList<String>>(); Boolean doit = false; StringBuilder sb = new StringBuilder(); StringBuilder sb2 = new StringBuilder(); StringBuilder sb3 = new StringBuilder(); int cnt = 0; Boolean dw = false; ArrayList<String> jdmatchesSS = null; ; sb.append("I need Print Cartridges description HP 28 and 48 "); if (mWalmart != null && mWalmart.isChecked()) { sb.append(" location Walmart "); dw = true; } if (mWalgreens != null && mWalgreens.isChecked()) { sb.append(" location Walgreens "); dw = true; } if (dw) { // they checked something doit = true; jdmatchesSS = new ArrayList<String>(); jdmatchesSS.add(sb.toString()); allItems.add(jdmatchesSS); cnt++; } if (mSevenEleven != null && mSevenEleven.isChecked()) { sb3.append("I need Energy Drink description Red Bull location 7-Eleven "); ArrayList<String> jdmatches = new ArrayList<String>(); jdmatches.add(sb3.toString()); allItems.add(jdmatches); cnt++; doit = true; } if (mStarbucks != null && mStarbucks.isChecked()) { sb2.append("I need Coffee description French Roast location Starbucks"); ArrayList<String> jdmatches = new ArrayList<String>(); jdmatches.add(sb2.toString()); allItems.add(jdmatches); cnt++; doit = true; } if (doit) { whereImAtInAllItems = 0; INeedToo.this.showDialog(DOING_SAMPLE_NEEDS_DIALOG); } } }); mWalmart = (CheckBox) layout2.findViewById(R.id.BuildWalmart); mWalgreens = (CheckBox) layout2.findViewById(R.id.BuildWalgreens); mSevenEleven = (CheckBox) layout2.findViewById(R.id.Build7Eleven); mStarbucks = (CheckBox) layout2.findViewById(R.id.BuildStarbucks); aDialog = builder2.create(); return aDialog; case DIALOG_SPLASH: /* jdd=new Dialog(mContext); jdd.setContentView(R.layout.ineed2splash); jdd.setTitle("W E L C O M E"); */ AlertDialog.Builder builder; LayoutInflater inflater = (LayoutInflater) this.getSystemService(LAYOUT_INFLATER_SERVICE); View layout = inflater.inflate(R.layout.ineed2splashv2, (ViewGroup) findViewById(R.id.ScrollView01lmnop2)); builder = new AlertDialog.Builder(this); builder.setPositiveButton("Okay", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { if (mWantSample != null) { if (mWantSample.isChecked()) { showDialog(DIALOG_SAMPLES); } } } }); builder.setTitle("W E L C O M E"); if (getDbAdapter().thereAreSomeLocationsOnSystem()) { LinearLayout ll = (LinearLayout) layout.findViewById(R.id.CreateDefaultValues); ll.setVisibility(View.INVISIBLE); } else { mWantSample = (CheckBox) layout.findViewById(R.id.BuildDefaultValues); } builder.setView(layout); jdd = builder.create(); //Button butt=(Button)jdd.findViewById(R.id.Button01); /*butt.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { jdd.cancel(); } }); */ break; default: return null; } return jdd; }
From source file:com.aniruddhc.acemusic.player.EqualizerActivity.EqualizerActivity.java
/** * Builds the "Save Preset" dialog. Does not call the show() method, so you * should do this manually when calling this method. * // w ww . ja va 2 s . c o m * @return A fully built AlertDialog reference. */ private AlertDialog buildSavePresetDialog() { AlertDialog.Builder builder = new AlertDialog.Builder(this); View dialogView = getLayoutInflater().inflate(R.layout.add_new_equalizer_preset_dialog_layout, null); final EditText newPresetNameField = (EditText) dialogView.findViewById(R.id.new_preset_name_text_field); newPresetNameField.setTypeface(TypefaceHelper.getTypeface(mContext, "Roboto-Light")); newPresetNameField.setPaintFlags( newPresetNameField.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG); //Set the dialog title. builder.setTitle(R.string.save_preset); builder.setView(dialogView); builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int arg1) { dialog.dismiss(); } }); builder.setPositiveButton(R.string.done, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { //Get the preset name from the text field. String presetName = newPresetNameField.getText().toString(); //Add the preset and it's values to the DB. mApp.getDBAccessHelper().addNewEQPreset(presetName, fiftyHertzLevel, oneThirtyHertzLevel, threeTwentyHertzLevel, eightHundredHertzLevel, twoKilohertzLevel, fiveKilohertzLevel, twelvePointFiveKilohertzLevel, (short) virtualizerSeekBar.getProgress(), (short) bassBoostSeekBar.getProgress(), (short) reverbSpinner.getSelectedItemPosition()); Toast.makeText(mContext, R.string.preset_saved, Toast.LENGTH_SHORT).show(); dialog.dismiss(); } }); return builder.create(); }
From source file:com.bluros.music.widgets.SleepModeDialog.java
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { context = getActivity().getBaseContext(); Intent action = new Intent(MusicService.SLEEP_MODE_STOP_ACTION); ComponentName serviceName = new ComponentName(context, MusicService.class); action.setComponent(serviceName);// w w w. j a va 2s . c om pendingIntent = PendingIntent.getService(context, 4, action, 0); alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); LayoutInflater inflater = (LayoutInflater) getActivity().getSystemService(context.LAYOUT_INFLATER_SERVICE); View view = inflater.inflate(R.layout.sleep_mode_time_selector, null); int minutes = Integer.valueOf(getString(R.string.default_interval)); final TextView tvPopUpTime = (TextView) view.findViewById(R.id.pop_up_time); tvPopUpTime.setText(String.valueOf(minutes)); final SeekBar sBar = (SeekBar) view.findViewById(R.id.seekbar); sBar.setProgress(minutes - 1); sBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar arg0, int arg1, boolean arg2) { tvPopUpTime.setText(String.valueOf(arg1 + 1)); } @Override public void onStartTrackingTouch(SeekBar arg0) { } @Override public void onStopTrackingTouch(SeekBar arg0) { } }); builder.setTitle(R.string.select_quit_time); builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int arg1) { long timeLeft = (sBar.getProgress() + 1) * mMill; alarmManager.set(AlarmManager.RTC_WAKEUP, timeLeft + System.currentTimeMillis(), pendingIntent); MusicPlayer.setSleepMode(true); Toast.makeText(context, String.format(getString(R.string.quit_warining), sBar.getProgress() + 1), Toast.LENGTH_SHORT).show(); dialog.dismiss(); } }); builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int arg1) { dialog.dismiss(); } }); builder.setView(view); return builder.create(); }
From source file:com.safecell.LoginActivity.java
void dialogforWebview() { AlertDialog.Builder builder; Context mContext = LoginActivity.this; LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(LAYOUT_INFLATER_SERVICE); View layout = inflater.inflate(R.layout.private_policy_layout, (ViewGroup) findViewById(R.id.layout_root)); final Activity activity = LoginActivity.this; wv = (WebView) layout.findViewById(R.id.webview); wv.getSettings().setJavaScriptEnabled(true); wv.getSettings().setJavaScriptCanOpenWindowsAutomatically(true); wv.setWebViewClient(new HelloWebViewClient()); wv.setWebChromeClient(new WebChromeClient() { public void onProgressChanged(WebView view, int newProgress) { activity.setProgress(newProgress * 100); if (newProgress == 100) { }/*from w w w . j a v a2 s . c o m*/ }; }); wv.setWebViewClient(new WebViewClient() { public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { // Log.v("errorCode", "errorcode "+errorCode + description); alertDialogForTermsConditions.cancel(); } }); // wv.loadUrl(URLs.REMOTE_URL + // "api/1/site_setting/terms_of_service.html"); wv.loadUrl("file:///android_asset/terms_of_service.html"); builder = new AlertDialog.Builder(mContext); builder.setView(layout); builder.setTitle("Policy"); builder.setPositiveButton("Accept", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { isTermsAcepted = true; dialog.cancel(); } }).setNegativeButton("Don't Accept", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { isTermsAcepted = false; dialog.cancel(); quitDialog("License", "Terms and conditions should accept. "); } }); alertDialogForTermsConditions = builder.create(); if (progressDialog != null && progressDialog.isShowing()) { progressDialog.dismiss(); } try { alertDialogForTermsConditions.show(); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.ifeel.healthy.SelectionFragment.java
private void openHtml(String htmlFile, String title) { AlertDialog.Builder alert = new AlertDialog.Builder(getActivity()); alert.setTitle(title);/*from w w w . j a v a 2 s .c o m*/ WebView wv = new WebView(getActivity()); // loading the html file String htmlData = readAsset(htmlFile); //wv.loadUrl("http://ws-na.amazon-adsystem.com/widgets/q?ServiceVersion=20070822&OneJS=1&Operation=GetAdHtml&MarketPlace=US&source=ac&ref=tf_til&ad_type=product_link&tracking_id=ifeelmobiltec-20&marketplace=amazon®ion=US&placement=B007S088F4&asins=B007S088F4&linkId=JCQFMHWLLV5N2SZO&show_border=true&link_opens_in_new_window=true"); wv.loadDataWithBaseURL("file:///android_asset/", htmlData, "text/html", "UTF-8", null); alert.setView(wv); alert.setNegativeButton(getActivity().getString(R.string.close), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { dialog.dismiss(); } }); alert.create(); alert.show(); }
From source file:com.dahl.brendan.wordsearch.view.WordSearchActivity.java
@Override protected Dialog onCreateDialog(int id) { Dialog dialog;/* w w w .j av a2 s . c o m*/ switch (id) { case DIALOG_ID_NO_WORDS: { final DialogNoWordsListener DIALOG_LISTENER_NO_WORDS = new DialogNoWordsListener(); AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setMessage(R.string.no_words); builder.setNegativeButton(R.string.category, DIALOG_LISTENER_NO_WORDS); builder.setPositiveButton(R.string.new_game, DIALOG_LISTENER_NO_WORDS); builder.setNeutralButton(R.string.size, DIALOG_LISTENER_NO_WORDS); dialog = builder.create(); break; } case DIALOG_ID_NO_WORDS_CUSTOM: { final DialogNoWordsCustomListener DIALOG_LISTENER_NO_WORDS_CUSTOM = new DialogNoWordsCustomListener(); AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setMessage(R.string.no_words_custom); builder.setNegativeButton(R.string.category, DIALOG_LISTENER_NO_WORDS_CUSTOM); builder.setPositiveButton(R.string.custom_editor, DIALOG_LISTENER_NO_WORDS_CUSTOM); dialog = builder.create(); break; } case DIALOG_ID_GAME_OVER: { final DialogGameOverListener DIALOG_LISTENER_GAME_OVER = new DialogGameOverListener(); AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setMessage("blank"); EditText text = new EditText(this); text.setSingleLine(); text.setId(android.R.id.input); builder.setView(text); builder.setPositiveButton(R.string.SAVE_SUBMIT, DIALOG_LISTENER_GAME_OVER); builder.setNeutralButton(R.string.SAVE, DIALOG_LISTENER_GAME_OVER); builder.setOnCancelListener(DIALOG_LISTENER_GAME_OVER); dialog = builder.create(); break; } case DIALOG_ID_HIGH_SCORES_LOCAL_SHOW: { final DialogHighScoresLocalShowListener DIALOG_LISTENER_HIGH_SCORES_SHOW = new DialogHighScoresLocalShowListener(); AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setMessage("blank"); builder.setTitle(R.string.LOCAL_HIGH_SCORES); builder.setNegativeButton(R.string.reset, DIALOG_LISTENER_HIGH_SCORES_SHOW); builder.setNeutralButton(android.R.string.ok, DIALOG_LISTENER_HIGH_SCORES_SHOW); builder.setPositiveButton(R.string.GLOBAL, DIALOG_LISTENER_HIGH_SCORES_SHOW); dialog = builder.create(); break; } case DIALOG_ID_GAME_NEW: { final DialogGameNewListener DIALOG_LISTENER_GAME_NEW = new DialogGameNewListener(); AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setMessage(this.getString(R.string.game_over)); builder.setPositiveButton(R.string.new_game, DIALOG_LISTENER_GAME_NEW); builder.setNeutralButton(R.string.REPLAY, DIALOG_LISTENER_GAME_NEW); builder.setNegativeButton(android.R.string.cancel, DIALOG_LISTENER_GAME_NEW); dialog = builder.create(); break; } case DIALOG_ID_INTRO_INPUT_TYPE: { final DialogIntroListener DIALOG_LISTENER_INTRO = new DialogIntroListener(); AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setMessage(R.string.INTRO); builder.setPositiveButton(R.string.tap, DIALOG_LISTENER_INTRO); builder.setNeutralButton(android.R.string.cancel, DIALOG_LISTENER_INTRO); builder.setNegativeButton(R.string.drag, DIALOG_LISTENER_INTRO); dialog = builder.create(); break; } case DIALOG_ID_INTRO_DONATE: { final DialogInterface.OnClickListener LISTENER = new DialogIntroDonateListener(); AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setMessage(R.string.INTRO_DONATE_MSG); builder.setPositiveButton(R.string.DONATE, LISTENER); builder.setNegativeButton(R.string.DONATE_NO, LISTENER); dialog = builder.create(); break; } case DIALOG_ID_DONATE: { final DialogInterface.OnClickListener LISTENER = new DialogDonateListener(); AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setMessage(R.string.DONATE_MSG); builder.setPositiveButton(R.string.DONATE_MARKET, LISTENER); builder.setNeutralButton(R.string.DONATE_WEB, LISTENER); builder.setNegativeButton(R.string.DONATE_NO, LISTENER); dialog = builder.create(); break; } default: dialog = super.onCreateDialog(id); break; } return dialog; }
From source file:za.co.neilson.alarm.preferences.AlarmPreferencesActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // requestWindowFeature(Window.FEATURE_NO_TITLE); ActionBar actionBar = getSupportActionBar(); actionBar.setDisplayHomeAsUpEnabled(true); setContentView(R.layout.alarm_preferences); pref = getSharedPreferences("AppPref", MODE_PRIVATE); email = getIntent().getStringExtra("email"); Log.d("? ???!!! ", "" + email); Bundle bundle = getIntent().getExtras(); if (bundle != null && bundle.containsKey("alarm")) { setMathAlarm((Alarm) bundle.getSerializable("alarm")); } else {//from w w w .j a v a2s . co m setMathAlarm(new Alarm()); } if (bundle != null && bundle.containsKey("adapter")) { setListAdapter((AlarmPreferenceListAdapter) bundle.getSerializable("adapter")); } else { setListAdapter(new AlarmPreferenceListAdapter(this, getMathAlarm())); } getListView().setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> l, View v, int position, long id) { final AlarmPreferenceListAdapter alarmPreferenceListAdapter = (AlarmPreferenceListAdapter) getListAdapter(); final AlarmPreference alarmPreference = (AlarmPreference) alarmPreferenceListAdapter .getItem(position); AlertDialog.Builder alert; v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY); switch (alarmPreference.getType()) { case BOOLEAN: CheckedTextView checkedTextView = (CheckedTextView) v; boolean checked = !checkedTextView.isChecked(); ((CheckedTextView) v).setChecked(checked); switch (alarmPreference.getKey()) { case ALARM_ACTIVE: alarm.setAlarmActive(checked); break; case ALARM_VIBRATE: alarm.setVibrate(checked); if (checked) { Vibrator vibrator = (Vibrator) getSystemService(VIBRATOR_SERVICE); vibrator.vibrate(1000); } break; } alarmPreference.setValue(checked); break; case STRING: alert = new AlertDialog.Builder(AlarmPreferencesActivity.this); alert.setTitle(alarmPreference.getTitle()); // alert.setMessage(message); // Set an EditText view to get user input final EditText input = new EditText(AlarmPreferencesActivity.this); input.setText(alarmPreference.getValue().toString()); alert.setView(input); alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { alarmPreference.setValue(input.getText().toString()); if (alarmPreference.getKey() == Key.ALARM_NAME) { alarm.setAlarmName(alarmPreference.getValue().toString()); } alarmPreferenceListAdapter.setMathAlarm(getMathAlarm()); alarmPreferenceListAdapter.notifyDataSetChanged(); } }); alert.show(); break; case LIST: alert = new AlertDialog.Builder(AlarmPreferencesActivity.this); alert.setTitle(alarmPreference.getTitle()); // alert.setMessage(message); CharSequence[] items = new CharSequence[alarmPreference.getOptions().length]; for (int i = 0; i < items.length; i++) items[i] = alarmPreference.getOptions()[i]; alert.setItems(items, new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { switch (alarmPreference.getKey()) { case ALARM_DIFFICULTY: Alarm.Difficulty d = Alarm.Difficulty.values()[which]; alarm.setDifficulty(d); break; case ALARM_TONE: alarm.setAlarmTonePath(alarmPreferenceListAdapter.getAlarmTonePaths()[which]); if (alarm.getAlarmTonePath() != null) { if (mediaPlayer == null) { mediaPlayer = new MediaPlayer(); } else { if (mediaPlayer.isPlaying()) mediaPlayer.stop(); mediaPlayer.reset(); } try { // mediaPlayer.setVolume(1.0f, 1.0f); mediaPlayer.setVolume(0.2f, 0.2f); mediaPlayer.setDataSource(AlarmPreferencesActivity.this, Uri.parse(alarm.getAlarmTonePath())); mediaPlayer.setAudioStreamType(AudioManager.STREAM_ALARM); mediaPlayer.setLooping(false); mediaPlayer.prepare(); mediaPlayer.start(); // Force the mediaPlayer to stop after 3 // seconds... if (alarmToneTimer != null) alarmToneTimer.cancel(); alarmToneTimer = new CountDownTimer(3000, 3000) { @Override public void onTick(long millisUntilFinished) { } @Override public void onFinish() { try { if (mediaPlayer.isPlaying()) mediaPlayer.stop(); } catch (Exception e) { } } }; alarmToneTimer.start(); } catch (Exception e) { try { if (mediaPlayer.isPlaying()) mediaPlayer.stop(); } catch (Exception e2) { } } } break; default: break; } alarmPreferenceListAdapter.setMathAlarm(getMathAlarm()); alarmPreferenceListAdapter.notifyDataSetChanged(); } }); alert.show(); break; case MULTIPLE_LIST: alert = new AlertDialog.Builder(AlarmPreferencesActivity.this); alert.setTitle(alarmPreference.getTitle()); // alert.setMessage(message); CharSequence[] multiListItems = new CharSequence[alarmPreference.getOptions().length]; for (int i = 0; i < multiListItems.length; i++) multiListItems[i] = alarmPreference.getOptions()[i]; boolean[] checkedItems = new boolean[multiListItems.length]; for (Alarm.Day day : getMathAlarm().getDays()) { checkedItems[day.ordinal()] = true; } alert.setMultiChoiceItems(multiListItems, checkedItems, new OnMultiChoiceClickListener() { @Override public void onClick(final DialogInterface dialog, int which, boolean isChecked) { Alarm.Day thisDay = Alarm.Day.values()[which]; if (isChecked) { alarm.addDay(thisDay); } else { // Only remove the day if there are more than 1 // selected if (alarm.getDays().length > 1) { alarm.removeDay(thisDay); } else { // If the last day was unchecked, re-check // it ((AlertDialog) dialog).getListView().setItemChecked(which, true); } } } }); alert.setOnCancelListener(new OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { alarmPreferenceListAdapter.setMathAlarm(getMathAlarm()); alarmPreferenceListAdapter.notifyDataSetChanged(); } }); alert.show(); break; case TIME: TimePickerDialog timePickerDialog = new TimePickerDialog(AlarmPreferencesActivity.this, new OnTimeSetListener() { @Override public void onTimeSet(TimePicker timePicker, int hours, int minutes) { Calendar newAlarmTime = Calendar.getInstance(); newAlarmTime.set(Calendar.HOUR_OF_DAY, hours); newAlarmTime.set(Calendar.MINUTE, minutes); newAlarmTime.set(Calendar.SECOND, 0); alarm.setAlarmTime(newAlarmTime); alarmPreferenceListAdapter.setMathAlarm(getMathAlarm()); alarmPreferenceListAdapter.notifyDataSetChanged(); } }, alarm.getAlarmTime().get(Calendar.HOUR_OF_DAY), alarm.getAlarmTime().get(Calendar.MINUTE), true); timePickerDialog.setTitle(alarmPreference.getTitle()); timePickerDialog.show(); default: break; } } }); }