Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xiaoxuan_i809
AndroidUtilCode
提交
72d84e43
A
AndroidUtilCode
项目概览
xiaoxuan_i809
/
AndroidUtilCode
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
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,发现更多精彩内容 >>
提交
72d84e43
编写于
2月 10, 2018
作者:
B
Blankj
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
see 02/10 log
上级
6a1cb735
变更
29
隐藏空白更改
内联
并排
Showing
29 changed file
with
583 addition
and
189 deletion
+583
-189
app/build.gradle
app/build.gradle
+1
-12
app/src/main/AndroidManifest.xml
app/src/main/AndroidManifest.xml
+3
-1
app/src/main/java/com/blankj/androidutilcode/UtilsApp.java
app/src/main/java/com/blankj/androidutilcode/UtilsApp.java
+8
-5
app/src/main/java/com/blankj/androidutilcode/feature/core/activity/ActivityActivity.java
...droidutilcode/feature/core/activity/ActivityActivity.java
+8
-6
app/src/main/java/com/blankj/androidutilcode/feature/core/bar/BarStatusActivity.java
...j/androidutilcode/feature/core/bar/BarStatusActivity.java
+8
-0
app/src/main/java/com/blankj/androidutilcode/feature/core/bar/BarStatusAlphaFragment.java
...roidutilcode/feature/core/bar/BarStatusAlphaFragment.java
+2
-2
app/src/main/java/com/blankj/androidutilcode/feature/core/permission/PermissionActivity.java
...dutilcode/feature/core/permission/PermissionActivity.java
+2
-0
app/src/main/java/com/blankj/androidutilcode/feature/core/screen/ScreenActivity.java
...j/androidutilcode/feature/core/screen/ScreenActivity.java
+23
-18
app/src/main/java/com/blankj/androidutilcode/feature/sub/SubUtilActivity.java
...m/blankj/androidutilcode/feature/sub/SubUtilActivity.java
+5
-0
app/src/main/java/com/blankj/androidutilcode/feature/sub/brightness/BrightnessActivity.java
...idutilcode/feature/sub/brightness/BrightnessActivity.java
+154
-0
app/src/main/res_core/layout/activity_bar_status.xml
app/src/main/res_core/layout/activity_bar_status.xml
+14
-0
app/src/main/res_core/layout/activity_screen.xml
app/src/main/res_core/layout/activity_screen.xml
+57
-50
app/src/main/res_core/values/strings.xml
app/src/main/res_core/values/strings.xml
+2
-0
app/src/main/res_sub/layout/activity_brightness.xml
app/src/main/res_sub/layout/activity_brightness.xml
+53
-0
app/src/main/res_sub/layout/activity_util_sub.xml
app/src/main/res_sub/layout/activity_util_sub.xml
+7
-0
app/src/main/res_sub/values/strings.xml
app/src/main/res_sub/values/strings.xml
+6
-1
build.gradle
build.gradle
+4
-1
subutil/README-CN.md
subutil/README-CN.md
+15
-1
subutil/build.gradle
subutil/build.gradle
+0
-8
subutil/src/main/java/com/blankj/subutil/util/BrightnessUtils.java
...rc/main/java/com/blankj/subutil/util/BrightnessUtils.java
+125
-0
subutil/src/main/java/com/blankj/subutil/util/LocationUtils.java
.../src/main/java/com/blankj/subutil/util/LocationUtils.java
+12
-8
update_log.md
update_log.md
+3
-0
utilcode/build.gradle
utilcode/build.gradle
+0
-7
utilcode/src/main/java/com/blankj/utilcode/constant/MemoryConstants.java
...in/java/com/blankj/utilcode/constant/MemoryConstants.java
+1
-13
utilcode/src/main/java/com/blankj/utilcode/constant/PermissionConstants.java
...ava/com/blankj/utilcode/constant/PermissionConstants.java
+1
-1
utilcode/src/main/java/com/blankj/utilcode/constant/RegexConstants.java
...ain/java/com/blankj/utilcode/constant/RegexConstants.java
+34
-31
utilcode/src/main/java/com/blankj/utilcode/constant/TimeConstants.java
...main/java/com/blankj/utilcode/constant/TimeConstants.java
+1
-16
utilcode/src/main/java/com/blankj/utilcode/util/ActivityUtils.java
...src/main/java/com/blankj/utilcode/util/ActivityUtils.java
+8
-7
utilcode/src/main/java/com/blankj/utilcode/util/BarUtils.java
...code/src/main/java/com/blankj/utilcode/util/BarUtils.java
+26
-1
未找到文件。
app/build.gradle
浏览文件 @
72d84e43
plugins
{
id
"tech.harmonysoft.oss.traute"
version
'1.0.5'
}
apply
plugin:
'com.android.application'
File
signPropertiesFile
=
rootProject
.
file
(
'sign/keystore.properties'
)
...
...
@@ -49,25 +46,17 @@ android {
}
}
traute
{
javacPluginVersion
=
trauteVersion
}
dependencies
{
implementation
fileTree
(
include:
[
'*.jar'
],
dir:
'libs'
)
implementation
project
(
':utilcode'
)
implementation
project
(
':subutil'
)
implementation
"com.android.support:appcompat-v7:$support_version"
implementation
"com.android.support:design:$support_version"
implementation
'com.r0adkll:slidableactivity:2.0.5'
// LeakCanary
debugImplementation
"com.squareup.leakcanary:leakcanary-android:$leakcanary_version"
releaseImplementation
"com.squareup.leakcanary:leakcanary-android-no-op:$leakcanary_version"
// implementation 'com.blankj:utilcode:1.12.5'
// implementation 'com.blankj:utilcode:1.12.5'
}
app/src/main/AndroidManifest.xml
浏览文件 @
72d84e43
...
...
@@ -37,7 +37,6 @@
<!--screen-->
<uses-permission
android:name=
"android.permission.WRITE_SETTINGS"
/>
<!--flashlight-->
<uses-permission
android:name=
"android.permission.CAMERA"
/>
...
...
@@ -181,6 +180,9 @@
<activity
android:name=
".feature.sub.SubUtilActivity"
android:launchMode=
"singleTop"
/>
<activity
android:name=
".feature.sub.brightness.BrightnessActivity"
android:launchMode=
"singleTop"
/>
<activity
android:name=
".feature.sub.location.LocationActivity"
android:launchMode=
"singleTop"
/>
...
...
app/src/main/java/com/blankj/androidutilcode/UtilsApp.java
浏览文件 @
72d84e43
...
...
@@ -9,7 +9,6 @@ import com.blankj.androidutilcode.base.BaseApplication;
import
com.blankj.utilcode.util.ActivityUtils
;
import
com.blankj.utilcode.util.CrashUtils
;
import
com.blankj.utilcode.util.LogUtils
;
import
com.blankj.utilcode.util.PermissionUtils
;
import
com.squareup.leakcanary.LeakCanary
;
/**
...
...
@@ -37,8 +36,6 @@ public class UtilsApp extends BaseApplication {
initLeakCanary
();
initLog
();
initCrash
();
LogUtils
.
d
(
PermissionUtils
.
getPermissions
());
}
private
void
initLeakCanary
()
{
...
...
@@ -53,7 +50,7 @@ public class UtilsApp extends BaseApplication {
// init it in ur application
public
void
initLog
()
{
LogUtils
.
Config
config
=
LogUtils
.
getConfig
()
final
LogUtils
.
Config
config
=
LogUtils
.
getConfig
()
.
setLogSwitch
(
BuildConfig
.
DEBUG
)
// 设置 log 总开关,包括输出到控制台和文件,默认开
.
setConsoleSwitch
(
BuildConfig
.
DEBUG
)
// 设置是否输出到控制台开关,默认开
.
setGlobalTag
(
null
)
// 设置 log 全局标签,默认为空
...
...
@@ -67,7 +64,13 @@ public class UtilsApp extends BaseApplication {
.
setConsoleFilter
(
LogUtils
.
V
)
// log 的控制台过滤器,和 logcat 过滤器同理,默认 Verbose
.
setFileFilter
(
LogUtils
.
V
)
// log 文件过滤器,和 logcat 过滤器同理,默认 Verbose
.
setStackDeep
(
1
);
// log 栈深度,默认为 1
LogUtils
.
d
(
config
.
toString
());
new
Thread
(
new
Runnable
()
{
@Override
public
void
run
()
{
LogUtils
.
d
(
config
.
toString
());
}
}).
start
();
}
private
void
initCrash
()
{
...
...
app/src/main/java/com/blankj/androidutilcode/feature/core/activity/ActivityActivity.java
浏览文件 @
72d84e43
...
...
@@ -18,6 +18,7 @@ import com.blankj.androidutilcode.base.BaseBackActivity;
import
com.blankj.androidutilcode.feature.core.CoreUtilActivity
;
import
com.blankj.androidutilcode.MainActivity
;
import
com.blankj.utilcode.util.ActivityUtils
;
import
com.blankj.utilcode.util.LogUtils
;
import
com.blankj.utilcode.util.SpanUtils
;
import
java.util.Random
;
...
...
@@ -225,7 +226,7 @@ public class ActivityActivity extends BaseBackActivity {
case
R
.
id
.
btn_act_intents_opt
:
ActivityUtils
.
startActivities
(
this
,
intents
,
getOption
(
random
.
nextInt
(
3
)));
getOption
(
random
.
nextInt
(
5
)));
break
;
case
R
.
id
.
btn_act_intents_anim
:
ActivityUtils
.
startActivities
(
this
,
...
...
@@ -248,6 +249,7 @@ public class ActivityActivity extends BaseBackActivity {
}
private
Bundle
getOption
(
int
type
)
{
LogUtils
.
d
(
type
);
switch
(
type
)
{
case
0
:
return
ActivityOptionsCompat
.
makeCustomAnimation
(
this
,
...
...
@@ -266,16 +268,16 @@ public class ActivityActivity extends BaseBackActivity {
0
,
0
)
.
toBundle
();
case
3
:
return
ActivityOptionsCompat
.
makeSceneTransitionAnimation
(
this
,
viewSharedElement
,
getString
(
R
.
string
.
activity_shared_element
))
.
toBundle
();
case
4
:
return
ActivityOptionsCompat
.
makeClipRevealAnimation
(
viewSharedElement
,
viewSharedElement
.
getWidth
()
/
2
,
viewSharedElement
.
getHeight
()
/
2
,
0
,
0
)
.
toBundle
();
case
4
:
return
ActivityOptionsCompat
.
makeSceneTransitionAnimation
(
this
,
viewSharedElement
,
getString
(
R
.
string
.
activity_shared_element
))
.
toBundle
();
default
:
return
null
;
}
...
...
app/src/main/java/com/blankj/androidutilcode/feature/core/bar/BarStatusActivity.java
浏览文件 @
72d84e43
...
...
@@ -46,6 +46,8 @@ public class BarStatusActivity extends BaseBackActivity {
tvAboutStatus
=
findViewById
(
R
.
id
.
tv_about_status
);
findViewById
(
R
.
id
.
btn_show_status
).
setOnClickListener
(
this
);
findViewById
(
R
.
id
.
btn_hide_status
).
setOnClickListener
(
this
);
findViewById
(
R
.
id
.
btn_light_mode
).
setOnClickListener
(
this
);
findViewById
(
R
.
id
.
btn_dark_mode
).
setOnClickListener
(
this
);
updateAboutStatus
();
}
...
...
@@ -63,6 +65,12 @@ public class BarStatusActivity extends BaseBackActivity {
case
R
.
id
.
btn_hide_status
:
BarUtils
.
setStatusBarVisibility
(
this
,
false
);
break
;
case
R
.
id
.
btn_light_mode
:
BarUtils
.
setStatusBarLightMode
(
this
,
true
);
break
;
case
R
.
id
.
btn_dark_mode
:
BarUtils
.
setStatusBarLightMode
(
this
,
false
);
break
;
}
updateAboutStatus
();
}
...
...
app/src/main/java/com/blankj/androidutilcode/feature/core/bar/BarStatusAlphaFragment.java
浏览文件 @
72d84e43
...
...
@@ -43,8 +43,8 @@ public class BarStatusAlphaFragment extends BaseFragment {
@Override
public
void
initView
(
Bundle
savedInstanceState
,
View
view
)
{
fakeStatusBar
=
view
.
findViewById
(
R
.
id
.
fake_status_bar
);
mTvStatusAlpha
=
(
TextView
)
view
.
findViewById
(
R
.
id
.
tv_status_alpha
);
sbChangeAlpha
=
(
SeekBar
)
view
.
findViewById
(
R
.
id
.
sb_change_alpha
);
mTvStatusAlpha
=
view
.
findViewById
(
R
.
id
.
tv_status_alpha
);
sbChangeAlpha
=
view
.
findViewById
(
R
.
id
.
sb_change_alpha
);
view
.
findViewById
(
R
.
id
.
btn_set_transparent
).
setOnClickListener
(
this
);
sbChangeAlpha
.
setOnSeekBarChangeListener
(
translucentListener
);
mTvStatusAlpha
.
setText
(
String
.
valueOf
(
mAlpha
));
...
...
app/src/main/java/com/blankj/androidutilcode/feature/core/permission/PermissionActivity.java
浏览文件 @
72d84e43
...
...
@@ -92,6 +92,7 @@ public class PermissionActivity extends BaseBackActivity {
@Override
public
void
onGranted
(
List
<
String
>
permissionsGranted
)
{
updateAboutPermission
();
LogUtils
.
d
(
permissionsGranted
);
}
@Override
...
...
@@ -123,6 +124,7 @@ public class PermissionActivity extends BaseBackActivity {
@Override
public
void
onGranted
(
List
<
String
>
permissionsGranted
)
{
updateAboutPermission
();
LogUtils
.
d
(
permissionsGranted
);
}
@Override
...
...
app/src/main/java/com/blankj/androidutilcode/feature/core/screen/ScreenActivity.java
浏览文件 @
72d84e43
...
...
@@ -8,7 +8,7 @@ import android.widget.ImageView;
import
android.widget.TextView
;
import
com.blankj.androidutilcode.R
;
import
com.blankj.androidutilcode.base.Base
Back
Activity
;
import
com.blankj.androidutilcode.base.BaseActivity
;
import
com.blankj.utilcode.util.ScreenUtils
;
import
com.blankj.utilcode.util.SpanUtils
;
...
...
@@ -20,9 +20,10 @@ import com.blankj.utilcode.util.SpanUtils;
* desc : Screen 工具类 Demo
* </pre>
*/
public
class
ScreenActivity
extends
Base
Back
Activity
{
public
class
ScreenActivity
extends
BaseActivity
{
ImageView
ivScreenshot
;
TextView
tvAboutScreen
;
public
static
void
start
(
Context
context
)
{
Intent
starter
=
new
Intent
(
context
,
ScreenActivity
.
class
);
...
...
@@ -36,31 +37,20 @@ public class ScreenActivity extends BaseBackActivity {
@Override
public
int
bindLayout
()
{
return
R
.
layout
.
activity_
screen
;
return
R
.
layout
.
activity_
brightness
;
}
@Override
public
void
initView
(
Bundle
savedInstanceState
,
View
view
)
{
getToolBar
().
setTitle
(
getString
(
R
.
string
.
demo_sdcard
)
);
ivScreenshot
=
findViewById
(
R
.
id
.
iv_screenshot
);
tvAboutScreen
=
findViewById
(
R
.
id
.
tv_about_screen
);
findViewById
(
R
.
id
.
btn_set_fullscreen
).
setOnClickListener
(
this
);
findViewById
(
R
.
id
.
btn_set_landscape
).
setOnClickListener
(
this
);
findViewById
(
R
.
id
.
btn_set_portrait
).
setOnClickListener
(
this
);
findViewById
(
R
.
id
.
btn_screenshot
).
setOnClickListener
(
this
);
findViewById
(
R
.
id
.
btn_set_sleep_duration
).
setOnClickListener
(
this
);
ivScreenshot
=
findViewById
(
R
.
id
.
iv_screenshot
);
TextView
tvAboutSdcard
=
findViewById
(
R
.
id
.
tv_about_screen
);
tvAboutSdcard
.
setText
(
new
SpanUtils
()
.
appendLine
(
"getScreenWidth: "
+
ScreenUtils
.
getScreenWidth
())
.
appendLine
(
"getScreenHeight: "
+
ScreenUtils
.
getScreenHeight
())
.
appendLine
(
"isLandscape: "
+
ScreenUtils
.
isLandscape
())
.
appendLine
(
"isPortrait: "
+
ScreenUtils
.
isPortrait
())
.
appendLine
(
"getScreenRotation: "
+
ScreenUtils
.
getScreenRotation
(
this
))
.
appendLine
(
"isScreenLock: "
+
ScreenUtils
.
isScreenLock
())
.
appendLine
(
"getSleepDuration: "
+
ScreenUtils
.
getSleepDuration
())
.
append
(
"isTablet: "
+
ScreenUtils
.
isTablet
())
.
create
()
);
updateAboutScreen
();
}
@Override
...
...
@@ -85,7 +75,22 @@ public class ScreenActivity extends BaseBackActivity {
break
;
case
R
.
id
.
btn_set_sleep_duration
:
ScreenUtils
.
setSleepDuration
(
100000
);
updateAboutScreen
();
break
;
}
}
private
void
updateAboutScreen
()
{
tvAboutScreen
.
setText
(
new
SpanUtils
()
.
appendLine
(
"getScreenWidth: "
+
ScreenUtils
.
getScreenWidth
())
.
appendLine
(
"getScreenHeight: "
+
ScreenUtils
.
getScreenHeight
())
.
appendLine
(
"isLandscape: "
+
ScreenUtils
.
isLandscape
())
.
appendLine
(
"isPortrait: "
+
ScreenUtils
.
isPortrait
())
.
appendLine
(
"getScreenRotation: "
+
ScreenUtils
.
getScreenRotation
(
this
))
.
appendLine
(
"isScreenLock: "
+
ScreenUtils
.
isScreenLock
())
.
appendLine
(
"getSleepDuration: "
+
ScreenUtils
.
getSleepDuration
())
.
append
(
"isTablet: "
+
ScreenUtils
.
isTablet
())
.
create
()
);
}
}
app/src/main/java/com/blankj/androidutilcode/feature/sub/SubUtilActivity.java
浏览文件 @
72d84e43
...
...
@@ -7,6 +7,7 @@ import android.view.View;
import
com.blankj.androidutilcode.R
;
import
com.blankj.androidutilcode.base.BaseBackActivity
;
import
com.blankj.androidutilcode.feature.sub.brightness.BrightnessActivity
;
import
com.blankj.androidutilcode.feature.sub.location.LocationActivity
;
import
com.blankj.androidutilcode.feature.sub.pinyin.PinyinActivity
;
...
...
@@ -50,6 +51,10 @@ public class SubUtilActivity extends BaseBackActivity {
}
public
void
brightnessClick
(
View
view
)
{
BrightnessActivity
.
start
(
this
);
}
public
void
locationClick
(
View
view
)
{
LocationActivity
.
start
(
this
);
}
...
...
app/src/main/java/com/blankj/androidutilcode/feature/sub/brightness/BrightnessActivity.java
0 → 100644
浏览文件 @
72d84e43
package
com.blankj.androidutilcode.feature.sub.brightness
;
import
android.content.Context
;
import
android.content.Intent
;
import
android.net.Uri
;
import
android.os.Build
;
import
android.os.Bundle
;
import
android.provider.Settings
;
import
android.view.View
;
import
android.widget.CompoundButton
;
import
android.widget.SeekBar
;
import
android.widget.TextView
;
import
android.widget.ToggleButton
;
import
com.blankj.androidutilcode.R
;
import
com.blankj.androidutilcode.base.BaseActivity
;
import
com.blankj.subutil.util.BrightnessUtils
;
import
com.blankj.subutil.util.Utils
;
import
com.blankj.utilcode.util.SpanUtils
;
/**
* <pre>
* author: Blankj
* blog : http://blankj.com
* time : 2018/02/08
* desc :
* </pre>
*/
public
class
BrightnessActivity
extends
BaseActivity
{
TextView
tvBrightness
;
SeekBar
sbBrightness
;
TextView
tvWindowBrightness
;
SeekBar
sbWindowBrightness
;
ToggleButton
tbAutoBrightness
;
private
SeekBar
.
OnSeekBarChangeListener
brightnessChangeListener
=
new
SeekBar
.
OnSeekBarChangeListener
()
{
@Override
public
void
onProgressChanged
(
SeekBar
seekBar
,
int
progress
,
boolean
fromUser
)
{
BrightnessUtils
.
setBrightness
(
progress
);
updateBrightness
();
}
@Override
public
void
onStartTrackingTouch
(
SeekBar
seekBar
)
{
}
@Override
public
void
onStopTrackingTouch
(
SeekBar
seekBar
)
{
}
};
private
SeekBar
.
OnSeekBarChangeListener
windowBrightnessChangeListener
=
new
SeekBar
.
OnSeekBarChangeListener
()
{
@Override
public
void
onProgressChanged
(
SeekBar
seekBar
,
int
progress
,
boolean
fromUser
)
{
BrightnessUtils
.
setWindowBrightness
(
getWindow
(),
progress
);
updateWindowBrightness
();
}
@Override
public
void
onStartTrackingTouch
(
SeekBar
seekBar
)
{
}
@Override
public
void
onStopTrackingTouch
(
SeekBar
seekBar
)
{
}
};
public
static
void
start
(
Context
context
)
{
Intent
starter
=
new
Intent
(
context
,
BrightnessActivity
.
class
);
context
.
startActivity
(
starter
);
}
@Override
public
void
initData
(
Bundle
bundle
)
{
}
@Override
public
int
bindLayout
()
{
return
R
.
layout
.
activity_brightness
;
}
@Override
public
void
initView
(
Bundle
savedInstanceState
,
View
view
)
{
tvBrightness
=
findViewById
(
R
.
id
.
tv_brightness
);
sbBrightness
=
findViewById
(
R
.
id
.
sb_brightness
);
tvWindowBrightness
=
findViewById
(
R
.
id
.
tv_window_brightness
);
sbWindowBrightness
=
findViewById
(
R
.
id
.
sb_window_brightness
);
tbAutoBrightness
=
findViewById
(
R
.
id
.
tb_set_auto_brightness_enable
);
sbBrightness
.
setProgress
(
BrightnessUtils
.
getBrightness
());
sbBrightness
.
setOnSeekBarChangeListener
(
brightnessChangeListener
);
updateBrightness
();
sbWindowBrightness
.
setProgress
(
BrightnessUtils
.
getWindowBrightness
(
getWindow
()));
sbWindowBrightness
.
setOnSeekBarChangeListener
(
windowBrightnessChangeListener
);
updateWindowBrightness
();
tbAutoBrightness
.
setChecked
(
BrightnessUtils
.
isAutoBrightnessEnabled
());
tbAutoBrightness
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
@Override
public
void
onClick
(
View
v
)
{
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
M
&&
!
Settings
.
System
.
canWrite
(
Utils
.
getApp
()))
{
Intent
intent
=
new
Intent
(
android
.
provider
.
Settings
.
ACTION_MANAGE_WRITE_SETTINGS
);
intent
.
setData
(
Uri
.
parse
(
"package:"
+
Utils
.
getApp
().
getPackageName
()));
intent
.
addFlags
(
Intent
.
FLAG_ACTIVITY_NEW_TASK
);
Utils
.
getApp
().
startActivity
(
intent
);
}
}
});
tbAutoBrightness
.
setOnCheckedChangeListener
(
new
CompoundButton
.
OnCheckedChangeListener
()
{
@Override
public
void
onCheckedChanged
(
CompoundButton
buttonView
,
boolean
isChecked
)
{
boolean
isSuccess
=
BrightnessUtils
.
setAutoBrightnessEnabled
(
isChecked
);
if
(!
isSuccess
)
{
tbAutoBrightness
.
toggle
();
}
}
});
}
@Override
public
void
doBusiness
()
{
}
@Override
public
void
onWidgetClick
(
View
view
)
{
}
private
void
updateBrightness
()
{
tvBrightness
.
setText
(
new
SpanUtils
()
.
append
(
String
.
valueOf
(
BrightnessUtils
.
getBrightness
()))
.
create
()
);
}
private
void
updateWindowBrightness
()
{
tvWindowBrightness
.
setText
(
new
SpanUtils
()
.
append
(
String
.
valueOf
(
BrightnessUtils
.
getWindowBrightness
(
getWindow
())))
.
create
()
);
}
}
app/src/main/res_core/layout/activity_bar_status.xml
浏览文件 @
72d84e43
...
...
@@ -27,4 +27,18 @@
android:layout_height=
"wrap_content"
android:text=
"@string/bar_status_hide"
/>
<Button
android:id=
"@+id/btn_light_mode"
style=
"@style/WideBtnStyle"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:text=
"@string/bar_status_light_mode"
/>
<Button
android:id=
"@+id/btn_dark_mode"
style=
"@style/WideBtnStyle"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:text=
"@string/bar_status_dark_mode"
/>
</LinearLayout>
app/src/main/res_core/layout/activity_screen.xml
浏览文件 @
72d84e43
<?xml version="1.0" encoding="utf-8"?>
<
LinearLayout
<
ScrollView
xmlns:android=
"http://schemas.android.com/apk/res/android"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:gravity=
"center_horizontal"
android:orientation=
"vertical"
android:padding=
"@dimen/spacing_16"
>
<TextView
android:id=
"@+id/tv_about_screen"
style=
"@style/TextStyle"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
/>
<Button
android:id=
"@+id/btn_set_fullscreen"
style=
"@style/WideBtnStyle"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:text=
"@string/screen_set_fullscreen"
/>
<Button
android:id=
"@+id/btn_set_landscape"
style=
"@style/WideBtnStyle"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:text=
"@string/screen_set_landscape"
/>
<Button
android:id=
"@+id/btn_set_portrait"
style=
"@style/WideBtnStyle"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:text=
"@string/screen_set_portrait"
/>
<Button
android:id=
"@+id/btn_screenshot"
style=
"@style/WideBtnStyle"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:text=
"@string/screen_screenshot"
/>
android:layout_height=
"match_parent"
android:background=
"@color/white"
>
<Button
android:id=
"@+id/btn_set_sleep_duration"
style=
"@style/WideBtnStyle"
<LinearLayout
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:text=
"@string/screen_set_sleep_duration"
/>
<ImageView
android:id=
"@+id/iv_screenshot"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
/>
</LinearLayout>
android:gravity=
"center_horizontal"
android:orientation=
"vertical"
android:paddingLeft=
"@dimen/spacing_16"
android:paddingRight=
"@dimen/spacing_16"
>
<ImageView
android:id=
"@+id/iv_screenshot"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
/>
<TextView
android:id=
"@+id/tv_about_screen"
style=
"@style/TextStyle"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
/>
<Button
android:id=
"@+id/btn_set_fullscreen"
style=
"@style/WideBtnStyle"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:text=
"@string/screen_set_fullscreen"
/>
<Button
android:id=
"@+id/btn_set_landscape"
style=
"@style/WideBtnStyle"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:text=
"@string/screen_set_landscape"
/>
<Button
android:id=
"@+id/btn_set_portrait"
style=
"@style/WideBtnStyle"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:text=
"@string/screen_set_portrait"
/>
<Button
android:id=
"@+id/btn_screenshot"
style=
"@style/WideBtnStyle"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:text=
"@string/screen_screenshot"
/>
<Button
android:id=
"@+id/btn_set_sleep_duration"
style=
"@style/WideBtnStyle"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:text=
"@string/screen_set_sleep_duration"
/>
</LinearLayout>
</ScrollView>
\ No newline at end of file
app/src/main/res_core/values/strings.xml
浏览文件 @
72d84e43
...
...
@@ -77,6 +77,8 @@
<string
name=
"bar_status_about"
>
About Status
</string>
<string
name=
"bar_status_show"
>
Show Status
</string>
<string
name=
"bar_status_hide"
>
Hide Status
</string>
<string
name=
"bar_status_light_mode"
>
Light Mode Status
</string>
<string
name=
"bar_status_dark_mode"
>
Dark Mode Status
</string>
<string
name=
"bar_status_set_color"
>
Set Color
</string>
<string
name=
"bar_status_set_alpha"
>
Set Alpha
</string>
<string
name=
"bar_status_set_image_view"
>
Set Image View
</string>
...
...
app/src/main/res_sub/layout/activity_brightness.xml
0 → 100644
浏览文件 @
72d84e43
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android=
"http://schemas.android.com/apk/res/android"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
android:background=
"@color/white"
>
<LinearLayout
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:gravity=
"center_horizontal"
android:orientation=
"vertical"
android:paddingLeft=
"@dimen/spacing_16"
android:paddingRight=
"@dimen/spacing_16"
>
<TextView
android:id=
"@+id/tv_brightness"
style=
"@style/TextStyle"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_gravity=
"center_horizontal"
/>
<SeekBar
android:id=
"@+id/sb_brightness"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:max=
"255"
android:padding=
"@dimen/spacing_8"
/>
<TextView
android:id=
"@+id/tv_window_brightness"
style=
"@style/TextStyle"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_gravity=
"center_horizontal"
/>
<SeekBar
android:id=
"@+id/sb_window_brightness"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:max=
"255"
android:padding=
"@dimen/spacing_8"
/>
<ToggleButton
android:id=
"@+id/tb_set_auto_brightness_enable"
style=
"@style/WideBtnStyle"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:textOff=
"@string/brightness_set_auto_brightness_enable"
android:textOn=
"@string/brightness_set_auto_brightness_disable"
/>
</LinearLayout>
</ScrollView>
\ No newline at end of file
app/src/main/res_sub/layout/activity_util_sub.xml
浏览文件 @
72d84e43
...
...
@@ -16,6 +16,13 @@
<!--android:text="@string/demo_flashlight"-->
<!--/>-->
<Button
style=
"@style/WideBtnStyle"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:onClick=
"brightnessClick"
android:text=
"@string/demo_brightness"
/>
<Button
style=
"@style/WideBtnStyle"
android:layout_width=
"match_parent"
...
...
app/src/main/res_sub/values/strings.xml
浏览文件 @
72d84e43
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string
name=
"demo_flashlight"
>
FlashlightUtils Demo
</string>
<string
name=
"demo_brightness"
>
Brightness Demo
</string>
<string
name=
"demo_location"
>
LocationUtils Demo
</string>
<string
name=
"demo_pinyin"
>
PinyinUtils Demo
</string>
<!--Flashlight相关-->
<!-- Brightness 相关 -->
<string
name=
"brightness_set_auto_brightness_enable"
>
Set Auto Brightness Enable
</string>
<string
name=
"brightness_set_auto_brightness_disable"
>
Set Auto Brightness Disable
</string>
<!-- Flashlight相关 -->
<string
name=
"flashlight_open"
>
Open Flashlight
</string>
<string
name=
"flashlight_close"
>
Close Flashlight
</string>
...
...
build.gradle
浏览文件 @
72d84e43
...
...
@@ -9,12 +9,15 @@ buildscript {
classpath
'com.android.tools.build:gradle:3.0.1'
classpath
'com.github.dcendents:android-maven-gradle-plugin:1.5'
classpath
'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3'
classpath
"tech.harmonysoft:traute-gradle:1.1.8"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects
{
apply
plugin:
"tech.harmonysoft.oss.traute"
repositories
{
google
()
jcenter
()
...
...
@@ -43,7 +46,7 @@ ext {
junit_version
=
'4.12'
robolectric_version
=
'3.1.2'
trauteVersion
=
'1.
0.10
'
trauteVersion
=
'1.
1.8
'
}
subutil/README-CN.md
浏览文件 @
72d84e43
...
...
@@ -5,6 +5,16 @@
## APIs
*
### 亮度相关 ->
[
BrightnessUtils.java
][
brightness.java
]
->
[
Demo
][
brightness.demo
]
```
isAutoBrightnessEnabled : 判断是否开启自动调节亮度
setAutoBrightnessEnabled : 设置是否开启自动调节亮度
getBrightness : 获取屏幕亮度
setBrightness : 设置屏幕亮度
setWindowBrightness: 设置窗口亮度
getWindowBrightness : 获取窗口亮度
```
*
### 剪贴板相关 ->
[
ClipboardUtils.java
][
clipboard.java
]
->
[
Test
][
clipboard.test
]
```
copyText : 复制文本到剪贴板
...
...
@@ -59,10 +69,14 @@ scheduleWithFixedRate : 延迟并循环执行命令
scheduleWithFixedDelay: 延迟并以固定休息时间循环执行命令
```
[
brightness.java
]:
https://github.com/Blankj/AndroidUtilCode/blob/master/subutil/src/main/java/com/blankj/subutil/util/BrightnessUtils.java
[
brightness.test
]:
https://github.com/Blankj/AndroidUtilCode/blob/master/app/src/main/java/com/blankj/androidutilcode/feature/sub/brightness/BrightnessActivity.java
[
clipboard.java
]:
https://github.com/Blankj/AndroidUtilCode/blob/master/subutil/src/main/java/com/blankj/subutil/util/ClipboardUtils.java
[
clipboard.test
]:
https://github.com/Blankj/AndroidUtilCode/blob/master/subutil/src/test/java/com/blankj/subutil/util/ClipboardUtilsTest.java
[
location.java
]:
https://github.com/Blankj/AndroidUtilCode/blob/master/subutil/src/main/java/com/blankj/subutil/util/LocationUtils.java
[
location.demo
]:
https://github.com/Blankj/AndroidUtilCode/blob/master/app/src/main/java/com/blankj/androidutilcode/feature/sub/location/LocationActivity.java
...
...
subutil/build.gradle
浏览文件 @
72d84e43
plugins
{
id
"tech.harmonysoft.oss.traute"
version
'1.0.5'
}
apply
plugin:
'com.android.library'
apply
plugin:
'jacoco'
...
...
@@ -45,7 +42,6 @@ android {
abortOnError
false
}
testOptions
.
unitTests
.
all
{
testLogging
{
events
'passed'
,
'skipped'
,
'failed'
,
'standardOut'
,
'standardError'
...
...
@@ -53,10 +49,6 @@ android {
}
}
traute
{
javacPluginVersion
=
trauteVersion
}
dependencies
{
compileOnly
"com.android.support:appcompat-v7:$support_version"
compileOnly
"com.android.support:design:$support_version"
...
...
subutil/src/main/java/com/blankj/subutil/util/BrightnessUtils.java
0 → 100644
浏览文件 @
72d84e43
package
com.blankj.subutil.util
;
import
android.content.ContentResolver
;
import
android.content.Intent
;
import
android.net.Uri
;
import
android.os.Build
;
import
android.provider.Settings
;
import
android.support.annotation.IntRange
;
import
android.support.annotation.NonNull
;
import
android.view.Window
;
import
android.view.WindowManager
;
/**
* <pre>
* author: Blankj
* blog : http://blankj.com
* time : 2018/02/08
* desc : 亮度相关工具类
* </pre>
*/
public
class
BrightnessUtils
{
private
BrightnessUtils
()
{
throw
new
UnsupportedOperationException
(
"u can't instantiate me..."
);
}
/**
* 判断是否开启自动调节亮度
*
* @return {@code true}: 是<br>{@code false}: 否
*/
public
static
boolean
isAutoBrightnessEnabled
()
{
try
{
int
mode
=
Settings
.
System
.
getInt
(
Utils
.
getApp
().
getContentResolver
(),
Settings
.
System
.
SCREEN_BRIGHTNESS_MODE
);
return
mode
==
Settings
.
System
.
SCREEN_BRIGHTNESS_MODE_AUTOMATIC
;
}
catch
(
Settings
.
SettingNotFoundException
e
)
{
e
.
printStackTrace
();
return
false
;
}
}
/**
* 设置是否开启自动调节亮度
* <p>需添加权限 {@code <uses-permission android:name="android.permission.WRITE_SETTINGS" />}</p>
* 并得到授权
*
* @param enabled {@code true}: 打开<br>{@code false}: 关闭
* @return {@code true}: 成功<br>{@code false}: 失败
*/
public
static
boolean
setAutoBrightnessEnabled
(
final
boolean
enabled
)
{
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
M
&&
!
Settings
.
System
.
canWrite
(
Utils
.
getApp
()))
{
Intent
intent
=
new
Intent
(
android
.
provider
.
Settings
.
ACTION_MANAGE_WRITE_SETTINGS
);
intent
.
setData
(
Uri
.
parse
(
"package:"
+
Utils
.
getApp
().
getPackageName
()));
intent
.
addFlags
(
Intent
.
FLAG_ACTIVITY_NEW_TASK
);
Utils
.
getApp
().
startActivity
(
intent
);
return
false
;
}
return
Settings
.
System
.
putInt
(
Utils
.
getApp
().
getContentResolver
(),
Settings
.
System
.
SCREEN_BRIGHTNESS_MODE
,
enabled
?
Settings
.
System
.
SCREEN_BRIGHTNESS_MODE_AUTOMATIC
:
Settings
.
System
.
SCREEN_BRIGHTNESS_MODE_MANUAL
);
}
/**
* 获取屏幕亮度
*
* @return 屏幕亮度 0-255
*/
public
static
int
getBrightness
()
{
try
{
return
Settings
.
System
.
getInt
(
Utils
.
getApp
().
getContentResolver
(),
Settings
.
System
.
SCREEN_BRIGHTNESS
);
}
catch
(
Settings
.
SettingNotFoundException
e
)
{
e
.
printStackTrace
();
return
0
;
}
}
/**
* 设置屏幕亮度
* <p>需添加权限 {@code <uses-permission android:name="android.permission.WRITE_SETTINGS" />}</p>
* 并得到授权
*
* @param brightness 亮度值
*/
public
static
void
setBrightness
(
@IntRange
(
from
=
0
,
to
=
255
)
final
int
brightness
)
{
ContentResolver
resolver
=
Utils
.
getApp
().
getContentResolver
();
Settings
.
System
.
putInt
(
resolver
,
Settings
.
System
.
SCREEN_BRIGHTNESS
,
brightness
);
resolver
.
notifyChange
(
Settings
.
System
.
getUriFor
(
"screen_brightness"
),
null
);
}
/**
* 设置窗口亮度
*
* @param window 窗口
* @param brightness 亮度值
*/
public
static
void
setWindowBrightness
(
@NonNull
final
Window
window
,
@IntRange
(
from
=
0
,
to
=
255
)
final
int
brightness
)
{
WindowManager
.
LayoutParams
lp
=
window
.
getAttributes
();
lp
.
screenBrightness
=
brightness
/
255
f
;
window
.
setAttributes
(
lp
);
}
/**
* 获取窗口亮度
*
* @param window 窗口
* @return 屏幕亮度 0-255
*/
public
static
int
getWindowBrightness
(
final
Window
window
)
{
WindowManager
.
LayoutParams
lp
=
window
.
getAttributes
();
float
brightness
=
lp
.
screenBrightness
;
if
(
brightness
<
0
)
return
getBrightness
();
return
(
int
)
(
brightness
*
255
);
}
}
subutil/src/main/java/com/blankj/subutil/util/LocationUtils.java
浏览文件 @
72d84e43
...
...
@@ -50,6 +50,7 @@ public final class LocationUtils {
// * @return {@code Location}
// */
//
// @SuppressLint("MissingPermission")
// public static Location getLocation(Context context, LocationListener listener) {
// Location location = null;
// try {
...
...
@@ -111,7 +112,7 @@ public final class LocationUtils {
*/
public
static
boolean
isGpsEnabled
()
{
LocationManager
lm
=
(
LocationManager
)
Utils
.
getApp
().
getSystemService
(
LOCATION_SERVICE
);
return
lm
.
isProviderEnabled
(
LocationManager
.
GPS_PROVIDER
);
return
lm
!=
null
&&
lm
.
isProviderEnabled
(
LocationManager
.
GPS_PROVIDER
);
}
/**
...
...
@@ -122,9 +123,8 @@ public final class LocationUtils {
public
static
boolean
isLocationEnabled
()
{
LocationManager
lm
=
(
LocationManager
)
Utils
.
getApp
().
getSystemService
(
LOCATION_SERVICE
);
return
lm
!=
null
&&
(
lm
.
isProviderEnabled
(
LocationManager
.
NETWORK_PROVIDER
)
||
lm
.
isProviderEnabled
(
LocationManager
.
GPS_PROVIDER
)
&&
(
lm
.
isProviderEnabled
(
LocationManager
.
NETWORK_PROVIDER
)
||
lm
.
isProviderEnabled
(
LocationManager
.
GPS_PROVIDER
)
);
}
...
...
@@ -155,20 +155,21 @@ public final class LocationUtils {
public
static
boolean
register
(
long
minTime
,
long
minDistance
,
OnLocationChangeListener
listener
)
{
if
(
listener
==
null
)
return
false
;
mLocationManager
=
(
LocationManager
)
Utils
.
getApp
().
getSystemService
(
LOCATION_SERVICE
);
mListener
=
listener
;
if
(!
isLocationEnabled
())
{
if
(
mLocationManager
==
null
||
(!
mLocationManager
.
isProviderEnabled
(
LocationManager
.
NETWORK_PROVIDER
)
&&
!
mLocationManager
.
isProviderEnabled
(
LocationManager
.
GPS_PROVIDER
)))
{
Log
.
d
(
"LocationUtils"
,
"无法定位,请打开定位服务"
);
return
false
;
}
mListener
=
listener
;
String
provider
=
mLocationManager
.
getBestProvider
(
getCriteria
(),
true
);
@SuppressLint
(
"MissingPermission"
)
Location
location
=
mLocationManager
.
getLastKnownLocation
(
provider
);
Location
location
=
mLocationManager
.
getLastKnownLocation
(
provider
);
if
(
location
!=
null
)
listener
.
getLastKnownLocation
(
location
);
if
(
myLocationListener
==
null
)
myLocationListener
=
new
MyLocationListener
();
mLocationManager
.
requestLocationUpdates
(
provider
,
minTime
,
minDistance
,
myLocationListener
);
return
true
;
}
/**
* 注销
*/
...
...
@@ -181,6 +182,9 @@ public final class LocationUtils {
}
mLocationManager
=
null
;
}
if
(
mListener
!=
null
)
{
mListener
=
null
;
}
}
/**
...
...
update_log.md
浏览文件 @
72d84e43
*
18/02/10 完善中文版为英文版
*
18/02/09 完善非空转换插件 traute 的使用方式
*
18/02/08 修复 ActivityUtils option 低版本为空的异常
*
18/01/31 修复 default 相关的逻辑错误,发布 1.12.4,修复 ToastUtils 在 kotlin 中转义失败,发布 1.12.5
*
18/01/28 修复 ToastUtils 默认样式问题,发布 1.12.2,新增 DeviceUtils#getSDKVersionName,发布 1.12.3
*
18/01/27 修复 PermissionUtils 某些机型闪烁问题,发布 1.12.1
...
...
utilcode/build.gradle
浏览文件 @
72d84e43
plugins
{
id
"tech.harmonysoft.oss.traute"
version
'1.0.5'
}
apply
plugin:
'com.android.library'
apply
plugin:
'jacoco'
...
...
@@ -52,10 +49,6 @@ android {
}
}
traute
{
javacPluginVersion
=
trauteVersion
}
dependencies
{
compileOnly
"com.android.support:appcompat-v7:$support_version"
compileOnly
"com.android.support:design:$support_version"
...
...
utilcode/src/main/java/com/blankj/utilcode/constant/MemoryConstants.java
浏览文件 @
72d84e43
...
...
@@ -10,26 +10,14 @@ import java.lang.annotation.RetentionPolicy;
* author: Blankj
* blog : http://blankj.com
* time : 2017/03/13
* desc :
存储相关常量
* desc :
The constants of memory
* </pre>
*/
public
final
class
MemoryConstants
{
/**
* Byte 与 Byte 的倍数
*/
public
static
final
int
BYTE
=
1
;
/**
* KB 与 Byte 的倍数
*/
public
static
final
int
KB
=
1024
;
/**
* MB 与 Byte 的倍数
*/
public
static
final
int
MB
=
1048576
;
/**
* GB 与 Byte 的倍数
*/
public
static
final
int
GB
=
1073741824
;
@IntDef
({
BYTE
,
KB
,
MB
,
GB
})
...
...
utilcode/src/main/java/com/blankj/utilcode/constant/PermissionConstants.java
浏览文件 @
72d84e43
...
...
@@ -14,7 +14,7 @@ import java.lang.annotation.RetentionPolicy;
* author: Blankj
* blog : http://blankj.com
* time : 2017/12/29
* desc :
权限相关常量
* desc :
The constants of permission
* </pre>
*/
@SuppressLint
(
"InlinedApi"
)
...
...
utilcode/src/main/java/com/blankj/utilcode/constant/RegexConstants.java
浏览文件 @
72d84e43
...
...
@@ -5,107 +5,110 @@ package com.blankj.utilcode.constant;
* author: Blankj
* blog : http://blankj.com
* time : 2017/03/13
* desc :
正则相关常量
* desc :
The constants of regex
* </pre>
*/
public
final
class
RegexConstants
{
/**
*
正则:手机号(简单)
*
regex of simple mobile
*/
public
static
final
String
REGEX_MOBILE_SIMPLE
=
"^[1]\\d{10}$"
;
/**
*
正则:手机号(精确)
* <p>
移动:134(0-8)、135、136、137、138、139、147、150、151、152、157、158、159、178、182、183、184、187、188、
198</p>
* <p>
联通:130、131、132、145、155、156、166、171、175、176、185、
186</p>
* <p>
电信:133、153、173、177、180、181、189、
199</p>
* <p>
全球星:
1349</p>
* <p>
虚拟运营商:
170</p>
*
regex of exact mobile
* <p>
china mobile: 134(0-8), 135, 136, 137, 138, 139, 147, 150, 151, 152, 157, 158, 159, 178, 182, 183, 184, 187, 188,
198</p>
* <p>
china unicom: 130, 131, 132, 145, 155, 156, 166, 171, 175, 176, 185,
186</p>
* <p>
china telecom: 133, 153, 173, 177, 180, 181, 189,
199</p>
* <p>
global star:
1349</p>
* <p>
virtual operator:
170</p>
*/
public
static
final
String
REGEX_MOBILE_EXACT
=
"^((13[0-9])|(14[5,7])|(15[0-3,5-9])|(16[6])|(17[0,1,3,5-8])|(18[0-9])|(19[8,9]))\\d{8}$"
;
/**
*
正则:电话号码
*
regex of telephone number
*/
public
static
final
String
REGEX_TEL
=
"^0\\d{2,3}[- ]?\\d{7,8}"
;
/**
*
正则:身份证号码 15 位
*
regex of id card number which length is 15
*/
public
static
final
String
REGEX_ID_CARD15
=
"^[1-9]\\d{7}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])\\d{3}$"
;
/**
*
正则:身份证号码 18 位
*
regex of id card number which length is 18
*/
public
static
final
String
REGEX_ID_CARD18
=
"^[1-9]\\d{5}[1-9]\\d{3}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])\\d{3}([0-9Xx])$"
;
/**
*
正则:邮箱
*
regex of email
*/
public
static
final
String
REGEX_EMAIL
=
"^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$"
;
/**
*
正则:URL
*
regex of url
*/
public
static
final
String
REGEX_URL
=
"[a-zA-z]+://[^\\s]*"
;
/**
*
正则:汉字
*
regex of Chinese character
*/
public
static
final
String
REGEX_ZH
=
"^[\\u4e00-\\u9fa5]+$"
;
/**
* 正则:用户名,取值范围为 a-z,A-Z,0-9,"_",汉字,不能以"_"结尾,用户名必须是 6-20 位
* regex of username
* <p>scope for "a-z", "A-Z", "0-9", "_", "Chinese character"</p>
* <p>can't end with "_"</p>
* <p>length is between 6 to 20</p>
*/
public
static
final
String
REGEX_USERNAME
=
"^[\\w\\u4e00-\\u9fa5]{6,20}(?<!_)$"
;
/**
*
正则:yyyy-MM-dd 格式的日期校验,已考虑平闰年
*
regex of date which pattern is "yyyy-MM-dd"
*/
public
static
final
String
REGEX_DATE
=
"^(?:(?!0000)[0-9]{4}-(?:(?:0[1-9]|1[0-2])-(?:0[1-9]|1[0-9]|2[0-8])|(?:0[13-9]|1[0-2])-(?:29|30)|(?:0[13578]|1[02])-31)|(?:[0-9]{2}(?:0[48]|[2468][048]|[13579][26])|(?:0[48]|[2468][048]|[13579][26])00)-02-29)$"
;
/**
*
正则:IP 地址
*
regex of ip address
*/
public
static
final
String
REGEX_IP
=
"((2[0-4]\\d|25[0-5]|[01]?\\d\\d?)\\.){3}(2[0-4]\\d|25[0-5]|[01]?\\d\\d?)"
;
///////////////////////////////////////////////////////////////////////////
//
以下摘自
http://tool.oschina.net/regex
//
the following comes from
http://tool.oschina.net/regex
///////////////////////////////////////////////////////////////////////////
/**
*
正则:双字节字符(包括汉字在内)
*
regex of double-byte characters
*/
public
static
final
String
REGEX_DOUBLE_BYTE_CHAR
=
"[^\\x00-\\xff]"
;
/**
*
正则:空白行
*
regex of blank line
*/
public
static
final
String
REGEX_BLANK_LINE
=
"\\n\\s*\\r"
;
/**
*
正则:QQ 号
*
regex of QQ number
*/
public
static
final
String
REGEX_
TENCENT_NUM
=
"[1-9][0-9]{4,}"
;
public
static
final
String
REGEX_
QQ_NUM
=
"[1-9][0-9]{4,}"
;
/**
*
正则:中国邮政编码
*
regex of postal code in China
*/
public
static
final
String
REGEX_
ZIP_CODE
=
"[1-9]\\d{5}(?!\\d)"
;
public
static
final
String
REGEX_
CHINA_POSTAL_CODE
=
"[1-9]\\d{5}(?!\\d)"
;
/**
*
正则:正整数
*
regex of positive integer
*/
public
static
final
String
REGEX_POSITIVE_INTEGER
=
"^[1-9]\\d*$"
;
/**
*
正则:负整数
*
regex of negative integer
*/
public
static
final
String
REGEX_NEGATIVE_INTEGER
=
"^-[1-9]\\d*$"
;
/**
*
正则:整数
*
regex of integer
*/
public
static
final
String
REGEX_INTEGER
=
"^-?[1-9]\\d*$"
;
/**
*
正则:非负整数(正整数 + 0)
*
regex of non-negative integer
*/
public
static
final
String
REGEX_NOT_NEGATIVE_INTEGER
=
"^[1-9]\\d*|0$"
;
/**
*
正则:非正整数(负整数 + 0)
*
regex of non-positive integer
*/
public
static
final
String
REGEX_NOT_POSITIVE_INTEGER
=
"^-[1-9]\\d*|0$"
;
/**
*
正则:正浮点数
*
regex of positive float
*/
public
static
final
String
REGEX_POSITIVE_FLOAT
=
"^[1-9]\\d*\\.\\d*|0\\.\\d*[1-9]\\d*$"
;
/**
*
正则:负浮点数
*
regex of negative float
*/
public
static
final
String
REGEX_NEGATIVE_FLOAT
=
"^-[1-9]\\d*\\.\\d*|-0\\.\\d*[1-9]\\d*$"
;
...
...
utilcode/src/main/java/com/blankj/utilcode/constant/TimeConstants.java
浏览文件 @
72d84e43
...
...
@@ -10,30 +10,15 @@ import java.lang.annotation.RetentionPolicy;
* author: Blankj
* blog : http://blankj.com
* time : 2017/03/13
* desc :
时间相关常量
* desc :
The constants of time
* </pre>
*/
public
final
class
TimeConstants
{
/**
* 秒与毫秒的倍数
*/
public
static
final
int
MSEC
=
1
;
/**
* 秒与毫秒的倍数
*/
public
static
final
int
SEC
=
1000
;
/**
* 分与毫秒的倍数
*/
public
static
final
int
MIN
=
60000
;
/**
* 时与毫秒的倍数
*/
public
static
final
int
HOUR
=
3600000
;
/**
* 天与毫秒的倍数
*/
public
static
final
int
DAY
=
86400000
;
@IntDef
({
MSEC
,
SEC
,
MIN
,
HOUR
,
DAY
})
...
...
utilcode/src/main/java/com/blankj/utilcode/util/ActivityUtils.java
浏览文件 @
72d84e43
...
...
@@ -11,6 +11,7 @@ import android.os.Build;
import
android.os.Bundle
;
import
android.support.annotation.AnimRes
;
import
android.support.annotation.NonNull
;
import
android.support.annotation.Nullable
;
import
android.support.v4.app.ActivityOptionsCompat
;
import
android.support.v4.util.Pair
;
import
android.view.View
;
...
...
@@ -64,7 +65,7 @@ public final class ActivityUtils {
* @param options 跳转动画
*/
public
static
void
startActivity
(
@NonNull
final
Class
<?>
clz
,
@N
onNull
final
Bundle
options
)
{
@N
ullable
final
Bundle
options
)
{
Context
context
=
getActivityOrApp
();
startActivity
(
context
,
null
,
context
.
getPackageName
(),
clz
.
getName
(),
options
);
}
...
...
@@ -107,7 +108,7 @@ public final class ActivityUtils {
*/
public
static
void
startActivity
(
@NonNull
final
Activity
activity
,
@NonNull
final
Class
<?>
clz
,
@N
onNull
final
Bundle
options
)
{
@N
ullable
final
Bundle
options
)
{
startActivity
(
activity
,
null
,
activity
.
getPackageName
(),
clz
.
getName
(),
options
);
}
...
...
@@ -276,7 +277,7 @@ public final class ActivityUtils {
*/
public
static
void
startActivity
(
@NonNull
final
String
pkg
,
@NonNull
final
String
cls
,
@N
onNull
final
Bundle
options
)
{
@N
ullable
final
Bundle
options
)
{
startActivity
(
getActivityOrApp
(),
null
,
pkg
,
cls
,
options
);
}
...
...
@@ -323,7 +324,7 @@ public final class ActivityUtils {
public
static
void
startActivity
(
@NonNull
final
Activity
activity
,
@NonNull
final
String
pkg
,
@NonNull
final
String
cls
,
@N
onNull
final
Bundle
options
)
{
@N
ullable
final
Bundle
options
)
{
startActivity
(
activity
,
null
,
pkg
,
cls
,
options
);
}
...
...
@@ -538,7 +539,7 @@ public final class ActivityUtils {
*/
public
static
void
startActivity
(
@NonNull
final
Activity
activity
,
@NonNull
final
Intent
intent
,
@N
onNull
final
Bundle
options
)
{
@N
ullable
final
Bundle
options
)
{
startActivity
(
intent
,
activity
,
options
);
}
...
...
@@ -589,7 +590,7 @@ public final class ActivityUtils {
* @param options 跳转动画
*/
public
static
void
startActivities
(
@NonNull
final
Intent
[]
intents
,
@N
onNull
final
Bundle
options
)
{
@N
ullable
final
Bundle
options
)
{
startActivities
(
intents
,
getActivityOrApp
(),
options
);
}
...
...
@@ -630,7 +631,7 @@ public final class ActivityUtils {
*/
public
static
void
startActivities
(
@NonNull
final
Activity
activity
,
@NonNull
final
Intent
[]
intents
,
@N
onNull
final
Bundle
options
)
{
@N
ullable
final
Bundle
options
)
{
startActivities
(
intents
,
activity
,
options
);
}
...
...
utilcode/src/main/java/com/blankj/utilcode/util/BarUtils.java
浏览文件 @
72d84e43
...
...
@@ -69,7 +69,6 @@ public final class BarUtils {
}
}
/**
* 判断状态栏是否可见
*
...
...
@@ -81,12 +80,36 @@ public final class BarUtils {
return
(
flags
&
WindowManager
.
LayoutParams
.
FLAG_FULLSCREEN
)
==
0
;
}
/**
* 设置状态栏是否为浅色模式
*
* @param activity activity
* @param isLightMode 是否为浅色模式
*/
public
static
void
setStatusBarLightMode
(
final
Activity
activity
,
final
boolean
isLightMode
)
{
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
M
)
{
Window
window
=
activity
.
getWindow
();
View
decorView
=
window
.
getDecorView
();
if
(
decorView
!=
null
)
{
int
vis
=
decorView
.
getSystemUiVisibility
();
if
(
isLightMode
)
{
window
.
addFlags
(
WindowManager
.
LayoutParams
.
FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS
);
vis
|=
View
.
SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
;
}
else
{
vis
&=
~
View
.
SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
;
}
decorView
.
setSystemUiVisibility
(
vis
);
}
}
}
/**
* 为 view 增加 MarginTop 为状态栏高度
*
* @param view view
*/
public
static
void
addMarginTopEqualStatusBarHeight
(
@NonNull
View
view
)
{
if
(
Build
.
VERSION
.
SDK_INT
<
Build
.
VERSION_CODES
.
KITKAT
)
return
;
Object
haveSetOffset
=
view
.
getTag
(
TAG_OFFSET
);
if
(
haveSetOffset
!=
null
&&
(
Boolean
)
haveSetOffset
)
return
;
MarginLayoutParams
layoutParams
=
(
MarginLayoutParams
)
view
.
getLayoutParams
();
...
...
@@ -103,6 +126,7 @@ public final class BarUtils {
* @param view view
*/
public
static
void
subtractMarginTopEqualStatusBarHeight
(
@NonNull
View
view
)
{
if
(
Build
.
VERSION
.
SDK_INT
<
Build
.
VERSION_CODES
.
KITKAT
)
return
;
Object
haveSetOffset
=
view
.
getTag
(
TAG_OFFSET
);
if
(
haveSetOffset
==
null
||
!(
Boolean
)
haveSetOffset
)
return
;
MarginLayoutParams
layoutParams
=
(
MarginLayoutParams
)
view
.
getLayoutParams
();
...
...
@@ -433,6 +457,7 @@ public final class BarUtils {
if
(
Build
.
VERSION
.
SDK_INT
<
Build
.
VERSION_CODES
.
KITKAT
)
return
;
Window
window
=
activity
.
getWindow
();
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
LOLLIPOP
)
{
window
.
addFlags
(
WindowManager
.
LayoutParams
.
FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS
);
int
option
=
View
.
SYSTEM_UI_FLAG_LAYOUT_STABLE
|
View
.
SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
;
window
.
getDecorView
().
setSystemUiVisibility
(
option
);
window
.
setStatusBarColor
(
Color
.
TRANSPARENT
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录