use of com.afollestad.materialdialogs.MaterialDialog 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();
}
use of com.afollestad.materialdialogs.MaterialDialog in project material-dialogs by afollestad.
the class DialogUtils method showKeyboard.
public static void showKeyboard(@NonNull final DialogInterface di, @NonNull final MaterialDialog.Builder builder) {
final MaterialDialog dialog = (MaterialDialog) di;
if (dialog.getInputEditText() == null) {
return;
}
dialog.getInputEditText().post(new Runnable() {
@Override
public void run() {
dialog.getInputEditText().requestFocus();
InputMethodManager imm = (InputMethodManager) builder.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
if (imm != null) {
imm.showSoftInput(dialog.getInputEditText(), InputMethodManager.SHOW_IMPLICIT);
}
}
});
}
use of com.afollestad.materialdialogs.MaterialDialog in project material-dialogs by afollestad.
the class DialogUtils method hideKeyboard.
public static void hideKeyboard(@NonNull final DialogInterface di, @NonNull final MaterialDialog.Builder builder) {
final MaterialDialog dialog = (MaterialDialog) di;
if (dialog.getInputEditText() == null) {
return;
}
InputMethodManager imm = (InputMethodManager) builder.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
if (imm != null) {
final View currentFocus = dialog.getCurrentFocus();
final IBinder windowToken = currentFocus != null ? currentFocus.getWindowToken() : dialog.getView().getWindowToken();
if (windowToken != null) {
imm.hideSoftInputFromWindow(windowToken, 0);
}
}
}
use of com.afollestad.materialdialogs.MaterialDialog in project PocketHub by pockethub.
the class RepositoryListFragment method onListItemLongClick.
@Override
public boolean onListItemLongClick(ListView list, View v, int position, long itemId) {
if (!isUsable()) {
return false;
}
final Repository repo = (Repository) list.getItemAtPosition(position);
if (repo == null) {
return false;
}
MaterialDialog.Builder builder = new MaterialDialog.Builder(getActivity()).title(InfoUtils.createRepoId(repo));
final MaterialDialog[] dialogHolder = new MaterialDialog[1];
View view = getActivity().getLayoutInflater().inflate(R.layout.repo_dialog, null);
ViewFinder finder = new ViewFinder(view);
final User owner = repo.owner();
avatars.bind(finder.imageView(R.id.iv_owner_avatar), owner);
finder.setText(R.id.tv_owner_name, getString(R.string.navigate_to_user, owner.login()));
finder.onClick(R.id.ll_owner_area, new OnClickListener() {
@Override
public void onClick(View v) {
dialogHolder[0].dismiss();
viewUser(owner);
}
});
if ((recentRepos != null) && (recentRepos.contains(repo))) {
finder.find(R.id.divider).setVisibility(View.VISIBLE);
finder.find(R.id.ll_recent_repo_area).setVisibility(View.VISIBLE);
finder.onClick(R.id.ll_recent_repo_area, new OnClickListener() {
@Override
public void onClick(View v) {
dialogHolder[0].dismiss();
recentRepos.remove(repo);
refresh();
}
});
}
builder.customView(view, false);
MaterialDialog dialog = builder.build();
dialogHolder[0] = dialog;
dialog.setCanceledOnTouchOutside(true);
dialog.show();
return true;
}
use of com.afollestad.materialdialogs.MaterialDialog in project PocketHub by pockethub.
the class AssigneeDialogFragment method onCreateDialog.
@Override
public Dialog onCreateDialog(final Bundle savedInstanceState) {
Activity activity = getActivity();
Bundle arguments = getArguments();
final MaterialDialog.Builder dialogBuilder = createDialogBuilder().negativeText(R.string.cancel).onNegative(new MaterialDialog.SingleButtonCallback() {
@Override
public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
AssigneeDialogFragment.this.onClick(dialog, BUTTON_NEGATIVE);
}
}).neutralText(R.string.clear).onNeutral(new MaterialDialog.SingleButtonCallback() {
@Override
public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
AssigneeDialogFragment.this.onClick(dialog, BUTTON_NEUTRAL);
}
});
LayoutInflater inflater = activity.getLayoutInflater();
ListView view = (ListView) inflater.inflate(R.layout.dialog_list_view, null);
view.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
onClick(getDialog(), position);
}
});
ArrayList<User> choices = getChoices();
int selected = arguments.getInt(ARG_SELECTED_CHOICE);
UserListAdapter adapter = new UserListAdapter(inflater, choices.toArray(new User[choices.size()]), selected, loader);
view.setAdapter(adapter);
if (selected >= 0) {
view.setSelection(selected);
}
dialogBuilder.customView(view, false);
return dialogBuilder.build();
}
Aggregations