From 322f8def762d25abc7ef76bb45290709fe6f29f0 Mon Sep 17 00:00:00 2001 From: xynngh Date: Tue, 2 Jun 2020 16:36:45 +0400 Subject: [PATCH] Fix some lint issues --- app/build.gradle | 1 + .../yetanothercallblocker/CallReceiver.java | 1 + .../yetanothercallblocker/DebugActivity.java | 2 +- .../yetanothercallblocker/EventHandler.java | 2 ++ .../yetanothercallblocker/IconAndColor.java | 3 +-- .../NotificationHelper.java | 2 +- .../yetanothercallblocker/UiUtils.java | 17 +++++++++++++++++ app/src/main/res/values/colors.xml | 1 - 8 files changed, 24 insertions(+), 5 deletions(-) create mode 100644 app/src/main/java/dummydomain/yetanothercallblocker/UiUtils.java diff --git a/app/build.gradle b/app/build.gradle index f45f2f7..9d5bcec 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -5,6 +5,7 @@ android { defaultConfig { applicationId "dummydomain.yetanothercallblocker" minSdkVersion 14 + //noinspection OldTargetApi: required for call blocking targetSdkVersion 28 versionCode 4030 versionName "0.4.3" diff --git a/app/src/main/java/dummydomain/yetanothercallblocker/CallReceiver.java b/app/src/main/java/dummydomain/yetanothercallblocker/CallReceiver.java index 1218f7d..fcf73bc 100644 --- a/app/src/main/java/dummydomain/yetanothercallblocker/CallReceiver.java +++ b/app/src/main/java/dummydomain/yetanothercallblocker/CallReceiver.java @@ -95,6 +95,7 @@ public class CallReceiver extends BroadcastReceiver { TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); try { + @SuppressLint("DiscouragedPrivateApi") // no choice Method m = tm.getClass().getDeclaredMethod("getITelephony"); m.setAccessible(true); ITelephony telephony = (ITelephony)m.invoke(tm); diff --git a/app/src/main/java/dummydomain/yetanothercallblocker/DebugActivity.java b/app/src/main/java/dummydomain/yetanothercallblocker/DebugActivity.java index d989ef9..1393c2d 100644 --- a/app/src/main/java/dummydomain/yetanothercallblocker/DebugActivity.java +++ b/app/src/main/java/dummydomain/yetanothercallblocker/DebugActivity.java @@ -68,7 +68,7 @@ public class DebugActivity extends AppCompatActivity { FeaturedDatabaseItem featuredItem = DatabaseSingleton.getFeaturedDatabase() .getDbItemByNumber(getNumber()); - return new Pair(item, featuredItem); + return new Pair<>(item, featuredItem); } @Override diff --git a/app/src/main/java/dummydomain/yetanothercallblocker/EventHandler.java b/app/src/main/java/dummydomain/yetanothercallblocker/EventHandler.java index 822f0bb..21d58f3 100644 --- a/app/src/main/java/dummydomain/yetanothercallblocker/EventHandler.java +++ b/app/src/main/java/dummydomain/yetanothercallblocker/EventHandler.java @@ -1,5 +1,6 @@ package dummydomain.yetanothercallblocker; +import android.annotation.SuppressLint; import android.content.Context; import org.greenrobot.eventbus.EventBus; @@ -12,6 +13,7 @@ public class EventHandler { private static final Logger LOG = LoggerFactory.getLogger(EventHandler.class); + @SuppressLint("StaticFieldLeak") // same lifecycle private static EventHandler instance; private Context context; diff --git a/app/src/main/java/dummydomain/yetanothercallblocker/IconAndColor.java b/app/src/main/java/dummydomain/yetanothercallblocker/IconAndColor.java index b6efabf..fb3c6ae 100644 --- a/app/src/main/java/dummydomain/yetanothercallblocker/IconAndColor.java +++ b/app/src/main/java/dummydomain/yetanothercallblocker/IconAndColor.java @@ -8,7 +8,6 @@ import androidx.annotation.ColorRes; import androidx.annotation.DrawableRes; import androidx.annotation.NonNull; import androidx.appcompat.widget.AppCompatImageView; -import androidx.core.content.res.ResourcesCompat; import androidx.core.widget.ImageViewCompat; import dummydomain.yetanothercallblocker.data.NumberInfo; @@ -34,7 +33,7 @@ class IconAndColor { @ColorInt int getColorInt(@NonNull Context context) { - return ResourcesCompat.getColor(context.getResources(), colorResId, context.getTheme()); + return UiUtils.getColorInt(context, colorResId); } void setOnImageView(AppCompatImageView imageView) { diff --git a/app/src/main/java/dummydomain/yetanothercallblocker/NotificationHelper.java b/app/src/main/java/dummydomain/yetanothercallblocker/NotificationHelper.java index dad54df..046d2f8 100644 --- a/app/src/main/java/dummydomain/yetanothercallblocker/NotificationHelper.java +++ b/app/src/main/java/dummydomain/yetanothercallblocker/NotificationHelper.java @@ -165,7 +165,7 @@ public class NotificationHelper { NotificationCompat.Builder builder = new NotificationCompat.Builder( context, CHANNEL_ID_BLOCKED_INFO) .setSmallIcon(R.drawable.ic_brick_24dp) - .setColor(context.getResources().getColor(R.color.rateNegative)) + .setColor(UiUtils.getColorInt(context, R.color.rateNegative)) .setContentTitle(title) .setContentText(text) .setPriority(NotificationCompat.PRIORITY_DEFAULT) diff --git a/app/src/main/java/dummydomain/yetanothercallblocker/UiUtils.java b/app/src/main/java/dummydomain/yetanothercallblocker/UiUtils.java new file mode 100644 index 0000000..d2e9e75 --- /dev/null +++ b/app/src/main/java/dummydomain/yetanothercallblocker/UiUtils.java @@ -0,0 +1,17 @@ +package dummydomain.yetanothercallblocker; + +import android.content.Context; + +import androidx.annotation.ColorInt; +import androidx.annotation.ColorRes; +import androidx.annotation.NonNull; +import androidx.core.content.res.ResourcesCompat; + +public class UiUtils { + + @ColorInt + public static int getColorInt(@NonNull Context context, @ColorRes int colorResId) { + return ResourcesCompat.getColor(context.getResources(), colorResId, context.getTheme()); + } + +} diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index 2e4a801..6393002 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -7,6 +7,5 @@ #679f41 #ffb300 #d40000 - #999999 #999999