Search in sources :

Example 31 with DialogAction

use of com.afollestad.materialdialogs.DialogAction in project XposedInstaller by rovo89.

the class StatusInstallerFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.status_installer, container, false);
    // Available ZIPs
    final SwipeRefreshLayout refreshLayout = (SwipeRefreshLayout) v.findViewById(R.id.swiperefreshlayout);
    refreshLayout.setColorSchemeColors(getResources().getColor(R.color.colorPrimary));
    ONLINE_ZIP_LOADER.setSwipeRefreshLayout(refreshLayout);
    ONLINE_ZIP_LOADER.addListener(mOnlineZipListener);
    ONLINE_ZIP_LOADER.triggerFirstLoadIfNecessary();
    LOCAL_ZIP_LOADER.addListener(mLocalZipListener);
    LOCAL_ZIP_LOADER.triggerFirstLoadIfNecessary();
    refreshZipViews(v);
    // Disable switch
    final SwitchCompat disableSwitch = (SwitchCompat) v.findViewById(R.id.disableSwitch);
    disableSwitch.setChecked(!DISABLE_FILE.exists());
    disableSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (DISABLE_FILE.exists()) {
                DISABLE_FILE.delete();
                Snackbar.make(disableSwitch, R.string.xposed_on_next_reboot, Snackbar.LENGTH_LONG).show();
            } else {
                try {
                    DISABLE_FILE.createNewFile();
                    Snackbar.make(disableSwitch, R.string.xposed_off_next_reboot, Snackbar.LENGTH_LONG).show();
                } catch (IOException e) {
                    Log.e(XposedApp.TAG, "Could not create " + DISABLE_FILE, e);
                }
            }
        }
    });
    // Device info
    TextView androidSdk = (TextView) v.findViewById(R.id.android_version);
    TextView manufacturer = (TextView) v.findViewById(R.id.ic_manufacturer);
    TextView cpu = (TextView) v.findViewById(R.id.cpu);
    androidSdk.setText(getString(R.string.android_sdk, Build.VERSION.RELEASE, getAndroidVersion(), Build.VERSION.SDK_INT));
    manufacturer.setText(getUIFramework());
    cpu.setText(FrameworkZips.ARCH);
    // Known issues
    refreshKnownIssue(v);
    // Display warning dialog to new users
    if (!XposedApp.getPreferences().getBoolean("hide_install_warning", false)) {
        new MaterialDialog.Builder(getActivity()).title(R.string.install_warning_title).content(R.string.install_warning).positiveText(android.R.string.ok).onPositive(new MaterialDialog.SingleButtonCallback() {

            @Override
            public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                if (dialog.isPromptCheckBoxChecked()) {
                    XposedApp.getPreferences().edit().putBoolean("hide_install_warning", true).apply();
                }
            }
        }).checkBoxPromptRes(R.string.dont_show_again, false, null).cancelable(false).show();
    }
    return v;
}
Also used : MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) IOException(java.io.IOException) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout) DialogAction(com.afollestad.materialdialogs.DialogAction) NonNull(android.support.annotation.NonNull) TextView(android.widget.TextView) CompoundButton(android.widget.CompoundButton) SwitchCompat(android.support.v7.widget.SwitchCompat)

Example 32 with DialogAction

use of com.afollestad.materialdialogs.DialogAction in project material-dialogs by afollestad.

the class FileChooserDialog method onCreateDialog.

@SuppressWarnings("ConstantConditions")
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && ActivityCompat.checkSelfPermission(getActivity(), Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
        return new MaterialDialog.Builder(getActivity()).title(R.string.md_error_label).content(R.string.md_storage_perm_error).positiveText(android.R.string.ok).build();
    }
    if (getArguments() == null || !getArguments().containsKey("builder")) {
        throw new IllegalStateException("You must create a FileChooserDialog using the Builder.");
    }
    if (!getArguments().containsKey("current_path")) {
        getArguments().putString("current_path", getBuilder().initialPath);
    }
    parentFolder = new File(getArguments().getString("current_path"));
    checkIfCanGoUp();
    parentContents = listFiles(getBuilder().mimeType, getBuilder().extensions);
    return new MaterialDialog.Builder(getActivity()).title(parentFolder.getAbsolutePath()).items(getContentsArray()).itemsCallback(this).onNegative(new MaterialDialog.SingleButtonCallback() {

        @Override
        public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
            dialog.dismiss();
        }
    }).autoDismiss(false).negativeText(getBuilder().cancelButton).build();
}
Also used : MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) DialogAction(com.afollestad.materialdialogs.DialogAction) NonNull(android.support.annotation.NonNull) File(java.io.File) NonNull(android.support.annotation.NonNull)

Example 33 with DialogAction

use of com.afollestad.materialdialogs.DialogAction in project material-dialogs by afollestad.

the class MaterialEditTextPreference method showDialog.

@Override
protected void showDialog(Bundle state) {
    Builder mBuilder = new MaterialDialog.Builder(getContext()).title(getDialogTitle()).icon(getDialogIcon()).positiveText(getPositiveButtonText()).negativeText(getNegativeButtonText()).dismissListener(this).onAny(new MaterialDialog.SingleButtonCallback() {

        @Override
        public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
            switch(which) {
                default:
                    MaterialEditTextPreference.this.onClick(dialog, DialogInterface.BUTTON_POSITIVE);
                    break;
                case NEUTRAL:
                    MaterialEditTextPreference.this.onClick(dialog, DialogInterface.BUTTON_NEUTRAL);
                    break;
                case NEGATIVE:
                    MaterialEditTextPreference.this.onClick(dialog, DialogInterface.BUTTON_NEGATIVE);
                    break;
            }
        }
    }).dismissListener(this);
    @SuppressLint("InflateParams") View layout = LayoutInflater.from(getContext()).inflate(R.layout.md_stub_inputpref, null);
    onBindDialogView(layout);
    MDTintHelper.setTint(editText, color);
    TextView message = (TextView) layout.findViewById(android.R.id.message);
    if (getDialogMessage() != null && getDialogMessage().toString().length() > 0) {
        message.setVisibility(View.VISIBLE);
        message.setText(getDialogMessage());
    } else {
        message.setVisibility(View.GONE);
    }
    mBuilder.customView(layout, false);
    PrefUtil.registerOnActivityDestroyListener(this, this);
    dialog = mBuilder.build();
    if (state != null) {
        dialog.onRestoreInstanceState(state);
    }
    requestInputMethod(dialog);
    dialog.show();
}
Also used : MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) Builder(com.afollestad.materialdialogs.MaterialDialog.Builder) DialogAction(com.afollestad.materialdialogs.DialogAction) Builder(com.afollestad.materialdialogs.MaterialDialog.Builder) NonNull(android.support.annotation.NonNull) SuppressLint(android.annotation.SuppressLint) TextView(android.widget.TextView) View(android.view.View) TextView(android.widget.TextView)

Example 34 with DialogAction

use of com.afollestad.materialdialogs.DialogAction in project material-dialogs by afollestad.

the class MaterialListPreference method showDialog.

@Override
protected void showDialog(Bundle state) {
    if (getEntries() == null || getEntryValues() == null) {
        throw new IllegalStateException("ListPreference requires an entries array and an entryValues array.");
    }
    int preselect = findIndexOfValue(getValue());
    MaterialDialog.Builder builder = new MaterialDialog.Builder(context).title(getDialogTitle()).icon(getDialogIcon()).dismissListener(this).onAny(new MaterialDialog.SingleButtonCallback() {

        @Override
        public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
            switch(which) {
                default:
                    MaterialListPreference.this.onClick(dialog, DialogInterface.BUTTON_POSITIVE);
                    break;
                case NEUTRAL:
                    MaterialListPreference.this.onClick(dialog, DialogInterface.BUTTON_NEUTRAL);
                    break;
                case NEGATIVE:
                    MaterialListPreference.this.onClick(dialog, DialogInterface.BUTTON_NEGATIVE);
                    break;
            }
        }
    }).negativeText(getNegativeButtonText()).items(getEntries()).autoDismiss(// immediately close the dialog after selection
    true).itemsCallbackSingleChoice(preselect, new MaterialDialog.ListCallbackSingleChoice() {

        @Override
        public boolean onSelection(MaterialDialog dialog, View itemView, int which, CharSequence text) {
            onClick(null, DialogInterface.BUTTON_POSITIVE);
            if (which >= 0 && getEntryValues() != null) {
                try {
                    Field clickedIndex = ListPreference.class.getDeclaredField("mClickedDialogEntryIndex");
                    clickedIndex.setAccessible(true);
                    clickedIndex.set(MaterialListPreference.this, which);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            return true;
        }
    });
    final View contentView = onCreateDialogView();
    if (contentView != null) {
        onBindDialogView(contentView);
        builder.customView(contentView, false);
    } else {
        builder.content(getDialogMessage());
    }
    PrefUtil.registerOnActivityDestroyListener(this, this);
    dialog = builder.build();
    if (state != null) {
        dialog.onRestoreInstanceState(state);
    }
    onClick(dialog, DialogInterface.BUTTON_NEGATIVE);
    dialog.show();
}
Also used : MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) ListPreference(android.preference.ListPreference) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View) Field(java.lang.reflect.Field) DialogAction(com.afollestad.materialdialogs.DialogAction)

Example 35 with DialogAction

use of com.afollestad.materialdialogs.DialogAction in project material-dialogs by afollestad.

the class MaterialMultiSelectListPreference method showDialog.

@Override
protected void showDialog(Bundle state) {
    List<Integer> indices = new ArrayList<>();
    for (String s : getValues()) {
        int index = findIndexOfValue(s);
        if (index >= 0) {
            indices.add(findIndexOfValue(s));
        }
    }
    MaterialDialog.Builder builder = new MaterialDialog.Builder(context).title(getDialogTitle()).icon(getDialogIcon()).negativeText(getNegativeButtonText()).positiveText(getPositiveButtonText()).onAny(new MaterialDialog.SingleButtonCallback() {

        @Override
        public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
            switch(which) {
                default:
                    MaterialMultiSelectListPreference.this.onClick(dialog, DialogInterface.BUTTON_POSITIVE);
                    break;
                case NEUTRAL:
                    MaterialMultiSelectListPreference.this.onClick(dialog, DialogInterface.BUTTON_NEUTRAL);
                    break;
                case NEGATIVE:
                    MaterialMultiSelectListPreference.this.onClick(dialog, DialogInterface.BUTTON_NEGATIVE);
                    break;
            }
        }
    }).items(getEntries()).itemsCallbackMultiChoice(indices.toArray(new Integer[indices.size()]), new MaterialDialog.ListCallbackMultiChoice() {

        @Override
        public boolean onSelection(MaterialDialog dialog, Integer[] which, CharSequence[] text) {
            onClick(null, DialogInterface.BUTTON_POSITIVE);
            dialog.dismiss();
            final Set<String> values = new HashSet<>();
            for (int i : which) {
                values.add(getEntryValues()[i].toString());
            }
            if (callChangeListener(values)) {
                setValues(values);
            }
            return true;
        }
    }).dismissListener(this);
    final View contentView = onCreateDialogView();
    if (contentView != null) {
        onBindDialogView(contentView);
        builder.customView(contentView, false);
    } else {
        builder.content(getDialogMessage());
    }
    PrefUtil.registerOnActivityDestroyListener(this, this);
    mDialog = builder.build();
    if (state != null) {
        mDialog.onRestoreInstanceState(state);
    }
    mDialog.show();
}
Also used : MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) ArrayList(java.util.ArrayList) View(android.view.View) DialogAction(com.afollestad.materialdialogs.DialogAction) NonNull(android.support.annotation.NonNull) HashSet(java.util.HashSet)

Aggregations

DialogAction (com.afollestad.materialdialogs.DialogAction)43 MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)43 NonNull (android.support.annotation.NonNull)28 View (android.view.View)28 TextView (android.widget.TextView)22 ImageView (android.widget.ImageView)15 RecyclerView (android.support.v7.widget.RecyclerView)13 MenuItem (android.view.MenuItem)12 PopupMenu (android.widget.PopupMenu)12 Intent (android.content.Intent)8 File (java.io.File)8 LayoutInflater (android.view.LayoutInflater)7 List (java.util.List)7 Song (io.hefuyi.listener.mvp.model.Song)6 SuppressLint (android.annotation.SuppressLint)5 IOException (java.io.IOException)5 Activity (android.app.Activity)4 ProgressDialog (android.app.ProgressDialog)4 Context (android.content.Context)4 Bundle (android.os.Bundle)4