Example usage for android.support.v4.content PermissionChecker PERMISSION_GRANTED

List of usage examples for android.support.v4.content PermissionChecker PERMISSION_GRANTED

Introduction

In this page you can find the example usage for android.support.v4.content PermissionChecker PERMISSION_GRANTED.

Prototype

int PERMISSION_GRANTED

To view the source code for android.support.v4.content PermissionChecker PERMISSION_GRANTED.

Click Source Link

Document

Permission result: The permission is granted.

Usage

From source file:android.support.v7.app.TwilightManager.java

private Location getLastKnownLocation() {
    Location coarseLoc = null;//w  w w . ja va  2  s . com
    Location fineLoc = null;

    int permission = PermissionChecker.checkSelfPermission(mContext,
            Manifest.permission.ACCESS_COARSE_LOCATION);
    if (permission == PermissionChecker.PERMISSION_GRANTED) {
        coarseLoc = getLastKnownLocationForProvider(LocationManager.NETWORK_PROVIDER);
    }

    permission = PermissionChecker.checkSelfPermission(mContext, Manifest.permission.ACCESS_FINE_LOCATION);
    if (permission == PermissionChecker.PERMISSION_GRANTED) {
        fineLoc = getLastKnownLocationForProvider(LocationManager.GPS_PROVIDER);
    }

    if (fineLoc != null && coarseLoc != null) {
        // If we have both a fine and coarse location, use the latest
        return fineLoc.getTime() > coarseLoc.getTime() ? fineLoc : coarseLoc;
    } else {
        // Else, return the non-null one (if there is one)
        return fineLoc != null ? fineLoc : coarseLoc;
    }
}

From source file:com.tozny.e3db.android.KeyAuthentication.java

/**
 * Indicates if the device and SDK support the given type of key authentication.
 * @param ctx Application context./* w w  w  .j a  va  2  s  .  com*/
 * @param authentication Authentication type.
 * @return {@code true} if the authencation type is supported; {@code false} otherwise.
 */
@SuppressLint("MissingPermission")
public static boolean protectionTypeSupported(Context ctx, KeyAuthenticationType authentication) {
    switch (authentication) {
    case NONE:
    case PASSWORD:
        return true;
    case LOCK_SCREEN:
        return Build.VERSION.SDK_INT >= Build.VERSION_CODES.M;
    case FINGERPRINT:
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            // Some devices support fingerprint but the support library doesn't recognize it, so
            // we use the actual FingerprintManager here. (https://stackoverflow.com/a/45181416/169359)
            FingerprintManager mgr = ctx.getSystemService(FingerprintManager.class);
            if (mgr != null) {
                return PermissionChecker.checkSelfPermission(ctx,
                        Manifest.permission.USE_FINGERPRINT) == PermissionChecker.PERMISSION_GRANTED
                        && mgr.isHardwareDetected() && mgr.hasEnrolledFingerprints();
            }
        }
        return false;
    default:
        throw new IllegalStateException("Unhandled authentication type: " + authentication);
    }
}

From source file:com.ultramegasoft.flavordex2.util.PermissionUtils.java

/**
 * Check whether we have permission to access the device's location.
 *
 * @param context The Context// w w w . j  a  v  a2 s.  c o  m
 * @return Whether we have permission to access the device's location
 */
public static boolean hasLocationPerm(@NonNull Context context) {
    return PermissionChecker.checkSelfPermission(context,
            Manifest.permission.ACCESS_COARSE_LOCATION) == PermissionChecker.PERMISSION_GRANTED;
}

From source file:com.auth0.android.provider.PermissionHandler.java

/**
 * Called when there is a new response for a Android Manifest Permission request
 *
 * @param requestCode  received.//from   w w w . j a v a2 s .c  o m
 * @param permissions  the Android Manifest Permissions that were requested
 * @param grantResults the grant result for each permission
 * @return the list of Android Manifest Permissions that were declined by the user.
 */
public List<String> parseRequestResult(int requestCode, @NonNull String[] permissions,
        @NonNull int[] grantResults) {
    if (requestCode != this.lastRequestCode) {
        Log.d(TAG,
                String.format(
                        "The received Request Code doesn't match the expected one. Was %d but expected %d",
                        requestCode, this.lastRequestCode));
        return Arrays.asList(permissions);
    } else if (permissions.length == 0 && grantResults.length == 0) {
        Log.w(TAG, "All the required permissions were declined by the user.");
        return Arrays.asList(permissions);
    }

    List<String> declinedPermissions = new ArrayList<>();
    for (int i = 0; i < permissions.length; i++) {
        if (grantResults[i] != PermissionChecker.PERMISSION_GRANTED) {
            declinedPermissions.add(permissions[i]);
        }
    }
    if (!declinedPermissions.isEmpty()) {
        Log.w(TAG, String.format("%d permissions were explicitly declined by the user.",
                declinedPermissions.size()));
    }
    return declinedPermissions;
}

From source file:com.rks.musicx.misc.utils.permissionManager.java

public static boolean isSystemAlertGranted(@NonNull Context context) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        boolean result = PermissionChecker.checkCallingOrSelfPermission(context,
                Manifest.permission.SYSTEM_ALERT_WINDOW) == PermissionChecker.PERMISSION_GRANTED;
        if (result || Settings.canDrawOverlays(context)) {
            return true;
        } else {//  ww w  .j a va  2  s.co m
            return false;
        }
    } else {
        return true;
    }
}

From source file:com.alexcruz.papuhwalls.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    this.Preferences = new Preferences(getApplicationContext());

    super.onCreate(savedInstanceState);

    setContentView(R.layout.main_activity);
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

    context = this;
    CustomActivityOnCrash.install(this);

    prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
    if (prefs.getBoolean(Preferences.IS_FIRST__RUN, true)) {
        startActivity(new Intent(this, Slides.class));
        finish();//from  w w  w. j  a v  a 2 s .  c  o  m
    }

    if (Build.VERSION.SDK_INT >= 23 && PermissionChecker.checkSelfPermission(this,
            Manifest.permission.READ_EXTERNAL_STORAGE) != PermissionChecker.PERMISSION_GRANTED) {
        requestPermissions(new String[] { Manifest.permission.READ_EXTERNAL_STORAGE },
                REQUEST_READ_STORAGE_PERMISSION);
    } else {
        // Do absolutely NOTHING
    }

    final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    com.alexcruz.papuhwalls.Preferences.themeMe(this, toolbar);

    Home = getResources().getString(R.string.app_name);
    final String Home = getResources().getString(R.string.section_home);
    AllWalls = getResources().getString(R.string.section_all_walls);
    AndroidWalls = getResources().getString(R.string.section_android_walls);
    BwWalls = getResources().getString(R.string.section_bw_walls);
    BlurWalls = getResources().getString(R.string.section_blur_walls);
    CloudsWalls = getResources().getString(R.string.section_clouds_walls);
    MiscWalls = getResources().getString(R.string.section_misc_walls);
    MustachesWalls = getResources().getString(R.string.section_mustaches_walls);
    NexusWalls = getResources().getString(R.string.section_nexus_walls);
    OriginalWalls = getResources().getString(R.string.section_original_walls);
    PapuhWalls = getResources().getString(R.string.section_papuh_walls);
    SolidsWalls = getResources().getString(R.string.section_solids_walls);
    StarsWalls = getResources().getString(R.string.section_stars_walls);
    RomCategory = getResources().getString(R.string.section_rom_category);
    AicpWalls = getResources().getString(R.string.section_aicp_walls);
    BrokenOsWalls = getResources().getString(R.string.section_brokenos_walls);
    CandyWalls = getResources().getString(R.string.section_candy_walls);
    DuWalls = getResources().getString(R.string.section_du_walls);
    EosWalls = getResources().getString(R.string.section_eos_walls);
    LiquidsmoothWalls = getResources().getString(R.string.section_liquidsmooth_walls);
    OmniWalls = getResources().getString(R.string.section_omni_walls);
    OrionWalls = getResources().getString(R.string.section_orion_walls);
    PaWalls = getResources().getString(R.string.section_pa_walls);
    PacromWalls = getResources().getString(R.string.section_pacrom_walls);
    RrWalls = getResources().getString(R.string.section_rr_walls);
    SlimWalls = getResources().getString(R.string.section_slim_walls);
    TeslaWalls = getResources().getString(R.string.section_tesla_walls);
    TwistedAOSPWalls = getResources().getString(R.string.section_twistedaosp_walls);
    ValidusWalls = getResources().getString(R.string.section_validus_walls);
    Settings = getResources().getString(R.string.settings);
    LiveWallpaper = getResources().getString(R.string.live_wallpaper_description);
    MuzeiSettings = getResources().getString(R.string.muzei_settings);
    AboutApp = getResources().getString(R.string.section_aboutapp);

    currentItem = 1;

    final IProfile profile = new ProfileDrawerItem().withName("Alex Cruz aka Mazda")
            .withIcon(getResources().getDrawable(R.drawable.alexcruz)).withIdentifier(1);

    int header = Calendar.getInstance().get(Calendar.HOUR_OF_DAY);
    if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean(getString(R.string.time_context_headers),
            false)) {
        if (header < TIME_SUNRISE || header >= TIME_NIGHT) {
            if (PreferenceManager.getDefaultSharedPreferences(this)
                    .getBoolean(getString(R.string.poly_time_context_headers), false)) {
                header = R.drawable.poly_night;
            } else {
                header = R.drawable.night;
            }
        } else if (header >= TIME_SUNRISE && header < TIME_MORNING) {
            if (PreferenceManager.getDefaultSharedPreferences(this)
                    .getBoolean(getString(R.string.poly_time_context_headers), false)) {
                header = R.drawable.poly_sunrise;
            } else {
                header = R.drawable.sunrise;
            }
        } else if (header >= TIME_MORNING && header < TIME_NOON) {
            if (PreferenceManager.getDefaultSharedPreferences(this)
                    .getBoolean(getString(R.string.poly_time_context_headers), false)) {
                header = R.drawable.poly_morning;
            } else {
                header = R.drawable.morning;
            }
        } else if (header >= TIME_NOON && header < TIME_AFTERNOON) {
            if (PreferenceManager.getDefaultSharedPreferences(this)
                    .getBoolean(getString(R.string.poly_time_context_headers), false)) {
                header = R.drawable.poly_noon;
            } else {
                header = R.drawable.noon;
            }
        } else if (header >= TIME_AFTERNOON && header < TIME_SUNSET) {
            if (PreferenceManager.getDefaultSharedPreferences(this)
                    .getBoolean(getString(R.string.poly_time_context_headers), false)) {
                header = R.drawable.poly_afternoon;
            } else {
                header = R.drawable.afternoon;
            }
        } else if (header >= TIME_SUNSET && header < TIME_NIGHT) {
            if (PreferenceManager.getDefaultSharedPreferences(this)
                    .getBoolean(getString(R.string.poly_time_context_headers), false)) {
                header = R.drawable.poly_sunset;
            } else {
                header = R.drawable.sunset;
            }
        }
    } else {
        header = R.drawable.header;
    }

    String versionName;

    try {
        versionName = getPackageManager().getPackageInfo(getPackageName(), 0).versionName;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }

    headerResult = new AccountHeaderBuilder().withActivity(this).withHeaderBackground(header)
            .withSelectionFirstLine(getResources().getString(R.string.app_long_name))
            .withSelectionSecondLine("v" + versionName).withSelectionListEnabledForSingleProfile(false)
            .addProfiles(profile).withOnAccountHeaderListener(new AccountHeader.OnAccountHeaderListener() {
                @Override
                public boolean onProfileChanged(View view, IProfile profile, boolean current) {
                    if (profile instanceof IDrawerItem
                            && ((IDrawerItem) profile).getIdentifier() == PROFILE_SETTING) {
                        int count = 100 + headerResult.getProfiles().size() + 1;
                        if (headerResult.getProfiles() != null) {
                            Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
                            emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,
                                    new String[] { getResources().getString(R.string.email_address) });
                            emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,
                                    getResources().getText(R.string.artsource_name));
                            emailIntent.setType("plain/text");
                            startActivity(Intent.createChooser(emailIntent, "Contact Alex"));
                        } else {
                            headerResult.addProfiles(profile);
                        }
                    }
                    return false;
                }
            }).withSavedInstance(savedInstanceState).build();

    result = new DrawerBuilder().withActivity(this).withToolbar(toolbar).withAccountHeader(headerResult)
            .withHeader(R.layout.header).withSavedInstance(savedInstanceState).withScrollToTopAfterClick(true)
            .withFooterDivider(true).withSliderBackgroundColor(Preferences.Drawer())
            .withStatusBarColor(
                    Preferences.StatusBarTint() ? tint(Preferences.Theme(), 0.8) : Preferences.Theme())
            .addDrawerItems(
                    new PrimaryDrawerItem().withName(Home).withIcon(R.drawable.ic_home)
                            .withIconTintingEnabled(true).withSelectedIconColor(Preferences.SelectedIcon())
                            .withIconColor(Preferences.NormalIcon())
                            .withSelectedTextColor(tint(Preferences.SelectedDrawerText(), 1.0))
                            .withSelectedColor(tint(Preferences.DrawerSelector(), 1.0))
                            .withTextColor(Preferences.DrawerText()).withIdentifier(1),
                    new PrimaryDrawerItem().withName(AllWalls).withIcon(R.drawable.ic_allwalls)
                            .withIconTintingEnabled(true).withSelectedIconColor(Preferences.SelectedIcon())
                            .withIconColor(Preferences.NormalIcon())
                            .withSelectedTextColor(tint(Preferences.SelectedDrawerText(), 1.0))
                            .withSelectedColor(tint(Preferences.DrawerSelector(), 1.0))
                            .withTextColor(Preferences.DrawerText()).withIdentifier(2).withBadge("1630+")
                            .withBadgeStyle(new BadgeStyle().withTextColor(Preferences.BadgeText())
                                    .withColor(Preferences.BadgeBackground())),
                    new PrimaryDrawerItem().withName(AndroidWalls).withIcon(R.drawable.ic_android)
                            .withIconTintingEnabled(true).withSelectedIconColor(Preferences.SelectedIcon())
                            .withIconColor(Preferences.NormalIcon())
                            .withSelectedTextColor(tint(Preferences.SelectedDrawerText(), 1.0))
                            .withSelectedColor(tint(Preferences.DrawerSelector(), 1.0))
                            .withTextColor(Preferences.DrawerText()).withIdentifier(3).withBadge("17+")
                            .withBadgeStyle(new BadgeStyle().withTextColor(Preferences.BadgeText())
                                    .withColor(Preferences.BadgeBackground())),
                    new PrimaryDrawerItem().withName(BwWalls).withIcon(R.drawable.ic_bw)
                            .withIconTintingEnabled(true).withSelectedIconColor(Preferences.SelectedIcon())
                            .withIconColor(Preferences.NormalIcon())
                            .withSelectedTextColor(tint(Preferences.SelectedDrawerText(), 1.0))
                            .withSelectedColor(tint(Preferences.DrawerSelector(), 1.0))
                            .withTextColor(Preferences.DrawerText()).withIdentifier(4).withBadge("56+")
                            .withBadgeStyle(new BadgeStyle().withTextColor(Preferences.BadgeText())
                                    .withColor(Preferences.BadgeBackground())),
                    new PrimaryDrawerItem().withName(BlurWalls).withIcon(R.drawable.ic_blur)
                            .withIconTintingEnabled(true).withSelectedIconColor(Preferences.SelectedIcon())
                            .withIconColor(Preferences.NormalIcon())
                            .withSelectedTextColor(tint(Preferences.SelectedDrawerText(), 1.0))
                            .withSelectedColor(tint(Preferences.DrawerSelector(), 1.0))
                            .withTextColor(Preferences.DrawerText()).withIdentifier(5).withBadge("10+")
                            .withBadgeStyle(new BadgeStyle().withTextColor(Preferences.BadgeText())
                                    .withColor(Preferences.BadgeBackground())),
                    new PrimaryDrawerItem().withName(CloudsWalls).withIcon(R.drawable.ic_clouds)
                            .withIconTintingEnabled(true).withSelectedIconColor(Preferences.SelectedIcon())
                            .withIconColor(Preferences.NormalIcon())
                            .withSelectedTextColor(tint(Preferences.SelectedDrawerText(), 1.0))
                            .withSelectedColor(tint(Preferences.DrawerSelector(), 1.0))
                            .withTextColor(Preferences.DrawerText()).withIdentifier(6).withBadge("60+")
                            .withBadgeStyle(new BadgeStyle().withTextColor(Preferences.BadgeText())
                                    .withColor(Preferences.BadgeBackground())),
                    new PrimaryDrawerItem().withName(MiscWalls).withIcon(R.drawable.ic_misc)
                            .withIconTintingEnabled(true).withSelectedIconColor(Preferences.SelectedIcon())
                            .withIconColor(Preferences.NormalIcon())
                            .withSelectedTextColor(tint(Preferences.SelectedDrawerText(), 1.0))
                            .withSelectedColor(tint(Preferences.DrawerSelector(), 1.0))
                            .withTextColor(Preferences.DrawerText()).withIdentifier(7).withBadge("41+")
                            .withBadgeStyle(new BadgeStyle().withTextColor(Preferences.BadgeText())
                                    .withColor(Preferences.BadgeBackground())),
                    new PrimaryDrawerItem().withName(MustachesWalls).withIcon(R.drawable.ic_mustaches)
                            .withIconTintingEnabled(true).withSelectedIconColor(Preferences.SelectedIcon())
                            .withIconColor(Preferences.NormalIcon())
                            .withSelectedTextColor(tint(Preferences.SelectedDrawerText(), 1.0))
                            .withSelectedColor(tint(Preferences.DrawerSelector(), 1.0))
                            .withTextColor(Preferences.DrawerText()).withIdentifier(8).withBadge("10+")
                            .withBadgeStyle(new BadgeStyle().withTextColor(Preferences.BadgeText())
                                    .withColor(Preferences.BadgeBackground())),
                    new PrimaryDrawerItem().withName(NexusWalls).withIcon(R.drawable.ic_nexus)
                            .withIconTintingEnabled(true).withSelectedIconColor(Preferences.SelectedIcon())
                            .withIconColor(Preferences.NormalIcon())
                            .withSelectedTextColor(tint(Preferences.SelectedDrawerText(), 1.0))
                            .withSelectedColor(tint(Preferences.DrawerSelector(), 1.0))
                            .withTextColor(Preferences.DrawerText()).withIdentifier(9).withBadge("98+")
                            .withBadgeStyle(new BadgeStyle().withTextColor(Preferences.BadgeText())
                                    .withColor(Preferences.BadgeBackground())),
                    new PrimaryDrawerItem().withName(OriginalWalls).withIcon(R.drawable.ic_original)
                            .withIconTintingEnabled(true).withSelectedIconColor(Preferences.SelectedIcon())
                            .withIconColor(Preferences.NormalIcon())
                            .withSelectedTextColor(tint(Preferences.SelectedDrawerText(), 1.0))
                            .withSelectedColor(tint(Preferences.DrawerSelector(), 1.0))
                            .withTextColor(Preferences.DrawerText()).withIdentifier(10).withBadge("343+")
                            .withBadgeStyle(new BadgeStyle().withTextColor(Preferences.BadgeText())
                                    .withColor(Preferences.BadgeBackground())),
                    new PrimaryDrawerItem().withName(PapuhWalls).withIcon(R.drawable.ic_papuh)
                            .withIconTintingEnabled(true).withSelectedIconColor(Preferences.SelectedIcon())
                            .withIconColor(Preferences.NormalIcon())
                            .withSelectedTextColor(tint(Preferences.SelectedDrawerText(), 1.0))
                            .withSelectedColor(tint(Preferences.DrawerSelector(), 1.0))
                            .withTextColor(Preferences.DrawerText()).withIdentifier(11).withBadge("24+")
                            .withBadgeStyle(new BadgeStyle().withTextColor(Preferences.BadgeText())
                                    .withColor(Preferences.BadgeBackground())),
                    new PrimaryDrawerItem().withName(SolidsWalls).withIcon(R.drawable.ic_solids)
                            .withIconTintingEnabled(true).withSelectedIconColor(Preferences.SelectedIcon())
                            .withIconColor(Preferences.NormalIcon())
                            .withSelectedTextColor(tint(Preferences.SelectedDrawerText(), 1.0))
                            .withSelectedColor(tint(Preferences.DrawerSelector(), 1.0))
                            .withTextColor(Preferences.DrawerText()).withIdentifier(12).withBadge("72+")
                            .withBadgeStyle(new BadgeStyle().withTextColor(Preferences.BadgeText())
                                    .withColor(Preferences.BadgeBackground())),
                    new PrimaryDrawerItem().withName(StarsWalls).withIcon(R.drawable.ic_stars)
                            .withIconTintingEnabled(true).withSelectedIconColor(Preferences.SelectedIcon())
                            .withIconColor(Preferences.NormalIcon())
                            .withSelectedTextColor(tint(Preferences.SelectedDrawerText(), 1.0))
                            .withSelectedColor(tint(Preferences.DrawerSelector(), 1.0))
                            .withTextColor(Preferences.DrawerText()).withIdentifier(13).withBadge("11+")
                            .withBadgeStyle(new BadgeStyle().withTextColor(Preferences.BadgeText())
                                    .withColor(Preferences.BadgeBackground())),
                    new SectionDrawerItem().withName(RomCategory).withTypeface(Typeface.DEFAULT_BOLD)
                            .withTextColor(Preferences.DrawerText()),
                    new PrimaryDrawerItem().withName(AicpWalls).withIcon(R.drawable.ic_aicp)
                            .withIconTintingEnabled(true).withSelectedIconColor(Preferences.SelectedIcon())
                            .withIconColor(Preferences.NormalIcon())
                            .withSelectedTextColor(tint(Preferences.SelectedDrawerText(), 1.0))
                            .withSelectedColor(tint(Preferences.DrawerSelector(), 1.0))
                            .withTextColor(Preferences.DrawerText()).withIdentifier(15).withBadge("84+")
                            .withBadgeStyle(new BadgeStyle().withTextColor(Preferences.BadgeText())
                                    .withColor(Preferences.BadgeBackground())),
                    new PrimaryDrawerItem().withName(BrokenOsWalls).withIcon(R.drawable.ic_brokenos)
                            .withIconTintingEnabled(true).withSelectedIconColor(Preferences.SelectedIcon())
                            .withIconColor(Preferences.NormalIcon())
                            .withSelectedTextColor(tint(Preferences.SelectedDrawerText(), 1.0))
                            .withSelectedColor(tint(Preferences.DrawerSelector(), 1.0))
                            .withTextColor(Preferences.DrawerText()).withIdentifier(16).withBadge("53+")
                            .withBadgeStyle(new BadgeStyle().withTextColor(Preferences.BadgeText())
                                    .withColor(Preferences.BadgeBackground())),
                    new PrimaryDrawerItem().withName(CandyWalls).withIcon(R.drawable.ic_candy)
                            .withIconTintingEnabled(true).withSelectedIconColor(Preferences.SelectedIcon())
                            .withIconColor(Preferences.NormalIcon())
                            .withSelectedTextColor(tint(Preferences.SelectedDrawerText(), 1.0))
                            .withSelectedColor(tint(Preferences.DrawerSelector(), 1.0))
                            .withTextColor(Preferences.DrawerText()).withIdentifier(17).withBadge("80+")
                            .withBadgeStyle(new BadgeStyle().withTextColor(Preferences.BadgeText())
                                    .withColor(Preferences.BadgeBackground())),
                    new PrimaryDrawerItem().withName(DuWalls).withIcon(R.drawable.ic_dirtyunicorns)
                            .withIconTintingEnabled(true).withSelectedIconColor(Preferences.SelectedIcon())
                            .withIconColor(Preferences.NormalIcon())
                            .withSelectedTextColor(tint(Preferences.SelectedDrawerText(), 1.0))
                            .withSelectedColor(tint(Preferences.DrawerSelector(), 1.0))
                            .withTextColor(Preferences.DrawerText()).withIdentifier(18).withBadge("139+")
                            .withBadgeStyle(new BadgeStyle().withTextColor(Preferences.BadgeText())
                                    .withColor(Preferences.BadgeBackground())),
                    new PrimaryDrawerItem().withName(EosWalls).withIcon(R.drawable.ic_eos)
                            .withIconTintingEnabled(true).withSelectedIconColor(Preferences.SelectedIcon())
                            .withIconColor(Preferences.NormalIcon())
                            .withSelectedTextColor(tint(Preferences.SelectedDrawerText(), 1.0))
                            .withSelectedColor(tint(Preferences.DrawerSelector(), 1.0))
                            .withTextColor(Preferences.DrawerText()).withIdentifier(19).withBadge("48+")
                            .withBadgeStyle(new BadgeStyle().withTextColor(Preferences.BadgeText())
                                    .withColor(Preferences.BadgeBackground())),
                    new PrimaryDrawerItem().withName(LiquidsmoothWalls).withIcon(R.drawable.ic_liquidsmooth)
                            .withIconTintingEnabled(true).withSelectedIconColor(Preferences.SelectedIcon())
                            .withIconColor(Preferences.NormalIcon())
                            .withSelectedTextColor(tint(Preferences.SelectedDrawerText(), 1.0))
                            .withSelectedColor(tint(Preferences.DrawerSelector(), 1.0))
                            .withTextColor(Preferences.DrawerText()).withIdentifier(20).withBadge("65+")
                            .withBadgeStyle(new BadgeStyle().withTextColor(Preferences.BadgeText())
                                    .withColor(Preferences.BadgeBackground())),
                    new PrimaryDrawerItem().withName(OmniWalls).withIcon(R.drawable.ic_omni)
                            .withIconTintingEnabled(true).withSelectedIconColor(Preferences.SelectedIcon())
                            .withIconColor(Preferences.NormalIcon())
                            .withSelectedTextColor(tint(Preferences.SelectedDrawerText(), 1.0))
                            .withSelectedColor(tint(Preferences.DrawerSelector(), 1.0))
                            .withTextColor(Preferences.DrawerText()).withIdentifier(21).withBadge("29+")
                            .withBadgeStyle(new BadgeStyle().withTextColor(Preferences.BadgeText())
                                    .withColor(Preferences.BadgeBackground())),
                    new PrimaryDrawerItem().withName(OrionWalls).withIcon(R.drawable.ic_orion)
                            .withIconTintingEnabled(true).withSelectedIconColor(Preferences.SelectedIcon())
                            .withIconColor(Preferences.NormalIcon())
                            .withSelectedTextColor(tint(Preferences.SelectedDrawerText(), 1.0))
                            .withSelectedColor(tint(Preferences.DrawerSelector(), 1.0))
                            .withTextColor(Preferences.DrawerText()).withIdentifier(22).withBadge("10+")
                            .withBadgeStyle(new BadgeStyle().withTextColor(Preferences.BadgeText())
                                    .withColor(Preferences.BadgeBackground())),
                    new PrimaryDrawerItem().withName(PaWalls).withIcon(R.drawable.ic_pa)
                            .withIconTintingEnabled(true).withSelectedIconColor(Preferences.SelectedIcon())
                            .withIconColor(Preferences.NormalIcon())
                            .withSelectedTextColor(tint(Preferences.SelectedDrawerText(), 1.0))
                            .withSelectedColor(tint(Preferences.DrawerSelector(), 1.0))
                            .withTextColor(Preferences.DrawerText()).withIdentifier(23).withBadge("10+")
                            .withBadgeStyle(new BadgeStyle().withTextColor(Preferences.BadgeText())
                                    .withColor(Preferences.BadgeBackground())),
                    new PrimaryDrawerItem().withName(PacromWalls).withIcon(R.drawable.ic_pacrom)
                            .withIconTintingEnabled(true).withSelectedIconColor(Preferences.SelectedIcon())
                            .withIconColor(Preferences.NormalIcon())
                            .withSelectedTextColor(tint(Preferences.SelectedDrawerText(), 1.0))
                            .withSelectedColor(tint(Preferences.DrawerSelector(), 1.0))
                            .withTextColor(Preferences.DrawerText()).withIdentifier(24).withBadge("21+")
                            .withBadgeStyle(new BadgeStyle().withTextColor(Preferences.BadgeText())
                                    .withColor(Preferences.BadgeBackground())),
                    new PrimaryDrawerItem().withName(RrWalls).withIcon(R.drawable.ic_rr)
                            .withIconTintingEnabled(true).withSelectedIconColor(Preferences.SelectedIcon())
                            .withIconColor(Preferences.NormalIcon())
                            .withSelectedTextColor(tint(Preferences.SelectedDrawerText(), 1.0))
                            .withSelectedColor(tint(Preferences.DrawerSelector(), 1.0))
                            .withTextColor(Preferences.DrawerText()).withIdentifier(25).withBadge("54+")
                            .withBadgeStyle(new BadgeStyle().withTextColor(Preferences.BadgeText())
                                    .withColor(Preferences.BadgeBackground())),
                    new PrimaryDrawerItem().withName(SlimWalls).withIcon(R.drawable.ic_slim)
                            .withIconTintingEnabled(true).withSelectedIconColor(Preferences.SelectedIcon())
                            .withIconColor(Preferences.NormalIcon())
                            .withSelectedTextColor(tint(Preferences.SelectedDrawerText(), 1.0))
                            .withSelectedColor(tint(Preferences.DrawerSelector(), 1.0))
                            .withTextColor(Preferences.DrawerText()).withIdentifier(26).withBadge("8+")
                            .withBadgeStyle(new BadgeStyle().withTextColor(Preferences.BadgeText())
                                    .withColor(Preferences.BadgeBackground())),
                    new PrimaryDrawerItem().withName(TeslaWalls).withIcon(R.drawable.ic_tesla)
                            .withIconTintingEnabled(true).withSelectedIconColor(Preferences.SelectedIcon())
                            .withIconColor(Preferences.NormalIcon())
                            .withSelectedTextColor(tint(Preferences.SelectedDrawerText(), 1.0))
                            .withSelectedColor(tint(Preferences.DrawerSelector(), 1.0))
                            .withTextColor(Preferences.DrawerText()).withIdentifier(27).withBadge("43+")
                            .withBadgeStyle(new BadgeStyle().withTextColor(Preferences.BadgeText())
                                    .withColor(Preferences.BadgeBackground())),
                    new PrimaryDrawerItem().withName(TwistedAOSPWalls).withIcon(R.drawable.ic_twistedaosp)
                            .withIconTintingEnabled(true).withSelectedIconColor(Preferences.SelectedIcon())
                            .withIconColor(Preferences.NormalIcon())
                            .withSelectedTextColor(tint(Preferences.SelectedDrawerText(), 1.0))
                            .withSelectedColor(tint(Preferences.DrawerSelector(), 1.0))
                            .withTextColor(Preferences.DrawerText()).withIdentifier(28).withBadge("43+")
                            .withBadgeStyle(new BadgeStyle().withTextColor(Preferences.BadgeText())
                                    .withColor(Preferences.BadgeBackground())),
                    new PrimaryDrawerItem().withName(ValidusWalls).withIcon(R.drawable.ic_validus)
                            .withIconTintingEnabled(true).withSelectedIconColor(Preferences.SelectedIcon())
                            .withIconColor(Preferences.NormalIcon())
                            .withSelectedTextColor(tint(Preferences.SelectedDrawerText(), 1.0))
                            .withSelectedColor(tint(Preferences.DrawerSelector(), 1.0))
                            .withTextColor(Preferences.DrawerText()).withIdentifier(29).withBadge("258+")
                            .withBadgeStyle(new BadgeStyle().withTextColor(Preferences.BadgeText())
                                    .withColor(Preferences.BadgeBackground())),
                    new DividerDrawerItem(),
                    new SecondaryDrawerItem().withName(Settings).withIcon(R.drawable.ic_settings)
                            .withIconTintingEnabled(true).withSelectedIconColor(Preferences.SelectedIcon())
                            .withIconColor(Preferences.NormalIcon())
                            .withSelectedTextColor(tint(Preferences.SelectedDrawerText(), 1.0))
                            .withSelectedColor(tint(Preferences.DrawerSelector(), 1.0))
                            .withTextColor(Preferences.DrawerText()).withIdentifier(30),
                    new SecondaryDrawerItem().withName(LiveWallpaper)
                            .withIcon(R.drawable.ic_device_now_wallpaper).withIconTintingEnabled(true)
                            .withSelectedIconColor(Preferences.SelectedIcon())
                            .withIconColor(Preferences.NormalIcon())
                            .withSelectedTextColor(tint(Preferences.SelectedDrawerText(), 1.0))
                            .withSelectedColor(tint(Preferences.DrawerSelector(), 1.0))
                            .withTextColor(Preferences.DrawerText()).withIdentifier(33),
                    new SecondaryDrawerItem().withName(MuzeiSettings).withIcon(R.drawable.ic_muzei)
                            .withIconTintingEnabled(true).withSelectedIconColor(Preferences.SelectedIcon())
                            .withIconColor(Preferences.NormalIcon())
                            .withSelectedTextColor(tint(Preferences.SelectedDrawerText(), 1.0))
                            .withSelectedColor(tint(Preferences.DrawerSelector(), 1.0))
                            .withTextColor(Preferences.DrawerText()).withIdentifier(31),
                    new SecondaryDrawerItem().withName(AboutApp).withIcon(R.drawable.ic_about)
                            .withIconTintingEnabled(true).withSelectedIconColor(Preferences.SelectedIcon())
                            .withIconColor(Preferences.NormalIcon())
                            .withSelectedTextColor(tint(Preferences.SelectedDrawerText(), 1.0))
                            .withSelectedColor(tint(Preferences.DrawerSelector(), 1.0))
                            .withTextColor(Preferences.DrawerText()).withIdentifier(32))
            .withOnDrawerListener(new Drawer.OnDrawerListener() {
                @Override
                public void onDrawerOpened(View drawerView) {
                }

                @Override
                public void onDrawerClosed(View drawerView) {
                }

                @Override
                public void onDrawerSlide(View drawerView, float slideOffset) {

                }
            }).withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() {
                @Override
                public boolean onItemClick(View view, int position, IDrawerItem drawerItem) {

                    boolean isMuzeiInstalled = Preferences.isAppInstalled(context, "net.nurik.roman.muzei");
                    boolean isConnected = isConnected(MainActivity.this);

                    if (drawerItem != null) {
                        switch (drawerItem.getIdentifier()) {
                        case 1:
                            switchFragment(1, Home, "BaseActivity");
                            break;
                        case 2:
                            if (isConnected) {
                                switchWalls(2, AllWalls, "AllWalls");
                            } else {
                                showNotConnectedDialog();
                            }
                            break;
                        case 3:
                            if (isConnected) {
                                switchWalls(3, AndroidWalls, "AndroidWalls");
                            } else {
                                showNotConnectedDialog();
                            }
                            break;
                        case 4:
                            if (isConnected) {
                                switchWalls(4, BwWalls, "BwWalls");
                            } else {
                                showNotConnectedDialog();
                            }
                            break;
                        case 5:
                            if (isConnected) {
                                switchWalls(5, BlurWalls, "BlurWalls");
                            } else {
                                showNotConnectedDialog();
                            }
                            break;
                        case 6:
                            if (isConnected) {
                                switchWalls(6, BwWalls, "CloudsWalls");
                            } else {
                                showNotConnectedDialog();
                            }
                            break;
                        case 7:
                            if (isConnected) {
                                switchWalls(7, MiscWalls, "MiscWalls");
                            } else {
                                showNotConnectedDialog();
                            }
                            break;
                        case 8:
                            if (isConnected) {
                                switchWalls(8, MustachesWalls, "MustachesWalls");
                            } else {
                                showNotConnectedDialog();
                            }
                            break;
                        case 9:
                            if (isConnected) {
                                switchWalls(9, NexusWalls, "NexusWalls");
                            } else {
                                showNotConnectedDialog();
                            }
                            break;
                        case 10:
                            if (isConnected) {
                                switchWalls(10, OriginalWalls, "OriginalWalls");
                            } else {
                                showNotConnectedDialog();
                            }
                            break;
                        case 11:
                            if (isConnected) {
                                switchWalls(11, PapuhWalls, "PapuhWalls");
                            } else {
                                showNotConnectedDialog();
                            }
                            break;
                        case 12:
                            if (isConnected) {
                                switchWalls(12, SolidsWalls, "SolidsWalls");
                            } else {
                                showNotConnectedDialog();
                            }
                            break;
                        case 13:
                            if (isConnected) {
                                switchWalls(13, StarsWalls, "StarsWalls");
                            } else {
                                showNotConnectedDialog();
                            }
                            break;
                        case 14:
                            setTitle(R.string.section_rom_category);
                            ;
                            break;
                        case 15:
                            if (isConnected) {
                                switchWalls(15, AicpWalls, "AicpWalls");
                            } else {
                                showNotConnectedDialog();
                            }
                            break;
                        case 16:
                            if (isConnected) {
                                switchWalls(16, BrokenOsWalls, "BrokenOsWalls");
                            } else {
                                showNotConnectedDialog();
                            }
                            break;
                        case 17:
                            if (isConnected) {
                                switchWalls(17, CandyWalls, "CandyWalls");
                            } else {
                                showNotConnectedDialog();
                            }
                            break;
                        case 18:
                            if (isConnected) {
                                switchWalls(18, DuWalls, "DuWalls");
                            } else {
                                showNotConnectedDialog();
                            }
                            break;
                        case 19:
                            if (isConnected) {
                                switchWalls(19, EosWalls, "EosWalls");
                            } else {
                                showNotConnectedDialog();
                            }
                            break;
                        case 20:
                            if (isConnected) {
                                switchWalls(20, LiquidsmoothWalls, "LiquidsmoothWalls");
                            } else {
                                showNotConnectedDialog();
                            }
                            break;
                        case 21:
                            if (isConnected) {
                                switchWalls(21, OmniWalls, "OmniWalls");
                            } else {
                                showNotConnectedDialog();
                            }
                            break;
                        case 22:
                            if (isConnected) {
                                switchWalls(22, OrionWalls, "OrionWalls");
                            } else {
                                showNotConnectedDialog();
                            }
                            break;
                        case 23:
                            if (isConnected) {
                                switchWalls(23, PaWalls, "PaWalls");
                            } else {
                                showNotConnectedDialog();
                            }
                            break;
                        case 24:
                            if (isConnected) {
                                switchWalls(24, PacromWalls, "PacromWalls");
                            } else {
                                showNotConnectedDialog();
                            }
                            break;
                        case 25:
                            if (isConnected) {
                                switchWalls(25, RrWalls, "RrWalls");
                            } else {
                                showNotConnectedDialog();
                            }
                            break;
                        case 26:
                            if (isConnected) {
                                switchWalls(26, SlimWalls, "SlimWalls");
                            } else {
                                showNotConnectedDialog();
                            }
                            break;
                        case 27:
                            if (isConnected) {
                                switchWalls(27, TeslaWalls, "TeslaWalls");
                            } else {
                                showNotConnectedDialog();
                            }
                            break;
                        case 28:
                            if (isConnected) {
                                switchWalls(28, TwistedAOSPWalls, "TwistedAOSPWalls");
                            } else {
                                showNotConnectedDialog();
                            }
                            break;
                        case 29:
                            if (isConnected) {
                                switchWalls(29, ValidusWalls, "ValidusWalls");
                            } else {
                                showNotConnectedDialog();
                            }
                            break;
                        case 30:
                            Intent SettingsIntent = new Intent(MainActivity.this, SettingsActivity.class);
                            startActivityForResult(SettingsIntent, 0);
                            break;
                        case 31:
                            if (isMuzeiInstalled) {
                                Intent launchMuzeiIntent = new Intent(MainActivity.this, Settings.class);
                                startActivityForResult(launchMuzeiIntent, 0);
                            } else {
                                // Do absolutely NOTHING
                            }
                            break;
                        case 32:
                            switchFragment(32, AboutApp, "Credits");
                            break;
                        case 33:
                            Intent LWIntent = new Intent(MainActivity.this,
                                    com.alexcruz.papuhwalls.Live.Settings.class);
                            startActivityForResult(LWIntent, 0);
                            break;
                        }
                    }

                    return false;
                }
            }).withOnDrawerItemLongClickListener(new Drawer.OnDrawerItemLongClickListener() {
                @Override
                public boolean onItemLongClick(View view, int position, IDrawerItem drawerItem) {
                    if (drawerItem instanceof SecondaryDrawerItem) {
                    }
                    return false;
                }
            }).build();
    result.setSelection(1, true);
    boolean isMuzeiInstalled = Preferences.isAppInstalled(context, "net.nurik.roman.muzei");
    if (!isMuzeiInstalled) {
        result.removeItem(31);
    } else {
        // Do absolutely NOTHING
    }

    if (Preferences.getLiveWalls().size() == 0 & isConnected(this))
        new SetupLW(this).execute();
}

From source file:com.catchoom.craftarsdkexamples.LaunchersActivity.java

public void checkPermissionAndAskIfNotGranted(Runnable doWhenGranted) {
    this.doWhenGranted = doWhenGranted;
    if (PermissionChecker.checkSelfPermission(this,
            android.Manifest.permission.CAMERA) != PermissionChecker.PERMISSION_GRANTED) {

        // Should we show an explanation?
        if (ActivityCompat.shouldShowRequestPermissionRationale(this, android.Manifest.permission.CAMERA)) {
            showExplanation("Camera access",
                    "This app needs to use the camera to demostrate the SDK's capabilities",
                    android.Manifest.permission.CAMERA, CAMERA_PERMISSION);
        } else {/*from  w  w  w  .  j a  va 2 s .com*/
            requestPermission(android.Manifest.permission.CAMERA, CAMERA_PERMISSION);
        }
    } else {
        doWhenGranted.run();
    }
}

From source file:com.ultramegasoft.flavordex2.util.PermissionUtils.java

/**
 * Callback for permission requests. If external storage permissions are granted, this will
 * restart the application.//from   w  w w  .  j  ava 2 s  . c  om
 *
 * @param context      The Context
 * @param requestCode  The request code
 * @param permissions  Array of permissions requested
 * @param grantResults Array of results of the permission requests
 */
public static void onRequestPermissionsResult(@NonNull Context context, int requestCode,
        @NonNull String[] permissions, @NonNull int[] grantResults) {
    switch (requestCode) {
    case REQUEST_LOCATION:
        for (int i = 0; i < grantResults.length; i++) {
            if (!Manifest.permission.ACCESS_COARSE_LOCATION.equals(permissions[i])) {
                continue;
            }
            if (grantResults[i] == PermissionChecker.PERMISSION_GRANTED) {
                PreferenceManager.getDefaultSharedPreferences(context).edit()
                        .putBoolean(FlavordexApp.PREF_DETECT_LOCATION, true).apply();
            }
        }
        break;
    }
}

From source file:com.rks.musicx.misc.utils.permissionManager.java

public static boolean isAudioRecordGranted(@NonNull Context context) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        if (PermissionChecker.checkCallingOrSelfPermission(context,
                Manifest.permission.RECORD_AUDIO) == PermissionChecker.PERMISSION_GRANTED) {
            return true;
        } else {/*ww w  . jav  a  2s. co m*/
            return false;
        }
    } else {
        return true;
    }
}

From source file:com.xiaodu.permission.util2.ESPermission.java

private static boolean checkSelfPermission(Context context, int targetSdkVersion, String perm) {
    boolean hasPerm = true;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {

        if (targetSdkVersion >= Build.VERSION_CODES.M) {
            hasPerm = context.checkSelfPermission(perm) == PackageManager.PERMISSION_GRANTED;
        } else {//from w  w w . j  a  v  a 2s .c o m
            hasPerm = PermissionChecker.checkSelfPermission(context,
                    perm) == PermissionChecker.PERMISSION_GRANTED;
        }
    }

    return hasPerm;
}