Search in sources :

Example 1 with MaterialDialog

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

the class ColorChooserDialog method onClick.

@Override
public void onClick(View v) {
    if (v.getTag() != null) {
        final String[] tag = ((String) v.getTag()).split(":");
        final int index = Integer.parseInt(tag[0]);
        final MaterialDialog dialog = (MaterialDialog) getDialog();
        final Builder builder = getBuilder();
        if (isInSub()) {
            subIndex(index);
        } else {
            topIndex(index);
            if (colorsSub != null && index < colorsSub.length) {
                dialog.setActionButton(DialogAction.NEGATIVE, builder.backBtn);
                isInSub(true);
            }
        }
        if (builder.allowUserCustom) {
            selectedCustomColor = getSelectedColor();
        }
        invalidateDynamicButtonColors();
        invalidate();
    }
}
Also used : MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) SuppressLint(android.annotation.SuppressLint)

Example 2 with MaterialDialog

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

the class ColorChooserDialog method onCreateDialog.

@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    if (getArguments() == null || !getArguments().containsKey("builder")) {
        throw new IllegalStateException("ColorChooserDialog should be created using its Builder interface.");
    }
    generateColors();
    int preselectColor;
    boolean foundPreselectColor = false;
    if (savedInstanceState != null) {
        foundPreselectColor = !savedInstanceState.getBoolean("in_custom", false);
        preselectColor = getSelectedColor();
    } else {
        if (getBuilder().setPreselectionColor) {
            preselectColor = getBuilder().preselectColor;
            if (preselectColor != 0) {
                for (int topIndex = 0; topIndex < colorsTop.length; topIndex++) {
                    if (colorsTop[topIndex] == preselectColor) {
                        foundPreselectColor = true;
                        topIndex(topIndex);
                        if (getBuilder().accentMode) {
                            subIndex(2);
                        } else if (colorsSub != null) {
                            findSubIndexForColor(topIndex, preselectColor);
                        } else {
                            subIndex(5);
                        }
                        break;
                    }
                    if (colorsSub != null) {
                        for (int subIndex = 0; subIndex < colorsSub[topIndex].length; subIndex++) {
                            if (colorsSub[topIndex][subIndex] == preselectColor) {
                                foundPreselectColor = true;
                                topIndex(topIndex);
                                subIndex(subIndex);
                                break;
                            }
                        }
                        if (foundPreselectColor) {
                            break;
                        }
                    }
                }
            }
        } else {
            preselectColor = Color.BLACK;
            foundPreselectColor = true;
        }
    }
    circleSize = getResources().getDimensionPixelSize(R.dimen.md_colorchooser_circlesize);
    final Builder builder = getBuilder();
    MaterialDialog.Builder bd = new MaterialDialog.Builder(getActivity()).title(getTitle()).autoDismiss(false).customView(R.layout.md_dialog_colorchooser, false).negativeText(builder.cancelBtn).positiveText(builder.doneBtn).neutralText(builder.allowUserCustom ? builder.customBtn : 0).onPositive(new MaterialDialog.SingleButtonCallback() {

        @Override
        public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
            callback.onColorSelection(ColorChooserDialog.this, getSelectedColor());
            dismiss();
        }
    }).onNegative(new MaterialDialog.SingleButtonCallback() {

        @Override
        public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
            if (isInSub()) {
                dialog.setActionButton(DialogAction.NEGATIVE, getBuilder().cancelBtn);
                isInSub(false);
                // Do this to avoid ArrayIndexOutOfBoundsException
                subIndex(-1);
                invalidate();
            } else {
                dialog.cancel();
            }
        }
    }).onNeutral(new MaterialDialog.SingleButtonCallback() {

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

        @Override
        public void onShow(DialogInterface dialog) {
            invalidateDynamicButtonColors();
        }
    });
    if (builder.theme != null) {
        bd.theme(builder.theme);
    }
    final MaterialDialog dialog = bd.build();
    final View v = dialog.getCustomView();
    grid = (GridView) v.findViewById(R.id.md_grid);
    if (builder.allowUserCustom) {
        selectedCustomColor = preselectColor;
        colorChooserCustomFrame = v.findViewById(R.id.md_colorChooserCustomFrame);
        customColorHex = (EditText) v.findViewById(R.id.md_hexInput);
        customColorIndicator = v.findViewById(R.id.md_colorIndicator);
        customSeekA = (SeekBar) v.findViewById(R.id.md_colorA);
        customSeekAValue = (TextView) v.findViewById(R.id.md_colorAValue);
        customSeekR = (SeekBar) v.findViewById(R.id.md_colorR);
        customSeekRValue = (TextView) v.findViewById(R.id.md_colorRValue);
        customSeekG = (SeekBar) v.findViewById(R.id.md_colorG);
        customSeekGValue = (TextView) v.findViewById(R.id.md_colorGValue);
        customSeekB = (SeekBar) v.findViewById(R.id.md_colorB);
        customSeekBValue = (TextView) v.findViewById(R.id.md_colorBValue);
        if (!builder.allowUserCustomAlpha) {
            v.findViewById(R.id.md_colorALabel).setVisibility(View.GONE);
            customSeekA.setVisibility(View.GONE);
            customSeekAValue.setVisibility(View.GONE);
            customColorHex.setHint("2196F3");
            customColorHex.setFilters(new InputFilter[] { new InputFilter.LengthFilter(6) });
        } else {
            customColorHex.setHint("FF2196F3");
            customColorHex.setFilters(new InputFilter[] { new InputFilter.LengthFilter(8) });
        }
        if (!foundPreselectColor) {
            // If color wasn't found in the preset colors, it must be custom
            toggleCustom(dialog);
        }
    }
    invalidate();
    return dialog;
}
Also used : InputFilter(android.text.InputFilter) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) DialogInterface(android.content.DialogInterface) GridView(android.widget.GridView) View(android.view.View) TextView(android.widget.TextView) SuppressLint(android.annotation.SuppressLint) DialogAction(com.afollestad.materialdialogs.DialogAction) NonNull(android.support.annotation.NonNull) NonNull(android.support.annotation.NonNull)

Example 3 with MaterialDialog

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

the class FileChooserDialog method onSelection.

@Override
public void onSelection(MaterialDialog materialDialog, View view, int i, CharSequence s) {
    if (canGoUp && i == 0) {
        parentFolder = parentFolder.getParentFile();
        if (parentFolder.getAbsolutePath().equals("/storage/emulated")) {
            parentFolder = parentFolder.getParentFile();
        }
        canGoUp = parentFolder.getParent() != null;
    } else {
        parentFolder = parentContents[canGoUp ? i - 1 : i];
        canGoUp = true;
        if (parentFolder.getAbsolutePath().equals("/storage/emulated")) {
            parentFolder = Environment.getExternalStorageDirectory();
        }
    }
    if (parentFolder.isFile()) {
        callback.onFileSelection(this, parentFolder);
        dismiss();
    } else {
        parentContents = listFiles(getBuilder().mimeType, getBuilder().extensions);
        MaterialDialog dialog = (MaterialDialog) getDialog();
        dialog.setTitle(parentFolder.getAbsolutePath());
        getArguments().putString("current_path", parentFolder.getAbsolutePath());
        dialog.setItems(getContentsArray());
    }
}
Also used : MaterialDialog(com.afollestad.materialdialogs.MaterialDialog)

Example 4 with MaterialDialog

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

the class FolderChooserDialog method createNewFolder.

private void createNewFolder() {
    new MaterialDialog.Builder(getActivity()).title(getBuilder().newFolderButton).input(0, 0, false, new MaterialDialog.InputCallback() {

        @Override
        public void onInput(@NonNull MaterialDialog dialog, CharSequence input) {
            //noinspection ResultOfMethodCallIgnored
            final File newFi = new File(parentFolder, input.toString());
            if (!newFi.mkdir()) {
                String msg = "Unable to create folder " + newFi.getAbsolutePath() + ", make sure you have the WRITE_EXTERNAL_STORAGE permission or root permissions.";
                Toast.makeText(getActivity(), msg, Toast.LENGTH_LONG).show();
            } else {
                reload();
            }
        }
    }).show();
}
Also used : MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) NonNull(android.support.annotation.NonNull) File(java.io.File)

Example 5 with MaterialDialog

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

the class FolderChooserDialog 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 FolderChooserDialog using the Builder.");
    }
    if (!getArguments().containsKey("current_path")) {
        getArguments().putString("current_path", getBuilder().initialPath);
    }
    parentFolder = new File(getArguments().getString("current_path"));
    checkIfCanGoUp();
    parentContents = listFiles();
    MaterialDialog.Builder builder = new MaterialDialog.Builder(getActivity()).title(parentFolder.getAbsolutePath()).items((CharSequence[]) getContentsArray()).itemsCallback(this).onPositive(new MaterialDialog.SingleButtonCallback() {

        @Override
        public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
            dialog.dismiss();
            callback.onFolderSelection(FolderChooserDialog.this, parentFolder);
        }
    }).onNegative(new MaterialDialog.SingleButtonCallback() {

        @Override
        public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
            dialog.dismiss();
        }
    }).autoDismiss(false).positiveText(getBuilder().chooseButton).negativeText(getBuilder().cancelButton);
    if (getBuilder().allowNewFolder) {
        builder.neutralText(getBuilder().newFolderButton);
        builder.onNeutral(new MaterialDialog.SingleButtonCallback() {

            @Override
            public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                createNewFolder();
            }
        });
    }
    if ("/".equals(getBuilder().initialPath)) {
        canGoUp = false;
    }
    return builder.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)

Aggregations

MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)287 DialogAction (com.afollestad.materialdialogs.DialogAction)167 View (android.view.View)160 NonNull (android.support.annotation.NonNull)106 TextView (android.widget.TextView)93 Intent (android.content.Intent)75 DialogInterface (android.content.DialogInterface)62 ImageView (android.widget.ImageView)53 RecyclerView (android.support.v7.widget.RecyclerView)50 ArrayList (java.util.ArrayList)44 SuppressLint (android.annotation.SuppressLint)38 File (java.io.File)35 List (java.util.List)33 ListView (android.widget.ListView)29 AdapterView (android.widget.AdapterView)28 Context (android.content.Context)26 Dialog (android.app.Dialog)25 LayoutInflater (android.view.LayoutInflater)24 EditText (android.widget.EditText)23 Snackbar (android.support.design.widget.Snackbar)22