Search in sources :

Example 56 with MaterialDialog

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

the class ColorChooserDialog method invalidateDynamicButtonColors.

private void invalidateDynamicButtonColors() {
    final MaterialDialog dialog = (MaterialDialog) getDialog();
    if (dialog == null) {
        return;
    }
    final Builder builder = getBuilder();
    if (builder.dynamicButtonColor) {
        int selectedColor = getSelectedColor();
        if (Color.alpha(selectedColor) < 64 || (Color.red(selectedColor) > 247 && Color.green(selectedColor) > 247 && Color.blue(selectedColor) > 247)) {
            // Once we get close to white or transparent,
            // the action buttons and seekbars will be a very light gray.
            selectedColor = Color.parseColor("#DEDEDE");
        }
        if (getBuilder().dynamicButtonColor) {
            dialog.getActionButton(DialogAction.POSITIVE).setTextColor(selectedColor);
            dialog.getActionButton(DialogAction.NEGATIVE).setTextColor(selectedColor);
            dialog.getActionButton(DialogAction.NEUTRAL).setTextColor(selectedColor);
        }
        if (customSeekR != null) {
            if (customSeekA.getVisibility() == View.VISIBLE) {
                MDTintHelper.setTint(customSeekA, selectedColor);
            }
            MDTintHelper.setTint(customSeekR, selectedColor);
            MDTintHelper.setTint(customSeekG, selectedColor);
            MDTintHelper.setTint(customSeekB, selectedColor);
        }
    }
}
Also used : MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) SuppressLint(android.annotation.SuppressLint)

Example 57 with MaterialDialog

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

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

the class FolderChooserDialog method reload.

private void reload() {
    parentContents = listFiles();
    MaterialDialog dialog = (MaterialDialog) getDialog();
    dialog.setTitle(parentFolder.getAbsolutePath());
    getArguments().putString("current_path", parentFolder.getAbsolutePath());
    dialog.setItems((CharSequence[]) getContentsArray());
}
Also used : MaterialDialog(com.afollestad.materialdialogs.MaterialDialog)

Example 59 with MaterialDialog

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

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

Aggregations

MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)90 View (android.view.View)57 DialogAction (com.afollestad.materialdialogs.DialogAction)45 TextView (android.widget.TextView)36 NonNull (android.support.annotation.NonNull)33 Intent (android.content.Intent)21 File (java.io.File)21 RecyclerView (android.support.v7.widget.RecyclerView)20 ImageView (android.widget.ImageView)19 SuppressLint (android.annotation.SuppressLint)18 List (java.util.List)16 LayoutInflater (android.view.LayoutInflater)14 MenuItem (android.view.MenuItem)14 Context (android.content.Context)13 PopupMenu (android.widget.PopupMenu)12 Activity (android.app.Activity)11 ListView (android.widget.ListView)11 Toast (android.widget.Toast)11 ArrayList (java.util.ArrayList)11 Bundle (android.os.Bundle)8