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);
}
}
}
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();
}
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());
}
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();
}
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();
}
Aggregations