From 1fa64518cf3b501adc289d136f3ba7a916741fd0 Mon Sep 17 00:00:00 2001 From: travelgeezer Date: Thu, 21 Sep 2017 16:48:05 +0800 Subject: [PATCH] Try compatible miui --- .../com/beefe/picker/PickerViewModule.java | 7 +- .../beefe/picker/util/BuildProperties.java | 72 +++++++++++++++++++ .../java/com/beefe/picker/util/MIUIUtils.java | 25 +++++++ 3 files changed, 103 insertions(+), 1 deletion(-) create mode 100644 android/src/main/java/com/beefe/picker/util/BuildProperties.java create mode 100644 android/src/main/java/com/beefe/picker/util/MIUIUtils.java diff --git a/android/src/main/java/com/beefe/picker/PickerViewModule.java b/android/src/main/java/com/beefe/picker/PickerViewModule.java index ed90d24..88ed90e 100644 --- a/android/src/main/java/com/beefe/picker/PickerViewModule.java +++ b/android/src/main/java/com/beefe/picker/PickerViewModule.java @@ -13,6 +13,7 @@ import android.view.WindowManager; import android.widget.RelativeLayout; import android.widget.TextView; +import com.beefe.picker.util.MIUIUtils; import com.beefe.picker.view.OnSelectedListener; import com.beefe.picker.view.PickerViewAlone; import com.beefe.picker.view.PickerViewLinkage; @@ -349,8 +350,12 @@ public class PickerViewModule extends ReactContextBaseJavaModule implements Life WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams(); Window window = dialog.getWindow(); if (window != null) { + if (MIUIUtils.isMIUI()) { + layoutParams.type = WindowManager.LayoutParams.TYPE_APPLICATION; + }else { + layoutParams.type = WindowManager.LayoutParams.TYPE_TOAST; + } layoutParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE; - layoutParams.type = WindowManager.LayoutParams.TYPE_TOAST; layoutParams.format = PixelFormat.TRANSPARENT; layoutParams.windowAnimations = R.style.PickerAnim; layoutParams.width = WindowManager.LayoutParams.MATCH_PARENT; diff --git a/android/src/main/java/com/beefe/picker/util/BuildProperties.java b/android/src/main/java/com/beefe/picker/util/BuildProperties.java new file mode 100644 index 0000000..dc5298d --- /dev/null +++ b/android/src/main/java/com/beefe/picker/util/BuildProperties.java @@ -0,0 +1,72 @@ +package com.beefe.picker.util; + +/** + * Created by geezer. on 2017/9/21. + */ + +import android.os.Environment; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.util.Collection; +import java.util.Enumeration; +import java.util.Map.Entry; +import java.util.Properties; +import java.util.Set; + + +public class BuildProperties { + + private final Properties properties; + + private BuildProperties() throws IOException { + properties = new Properties(); + properties.load(new FileInputStream(new File(Environment.getRootDirectory(), "build.prop"))); + } + + public boolean containsKey(final Object key) { + return properties.containsKey(key); + } + + public boolean containsValue(final Object value) { + return properties.containsValue(value); + } + + public Set> entrySet() { + return properties.entrySet(); + } + + public String getProperty(final String name) { + return properties.getProperty(name); + } + + public String getProperty(final String name, final String defaultValue) { + return properties.getProperty(name, defaultValue); + } + + public boolean isEmpty() { + return properties.isEmpty(); + } + + public Enumeration keys() { + return properties.keys(); + } + + public Set keySet() { + return properties.keySet(); + } + + public int size() { + return properties.size(); + } + + public Collection values() { + return properties.values(); + } + + public static BuildProperties newInstance() throws IOException { + return new BuildProperties(); + } + +} diff --git a/android/src/main/java/com/beefe/picker/util/MIUIUtils.java b/android/src/main/java/com/beefe/picker/util/MIUIUtils.java new file mode 100644 index 0000000..573a6f4 --- /dev/null +++ b/android/src/main/java/com/beefe/picker/util/MIUIUtils.java @@ -0,0 +1,25 @@ +package com.beefe.picker.util; + +import java.io.IOException; + +/** + * Created by geezer. on 2017/9/21. + */ + +public final class MIUIUtils { + + 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"; + + public static boolean isMIUI() { + try { + final BuildProperties prop = BuildProperties.newInstance(); + return prop.getProperty(KEY_MIUI_VERSION_CODE, null) != null + || prop.getProperty(KEY_MIUI_VERSION_NAME, null) != null + || prop.getProperty(KEY_MIUI_INTERNAL_STORAGE, null) != null; + } catch (final IOException e) { + return false; + } + } +} -- 2.26.2