提交 368926cc 编写于 作者: B Blankj

see 01/07 log

上级 1e20b865
* `19/01/04` [add] CacheDiskStaticUtils, CacheDoubleStaticUtils, CacheMemoryStaticUtils.
* `19/01/03` [add] SPStaticUtils.
* `19/01/02` [fix] LogUtils log object. Publish v1.22.10.
* `19/01/01` [add] GsonUtils.
* `18/12/29` [add] AntiShakeUtils and VibrateUtils. Publish v1.22.9.
......
......@@ -41,7 +41,7 @@
[logo]: https://raw.githubusercontent.com/Blankj/AndroidUtilCode/master/art/logo.png
[aucSvg]: https://img.shields.io/badge/AndroidUtilCode-v1.22.10-brightgreen.svg
[aucSvg]: https://img.shields.io/badge/AndroidUtilCode-v1.22.11-brightgreen.svg
[auc]: https://github.com/Blankj/AndroidUtilCode
[apiSvg]: https://img.shields.io/badge/API-14+-brightgreen.svg
......
......@@ -41,7 +41,7 @@ If this project helps you a lot and you want to support the project's developmen
[logo]: https://raw.githubusercontent.com/Blankj/AndroidUtilCode/master/art/logo.png
[aucSvg]: https://img.shields.io/badge/AndroidUtilCode-v1.22.10-brightgreen.svg
[aucSvg]: https://img.shields.io/badge/AndroidUtilCode-v1.22.11-brightgreen.svg
[auc]: https://github.com/Blankj/AndroidUtilCode
[apiSvg]: https://img.shields.io/badge/API-14+-brightgreen.svg
......
......@@ -5,8 +5,8 @@ ext {
compileSdkVersion = 27
minSdkVersion = 14
targetSdkVersion = 27
versionCode = 1_022_010
versionName = '1.22.10'// E.g. 1.9.72 => 1,009,072
versionCode = 1_022_011
versionName = '1.22.11'// E.g. 1.9.72 => 1,009,072
bus = [
isDebug: false,
......
......@@ -15,5 +15,5 @@ dependencies {
api dep.free_proguard
api 'com.r0adkll:slidableactivity:2.0.5'
compileOnly dep.leakcanary.android_no_op
// api 'com.blankj:utilcode:1.22.10'
// api 'com.blankj:utilcode:1.22.11'
}
\ No newline at end of file
......@@ -2,7 +2,7 @@
Gradle:
```groovy
implementation 'com.blankj:utilcode:1.22.10'
implementation 'com.blankj:utilcode:1.22.11'
```
......
......@@ -27,7 +27,7 @@ apply plugin: "com.blankj.bus"
给 base 模块添加 [AndroidUtilCode](https://github.com/Blankj/AndroidUtilCode) 依赖:
```groovy
api "com.blankj:utilcode:1.22.10"
api "com.blankj:utilcode:1.22.11"
```
比如 module0 中存在的 `Module0Activity.java`,我们通常都是在它内部写一个 `start` 函数来启动它,现在我们给它添加 `@BusUtils.Subscribe` 注解,并给注解的 `name` 赋唯一值,要注意,函数务必要 `public static` 哦:
......
......@@ -2,7 +2,7 @@
Gradle:
```groovy
implementation 'com.blankj:utilcode:1.22.10'
implementation 'com.blankj:utilcode:1.22.11'
```
......
//package com.blankj.utilcode.util;
//
//
//import org.json.JSONException;
//import org.json.JSONObject;
//
//public final class JsonUtils {
//
// private static byte TYPE_LONG = 0x01;
// private static byte TYPE_INT = 0x02;
//
// private JsonUtils() {
// throw new UnsupportedOperationException("u can't instantiate me...");
// }
//
// public static long getLong(final JSONObject jsonObject,
// final String key,
// final long defaultValue) {
// if (jsonObject == null || key == null || key.length() == 0) {
// return defaultValue;
// }
// try {
// return jsonObject.getLong(key);
// } catch (JSONException e) {
// return defaultValue;
// }
// }
//
// public static long getLong(final String json,
// final String key,
// final long defaultValue) {
// if (json == null || json.length() == 0
// || key == null || key.length() == 0) {
// return defaultValue;
// }
//
// try {
// return getLong(new JSONObject(json), key, defaultValue);
// } catch (JSONException e) {
// e.printStackTrace();
// return defaultValue;
// }
// }
//
// public static Object getType(final JSONObject jsonObject,
// final String key,
// final Object defaultValue,
// final byte type) {
// if (jsonObject == null || key == null || key.length() == 0) {
// return defaultValue;
// }
// try {
// if (type == TYPE_LONG) {
// return jsonObject.getLong(key);
// } else if (type == TYPE_INT) {
// return jsonObject.getInt(key);
// }
// } catch (JSONException e) {
// return defaultValue;
// }
// }
//
// public static long getLong(final String json,
// final String key,
// final long defaultValue) {
// if (json == null || json.length() == 0
// || key == null || key.length() == 0) {
// return defaultValue;
// }
//
// try {
// return getLong(new JSONObject(json), key, defaultValue);
// } catch (JSONException e) {
// e.printStackTrace();
// return defaultValue;
// }
// }
//
//}
package com.blankj.utilcode.util;
import android.util.Log;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
public final class JsonUtils {
private static final byte TYPE_BOOLEAN = 0x00;
private static final byte TYPE_INT = 0x01;
private static final byte TYPE_LONG = 0x02;
private static final byte TYPE_DOUBLE = 0x03;
private static final byte TYPE_STRING = 0x04;
private static final byte TYPE_JSON_OBJECT = 0x05;
private static final byte TYPE_JSON_ARRAY = 0x06;
private JsonUtils() {
throw new UnsupportedOperationException("u can't instantiate me...");
}
public static boolean getBoolean(final JSONObject jsonObject,
final String key) {
return getBoolean(jsonObject, key, false);
}
public static boolean getBoolean(final JSONObject jsonObject,
final String key,
final boolean defaultValue) {
return getValueByType(jsonObject, key, defaultValue, TYPE_BOOLEAN);
}
public static boolean getBoolean(final String json,
final String key) {
return getBoolean(json, key, false);
}
public static boolean getBoolean(final String json,
final String key,
final boolean defaultValue) {
return getValueByType(json, key, defaultValue, TYPE_BOOLEAN);
}
public static int getInt(final JSONObject jsonObject,
final String key) {
return getInt(jsonObject, key, -1);
}
public static int getInt(final JSONObject jsonObject,
final String key,
final int defaultValue) {
return getValueByType(jsonObject, key, defaultValue, TYPE_INT);
}
public static int getInt(final String json,
final String key) {
return getInt(json, key, -1);
}
public static int getInt(final String json,
final String key,
final int defaultValue) {
return getValueByType(json, key, defaultValue, TYPE_INT);
}
public static long getLong(final JSONObject jsonObject,
final String key) {
return getLong(jsonObject, key, -1);
}
public static long getLong(final JSONObject jsonObject,
final String key,
final long defaultValue) {
return getValueByType(jsonObject, key, defaultValue, TYPE_LONG);
}
public static long getLong(final String json,
final String key) {
return getLong(json, key, -1);
}
public static long getLong(final String json,
final String key,
final long defaultValue) {
return getValueByType(json, key, defaultValue, TYPE_LONG);
}
public static double getDouble(final JSONObject jsonObject,
final String key) {
return getDouble(jsonObject, key, -1);
}
public static double getDouble(final JSONObject jsonObject,
final String key,
final double defaultValue) {
return getValueByType(jsonObject, key, defaultValue, TYPE_DOUBLE);
}
public static double getDouble(final String json,
final String key) {
return getDouble(json, key, -1);
}
public static double getDouble(final String json,
final String key,
final double defaultValue) {
return getValueByType(json, key, defaultValue, TYPE_DOUBLE);
}
public static String getString(final JSONObject jsonObject,
final String key) {
return getString(jsonObject, key, "");
}
public static String getString(final JSONObject jsonObject,
final String key,
final String defaultValue) {
return getValueByType(jsonObject, key, defaultValue, TYPE_STRING);
}
public static String getString(final String json,
final String key) {
return getString(json, key, "");
}
public static String getString(final String json,
final String key,
final String defaultValue) {
return getValueByType(json, key, defaultValue, TYPE_STRING);
}
public static JSONObject getJSONObject(final JSONObject jsonObject,
final String key,
final JSONObject defaultValue) {
return getValueByType(jsonObject, key, defaultValue, TYPE_JSON_OBJECT);
}
public static JSONObject getJSONObject(final String json,
final String key,
final JSONObject defaultValue) {
return getValueByType(json, key, defaultValue, TYPE_JSON_OBJECT);
}
public static JSONArray getJSONArray(final JSONObject jsonObject,
final String key,
final JSONArray defaultValue) {
return getValueByType(jsonObject, key, defaultValue, TYPE_JSON_ARRAY);
}
public static JSONArray getJSONArray(final String json,
final String key,
final JSONArray defaultValue) {
return getValueByType(json, key, defaultValue, TYPE_JSON_ARRAY);
}
private static <T> T getValueByType(final JSONObject jsonObject,
final String key,
final T defaultValue,
final byte type) {
if (jsonObject == null || key == null || key.length() == 0) {
return defaultValue;
}
try {
Object ret;
if (type == TYPE_BOOLEAN) {
ret = jsonObject.getBoolean(key);
} else if (type == TYPE_INT) {
ret = jsonObject.getInt(key);
} else if (type == TYPE_LONG) {
ret = jsonObject.getLong(key);
} else if (type == TYPE_DOUBLE) {
ret = jsonObject.getDouble(key);
} else if (type == TYPE_STRING) {
ret = jsonObject.getString(key);
} else if (type == TYPE_JSON_OBJECT) {
ret = jsonObject.getJSONObject(key);
} else if (type == TYPE_JSON_ARRAY) {
ret = jsonObject.getJSONArray(key);
} else {
return defaultValue;
}
//noinspection unchecked
return (T) ret;
} catch (JSONException e) {
Log.e("JsonUtils", "getValueByType: ", e);
return defaultValue;
}
}
private static <T> T getValueByType(final String json,
final String key,
final T defaultValue,
final byte type) {
if (json == null || json.length() == 0
|| key == null || key.length() == 0) {
return defaultValue;
}
try {
return getValueByType(new JSONObject(json), key, defaultValue, type);
} catch (JSONException e) {
Log.e("JsonUtils", "getValueByType: ", e);
return defaultValue;
}
}
}
......@@ -14,7 +14,7 @@ import static org.junit.Assert.assertNull;
* desc : test CacheMemoryStaticUtils
* </pre>
*/
public class CacheMemoryStaticUtilsTest {
public class CacheMemoryStaticUtilsTest extends BaseTest {
private CacheMemoryUtils mCacheMemoryUtils = CacheMemoryUtils.getInstance(3);
......
......@@ -14,7 +14,7 @@ import static org.junit.Assert.assertNull;
* desc : test CacheMemoryUtils
* </pre>
*/
public class CacheMemoryUtilsTest {
public class CacheMemoryUtilsTest extends BaseTest {
private CacheMemoryUtils mCacheMemoryUtils1 = CacheMemoryUtils.getInstance();
private CacheMemoryUtils mCacheMemoryUtils2 = CacheMemoryUtils.getInstance(3);
......
......@@ -20,7 +20,7 @@ import static org.junit.Assert.assertTrue;
* desc : test ConvertUtils
* </pre>
*/
public class ConvertUtilsTest {
public class ConvertUtilsTest extends BaseTest {
private byte[] mBytes = new byte[]{0x00, 0x08, (byte) 0xdb, 0x33, 0x45, (byte) 0xab, 0x02, 0x23};
private String hexString = "0008DB3345AB0223";
......
......@@ -17,7 +17,7 @@ import static com.blankj.utilcode.util.TestConfig.PATH_TEMP;
* desc : test FileIOUtils
* </pre>
*/
public class FileIOUtilsTest {
public class FileIOUtilsTest extends BaseTest {
@Test
public void writeFileFromIS() throws Exception {
......
......@@ -22,7 +22,7 @@ import static org.junit.Assert.assertTrue;
* desc : test FileUtils
* </pre>
*/
public class FileUtilsTest {
public class FileUtilsTest extends BaseTest {
private FileFilter mFilter = new FileFilter() {
@Override
......
......@@ -12,7 +12,7 @@ import org.junit.Test;
* desc : test GsonUtils
* </pre>
*/
public class GsonUtilsTest {
public class GsonUtilsTest extends BaseTest {
@Test
public void getGson() {
......
......@@ -8,9 +8,6 @@ import android.util.SparseIntArray;
import android.util.SparseLongArray;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config;
import java.util.HashMap;
import java.util.LinkedList;
......@@ -26,9 +23,7 @@ import static org.junit.Assert.assertTrue;
* desc : test ObjectUtils
* </pre>
*/
@RunWith(RobolectricTestRunner.class)
@Config(manifest = Config.NONE, sdk = 23)
public class ObjectUtilsTest {
public class ObjectUtilsTest extends BaseTest {
@Test
public void isEmpty() {
......
......@@ -15,7 +15,7 @@ import static org.junit.Assert.assertTrue;
* desc : test RegexUtils
* </pre>
*/
public class RegexUtilsTest {
public class RegexUtilsTest extends BaseTest {
@Test
public void isMobileSimple() {
......
......@@ -14,7 +14,7 @@ import static org.junit.Assert.assertTrue;
* desc : test StringUtils
* </pre>
*/
public class StringUtilsTest {
public class StringUtilsTest extends BaseTest {
@Test
public void isEmpty() {
......
......@@ -14,7 +14,7 @@ import java.util.concurrent.atomic.AtomicInteger;
* desc :
* </pre>
*/
public class ThreadUtilsTest {
public class ThreadUtilsTest extends BaseTest {
@Test
public void executeByFixed() throws Exception {
......
......@@ -23,7 +23,7 @@ import static org.junit.Assert.assertTrue;
* desc : test TimeUtils
* </pre>
*/
public class TimeUtilsTest {
public class TimeUtilsTest extends BaseTest {
private final DateFormat defaultFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault());
private final DateFormat mFormat = new SimpleDateFormat("yyyy MM dd HH:mm:ss", Locale.getDefault());
......
......@@ -19,7 +19,7 @@ import static junit.framework.TestCase.assertTrue;
* desc : test ZipUtils
* </pre>
*/
public class ZipUtilsTest {
public class ZipUtilsTest extends BaseTest {
private String zipFile = PATH_TEMP + "zipFile.zip";
private String zipFiles = PATH_TEMP + "zipFiles.zip";
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册