Search in sources :

Example 1 with BUTTON_POSITIVE

use of android.content.DialogInterface.BUTTON_POSITIVE in project MaxLock by Maxr1998.

the class MaxLockPreferenceFragment method onLockscreenDismissed.

public void onLockscreenDismissed() {
    // Show changelog and rating dialog
    int lastVersionNumber = prefs.getInt(Common.LAST_VERSION_NUMBER, -1);
    if (BuildConfig.VERSION_CODE > lastVersionNumber) {
        // Don't show updated dialog on first start
        if (lastVersionNumber > 0)
            showUpdatedMessage();
        prefs.edit().putInt(Common.LAST_VERSION_NUMBER, BuildConfig.VERSION_CODE).apply();
    } else {
        if (isFirstPane() && allowRatingDialog()) {
            prefs.edit().putInt(Common.RATING_DIALOG_APP_OPENING_COUNTER, 0).putLong(Common.RATING_DIALOG_LAST_SHOWN, System.currentTimeMillis()).apply();
            @SuppressLint("InflateParams") View dialogView = LayoutInflater.from(getContext()).inflate(R.layout.dialog_like_app, null);
            if (prefs.getBoolean(Common.DONATED, false)) {
                TextView dialogText = dialogView.findViewById(R.id.dialog_like_app_text);
                dialogText.setText(R.string.dialog_like_app_text_pro);
            }
            @SuppressWarnings("ResourceType") final CheckBox checkBox = dialogView.findViewById(R.id.dialog_cb_never_again);
            DialogInterface.OnClickListener onClickListener = (dialogInterface, i) -> {
                if (checkBox.isChecked()) {
                    prefs.edit().putBoolean(Common.RATING_DIALOG_SHOW_NEVER, true).apply();
                }
                switch(i) {
                    case BUTTON_NEUTRAL:
                        try {
                            startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + BuildConfig.APPLICATION_ID)));
                        } catch (ActivityNotFoundException e) {
                            startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + BuildConfig.APPLICATION_ID)));
                        }
                        break;
                    case BUTTON_POSITIVE:
                        startActivity(new Intent(getActivity(), DonateActivity.class));
                        break;
                }
            };
            AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()).setTitle(R.string.dialog_like_app).setView(dialogView);
            if (!prefs.getBoolean(Common.DONATED, false))
                builder.setPositiveButton(R.string.dialog_button_donate, onClickListener);
            builder.setNeutralButton(R.string.dialog_button_rate, onClickListener).setNegativeButton(android.R.string.cancel, onClickListener).create().show();
        }
    }
    if (SDK_INT > Build.VERSION_CODES.O && ContextCompat.checkSelfPermission(getContext(), READ_EXTERNAL_STORAGE) != PERMISSION_GRANTED) {
        new AlertDialog.Builder(getActivity()).setMessage(R.string.dialog_need_storage_permission_oreo).setPositiveButton(android.R.string.ok, (dialog, which) -> ActivityCompat.requestPermissions(getActivity(), new String[] { READ_EXTERNAL_STORAGE }, 0)).setNegativeButton(android.R.string.cancel, null).show();
    }
}
Also used : Bundle(android.os.Bundle) PackageManager(android.content.pm.PackageManager) BuildConfig(de.Maxr1998.xposed.maxlock.BuildConfig) Uri(android.net.Uri) CustomTabsIntent(android.support.customtabs.CustomTabsIntent) LockPatternActivity(com.haibison.android.lockpattern.LockPatternActivity) ColorDrawable(android.graphics.drawable.ColorDrawable) PreferenceScreen(android.preference.PreferenceScreen) SDK_INT(android.os.Build.VERSION.SDK_INT) VisibleForTesting(android.support.annotation.VisibleForTesting) Util(de.Maxr1998.xposed.maxlock.util.Util) PreferenceFragmentCompat(android.support.v4.preference.PreferenceFragmentCompat) CheckBox(android.widget.CheckBox) MLImplementation(de.Maxr1998.xposed.maxlock.MLImplementation) WebViewClient(android.webkit.WebViewClient) View(android.view.View) BUTTON_NEUTRAL(android.content.DialogInterface.BUTTON_NEUTRAL) WebView(android.webkit.WebView) PERMISSION_GRANTED(android.content.pm.PackageManager.PERMISSION_GRANTED) Fragment(android.support.v4.app.Fragment) ContextCompat(android.support.v4.content.ContextCompat) FileProvider.getUriForFile(android.support.v4.content.FileProvider.getUriForFile) PorterDuff(android.graphics.PorterDuff) ActivityCompat(android.support.v4.app.ActivityCompat) AppCompatActivity(android.support.v7.app.AppCompatActivity) IOUtils(org.apache.commons.io.IOUtils) ListPreference(android.preference.ListPreference) TextView(android.widget.TextView) ActivityNotFoundException(android.content.ActivityNotFoundException) Snackbar(android.support.design.widget.Snackbar) SettingsActivity(de.Maxr1998.xposed.maxlock.ui.SettingsActivity) ZipOutputStream(java.util.zip.ZipOutputStream) Context(android.content.Context) PreferenceCategory(android.preference.PreferenceCategory) Intent(android.content.Intent) CheckBoxPreference(android.preference.CheckBoxPreference) StringRes(android.support.annotation.StringRes) NonNull(android.support.annotation.NonNull) XmlRes(android.support.annotation.XmlRes) BufferedOutputStream(java.io.BufferedOutputStream) FingerprintManagerCompat(android.support.v4.hardware.fingerprint.FingerprintManagerCompat) SuppressLint(android.annotation.SuppressLint) KUtil(de.Maxr1998.xposed.maxlock.util.KUtil) Charset(java.nio.charset.Charset) DevicePolicyManager(android.app.admin.DevicePolicyManager) READ_EXTERNAL_STORAGE(android.Manifest.permission.READ_EXTERNAL_STORAGE) Toast(android.widget.Toast) Build(android.os.Build) AppListFragment(de.Maxr1998.xposed.maxlock.ui.settings.applist.AppListFragment) DialogInterface(android.content.DialogInterface) BUTTON_POSITIVE(android.content.DialogInterface.BUTTON_POSITIVE) ImplementationPreference(de.Maxr1998.xposed.maxlock.preference.ImplementationPreference) MLPreferences(de.Maxr1998.xposed.maxlock.util.MLPreferences) ComponentName(android.content.ComponentName) LayoutInflater(android.view.LayoutInflater) FileOutputStream(java.io.FileOutputStream) FileUtils(org.apache.commons.io.FileUtils) IOException(java.io.IOException) Common(de.Maxr1998.xposed.maxlock.Common) File(java.io.File) R(de.Maxr1998.xposed.maxlock.R) Color(android.graphics.Color) TimeUnit(java.util.concurrent.TimeUnit) FragmentManager(android.support.v4.app.FragmentManager) AlertDialog(android.support.v7.app.AlertDialog) SharedPreferences(android.content.SharedPreferences) TwoStatePreference(android.preference.TwoStatePreference) Preference(android.preference.Preference) Activity(android.app.Activity) FragmentTransaction(android.support.v4.app.FragmentTransaction) InputStream(java.io.InputStream) AlertDialog(android.support.v7.app.AlertDialog) DialogInterface(android.content.DialogInterface) CustomTabsIntent(android.support.customtabs.CustomTabsIntent) Intent(android.content.Intent) View(android.view.View) WebView(android.webkit.WebView) TextView(android.widget.TextView) SuppressLint(android.annotation.SuppressLint) ActivityNotFoundException(android.content.ActivityNotFoundException) CheckBox(android.widget.CheckBox) SuppressLint(android.annotation.SuppressLint) TextView(android.widget.TextView)

Aggregations

READ_EXTERNAL_STORAGE (android.Manifest.permission.READ_EXTERNAL_STORAGE)1 SuppressLint (android.annotation.SuppressLint)1 Activity (android.app.Activity)1 DevicePolicyManager (android.app.admin.DevicePolicyManager)1 ActivityNotFoundException (android.content.ActivityNotFoundException)1 ComponentName (android.content.ComponentName)1 Context (android.content.Context)1 DialogInterface (android.content.DialogInterface)1 BUTTON_NEUTRAL (android.content.DialogInterface.BUTTON_NEUTRAL)1 BUTTON_POSITIVE (android.content.DialogInterface.BUTTON_POSITIVE)1 Intent (android.content.Intent)1 SharedPreferences (android.content.SharedPreferences)1 PackageManager (android.content.pm.PackageManager)1 PERMISSION_GRANTED (android.content.pm.PackageManager.PERMISSION_GRANTED)1 Color (android.graphics.Color)1 PorterDuff (android.graphics.PorterDuff)1 ColorDrawable (android.graphics.drawable.ColorDrawable)1 Uri (android.net.Uri)1 Build (android.os.Build)1 SDK_INT (android.os.Build.VERSION.SDK_INT)1