Search in sources :

Example 1 with DatePickerFragment

use of com.eveningoutpost.dexdrip.profileeditor.DatePickerFragment in project xDrip by NightscoutFoundation.

the class StartNewSensor method sensorButtonClick.

private void sensorButtonClick() {
    ucalendar = Calendar.getInstance();
    final AlertDialog.Builder builder = new AlertDialog.Builder(activity);
    builder.setTitle("Did you insert it today?");
    builder.setMessage("We need to know when the sensor was inserted to improve calculation accuracy.\n\nWas it inserted today?");
    builder.setPositiveButton("YES, today", new DialogInterface.OnClickListener() {

        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
            askSesorInsertionTime();
        }
    });
    builder.setNegativeButton("Not today", new DialogInterface.OnClickListener() {

        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
            if (DexCollectionType.hasLibre()) {
                ucalendar.add(Calendar.DAY_OF_MONTH, -1);
                realStartSensor();
            } else {
                final DatePickerFragment datePickerFragment = new DatePickerFragment();
                datePickerFragment.setAllowFuture(false);
                if (!Home.get_engineering_mode()) {
                    // 30 days
                    datePickerFragment.setEarliestDate(JoH.tsl() - (30L * 24 * 60 * 60 * 1000));
                }
                datePickerFragment.setTitle("Which day was it inserted?");
                datePickerFragment.setDateCallback(new ProfileAdapter.DatePickerCallbacks() {

                    @Override
                    public void onDateSet(int year, int month, int day) {
                        ucalendar.set(year, month, day);
                        // Long enough in the past for age adjustment to be meaningless? Skip asking time
                        if ((!Home.get_engineering_mode()) && (JoH.tsl() - ucalendar.getTimeInMillis() > (AGE_ADJUSTMENT_TIME + (1000 * 60 * 60 * 24)))) {
                            realStartSensor();
                        } else {
                            askSesorInsertionTime();
                        }
                    }
                });
                datePickerFragment.show(activity.getFragmentManager(), "DatePicker");
            }
        }
    });
    builder.create().show();
}
Also used : AlertDialog(android.app.AlertDialog) DatePickerFragment(com.eveningoutpost.dexdrip.profileeditor.DatePickerFragment) DialogInterface(android.content.DialogInterface)

Example 2 with DatePickerFragment

use of com.eveningoutpost.dexdrip.profileeditor.DatePickerFragment in project xDrip by NightscoutFoundation.

the class Home method onOptionsItemSelected.

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch(item.getItemId()) {
        case R.id.action_resend_last_bg:
            startService(new Intent(this, WatchUpdaterService.class).setAction(WatchUpdaterService.ACTION_RESEND));
            break;
        case R.id.action_open_watch_settings:
            startService(new Intent(this, WatchUpdaterService.class).setAction(WatchUpdaterService.ACTION_OPEN_SETTINGS));
            break;
        case R.id.action_sync_watch_db:
            startService(new Intent(this, WatchUpdaterService.class).setAction(WatchUpdaterService.ACTION_RESET_DB));
            break;
    }
    if (item.getItemId() == R.id.action_export_database) {
        new AsyncTask<Void, Void, String>() {

            @Override
            protected String doInBackground(Void... params) {
                int permissionCheck = ContextCompat.checkSelfPermission(Home.this, Manifest.permission.READ_EXTERNAL_STORAGE);
                if (permissionCheck != PackageManager.PERMISSION_GRANTED) {
                    ActivityCompat.requestPermissions(Home.this, new String[] { Manifest.permission.READ_EXTERNAL_STORAGE }, 0);
                    return null;
                } else {
                    return DatabaseUtil.saveSql(getBaseContext());
                }
            }

            @Override
            protected void onPostExecute(String filename) {
                super.onPostExecute(filename);
                if (filename != null) {
                    snackBar(R.string.share, getString(R.string.exported_to) + filename, makeSnackBarUriLauncher(Uri.fromFile(new File(filename)), "Share database..."), Home.this);
                    startActivity(new Intent(xdrip.getAppContext(), SdcardImportExport.class).putExtra("backup", "now").setFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
                /*    SnackbarManager.show(
                                Snackbar.with(Home.this)
                                        .type(SnackbarType.MULTI_LINE)
                                        .duration(4000)
                                        .text(getString(R.string.exported_to) + filename) // text to display
                                        .actionLabel("Share") // action button label
                                        .actionListener(new SnackbarUriListener(Uri.fromFile(new File(filename)))),
                                Home.this);*/
                } else {
                    Toast.makeText(Home.this, R.string.could_not_export_database, Toast.LENGTH_LONG).show();
                }
            }
        }.execute();
        return true;
    }
    if (item.getItemId() == R.id.action_import_db) {
        startActivity(new Intent(this, ImportDatabaseActivity.class));
        return true;
    }
    if (item.getItemId() == R.id.action_export_csv_sidiary) {
        long from = Pref.getLong("sidiary_last_exportdate", 0);
        final GregorianCalendar date = new GregorianCalendar();
        final DatePickerFragment datePickerFragment = new DatePickerFragment();
        if (from > 0)
            datePickerFragment.setInitiallySelectedDate(from);
        datePickerFragment.setAllowFuture(false);
        datePickerFragment.setTitle(getString(R.string.sidiary_date_title));
        datePickerFragment.setDateCallback(new ProfileAdapter.DatePickerCallbacks() {

            @Override
            public void onDateSet(int year, int month, int day) {
                date.set(year, month, day);
                date.set(Calendar.HOUR_OF_DAY, 0);
                date.set(Calendar.MINUTE, 0);
                date.set(Calendar.SECOND, 0);
                date.set(Calendar.MILLISECOND, 0);
                new AsyncTask<Void, Void, String>() {

                    @Override
                    protected String doInBackground(Void... params) {
                        return DatabaseUtil.saveCSV(getBaseContext(), date.getTimeInMillis());
                    }

                    @Override
                    protected void onPostExecute(String filename) {
                        super.onPostExecute(filename);
                        if (filename != null) {
                            Pref.setLong("sidiary_last_exportdate", System.currentTimeMillis());
                            snackBar(R.string.share, getString(R.string.exported_to) + filename, makeSnackBarUriLauncher(Uri.fromFile(new File(filename)), "Share database..."), Home.this);
                        } else {
                            Toast.makeText(Home.this, "Could not export CSV :(", Toast.LENGTH_LONG).show();
                        }
                    }
                }.execute();
            }
        });
        datePickerFragment.show(getFragmentManager(), "DatePicker");
        return true;
    }
    if (item.getItemId() == R.id.action_toggle_speakreadings) {
        Pref.toggleBoolean("bg_to_speech");
        invalidateOptionsMenu();
        if (Pref.getBooleanDefaultFalse("bg_to_speech")) {
            BgToSpeech.testSpeech();
        }
        return true;
    }
    return super.onOptionsItemSelected(item);
}
Also used : DatePickerFragment(com.eveningoutpost.dexdrip.profileeditor.DatePickerFragment) ProfileAdapter(com.eveningoutpost.dexdrip.profileeditor.ProfileAdapter) GregorianCalendar(java.util.GregorianCalendar) AsyncTask(android.os.AsyncTask) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) RecognizerIntent(android.speech.RecognizerIntent) Paint(android.graphics.Paint) Point(android.graphics.Point) File(java.io.File)

Example 3 with DatePickerFragment

use of com.eveningoutpost.dexdrip.profileeditor.DatePickerFragment in project xDrip-plus by jamorham.

the class NightscoutBackfillActivity method backfillPick.

public void backfillPick(View v) {
    final DatePickerFragment datePickerFragment = new DatePickerFragment();
    datePickerFragment.setAllowFuture(false);
    datePickerFragment.setInitiallySelectedDate(calendar.getTimeInMillis());
    datePickerFragment.setTitle("How far back?");
    datePickerFragment.setDateCallback(new ProfileAdapter.DatePickerCallbacks() {

        @Override
        public void onDateSet(int year, int month, int day) {
            calendar.set(year, month, day);
            updateDateButton();
        }
    });
    datePickerFragment.show(this.getFragmentManager(), "DatePicker");
}
Also used : DatePickerFragment(com.eveningoutpost.dexdrip.profileeditor.DatePickerFragment) ProfileAdapter(com.eveningoutpost.dexdrip.profileeditor.ProfileAdapter)

Example 4 with DatePickerFragment

use of com.eveningoutpost.dexdrip.profileeditor.DatePickerFragment in project xDrip by NightscoutFoundation.

the class Reminders method askTime.

// //
private void askTime(final int position) {
    final Calendar calendar = Calendar.getInstance();
    final Reminder reminder = reminders.get(position);
    calendar.setTimeInMillis(reminder.next_due);
    final TimePickerFragment timePickerFragment = new TimePickerFragment();
    timePickerFragment.setTime(calendar.get(Calendar.HOUR_OF_DAY), calendar.get(Calendar.MINUTE));
    timePickerFragment.setTitle("What time of day?");
    timePickerFragment.setTimeCallback(new ProfileAdapter.TimePickerCallbacks() {

        @Override
        public void onTimeUpdated(int newmins) {
            int min = newmins % 60;
            int hour = (newmins - min) / 60;
            calendar.set(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH), hour, min);
            reminder.next_due = calendar.getTimeInMillis();
            // reset this field
            reminder.snoozed_till = 0;
            reminder.save();
            freshen(reminder);
        }
    });
    timePickerFragment.show(this.getFragmentManager(), "TimePicker");
    // appears on top
    if (JoH.msTill(reminder.next_due) > Constants.DAY_IN_MS) {
        final DatePickerFragment datePickerFragment = new DatePickerFragment();
        datePickerFragment.setAllowFuture(true);
        datePickerFragment.setEarliestDate(JoH.tsl());
        datePickerFragment.setInitiallySelectedDate(reminder.next_due);
        datePickerFragment.setTitle("Which day?");
        datePickerFragment.setDateCallback(new ProfileAdapter.DatePickerCallbacks() {

            @Override
            public void onDateSet(int year, int month, int day) {
                calendar.set(year, month, day);
            }
        });
        datePickerFragment.show(this.getFragmentManager(), "DatePicker");
    }
}
Also used : ProfileAdapter(com.eveningoutpost.dexdrip.profileeditor.ProfileAdapter) DatePickerFragment(com.eveningoutpost.dexdrip.profileeditor.DatePickerFragment) Reminder(com.eveningoutpost.dexdrip.Models.Reminder) TimePickerFragment(com.eveningoutpost.dexdrip.profileeditor.TimePickerFragment) Calendar(java.util.Calendar)

Example 5 with DatePickerFragment

use of com.eveningoutpost.dexdrip.profileeditor.DatePickerFragment in project xDrip by NightscoutFoundation.

the class NightscoutBackfillActivity method backfillPick.

public void backfillPick(View v) {
    final DatePickerFragment datePickerFragment = new DatePickerFragment();
    datePickerFragment.setAllowFuture(false);
    datePickerFragment.setInitiallySelectedDate(calendar.getTimeInMillis());
    datePickerFragment.setTitle("How far back?");
    datePickerFragment.setDateCallback(new ProfileAdapter.DatePickerCallbacks() {

        @Override
        public void onDateSet(int year, int month, int day) {
            calendar.set(year, month, day);
            updateDateButton();
        }
    });
    datePickerFragment.show(this.getFragmentManager(), "DatePicker");
}
Also used : DatePickerFragment(com.eveningoutpost.dexdrip.profileeditor.DatePickerFragment) ProfileAdapter(com.eveningoutpost.dexdrip.profileeditor.ProfileAdapter)

Aggregations

DatePickerFragment (com.eveningoutpost.dexdrip.profileeditor.DatePickerFragment)8 ProfileAdapter (com.eveningoutpost.dexdrip.profileeditor.ProfileAdapter)6 AlertDialog (android.app.AlertDialog)2 PendingIntent (android.app.PendingIntent)2 DialogInterface (android.content.DialogInterface)2 Intent (android.content.Intent)2 Paint (android.graphics.Paint)2 Point (android.graphics.Point)2 AsyncTask (android.os.AsyncTask)2 RecognizerIntent (android.speech.RecognizerIntent)2 Reminder (com.eveningoutpost.dexdrip.Models.Reminder)2 TimePickerFragment (com.eveningoutpost.dexdrip.profileeditor.TimePickerFragment)2 File (java.io.File)2 Calendar (java.util.Calendar)2 GregorianCalendar (java.util.GregorianCalendar)2