use of android.widget.DatePicker in project Gadgetbridge by Freeyourgadget.
the class BatteryInfoActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final Context appContext = this.getApplicationContext();
if (appContext instanceof GBApplication) {
setContentView(R.layout.activity_battery_info);
}
Intent intent = getIntent();
Bundle bundle = intent.getExtras();
if (bundle != null) {
gbDevice = bundle.getParcelable(GBDevice.EXTRA_DEVICE);
batteryIndex = bundle.getInt(GBDevice.BATTERY_INDEX, 0);
} else {
throw new IllegalArgumentException("Must provide a device when invoking this activity");
}
final BatteryInfoChartFragment batteryInfoChartFragment = new BatteryInfoChartFragment();
getSupportFragmentManager().beginTransaction().replace(R.id.batteryChartFragmentHolder, batteryInfoChartFragment).commit();
timeTo = (int) (System.currentTimeMillis() / 1000);
batteryInfoChartFragment.setDateAndGetData(gbDevice, batteryIndex, timeFrom, timeTo);
TextView battery_status_device_name_text = (TextView) findViewById(R.id.battery_status_device_name);
TextView battery_status_battery_voltage = (TextView) findViewById(R.id.battery_status_battery_voltage);
TextView battery_status_extra_name = (TextView) findViewById(R.id.battery_status_extra_name);
final TextView battery_status_date_from_text = (TextView) findViewById(R.id.battery_status_date_from_text);
final TextView battery_status_date_to_text = (TextView) findViewById(R.id.battery_status_date_to_text);
final SeekBar battery_status_time_span_seekbar = (SeekBar) findViewById(R.id.battery_status_time_span_seekbar);
final TextView battery_status_time_span_text = (TextView) findViewById(R.id.battery_status_time_span_text);
LinearLayout battery_status_date_to_layout = (LinearLayout) findViewById(R.id.battery_status_date_to_layout);
battery_status_time_span_seekbar.setMax(5);
battery_status_time_span_seekbar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
String text;
switch(i) {
case 0:
text = getString(R.string.calendar_day);
timeFrom = DateTimeUtils.shiftDays(timeTo, -1);
break;
case 1:
text = getString(R.string.calendar_week);
timeFrom = DateTimeUtils.shiftDays(timeTo, -7);
break;
case 2:
text = getString(R.string.calendar_two_weeks);
timeFrom = DateTimeUtils.shiftDays(timeTo, -14);
break;
case 3:
text = getString(R.string.calendar_month);
timeFrom = DateTimeUtils.shiftMonths(timeTo, -1);
break;
case 4:
text = getString(R.string.calendar_six_months);
timeFrom = DateTimeUtils.shiftMonths(timeTo, -6);
break;
case 5:
text = getString(R.string.calendar_year);
timeFrom = DateTimeUtils.shiftMonths(timeTo, -12);
break;
default:
text = getString(R.string.calendar_two_weeks);
timeFrom = DateTimeUtils.shiftDays(timeTo, -14);
}
battery_status_time_span_text.setText(text);
battery_status_date_from_text.setText(DateTimeUtils.formatDate(new Date(timeFrom * 1000L)));
battery_status_date_to_text.setText(DateTimeUtils.formatDate(new Date(timeTo * 1000L)));
batteryInfoChartFragment.setDateAndGetData(gbDevice, batteryIndex, timeFrom, timeTo);
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
});
// Button battery_status_calendar_button = findViewById(R.id.battery_status_calendar_button);
battery_status_date_to_layout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final Calendar currentDate = Calendar.getInstance();
currentDate.setTimeInMillis(timeTo * 1000L);
Context context = getApplicationContext();
if (context instanceof GBApplication) {
new DatePickerDialog(BatteryInfoActivity.this, new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
Calendar date = Calendar.getInstance();
date.set(year, monthOfYear, dayOfMonth);
timeTo = (int) (date.getTimeInMillis() / 1000);
battery_status_date_to_text.setText(DateTimeUtils.formatDate(new Date(timeTo * 1000L)));
battery_status_time_span_seekbar.setProgress(0);
battery_status_time_span_seekbar.setProgress(1);
batteryInfoChartFragment.setDateAndGetData(gbDevice, batteryIndex, timeFrom, timeTo);
}
}, currentDate.get(Calendar.YEAR), currentDate.get(Calendar.MONTH), currentDate.get(Calendar.DATE)).show();
}
}
});
battery_status_time_span_seekbar.setProgress(2);
ImageView battery_status_device_icon = findViewById(R.id.battery_status_device_icon);
battery_status_device_icon.setImageResource(gbDevice.isInitialized() ? gbDevice.getType().getIcon() : gbDevice.getType().getDisabledIcon());
TextView battery_status_battery_level_text = (TextView) findViewById(R.id.battery_status_battery_level);
String level = gbDevice.getBatteryLevel(batteryIndex) > 0 ? String.format("%1s%%", gbDevice.getBatteryLevel(batteryIndex)) : "";
String voltage = gbDevice.getBatteryVoltage(batteryIndex) > 0 ? String.format("%1sV", gbDevice.getBatteryVoltage(batteryIndex)) : "";
battery_status_device_name_text.setText(gbDevice.getName());
battery_status_battery_level_text.setText(level);
battery_status_battery_voltage.setText(voltage);
DeviceCoordinator coordinator = DeviceHelper.getInstance().getCoordinator(gbDevice);
for (BatteryConfig batteryConfig : coordinator.getBatteryConfig()) {
if (batteryConfig.getBatteryIndex() == batteryIndex) {
battery_status_extra_name.setText(batteryConfig.getBatteryLabel());
battery_status_device_icon.setImageResource(batteryConfig.getBatteryIcon());
if (gbDevice.isInitialized()) {
battery_status_device_icon.setColorFilter(this.getResources().getColor(R.color.accent));
}
}
}
}
use of android.widget.DatePicker in project Gadgetbridge by Freeyourgadget.
the class ActivitySummariesFilter method getDate.
public void getDate(final String filter, long currentDatemillis) {
Calendar currentDate = Calendar.getInstance();
if (currentDatemillis > 0) {
currentDate = GregorianCalendar.getInstance();
currentDate.setTimeInMillis(currentDatemillis);
}
new DatePickerDialog(this, new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
Calendar date = Calendar.getInstance();
if (filter.equals(DATE_FILTER_FROM)) {
date.set(year, monthOfYear, dayOfMonth, 0, 0);
dateFromFilter = date.getTimeInMillis();
} else {
date.set(year, monthOfYear, dayOfMonth, 23, 59);
dateToFilter = date.getTimeInMillis();
}
update_filter_fields();
}
}, currentDate.get(Calendar.YEAR), currentDate.get(Calendar.MONTH), currentDate.get(Calendar.DATE)).show();
}
use of android.widget.DatePicker in project Gadgetbridge by Freeyourgadget.
the class ActivitySummariesActivity method resetFetchTimestampToChosenDate.
public void resetFetchTimestampToChosenDate() {
final Calendar currentDate = Calendar.getInstance();
new DatePickerDialog(this, new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
Calendar date = Calendar.getInstance();
date.set(year, monthOfYear, dayOfMonth);
long timestamp = date.getTimeInMillis() - 1000;
SharedPreferences.Editor editor = GBApplication.getDeviceSpecificSharedPrefs(mGBDevice.getAddress()).edit();
// FIXME: key reconstruction is BAD
editor.remove("lastSportsActivityTimeMillis");
editor.putLong("lastSportsActivityTimeMillis", timestamp);
editor.apply();
}
}, currentDate.get(Calendar.YEAR), currentDate.get(Calendar.MONTH), currentDate.get(Calendar.DATE)).show();
}
use of android.widget.DatePicker in project diary by billthefarmer.
the class DatePickerPreference method onCreateDialogView.
// On create dialog view
@Override
protected View onCreateDialogView() {
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(value);
DatePicker picker = new DatePicker(getContext());
// onDateChanged
picker.init(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DATE), (view, year, monthOfYear, dayOfMonth) -> {
Calendar calendar1 = new GregorianCalendar(year, monthOfYear, dayOfMonth);
value = calendar1.getTimeInMillis();
});
return picker;
}
use of android.widget.DatePicker in project Eye by tommyolsson.
the class FragmentCreateEvent method onCreateView.
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View inf = inflater.inflate(R.layout.fragment_create_event, container, false);
// Changes title to the subject name
((MainActivity) getActivity()).setActionBarTitle(getResources().getString(R.string.newActivity));
((MainActivity) getActivity()).showBackButton();
getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
subjectEditText = (EditText) inf.findViewById(R.id.subjectEditText);
locationEditText = (EditText) inf.findViewById(R.id.locationEditText);
dateEditText = (EditText) inf.findViewById(R.id.dateEditText);
startEditText = (EditText) inf.findViewById(R.id.startEditText);
endEditText = (EditText) inf.findViewById(R.id.endEditText);
dateEditText.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
// To show current date in the datepicker
final Calendar mCalendar = Calendar.getInstance();
int mYear = mCalendar.get(Calendar.YEAR);
int mMonth = mCalendar.get(Calendar.MONTH);
int mDay = mCalendar.get(Calendar.DAY_OF_MONTH);
DatePickerDialog mDatePicker = new DatePickerDialog(getContext(), new DatePickerDialog.OnDateSetListener() {
public void onDateSet(DatePicker datepicker, int selectedyear, int selectedmonth, int selectedday) {
// TODO Auto-generated method stub
/* Set picked date in textedit */
String myFormat = "yyyy-MM-dd";
SimpleDateFormat sdf = new SimpleDateFormat(myFormat, Locale.getDefault());
mCalendar.set(Calendar.YEAR, selectedyear);
mCalendar.set(Calendar.MONTH, selectedmonth);
mCalendar.set(Calendar.DAY_OF_MONTH, selectedday);
dateEditText.setText(sdf.format(mCalendar.getTime()));
}
}, mYear, mMonth, mDay);
mDatePicker.getDatePicker().setCalendarViewShown(false);
mDatePicker.setTitle("Select date");
mDatePicker.show();
}
});
startEditText.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Calendar mcurrentTime = Calendar.getInstance();
int hour = mcurrentTime.get(Calendar.HOUR_OF_DAY);
int minute = mcurrentTime.get(Calendar.MINUTE);
TimePickerDialog mTimePicker;
mTimePicker = new TimePickerDialog(getContext(), new TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker timePicker, int selectedHour, int selectedMinute) {
startEditText.setText(String.format("%02d:%02d", selectedHour, selectedMinute));
}
}, hour, minute, // Yes 24 hour time
true);
mTimePicker.setTitle("Select Time");
mTimePicker.show();
}
});
endEditText.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Calendar mcurrentTime = Calendar.getInstance();
int hour = mcurrentTime.get(Calendar.HOUR_OF_DAY);
int minute = mcurrentTime.get(Calendar.MINUTE);
TimePickerDialog mTimePicker;
mTimePicker = new TimePickerDialog(getContext(), new TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker timePicker, int selectedHour, int selectedMinute) {
endEditText.setText(String.format("%02d:%02d", selectedHour, selectedMinute));
}
}, hour, minute, // Yes 24 hour time
true);
mTimePicker.setTitle("Select Time");
mTimePicker.show();
}
});
checkBox = inf.findViewById(R.id.checkBox);
checkBox.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (((CheckBox) v).isChecked()) {
// Disables editText for time if event is all day
startEditText.setEnabled(false);
endEditText.setEnabled(false);
isAllDay = true;
} else {
startEditText.setEnabled(true);
endEditText.setEnabled(true);
isAllDay = false;
}
}
});
createButton = inf.findViewById(R.id.createButton);
createButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String subject = subjectEditText.getText().toString();
String location = locationEditText.getText().toString();
String date = dateEditText.getText().toString();
String start = startEditText.getText().toString();
String end = endEditText.getText().toString();
Log.i("Ämne", subject);
Log.i("Plats", location);
Log.i("Datum", date);
Log.i("Start", start);
Log.i("Slut", end);
Log.i("Heldag", Boolean.toString(isAllDay));
if (subject.matches("")) {
Toast.makeText(getContext(), "Namn på aktivitet saknas", Toast.LENGTH_SHORT).show();
} else {
if (isAllDay) {
LocalDate ld = LocalDate.parse(date, DateTimeFormatter.ofPattern("yyyy-MM-dd"));
String endDate = ld.plusDays(1).toString();
((MainActivity) getActivity()).createEventGraphAPI(subject, location, date, endDate, "00", "00", isAllDay);
} else {
((MainActivity) getActivity()).createEventGraphAPI(subject, location, date, date, start, end, isAllDay);
}
Toast.makeText(getContext(), "Aktivitet skapad", Toast.LENGTH_SHORT).show();
getActivity().onBackPressed();
}
}
});
return inf;
}
Aggregations