androidx.core.content.ContextCompat Java Examples
The following examples show how to use
androidx.core.content.ContextCompat.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: NotiHelper.java From hipda with GNU General Public License v2.0 | 6 votes |
public static void initNotificationChannel() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { Context context = HiApplication.getAppContext(); NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); if (notificationManager.getNotificationChannel(CHANNEL_ID) == null) { int color = ContextCompat.getColor(context, R.color.icon_blue); NotificationChannel notificationChannel = new NotificationChannel(CHANNEL_ID, CHANNEL_NAME, NotificationManager.IMPORTANCE_HIGH); notificationChannel.enableLights(true); notificationChannel.setLightColor(color); notificationChannel.enableVibration(false); notificationChannel.setBypassDnd(false); notificationManager.createNotificationChannel(notificationChannel); } } }
Example #2
Source File: MainActivity.java From wear-os-samples with Apache License 2.0 | 6 votes |
/** Restores the UI to active (non-ambient) mode. */ @Override public void onExitAmbient() { super.onExitAmbient(); Log.d(TAG, "onExitAmbient()"); // Changes views to color. Context context = getApplicationContext(); Resources resources = context.getResources(); mOuterCircle.setBackgroundColor( ContextCompat.getColor(context, R.color.background_color)); mInnerCircle.setBackground( ContextCompat.getDrawable(context, R.drawable.color_circle)); mProgressBar.setProgressTintList( resources.getColorStateList(R.color.progressbar_tint, context.getTheme())); mProgressBar.setProgressBackgroundTintList( resources.getColorStateList( R.color.progressbar_background_tint, context.getTheme())); }
Example #3
Source File: SplashActivity.java From shinny-futures-android with GNU General Public License v3.0 | 6 votes |
private void changeStatusBarColor(boolean isFirm) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT && Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { Window w = getWindow(); w.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS, WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); int statusBarHeight = getStatusBarHeight(BaseApplication.getContext()); View view = new View(this); view.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); view.getLayoutParams().height = statusBarHeight; ((ViewGroup) w.getDecorView()).addView(view); if (isFirm) view.setBackground(getResources().getDrawable(R.color.colorPrimaryDark)); else view.setBackground(getResources().getDrawable(R.color.login_simulation_hint)); } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { Window window = getWindow(); window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); if (isFirm) window.setStatusBarColor(ContextCompat.getColor(this, R.color.colorPrimaryDark)); else window.setStatusBarColor(ContextCompat.getColor(this, R.color.login_simulation_hint)); } }
Example #4
Source File: ChoiceBookActivity.java From HaoReader with GNU General Public License v3.0 | 6 votes |
@Override public View getView(int position, View convertView, ViewGroup parent) { if (convertView == null) { convertView = View.inflate(context, R.layout.item_choice_book_category, null); } TextView tvText = convertView.findViewById(R.id.tv_text); tvText.setText(getItem(position).getKindName()); GradientDrawable drawable = (GradientDrawable) tvText.getBackground(); if (lastPosition == position) { int selectedColor = ContextCompat.getColor(context, R.color.colorAccent); tvText.setTextColor(selectedColor); drawable.setStroke(DensityUtil.dp2px(context, 2), selectedColor); } else { int normalColor = ContextCompat.getColor(context, R.color.colorBarText); tvText.setTextColor(normalColor); drawable.setStroke(DensityUtil.dp2px(context, 2), normalColor); } return convertView; }
Example #5
Source File: UiSettingsDemoActivity.java From android-samples with Apache License 2.0 | 6 votes |
public void setMyLocationButtonEnabled(View v) { if (!checkReady()) { return; } // Enables/disables the my location button (this DOES NOT enable/disable the my location // dot/chevron on the map). The my location button will never appear if the my location // layer is not enabled. // First verify that the location permission has been granted. if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) { mUiSettings.setMyLocationButtonEnabled(mMyLocationButtonCheckbox.isChecked()); } else { // Uncheck the box and request missing location permission. mMyLocationButtonCheckbox.setChecked(false); requestLocationPermission(MY_LOCATION_PERMISSION_REQUEST_CODE); } }
Example #6
Source File: AirQuality.java From GeometricWeather with GNU Lesser General Public License v3.0 | 6 votes |
@ColorInt public int getCOColor(Context context) { if (co == null) { return Color.TRANSPARENT; } else if (co <= 5) { return ContextCompat.getColor(context, R.color.colorLevel_1); } else if (co <= 10) { return ContextCompat.getColor(context, R.color.colorLevel_2); } else if (co <= 35) { return ContextCompat.getColor(context, R.color.colorLevel_3); } else if (co <= 60) { return ContextCompat.getColor(context, R.color.colorLevel_4); } else if (co <= 90) { return ContextCompat.getColor(context, R.color.colorLevel_5); } else { return ContextCompat.getColor(context, R.color.colorLevel_6); } }
Example #7
Source File: PreferenceFragment.java From AndroidPreferenceActivity with Apache License 2.0 | 6 votes |
/** * Obtains the background of the button bar from the activity's current theme. */ private void obtainButtonBarBackground() { try { int color = ThemeUtil.getColor(getActivity(), R.attr.restoreDefaultsButtonBarBackground); setButtonBarBackgroundColor(color); } catch (NotFoundException e) { int resourceId = ThemeUtil .getResId(getActivity(), R.attr.restoreDefaultsButtonBarBackground, -1); if (resourceId != -1) { setButtonBarBackground(resourceId); } else { setButtonBarBackgroundColor( ContextCompat.getColor(getActivity(), R.color.button_bar_background_light)); } } }
Example #8
Source File: SkinManager.java From NewFastFrame with Apache License 2.0 | 6 votes |
public ColorStateList getColorStateList(int resId) { if (isLocal) { CommonLogger.e("放回本地"); return ContextCompat.getColorStateList(context, resId); } int id = resources.getIdentifier(context.getResources().getResourceEntryName(resId), "color", packageName); if (id == 0) { // 如果找不到资源,返回本地资源 return ContextCompat.getColorStateList(context, resId); } else { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { return resources.getColorStateList(id, null); } else { return resources.getColorStateList(id); } } }
Example #9
Source File: LiveDataRowsActivity.java From tv-samples with Apache License 2.0 | 6 votes |
@Override public void onCreate(Bundle savedInstanceState) { AndroidInjection.inject(this); super.onCreate(savedInstanceState); setContentView(R.layout.activity_livedata_rows); if (ContextCompat.checkSelfPermission(LiveDataRowsActivity.this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { // If the permission is not authorized in the first time. A new permission access // request will be created. if (ActivityCompat.shouldShowRequestPermissionRationale(LiveDataRowsActivity.this, Manifest.permission.WRITE_EXTERNAL_STORAGE)) { ActivityCompat.requestPermissions(LiveDataRowsActivity.this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, WRITE_PERMISSION); } else { ActivityCompat.requestPermissions(LiveDataRowsActivity.this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, WRITE_PERMISSION); } } }
Example #10
Source File: TintHelper.java From MyBookshelf with GNU General Public License v3.0 | 6 votes |
public static void setTint(@NonNull RadioButton radioButton, @ColorInt int color, boolean useDarker) { ColorStateList sl = new ColorStateList(new int[][]{ new int[]{-android.R.attr.state_enabled}, new int[]{android.R.attr.state_enabled, -android.R.attr.state_checked}, new int[]{android.R.attr.state_enabled, android.R.attr.state_checked} }, new int[]{ // Radio button includes own alpha for disabled state ColorUtil.stripAlpha(ContextCompat.getColor(radioButton.getContext(), useDarker ? R.color.ate_control_disabled_dark : R.color.ate_control_disabled_light)), ContextCompat.getColor(radioButton.getContext(), useDarker ? R.color.ate_control_normal_dark : R.color.ate_control_normal_light), color }); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { radioButton.setButtonTintList(sl); } else { Drawable d = createTintedDrawable(ContextCompat.getDrawable(radioButton.getContext(), R.drawable.abc_btn_radio_material), sl); radioButton.setButtonDrawable(d); } }
Example #11
Source File: CurrentPlaceTestActivity.java From android-places-demos with Apache License 2.0 | 6 votes |
/** * Fetches a list of {@link PlaceLikelihood} instances that represent the Places the user is * most * likely to be at currently. */ private void findCurrentPlace() { if (ContextCompat.checkSelfPermission(this, permission.ACCESS_WIFI_STATE) != PackageManager.PERMISSION_GRANTED || ContextCompat.checkSelfPermission(this, permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) { Toast.makeText( this, "Both ACCESS_WIFI_STATE & ACCESS_FINE_LOCATION permissions are required", Toast.LENGTH_SHORT) .show(); } // Note that it is not possible to request a normal (non-dangerous) permission from // ActivityCompat.requestPermissions(), which is why the checkPermission() only checks if // ACCESS_FINE_LOCATION is granted. It is still possible to check whether a normal permission // is granted or not using ContextCompat.checkSelfPermission(). if (checkPermission(ACCESS_FINE_LOCATION)) { findCurrentPlaceWithPermissions(); } }
Example #12
Source File: RainImplementor.java From GeometricWeather with GNU Lesser General Public License v3.0 | 6 votes |
@ColorInt public static int getThemeColor(Context context, @TypeRule int type) { switch (type) { case TYPE_RAIN_DAY: return Color.rgb(64, 151, 231); case TYPE_RAIN_NIGHT: return Color.rgb(38, 78, 143); case TYPE_SLEET_DAY: return Color.rgb(104, 186, 255); case TYPE_SLEET_NIGHT: return Color.rgb(26, 91, 146); case TYPE_THUNDERSTORM: return Color.rgb(43, 29, 69); } return ContextCompat.getColor(context, R.color.colorPrimary); }
Example #13
Source File: ObservationEditActivity.java From mage-android with Apache License 2.0 | 5 votes |
public void onCameraClick(View v) { if (ContextCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED || ContextCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { ActivityCompat.requestPermissions(ObservationEditActivity.this, new String[]{Manifest.permission.CAMERA, Manifest.permission.WRITE_EXTERNAL_STORAGE}, PERMISSIONS_REQUEST_CAMERA); } else { launchCameraIntent(); } }
Example #14
Source File: IntroActivity.java From material-intro with MIT License | 5 votes |
private void updateTaskDescription() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { String title = getTitle().toString(); Drawable iconDrawable = getApplicationInfo().loadIcon(getPackageManager()); Bitmap icon = iconDrawable instanceof BitmapDrawable ? ((BitmapDrawable) iconDrawable).getBitmap() : null; int colorPrimary; if (position < getCount()) { try { colorPrimary = ContextCompat.getColor(IntroActivity.this, getBackgroundDark(position)); } catch (Resources.NotFoundException e) { colorPrimary = ContextCompat.getColor(IntroActivity.this, getBackground(position)); } } else { TypedValue typedValue = new TypedValue(); TypedArray a = obtainStyledAttributes(typedValue.data, new int[]{R.attr.colorPrimary}); colorPrimary = a.getColor(0, 0); a.recycle(); } colorPrimary = ColorUtils.setAlphaComponent(colorPrimary, 0xFF); setTaskDescription(new ActivityManager.TaskDescription(title, icon, colorPrimary)); } }
Example #15
Source File: ReactionsPopup.java From aptoide-client-v8 with GNU General Public License v3.0 | 5 votes |
/** * Constructor to create a new reactions popup with an anchor view. * * @param context Context the reactions popup is running in, through which it * can access the current theme, resources, etc. * @param anchor Anchor view for this popup. The popup will appear on top of */ public ReactionsPopup(@NonNull Context context, @NonNull View anchor) { this.anchorView = anchor; popup = new PopupWindow(); popup.setWindowLayoutMode(WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.WRAP_CONTENT); reactionsView = new ReactionsView(context); reactionsView.setVisibility(View.VISIBLE); popup.setContentView(reactionsView); popup.setFocusable(true); popup.setClippingEnabled(true); popup.setBackgroundDrawable( ContextCompat.getDrawable(context, R.drawable.rounded_corners_reactions)); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { popup.setElevation(10); } reactionsView.setCallback(reactionType -> { if (reactionClickListener != null) { reactionClickListener.onReactionItemClick(reactionType); } }); popup.setOnDismissListener(() -> { if (onDismissListener != null) { onDismissListener.onDismiss(reactionsView); } }); }
Example #16
Source File: WhatIfOverviewFragment.java From Easy_xkcd with Apache License 2.0 | 5 votes |
@Override public void onBindViewHolder(final ComicViewHolder comicViewHolder, int i) { comicViewHolder.articleTitle.setText(titles.get(i)); String title = titles.get(i); int n = WhatIfFragment.mTitles.size() - WhatIfFragment.mTitles.indexOf(title); comicViewHolder.articleNumber.setText(String.valueOf(n)); int id = databaseManager.getWhatIfMissingThumbnailId(title); if (id != 0) { comicViewHolder.thumbnail.setImageDrawable(ContextCompat.getDrawable(context, id)); return; } if (prefHelper.fullOfflineWhatIf()) { File offlinePath = prefHelper.getOfflinePath(); File dir = new File(offlinePath.getAbsolutePath() + OFFLINE_WHATIF_OVERVIEW_PATH); File file = new File(dir, String.valueOf(n) + ".png"); GlideApp.with(context) .load(file) .apply(new RequestOptions().placeholder(getCircularProgress())) .into(comicViewHolder.thumbnail); } else { GlideApp.with(context) .load(imgs.get(i)) .apply(new RequestOptions().placeholder(getCircularProgress())) .into(comicViewHolder.thumbnail); } }
Example #17
Source File: AbstractPreferenceFragment.java From AndroidPreferenceActivity with Apache License 2.0 | 5 votes |
/** * Obtains the appearance of the dividers, which are shown above preference categories, from the * activity's theme. */ private void obtainDividerDecoration() { int dividerColor; try { dividerColor = ThemeUtil.getColor(getActivity(), R.attr.dividerColor); } catch (NotFoundException e) { dividerColor = ContextCompat.getColor(getActivity(), R.color.preference_divider_color_light); } this.dividerDecoration.setDividerColor(dividerColor); this.dividerDecoration.setDividerHeight(DisplayUtil.dpToPixels(getActivity(), 1)); }
Example #18
Source File: MainMenuActivity.java From EFRConnect-android with Apache License 2.0 | 5 votes |
private void showEnableBluetoothAdapterBar() { bluetoothEnableMsg.setText(R.string.bluetooth_adapter_bar_disabled); bluetoothEnableBar.setBackgroundColor(ContextCompat.getColor(MainMenuActivity.this, R.color.silabs_red_dark)); bluetoothEnableBtn.setVisibility(VISIBLE); bluetoothEnableBar.setVisibility(VISIBLE); Toast.makeText(MainMenuActivity.this, R.string.toast_bluetooth_not_enabled, Toast.LENGTH_SHORT).show(); }
Example #19
Source File: KeyFobsRecyclerViewAdapter.java From EFRConnect-android with Apache License 2.0 | 5 votes |
private void setAsFobEntryItem(boolean isBlueGecko, BluetoothDeviceInfo btInfo) { isHeader = false; this.isBlueGecko = isBlueGecko; int devContainerColor = isBlueGecko ? Color.WHITE : ContextCompat.getColor(context, R.color.other_fobs_header_background); deviceContainer.setBackgroundColor(devContainerColor); container.setBackgroundColor(devContainerColor); deviceContainer.setVisibility(View.VISIBLE); headerContainer.setVisibility(View.GONE); ScanResultCompat scanInfo = btInfo.scanInfo; String name = scanInfo.getDevice().getName(); name = TextUtils.isEmpty(name) ? "" + scanInfo.getDevice().getAddress() : name; SignalStrength strength = SignalStrength.calculateSignalStrengthUsingRssi(scanInfo.getRssi()); String stringLabelFromStrength = SignalStrength.getStringLabelFromStrength(context, strength); deviceName.setText(name); signalStrengthIcon.setSignalStrength(strength); signalStrengthText.setText(stringLabelFromStrength); findButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { findKeyFobSelectedCallback.findKeyFob(CustomViewHolder.this.btInfo); } }); itemDividerBelow.setVisibility(View.VISIBLE); }
Example #20
Source File: StreamActivity.java From Pocket-Plays-for-Twitch with GNU General Public License v3.0 | 5 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(getLayoutRessource()); setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED); if (Build.VERSION.SDK_INT >= 21) { getWindow().setNavigationBarColor(ContextCompat.getColor(this, R.color.black)); getWindow().setStatusBarColor(ContextCompat.getColor(this, R.color.black)); } if(savedInstanceState == null) { FragmentManager fm = getSupportFragmentManager(); // If the Fragment is non-null, then it is currently being // retained across a configuration change. if (mStreamFragment == null) { mStreamFragment = StreamFragment.newInstance(getStreamArguments()); fm.beginTransaction().replace(getVideoContainerRessource(), mStreamFragment, getString(R.string.stream_fragment_tag)).commit(); } } try { SensorManager mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE); mRotationSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ROTATION_VECTOR); mSensorManager.registerListener(this, mRotationSensor, SENSOR_DELAY); } catch (Exception e) { e.printStackTrace(); } }
Example #21
Source File: MainActivity.java From PrinterThermal-ESCPOS-Android with MIT License | 5 votes |
public void printIt() { if (ContextCompat.checkSelfPermission(this, Manifest.permission.BLUETOOTH) != PackageManager.PERMISSION_GRANTED) { ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.BLUETOOTH}, MainActivity.PERMISSION_BLUETOOTH); } else { Printer printer = new Printer(BluetoothPrinters.selectFirstPairedBluetoothPrinter(), 203, 48f, 32); printer .printFormattedText( "[C]<img>" + PrinterTextParserImg.bitmapToHexadecimalString(printer, this.getApplicationContext().getResources().getDrawableForDensity(R.drawable.logo, DisplayMetrics.DENSITY_MEDIUM)) + "</img>\n" + "[L]\n" + "[C]<u><font size='big'>ORDER N°045</font></u>\n" + "[L]\n" + "[C]================================\n" + "[L]\n" + "[L]<b>BEAUTIFUL SHIRT</b>[R]9.99e\n" + "[L] + Size : S\n" + "[L]\n" + "[L]<b>AWESOME HAT</b>[R]24.99e\n" + "[L] + Size : 57/58\n" + "[L]\n" + "[C]--------------------------------\n" + "[R]TOTAL PRICE :[R]34.98e\n" + "[R]TAX :[R]4.23e\n" + "[L]\n" + "[C]================================\n" + "[L]\n" + "[L]<font size='tall'>Customer :</font>\n" + "[L]Raymond DUPONT\n" + "[L]5 rue des girafes\n" + "[L]31547 PERPETES\n" + "[L]Tel : +33801201456\n" + "[L]\n" + "[C]<barcode type='ean13' height='10'>831254784551</barcode>\n" + "[C]<qrcode size='20'>http://www.developpeur-web.dantsu.com/</qrcode>" ); } }
Example #22
Source File: CustomControlsFragment.java From MTweaks-KernelAdiutorMOD with GNU General Public License v3.0 | 5 votes |
@Override protected Drawable getTopFabDrawable() { Drawable drawable = DrawableCompat.wrap( ContextCompat.getDrawable(getActivity(), R.drawable.ic_add)); DrawableCompat.setTint(drawable, Color.WHITE); return drawable; }
Example #23
Source File: LogAdapter.java From EFRConnect-android with Apache License 2.0 | 5 votes |
@Override public void onBindViewHolder(LogAdapter.LogViewHolder holder, int position) { Log log = logList.get(position); if (logByAddress) { if (log.getDeviceAddress().equals(this.deviceAddress)) { if (logList.get(position).getLogType().equals(LogType.CALLBACK)) { holder.infoTV.setText("(Callback)" + log.getLogInfo()); holder.infoTV.setTextColor(ContextCompat.getColor(context, R.color.silabs_blue)); } else { holder.infoTV.setText(log.getLogInfo()); holder.infoTV.setTextColor(ContextCompat.getColor(context, R.color.silabs_subtle_text)); } holder.timeTV.setText(logList.get(position).getLogTime()); } } else { if (logList.get(position).getLogType().equals(LogType.CALLBACK)) { holder.infoTV.setText("(Callback)" + log.getLogInfo()); holder.infoTV.setTextColor(ContextCompat.getColor(context, R.color.silabs_blue)); } else { holder.infoTV.setText(log.getLogInfo()); holder.infoTV.setTextColor(ContextCompat.getColor(context, R.color.silabs_subtle_text)); } holder.timeTV.setText(logList.get(position).getLogTime()); } }
Example #24
Source File: LineDrawableActivity.java From ProjectX with Apache License 2.0 | 5 votes |
@Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setSupportActionBar(R.id.lid_toolbar); drawable = new LineDrawable(Color.TRANSPARENT, ContextCompat.getColor(this, R.color.colorPrimary), 1, Gravity.BOTTOM); if (Build.VERSION.SDK_INT >= 16) { findViewById(R.id.lid_tv_content).setBackground(drawable); } else { findViewById(R.id.lid_tv_content).setBackgroundDrawable(drawable); } this.<Spinner>findViewById(R.id.lid_sp_gravity).setOnItemSelectedListener(this); this.<SeekBar>findViewById(R.id.lid_sb_size).setOnSeekBarChangeListener(this); }
Example #25
Source File: BackupFragment.java From MTweaks-KernelAdiutorMOD with GNU General Public License v3.0 | 5 votes |
@Override protected Drawable getTopFabDrawable() { Drawable drawable = DrawableCompat.wrap( ContextCompat.getDrawable(getActivity(), R.drawable.ic_add)); DrawableCompat.setTint(drawable, Color.WHITE); return drawable; }
Example #26
Source File: SplashActivity.java From AppsMonitor with MIT License | 5 votes |
private List<String> checkPermissions() { List<String> permissions = new ArrayList<>(); if (ContextCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { permissions.add(Manifest.permission.WRITE_EXTERNAL_STORAGE); } if (ContextCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED) { permissions.add(Manifest.permission.READ_PHONE_STATE); } return permissions; }
Example #27
Source File: PermissionUtil.java From Hentoid with Apache License 2.0 | 5 votes |
public static boolean requestExternalStorageReadPermission(Activity activity, int permissionRequestCode) { if (ContextCompat.checkSelfPermission(activity, Manifest.permission.READ_EXTERNAL_STORAGE) == PERMISSION_GRANTED) { return true; } else { ActivityCompat.requestPermissions(activity, new String[]{ Manifest.permission.READ_EXTERNAL_STORAGE}, permissionRequestCode); return false; } }
Example #28
Source File: MyLocationActivity.java From Complete-Google-Map-API-Tutorial with Apache License 2.0 | 5 votes |
private void enableMyLocation() { if (ContextCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) { PermissionUtils.requestPermission(this, LOCATION_PERMISSION_REQUEST_CODE, android.Manifest.permission.ACCESS_FINE_LOCATION, true); } else if (googleMap != null) { googleMap.setMyLocationEnabled(true); } }
Example #29
Source File: MaterialValueHelper.java From MyBookshelf with GNU General Public License v3.0 | 5 votes |
@SuppressLint("PrivateResource") @ColorInt public static int getPrimaryTextColor(final Context context, boolean dark) { if (dark) { return ContextCompat.getColor(context, R.color.primary_text_default_material_light); } return ContextCompat.getColor(context, R.color.primary_text_default_material_dark); }
Example #30
Source File: MicrophoneConfigureActivity.java From haven with GNU General Public License v3.0 | 5 votes |
private void startMic () { String permission = Manifest.permission.RECORD_AUDIO; int requestCode = 999; if (ContextCompat.checkSelfPermission(this, permission) != PackageManager.PERMISSION_GRANTED) { // Should we show an explanation? if (ActivityCompat.shouldShowRequestPermissionRationale(this, permission)) { //This is called if user has denied the permission before //In this case I am just asking the permission again ActivityCompat.requestPermissions(this, new String[]{permission}, requestCode); } else { ActivityCompat.requestPermissions(this, new String[]{permission}, requestCode); } } else { try { microphone = MicrophoneTaskFactory.makeSampler(this); microphone.setMicListener(this); microphone.execute(); } catch (MicrophoneTaskFactory.RecordLimitExceeded e) { // TODO Auto-generated catch block e.printStackTrace(); } } }