Search in sources :

Example 1 with PERMISSION_GRANTED

use of android.content.pm.PackageManager.PERMISSION_GRANTED 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)

Example 2 with PERMISSION_GRANTED

use of android.content.pm.PackageManager.PERMISSION_GRANTED in project anitrend-app by AniTrend.

the class MainActivity method onNavigate.

private void onNavigate(@IdRes int menu) {
    Intent intent;
    switch(menu) {
        case R.id.nav_home_feed:
            mToolbar.setTitle(getString(R.string.drawer_title_home));
            selectedItem = menu;
            mViewPager.setAdapter(new FeedPageAdapter(getSupportFragmentManager(), getApplicationContext()));
            mNavigationTabStrip.setViewPager(mViewPager);
            break;
        case R.id.nav_anime:
            mToolbar.setTitle(getString(R.string.drawer_title_anime));
            selectedItem = menu;
            mViewPager.setAdapter(new SeasonPageAdapter(getSupportFragmentManager(), getApplicationContext()));
            mNavigationTabStrip.setViewPager(mViewPager);
            mViewPager.setCurrentItem(mPageIndex, false);
            break;
        case R.id.nav_manga:
            mToolbar.setTitle(getString(R.string.drawer_title_manga));
            selectedItem = menu;
            mViewPager.setAdapter(new MangaPageAdapter(getSupportFragmentManager(), getApplicationContext()));
            mNavigationTabStrip.setViewPager(mViewPager);
            break;
        case R.id.nav_trending:
            mToolbar.setTitle(getString(R.string.drawer_title_trending));
            selectedItem = menu;
            mViewPager.setAdapter(new TrendingPageAdapter(getSupportFragmentManager(), getApplicationContext()));
            mNavigationTabStrip.setViewPager(mViewPager);
            break;
        case R.id.nav_airing:
            mToolbar.setTitle(getString(R.string.drawer_title_airing));
            mViewPager.setAdapter(new AiringPageAdapter(getSupportFragmentManager(), getApplicationContext()));
            mNavigationTabStrip.setViewPager(mViewPager);
            selectedItem = menu;
            break;
        case R.id.nav_myanime:
            intent = new Intent(this, MediaListActivity.class);
            intent.putExtra(KeyUtil.arg_mediaType, KeyUtil.ANIME);
            intent.putExtra(KeyUtil.arg_userName, getPresenter().getDatabase().getCurrentUser().getName());
            intent.putExtra(KeyUtil.arg_id, getPresenter().getDatabase().getCurrentUser().getId());
            startActivity(intent);
            break;
        case R.id.nav_mymanga:
            intent = new Intent(this, MediaListActivity.class);
            intent.putExtra(KeyUtil.arg_mediaType, KeyUtil.MANGA);
            intent.putExtra(KeyUtil.arg_userName, getPresenter().getDatabase().getCurrentUser().getName());
            intent.putExtra(KeyUtil.arg_id, getPresenter().getDatabase().getCurrentUser().getId());
            startActivity(intent);
            break;
        case R.id.nav_hub:
            mToolbar.setTitle(getString(R.string.drawer_title_hub));
            mViewPager.setAdapter(new HubPageAdapter(getSupportFragmentManager(), getApplicationContext()));
            mNavigationTabStrip.setViewPager(mViewPager);
            selectedItem = menu;
            break;
        case R.id.nav_reviews:
            mToolbar.setTitle(getString(R.string.drawer_title_reviews));
            selectedItem = menu;
            mViewPager.setAdapter(new ReviewPageAdapter(getSupportFragmentManager(), getApplicationContext()));
            mNavigationTabStrip.setViewPager(mViewPager);
            break;
        case R.id.nav_sign_in:
            startActivity(new Intent(MainActivity.this, LoginActivity.class));
            break;
        case R.id.nav_sign_out:
            mBottomSheet = new BottomSheetMessage.Builder().setText(R.string.drawer_signout_text).setTitle(R.string.drawer_signout_title).setPositiveText(R.string.Yes).setNegativeText(R.string.No).buildWithCallback(new BottomSheetChoice() {

                @Override
                public void onPositiveButton() {
                    WebTokenRequest.invalidateInstance(getApplicationContext());
                    Intent intent = new Intent(MainActivity.this, SplashActivity.class);
                    finish();
                    startActivity(intent);
                }

                @Override
                public void onNegativeButton() {
                }
            });
            showBottomSheet();
            break;
        case R.id.nav_check_update:
            switch(ContextCompat.checkSelfPermission(getApplicationContext(), android.Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
                case PERMISSION_GRANTED:
                    mBottomSheet = new BottomSheetMessage.Builder().setText(R.string.drawer_update_text).setTitle(R.string.drawer_update_title).setPositiveText(R.string.Yes).setNegativeText(R.string.No).buildWithCallback(new BottomSheetChoice() {

                        @Override
                        public void onPositiveButton() {
                            Version version = getPresenter().getDatabase().getRemoteVersion();
                            if (version != null && version.isNewerVersion())
                                DownloaderService.downloadNewVersion(MainActivity.this, version);
                            else
                                NotifyUtil.createAlerter(MainActivity.this, getString(R.string.title_update_infodadat), getString(R.string.app_no_date), R.drawable.ic_cloud_done_white_24dp, R.color.colorStateGreen);
                        }

                        @Override
                        public void onNegativeButton() {
                        }
                    });
                    showBottomSheet();
                    break;
                case PERMISSION_DENIED:
                    if (ActivityCompat.shouldShowRequestPermissionRationale(MainActivity.this, Manifest.permission.WRITE_EXTERNAL_STORAGE))
                        DialogUtil.createMessage(MainActivity.this, R.string.title_permission_write, R.string.text_permission_write, (dialog, which) -> {
                            switch(which) {
                                case POSITIVE:
                                    ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE }, REQUEST_PERMISSION);
                                    break;
                                case NEGATIVE:
                                    NotifyUtil.makeText(MainActivity.this, R.string.canceled_by_user, Toast.LENGTH_SHORT).show();
                                    break;
                            }
                        });
                    else
                        hasPermission(android.Manifest.permission.WRITE_EXTERNAL_STORAGE);
                    break;
            }
            break;
        case R.id.nav_light_theme:
            getPresenter().getApplicationPref().toggleTheme();
            recreate();
            break;
        default:
            break;
    }
}
Also used : NavigationView(android.support.design.widget.NavigationView) ProfileActivity(com.mxt.anitrend.view.activity.detail.ProfileActivity) Bundle(android.os.Bundle) FeedPageAdapter(com.mxt.anitrend.adapter.pager.index.FeedPageAdapter) Uri(android.net.Uri) SeasonPageAdapter(com.mxt.anitrend.adapter.pager.index.SeasonPageAdapter) BasePresenter(com.mxt.anitrend.presenter.base.BasePresenter) BindView(butterknife.BindView) Manifest(android.Manifest) BottomSheetChoice(com.mxt.anitrend.base.interfaces.event.BottomSheetChoice) User(com.mxt.anitrend.model.entity.anilist.User) NotifyUtil(com.mxt.anitrend.util.NotifyUtil) R(com.mxt.anitrend.R) View(android.view.View) BaseConsumer(com.mxt.anitrend.base.custom.consumer.BaseConsumer) CompatUtil(com.mxt.anitrend.util.CompatUtil) PERMISSION_GRANTED(android.content.pm.PackageManager.PERMISSION_GRANTED) ContextCompat(android.support.v4.content.ContextCompat) NotificationActivity(com.mxt.anitrend.view.activity.detail.NotificationActivity) ThreadMode(org.greenrobot.eventbus.ThreadMode) ActivityCompat(android.support.v4.app.ActivityCompat) Version(com.mxt.anitrend.model.entity.base.Version) DialogUtil(com.mxt.anitrend.util.DialogUtil) TextView(android.widget.TextView) Nullable(android.support.annotation.Nullable) KeyUtil(com.mxt.anitrend.util.KeyUtil) CoordinatorLayout(android.support.design.widget.CoordinatorLayout) DateUtil(com.mxt.anitrend.util.DateUtil) ButterKnife(butterknife.ButterKnife) ViewPager(android.support.v4.view.ViewPager) Intent(android.content.Intent) StringRes(android.support.annotation.StringRes) NonNull(android.support.annotation.NonNull) MenuItem(android.view.MenuItem) GravityCompat(android.support.v4.view.GravityCompat) HeaderImageView(com.mxt.anitrend.base.custom.view.image.HeaderImageView) HubPageAdapter(com.mxt.anitrend.adapter.pager.index.HubPageAdapter) Toast(android.widget.Toast) EventBus(org.greenrobot.eventbus.EventBus) Menu(android.view.Menu) ReviewPageAdapter(com.mxt.anitrend.adapter.pager.index.ReviewPageAdapter) AboutActivity(com.mxt.anitrend.view.activity.base.AboutActivity) DrawerLayout(android.support.v4.widget.DrawerLayout) WebTokenRequest(com.mxt.anitrend.base.custom.async.WebTokenRequest) MediaListActivity(com.mxt.anitrend.view.activity.detail.MediaListActivity) PERMISSION_DENIED(android.content.pm.PackageManager.PERMISSION_DENIED) SettingsActivity(com.mxt.anitrend.view.activity.base.SettingsActivity) ActivityBase(com.mxt.anitrend.base.custom.activity.ActivityBase) DownloaderService(com.mxt.anitrend.service.DownloaderService) IdRes(android.support.annotation.IdRes) MangaPageAdapter(com.mxt.anitrend.adapter.pager.index.MangaPageAdapter) TrendingPageAdapter(com.mxt.anitrend.adapter.pager.index.TrendingPageAdapter) Subscribe(org.greenrobot.eventbus.Subscribe) AvatarIndicatorView(com.mxt.anitrend.base.custom.view.image.AvatarIndicatorView) Toolbar(android.support.v7.widget.Toolbar) UserBase(com.mxt.anitrend.model.entity.base.UserBase) Crashlytics(com.crashlytics.android.Crashlytics) AiringPageAdapter(com.mxt.anitrend.adapter.pager.index.AiringPageAdapter) SmartTabLayout(com.ogaclejapan.smarttablayout.SmartTabLayout) ActionBarDrawerToggle(android.support.v7.app.ActionBarDrawerToggle) BottomSheetMessage(com.mxt.anitrend.view.sheet.BottomSheetMessage) FeedPageAdapter(com.mxt.anitrend.adapter.pager.index.FeedPageAdapter) SeasonPageAdapter(com.mxt.anitrend.adapter.pager.index.SeasonPageAdapter) BottomSheetChoice(com.mxt.anitrend.base.interfaces.event.BottomSheetChoice) Intent(android.content.Intent) MangaPageAdapter(com.mxt.anitrend.adapter.pager.index.MangaPageAdapter) ReviewPageAdapter(com.mxt.anitrend.adapter.pager.index.ReviewPageAdapter) TrendingPageAdapter(com.mxt.anitrend.adapter.pager.index.TrendingPageAdapter) AiringPageAdapter(com.mxt.anitrend.adapter.pager.index.AiringPageAdapter) Version(com.mxt.anitrend.model.entity.base.Version) MediaListActivity(com.mxt.anitrend.view.activity.detail.MediaListActivity) HubPageAdapter(com.mxt.anitrend.adapter.pager.index.HubPageAdapter)

Aggregations

Intent (android.content.Intent)2 PERMISSION_GRANTED (android.content.pm.PackageManager.PERMISSION_GRANTED)2 Uri (android.net.Uri)2 Bundle (android.os.Bundle)2 NonNull (android.support.annotation.NonNull)2 StringRes (android.support.annotation.StringRes)2 ActivityCompat (android.support.v4.app.ActivityCompat)2 ContextCompat (android.support.v4.content.ContextCompat)2 Manifest (android.Manifest)1 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 SharedPreferences (android.content.SharedPreferences)1