com.afollestad.materialdialogs.MaterialDialog Java Examples

The following examples show how to use com.afollestad.materialdialogs.MaterialDialog. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CreditsFragment.java    From candybar-library with Apache License 2.0 6 votes vote down vote up
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    MaterialDialog.Builder builder = new MaterialDialog.Builder(getActivity());
    builder.customView(R.layout.fragment_credits, false);
    builder.typeface(
            TypefaceHelper.getMedium(getActivity()),
            TypefaceHelper.getRegular(getActivity()));
    builder.title(getTitle(mType));
    builder.positiveText(R.string.close);

    MaterialDialog dialog = builder.build();
    dialog.show();
    mListView = (ListView) dialog.findViewById(R.id.listview);
    return dialog;
}
 
Example #2
Source File: FragmentMain.java    From iGap-Android with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public void isDeprecated() {
    new Handler(Looper.getMainLooper()).post(new Runnable() {
        @Override
        public void run() {
            new MaterialDialog.Builder(getActivity())
                    .cancelable(false)
                    .title(R.string.new_version_alert).titleGravity(GravityEnum.CENTER)
                    .titleColor(Color.parseColor("#f44336"))
                    .content(R.string.deprecated)
                    .contentGravity(GravityEnum.CENTER)
                    .show();
        }
    });

}
 
Example #3
Source File: ReportBugsHelper.java    From candybar with Apache License 2.0 6 votes vote down vote up
public static void prepareReportBugs(@NonNull Context context) {
    MaterialDialog.Builder builder = new MaterialDialog.Builder(context);
    builder.customView(R.layout.dialog_report_bugs, true);
    builder.typeface(
            TypefaceHelper.getMedium(context),
            TypefaceHelper.getRegular(context));
    builder.positiveText(R.string.report_bugs_send);
    builder.negativeText(R.string.close);

    MaterialDialog dialog = builder.build();

    EditText editText = (EditText) dialog.findViewById(R.id.input_desc);
    TextInputLayout inputLayout = (TextInputLayout) dialog.findViewById(R.id.input_layout);

    dialog.getActionButton(DialogAction.POSITIVE).setOnClickListener(view -> {
        if (editText.getText().length() > 0) {
            inputLayout.setErrorEnabled(false);
            ReportBugsTask.start(context, editText.getText().toString(), AsyncTask.THREAD_POOL_EXECUTOR);
            dialog.dismiss();
            return;
        }

        inputLayout.setError(context.getResources().getString(R.string.report_bugs_desc_empty));
    });
    dialog.show();
}
 
Example #4
Source File: ScanMediaFolderChooserDialog.java    From VinylMusicPlayer with GNU General Public License v3.0 6 votes vote down vote up
@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();
        }
        checkIfCanGoUp();
    } else {
        parentFolder = parentContents[canGoUp ? i - 1 : i];
        canGoUp = true;
        if (parentFolder.getAbsolutePath().equals("/storage/emulated")) {
            parentFolder = Environment.getExternalStorageDirectory();
        }
    }
    reload();
}
 
Example #5
Source File: BaseDialogActivity.java    From q-municate-android with Apache License 2.0 6 votes vote down vote up
protected void startLoadAttachFile(final Attachment.Type type, final Object attachment, final String dialogId) {
    TwoButtonsDialogFragment.show(getSupportFragmentManager(), getString(R.string.dialog_confirm_sending_attach,
            StringUtils.getAttachmentNameByType(this, type)), false,
            new MaterialDialog.ButtonCallback() {
                @Override
                public void onPositive(MaterialDialog dialog) {
                    super.onPositive(dialog);
                    switch (type) {
                        case LOCATION:
                            sendMessageWithAttachment(dialogId, Attachment.Type.LOCATION, attachment, null);
                            break;
                        case IMAGE:
                        case AUDIO:
                        case VIDEO:
                            showProgress();
                            QBLoadAttachFileCommand.start(BaseDialogActivity.this, (File) attachment, dialogId);
                            break;
                    }
                }
            });
}
 
Example #6
Source File: ActivityLocation.java    From RxTools-master with Apache License 2.0 6 votes vote down vote up
private void gpsCheck() {
    if (!RxLocationTool.isGpsEnabled(this)) {
        MaterialDialog.Builder builder = new MaterialDialog.Builder(this);
        MaterialDialog materialDialog = builder.title("GPS未打开").content("您需要在系统设置中打开GPS方可采集数据").positiveText("去设置")
                .onPositive(new MaterialDialog.SingleButtonCallback() {
                    @Override
                    public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                        RxLocationTool.openGpsSettings(mContext);
                    }
                }).build();
        materialDialog.setCanceledOnTouchOutside(false);
        materialDialog.setCancelable(false);
        materialDialog.show();
    } else {
        getLocation();
    }
}
 
Example #7
Source File: LinksHelper.java    From redgram-for-reddit with GNU General Public License v3.0 6 votes vote down vote up
public static MaterialDialog.ListCallback getShareCallback(Context context, PostItem item) {
    return new MaterialDialog.ListCallback() {
        @Override
        public void onSelection(MaterialDialog materialDialog, View view, int i, CharSequence charSequence) {
            String urlToShare = "";
            if (charSequence.toString().equalsIgnoreCase("Link")) {
                urlToShare = item.getUrl();
            }

            if (charSequence.toString().equalsIgnoreCase("Comments")) {
                urlToShare = "https://reddit.com/" + item.getPermalink();
            }

            LinksHelper.callShareDialog(context, urlToShare);
        }
    };
}
 
Example #8
Source File: LauncherHelper.java    From candybar with Apache License 2.0 6 votes vote down vote up
private static void openGooglePlay(Context context, String packageName, String launcherName) {
    new MaterialDialog.Builder(context)
            .typeface(
                    TypefaceHelper.getMedium(context),
                    TypefaceHelper.getRegular(context))
            .title(launcherName)
            .content(R.string.apply_launcher_not_installed, launcherName)
            .positiveText(context.getResources().getString(R.string.install))
            .onPositive((dialog, which) -> {
                try {
                    Intent store = new Intent(Intent.ACTION_VIEW, Uri.parse(
                            "https://play.google.com/store/apps/details?id=" + packageName));
                    context.startActivity(store);
                } catch (ActivityNotFoundException e) {
                    Toast.makeText(context, context.getResources().getString(
                            R.string.no_browser), Toast.LENGTH_LONG).show();
                }
            })
            .negativeText(android.R.string.cancel)
            .show();
}
 
Example #9
Source File: PlaystoreCheckHelper.java    From candybar with Apache License 2.0 6 votes vote down vote up
private void onPlaystoreChecked(boolean success) {
    MaterialDialog.Builder dialog = new MaterialDialog.Builder(mContext)
            .typeface(
                    TypefaceHelper.getMedium(mContext),
                    TypefaceHelper.getRegular(mContext))
            .title(R.string.playstore_check)
            .content(contentString)
            .positiveText(R.string.close)
            .onPositive((dial, which) -> {
                Preferences.get(mContext).setFirstRun(false);
                doIfNewVersion();
            })
            .cancelable(false)
            .canceledOnTouchOutside(false);

    if (success) {
        if (Preferences.get(mContext).isFirstRun()) {
            dialog.show();
        } else {
            doIfNewVersion();
        }
    } else {
        dialog.onPositive((dial, which) -> ((AppCompatActivity) mContext).finish()).show();
    }
}
 
Example #10
Source File: CGroupsFragment.java    From call_manage with MIT License 6 votes vote down vote up
@Override
public void onImport(CGroup list, File excelFile, int nameColIndex, int numberColIndex) {
    MaterialDialog progressDialog = new MaterialDialog.Builder(getContext())
            .progress(false, 0, true)
            .progressNumberFormat("%1d/%2d")
            .show();

    AsyncSpreadsheetImport task = new AsyncSpreadsheetImport(getContext(),
            excelFile,
            nameColIndex,
            numberColIndex,
            list);

    AsyncSpreadsheetImport.OnProgressListener onProgressListener = (rowsRead, rowsCount) -> {
        progressDialog.setProgress(rowsRead);
        progressDialog.setMaxProgress(rowsCount);
    };

    AsyncSpreadsheetImport.OnFinishListener onFinishListener = callback -> progressDialog.dismiss();

    task.setOnProgressListener(onProgressListener);
    task.setOnFinishListener(onFinishListener);
    task.execute();
}
 
Example #11
Source File: MainActivity.java    From Ency with Apache License 2.0 6 votes vote down vote up
/**
 * 检查更新提示框
 */
@Override
public void showUpdateDialog(final UpdateBean updateBean) {
    if (null != updateBean) {
        new MaterialDialog.Builder(mContext)
                .title(R.string.app_update)
                .content("最新版本:" + updateBean.getVersionShort() + "\n"
                        + "版本大小:" + SystemUtil.getFormatSize(updateBean.getBinary().getFsize()) + "\n"
                        + "更新内容:" + updateBean.getChangelog())
                .negativeText(R.string.no)
                .negativeColorRes(R.color.colorNegative)
                .positiveText(R.string.update)
                .positiveColorRes(R.color.colorPositive)
                .onPositive(new MaterialDialog.SingleButtonCallback() {
                    @Override
                    public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                        showMsg(getResources().getString(R.string.start_update));
                        Intent intent = new Intent(mContext, UpdateService.class);
                        intent.putExtra("downloadurl", updateBean.getInstall_url());
                        startService(intent);
                    }
                })
                .show();
    }
}
 
Example #12
Source File: DialogHelper.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
public static void showFilenameSuggestingDialog(final Context context,
                                                final MaterialDialog.SingleButtonCallback callback,
                                                final MaterialDialog.InputCallback inputCallback, int titleResId) {


    MaterialDialog.Builder builder = new MaterialDialog.Builder(context);
    builder.title(titleResId)
            .negativeText(android.R.string.cancel)
            .positiveText(android.R.string.ok)
            .content(R.string.enter_filename)
            .input("", "", inputCallback)
            .onAny(callback);

    MaterialDialog show = builder.show();
    initFilenameInputDialog(show);
}
 
Example #13
Source File: AddPlaylistDialog.java    From Muzesto with GNU General Public License v3.0 6 votes vote down vote up
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {

    final List<Playlist> playlists = PlaylistLoader.getPlaylists(getActivity(), false);
    CharSequence[] chars = new CharSequence[playlists.size() + 1];
    chars[0] = "Create new playlist";

    for (int i = 0; i < playlists.size(); i++) {
        chars[i + 1] = playlists.get(i).name;
    }
    return new MaterialDialog.Builder(getActivity()).title("Add to playlist").items(chars).itemsCallback(new MaterialDialog.ListCallback() {
        @Override
        public void onSelection(MaterialDialog dialog, View itemView, int which, CharSequence text) {
            long[] songs = getArguments().getLongArray("songs");
            if (which == 0) {
                CreatePlaylistDialog.newInstance(songs).show(getActivity().getSupportFragmentManager(), "CREATE_PLAYLIST");
                return;
            }

            MusicPlayer.addToPlaylist(getActivity(), songs, playlists.get(which - 1).id);
            dialog.dismiss();

        }
    }).build();
}
 
Example #14
Source File: TrendingActivity.java    From WeGit with Apache License 2.0 6 votes vote down vote up
public void showLanguageSelectDialog(){
    new MaterialDialog.Builder(this)
            .title(R.string.language)
            .items(languages)
            .itemsCallbackSingleChoice(lastLanguageDialogSelected, new MaterialDialog.ListCallbackSingleChoice() {
                @Override
                public boolean onSelection(MaterialDialog dialog, View view, int which, CharSequence text) {
                    Log.i(TAG, "onSelection " + text);
                    currentLanguage = text.toString();
                    toolbar.setSubtitle(currentLanguage);
                    lastLanguageDialogSelected = which;
                    updateUrl(currentSinceType, languageUrlMap.get(currentLanguage));
                    fragment.reload(trendingRepoUrl);
                    return true;
                }
            })
            .cancelable(true)
            .show();
}
 
Example #15
Source File: YoutubeDownloadInfo.java    From OneTapVideoDownload with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean handleOptionClicks(Context context, int resId) {
    if (super.handleOptionClicks(context, resId)) {
        return true;
    }

    switch (resId) {
        case R.string.download_in_other_resolution:
            mProgressDialog = new MaterialDialog.Builder(context)
                    .title(R.string.progress_dialog)
                    .content(R.string.please_wait)
                    .progress(true, 0)
                    .show();
            YoutubeParserProxy.startParsing(mContext, mParam, YoutubeDownloadInfo.this);
            return true;
    }

    return false;
}
 
Example #16
Source File: FeedRequestAdapter.java    From Focus with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void convert(BaseViewHolder helper, final FeedRequest item) {
    helper.setText(R.id.date, DateUtil.getRFCStringByInt(item.getTime()));
    helper.setText(R.id.code, item.getCode()+"");
    if (StringUtil.trim(item.getReason()).equals("")){
        helper.setText(R.id.reason, "成功");
    }else {
        helper.setText(R.id.reason, "点击查看详情");
        helper.getView(R.id.reason).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                new MaterialDialog.Builder(activity)
                        .title("失败原因")
                        .content(item.getReason())
                        .show();
            }
        });
    }
    helper.setText(R.id.num, item.getNum()+"");
}
 
Example #17
Source File: ClearSmartPlaylistDialog.java    From Orin with GNU General Public License v3.0 6 votes vote down vote up
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    //noinspection unchecked
    final AbsSmartPlaylist playlist = getArguments().getParcelable("playlist");
    int title = R.string.clear_playlist_title;
    //noinspection ConstantConditions
    CharSequence content = Html.fromHtml(getString(R.string.clear_playlist_x, playlist.name));

    return new MaterialDialog.Builder(getActivity())
            .title(title)
            .content(content)
            .positiveText(R.string.clear_action)
            .negativeText(android.R.string.cancel)
            .onPositive(new MaterialDialog.SingleButtonCallback() {
                @Override
                public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                    if (getActivity() == null) {
                        return;
                    }
                    playlist.clear(getActivity());
                }
            })
            .build();
}
 
Example #18
Source File: TodoListActivity.java    From TodoFluxArchitecture with Apache License 2.0 6 votes vote down vote up
private void showEditDialog(TodoItem item) {

        View customView = LayoutInflater.from(this).inflate(R.layout.dialog_todo_edit, null);
        final AppCompatEditText editText = ButterKnife.findById(customView, R.id.inputEditText);
        editText.setText(item.getDescription());
        editText.setSelection(item.getDescription().length());

        materialDialog = new MaterialDialog.Builder(this)
                .customView(customView, false)
                .positiveColorRes(R.color.positive_color)
                .negativeColorRes(R.color.positive_color)
                .positiveText(R.string.action_sure)
                .negativeText(R.string.action_cancel)
                .onPositive((dialog, which) -> {
                    String text = editText.getText().toString();
                    if (!TextUtils.isEmpty(text)) {
                        actionCreator.createItemEditAction(item.getId(), text, item.isCompleted(), item.isStared());
                        dialog.dismiss();
                    }
                })
                .build();


        materialDialog.show();
    }
 
Example #19
Source File: RequestLoginActivity.java    From green_android with GNU General Public License v3.0 6 votes vote down vote up
private void showFirmwareOutdated(final int resId, final Runnable onContinue) {
    // FIXME: Close and set mUsb to null for ledger in onNegative/onCancel

    if (!BuildConfig.DEBUG) {
        // Only allow the user to skip firmware checks in debug builds.
        showInstructions(resId);
        return;
    }

    runOnUiThread(() -> {
        final MaterialDialog d;
        d = UI.popup(RequestLoginActivity.this, R.string.id_warning, R.string.id_continue, R.string.id_cancel)
            .content(resId)
            .onPositive((dialog, which) -> onContinue.run()).build();
        UI.setDialogCloseHandler(d, this::finishOnUiThread);
        d.show();
    });
}
 
Example #20
Source File: ExpandableNewsFragment.java    From SimpleNews with Apache License 2.0 6 votes vote down vote up
@Override
public void onLongClick(Entry entry) {
    final List<Entry> entries = new ArrayList<>();
    entries.add(entry);
    new MaterialDialog.Builder(getActivity())
            .items(R.array.entry_options)
            .itemsCallback(new MaterialDialog.ListCallback() {
                @Override
                public void onSelection(MaterialDialog materialDialog, View view, int which, CharSequence charSequence) {
                    switch (which) {
                        case 0: //Share
                            share(entries);
                            break;
                        case 1: // Save
                            saveSelectedEntries(entries);
                            break;
                        case 2: // Read
                            markEntriesAsRead(entries);
                            break;
                        case 3: // Delete
                            deleteSelectedEntries(entries);
                            break;
                    }
                }
            }).show();
}
 
Example #21
Source File: HelpDialog.java    From Focus with GNU General Public License v3.0 6 votes vote down vote up
@SuppressLint("InflateParams")
    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        final View customView;
        try {
            customView = LayoutInflater.from(getActivity()).inflate(R.layout.dialog_help_view, null);
        } catch (InflateException e) {
            throw new IllegalStateException("This device does not support Web Views.");
        }
        MaterialDialog dialog =
                new MaterialDialog.Builder(getActivity())
                        .theme(getArguments().getBoolean("dark_theme") ? Theme.DARK : Theme.LIGHT)
                        .title("帮助信息")
                        .customView(customView, false)
                        .positiveText(android.R.string.ok)
                        .build();

        final WebView webView = customView.findViewById(R.id.webview);
//        webView.loadData(this.content, "text/html", "UTF-8");
        WebViewUtil.LoadHtmlIntoWebView(webView,this.content,getActivity(),"");
        return dialog;
    }
 
Example #22
Source File: SuperUserHelper.java    From matlog with GNU General Public License v3.0 6 votes vote down vote up
private static void showWarningDialog(final Context context) {
    Handler handler = new Handler(Looper.getMainLooper());

    handler.post(() -> {
        final String command = String.format("adb shell pm grant %s android.permission.READ_LOGS", BuildConfig.APPLICATION_ID);
        new MaterialDialog.Builder(context)
                .title(R.string.no_logs_warning_title)
                .content(Html.fromHtml(context.getString(R.string.no_logs_warning, context.getString(R.string.app_name), command)))
                .positiveText(android.R.string.ok)
                .neutralText(R.string.copy_command)
                .onPositive((dialog, which) -> dialog.dismiss())
                .onNeutral((dialog, which) -> {
                    ((ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE))
                            .setPrimaryClip(ClipData.newPlainText(context.getString(R.string.adb_command), command));
                    Toast.makeText(context, R.string.copied_to_clipboard, Toast.LENGTH_SHORT).show();
                })
                .autoDismiss(false)
                .show();
    });
}
 
Example #23
Source File: FragmentGroupProfileViewModel.java    From iGap-Android with GNU Affero General Public License v3.0 5 votes vote down vote up
private void convertToPublic(final View view) {
    new MaterialDialog.Builder(G.fragmentActivity).title(G.fragmentActivity.getResources().getString(R.string.group_title_convert_to_public)).content(G.fragmentActivity.getResources().getString(R.string.group_text_convert_to_public)).positiveText(R.string.yes).onPositive(new MaterialDialog.SingleButtonCallback() {
        @Override
        public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {

            dialog.dismiss();
            setUsername(view);
        }
    }).negativeText(R.string.no).show();
}
 
Example #24
Source File: LanguagesFragment.java    From wallpaperboard with Apache License 2.0 5 votes vote down vote up
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    MaterialDialog.Builder builder = new MaterialDialog.Builder(getActivity());
    builder.customView(R.layout.fragment_languages, false);
    builder.typeface(TypefaceHelper.getMedium(getActivity()), TypefaceHelper.getRegular(getActivity()));
    builder.title(R.string.pref_language_header);
    MaterialDialog dialog = builder.build();
    dialog.show();

    ButterKnife.bind(this, dialog);
    return dialog;
}
 
Example #25
Source File: MainActivity.java    From WeGit with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    ButterKnife.bind(this);
    //UI
    headerView = navigationView.inflateHeaderView(R.layout.nav_header);
    img_avatar = (CircleImageView) headerView.findViewById(R.id.avatar);
    txt_user = (TextView) headerView.findViewById(R.id.headerText);
    imageLoader = ImageLoader.getInstance();
    option = new DisplayImageOptions.Builder().cacheInMemory(true).cacheOnDisk(true)
            .considerExifParams(true).build();
    toolbar.setTitle("Github");
    setSupportActionBar(toolbar);
    getSupportActionBar().setHomeButtonEnabled(true); //设置返回键可用
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this,
            mDrawerLayout, toolbar, R.string.app_name,
            R.string.app_name);
    toggle.syncState();
    mDrawerLayout.setDrawerListener(toggle);
    navigationView.setNavigationItemSelectedListener(this);
    adapter = new FragmentPagerAdapter(getSupportFragmentManager());
    viewpager.setAdapter(adapter);
    builder = new MaterialDialog.Builder(this)
            .content(R.string.initial)
            .cancelable(false)
            .progress(true, 0);
    //logic
    presenter = new AuthPresenterImpl(this, this);
    presenter.auth();
    headerView.setOnClickListener(this);
}
 
Example #26
Source File: DetailsActivity.java    From YTS with MIT License 5 votes vote down vote up
private void showTorrentInfoDialog(Quality quality) {
  MaterialDialog.Builder builder = dialogUtil.buildDialog(R.layout.dialog_download);
  builder.title(dialogTitle);
  setupInfoDialogButtons(builder, quality);
  MaterialDialog matDialog = builder.build();
  matDialog.setCancelable(true);
  View dialogView = matDialog.getView();

  ImageView qualityLogo = dialogView.findViewById(R.id.dialog_download_iv_quality);
  TextView fileSize = dialogView.findViewById(R.id.dialog_download_tv_size);

  switch (quality) {
    case Q_3D:
      qualityLogo.setImageDrawable(quality3Drawable);
      fileSize.setText(presenter.getMovieSize(Quality.Q_3D));
      break;
    case Q_720P:
      qualityLogo.setImageDrawable(quality720pDrawable);
      fileSize.setText(presenter.getMovieSize(Quality.Q_720P));
      break;
    case Q_1080P:
      qualityLogo.setImageDrawable(quality1080pDrawable);
      fileSize.setText(presenter.getMovieSize(Quality.Q_1080P));
      break;
  }
  matDialog.show();
}
 
Example #27
Source File: BaseAuthActivity.java    From q-municate-android with Apache License 2.0 5 votes vote down vote up
protected void startSocialLogin() {
    if (!appSharedHelper.isShownUserAgreement()) {
        UserAgreementDialogFragment
                .show(getSupportFragmentManager(), new MaterialDialog.ButtonCallback() {
                    @Override
                    public void onPositive(MaterialDialog dialog) {
                        super.onPositive(dialog);
                        appSharedHelper.saveShownUserAgreement(true);
                        loginWithSocial();
                    }
                });
    } else {
        loginWithSocial();
    }
}
 
Example #28
Source File: DeletePlaylistDialog.java    From Orin with GNU General Public License v3.0 5 votes vote down vote up
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    //noinspection unchecked
    final ArrayList<Playlist> playlists = getArguments().getParcelableArrayList("playlists");
    int title;
    CharSequence content;
    //noinspection ConstantConditions
    if (playlists.size() > 1) {
        title = R.string.delete_playlists_title;
        content = Html.fromHtml(getString(R.string.delete_x_playlists, playlists.size()));
    } else {
        title = R.string.delete_playlist_title;
        content = Html.fromHtml(getString(R.string.delete_playlist_x, playlists.get(0).name));
    }
    return new MaterialDialog.Builder(getActivity())
            .title(title)
            .content(content)
            .positiveText(R.string.delete_action)
            .negativeText(android.R.string.cancel)
            .onPositive(new MaterialDialog.SingleButtonCallback() {
                @Override
                public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                    if (getActivity() == null)
                        return;
                    PlaylistsUtil.deletePlaylists(getActivity(), playlists);
                }
            })
            .build();
}
 
Example #29
Source File: PostImage.java    From Hify with MIT License 5 votes vote down vote up
@Override
public void onBackPressed() {
    new MaterialDialog.Builder(this)
            .title("Discard")
            .content("Are you sure do you want to go back?")
            .positiveText("Yes")
            .canceledOnTouchOutside(false)
            .cancelable(false)
            .onPositive((dialog, which) -> finish())
            .negativeText("No")
            .show();
}
 
Example #30
Source File: BaseFragment.java    From EdXposedManager with GNU General Public License v3.0 5 votes vote down vote up
static void areYouSure(@NonNull Activity activity, String contentText, MaterialDialog.SingleButtonCallback positiveSingleButtonCallback, MaterialDialog.SingleButtonCallback negativeSingleButtonCallback) {
    new MaterialDialog.Builder(activity).title(R.string.areyousure)
            .content(contentText)
            .iconAttr(android.R.attr.alertDialogIcon)
            .positiveText(android.R.string.yes)
            .negativeText(android.R.string.no)
            .onPositive(positiveSingleButtonCallback)
            .onNegative(negativeSingleButtonCallback)
            .show();
}