List of usage examples for android.app TimePickerDialog TimePickerDialog
public TimePickerDialog(Context context, OnTimeSetListener listener, int hourOfDay, int minute, boolean is24HourView)
From source file:com.markupartist.sthlmtraveling.ChangeRouteTimeActivity.java
@SuppressLint("InlinedApi") @Override/* w ww .jav a2 s . c om*/ protected Dialog onCreateDialog(int id) { Calendar calendar = Calendar.getInstance(); calendar.setTime(mTime); switch (id) { case DIALOG_DATE: // Workaround for broken date time picker on some Samsung devices. // http://stackoverflow.com/questions/28618405/datepicker-crashes-on-my-device-when-clicked-with-personal-app Context context = this; if (isBrokenSamsungDevice()) { context = new ContextThemeWrapper(this, android.R.style.Theme_Holo_Light_Dialog); } return new DatePickerDialog(context, mDateSetListener, calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH)); case DIALOG_TIME: return new TimePickerDialog(this, mTimeSetListener, calendar.get(Calendar.HOUR_OF_DAY), calendar.get(Calendar.MINUTE), android.text.format.DateFormat.is24HourFormat(this)); } return null; }
From source file:net.evecom.android.PublicOpinionLookActivity.java
/** * //from ww w .j a v a 2s .co m */ private void listener() { lysjButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Dialog dialog = new AlertDialog.Builder(PublicOpinionLookActivity.this).setTitle("") .setPositiveButton("", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Dialog dialog1 = new DatePickerDialog(PublicOpinionLookActivity.this, new DatePickerDialog.OnDateSetListener() { public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { String MonthOfYear = ""; String DayOfMonth = ""; years = year; month = monthOfYear + 1; day = dayOfMonth; if (monthOfYear < 9) { MonthOfYear = "0" + month; } else { MonthOfYear = "" + month; } if (dayOfMonth < 9) { DayOfMonth = "0" + dayOfMonth; } else { DayOfMonth = "" + dayOfMonth; } lysjButton.setText("" + year + "-" + MonthOfYear + "-" + DayOfMonth + " " + hours + ":" + minutes + ":" + calendar.get(Calendar.SECOND)); // lysjButton.setText("" + years // + "-" // + month // + "-" + day +" " // + hours +":" // + minutes+":" // + // calendar.get(Calendar.SECOND)); lysj = years + "-" + month + "-" + day + "+" + hours + "%3A" + minutes + "%3A" + calendar.get(Calendar.SECOND); } }, calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH));// dialog1.show(); } }).setNeutralButton("", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Dialog dialog2 = new TimePickerDialog(PublicOpinionLookActivity.this, new TimePickerDialog.OnTimeSetListener() { public void onTimeSet(TimePicker view, int hour, int minute) { lysjButton.setText("" + years + "-" + month + "-" + day + " " + hour + ":" + minute + ":" + calendar.get(Calendar.SECOND)); hours = hour; minutes = minute; lysj = years + "-" + month + "-" + day + "+" + hours + "%3A" + minutes + "%3A" + calendar.get(Calendar.SECOND); } }, calendar.get(Calendar.HOUR_OF_DAY), calendar.get(Calendar.MINUTE), true);// dialog2.show(); } }).setNegativeButton("", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { lysjButton.setText(""); lysj = ""; } }).show(); } }); // lylxButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { Dialog schDia = new AlertDialog.Builder(PublicOpinionLookActivity.this) .setIcon(R.drawable.login_error_icon).setTitle("") .setItems(lylxs, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dia, int which) { lylxButton.setText(lylxs[which]); sourceway = which + 1; } }).setNegativeButton("", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dia, int which) { dia.dismiss(); } }).create(); schDia.show(); } }); }
From source file:com.dsi.ant.antplus.pluginsampler.geocache.Dialog_GeoProgramDevice.java
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); builder.setTitle("Program Device " + deviceData.deviceId); // Get the layout inflater LayoutInflater inflater = getActivity().getLayoutInflater(); View detailsView = inflater.inflate(R.layout.dialog_geocache_programdevice, null); // Inflate and set the layout for the dialog // Pass null as the parent view because its going in the dialog layout builder.setView(detailsView);/*from ww w . j a v a 2 s.c om*/ // Add action buttons //Note we override the positive button in show() below so we can prevent it from closing builder.setPositiveButton("Begin Programing", null); builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { //Let dialog dismiss } }); checkBox_EnableIdString = (CheckBox) detailsView.findViewById(R.id.checkBox_EnableIdentifcationString); checkBox_EnablePIN = (CheckBox) detailsView.findViewById(R.id.checkBox_EnablePIN); checkBox_EnableLatitude = (CheckBox) detailsView.findViewById(R.id.checkBox_EnableLatitude); checkBox_EnableLongitude = (CheckBox) detailsView.findViewById(R.id.checkBox_EnableLongitude); checkBox_EnableHintString = (CheckBox) detailsView.findViewById(R.id.checkBox_EnableHintString); checkBox_EnableLastVisit = (CheckBox) detailsView.findViewById(R.id.checkBox_EnableLastVisitInfo); final TextView textView_NumVisitsTitle = (TextView) detailsView .findViewById(R.id.textView_NumberOfVisitsTitle); final TextView textView_LastVisitDateTitle = (TextView) detailsView .findViewById(R.id.textView_LastVisitDateTitle); final TextView textView_LastVisitTimeTitle = (TextView) detailsView .findViewById(R.id.textView_LastVisitTimeTitle); editText_IdString = (EditText) detailsView.findViewById(R.id.editText_IdentificationString); editText_PIN = (EditText) detailsView.findViewById(R.id.editText_PIN); editText_Latitude = (EditText) detailsView.findViewById(R.id.editText_Latitude); editText_Longitude = (EditText) detailsView.findViewById(R.id.editText_Longitude); editText_HintString = (EditText) detailsView.findViewById(R.id.editText_HintString); editText_NumVisits = (EditText) detailsView.findViewById(R.id.editText_NumberOfVisits); textView_LastVisitDate = (TextView) detailsView.findViewById(R.id.textView_LastVisitDate); textView_LastVisitTime = (TextView) detailsView.findViewById(R.id.textView_LastVisitTime); radioButton_ClearExisitingData = (RadioButton) detailsView.findViewById(R.id.radioButton_ClearExistingData); //Hook up checkboxes to enable/disable fields checkBox_EnableIdString.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { editText_IdString.setEnabled(isChecked); if (isChecked && editText_IdString.getText().length() == 0) editText_IdString.setText("ID STR"); } }); checkBox_EnablePIN.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { editText_PIN.setEnabled(isChecked); if (isChecked && editText_PIN.getText().length() == 0) editText_PIN.setText("123456"); } }); checkBox_EnableLatitude.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { editText_Latitude.setEnabled(isChecked); if (isChecked && editText_Latitude.getText().length() == 0) editText_Latitude.setText("-40.1"); } }); checkBox_EnableLongitude.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { editText_Longitude.setEnabled(isChecked); if (isChecked && editText_Longitude.getText().length() == 0) editText_Longitude.setText("-20.1"); } }); checkBox_EnableHintString.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { editText_HintString.setEnabled(isChecked); if (isChecked && editText_HintString.getText().length() == 0) editText_HintString.setText("Hint string."); } }); checkBox_EnableLastVisit.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { textView_NumVisitsTitle.setEnabled(isChecked); textView_LastVisitDateTitle.setEnabled(isChecked); textView_LastVisitTimeTitle.setEnabled(isChecked); editText_NumVisits.setEnabled(isChecked); textView_LastVisitDate.setEnabled(isChecked); textView_LastVisitTime.setEnabled(isChecked); if (isChecked) { if (editText_NumVisits.length() == 0) editText_NumVisits.setText("0"); if (textView_LastVisitDate.length() == 0) textView_LastVisitDate.setText("dd/mmm/yyyy"); if (textView_LastVisitTime.length() == 0) textView_LastVisitDate.setText("hh:mm"); } } }); //Set data editText_IdString.setText(String.valueOf(deviceData.programmableData.identificationString)); editText_PIN.setText(String.valueOf(deviceData.programmableData.PIN)); if (deviceData.programmableData.latitude != null) editText_Latitude.setText( String.valueOf(deviceData.programmableData.latitude.setScale(5, BigDecimal.ROUND_HALF_UP))); else editText_Latitude.setText(""); if (deviceData.programmableData.longitude != null) editText_Longitude.setText( String.valueOf(deviceData.programmableData.longitude.setScale(5, BigDecimal.ROUND_HALF_UP))); else editText_Longitude.setText(""); if (deviceData.programmableData.hintString != null) editText_HintString.setText(String.valueOf(deviceData.programmableData.hintString)); else editText_HintString.setText(""); if (deviceData.programmableData.numberOfVisits != null) editText_NumVisits.setText(String.valueOf(deviceData.programmableData.numberOfVisits)); else editText_NumVisits.setText(""); if (deviceData.programmableData.lastVisitTimestamp != null) { currentDisplayDatetime = deviceData.programmableData.lastVisitTimestamp; updateDateAndTime(); } else { textView_LastVisitDate.setText(""); textView_LastVisitTime.setText(""); } //Hook up date and time fields to pickers textView_LastVisitDate.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (currentDisplayDatetime == null) currentDisplayDatetime = new GregorianCalendar(TimeZone.getTimeZone("UTC")); DatePickerDialog d = new DatePickerDialog(getActivity(), new OnDateSetListener() { @Override public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { currentDisplayDatetime.set(year, monthOfYear, dayOfMonth); updateDateAndTime(); } }, currentDisplayDatetime.get(Calendar.YEAR), currentDisplayDatetime.get(Calendar.MONTH), currentDisplayDatetime.get(Calendar.DAY_OF_MONTH)); d.show(); } }); textView_LastVisitTime.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (currentDisplayDatetime == null) currentDisplayDatetime = new GregorianCalendar(TimeZone.getTimeZone("UTC")); TimePickerDialog d = new TimePickerDialog(getActivity(), new OnTimeSetListener() { @Override public void onTimeSet(TimePicker view, int hourOfDay, int minute) { currentDisplayDatetime.set(Calendar.HOUR_OF_DAY, hourOfDay); currentDisplayDatetime.set(Calendar.MINUTE, minute); updateDateAndTime(); } }, currentDisplayDatetime.get(Calendar.HOUR_OF_DAY), currentDisplayDatetime.get(Calendar.MINUTE), false); d.show(); } }); return builder.create(); }
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 ww. j a v a2 s . c o 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; } } }); }
From source file:org.mythdroid.activities.Guide.java
@Override public Dialog onCreateDialog(int id) { switch (id) { case DIALOG_DATE: return new DatePickerDialog(this, new OnDateSetListener() { private int Year = -1, Month = -1, Day = -1; @Override/*w w w. j ava 2 s . c o m*/ public void onDateSet(DatePicker view, int year, int month, int day) { if (year == Year && month == Month && day == Day) return; Year = year; Month = month; Day = day; now.setYear(year - 1900); now.setMonth(month); now.setDate(day); displayGuide(now); } }, now.getYear() + 1900, now.getMonth(), now.getDate()); case DIALOG_TIME: return new TimePickerDialog(this, new OnTimeSetListener() { private int Hour = -1, Min = -1; @Override public void onTimeSet(TimePicker view, int hour, int min) { if (hour == Hour && min == Min) return; Hour = hour; Min = min; now.setHours(hour); now.setMinutes(min); displayGuide(now); } }, now.getHours(), now.getMinutes(), true); default: return super.onCreateDialog(id); } }
From source file:tw.com.geminihsu.app01.fragment.Fragment_PickUpTrain.java
private void setLister() { calendar = Calendar.getInstance(); timePicker = new TimePickerDialog.OnTimeSetListener() { public void onTimeSet(TimePicker view, int hourOfDay, int minute) { }//from www.j a v a 2 s .com }; timerPicker.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { new TimePickerDialog(getActivity(), timePicker, 24, 59, true).show(); } }); datePicker = new DatePickerDialog.OnDateSetListener() { @Override public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) { date.setText(dayOfMonth + "/" + (month + 1) + "/" + year); } }; btn_datePicker.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { new DatePickerDialog(getActivity(), datePicker, calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH)).show(); } }); radioGroup_orderTimetype.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { public void onCheckedChanged(RadioGroup group, int checkedId) { if (checkedId == reservation.getId()) { linearLayout_date_picker.setVisibility(View.VISIBLE); linearLayout_time_picker.setVisibility(View.GONE); } else { linearLayout_date_picker.setVisibility(View.GONE); linearLayout_time_picker.setVisibility(View.VISIBLE); } } }); radiogroup_destination_station.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { public void onCheckedChanged(RadioGroup group, int checkedId) { if (checkedId == thsrStation.getId()) { getLocationFromDB("?"); } else { getLocationFromDB("?"); } } }); radiogroup_leave_location.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { public void onCheckedChanged(RadioGroup group, int checkedId) { if (checkedId == departure_thsr_train.getId()) { getLocationFromDB("?"); } else { getLocationFromDB("?"); } } }); departure.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { AlertDialog.Builder builderSingle = new AlertDialog.Builder(getActivity()); final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(getActivity(), android.R.layout.select_dialog_item); arrayAdapter.add(getString(R.string.pop_map_option1)); arrayAdapter.add(getString(R.string.pop_map_option2)); builderSingle.setAdapter(arrayAdapter, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { String strName = arrayAdapter.getItem(which); switch (which) { case 0: Intent map = new Intent(getActivity(), OrderMapActivity.class); Bundle b = new Bundle(); b.putInt(Constants.ARG_POSITION, Constants.DEPARTURE_QUERY_GPS); map.putExtras(b); startActivityForResult(map, Constants.DEPARTURE_QUERY_GPS); break; case 1: Intent page = new Intent(getActivity(), BookmarksMapListActivity.class); Bundle flag = new Bundle(); flag.putInt(Constants.ARG_POSITION, Constants.DEPARTURE_QUERY_BOOKMARK); page.putExtras(flag); startActivityForResult(page, Constants.DEPARTURE_QUERY_BOOKMARK); break; } } }); builderSingle.show(); } }); stop.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { AlertDialog.Builder builderSingle = new AlertDialog.Builder(getActivity()); final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(getActivity(), android.R.layout.select_dialog_item); arrayAdapter.add(getString(R.string.pop_map_option1)); arrayAdapter.add(getString(R.string.pop_map_option2)); builderSingle.setAdapter(arrayAdapter, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { String strName = arrayAdapter.getItem(which); switch (which) { case 0: Intent map = new Intent(getActivity(), OrderMapActivity.class); Bundle b = new Bundle(); b.putInt(Constants.ARG_POSITION, Constants.STOP_QUERY_GPS); map.putExtras(b); startActivityForResult(map, Constants.STOP_QUERY_GPS); break; case 1: Intent page = new Intent(getActivity(), BookmarksMapListActivity.class); Bundle flag = new Bundle(); flag.putInt(Constants.ARG_POSITION, Constants.STOP_QUERY_BOOKMARK); page.putExtras(flag); startActivityForResult(page, Constants.STOP_QUERY_BOOKMARK); break; } } }); builderSingle.show(); } }); destination.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { AlertDialog.Builder builderSingle = new AlertDialog.Builder(getActivity()); final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(getActivity(), android.R.layout.select_dialog_item); arrayAdapter.add(getString(R.string.pop_map_option1)); arrayAdapter.add(getString(R.string.pop_map_option2)); builderSingle.setAdapter(arrayAdapter, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { String strName = arrayAdapter.getItem(which); switch (which) { case 0: Intent map = new Intent(getActivity(), OrderMapActivity.class); Bundle b = new Bundle(); b.putInt(Constants.ARG_POSITION, Constants.DESTINATION_QUERY_GPS); map.putExtras(b); startActivityForResult(map, Constants.DESTINATION_QUERY_GPS); break; case 1: Intent page = new Intent(getActivity(), BookmarksMapListActivity.class); Bundle flag = new Bundle(); flag.putInt(Constants.ARG_POSITION, Constants.DESTINATION_QUERY_BOOKMARK); page.putExtras(flag); startActivityForResult(page, Constants.DESTINATION_QUERY_BOOKMARK); break; } } }); builderSingle.show(); } }); getDataFromDB(); linearLayout_spec.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // custom dialog final Dialog dialog = new Dialog(getActivity()); dialog.setContentView(R.layout.client_take_ride_selectspec_requirement); dialog.setTitle(getString(R.string.txt_take_spec)); Button cancel = (Button) dialog.findViewById(R.id.button_category_cancel); Button ok = (Button) dialog.findViewById(R.id.button_category_ok); //dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); // set the custom dialog components - text, image and button ListView requirement = (ListView) dialog.findViewById(R.id.listViewDialog); requirement.setOnItemClickListener(new AdapterView.OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View v, int position, long id) { ClientTakeRideSelectSpecListItem item = mCommentListData.get(position); item.check = !item.check; mCommentListData.set(position, item); listViewAdapter.notifyDataSetChanged(); } }); if (listViewAdapter == null) { listViewAdapter = new ClientTakeRideSelectSpecListItemAdapter(getActivity(), 0, mCommentListData); } requirement.setAdapter(listViewAdapter); listViewAdapter.notifyDataSetChanged(); dialog.show(); cancel.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { dialog.cancel(); } }); String require; ok.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { String require = ""; for (ClientTakeRideSelectSpecListItem item : mCommentListData) { if (item.check) { spec_list.add(item); require += item.book_title + ","; } } if (!require.isEmpty()) require = require.substring(0, require.length() - 1); spec_value.setText(require); dialog.cancel(); } }); } }); spec.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // custom dialog final Dialog dialog = new Dialog(getActivity()); dialog.setContentView(R.layout.client_take_ride_selectspec_requirement); dialog.setTitle(getString(R.string.txt_take_spec)); Button cancel = (Button) dialog.findViewById(R.id.button_category_ok); //dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); // set the custom dialog components - text, image and button ListView requirement = (ListView) dialog.findViewById(R.id.listViewDialog); getDataFromDB(); listViewAdapter = new ClientTakeRideSelectSpecListItemAdapter(getActivity(), 0, mCommentListData); requirement.setAdapter(listViewAdapter); listViewAdapter.notifyDataSetChanged(); dialog.show(); cancel.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { dialog.cancel(); } }); } }); spinner_go_location.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> adapter, View v, int position, long id) { currentLocation = tainStationList.get(position); destination_detail = new LocationAddress(); destination_detail.setLongitude(Double.parseDouble(currentLocation.getLng())); destination_detail.setLatitude(Double.parseDouble(currentLocation.getLat())); destination_detail.setAddress(currentLocation.getStreetAddress().substring(3, currentLocation.getStreetAddress().length())); destination_detail.setLocation(currentLocation.getLocation()); String zipCpde = (getTrainStationZip(currentLocation.getLocation())); destination_detail.setZipCode(zipCpde); destination_detail.setCountryName("Taiwan"); destination_detail.setLocality(currentLocation.getStreetAddress()); } @Override public void onNothingSelected(AdapterView<?> arg0) { // TODO Auto-generated method stub } }); spinner_departure.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> adapter, View v, int position, long id) { currentLocation = tainStationList.get(position); departure_detail = new LocationAddress(); departure_detail.setLongitude(Double.parseDouble(currentLocation.getLng())); departure_detail.setLatitude(Double.parseDouble(currentLocation.getLat())); departure_detail.setAddress(currentLocation.getStreetAddress().substring(3, currentLocation.getStreetAddress().length())); departure_detail.setLocation(currentLocation.getLocation()); //departure_detail.setZipCode(currentLocation.getStreetAddress().substring(0,3)); String zipCode = (getTrainStationZip(currentLocation.getLocation())); departure_detail.setZipCode(zipCode); departure_detail.setCountryName("Taiwan"); departure_detail.setLocality(currentLocation.getStreetAddress()); } @Override public void onNothingSelected(AdapterView<?> arg0) { // TODO Auto-generated method stub } }); }
From source file:de.spiritcroc.ownlog.ui.fragment.LogItemEditFragment.java
@Override public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) { mTime.set(year, month, dayOfMonth);/*from w w w .j av a 2 s . co m*/ new TimePickerDialog(getActivity(), this, mTime.get(Calendar.HOUR_OF_DAY), mTime.get(Calendar.MINUTE), DateFormat.is24HourFormat(getActivity())).show(); updateTitle(); }
From source file:tinygsn.gui.android.ActivityViewDataNew.java
private void addTableViewModeCustomize() { table_view_mode = (TableLayout) findViewById(R.id.table_view_mode); table_view_mode.removeAllViews();/*from w ww. j a va 2 s. c o m*/ // Row From TableRow row = new TableRow(this); TextView txt = new TextView(this); txt.setText("From: "); txt.setTextColor(Color.parseColor("#000000")); row.addView(txt); // Date time = new Date(); startTime = new Date(); startTime.setMinutes(startTime.getMinutes() - 1); endTime = new Date(); // Start Time SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss"); txtStartTime = new TextView(this); txtStartTime.setText(formatter.format(startTime) + ""); txtStartTime.setTextColor(Color.parseColor("#000000")); txtStartTime.setBackgroundColor(Color.parseColor("#8dc63f")); row.addView(txtStartTime); txtStartTime.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { new TimePickerDialog(context, startTimeSetListener, dateAndTime.get(Calendar.HOUR_OF_DAY) - 1, dateAndTime.get(Calendar.MINUTE), true).show(); } }); // Add space txt = new TextView(this); txt.setText(" "); row.addView(txt); // Start Date formatter = new SimpleDateFormat("dd/MM/yyyy"); // txtStartDate, txtStartTime txtStartDate = new TextView(this); txtStartDate.setText(formatter.format(startTime) + ""); txtStartDate.setTextColor(Color.parseColor("#000000")); txtStartDate.setBackgroundColor(Color.parseColor("#8dc63f")); row.addView(txtStartDate); txtStartDate.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { new DatePickerDialog(context, startDateSetListener, dateAndTime.get(Calendar.YEAR), dateAndTime.get(Calendar.MONTH), dateAndTime.get(Calendar.DAY_OF_MONTH)).show(); } }); table_view_mode.addView(row); // Add a space row row = new TableRow(this); txt = new TextView(this); txt.setText("-"); row.addView(txt); table_view_mode.addView(row); // Row To row = new TableRow(this); txt = new TextView(this); txt.setText("To"); txt.setTextColor(Color.parseColor("#000000")); row.addView(txt); // End Time formatter = new SimpleDateFormat("HH:mm:ss"); txtEndTime = new TextView(this); txtEndTime.setText(formatter.format(endTime) + ""); txtEndTime.setTextColor(Color.parseColor("#000000")); txtEndTime.setBackgroundColor(Color.parseColor("#8dc63f")); row.addView(txtEndTime); txtEndTime.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { new TimePickerDialog(context, endTimeSetListener, dateAndTime.get(Calendar.HOUR_OF_DAY), dateAndTime.get(Calendar.MINUTE), true).show(); } }); // Add space txt = new TextView(this); txt.setText(" "); row.addView(txt); // End Date formatter = new SimpleDateFormat("dd/MM/yyyy"); // txtStartDate, txtStartTime txtEndDate = new TextView(this); txtEndDate.setText(formatter.format(endTime) + ""); txtEndDate.setTextColor(Color.parseColor("#000000")); txtEndDate.setBackgroundColor(Color.parseColor("#8dc63f")); row.addView(txtEndDate); txtEndDate.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { new DatePickerDialog(context, endDateSetListener, dateAndTime.get(Calendar.YEAR), dateAndTime.get(Calendar.MONTH), dateAndTime.get(Calendar.DAY_OF_MONTH)).show(); } }); table_view_mode.addView(row); // Row row = new TableRow(this); Button detailBtn = new Button(this); detailBtn.setTextSize(TEXT_SIZE + 2); detailBtn.setText("Detail"); detailBtn.setTextColor(Color.parseColor("#000000")); detailBtn.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { } }); Button plotDataBtn = new Button(this); plotDataBtn.setTextSize(TEXT_SIZE + 2); plotDataBtn.setText("Plot data"); plotDataBtn.setTextColor(Color.parseColor("#000000")); plotDataBtn.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { viewChart(); } }); TableRow.LayoutParams params = new TableRow.LayoutParams(); // params.addRule(TableRow.LayoutParams.FILL_PARENT); params.span = 2; row.addView(detailBtn, params); row.addView(plotDataBtn, params); row.setLayoutParams(new TableLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); table_view_mode.addView(row); }
From source file:net.naonedbus.fragment.impl.ItineraireFragment.java
private void showTimePicker() { final TimePickerDialog dialog = new TimePickerDialog(getActivity(), this, mDateTime.getHourOfDay(), mDateTime.getMinuteOfHour(), true); dialog.show();/*from w w w .java2 s . co m*/ }
From source file:de.j4velin.wifiAutoOff.Preferences.java
@SuppressWarnings("deprecation") @Override//from www . j a va 2s. c om public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.preferences); if (BuildConfig.DEBUG && PermissionChecker.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PermissionChecker.PERMISSION_GRANTED) { requestPermissions(new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE }, 0); } status = (StatusPreference) findPreference("status"); status.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(final Preference preference) { WifiManager wm = (WifiManager) getSystemService(Context.WIFI_SERVICE); boolean connected = ((ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE)) .getNetworkInfo(ConnectivityManager.TYPE_WIFI).isConnected(); if (wm.isWifiEnabled() && !connected) { try { startActivity(new Intent(WifiManager.ACTION_PICK_WIFI_NETWORK) .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)); } catch (Exception e) { Toast.makeText(Preferences.this, R.string.settings_not_found_, Toast.LENGTH_SHORT).show(); } } else if (!wm.isWifiEnabled()) { wm.setWifiEnabled(true); } else { try { startActivity( new Intent(Settings.ACTION_WIFI_SETTINGS).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)); } catch (Exception e) { Toast.makeText(Preferences.this, R.string.settings_not_found_, Toast.LENGTH_SHORT).show(); } } return true; } }); final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); final CheckBoxPreference screen_off = (CheckBoxPreference) findPreference("off_screen_off"); screen_off.setSummary( getString(R.string.for_at_least, prefs.getInt("screen_off_timeout", Receiver.TIMEOUT_SCREEN_OFF))); if (!keepWiFiOn(this)) { screen_off.setChecked(false); } screen_off.setOnPreferenceChangeListener(new OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(final Preference preference, final Object newValue) { if ((Boolean) newValue) { if (!keepWiFiOn(Preferences.this)) { new AlertDialog.Builder(Preferences.this).setMessage(R.string.sleep_policy) .setPositiveButton(R.string.adv_wifi_settings, new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { try { startActivity(new Intent(Settings.ACTION_WIFI_IP_SETTINGS) .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)); } catch (Exception e) { Toast.makeText(Preferences.this, R.string.settings_not_found_, Toast.LENGTH_SHORT).show(); } } }).setNegativeButton(android.R.string.cancel, new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }).create().show(); return false; } if (android.os.Build.VERSION.SDK_INT >= 11) { APILevel11Wrapper.showNumberPicker(Preferences.this, prefs, screen_off, R.string.for_at_least, 1, 60, getString(R.string.minutes_before_turning_off_wifi_), "screen_off_timeout", Receiver.TIMEOUT_SCREEN_OFF, false); } else { showPre11NumberPicker(Preferences.this, prefs, screen_off, R.string.for_at_least, 1, 60, getString(R.string.minutes_before_turning_off_wifi_), "screen_off_timeout", Receiver.TIMEOUT_SCREEN_OFF, false); } } return true; } }); findPreference("off_no_network").setOnPreferenceChangeListener(new OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(final Preference preference, final Object newValue) { if ((Boolean) newValue) { if (android.os.Build.VERSION.SDK_INT >= 11) { APILevel11Wrapper.showNumberPicker(Preferences.this, prefs, preference, R.string.for_at_least, 1, 60, getString(R.string.minutes_before_turning_off_wifi_), "no_network_timeout", Receiver.TIMEOUT_NO_NETWORK, false); } else { showPre11NumberPicker(Preferences.this, prefs, preference, R.string.for_at_least, 1, 60, getString(R.string.minutes_before_turning_off_wifi_), "no_network_timeout", Receiver.TIMEOUT_NO_NETWORK, false); } } return true; } }); final CheckBoxPreference on_at = (CheckBoxPreference) findPreference("on_at"); on_at.setTitle(getString(R.string.at_summary, prefs.getString("on_at_time", Receiver.ON_AT_TIME))); on_at.setOnPreferenceChangeListener(new OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(final Preference preference, final Object newValue) { if ((Boolean) newValue) { String[] time = prefs.getString("on_at_time", Receiver.ON_AT_TIME).split(":"); final TimePickerDialog dialog = new TimePickerDialog(Preferences.this, new OnTimeSetListener() { @Override public void onTimeSet(TimePicker view, int hourOfDay, int minute) { prefs.edit().putString("on_at_time", hourOfDay + ":" + (minute < 10 ? "0" + minute : minute)).commit(); on_at.setTitle(getString(R.string.at_summary, hourOfDay + ":" + (minute < 10 ? "0" + minute : minute))); } }, Integer.parseInt(time[0]), Integer.parseInt(time[1]), true); dialog.setOnCancelListener(new OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { on_at.setChecked(false); } }); dialog.setTitle(getString(R.string.turn_wifi_on_at_)); dialog.show(); } return true; } }); final CheckBoxPreference off_at = (CheckBoxPreference) findPreference("off_at"); off_at.setTitle(getString(R.string.at_summary, prefs.getString("off_at_time", Receiver.OFF_AT_TIME))); off_at.setOnPreferenceChangeListener(new OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(final Preference preference, final Object newValue) { if ((Boolean) newValue) { String[] time = prefs.getString("off_at_time", Receiver.OFF_AT_TIME).split(":"); final TimePickerDialog dialog = new TimePickerDialog(Preferences.this, new OnTimeSetListener() { @Override public void onTimeSet(TimePicker view, int hourOfDay, int minute) { prefs.edit().putString("off_at_time", hourOfDay + ":" + (minute < 10 ? "0" + minute : minute)).commit(); off_at.setTitle(getString(R.string.at_summary, hourOfDay + ":" + (minute < 10 ? "0" + minute : minute))); } }, Integer.parseInt(time[0]), Integer.parseInt(time[1]), true); dialog.setOnCancelListener(new OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { off_at.setChecked(false); } }); dialog.setTitle(getString(R.string.turn_wifi_off_at_)); dialog.show(); } return true; } }); final Preference on_every = findPreference("on_every"); final String[] time_names = getResources().getStringArray(R.array.time_names); // default 2 hours on_every.setTitle(getString(R.string.every_summary, prefs.getString("on_every_str", time_names[4]))); on_every.setOnPreferenceChangeListener(new OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(final Preference preference, final Object newValue) { if ((Boolean) newValue) { AlertDialog.Builder builder = new AlertDialog.Builder(Preferences.this); builder.setTitle(R.string.turn_wifi_on_every).setItems(time_names, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { prefs.edit().putInt("on_every_time_min", time_values[which]) .putString("on_every_str", time_names[which]).commit(); on_every.setTitle(getString(R.string.every_summary, time_names[which])); } }); builder.create().show(); } return true; } }); Preference locations = findPreference("locations"); if (BuildConfig.FLAVOR.equals("play")) { if (getPackageManager().hasSystemFeature(PackageManager.FEATURE_LOCATION_NETWORK)) { locations.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(final Preference preference) { startActivity(new Intent(Preferences.this, Locations.class)); return true; } }); } else { locations.setEnabled(false); } } else { locations.setSummary("Not available in F-Droid version"); locations.setEnabled(false); } final Preference power = findPreference("power_connected"); power.setOnPreferenceChangeListener(new OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(final Preference preference, final Object newValue) { if ((boolean) newValue) { Intent battery = registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED)); if (battery != null && battery.getIntExtra(BatteryManager.EXTRA_PLUGGED, 0) > 0) { // already connected to external power prefs.edit().putBoolean("ignore_screen_off", true).commit(); } } else { prefs.edit().putBoolean("ignore_screen_off", false).commit(); } return true; } }); }