Search in sources :

Example 81 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 82 with MaterialDialog

use of com.afollestad.materialdialogs.MaterialDialog in project PocketHub by pockethub.

the class NewsFragment method onListItemLongClick.

@Override
public boolean onListItemLongClick(ListView l, View v, int position, long itemId) {
    if (!isUsable()) {
        return false;
    }
    final GitHubEvent event = (GitHubEvent) l.getItemAtPosition(position);
    final Repository repo = ConvertUtils.eventRepoToRepo(event.repo());
    final User user = event.actor();
    if (repo != null && user != null) {
        final MaterialDialog.Builder builder = new MaterialDialog.Builder(getActivity()).title(R.string.navigate_to);
        // Hacky but necessary since material dialogs has a different API
        final MaterialDialog[] dialogHolder = new MaterialDialog[1];
        View view = getActivity().getLayoutInflater().inflate(R.layout.nav_dialog, null);
        ViewFinder finder = new ViewFinder(view);
        avatars.bind(finder.imageView(R.id.iv_user_avatar), user);
        avatars.bind(finder.imageView(R.id.iv_repo_avatar), repo.owner());
        finder.setText(R.id.tv_login, user.login());
        finder.setText(R.id.tv_repo_name, InfoUtils.createRepoId(repo));
        finder.onClick(R.id.ll_user_area, new OnClickListener() {

            @Override
            public void onClick(View v) {
                dialogHolder[0].dismiss();
                viewUser(user);
            }
        });
        finder.onClick(R.id.ll_repo_area, new OnClickListener() {

            @Override
            public void onClick(View v) {
                dialogHolder[0].dismiss();
                viewRepository(repo);
            }
        });
        builder.customView(view, false);
        MaterialDialog dialog = builder.build();
        dialogHolder[0] = dialog;
        dialog.setCanceledOnTouchOutside(true);
        dialog.show();
        return true;
    }
    return false;
}
Also used : Repository(com.meisolsson.githubsdk.model.Repository) User(com.meisolsson.githubsdk.model.User) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) ViewFinder(com.github.kevinsawicki.wishlist.ViewFinder) OnClickListener(android.view.View.OnClickListener) GitHubEvent(com.meisolsson.githubsdk.model.GitHubEvent) View(android.view.View) ListView(android.widget.ListView)

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