Java Code Examples for com.afollestad.materialdialogs.MaterialDialog#Builder

The following examples show how to use com.afollestad.materialdialogs.MaterialDialog#Builder . 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: GeneralDialogCreation.java    From PowerFileExplorer with GNU General Public License v3.0 6 votes vote down vote up
public static void showHistoryDialog(final DataUtils dataUtils, Futils utils, final ContentFragment m, AppTheme appTheme) {
     int accentColor = m.activity.getColorPreference().getColor(ColorUsage.ACCENT);
     final MaterialDialog.Builder a = new MaterialDialog.Builder(m.getActivity());
     a.positiveText(R.string.cancel);
     a.positiveColor(accentColor);
     a.negativeText(R.string.clear);
     a.negativeColor(accentColor);
     a.title(R.string.history);
     a.onNegative(new MaterialDialog.SingleButtonCallback() {
	@Override
	public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
		dataUtils.clearHistory();
	}
});
     a.theme(appTheme.getMaterialDialogTheme());

     a.autoDismiss(true);
     HiddenAdapter adapter = new HiddenAdapter(m.getActivity(), m, utils, R.layout.bookmarkrow,
									  toHFileArray(dataUtils.getHistory()), null, true);
     a.adapter(adapter, null);

     MaterialDialog x= a.build();
     adapter.updateDialog(x);
     x.show();
 }
 
Example 2
Source File: DialogUtils.java    From io16experiment-master with Apache License 2.0 6 votes vote down vote up
/**
 * Create a progress dialog for the loading spinner or progress indicator
 * <p/>
 * @param activity
 * @param spinner
 * @param titleId
 * @param messageId
 * @param cancelable
 * @param max
 * @param onCancelListener
 * @param typeface
 * @param formatArgs
 * @return
 */
private static MaterialDialog createProgressDialog(final Activity activity, boolean spinner, int titleId, int messageId,
                                                   boolean cancelable, int max, DialogInterface.OnCancelListener onCancelListener,
                                                   Typeface typeface, Object... formatArgs) {
    MaterialDialog.Builder builder = new MaterialDialog.Builder(activity)
            .cancelable(cancelable);

    if (titleId > DEFAULT_TITLE_ID) {
        builder.title(messageId > DEFAULT_MESSAGE_ID ? activity.getString(titleId) : activity.getString(titleId, formatArgs));
    }
    if (messageId > DEFAULT_MESSAGE_ID) {
        builder.content(activity.getString(messageId, formatArgs)).typeface(typeface, typeface);
    }
    if (onCancelListener != null) {
        builder.cancelListener(onCancelListener);
    }
    if (spinner) {
        builder.progress(true, 0);
    } else {
        builder.progress(false, max, true);
    }

    return builder.build();
}
 
Example 3
Source File: PopupCodeResolver.java    From green_android with GNU General Public License v3.0 6 votes vote down vote up
@Override
public SettableFuture<String> code(final String method) {
    final SettableFuture<String> future = SettableFuture.create();

    final MaterialDialog.Builder builder =
        UI.popup(activity, activity.getString(R.string.id_please_provide_your_1s_code,
                                              method))
        .inputType(InputType.TYPE_CLASS_NUMBER)
        .icon(getIconFor(method))
        .cancelable(false)
        .input("", "", (dialog, input) -> {
        Log.d("RSV", "PopupCodeResolver OK callback");
        future.set(input.toString());
    })
        .onNegative((dialog, which) -> {
        Log.d("RSV", "PopupCodeResolver CANCEL callback");
        future.set(null);
    });

    activity.runOnUiThread(() -> {
        Log.d("RSV", "PopupCodeResolver dialog show");
        builder.show();
    });

    return future;
}
 
Example 4
Source File: UtilsDialog.java    From WhatsAppBetaUpdater with GNU General Public License v3.0 6 votes vote down vote up
public static MaterialDialog.Builder showDownloadingDialog(Context context, UtilsEnum.DownloadType downloadType, String version) {
    Boolean showMinMax = false; // Show a max/min ratio to the left of the seek bar

    MaterialDialog.Builder builder = new MaterialDialog.Builder(context)
            .progress(false, 100, showMinMax)
            .cancelable(false)
            .negativeText(context.getResources().getString(android.R.string.cancel));

    switch (downloadType) {
        case WHATSAPP_APK:
            builder.title(String.format(context.getResources().getString(R.string.downloading), context.getResources().getString(R.string.app_whatsapp), version));
            break;
        case UPDATE:
            builder.title(String.format(context.getResources().getString(R.string.downloading), context.getResources().getString(R.string.app_name), version));
            break;
    }

    return builder;
}
 
Example 5
Source File: DialogAndroid.java    From react-native-dialogs with MIT License 5 votes vote down vote up
@ReactMethod
public void list(ReadableMap options, final Callback callback) {
    final MaterialSimpleListAdapter simpleListAdapter = new MaterialSimpleListAdapter(new MaterialSimpleListAdapter.Callback() {
        @Override
        public void onMaterialListItemSelected(MaterialDialog dialog, int index, MaterialSimpleListItem item) {
            if (!mCallbackConsumed) {
                mCallbackConsumed = true;
                callback.invoke(index, item.getContent());
            }
            if (simple != null) {
                simple.dismiss();
            }
        }
    });

    ReadableArray arr = options.getArray("items");
    for(int i = 0; i < arr.size(); i++){
        simpleListAdapter.add(new MaterialSimpleListItem.Builder(getCurrentActivity())
                .content(arr.getString(i))
                .build());
    }

    final MaterialDialog.Builder adapter = new MaterialDialog.Builder(getCurrentActivity())
            .title(options.hasKey("title") ? options.getString("title") : "")
            .adapter(simpleListAdapter, null)
            .autoDismiss(true);

    UiThreadUtil.runOnUiThread(new Runnable() {
        public void run() {
            if (simple != null) {
                simple.dismiss();
            }
            simple = adapter.build();
            simple.show();
        }
    });
}
 
Example 6
Source File: UtilsDialog.java    From MLManager with GNU General Public License v3.0 5 votes vote down vote up
public static MaterialDialog showTitleContent(Context context, String title, String content) {
    MaterialDialog.Builder materialBuilder = new MaterialDialog.Builder(context)
            .title(title)
            .content(content)
            .positiveText(context.getResources().getString(android.R.string.ok))
            .cancelable(true);
    return materialBuilder.show();
}
 
Example 7
Source File: Login.java    From Slide with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onPreExecute() {
    //Show a dialog to indicate progress
    MaterialDialog.Builder builder =
            new MaterialDialog.Builder(Login.this).title(R.string.login_authenticating)
                    .progress(true, 0)
                    .content(R.string.misc_please_wait)
                    .cancelable(false);
    mMaterialDialog = builder.build();
    mMaterialDialog.show();
}
 
Example 8
Source File: ComponentDialogFragment.java    From Walrus with GNU General Public License v3.0 5 votes vote down vote up
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    boolean editable = getArguments().getBoolean("editable");

    MaterialDialog.Builder builder = new MaterialDialog.Builder(getActivity())
            .title(getArguments().getString("title"))
            .customView(R.layout.dialog_component_dialog, true);

    if (editable) {
        builder
                .positiveText(android.R.string.ok)
                .onPositive(new MaterialDialog.SingleButtonCallback() {
                    @Override
                    public void onClick(@NonNull MaterialDialog dialog,
                            @NonNull DialogAction which) {
                        viewModel.getComponentSourceAndSink().applyComponent(component);

                        if (getActivity() instanceof OnEditedCallback) {
                            ((OnEditedCallback) getActivity()).onEdited(
                                    viewModel.getComponentSourceAndSink(),
                                    getArguments().getInt("callback_id"));
                        }

                        dismiss();
                    }
                })
                .negativeText(android.R.string.cancel);
    }

    return builder.build();
}
 
Example 9
Source File: SPVPreferenceFragment.java    From green_android with GNU General Public License v3.0 5 votes vote down vote up
private boolean onSPVEnabledChanged(final Boolean newValue) {
    mTrustedPeer.setEnabled(newValue);
    mSpv.setSPVEnabledAsync(newValue);
    mSPVSyncOnMobile.setEnabled(newValue);
    mScanSPV.setEnabled(newValue);
    final String network = PreferenceManager.getDefaultSharedPreferences(getContext()).getString(
        PrefKeys.NETWORK_ID_ACTIVE, "mainnet");
    final SharedPreferences preferences = getContext().getSharedPreferences(network, MODE_PRIVATE);
    final boolean proxyEnabled = preferences.getBoolean(PrefKeys.PROXY_ENABLED, false);
    final boolean torEnabled = preferences.getBoolean(PrefKeys.TOR_ENABLED, false);
    final String peers =
        preferences.getString(PrefKeys.TRUSTED_ADDRESS, preferences.getString("trusted_peer", "")).trim();

    if (!newValue) {
        mSPVSyncOnMobile.setChecked(false);
        mSpv.setSPVSyncOnMobileEnabledAsync(false);
    } else if ((torEnabled || proxyEnabled) && peers.isEmpty()) {
        if (getActivity() == null) {
            return true;
        }

        final MaterialDialog.Builder builder = UI.popup(
            getActivity(),
            R.string.id_warning_no_trusted_node_set,
            android.R.string.ok)
                                               .content(R.string.id_spv_synchronization_using_tor)
                                               .cancelable(false)
                                               .onAny((dialog,
                                                       which) -> getPreferenceManager().showDialog(mTrustedPeer));
        getActivity().runOnUiThread(() -> { builder.show(); });
    }
    return true;
}
 
Example 10
Source File: DialogHelper.java    From openlauncher with Apache License 2.0 5 votes vote down vote up
public static void selectGestureDialog(final Context context, String title, MaterialDialog.ListCallback callback) {
    MaterialDialog.Builder builder = new MaterialDialog.Builder(context);
    builder.title(title)
            .items(R.array.entries__gesture)
            .itemsCallback(callback)
            .show();
}
 
Example 11
Source File: LicensesFragment.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_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 12
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 13
Source File: UserInfoEditActivity.java    From Elephant with Apache License 2.0 5 votes vote down vote up
private void initDialog() {
    mInputDialog = new MaterialDialog.Builder(this);
    mInputDialog.negativeText(getString(R.string.dialog_btn_cancel));
    mInputDialog.positiveText(getString(R.string.dialog_btn_confirm));
    mInputDialog.positiveColorRes(R.color.colorPrimary);
    mInputDialog.negativeColorRes(R.color.colorPrimary);
    mInputDialog.titleColorRes(R.color.text_common);
    mInputDialog.inputType(InputType.TYPE_CLASS_TEXT);
    mInputDialog.widgetColorRes(R.color.colorPrimary);
}
 
Example 14
Source File: InactiveTimePreference.java    From AcDisplay with GNU General Public License v2.0 5 votes vote down vote up
@NonNull
@Override
public MaterialDialog onBuildDialog(@NonNull MaterialDialog.Builder builder) {
    Context context = getContext();
    MaterialDialog md = builder
            .customView(R.layout.preference_dialog_inactive_hours, false)
            .build();

    View root = md.getCustomView();
    assert root != null;
    TextView fromTextView = (TextView) root.findViewById(R.id.from);
    TextView toTextView = (TextView) root.findViewById(R.id.to);
    mEnabled = (CheckBox) root.findViewById(R.id.checkbox);

    fromTextView.setOnClickListener(this);
    toTextView.setOnClickListener(this);

    mFrom.labelTextView = fromTextView;
    mFrom.labelSource = context.getString(R.string.preference_inactive_hours_from);
    mTo.labelTextView = toTextView;
    mTo.labelSource = context.getString(R.string.preference_inactive_hours_to);

    Config config = Config.getInstance();
    mFrom.setTime(context, config.getInactiveTimeFrom());
    mTo.setTime(context, config.getInactiveTimeTo());
    mEnabled.setChecked(config.isInactiveTimeEnabled());
    return md;
}
 
Example 15
Source File: SettingsFragment.java    From candybar-library with Apache License 2.0 5 votes vote down vote up
@Override
protected void onPreExecute() {
    super.onPreExecute();
    MaterialDialog.Builder builder = new MaterialDialog.Builder(getActivity());
    builder.typeface(
            TypefaceHelper.getMedium(getActivity()),
            TypefaceHelper.getRegular(getActivity()));
    builder.content(R.string.premium_request_rebuilding);
    builder.cancelable(false);
    builder.canceledOnTouchOutside(false);
    builder.progress(true, 0);
    builder.progressIndeterminateStyle(true);
    dialog = builder.build();
    dialog.show();
}
 
Example 16
Source File: BaseActivity.java    From Elephant with Apache License 2.0 4 votes vote down vote up
public MaterialDialog.Builder getLoadingDialog() {
    return mLoadingDialog;
}
 
Example 17
Source File: WeatherFragment.java    From Weather with GNU General Public License v3.0 4 votes vote down vote up
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    rootView = inflater.inflate(R.layout.fragment_weather, container, false);
    ButterKnife.bind(this, rootView);
    MaterialDialog.Builder builder = new MaterialDialog.Builder(this.activity())
            .title(getString(R.string.please_wait))
            .content(getString(R.string.loading))
            .cancelable(false)
            .progress(true, 0);
    pd = builder.build();
    setHasOptionsMenu(true);
    preferences = new Prefs(context());
    weatherFont = Typeface.createFromAsset(activity().getAssets(), "fonts/weather-icons-v2.0.10.ttf");
    fab = ((WeatherActivity) activity()).findViewById(R.id.fab);
    Bundle bundle = getArguments();
    fabProgressCircle = ((WeatherActivity) activity()).findViewById(R.id.fabProgressCircle);
    int mode;
    if (bundle != null)
        mode = bundle.getInt(Constants.MODE, 0);
    else
        mode = 0;
    if (mode == 0)
        updateWeatherData(preferences.getCity(), null, null);
    else
        updateWeatherData(null, Float.toString(preferences.getLatitude()), Float.toString(preferences.getLongitude()));
    gps = new GPSTracker(context());
    cityField.setTextColor(ContextCompat.getColor(context(), R.color.textColor));
    updatedField.setTextColor(ContextCompat.getColor(context(), R.color.textColor));
    humidityView.setTextColor(ContextCompat.getColor(context(), R.color.textColor));
    sunriseIcon.setTextColor(ContextCompat.getColor(context(), R.color.textColor));
    sunriseIcon.setTypeface(weatherFont);
    sunriseIcon.setText(activity().getString(R.string.sunrise_icon));
    sunsetIcon.setTextColor(ContextCompat.getColor(context(), R.color.textColor));
    sunsetIcon.setTypeface(weatherFont);
    sunsetIcon.setText(activity().getString(R.string.sunset_icon));
    humidityIcon.setTextColor(ContextCompat.getColor(context(), R.color.textColor));
    humidityIcon.setTypeface(weatherFont);
    humidityIcon.setText(activity().getString(R.string.humidity_icon));
    windView.setTextColor(ContextCompat.getColor(context(), R.color.textColor));
    swipeView.setColorSchemeResources(R.color.red, R.color.green, R.color.blue, R.color.yellow, R.color.orange);
    swipeView.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
        @Override
        public void onRefresh() {
            handler.post(new Runnable() {
                @Override
                public void run() {
                    changeCity(preferences.getCity());
                    swipeView.setRefreshing(false);
                }
            });
        }
    });
    horizontalLayoutManager
            = new LinearLayoutManager(context(), LinearLayoutManager.HORIZONTAL, false);
    horizontalRecyclerView.setLayoutManager(horizontalLayoutManager);
    horizontalRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            if (horizontalLayoutManager.findLastVisibleItemPosition() == 9 || citys != null)
                fab.hide();
            else
                fab.show();
        }
    });
    directionView.setTypeface(weatherFont);
    directionView.setTextColor(ContextCompat.getColor(context(), R.color.textColor));
    dailyView.setText(getString(R.string.daily));
    dailyView.setTextColor(ContextCompat.getColor(context(), R.color.textColor));
    sunriseView.setTextColor(ContextCompat.getColor(context(), R.color.textColor));
    sunsetView.setTextColor(ContextCompat.getColor(context(), R.color.textColor));
    button.setTextColor(ContextCompat.getColor(context(), R.color.textColor));
    pd.show();
    horizontalRecyclerView.setBackgroundColor(getResources().getColor(R.color.colorPrimary));
    weatherIcon.setTypeface(weatherFont);
    weatherIcon.setTextColor(ContextCompat.getColor(context(), R.color.textColor));
    if (citys == null)
        ((WeatherActivity) activity()).showFab();
    else
        ((WeatherActivity) activity()).hideFab();
    return rootView;
}
 
Example 18
Source File: FragmentRegistrationNickname.java    From iGap-Android with GNU Affero General Public License v3.0 4 votes vote down vote up
private void startDialog() {
    MaterialDialog.Builder imageDialog = new MaterialDialog.Builder(G.fragmentActivity).title(G.fragmentActivity.getResources().getString(R.string.choose_picture))
            .negativeText(G.fragmentActivity.getResources().getString(R.string.B_cancel))
            .items(R.array.profile)
            .itemsCallback(new MaterialDialog.ListCallback() {
                @Override
                public void onSelection(final MaterialDialog dialog, View view, int which, CharSequence text) {

                    switch (which) {
                        case 0: {
                            useGallery();
                            dialog.dismiss();
                            break;
                        }
                        case 1: {
                            if (G.context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA_ANY)) {
                                try {
                                    HelperPermission.getCameraPermission(G.fragmentActivity, new OnGetPermission() {
                                        @Override
                                        public void Allow() {
                                            // this dialog show 2 way for choose image : gallery and camera
                                            dialog.dismiss();
                                            useCamera();
                                        }

                                        @Override
                                        public void deny() {

                                        }
                                    });
                                } catch (IOException e) {
                                    e.printStackTrace();
                                }
                            } else {

                                HelperError.showSnackMessage(G.fragmentActivity.getResources().getString(R.string.please_check_your_camera), false);
                            }
                            break;
                        }
                    }
                }
            });
    if (!(G.fragmentActivity).isFinishing()) {
        imageDialog.show();
    }
}
 
Example 19
Source File: BaseMaterialDialog.java    From RxJava2RetrofitDemo with Apache License 2.0 4 votes vote down vote up
protected static MaterialDialog.Builder newSimpleProgressLoadingBuilder(Context context, @StringRes int StrRes) {
    String message = context.getString(StrRes);
    return newSimpleProgressLoadingBuilder(context, message);
}
 
Example 20
Source File: UI.java    From green_android with GNU General Public License v3.0 4 votes vote down vote up
public static MaterialDialog.Builder popup(final Activity a, final String title) {
    return popup(a, title, android.R.string.ok, android.R.string.cancel);
}