public class ContextUtils
extends java.lang.Object
构造器和说明 |
---|
ContextUtils() |
限定符和类型 | 方法和说明 |
---|---|
static void |
copyToClipboard(android.content.Context context,
java.lang.String text)
复制文本到剪贴板
|
static float |
density(android.content.Context context)
获取屏幕像素容积率
|
static int |
dip2px(android.content.Context context,
float dpValue)
根据手机的分辨率从 dp 的单位 转成为 px(像素)
|
static android.app.ActivityManager |
getActivityManager(android.content.Context context)
Activity管理器
|
static java.lang.String |
getAppName(android.content.Context context)
获取应用名称
|
static org.lasque.tusdk.core.struct.TuSdkSize |
getDisplaySize(android.content.Context context)
获取显示长宽
|
static InterfaceOrientation |
getInterfaceRotation(android.content.Context context)
Interface Orientation
|
static android.app.NotificationManager |
getNotificationManager(android.content.Context context)
获取通知管理对象
|
static android.content.pm.PackageInfo |
getPackageInfo(android.content.Context context)
获取包信息
|
static java.io.InputStream |
getRawStream(android.content.Context context,
int resId)
获取资源文件RAW文件输入流
|
static int |
getResColor(android.content.Context context,
int resId)
获取颜色
|
static float |
getResDimension(android.content.Context context,
int id)
获取资源距离
|
static int |
getResOffset(android.content.Context context,
int id)
获取资源距离大小 DP
|
static int |
getResSize(android.content.Context context,
int id)
获取资源距离大小
|
static java.lang.String |
getResString(android.content.Context context,
int resId)
获取资源字符串
|
static java.lang.String |
getResString(android.content.Context context,
int resId,
java.lang.Object... formatArgs)
获取资源字符串
|
static android.view.ContextThemeWrapper |
getResStyleContext(android.content.Context context,
int id)
获取资源样式容器 字体颜色无法通过此设置,需要手动设置
|
static int |
getRotation(android.content.Context context)
获取屏幕旋转角度
|
static org.lasque.tusdk.core.struct.TuSdkSize |
getScreenSize(android.content.Context context)
获得屏幕尺寸
|
static android.content.SharedPreferences |
getSharedPreferences(android.content.Context context,
java.lang.String name,
int mode)
获取本地存储
|
static <T> T |
getSystemService(android.content.Context context,
java.lang.String serviceName)
获取系统服务
|
static int |
getVersionCode(android.content.Context context)
获取版本号
|
static java.lang.String |
getVersionName(android.content.Context context)
获取版本名称
|
static android.view.WindowManager |
getWindowManager(android.content.Context context)
获取 WindowManager
|
static boolean |
hasPermission(android.content.Context context,
PermissionType permission)
是否存在该权限
|
static boolean |
hasSystemFeature(android.content.Context context,
java.lang.String name)
是否支持系统功能
|
boolean |
isAppOnForeground(android.content.Context context)
应用是否在前台运行
|
static int |
px2dip(android.content.Context context,
float pxValue)
根据手机的分辨率从 px(像素) 的单位 转成为 dp
|
static int |
px2sp(android.content.Context context,
float pxValue)
将px值转换为sp值,保证文字大小不变
|
static int |
sp2px(android.content.Context context,
float spValue)
将sp值转换为px值,保证文字大小不变
|
static float |
sp2pxFloat(android.content.Context context,
float spValue)
将sp值转换为px值,使用 float类型,保证文字大小不变
|
public static <T> T getSystemService(android.content.Context context, java.lang.String serviceName)
context
- 内容上下文serviceName
- 系统服务名称public static boolean hasSystemFeature(android.content.Context context, java.lang.String name)
context
- name
- public static boolean hasPermission(android.content.Context context, PermissionType permission)
permission
- 安卓权限public static android.view.WindowManager getWindowManager(android.content.Context context)
context
- public static android.app.ActivityManager getActivityManager(android.content.Context context)
context
- public static android.app.NotificationManager getNotificationManager(android.content.Context context)
context
- public static org.lasque.tusdk.core.struct.TuSdkSize getScreenSize(android.content.Context context)
context
- public static org.lasque.tusdk.core.struct.TuSdkSize getDisplaySize(android.content.Context context)
context
- public static float density(android.content.Context context)
public static int dip2px(android.content.Context context, float dpValue)
context
- dpValue
- public static int px2dip(android.content.Context context, float pxValue)
context
- pxValue
- public static int px2sp(android.content.Context context, float pxValue)
pxValue
- fontScale
- (DisplayMetrics类中属性scaledDensity)public static int sp2px(android.content.Context context, float spValue)
spValue
- fontScale
- (DisplayMetrics类中属性scaledDensity)public static float sp2pxFloat(android.content.Context context, float spValue)
spValue
- fontScale
- (DisplayMetrics类中属性scaledDensity)public static android.content.pm.PackageInfo getPackageInfo(android.content.Context context)
context
- public static java.lang.String getVersionName(android.content.Context context)
context
- public static int getVersionCode(android.content.Context context)
context
- public static java.lang.String getAppName(android.content.Context context)
context
- public static java.lang.String getResString(android.content.Context context, int resId)
context
- resId
- 资源IDpublic static java.lang.String getResString(android.content.Context context, int resId, java.lang.Object... formatArgs)
context
- resId
- 资源IDformatArgs
- 格式化参数public static int getResColor(android.content.Context context, int resId)
context
- resId
- 资源IDpublic static android.view.ContextThemeWrapper getResStyleContext(android.content.Context context, int id)
context
- id
- public static float getResDimension(android.content.Context context, int id)
context
- id
- public static int getResOffset(android.content.Context context, int id)
context
- id
- public static int getResSize(android.content.Context context, int id)
context
- id
- public static java.io.InputStream getRawStream(android.content.Context context, int resId)
context
- resId
- public static int getRotation(android.content.Context context)
public static InterfaceOrientation getInterfaceRotation(android.content.Context context)
public static android.content.SharedPreferences getSharedPreferences(android.content.Context context, java.lang.String name, int mode)
name
- mode
- public boolean isAppOnForeground(android.content.Context context)
public static void copyToClipboard(android.content.Context context, java.lang.String text)
context
- text
-