Рефактор Utils (#1000)

* Refactor:обновил Deprecated в новых Андроидах вызовы в некоторых утилитах

* Refactor:обновил Deprecated в новых Андроидах вызовы в некоторых утилитах

* Пофиксил
This commit is contained in:
xsafter
2023-01-11 13:41:46 +03:00
committed by GitHub
parent effab03fd2
commit bfc718bc98
4 changed files with 15 additions and 10 deletions
@@ -38,8 +38,9 @@ public class About {
}
public static String getBuild(Context context, String name) {
try {
Scanner scanner = new Scanner(context.getAssets().open(name));
try (
Scanner scanner = new Scanner(context.getAssets().open(name))
) {
while (scanner.hasNextLine()) {
String line = scanner.findInLine("VERSION_BUILD=.+");
if (line != null)
@@ -97,7 +97,7 @@ public class IOUtils {
public static void copyFile(InputStream is, File target) throws IOException {
var parent = target.getParentFile();
if (!parent.exists())
if (!(parent != null ? parent.exists() : false))
parent.getParentFile().mkdirs();
writeToFile(target, readAllBytes(is));
}
@@ -8,7 +8,7 @@ import java.lang.reflect.Modifier;
public class ReflectionUtils {
/**
* Gets a class with specific name.
* Gets a class with a specific name.
* Supports smali type (Lpackage/Class;)
*/
public static Class<?> getClass(String name)
@@ -6,6 +6,7 @@ import android.content.res.ColorStateList;
import android.content.res.Resources;
import android.graphics.Color;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffColorFilter;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.util.Log;
@@ -115,7 +116,7 @@ public class ThemesUtils {
view.setHighlightColor(ThemesUtils.getMutedAccentColor());
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
view.getTextCursorDrawable().setColorFilter(ThemesUtils.getAccentColor(), PorterDuff.Mode.SRC_IN);
view.getTextCursorDrawable().setColorFilter(new PorterDuffColorFilter(ThemesUtils.getAccentColor(), PorterDuff.Mode.SRC_IN));
} else if (!OEMDetector.isMIUI()) {
Field field = TextView.class.getDeclaredField("mCursorDrawableRes");
field.setAccessible(true);
@@ -139,16 +140,18 @@ public class ThemesUtils {
field.set(editor, drawables);
}
}
} catch (Exception ignored) {
} catch (Exception e) {
Log.e("ThemesUtils", "setCursorColor: ", e);
}
}
@SuppressLint("DiscouragedPrivateApi")
public static void colorHandles(TextView view) {
try {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
view.getTextSelectHandle().setColorFilter(ThemesUtils.getAccentColor(), PorterDuff.Mode.SRC_IN);
view.getTextSelectHandleRight().setColorFilter(ThemesUtils.getAccentColor(), PorterDuff.Mode.SRC_IN);
view.getTextSelectHandleLeft().setColorFilter(ThemesUtils.getAccentColor(), PorterDuff.Mode.SRC_IN);
PorterDuffColorFilter filter = new PorterDuffColorFilter(ThemesUtils.getAccentColor(), PorterDuff.Mode.SRC_IN);
view.getTextSelectHandle().setColorFilter(filter);
view.getTextSelectHandleRight().setColorFilter(filter);
view.getTextSelectHandleLeft().setColorFilter(filter);
} else if (!OEMDetector.isMIUI()) {
Field editorField = TextView.class.getDeclaredField("mEditor");
@@ -189,7 +192,8 @@ public class ThemesUtils {
}
}
}
} catch (Exception ignored) {
} catch (Exception e) {
Log.e("ThemesUtils", "colorHandles: ", e);
}
}