Search in sources :

Example 31 with DatePicker

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));
            }
        }
    }
}
Also used : Context(android.content.Context) GBApplication(nodomain.freeyourgadget.gadgetbridge.GBApplication) SeekBar(android.widget.SeekBar) DatePickerDialog(android.app.DatePickerDialog) Bundle(android.os.Bundle) Calendar(java.util.Calendar) Intent(android.content.Intent) ImageView(android.widget.ImageView) TextView(android.widget.TextView) View(android.view.View) Date(java.util.Date) BatteryConfig(nodomain.freeyourgadget.gadgetbridge.model.BatteryConfig) TextView(android.widget.TextView) DatePicker(android.widget.DatePicker) ImageView(android.widget.ImageView) LinearLayout(android.widget.LinearLayout) DeviceCoordinator(nodomain.freeyourgadget.gadgetbridge.devices.DeviceCoordinator)

Example 32 with DatePicker

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();
}
Also used : DatePickerDialog(android.app.DatePickerDialog) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) DatePicker(android.widget.DatePicker)

Example 33 with DatePicker

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();
}
Also used : DatePickerDialog(android.app.DatePickerDialog) SharedPreferences(android.content.SharedPreferences) Calendar(java.util.Calendar) DatePicker(android.widget.DatePicker)

Example 34 with DatePicker

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;
}
Also used : Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) GregorianCalendar(java.util.GregorianCalendar) DatePicker(android.widget.DatePicker)

Example 35 with DatePicker

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;
}
Also used : TimePicker(android.widget.TimePicker) DatePickerDialog(android.app.DatePickerDialog) Calendar(java.util.Calendar) TimePickerDialog(android.app.TimePickerDialog) MainActivity(kogvet.eye.MainActivity) View(android.view.View) LocalDate(org.threeten.bp.LocalDate) DatePicker(android.widget.DatePicker) SimpleDateFormat(java.text.SimpleDateFormat) Nullable(android.support.annotation.Nullable)

Aggregations

DatePicker (android.widget.DatePicker)68 DatePickerDialog (android.app.DatePickerDialog)45 Calendar (java.util.Calendar)42 View (android.view.View)27 TextView (android.widget.TextView)20 DialogInterface (android.content.DialogInterface)13 Intent (android.content.Intent)13 TimePicker (android.widget.TimePicker)11 AlertDialog (android.app.AlertDialog)9 Dialog (android.app.Dialog)9 AdapterView (android.widget.AdapterView)9 Button (android.widget.Button)9 EditText (android.widget.EditText)9 LinearLayout (android.widget.LinearLayout)9 Date (java.util.Date)9 SimpleDateFormat (java.text.SimpleDateFormat)8 Context (android.content.Context)7 TimePickerDialog (android.app.TimePickerDialog)6 ArrayAdapter (android.widget.ArrayAdapter)6 ImageView (android.widget.ImageView)6