Search in sources :

Example 76 with MaterialDialog

use of com.afollestad.materialdialogs.MaterialDialog in project AntennaPod by AntennaPod.

the class VariableSpeedDialog method showGetPluginDialog.

private static void showGetPluginDialog(final Context context, boolean showSpeedSelector) {
    MaterialDialog.Builder builder = new MaterialDialog.Builder(context);
    builder.title(R.string.no_playback_plugin_title);
    builder.content(R.string.no_playback_plugin_or_sonic_msg);
    builder.positiveText(R.string.enable_sonic);
    builder.negativeText(R.string.download_plugin_label);
    builder.neutralText(R.string.close_label);
    builder.onPositive((dialog, which) -> {
        if (Build.VERSION.SDK_INT >= 16) {
            // just to be safe
            UserPreferences.enableSonic(true);
            if (showSpeedSelector) {
                showSpeedSelectorDialog(context);
            }
        }
    });
    builder.onNegative((dialog, which) -> {
        try {
            context.startActivity(playStoreIntent);
        } catch (ActivityNotFoundException e) {
            // this is usually thrown on an emulator if the Android market is not installed
            Log.e(TAG, Log.getStackTraceString(e));
        }
    });
    builder.forceStacking(true);
    MaterialDialog dialog = builder.show();
    if (Build.VERSION.SDK_INT < 16) {
        View pos = dialog.getActionButton(DialogAction.POSITIVE);
        pos.setEnabled(false);
    }
    if (!IntentUtils.isCallable(context.getApplicationContext(), playStoreIntent)) {
        View pos = dialog.getActionButton(DialogAction.NEGATIVE);
        pos.setEnabled(false);
    }
}
Also used : MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) ActivityNotFoundException(android.content.ActivityNotFoundException) View(android.view.View)

Example 77 with MaterialDialog

use of com.afollestad.materialdialogs.MaterialDialog in project AntennaPod by AntennaPod.

the class PreferenceController method showChooseDataFolderDialog.

private void showChooseDataFolderDialog() {
    Context context = ui.getActivity();
    File dataFolder = UserPreferences.getDataFolder(null);
    if (dataFolder == null) {
        new MaterialDialog.Builder(ui.getActivity()).title(R.string.error_label).content(R.string.external_storage_error_msg).neutralText(android.R.string.ok).show();
        return;
    }
    String dataFolderPath = dataFolder.getAbsolutePath();
    int selectedIndex = -1;
    File[] mediaDirs = ContextCompat.getExternalFilesDirs(context, null);
    List<String> folders = new ArrayList<>(mediaDirs.length);
    List<CharSequence> choices = new ArrayList<>(mediaDirs.length);
    for (int i = 0; i < mediaDirs.length; i++) {
        File dir = mediaDirs[i];
        if (dir == null || !dir.exists() || !dir.canRead() || !dir.canWrite()) {
            continue;
        }
        String path = mediaDirs[i].getAbsolutePath();
        folders.add(path);
        if (dataFolderPath.equals(path)) {
            selectedIndex = i;
        }
        int index = path.indexOf("Android");
        String choice;
        if (index >= 0) {
            choice = path.substring(0, index);
        } else {
            choice = path;
        }
        long bytes = StorageUtils.getFreeSpaceAvailable(path);
        String freeSpace = String.format(context.getString(R.string.free_space_label), Converter.byteToString(bytes));
        choices.add(Html.fromHtml("<html><small>" + choice + " [" + freeSpace + "]" + "</small></html>"));
    }
    if (choices.size() == 0) {
        new MaterialDialog.Builder(ui.getActivity()).title(R.string.error_label).content(R.string.external_storage_error_msg).neutralText(android.R.string.ok).show();
        return;
    }
    MaterialDialog dialog = new MaterialDialog.Builder(ui.getActivity()).title(R.string.choose_data_directory).content(R.string.choose_data_directory_message).items(choices.toArray(new CharSequence[choices.size()])).itemsCallbackSingleChoice(selectedIndex, (dialog1, itemView, which, text) -> {
        String folder = folders.get(which);
        Log.d(TAG, "data folder: " + folder);
        UserPreferences.setDataFolder(folder);
        setDataFolderText();
        return true;
    }).negativeText(R.string.cancel_label).cancelable(true).build();
    dialog.show();
}
Also used : Context(android.content.Context) Arrays(java.util.Arrays) DateUtils(android.text.format.DateUtils) PackageManager(android.content.pm.PackageManager) Uri(android.net.Uri) AndroidSchedulers(rx.android.schedulers.AndroidSchedulers) FlattrUtils(de.danoeh.antennapod.core.util.flattr.FlattrUtils) PreferenceScreen(android.preference.PreferenceScreen) EditTextPreference(android.preference.EditTextPreference) UserPreferences(de.danoeh.antennapod.core.preferences.UserPreferences) Manifest(android.Manifest) ExportWorker(de.danoeh.antennapod.asynctask.ExportWorker) Schedulers(rx.schedulers.Schedulers) PreferenceManager(android.preference.PreferenceManager) GpodnetSyncService(de.danoeh.antennapod.core.service.GpodnetSyncService) Log(android.util.Log) WifiConfiguration(android.net.wifi.WifiConfiguration) GpodnetSetHostnameDialog(de.danoeh.antennapod.dialog.GpodnetSetHostnameDialog) GregorianCalendar(java.util.GregorianCalendar) ContextCompat(android.support.v4.content.ContextCompat) ActivityCompat(android.support.v4.app.ActivityCompat) DateFormat(android.text.format.DateFormat) ListPreference(android.preference.ListPreference) List(java.util.List) MainActivity(de.danoeh.antennapod.activity.MainActivity) HtmlWriter(de.danoeh.antennapod.core.export.html.HtmlWriter) ActivityNotFoundException(android.content.ActivityNotFoundException) Html(android.text.Html) AutoFlattrPreferenceDialog(de.danoeh.antennapod.dialog.AutoFlattrPreferenceDialog) ListView(android.widget.ListView) Snackbar(android.support.design.widget.Snackbar) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) Subscription(rx.Subscription) TextWatcher(android.text.TextWatcher) Converter(de.danoeh.antennapod.core.util.Converter) Context(android.content.Context) TimePickerDialog(android.app.TimePickerDialog) AboutActivity(de.danoeh.antennapod.activity.AboutActivity) AuthenticationDialog(de.danoeh.antennapod.dialog.AuthenticationDialog) ExportWriter(de.danoeh.antennapod.core.export.ExportWriter) Intent(android.content.Intent) CheckBoxPreference(android.preference.CheckBoxPreference) ArrayUtils(org.apache.commons.lang3.ArrayUtils) Editable(android.text.Editable) ArrayList(java.util.ArrayList) Observable(rx.Observable) StatisticsActivity(de.danoeh.antennapod.activity.StatisticsActivity) SuppressLint(android.annotation.SuppressLint) OpmlWriter(de.danoeh.antennapod.core.export.opml.OpmlWriter) Calendar(java.util.Calendar) PreferenceActivity(de.danoeh.antennapod.activity.PreferenceActivity) Toast(android.widget.Toast) CrashReportWriter(de.danoeh.antennapod.CrashReportWriter) StorageUtils(de.danoeh.antennapod.core.util.StorageUtils) Build(android.os.Build) ProxyDialog(de.danoeh.antennapod.dialog.ProxyDialog) R(de.danoeh.antennapod.R) PreferenceActivityGingerbread(de.danoeh.antennapod.activity.PreferenceActivityGingerbread) VariableSpeedDialog(de.danoeh.antennapod.dialog.VariableSpeedDialog) ProgressDialog(android.app.ProgressDialog) File(java.io.File) DirectoryChooserActivity(de.danoeh.antennapod.activity.DirectoryChooserActivity) TimeUnit(java.util.concurrent.TimeUnit) WifiManager(android.net.wifi.WifiManager) AlertDialog(android.support.v7.app.AlertDialog) SharedPreferences(android.content.SharedPreferences) Preference(android.preference.Preference) GpodnetPreferences(de.danoeh.antennapod.core.preferences.GpodnetPreferences) Comparator(java.util.Comparator) Activity(android.app.Activity) Collections(java.util.Collections) EditText(android.widget.EditText) Resources(android.content.res.Resources) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) ArrayList(java.util.ArrayList) SuppressLint(android.annotation.SuppressLint) File(java.io.File)

Example 78 with MaterialDialog

use of com.afollestad.materialdialogs.MaterialDialog in project Weather by Sparker0i.

the class GPSTracker method showSettingsAlert.

/**
     * Function to show settings alert dialog
     * On pressing Settings button will launch Settings Options
     * */
public void showSettingsAlert() {
    new MaterialDialog.Builder(mContext).title("Enable GPS").content("You need to enable GPS for this function to work").positiveText("ENABLE").onPositive(new MaterialDialog.SingleButtonCallback() {

        @Override
        public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
            Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
            mContext.startActivity(intent);
        }
    }).negativeText("CANCEL").onNegative(new MaterialDialog.SingleButtonCallback() {

        @Override
        public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
            dialog.dismiss();
        }
    }).show();
}
Also used : MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) DialogAction(com.afollestad.materialdialogs.DialogAction) NonNull(android.support.annotation.NonNull) Intent(android.content.Intent)

Example 79 with MaterialDialog

use of com.afollestad.materialdialogs.MaterialDialog in project Tapad by berict.

the class UserBenefitsActivity method showDialogPreset.

private void showDialogPreset(int delay) {
    Handler dialogDelay = new Handler();
    dialogDelay.postDelayed(new Runnable() {

        @Override
        public void run() {
            int color;
            switch(prefs.getInt("scheme", 0)) {
                case 1:
                    color = R.color.hello;
                    break;
                case 2:
                    color = R.color.roses;
                    break;
                case 3:
                    color = R.color.faded;
                    break;
                default:
                    color = R.color.hello;
                    break;
            }
            PresetDialog = new MaterialDialog.Builder(activity).title(R.string.dialog_preset_title).content(R.string.user_benefits_dialog_hint).items(R.array.presets).cancelable(false).autoDismiss(false).itemsCallbackSingleChoice(0, new MaterialDialog.ListCallbackSingleChoice() {

                @Override
                public boolean onSelection(MaterialDialog dialog, View view, int which, CharSequence text) {
                    setPreset(which);
                    switch(which) {
                        case 0:
                            PresetDialog.getBuilder().widgetColorRes(R.color.hello).positiveColorRes(R.color.hello);
                            break;
                        case 1:
                            PresetDialog.getBuilder().widgetColorRes(R.color.roses).positiveColorRes(R.color.roses);
                            break;
                        case 2:
                            PresetDialog.getBuilder().widgetColorRes(R.color.faded).positiveColorRes(R.color.faded);
                            break;
                        default:
                            break;
                    }
                    return true;
                }
            }).alwaysCallSingleChoiceCallback().widgetColorRes(color).positiveText(R.string.user_benefits_dialog_positive).positiveColorRes(R.color.colorAccent).onPositive(new MaterialDialog.SingleButtonCallback() {

                @Override
                public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                    PresetDialog.dismiss();
                    intent.intentFlag(activity, "activity.MainActivity", 0);
                    prefs.edit().putInt("quickstart", 0).apply();
                }
            }).show();
        }
    }, delay);
}
Also used : MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) DialogAction(com.afollestad.materialdialogs.DialogAction) NonNull(android.support.annotation.NonNull) Handler(android.os.Handler) View(android.view.View) TextView(android.widget.TextView)

Example 80 with MaterialDialog

use of com.afollestad.materialdialogs.MaterialDialog in project Tapad by berict.

the class MainActivity method setQuickstart.

public void setQuickstart(final Activity activity) {
    final SharedPreferences pref = activity.getSharedPreferences(APPLICATION_ID, MODE_PRIVATE);
    try {
        currentVersionCode = activity.getPackageManager().getPackageInfo(activity.getPackageName(), 0).versionCode;
        Log.i("versionCode", "versionCode retrieved = " + String.valueOf(currentVersionCode));
    } catch (android.content.pm.PackageManager.NameNotFoundException e) {
        // handle exception
        currentVersionCode = -1;
        Log.e("NameNotFound", "NNFE, currentVersionCode = -1");
    }
    try {
        Log.d("VersionCode", "sharedPrefs versionCode = " + String.valueOf(pref.getInt("versionCode", -1)) + " , currentVersionCode = " + String.valueOf(currentVersionCode));
        Log.d("VersionCode", "Updated, show changelog");
        if (currentVersionCode > pref.getInt("versionCode", -1)) {
            // new app and updates
            new MaterialDialog.Builder(activity).title(w.getStringId("info_tapad_info_changelog")).content(w.getStringId("info_tapad_info_changelog_text")).contentColorRes(R.color.dark_primary).positiveText(R.string.dialog_close).positiveColorRes(R.color.colorAccent).dismissListener(new DialogInterface.OnDismissListener() {

                @Override
                public void onDismiss(DialogInterface dialogInterface) {
                    // Dialog
                    if (pref.getInt(qs, 0) == 0) {
                        closeToolbar(activity);
                        new MaterialDialog.Builder(activity).title(R.string.dialog_quickstart_welcome_title).content(R.string.dialog_quickstart_welcome_text).positiveText(R.string.dialog_quickstart_welcome_positive).positiveColorRes(R.color.colorAccent).negativeText(R.string.dialog_quickstart_welcome_negative).negativeColorRes(R.color.dark_secondary).onPositive(new MaterialDialog.SingleButtonCallback() {

                            @Override
                            public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                                pref.edit().putInt(qs, 0).apply();
                                Log.i("sharedPrefs", "quickstart edited to 0");
                            }
                        }).onNegative(new MaterialDialog.SingleButtonCallback() {

                            @Override
                            public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                                pref.edit().putInt(qs, -1).apply();
                                Log.i("sharedPrefs", "quickstart edited to -1");
                            }
                        }).dismissListener(new DialogInterface.OnDismissListener() {

                            @Override
                            public void onDismiss(DialogInterface dialogInterface) {
                                if (pref.getInt(qs, 0) == 0) {
                                    Log.i("setQuickstart", "Quickstart started");
                                    if (promptFab != null) {
                                        return;
                                    }
                                    promptToggle = new MaterialTapTargetPrompt.Builder(activity).setTarget(activity.findViewById(R.id.tgl1)).setPrimaryText(R.string.dialog_tap_target_toggle_primary).setSecondaryText(R.string.dialog_tap_target_toggle_secondary).setAnimationInterpolator(new FastOutSlowInInterpolator()).setAutoDismiss(false).setAutoFinish(false).setFocalColourFromRes(R.color.white).setCaptureTouchEventOutsidePrompt(true).setOnHidePromptListener(new MaterialTapTargetPrompt.OnHidePromptListener() {

                                        @Override
                                        public void onHidePrompt(MotionEvent event, boolean tappedTarget) {
                                            if (tappedTarget) {
                                                promptToggle.finish();
                                                promptToggle = null;
                                                pref.edit().putInt(qs, 1).apply();
                                                Log.i("sharedPrefs", "quickstart edited to 1");
                                            }
                                        }

                                        @Override
                                        public void onHidePromptComplete() {
                                            promptButton = new MaterialTapTargetPrompt.Builder(activity).setTarget(activity.findViewById(R.id.btn31)).setPrimaryText(R.string.dialog_tap_target_button_primary).setSecondaryText(R.string.dialog_tap_target_button_secondary).setAnimationInterpolator(new FastOutSlowInInterpolator()).setAutoDismiss(false).setAutoFinish(false).setFocalColourFromRes(R.color.white).setFocalRadius((float) w.convertDPtoPX(80, activity)).setCaptureTouchEventOutsidePrompt(true).setOnHidePromptListener(new MaterialTapTargetPrompt.OnHidePromptListener() {

                                                @Override
                                                public void onHidePrompt(MotionEvent event, boolean tappedTarget) {
                                                    if (tappedTarget) {
                                                        promptButton.finish();
                                                        promptButton = null;
                                                        pref.edit().putInt(qs, 3).apply();
                                                        Log.i("sharedPrefs", "quickstart edited to 3");
                                                    }
                                                }

                                                @Override
                                                public void onHidePromptComplete() {
                                                    promptSwipe = new MaterialTapTargetPrompt.Builder(activity).setTarget(activity.findViewById(R.id.btn23)).setPrimaryText(R.string.dialog_tap_target_swipe_primary).setSecondaryText(R.string.dialog_tap_target_swipe_secondary).setAnimationInterpolator(new FastOutSlowInInterpolator()).setAutoDismiss(false).setAutoFinish(false).setFocalColourFromRes(R.color.white).setFocalRadius((float) w.convertDPtoPX(80, activity)).setCaptureTouchEventOutsidePrompt(true).setOnHidePromptListener(new MaterialTapTargetPrompt.OnHidePromptListener() {

                                                        @Override
                                                        public void onHidePrompt(MotionEvent event, boolean tappedTarget) {
                                                            if (tappedTarget) {
                                                                promptSwipe.finish();
                                                                promptSwipe = null;
                                                                pref.edit().putInt(qs, 4).apply();
                                                                Log.i("sharedPrefs", "quickstart edited to 4");
                                                            }
                                                        }

                                                        @Override
                                                        public void onHidePromptComplete() {
                                                            promptLoop = new MaterialTapTargetPrompt.Builder(activity).setTarget(activity.findViewById(R.id.btn42)).setPrimaryText(R.string.dialog_tap_target_loop_primary).setSecondaryText(R.string.dialog_tap_target_loop_secondary).setAnimationInterpolator(new FastOutSlowInInterpolator()).setAutoDismiss(false).setAutoFinish(false).setFocalColourFromRes(R.color.white).setFocalRadius((float) w.convertDPtoPX(80, activity)).setCaptureTouchEventOutsidePrompt(true).setOnHidePromptListener(new MaterialTapTargetPrompt.OnHidePromptListener() {

                                                                @Override
                                                                public void onHidePrompt(MotionEvent event, boolean tappedTarget) {
                                                                    if (tappedTarget) {
                                                                        promptLoop.finish();
                                                                        promptLoop = null;
                                                                        pref.edit().putInt(qs, 5).apply();
                                                                        Log.i("sharedPrefs", "quickstart edited to 5");
                                                                    }
                                                                }

                                                                @Override
                                                                public void onHidePromptComplete() {
                                                                    promptPattern = new MaterialTapTargetPrompt.Builder(activity).setTarget(activity.findViewById(R.id.tgl7)).setPrimaryText(R.string.dialog_tap_target_pattern_primary).setSecondaryText(R.string.dialog_tap_target_pattern_secondary).setAnimationInterpolator(new FastOutSlowInInterpolator()).setAutoDismiss(false).setAutoFinish(false).setFocalColourFromRes(R.color.white).setCaptureTouchEventOutsidePrompt(true).setOnHidePromptListener(new MaterialTapTargetPrompt.OnHidePromptListener() {

                                                                        @Override
                                                                        public void onHidePrompt(MotionEvent event, boolean tappedTarget) {
                                                                            if (tappedTarget) {
                                                                                promptPattern.finish();
                                                                                promptPattern = null;
                                                                                pref.edit().putInt(qs, 5).apply();
                                                                                Log.i("sharedPrefs", "quickstart edited to 5");
                                                                            }
                                                                        }

                                                                        @Override
                                                                        public void onHidePromptComplete() {
                                                                            promptFab = new MaterialTapTargetPrompt.Builder(activity).setTarget(activity.findViewById(R.id.fab)).setPrimaryText(R.string.dialog_tap_target_fab_primary).setSecondaryText(R.string.dialog_tap_target_fab_secondary).setAnimationInterpolator(new FastOutSlowInInterpolator()).setAutoDismiss(false).setAutoFinish(false).setFocalColourFromRes(R.color.white).setCaptureTouchEventOutsidePrompt(true).setOnHidePromptListener(new MaterialTapTargetPrompt.OnHidePromptListener() {

                                                                                @Override
                                                                                public void onHidePrompt(MotionEvent event, boolean tappedTarget) {
                                                                                    if (tappedTarget) {
                                                                                        promptFab.finish();
                                                                                        promptFab = null;
                                                                                        pref.edit().putInt(qs, 6).apply();
                                                                                        Log.i("sharedPrefs", "quickstart edited to 6");
                                                                                    }
                                                                                }

                                                                                @Override
                                                                                public void onHidePromptComplete() {
                                                                                    promptPreset = new MaterialTapTargetPrompt.Builder(activity).setTarget(activity.findViewById(R.id.toolbar_preset)).setPrimaryText(R.string.dialog_tap_target_preset_primary).setSecondaryText(R.string.dialog_tap_target_preset_secondary).setAnimationInterpolator(new FastOutSlowInInterpolator()).setAutoDismiss(false).setAutoFinish(false).setFocalColourFromRes(R.color.blue_500).setCaptureTouchEventOutsidePrompt(true).setOnHidePromptListener(new MaterialTapTargetPrompt.OnHidePromptListener() {

                                                                                        @Override
                                                                                        public void onHidePrompt(MotionEvent event, boolean tappedTarget) {
                                                                                            if (tappedTarget) {
                                                                                                promptPreset.finish();
                                                                                                promptPreset = null;
                                                                                                pref.edit().putInt(qs, 7).apply();
                                                                                                Log.i("sharedPrefs", "quickstart edited to 7");
                                                                                            }
                                                                                        }

                                                                                        @Override
                                                                                        public void onHidePromptComplete() {
                                                                                        }
                                                                                    }).show();
                                                                                }
                                                                            }).show();
                                                                        }
                                                                    }).show();
                                                                }
                                                            }).show();
                                                        }
                                                    }).show();
                                                }
                                            }).show();
                                        }
                                    }).show();
                                } else {
                                    Log.i("setQuickstart", "Quickstart canceled");
                                    pref.edit().putInt(qs, -1).apply();
                                }
                            }
                        }).show();
                    }
                    // Change this
                    pref.edit().putInt("versionCode", currentVersionCode).apply();
                    Log.d("VersionCode", "putInt " + String.valueOf(pref.getInt("versionCode", -1)));
                }
            }).show();
        }
    } catch (Exception e) {
        Log.e("QuickstartException", e.getMessage());
    }
}
Also used : MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) SharedPreferences(android.content.SharedPreferences) DialogInterface(android.content.DialogInterface) MotionEvent(android.view.MotionEvent) DialogAction(com.afollestad.materialdialogs.DialogAction) NonNull(android.support.annotation.NonNull) FastOutSlowInInterpolator(android.support.v4.view.animation.FastOutSlowInInterpolator) MaterialTapTargetPrompt(uk.co.samuelwall.materialtaptargetprompt.MaterialTapTargetPrompt)

Aggregations

MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)80 View (android.view.View)49 DialogAction (com.afollestad.materialdialogs.DialogAction)44 NonNull (android.support.annotation.NonNull)32 TextView (android.widget.TextView)32 Intent (android.content.Intent)19 ImageView (android.widget.ImageView)19 RecyclerView (android.support.v7.widget.RecyclerView)17 File (java.io.File)17 MenuItem (android.view.MenuItem)14 PopupMenu (android.widget.PopupMenu)12 List (java.util.List)12 ListView (android.widget.ListView)11 Activity (android.app.Activity)9 Toast (android.widget.Toast)9 SuppressLint (android.annotation.SuppressLint)8 Context (android.content.Context)8 Bundle (android.os.Bundle)8 ArrayList (java.util.ArrayList)8 LayoutInflater (android.view.LayoutInflater)7