Search in sources :

Example 1 with TimeDurationPicker

use of mobi.upod.timedurationpicker.TimeDurationPicker in project PhoneProfilesPlus by henrichg.

the class DurationDialogPreference method showDialog.

@SuppressLint("SetTextI18n")
@Override
protected void showDialog(Bundle state) {
    MaterialDialog.Builder mBuilder = new MaterialDialog.Builder(getContext()).title(getDialogTitle()).icon(getDialogIcon()).positiveText(getPositiveButtonText()).negativeText(getNegativeButtonText()).content(getDialogMessage()).customView(R.layout.activity_duration_pref_dialog, true).onPositive(new MaterialDialog.SingleButtonCallback() {

        @Override
        public void onClick(@NonNull MaterialDialog materialDialog, @NonNull DialogAction dialogAction) {
            int hours = mSeekBarHours.getProgress();
            int minutes = mSeekBarMinutes.getProgress();
            int seconds = mSeekBarSeconds.getProgress();
            int iValue = (hours * 3600 + minutes * 60 + seconds);
            if (iValue < mMin)
                iValue = mMin;
            if (iValue > mMax)
                iValue = mMax;
            value = String.valueOf(iValue);
            if (callChangeListener(value)) {
                // persistInt(mNumberPicker.getValue());
                persistString(value);
                setSummaryDDP();
            }
        }
    });
    mDialog = mBuilder.build();
    View layout = mDialog.getCustomView();
    // noinspection ConstantConditions
    TextView mTextViewRange = layout.findViewById(R.id.duration_pref_dlg_range);
    mValue = layout.findViewById(R.id.duration_pref_dlg_value);
    mSeekBarHours = layout.findViewById(R.id.duration_pref_dlg_hours);
    mSeekBarMinutes = layout.findViewById(R.id.duration_pref_dlg_minutes);
    mSeekBarSeconds = layout.findViewById(R.id.duration_pref_dlg_seconds);
    // mSeekBarHours.setRotation(180);
    // mSeekBarMinutes.setRotation(180);
    // mSeekBarSeconds.setRotation(180);
    // Initialize state
    int hours;
    int minutes;
    int seconds;
    hours = mMax / 3600;
    minutes = (mMax % 3600) / 60;
    seconds = mMax % 60;
    final String sMax = GlobalGUIRoutines.getDurationString(mMax);
    mSeekBarHours.setMax(hours);
    if (hours == 0)
        mSeekBarMinutes.setMax(minutes);
    else
        mSeekBarMinutes.setMax(59);
    if ((hours == 0) && (minutes == 0))
        mSeekBarSeconds.setMax(seconds);
    else
        mSeekBarSeconds.setMax(59);
    final String sMin = GlobalGUIRoutines.getDurationString(mMin);
    int iValue = Integer.valueOf(value);
    hours = iValue / 3600;
    minutes = (iValue % 3600) / 60;
    seconds = iValue % 60;
    mSeekBarHours.setProgress(hours);
    mSeekBarMinutes.setProgress(minutes);
    mSeekBarSeconds.setProgress(seconds);
    mValue.setText(GlobalGUIRoutines.getDurationString(iValue));
    mValueDialog = new TimeDurationPickerDialog(context, new TimeDurationPickerDialog.OnDurationSetListener() {

        @Override
        public void onDurationSet(TimeDurationPicker view, long duration) {
            int iValue = (int) duration / 1000;
            if (iValue < mMin)
                iValue = mMin;
            if (iValue > mMax)
                iValue = mMax;
            mValue.setText(GlobalGUIRoutines.getDurationString(iValue));
            int hours = iValue / 3600;
            int minutes = (iValue % 3600) / 60;
            int seconds = iValue % 60;
            mSeekBarHours.setProgress(hours);
            mSeekBarMinutes.setProgress(minutes);
            mSeekBarSeconds.setProgress(seconds);
        }
    }, iValue * 1000, TimeDurationPicker.HH_MM_SS);
    mValue.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            int hours = mSeekBarHours.getProgress();
            int minutes = mSeekBarMinutes.getProgress();
            int seconds = mSeekBarSeconds.getProgress();
            int iValue = (hours * 3600 + minutes * 60 + seconds);
            if (iValue < mMin)
                iValue = mMin;
            if (iValue > mMax)
                iValue = mMax;
            mValueDialog.setDuration(iValue * 1000);
            mValueDialog.show();
        }
    });
    mSeekBarHours.setOnSeekBarChangeListener(this);
    mSeekBarMinutes.setOnSeekBarChangeListener(this);
    mSeekBarSeconds.setOnSeekBarChangeListener(this);
    mTextViewRange.setText(sMin + " - " + sMax);
    GlobalGUIRoutines.registerOnActivityDestroyListener(this, this);
    if (state != null)
        mDialog.onRestoreInstanceState(state);
    mDialog.setOnDismissListener(this);
    mDialog.show();
}
Also used : MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) TimeDurationPicker(mobi.upod.timedurationpicker.TimeDurationPicker) TextView(android.widget.TextView) View(android.view.View) SuppressLint(android.annotation.SuppressLint) DialogAction(com.afollestad.materialdialogs.DialogAction) TimeDurationPickerDialog(mobi.upod.timedurationpicker.TimeDurationPickerDialog) TextView(android.widget.TextView) SuppressLint(android.annotation.SuppressLint)

Example 2 with TimeDurationPicker

use of mobi.upod.timedurationpicker.TimeDurationPicker in project PhoneProfilesPlus by henrichg.

the class MobileCellsRegistrationDialogPreference method showDialog.

@SuppressLint("SetTextI18n")
@Override
protected void showDialog(Bundle state) {
    MaterialDialog.Builder mBuilder = new MaterialDialog.Builder(getContext()).title(getDialogTitle()).icon(getDialogIcon()).positiveText(R.string.mobile_cells_registration_pref_dlg_start_button).negativeText(getNegativeButtonText()).content(getDialogMessage()).customView(R.layout.activity_mobile_cells_registration_pref_dialog, true).onPositive(new MaterialDialog.SingleButtonCallback() {

        @Override
        public void onClick(@NonNull MaterialDialog materialDialog, @NonNull DialogAction dialogAction) {
            int hours = mSeekBarHours.getProgress();
            int minutes = mSeekBarMinutes.getProgress();
            int seconds = mSeekBarSeconds.getProgress();
            int iValue = (hours * 3600 + minutes * 60 + seconds);
            if (iValue < mMin)
                iValue = mMin;
            if (iValue > mMax)
                iValue = mMax;
            // Log.d("MobileCellsRegistrationDialogPreference.onPositive","iValue="+iValue);
            // Log.d("MobileCellsRegistrationDialogPreference.onPositive","is started");
            MobileCellsRegistrationService.setMobileCellsAutoRegistrationRemainingDuration(context, iValue);
            PhoneStateScanner.durationForAutoRegistration = iValue;
            PhoneStateScanner.cellsNameForAutoRegistration = mCellsName.getText().toString();
            PhoneStateScanner.enabledAutoRegistration = true;
            MobileCellsRegistrationService.setMobileCellsAutoRegistration(context, false);
            PhoneStateScanner.startAutoRegistration(context);
            value = String.valueOf(iValue);
            setSummaryDDP(0);
        /*
                        value = String.valueOf(iValue);

                        if (callChangeListener(value)) {
                            //persistInt(mNumberPicker.getValue());
                            persistString(value);
                        }
                        */
        }
    });
    mBuilder.showListener(new DialogInterface.OnShowListener() {

        @Override
        public void onShow(DialogInterface dialog) {
            updateInterface(0, false);
        }
    });
    mDialog = mBuilder.build();
    View layout = mDialog.getCustomView();
    // noinspection ConstantConditions
    TextView mTextViewRange = layout.findViewById(R.id.duration_pref_dlg_range);
    // noinspection ConstantConditions
    mValue = layout.findViewById(R.id.duration_pref_dlg_value);
    // noinspection ConstantConditions
    mSeekBarHours = layout.findViewById(R.id.duration_pref_dlg_hours);
    // noinspection ConstantConditions
    mSeekBarMinutes = layout.findViewById(R.id.duration_pref_dlg_minutes);
    // noinspection ConstantConditions
    mSeekBarSeconds = layout.findViewById(R.id.duration_pref_dlg_seconds);
    // noinspection ConstantConditions
    mCellsName = layout.findViewById(R.id.mobile_cells_registration_cells_name);
    // noinspection ConstantConditions
    mStatus = layout.findViewById(R.id.mobile_cells_registration_status);
    // noinspection ConstantConditions
    mRemainingTime = layout.findViewById(R.id.mobile_cells_registration_remaining_time);
    mCellsName.addTextChangedListener(new TextWatcher() {

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }

        @Override
        public void afterTextChanged(Editable s) {
            String value = mCellsName.getText().toString();
            MDButton button = mDialog.getActionButton(DialogAction.POSITIVE);
            button.setEnabled(!value.isEmpty());
        }
    });
    // mSeekBarHours.setRotation(180);
    // mSeekBarMinutes.setRotation(180);
    // mSeekBarSeconds.setRotation(180);
    // Initialize state
    int hours;
    int minutes;
    int seconds;
    hours = mMax / 3600;
    minutes = (mMax % 3600) / 60;
    seconds = mMax % 60;
    final String sMax = GlobalGUIRoutines.getDurationString(mMax);
    mSeekBarHours.setMax(hours);
    if (hours == 0)
        mSeekBarMinutes.setMax(minutes);
    else
        mSeekBarMinutes.setMax(59);
    if ((hours == 0) && (minutes == 0))
        mSeekBarSeconds.setMax(seconds);
    else
        mSeekBarSeconds.setMax(59);
    final String sMin = GlobalGUIRoutines.getDurationString(mMin);
    int iValue = Integer.valueOf(value);
    hours = iValue / 3600;
    minutes = (iValue % 3600) / 60;
    seconds = iValue % 60;
    mSeekBarHours.setProgress(hours);
    mSeekBarMinutes.setProgress(minutes);
    mSeekBarSeconds.setProgress(seconds);
    mValue.setText(GlobalGUIRoutines.getDurationString(iValue));
    mValueDialog = new TimeDurationPickerDialog(context, new TimeDurationPickerDialog.OnDurationSetListener() {

        @Override
        public void onDurationSet(TimeDurationPicker view, long duration) {
            int iValue = (int) duration / 1000;
            if (iValue < mMin)
                iValue = mMin;
            if (iValue > mMax)
                iValue = mMax;
            mValue.setText(GlobalGUIRoutines.getDurationString(iValue));
            int hours = iValue / 3600;
            int minutes = (iValue % 3600) / 60;
            int seconds = iValue % 60;
            mSeekBarHours.setProgress(hours);
            mSeekBarMinutes.setProgress(minutes);
            mSeekBarSeconds.setProgress(seconds);
        }
    }, iValue * 1000, TimeDurationPicker.HH_MM_SS);
    mValue.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            int hours = mSeekBarHours.getProgress();
            int minutes = mSeekBarMinutes.getProgress();
            int seconds = mSeekBarSeconds.getProgress();
            int iValue = (hours * 3600 + minutes * 60 + seconds);
            if (iValue < mMin)
                iValue = mMin;
            if (iValue > mMax)
                iValue = mMax;
            mValueDialog.setDuration(iValue * 1000);
            mValueDialog.show();
        }
    });
    mMobileCellNamesDialog = new MobileCellNamesDialog(context, this, false);
    mCellsName.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            mMobileCellNamesDialog.show();
        }
    });
    mSeekBarHours.setOnSeekBarChangeListener(this);
    mSeekBarMinutes.setOnSeekBarChangeListener(this);
    mSeekBarSeconds.setOnSeekBarChangeListener(this);
    mTextViewRange.setText(sMin + " - " + sMax);
    stopButton = layout.findViewById(R.id.mobile_cells_registration_stop_button);
    stopButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            updateInterface(0, true);
            MobileCellsRegistrationService.setMobileCellsAutoRegistrationRemainingDuration(context, 0);
            // PPApplication.phoneProfilesService.phoneStateScanner.durationForAutoRegistration = 0;
            // PPApplication.phoneProfilesService.phoneStateScanner.cellsNameForAutoRegistration = "";
            PhoneStateScanner.enabledAutoRegistration = false;
            MobileCellsRegistrationService.setMobileCellsAutoRegistration(context, false);
            setSummaryDDP(0);
            PhoneStateScanner.stopAutoRegistration(context);
        }
    });
    GlobalGUIRoutines.registerOnActivityDestroyListener(this, this);
    if (state != null)
        mDialog.onRestoreInstanceState(state);
    mDialog.setOnDismissListener(this);
    String value = mCellsName.getText().toString();
    MDButton button = mDialog.getActionButton(DialogAction.POSITIVE);
    button.setEnabled(!value.isEmpty());
    mDialog.show();
}
Also used : MDButton(com.afollestad.materialdialogs.internal.MDButton) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) DialogInterface(android.content.DialogInterface) TimeDurationPicker(mobi.upod.timedurationpicker.TimeDurationPicker) TextView(android.widget.TextView) View(android.view.View) SuppressLint(android.annotation.SuppressLint) DialogAction(com.afollestad.materialdialogs.DialogAction) TimeDurationPickerDialog(mobi.upod.timedurationpicker.TimeDurationPickerDialog) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) TextView(android.widget.TextView) SuppressLint(android.annotation.SuppressLint)

Example 3 with TimeDurationPicker

use of mobi.upod.timedurationpicker.TimeDurationPicker in project PhoneProfiles by henrichg.

the class DurationDialogPreference method showDialog.

@SuppressLint("SetTextI18n")
@Override
protected void showDialog(Bundle state) {
    MaterialDialog.Builder mBuilder = new MaterialDialog.Builder(getContext()).title(getDialogTitle()).icon(getDialogIcon()).positiveText(getPositiveButtonText()).negativeText(getNegativeButtonText()).content(getDialogMessage()).customView(R.layout.activity_duration_pref_dialog, true).onPositive(new MaterialDialog.SingleButtonCallback() {

        @Override
        public void onClick(@NonNull MaterialDialog materialDialog, @NonNull DialogAction dialogAction) {
            int hours = mSeekBarHours.getProgress();
            int minutes = mSeekBarMinutes.getProgress();
            int seconds = mSeekBarSeconds.getProgress();
            int iValue = (hours * 3600 + minutes * 60 + seconds);
            if (iValue < mMin)
                iValue = mMin;
            if (iValue > mMax)
                iValue = mMax;
            value = String.valueOf(iValue);
            if (callChangeListener(value)) {
                // persistInt(mNumberPicker.getValue());
                persistString(value);
                setSummaryDDP();
            }
        }
    });
    mDialog = mBuilder.build();
    View layout = mDialog.getCustomView();
    // noinspection ConstantConditions
    TextView mTextViewRange = layout.findViewById(R.id.duration_pref_dlg_range);
    // noinspection ConstantConditions
    mValue = layout.findViewById(R.id.duration_pref_dlg_value);
    // noinspection ConstantConditions
    mSeekBarHours = layout.findViewById(R.id.duration_pref_dlg_hours);
    // noinspection ConstantConditions
    mSeekBarMinutes = layout.findViewById(R.id.duration_pref_dlg_minutes);
    // noinspection ConstantConditions
    mSeekBarSeconds = layout.findViewById(R.id.duration_pref_dlg_seconds);
    // mSeekBarHours.setRotation(180);
    // mSeekBarMinutes.setRotation(180);
    // mSeekBarSeconds.setRotation(180);
    // Initialize state
    int hours;
    int minutes;
    int seconds;
    hours = mMax / 3600;
    minutes = (mMax % 3600) / 60;
    seconds = mMax % 60;
    final String sMax = GlobalGUIRoutines.getDurationString(mMax);
    mSeekBarHours.setMax(hours);
    if (hours == 0)
        mSeekBarMinutes.setMax(minutes);
    else
        mSeekBarMinutes.setMax(59);
    if ((hours == 0) && (minutes == 0))
        mSeekBarSeconds.setMax(seconds);
    else
        mSeekBarSeconds.setMax(59);
    final String sMin = GlobalGUIRoutines.getDurationString(mMin);
    int iValue = Integer.valueOf(value);
    hours = iValue / 3600;
    minutes = (iValue % 3600) / 60;
    seconds = iValue % 60;
    mSeekBarHours.setProgress(hours);
    mSeekBarMinutes.setProgress(minutes);
    mSeekBarSeconds.setProgress(seconds);
    mValue.setText(GlobalGUIRoutines.getDurationString(iValue));
    mValueDialog = new TimeDurationPickerDialog(context, new TimeDurationPickerDialog.OnDurationSetListener() {

        @Override
        public void onDurationSet(TimeDurationPicker view, long duration) {
            int iValue = (int) duration / 1000;
            if (iValue < mMin)
                iValue = mMin;
            if (iValue > mMax)
                iValue = mMax;
            mValue.setText(GlobalGUIRoutines.getDurationString(iValue));
            int hours = iValue / 3600;
            int minutes = (iValue % 3600) / 60;
            int seconds = iValue % 60;
            mSeekBarHours.setProgress(hours);
            mSeekBarMinutes.setProgress(minutes);
            mSeekBarSeconds.setProgress(seconds);
        }
    }, iValue * 1000, TimeDurationPicker.HH_MM_SS);
    mValue.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            int hours = mSeekBarHours.getProgress();
            int minutes = mSeekBarMinutes.getProgress();
            int seconds = mSeekBarSeconds.getProgress();
            int iValue = (hours * 3600 + minutes * 60 + seconds);
            if (iValue < mMin)
                iValue = mMin;
            if (iValue > mMax)
                iValue = mMax;
            mValueDialog.setDuration(iValue * 1000);
            mValueDialog.show();
        }
    });
    mSeekBarHours.setOnSeekBarChangeListener(this);
    mSeekBarMinutes.setOnSeekBarChangeListener(this);
    mSeekBarSeconds.setOnSeekBarChangeListener(this);
    mTextViewRange.setText(sMin + " - " + sMax);
    GlobalGUIRoutines.registerOnActivityDestroyListener(this, this);
    if (state != null)
        mDialog.onRestoreInstanceState(state);
    mDialog.setOnDismissListener(this);
    mDialog.show();
}
Also used : MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) TimeDurationPicker(mobi.upod.timedurationpicker.TimeDurationPicker) TextView(android.widget.TextView) View(android.view.View) SuppressLint(android.annotation.SuppressLint) DialogAction(com.afollestad.materialdialogs.DialogAction) TimeDurationPickerDialog(mobi.upod.timedurationpicker.TimeDurationPickerDialog) TextView(android.widget.TextView) SuppressLint(android.annotation.SuppressLint)

Aggregations

SuppressLint (android.annotation.SuppressLint)3 View (android.view.View)3 TextView (android.widget.TextView)3 DialogAction (com.afollestad.materialdialogs.DialogAction)3 MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)3 TimeDurationPicker (mobi.upod.timedurationpicker.TimeDurationPicker)3 TimeDurationPickerDialog (mobi.upod.timedurationpicker.TimeDurationPickerDialog)3 DialogInterface (android.content.DialogInterface)1 Editable (android.text.Editable)1 TextWatcher (android.text.TextWatcher)1 MDButton (com.afollestad.materialdialogs.internal.MDButton)1