Skip to content

Commit

Permalink
Improve support for API 30 and above
Browse files Browse the repository at this point in the history
  • Loading branch information
pranavpandey committed Jun 18, 2021
1 parent 6a81d4e commit d4c6650
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
import java.util.List;

/**
* Help class to request and manage runtime permissions introduced in API 23.
* Helper class to request and manage runtime permissions introduced in API 23.
* <p>It must be initialized before using any of its functions or requesting any permissions.
*
* <p>Register the {@link DynamicPermissionsActivity} via {@link #setPermissionActivity(Class)}
Expand Down Expand Up @@ -478,6 +478,8 @@ public boolean canDrawOverlays() {
*
* @see Manifest.permission#PACKAGE_USAGE_STATS
*/
@SuppressWarnings("deprecation")
@TargetApi(Build.VERSION_CODES.R)
public boolean hasUsageAccess() {
if (DynamicSdkUtils.is21()) {
try {
Expand All @@ -487,8 +489,15 @@ public boolean hasUsageAccess() {
AppOpsManager appOpsManager = (AppOpsManager) getContext()
.getSystemService(Context.APP_OPS_SERVICE);

int mode = AppOpsManager.MODE_ERRORED;
if (appOpsManager != null) {
if (appOpsManager == null) {
return false;
}

int mode;
if (DynamicSdkUtils.is30()) {
mode = appOpsManager.unsafeCheckOpNoThrow(AppOpsManager.OPSTR_GET_USAGE_STATS,
applicationInfo.uid, applicationInfo.packageName);
} else {
mode = appOpsManager.checkOpNoThrow(AppOpsManager.OPSTR_GET_USAGE_STATS,
applicationInfo.uid, applicationInfo.packageName);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import com.pranavpandey.android.dynamic.support.utils.DynamicResourceUtils;
import com.pranavpandey.android.dynamic.support.view.base.DynamicInfoView;
import com.pranavpandey.android.dynamic.utils.DynamicTextUtils;
import com.pranavpandey.android.dynamic.utils.DynamicViewUtils;

import java.util.List;
import java.util.Locale;
Expand Down Expand Up @@ -187,9 +188,7 @@ public ViewHolder(@NonNull View view) {
dynamicInfo = view.findViewById(R.id.ads_dynamic_info_view);

Dynamic.setColorType(dynamicInfo.getIconView(), Defaults.ADS_COLOR_TYPE_ICON);
if (dynamicInfo.getSubtitleView() != null) {
dynamicInfo.getSubtitleView().setAllCaps(true);
}
DynamicViewUtils.setTextViewAllCaps(dynamicInfo.getSubtitleView(), true);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ public void loadFromAttributes(@Nullable AttributeSet attrs) {

getViewTreeObserver().addOnGlobalLayoutListener(
new ViewTreeObserver.OnGlobalLayoutListener() {
@SuppressWarnings("deprecation")
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
@Override
public void onGlobalLayout() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {

mFooter.getViewTreeObserver().addOnGlobalLayoutListener(
new ViewTreeObserver.OnGlobalLayoutListener() {
@SuppressWarnings("deprecation")
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
@Override
public void onGlobalLayout() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,7 @@ public static void setEdgeEffectColor(@Nullable ViewPager view, @ColorInt int co
* @param edgeEffect The edge effect object to be used.
* @param color The edge effect color to be set.
*/
@SuppressWarnings("deprecation")
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public static void setEdgeEffectColor(@Nullable Object edgeEffect, @ColorInt int color) {
if (edgeEffect instanceof EdgeEffectCompat) {
Expand Down

0 comments on commit d4c6650

Please sign in to comment.