Search in sources :

Example 46 with DialogAction

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

the class MobileCellsPreference method showDialog.

@Override
protected void showDialog(Bundle state) {
    // persistedValue = getPersistedString("");
    // value = persistedValue;
    value = getPersistedString("");
    // IntentFilter intentFilter = new IntentFilter();
    // intentFilter.addAction(PhoneStateScanner.ACTION_PHONE_STATE_CHANGED);
    phoneStateChangedBroadcastReceiver = new PhoneStateChangedBroadcastReceiver(this);
    // context.registerReceiver(EventPreferencesNestedFragment.phoneStateChangedBroadcastReceiver, intentFilter);
    LocalBroadcastManager.getInstance(context).registerReceiver(phoneStateChangedBroadcastReceiver, new IntentFilter("PhoneStateChangedBroadcastReceiver_preference"));
    PPApplication.forceStartPhoneStateScanner(context);
    forceStart = true;
    /*
        DatabaseHandler db = DatabaseHandler.getInstance(context);
        db.deleteMobileCell(2826251);
        db.deleteMobileCell(2843189);
        db.deleteMobileCell(2877237);
        db.deleteMobileCell(2649653);
        db.deleteMobileCell(2649613);
        */
    MaterialDialog.Builder mBuilder = new MaterialDialog.Builder(getContext()).title(getDialogTitle()).icon(getDialogIcon()).positiveText(getPositiveButtonText()).negativeText(getNegativeButtonText()).autoDismiss(false).content(getDialogMessage()).customView(R.layout.activity_mobile_cells_pref_dialog, false).dividerColor(0).onPositive(new MaterialDialog.SingleButtonCallback() {

        @Override
        public void onClick(@NonNull MaterialDialog materialDialog, @NonNull DialogAction dialogAction) {
            if (shouldPersist()) {
                // Log.d("MobileCellsPreference.onPositive", "1");
                if (callChangeListener(value)) {
                    // Log.d("MobileCellsPreference.onPositive", "2");
                    DatabaseHandler db = DatabaseHandler.getInstance(context);
                    db.saveMobileCellsList(cellsList, false, false);
                    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.mobile_cells_pref_dlg_linla_progress);
    // dataRelativeLayout = layout.findViewById(R.id.mobile_cells_pref_dlg_rella_data);
    // noinspection ConstantConditions
    cellFilter = layout.findViewById(R.id.mobile_cells_pref_dlg_cells_filter_name);
    if (value.isEmpty())
        cellFilter.setText(R.string.mobile_cell_names_dialog_item_show_all);
    else
        cellFilter.setText(R.string.mobile_cell_names_dialog_item_show_selected);
    cellFilter.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) {
            refreshListView(false);
        }
    });
    cellName = layout.findViewById(R.id.mobile_cells_pref_dlg_cells_name);
    ListView cellsListView = layout.findViewById(R.id.mobile_cells_pref_dlg_listview);
    listAdapter = new MobileCellsPreferenceAdapter(context, this);
    cellsListView.setAdapter(listAdapter);
    refreshListView(false);
    /*
        cellsListView.setOnItemClickListener(new OnItemClickListener() {
            public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
                cellName.setText(cellsList.get(position).name);
            }

        });
        */
    mMobileCellsFilterDialog = new MobileCellNamesDialog(context, this, true);
    cellFilter.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            mMobileCellsFilterDialog.show();
        }
    });
    mMobileCellNamesDialog = new MobileCellNamesDialog(context, this, false);
    cellName.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            mMobileCellNamesDialog.show();
        }
    });
    final ImageView editIcon = layout.findViewById(R.id.mobile_cells_pref_dlg_rename);
    editIcon.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            mRenameDialog = new MaterialDialog.Builder(context).title(R.string.mobile_cells_pref_dlg_cell_rename_title).items(R.array.mobileCellsRenameArray).itemsCallbackSingleChoice(0, new MaterialDialog.ListCallbackSingleChoice() {

                @Override
                public boolean onSelection(MaterialDialog dialog, View view, int which, CharSequence text) {
                    final DatabaseHandler db = DatabaseHandler.getInstance(context);
                    switch(which) {
                        case 0:
                        case 1:
                            db.renameMobileCellsList(filteredCellsList, cellName.getText().toString(), which == 0, value);
                            break;
                        case 2:
                            db.renameMobileCellsList(filteredCellsList, cellName.getText().toString(), false, value);
                            break;
                    }
                    refreshListView(false);
                    return true;
                }
            }).positiveText(R.string.mobile_cells_pref_dlg_cell_rename_button).negativeText(getNegativeButtonText()).show();
        }
    });
    ImageView changeSelectionIcon = layout.findViewById(R.id.mobile_cells_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.mobileCellsChangeSelectionArray).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 (MobileCellsData cell : filteredCellsList) {
                                if (cell.name.equals(cellName.getText().toString()))
                                    addCellId(cell.cellId);
                            }
                            break;
                        case 2:
                            value = "";
                            for (MobileCellsData cell : filteredCellsList) {
                                addCellId(cell.cellId);
                            }
                            break;
                        default:
                    }
                    refreshListView(false);
                    return true;
                }
            }).positiveText(R.string.pref_dlg_change_selection_button).negativeText(getNegativeButtonText()).show();
        }
    });
    final ImageView helpIcon = layout.findViewById(R.id.mobile_cells_pref_dlg_helpIcon);
    helpIcon.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            DialogHelpPopupWindow.showPopup(helpIcon, context, R.string.mobile_cells_pref_dlg_help);
        }
    });
    final Button rescanButton = layout.findViewById(R.id.mobile_cells_pref_dlg_rescanButton);
    rescanButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (Permissions.grantMobileCellsDialogPermissions(context, MobileCellsPreference.this))
                refreshListView(true);
        }
    });
    GlobalGUIRoutines.registerOnActivityDestroyListener(this, this);
    if (state != null)
        mDialog.onRestoreInstanceState(state);
    mDialog.setOnDismissListener(this);
    mDialog.show();
}
Also used : IntentFilter(android.content.IntentFilter) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) ListView(android.widget.ListView) SuppressLint(android.annotation.SuppressLint) ListView(android.widget.ListView) Button(android.widget.Button) DialogAction(com.afollestad.materialdialogs.DialogAction) NonNull(android.support.annotation.NonNull) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) ImageView(android.widget.ImageView)

Example 47 with DialogAction

use of com.afollestad.materialdialogs.DialogAction 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 48 with DialogAction

use of com.afollestad.materialdialogs.DialogAction 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 49 with DialogAction

use of com.afollestad.materialdialogs.DialogAction 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 50 with DialogAction

use of com.afollestad.materialdialogs.DialogAction 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)

Aggregations

DialogAction (com.afollestad.materialdialogs.DialogAction)165 MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)165 View (android.view.View)97 NonNull (android.support.annotation.NonNull)85 TextView (android.widget.TextView)59 DialogInterface (android.content.DialogInterface)51 Intent (android.content.Intent)45 ImageView (android.widget.ImageView)39 RecyclerView (android.support.v7.widget.RecyclerView)28 ArrayList (java.util.ArrayList)25 List (java.util.List)25 SuppressLint (android.annotation.SuppressLint)23 ListView (android.widget.ListView)21 LayoutInflater (android.view.LayoutInflater)20 AdapterView (android.widget.AdapterView)20 NonNull (androidx.annotation.NonNull)20 Dialog (android.app.Dialog)18 AlertDialog (androidx.appcompat.app.AlertDialog)18 Context (android.content.Context)17 MenuItem (android.view.MenuItem)16