diff --git a/README-CN.md b/README-CN.md
index a160ff4ca0..0d9db8560c 100644
--- a/README-CN.md
+++ b/README-CN.md
@@ -41,7 +41,7 @@
[logo]: https://raw.githubusercontent.com/Blankj/AndroidUtilCode/master/art/logo.png
-[aucsvg]: https://img.shields.io/badge/AndroidUtilCode-v1.17.2-brightgreen.svg
+[aucsvg]: https://img.shields.io/badge/AndroidUtilCode-v1.17.3-brightgreen.svg
[auc]: https://github.com/Blankj/AndroidUtilCode
[apisvg]: https://img.shields.io/badge/API-14+-brightgreen.svg
diff --git a/app/src/main/java/com/blankj/androidutilcode/feature/core/keyboard/KeyboardActivity.java b/app/src/main/java/com/blankj/androidutilcode/feature/core/keyboard/KeyboardActivity.java
index 07fd38a17b..560698b794 100644
--- a/app/src/main/java/com/blankj/androidutilcode/feature/core/keyboard/KeyboardActivity.java
+++ b/app/src/main/java/com/blankj/androidutilcode/feature/core/keyboard/KeyboardActivity.java
@@ -10,7 +10,7 @@
import android.widget.TextView;
import com.blankj.androidutilcode.R;
-import com.blankj.androidutilcode.base.BaseBackActivity;
+import com.blankj.androidutilcode.base.BaseActivity;
import com.blankj.androidutilcode.helper.DialogHelper;
import com.blankj.utilcode.util.KeyboardUtils;
import com.blankj.utilcode.util.SpanUtils;
@@ -23,7 +23,7 @@
* desc : demo about KeyboardUtils
*
*/
-public class KeyboardActivity extends BaseBackActivity {
+public class KeyboardActivity extends BaseActivity{
public static void start(Context context) {
Intent starter = new Intent(context, KeyboardActivity.class);
@@ -41,13 +41,13 @@ public void initData(@Nullable Bundle bundle) {
@Override
public int bindLayout() {
- return R.layout.activity_keyboard;
+ return R.layout.activity_keyboard1;
}
@Override
public void initView(Bundle savedInstanceState, View contentView) {
KeyboardUtils.fixAndroidBug5497(this);
- getToolBar().setTitle(getString(R.string.demo_keyboard));
+// getToolBar().setTitle(getString(R.string.demo_keyboard));
etInput = findViewById(R.id.et_input);
findViewById(R.id.btn_hide_soft_input).setOnClickListener(this);
findViewById(R.id.btn_show_soft_input).setOnClickListener(this);
diff --git a/app/src/main/res_core/layout/activity_keyboard1.xml b/app/src/main/res_core/layout/activity_keyboard1.xml
new file mode 100644
index 0000000000..aae8a3925b
--- /dev/null
+++ b/app/src/main/res_core/layout/activity_keyboard1.xml
@@ -0,0 +1,50 @@
+
+
+ * author: Blankj + * blog : http://blankj.com + * time : 2018/07/04 + * desc : utils about rom + *+ */ +public final class RomUtils { + + public static final String SYS_EMUI = "emui"; + public static final String SYS_MIUI = "miui"; + public static final String SYS_FLYME = "flyme"; + public static final String SYS_COLOROS = "colorOs"; + public static final String SYS_FUNTOUCH = "Funtouch"; + public static final String SYS_SAMSUNG = "samsung"; + + /////////////////////////////////////////////////////////////////////////// + // MIUI + /////////////////////////////////////////////////////////////////////////// + private static final String KEY_MIUI_VERSION_CODE = "ro.miui.ui.version.code"; + private static final String KEY_MIUI_VERSION_NAME = "ro.miui.ui.version.name"; + private static final String KEY_MIUI_INTERNAL_STORAGE = "ro.miui.internal.storage"; + private static final String KEY_MIUI_VERSION_INCREMENTAL = "ro.build.version.incremental"; + + /////////////////////////////////////////////////////////////////////////// + // EMUI + /////////////////////////////////////////////////////////////////////////// + private static final String KEY_EMUI_API_LEVEL = "ro.build.hw_emui_api_level"; + private static final String KEY_EMUI_VERSION = "ro.build.version.emui"; + private static final String KEY_EMUI_CONFIG_HW_SYS_VERSION = "ro.confg.hw_systemversion"; + + /////////////////////////////////////////////////////////////////////////// + // OPPO + /////////////////////////////////////////////////////////////////////////// + private static final String KEY_OPPO_NAME = "ro.rom.different.version"; + private static final String KEY_OPPO_VERSION = "ro.build.version.opporom"; + + /////////////////////////////////////////////////////////////////////////// + // VIVO + /////////////////////////////////////////////////////////////////////////// + private static final String KEY_VIVO_NAME = "ro.vivo.os.name"; + private static final String KEY_VIVO_VERSION = "ro.vivo.os.version"; + + private static RomBean bean = null; + + /** + * Return the name of rom. + * + * @return the name of rom + */ + public static RomBean getRom() { + if (bean != null) return bean; + bean = new RomBean(); + // 小米 + if (!TextUtils.isEmpty(getSystemProperty(KEY_MIUI_VERSION_CODE)) + || !TextUtils.isEmpty(getSystemProperty(KEY_MIUI_VERSION_NAME)) + || !TextUtils.isEmpty(getSystemProperty(KEY_MIUI_INTERNAL_STORAGE))) { + bean.setRomName(SYS_MIUI); + bean.setRomVersion(getSystemProperty(KEY_MIUI_VERSION_INCREMENTAL)); + } + // 华为 + else if (!TextUtils.isEmpty(getSystemProperty(KEY_EMUI_API_LEVEL)) + || !TextUtils.isEmpty(getSystemProperty(KEY_EMUI_VERSION)) + || !TextUtils.isEmpty(getSystemProperty(KEY_EMUI_CONFIG_HW_SYS_VERSION))) { + bean.setRomName(SYS_EMUI); + String version = getSystemProperty(KEY_EMUI_VERSION);// EmotionUI_2.0 + String[] temp = version.split("_"); + if (temp.length > 1) { + bean.setRomVersion(temp[1]); + } else { + bean.setRomVersion(version); + } + } + // 魅族 + else if (Build.DISPLAY.toLowerCase().contains("flyme")) { + bean.setRomName(SYS_FLYME); + bean.setRomVersion(Build.DISPLAY); + return bean; + } + // OPPO + else if (!TextUtils.isEmpty(getSystemProperty(KEY_OPPO_NAME)) && + getSystemProperty(KEY_OPPO_NAME).toLowerCase().contains("coloros")) { + bean.setRomName(SYS_COLOROS); + bean.setRomVersion(getSystemProperty(KEY_OPPO_VERSION)); + } + // VIVO + else if (!TextUtils.isEmpty(getSystemProperty(KEY_VIVO_NAME))) { + bean.setRomName(SYS_FUNTOUCH); + bean.setRomVersion(getSystemProperty(KEY_VIVO_VERSION)); + } + // 其他手机 + else { + String brand = Build.BRAND; + bean.setRomName(Build.BRAND); + if (SYS_SAMSUNG.equalsIgnoreCase(brand)) { + bean.setRomVersion(getSystemProperty("ro.build.changelist")); + } + } + return bean; + } + + private static String getSystemProperty(final String name) { + String prop = getSystemPropertyByShell(name); + if (!TextUtils.isEmpty(prop)) return prop; + prop = getSystemPropertyByStream(name); + if (!TextUtils.isEmpty(prop)) return prop; + if (Build.VERSION.SDK_INT < 28) { + return getSystemPropertyByReflect(name); + } + return prop; + } + + private static String getSystemPropertyByShell(final String propName) { + String line; + BufferedReader input = null; + try { + Process p = Runtime.getRuntime().exec("getprop " + propName); + input = new BufferedReader(new InputStreamReader(p.getInputStream()), 1024); + return input.readLine(); + } catch (IOException e) { + return ""; + } finally { + if (input != null) { + try { + input.close(); + } catch (IOException ignore) { + + } + } + } + } + + private static String getSystemPropertyByStream(final String key) { + try { + Properties prop = new Properties(); + FileInputStream is = new FileInputStream( + new File(Environment.getRootDirectory(), "build.prop") + ); + prop.load(is); + return prop.getProperty(key, ""); + } catch (Exception e) { + e.printStackTrace(); + return ""; + } + } + + private static String getSystemPropertyByReflect(String key) { + try { + @SuppressLint("PrivateApi") + Class> clz = Class.forName("android.os.SystemProperties"); + Method get = clz.getMethod("get", String.class, String.class); + return (String) get.invoke(clz, key, ""); + } catch (Exception e) { + return ""; + } + } + + public static class RomBean { + private String romName; + private String romVersion; + + public String getRomName() { + if (romName == null) return ""; + return romName; + } + + private void setRomName(String romName) { + this.romName = romName; + } + + public String getRomVersion() { + if (romVersion == null) return ""; + return romVersion; + } + + private void setRomVersion(String romVersion) { + this.romVersion = romVersion; + } + + @Override + public String toString() { + return "romName: " + romName + + "\nromVersion: " + romVersion; + } + } +} diff --git a/update_log.md b/update_log.md index 7a7d006f5f..fecd13b0fd 100644 --- a/update_log.md +++ b/update_log.md @@ -1,3 +1,4 @@ +* 18/06/29 修复 IntentUtils 分享图片判断逻辑,CacheDiskUtils 可放入 byte[0],发布 1.17.3 * 18/06/29 修复 FragmentUtils 中 getFragmentManager 空指针错误,发布 1.17.2 * 18/06/27 新增 UriUtils#uri2File * 18/06/25 新增 KeyboardUtils#fixAndroidBug5497,发布 1.17.1 版本 diff --git a/utilcode/README-CN.md b/utilcode/README-CN.md index f7e76aae9d..36cff1acad 100644 --- a/utilcode/README-CN.md +++ b/utilcode/README-CN.md @@ -2,7 +2,7 @@ Gradle: ```groovy -implementation 'com.blankj:utilcode:1.17.2' +implementation 'com.blankj:utilcode:1.17.3' ``` diff --git a/utilcode/README.md b/utilcode/README.md index ae5bf67112..a08f99a708 100644 --- a/utilcode/README.md +++ b/utilcode/README.md @@ -2,7 +2,7 @@ Gradle: ```groovy -implementation 'com.blankj:utilcode:1.17.2' +implementation 'com.blankj:utilcode:1.17.3' ``` diff --git a/utilcode/src/main/java/com/blankj/utilcode/util/CacheDiskUtils.java b/utilcode/src/main/java/com/blankj/utilcode/util/CacheDiskUtils.java index 30d3fd5876..aed0ec7d66 100644 --- a/utilcode/src/main/java/com/blankj/utilcode/util/CacheDiskUtils.java +++ b/utilcode/src/main/java/com/blankj/utilcode/util/CacheDiskUtils.java @@ -172,7 +172,7 @@ public void put(@NonNull final String key, final byte[] value) { * @param saveTime The save time of cache, in seconds. */ public void put(@NonNull final String key, byte[] value, final int saveTime) { - if (value == null || value.length <= 0) return; + if (value == null) return; if (saveTime >= 0) value = DiskCacheHelper.newByteArrayWithTime(saveTime, value); File file = mDiskCacheManager.getFileBeforePut(key); DiskCacheHelper.writeFileFromBytes(file, value); diff --git a/utilcode/src/main/java/com/blankj/utilcode/util/CacheMemoryUtils.java b/utilcode/src/main/java/com/blankj/utilcode/util/CacheMemoryUtils.java index b48e5cfed0..6e48d5adb8 100644 --- a/utilcode/src/main/java/com/blankj/utilcode/util/CacheMemoryUtils.java +++ b/utilcode/src/main/java/com/blankj/utilcode/util/CacheMemoryUtils.java @@ -6,8 +6,6 @@ import com.blankj.utilcode.constant.CacheConstants; -import java.lang.reflect.Array; - /** *
* author: Blankj @@ -79,7 +77,6 @@ public void put(@NonNull final String key, final Object value) { */ public void put(@NonNull final String key, final Object value, int saveTime) { if (value == null) return; - if (value.getClass().isArray() && Array.getLength(value) <= 0) return; long dueTime = saveTime < 0 ? -1 : System.currentTimeMillis() + saveTime * 1000; mMemoryCache.put(key, new CacheValue(dueTime, value)); } diff --git a/utilcode/src/main/java/com/blankj/utilcode/util/CacheUtils.java b/utilcode/src/main/java/com/blankj/utilcode/util/CacheUtils.java index 11dfca4c9c..b40dc6cac9 100644 --- a/utilcode/src/main/java/com/blankj/utilcode/util/CacheUtils.java +++ b/utilcode/src/main/java/com/blankj/utilcode/util/CacheUtils.java @@ -175,7 +175,7 @@ public void put(@NonNull final String key, final byte[] value) { * @param saveTime The save time of cache, in seconds. */ public void put(@NonNull final String key, byte[] value, final int saveTime) { - if (value == null || value.length <= 0) return; + if (value == null) return; if (saveTime >= 0) value = DiskCacheHelper.newByteArrayWithTime(saveTime, value); File file = mDiskCacheManager.getFileBeforePut(key); DiskCacheHelper.writeFileFromBytes(file, value); diff --git a/utilcode/src/main/java/com/blankj/utilcode/util/IntentUtils.java b/utilcode/src/main/java/com/blankj/utilcode/util/IntentUtils.java index cd887b73e8..def756710a 100644 --- a/utilcode/src/main/java/com/blankj/utilcode/util/IntentUtils.java +++ b/utilcode/src/main/java/com/blankj/utilcode/util/IntentUtils.java @@ -10,6 +10,9 @@ import android.support.v4.content.FileProvider; import java.io.File; +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; import static android.Manifest.permission.CALL_PHONE; @@ -309,8 +312,8 @@ public static Intent getShareImageIntent(final String content, final File image) public static Intent getShareImageIntent(final String content, final File image, final boolean isNewTask) { - if (image != null && image.isFile()) return null; - return getShareImageIntent(content, Uri.fromFile(image), isNewTask); + if (image == null || !image.isFile()) return null; + return getShareImageIntent(content, file2Uri(image), isNewTask); } /** @@ -342,6 +345,96 @@ public static Intent getShareImageIntent(final String content, return getIntent(intent, isNewTask); } + /** + * Return the intent of share images. + * + * @param content The content. + * @param imagePaths The paths of images. + * @return the intent of share images + */ + public static Intent getShareImageIntent(final String content, final LinkedListimagePaths) { + return getShareImageIntent(content, imagePaths, false); + } + + /** + * Return the intent of share images. + * + * @param content The content. + * @param imagePaths The paths of images. + * @param isNewTask True to add flag of new task, false otherwise. + * @return the intent of share images + */ + public static Intent getShareImageIntent(final String content, + final LinkedList imagePaths, + final boolean isNewTask) { + if (imagePaths == null || imagePaths.isEmpty()) return null; + List files = new ArrayList<>(); + for (String imagePath : imagePaths) { + files.add(new File(imagePath)); + } + return getShareImageIntent(content, files, isNewTask); + } + + /** + * Return the intent of share images. + * + * @param content The content. + * @param images The files of images. + * @return the intent of share images + */ + public static Intent getShareImageIntent(final String content, final List images) { + return getShareImageIntent(content, images, false); + } + + /** + * Return the intent of share images. + * + * @param content The content. + * @param images The files of images. + * @param isNewTask True to add flag of new task, false otherwise. + * @return the intent of share images + */ + public static Intent getShareImageIntent(final String content, + final List images, + final boolean isNewTask) { + if (images == null || images.isEmpty()) return null; + ArrayList uris = new ArrayList<>(); + for (File image : images) { + if (!image.isFile()) continue; + uris.add(file2Uri(image)); + } + return getShareImageIntent(content, uris, isNewTask); + } + + /** + * Return the intent of share images. + * + * @param content The content. + * @param uris The uris of images. + * @return the intent of share images + */ + public static Intent getShareImageIntent(final String content, final ArrayList uris) { + return getShareImageIntent(content, uris, false); + } + + /** + * Return the intent of share images. + * + * @param content The content. + * @param uris The uris of image. + * @param isNewTask True to add flag of new task, false otherwise. + * @return the intent of share image + */ + public static Intent getShareImageIntent(final String content, + final ArrayList uris, + final boolean isNewTask) { + Intent intent = new Intent(Intent.ACTION_SEND_MULTIPLE); + intent.putExtra(Intent.EXTRA_TEXT, content); + intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris); + intent.setType("image/*"); + return getIntent(intent, isNewTask); + } + /** * Return the intent of component. * @@ -548,6 +641,16 @@ private static boolean isSpace(final String s) { return true; } + private static Uri file2Uri(final File file) { + if (file == null) return null; + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { + String authority = Utils.getApp().getPackageName() + ".utilcode.provider"; + return FileProvider.getUriForFile(Utils.getApp(), authority, file); + } else { + return Uri.fromFile(file); + } + } + // /** // * 获取选择照片的 Intent // * diff --git a/version.gradle b/version.gradle index ced980c8a0..c937038a2e 100644 --- a/version.gradle +++ b/version.gradle @@ -4,8 +4,8 @@ ext{ min_sdk_version = 14 target_sdk_version = 27 - version_code = 1_017_002 - version_name = '1.17.2'// E.g 1.9.72 => 1,009,072 + version_code = 1_017_003 + version_name = '1.17.3'// E.g 1.9.72 => 1,009,072 // App dependencies support_version = '27.1.0'