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;
}
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());
}
}
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();
}
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();
}
use of com.afollestad.materialdialogs.MaterialDialog in project material-dialogs by afollestad.
the class MaterialDialogPreference method showDialog.
@Override
protected void showDialog(Bundle state) {
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:
MaterialDialogPreference.this.onClick(dialog, DialogInterface.BUTTON_POSITIVE);
break;
case NEUTRAL:
MaterialDialogPreference.this.onClick(dialog, DialogInterface.BUTTON_NEUTRAL);
break;
case NEGATIVE:
MaterialDialogPreference.this.onClick(dialog, DialogInterface.BUTTON_NEGATIVE);
break;
}
}
}).positiveText(getPositiveButtonText()).negativeText(getNegativeButtonText()).autoDismiss(// immediately close the dialog after selection
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);
}
dialog.show();
}
Aggregations