119 lines
3.6 KiB
Java
119 lines
3.6 KiB
Java
package androidx.core.content;
|
|
|
|
import android.content.Context;
|
|
import android.content.Intent;
|
|
import android.content.res.ColorStateList;
|
|
import android.graphics.drawable.Drawable;
|
|
import android.os.Build;
|
|
import android.os.Bundle;
|
|
import android.os.Process;
|
|
import android.util.Log;
|
|
import android.util.TypedValue;
|
|
import java.io.File;
|
|
|
|
/* loaded from: classes.dex */
|
|
public class ContextCompat {
|
|
private static final Object a = new Object();
|
|
private static TypedValue b;
|
|
|
|
public static boolean a(Context context, Intent[] intentArr, Bundle bundle) {
|
|
if (Build.VERSION.SDK_INT >= 16) {
|
|
context.startActivities(intentArr, bundle);
|
|
return true;
|
|
}
|
|
context.startActivities(intentArr);
|
|
return true;
|
|
}
|
|
|
|
public static File[] b(Context context, String str) {
|
|
return Build.VERSION.SDK_INT >= 19 ? context.getExternalFilesDirs(str) : new File[]{context.getExternalFilesDir(str)};
|
|
}
|
|
|
|
public static Drawable c(Context context, int i) {
|
|
int i2;
|
|
int i3 = Build.VERSION.SDK_INT;
|
|
if (i3 >= 21) {
|
|
return context.getDrawable(i);
|
|
}
|
|
if (i3 >= 16) {
|
|
return context.getResources().getDrawable(i);
|
|
}
|
|
synchronized (a) {
|
|
if (b == null) {
|
|
b = new TypedValue();
|
|
}
|
|
context.getResources().getValue(i, b, true);
|
|
i2 = b.resourceId;
|
|
}
|
|
return context.getResources().getDrawable(i2);
|
|
}
|
|
|
|
public static void a(Context context, Intent intent, Bundle bundle) {
|
|
if (Build.VERSION.SDK_INT >= 16) {
|
|
context.startActivity(intent, bundle);
|
|
} else {
|
|
context.startActivity(intent);
|
|
}
|
|
}
|
|
|
|
public static ColorStateList b(Context context, int i) {
|
|
if (Build.VERSION.SDK_INT >= 23) {
|
|
return context.getColorStateList(i);
|
|
}
|
|
return context.getResources().getColorStateList(i);
|
|
}
|
|
|
|
public static File[] a(Context context) {
|
|
return Build.VERSION.SDK_INT >= 19 ? context.getExternalCacheDirs() : new File[]{context.getExternalCacheDir()};
|
|
}
|
|
|
|
public static File b(Context context) {
|
|
if (Build.VERSION.SDK_INT >= 21) {
|
|
return context.getNoBackupFilesDir();
|
|
}
|
|
return a(new File(context.getApplicationInfo().dataDir, "no_backup"));
|
|
}
|
|
|
|
public static int a(Context context, int i) {
|
|
if (Build.VERSION.SDK_INT >= 23) {
|
|
return context.getColor(i);
|
|
}
|
|
return context.getResources().getColor(i);
|
|
}
|
|
|
|
public static boolean c(Context context) {
|
|
if (Build.VERSION.SDK_INT >= 24) {
|
|
return context.isDeviceProtectedStorage();
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public static int a(Context context, String str) {
|
|
if (str != null) {
|
|
return context.checkPermission(str, Process.myPid(), Process.myUid());
|
|
}
|
|
throw new IllegalArgumentException("permission is null");
|
|
}
|
|
|
|
private static synchronized File a(File file) {
|
|
synchronized (ContextCompat.class) {
|
|
if (file.exists() || file.mkdirs()) {
|
|
return file;
|
|
}
|
|
if (file.exists()) {
|
|
return file;
|
|
}
|
|
Log.w("ContextCompat", "Unable to create files subdir " + file.getPath());
|
|
return null;
|
|
}
|
|
}
|
|
|
|
public static void a(Context context, Intent intent) {
|
|
if (Build.VERSION.SDK_INT >= 26) {
|
|
context.startForegroundService(intent);
|
|
} else {
|
|
context.startService(intent);
|
|
}
|
|
}
|
|
}
|