List of usage examples for android.support.v4.content PermissionChecker checkSelfPermission
public static int checkSelfPermission(@NonNull Context context, @NonNull String permission)
From source file:com.ultramegasoft.flavordex2.util.PermissionUtils.java
/** * Check whether we have permission to access the device's location. * * @param context The Context/*from ww w.ja v a 2s .co 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.hellofyc.base.app.AppSupportDelegate.java
public final boolean checkSelfPermission(@NonNull String permission) { return PermissionChecker.checkSelfPermission(mActivity, permission) == PackageManager.PERMISSION_GRANTED; }
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();/* w ww .j a va 2 s .c om*/ } 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 ww . j a va 2 s . co m*/ requestPermission(android.Manifest.permission.CAMERA, CAMERA_PERMISSION); } } else { doWhenGranted.run(); } }
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 {// w ww. j a va2s .co m hasPerm = PermissionChecker.checkSelfPermission(context, perm) == PermissionChecker.PERMISSION_GRANTED; } } return hasPerm; }
From source file:de.j4velin.wifiAutoOff.Preferences.java
@SuppressWarnings("deprecation") @Override//from ww w .ja v a 2 s .c o m public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.preferences); if (BuildConfig.DEBUG && PermissionChecker.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PermissionChecker.PERMISSION_GRANTED) { requestPermissions(new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE }, 0); } status = (StatusPreference) findPreference("status"); status.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(final Preference preference) { WifiManager wm = (WifiManager) getSystemService(Context.WIFI_SERVICE); boolean connected = ((ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE)) .getNetworkInfo(ConnectivityManager.TYPE_WIFI).isConnected(); if (wm.isWifiEnabled() && !connected) { try { startActivity(new Intent(WifiManager.ACTION_PICK_WIFI_NETWORK) .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)); } catch (Exception e) { Toast.makeText(Preferences.this, R.string.settings_not_found_, Toast.LENGTH_SHORT).show(); } } else if (!wm.isWifiEnabled()) { wm.setWifiEnabled(true); } else { try { startActivity( new Intent(Settings.ACTION_WIFI_SETTINGS).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)); } catch (Exception e) { Toast.makeText(Preferences.this, R.string.settings_not_found_, Toast.LENGTH_SHORT).show(); } } return true; } }); final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); final CheckBoxPreference screen_off = (CheckBoxPreference) findPreference("off_screen_off"); screen_off.setSummary( getString(R.string.for_at_least, prefs.getInt("screen_off_timeout", Receiver.TIMEOUT_SCREEN_OFF))); if (!keepWiFiOn(this)) { screen_off.setChecked(false); } screen_off.setOnPreferenceChangeListener(new OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(final Preference preference, final Object newValue) { if ((Boolean) newValue) { if (!keepWiFiOn(Preferences.this)) { new AlertDialog.Builder(Preferences.this).setMessage(R.string.sleep_policy) .setPositiveButton(R.string.adv_wifi_settings, new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { try { startActivity(new Intent(Settings.ACTION_WIFI_IP_SETTINGS) .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)); } catch (Exception e) { Toast.makeText(Preferences.this, R.string.settings_not_found_, Toast.LENGTH_SHORT).show(); } } }).setNegativeButton(android.R.string.cancel, new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }).create().show(); return false; } if (android.os.Build.VERSION.SDK_INT >= 11) { APILevel11Wrapper.showNumberPicker(Preferences.this, prefs, screen_off, R.string.for_at_least, 1, 60, getString(R.string.minutes_before_turning_off_wifi_), "screen_off_timeout", Receiver.TIMEOUT_SCREEN_OFF, false); } else { showPre11NumberPicker(Preferences.this, prefs, screen_off, R.string.for_at_least, 1, 60, getString(R.string.minutes_before_turning_off_wifi_), "screen_off_timeout", Receiver.TIMEOUT_SCREEN_OFF, false); } } return true; } }); findPreference("off_no_network").setOnPreferenceChangeListener(new OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(final Preference preference, final Object newValue) { if ((Boolean) newValue) { if (android.os.Build.VERSION.SDK_INT >= 11) { APILevel11Wrapper.showNumberPicker(Preferences.this, prefs, preference, R.string.for_at_least, 1, 60, getString(R.string.minutes_before_turning_off_wifi_), "no_network_timeout", Receiver.TIMEOUT_NO_NETWORK, false); } else { showPre11NumberPicker(Preferences.this, prefs, preference, R.string.for_at_least, 1, 60, getString(R.string.minutes_before_turning_off_wifi_), "no_network_timeout", Receiver.TIMEOUT_NO_NETWORK, false); } } return true; } }); final CheckBoxPreference on_at = (CheckBoxPreference) findPreference("on_at"); on_at.setTitle(getString(R.string.at_summary, prefs.getString("on_at_time", Receiver.ON_AT_TIME))); on_at.setOnPreferenceChangeListener(new OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(final Preference preference, final Object newValue) { if ((Boolean) newValue) { String[] time = prefs.getString("on_at_time", Receiver.ON_AT_TIME).split(":"); final TimePickerDialog dialog = new TimePickerDialog(Preferences.this, new OnTimeSetListener() { @Override public void onTimeSet(TimePicker view, int hourOfDay, int minute) { prefs.edit().putString("on_at_time", hourOfDay + ":" + (minute < 10 ? "0" + minute : minute)).commit(); on_at.setTitle(getString(R.string.at_summary, hourOfDay + ":" + (minute < 10 ? "0" + minute : minute))); } }, Integer.parseInt(time[0]), Integer.parseInt(time[1]), true); dialog.setOnCancelListener(new OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { on_at.setChecked(false); } }); dialog.setTitle(getString(R.string.turn_wifi_on_at_)); dialog.show(); } return true; } }); final CheckBoxPreference off_at = (CheckBoxPreference) findPreference("off_at"); off_at.setTitle(getString(R.string.at_summary, prefs.getString("off_at_time", Receiver.OFF_AT_TIME))); off_at.setOnPreferenceChangeListener(new OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(final Preference preference, final Object newValue) { if ((Boolean) newValue) { String[] time = prefs.getString("off_at_time", Receiver.OFF_AT_TIME).split(":"); final TimePickerDialog dialog = new TimePickerDialog(Preferences.this, new OnTimeSetListener() { @Override public void onTimeSet(TimePicker view, int hourOfDay, int minute) { prefs.edit().putString("off_at_time", hourOfDay + ":" + (minute < 10 ? "0" + minute : minute)).commit(); off_at.setTitle(getString(R.string.at_summary, hourOfDay + ":" + (minute < 10 ? "0" + minute : minute))); } }, Integer.parseInt(time[0]), Integer.parseInt(time[1]), true); dialog.setOnCancelListener(new OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { off_at.setChecked(false); } }); dialog.setTitle(getString(R.string.turn_wifi_off_at_)); dialog.show(); } return true; } }); final Preference on_every = findPreference("on_every"); final String[] time_names = getResources().getStringArray(R.array.time_names); // default 2 hours on_every.setTitle(getString(R.string.every_summary, prefs.getString("on_every_str", time_names[4]))); on_every.setOnPreferenceChangeListener(new OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(final Preference preference, final Object newValue) { if ((Boolean) newValue) { AlertDialog.Builder builder = new AlertDialog.Builder(Preferences.this); builder.setTitle(R.string.turn_wifi_on_every).setItems(time_names, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { prefs.edit().putInt("on_every_time_min", time_values[which]) .putString("on_every_str", time_names[which]).commit(); on_every.setTitle(getString(R.string.every_summary, time_names[which])); } }); builder.create().show(); } return true; } }); Preference locations = findPreference("locations"); if (BuildConfig.FLAVOR.equals("play")) { if (getPackageManager().hasSystemFeature(PackageManager.FEATURE_LOCATION_NETWORK)) { locations.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(final Preference preference) { startActivity(new Intent(Preferences.this, Locations.class)); return true; } }); } else { locations.setEnabled(false); } } else { locations.setSummary("Not available in F-Droid version"); locations.setEnabled(false); } final Preference power = findPreference("power_connected"); power.setOnPreferenceChangeListener(new OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(final Preference preference, final Object newValue) { if ((boolean) newValue) { Intent battery = registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED)); if (battery != null && battery.getIntExtra(BatteryManager.EXTRA_PLUGGED, 0) > 0) { // already connected to external power prefs.edit().putBoolean("ignore_screen_off", true).commit(); } } else { prefs.edit().putBoolean("ignore_screen_off", false).commit(); } return true; } }); }
From source file:com.raspberry.library.util.AppUtils.java
/** * ????// ww w . j ava2 s . co m * * @param context * @param permission * @return */ public boolean selfPermissionGranted(Context context, String permission) { // Android 6.0 ?? boolean result = true; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (targetSdkVersion >= Build.VERSION_CODES.M) { // targetSdkVersion >= 23, Context#checkSelfPermission result = context.checkSelfPermission(permission) == PackageManager.PERMISSION_GRANTED; } else { // targetSdkVersion < 23, ? PermissionChecker result = PermissionChecker.checkSelfPermission(context, permission) == PermissionChecker.PERMISSION_GRANTED; } } return result; }
From source file:com.mgtv.qxx.ttsdemo.Camera2BasicFragment.java
/** * Opens the camera specified by {@link Camera2BasicFragment#mCameraId}. *///www . j av a 2s .com private void openCamera(int width, int height) { // if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M){ // if (ContextCompat.checkSelfPermission(getActivity(), Manifest.permission.CAMERA) // != PackageManager.PERMISSION_GRANTED) { // requestCameraPermission(); // return; // } // }else { // targetSdkVersion < Android M, we have to use PermissionChecker if (PermissionChecker.checkSelfPermission(getActivity(), Manifest.permission.CAMERA) != PermissionChecker.PERMISSION_GRANTED) { requestCameraPermission(); } // } setUpCameraOutputs(width, height); configureTransform(width, height); Activity activity = getActivity(); CameraManager manager = (CameraManager) activity.getSystemService(Context.CAMERA_SERVICE); try { if (!mCameraOpenCloseLock.tryAcquire(2500, TimeUnit.MILLISECONDS)) { throw new RuntimeException("Time out waiting to lock camera opening."); } manager.openCamera(mCameraId, mStateCallback, mBackgroundHandler); } catch (CameraAccessException e) { e.printStackTrace(); } catch (InterruptedException e) { throw new RuntimeException("Interrupted while trying to lock camera opening.", e); } }
From source file:com.tct.mail.ui.AbstractActivityController.java
@Override public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { if (requestCode == PermissionUtil.REQ_CODE_PERMISSION_SAVE_ATTACHMENT || requestCode == PermissionUtil.REQ_CODE_PERMISSION_REDOWNLOAD_ATTACHMENT || requestCode == PermissionUtil.REQ_CODE_PERMISSION_VIEW_ATTACHMENT) { //TS: zheng.zou 2016-1-22 EMAIL BUGFIX-1431088 MOD for (String permission : permissions) { if (PermissionChecker.checkSelfPermission(mContext, permission) != PackageManager.PERMISSION_GRANTED) { showNeedPermissionToast(R.string.permission_needed_to_save_attachment); }//from ww w.j av a2 s . c o m } } else if (requestCode == PermissionUtil.REQ_CODE_PERMISSION_SEE_CALENDAR) { for (String permission : permissions) { if (PermissionChecker.checkSelfPermission(mContext, permission) != PackageManager.PERMISSION_GRANTED) { showNeedPermissionToast(R.string.permission_needed_to_see_calendar); } } } }