Search in sources :

Example 61 with MaterialDialog

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();
}
Also used : MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) ArrayList(java.util.ArrayList) View(android.view.View) DialogAction(com.afollestad.materialdialogs.DialogAction) NonNull(android.support.annotation.NonNull) HashSet(java.util.HashSet)

Example 62 with MaterialDialog

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);
            }
        }
    });
}
Also used : MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) InputMethodManager(android.view.inputmethod.InputMethodManager)

Example 63 with MaterialDialog

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);
        }
    }
}
Also used : IBinder(android.os.IBinder) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) InputMethodManager(android.view.inputmethod.InputMethodManager) View(android.view.View)

Example 64 with MaterialDialog

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;
}
Also used : Repository(com.meisolsson.githubsdk.model.Repository) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) ViewFinder(com.github.kevinsawicki.wishlist.ViewFinder) User(com.meisolsson.githubsdk.model.User) OnClickListener(android.view.View.OnClickListener) View(android.view.View) ListView(android.widget.ListView)

Example 65 with MaterialDialog

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();
}
Also used : MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) User(com.meisolsson.githubsdk.model.User) OnItemClickListener(android.widget.AdapterView.OnItemClickListener) Bundle(android.os.Bundle) BaseActivity(com.github.pockethub.android.ui.BaseActivity) Activity(android.app.Activity) View(android.view.View) AdapterView(android.widget.AdapterView) ListView(android.widget.ListView) ListView(android.widget.ListView) DialogAction(com.afollestad.materialdialogs.DialogAction) LayoutInflater(android.view.LayoutInflater)

Aggregations

MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)90 View (android.view.View)57 DialogAction (com.afollestad.materialdialogs.DialogAction)45 TextView (android.widget.TextView)36 NonNull (android.support.annotation.NonNull)33 Intent (android.content.Intent)21 File (java.io.File)21 RecyclerView (android.support.v7.widget.RecyclerView)20 ImageView (android.widget.ImageView)19 SuppressLint (android.annotation.SuppressLint)18 List (java.util.List)16 LayoutInflater (android.view.LayoutInflater)14 MenuItem (android.view.MenuItem)14 Context (android.content.Context)13 PopupMenu (android.widget.PopupMenu)12 Activity (android.app.Activity)11 ListView (android.widget.ListView)11 Toast (android.widget.Toast)11 ArrayList (java.util.ArrayList)11 Bundle (android.os.Bundle)8