Search in sources :

Example 51 with DatePicker

use of android.widget.DatePicker in project J2ME-Loader by nikita36078.

the class DateField method getItemContentView.

@Override
protected View getItemContentView() {
    if (layout == null) {
        Context context = getOwnerForm().getParentActivity();
        layout = new LinearLayout(context);
        layout.setOrientation(LinearLayout.VERTICAL);
        datePicker = new DatePicker(context);
        timePicker = new TimePicker(context);
        datePicker.init(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH), dateChangedListener);
        timePicker.setCurrentHour(calendar.get(Calendar.HOUR_OF_DAY));
        timePicker.setCurrentMinute(calendar.get(Calendar.MINUTE));
        timePicker.setOnTimeChangedListener(timeChangedListener);
        layout.addView(datePicker);
        layout.addView(timePicker);
        if (mode == DATE) {
            datePicker.setVisibility(View.VISIBLE);
            timePicker.setVisibility(View.GONE);
        } else if (mode == TIME) {
            datePicker.setVisibility(View.GONE);
            timePicker.setVisibility(View.VISIBLE);
        } else if (mode == DATE_TIME) {
            datePicker.setVisibility(View.VISIBLE);
            timePicker.setVisibility(View.VISIBLE);
        }
    }
    return layout;
}
Also used : Context(android.content.Context) TimePicker(android.widget.TimePicker) DatePicker(android.widget.DatePicker) LinearLayout(android.widget.LinearLayout)

Example 52 with DatePicker

use of android.widget.DatePicker in project c-geo by just-radovan.

the class cgeodate method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    try {
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setLayout(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
    } catch (Exception e) {
    // nothing
    }
    setContentView(R.layout.date);
    // google analytics
    base.sendAnal(this.getContext(), "/date");
    DatePicker picker = (DatePicker) findViewById(R.id.picker);
    picker.init(date.get(Calendar.YEAR), date.get(Calendar.MONTH), date.get(Calendar.DATE), new pickerListener());
}
Also used : DatePicker(android.widget.DatePicker)

Example 53 with DatePicker

use of android.widget.DatePicker in project Etar-Calendar by Etar-Group.

the class AllInOneActivity method onOptionsItemSelected.

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    Time t = null;
    int viewType = ViewType.CURRENT;
    long extras = CalendarController.EXTRA_GOTO_TIME;
    final int itemId = item.getItemId();
    if (itemId == R.id.action_refresh) {
        mController.refreshCalendars();
        return true;
    } else if (itemId == R.id.action_today) {
        t = new Time(mTimeZone);
        t.setToNow();
        extras |= CalendarController.EXTRA_GOTO_TODAY;
        mController.sendEvent(this, EventType.GO_TO, t, null, t, -1, viewType, extras, null, null);
        return true;
    } else if (itemId == R.id.action_goto) {
        Time todayTime;
        t = new Time(mTimeZone);
        t.set(mController.getTime());
        todayTime = new Time(mTimeZone);
        todayTime.setToNow();
        if (todayTime.month == t.month) {
            t = todayTime;
        }
        DatePickerDialog.OnDateSetListener datePickerListener = new DatePickerDialog.OnDateSetListener() {

            public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
                Time selectedTime = new Time(mTimeZone);
                // Needed for recalc function in DayView(time + gmtoff)
                selectedTime.setToNow();
                selectedTime.year = year;
                selectedTime.month = monthOfYear;
                selectedTime.monthDay = dayOfMonth;
                Calendar c = Calendar.getInstance();
                c.set(year, monthOfYear, dayOfMonth);
                int weekday = c.get(Calendar.DAY_OF_WEEK);
                if (weekday == 1) {
                    selectedTime.weekDay = 7;
                } else {
                    selectedTime.weekDay = weekday - 1;
                }
                long extras = CalendarController.EXTRA_GOTO_TIME | CalendarController.EXTRA_GOTO_DATE;
                mController.sendEvent(this, EventType.GO_TO, selectedTime, null, selectedTime, -1, ViewType.CURRENT, extras, null, null);
            }
        };
        DatePickerDialog datePickerDialog = new DatePickerDialog(this, datePickerListener, t.year, t.month, t.monthDay);
        datePickerDialog.getDatePicker().setFirstDayOfWeek(Utils.getFirstDayOfWeekAsCalendar(this));
        datePickerDialog.show();
    } else if (itemId == R.id.action_hide_controls) {
        mHideControls = !mHideControls;
        Utils.setSharedPreference(this, GeneralPreferences.KEY_SHOW_CONTROLS, !mHideControls);
        item.setTitle(mHideControls ? mShowString : mHideString);
        if (!mHideControls) {
            mMiniMonth.setVisibility(View.VISIBLE);
            mCalendarsList.setVisibility(View.VISIBLE);
            mMiniMonthContainer.setVisibility(View.VISIBLE);
        }
        final ObjectAnimator slideAnimation = ObjectAnimator.ofInt(this, "controlsOffset", mHideControls ? 0 : mControlsAnimateWidth, mHideControls ? mControlsAnimateWidth : 0);
        slideAnimation.setDuration(mCalendarControlsAnimationTime);
        ObjectAnimator.setFrameDelay(0);
        slideAnimation.start();
        return true;
    } else if (itemId == R.id.action_search) {
        return false;
    } else if (itemId == R.id.action_import) {
        ImportActivity.pickImportFile(this);
    } else if (itemId == R.id.action_view_settings) {
        Intent intent = new Intent(this, SettingsActivity.class);
        intent.putExtra(SettingsActivityKt.EXTRA_SHOW_FRAGMENT, ViewDetailsPreferences.class.getName());
        startActivity(intent);
    } else {
        return mExtensions.handleItemSelected(item, this);
    }
    return true;
}
Also used : DatePickerDialog(android.app.DatePickerDialog) ObjectAnimator(android.animation.ObjectAnimator) Calendar(java.util.Calendar) Time(android.text.format.Time) Intent(android.content.Intent) DatePicker(android.widget.DatePicker) ViewDetailsPreferences(com.android.calendar.settings.ViewDetailsPreferences)

Example 54 with DatePicker

use of android.widget.DatePicker in project Gadgetbridge by Freeyourgadget.

the class DebugActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_debug);
    IntentFilter filter = new IntentFilter();
    filter.addAction(ACTION_REPLY);
    filter.addAction(DeviceService.ACTION_REALTIME_SAMPLES);
    LocalBroadcastManager.getInstance(this).registerReceiver(mReceiver, filter);
    // for ACTION_REPLY
    registerReceiver(mReceiver, filter);
    editContent = findViewById(R.id.editContent);
    final ArrayList<String> spinnerArray = new ArrayList<>();
    for (NotificationType notificationType : NotificationType.values()) {
        spinnerArray.add(notificationType.name());
    }
    ArrayAdapter<String> spinnerArrayAdapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_dropdown_item, spinnerArray);
    sendTypeSpinner = findViewById(R.id.sendTypeSpinner);
    sendTypeSpinner.setAdapter(spinnerArrayAdapter);
    Button sendButton = findViewById(R.id.sendButton);
    sendButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            NotificationSpec notificationSpec = new NotificationSpec();
            String testString = editContent.getText().toString();
            notificationSpec.phoneNumber = testString;
            notificationSpec.body = testString;
            notificationSpec.sender = testString;
            notificationSpec.subject = testString;
            notificationSpec.type = NotificationType.values()[sendTypeSpinner.getSelectedItemPosition()];
            notificationSpec.pebbleColor = notificationSpec.type.color;
            GBApplication.deviceService().onNotification(notificationSpec);
        }
    });
    Button incomingCallButton = findViewById(R.id.incomingCallButton);
    incomingCallButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            CallSpec callSpec = new CallSpec();
            callSpec.command = CallSpec.CALL_INCOMING;
            callSpec.number = editContent.getText().toString();
            GBApplication.deviceService().onSetCallState(callSpec);
        }
    });
    Button outgoingCallButton = findViewById(R.id.outgoingCallButton);
    outgoingCallButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            CallSpec callSpec = new CallSpec();
            callSpec.command = CallSpec.CALL_OUTGOING;
            callSpec.number = editContent.getText().toString();
            GBApplication.deviceService().onSetCallState(callSpec);
        }
    });
    Button startCallButton = findViewById(R.id.startCallButton);
    startCallButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            CallSpec callSpec = new CallSpec();
            callSpec.command = CallSpec.CALL_START;
            GBApplication.deviceService().onSetCallState(callSpec);
        }
    });
    Button endCallButton = findViewById(R.id.endCallButton);
    endCallButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            CallSpec callSpec = new CallSpec();
            callSpec.command = CallSpec.CALL_END;
            GBApplication.deviceService().onSetCallState(callSpec);
        }
    });
    Button rebootButton = findViewById(R.id.rebootButton);
    rebootButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            GBApplication.deviceService().onReset(GBDeviceProtocol.RESET_FLAGS_REBOOT);
        }
    });
    Button factoryResetButton = findViewById(R.id.factoryResetButton);
    factoryResetButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            new AlertDialog.Builder(DebugActivity.this).setCancelable(true).setTitle(R.string.debugactivity_really_factoryreset_title).setMessage(R.string.debugactivity_really_factoryreset).setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    GBApplication.deviceService().onReset(GBDeviceProtocol.RESET_FLAGS_FACTORY_RESET);
                }
            }).setNegativeButton(R.string.Cancel, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                }
            }).show();
        }
    });
    Button heartRateButton = findViewById(R.id.HeartRateButton);
    heartRateButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            GB.toast("Measuring heart rate, please wait...", Toast.LENGTH_LONG, GB.INFO);
            GBApplication.deviceService().onHeartRateTest();
        }
    });
    Button setFetchTimeButton = findViewById(R.id.SetFetchTimeButton);
    setFetchTimeButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            final Calendar currentDate = Calendar.getInstance();
            Context context = getApplicationContext();
            if (context instanceof GBApplication) {
                GBApplication gbApp = (GBApplication) context;
                final GBDevice device = gbApp.getDeviceManager().getSelectedDevice();
                if (device != null) {
                    new DatePickerDialog(DebugActivity.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;
                            GB.toast("Setting lastSyncTimeMillis: " + timestamp, Toast.LENGTH_LONG, GB.INFO);
                            SharedPreferences.Editor editor = GBApplication.getDeviceSpecificSharedPrefs(device.getAddress()).edit();
                            // FIXME: key reconstruction is BAD
                            editor.remove("lastSyncTimeMillis");
                            editor.putLong("lastSyncTimeMillis", timestamp);
                            editor.apply();
                        }
                    }, currentDate.get(Calendar.YEAR), currentDate.get(Calendar.MONTH), currentDate.get(Calendar.DATE)).show();
                } else {
                    GB.toast("Device not selected/connected", Toast.LENGTH_LONG, GB.INFO);
                }
            }
        }
    });
    Button setMusicInfoButton = findViewById(R.id.setMusicInfoButton);
    setMusicInfoButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            MusicSpec musicSpec = new MusicSpec();
            String testString = editContent.getText().toString();
            musicSpec.artist = testString + "(artist)";
            musicSpec.album = testString + "(album)";
            musicSpec.track = testString + "(track)";
            musicSpec.duration = 10;
            musicSpec.trackCount = 5;
            musicSpec.trackNr = 2;
            GBApplication.deviceService().onSetMusicInfo(musicSpec);
            MusicStateSpec stateSpec = new MusicStateSpec();
            stateSpec.position = 0;
            // playing
            stateSpec.state = 0x01;
            stateSpec.playRate = 100;
            stateSpec.repeat = 1;
            stateSpec.shuffle = 1;
            GBApplication.deviceService().onSetMusicState(stateSpec);
        }
    });
    Button setTimeButton = findViewById(R.id.setTimeButton);
    setTimeButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            GBApplication.deviceService().onSetTime();
        }
    });
    Button testNotificationButton = findViewById(R.id.testNotificationButton);
    testNotificationButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            testNotification();
        }
    });
    Button testPebbleKitNotificationButton = findViewById(R.id.testPebbleKitNotificationButton);
    testPebbleKitNotificationButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            testPebbleKitNotification();
        }
    });
    Button fetchDebugLogsButton = findViewById(R.id.fetchDebugLogsButton);
    fetchDebugLogsButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            GBApplication.deviceService().onFetchRecordedData(RecordedDataTypes.TYPE_DEBUGLOGS);
        }
    });
    Button testNewFunctionalityButton = findViewById(R.id.testNewFunctionality);
    testNewFunctionalityButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            testNewFunctionality();
        }
    });
    Button shareLogButton = findViewById(R.id.shareLog);
    shareLogButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            showWarning();
        }
    });
    Button showWidgetsButton = findViewById(R.id.showWidgetsButton);
    showWidgetsButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            showAllRegisteredAppWidgets();
        }
    });
    Button unregisterWidgetsButton = findViewById(R.id.deleteWidgets);
    unregisterWidgetsButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            unregisterAllRegisteredAppWidgets();
        }
    });
    Button showWidgetsPrefsButton = findViewById(R.id.showWidgetsPrefs);
    showWidgetsPrefsButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            showAppWidgetsPrefs();
        }
    });
    Button deleteWidgetsPrefsButton = findViewById(R.id.deleteWidgetsPrefs);
    deleteWidgetsPrefsButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            deleteWidgetsPrefs();
        }
    });
    Button removeDevicePreferencesButton = findViewById(R.id.removeDevicePreferences);
    removeDevicePreferencesButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Context context = getApplicationContext();
            GBApplication gbApp = (GBApplication) context;
            final GBDevice device = gbApp.getDeviceManager().getSelectedDevice();
            if (device != null) {
                GBApplication.deleteDeviceSpecificSharedPrefs(device.getAddress());
            }
        }
    });
    Button runDebugFunction = findViewById(R.id.runDebugFunction);
    runDebugFunction.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
        // SharedPreferences.Editor editor = GBApplication.getPrefs().getPreferences().edit();
        // editor.remove("notification_list_is_blacklist").apply();
        }
    });
    Button addDeviceButtonDebug = findViewById(R.id.addDeviceButtonDebug);
    addDeviceButtonDebug.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            LinkedHashMap<String, Pair<Long, Integer>> allDevices;
            allDevices = getAllSupportedDevices(getApplicationContext());
            final LinearLayout linearLayout = new LinearLayout(DebugActivity.this);
            linearLayout.setOrientation(LinearLayout.VERTICAL);
            final LinearLayout macLayout = new LinearLayout(DebugActivity.this);
            macLayout.setOrientation(LinearLayout.HORIZONTAL);
            macLayout.setPadding(20, 0, 20, 0);
            final TextView textView = new TextView(DebugActivity.this);
            textView.setText("MAC Address: ");
            final EditText editText = new EditText(DebugActivity.this);
            selectedTestDeviceMAC = randomMac();
            editText.setText(selectedTestDeviceMAC);
            editText.addTextChangedListener(new TextWatcher() {

                @Override
                public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
                }

                @Override
                public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
                }

                @Override
                public void afterTextChanged(Editable editable) {
                    selectedTestDeviceMAC = editable.toString();
                }
            });
            macLayout.addView(textView);
            macLayout.addView(editText);
            final Spinner deviceListSpinner = new Spinner(DebugActivity.this);
            ArrayList<SpinnerWithIconItem> deviceListArray = new ArrayList<>();
            for (Map.Entry<String, Pair<Long, Integer>> item : allDevices.entrySet()) {
                deviceListArray.add(new SpinnerWithIconItem(item.getKey(), item.getValue().first, item.getValue().second));
            }
            final SpinnerWithIconAdapter deviceListAdapter = new SpinnerWithIconAdapter(DebugActivity.this, R.layout.spinner_with_image_layout, R.id.spinner_item_text, deviceListArray);
            deviceListSpinner.setAdapter(deviceListAdapter);
            addListenerOnSpinnerDeviceSelection(deviceListSpinner);
            linearLayout.addView(deviceListSpinner);
            linearLayout.addView(macLayout);
            new AlertDialog.Builder(DebugActivity.this).setCancelable(true).setTitle(R.string.add_test_device).setView(linearLayout).setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    createTestDevice(DebugActivity.this, selectedTestDeviceKey, selectedTestDeviceMAC);
                }
            }).setNegativeButton(R.string.Cancel, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                }
            }).show();
        }
    });
    CheckBox activity_list_debug_extra_time_range = findViewById(R.id.activity_list_debug_extra_time_range);
    activity_list_debug_extra_time_range.setAllCaps(true);
    boolean activity_list_debug_extra_time_range_value = GBApplication.getPrefs().getPreferences().getBoolean("activity_list_debug_extra_time_range", false);
    activity_list_debug_extra_time_range.setChecked(activity_list_debug_extra_time_range_value);
    activity_list_debug_extra_time_range.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
            GBApplication.getPrefs().getPreferences().getBoolean("activity_list_debug_extra_time_range", false);
            SharedPreferences.Editor editor = GBApplication.getPrefs().getPreferences().edit();
            editor.putBoolean("activity_list_debug_extra_time_range", b).apply();
        }
    });
}
Also used : AlertDialog(android.app.AlertDialog) GBApplication(nodomain.freeyourgadget.gadgetbridge.GBApplication) DialogInterface(android.content.DialogInterface) Spinner(android.widget.Spinner) ArrayList(java.util.ArrayList) SpinnerWithIconItem(nodomain.freeyourgadget.gadgetbridge.adapter.SpinnerWithIconItem) GBDevice(nodomain.freeyourgadget.gadgetbridge.impl.GBDevice) LinkedHashMap(java.util.LinkedHashMap) MusicStateSpec(nodomain.freeyourgadget.gadgetbridge.model.MusicStateSpec) MusicSpec(nodomain.freeyourgadget.gadgetbridge.model.MusicSpec) Button(android.widget.Button) CompoundButton(android.widget.CompoundButton) CallSpec(nodomain.freeyourgadget.gadgetbridge.model.CallSpec) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) TextView(android.widget.TextView) Context(android.content.Context) EditText(android.widget.EditText) IntentFilter(android.content.IntentFilter) DatePickerDialog(android.app.DatePickerDialog) Calendar(java.util.Calendar) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) CheckBox(android.widget.CheckBox) NotificationType(nodomain.freeyourgadget.gadgetbridge.model.NotificationType) NotificationSpec(nodomain.freeyourgadget.gadgetbridge.model.NotificationSpec) DatePicker(android.widget.DatePicker) ArrayAdapter(android.widget.ArrayAdapter) LinearLayout(android.widget.LinearLayout) SpinnerWithIconAdapter(nodomain.freeyourgadget.gadgetbridge.adapter.SpinnerWithIconAdapter) CompoundButton(android.widget.CompoundButton)

Example 55 with DatePicker

use of android.widget.DatePicker in project Gadgetbridge by Freeyourgadget.

the class ActivityListingDashboard method onViewCreated.

@Override
public void onViewCreated(final View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    int time = getArguments().getInt("time", 1);
    Calendar day = Calendar.getInstance();
    day.setTimeInMillis(time * 1000L);
    day.set(Calendar.HOUR_OF_DAY, 23);
    day.set(Calendar.MINUTE, 59);
    day.set(Calendar.SECOND, 59);
    timeTo = (int) (day.getTimeInMillis() / 1000);
    gbDevice = getArguments().getParcelable(GBDevice.EXTRA_DEVICE);
    if (gbDevice == null) {
        throw new IllegalArgumentException("Must provide a device when invoking this activity");
    }
    stepListAdapter = new ActivityListingAdapter(getContext());
    fragmentView = view;
    final TextView battery_status_date_from_text = (TextView) view.findViewById(R.id.battery_status_date_from_text);
    final TextView battery_status_date_to_text = (TextView) view.findViewById(R.id.battery_status_date_to_text);
    LinearLayout battery_status_date_to_layout = (LinearLayout) view.findViewById(R.id.battery_status_date_to_layout);
    final SeekBar battery_status_time_span_seekbar = (SeekBar) view.findViewById(R.id.battery_status_time_span_seekbar);
    boolean activity_list_debug_extra_time_range_value = GBApplication.getPrefs().getPreferences().getBoolean("activity_list_debug_extra_time_range", false);
    if (!activity_list_debug_extra_time_range_value) {
        battery_status_time_span_seekbar.setMax(3);
    }
    final TextView battery_status_time_span_text = (TextView) view.findViewById(R.id.battery_status_time_span_text);
    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_three_months);
                    timeFrom = DateTimeUtils.shiftMonths(timeTo, -3);
                    break;
                case 5:
                    text = getString(R.string.calendar_six_months);
                    timeFrom = DateTimeUtils.shiftMonths(timeTo, -6);
                    break;
                case 6:
                    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)));
            createRefreshTask("Visualizing data", getActivity()).execute();
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
        }
    });
    battery_status_date_to_layout.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            final Calendar currentDate = Calendar.getInstance();
            currentDate.setTimeInMillis(timeTo * 1000L);
            new DatePickerDialog(getContext(), new DatePickerDialog.OnDateSetListener() {

                @Override
                public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
                    Calendar date = Calendar.getInstance();
                    date.set(year, monthOfYear, dayOfMonth);
                    int time = (int) (date.getTimeInMillis() / 1000);
                    Calendar day = Calendar.getInstance();
                    day.setTimeInMillis(time * 1000L);
                    day.set(Calendar.HOUR_OF_DAY, 23);
                    day.set(Calendar.MINUTE, 59);
                    day.set(Calendar.SECOND, 59);
                    timeTo = (int) (day.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);
                }
            }, currentDate.get(Calendar.YEAR), currentDate.get(Calendar.MONTH), currentDate.get(Calendar.DATE)).show();
        }
    });
    battery_status_time_span_seekbar.setProgress(2);
}
Also used : SeekBar(android.widget.SeekBar) DatePickerDialog(android.app.DatePickerDialog) Calendar(java.util.Calendar) View(android.view.View) TextView(android.widget.TextView) Date(java.util.Date) TextView(android.widget.TextView) DatePicker(android.widget.DatePicker) LinearLayout(android.widget.LinearLayout)

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