提交 bc1fadee 编写于 作者: B Blankj

see 02/12 log

上级 31c5a6be
...@@ -41,7 +41,7 @@ ...@@ -41,7 +41,7 @@
[logo]: https://raw.githubusercontent.com/Blankj/AndroidUtilCode/master/art/logo.png [logo]: https://raw.githubusercontent.com/Blankj/AndroidUtilCode/master/art/logo.png
[aucsvg]: https://img.shields.io/badge/AndroidUtilCode-v1.12.5-brightgreen.svg [aucsvg]: https://img.shields.io/badge/AndroidUtilCode-v1.12.6-brightgreen.svg
[auc]: https://github.com/Blankj/AndroidUtilCode [auc]: https://github.com/Blankj/AndroidUtilCode
[apisvg]: https://img.shields.io/badge/API-14+-brightgreen.svg [apisvg]: https://img.shields.io/badge/API-14+-brightgreen.svg
......
...@@ -41,7 +41,7 @@ If this ptoject helps you a lot, and you would like to support this ptoject's fu ...@@ -41,7 +41,7 @@ If this ptoject helps you a lot, and you would like to support this ptoject's fu
[logo]: https://raw.githubusercontent.com/Blankj/AndroidUtilCode/master/art/logo.png [logo]: https://raw.githubusercontent.com/Blankj/AndroidUtilCode/master/art/logo.png
[aucsvg]: https://img.shields.io/badge/AndroidUtilCode-v1.12.5-brightgreen.svg [aucsvg]: https://img.shields.io/badge/AndroidUtilCode-v1.12.6-brightgreen.svg
[auc]: https://github.com/Blankj/AndroidUtilCode [auc]: https://github.com/Blankj/AndroidUtilCode
[apisvg]: https://img.shields.io/badge/API-14+-brightgreen.svg [apisvg]: https://img.shields.io/badge/API-14+-brightgreen.svg
......
...@@ -56,7 +56,7 @@ dependencies { ...@@ -56,7 +56,7 @@ dependencies {
// LeakCanary // LeakCanary
debugImplementation "com.squareup.leakcanary:leakcanary-android:$leakcanary_version" debugImplementation "com.squareup.leakcanary:leakcanary-android:$leakcanary_version"
releaseImplementation "com.squareup.leakcanary:leakcanary-android-no-op:$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.6'
} }
...@@ -73,7 +73,7 @@ public class NetworkActivity extends BaseBackActivity { ...@@ -73,7 +73,7 @@ public class NetworkActivity extends BaseBackActivity {
tvAboutNetworkAsync = findViewById(R.id.tv_about_network_async); tvAboutNetworkAsync = findViewById(R.id.tv_about_network_async);
findViewById(R.id.btn_open_wireless_settings).setOnClickListener(this); findViewById(R.id.btn_open_wireless_settings).setOnClickListener(this);
findViewById(R.id.btn_set_wifi_enabled).setOnClickListener(this); findViewById(R.id.btn_set_wifi_enabled).setOnClickListener(this);
setAboutNetwork(); updateAboutNetwork();
} }
@Override @Override
...@@ -112,10 +112,10 @@ public class NetworkActivity extends BaseBackActivity { ...@@ -112,10 +112,10 @@ public class NetworkActivity extends BaseBackActivity {
NetworkUtils.setWifiEnabled(!NetworkUtils.getWifiEnabled()); NetworkUtils.setWifiEnabled(!NetworkUtils.getWifiEnabled());
break; break;
} }
setAboutNetwork(); updateAboutNetwork();
} }
private void setAboutNetwork() { private void updateAboutNetwork() {
tvAboutNetwork.setText(new SpanUtils() tvAboutNetwork.setText(new SpanUtils()
.appendLine("isConnected: " + NetworkUtils.isConnected()) .appendLine("isConnected: " + NetworkUtils.isConnected())
.appendLine("getMobileDataEnabled: " + NetworkUtils.getMobileDataEnabled()) .appendLine("getMobileDataEnabled: " + NetworkUtils.getMobileDataEnabled())
......
...@@ -37,7 +37,7 @@ public class ScreenActivity extends BaseActivity { ...@@ -37,7 +37,7 @@ public class ScreenActivity extends BaseActivity {
@Override @Override
public int bindLayout() { public int bindLayout() {
return R.layout.activity_brightness; return R.layout.activity_screen;
} }
@Override @Override
......
...@@ -91,10 +91,19 @@ public class BrightnessUtils { ...@@ -91,10 +91,19 @@ public class BrightnessUtils {
* *
* @param brightness 亮度值 * @param brightness 亮度值
*/ */
public static void setBrightness(@IntRange(from = 0, to = 255) final int brightness) { public static boolean setBrightness(@IntRange(from = 0, to = 255) final int brightness) {
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;
}
ContentResolver resolver = Utils.getApp().getContentResolver(); ContentResolver resolver = Utils.getApp().getContentResolver();
Settings.System.putInt(resolver, Settings.System.SCREEN_BRIGHTNESS, brightness); boolean b = Settings.System.putInt(resolver, Settings.System.SCREEN_BRIGHTNESS, brightness);
resolver.notifyChange(Settings.System.getUriFor("screen_brightness"), null); resolver.notifyChange(Settings.System.getUriFor("screen_brightness"), null);
return b;
} }
/** /**
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
Gradle: Gradle:
```groovy ```groovy
compile 'com.blankj:utilcode:1.12.5' compile 'com.blankj:utilcode:1.12.6'
``` ```
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
Gradle: Gradle:
```groovy ```groovy
compile 'com.blankj:utilcode:1.12.5' compile 'com.blankj:utilcode:1.12.6'
``` ```
......
...@@ -10,7 +10,7 @@ import java.lang.annotation.RetentionPolicy; ...@@ -10,7 +10,7 @@ import java.lang.annotation.RetentionPolicy;
* author: Blankj * author: Blankj
* blog : http://blankj.com * blog : http://blankj.com
* time : 2017/03/13 * time : 2017/03/13
* desc : The constants of memory * desc : The constants of memory.
* </pre> * </pre>
*/ */
public final class MemoryConstants { public final class MemoryConstants {
......
...@@ -14,7 +14,7 @@ import java.lang.annotation.RetentionPolicy; ...@@ -14,7 +14,7 @@ import java.lang.annotation.RetentionPolicy;
* author: Blankj * author: Blankj
* blog : http://blankj.com * blog : http://blankj.com
* time : 2017/12/29 * time : 2017/12/29
* desc : The constants of permission * desc : The constants of permission.
* </pre> * </pre>
*/ */
@SuppressLint("InlinedApi") @SuppressLint("InlinedApi")
......
...@@ -5,17 +5,17 @@ package com.blankj.utilcode.constant; ...@@ -5,17 +5,17 @@ package com.blankj.utilcode.constant;
* author: Blankj * author: Blankj
* blog : http://blankj.com * blog : http://blankj.com
* time : 2017/03/13 * time : 2017/03/13
* desc : The constants of regex * desc : The constants of regex.
* </pre> * </pre>
*/ */
public final class RegexConstants { public final class RegexConstants {
/** /**
* regex of simple mobile * Regex of simple mobile.
*/ */
public static final String REGEX_MOBILE_SIMPLE = "^[1]\\d{10}$"; public static final String REGEX_MOBILE_SIMPLE = "^[1]\\d{10}$";
/** /**
* regex of exact mobile * 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 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 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>china telecom: 133, 153, 173, 177, 180, 181, 189, 199</p>
...@@ -24,91 +24,91 @@ public final class RegexConstants { ...@@ -24,91 +24,91 @@ public final class RegexConstants {
*/ */
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}$"; 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 * Regex of telephone number.
*/ */
public static final String REGEX_TEL = "^0\\d{2,3}[- ]?\\d{7,8}"; public static final String REGEX_TEL = "^0\\d{2,3}[- ]?\\d{7,8}";
/** /**
* regex of id card number which length is 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}$"; 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}$";
/** /**
* regex of id card number which length is 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])$"; 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 * Regex of email.
*/ */
public static final String REGEX_EMAIL = "^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$"; public static final String REGEX_EMAIL = "^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$";
/** /**
* regex of url * Regex of url.
*/ */
public static final String REGEX_URL = "[a-zA-z]+://[^\\s]*"; public static final String REGEX_URL = "[a-zA-z]+://[^\\s]*";
/** /**
* regex of Chinese character * Regex of Chinese character.
*/ */
public static final String REGEX_ZH = "^[\\u4e00-\\u9fa5]+$"; public static final String REGEX_ZH = "^[\\u4e00-\\u9fa5]+$";
/** /**
* regex of username * Regex of username.
* <p>scope for "a-z", "A-Z", "0-9", "_", "Chinese character"</p> * <p>scope for "a-z", "A-Z", "0-9", "_", "Chinese character"</p>
* <p>can't end with "_"</p> * <p>can't end with "_"</p>
* <p>length is between 6 to 20</p> * <p>length is between 6 to 20</p>
*/ */
public static final String REGEX_USERNAME = "^[\\w\\u4e00-\\u9fa5]{6,20}(?<!_)$"; public static final String REGEX_USERNAME = "^[\\w\\u4e00-\\u9fa5]{6,20}(?<!_)$";
/** /**
* regex of date which pattern is "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)$"; 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)$";
/** /**
* regex of ip address * 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?)"; 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?)";
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
// the following comes from http://tool.oschina.net/regex // The following come from http://tool.oschina.net/regex
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
/** /**
* regex of double-byte characters * Regex of double-byte characters.
*/ */
public static final String REGEX_DOUBLE_BYTE_CHAR = "[^\\x00-\\xff]"; public static final String REGEX_DOUBLE_BYTE_CHAR = "[^\\x00-\\xff]";
/** /**
* regex of blank line * Regex of blank line.
*/ */
public static final String REGEX_BLANK_LINE = "\\n\\s*\\r"; public static final String REGEX_BLANK_LINE = "\\n\\s*\\r";
/** /**
* regex of QQ number * Regex of QQ number.
*/ */
public static final String REGEX_QQ_NUM = "[1-9][0-9]{4,}"; public static final String REGEX_QQ_NUM = "[1-9][0-9]{4,}";
/** /**
* regex of postal code in China * Regex of postal code in China.
*/ */
public static final String REGEX_CHINA_POSTAL_CODE = "[1-9]\\d{5}(?!\\d)"; public static final String REGEX_CHINA_POSTAL_CODE = "[1-9]\\d{5}(?!\\d)";
/** /**
* regex of positive integer * Regex of positive integer.
*/ */
public static final String REGEX_POSITIVE_INTEGER = "^[1-9]\\d*$"; public static final String REGEX_POSITIVE_INTEGER = "^[1-9]\\d*$";
/** /**
* regex of negative integer * Regex of negative integer.
*/ */
public static final String REGEX_NEGATIVE_INTEGER = "^-[1-9]\\d*$"; public static final String REGEX_NEGATIVE_INTEGER = "^-[1-9]\\d*$";
/** /**
* regex of integer * Regex of integer.
*/ */
public static final String REGEX_INTEGER = "^-?[1-9]\\d*$"; public static final String REGEX_INTEGER = "^-?[1-9]\\d*$";
/** /**
* regex of non-negative integer * Regex of non-negative integer.
*/ */
public static final String REGEX_NOT_NEGATIVE_INTEGER = "^[1-9]\\d*|0$"; public static final String REGEX_NOT_NEGATIVE_INTEGER = "^[1-9]\\d*|0$";
/** /**
* regex of non-positive integer * Regex of non-positive integer.
*/ */
public static final String REGEX_NOT_POSITIVE_INTEGER = "^-[1-9]\\d*|0$"; public static final String REGEX_NOT_POSITIVE_INTEGER = "^-[1-9]\\d*|0$";
/** /**
* regex of positive float * Regex of positive float.
*/ */
public static final String REGEX_POSITIVE_FLOAT = "^[1-9]\\d*\\.\\d*|0\\.\\d*[1-9]\\d*$"; public static final String REGEX_POSITIVE_FLOAT = "^[1-9]\\d*\\.\\d*|0\\.\\d*[1-9]\\d*$";
/** /**
* regex of negative float * Regex of negative float.
*/ */
public static final String REGEX_NEGATIVE_FLOAT = "^-[1-9]\\d*\\.\\d*|-0\\.\\d*[1-9]\\d*$"; public static final String REGEX_NEGATIVE_FLOAT = "^-[1-9]\\d*\\.\\d*|-0\\.\\d*[1-9]\\d*$";
......
...@@ -10,7 +10,7 @@ import java.lang.annotation.RetentionPolicy; ...@@ -10,7 +10,7 @@ import java.lang.annotation.RetentionPolicy;
* author: Blankj * author: Blankj
* blog : http://blankj.com * blog : http://blankj.com
* time : 2017/03/13 * time : 2017/03/13
* desc : The constants of time * desc : The constants of time.
* </pre> * </pre>
*/ */
public final class TimeConstants { public final class TimeConstants {
......
...@@ -45,8 +45,10 @@ public final class NetworkUtils { ...@@ -45,8 +45,10 @@ public final class NetworkUtils {
* 打开网络设置界面 * 打开网络设置界面
*/ */
public static void openWirelessSettings() { public static void openWirelessSettings() {
Utils.getApp().startActivity(new Intent(android.provider.Settings.ACTION_WIRELESS_SETTINGS) Utils.getApp().startActivity(
.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)); new Intent(android.provider.Settings.ACTION_WIRELESS_SETTINGS)
.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
);
} }
/** /**
......
...@@ -4,6 +4,7 @@ import android.annotation.SuppressLint; ...@@ -4,6 +4,7 @@ import android.annotation.SuppressLint;
import android.app.Activity; import android.app.Activity;
import android.app.Application; import android.app.Application;
import android.app.Application.ActivityLifecycleCallbacks; import android.app.Application.ActivityLifecycleCallbacks;
import android.content.Context;
import android.os.Bundle; import android.os.Bundle;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
...@@ -13,45 +14,22 @@ import java.util.List; ...@@ -13,45 +14,22 @@ import java.util.List;
/** /**
* <pre> * <pre>
* author: Blankj * author:
* ___ ___ ___ ___
* _____ / /\ /__/\ /__/| / /\
* / /::\ / /::\ \ \:\ | |:| / /:/
* / /:/\:\ ___ ___ / /:/\:\ \ \:\ | |:| /__/::\
* / /:/~/::\ /__/\ / /\ / /:/~/::\ _____\__\:\ __| |:| \__\/\:\
* /__/:/ /:/\:| \ \:\ / /:/ /__/:/ /:/\:\ /__/::::::::\ /__/\_|:|____ \ \:\
* \ \:\/:/~/:/ \ \:\ /:/ \ \:\/:/__\/ \ \:\~~\~~\/ \ \:\/:::::/ \__\:\
* \ \::/ /:/ \ \:\/:/ \ \::/ \ \:\ ~~~ \ \::/~~~~ / /:/
* \ \:\/:/ \ \::/ \ \:\ \ \:\ \ \:\ /__/:/
* \ \::/ \__\/ \ \:\ \ \:\ \ \:\ \__\/
* \__\/ \__\/ \__\/ \__\/
* blog : http://blankj.com * blog : http://blankj.com
* time : 16/12/08 * time : 16/12/08
* desc : Utils 初始化相关 * desc : Utils about initialization.
* </pre> * </pre>
*          瓦瓦            十
*         十齱龠己         亅瓦車己
*         乙龍龠毋日丶      丶乙己毋毋丶
*         十龠馬鬼車瓦      己十瓦毋毋
*          鬼馬龠馬龠十    己己毋車毋瓦
*          毋龠龠龍龠鬼乙丶丶乙車乙毋鬼車己
*          乙龠龍龍鬼龍瓦 十瓦毋乙瓦龠瓦亅
*           馬齱龍馬鬼十丶日己己己毋車乙丶
*           己齱馬鬼車十十毋日乙己己乙乙
*            車馬齱齱日乙毋瓦己乙瓦日亅
*            亅車齺龖瓦乙車龖龍乙乙十
*             日龠龠十亅車龍毋十十
*             日毋己亅 己己十亅亅
*            丶己十十乙  丶丶丶丶丶
*            亅己十龍龖瓦  丶 丶 乙十
*            亅己十龠龖毋 丶丶  丶己鬼鬼瓦亅
*            十日十十日亅丶亅丶 丶十日毋鬼馬馬車乙
*            十日乙十亅亅亅丶  十乙己毋鬼鬼鬼龍齺馬乙
*            丶瓦己乙十十亅丶亅乙乙乙己毋鬼鬼鬼龍齱齺齺鬼十
*             乙乙十十十亅乙瓦瓦己日瓦毋鬼鬼龠齱齱龍龍齱齱毋丶
*             亅十十十十乙瓦車毋瓦瓦日車馬龠龍龍龍龍龍龠龠龠馬亅
*              十十十十己毋車瓦瓦瓦瓦鬼馬龠龍龠龠龍龠龠龠馬龠車
*               亅十十日毋瓦日日瓦鬼鬼鬼龠龠馬馬龠龍龍龠馬馬車
*               亅亅亅乙瓦瓦毋車車車馬龍龠鬼鬼馬龠龍龍龠馬馬鬼
*             丶丶乙亅亅乙車鬼鬼鬼毋車龍龍龠鬼馬馬龠龍齱齱龍馬鬼
*            亅己十十己十日鬼鬼車瓦毋龠龍龠馬馬龠龠龠齱齺齺齱龠鬼
*             亅乙乙乙十車馬車毋馬齱齱龍龠龠龠馬龠龍齱龍龠龠鬼瓦
*                 丶毋龠鬼車瓦車馬龠龍龠龠龍齱齱龠馬馬鬼毋日
*                 十乙己日十  丶己鬼龍齱齺齱龍馬馬馬車毋己
*               丶十己乙亅丶      亅瓦馬龠龍龠龠馬毋瓦乙
*              丶十十乙亅十        亅己瓦車馬龠鬼車瓦乙
*              丶十乙十十丶         丶丶亅十瓦鬼車瓦己
*               丶亅亅丶               亅日瓦日
*                                     丶
*/ */
public final class Utils { public final class Utils {
...@@ -104,19 +82,20 @@ public final class Utils { ...@@ -104,19 +82,20 @@ public final class Utils {
} }
/** /**
* 初始化工具类 * Init utils.
* <p>Init it in the class of Application.</p>
* *
* @param app 应用 * @param context context
*/ */
public static void init(@NonNull final Application app) { public static void init(@NonNull final Context context) {
Utils.sApplication = app; Utils.sApplication = ((Application) context.getApplicationContext());
app.registerActivityLifecycleCallbacks(mCallbacks); Utils.sApplication.registerActivityLifecycleCallbacks(mCallbacks);
} }
/** /**
* 获取 Application * Return the context of Application object.
* *
* @return Application * @return the context of Application object
*/ */
public static Application getApp() { public static Application getApp() {
if (sApplication != null) return sApplication; if (sApplication != null) return sApplication;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册