Example usage for android.widget TimePicker setCurrentMinute

List of usage examples for android.widget TimePicker setCurrentMinute

Introduction

In this page you can find the example usage for android.widget TimePicker setCurrentMinute.

Prototype

@Deprecated
public void setCurrentMinute(@NonNull Integer currentMinute) 

Source Link

Document

Sets the currently selected minute.

Usage

From source file:net.czlee.debatekeeper.DebatingActivity.java

/**
 * Displays the time picker to edit the current time.
 * Does nothing if there is no debate loaded or if the timer is running.
 */// www. j  a v a2  s. co  m
private void editCurrentTimeStart() {

    // Check that things are in a valid state to enter edit time mode
    // If they aren't, return straight away
    if (mDebateManager == null)
        return;
    if (mDebateManager.isRunning())
        return;

    // Only if things were in a valid state do we enter edit time mode
    mIsEditingTime = true;

    TimePicker currentTimePicker = (TimePicker) mDebateTimerDisplay
            .findViewById(R.id.debateTimer_currentTimePicker);

    if (currentTimePicker == null) {
        Log.e(TAG, "editCurrentTimeFinish: currentTimePicker was null");
        return;
    }

    long currentTime = mDebateManager.getActivePhaseCurrentTime();

    // Invert the time if in count-down mode
    currentTime = subtractFromSpeechLengthIfCountingDown(currentTime);

    // Limit to the allowable time range
    if (currentTime < 0) {
        currentTime = 0;
        Toast.makeText(this, R.string.mainScreen_toast_editTextDiscardChangesInfo_limitedBelow,
                Toast.LENGTH_LONG).show();
    }
    if (currentTime >= 24 * 60) {
        currentTime = 24 * 60 - 1;
        Toast.makeText(this, R.string.mainScreen_toast_editTextDiscardChangesInfo_limitedAbove,
                Toast.LENGTH_LONG).show();
    }

    // We're using this in hours and minutes, not minutes and seconds
    currentTimePicker.setCurrentHour((int) (currentTime / 60));
    currentTimePicker.setCurrentMinute((int) (currentTime % 60));

    updateGui();

    // If we had to limit the time, display a helpful/apologetic message informing the user
    // of how to discard their changes, since they can't recover the time.

}

From source file:org.tvbrowser.tvbrowser.TvBrowser.java

private void updateTvData() {
    if (!TvDataUpdateService.IS_RUNNING) {
        Cursor test = getContentResolver().query(TvBrowserContentProvider.CONTENT_URI_CHANNELS, null,
                TvBrowserContentProvider.CHANNEL_KEY_SELECTION + "=1", null, null);

        if (test.getCount() > 0) {
            AlertDialog.Builder builder = new AlertDialog.Builder(TvBrowser.this);

            RelativeLayout dataDownload = (RelativeLayout) getLayoutInflater()
                    .inflate(R.layout.dialog_data_update_selection, getParentViewGroup(), false);

            final Spinner days = (Spinner) dataDownload
                    .findViewById(R.id.dialog_data_update_selection_download_days);
            final CheckBox pictures = (CheckBox) dataDownload
                    .findViewById(R.id.dialog_data_update_selection_download_picture);

            final Spinner autoUpdate = (Spinner) dataDownload
                    .findViewById(R.id.dialog_data_update_preferences_auto_update_selection_type);
            final Spinner frequency = (Spinner) dataDownload
                    .findViewById(R.id.dialog_data_update_preferences_auto_update_selection_frequency);
            final CheckBox onlyWiFi = (CheckBox) dataDownload
                    .findViewById(R.id.dialog_data_update_preferences_auto_update_selection_type_connection);
            final TextView timeLabel = (TextView) dataDownload
                    .findViewById(R.id.dialog_data_update_preferences_auto_update_selection_time_label);
            final TextView time = (TextView) dataDownload
                    .findViewById(R.id.dialog_data_update_preferences_auto_update_selection_time);
            time.setTextColor(onlyWiFi.getTextColors());

            String currentDownloadDays = PrefUtils.getStringValue(R.string.DAYS_TO_DOWNLOAD,
                    R.string.days_to_download_default);

            final String[] possibleDownloadDays = getResources().getStringArray(R.array.download_days);

            for (int i = 0; i < possibleDownloadDays.length; i++) {
                if (currentDownloadDays.equals(possibleDownloadDays[i])) {
                    days.setSelection(i);
                    break;
                }/*from  w ww . ja v a2 s. c o m*/
            }

            pictures.setChecked(
                    PrefUtils.getBooleanValue(R.string.LOAD_PICTURE_DATA, R.bool.load_picture_data_default));

            String currentAutoUpdateValue = PrefUtils.getStringValue(R.string.PREF_AUTO_UPDATE_TYPE,
                    R.string.pref_auto_update_type_default);
            String currentAutoUpdateFrequency = PrefUtils.getStringValue(R.string.PREF_AUTO_UPDATE_FREQUENCY,
                    R.string.pref_auto_update_frequency_default);

            if (currentAutoUpdateValue.equals("0")) {
                frequency.setEnabled(false);
                onlyWiFi.setEnabled(false);
                timeLabel.setEnabled(false);
                time.setEnabled(false);
                frequency.setVisibility(View.GONE);
                onlyWiFi.setVisibility(View.GONE);
                timeLabel.setVisibility(View.GONE);
                time.setVisibility(View.GONE);
            } else if (currentAutoUpdateValue.equals("1")) {
                autoUpdate.setSelection(1);
                timeLabel.setEnabled(false);
                time.setEnabled(false);
                timeLabel.setVisibility(View.GONE);
                time.setVisibility(View.GONE);
            } else if (currentAutoUpdateValue.equals("2")) {
                autoUpdate.setSelection(2);
            }

            final String[] autoFrequencyPossibleValues = getResources()
                    .getStringArray(R.array.pref_auto_update_frequency_values);

            for (int i = 0; i < autoFrequencyPossibleValues.length; i++) {
                if (autoFrequencyPossibleValues[i].equals(currentAutoUpdateFrequency)) {
                    frequency.setSelection(i);
                    break;
                }
            }

            onlyWiFi.setChecked(PrefUtils.getBooleanValue(R.string.PREF_AUTO_UPDATE_ONLY_WIFI,
                    R.bool.pref_auto_update_only_wifi_default));

            final AtomicInteger currentAutoUpdateTime = new AtomicInteger(PrefUtils.getIntValue(
                    R.string.PREF_AUTO_UPDATE_START_TIME, R.integer.pref_auto_update_start_time_default));

            Calendar now = Calendar.getInstance();

            now.set(Calendar.HOUR_OF_DAY, currentAutoUpdateTime.get() / 60);
            now.set(Calendar.MINUTE, currentAutoUpdateTime.get() % 60);
            now.set(Calendar.SECOND, 0);
            now.set(Calendar.MILLISECOND, 0);

            time.setText(DateFormat.getTimeFormat(TvBrowser.this).format(now.getTime()));

            autoUpdate.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
                @Override
                public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                    frequency.setEnabled(position != 0);
                    onlyWiFi.setEnabled(position != 0);

                    if (position != 0) {
                        frequency.setVisibility(View.VISIBLE);
                        onlyWiFi.setVisibility(View.VISIBLE);
                    } else {
                        frequency.setVisibility(View.GONE);
                        onlyWiFi.setVisibility(View.GONE);
                    }

                    timeLabel.setEnabled(position == 2);
                    time.setEnabled(position == 2);

                    if (position == 2) {
                        timeLabel.setVisibility(View.VISIBLE);
                        time.setVisibility(View.VISIBLE);
                    } else {
                        timeLabel.setVisibility(View.GONE);
                        time.setVisibility(View.GONE);
                    }
                }

                @Override
                public void onNothingSelected(AdapterView<?> parent) {

                }
            });

            View.OnClickListener onClickListener = new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    AlertDialog.Builder b2 = new AlertDialog.Builder(TvBrowser.this);

                    LinearLayout timeSelection = (LinearLayout) getLayoutInflater().inflate(
                            R.layout.dialog_data_update_selection_auto_update_time, getParentViewGroup(),
                            false);

                    final TimePicker timePick = (TimePicker) timeSelection
                            .findViewById(R.id.dialog_data_update_selection_auto_update_selection_time);
                    timePick.setIs24HourView(DateFormat.is24HourFormat(TvBrowser.this));
                    timePick.setCurrentHour(currentAutoUpdateTime.get() / 60);
                    timePick.setCurrentMinute(currentAutoUpdateTime.get() % 60);

                    b2.setView(timeSelection);

                    b2.setPositiveButton(android.R.string.ok, new OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            currentAutoUpdateTime
                                    .set(timePick.getCurrentHour() * 60 + timePick.getCurrentMinute());

                            Calendar now = Calendar.getInstance();

                            now.set(Calendar.HOUR_OF_DAY, currentAutoUpdateTime.get() / 60);
                            now.set(Calendar.MINUTE, currentAutoUpdateTime.get() % 60);
                            now.set(Calendar.SECOND, 0);
                            now.set(Calendar.MILLISECOND, 0);

                            time.setText(DateFormat.getTimeFormat(TvBrowser.this).format(now.getTime()));
                        }
                    });
                    b2.setNegativeButton(android.R.string.cancel, null);

                    b2.show();
                }
            };

            time.setOnClickListener(onClickListener);
            timeLabel.setOnClickListener(onClickListener);

            builder.setTitle(R.string.download_data);
            builder.setView(dataDownload);

            builder.setPositiveButton(android.R.string.ok, new OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    String value = possibleDownloadDays[days.getSelectedItemPosition()];

                    Editor settings = PreferenceManager.getDefaultSharedPreferences(TvBrowser.this).edit();

                    if (PrefUtils.getStringValueAsInt(R.string.PREF_AUTO_UPDATE_RANGE,
                            R.string.pref_auto_update_range_default) < Integer.parseInt(value)) {
                        settings.putString(getString(R.string.PREF_AUTO_UPDATE_RANGE), value);
                    }

                    settings.putString(getString(R.string.DAYS_TO_DOWNLOAD), value);
                    settings.putBoolean(getString(R.string.LOAD_PICTURE_DATA), pictures.isChecked());
                    settings.putString(getString(R.string.PREF_AUTO_UPDATE_TYPE),
                            String.valueOf(autoUpdate.getSelectedItemPosition()));

                    if (autoUpdate.getSelectedItemPosition() == 1
                            || autoUpdate.getSelectedItemPosition() == 2) {
                        settings.putString(getString(R.string.PREF_AUTO_UPDATE_FREQUENCY),
                                autoFrequencyPossibleValues[frequency.getSelectedItemPosition()]);
                        settings.putBoolean(getString(R.string.PREF_AUTO_UPDATE_ONLY_WIFI),
                                onlyWiFi.isChecked());

                        if (autoUpdate.getSelectedItemPosition() == 2) {
                            settings.putInt(getString(R.string.PREF_AUTO_UPDATE_START_TIME),
                                    currentAutoUpdateTime.get());
                        }
                    }

                    settings.commit();

                    IOUtils.handleDataUpdatePreferences(TvBrowser.this);

                    Intent startDownload = new Intent(TvBrowser.this, TvDataUpdateService.class);
                    startDownload.putExtra(TvDataUpdateService.TYPE, TvDataUpdateService.TV_DATA_TYPE);
                    startDownload.putExtra(getResources().getString(R.string.DAYS_TO_DOWNLOAD),
                            Integer.parseInt(value));

                    startService(startDownload);

                    updateProgressIcon(true);
                }
            });
            builder.setNegativeButton(android.R.string.cancel, null);
            builder.show();
        } else {
            Cursor test2 = getContentResolver().query(TvBrowserContentProvider.CONTENT_URI_CHANNELS, null, null,
                    null, null);

            boolean loadAgain = test2.getCount() < 1;

            test2.close();

            selectChannels(loadAgain);
        }

        test.close();
    }
}