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