diff --git a/foudations/mogo-utils/.gitignore b/foudations/mogo-utils/.gitignore deleted file mode 100644 index 796b96d1c4..0000000000 --- a/foudations/mogo-utils/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/build diff --git a/foudations/mogo-utils/build.gradle b/foudations/mogo-utils/build.gradle deleted file mode 100644 index 0e04911b9a..0000000000 --- a/foudations/mogo-utils/build.gradle +++ /dev/null @@ -1,55 +0,0 @@ -apply plugin: 'com.android.library' -apply plugin: 'kotlin-android' -apply plugin: 'kotlin-android-extensions' -android { - compileSdkVersion rootProject.ext.android.compileSdkVersion - // buildToolsVersion rootProject.ext.android.buildToolsVersion - defaultConfig { - minSdkVersion rootProject.ext.android.minSdkVersion - targetSdkVersion rootProject.ext.android.targetSdkVersion - versionCode Integer.valueOf(VERSION_CODE) - versionName getValueFromRootProperties("${project.name.replace("-", "_").toUpperCase()}_VERSION") - - testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" - consumerProguardFiles 'consumer-rules.pro' - } - - buildTypes { - release { - minifyEnabled false - proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' - } - } - - compileOptions { - sourceCompatibility JavaVersion.VERSION_1_8 - targetCompatibility JavaVersion.VERSION_1_8 - } - -} - -dependencies { - implementation fileTree(dir: 'libs', include: ['*.jar']) - api rootProject.ext.dependencies.glide - implementation rootProject.ext.dependencies.kotlinstdlibjdk7 - implementation rootProject.ext.dependencies.coroutinescore - implementation rootProject.ext.dependencies.coroutinesandroid - implementation rootProject.ext.dependencies.glideanno - implementation rootProject.ext.dependencies.glideokhttp3 - implementation rootProject.ext.dependencies.androidxannotation - annotationProcessor rootProject.ext.dependencies.androidxannotation - annotationProcessor rootProject.ext.dependencies.glidecompiler - implementation rootProject.ext.dependencies.androidxappcompat - api 'ch.hsr:geohash:1.4.0' - - api rootProject.ext.dependencies.mogoaicloudnetwork - api rootProject.ext.dependencies.mogoaicloudpassport - - if (Boolean.valueOf(USE_MAVEN_PACKAGE)) { - implementation rootProject.ext.dependencies.mogo_core_data - } else { - implementation project(':core:mogo-core-data') - } -} - -apply from: new File(rootProject.rootDir, "gradle/upload.gradle").toString() diff --git a/foudations/mogo-utils/consumer-rules.pro b/foudations/mogo-utils/consumer-rules.pro deleted file mode 100644 index a5769c6fed..0000000000 --- a/foudations/mogo-utils/consumer-rules.pro +++ /dev/null @@ -1,8 +0,0 @@ -#-----MogoUtils----- --keep class com.mogo.utils.network.CallerType --keep class com.mogo.utils.network.CallerRestrictTo --keep class com.mogo.utils.glide.GlideRoundedCornersTransform.CornerType --keep class com.mogo.utils.logger.LogLevel{*;} --keep class com.mogo.utils.sqlite.**{*;} --keep class com.mogo.utils.network.HttpDns{*;} --keep class com.mogo.httpdnshelper.sdk.**{*;} \ No newline at end of file diff --git a/foudations/mogo-utils/gradle.properties b/foudations/mogo-utils/gradle.properties deleted file mode 100644 index 914f308c6e..0000000000 --- a/foudations/mogo-utils/gradle.properties +++ /dev/null @@ -1,3 +0,0 @@ -GROUP=com.mogo.commons -POM_ARTIFACT_ID=mogo-utils -VERSION_CODE=1 diff --git a/foudations/mogo-utils/proguard-rules.pro b/foudations/mogo-utils/proguard-rules.pro deleted file mode 100644 index 664ac30532..0000000000 --- a/foudations/mogo-utils/proguard-rules.pro +++ /dev/null @@ -1,27 +0,0 @@ -# Add project specific ProGuard rules here. -# You can control the set of applied configuration files using the -# proguardFiles setting in build.gradle. -# -# For more details, see -# http://developer.android.com/guide/developing/tools/proguard.html - -# If your project uses WebView with JS, uncomment the following -# and specify the fully qualified class name to the JavaScript interface -# class: -#-keepclassmembers class fqcn.of.javascript.interface.for.webview { -# public *; -#} - -# Uncomment this to preserve the line number information for -# debugging stack traces. -#-keepattributes SourceFile,LineNumberTable - -# If you keep the line number information, uncomment this to -# hide the original source file name. -#-renamesourcefileattribute SourceFile - -#-----MogoUtils----- --keep class com.mogo.utils.network.CallerType --keep class com.mogo.utils.network.CallerRestrictTo --keep class com.mogo.utils.glide.GlideRoundedCornersTransform.CornerType --keep class com.mogo.utils.logger.LogLevel \ No newline at end of file diff --git a/foudations/mogo-utils/src/main/AndroidManifest.xml b/foudations/mogo-utils/src/main/AndroidManifest.xml deleted file mode 100644 index 9febd3d8f7..0000000000 --- a/foudations/mogo-utils/src/main/AndroidManifest.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - diff --git a/foudations/mogo-utils/src/main/java/com/mogo/utils/CheckUtils.java b/foudations/mogo-utils/src/main/java/com/mogo/utils/CheckUtils.java deleted file mode 100644 index 39f653cf3b..0000000000 --- a/foudations/mogo-utils/src/main/java/com/mogo/utils/CheckUtils.java +++ /dev/null @@ -1,199 +0,0 @@ -package com.mogo.utils; - -import android.content.Context; -import android.graphics.Rect; -import android.net.ConnectivityManager; -import android.net.NetworkInfo; -import android.provider.Settings; -import android.text.TextUtils; -import android.view.MotionEvent; -import android.view.View; - -import androidx.annotation.Nullable; - -import java.util.Collection; -import java.util.Map; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -public class CheckUtils { - - /** - * 检查任意Object是否为空 - *
- * shallow check : 不会检查容器内部的元素是否为空 - */ - public static boolean isEmpty( Object obj) { - - if (obj == null) { - return true; - } - - if (obj instanceof Collection ) { - // 检查各种Collection是否为空(List,Queue,Set) - return (( Collection ) obj).isEmpty(); - } else if (obj instanceof Map ) { - // 检查各种Map - return (( Map ) obj).isEmpty(); - } else if (obj instanceof CharSequence ) { - // 检查各种CharSequence - return (( CharSequence ) obj).length() == 0; - } else if (obj.getClass().isArray()) { - // 检查各种base array - // return Array.getLength(obj) == 0; - if (obj instanceof Object[]) { - return (( Object[]) obj).length == 0; - } else if (obj instanceof int[]) { - return ((int[]) obj).length == 0; - } else if (obj instanceof long[]) { - return ((long[]) obj).length == 0; - } else if (obj instanceof short[]) { - return ((short[]) obj).length == 0; - } else if (obj instanceof double[]) { - return ((double[]) obj).length == 0; - } else if (obj instanceof float[]) { - return ((float[]) obj).length == 0; - } else if (obj instanceof boolean[]) { - return ((boolean[]) obj).length == 0; - } else if (obj instanceof char[]) { - return ((char[]) obj).length == 0; - } else if (obj instanceof byte[]) { - return ((byte[]) obj).length == 0; - } - } - - return false; - } - - public static boolean isExist( Object obj) { - return !isEmpty(obj); - } - - public static boolean isContainsEmpty( Object... objs) { - if (isEmpty(objs)) { - return true; - } - for ( Object obj : objs) { - if (isEmpty(obj)) { - return true; - } - } - return false; - } - - /** - * 是否为奇数 - */ - public static boolean isOdd(int i) { - return i % 2 != 0; - } - - /** - * 是否为偶数 - */ - public static boolean isEven(int i) { - return i % 2 == 0; - } - - /** - * 检查枚举组中是否包含指定枚举 - */ - public static boolean isContainsEnum( @Nullable Enum[] group, Enum child) { - - if (isEmpty(group)) { - return false; - } - - for ( Enum enums : group) { - if (enums == child) { - return true; - } - } - return false; - } - - /** - * 快速点击事件 - */ - private static long lastClickTime; - public static boolean isFastDoubleClick() { - long time = System.currentTimeMillis(); - long timeD = time - lastClickTime; - long delayTime = 500L; - if (0L < timeD && timeD < delayTime) { - return true; - } else { - lastClickTime = time; - return false; - } - } - - /** - * 网络是否可用 - */ - public static boolean isNetworkConnected( Context context) { - if ( context == null ) { - return false; - } - ConnectivityManager cm = ( ConnectivityManager ) context.getSystemService( Context.CONNECTIVITY_SERVICE); - NetworkInfo network = null; - if (cm != null) { - network = cm.getActiveNetworkInfo(); - } - return network != null && network.isAvailable() && network.isConnected(); - - } - - /** - * 检查gps开关是否已打开 - */ - public static boolean isGpsOpenStatus( Context context) { - if ( context == null ) { - return false; - } - String gps = Settings.System.getString(context.getContentResolver(), Settings.System.LOCATION_PROVIDERS_ALLOWED); - return !( TextUtils.isEmpty(gps) || !gps.contains("gps")); - } - - /** - * 检查是否模拟位置 - */ - public static boolean isOPenMockLocation( Context context) { - if ( context == null ) { - return false; - } - return Settings.Secure.getInt(context.getContentResolver(), Settings.Secure.ALLOW_MOCK_LOCATION, 0) != 0; - } - - /**当前点击点是否在视图中*/ - public static boolean isInsideView( MotionEvent event, View view) { - if (view != null && event != null) { - float eventX = event.getRawX(); - float eventY = event.getRawY(); - - int[] contentArray = new int[2]; - - Rect contentRect = new Rect(); - view.getLocationOnScreen(contentArray); - view.getDrawingRect(contentRect); - contentRect.offsetTo(contentArray[0], contentArray[1]); - - return contentRect.contains((int) eventX, (int) eventY); - } - - return false; - } - - /** - * 判断扫描内容是否为url格式 - */ - public static boolean isUrl( String url) { - if ( TextUtils.isEmpty(url)) { - return false; - } - String regex = "http(s)?://.*"; - Pattern pattern = Pattern.compile(regex, Pattern.CASE_INSENSITIVE); - Matcher m = pattern.matcher(url); - return m.matches(); - } -} diff --git a/foudations/mogo-utils/src/main/java/com/mogo/utils/Dispatch.java b/foudations/mogo-utils/src/main/java/com/mogo/utils/Dispatch.java deleted file mode 100644 index 2c5188a60e..0000000000 --- a/foudations/mogo-utils/src/main/java/com/mogo/utils/Dispatch.java +++ /dev/null @@ -1,501 +0,0 @@ -package com.mogo.utils; - -import java.io.Serializable; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.Comparator; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.NoSuchElementException; -import java.util.Objects; -import java.util.Random; -import java.util.Set; - -public final class Dispatch { - - private static final Dispatch EMPTY = new Dispatch<>(); - - private final T value; - - public Dispatch() { - this.value = null; - } - - private Dispatch(T value) { - this.value = requireNonNull(value); - } - - private static T requireNonNull(T obj) { - if (obj == null) { - throw new NullPointerException(); - } - return obj; - } - - private static Dispatch empty() { - Dispatch t = (Dispatch) EMPTY; - return t; - } - - public static Dispatch of(R value) { - return new Dispatch<>(value); - } - - public static Dispatch ofNullable(T value) { - return value == null ? (Dispatch) empty() : of(value); - } - - public static DispatchImpl stream(Collection collection) { - return new DispatchImpl<>(new ArrayList<>(collection)); - } - - public static DispatchImpl stream(R... values) { - List list = new ArrayList<>(); - for (R r : values) { - list.add(r); - } - return new DispatchImpl<>(list); - } - - public static DispatchImpl iterate(T seed, final Function mapper, int maxSize) { - List list = new ArrayList<>(); - list.add(seed); - if (maxSize - 1 > 0) { - for (int i = 0, len = maxSize - 1; i < len; i++) { - list.add(seed = mapper.apply(seed)); - } - } - return new DispatchImpl<>(list); - } - - public final T get() { - if (value == null) { - throw new NoSuchElementException("No value present"); - } - return value; - } - - public final boolean isPresent() { - return value != null; - } - - public final void ifPresent(Consumer consumer) { - if (value != null) { - consumer.accept(value); - } - } - - public final Dispatch filter(Predicate predicate) { - requireNonNull(predicate); - if (!isPresent()) { - return this; - } else { - return predicate.test(value) ? this : (Dispatch) empty(); - } - } - - public final Dispatch map(Function mapper) { - requireNonNull(mapper); - if (!isPresent()) { - return empty(); - } else { - return Dispatch.ofNullable(mapper.apply(value)); - } - } - - public final Dispatch flatMap(Function> mapper) { - requireNonNull(mapper); - if (!isPresent()) { - return empty(); - } else { - return requireNonNull(mapper.apply(value)); - } - } - - public final T orElse(T other) { - return value != null ? value : other; - } - - public final T orElseGet(Supplier other) { - return value != null ? value : other.get(); - } - - public final T orElseThrow(Supplier exceptionSupplier) throws X { - if (value != null) { - return value; - } else { - throw exceptionSupplier.get(); - } - } - - @Override - public final boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (!(obj instanceof Dispatch)) { - return false; - } - Dispatch other = (Dispatch) obj; - - return Objects.equals(value, other.value); - } - - @Override - public final int hashCode() { - return value != null ? value.hashCode() : 0; - } - - @Override - public final String toString() { - return value != null - ? String.format("Dispatch[%s]", value) - : "Dispatch.empty"; - } - - - public final static class DispatchImpl { - - private final List value; - - private DispatchImpl() { - this.value = null; - } - - private DispatchImpl(List value) { - this.value = value; - } - - public final boolean isPresent() { - return value != null; - } - - public final DispatchImpl filter(Predicate predicate) { - requireNonNull(predicate); - if (isPresent()) { - forEach(e -> { - if (!predicate.test(e)) { - this.value.remove(e); - } - }); - } - return this; - } - - public final DispatchImpl map(Function mapper) { - requireNonNull(mapper); - - List target = new ArrayList<>(); - if (isPresent()) { - for (E e : value) { - target.add(mapper.apply(e)); - } - } - return new DispatchImpl<>(target); - } - - /** - * 多个数组数据源转换成一个数组数据源 - * - * @param mapper - * @param - * @return - */ - public final DispatchImpl flatMap(Function> mapper) { - requireNonNull(mapper); - - List dispatchStream = new ArrayList<>(); - if (isPresent()) { - this.forEach(e -> { - dispatchStream.addAll(((DispatchImpl) mapper.apply(e)).value); - }); - } - return new DispatchImpl<>(dispatchStream); - } - - public final DispatchImpl distinct() { - List target = new ArrayList<>(); - if (isPresent()) { - for (E e : value) { - if (!target.contains(e)) { - target.add(e); - } - } - } - return this; - } - - public final DispatchImpl forEach(Consumer action) { - requireNonNull(action); - if (isPresent()) { - for (E e : value) { - action.accept(e); - } - } - return this; - } - - public final DispatchImpl forEach(BiConsumer action) { - requireNonNull(action); - if (isPresent()) { - for (int i = 0, len = value.size(); i < len; i++) { - action.accept(i, value.get(i)); - } - } - return this; - } - - public final DispatchImpl limit(int maxSize) { - if (this.isPresent() && maxSize > 0) { - return new DispatchImpl<>(this.value.subList(0, maxSize > this.count() ? this.count() : maxSize)); - } - return this; - } - - public final DispatchImpl skip(int n) { - if (this.isPresent() && n > 0 && n < count()) { - return new DispatchImpl<>(this.value.subList(n, this.count())); - } - return this; - } - - public final DispatchImpl peek(Consumer action) { - if (this.isPresent()) { - forEach(action); - } - forEach(action); - return this; - } - - public final DispatchImpl sorted() { - return sorted(Object::hashCode); - } - - public final > DispatchImpl sorted(Function function) { - requireNonNull(function); - return sorted((Comparator & Serializable) (c1, c2) -> function.apply(c1).compareTo(function.apply(c2))); - } - - public final DispatchImpl sorted(Comparator comparator) { - requireNonNull(comparator); - if (isPresent()) { - Collections.sort(value, comparator); - } - return this; - } - - public final int count() { - if (isPresent()) { - return value.size(); - } - return 0; - } - - public final Dispatch findFirst() { - if (isPresent() && value.size() > 0) { - return Dispatch.ofNullable(value.get(0)); - } - return Dispatch.empty(); - } - - public final Dispatch findAny() { - if (isPresent() && value.size() > 0) { - return Dispatch.ofNullable(value.get(new Random().nextInt(value.size()))); - } - return Dispatch.empty(); - } - - public final Dispatch findAny(Predicate predicate) { - if (isPresent() && value.size() > 0) { - for (E e : value) { - if (predicate.test(e)) { - return Dispatch.ofNullable(e); - } - } - } - return Dispatch.empty(); - } - - public final E[] toArray() { - if (isPresent()) { - return (E[]) this.value.toArray(); - } - return null; - } - - - /** - * 输出需要的数据类型 - * - * @param supplier - * @param accumulator - * @return - */ - public final R toCollect(Supplier supplier, BiConsumer accumulator) { - requireNonNull(supplier); - requireNonNull(accumulator); - R r = supplier.get(); - forEach(t -> { - accumulator.accept(r, t); - }); - return r; - } - - - public final R toCollection(Supplier supplier) { - return toCollect(supplier, Collection::add); - } - - public final List toList() { - return toCollection((Supplier>) ArrayList::new); - } - - public final Set toSet() { - return toCollection((Supplier>) HashSet::new); - } - - - public final Map toMap(Function keyMapper, Function valueMapper, BiFunction mergeFunction, Supplier> mapSupplier) { - BiConsumer, E> accumulator = (map, element) -> { - K key = keyMapper.apply(element); - U value = valueMapper.apply(element); - - U oldValue = map.get(key); - U newValue = (oldValue == null) ? value : mergeFunction.apply(oldValue, value); - if (newValue == null) { - map.remove(key); - } else { - map.put(key, newValue); - } - }; - return this.toCollect(HashMap::new, accumulator); - } - - public final Map toMap(Function keyMapper, Function valueMapper, BiFunction mergeFunction) { - return this.toMap(keyMapper, valueMapper, (u, v) -> mergeFunction.apply(u, v), (Supplier>) HashMap::new); - } - - public final Map toMap(Function keyMapper, Function valueMapper) { - return this.toMap(keyMapper, valueMapper, (u, v) -> { - throw new IllegalStateException(String.format("Duplicate key %s", u)); - }); - } - - - public final Map> toGroupingBy(Function classifier) { - return toGroupingBy(classifier, (Supplier>>) HashMap::new); - } - - public final Map> toGroupingBy(Function classifier, Supplier>> mapFactory) { - - BiConsumer>, E> accumulator = (map, element) -> { - K key = classifier.apply(element); - if (map.containsKey(key)) { - List temp = map.get(key); - temp.add(element); - } else { - List list = new ArrayList<>(); - list.add(element); - map.put(key, list); - } - }; - return toCollect(mapFactory, accumulator); - } - - - public final E toJoin(BiFunction biFunction) { - requireNonNull(biFunction); - BiFunction temp = (t, u) -> { - if (t == null) { - return u; - } else { - return biFunction.apply(t, u); - } - }; - E apply = null; - if (isPresent()) { - for (int i = 0, len = value.size() - 1; i <= len; i++) { - apply = temp.apply(apply, value.get(i)); - } - } - return apply; - } - - - @Override - public final String toString() { - return isPresent() ? value.toString() : super.toString(); - } - - - } - - public interface Supplier { - - /** - * Gets a result. - * - * @return a result - */ - T get(); - } - - public interface BiConsumer { - - /** - * Performs this operation on the given arguments. - * - * @param t the first input argument - * @param u the second input argument - */ - void accept(T t, U u); - } - - public interface BiFunction { - - /** - * Applies this function to the given arguments. - * - * @param t the first function argument - * @param u the second function argument - * @return the function result - */ - R apply(T t, U u); - } - - public interface Consumer { - /** - * Performs this operation on the given argument. - * - * @param t the input argument - */ - void accept(T t); - } - - public interface Predicate { - /** - * Evaluates this predicate on the given argument. - * - * @param t the input argument - * @return {@code true} if the input argument matches the predicate, - * otherwise {@code false} - */ - boolean test(T t); - - } - - public interface Function { - - /** - * Applies this function to the given argument. - * - * @param t the function argument - * @return the function result - */ - R apply(T t); - } - -} diff --git a/foudations/mogo-utils/src/main/java/com/mogo/utils/IntentUtils.java b/foudations/mogo-utils/src/main/java/com/mogo/utils/IntentUtils.java deleted file mode 100644 index f36c5d3557..0000000000 --- a/foudations/mogo-utils/src/main/java/com/mogo/utils/IntentUtils.java +++ /dev/null @@ -1,361 +0,0 @@ -package com.mogo.utils; - -import android.net.Uri; -import android.util.Log; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.UnsupportedEncodingException; -import java.net.URISyntaxException; -import java.nio.charset.Charset; -import java.util.Collections; -import java.util.HashMap; -import java.util.LinkedHashSet; -import java.util.Set; -import java.util.TreeMap; - -public class IntentUtils { - - /** - * urlDecode的时候会把'+'转换成' ' - * - * @param uri - * @return - */ - public static TreeMap< String, String > splitParams2( Uri uri) { - if (uri == null) { - return new TreeMap< String, String >(); - } - Set< String > keys = getQueryParameterNames(uri); - TreeMap< String, String > map = new TreeMap< String, String >(); - - for ( String key : keys) { - map.put(key, getQueryParameter(uri, key)); - } - return map; - } - - /** - * urlDecode时
- * 4.0版本以后 '+' ->' '
- * 2.3版本之前 '+' -> '+'
- * - * @param uri - * @return - */ - public static HashMap< String, String > splitParams1( Uri uri) { - if (uri == null) { - return new HashMap< String, String >(); - } - Set< String > keys = getQueryParameterNames(uri); - HashMap< String, String > map = new HashMap< String, String >(keys.size()); - - for ( String key : keys) { - map.put(key, uri.getQueryParameter(key)); - } - return map; - } - - /** - * Searches the query string for the first value with the given key. - * - *

- * Warning: this decoded the '+' character as ' '. - * - * @param key which will be encoded - * @throws UnsupportedOperationException if this isn't a hierarchical URI - * @throws NullPointerException if key is null - * @return the decoded value or null if no parameter is found - */ - public static String getQueryParameter( Uri uri, String key) { - if (uri.isOpaque()) { - throw new UnsupportedOperationException("This isn't a hierarchical URI."); - } - if (key == null) { - throw new NullPointerException("key"); - } - - final String query = uri.getEncodedQuery(); - if (query == null) { - return null; - } - - final String encodedKey = Uri.encode(key, null); - final int length = query.length(); - int start = 0; - do { - int nextAmpersand = query.indexOf('&', start); - int end = nextAmpersand != -1 ? nextAmpersand : length; - - int separator = query.indexOf('=', start); - if (separator > end || separator == -1) { - separator = end; - } - - if (separator - start == encodedKey.length() - && query.regionMatches(start, encodedKey, 0, encodedKey.length())) { - if (separator == end) { - return ""; - } else { - String encodedValue = query.substring(separator + 1, end); - return UriCodec.decode(encodedValue, true, UriCodec.UTF_8, false); - } - } - - // Move start to end of name. - if (nextAmpersand != -1) { - start = nextAmpersand + 1; - } else { - break; - } - } while (true); - return null; - } - - public static Set< String > getQueryParameterNames( Uri uri) { - if (uri.isOpaque()) { - throw new UnsupportedOperationException("This isn't a hierarchical URI."); - } - - String query = uri.getEncodedQuery(); - if (query == null) { - return Collections.emptySet(); - } - - Set< String > names = new LinkedHashSet< String >(); - int start = 0; - do { - int next = query.indexOf('&', start); - int end = next == -1 ? query.length() : next; - - int separator = query.indexOf('=', start); - if (separator > end || separator == -1) { - separator = end; - } - - String name = query.substring(start, separator); - names.add( Uri.decode(name)); - - // Move start to end of name. - start = end + 1; - } while (start < query.length()); - - return Collections.unmodifiableSet(names); - } - - /** - * Encodes and decodes {@code application/x-www-form-urlencoded} content. Subclasses define exactly which characters - * are legal. - * - *

- * By default, UTF-8 is used to encode escaped characters. A single input character like "\u0080" may be encoded to - * multiple octets like %C2%80. - */ - abstract static class UriCodec { - - /** - * Returns true if {@code c} does not need to be escaped. - */ - protected abstract boolean isRetained(char c); - - /** - * Throws if {@code s} is invalid according to this encoder. - */ - public final String validate( String uri, int start, int end, String name) throws URISyntaxException { - for (int i = start; i < end;) { - char ch = uri.charAt(i); - if (ch >= 'a' && ch <= 'z' || ch >= 'A' && ch <= 'Z' || ch >= '0' && ch <= '9' || isRetained(ch)) { - i++; - } else if (ch == '%') { - if (i + 2 >= end) { - throw new URISyntaxException(uri, "Incomplete % sequence in " + name, i); - } - int d1 = hexToInt(uri.charAt(i + 1)); - int d2 = hexToInt(uri.charAt(i + 2)); - if (d1 == -1 || d2 == -1) { - throw new URISyntaxException(uri, "Invalid % sequence: " + uri.substring(i, i + 3) + " in " - + name, i); - } - i += 3; - } else { - throw new URISyntaxException(uri, "Illegal character in " + name, i); - } - } - return uri.substring(start, end); - } - - /** - * Throws if {@code s} contains characters that are not letters, digits or in {@code legal}. - */ - public static void validateSimple( String s, String legal) throws URISyntaxException { - for (int i = 0; i < s.length(); i++) { - char ch = s.charAt(i); - if (!(ch >= 'a' && ch <= 'z' || ch >= 'A' && ch <= 'Z' || ch >= '0' && ch <= '9' || legal.indexOf(ch) > -1)) { - throw new URISyntaxException(s, "Illegal character", i); - } - } - } - - /** - * Encodes {@code s} and appends the orderList to {@code builder}. - * - * @param isPartiallyEncoded true to fix input that has already been partially or fully encoded. For example, - * input of "hello%20world" is unchanged with isPartiallyEncoded=true but would be double-escaped to - * "hello%2520world" otherwise. - * @throws UnsupportedEncodingException - */ - private void appendEncoded( StringBuilder builder, String s, Charset charset, boolean isPartiallyEncoded) - throws UnsupportedEncodingException { - if (s == null) { - throw new NullPointerException(); - } - - int escapeStart = -1; - for (int i = 0; i < s.length(); i++) { - char c = s.charAt(i); - if (c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z' || c >= '0' && c <= '9' || isRetained(c) || c == '%' - && isPartiallyEncoded) { - if (escapeStart != -1) { - appendHex(builder, s.substring(escapeStart, i), charset); - escapeStart = -1; - } - if (c == '%' && isPartiallyEncoded) { - // this is an encoded 3-character sequence like "%20" - builder.append(s, i, i + 3); - i += 2; - } else if (c == ' ') { - builder.append('+'); - } else { - builder.append(c); - } - } else if (escapeStart == -1) { - escapeStart = i; - } - } - if (escapeStart != -1) { - appendHex(builder, s.substring(escapeStart, s.length()), charset); - } - } - - public final String encode( String s, Charset charset) throws UnsupportedEncodingException { - // Guess a bit larger for encoded form - StringBuilder builder = new StringBuilder(s.length() + 16); - appendEncoded(builder, s, charset, false); - return builder.toString(); - } - - static final Charset UTF_8 = Charset.forName("UTF-8"); - - public final void appendEncoded( StringBuilder builder, String s) throws UnsupportedEncodingException { - appendEncoded(builder, s, UTF_8, false); - } - - public final void appendPartiallyEncoded( StringBuilder builder, String s) throws UnsupportedEncodingException { - appendEncoded(builder, s, UTF_8, true); - } - - /** - * @param convertPlus true to convert '+' to ' '. - * @param throwOnFailure true to throw an IllegalArgumentException on invalid escape sequences; false to replace - * them with the replacement character (U+fffd). - * @throws UnsupportedEncodingException - */ - public static String decode( String s, boolean convertPlus, Charset charset, boolean throwOnFailure) { - if (s.indexOf('%') == -1 && (!convertPlus || s.indexOf('+') == -1)) { - return s; - } - - StringBuilder result = new StringBuilder(s.length()); - ByteArrayOutputStream out = new ByteArrayOutputStream();; - try { - for (int i = 0; i < s.length();) { - char c = s.charAt(i); - if (c == '%') { - do { - int d1, d2; - if (i + 2 < s.length() && (d1 = hexToInt(s.charAt(i + 1))) != -1 - && (d2 = hexToInt(s.charAt(i + 2))) != -1) { - out.write((byte) ((d1 << 4) + d2)); - } else if (throwOnFailure) { - throw new IllegalArgumentException("Invalid % sequence at " + i + ": " + s); - } else { - byte[] replacement = "\ufffd".getBytes(charset.name()); - out.write(replacement, 0, replacement.length); - } - i += 3; - } while (i < s.length() && s.charAt(i) == '%'); - result.append(new String(out.toByteArray(), charset.name())); - out.reset(); - } else { - if (convertPlus && c == '+') { - c = ' '; - } - result.append(c); - i++; - } - } - } catch ( UnsupportedEncodingException e) { - Log.e("IntentUtils",e.getMessage()); - }finally { - try { - out.close(); - } catch ( IOException e) { - Log.e("IntentUtils",e.getMessage()); - } - } - return result.toString(); - } - - /** - * Like {@link Character#digit}, but without support for non-ASCII characters. - */ - private static int hexToInt(char c) { - if ('0' <= c && c <= '9') { - return c - '0'; - } else if ('a' <= c && c <= 'f') { - return 10 + c - 'a'; - } else if ('A' <= c && c <= 'F') { - return 10 + c - 'A'; - } else { - return -1; - } - } - - public static String decode( String s) throws UnsupportedEncodingException { - return decode(s, false, UTF_8, true); - } - - private static void appendHex( StringBuilder builder, String s, Charset charset) - throws UnsupportedEncodingException { - for (byte b : s.getBytes(charset.name())) { - appendHex(builder, b); - } - } - - private static void appendHex( StringBuilder sb, byte b) { - sb.append('%'); - sb.append(byteToHexString(b, true)); - } - - /** - * The digits for every supported radix. - */ - private static final char[] DIGITS = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', - 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', - 'y', 'z' }; - - private static final char[] UPPER_CASE_DIGITS = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', - 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', - 'W', 'X', 'Y', 'Z' }; - - public static String byteToHexString( byte b, boolean upperCase) { - char[] digits = upperCase ? UPPER_CASE_DIGITS : DIGITS; - char[] buf = new char[2]; // We always want two digits. - buf[0] = digits[b >> 4 & 0xf]; - buf[1] = digits[b & 0xf]; - return new String(buf, 0, 2); - } - - } - -} diff --git a/foudations/mogo-utils/src/main/java/com/mogo/utils/ReflectUtils.java b/foudations/mogo-utils/src/main/java/com/mogo/utils/ReflectUtils.java deleted file mode 100644 index f3ee5ec450..0000000000 --- a/foudations/mogo-utils/src/main/java/com/mogo/utils/ReflectUtils.java +++ /dev/null @@ -1,73 +0,0 @@ -package com.mogo.utils; - -import android.util.Log; - -import java.lang.reflect.Constructor; -import java.lang.reflect.Field; -import java.lang.reflect.Method; - - -@SuppressWarnings("rawtypes") -public class ReflectUtils { - - public static Object getField( Class clazz, Object target, String name) throws Exception { - Field field = clazz.getDeclaredField(name); - field.setAccessible(true); - return field.get(target); - } - - public static void setField( Class clazz, Object target, String name, Object value) throws Exception { - Field field = clazz.getDeclaredField(name); - field.setAccessible(true); - field.set(target, value); - } - - public static void setFieldNoException( Class clazz, Object target, String name, Object value) { - try { - ReflectUtils.setField(clazz, target, name, value); - } catch ( Exception e) { - Log.e("ReflectUtil",e.getMessage(),e); - } - } - - @SuppressWarnings("unchecked") - public static Object invoke( Class clazz, Object target, String name, Object... args) - throws Exception { - Class[] parameterTypes = null; - if (args != null) { - parameterTypes = new Class[args.length]; - for (int i = 0; i < args.length; i++) { - parameterTypes[i] = args[i].getClass(); - } - } - - Method method = clazz.getDeclaredMethod(name, parameterTypes); - method.setAccessible(true); - return method.invoke(target, args); - } - - @SuppressWarnings("unchecked") - public static Object invoke( Class clazz, Object target, String name, Class[] parameterTypes, Object... args) - throws Exception { - Method method = clazz.getDeclaredMethod(name, parameterTypes); - method.setAccessible(true); - return method.invoke(target, args); - } - - @SuppressWarnings("unchecked") - public static T invokeConstructor( Class clazz, Class[] parameterTypes, Object... args) - throws Exception { - Constructor constructor = clazz.getDeclaredConstructor(parameterTypes); - constructor.setAccessible(true); - return (T) constructor.newInstance(args); - } - - @SuppressWarnings("unchecked") - public static T invokeConstructor( Class clazz) - throws Exception { - Constructor constructor = clazz.getDeclaredConstructor(); - constructor.setAccessible(true); - return (T) constructor.newInstance(); - } - -} diff --git a/foudations/mogo-utils/src/main/java/com/mogo/utils/statusbar/Eyes.java b/foudations/mogo-utils/src/main/java/com/mogo/utils/statusbar/Eyes.java deleted file mode 100644 index b0eecffd79..0000000000 --- a/foudations/mogo-utils/src/main/java/com/mogo/utils/statusbar/Eyes.java +++ /dev/null @@ -1,177 +0,0 @@ -package com.mogo.utils.statusbar; - -import android.app.Activity; -import android.content.Context; -import android.graphics.Color; -import android.os.Build; -import android.util.TypedValue; -import android.view.View; -import android.view.ViewGroup; -import android.view.Window; -import android.view.WindowManager; -import androidx.core.view.ViewCompat; -import java.lang.reflect.Field; -import java.lang.reflect.Method; - -public class Eyes { - - - public static void setStatusBarColor( Activity activity, int statusColor ) { - if ( Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP ) { - EyesLollipop.setStatusBarColor( activity, statusColor ); - } else if ( Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT ) { - EyesKitKat.setStatusBarColor( activity, statusColor ); - } - } - - public static void translucentStatusBar( Activity activity ) { - translucentStatusBar( activity, false ); - } - - public static void translucentStatusBar( Activity activity, boolean hideStatusBarBackground ) { - if ( Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP ) { - EyesLollipop.translucentStatusBar( activity, hideStatusBarBackground ); - } else if ( Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT ) { - EyesKitKat.translucentStatusBar( activity ); - } - } -// -// public static void setStatusBarColorForCollapsingToolbar(@NonNull Activity activity, AppBarLayout appBarLayout, CollapsingToolbarLayout collapsingToolbarLayout, -// Toolbar toolbar, @ColorInt int statusColor) { -// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { -// EyesLollipop.setStatusBarColorForCollapsingToolbar(activity, appBarLayout, collapsingToolbarLayout, toolbar, statusColor); -// } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { -// EyesKitKat.setStatusBarColorForCollapsingToolbar(activity, appBarLayout, collapsingToolbarLayout, toolbar, statusColor); -// } -// } - - public static void setStatusBarLightMode( Activity activity, int color ) { - if ( Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT ) { - //判断是否为小米或魅族手机,如果是则将状态栏文字改为黑色 - if ( MIUISetStatusBarLightMode( activity, true ) || FlymeSetStatusBarLightMode( activity, true ) ) { - //设置状态栏为指定颜色 - if ( Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP ) {//5.0 - activity.getWindow().setStatusBarColor( color ); - } else {//4.4 - //调用修改状态栏颜色的方法 - setStatusBarColor( activity, color ); - } - } else if ( Build.VERSION.SDK_INT >= Build.VERSION_CODES.M ) { - //如果是6.0以上将状态栏文字改为黑色,并设置状态栏颜色 - activity.getWindow().setBackgroundDrawableResource( android.R.color.transparent ); - activity.getWindow().getDecorView().setSystemUiVisibility( View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR ); - activity.getWindow().setStatusBarColor( color ); - - //fitsSystemWindow 为 false, 不预留系统栏位置. - ViewGroup mContentView = activity.getWindow().findViewById( Window.ID_ANDROID_CONTENT ); - View mChildView = mContentView.getChildAt( 0 ); - if ( mChildView != null ) { - mChildView.setFitsSystemWindows( true ); - ViewCompat.requestApplyInsets( mChildView ); - } - } - } - } - -// -// public static void setStatusBarLightForCollapsingToolbar(Activity activity, AppBarLayout appBarLayout, -// CollapsingToolbarLayout collapsingToolbarLayout, Toolbar toolbar, int statusBarColor) { -// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { -// EyesLollipop.setStatusBarWhiteForCollapsingToolbar(activity, appBarLayout, collapsingToolbarLayout, toolbar, statusBarColor); -// } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { -// EyesKitKat.setStatusBarWhiteForCollapsingToolbar(activity, appBarLayout, collapsingToolbarLayout, toolbar, statusBarColor); -// } -// } - - - /** - * MIUI的沉浸支持透明白色字体和透明黑色字体 - * https://dev.mi.com/console/doc/detail?pId=1159 - */ - static boolean MIUISetStatusBarLightMode( Activity activity, boolean darkmode ) { - try { - Class< ? > layoutParams = Class.forName( "android.view.MiuiWindowManager$LayoutParams" ); - - Window window = activity.getWindow(); - window.addFlags( WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS ); - window.clearFlags( WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS ); - window.getDecorView().setSystemUiVisibility( View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR ); - - Class< ? extends Window> clazz = activity.getWindow().getClass(); - Field field = layoutParams.getField( "EXTRA_FLAG_STATUS_BAR_DARK_MODE" ); - int darkModeFlag = field.getInt( layoutParams ); - Method extraFlagField = clazz.getMethod( "setExtraFlags", int.class, int.class ); - extraFlagField.invoke( activity.getWindow(), darkmode ? darkModeFlag : 0, darkModeFlag ); - return true; - } catch ( Exception e ) { - } - return false; - } - - /** - * 设置状态栏图标为深色和魅族特定的文字风格,Flyme4.0以上 - */ - static boolean FlymeSetStatusBarLightMode( Activity activity, boolean darkmode ) { - try { - WindowManager.LayoutParams lp = activity.getWindow().getAttributes(); - Field darkFlag = WindowManager.LayoutParams.class - .getDeclaredField( "MEIZU_FLAG_DARK_STATUS_BAR_ICON" ); - Field meizuFlags = WindowManager.LayoutParams.class - .getDeclaredField( "meizuFlags" ); - darkFlag.setAccessible( true ); - meizuFlags.setAccessible( true ); - int bit = darkFlag.getInt( null ); - int value = meizuFlags.getInt( lp ); - if ( darkmode ) { - value |= bit; - } else { - value &= ~bit; - } - meizuFlags.setInt( lp, value ); - activity.getWindow().setAttributes( lp ); - return true; - } catch ( Exception e ) { - } - return false; - } - - static void setContentTopPadding( Activity activity, int padding ) { - ViewGroup mContentView = activity.getWindow().findViewById( Window.ID_ANDROID_CONTENT ); - mContentView.setPadding( 0, padding, 0, 0 ); - } - - static int getPxFromDp( Context context, float dp ) { - return ( int ) TypedValue.applyDimension( TypedValue.COMPLEX_UNIT_DIP, dp, context.getResources().getDisplayMetrics() ); - } - - /** - * 设置状态栏颜色 - * - * @param activity - * @param isBlackText true黑色 false 白字 - */ - public static void setStatusBarStyle( Activity activity, boolean isBlackText, boolean isFitSystem ) { - setStatusBarStyle( activity, isBlackText, isBlackText ? Color.WHITE : Color.TRANSPARENT, isFitSystem ); - } - - public static void setStatusBarStyle( Activity activity, boolean isBlackText, int statusBarBgColor, boolean isFitSystem ) { - if ( Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP ) { - activity.getWindow().setBackgroundDrawableResource( android.R.color.transparent ); - if ( isBlackText ) { - activity.getWindow().getDecorView().setSystemUiVisibility( ( isFitSystem ? View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN : View.SYSTEM_UI_FLAG_VISIBLE ) | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR ); - } else { - activity.getWindow().getDecorView().setSystemUiVisibility( ( isFitSystem ? View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN : View.SYSTEM_UI_FLAG_VISIBLE ) ); - } - activity.getWindow().setStatusBarColor( statusBarBgColor ); - } - } - - - public static void setMessageFragmentStatus( Activity activity ) { - if ( Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP ) { - activity.getWindow().setBackgroundDrawableResource( android.R.color.transparent ); - activity.getWindow().getDecorView().setSystemUiVisibility( View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR ); - } - } - -} diff --git a/foudations/mogo-utils/src/main/java/com/mogo/utils/statusbar/EyesKitKat.java b/foudations/mogo-utils/src/main/java/com/mogo/utils/statusbar/EyesKitKat.java deleted file mode 100644 index c922602529..0000000000 --- a/foudations/mogo-utils/src/main/java/com/mogo/utils/statusbar/EyesKitKat.java +++ /dev/null @@ -1,277 +0,0 @@ -package com.mogo.utils.statusbar; - -import android.annotation.TargetApi; -import android.app.Activity; -import android.content.Context; -import android.os.Build; -import android.util.TypedValue; -import android.view.Gravity; -import android.view.View; -import android.view.ViewGroup; -import android.view.Window; -import android.view.WindowManager; -import android.widget.FrameLayout; -import com.mogo.utils.R; - -@TargetApi( Build.VERSION_CODES.KITKAT ) -class EyesKitKat { - private static final String TAG_FAKE_STATUS_BAR_VIEW = "statusBarView"; - private static final String TAG_MARGIN_ADDED = "marginAdded"; - - static void setStatusBarColor( Activity activity, int statusColor ) { - Window window = activity.getWindow(); - //设置Window为全透明 - window.addFlags( WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS ); - - ViewGroup mContentView = window.findViewById( Window.ID_ANDROID_CONTENT ); - //获取父布局 - View mContentChild = mContentView.getChildAt( 0 ); - //获取状态栏高度 - int statusBarHeight = getStatusBarHeight( activity ); - - //如果已经存在假状态栏则移除,防止重复添加 - removeFakeStatusBarViewIfExist( activity ); - //添加一个View来作为状态栏的填充 - addFakeStatusBarView( activity, statusColor, statusBarHeight ); - //设置子控件到状态栏的间距 - addMarginTopToContentChild( mContentChild, statusBarHeight ); - //不预留系统栏位置 - if ( mContentChild != null ) { - mContentChild.setFitsSystemWindows( false ); - } - //如果在Activity中使用了ActionBar则需要再将布局与状态栏的高度跳高一个ActionBar的高度,否则内容会被ActionBar遮挡 - int action_bar_id = activity.getResources().getIdentifier( "action_bar", "id", activity.getPackageName() ); - View view = activity.findViewById( action_bar_id ); - if ( view != null ) { - TypedValue typedValue = new TypedValue(); - if ( activity.getTheme().resolveAttribute( R.attr.actionBarSize, typedValue, true ) ) { - int actionBarHeight = TypedValue.complexToDimensionPixelSize( typedValue.data, activity.getResources().getDisplayMetrics() ); - Eyes.setContentTopPadding( activity, actionBarHeight ); - } - } - } - - static void translucentStatusBar( Activity activity ) { - Window window = activity.getWindow(); - //设置Window为透明 - window.addFlags( WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS ); - - ViewGroup mContentView = activity.findViewById( Window.ID_ANDROID_CONTENT ); - View mContentChild = mContentView.getChildAt( 0 ); - - //移除已经存在假状态栏则,并且取消它的Margin间距 - removeFakeStatusBarViewIfExist( activity ); - removeMarginTopOfContentChild( mContentChild, getStatusBarHeight( activity ) ); - if ( mContentChild != null ) { - //fitsSystemWindow 为 false, 不预留系统栏位置. - mContentChild.setFitsSystemWindows( false ); - } - } - -// static void setStatusBarColorForCollapsingToolbar( final Activity activity, final AppBarLayout appBarLayout, final CollapsingToolbarLayout collapsingToolbarLayout, -// Toolbar toolbar, int statusColor ) { -// Window window = activity.getWindow(); -// //设置Window为全透明 -// window.addFlags( WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS ); -// ViewGroup mContentView = window.findViewById( Window.ID_ANDROID_CONTENT ); -// -// //AppBarLayout,CollapsingToolbarLayout,ToolBar,ImageView的fitsSystemWindow统一改为false, 不预留系统栏位置. -// View mContentChild = mContentView.getChildAt( 0 ); -// mContentChild.setFitsSystemWindows( false ); -// ( ( View ) appBarLayout.getParent() ).setFitsSystemWindows( false ); -// appBarLayout.setFitsSystemWindows( false ); -// collapsingToolbarLayout.setFitsSystemWindows( false ); -// collapsingToolbarLayout.getChildAt( 0 ).setFitsSystemWindows( false ); -// -// toolbar.setFitsSystemWindows( false ); -// //为Toolbar添加一个状态栏的高度, 同时为Toolbar添加paddingTop,使Toolbar覆盖状态栏,ToolBar的title可以正常显示. -// if ( toolbar.getTag() == null ) { -// CollapsingToolbarLayout.LayoutParams lp = ( CollapsingToolbarLayout.LayoutParams ) toolbar.getLayoutParams(); -// int statusBarHeight = getStatusBarHeight( activity ); -// lp.height += statusBarHeight; -// toolbar.setLayoutParams( lp ); -// toolbar.setPadding( toolbar.getPaddingLeft(), toolbar.getPaddingTop() + statusBarHeight, toolbar.getPaddingRight(), toolbar.getPaddingBottom() ); -// toolbar.setTag( true ); -// } -// //移除已经存在假状态栏则,并且取消它的Margin间距 -// int statusBarHeight = getStatusBarHeight( activity ); -// removeFakeStatusBarViewIfExist( activity ); -// removeMarginTopOfContentChild( mContentChild, statusBarHeight ); -// //添加一个View来作为状态栏的填充 -// final View statusView = addFakeStatusBarView( activity, statusColor, statusBarHeight ); -// -// CoordinatorLayout.Behavior behavior = ( ( CoordinatorLayout.LayoutParams ) appBarLayout.getLayoutParams() ).getBehavior(); -// if ( behavior != null && behavior instanceof AppBarLayout.Behavior ) { -// int verticalOffset = ( ( AppBarLayout.Behavior ) behavior ).getTopAndBottomOffset(); -// if ( Math.abs( verticalOffset ) > appBarLayout.getHeight() - collapsingToolbarLayout.getScrimVisibleHeightTrigger() ) { -// statusView.setAlpha( 1f ); -// } else { -// statusView.setAlpha( 0f ); -// } -// } else { -// statusView.setAlpha( 0f ); -// } -// appBarLayout.addOnOffsetChangedListener( new AppBarLayout.OnOffsetChangedListener() { -// @Override -// public void onOffsetChanged( AppBarLayout appBarLayout, int verticalOffset ) { -// if ( Math.abs( verticalOffset ) > appBarLayout.getHeight() - collapsingToolbarLayout.getScrimVisibleHeightTrigger() ) { -// //toolbar被折叠时显示状态栏 -// if ( statusView.getAlpha() == 0 ) { -// statusView.animate().cancel(); -// statusView.animate().alpha( 1f ).setDuration( collapsingToolbarLayout.getScrimAnimationDuration() ).start(); -// } -// } else { -// //toolbar展开时显示状态栏 -// if ( statusView.getAlpha() == 1 ) { -// statusView.animate().cancel(); -// statusView.animate().alpha( 0f ).setDuration( collapsingToolbarLayout.getScrimAnimationDuration() ).start(); -// } -// } -// } -// } ); -// } -// -// static void setStatusBarWhiteForCollapsingToolbar( final Activity activity, AppBarLayout appBarLayout, final CollapsingToolbarLayout collapsingToolbarLayout, Toolbar toolbar, final int statusBarColor ) { -// final Window window = activity.getWindow(); -// window.addFlags( WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS ); -// -// ViewGroup mContentView = window.findViewById( Window.ID_ANDROID_CONTENT ); -// View mContentChild = mContentView.getChildAt( 0 ); -// mContentChild.setFitsSystemWindows( false ); -// ( ( View ) appBarLayout.getParent() ).setFitsSystemWindows( false ); -// appBarLayout.setFitsSystemWindows( false ); -// collapsingToolbarLayout.setFitsSystemWindows( false ); -// collapsingToolbarLayout.getChildAt( 0 ).setFitsSystemWindows( false ); -// toolbar.setFitsSystemWindows( false ); -// -// if ( toolbar.getTag() == null ) { -// CollapsingToolbarLayout.LayoutParams lp = ( CollapsingToolbarLayout.LayoutParams ) toolbar.getLayoutParams(); -// int statusBarHeight = getStatusBarHeight( activity ); -// lp.height += statusBarHeight; -// toolbar.setLayoutParams( lp ); -// toolbar.setPadding( toolbar.getPaddingLeft(), toolbar.getPaddingTop() + statusBarHeight, toolbar.getPaddingRight(), toolbar.getPaddingBottom() ); -// toolbar.setTag( true ); -// } -// -// int statusBarHeight = getStatusBarHeight( activity ); -// int color = Color.BLACK; -// try { -// Class< ? > layoutParams = Class.forName( "android.view.MiuiWindowManager$LayoutParams" ); -// color = statusBarColor; -// } catch ( ClassNotFoundException e ) { -// e.printStackTrace(); -// } -// try { -// Field darkFlag = WindowManager.LayoutParams.class.getDeclaredField( "MEIZU_FLAG_DARK_STATUS_BAR_ICON" ); -// color = statusBarColor; -// } catch ( NoSuchFieldException e ) { -// e.printStackTrace(); -// } -// final View statusView = addFakeStatusBarView( activity, color, statusBarHeight ); -// CoordinatorLayout.Behavior behavior = ( ( CoordinatorLayout.LayoutParams ) appBarLayout.getLayoutParams() ).getBehavior(); -// if ( behavior != null && behavior instanceof AppBarLayout.Behavior ) { -// int verticalOffset = ( ( AppBarLayout.Behavior ) behavior ).getTopAndBottomOffset(); -// if ( Math.abs( verticalOffset ) > appBarLayout.getHeight() - collapsingToolbarLayout.getScrimVisibleHeightTrigger() ) { -// statusView.setAlpha( 1f ); -// } else { -// statusView.setAlpha( 0f ); -// } -// } else { -// statusView.setAlpha( 0f ); -// } -// -// appBarLayout.addOnOffsetChangedListener( new AppBarLayout.OnOffsetChangedListener() { -// private final static int EXPANDED = 0; -// private final static int COLLAPSED = 1; -// private int appBarLayoutState; -// -// @Override -// public void onOffsetChanged( AppBarLayout appBarLayout, int verticalOffset ) { -// if ( Math.abs( verticalOffset ) >= ( appBarLayout.getTotalScrollRange() - Eyes.getPxFromDp( activity, 56 ) ) ) { -// if ( appBarLayoutState != COLLAPSED ) { -// appBarLayoutState = COLLAPSED; -// -// if ( Eyes.MIUISetStatusBarLightMode( activity, true ) || Eyes.FlymeSetStatusBarLightMode( activity, true ) ) { -// } -// if ( statusView.getAlpha() == 0 ) { -// statusView.animate().cancel(); -// statusView.animate().alpha( 1f ).setDuration( collapsingToolbarLayout.getScrimAnimationDuration() ).start(); -// } -// } -// } else { -// if ( appBarLayoutState != EXPANDED ) { -// appBarLayoutState = EXPANDED; -// -// if ( Eyes.MIUISetStatusBarLightMode( activity, false ) || Eyes.FlymeSetStatusBarLightMode( activity, false ) ) { -// } -// if ( statusView.getAlpha() == 1 ) { -// statusView.animate().cancel(); -// statusView.animate().alpha( 0f ).setDuration( collapsingToolbarLayout.getScrimAnimationDuration() ).start(); -// } -// translucentStatusBar( activity ); -// } -// } -// } -// } ); -// } - - private static void removeFakeStatusBarViewIfExist( Activity activity ) { - Window window = activity.getWindow(); - ViewGroup mDecorView = (ViewGroup) window.getDecorView(); - - View fakeView = mDecorView.findViewWithTag( TAG_FAKE_STATUS_BAR_VIEW ); - if ( fakeView != null ) { - mDecorView.removeView( fakeView ); - } - } - - private static View addFakeStatusBarView( Activity activity, int statusBarColor, int statusBarHeight ) { - Window window = activity.getWindow(); - ViewGroup mDecorView = (ViewGroup) window.getDecorView(); - - View mStatusBarView = new View( activity ); - FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, statusBarHeight ); - layoutParams.gravity = Gravity.TOP; - mStatusBarView.setLayoutParams( layoutParams ); - mStatusBarView.setBackgroundColor( statusBarColor ); - mStatusBarView.setTag( TAG_FAKE_STATUS_BAR_VIEW ); - - mDecorView.addView( mStatusBarView ); - return mStatusBarView; - } - - private static void addMarginTopToContentChild( View mContentChild, int statusBarHeight ) { - if ( mContentChild == null ) { - return; - } - if ( !TAG_MARGIN_ADDED.equals( mContentChild.getTag() ) ) { - FrameLayout.LayoutParams lp = ( FrameLayout.LayoutParams ) mContentChild.getLayoutParams(); - lp.topMargin += statusBarHeight; - mContentChild.setLayoutParams( lp ); - mContentChild.setTag( TAG_MARGIN_ADDED ); - } - } - - private static int getStatusBarHeight( Context context ) { - int result = 0; - int resId = context.getResources().getIdentifier( "status_bar_height", "dimen", "android" ); - if ( resId > 0 ) { - result = context.getResources().getDimensionPixelOffset( resId ); - } - return result; - } - - private static void removeMarginTopOfContentChild( View mContentChild, int statusBarHeight ) { - if ( mContentChild == null ) { - return; - } - if ( TAG_MARGIN_ADDED.equals( mContentChild.getTag() ) ) { - FrameLayout.LayoutParams lp = ( FrameLayout.LayoutParams ) mContentChild.getLayoutParams(); - lp.topMargin -= statusBarHeight; - mContentChild.setLayoutParams( lp ); - mContentChild.setTag( null ); - } - } - - -} diff --git a/foudations/mogo-utils/src/main/java/com/mogo/utils/statusbar/EyesLollipop.java b/foudations/mogo-utils/src/main/java/com/mogo/utils/statusbar/EyesLollipop.java deleted file mode 100644 index f7426867ca..0000000000 --- a/foudations/mogo-utils/src/main/java/com/mogo/utils/statusbar/EyesLollipop.java +++ /dev/null @@ -1,219 +0,0 @@ -package com.mogo.utils.statusbar; - - -import android.annotation.TargetApi; -import android.app.Activity; -import android.content.Context; -import android.graphics.Color; -import android.os.Build; -import android.view.View; -import android.view.ViewGroup; -import android.view.Window; -import android.view.WindowManager; -import androidx.core.view.ViewCompat; - -@TargetApi(Build.VERSION_CODES.LOLLIPOP) -class EyesLollipop { - - static void setStatusBarColor(Activity activity, int statusColor) { - Window window = activity.getWindow(); - //取消状态栏透明 - window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); - //添加Flag把状态栏设为可绘制模式 - window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); - //设置状态栏颜色 - window.setStatusBarColor(statusColor); - //设置系统状态栏处于可见状态 - window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE); - //让view不根据系统窗口来调整自己的布局 - ViewGroup mContentView = window.findViewById(Window.ID_ANDROID_CONTENT); - View mChildView = mContentView.getChildAt(0); - if (mChildView != null) { - mChildView.setFitsSystemWindows(false); - ViewCompat.requestApplyInsets(mChildView); - } - } - - static void translucentStatusBar(Activity activity, boolean hideStatusBarBackground) { - Window window = activity.getWindow(); - //添加Flag把状态栏设为可绘制模式 - window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); - if (hideStatusBarBackground) { - //如果为全透明模式,取消设置Window半透明的Flag - window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); - //设置状态栏为透明 - window.setStatusBarColor(Color.TRANSPARENT); - //设置window的状态栏不可见 - window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN); - } else { - //如果为半透明模式,添加设置Window半透明的Flag - window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); - //设置系统状态栏处于可见状态 - window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE); - } - //view不根据系统窗口来调整自己的布局 - ViewGroup mContentView = window.findViewById(Window.ID_ANDROID_CONTENT); - View mChildView = mContentView.getChildAt(0); - if (mChildView != null) { - mChildView.setFitsSystemWindows(false); - ViewCompat.requestApplyInsets(mChildView); - } - } - -// static void setStatusBarColorForCollapsingToolbar(final Activity activity, final AppBarLayout appBarLayout, final CollapsingToolbarLayout collapsingToolbarLayout, -// Toolbar toolbar, final int statusColor) { -// final Window window = activity.getWindow(); -// //取消设置Window半透明的Flag -// window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); -// ////添加Flag把状态栏设为可绘制模式 -// window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); -// //设置状态栏为透明 -// window.setStatusBarColor(Color.TRANSPARENT); -// //设置系统状态栏处于可见状态 -// window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE); -// //通过OnApplyWindowInsetsListener()使Layout在绘制过程中将View向下偏移了,使collapsingToolbarLayout可以占据状态栏 -// ViewCompat.setOnApplyWindowInsetsListener(collapsingToolbarLayout, new OnApplyWindowInsetsListener() { -// @Override -// public WindowInsetsCompat onApplyWindowInsets(View v, WindowInsetsCompat insets) { -// return insets; -// } -// }); -// -// ViewGroup mContentView = window.findViewById(Window.ID_ANDROID_CONTENT); -// View mChildView = mContentView.getChildAt(0); -// //view不根据系统窗口来调整自己的布局 -// if (mChildView != null) { -// mChildView.setFitsSystemWindows(false); -// ViewCompat.requestApplyInsets(mChildView); -// } -// -// ((View) appBarLayout.getParent()).setFitsSystemWindows(false); -// appBarLayout.setFitsSystemWindows(false); -// collapsingToolbarLayout.setFitsSystemWindows(false); -// collapsingToolbarLayout.getChildAt(0).setFitsSystemWindows(false); -// //设置状态栏的颜色 -// collapsingToolbarLayout.setStatusBarScrimColor(statusColor); -// toolbar.setFitsSystemWindows(false); -// //为Toolbar添加一个状态栏的高度, 同时为Toolbar添加paddingTop,使Toolbar覆盖状态栏,ToolBar的title可以正常显示. -// if (toolbar.getTag() == null) { -// CollapsingToolbarLayout.LayoutParams lp = (CollapsingToolbarLayout.LayoutParams) toolbar.getLayoutParams(); -// int statusBarHeight = getStatusBarHeight(activity); -// lp.height += statusBarHeight; -// toolbar.setLayoutParams(lp); -// toolbar.setPadding(toolbar.getPaddingLeft(), toolbar.getPaddingTop() + statusBarHeight, toolbar.getPaddingRight(), toolbar.getPaddingBottom()); -// toolbar.setTag(true); -// } -// -// appBarLayout.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() { -// private final static int EXPANDED = 0; -// private final static int COLLAPSED = 1; -// private int appBarLayoutState; -// -// @Override -// public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) { -// //toolbar被折叠时显示状态栏 -// if (Math.abs(verticalOffset) > collapsingToolbarLayout.getScrimVisibleHeightTrigger()) { -// if (appBarLayoutState != COLLAPSED) { -// appBarLayoutState = COLLAPSED;//修改状态标记为折叠 -// setStatusBarColor(activity, statusColor); -// } -// } else { -// //toolbar显示时同时显示状态栏 -// if (appBarLayoutState != EXPANDED) { -// appBarLayoutState = EXPANDED;//修改状态标记为展开 -// translucentStatusBar(activity, true); -// } -// } -// } -// }); -// } -// -// static void setStatusBarWhiteForCollapsingToolbar(final Activity activity, final AppBarLayout appBarLayout, final CollapsingToolbarLayout collapsingToolbarLayout, final Toolbar toolbar, final int statusBarColor) { -// final Window window = activity.getWindow(); -// window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); -// window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); -// window.setStatusBarColor(Color.TRANSPARENT); -// window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE); -// -// ViewCompat.setOnApplyWindowInsetsListener(collapsingToolbarLayout, new OnApplyWindowInsetsListener() { -// @Override -// public WindowInsetsCompat onApplyWindowInsets(View v, WindowInsetsCompat insets) { -// return insets; -// } -// }); -// -// ViewGroup mContentView = window.findViewById(Window.ID_ANDROID_CONTENT); -// View mChildView = mContentView.getChildAt(0); -// if (mChildView != null) { -// mChildView.setFitsSystemWindows(false); -// ViewCompat.requestApplyInsets(mChildView); -// } -// -// ((View) appBarLayout.getParent()).setFitsSystemWindows(false); -// appBarLayout.setFitsSystemWindows(false); -// toolbar.setFitsSystemWindows(false); -// if (toolbar.getTag() == null) { -// CollapsingToolbarLayout.LayoutParams lp = (CollapsingToolbarLayout.LayoutParams) toolbar.getLayoutParams(); -// int statusBarHeight = getStatusBarHeight(activity); -// lp.height += statusBarHeight; -// toolbar.setLayoutParams(lp); -// toolbar.setPadding(toolbar.getPaddingLeft(), toolbar.getPaddingTop() + statusBarHeight, toolbar.getPaddingRight(), toolbar.getPaddingBottom()); -// toolbar.setTag(true); -// } -// -// collapsingToolbarLayout.setFitsSystemWindows(false); -// collapsingToolbarLayout.getChildAt(0).setFitsSystemWindows(false); -// collapsingToolbarLayout.setStatusBarScrimColor(statusBarColor); -// appBarLayout.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() { -// private final static int EXPANDED = 0; -// private final static int COLLAPSED = 1; -// private int appBarLayoutState; -// -// @Override -// public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) { -// //toolbar被折叠时显示状态栏 -// if (Math.abs(verticalOffset) > collapsingToolbarLayout.getScrimVisibleHeightTrigger()) { -// if (appBarLayoutState != COLLAPSED) { -// appBarLayoutState = COLLAPSED;//修改状态标记为折叠 -// -// //先判断是否为小米设备,设置状态栏不成功判断是否为6.0以上设备,不是6.0以上设备再判断是否为魅族设备,不是魅族设备就只设置状态栏颜色 -// if (Eyes.MIUISetStatusBarLightMode(activity, true)) { -// return; -// } -// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { -// activity.getWindow().setBackgroundDrawableResource(android.R.color.transparent); -// activity.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR); -// activity.getWindow().setStatusBarColor(statusBarColor); -// } else if (!Eyes.FlymeSetStatusBarLightMode(activity, true)) { -// setStatusBarColor(activity, statusBarColor); -// } -// } -// } else { -// //toolbar显示时同时显示状态栏 -// if (appBarLayoutState != EXPANDED) { -// appBarLayoutState = EXPANDED;//修改状态标记为展开 -// -// if (Eyes.MIUISetStatusBarLightMode(activity, false)) { -// translucentStatusBar(activity, true); -// return; -// } -// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { -// activity.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE); -// } else if (Eyes.FlymeSetStatusBarLightMode(activity, true)) { -// } -// translucentStatusBar(activity, true); -// } -// } -// } -// }); -// } - - private static int getStatusBarHeight(Context context) { - int result = 0; - int resId = context.getResources().getIdentifier("status_bar_height", "dimen", "android"); - if (resId > 0) { - result = context.getResources().getDimensionPixelOffset(resId); - } - return result; - } -} diff --git a/foudations/mogo-utils/src/main/res/values/strings.xml b/foudations/mogo-utils/src/main/res/values/strings.xml deleted file mode 100644 index b136d6c475..0000000000 --- a/foudations/mogo-utils/src/main/res/values/strings.xml +++ /dev/null @@ -1,3 +0,0 @@ - - mogo-utils -