Java Code Examples for com.afollestad.materialdialogs.MaterialDialog

The following examples show how to use com.afollestad.materialdialogs.MaterialDialog. These examples are extracted from open source projects. 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 Project: matlog   Source File: SuperUserHelper.java    License: 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 2
@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 3
Source Project: candybar   Source File: LauncherHelper.java    License: 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 4
Source Project: candybar   Source File: ReportBugsHelper.java    License: 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 5
Source Project: candybar   Source File: PlaystoreCheckHelper.java    License: 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 6
Source Project: call_manage   Source File: CGroupsFragment.java    License: 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 7
Source Project: Ency   Source File: MainActivity.java    License: 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 8
Source Project: SimpleNews   Source File: ExpandableNewsFragment.java    License: 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 9
Source Project: java-n-IDE-for-Android   Source File: DialogHelper.java    License: 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 10
Source Project: WeGit   Source File: TrendingActivity.java    License: 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 11
@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 12
@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 13
Source Project: Focus   Source File: HelpDialog.java    License: 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 14
Source Project: candybar-library   Source File: CreditsFragment.java    License: 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 15
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 16
Source Project: TodoFluxArchitecture   Source File: TodoListActivity.java    License: 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 17
Source Project: Focus   Source File: FeedRequestAdapter.java    License: 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 18
Source Project: Muzesto   Source File: AddPlaylistDialog.java    License: 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 19
@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 20
Source Project: q-municate-android   Source File: BaseDialogActivity.java    License: 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 21
Source Project: RxTools-master   Source File: ActivityLocation.java    License: 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 22
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 23
Source Project: Hify   Source File: PostImage.java    License: MIT License 5 votes vote down vote up
public void deleteItem(View view) {

        new MaterialDialog.Builder(this)
                .title("Remove")
                .content("Are you sure do you want to remove this image?")
                .positiveText("Yes")
                .onPositive((dialog, which) -> {

                    if(imagesList.size()==1) {
                        finish();
                        return;
                    }

                    imagesList.remove(pager.getCurrentItem());

                    adapter=new PagerPhotosAdapter(PostImage.this,imagesList);
                    pager.setAdapter(adapter);
                    indicator.setViewPager(pager);

                    if(imagesList.size()>1){
                        indicator_holder.setVisibility(View.VISIBLE);
                        indicator.setViewPager(pager);
                    }else{
                        indicator_holder.setVisibility(GONE);
                    }

                })
                .negativeText("No")
                .show();
    }
 
Example 24
Source Project: Fishing   Source File: PlaceAddActivity.java    License: GNU General Public License v3.0 5 votes vote down vote up
private void showPoolTypeEdit() {
    new MaterialDialog.Builder(this)
            .title("请选择水系类型")
            .items(Constant.PlacePoolType)
            .itemsCallbackSingleChoice(getPresenter().getPlaceDetail().getPoolType(), new MaterialDialog.ListCallbackSingleChoice() {
                @Override
                public boolean onSelection(MaterialDialog dialog, View view, int which, CharSequence text) {
                    getPresenter().setPoolType(which);
                    return true;
                }
            })
            .positiveText("确定")
            .show();
}
 
Example 25
Source Project: OpenHub   Source File: ColorChooserDialog.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onClick(View v) {
  if (v.getTag() != null) {
    final String[] tag = ((String) v.getTag()).split(":");
    final int index = Integer.parseInt(tag[0]);
    final MaterialDialog dialog = (MaterialDialog) getDialog();
    final Builder builder = getBuilder();

    if (isInSub()) {
      subIndex(index);
    } else {
      topIndex(index);
      if (colorsSub != null && index < colorsSub.length) {
        dialog.setActionButton(DialogAction.NEGATIVE, builder.backBtn);
        isInSub(true);
      }
    }

    if (builder.allowUserCustom) {
      selectedCustomColor = getSelectedColor();
    }
    invalidateDynamicButtonColors();
    invalidate();
    //if no done button, click color meaning it's selected
    if(builder.doneBtn == 0){
      callback.onColorSelection(ColorChooserDialog.this, getSelectedColor());
    }
  }
}
 
Example 26
Source Project: wallpaperboard   Source File: LicensesFragment.java    License: 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_licenses, false);
    builder.typeface(TypefaceHelper.getMedium(getActivity()), TypefaceHelper.getRegular(getActivity()));
    builder.title(R.string.about_open_source_licenses);
    MaterialDialog dialog = builder.build();
    dialog.show();

    ButterKnife.bind(this, dialog);
    return dialog;
}
 
Example 27
Source Project: candybar   Source File: RequestHelper.java    License: Apache License 2.0 5 votes vote down vote up
public static void showPremiumRequestLimitDialog(@NonNull Context context, int selected) {
    String message = String.format(context.getResources().getString(R.string.premium_request_limit),
            Preferences.get(context).getPremiumRequestCount());
    message += " " + String.format(context.getResources().getString(R.string.premium_request_limit1),
            selected);
    new MaterialDialog.Builder(context)
            .typeface(
                    TypefaceHelper.getMedium(context),
                    TypefaceHelper.getRegular(context))
            .title(R.string.premium_request)
            .content(message)
            .positiveText(R.string.close)
            .show();
}
 
Example 28
Source Project: candybar   Source File: RequestHelper.java    License: Apache License 2.0 5 votes vote down vote up
public static void showPremiumRequestStillAvailable(@NonNull Context context) {
    String message = String.format(context.getResources().getString(
            R.string.premium_request_already_purchased),
            Preferences.get(context).getPremiumRequestCount());
    new MaterialDialog.Builder(context)
            .typeface(
                    TypefaceHelper.getMedium(context),
                    TypefaceHelper.getRegular(context))
            .title(R.string.premium_request)
            .content(message)
            .positiveText(R.string.close)
            .show();
}
 
Example 29
Source Project: OmniList   Source File: LockActivity.java    License: GNU Affero General Public License v3.0 5 votes vote down vote up
private void showFreezeDialog() {
    new MaterialDialog.Builder(this)
            .title(R.string.text_tips)
            .content(R.string.setting_password_frozen)
            .positiveText(R.string.text_ok)
            .onPositive((dialog, which) -> showQuestionDialog())
            .negativeText(R.string.text_cancel)
            .build().show();
}
 
Example 30
Source Project: android-issue-reporter   Source File: IssueReporterActivity.java    License: MIT License 5 votes vote down vote up
@Override
protected Dialog createDialog(@NonNull Context context) {
    return new MaterialDialog.Builder(context)
            .progress(true, 0)
            .progressIndeterminateStyle(true)
            .title(R.string.air_dialog_title_loading)
            .show();
}