Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
mmm-rain
AndroidUtilCode
提交
e71c98fa
A
AndroidUtilCode
项目概览
mmm-rain
/
AndroidUtilCode
与 Fork 源项目一致
从无法访问的项目Fork
通知
4
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
A
AndroidUtilCode
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
e71c98fa
编写于
3月 03, 2018
作者:
B
Blankj
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
see 03/03 log
上级
44bfe5e9
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
51 addition
and
54 deletion
+51
-54
utilcode/src/main/java/com/blankj/utilcode/util/CacheUtils.java
...de/src/main/java/com/blankj/utilcode/util/CacheUtils.java
+14
-14
utilcode/src/main/java/com/blankj/utilcode/util/ScreenUtils.java
...e/src/main/java/com/blankj/utilcode/util/ScreenUtils.java
+37
-40
未找到文件。
utilcode/src/main/java/com/blankj/utilcode/util/CacheUtils.java
浏览文件 @
e71c98fa
...
...
@@ -85,7 +85,7 @@ public final class CacheUtils {
* Return the single {@link CacheUtils} instance.
* <p>cache directory: /data/data/package/cache/cacheUtils</p>
*
* @param maxSize The max size
, in bytes, of cache
.
* @param maxSize The max size
of cache, in bytes
.
* @param maxCount The max count of cache.
* @return the single {@link CacheUtils} instance
*/
...
...
@@ -98,7 +98,7 @@ public final class CacheUtils {
* <p>cache directory: /data/data/package/cache/cacheName</p>
*
* @param cacheName The name of cache.
* @param maxSize The max size
, in bytes, of cache
.
* @param maxSize The max size
of cache, in bytes
.
* @param maxCount The max count of cache.
* @return the single {@link CacheUtils} instance
*/
...
...
@@ -124,7 +124,7 @@ public final class CacheUtils {
* Return the single {@link CacheUtils} instance.
*
* @param cacheDir The directory of cache.
* @param maxSize The max size
, in bytes, of cache
.
* @param maxSize The max size
of cache, in bytes
.
* @param maxCount The max count of cache.
* @return the single {@link CacheUtils} instance
*/
...
...
@@ -166,7 +166,7 @@ public final class CacheUtils {
*
* @param key The key of cache.
* @param value The value of cache.
* @param saveTime The save time
, in seconds, of cache
.
* @param saveTime The save time
of cache, in seconds
.
*/
public
void
put
(
@NonNull
final
String
key
,
@NonNull
byte
[]
value
,
final
int
saveTime
)
{
if
(
value
.
length
<=
0
)
return
;
...
...
@@ -225,7 +225,7 @@ public final class CacheUtils {
*
* @param key The key of cache.
* @param value The value of cache.
* @param saveTime The save time
, in seconds, of cache
.
* @param saveTime The save time
of cache, in seconds
.
*/
public
void
put
(
@NonNull
final
String
key
,
@NonNull
final
String
value
,
final
int
saveTime
)
{
put
(
key
,
CacheHelper
.
string2Bytes
(
value
),
saveTime
);
...
...
@@ -273,7 +273,7 @@ public final class CacheUtils {
*
* @param key The key of cache.
* @param value The value of cache.
* @param saveTime The save time
, in seconds, of cache
.
* @param saveTime The save time
of cache, in seconds
.
*/
public
void
put
(
@NonNull
final
String
key
,
@NonNull
final
JSONObject
value
,
...
...
@@ -324,7 +324,7 @@ public final class CacheUtils {
*
* @param key The key of cache.
* @param value The value of cache.
* @param saveTime The save time
, in seconds, of cache
.
* @param saveTime The save time
of cache, in seconds
.
*/
public
void
put
(
@NonNull
final
String
key
,
@NonNull
final
JSONArray
value
,
final
int
saveTime
)
{
put
(
key
,
CacheHelper
.
jsonArray2Bytes
(
value
),
saveTime
);
...
...
@@ -373,7 +373,7 @@ public final class CacheUtils {
*
* @param key The key of cache.
* @param value The value of cache.
* @param saveTime The save time
, in seconds, of cache
.
* @param saveTime The save time
of cache, in seconds
.
*/
public
void
put
(
@NonNull
final
String
key
,
@NonNull
final
Bitmap
value
,
final
int
saveTime
)
{
put
(
key
,
CacheHelper
.
bitmap2Bytes
(
value
),
saveTime
);
...
...
@@ -421,7 +421,7 @@ public final class CacheUtils {
*
* @param key The key of cache.
* @param value The value of cache.
* @param saveTime The save time
, in seconds, of cache
.
* @param saveTime The save time
of cache, in seconds
.
*/
public
void
put
(
@NonNull
final
String
key
,
@NonNull
final
Drawable
value
,
final
int
saveTime
)
{
put
(
key
,
CacheHelper
.
drawable2Bytes
(
value
),
saveTime
);
...
...
@@ -469,7 +469,7 @@ public final class CacheUtils {
*
* @param key The key of cache.
* @param value The value of cache.
* @param saveTime The save time
, in seconds, of cache
.
* @param saveTime The save time
of cache, in seconds
.
*/
public
void
put
(
@NonNull
final
String
key
,
@NonNull
final
Parcelable
value
,
...
...
@@ -526,7 +526,7 @@ public final class CacheUtils {
*
* @param key The key of cache.
* @param value The value of cache.
* @param saveTime The save time
, in seconds, of cache
.
* @param saveTime The save time
of cache, in seconds
.
*/
public
void
put
(
@NonNull
final
String
key
,
@NonNull
final
Serializable
value
,
...
...
@@ -558,9 +558,9 @@ public final class CacheUtils {
}
/**
* Return the size
, in bytes, of cache
.
* Return the size
of cache, in bytes
.
*
* @return the size
, in bytes, of cache
* @return the size
of cache, in bytes
*/
public
long
getCacheSize
()
{
return
mCacheManager
.
getCacheSize
();
...
...
@@ -712,7 +712,7 @@ public final class CacheUtils {
/**
* Remove the oldest files.
*
* @return the size
, in bytes, of oldest fil
es
* @return the size
of oldest files, in byt
es
*/
private
long
removeOldest
()
{
if
(
lastUsageDates
.
isEmpty
())
return
0
;
...
...
utilcode/src/main/java/com/blankj/utilcode/util/ScreenUtils.java
浏览文件 @
e71c98fa
...
...
@@ -11,17 +11,20 @@ import android.graphics.Point;
import
android.os.Build
;
import
android.provider.Settings
;
import
android.support.annotation.NonNull
;
import
android.support.annotation.RequiresPermission
;
import
android.util.DisplayMetrics
;
import
android.view.Surface
;
import
android.view.View
;
import
android.view.WindowManager
;
import
static
android
.
Manifest
.
permission
.
WRITE_SETTINGS
;
/**
* <pre>
* author: Blankj
* blog : http://blankj.com
* time : 2016/08/02
* desc :
屏幕相关工具类
* desc :
utils about screen
* </pre>
*/
public
final
class
ScreenUtils
{
...
...
@@ -31,9 +34,9 @@ public final class ScreenUtils {
}
/**
*
获取屏幕的宽度(单位:px)
*
Return the width of screen, in pixel.
*
* @return
屏幕宽
* @return
the width of screen, in pixel
*/
public
static
int
getScreenWidth
()
{
WindowManager
wm
=
(
WindowManager
)
Utils
.
getApp
().
getSystemService
(
Context
.
WINDOW_SERVICE
);
...
...
@@ -50,9 +53,9 @@ public final class ScreenUtils {
}
/**
*
获取屏幕的高度(单位:px)
*
Return the height of screen, in pixel.
*
* @return
屏幕高
* @return
the height of screen, in pixel
*/
public
static
int
getScreenHeight
()
{
WindowManager
wm
=
(
WindowManager
)
Utils
.
getApp
().
getSystemService
(
Context
.
WINDOW_SERVICE
);
...
...
@@ -69,25 +72,25 @@ public final class ScreenUtils {
}
/**
*
获取屏幕密度
*
Return the density of screen.
*
* @return
屏幕密度
* @return
the density of screen
*/
public
static
float
getScreenDensity
()
{
return
Utils
.
getApp
().
getResources
().
getDisplayMetrics
().
density
;
}
/**
*
获取屏幕密度 DPI
*
Return the screen density expressed as dots-per-inch.
*
* @return
屏幕密度 DPI
* @return
the screen density expressed as dots-per-inch
*/
public
static
int
getScreenDensityDpi
()
{
return
Utils
.
getApp
().
getResources
().
getDisplayMetrics
().
densityDpi
;
}
/**
*
设置屏幕为全屏
*
Set full screen.
*
* @param activity The activity.
*/
...
...
@@ -97,15 +100,7 @@ public final class ScreenUtils {
}
/**
* 设置屏幕为横屏
* <p>还有一种就是在 Activity 中加属性 android:screenOrientation="landscape"</p>
* <p>不设置 Activity 的 android:configChanges 时,
* 切屏会重新调用各个生命周期,切横屏时会执行一次,切竖屏时会执行两次</p>
* <p>设置 Activity 的 android:configChanges="orientation"时,
* 切屏还是会重新调用各个生命周期,切横、竖屏时只会执行一次</p>
* <p>设置 Activity 的 android:configChanges="orientation|keyboardHidden|screenSize"
* (4.0 以上必须带最后一个参数)时
* 切屏不会重新调用各个生命周期,只会执行 onConfigurationChanged 方法</p>
* Set the screen to landscape.
*
* @param activity The activity.
*/
...
...
@@ -114,7 +109,7 @@ public final class ScreenUtils {
}
/**
*
设置屏幕为竖屏
*
Set the screen to portrait.
*
* @param activity The activity.
*/
...
...
@@ -123,9 +118,9 @@ public final class ScreenUtils {
}
/**
*
判断是否横屏
*
Return whether screen is landscape.
*
* @return {@code true}:
是<br>{@code false}: 否
* @return {@code true}:
yes<br>{@code false}: no
*/
public
static
boolean
isLandscape
()
{
return
Utils
.
getApp
().
getResources
().
getConfiguration
().
orientation
...
...
@@ -133,9 +128,9 @@ public final class ScreenUtils {
}
/**
*
判断是否竖屏
*
Return whether screen is portrait.
*
* @return {@code true}:
是<br>{@code false}: 否
* @return {@code true}:
yes<br>{@code false}: no
*/
public
static
boolean
isPortrait
()
{
return
Utils
.
getApp
().
getResources
().
getConfiguration
().
orientation
...
...
@@ -143,10 +138,10 @@ public final class ScreenUtils {
}
/**
*
获取屏幕旋转角度
*
Return the rotation of screen.
*
* @param activity The activity.
* @return
屏幕旋转角度
* @return
the rotation of screen
*/
public
static
int
getScreenRotation
(
@NonNull
final
Activity
activity
)
{
switch
(
activity
.
getWindowManager
().
getDefaultDisplay
().
getRotation
())
{
...
...
@@ -164,20 +159,21 @@ public final class ScreenUtils {
}
/**
*
截屏
*
Return the bitmap of screen.
*
* @param activity The activity.
* @return
Bitmap
* @return
the bitmap of screen
*/
public
static
Bitmap
screenShot
(
@NonNull
final
Activity
activity
)
{
return
screenShot
(
activity
,
false
);
}
/**
*
截屏
*
Return the bitmap of screen.
*
* @param activity The activity.
* @return Bitmap
* @param activity The activity.
* @param isDeleteStatusBar True to delete status bar, false otherwise.
* @return the bitmap of screen
*/
public
static
Bitmap
screenShot
(
@NonNull
final
Activity
activity
,
boolean
isDeleteStatusBar
)
{
View
decorView
=
activity
.
getWindow
().
getDecorView
();
...
...
@@ -206,9 +202,9 @@ public final class ScreenUtils {
}
/**
*
判断是否锁屏
*
Return whether screen is locked.
*
* @return {@code true}:
是<br>{@code false}: 否
* @return {@code true}:
yes<br>{@code false}: no
*/
public
static
boolean
isScreenLock
()
{
KeyguardManager
km
=
...
...
@@ -217,11 +213,12 @@ public final class ScreenUtils {
}
/**
*
设置进入休眠时长
* <p>
需添加权限
{@code <uses-permission android:name="android.permission.WRITE_SETTINGS" />}</p>
*
Set the duration of sleep.
* <p>
Must hold
{@code <uses-permission android:name="android.permission.WRITE_SETTINGS" />}</p>
*
* @param duration
时长
* @param duration
The duration.
*/
@RequiresPermission
(
WRITE_SETTINGS
)
public
static
void
setSleepDuration
(
final
int
duration
)
{
Settings
.
System
.
putInt
(
Utils
.
getApp
().
getContentResolver
(),
...
...
@@ -231,9 +228,9 @@ public final class ScreenUtils {
}
/**
*
获取进入休眠时长
*
Return the duration of sleep.
*
* @return
进入休眠时长,报错返回-123
* @return
the duration of sleep.
*/
public
static
int
getSleepDuration
()
{
try
{
...
...
@@ -248,9 +245,9 @@ public final class ScreenUtils {
}
/**
*
判断是否是平板
*
Return whether device is tablet.
*
* @return {@code true}:
是<br>{@code false}: 否
* @return {@code true}:
yes<br>{@code false}: no
*/
public
static
boolean
isTablet
()
{
return
(
Utils
.
getApp
().
getResources
().
getConfiguration
().
screenLayout
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录