Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xiaoxuan_i809
AndroidUtilCode
提交
2ba5a178
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,体验更适合开发者的 AI 搜索 >>
提交
2ba5a178
编写于
1月 13, 2017
作者:
C
cmj
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
see 01/13 log
上级
939a4963
变更
11
隐藏空白更改
内联
并排
Showing
11 changed file
with
121 addition
and
46 deletion
+121
-46
app/src/main/java/com/blankj/androidutilcode/activities/DeviceActivity.java
...com/blankj/androidutilcode/activities/DeviceActivity.java
+1
-1
app/src/main/java/com/blankj/androidutilcode/activities/NetworkActivity.java
...om/blankj/androidutilcode/activities/NetworkActivity.java
+1
-0
utilcode/build.gradle
utilcode/build.gradle
+1
-2
utilcode/src/main/java/com/blankj/utilcode/utils/CrashUtils.java
...e/src/main/java/com/blankj/utilcode/utils/CrashUtils.java
+11
-6
utilcode/src/main/java/com/blankj/utilcode/utils/IntentUtils.java
.../src/main/java/com/blankj/utilcode/utils/IntentUtils.java
+12
-1
utilcode/src/main/java/com/blankj/utilcode/utils/NetworkUtils.java
...src/main/java/com/blankj/utilcode/utils/NetworkUtils.java
+3
-3
utilcode/src/main/java/com/blankj/utilcode/utils/PhoneUtils.java
...e/src/main/java/com/blankj/utilcode/utils/PhoneUtils.java
+8
-4
utilcode/src/main/java/com/blankj/utilcode/utils/SDCardUtils.java
.../src/main/java/com/blankj/utilcode/utils/SDCardUtils.java
+1
-1
utilcode/src/main/java/com/blankj/utilcode/utils/ScreenUtils.java
.../src/main/java/com/blankj/utilcode/utils/ScreenUtils.java
+25
-0
utilcode/src/main/java/com/blankj/utilcode/utils/SnackbarUtils.java
...rc/main/java/com/blankj/utilcode/utils/SnackbarUtils.java
+1
-4
utilcode/src/test/java/com/blankj/utilcode/utils/DogeTest.java
...ode/src/test/java/com/blankj/utilcode/utils/DogeTest.java
+57
-24
未找到文件。
app/src/main/java/com/blankj/androidutilcode/activities/DeviceActivity.java
浏览文件 @
2ba5a178
...
...
@@ -31,7 +31,7 @@ public class DeviceActivity extends Activity
findViewById
(
R
.
id
.
btn_reboot_to_recovery
).
setOnClickListener
(
this
);
findViewById
(
R
.
id
.
btn_reboot_to_bootloader
).
setOnClickListener
(
this
);
tvAboutDevice
.
setText
(
"isRoot: "
+
DeviceUtils
.
isDeviceRoot
()
tvAboutDevice
.
setText
(
"isRoot: "
+
DeviceUtils
.
isDeviceRoot
ed
()
+
"\ngetSDKVersion: "
+
DeviceUtils
.
getSDKVersion
()
+
"\ngetAndroidID: "
+
DeviceUtils
.
getAndroidID
()
+
"\ngetMacAddress: "
+
DeviceUtils
.
getMacAddress
()
...
...
app/src/main/java/com/blankj/androidutilcode/activities/NetworkActivity.java
浏览文件 @
2ba5a178
...
...
@@ -58,6 +58,7 @@ public class NetworkActivity extends Activity
+
"\ngetWifiEnabled: "
+
NetworkUtils
.
getWifiEnabled
()
+
"\nisWifiConnected: "
+
NetworkUtils
.
isWifiConnected
()
+
"\nisWifiAvailable: "
+
NetworkUtils
.
isWifiAvailable
()
+
"\nisAvailableByPing: "
+
NetworkUtils
.
isAvailableByPing
()
+
"\ngetNetworkOperatorName: "
+
NetworkUtils
.
getNetworkOperatorName
()
+
"\ngetNetworkTypeName: "
+
NetworkUtils
.
getNetworkType
()
+
"\ngetIPAddress: "
+
NetworkUtils
.
getIPAddress
(
true
)
...
...
utilcode/build.gradle
浏览文件 @
2ba5a178
...
...
@@ -6,7 +6,6 @@ android {
defaultConfig
{
minSdkVersion
rootProject
.
ext
.
android
.
minSdkVersion
targetSdkVersion
rootProject
.
ext
.
android
.
targetSdkVersion
versionCode
rootProject
.
ext
.
android
.
versionCode
versionName
rootProject
.
ext
.
android
.
versionName
}
...
...
@@ -26,5 +25,5 @@ dependencies {
testCompile
rootProject
.
ext
.
deps
.
truth
testCompile
rootProject
.
ext
.
deps
.
robolectric
}
apply
from:
"https://raw.githubusercontent.com/xiaopansky/android-library-publish-to-jcenter/master/bintrayUpload.gradle"
//
apply from: "https://raw.githubusercontent.com/xiaopansky/android-library-publish-to-jcenter/master/bintrayUpload.gradle"
//gradlew bintrayUpload
utilcode/src/main/java/com/blankj/utilcode/utils/CrashUtils.java
浏览文件 @
2ba5a178
...
...
@@ -28,10 +28,11 @@ public class CrashUtils
private
volatile
static
CrashUtils
mInstance
;
private
UncaughtExceptionHandler
mHandler
;
private
boolean
mInitialized
;
private
String
crashDir
;
private
String
versionName
;
private
int
versionCode
;
private
boolean
mInitialized
;
private
String
crashDir
;
private
String
versionName
;
private
int
versionCode
;
private
CrashUtils
()
{
}
...
...
@@ -62,9 +63,13 @@ public class CrashUtils
public
boolean
init
()
{
if
(
mInitialized
)
return
true
;
if
(
Environment
.
MEDIA_MOUNTED
.
equals
(
Environment
.
getExternalStorageState
()))
{
crashDir
=
Utils
.
getContext
().
getExternalCacheDir
().
getPath
()
+
File
.
separator
+
"crash"
+
File
.
separator
;
File
baseCache
=
Utils
.
getContext
().
getExternalCacheDir
();
if
(
baseCache
==
null
)
return
false
;
crashDir
=
baseCache
.
getPath
()
+
File
.
separator
+
"crash"
+
File
.
separator
;
}
else
{
crashDir
=
Utils
.
getContext
().
getCacheDir
().
getPath
()
+
File
.
separator
+
"crash"
+
File
.
separator
;
File
baseCache
=
Utils
.
getContext
().
getCacheDir
();
if
(
baseCache
==
null
)
return
false
;
crashDir
=
baseCache
.
getPath
()
+
File
.
separator
+
"crash"
+
File
.
separator
;
}
try
{
PackageInfo
pi
=
Utils
.
getContext
().
getPackageManager
().
getPackageInfo
(
Utils
.
getContext
().
getPackageName
(),
0
);
...
...
utilcode/src/main/java/com/blankj/utilcode/utils/IntentUtils.java
浏览文件 @
2ba5a178
...
...
@@ -3,11 +3,11 @@ package com.blankj.utilcode.utils;
import
android.content.ComponentName
;
import
android.content.Context
;
import
android.content.Intent
;
import
android.graphics.Bitmap
;
import
android.net.Uri
;
import
android.os.Build
;
import
android.os.Bundle
;
import
android.provider.MediaStore
;
import
android.support.v4.content.FileProvider
;
import
android.webkit.MimeTypeMap
;
import
java.io.File
;
...
...
@@ -46,11 +46,17 @@ public class IntentUtils {
if
(
file
==
null
)
return
null
;
Intent
intent
=
new
Intent
(
Intent
.
ACTION_VIEW
);
String
type
;
if
(
Build
.
VERSION
.
SDK_INT
<
23
)
{
type
=
"application/vnd.android.package-archive"
;
}
else
{
type
=
MimeTypeMap
.
getSingleton
().
getMimeTypeFromExtension
(
FileUtils
.
getFileExtension
(
file
));
}
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
N
)
{
intent
.
setFlags
(
Intent
.
FLAG_GRANT_READ_URI_PERMISSION
);
Uri
contentUri
=
FileProvider
.
getUriForFile
(
Utils
.
getContext
(),
"com.your.package.fileProvider"
,
file
);
intent
.
setDataAndType
(
contentUri
,
type
);
}
intent
.
setDataAndType
(
Uri
.
fromFile
(
file
),
type
);
return
intent
.
addFlags
(
Intent
.
FLAG_ACTIVITY_NEW_TASK
);
}
...
...
@@ -179,6 +185,11 @@ public class IntentUtils {
return
intent
.
addFlags
(
Intent
.
FLAG_ACTIVITY_NEW_TASK
);
}
// public static Intent getDailIntent(){
//
// }
/**
* 获取拍照的意图
*
...
...
utilcode/src/main/java/com/blankj/utilcode/utils/NetworkUtils.java
浏览文件 @
2ba5a178
...
...
@@ -52,9 +52,9 @@ public class NetworkUtils {
*/
public
static
void
openWirelessSettings
()
{
if
(
android
.
os
.
Build
.
VERSION
.
SDK_INT
>
10
)
{
Utils
.
getContext
().
startActivity
(
new
Intent
(
android
.
provider
.
Settings
.
ACTION_WIRELESS_SETTINGS
));
Utils
.
getContext
().
startActivity
(
new
Intent
(
android
.
provider
.
Settings
.
ACTION_WIRELESS_SETTINGS
)
.
setFlags
(
Intent
.
FLAG_ACTIVITY_NEW_TASK
)
);
}
else
{
Utils
.
getContext
().
startActivity
(
new
Intent
(
android
.
provider
.
Settings
.
ACTION_SETTINGS
));
Utils
.
getContext
().
startActivity
(
new
Intent
(
android
.
provider
.
Settings
.
ACTION_SETTINGS
)
.
setFlags
(
Intent
.
FLAG_ACTIVITY_NEW_TASK
)
);
}
}
...
...
@@ -88,7 +88,7 @@ public class NetworkUtils {
* @return {@code true}: 可用<br>{@code false}: 不可用
*/
public
static
boolean
isAvailableByPing
()
{
ShellUtils
.
CommandResult
result
=
ShellUtils
.
execCmd
(
"ping -c 1 -w 1
123.125.114.144
"
,
false
);
ShellUtils
.
CommandResult
result
=
ShellUtils
.
execCmd
(
"ping -c 1 -w 1
223.5.5.5
"
,
false
);
boolean
ret
=
result
.
result
==
0
;
if
(
result
.
errorMsg
!=
null
)
{
LogUtils
.
d
(
"isAvailableByPing errorMsg"
,
result
.
errorMsg
);
...
...
utilcode/src/main/java/com/blankj/utilcode/utils/PhoneUtils.java
浏览文件 @
2ba5a178
...
...
@@ -49,7 +49,7 @@ public class PhoneUtils {
* 获取IMEI码
* <p>需添加权限 {@code <uses-permission android:name="android.permission.READ_PHONE_STATE"/>}</p>
*
* @return IM
IE
码
* @return IM
EI
码
*/
@SuppressLint
(
"HardwareIds"
)
public
static
String
getIMEI
()
{
...
...
@@ -61,7 +61,7 @@ public class PhoneUtils {
* 获取IMSI码
* <p>需添加权限 {@code <uses-permission android:name="android.permission.READ_PHONE_STATE"/>}</p>
*
* @return IM
IE
码
* @return IM
SI
码
*/
@SuppressLint
(
"HardwareIds"
)
public
static
String
getIMSI
()
{
...
...
@@ -178,7 +178,9 @@ public class PhoneUtils {
* @param phoneNumber 电话号码
*/
public
static
void
dial
(
String
phoneNumber
)
{
Utils
.
getContext
().
startActivity
(
new
Intent
(
Intent
.
ACTION_DIAL
,
Uri
.
parse
(
"tel:"
+
phoneNumber
)));
Intent
intent
=
new
Intent
(
Intent
.
ACTION_DIAL
,
Uri
.
parse
(
"tel:"
+
phoneNumber
));
intent
.
addFlags
(
Intent
.
FLAG_ACTIVITY_NEW_TASK
);
Utils
.
getContext
().
startActivity
(
intent
);
}
/**
...
...
@@ -188,7 +190,9 @@ public class PhoneUtils {
* @param phoneNumber 电话号码
*/
public
static
void
call
(
String
phoneNumber
)
{
Utils
.
getContext
().
startActivity
(
new
Intent
(
"android.intent.action.CALL"
,
Uri
.
parse
(
"tel:"
+
phoneNumber
)));
Intent
intent
=
new
Intent
(
"android.intent.action.CALL"
,
Uri
.
parse
(
"tel:"
+
phoneNumber
));
intent
.
addFlags
(
Intent
.
FLAG_ACTIVITY_NEW_TASK
);
Utils
.
getContext
().
startActivity
(
intent
);
}
/**
...
...
utilcode/src/main/java/com/blankj/utilcode/utils/SDCardUtils.java
浏览文件 @
2ba5a178
...
...
@@ -56,7 +56,7 @@ public class SDCardUtils {
}
}
if
(
p
.
waitFor
()
!=
0
&&
p
.
exitValue
()
==
1
)
{
return
" 命令执行失败"
;
break
;
}
}
}
catch
(
Exception
e
)
{
...
...
utilcode/src/main/java/com/blankj/utilcode/utils/ScreenUtils.java
浏览文件 @
2ba5a178
...
...
@@ -6,6 +6,7 @@ import android.content.Context;
import
android.content.pm.ActivityInfo
;
import
android.content.res.Configuration
;
import
android.graphics.Bitmap
;
import
android.provider.Settings
;
import
android.util.DisplayMetrics
;
import
android.view.Surface
;
import
android.view.View
;
...
...
@@ -157,4 +158,28 @@ public class ScreenUtils {
.
getSystemService
(
Context
.
KEYGUARD_SERVICE
);
return
km
.
inKeyguardRestrictedInputMode
();
}
/**
* 设置进入休眠时长
* <uses-permission android:name="android.permission.WRITE_SETTINGS" />
*
* @param duration 时长
*/
public
static
void
setSleepDuration
(
int
duration
)
{
Settings
.
System
.
putInt
(
Utils
.
getContext
().
getContentResolver
(),
Settings
.
System
.
SCREEN_OFF_TIMEOUT
,
duration
);
}
/**
* 获取进入休眠时长
*
* @return 进入休眠时长,报错返回-123
*/
public
static
int
getSleepDuration
()
{
try
{
return
Settings
.
System
.
getInt
(
Utils
.
getContext
().
getContentResolver
(),
Settings
.
System
.
SCREEN_OFF_TIMEOUT
);
}
catch
(
Settings
.
SettingNotFoundException
e
)
{
e
.
printStackTrace
();
return
-
123
;
}
}
}
\ No newline at end of file
utilcode/src/main/java/com/blankj/utilcode/utils/SnackbarUtils.java
浏览文件 @
2ba5a178
package
com.blankj.utilcode.utils
;
import
android.support.annotation.ColorInt
;
import
android.support.design.widget.BaseTransientBottomBar
;
import
android.support.design.widget.Snackbar
;
import
android.view.Gravity
;
import
android.view.LayoutInflater
;
...
...
@@ -89,7 +88,6 @@ public class SnackbarUtils {
*
* @param parent 父视图(CoordinatorLayout或者DecorView)
* @param text 文本
* @param duration 自定义时长
* @param textColor 文本颜色
* @param bgColor 背景色
*/
...
...
@@ -102,7 +100,6 @@ public class SnackbarUtils {
*
* @param parent 父视图(CoordinatorLayout或者DecorView)
* @param text 文本
* @param duration 自定义时长
* @param textColor 文本颜色
* @param bgColor 背景色
* @param actionText 事件文本
...
...
@@ -128,7 +125,7 @@ public class SnackbarUtils {
* @param listener 监听器
*/
private
static
void
showSnackbar
(
View
parent
,
CharSequence
text
,
@BaseTransientBottomBar
.
Duration
int
duration
,
int
duration
,
@ColorInt
int
textColor
,
@ColorInt
int
bgColor
,
CharSequence
actionText
,
int
actionTextColor
,
View
.
OnClickListener
listener
)
{
...
...
utilcode/src/test/java/com/blankj/utilcode/utils/DogeTest.java
浏览文件 @
2ba5a178
...
...
@@ -3,7 +3,9 @@ package com.blankj.utilcode.utils;
import
org.junit.Test
;
import
java.io.File
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Locale
;
/**
* <pre>
...
...
@@ -15,39 +17,70 @@ import java.util.List;
*/
public
class
DogeTest
{
private
static
List
<
File
>
dogeFiles
=
new
ArrayList
<>();
private
static
int
[]
indexes
=
{
0
,
50
,
100
,
150
,
200
,
300
,
400
,
450
,
500
,
550
,
600
,
700
};
private
static
int
bitNum
=
3
;
static
{
dogeFiles
.
add
(
new
File
(
"F:/MyGithub/doge-expression/_00_000_049_SingleRun"
));
dogeFiles
.
add
(
new
File
(
"F:/MyGithub/doge-expression/_01_050_099_Tear"
));
dogeFiles
.
add
(
new
File
(
"F:/MyGithub/doge-expression/_02_100_149_Lines"
));
dogeFiles
.
add
(
new
File
(
"F:/MyGithub/doge-expression/_03_150_199_MoreRun"
));
dogeFiles
.
add
(
new
File
(
"F:/MyGithub/doge-expression/_04_200_299_ToLeft"
));
dogeFiles
.
add
(
new
File
(
"F:/MyGithub/doge-expression/_05_300_399_ToRight"
));
dogeFiles
.
add
(
new
File
(
"F:/MyGithub/doge-expression/_06_400_449_Big"
));
dogeFiles
.
add
(
new
File
(
"F:/MyGithub/doge-expression/_07_450_499_Hug"
));
dogeFiles
.
add
(
new
File
(
"F:/MyGithub/doge-expression/_08_500_549_Wang"
));
dogeFiles
.
add
(
new
File
(
"F:/MyGithub/doge-expression/_09_550_599_ToWall"
));
dogeFiles
.
add
(
new
File
(
"F:/MyGithub/doge-expression/_10_600_699_OtherGif"
));
dogeFiles
.
add
(
new
File
(
"F:/MyGithub/doge-expression/_11_700_799_OtherJpg"
));
}
@Test
public
void
generateDogeMD
()
throws
Exception
{
bitNum
=
4
;
renameDogeNames
();
bitNum
=
3
;
renameDogeNames
();
StringBuilder
sb
=
new
StringBuilder
();
sb
.
append
(
"卡通doge的表情大集合,喜爱doge的朋友的福利到了,花了
大半天的时间整理出来的狗东西,就被你们这么轻而易举地拿走了,现附上QQ表情包链接[doge-expression.eif](https://github.com/Blankj/doge-expression/blob
/master/doge-expression.eif)(进去点击Download即可)\n\n"
);
sb
.
append
(
"卡通doge的表情大集合,喜爱doge的朋友的福利到了,花了
很多的时间整理出来的狗东西,就被你们这么轻而易举地拿走了,现附上QQ表情包链接[doge-expression.eif](https://raw.githubusercontent.com/Blankj/doge-expression
/master/doge-expression.eif)(进去点击Download即可)\n\n"
);
sb
.
append
(
"下面展示doge各种姿势,请系好安全带,开车啦,滴滴滴~~\n\n"
);
File
file
=
new
File
(
"F:/MyGithub/doge-expression/expression"
);
List
<
File
>
files
=
FileUtils
.
listFilesInDir
(
file
);
for
(
File
f
:
files
)
{
String
name
=
f
.
getName
();
sb
.
append
(
"!["
)
.
append
(
name
)
.
append
(
"]"
)
.
append
(
"(https://github.com/Blankj/doge-expression/raw/master/expression/"
)
.
append
(
name
)
.
append
(
") \n"
);
for
(
int
i
=
0
;
i
<
dogeFiles
.
size
();
++
i
)
{
List
<
File
>
files
=
FileUtils
.
listFilesInDir
(
dogeFiles
.
get
(
i
));
for
(
File
f
:
files
)
{
String
name
=
f
.
getName
();
sb
.
append
(
"!["
)
.
append
(
name
)
.
append
(
"]"
)
.
append
(
"(https://github.com/Blankj/doge-expression/raw/master/"
)
.
append
(
f
.
getParentFile
().
getName
())
.
append
(
"/"
)
.
append
(
name
)
.
append
(
") \n"
);
}
}
// System.out.println(sb.toString());
FileUtils
.
writeFileFromString
(
"F:/MyGithub/doge-expression/README.md"
,
sb
.
toString
(),
false
);
}
@Test
public
void
generateDogeNames
()
throws
Exception
{
StringBuilder
sb
=
new
StringBuilder
();
File
file
=
new
File
(
"F:/MyGithub/doge-expression/expression"
);
List
<
File
>
files
=
FileUtils
.
listFilesInDir
(
file
);
for
(
File
f
:
files
)
{
String
name
=
f
.
getName
();
sb
.
append
(
"!["
)
.
append
(
name
)
.
append
(
"]"
)
.
append
(
"(https://github.com/Blankj/doge-expression/raw/master/expression/"
)
.
append
(
name
)
.
append
(
") \n"
);
public
void
renameDogeNames
()
throws
Exception
{
for
(
int
i
=
0
;
i
<
dogeFiles
.
size
();
++
i
)
{
List
<
File
>
files
=
FileUtils
.
listFilesInDir
(
dogeFiles
.
get
(
i
));
int
index
=
indexes
[
i
];
for
(
File
f
:
files
)
{
String
name
=
f
.
getName
();
String
rename
=
String
.
format
(
Locale
.
getDefault
(),
"%s%0"
+
bitNum
+
"d%s"
,
f
.
getParent
()
+
File
.
separator
,
index
++,
name
.
substring
(
name
.
length
()
-
4
)
);
f
.
renameTo
(
new
File
(
rename
));
}
}
FileUtils
.
writeFileFromString
(
"F:/MyGithub/doge-expression/README.md"
,
sb
.
toString
(),
false
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录