Search in sources :

Example 96 with MaterialDialog

use of com.afollestad.materialdialogs.MaterialDialog in project PhoneProfilesPlus by henrichg.

the class TimePreference method showDialog.

protected void showDialog(Bundle state) {
    MaterialDialog.Builder mBuilder = new MaterialDialog.Builder(getContext()).title(getDialogTitle()).icon(getDialogIcon()).positiveText(getPositiveButtonText()).negativeText(getNegativeButtonText()).content(getDialogMessage()).onPositive(new MaterialDialog.SingleButtonCallback() {

        @Override
        public void onClick(@NonNull MaterialDialog materialDialog, @NonNull DialogAction dialogAction) {
            if (shouldPersist()) {
                picker.clearFocus();
                value = picker.getCurrentHour() * 60 + picker.getCurrentMinute();
                setSummary(getSummary());
                if (callChangeListener(value)) {
                    persistInt(value);
                    notifyChanged();
                }
            }
        }
    });
    /*
        if (PPApplication.applicationTheme.equals("dark"))
            picker = new TimePicker(context, attributeSet, TimePickerDialog.THEME_HOLO_DARK);
        else
            picker = new TimePicker(context, attributeSet, TimePickerDialog.THEME_HOLO_LIGHT);
        */
    picker = new TimePicker(context, attributeSet);
    picker.setIs24HourView(DateFormat.is24HourFormat(context));
    onBindDialogView(picker);
    mBuilder.customView(picker, false);
    GlobalGUIRoutines.registerOnActivityDestroyListener(this, this);
    mDialog = mBuilder.build();
    if (state != null)
        mDialog.onRestoreInstanceState(state);
    mDialog.setOnDismissListener(this);
    mDialog.show();
}
Also used : TimePicker(android.widget.TimePicker) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) DialogAction(com.afollestad.materialdialogs.DialogAction)

Example 97 with MaterialDialog

use of com.afollestad.materialdialogs.MaterialDialog in project PhoneProfilesPlus by henrichg.

the class VolumeDialogPreference method showDialog.

@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_volume_pref_dialog, true).onPositive(new MaterialDialog.SingleButtonCallback() {

        @Override
        public void onClick(@NonNull MaterialDialog materialDialog, @NonNull DialogAction dialogAction) {
            if (shouldPersist()) {
                persistString(Integer.toString(value + minimumValue) + "|" + Integer.toString(noChange) + "|" + Integer.toString(defaultProfile));
                setSummaryVDP();
            }
        }
    });
    mDialog = mBuilder.build();
    View layout = mDialog.getCustomView();
    // noinspection ConstantConditions
    seekBar = layout.findViewById(R.id.volumePrefDialogSeekbar);
    // noinspection ConstantConditions
    valueText = layout.findViewById(R.id.volumePrefDialogValueText);
    // noinspection ConstantConditions
    noChangeChBox = layout.findViewById(R.id.volumePrefDialogNoChange);
    // noinspection ConstantConditions
    defaultProfileChBox = layout.findViewById(R.id.volumePrefDialogDefaultProfile);
    seekBar.setOnSeekBarChangeListener(this);
    seekBar.setKeyProgressIncrement(stepSize);
    seekBar.setMax(maximumValue - minimumValue);
    getValueVDP();
    seekBar.setProgress(value);
    noChangeChBox.setOnCheckedChangeListener(this);
    noChangeChBox.setChecked((noChange == 1));
    defaultProfileChBox.setOnCheckedChangeListener(this);
    defaultProfileChBox.setChecked((defaultProfile == 1));
    defaultProfileChBox.setEnabled(disableDefaultProfile == 0);
    if (noChange == 1)
        defaultProfileChBox.setChecked(false);
    if (defaultProfile == 1)
        noChangeChBox.setChecked(false);
    valueText.setEnabled((noChange == 0) && (defaultProfile == 0));
    seekBar.setEnabled((noChange == 0) && (defaultProfile == 0));
    GlobalGUIRoutines.registerOnActivityDestroyListener(this, this);
    if (state != null)
        mDialog.onRestoreInstanceState(state);
    mDialog.setOnDismissListener(this);
    mDialog.show();
}
Also used : MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) DialogAction(com.afollestad.materialdialogs.DialogAction) TextView(android.widget.TextView) View(android.view.View)

Example 98 with MaterialDialog

use of com.afollestad.materialdialogs.MaterialDialog in project PhoneProfilesPlus by henrichg.

the class ProfilePreference method showDialog.

protected void showDialog(Bundle state) {
    PPApplication.logE("ProfilePreference.showDialog", "xx");
    MaterialDialog.Builder mBuilder = new MaterialDialog.Builder(getContext()).title(getDialogTitle()).icon(getDialogIcon()).negativeText(getNegativeButtonText()).content(getDialogMessage()).customView(R.layout.activity_profile_pref_dialog, false).autoDismiss(false).onNegative(new MaterialDialog.SingleButtonCallback() {

        @Override
        public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
            mDialog.dismiss();
        }
    });
    mBuilder.showListener(new DialogInterface.OnShowListener() {

        @Override
        public void onShow(DialogInterface dialog) {
            ProfilePreference.this.onShow();
        }
    });
    mDialog = mBuilder.build();
    View layout = mDialog.getCustomView();
    // noinspection ConstantConditions
    linlaProgress = layout.findViewById(R.id.profile_pref_dlg_linla_progress);
    // noinspection ConstantConditions
    listView = layout.findViewById(R.id.profile_pref_dlg_listview);
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        public void onItemClick(AdapterView<?> parent, View item, int position, long id) {
            doOnItemSelected(position);
        }
    });
    GlobalGUIRoutines.registerOnActivityDestroyListener(this, this);
    if (state != null)
        mDialog.onRestoreInstanceState(state);
    mDialog.setOnDismissListener(this);
    mDialog.show();
}
Also used : MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) DialogInterface(android.content.DialogInterface) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) ListView(android.widget.ListView) SuppressLint(android.annotation.SuppressLint) DialogAction(com.afollestad.materialdialogs.DialogAction) AdapterView(android.widget.AdapterView)

Example 99 with MaterialDialog

use of com.afollestad.materialdialogs.MaterialDialog 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 100 with MaterialDialog

use of com.afollestad.materialdialogs.MaterialDialog in project PhoneProfilesPlus by henrichg.

the class NFCTagPreference method showDialog.

@Override
protected void showDialog(Bundle state) {
    value = getPersistedString(value);
    MaterialDialog.Builder mBuilder = new MaterialDialog.Builder(getContext()).title(getDialogTitle()).icon(getDialogIcon()).positiveText(getPositiveButtonText()).negativeText(getNegativeButtonText()).autoDismiss(false).content(getDialogMessage()).customView(R.layout.activity_nfc_tag_pref_dialog, false).dividerColor(0).onPositive(new MaterialDialog.SingleButtonCallback() {

        @Override
        public void onClick(@NonNull MaterialDialog materialDialog, @NonNull DialogAction dialogAction) {
            if (shouldPersist()) {
                if (callChangeListener(value)) {
                    persistString(value);
                }
            }
            mDialog.dismiss();
        }
    }).onNegative(new MaterialDialog.SingleButtonCallback() {

        @Override
        public void onClick(@NonNull MaterialDialog materialDialog, @NonNull DialogAction dialogAction) {
            mDialog.dismiss();
        }
    });
    mDialog = mBuilder.build();
    View layout = mDialog.getCustomView();
    // progressLinearLayout = layout.findViewById(R.id.nfc_tag_pref_dlg_linla_progress);
    // dataRelativeLayout = layout.findViewById(R.id.nfc_tag_pref_dlg_rella_data);
    // noinspection ConstantConditions
    addIcon = layout.findViewById(R.id.nfc_tag_pref_dlg_addIcon);
    addIcon.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            String tag = nfcTagName.getText().toString();
            addNfcTag(tag);
            DatabaseHandler.getInstance(context).addNFCTag(tag);
            refreshListView(tag);
        }
    });
    // noinspection ConstantConditions
    nfcTagName = layout.findViewById(R.id.nfc_tag_pref_dlg_bt_name);
    nfcTagName.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) {
            GlobalGUIRoutines.setImageButtonEnabled(!nfcTagName.getText().toString().isEmpty(), addIcon, R.drawable.ic_action_location_add, context.getApplicationContext());
        }
    });
    GlobalGUIRoutines.setImageButtonEnabled(!nfcTagName.getText().toString().isEmpty(), addIcon, R.drawable.ic_action_location_add, context.getApplicationContext());
    nfcTagListView = layout.findViewById(R.id.nfc_tag_pref_dlg_listview);
    listAdapter = new NFCTagPreferenceAdapter(context, this);
    nfcTagListView.setAdapter(listAdapter);
    refreshListView("");
    nfcTagListView.setOnItemClickListener(new OnItemClickListener() {

        public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
            // NFCTagPreferenceAdapter.ViewHolder viewHolder =
            // (NFCTagPreferenceAdapter.ViewHolder) v.getTag();
            String nfcTag = nfcTagList.get(position).name;
            nfcTagName.setText(nfcTag);
        }
    });
    /*
        final TextView helpText = layout.findViewById(R.id.nfc_tag_pref_dlg_helpText);
        final ImageView helpIcon = layout.findViewById(R.id.nfc_tag_pref_dlg_helpIcon);
        ApplicationPreferences.getSharedPreferences(context);
        if (ApplicationPreferences.preferences.getBoolean(PREF_SHOW_HELP, true)) {
            helpIcon.setImageResource(R.drawable.ic_action_profileicon_help_closed);
            helpText.setVisibility(View.VISIBLE);
        }
        else {
            helpIcon.setImageResource(R.drawable.ic_action_profileicon_help);
            helpText.setVisibility(View.GONE);
        }
        helpIcon.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ApplicationPreferences.getSharedPreferences(context);
                SharedPreferences.Editor editor = ApplicationPreferences.preferences.edit();
                int visibility = helpText.getVisibility();
                if (visibility == View.VISIBLE) {
                    helpIcon.setImageResource(R.drawable.ic_action_profileicon_help);
                    visibility = View.GONE;
                    editor.putBoolean(PREF_SHOW_HELP, false);
                }
                else {
                    helpIcon.setImageResource(R.drawable.ic_action_profileicon_help_closed);
                    visibility = View.VISIBLE;
                    editor.putBoolean(PREF_SHOW_HELP, true);
                }
                helpText.setVisibility(visibility);
                editor.apply();
            }
        });
        */
    final ImageView helpIcon = layout.findViewById(R.id.nfc_tag_pref_dlg_helpIcon);
    helpIcon.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            DialogHelpPopupWindow.showPopup(helpIcon, context, R.string.nfc_tag_pref_dlg_help);
        }
    });
    ImageView changeSelectionIcon = layout.findViewById(R.id.nfc_tag_pref_dlg_changeSelection);
    changeSelectionIcon.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            mSelectorDialog = new MaterialDialog.Builder(context).title(R.string.pref_dlg_change_selection_title).items(R.array.nfcTagsChangeSelectionArray).itemsCallbackSingleChoice(0, new MaterialDialog.ListCallbackSingleChoice() {

                @Override
                public boolean onSelection(MaterialDialog dialog, View view, int which, CharSequence text) {
                    switch(which) {
                        case 0:
                            value = "";
                            break;
                        case 1:
                            for (NFCTagData nfcTag : nfcTagList) {
                                if (nfcTag.name.equals(nfcTagName.getText().toString()))
                                    addNfcTag(nfcTag.name);
                            }
                            break;
                        default:
                    }
                    refreshListView("");
                    return true;
                }
            }).positiveText(R.string.pref_dlg_change_selection_button).negativeText(getNegativeButtonText()).show();
        }
    });
    GlobalGUIRoutines.registerOnActivityDestroyListener(this, this);
    if (state != null)
        mDialog.onRestoreInstanceState(state);
    mDialog.setOnDismissListener(this);
    mDialog.show();
}
Also used : MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) OnItemClickListener(android.widget.AdapterView.OnItemClickListener) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) ListView(android.widget.ListView) SuppressLint(android.annotation.SuppressLint) DialogAction(com.afollestad.materialdialogs.DialogAction) NonNull(android.support.annotation.NonNull) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) ImageView(android.widget.ImageView)

Aggregations

MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)295 DialogAction (com.afollestad.materialdialogs.DialogAction)175 View (android.view.View)168 TextView (android.widget.TextView)99 NonNull (android.support.annotation.NonNull)98 Intent (android.content.Intent)84 DialogInterface (android.content.DialogInterface)60 ImageView (android.widget.ImageView)54 ArrayList (java.util.ArrayList)50 RecyclerView (android.support.v7.widget.RecyclerView)45 List (java.util.List)44 Context (android.content.Context)40 SuppressLint (android.annotation.SuppressLint)38 LayoutInflater (android.view.LayoutInflater)37 File (java.io.File)35 Dialog (android.app.Dialog)34 EditText (android.widget.EditText)31 Bundle (android.os.Bundle)30 ListView (android.widget.ListView)29 Toast (android.widget.Toast)29