Commit d0413a515c85ccefceda99065fcc960c96980db6
1 parent
e3d87fb5
1 集成网家家base
Showing
115 changed files
with
9417 additions
and
139 deletions
.idea/gradle.xml
| 1 | <?xml version="1.0" encoding="UTF-8"?> | 1 | <?xml version="1.0" encoding="UTF-8"?> |
| 2 | <project version="4"> | 2 | <project version="4"> |
| 3 | + <component name="GradleMigrationSettings" migrationVersion="1" /> | ||
| 3 | <component name="GradleSettings"> | 4 | <component name="GradleSettings"> |
| 4 | <option name="linkedExternalProjectsSettings"> | 5 | <option name="linkedExternalProjectsSettings"> |
| 5 | <GradleProjectSettings> | 6 | <GradleProjectSettings> |
| 7 | + <option name="delegatedBuild" value="true" /> | ||
| 8 | + <option name="testRunner" value="PLATFORM" /> | ||
| 6 | <option name="distributionType" value="DEFAULT_WRAPPED" /> | 9 | <option name="distributionType" value="DEFAULT_WRAPPED" /> |
| 7 | <option name="externalProjectPath" value="$PROJECT_DIR$" /> | 10 | <option name="externalProjectPath" value="$PROJECT_DIR$" /> |
| 8 | <option name="modules"> | 11 | <option name="modules"> |
| @@ -16,6 +19,7 @@ | @@ -16,6 +19,7 @@ | ||
| 16 | <option value="$PROJECT_DIR$/cloud/third_tool" /> | 19 | <option value="$PROJECT_DIR$/cloud/third_tool" /> |
| 17 | <option value="$PROJECT_DIR$/cloud/user" /> | 20 | <option value="$PROJECT_DIR$/cloud/user" /> |
| 18 | <option value="$PROJECT_DIR$/cloud/video" /> | 21 | <option value="$PROJECT_DIR$/cloud/video" /> |
| 22 | + <option value="$PROJECT_DIR$/cloud/wjj_lib" /> | ||
| 19 | <option value="$PROJECT_DIR$/core" /> | 23 | <option value="$PROJECT_DIR$/core" /> |
| 20 | <option value="$PROJECT_DIR$/core/app_qr" /> | 24 | <option value="$PROJECT_DIR$/core/app_qr" /> |
| 21 | <option value="$PROJECT_DIR$/core/base" /> | 25 | <option value="$PROJECT_DIR$/core/base" /> |
| @@ -31,7 +35,6 @@ | @@ -31,7 +35,6 @@ | ||
| 31 | </set> | 35 | </set> |
| 32 | </option> | 36 | </option> |
| 33 | <option name="resolveModulePerSourceSet" value="false" /> | 37 | <option name="resolveModulePerSourceSet" value="false" /> |
| 34 | - <option name="testRunner" value="PLATFORM" /> | ||
| 35 | </GradleProjectSettings> | 38 | </GradleProjectSettings> |
| 36 | </option> | 39 | </option> |
| 37 | </component> | 40 | </component> |
app/strike/build.gradle
| @@ -186,4 +186,6 @@ dependencies { | @@ -186,4 +186,6 @@ dependencies { | ||
| 186 | // implementation project(path: ':core:util') | 186 | // implementation project(path: ':core:util') |
| 187 | // implementation project(path: ':core:encipher') | 187 | // implementation project(path: ':core:encipher') |
| 188 | // implementation project(path: ':cloud:user') | 188 | // implementation project(path: ':cloud:user') |
| 189 | + implementation project(path: ':cloud:wjj_lib') | ||
| 190 | + | ||
| 189 | } | 191 | } |
build.gradle
| @@ -37,8 +37,8 @@ allprojects { | @@ -37,8 +37,8 @@ allprojects { | ||
| 37 | if (project.parent == null || project.parent == rootProject) return | 37 | if (project.parent == null || project.parent == rootProject) return |
| 38 | 38 | ||
| 39 | android { | 39 | android { |
| 40 | - compileSdkVersion 29 | ||
| 41 | - buildToolsVersion "29.0.0" | 40 | + compileSdkVersion rootProject.ext.compileSdkVersion |
| 41 | + buildToolsVersion rootProject.ext.buildToolsVersion | ||
| 42 | // defaultConfig 闭包:默认配置、应用程序包名、最小sdk版本、目标sdk版本、版本号、版本名称; | 42 | // defaultConfig 闭包:默认配置、应用程序包名、最小sdk版本、目标sdk版本、版本号、版本名称; |
| 43 | defaultConfig { | 43 | defaultConfig { |
| 44 | if (minSdkVersion == null) minSdkVersion 21 | 44 | if (minSdkVersion == null) minSdkVersion 21 |
| @@ -172,6 +172,7 @@ task clean(type: Delete) { | @@ -172,6 +172,7 @@ task clean(type: Delete) { | ||
| 172 | 172 | ||
| 173 | //配置全局变量 | 173 | //配置全局变量 |
| 174 | ext { | 174 | ext { |
| 175 | + buildToolsVersion = '29.0.0' | ||
| 175 | compileSdkVersion = 29 | 176 | compileSdkVersion = 29 |
| 176 | libMediaPicker = '1.6.0' | 177 | libMediaPicker = '1.6.0' |
| 177 | // loading动画 | 178 | // loading动画 |
cloud/wjj_lib/.gitignore
0 → 100644
| 1 | +/build |
cloud/wjj_lib/build.gradle
0 → 100644
| 1 | +apply plugin: 'com.android.library' | ||
| 2 | +//apply from: './maven_push.gradle' | ||
| 3 | + | ||
| 4 | +android { | ||
| 5 | +// compileSdkVersion rootProject.ext.compileSdkVersion | ||
| 6 | +// buildToolsVersion rootProject.ext.buildToolsVersion | ||
| 7 | + | ||
| 8 | + defaultConfig { | ||
| 9 | +// minSdkVersion rootProject.ext.minSdkVersion | ||
| 10 | +// targetSdkVersion rootProject.ext.targetSdkVersion | ||
| 11 | +// versionCode rootProject.ext.versionCode | ||
| 12 | +// versionName rootProject.ext.versionName | ||
| 13 | + | ||
| 14 | + javaCompileOptions { | ||
| 15 | + annotationProcessorOptions { | ||
| 16 | + arguments = [AROUTER_MODULE_NAME: project.getName(), AROUTER_GENERATE_DOC: "enable"] | ||
| 17 | + } | ||
| 18 | + } | ||
| 19 | + } | ||
| 20 | + | ||
| 21 | + //添加java编译指令,防止引用时,形参变成var1 | ||
| 22 | + gradle.projectsEvaluated { | ||
| 23 | + tasks.withType(JavaCompile) { | ||
| 24 | + options.compilerArgs.add('-parameters') | ||
| 25 | + } | ||
| 26 | + } | ||
| 27 | + compileOptions { | ||
| 28 | + sourceCompatibility JavaVersion.VERSION_1_8 | ||
| 29 | + targetCompatibility JavaVersion.VERSION_1_8 | ||
| 30 | + } | ||
| 31 | + buildTypes { | ||
| 32 | + debug { | ||
| 33 | + resValue("string", "ACCOUNT_LABEL", "网家家 内测") | ||
| 34 | + resValue("string", "ACCOUNT_TYPE", "com.cnlive.strike.debug.AccountType") | ||
| 35 | + resValue("string", "ACCOUNT_PROVIDE", "com.cnlive.strike.debug.AccountProvide") | ||
| 36 | + | ||
| 37 | + } | ||
| 38 | + release { | ||
| 39 | + resValue("string", "ACCOUNT_LABEL", "网家家") | ||
| 40 | + resValue("string", "ACCOUNT_TYPE", "com.cnlive.strike.AccountType") | ||
| 41 | + resValue("string", "ACCOUNT_PROVIDE", "com.cnlive.strike.AccountProvide") | ||
| 42 | + minifyEnabled false | ||
| 43 | + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | ||
| 44 | + } | ||
| 45 | + } | ||
| 46 | + dataBinding { | ||
| 47 | + enabled true | ||
| 48 | + } | ||
| 49 | +} | ||
| 50 | + | ||
| 51 | +dependencies { | ||
| 52 | + implementation fileTree(include: ['*.jar'], dir: 'libs') | ||
| 53 | +// implementation "com.android.support:support-v4:$rootProject.supportV4" | ||
| 54 | +// implementation "com.android.support:appcompat-v7:$rootProject.appcompatV7" | ||
| 55 | +// implementation "com.android.support:design:$rootProject.design" | ||
| 56 | +// implementation "com.android.support:support-v13:$rootProject.supportV13" | ||
| 57 | +// implementation "com.android.support:recyclerview-v7:$rootProject.recyclerviewV7" | ||
| 58 | +// implementation "com.android.support:cardview-v7:$rootProject.cardviewV7" | ||
| 59 | + //MVP | ||
| 60 | + | ||
| 61 | + //Java8 | ||
| 62 | + implementation 'net.sourceforge.streamsupport:streamsupport:1.5.5' | ||
| 63 | + implementation 'net.sourceforge.streamsupport:streamsupport-cfuture:1.5.5' | ||
| 64 | + implementation 'net.sourceforge.streamsupport:streamsupport-atomic:1.5.5' | ||
| 65 | + implementation 'net.sourceforge.streamsupport:streamsupport-flow:1.5.5' | ||
| 66 | + implementation 'net.sourceforge.streamsupport:streamsupport-literal:1.5.5' | ||
| 67 | +// //GSON | ||
| 68 | +// implementation "com.google.code.gson:gson:$rootProject.gson" | ||
| 69 | +// //RxJava | ||
| 70 | +// implementation 'io.reactivex.rxjava2:rxjava:2.1.8' | ||
| 71 | +// implementation('io.reactivex.rxjava2:rxandroid:2.0.1') { | ||
| 72 | +// exclude module: 'rxjava'// rxJava | ||
| 73 | +// } | ||
| 74 | +// //EventBus | ||
| 75 | +// implementation "org.greenrobot:eventbus:$rootProject.eventbus" | ||
| 76 | + implementation('com.github.pwittchen:reactivenetwork-rx2:3.0.6') { | ||
| 77 | + exclude module: "rxjava" | ||
| 78 | + } | ||
| 79 | +// //CNLive Encipher | ||
| 80 | +// implementation "com.cnlive:lib-cnencipher:$rootProject.libCnencipher" | ||
| 81 | + implementation "com.cnlive:lib_cnutil:$rootProject.libCnUtil" | ||
| 82 | +// //鲁班 暂时以源码形式引用,因为超大尺寸图片像素无法压缩 | ||
| 83 | +// //implementation 'top.zibin:Luban:1.1.8' | ||
| 84 | +// implementation "com.qmuiteam:qmui:$rootProject.qmui" | ||
| 85 | +// // compile 'top.zibin:Luban-turbo:1.0.0' | ||
| 86 | +// implementation 'com.github.GrenderG:Toasty:1.4.2' | ||
| 87 | +// | ||
| 88 | +// //ARouter | ||
| 89 | +// implementation "com.alibaba:arouter-api:$rootProject.arouterApiVersion" | ||
| 90 | +// annotationProcessor "com.alibaba:arouter-compiler:$rootProject.arouterCompilerVersion" | ||
| 91 | +// | ||
| 92 | +// api "com.cnlive.libs:network:$rootProject.libNetwork" | ||
| 93 | +// api files('libs/pinyin4j-2.5.0.jar') | ||
| 94 | +} | ||
| 95 | + | ||
| 96 | +//ext { | ||
| 97 | +// bintrayRepo = 'cnliveLibs' //Maven 库名称 | ||
| 98 | +// bintrayName = 'lib-appbase' //Maven 库内Lib包名 | ||
| 99 | +// | ||
| 100 | +// publishedGroupId = 'com.cnlive' | ||
| 101 | +// libraryName = 'base' | ||
| 102 | +// artifact = 'lib_base' //与包名保持一致! | ||
| 103 | +// | ||
| 104 | +// libraryDescription = 'for app libs' | ||
| 105 | +// | ||
| 106 | +// siteUrl = 'http://bj.gitlab.cnlive.com/cnlive-team/CNLiveSDK' | ||
| 107 | +// gitUrl = 'http://bj.gitlab.cnlive.com/cnlive-team/CNLiveSDK.git' | ||
| 108 | +// | ||
| 109 | +// libraryVersion = '1.1.3' | ||
| 110 | +// | ||
| 111 | +// developerId = 'CNlive' | ||
| 112 | +// developerName = 'Granzon' | ||
| 113 | +// developerEmail = 'zhuxiansong@cnlive.com' | ||
| 114 | +// | ||
| 115 | +// licenseName = 'The Apache Software License, Version 2.0' | ||
| 116 | +// licenseUrl = 'http://www.apache.org/licenses/LICENSE-2.0.txt' | ||
| 117 | +// allLicenses = ["Apache-2.0"] | ||
| 118 | +//} | ||
| 119 | +// | ||
| 120 | +//apply from: './from_installv1.gradle' | ||
| 121 | +//apply from: './from_bintrayv1.gradle' | ||
| 122 | + | ||
| 123 | +//ext { | ||
| 124 | +// PUBLISH_GROUP_ID = 'libcnlive' | ||
| 125 | +// PUBLISH_ARTIFACT_ID = 'base' | ||
| 126 | +// PUBLISH_VERSION = android.defaultConfig.versionName | ||
| 127 | +//} | ||
| 128 | +// | ||
| 129 | +//task makeBaseJar(type: Copy) { | ||
| 130 | +// def outJarVersion = project.PUBLISH_GROUP_ID +project.PUBLISH_ARTIFACT_ID + ".jar" | ||
| 131 | +// from('build/intermediates/bundles/release/') | ||
| 132 | +// into('build/libs/') | ||
| 133 | +// include('classes.jar') | ||
| 134 | +// rename('classes.jar', outJarVersion) | ||
| 135 | +//} | ||
| 136 | +// | ||
| 137 | +//makeBaseJar.dependsOn(build) |
cloud/wjj_lib/proguard-rules.pro
0 → 100644
| 1 | +# 通用混淆配置 | ||
| 2 | +#不混淆泛型 -keepattributes SourceFile | ||
| 3 | + -keepattributes Signature,InnerClasses,Exceptions,Deprecated,SourceFile,LineNumberTable,*Annotation*,EnclosingMethod | ||
| 4 | + | ||
| 5 | + -optimizationpasses 5 | ||
| 6 | + -dontusemixedcaseclassnames | ||
| 7 | + -dontskipnonpubliclibraryclasses | ||
| 8 | + -dontpreverify | ||
| 9 | + -verbose | ||
| 10 | + -optimizations !code/simplification/arithmetic,!field/*,!class/merging/* | ||
| 11 | + | ||
| 12 | + #忽略警告 也可以用-ignorewarnings | ||
| 13 | + -ignorewarnings | ||
| 14 | + -dontwarn | ||
| 15 | + | ||
| 16 | + -keep public class * extends android.app.Activity | ||
| 17 | + -keep public class * extends android.support.v4.app.Fragment | ||
| 18 | + -keep public class * extends android.app.Application | ||
| 19 | + -keep public class * extends android.app.Service | ||
| 20 | + -keep public class * extends android.content.BroadcastReceiver | ||
| 21 | + -keep public class * extends android.content.ContentProvider | ||
| 22 | + -keep public class * extends android.app.backup.BackupAgentHelper | ||
| 23 | + -keep public class * extends android.preference.Preference | ||
| 24 | + -keep public class com.android.vending.licensing.ILicensingService | ||
| 25 | + | ||
| 26 | + -keepclasseswithmembernames class * { | ||
| 27 | + native <methods>; | ||
| 28 | + } | ||
| 29 | + | ||
| 30 | + -keepclasseswithmembers class * { | ||
| 31 | + public <init>(android.content.Context, android.util.AttributeSet); | ||
| 32 | + } | ||
| 33 | + | ||
| 34 | + -keepclasseswithmembers class * { | ||
| 35 | + public <init>(android.content.Context, android.util.AttributeSet, int); | ||
| 36 | + } | ||
| 37 | + | ||
| 38 | + -keepclassmembers class * extends android.app.Activity { | ||
| 39 | + public void *(android.view.View); | ||
| 40 | + } | ||
| 41 | + | ||
| 42 | + -keepclassmembers enum * { | ||
| 43 | + public static **[] values(); | ||
| 44 | + public static ** valueOf(java.lang.String); | ||
| 45 | + } | ||
| 46 | + | ||
| 47 | + -keep class * implements android.os.Parcelable { | ||
| 48 | + public static final android.os.Parcelable$Creator *; | ||
| 49 | + } | ||
| 50 | + | ||
| 51 | +-keepclassmembers class **.R$* { | ||
| 52 | + public static <fields>; | ||
| 53 | +} | ||
| 54 | + | ||
| 55 | +# 通用混淆配置 End | ||
| 56 | + | ||
| 57 | +#统计SDK | ||
| 58 | +-keep class com.cnlive.libs.base.analytics.CNLiveProbe {*;} | ||
| 59 | +#应用配置信息 | ||
| 60 | +-keep class com.cnlive.libs.base.application.AppConfig {*;} | ||
| 61 | +#基础框架 | ||
| 62 | +-keep class com.cnlive.libs.base.frame.** {*;} | ||
| 63 | +-keep class com.cnlive.libs.base.logic.** {*;} | ||
| 64 | +-keep class com.cnlive.libs.base.recevier.** {*;} | ||
| 65 | +-keep class com.cnlive.libs.base.util.** {*;} | ||
| 66 | + | ||
| 67 | +# If single-type injection is used, that is, no interface is defined to implement IProvider, the following rules need to be added to protect the implementation | ||
| 68 | +-keep class * implements com.alibaba.android.arouter.facade.template.IProvider | ||
| 69 | +# # If you use the byType method to obtain Service, add the following rules to protect the interface: | ||
| 70 | +-keep interface * implements com.alibaba.android.arouter.facade.template.IProvider | ||
| 71 | +-keep class * implements com.alibaba.android.arouter.facade.template.ISyringe{*;} | ||
| 72 | + | ||
| 73 | +-keep interface com.cnlive.libs.base.arouter.user.CNLiveUserService{*;} | ||
| 74 | +-keep interface com.cnlive.libs.base.arouter.pay.CNLivePayService{*;} | ||
| 75 | +-keep interface com.cnlive.libs.base.arouter.share.CNLiveShareService{*;} | ||
| 76 | + | ||
| 77 | + |
cloud/wjj_lib/src/main/AndroidManifest.xml
0 → 100644
| 1 | +<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
| 2 | + package="com.cnlive.libs.base" > | ||
| 3 | + | ||
| 4 | + <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> | ||
| 5 | + <uses-permission | ||
| 6 | + android:name="android.permission.AUTHENTICATE_ACCOUNTS" | ||
| 7 | + android:maxSdkVersion="22" /> | ||
| 8 | + <uses-permission | ||
| 9 | + android:name="android.permission.GET_ACCOUNTS" | ||
| 10 | + android:maxSdkVersion="22" /> | ||
| 11 | + <uses-permission | ||
| 12 | + android:name="android.permission.MANAGE_ACCOUNTS" | ||
| 13 | + android:maxSdkVersion="22" /> | ||
| 14 | + <uses-permission android:name="android.permission.WRITE_SYNC_SETTINGS" /> | ||
| 15 | +</manifest> |
cloud/wjj_lib/src/main/java/com/cnlive/libs/base/application/AppConfig.java
0 → 100644
| 1 | +package com.cnlive.libs.base.application; | ||
| 2 | + | ||
| 3 | +import android.content.Context; | ||
| 4 | + | ||
| 5 | +import com.cnlive.libs.base.util.AppUtil; | ||
| 6 | +import com.cnlive.libs.base.util.ChannelUtil; | ||
| 7 | +import com.cnlive.libs.base.util.UUIDUtils; | ||
| 8 | + | ||
| 9 | +/** | ||
| 10 | + * Created by xiansong on 2018/4/24. | ||
| 11 | + */ | ||
| 12 | + | ||
| 13 | +public class AppConfig { | ||
| 14 | + private static String APP_ID = ""; | ||
| 15 | + private static String APP_KEY = ""; | ||
| 16 | + private static String APP_SCERET = ""; | ||
| 17 | + private static String APP_UUID = ""; | ||
| 18 | + private static String APP_PACKEG = ""; | ||
| 19 | + private static String APP_VERSION = ""; | ||
| 20 | + private static String APP_CHANNEL = ""; | ||
| 21 | + private static String PROMO_FROM = ""; | ||
| 22 | + private static int APP_SPECIAL_GROUP_MEMBER_LIMIT = 10; | ||
| 23 | + private static String BAIDU_APP_KEY = ""; | ||
| 24 | + private static String BAIDU_APP_SECRET = ""; | ||
| 25 | + private static String SID = ""; | ||
| 26 | + private static String WECHAT_APPID = ""; | ||
| 27 | + private static String PAY_ACCOUNT = ""; | ||
| 28 | + private static float FONT_SCALE = 1.0f; | ||
| 29 | + | ||
| 30 | + private static boolean VERSION_AS_DEBUG = true; | ||
| 31 | + private static String SHARE_DOWNLOAD = "http://apiwjj.cnlive.com/download/index.html"; | ||
| 32 | + private static String SHARE_ICON = "http://wjjh5.cnlive.com/static/logo.png"; | ||
| 33 | + private static String SHARE_LINK = "http://wjjh5.cnlive.com/static/tab_link.png"; | ||
| 34 | + private static String SHOP_PATH = "wjjshop.cnlive.com"; | ||
| 35 | + private static String SHARE_TITLE = "快来加入中国网家家,优享美好生活!"; | ||
| 36 | + private static String SHARE_SUBTITLE = "中国网家家 让生活更美好!"; | ||
| 37 | + private static String USER_PHONE = ""; | ||
| 38 | + private static String COUNTRY_CODE = ""; | ||
| 39 | + | ||
| 40 | + private static String COUNTRY_NAME = ""; | ||
| 41 | + private static String VERIFICATION_CODE = ""; | ||
| 42 | + private static String REPORT_URL = ""; | ||
| 43 | + private static boolean IS_TRTC_TALKING = false;//是否在进行音视频通话 | ||
| 44 | + private static String BAIDU_MAP_APP_KEY = "";//百度地图key | ||
| 45 | + | ||
| 46 | + | ||
| 47 | + public static void init(Context context, String id, String key, String sceret, | ||
| 48 | + int special_group_member_limit, boolean debug, String baidu_app_key, | ||
| 49 | + String baidu_app_secret, String loginSid, String wechatAppId, | ||
| 50 | + String shareDownload, String shareIcon, String pay_account, | ||
| 51 | + String shareTitle, String shareSubTitle, String reportUrl, | ||
| 52 | + String baidu_map_app_key, String shopPath) { | ||
| 53 | + APP_UUID = UUIDUtils.getUUID(context); | ||
| 54 | + APP_PACKEG = context.getPackageName(); | ||
| 55 | + APP_VERSION = AppUtil.getVersionName(context); | ||
| 56 | + APP_CHANNEL = ChannelUtil.getChannelFromApk(context); | ||
| 57 | + APP_SPECIAL_GROUP_MEMBER_LIMIT = special_group_member_limit; | ||
| 58 | + APP_ID = id; | ||
| 59 | + APP_KEY = key; | ||
| 60 | + APP_SCERET = sceret; | ||
| 61 | + VERSION_AS_DEBUG = debug; | ||
| 62 | + BAIDU_APP_KEY = baidu_app_key; | ||
| 63 | + BAIDU_APP_SECRET = baidu_app_secret; | ||
| 64 | + SID = loginSid; | ||
| 65 | + WECHAT_APPID = wechatAppId; | ||
| 66 | + SHARE_DOWNLOAD = shareDownload; | ||
| 67 | + SHARE_ICON = shareIcon; | ||
| 68 | + PAY_ACCOUNT = pay_account; | ||
| 69 | + SHARE_TITLE = shareTitle; | ||
| 70 | + SHARE_SUBTITLE = shareSubTitle; | ||
| 71 | + REPORT_URL = reportUrl; | ||
| 72 | + BAIDU_MAP_APP_KEY = baidu_map_app_key; | ||
| 73 | + SHOP_PATH = shopPath; | ||
| 74 | + } | ||
| 75 | + | ||
| 76 | + public static String getBaiduMapAppKey() { | ||
| 77 | + return BAIDU_MAP_APP_KEY; | ||
| 78 | + } | ||
| 79 | + | ||
| 80 | + public static void setBaiduMapAppKey(String baiduMapAppKey) { | ||
| 81 | + BAIDU_MAP_APP_KEY = baiduMapAppKey; | ||
| 82 | + } | ||
| 83 | + | ||
| 84 | + public static String getAppUUID() { | ||
| 85 | + return APP_UUID; | ||
| 86 | + } | ||
| 87 | + | ||
| 88 | + public static String getAppPackeg() { | ||
| 89 | + return APP_PACKEG; | ||
| 90 | + } | ||
| 91 | + | ||
| 92 | + public static String getAppVersion() { | ||
| 93 | + return APP_VERSION; | ||
| 94 | + } | ||
| 95 | + | ||
| 96 | + public static String getAppId() { | ||
| 97 | + return APP_ID; | ||
| 98 | + } | ||
| 99 | + | ||
| 100 | + public static String getAppKey() { | ||
| 101 | + return APP_KEY; | ||
| 102 | + } | ||
| 103 | + | ||
| 104 | + public static String getAppSceret() { | ||
| 105 | + return APP_SCERET; | ||
| 106 | + } | ||
| 107 | + | ||
| 108 | + public static String getAppChannel() { | ||
| 109 | + return APP_CHANNEL; | ||
| 110 | + } | ||
| 111 | + | ||
| 112 | + public static void setAppChannel(String channel) { | ||
| 113 | + APP_CHANNEL = channel == null ? "" : channel; | ||
| 114 | + } | ||
| 115 | + | ||
| 116 | + public static boolean isDebug() { | ||
| 117 | + return VERSION_AS_DEBUG; | ||
| 118 | + } | ||
| 119 | + | ||
| 120 | + public static int getAppSpecialGroupMemberLimit() { | ||
| 121 | + return APP_SPECIAL_GROUP_MEMBER_LIMIT; | ||
| 122 | + } | ||
| 123 | + | ||
| 124 | + public static String getPromoFrom() { | ||
| 125 | + return PROMO_FROM; | ||
| 126 | + } | ||
| 127 | + | ||
| 128 | + public static void setPromoFrom(String promoFrom) { | ||
| 129 | + PROMO_FROM = promoFrom; | ||
| 130 | + } | ||
| 131 | + | ||
| 132 | + public static String getBaiduAppKey() { | ||
| 133 | + return BAIDU_APP_KEY; | ||
| 134 | + } | ||
| 135 | + | ||
| 136 | + public static String getBaiduAppSecret() { | ||
| 137 | + return BAIDU_APP_SECRET; | ||
| 138 | + } | ||
| 139 | + | ||
| 140 | + public static void setAppSpecialGroupMemberLimit(int appSpecialGroupMemberLimit) { | ||
| 141 | + APP_SPECIAL_GROUP_MEMBER_LIMIT = appSpecialGroupMemberLimit; | ||
| 142 | + } | ||
| 143 | + | ||
| 144 | + public static String getSid() { | ||
| 145 | + return SID; | ||
| 146 | + } | ||
| 147 | + | ||
| 148 | + public static void setSid(String sid) { | ||
| 149 | + SID = sid; | ||
| 150 | + } | ||
| 151 | + | ||
| 152 | + public static String getWechatAppid() { | ||
| 153 | + return WECHAT_APPID; | ||
| 154 | + } | ||
| 155 | + | ||
| 156 | + public static float getFontScale() { | ||
| 157 | + return FONT_SCALE; | ||
| 158 | + } | ||
| 159 | + | ||
| 160 | + public static void setFontScale(float fontScale) { | ||
| 161 | + FONT_SCALE = fontScale; | ||
| 162 | + } | ||
| 163 | + | ||
| 164 | + public static String getShareDownload() { | ||
| 165 | + return SHARE_DOWNLOAD; | ||
| 166 | + } | ||
| 167 | + | ||
| 168 | + public static String getShareIcon() { | ||
| 169 | + return SHARE_ICON; | ||
| 170 | + } | ||
| 171 | + | ||
| 172 | + public static String getShareLink() { | ||
| 173 | + return SHARE_LINK; | ||
| 174 | + } | ||
| 175 | + | ||
| 176 | + public static String getPayAccount() { | ||
| 177 | + return PAY_ACCOUNT; | ||
| 178 | + } | ||
| 179 | + | ||
| 180 | + public static void setPayAccount(String payAccount) { | ||
| 181 | + PAY_ACCOUNT = payAccount; | ||
| 182 | + } | ||
| 183 | + | ||
| 184 | + public static void setShareDownload(String shareDownload) { | ||
| 185 | + SHARE_DOWNLOAD = shareDownload; | ||
| 186 | + } | ||
| 187 | + | ||
| 188 | + public static void setShareIcon(String shareIcon) { | ||
| 189 | + SHARE_ICON = shareIcon; | ||
| 190 | + } | ||
| 191 | + | ||
| 192 | + public static String getShareTitle() { | ||
| 193 | + return SHARE_TITLE; | ||
| 194 | + } | ||
| 195 | + | ||
| 196 | + public static void setShareTitle(String shareTitle) { | ||
| 197 | + SHARE_TITLE = shareTitle; | ||
| 198 | + } | ||
| 199 | + | ||
| 200 | + public static String getShareSubtitle() { | ||
| 201 | + return SHARE_SUBTITLE; | ||
| 202 | + } | ||
| 203 | + | ||
| 204 | + public static void setShareSubtitle(String shareSubtitle) { | ||
| 205 | + SHARE_SUBTITLE = shareSubtitle; | ||
| 206 | + } | ||
| 207 | + | ||
| 208 | + public static String getUserPhone() { | ||
| 209 | + return USER_PHONE; | ||
| 210 | + } | ||
| 211 | + | ||
| 212 | + public static void setUserPhone(String userPhone) { | ||
| 213 | + USER_PHONE = userPhone; | ||
| 214 | + } | ||
| 215 | + | ||
| 216 | + | ||
| 217 | + public static String getCountryCode() { | ||
| 218 | + return COUNTRY_CODE; | ||
| 219 | + } | ||
| 220 | + | ||
| 221 | + public static void setCountryCode(String countryCode) { | ||
| 222 | + COUNTRY_CODE = countryCode; | ||
| 223 | + } | ||
| 224 | + | ||
| 225 | + public static String getVerificationCode() { | ||
| 226 | + return VERIFICATION_CODE; | ||
| 227 | + } | ||
| 228 | + | ||
| 229 | + public static void setVerificationCode(String verificationCode) { | ||
| 230 | + VERIFICATION_CODE = verificationCode; | ||
| 231 | + } | ||
| 232 | + | ||
| 233 | + public static void setReportUrl(String reportUrl) { | ||
| 234 | + REPORT_URL = reportUrl; | ||
| 235 | + } | ||
| 236 | + | ||
| 237 | + public static String getReportUrl() { | ||
| 238 | + return REPORT_URL; | ||
| 239 | + } | ||
| 240 | + | ||
| 241 | + public static boolean isIsTrtcTalking() { | ||
| 242 | + return IS_TRTC_TALKING; | ||
| 243 | + } | ||
| 244 | + | ||
| 245 | + public static void setIsTrtcTalking(boolean isTrtcTalking) { | ||
| 246 | + IS_TRTC_TALKING = isTrtcTalking; | ||
| 247 | + } | ||
| 248 | + | ||
| 249 | + public static String getCountryName() { | ||
| 250 | + return COUNTRY_NAME; | ||
| 251 | + } | ||
| 252 | + | ||
| 253 | + public static void setCountryName(String countryName) { | ||
| 254 | + COUNTRY_NAME = countryName; | ||
| 255 | + } | ||
| 256 | + | ||
| 257 | + public static String getShopPath() { | ||
| 258 | + return SHOP_PATH; | ||
| 259 | + } | ||
| 260 | + | ||
| 261 | + public static void setShopPath(String shopPath) { | ||
| 262 | + SHOP_PATH = shopPath; | ||
| 263 | + } | ||
| 264 | +} |
cloud/wjj_lib/src/main/java/com/cnlive/libs/base/arouter/IJumpToView.java
0 → 100644
| 1 | +package com.cnlive.libs.base.arouter; | ||
| 2 | + | ||
| 3 | +import android.content.Context; | ||
| 4 | +import android.net.Uri; | ||
| 5 | + | ||
| 6 | +import com.alibaba.android.arouter.facade.template.IProvider; | ||
| 7 | + | ||
| 8 | +public interface IJumpToView extends IProvider { | ||
| 9 | + public static final String PATH_JUMP_TO_VIEW = "/cnStrike/cnJumpToViewService"; | ||
| 10 | + | ||
| 11 | + void jumpToView(Context context, String url); | ||
| 12 | + | ||
| 13 | + void jumpToView(Context context, Uri uri); | ||
| 14 | +} |
cloud/wjj_lib/src/main/java/com/cnlive/libs/base/arouter/IUpdateBtnStatus.java
0 → 100644
| 1 | +package com.cnlive.libs.base.arouter; | ||
| 2 | + | ||
| 3 | +import com.alibaba.android.arouter.facade.template.IProvider; | ||
| 4 | + | ||
| 5 | +public interface IUpdateBtnStatus extends IProvider { | ||
| 6 | + public static final String PATH_UPDATE_BTN_STATUS = "/cnStrike/cnUpdateBtnStatusService"; | ||
| 7 | + | ||
| 8 | + void changeCommentStatus(String pid, boolean selected, String model); | ||
| 9 | + | ||
| 10 | + void changeLikeStatus(String pid, boolean selected, String model); | ||
| 11 | + | ||
| 12 | + void changeCollectStatus(String pid, boolean selected, String model); | ||
| 13 | + | ||
| 14 | + void changeWitnessGraphicFocus(String spId, boolean focused); | ||
| 15 | +} |
cloud/wjj_lib/src/main/java/com/cnlive/libs/base/arouter/QrService.java
0 → 100644
| 1 | +package com.cnlive.libs.base.arouter; | ||
| 2 | + | ||
| 3 | +import android.graphics.Bitmap; | ||
| 4 | + | ||
| 5 | +import androidx.annotation.Nullable; | ||
| 6 | + | ||
| 7 | +import com.alibaba.android.arouter.facade.template.IProvider; | ||
| 8 | + | ||
| 9 | +/** | ||
| 10 | + * 作者: 吴奎庆 | ||
| 11 | + * <p> | ||
| 12 | + * 时间: 2019/6/18 | ||
| 13 | + * <p> | ||
| 14 | + * 简介: 生成二维码调用的服务 | ||
| 15 | + */ | ||
| 16 | +public interface QrService extends IProvider { | ||
| 17 | + String PATH = "/app/qrservice"; | ||
| 18 | + String NAME = "app_qrservice"; | ||
| 19 | + String GROUP = "appqr"; | ||
| 20 | + | ||
| 21 | + /** | ||
| 22 | + * 生成二维码的逻辑(带图标) | ||
| 23 | + * | ||
| 24 | + * @param content | ||
| 25 | + * @param size 宽高 | ||
| 26 | + * @param logoBitmap 图标的bitmap | ||
| 27 | + * @param logoPercent 百分比 | ||
| 28 | + * @return | ||
| 29 | + */ | ||
| 30 | + Bitmap createQrIconBitMap(String content, int size, @Nullable Bitmap logoBitmap, float logoPercent); | ||
| 31 | + | ||
| 32 | + /** | ||
| 33 | + * 生成不带图标的二维码 | ||
| 34 | + * | ||
| 35 | + * @param content 内容 | ||
| 36 | + * @param size 二维码大小 单位px | ||
| 37 | + * @return | ||
| 38 | + */ | ||
| 39 | + Bitmap createQRNoIconBitmap(@Nullable String content, int size); | ||
| 40 | + | ||
| 41 | +} |
cloud/wjj_lib/src/main/java/com/cnlive/libs/base/arouter/ar/CNLiveArService.java
0 → 100644
| 1 | +package com.cnlive.libs.base.arouter.ar; | ||
| 2 | + | ||
| 3 | +import android.content.Context; | ||
| 4 | + | ||
| 5 | +import com.alibaba.android.arouter.facade.template.IProvider; | ||
| 6 | + | ||
| 7 | +public interface CNLiveArService extends IProvider { | ||
| 8 | + static final String PATH = "/openService/CNLiveArService"; | ||
| 9 | + static final String NAME = "开放AR识别的服务接口"; | ||
| 10 | + | ||
| 11 | + /**跳转到AR识别页面 | ||
| 12 | + * @param context | ||
| 13 | + */ | ||
| 14 | + void jumpToArPage(Context context); | ||
| 15 | +} |
cloud/wjj_lib/src/main/java/com/cnlive/libs/base/arouter/classify/IClassifyJump.java
0 → 100644
| 1 | +package com.cnlive.libs.base.arouter.classify; | ||
| 2 | + | ||
| 3 | +import android.content.Context; | ||
| 4 | + | ||
| 5 | +import com.alibaba.android.arouter.facade.template.IProvider; | ||
| 6 | + | ||
| 7 | +public interface IClassifyJump extends IProvider { | ||
| 8 | + void classifyJumpToView(Context context, String programDataStr, String channelName); | ||
| 9 | +} |
cloud/wjj_lib/src/main/java/com/cnlive/libs/base/arouter/im/CheckFriendsResult.java
0 → 100644
| 1 | +package com.cnlive.libs.base.arouter.im; | ||
| 2 | + | ||
| 3 | +public class CheckFriendsResult { | ||
| 4 | + | ||
| 5 | + /** | ||
| 6 | + * 不是好友 | ||
| 7 | + */ | ||
| 8 | + public static final int TIM_FRIEND_RELATION_TYPE_NONE = 0; | ||
| 9 | + | ||
| 10 | + /** | ||
| 11 | + * 对方在我的好友列表中 | ||
| 12 | + */ | ||
| 13 | + public static final int TIM_FRIEND_RELATION_TYPE_MY_UNI = 1; | ||
| 14 | + | ||
| 15 | + /** | ||
| 16 | + * 我在对方的好友列表中 | ||
| 17 | + */ | ||
| 18 | + public static final int TIM_FRIEND_RELATION_TYPE_OTHER_UNI = 2; | ||
| 19 | + | ||
| 20 | + /** | ||
| 21 | + * 互为好友 | ||
| 22 | + */ | ||
| 23 | + public static final int TIM_FRIEND_RELATION_TYPE_BOTH_WAY = 3; | ||
| 24 | + | ||
| 25 | + private String identifier = ""; | ||
| 26 | + private int resultCode; | ||
| 27 | + private String resultInfo = ""; | ||
| 28 | + private int resultType; | ||
| 29 | + | ||
| 30 | + public CheckFriendsResult(String identifier, int resultCode, String resultInfo, int resultType) { | ||
| 31 | + this.identifier = identifier; | ||
| 32 | + this.resultCode = resultCode; | ||
| 33 | + this.resultInfo = resultInfo; | ||
| 34 | + this.resultType = resultType; | ||
| 35 | + } | ||
| 36 | + | ||
| 37 | + public String getIdentifier() { | ||
| 38 | + return identifier; | ||
| 39 | + } | ||
| 40 | + | ||
| 41 | + public void setIdentifier(String identifier) { | ||
| 42 | + this.identifier = identifier; | ||
| 43 | + } | ||
| 44 | + | ||
| 45 | + public int getResultCode() { | ||
| 46 | + return resultCode; | ||
| 47 | + } | ||
| 48 | + | ||
| 49 | + public void setResultCode(int resultCode) { | ||
| 50 | + this.resultCode = resultCode; | ||
| 51 | + } | ||
| 52 | + | ||
| 53 | + public String getResultInfo() { | ||
| 54 | + return resultInfo; | ||
| 55 | + } | ||
| 56 | + | ||
| 57 | + public void setResultInfo(String resultInfo) { | ||
| 58 | + this.resultInfo = resultInfo; | ||
| 59 | + } | ||
| 60 | + | ||
| 61 | + public int getResultType() { | ||
| 62 | + return resultType; | ||
| 63 | + } | ||
| 64 | + | ||
| 65 | + public void setResultType(int resultType) { | ||
| 66 | + this.resultType = resultType; | ||
| 67 | + } | ||
| 68 | +} |
cloud/wjj_lib/src/main/java/com/cnlive/libs/base/arouter/im/FriendListData.java
0 → 100644
| 1 | +package com.cnlive.libs.base.arouter.im; | ||
| 2 | + | ||
| 3 | +public class FriendListData { | ||
| 4 | + | ||
| 5 | + private String friendId; | ||
| 6 | + private String friendFaceUrl; | ||
| 7 | + private String friendNickName; | ||
| 8 | + private String friendRemark; | ||
| 9 | + private String friendCustomInfoJson; | ||
| 10 | + | ||
| 11 | + public String getFriendId() { | ||
| 12 | + return friendId; | ||
| 13 | + } | ||
| 14 | + | ||
| 15 | + public void setFriendId(String friendId) { | ||
| 16 | + this.friendId = friendId; | ||
| 17 | + } | ||
| 18 | + | ||
| 19 | + public String getFriendFaceUrl() { | ||
| 20 | + return friendFaceUrl; | ||
| 21 | + } | ||
| 22 | + | ||
| 23 | + public void setFriendFaceUrl(String friendFaceUrl) { | ||
| 24 | + this.friendFaceUrl = friendFaceUrl; | ||
| 25 | + } | ||
| 26 | + | ||
| 27 | + public String getFriendNickName() { | ||
| 28 | + return friendNickName; | ||
| 29 | + } | ||
| 30 | + | ||
| 31 | + public void setFriendNickName(String friendNickName) { | ||
| 32 | + this.friendNickName = friendNickName; | ||
| 33 | + } | ||
| 34 | + | ||
| 35 | + public String getFriendRemark() { | ||
| 36 | + return friendRemark; | ||
| 37 | + } | ||
| 38 | + | ||
| 39 | + public void setFriendRemark(String friendRemark) { | ||
| 40 | + this.friendRemark = friendRemark; | ||
| 41 | + } | ||
| 42 | + | ||
| 43 | + public String getFriendCustomInfoJson() { | ||
| 44 | + return friendCustomInfoJson; | ||
| 45 | + } | ||
| 46 | + | ||
| 47 | + public void setFriendCustomInfoJson(String friendCustomInfoJson) { | ||
| 48 | + this.friendCustomInfoJson = friendCustomInfoJson; | ||
| 49 | + } | ||
| 50 | +} |
cloud/wjj_lib/src/main/java/com/cnlive/libs/base/arouter/im/ImOpenService.java
0 → 100644
| 1 | +package com.cnlive.libs.base.arouter.im; | ||
| 2 | + | ||
| 3 | +import com.alibaba.android.arouter.facade.template.IProvider; | ||
| 4 | + | ||
| 5 | +import java.util.List; | ||
| 6 | + | ||
| 7 | +/** | ||
| 8 | + * IM相关的对外接口 | ||
| 9 | + */ | ||
| 10 | +public interface ImOpenService extends IProvider { | ||
| 11 | + //获取好友列表 | ||
| 12 | + void getFriendList(CNValueCallBack<List<FriendListData>> callBack); | ||
| 13 | + | ||
| 14 | + //是否已经加入了群组,注:本地数据判断 | ||
| 15 | + boolean hasJoinGroup(String groupId); | ||
| 16 | + | ||
| 17 | + //获取自己在群内的信息,注:网络获取 | ||
| 18 | + void getSelfInfoInGroup(String groupId, CNValueCallBack<JoinGroupState> callBack); | ||
| 19 | + | ||
| 20 | + //检测好友的状态 | ||
| 21 | + void checkFriends(String friendId, CNValueCallBack<CheckFriendsResult> callBack); | ||
| 22 | + | ||
| 23 | + interface CNCallBack { | ||
| 24 | + void onError(int errorCode, String errorMsg); | ||
| 25 | + | ||
| 26 | + void onSuccess(); | ||
| 27 | + } | ||
| 28 | + | ||
| 29 | + interface CNValueCallBack<T> { | ||
| 30 | + void onError(int var1, String var2); | ||
| 31 | + | ||
| 32 | + void onSuccess(T var1); | ||
| 33 | + } | ||
| 34 | + | ||
| 35 | + String getFriendRemarkName(String userId); | ||
| 36 | + | ||
| 37 | + String getUserName(String userId, String nickName); | ||
| 38 | + | ||
| 39 | +} |
cloud/wjj_lib/src/main/java/com/cnlive/libs/base/arouter/im/JoinGroupState.java
0 → 100644
| 1 | +package com.cnlive.libs.base.arouter.im; | ||
| 2 | + | ||
| 3 | +/** | ||
| 4 | + * author : gujun | ||
| 5 | + * date : 2019/11/5 15:53 | ||
| 6 | + * desc : 获取自己在群内的角色和消息接收状态 | ||
| 7 | + */ | ||
| 8 | +public class JoinGroupState { | ||
| 9 | + | ||
| 10 | + public static final int ROLE_TYPE_OWNER = 0x1001; | ||
| 11 | + public static final int ROLE_TYPE_ADMIN = 0x1002; | ||
| 12 | + public static final int ROLE_TYPE_NORMAL = 0x1003; | ||
| 13 | + public static final int ROLE_TYPE_NOT_MEMBER = 0x1004; | ||
| 14 | + | ||
| 15 | + public static final int ReceiveAndNotify = 0x2001; | ||
| 16 | + public static final int NotReceive = 0x2002; | ||
| 17 | + public static final int ReceiveNotNotify = 0x2003; | ||
| 18 | + | ||
| 19 | + private String groupId; | ||
| 20 | + private long recvOpt; | ||
| 21 | + private int role = ROLE_TYPE_NOT_MEMBER; | ||
| 22 | + | ||
| 23 | + public JoinGroupState(String groupId, long recvOpt, int role) { | ||
| 24 | + this.groupId = groupId; | ||
| 25 | + this.recvOpt = recvOpt; | ||
| 26 | + this.role = role; | ||
| 27 | + } | ||
| 28 | + | ||
| 29 | + public String getGroupId() { | ||
| 30 | + return groupId; | ||
| 31 | + } | ||
| 32 | + | ||
| 33 | + public void setGroupId(String groupId) { | ||
| 34 | + this.groupId = groupId; | ||
| 35 | + } | ||
| 36 | + | ||
| 37 | + public long getRecvOpt() { | ||
| 38 | + return recvOpt; | ||
| 39 | + } | ||
| 40 | + | ||
| 41 | + public void setRecvOpt(long recvOpt) { | ||
| 42 | + this.recvOpt = recvOpt; | ||
| 43 | + } | ||
| 44 | + | ||
| 45 | + public int getRole() { | ||
| 46 | + return role; | ||
| 47 | + } | ||
| 48 | + | ||
| 49 | + public void setRole(int role) { | ||
| 50 | + this.role = role; | ||
| 51 | + } | ||
| 52 | +} |
cloud/wjj_lib/src/main/java/com/cnlive/libs/base/arouter/input/ICommentInputLayoutService.java
0 → 100644
| 1 | +package com.cnlive.libs.base.arouter.input; | ||
| 2 | + | ||
| 3 | +import com.alibaba.android.arouter.facade.template.IProvider; | ||
| 4 | + | ||
| 5 | +/** | ||
| 6 | + * 评论输入窗 | ||
| 7 | + */ | ||
| 8 | +public interface ICommentInputLayoutService extends IProvider { | ||
| 9 | + /** | ||
| 10 | + * 隐藏输入框 | ||
| 11 | + * | ||
| 12 | + * @param content 输入框内文本 | ||
| 13 | + */ | ||
| 14 | + void hideInput(String content,String currentPage); | ||
| 15 | + | ||
| 16 | + /** | ||
| 17 | + * 发送内容 | ||
| 18 | + * | ||
| 19 | + * @param content 输入框内文本 | ||
| 20 | + */ | ||
| 21 | + void sendContent(String content,String currentPage); | ||
| 22 | + | ||
| 23 | + | ||
| 24 | + /** | ||
| 25 | + * 发送内容给某人 | ||
| 26 | + * | ||
| 27 | + * @param toSid 接收者ID | ||
| 28 | + * @param toName 接收者昵称 | ||
| 29 | + * @param content 输入框内文本内容 | ||
| 30 | + */ | ||
| 31 | + void sendContent(String toSid, String toName, String content,String currentPage); | ||
| 32 | + | ||
| 33 | + | ||
| 34 | + void onClickEmoji(String currentPage); | ||
| 35 | + void onClickInput(String currentPage); | ||
| 36 | +} |
cloud/wjj_lib/src/main/java/com/cnlive/libs/base/arouter/input/InputEventData.java
0 → 100644
| 1 | +package com.cnlive.libs.base.arouter.input; | ||
| 2 | + | ||
| 3 | +public class InputEventData { | ||
| 4 | + | ||
| 5 | + public static final int send = 1; | ||
| 6 | + public static final int save = 2; | ||
| 7 | + public static final int clickEmoji = 3; | ||
| 8 | + public static final int clickInput = 4; | ||
| 9 | + private int type; | ||
| 10 | + private String userId; | ||
| 11 | + private String userName; | ||
| 12 | + private String content; | ||
| 13 | + private String currentPage; | ||
| 14 | + | ||
| 15 | + public String getCurrentPage() { | ||
| 16 | + return currentPage; | ||
| 17 | + } | ||
| 18 | + | ||
| 19 | + public void setCurrentPage(String currentPage) { | ||
| 20 | + this.currentPage = currentPage; | ||
| 21 | + } | ||
| 22 | + | ||
| 23 | + public InputEventData(int type, String content,String currentPage) { | ||
| 24 | + this.content = content; | ||
| 25 | + this.type = type; | ||
| 26 | + this.currentPage=currentPage; | ||
| 27 | + } | ||
| 28 | + | ||
| 29 | + public InputEventData(int type, String userId, String userName, String content, String currentPage) { | ||
| 30 | + this.userId = userId; | ||
| 31 | + this.userName = userName; | ||
| 32 | + this.content = content; | ||
| 33 | + this.type = type; | ||
| 34 | + this.currentPage = currentPage; | ||
| 35 | + } | ||
| 36 | + | ||
| 37 | + public int getType() { | ||
| 38 | + return type; | ||
| 39 | + } | ||
| 40 | + | ||
| 41 | + public void setType(int type) { | ||
| 42 | + this.type = type; | ||
| 43 | + } | ||
| 44 | + | ||
| 45 | + public String getUserId() { | ||
| 46 | + return userId; | ||
| 47 | + } | ||
| 48 | + | ||
| 49 | + public void setUserId(String userId) { | ||
| 50 | + this.userId = userId; | ||
| 51 | + } | ||
| 52 | + | ||
| 53 | + public String getUserName() { | ||
| 54 | + return userName; | ||
| 55 | + } | ||
| 56 | + | ||
| 57 | + public void setUserName(String userName) { | ||
| 58 | + this.userName = userName; | ||
| 59 | + } | ||
| 60 | + | ||
| 61 | + public String getContent() { | ||
| 62 | + return content; | ||
| 63 | + } | ||
| 64 | + | ||
| 65 | + public void setContent(String content) { | ||
| 66 | + this.content = content; | ||
| 67 | + } | ||
| 68 | +} |
cloud/wjj_lib/src/main/java/com/cnlive/libs/base/arouter/input/InputEventObservable.java
0 → 100644
| 1 | +package com.cnlive.libs.base.arouter.input; | ||
| 2 | + | ||
| 3 | +import java.util.Observable; | ||
| 4 | + | ||
| 5 | +public class InputEventObservable extends Observable { | ||
| 6 | + | ||
| 7 | + private static InputEventObservable instance = new InputEventObservable(); | ||
| 8 | + | ||
| 9 | + public static InputEventObservable getInstance() { | ||
| 10 | + return instance; | ||
| 11 | + } | ||
| 12 | + | ||
| 13 | + public void sendMessage(String content, String currentPage) { | ||
| 14 | + sendMessage("", "", content, currentPage); | ||
| 15 | + } | ||
| 16 | + | ||
| 17 | + public void sendMessage(String userId, String userName, String content, String currentPage) { | ||
| 18 | + InputEventData data = new InputEventData( | ||
| 19 | + InputEventData.send, userId, userName, content, currentPage); | ||
| 20 | + | ||
| 21 | + setChanged(); | ||
| 22 | + notifyObservers(data); | ||
| 23 | + } | ||
| 24 | + | ||
| 25 | + | ||
| 26 | + public void saveCommentMessage(String content, String currentPage) { | ||
| 27 | + InputEventData data = new InputEventData( | ||
| 28 | + InputEventData.save, content, currentPage); | ||
| 29 | + | ||
| 30 | + setChanged(); | ||
| 31 | + notifyObservers(data); | ||
| 32 | + } | ||
| 33 | + | ||
| 34 | + public void onClickEmoji(String currentPage) { | ||
| 35 | + InputEventData data = new InputEventData( | ||
| 36 | + InputEventData.clickEmoji, "", "", "", currentPage); | ||
| 37 | + | ||
| 38 | + setChanged(); | ||
| 39 | + notifyObservers(data); | ||
| 40 | + } | ||
| 41 | + | ||
| 42 | + public void onClickInput(String currentPage) { | ||
| 43 | + InputEventData data = new InputEventData( | ||
| 44 | + InputEventData.clickInput, "", "", "", currentPage); | ||
| 45 | + | ||
| 46 | + setChanged(); | ||
| 47 | + notifyObservers(data); | ||
| 48 | + } | ||
| 49 | +} |
cloud/wjj_lib/src/main/java/com/cnlive/libs/base/arouter/pay/CNLivePayService.java
0 → 100644
| 1 | +package com.cnlive.libs.base.arouter.pay; | ||
| 2 | + | ||
| 3 | +import android.content.Context; | ||
| 4 | + | ||
| 5 | +import com.alibaba.android.arouter.facade.template.IProvider; | ||
| 6 | + | ||
| 7 | +import java.util.Map; | ||
| 8 | + | ||
| 9 | +/** | ||
| 10 | + * 给上海电商 支付 | ||
| 11 | + */ | ||
| 12 | +public interface CNLivePayService extends IProvider { | ||
| 13 | + static final String PATH = "/openService/CNLivePayService"; | ||
| 14 | + static final String NAME = "开放支付的服务接口"; | ||
| 15 | + | ||
| 16 | + | ||
| 17 | + /** | ||
| 18 | + * 跳转到支付页面 | ||
| 19 | + * | ||
| 20 | + * @param context 上下文 | ||
| 21 | + * @param orderId 订单id | ||
| 22 | + * @param title 订单标题/订单描述/订单简介 | ||
| 23 | + * @param price 订单金额(单位:分) | ||
| 24 | + * @param notifyUrl 订单状态回调地址 | ||
| 25 | + * @param extraParamsMap 订单扩展字段 | ||
| 26 | + * @param fromId 支付方id | ||
| 27 | + * @param sellerId 收款方id | ||
| 28 | + * @param sellerName 收款方名称/店铺名称/商家名称(支付成功页面展示) | ||
| 29 | + * @param sellerFaceUrl 收款方头像/店铺头像/商家头像(支付成功页面展示) | ||
| 30 | + * @param remark 备注/描述(支付成功页面展示,付款页面不负责上传) | ||
| 31 | + * @param commodityId 商品ID(网家家付费节目-商品ID)(没有请填null) | ||
| 32 | + * @param isShowWjjPay 是否显示网家家支付 | ||
| 33 | + * @param isShowWeChatPay 是否显示微信支付 | ||
| 34 | + * @param isShowAliPay 是否显示支付宝支付 | ||
| 35 | + * @param isShowUnionPay 是否显示银联支付 | ||
| 36 | + */ | ||
| 37 | + void jumpToPayPage(Context context, String orderId, String title, double price, String notifyUrl, Map<String, String> extraParamsMap, String fromId, String sellerId, String sellerName, String sellerFaceUrl, String remark, String commodityId, boolean isShowWjjPay, boolean isShowWeChatPay, boolean isShowAliPay, boolean isShowUnionPay); | ||
| 38 | +} |
cloud/wjj_lib/src/main/java/com/cnlive/libs/base/arouter/share/CNLiveShareService.java
0 → 100644
| 1 | +package com.cnlive.libs.base.arouter.share; | ||
| 2 | + | ||
| 3 | +import android.content.Context; | ||
| 4 | +import android.graphics.Bitmap; | ||
| 5 | + | ||
| 6 | +import com.alibaba.android.arouter.facade.template.IProvider; | ||
| 7 | + | ||
| 8 | +public interface CNLiveShareService extends IProvider { | ||
| 9 | + static final String PATH = "/openService/CNLiveShareService"; | ||
| 10 | + static final String NAME = "开放分享的服务接口"; | ||
| 11 | + | ||
| 12 | + /** | ||
| 13 | + * 分享链接 | ||
| 14 | + * | ||
| 15 | + * @param context 上下文 | ||
| 16 | + * @param title 主标题 | ||
| 17 | + * @param subTitle 副标题 | ||
| 18 | + * @param shareUrl 分享的链接 | ||
| 19 | + * @param shareImgUrl 分享的图片的链接 | ||
| 20 | + * @param isShowWjjLife 是否显示网家家生活圈 | ||
| 21 | + * @param isShowWjjFriend 是否显示网家家好友 | ||
| 22 | + * @param isShowOther 是否显示更多 | ||
| 23 | + */ | ||
| 24 | + void shareLink(Context context, String title, String subTitle, String shareUrl, String shareImgUrl, boolean isShowWjjLife, boolean isShowWjjFriend, boolean isShowOther); | ||
| 25 | + | ||
| 26 | + | ||
| 27 | + /** | ||
| 28 | + * 分享图片 | ||
| 29 | + * | ||
| 30 | + * @param context 上下文 | ||
| 31 | + * @param base64Img 图片转成base64 | ||
| 32 | + */ | ||
| 33 | + void shareImg(Context context, String base64Img); | ||
| 34 | +} | ||
| 35 | + |
cloud/wjj_lib/src/main/java/com/cnlive/libs/base/arouter/user/CNLiveUserService.java
0 → 100644
| 1 | +package com.cnlive.libs.base.arouter.user; | ||
| 2 | + | ||
| 3 | +import android.content.Context; | ||
| 4 | + | ||
| 5 | +import com.alibaba.android.arouter.facade.template.IProvider; | ||
| 6 | + | ||
| 7 | +/** | ||
| 8 | + * 给上海电商 用户库 | ||
| 9 | + */ | ||
| 10 | +public interface CNLiveUserService extends IProvider { | ||
| 11 | + public static final String PATH = "/openService/CNLiveUserService"; | ||
| 12 | + public static final String NAME = "开放用户信息的服务接口"; | ||
| 13 | + | ||
| 14 | + /** | ||
| 15 | + * 跳转到登录页 | ||
| 16 | + * | ||
| 17 | + * @param tagUrl 跳转地址 | ||
| 18 | + */ | ||
| 19 | + void jumpToLoginActivity(Context context, String tagUrl); | ||
| 20 | + | ||
| 21 | + /** | ||
| 22 | + * 跳转到登录对话框 | ||
| 23 | + * | ||
| 24 | + * @param tagUrl 跳转地址 | ||
| 25 | + */ | ||
| 26 | + void jumpToLoginDialog(Context context, String tagUrl); | ||
| 27 | + | ||
| 28 | + /** | ||
| 29 | + * 跳转到登录页 | ||
| 30 | + */ | ||
| 31 | + void jumpToLoginActivity(Context context); | ||
| 32 | + | ||
| 33 | + /** | ||
| 34 | + * 跳转到登录对话框 | ||
| 35 | + */ | ||
| 36 | + void jumpToLoginDialog(Context context); | ||
| 37 | + | ||
| 38 | + /** | ||
| 39 | + * 判断用户是否在线 | ||
| 40 | + * author ys | ||
| 41 | + * | ||
| 42 | + * @param context | ||
| 43 | + * @return | ||
| 44 | + */ | ||
| 45 | + boolean isUserOnline(Context context); | ||
| 46 | + | ||
| 47 | + /** | ||
| 48 | + * 判断用户是否登录 | ||
| 49 | + * author ys | ||
| 50 | + * | ||
| 51 | + * @param context | ||
| 52 | + * @return | ||
| 53 | + */ | ||
| 54 | + boolean isUserLogin(Context context); | ||
| 55 | + | ||
| 56 | + /** | ||
| 57 | + * 获取用户信息 | ||
| 58 | + * author ys | ||
| 59 | + * | ||
| 60 | + * @param context | ||
| 61 | + * @return | ||
| 62 | + */ | ||
| 63 | + OpenUserInfo getUserInfo(Context context); | ||
| 64 | + | ||
| 65 | + /** | ||
| 66 | + * 获取用户id | ||
| 67 | + * author ys | ||
| 68 | + * | ||
| 69 | + * @param context | ||
| 70 | + * @return | ||
| 71 | + */ | ||
| 72 | + String getUid(Context context); | ||
| 73 | + | ||
| 74 | +} |
cloud/wjj_lib/src/main/java/com/cnlive/libs/base/arouter/user/OpenUserInfo.java
0 → 100644
| 1 | +package com.cnlive.libs.base.arouter.user; | ||
| 2 | + | ||
| 3 | +import android.text.TextUtils; | ||
| 4 | + | ||
| 5 | +import java.io.Serializable; | ||
| 6 | + | ||
| 7 | +/** | ||
| 8 | + * 开放平台-用户信息 | ||
| 9 | + * | ||
| 10 | + * @author ys | ||
| 11 | + */ | ||
| 12 | + | ||
| 13 | +public class OpenUserInfo implements Serializable { | ||
| 14 | + //用户id | ||
| 15 | + private String uid; | ||
| 16 | + //昵称 | ||
| 17 | + private String nickName; | ||
| 18 | + //性别 | ||
| 19 | + private String gender; | ||
| 20 | + //地址 | ||
| 21 | + private String location; | ||
| 22 | + //详细地址 | ||
| 23 | + private String locationDesc; | ||
| 24 | + //头像 | ||
| 25 | + private String faceUrl; | ||
| 26 | + //手机号 | ||
| 27 | + private String mobile; | ||
| 28 | + //邮箱 | ||
| 29 | + private String email; | ||
| 30 | + //平台TOKEN | ||
| 31 | + private String token; | ||
| 32 | + //新用户 | ||
| 33 | + private boolean isNewUser; | ||
| 34 | + //个性签名 | ||
| 35 | + private String userSign; | ||
| 36 | + //用户头像大图 | ||
| 37 | + private String bigFaceUrl; | ||
| 38 | + //手机号国家码 | ||
| 39 | + private String countryCode; | ||
| 40 | + //qqid | ||
| 41 | + private String qqUid; | ||
| 42 | + //微信id | ||
| 43 | + private String wxUid; | ||
| 44 | + //微博id | ||
| 45 | + private String sinaUid; | ||
| 46 | + | ||
| 47 | + | ||
| 48 | + public String getUid() { | ||
| 49 | + return uid == null ? "" : uid; | ||
| 50 | + } | ||
| 51 | + | ||
| 52 | + public void setUid(String uid) { | ||
| 53 | + this.uid = uid; | ||
| 54 | + } | ||
| 55 | + | ||
| 56 | + public String getNickName() { | ||
| 57 | + return nickName; | ||
| 58 | + } | ||
| 59 | + | ||
| 60 | + public void setNickName(String nickName) { | ||
| 61 | + this.nickName = nickName; | ||
| 62 | + } | ||
| 63 | + | ||
| 64 | + public String getGender() { | ||
| 65 | + return gender; | ||
| 66 | + } | ||
| 67 | + | ||
| 68 | + public void setGender(String gender) { | ||
| 69 | + this.gender = gender; | ||
| 70 | + } | ||
| 71 | + | ||
| 72 | + public String getLocation() { | ||
| 73 | + return location; | ||
| 74 | + } | ||
| 75 | + | ||
| 76 | + public void setLocation(String location) { | ||
| 77 | + this.location = location; | ||
| 78 | + } | ||
| 79 | + | ||
| 80 | + public String getLocationDesc() { | ||
| 81 | + return locationDesc; | ||
| 82 | + } | ||
| 83 | + | ||
| 84 | + public void setLocationDesc(String locationDesc) { | ||
| 85 | + this.locationDesc = locationDesc; | ||
| 86 | + } | ||
| 87 | + | ||
| 88 | + public String getFaceUrl() { | ||
| 89 | + return faceUrl; | ||
| 90 | + } | ||
| 91 | + | ||
| 92 | + public void setFaceUrl(String faceUrl) { | ||
| 93 | + this.faceUrl = faceUrl; | ||
| 94 | + } | ||
| 95 | + | ||
| 96 | + public String getBigFaceUrl() { | ||
| 97 | + if (TextUtils.isEmpty(bigFaceUrl)) return faceUrl; | ||
| 98 | + return bigFaceUrl; | ||
| 99 | + } | ||
| 100 | + | ||
| 101 | + public void setBigFaceUrl(String bigFaceUrl) { | ||
| 102 | + this.bigFaceUrl = bigFaceUrl; | ||
| 103 | + } | ||
| 104 | + | ||
| 105 | + public String getMobile() { | ||
| 106 | + return mobile; | ||
| 107 | + } | ||
| 108 | + | ||
| 109 | + public void setMobile(String mobile) { | ||
| 110 | + this.mobile = mobile; | ||
| 111 | + } | ||
| 112 | + | ||
| 113 | + public String getEmail() { | ||
| 114 | + return email; | ||
| 115 | + } | ||
| 116 | + | ||
| 117 | + public void setEmail(String email) { | ||
| 118 | + this.email = email; | ||
| 119 | + } | ||
| 120 | + | ||
| 121 | + public String getToken() { | ||
| 122 | + return token; | ||
| 123 | + } | ||
| 124 | + | ||
| 125 | + public void setToken(String token) { | ||
| 126 | + this.token = token; | ||
| 127 | + } | ||
| 128 | + | ||
| 129 | + public boolean isNewUser() { | ||
| 130 | + return isNewUser; | ||
| 131 | + } | ||
| 132 | + | ||
| 133 | + public void setNewUser(boolean newUser) { | ||
| 134 | + isNewUser = newUser; | ||
| 135 | + } | ||
| 136 | + | ||
| 137 | + public String getQqUid() { | ||
| 138 | + return qqUid; | ||
| 139 | + } | ||
| 140 | + | ||
| 141 | + public void setQqUid(String qqUid) { | ||
| 142 | + this.qqUid = qqUid; | ||
| 143 | + } | ||
| 144 | + | ||
| 145 | + public String getWxUid() { | ||
| 146 | + return wxUid; | ||
| 147 | + } | ||
| 148 | + | ||
| 149 | + public void setWxUid(String wxUid) { | ||
| 150 | + this.wxUid = wxUid; | ||
| 151 | + } | ||
| 152 | + | ||
| 153 | + public String getSinaUid() { | ||
| 154 | + return sinaUid; | ||
| 155 | + } | ||
| 156 | + | ||
| 157 | + public void setSinaUid(String sinaUid) { | ||
| 158 | + this.sinaUid = sinaUid; | ||
| 159 | + } | ||
| 160 | + | ||
| 161 | + public String getUserSign() { | ||
| 162 | + return userSign; | ||
| 163 | + } | ||
| 164 | + | ||
| 165 | + public void setUserSign(String userSign) { | ||
| 166 | + this.userSign = userSign; | ||
| 167 | + } | ||
| 168 | + | ||
| 169 | + public String getCountryCode() { | ||
| 170 | + return countryCode; | ||
| 171 | + } | ||
| 172 | + | ||
| 173 | + public void setCountryCode(String countryCode) { | ||
| 174 | + this.countryCode = countryCode; | ||
| 175 | + } | ||
| 176 | +} |
cloud/wjj_lib/src/main/java/com/cnlive/libs/base/arouter/user/OpenUserService.java
0 → 100644
| 1 | +package com.cnlive.libs.base.arouter.user; | ||
| 2 | + | ||
| 3 | +import android.content.Context; | ||
| 4 | +import android.net.Uri; | ||
| 5 | + | ||
| 6 | +import com.alibaba.android.arouter.facade.template.IProvider; | ||
| 7 | + | ||
| 8 | +/** | ||
| 9 | + * author : gujun | ||
| 10 | + * date : 2019/11/9 10:32 | ||
| 11 | + * desc : | ||
| 12 | + */ | ||
| 13 | +public interface OpenUserService extends IProvider { | ||
| 14 | + | ||
| 15 | + /** | ||
| 16 | + * 检测用户是否登录,未登录弹出登录框返回false,已登录返回true, | ||
| 17 | + * | ||
| 18 | + * @param userId 当前用户id | ||
| 19 | + * @param tagurl 跳转目标页面的分享地址 | ||
| 20 | + * @param isLoginDialog 登陆页面是弹框还是页面 | ||
| 21 | + * @return | ||
| 22 | + */ | ||
| 23 | + boolean userHasLogin(String userId, String tagurl, boolean isLoginDialog); | ||
| 24 | + | ||
| 25 | + /** | ||
| 26 | + * 此方式只是验证是否登录,不进行跳转 | ||
| 27 | + * | ||
| 28 | + * @param userId | ||
| 29 | + * @return | ||
| 30 | + */ | ||
| 31 | + boolean userHasLogin(String userId); | ||
| 32 | + | ||
| 33 | + /** | ||
| 34 | + * 检测用户是否登录,未登录弹出登录框返回false,已登录返回true, | ||
| 35 | + * | ||
| 36 | + * @param userId 当前用户id | ||
| 37 | + * @param tagurl 跳转目标页面的分享地址 | ||
| 38 | + * @param isClickAd 是否点击了广告 | ||
| 39 | + * @param isLoginDialog 登陆页面是弹框还是页面 | ||
| 40 | + * @return | ||
| 41 | + */ | ||
| 42 | + boolean userHasLogin(String userId, String tagurl, boolean isClickAd, boolean isLoginDialog, Uri uri); | ||
| 43 | + | ||
| 44 | +} |
cloud/wjj_lib/src/main/java/com/cnlive/libs/base/frame/ReflectUtil.java
0 → 100644
| 1 | +package com.cnlive.libs.base.frame; | ||
| 2 | + | ||
| 3 | + | ||
| 4 | +import java.lang.reflect.Constructor; | ||
| 5 | +import java.lang.reflect.Method; | ||
| 6 | +import java.lang.reflect.ParameterizedType; | ||
| 7 | + | ||
| 8 | +public class ReflectUtil { | ||
| 9 | + | ||
| 10 | + private static final String TAG = "ReflectUtil"; | ||
| 11 | + | ||
| 12 | + public static Object invoke(Object obj, String methodName, Object data, Class clazz) { | ||
| 13 | + Object result = null; | ||
| 14 | + try { | ||
| 15 | + Method method = obj.getClass().getMethod(methodName, clazz); | ||
| 16 | + result = method.invoke(obj, data); | ||
| 17 | + } catch (Exception ignored) { | ||
| 18 | + } | ||
| 19 | + return result; | ||
| 20 | + } | ||
| 21 | + | ||
| 22 | + public static Object invoke(Object obj, String methodName, Object data) { | ||
| 23 | + Object result = null; | ||
| 24 | + try { | ||
| 25 | + Method method = obj.getClass().getMethod(methodName, new Class[]{data.getClass()}); | ||
| 26 | + result = method.invoke(obj, data); | ||
| 27 | + } catch (Exception ignored) { | ||
| 28 | + } | ||
| 29 | + return result; | ||
| 30 | + } | ||
| 31 | + | ||
| 32 | + public static Object invoke(Object obj, String methodName) { | ||
| 33 | + Object result = null; | ||
| 34 | + try { | ||
| 35 | + Method method = obj.getClass().getMethod(methodName); | ||
| 36 | + result = method.invoke(obj); | ||
| 37 | + } catch (Exception ignored) { | ||
| 38 | + } | ||
| 39 | + return result; | ||
| 40 | + } | ||
| 41 | + | ||
| 42 | + public static <R> R instance(int position, Class type, Object data) { | ||
| 43 | + R result = null; | ||
| 44 | + try { | ||
| 45 | + ParameterizedType pt = (ParameterizedType) type.getGenericSuperclass(); | ||
| 46 | + Class<R> clazz = (Class<R>) pt.getActualTypeArguments()[position]; | ||
| 47 | + Constructor constructor = clazz.getConstructor(new Class[]{data.getClass()}); | ||
| 48 | + result = (R) constructor.newInstance(data); | ||
| 49 | + } catch (Exception ignored) { | ||
| 50 | + } | ||
| 51 | + return result; | ||
| 52 | + } | ||
| 53 | + | ||
| 54 | + public static <R> R instance(int position, Object object) { | ||
| 55 | + R result = null; | ||
| 56 | + try { | ||
| 57 | + ParameterizedType pt = (ParameterizedType) object.getClass().getGenericSuperclass(); | ||
| 58 | + Class<R> clazz = (Class<R>) pt.getActualTypeArguments()[position]; | ||
| 59 | + result = clazz.newInstance(); | ||
| 60 | + } catch (Exception ignored) { | ||
| 61 | + } | ||
| 62 | + return result; | ||
| 63 | + } | ||
| 64 | +} |
cloud/wjj_lib/src/main/java/com/cnlive/libs/base/frame/adapter/DataBindingRecyclerAdapter.java
0 → 100644
| 1 | +package com.cnlive.libs.base.frame.adapter; | ||
| 2 | + | ||
| 3 | +/** | ||
| 4 | + * Created by xiansong on 2017/9/1. | ||
| 5 | + */ | ||
| 6 | + | ||
| 7 | +import android.view.LayoutInflater; | ||
| 8 | +import android.view.View; | ||
| 9 | +import android.view.ViewGroup; | ||
| 10 | + | ||
| 11 | +import androidx.annotation.NonNull; | ||
| 12 | +import androidx.databinding.DataBindingUtil; | ||
| 13 | +import androidx.databinding.ViewDataBinding; | ||
| 14 | +import androidx.recyclerview.widget.RecyclerView; | ||
| 15 | + | ||
| 16 | +import com.cnlive.libs.base.frame.ReflectUtil; | ||
| 17 | + | ||
| 18 | +import java.util.List; | ||
| 19 | + | ||
| 20 | + | ||
| 21 | +public abstract class DataBindingRecyclerAdapter<D, T extends ViewDataBinding> extends RecyclerView.Adapter<DataBindingRecyclerAdapter<D, T>.DataBindingViewHolder> { | ||
| 22 | + | ||
| 23 | + class DataBindingViewHolder extends RecyclerView.ViewHolder { | ||
| 24 | + | ||
| 25 | + private ViewDataBinding binding; | ||
| 26 | + | ||
| 27 | + private DataBindingViewHolder(View itemView) { | ||
| 28 | + super(itemView); | ||
| 29 | + } | ||
| 30 | + | ||
| 31 | + public void setBinding(ViewDataBinding binding) { | ||
| 32 | + this.binding = binding; | ||
| 33 | + } | ||
| 34 | + | ||
| 35 | + public ViewDataBinding getBinding() { | ||
| 36 | + return binding; | ||
| 37 | + } | ||
| 38 | + } | ||
| 39 | + | ||
| 40 | + abstract class Click implements View.OnClickListener { | ||
| 41 | + int position; | ||
| 42 | + | ||
| 43 | + Click(int position) { | ||
| 44 | + this.position = position; | ||
| 45 | + } | ||
| 46 | + } | ||
| 47 | + | ||
| 48 | + public interface OnItemClickListener<D> { | ||
| 49 | + void onItemClick(int id, D item); | ||
| 50 | + } | ||
| 51 | + | ||
| 52 | + public abstract int getLayoutId(); | ||
| 53 | + | ||
| 54 | + public abstract List<D> getList(); | ||
| 55 | + | ||
| 56 | + private OnItemClickListener<D> listener; | ||
| 57 | + | ||
| 58 | + @Override | ||
| 59 | + public DataBindingViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { | ||
| 60 | + T binding = DataBindingUtil.inflate(LayoutInflater.from(parent.getContext()), getLayoutId(), parent, false); | ||
| 61 | + DataBindingViewHolder viewHolder = new DataBindingViewHolder(binding.getRoot()); | ||
| 62 | + viewHolder.setBinding(binding); | ||
| 63 | + return viewHolder; | ||
| 64 | + } | ||
| 65 | + | ||
| 66 | + @Override | ||
| 67 | + public void onBindViewHolder(@NonNull final DataBindingViewHolder holder, int position) { | ||
| 68 | + ReflectUtil.invoke(holder.binding, "setData", getList().get(position)); | ||
| 69 | + ReflectUtil.invoke(holder.binding, "setClick", new Click(position) { | ||
| 70 | + @Override | ||
| 71 | + public void onClick(View v) { | ||
| 72 | +// if (listener != null) listener.onItemClick(v.getId(), getList().get(position)); | ||
| 73 | + if (listener != null) | ||
| 74 | + listener.onItemClick(v.getId(), (D) ReflectUtil.invoke(holder.binding, "getData")); | ||
| 75 | + } | ||
| 76 | + }, View.OnClickListener.class); | ||
| 77 | + holder.binding.executePendingBindings(); | ||
| 78 | + } | ||
| 79 | + | ||
| 80 | + public D getItem(int location) { | ||
| 81 | + return getList().get(location); | ||
| 82 | + } | ||
| 83 | + | ||
| 84 | + @Override | ||
| 85 | + public int getItemCount() { | ||
| 86 | + return getList() == null ? 0 : getList().size(); | ||
| 87 | + } | ||
| 88 | + | ||
| 89 | + public void setItemClickListener(OnItemClickListener<D> listener) { | ||
| 90 | + this.listener = listener; | ||
| 91 | + } | ||
| 92 | + | ||
| 93 | + public void addItem(int position, D item) { | ||
| 94 | + if (item == null) return; | ||
| 95 | + getList().add(position, item); | ||
| 96 | + notifyItemInserted(position); | ||
| 97 | + } | ||
| 98 | + | ||
| 99 | + public void addItem(D item) { | ||
| 100 | + if (item == null) return; | ||
| 101 | + getList().add(getList().size(), item); | ||
| 102 | + notifyItemInserted(getList().size()); | ||
| 103 | + } | ||
| 104 | + | ||
| 105 | + public void addItems(List<D> items) { | ||
| 106 | + if (items == null) return; | ||
| 107 | + this.getList().addAll(items); | ||
| 108 | + notifyDataSetChanged(); | ||
| 109 | + } | ||
| 110 | + | ||
| 111 | + public boolean containsAll(List<D> items) { | ||
| 112 | + return getList().containsAll(items); | ||
| 113 | + } | ||
| 114 | + | ||
| 115 | + public void updateItem(D tasks, int position) { | ||
| 116 | + if (tasks == null) return; | ||
| 117 | + getList().set(position, tasks); | ||
| 118 | + notifyItemChanged(position); | ||
| 119 | + } | ||
| 120 | + | ||
| 121 | + public void updateItems(List<D> items) { | ||
| 122 | + if (items == null) return; | ||
| 123 | + this.getList().clear(); | ||
| 124 | + this.getList().addAll(items); | ||
| 125 | + notifyDataSetChanged(); | ||
| 126 | + } | ||
| 127 | + | ||
| 128 | + public void removeItem(int index) { | ||
| 129 | + getList().remove(index); | ||
| 130 | + notifyItemRemoved(index); | ||
| 131 | + } | ||
| 132 | + | ||
| 133 | + public void removeAllItems() { | ||
| 134 | + getList().clear(); | ||
| 135 | + notifyDataSetChanged(); | ||
| 136 | + } | ||
| 137 | +} | ||
| 0 | \ No newline at end of file | 138 | \ No newline at end of file |
cloud/wjj_lib/src/main/java/com/cnlive/libs/base/frame/model/ViewStateListData.java
0 → 100644
| 1 | +package com.cnlive.libs.base.frame.model; | ||
| 2 | + | ||
| 3 | +import android.os.Parcel; | ||
| 4 | +import android.os.Parcelable; | ||
| 5 | +import android.util.Log; | ||
| 6 | + | ||
| 7 | +import androidx.databinding.BaseObservable; | ||
| 8 | +import androidx.databinding.Bindable; | ||
| 9 | +import androidx.databinding.ViewDataBinding; | ||
| 10 | +import androidx.recyclerview.widget.RecyclerView; | ||
| 11 | + | ||
| 12 | +import com.cnlive.libs.base.frame.adapter.DataBindingRecyclerAdapter; | ||
| 13 | + | ||
| 14 | +import java.util.ArrayList; | ||
| 15 | +import java.util.List; | ||
| 16 | + | ||
| 17 | +/** | ||
| 18 | + * Created by xiansong on 2017/9/1. | ||
| 19 | + */ | ||
| 20 | + | ||
| 21 | +public abstract class ViewStateListData<ITEM extends BaseObservable, BINDING extends ViewDataBinding> extends BaseObservable implements Parcelable { | ||
| 22 | + | ||
| 23 | + private static final String TAG = "PageListData"; | ||
| 24 | + | ||
| 25 | + public static <T extends ViewStateListData<ITEM, BINDING>, ITEM extends BaseObservable, BINDING extends ViewDataBinding> T newInstance(Class<T> clazz, Parcel in) { | ||
| 26 | + T data = null; | ||
| 27 | + try { | ||
| 28 | + data = clazz.newInstance(); | ||
| 29 | + data.createFromParcel(in); | ||
| 30 | + } catch (Exception e) { | ||
| 31 | + Log.e(TAG, "Presenter or data need to implement the default constructor: constructor ()", e); | ||
| 32 | + } | ||
| 33 | + return data; | ||
| 34 | + } | ||
| 35 | + | ||
| 36 | + public abstract int getLayoutId(); | ||
| 37 | + | ||
| 38 | + public abstract RecyclerView.LayoutManager getLayoutManager(); | ||
| 39 | + | ||
| 40 | + private List<ITEM> list = new ArrayList<>(); | ||
| 41 | + | ||
| 42 | + | ||
| 43 | + private DataBindingRecyclerAdapter<ITEM, BINDING> adapter = new DataBindingRecyclerAdapter<ITEM, BINDING>() { | ||
| 44 | + @Override | ||
| 45 | + public int getLayoutId() { | ||
| 46 | + return ViewStateListData.this.getLayoutId(); | ||
| 47 | + } | ||
| 48 | + | ||
| 49 | + @Override | ||
| 50 | + public List<ITEM> getList() { | ||
| 51 | + return list; | ||
| 52 | + } | ||
| 53 | + }; | ||
| 54 | + | ||
| 55 | + @Bindable | ||
| 56 | + public DataBindingRecyclerAdapter<ITEM, BINDING> getAdapter() { | ||
| 57 | + return adapter; | ||
| 58 | + } | ||
| 59 | + | ||
| 60 | + public void setAdapter(DataBindingRecyclerAdapter<ITEM, BINDING> adapter) { | ||
| 61 | + this.adapter = adapter; | ||
| 62 | + notifyPropertyChanged(com.cnlive.libs.base.BR.adapter); | ||
| 63 | + } | ||
| 64 | + | ||
| 65 | + | ||
| 66 | + @Override | ||
| 67 | + public int describeContents() { | ||
| 68 | + return 0; | ||
| 69 | + } | ||
| 70 | + | ||
| 71 | + @Override | ||
| 72 | + public void writeToParcel(Parcel parcel, int i) { | ||
| 73 | + parcel.writeList(this.list); | ||
| 74 | + } | ||
| 75 | + | ||
| 76 | + public void createFromParcel(Parcel in) { | ||
| 77 | + in.readList(list, getClass().getClassLoader()); | ||
| 78 | + } | ||
| 79 | + | ||
| 80 | +} |
cloud/wjj_lib/src/main/java/com/cnlive/libs/base/frame/view/MvpStateView.java
0 → 100644
cloud/wjj_lib/src/main/java/com/cnlive/libs/base/logic/Config.java
0 → 100644
| 1 | +package com.cnlive.libs.base.logic; | ||
| 2 | + | ||
| 3 | +/** | ||
| 4 | + * Created by xiansong on 2018/1/4. | ||
| 5 | + */ | ||
| 6 | + | ||
| 7 | +public class Config { | ||
| 8 | + | ||
| 9 | + //成功状态 | ||
| 10 | + public static final int SUCCESS = 0; | ||
| 11 | + //失败状态 | ||
| 12 | + public static final int FAIL = -1; | ||
| 13 | + //系统错误 | ||
| 14 | + public static final int ERROR_SYSTEM = 2003; | ||
| 15 | + //上传/下载错误 | ||
| 16 | + public static final int ERROR_UPLOAD = 2004; | ||
| 17 | + //空闲状态 | ||
| 18 | + public static final int STATE_IDLE = 3001; | ||
| 19 | + //加载状态 | ||
| 20 | + public static final int STATE_LOAD = 3002; | ||
| 21 | + | ||
| 22 | + public static final String ERROR_DEF = "%S_ERROR_%s code:%s message:%s"; | ||
| 23 | +} |
cloud/wjj_lib/src/main/java/com/cnlive/libs/base/logic/Event.java
0 → 100644
| 1 | +package com.cnlive.libs.base.logic; | ||
| 2 | + | ||
| 3 | + | ||
| 4 | +import com.cnlive.libs.base.logic.callback.Callback; | ||
| 5 | +import com.cnlive.libs.base.logic.callback.CancelCallback; | ||
| 6 | +import com.cnlive.libs.base.logic.callback.FailureCallback; | ||
| 7 | +import com.cnlive.libs.base.logic.callback.ProgressCallback; | ||
| 8 | +import com.cnlive.libs.base.logic.callback.StateCallback; | ||
| 9 | +import com.cnlive.libs.base.logic.callback.SuccessCallback; | ||
| 10 | + | ||
| 11 | +import java.util.ArrayList; | ||
| 12 | +import java.util.HashMap; | ||
| 13 | +import java.util.List; | ||
| 14 | +import java.util.Map; | ||
| 15 | + | ||
| 16 | +import io.reactivex.disposables.Disposable; | ||
| 17 | + | ||
| 18 | +/** | ||
| 19 | + * Created by xiansong on 2018/1/8. | ||
| 20 | + */ | ||
| 21 | + | ||
| 22 | +public class Event<T> { | ||
| 23 | + | ||
| 24 | + private static final int success_call = 1; | ||
| 25 | + private static final int failure_call = 2; | ||
| 26 | + private static final int state_call = 3; | ||
| 27 | + private static final int cancel_call = 4; | ||
| 28 | + private static final int progress_call = 5; | ||
| 29 | + | ||
| 30 | + public boolean active = true; | ||
| 31 | + private Logic logic; | ||
| 32 | + private List<Disposable> disposables = new ArrayList<>(); | ||
| 33 | + private Map<Integer, Callback> callbackArray; | ||
| 34 | + | ||
| 35 | + public Event() { | ||
| 36 | + this.callbackArray = new HashMap<>(); | ||
| 37 | + } | ||
| 38 | + | ||
| 39 | + public void setLogic(Logic logic) { | ||
| 40 | + this.logic = logic; | ||
| 41 | + } | ||
| 42 | + | ||
| 43 | + public Event<T> setSuccessCallback(SuccessCallback<T> callback) { | ||
| 44 | + callbackArray.put(success_call, callback); | ||
| 45 | + return this; | ||
| 46 | + } | ||
| 47 | + | ||
| 48 | + public Event<T> setFailureCallback(FailureCallback callback) { | ||
| 49 | + callbackArray.put(failure_call, callback); | ||
| 50 | + return this; | ||
| 51 | + } | ||
| 52 | + | ||
| 53 | + public Event<T> setStateCallback(StateCallback callback) { | ||
| 54 | + callbackArray.put(state_call, callback); | ||
| 55 | + return this; | ||
| 56 | + } | ||
| 57 | + | ||
| 58 | + public Event<T> setCancelCallback(CancelCallback callback) { | ||
| 59 | + callbackArray.put(cancel_call, callback); | ||
| 60 | + return this; | ||
| 61 | + } | ||
| 62 | + | ||
| 63 | + public Event<T> setProgressCallback(ProgressCallback callback) { | ||
| 64 | + callbackArray.put(progress_call, callback); | ||
| 65 | + return this; | ||
| 66 | + } | ||
| 67 | + | ||
| 68 | + public Event<T> addDisposable(Disposable disposable) { | ||
| 69 | + if (disposable != null) disposables.add(disposable); | ||
| 70 | + return this; | ||
| 71 | + } | ||
| 72 | + | ||
| 73 | + public void onSuccess(T data) { | ||
| 74 | + active = false; | ||
| 75 | + SuccessCallback<T> callback = (SuccessCallback<T>) callbackArray.get(success_call); | ||
| 76 | + if (callback != null) callback.onSuccess(data); | ||
| 77 | + } | ||
| 78 | + | ||
| 79 | + public void onFailure(int state, String message) { | ||
| 80 | + active = false; | ||
| 81 | + FailureCallback callback = (FailureCallback) callbackArray.get(failure_call); | ||
| 82 | + if (callback != null) callback.onFailure(state, message); | ||
| 83 | + } | ||
| 84 | + | ||
| 85 | + public void onState(int state) { | ||
| 86 | + StateCallback callback = (StateCallback) callbackArray.get(state_call); | ||
| 87 | + if (callback != null) callback.onState(state); | ||
| 88 | + } | ||
| 89 | + | ||
| 90 | + public void onCancle() { | ||
| 91 | + CancelCallback callback = (CancelCallback) callbackArray.get(cancel_call); | ||
| 92 | + if (callback != null) callback.onCancel(); | ||
| 93 | + destroy(); | ||
| 94 | + } | ||
| 95 | + | ||
| 96 | + public void onProgress(double progress) { | ||
| 97 | + ProgressCallback callback = (ProgressCallback) callbackArray.get(progress_call); | ||
| 98 | + if (callback != null) callback.onProgress(progress); | ||
| 99 | + } | ||
| 100 | + | ||
| 101 | + public void cencel() { | ||
| 102 | + onCancle(); | ||
| 103 | + } | ||
| 104 | + | ||
| 105 | + private void destroy() { | ||
| 106 | + active = false; | ||
| 107 | + callbackArray.clear(); | ||
| 108 | + if (disposables != null) for (Disposable disposable : disposables) disposable.dispose(); | ||
| 109 | + } | ||
| 110 | + | ||
| 111 | + public Event<T> start() { | ||
| 112 | + if (logic != null) logic.start(this); | ||
| 113 | + return this; | ||
| 114 | + } | ||
| 115 | +} |
cloud/wjj_lib/src/main/java/com/cnlive/libs/base/logic/Logic.java
0 → 100644
| 1 | +package com.cnlive.libs.base.logic; | ||
| 2 | + | ||
| 3 | + | ||
| 4 | +import android.util.Log; | ||
| 5 | + | ||
| 6 | +import com.cnlive.libs.base.logic.callback.DataCallback; | ||
| 7 | + | ||
| 8 | +import java.util.ArrayList; | ||
| 9 | +import java.util.HashMap; | ||
| 10 | +import java.util.List; | ||
| 11 | +import java.util.Map; | ||
| 12 | + | ||
| 13 | +import io.reactivex.Observable; | ||
| 14 | +import io.reactivex.ObservableOnSubscribe; | ||
| 15 | +import io.reactivex.android.schedulers.AndroidSchedulers; | ||
| 16 | +import io.reactivex.disposables.Disposable; | ||
| 17 | +import io.reactivex.functions.Consumer; | ||
| 18 | +import io.reactivex.schedulers.Schedulers; | ||
| 19 | + | ||
| 20 | +import static com.cnlive.libs.base.logic.Config.FAIL; | ||
| 21 | +import static com.cnlive.libs.base.logic.Config.SUCCESS; | ||
| 22 | + | ||
| 23 | +public class Logic { | ||
| 24 | + private Event event; | ||
| 25 | + | ||
| 26 | + protected List<BaseAction> actions; | ||
| 27 | + | ||
| 28 | + private Object startParem; | ||
| 29 | + | ||
| 30 | + private Paramer paramer = new Paramer(); | ||
| 31 | + | ||
| 32 | + protected Logic(Object startParem) { | ||
| 33 | + this.startParem = startParem; | ||
| 34 | + actions = new ArrayList<>(); | ||
| 35 | + } | ||
| 36 | + | ||
| 37 | + public static Logic create(Object startParem) { | ||
| 38 | + return new Logic(startParem); | ||
| 39 | + } | ||
| 40 | + | ||
| 41 | + public static Logic create() { | ||
| 42 | + return new Logic(null); | ||
| 43 | + } | ||
| 44 | + | ||
| 45 | + public <param, result> Logic action(Action<param, result> action) { | ||
| 46 | + if (action == null) return this; | ||
| 47 | + actions.add(action); | ||
| 48 | + return this; | ||
| 49 | + } | ||
| 50 | + | ||
| 51 | + public <param, result> Logic action(ActionMerge<param, result> action) { | ||
| 52 | + if (action == null) return this; | ||
| 53 | + actions.add(action); | ||
| 54 | + return this; | ||
| 55 | + } | ||
| 56 | + | ||
| 57 | + private int action_index = -1; | ||
| 58 | + | ||
| 59 | + private boolean inStart() { | ||
| 60 | + return action_index != -1; | ||
| 61 | + } | ||
| 62 | + | ||
| 63 | + private <Data, Return> void next(Data data) { | ||
| 64 | + BaseAction action = actions.get(action_index++); | ||
| 65 | + BaseAction newAction = action_index < actions.size() ? actions.get(action_index) : null; | ||
| 66 | + LogicCallback<Return> callback = new LogicCallback<>(event, newAction); | ||
| 67 | + Disposable disposable = null; | ||
| 68 | + Exception exception = null; | ||
| 69 | + try { | ||
| 70 | + if (action == null) return; | ||
| 71 | + if (action instanceof Action) disposable = ((Action) action).action(data, callback); | ||
| 72 | + if (action instanceof ActionMerge) disposable = ((ActionMerge) action).action(data, paramer, callback); | ||
| 73 | + } catch (Exception e) { | ||
| 74 | + exception = e; | ||
| 75 | + Log.e("Logic", "页面逻辑出错!", e); | ||
| 76 | + } | ||
| 77 | + | ||
| 78 | + if (disposable != null) event.addDisposable(disposable); | ||
| 79 | + else if (exception != null) onError(FAIL, exception.getMessage(), event); | ||
| 80 | + } | ||
| 81 | + | ||
| 82 | + public <T> Event<T> event() { | ||
| 83 | + if (event != null) return event; | ||
| 84 | + event = new Event<T>(); | ||
| 85 | + event.setLogic(this); | ||
| 86 | + return event; | ||
| 87 | + } | ||
| 88 | + | ||
| 89 | + // | ||
| 90 | + public void start(Event event) { | ||
| 91 | + if (event == null) return; | ||
| 92 | + if (inStart()) return; | ||
| 93 | + | ||
| 94 | + this.action_index = 0; | ||
| 95 | + this.event = event; | ||
| 96 | + | ||
| 97 | + if (event.active) { | ||
| 98 | + event.onState(Config.STATE_LOAD); | ||
| 99 | + next(startParem); | ||
| 100 | + } | ||
| 101 | + } | ||
| 102 | + | ||
| 103 | + public interface Execute<T> { | ||
| 104 | + T execute(); | ||
| 105 | + } | ||
| 106 | + | ||
| 107 | + private static String getErrorMessage(Throwable throwable) { | ||
| 108 | + return throwable != null ? throwable.getMessage() : ""; | ||
| 109 | + } | ||
| 110 | + | ||
| 111 | + public static <T> Disposable process(Execute<T> exce, DataCallback<T> callback) { | ||
| 112 | + Consumer<T> successEV = data -> { | ||
| 113 | + if (callback != null) callback.callback(SUCCESS, "", data); | ||
| 114 | + }; | ||
| 115 | + Consumer<Throwable> errorEV = throwable -> { | ||
| 116 | + if (callback != null) callback.callback(FAIL, getErrorMessage(throwable), null); | ||
| 117 | + }; | ||
| 118 | + return Observable | ||
| 119 | + .create((ObservableOnSubscribe<T>) emitter -> emitter.onNext(exce.execute())) | ||
| 120 | + .subscribeOn(Schedulers.io()) | ||
| 121 | + .observeOn(AndroidSchedulers.mainThread()) | ||
| 122 | + .subscribe(successEV, errorEV); | ||
| 123 | + } | ||
| 124 | + | ||
| 125 | + private interface BaseAction { | ||
| 126 | + } | ||
| 127 | + | ||
| 128 | + public interface Action<param, result> extends BaseAction { | ||
| 129 | + Disposable action(param data, DataCallback<result> callback); | ||
| 130 | + } | ||
| 131 | + | ||
| 132 | + public interface ActionMerge<param, result> extends BaseAction { | ||
| 133 | + Disposable action(param data, Paramer paramer, DataCallback<result> callback); | ||
| 134 | + } | ||
| 135 | + | ||
| 136 | + public class LogicCallback<T> implements DataCallback<T> { | ||
| 137 | + private BaseAction action; | ||
| 138 | + private Event event; | ||
| 139 | + | ||
| 140 | + private LogicCallback(Event event, BaseAction action) { | ||
| 141 | + this.event = event; | ||
| 142 | + this.action = action; | ||
| 143 | + } | ||
| 144 | + | ||
| 145 | + @Override | ||
| 146 | + public void callback(int code, String message, T data) { | ||
| 147 | + if (code == Config.SUCCESS) { | ||
| 148 | + if (event.active) { | ||
| 149 | + if (action != null) next(data); | ||
| 150 | + else { | ||
| 151 | + event.onState(Config.STATE_IDLE); | ||
| 152 | + event.onSuccess(data); | ||
| 153 | + } | ||
| 154 | + } | ||
| 155 | + } else onError(code, message, event); | ||
| 156 | + } | ||
| 157 | + } | ||
| 158 | + | ||
| 159 | + private void onError(int code, String message, Event event) { | ||
| 160 | + if (event.active) { | ||
| 161 | + event.onState(Config.STATE_IDLE); | ||
| 162 | + event.onFailure(code, message); | ||
| 163 | + } | ||
| 164 | + } | ||
| 165 | + | ||
| 166 | + public static class Paramer { | ||
| 167 | + private Map<String, Object> map = new HashMap<>(); | ||
| 168 | + | ||
| 169 | + public void addParamer(String key, Object value) { | ||
| 170 | + map.put(key, value); | ||
| 171 | + } | ||
| 172 | + | ||
| 173 | + public <T> T getParamer(String key) { | ||
| 174 | + return (T) map.get(key); | ||
| 175 | + } | ||
| 176 | + } | ||
| 177 | +} |
cloud/wjj_lib/src/main/java/com/cnlive/libs/base/logic/callback/Callback.java
0 → 100644
cloud/wjj_lib/src/main/java/com/cnlive/libs/base/logic/callback/CancelCallback.java
0 → 100644
cloud/wjj_lib/src/main/java/com/cnlive/libs/base/logic/callback/DataCallback.java
0 → 100644
cloud/wjj_lib/src/main/java/com/cnlive/libs/base/logic/callback/FailureCallback.java
0 → 100644
cloud/wjj_lib/src/main/java/com/cnlive/libs/base/logic/callback/ProgressCallback.java
0 → 100644
cloud/wjj_lib/src/main/java/com/cnlive/libs/base/logic/callback/StateCallback.java
0 → 100644
cloud/wjj_lib/src/main/java/com/cnlive/libs/base/logic/callback/SuccessCallback.java
0 → 100644
cloud/wjj_lib/src/main/java/com/cnlive/libs/base/observable/ShareStateInfo.java
0 → 100644
| 1 | +package com.cnlive.libs.base.observable; | ||
| 2 | + | ||
| 3 | +/** | ||
| 4 | + * 作者: 吴奎庆 | ||
| 5 | + * <p> | ||
| 6 | + * 时间: 2019/10/23 | ||
| 7 | + * <p> | ||
| 8 | + * 简介: | ||
| 9 | + */ | ||
| 10 | +public class ShareStateInfo { | ||
| 11 | + | ||
| 12 | + // 1 网家家好友 2 网家家生活圈 3 微信好友 4 微信朋友圈 5 qq 6 微博 7 外部 8 举报 9 其他 | ||
| 13 | + String type; | ||
| 14 | + //商城的分享的类型 | ||
| 15 | + String shopShareType; | ||
| 16 | + //是否分享成功 | ||
| 17 | + boolean isShareSuccess; | ||
| 18 | + | ||
| 19 | + public String getType() { | ||
| 20 | + return type; | ||
| 21 | + } | ||
| 22 | + | ||
| 23 | + public void setType(String type) { | ||
| 24 | + this.type = type; | ||
| 25 | + } | ||
| 26 | + | ||
| 27 | + public String getShopShareType() { | ||
| 28 | + return shopShareType; | ||
| 29 | + } | ||
| 30 | + | ||
| 31 | + public void setShopShareType(String shopShareType) { | ||
| 32 | + this.shopShareType = shopShareType; | ||
| 33 | + } | ||
| 34 | + | ||
| 35 | + public boolean isShareSuccess() { | ||
| 36 | + return isShareSuccess; | ||
| 37 | + } | ||
| 38 | + | ||
| 39 | + public void setShareSuccess(boolean shareSuccess) { | ||
| 40 | + isShareSuccess = shareSuccess; | ||
| 41 | + } | ||
| 42 | + | ||
| 43 | + | ||
| 44 | + | ||
| 45 | +} |
cloud/wjj_lib/src/main/java/com/cnlive/libs/base/observable/ShareStateObservable.java
0 → 100644
| 1 | +package com.cnlive.libs.base.observable; | ||
| 2 | + | ||
| 3 | +import java.util.Observable; | ||
| 4 | + | ||
| 5 | +/** | ||
| 6 | + * 作者: 吴奎庆 | ||
| 7 | + * <p> | ||
| 8 | + * 时间: 2019/10/23 | ||
| 9 | + * <p> | ||
| 10 | + * 简介: 三方分享的状态回调 | ||
| 11 | + */ | ||
| 12 | +public class ShareStateObservable extends Observable { | ||
| 13 | + | ||
| 14 | + static ShareStateObservable instance; | ||
| 15 | + | ||
| 16 | + public static ShareStateObservable newInstance() { | ||
| 17 | + | ||
| 18 | + synchronized (ShareStateObservable.class) { | ||
| 19 | + if (instance == null) { | ||
| 20 | + instance = new ShareStateObservable(); | ||
| 21 | + } | ||
| 22 | + } | ||
| 23 | + return instance; | ||
| 24 | + } | ||
| 25 | + | ||
| 26 | + /** | ||
| 27 | + * 更新分享的状态 | ||
| 28 | + * @param info | ||
| 29 | + */ | ||
| 30 | + public void update(ShareStateInfo info) { | ||
| 31 | + setChanged(); | ||
| 32 | + notifyObservers(info); | ||
| 33 | + | ||
| 34 | + } | ||
| 35 | + | ||
| 36 | + | ||
| 37 | + | ||
| 38 | +} |
cloud/wjj_lib/src/main/java/com/cnlive/libs/base/observable/ShareWjjStateObservable.java
0 → 100644
| 1 | +package com.cnlive.libs.base.observable; | ||
| 2 | + | ||
| 3 | +import java.util.Observable; | ||
| 4 | + | ||
| 5 | +/** | ||
| 6 | + * 作者: 吴奎庆 | ||
| 7 | + * <p> | ||
| 8 | + * 时间: 2019/10/23 | ||
| 9 | + * <p> | ||
| 10 | + * 简介: 网++分享成功的状态 | ||
| 11 | + */ | ||
| 12 | +public class ShareWjjStateObservable extends Observable { | ||
| 13 | + | ||
| 14 | + static ShareWjjStateObservable instance; | ||
| 15 | + | ||
| 16 | + public static ShareWjjStateObservable newInstance() { | ||
| 17 | + | ||
| 18 | + synchronized (ShareWjjStateObservable.class) { | ||
| 19 | + if (instance == null) { | ||
| 20 | + instance = new ShareWjjStateObservable(); | ||
| 21 | + } | ||
| 22 | + return instance; | ||
| 23 | + } | ||
| 24 | + } | ||
| 25 | + | ||
| 26 | + public void update(boolean isSuccessed){ | ||
| 27 | + setChanged(); | ||
| 28 | + notifyObservers(isSuccessed); | ||
| 29 | + } | ||
| 30 | +} |
cloud/wjj_lib/src/main/java/com/cnlive/libs/base/observable/sp/SpFollowObservable.java
0 → 100644
| 1 | +package com.cnlive.libs.base.observable.sp; | ||
| 2 | + | ||
| 3 | +import java.util.Observable; | ||
| 4 | + | ||
| 5 | +/** | ||
| 6 | + * Created by Lynn on 2019/4/3. | ||
| 7 | + * 订阅号主页点击关注后,更新播放、H5详情页面关注按钮状态 | ||
| 8 | + */ | ||
| 9 | +public class SpFollowObservable extends Observable { | ||
| 10 | + private static SpFollowObservable instance; | ||
| 11 | + | ||
| 12 | + public static SpFollowObservable getInstance() { | ||
| 13 | + if (instance == null) { | ||
| 14 | + synchronized (SpFollowObservable.class) { | ||
| 15 | + if (instance == null) { | ||
| 16 | + instance = new SpFollowObservable(); | ||
| 17 | + } | ||
| 18 | + } | ||
| 19 | + } | ||
| 20 | + return instance; | ||
| 21 | + } | ||
| 22 | + | ||
| 23 | + public void changeAttentionStatus(String spId, boolean attention, String fansCount) { | ||
| 24 | + setChanged(); | ||
| 25 | + notifyObservers(new SubscribeInfo(spId, attention, fansCount)); | ||
| 26 | + } | ||
| 27 | + | ||
| 28 | + public void changeAttentionStatus(String spId, boolean attention) { | ||
| 29 | + setChanged(); | ||
| 30 | + notifyObservers(new SubscribeInfo(spId, attention)); | ||
| 31 | + } | ||
| 32 | + | ||
| 33 | + public static class SubscribeInfo { | ||
| 34 | + private String spId; | ||
| 35 | + private boolean attention; | ||
| 36 | + private String fansCount; | ||
| 37 | + | ||
| 38 | + public SubscribeInfo(String spId, boolean attention) { | ||
| 39 | + this.spId = spId; | ||
| 40 | + this.attention = attention; | ||
| 41 | + } | ||
| 42 | + | ||
| 43 | + public SubscribeInfo(String spId, boolean attention, String fansCount) { | ||
| 44 | + this.spId = spId; | ||
| 45 | + this.attention = attention; | ||
| 46 | + this.fansCount = fansCount; | ||
| 47 | + } | ||
| 48 | + | ||
| 49 | + public String getSpId() { | ||
| 50 | + return spId; | ||
| 51 | + } | ||
| 52 | + | ||
| 53 | + public void setSpId(String spId) { | ||
| 54 | + this.spId = spId; | ||
| 55 | + } | ||
| 56 | + | ||
| 57 | + public boolean isAttention() { | ||
| 58 | + return attention; | ||
| 59 | + } | ||
| 60 | + | ||
| 61 | + public void setAttention(boolean attention) { | ||
| 62 | + this.attention = attention; | ||
| 63 | + } | ||
| 64 | + | ||
| 65 | + public String getFansCount() { | ||
| 66 | + return getFansNum(fansCount); | ||
| 67 | + } | ||
| 68 | + | ||
| 69 | + public void setFansCount(String fansCount) { | ||
| 70 | + this.fansCount = fansCount; | ||
| 71 | + } | ||
| 72 | + | ||
| 73 | + private String getFansNum(String fansCount) { | ||
| 74 | + int fansNum; | ||
| 75 | + try { | ||
| 76 | + fansNum = Integer.parseInt(fansCount); | ||
| 77 | + } catch (Exception e) { | ||
| 78 | + fansNum = 0; | ||
| 79 | + } | ||
| 80 | + return fansNum + ""; | ||
| 81 | + } | ||
| 82 | + } | ||
| 83 | +} |
cloud/wjj_lib/src/main/java/com/cnlive/libs/base/recevier/IMReconnectReceive.java
0 → 100644
| 1 | +package com.cnlive.libs.base.recevier; | ||
| 2 | + | ||
| 3 | + | ||
| 4 | +import org.greenrobot.eventbus.EventBus; | ||
| 5 | + | ||
| 6 | +public class IMReconnectReceive { | ||
| 7 | + | ||
| 8 | + public static class IMConnectState { | ||
| 9 | + } | ||
| 10 | + | ||
| 11 | + public interface IMReconnectCallback { | ||
| 12 | + void onIMReconnectEvent(IMConnectState state); | ||
| 13 | + } | ||
| 14 | + | ||
| 15 | + public static void register(IMReconnectCallback subscriber) { | ||
| 16 | + if (EventBus.getDefault().isRegistered(subscriber)) return; | ||
| 17 | + EventBus.getDefault().register(subscriber); | ||
| 18 | + } | ||
| 19 | + | ||
| 20 | + public static void unregister(IMReconnectCallback subscriber) { | ||
| 21 | + EventBus.getDefault().unregister(subscriber); | ||
| 22 | + } | ||
| 23 | + | ||
| 24 | + public static void reconnect() { | ||
| 25 | + EventBus.getDefault().post(new IMConnectState()); | ||
| 26 | + } | ||
| 27 | +} |
cloud/wjj_lib/src/main/java/com/cnlive/libs/base/recevier/NetworkChangeReceive.java
0 → 100644
| 1 | +package com.cnlive.libs.base.recevier; | ||
| 2 | + | ||
| 3 | +import android.content.Context; | ||
| 4 | +import android.net.ConnectivityManager; | ||
| 5 | +import android.net.NetworkInfo; | ||
| 6 | + | ||
| 7 | + | ||
| 8 | +import com.github.pwittchen.reactivenetwork.library.rx2.Connectivity; | ||
| 9 | +import com.github.pwittchen.reactivenetwork.library.rx2.ReactiveNetwork; | ||
| 10 | + | ||
| 11 | +import org.greenrobot.eventbus.EventBus; | ||
| 12 | + | ||
| 13 | +import io.reactivex.android.schedulers.AndroidSchedulers; | ||
| 14 | +import io.reactivex.disposables.Disposable; | ||
| 15 | +import io.reactivex.schedulers.Schedulers; | ||
| 16 | + | ||
| 17 | + | ||
| 18 | +/** | ||
| 19 | + * Created by gujun on 2017/6/23. | ||
| 20 | + */ | ||
| 21 | + | ||
| 22 | +public class NetworkChangeReceive { | ||
| 23 | + | ||
| 24 | + private static Disposable disposable; | ||
| 25 | + | ||
| 26 | + | ||
| 27 | + public interface NetworkChangeCallback { | ||
| 28 | + void onNetworkChangeEvent(Connectivity connectivity); | ||
| 29 | + } | ||
| 30 | + | ||
| 31 | + public static void register(NetworkChangeCallback subscriber) { | ||
| 32 | + if (EventBus.getDefault().isRegistered(subscriber)) return; | ||
| 33 | + EventBus.getDefault().register(subscriber); | ||
| 34 | + } | ||
| 35 | + | ||
| 36 | + public static void unregister(NetworkChangeCallback subscriber) { | ||
| 37 | + EventBus.getDefault().unregister(subscriber); | ||
| 38 | + } | ||
| 39 | + | ||
| 40 | + /** | ||
| 41 | + * 启用网络通知 | ||
| 42 | + * | ||
| 43 | + * @param context 上下文 | ||
| 44 | + */ | ||
| 45 | + public static void enabled(Context context) { | ||
| 46 | + if (disposable == null) | ||
| 47 | + disposable = ReactiveNetwork.observeNetworkConnectivity(context) | ||
| 48 | + .subscribeOn(Schedulers.io()) | ||
| 49 | + .observeOn(AndroidSchedulers.mainThread()) | ||
| 50 | + .subscribe(connectivity -> EventBus.getDefault().post(connectivity)); | ||
| 51 | + } | ||
| 52 | + | ||
| 53 | + /** | ||
| 54 | + * 禁用网络通知 | ||
| 55 | + */ | ||
| 56 | + public static void disabled() { | ||
| 57 | + if (disposable != null) { | ||
| 58 | + disposable.dispose(); | ||
| 59 | + disposable = null; | ||
| 60 | + } | ||
| 61 | + } | ||
| 62 | + | ||
| 63 | + public static boolean isNetworkConnect(Context context) { | ||
| 64 | + if(context == null) return true; | ||
| 65 | + //判断是否有网络连接 | ||
| 66 | + ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); | ||
| 67 | + NetworkInfo mobileInfo = manager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE); | ||
| 68 | + NetworkInfo wifiInfo = manager.getNetworkInfo(ConnectivityManager.TYPE_WIFI); | ||
| 69 | + | ||
| 70 | + if (mobileInfo != null && mobileInfo.isConnected()) { | ||
| 71 | + return true; | ||
| 72 | + } else if (wifiInfo != null && wifiInfo.isConnected()) { | ||
| 73 | + return true; | ||
| 74 | + } else { | ||
| 75 | + return false; | ||
| 76 | + } | ||
| 77 | + } | ||
| 78 | + | ||
| 79 | +} |
cloud/wjj_lib/src/main/java/com/cnlive/libs/base/util/AlertUtil.java
0 → 100644
| 1 | +package com.cnlive.libs.base.util; | ||
| 2 | + | ||
| 3 | +import android.content.Context; | ||
| 4 | +import android.view.Gravity; | ||
| 5 | + | ||
| 6 | +import com.cnlive.libs.base.R; | ||
| 7 | + | ||
| 8 | +/** | ||
| 9 | + * Created by xiansong on 2017/9/11. | ||
| 10 | + */ | ||
| 11 | + | ||
| 12 | +public class AlertUtil { | ||
| 13 | + /** | ||
| 14 | + * 声明全局ToastUtil.Build对象 | ||
| 15 | + * 通过.build()获得ToastUtil对象 | ||
| 16 | + */ | ||
| 17 | + private static final ToastUtil.Build mainToast = ToastUtil.newBuild() | ||
| 18 | + //对齐参数设置 | ||
| 19 | + .setGravity(Gravity.CENTER, 0, 0) | ||
| 20 | + //设置布局 Layout Id 文本视图 View Id | ||
| 21 | + .setView(R.layout.layout_toast_1, R.id.text); | ||
| 22 | + | ||
| 23 | + public static void showDeftToast(Context context, int messageRes) { | ||
| 24 | + mainToast.build(context).showToast(context.getString(messageRes)); | ||
| 25 | + } | ||
| 26 | + | ||
| 27 | + public static void showDeftToast(Context context, String message) { | ||
| 28 | + mainToast.build(context).showToast(message); | ||
| 29 | + } | ||
| 30 | + | ||
| 31 | + public static void showLongToast(Context context, String message,int duration){ | ||
| 32 | + mainToast.build(context).showToast(message,duration); | ||
| 33 | + } | ||
| 34 | + | ||
| 35 | + /** | ||
| 36 | + * 成功的提示 | ||
| 37 | + * | ||
| 38 | + * @param context | ||
| 39 | + * @param message | ||
| 40 | + */ | ||
| 41 | + public static void showSuccessToast(Context context, String message) { | ||
| 42 | + ToastUtil.Build successToast = ToastUtil.newBuild() | ||
| 43 | + //对齐参数设置 | ||
| 44 | + .setGravity(Gravity.CENTER, 0, 0) | ||
| 45 | + //设置布局 Layout Id 文本视图 View Id | ||
| 46 | + .setView(R.layout.layout_toast_success, R.id.text); | ||
| 47 | + successToast.build(context).showToast(message); | ||
| 48 | + } | ||
| 49 | + | ||
| 50 | + /** | ||
| 51 | + * 失败的提示 | ||
| 52 | + * | ||
| 53 | + * @param context | ||
| 54 | + * @param message | ||
| 55 | + */ | ||
| 56 | + public static void showFailedToast(Context context, String message) { | ||
| 57 | + ToastUtil.Build failedToast = ToastUtil.newBuild() | ||
| 58 | + .setGravity(Gravity.CENTER, 0, 0) | ||
| 59 | + .setView(R.layout.layout_toast_failed, R.id.text); | ||
| 60 | + failedToast.build(context).showToast(message); | ||
| 61 | + } | ||
| 62 | + | ||
| 63 | + /** | ||
| 64 | + * 不比较吐司内容是否相同提示 | ||
| 65 | + * | ||
| 66 | + * @param context | ||
| 67 | + * @param message | ||
| 68 | + */ | ||
| 69 | + public static void showNoEqulesToast(Context context, String message) { | ||
| 70 | + ToastUtil.Build failedToast = ToastUtil.newBuild() | ||
| 71 | + .setGravity(Gravity.CENTER, 0, 0) | ||
| 72 | + .setView(R.layout.layout_toast_1, R.id.text); | ||
| 73 | + failedToast.build(context).showNoEqulesToast(message); | ||
| 74 | + } | ||
| 75 | +} |
cloud/wjj_lib/src/main/java/com/cnlive/libs/base/util/AppProbeUtil.java
0 → 100644
| 1 | +package com.cnlive.libs.base.util; | ||
| 2 | + | ||
| 3 | +import android.content.Context; | ||
| 4 | +import android.net.Uri; | ||
| 5 | +import android.text.TextUtils; | ||
| 6 | +import android.util.Log; | ||
| 7 | + | ||
| 8 | +import com.cnlive.libs.base.application.AppConfig; | ||
| 9 | + | ||
| 10 | +import java.lang.reflect.Method; | ||
| 11 | + | ||
| 12 | +/** | ||
| 13 | + * 统计已经迁移到新的module | ||
| 14 | + */ | ||
| 15 | +@Deprecated | ||
| 16 | +public class AppProbeUtil { | ||
| 17 | + private static String COUNT_TYPE = "type__count"; | ||
| 18 | + private static String DURATION_TYPE = "type__duration"; | ||
| 19 | + private static String SHARE_TYPE = "type__share"; | ||
| 20 | + private static String CHANNEL = "-channel__";//频道 | ||
| 21 | + private static String SID = "-sid__";//用户id | ||
| 22 | + private static String UID = "-uid__";//uuid | ||
| 23 | + private static String PID = "-pid__";//节目id | ||
| 24 | + private static String TITLE = "-title__";//节目名 | ||
| 25 | + private static String TO = "-to__";//分享到哪 | ||
| 26 | + private static String DATA = "-data_"; | ||
| 27 | + | ||
| 28 | + public static String TYPE_WJJ_FRIEND = "wjj_friend"; | ||
| 29 | + public static String TYPE_WJJ_MOMENT = "wjj_moment"; | ||
| 30 | + public static String TYPE_WX_FRIEND = "wx_friend"; | ||
| 31 | + public static String TYPE_WX_MOMENT = "wx_moment"; | ||
| 32 | + public static String TYPE_QQ_FRIEND = "qq_friend"; | ||
| 33 | + public static String TYPE_BROWSER = "browser"; | ||
| 34 | + | ||
| 35 | + public static String DAREN_HOME = "daren"; | ||
| 36 | + public static String APP = "app"; | ||
| 37 | + | ||
| 38 | + private static String shareEventIdBase; | ||
| 39 | + | ||
| 40 | + @Deprecated | ||
| 41 | + public static void Probe_ContentTimes(Context context, String type, String sid, String contentId, String title) { | ||
| 42 | + if (TextUtils.isEmpty(type)) | ||
| 43 | + return; | ||
| 44 | + String eventId = COUNT_TYPE.concat(CHANNEL).concat(type).concat(SID).concat(sid == null ? "" : sid).concat(UID).concat(AppConfig.getAppUUID()).concat(PID).concat(TextUtils.isEmpty(contentId) ? "" : contentId).concat(TITLE).concat(Uri.encode(TextUtils.isEmpty(title) ? "" : title)).concat(DATA); | ||
| 45 | + onEvent(context, eventId); | ||
| 46 | + } | ||
| 47 | + | ||
| 48 | + @Deprecated | ||
| 49 | + public static void Probe_ContentDuration(Context context, String type, String sid, String contentId, String title, boolean start) { | ||
| 50 | + if (TextUtils.isEmpty(type)) | ||
| 51 | + return; | ||
| 52 | + String eventId = DURATION_TYPE.concat(CHANNEL).concat(type).concat(SID).concat(sid == null ? "" : sid).concat(UID).concat(AppConfig.getAppUUID()).concat(PID).concat(TextUtils.isEmpty(contentId) ? "" : contentId).concat(TITLE).concat(Uri.encode(TextUtils.isEmpty(title) ? "" : title)).concat(DATA); | ||
| 53 | + if (start) { | ||
| 54 | + onEventBegin(eventId); | ||
| 55 | + } else { | ||
| 56 | + onEventEnd(context, eventId); | ||
| 57 | + } | ||
| 58 | + } | ||
| 59 | + | ||
| 60 | + @Deprecated | ||
| 61 | + public static void Probe_ShareTimes(Context context, String type, String sid, String contentId, String title) { | ||
| 62 | + if (TextUtils.isEmpty(type)) | ||
| 63 | + return; | ||
| 64 | + String eventIdBaseId = SHARE_TYPE.concat(CHANNEL).concat(type).concat(SID).concat(sid == null ? "" : sid).concat(UID).concat(AppConfig.getAppUUID()).concat(PID).concat(TextUtils.isEmpty(contentId) ? "" : contentId).concat(TITLE).concat(Uri.encode(TextUtils.isEmpty(title) ? "" : title)); | ||
| 65 | + setShareEventIdBase(eventIdBaseId); | ||
| 66 | + } | ||
| 67 | + | ||
| 68 | + @Deprecated | ||
| 69 | + public static void Probe_ShareTimes_To(Context context, String toType) { | ||
| 70 | + if (TextUtils.isEmpty(getShareEventIdBase())) | ||
| 71 | + return; | ||
| 72 | + String eventId = getShareEventIdBase().concat(TO).concat(TextUtils.isEmpty(toType) ? "" : toType).concat(DATA); | ||
| 73 | + onEvent(context, eventId); | ||
| 74 | + } | ||
| 75 | + | ||
| 76 | + private static void onEvent(Context context, String eventId) { | ||
| 77 | + try { | ||
| 78 | + Class<?> clazz = Class.forName("com.cnlive.libs.base.analytics.CNLiveProbe"); | ||
| 79 | + Method method = clazz.getMethod("onEvent", Context.class, String.class); | ||
| 80 | + method.invoke(clazz, context, eventId); | ||
| 81 | + } catch (Exception ex) { | ||
| 82 | + Log.d("DebugEvent", "", ex); | ||
| 83 | + } | ||
| 84 | + } | ||
| 85 | + | ||
| 86 | + private static void onEventBegin(String eventId) { | ||
| 87 | + try { | ||
| 88 | + Class<?> clazz = Class.forName("com.cnlive.libs.base.analytics.CNLiveProbe"); | ||
| 89 | + Method method = clazz.getMethod("onEventBegin", String.class); | ||
| 90 | + method.invoke(clazz, eventId); | ||
| 91 | + } catch (Exception ex) { | ||
| 92 | + Log.d("DebugEvent", "", ex); | ||
| 93 | + } | ||
| 94 | + } | ||
| 95 | + | ||
| 96 | + private static void onEventEnd(Context context, String eventId) { | ||
| 97 | + try { | ||
| 98 | + Class<?> clazz = Class.forName("com.cnlive.libs.base.analytics.CNLiveProbe"); | ||
| 99 | + Method method = clazz.getMethod("onEventEnd", Context.class, String.class); | ||
| 100 | + method.invoke(clazz, context, eventId); | ||
| 101 | + } catch (Exception ex) { | ||
| 102 | + Log.d("DebugEvent", "", ex); | ||
| 103 | + } | ||
| 104 | + } | ||
| 105 | + | ||
| 106 | + | ||
| 107 | + private static void setShareEventIdBase(String eventIdBase) { | ||
| 108 | + AppProbeUtil.shareEventIdBase = eventIdBase; | ||
| 109 | + } | ||
| 110 | + | ||
| 111 | + private static String getShareEventIdBase() { | ||
| 112 | + return shareEventIdBase; | ||
| 113 | + } | ||
| 114 | +} |
cloud/wjj_lib/src/main/java/com/cnlive/libs/base/util/AppUtil.java
0 → 100644
| 1 | +package com.cnlive.libs.base.util; | ||
| 2 | + | ||
| 3 | +import android.app.Activity; | ||
| 4 | +import android.app.ActivityManager; | ||
| 5 | +import android.content.ComponentName; | ||
| 6 | +import android.content.Context; | ||
| 7 | +import android.content.pm.ApplicationInfo; | ||
| 8 | +import android.content.pm.PackageInfo; | ||
| 9 | +import android.content.pm.PackageManager; | ||
| 10 | +import android.text.TextUtils; | ||
| 11 | +import android.util.Log; | ||
| 12 | + | ||
| 13 | +import java.util.List; | ||
| 14 | + | ||
| 15 | +/** | ||
| 16 | + * Created by gujun on 2017/10/9. | ||
| 17 | + */ | ||
| 18 | + | ||
| 19 | +public class AppUtil { | ||
| 20 | + | ||
| 21 | + private static final String TAG = "vlion AppUtil"; | ||
| 22 | + | ||
| 23 | + /** | ||
| 24 | + * 判断某个界面是否在前台 | ||
| 25 | + * | ||
| 26 | + * @param activity 要判断的Activity | ||
| 27 | + * @return 是否在前台显示 | ||
| 28 | + */ | ||
| 29 | + public static boolean isForeground(Activity activity) { | ||
| 30 | + return isForeground(activity, activity.getClass().getName()); | ||
| 31 | + } | ||
| 32 | + | ||
| 33 | + /** | ||
| 34 | + * 判断某个界面是否在前台 | ||
| 35 | + * | ||
| 36 | + * @param context Context | ||
| 37 | + * @param className 界面的类名 | ||
| 38 | + * @return 是否在前台显示 | ||
| 39 | + */ | ||
| 40 | + public static boolean isForeground(Context context, String className) { | ||
| 41 | + if (context == null || TextUtils.isEmpty(className)) | ||
| 42 | + return false; | ||
| 43 | + ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); | ||
| 44 | + List<ActivityManager.RunningTaskInfo> list = am.getRunningTasks(1); | ||
| 45 | + if (list != null && list.size() > 0) { | ||
| 46 | + ComponentName cpn = list.get(0).topActivity; | ||
| 47 | + if (className.equals(cpn.getClassName())) | ||
| 48 | + return true; | ||
| 49 | + } | ||
| 50 | + return false; | ||
| 51 | + } | ||
| 52 | + | ||
| 53 | + /** | ||
| 54 | + * 获取包名 | ||
| 55 | + * | ||
| 56 | + * @param context | ||
| 57 | + * @return | ||
| 58 | + */ | ||
| 59 | + public static String getPackageName(Context context) { | ||
| 60 | + return context.getPackageName(); | ||
| 61 | + } | ||
| 62 | + | ||
| 63 | + /** | ||
| 64 | + * get App versionName | ||
| 65 | + * | ||
| 66 | + * @param context | ||
| 67 | + * @return | ||
| 68 | + */ | ||
| 69 | + public static String getVersionName(Context context) { | ||
| 70 | + PackageManager packageManager = context.getPackageManager(); | ||
| 71 | + PackageInfo packageInfo; | ||
| 72 | + String versionName = ""; | ||
| 73 | + try { | ||
| 74 | + packageInfo = packageManager.getPackageInfo(context.getPackageName(), 0); | ||
| 75 | + versionName = packageInfo.versionName; | ||
| 76 | + } catch (PackageManager.NameNotFoundException e) { | ||
| 77 | + e.printStackTrace(); | ||
| 78 | + } | ||
| 79 | + if (TextUtils.isEmpty(versionName)) { | ||
| 80 | + Log.e(TAG, "getVersionNameError: version name is null"); | ||
| 81 | + } | ||
| 82 | + return versionName; | ||
| 83 | + } | ||
| 84 | + | ||
| 85 | + /** | ||
| 86 | + * 判断当前应用是否是debug状态 | ||
| 87 | + */ | ||
| 88 | + public static boolean isApkInDebug(Context context) { | ||
| 89 | + try { | ||
| 90 | + ApplicationInfo info = context.getApplicationInfo(); | ||
| 91 | + return (info.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0; | ||
| 92 | + } catch (Exception e) { | ||
| 93 | + return false; | ||
| 94 | + } | ||
| 95 | + } | ||
| 96 | + | ||
| 97 | + | ||
| 98 | + | ||
| 99 | + /** | ||
| 100 | + * get App versionName | ||
| 101 | + * | ||
| 102 | + * @param context | ||
| 103 | + * @return | ||
| 104 | + */ | ||
| 105 | + public static int getVersionCode(Context context) { | ||
| 106 | + PackageManager packageManager = context.getPackageManager(); | ||
| 107 | + PackageInfo packageInfo; | ||
| 108 | + int versionCode =-1; | ||
| 109 | + try { | ||
| 110 | + packageInfo = packageManager.getPackageInfo(context.getPackageName(), 0); | ||
| 111 | + versionCode = packageInfo.versionCode; | ||
| 112 | + } catch (PackageManager.NameNotFoundException e) { | ||
| 113 | + e.printStackTrace(); | ||
| 114 | + } | ||
| 115 | + | ||
| 116 | + return versionCode; | ||
| 117 | + } | ||
| 118 | +} |
cloud/wjj_lib/src/main/java/com/cnlive/libs/base/util/BaseActivityLifecycle.java
0 → 100644
| 1 | +package com.cnlive.libs.base.util; | ||
| 2 | + | ||
| 3 | +import android.app.Activity; | ||
| 4 | +import android.app.Application; | ||
| 5 | +import android.os.Bundle; | ||
| 6 | + | ||
| 7 | +public class BaseActivityLifecycle implements Application.ActivityLifecycleCallbacks { | ||
| 8 | + | ||
| 9 | + private static boolean active = false; | ||
| 10 | + private static int activeCount;//activity的count数 | ||
| 11 | + private static int numRunning; | ||
| 12 | + private static String currentActivityName; | ||
| 13 | + | ||
| 14 | + @Override | ||
| 15 | + public void onActivityCreated(Activity activity, Bundle savedInstanceState) { | ||
| 16 | + currentActivityName = activity.getClass().getName(); | ||
| 17 | + numRunning++; | ||
| 18 | + } | ||
| 19 | + | ||
| 20 | + @Override | ||
| 21 | + public void onActivityStarted(Activity activity) { | ||
| 22 | + currentActivityName = activity.getClass().getName(); | ||
| 23 | + activeCount++; | ||
| 24 | + if (!active) { | ||
| 25 | + active = true; | ||
| 26 | + } | ||
| 27 | + } | ||
| 28 | + | ||
| 29 | + @Override | ||
| 30 | + public void onActivityResumed(Activity activity) { | ||
| 31 | + currentActivityName = activity.getClass().getName(); | ||
| 32 | + } | ||
| 33 | + | ||
| 34 | + @Override | ||
| 35 | + public void onActivityPaused(Activity activity) { | ||
| 36 | +// currentActivity = activity; | ||
| 37 | + } | ||
| 38 | + | ||
| 39 | + @Override | ||
| 40 | + public void onActivityStopped(Activity activity) { | ||
| 41 | + activeCount--; | ||
| 42 | + if (activeCount == 0 && active) { | ||
| 43 | + active = false; | ||
| 44 | + } | ||
| 45 | +// AnalyticsUtil.appOnStop(activity); | ||
| 46 | + } | ||
| 47 | + | ||
| 48 | + @Override | ||
| 49 | + public void onActivitySaveInstanceState(Activity activity, Bundle outState) { | ||
| 50 | + } | ||
| 51 | + | ||
| 52 | + @Override | ||
| 53 | + public void onActivityDestroyed(Activity activity) { | ||
| 54 | +// currentActivity = activity; | ||
| 55 | + numRunning--; | ||
| 56 | + } | ||
| 57 | + | ||
| 58 | + public static int getNumRunning() { | ||
| 59 | + return numRunning; | ||
| 60 | + } | ||
| 61 | + | ||
| 62 | + public static boolean isActive() { | ||
| 63 | + return active; | ||
| 64 | + } | ||
| 65 | + | ||
| 66 | + public static String getCurrentActivityName() { | ||
| 67 | + return currentActivityName; | ||
| 68 | + } | ||
| 69 | + | ||
| 70 | +} | ||
| 0 | \ No newline at end of file | 71 | \ No newline at end of file |
cloud/wjj_lib/src/main/java/com/cnlive/libs/base/util/ChannelUtil.java
0 → 100644
| 1 | +package com.cnlive.libs.base.util; | ||
| 2 | + | ||
| 3 | +import android.content.Context; | ||
| 4 | +import android.content.pm.ApplicationInfo; | ||
| 5 | +import android.content.pm.PackageManager; | ||
| 6 | +import android.text.TextUtils; | ||
| 7 | +import android.util.Log; | ||
| 8 | + | ||
| 9 | +import com.cnlive.libs.base.application.AppConfig; | ||
| 10 | + | ||
| 11 | +/** | ||
| 12 | + * Created by xiansong on 2014/12/26. | ||
| 13 | + */ | ||
| 14 | +public class ChannelUtil { | ||
| 15 | + | ||
| 16 | + public static void setChannel(Context context, String channel) { | ||
| 17 | + if (TextUtils.isEmpty(channel)) return; | ||
| 18 | + try { | ||
| 19 | + SharedPreferencesHelper.getInstance(context).setValue("UMENG_CHANNEL", channel); | ||
| 20 | + } catch (Exception ignored) { | ||
| 21 | + } | ||
| 22 | + } | ||
| 23 | + | ||
| 24 | + public static String getChannelFromApk(Context context) { | ||
| 25 | + String channel = ""; | ||
| 26 | + String defaultChannel = AppConfig.isDebug() ? "debug" : "release"; | ||
| 27 | + | ||
| 28 | + try { | ||
| 29 | + SharedPreferencesHelper sp = SharedPreferencesHelper.getInstance(context); | ||
| 30 | + String channel_sp = sp.getValue("UMENG_CHANNEL"); | ||
| 31 | + | ||
| 32 | + if (!TextUtils.isEmpty(channel_sp)) return channel_sp; | ||
| 33 | + } catch (Exception e) { | ||
| 34 | + Log.e("ChannelUtil", "", e); | ||
| 35 | + } | ||
| 36 | + | ||
| 37 | + try { | ||
| 38 | + ApplicationInfo appInfo = context.getPackageManager().getApplicationInfo(context.getPackageName(), PackageManager.GET_META_DATA); | ||
| 39 | + channel = appInfo.metaData.getString("UMENG_CHANNEL"); | ||
| 40 | + } catch (Exception e) { | ||
| 41 | + Log.e("ChannelUtil", "", e); | ||
| 42 | + } | ||
| 43 | + | ||
| 44 | + channel = TextUtils.isEmpty(channel) ? defaultChannel : channel; | ||
| 45 | + Log.e("ChannelUtil", channel); | ||
| 46 | + return channel; | ||
| 47 | + } | ||
| 48 | +} |
cloud/wjj_lib/src/main/java/com/cnlive/libs/base/util/DoublePressed.java
0 → 100644
| 1 | +package com.cnlive.libs.base.util; | ||
| 2 | + | ||
| 3 | +public class DoublePressed { | ||
| 4 | + private static long time_pressed; | ||
| 5 | + private static long upload_time; | ||
| 6 | + | ||
| 7 | + /** | ||
| 8 | + * 连续点击处理 | ||
| 9 | + * | ||
| 10 | + * @return | ||
| 11 | + */ | ||
| 12 | + public static boolean onDoublePressed() { | ||
| 13 | + return onDoublePressed(false, 2000L); | ||
| 14 | + } | ||
| 15 | + | ||
| 16 | + public static boolean onLongDoublePressed() { | ||
| 17 | + return onDoublePressed(true, 2000L); | ||
| 18 | + } | ||
| 19 | + | ||
| 20 | + public static boolean onDoublePressed(boolean isLong, long time) { | ||
| 21 | + long timeMillis = System.currentTimeMillis(); | ||
| 22 | + boolean doublePressed = time_pressed + time > timeMillis; | ||
| 23 | + | ||
| 24 | + if (isLong) { | ||
| 25 | + time_pressed = timeMillis; | ||
| 26 | + } else if (upload_time < timeMillis) { | ||
| 27 | + upload_time = timeMillis + time; | ||
| 28 | + time_pressed = timeMillis; | ||
| 29 | + } | ||
| 30 | + | ||
| 31 | + return doublePressed; | ||
| 32 | + } | ||
| 33 | + | ||
| 34 | + public static void onRestart() { | ||
| 35 | + time_pressed = 0; | ||
| 36 | + upload_time = 0; | ||
| 37 | + } | ||
| 38 | +} |
cloud/wjj_lib/src/main/java/com/cnlive/libs/base/util/FileUtils.java
0 → 100644
| 1 | +package com.cnlive.libs.base.util; | ||
| 2 | + | ||
| 3 | +import android.content.Context; | ||
| 4 | +import android.os.Environment; | ||
| 5 | + | ||
| 6 | +import java.io.BufferedInputStream; | ||
| 7 | +import java.io.BufferedOutputStream; | ||
| 8 | +import java.io.File; | ||
| 9 | +import java.io.FileFilter; | ||
| 10 | +import java.io.FileInputStream; | ||
| 11 | +import java.io.FileNotFoundException; | ||
| 12 | +import java.io.FileOutputStream; | ||
| 13 | +import java.io.IOException; | ||
| 14 | +import java.io.InputStream; | ||
| 15 | +import java.io.OutputStream; | ||
| 16 | +import java.net.HttpURLConnection; | ||
| 17 | +import java.net.URL; | ||
| 18 | +import java.security.DigestInputStream; | ||
| 19 | +import java.security.MessageDigest; | ||
| 20 | +import java.security.NoSuchAlgorithmException; | ||
| 21 | +import java.util.ArrayList; | ||
| 22 | +import java.util.List; | ||
| 23 | +import java.util.Locale; | ||
| 24 | +/** | ||
| 25 | + * 作者: 吴奎庆 | ||
| 26 | + * <p> | ||
| 27 | + * 时间: 2018/9/11 | ||
| 28 | + * <p> | ||
| 29 | + * 简介: | ||
| 30 | + */ | ||
| 31 | + | ||
| 32 | +public class FileUtils { | ||
| 33 | + | ||
| 34 | + private static final String LINE_SEP = System.getProperty("line.separator"); | ||
| 35 | + | ||
| 36 | + private FileUtils() { | ||
| 37 | + throw new UnsupportedOperationException("u can't instantiate me..."); | ||
| 38 | + } | ||
| 39 | + | ||
| 40 | + /** | ||
| 41 | + * Return the file by path. | ||
| 42 | + * | ||
| 43 | + * @param filePath The path of file. | ||
| 44 | + * @return the file | ||
| 45 | + */ | ||
| 46 | + public static File getFileByPath(final String filePath) { | ||
| 47 | + return isSpace(filePath) ? null : new File(filePath); | ||
| 48 | + } | ||
| 49 | + | ||
| 50 | + /** | ||
| 51 | + * Return whether the file exists. | ||
| 52 | + * | ||
| 53 | + * @param filePath The path of file. | ||
| 54 | + * @return {@code true}: yes<br>{@code false}: no | ||
| 55 | + */ | ||
| 56 | + public static boolean isFileExists(final String filePath) { | ||
| 57 | + return isFileExists(getFileByPath(filePath)); | ||
| 58 | + } | ||
| 59 | + | ||
| 60 | + /** | ||
| 61 | + * Return whether the file exists. | ||
| 62 | + * | ||
| 63 | + * @param file The file. | ||
| 64 | + * @return {@code true}: yes<br>{@code false}: no | ||
| 65 | + */ | ||
| 66 | + public static boolean isFileExists(final File file) { | ||
| 67 | + return file != null && file.exists(); | ||
| 68 | + } | ||
| 69 | + | ||
| 70 | + /** | ||
| 71 | + * Rename the file. | ||
| 72 | + * | ||
| 73 | + * @param filePath The path of file. | ||
| 74 | + * @param newName The new name of file. | ||
| 75 | + * @return {@code true}: success<br>{@code false}: fail | ||
| 76 | + */ | ||
| 77 | + public static boolean rename(final String filePath, final String newName) { | ||
| 78 | + return rename(getFileByPath(filePath), newName); | ||
| 79 | + } | ||
| 80 | + | ||
| 81 | + /** | ||
| 82 | + * Rename the file. | ||
| 83 | + * | ||
| 84 | + * @param file The file. | ||
| 85 | + * @param newName The new name of file. | ||
| 86 | + * @return {@code true}: success<br>{@code false}: fail | ||
| 87 | + */ | ||
| 88 | + public static boolean rename(final File file, final String newName) { | ||
| 89 | + // file is null then return false | ||
| 90 | + if (file == null) return false; | ||
| 91 | + // file doesn't exist then return false | ||
| 92 | + if (!file.exists()) return false; | ||
| 93 | + // the new name is space then return false | ||
| 94 | + if (isSpace(newName)) return false; | ||
| 95 | + // the new name equals old name then return true | ||
| 96 | + if (newName.equals(file.getName())) return true; | ||
| 97 | + File newFile = new File(file.getParent() + File.separator + newName); | ||
| 98 | + // the new name of file exists then return false | ||
| 99 | + return !newFile.exists() | ||
| 100 | + && file.renameTo(newFile); | ||
| 101 | + } | ||
| 102 | + | ||
| 103 | + /** | ||
| 104 | + * Return whether it is a directory. | ||
| 105 | + * | ||
| 106 | + * @param dirPath The path of directory. | ||
| 107 | + * @return {@code true}: yes<br>{@code false}: no | ||
| 108 | + */ | ||
| 109 | + public static boolean isDir(final String dirPath) { | ||
| 110 | + return isDir(getFileByPath(dirPath)); | ||
| 111 | + } | ||
| 112 | + | ||
| 113 | + /** | ||
| 114 | + * Return whether it is a directory. | ||
| 115 | + * | ||
| 116 | + * @param file The file. | ||
| 117 | + * @return {@code true}: yes<br>{@code false}: no | ||
| 118 | + */ | ||
| 119 | + public static boolean isDir(final File file) { | ||
| 120 | + return file != null && file.exists() && file.isDirectory(); | ||
| 121 | + } | ||
| 122 | + | ||
| 123 | + /** | ||
| 124 | + * Return whether it is a file. | ||
| 125 | + * | ||
| 126 | + * @param filePath The path of file. | ||
| 127 | + * @return {@code true}: yes<br>{@code false}: no | ||
| 128 | + */ | ||
| 129 | + public static boolean isFile(final String filePath) { | ||
| 130 | + return isFile(getFileByPath(filePath)); | ||
| 131 | + } | ||
| 132 | + | ||
| 133 | + /** | ||
| 134 | + * Return whether it is a file. | ||
| 135 | + * | ||
| 136 | + * @param file The file. | ||
| 137 | + * @return {@code true}: yes<br>{@code false}: no | ||
| 138 | + */ | ||
| 139 | + public static boolean isFile(final File file) { | ||
| 140 | + return file != null && file.exists() && file.isFile(); | ||
| 141 | + } | ||
| 142 | + | ||
| 143 | + /** | ||
| 144 | + * Create a directory if it doesn't exist, otherwise do nothing. | ||
| 145 | + * 如果不存在创建文件夹 存在就不处理 | ||
| 146 | + * @param dirPath The path of directory. | ||
| 147 | + * @return {@code true}: exists or creates successfully<br>{@code false}: otherwise | ||
| 148 | + */ | ||
| 149 | + public static boolean createOrExistsDir(final String dirPath) { | ||
| 150 | + return createOrExistsDir(getFileByPath(dirPath)); | ||
| 151 | + } | ||
| 152 | + | ||
| 153 | + /** | ||
| 154 | + * Create a directory if it doesn't exist, otherwise do nothing. | ||
| 155 | + * | ||
| 156 | + * @param file The file. | ||
| 157 | + * @return {@code true}: exists or creates successfully<br>{@code false}: otherwise | ||
| 158 | + */ | ||
| 159 | + public static boolean createOrExistsDir(final File file) { | ||
| 160 | + return file != null && (file.exists() ? file.isDirectory() : file.mkdirs()); | ||
| 161 | + } | ||
| 162 | + | ||
| 163 | + /** | ||
| 164 | + * Create a file if it doesn't exist, otherwise do nothing. | ||
| 165 | + * | ||
| 166 | + * @param filePath The path of file. | ||
| 167 | + * @return {@code true}: exists or creates successfully<br>{@code false}: otherwise | ||
| 168 | + */ | ||
| 169 | + public static boolean createOrExistsFile(final String filePath) { | ||
| 170 | + return createOrExistsFile(getFileByPath(filePath)); | ||
| 171 | + } | ||
| 172 | + | ||
| 173 | + /** | ||
| 174 | + * Create a file if it doesn't exist, otherwise do nothing. | ||
| 175 | + * | ||
| 176 | + * @param file The file. | ||
| 177 | + * @return {@code true}: exists or creates successfully<br>{@code false}: otherwise | ||
| 178 | + */ | ||
| 179 | + public static boolean createOrExistsFile(final File file) { | ||
| 180 | + if (file == null) return false; | ||
| 181 | + if (file.exists()) return file.isFile(); | ||
| 182 | + if (!createOrExistsDir(file.getParentFile())) return false; | ||
| 183 | + try { | ||
| 184 | + return file.createNewFile(); | ||
| 185 | + } catch (IOException e) { | ||
| 186 | + e.printStackTrace(); | ||
| 187 | + return false; | ||
| 188 | + } | ||
| 189 | + } | ||
| 190 | + | ||
| 191 | + /** | ||
| 192 | + * Create a file if it doesn't exist, otherwise delete old file before creating. | ||
| 193 | + * | ||
| 194 | + * @param filePath The path of file. | ||
| 195 | + * @return {@code true}: success<br>{@code false}: fail | ||
| 196 | + */ | ||
| 197 | + public static boolean createFileByDeleteOldFile(final String filePath) { | ||
| 198 | + return createFileByDeleteOldFile(getFileByPath(filePath)); | ||
| 199 | + } | ||
| 200 | + | ||
| 201 | + /** | ||
| 202 | + * Create a file if it doesn't exist, otherwise delete old file before creating. | ||
| 203 | + * | ||
| 204 | + * @param file The file. | ||
| 205 | + * @return {@code true}: success<br>{@code false}: fail | ||
| 206 | + */ | ||
| 207 | + public static boolean createFileByDeleteOldFile(final File file) { | ||
| 208 | + if (file == null) return false; | ||
| 209 | + // file exists and unsuccessfully delete then return false | ||
| 210 | + if (file.exists() && !file.delete()) return false; | ||
| 211 | + if (!createOrExistsDir(file.getParentFile())) return false; | ||
| 212 | + try { | ||
| 213 | + return file.createNewFile(); | ||
| 214 | + } catch (IOException e) { | ||
| 215 | + e.printStackTrace(); | ||
| 216 | + return false; | ||
| 217 | + } | ||
| 218 | + } | ||
| 219 | + | ||
| 220 | + /** | ||
| 221 | + * Copy the directory. | ||
| 222 | + * | ||
| 223 | + * @param srcDirPath The path of source directory. | ||
| 224 | + * @param destDirPath The path of destination directory. | ||
| 225 | + * @return {@code true}: success<br>{@code false}: fail | ||
| 226 | + */ | ||
| 227 | + public static boolean copyDir(final String srcDirPath, | ||
| 228 | + final String destDirPath) { | ||
| 229 | + return copyDir(getFileByPath(srcDirPath), getFileByPath(destDirPath)); | ||
| 230 | + } | ||
| 231 | + | ||
| 232 | + /** | ||
| 233 | + * Copy the directory. | ||
| 234 | + * | ||
| 235 | + * @param srcDirPath The path of source directory. | ||
| 236 | + * @param destDirPath The path of destination directory. | ||
| 237 | + * @param listener The replace listener. | ||
| 238 | + * @return {@code true}: success<br>{@code false}: fail | ||
| 239 | + */ | ||
| 240 | + public static boolean copyDir(final String srcDirPath, | ||
| 241 | + final String destDirPath, | ||
| 242 | + final OnReplaceListener listener) { | ||
| 243 | + return copyDir(getFileByPath(srcDirPath), getFileByPath(destDirPath), listener); | ||
| 244 | + } | ||
| 245 | + | ||
| 246 | + /** | ||
| 247 | + * Copy the directory. | ||
| 248 | + * | ||
| 249 | + * @param srcDir The source directory. | ||
| 250 | + * @param destDir The destination directory. | ||
| 251 | + * @return {@code true}: success<br>{@code false}: fail | ||
| 252 | + */ | ||
| 253 | + public static boolean copyDir(final File srcDir, | ||
| 254 | + final File destDir) { | ||
| 255 | + return copyOrMoveDir(srcDir, destDir, false); | ||
| 256 | + } | ||
| 257 | + | ||
| 258 | + /** | ||
| 259 | + * Copy the directory. | ||
| 260 | + * | ||
| 261 | + * @param srcDir The source directory. | ||
| 262 | + * @param destDir The destination directory. | ||
| 263 | + * @param listener The replace listener. | ||
| 264 | + * @return {@code true}: success<br>{@code false}: fail | ||
| 265 | + */ | ||
| 266 | + public static boolean copyDir(final File srcDir, | ||
| 267 | + final File destDir, | ||
| 268 | + final OnReplaceListener listener) { | ||
| 269 | + return copyOrMoveDir(srcDir, destDir, listener, false); | ||
| 270 | + } | ||
| 271 | + | ||
| 272 | + /** | ||
| 273 | + * Copy the file. | ||
| 274 | + * | ||
| 275 | + * @param srcFilePath The path of source file. | ||
| 276 | + * @param destFilePath The path of destination file. | ||
| 277 | + * @return {@code true}: success<br>{@code false}: fail | ||
| 278 | + */ | ||
| 279 | + public static boolean copyFile(final String srcFilePath, | ||
| 280 | + final String destFilePath) { | ||
| 281 | + return copyFile(getFileByPath(srcFilePath), getFileByPath(destFilePath)); | ||
| 282 | + } | ||
| 283 | + | ||
| 284 | + /** | ||
| 285 | + * Copy the file. | ||
| 286 | + * | ||
| 287 | + * @param srcFilePath The path of source file. | ||
| 288 | + * @param destFilePath The path of destination file. | ||
| 289 | + * @param listener The replace listener. | ||
| 290 | + * @return {@code true}: success<br>{@code false}: fail | ||
| 291 | + */ | ||
| 292 | + public static boolean copyFile(final String srcFilePath, | ||
| 293 | + final String destFilePath, | ||
| 294 | + final OnReplaceListener listener) { | ||
| 295 | + return copyFile(getFileByPath(srcFilePath), getFileByPath(destFilePath), listener); | ||
| 296 | + } | ||
| 297 | + | ||
| 298 | + /** | ||
| 299 | + * Copy the file. | ||
| 300 | + * | ||
| 301 | + * @param srcFile The source file. | ||
| 302 | + * @param destFile The destination file. | ||
| 303 | + * @return {@code true}: success<br>{@code false}: fail | ||
| 304 | + */ | ||
| 305 | + public static boolean copyFile(final File srcFile, | ||
| 306 | + final File destFile) { | ||
| 307 | + return copyOrMoveFile(srcFile, destFile, false); | ||
| 308 | + } | ||
| 309 | + | ||
| 310 | + | ||
| 311 | + public static File getSaveFile(Context context, String fileName) { | ||
| 312 | + File file = new File(context.getFilesDir(), fileName + ".jpg"); | ||
| 313 | + return file; | ||
| 314 | + } | ||
| 315 | + | ||
| 316 | + /** | ||
| 317 | + * Copy the file. | ||
| 318 | + * | ||
| 319 | + * @param srcFile The source file. | ||
| 320 | + * @param destFile The destination file. | ||
| 321 | + * @param listener The replace listener. | ||
| 322 | + * @return {@code true}: success<br>{@code false}: fail | ||
| 323 | + */ | ||
| 324 | + public static boolean copyFile(final File srcFile, | ||
| 325 | + final File destFile, | ||
| 326 | + final OnReplaceListener listener) { | ||
| 327 | + return copyOrMoveFile(srcFile, destFile, listener, false); | ||
| 328 | + } | ||
| 329 | + | ||
| 330 | + /** | ||
| 331 | + * Move the directory. | ||
| 332 | + * | ||
| 333 | + * @param srcDirPath The path of source directory. | ||
| 334 | + * @param destDirPath The path of destination directory. | ||
| 335 | + * @return {@code true}: success<br>{@code false}: fail | ||
| 336 | + */ | ||
| 337 | + public static boolean moveDir(final String srcDirPath, | ||
| 338 | + final String destDirPath) { | ||
| 339 | + return moveDir(getFileByPath(srcDirPath), getFileByPath(destDirPath)); | ||
| 340 | + } | ||
| 341 | + | ||
| 342 | + /** | ||
| 343 | + * Move the directory. | ||
| 344 | + * | ||
| 345 | + * @param srcDirPath The path of source directory. | ||
| 346 | + * @param destDirPath The path of destination directory. | ||
| 347 | + * @param listener The replace listener. | ||
| 348 | + * @return {@code true}: success<br>{@code false}: fail | ||
| 349 | + */ | ||
| 350 | + public static boolean moveDir(final String srcDirPath, | ||
| 351 | + final String destDirPath, | ||
| 352 | + final OnReplaceListener listener) { | ||
| 353 | + return moveDir(getFileByPath(srcDirPath), getFileByPath(destDirPath), listener); | ||
| 354 | + } | ||
| 355 | + | ||
| 356 | + /** | ||
| 357 | + * Move the directory. | ||
| 358 | + * | ||
| 359 | + * @param srcDir The source directory. | ||
| 360 | + * @param destDir The destination directory. | ||
| 361 | + * @return {@code true}: success<br>{@code false}: fail | ||
| 362 | + */ | ||
| 363 | + public static boolean moveDir(final File srcDir, | ||
| 364 | + final File destDir) { | ||
| 365 | + return copyOrMoveDir(srcDir, destDir, true); | ||
| 366 | + } | ||
| 367 | + | ||
| 368 | + /** | ||
| 369 | + * Move the directory. | ||
| 370 | + * | ||
| 371 | + * @param srcDir The source directory. | ||
| 372 | + * @param destDir The destination directory. | ||
| 373 | + * @param listener The replace listener. | ||
| 374 | + * @return {@code true}: success<br>{@code false}: fail | ||
| 375 | + */ | ||
| 376 | + public static boolean moveDir(final File srcDir, | ||
| 377 | + final File destDir, | ||
| 378 | + final OnReplaceListener listener) { | ||
| 379 | + return copyOrMoveDir(srcDir, destDir, listener, true); | ||
| 380 | + } | ||
| 381 | + | ||
| 382 | + /** | ||
| 383 | + * Move the file. | ||
| 384 | + * | ||
| 385 | + * @param srcFilePath The path of source file. | ||
| 386 | + * @param destFilePath The path of destination file. | ||
| 387 | + * @return {@code true}: success<br>{@code false}: fail | ||
| 388 | + */ | ||
| 389 | + public static boolean moveFile(final String srcFilePath, | ||
| 390 | + final String destFilePath) { | ||
| 391 | + return moveFile(getFileByPath(srcFilePath), getFileByPath(destFilePath)); | ||
| 392 | + } | ||
| 393 | + | ||
| 394 | + /** | ||
| 395 | + * Move the file. | ||
| 396 | + * | ||
| 397 | + * @param srcFilePath The path of source file. | ||
| 398 | + * @param destFilePath The path of destination file. | ||
| 399 | + * @param listener The replace listener. | ||
| 400 | + * @return {@code true}: success<br>{@code false}: fail | ||
| 401 | + */ | ||
| 402 | + public static boolean moveFile(final String srcFilePath, | ||
| 403 | + final String destFilePath, | ||
| 404 | + final OnReplaceListener listener) { | ||
| 405 | + return moveFile(getFileByPath(srcFilePath), getFileByPath(destFilePath), listener); | ||
| 406 | + } | ||
| 407 | + | ||
| 408 | + /** | ||
| 409 | + * Move the file. | ||
| 410 | + * | ||
| 411 | + * @param srcFile The source file. | ||
| 412 | + * @param destFile The destination file. | ||
| 413 | + * @return {@code true}: success<br>{@code false}: fail | ||
| 414 | + */ | ||
| 415 | + public static boolean moveFile(final File srcFile, | ||
| 416 | + final File destFile) { | ||
| 417 | + return copyOrMoveFile(srcFile, destFile, true); | ||
| 418 | + } | ||
| 419 | + | ||
| 420 | + /** | ||
| 421 | + * Move the file. | ||
| 422 | + * | ||
| 423 | + * @param srcFile The source file. | ||
| 424 | + * @param destFile The destination file. | ||
| 425 | + * @param listener The replace listener. | ||
| 426 | + * @return {@code true}: success<br>{@code false}: fail | ||
| 427 | + */ | ||
| 428 | + public static boolean moveFile(final File srcFile, | ||
| 429 | + final File destFile, | ||
| 430 | + final OnReplaceListener listener) { | ||
| 431 | + return copyOrMoveFile(srcFile, destFile, listener, true); | ||
| 432 | + } | ||
| 433 | + | ||
| 434 | + private static boolean copyOrMoveDir(final File srcDir, | ||
| 435 | + final File destDir, | ||
| 436 | + final boolean isMove) { | ||
| 437 | + return copyOrMoveDir(srcDir, destDir, new OnReplaceListener() { | ||
| 438 | + @Override | ||
| 439 | + public boolean onReplace() { | ||
| 440 | + return true; | ||
| 441 | + } | ||
| 442 | + }, isMove); | ||
| 443 | + } | ||
| 444 | + | ||
| 445 | + private static boolean copyOrMoveDir(final File srcDir, | ||
| 446 | + final File destDir, | ||
| 447 | + final OnReplaceListener listener, | ||
| 448 | + final boolean isMove) { | ||
| 449 | + if (srcDir == null || destDir == null) return false; | ||
| 450 | + // destDir's path locate in srcDir's path then return false | ||
| 451 | + String srcPath = srcDir.getPath() + File.separator; | ||
| 452 | + String destPath = destDir.getPath() + File.separator; | ||
| 453 | + if (destPath.contains(srcPath)) return false; | ||
| 454 | + if (!srcDir.exists() || !srcDir.isDirectory()) return false; | ||
| 455 | + if (destDir.exists()) { | ||
| 456 | + if (listener == null || listener.onReplace()) {// require delete the old directory | ||
| 457 | + if (!deleteAllInDir(destDir)) {// unsuccessfully delete then return false | ||
| 458 | + return false; | ||
| 459 | + } | ||
| 460 | + } else { | ||
| 461 | + return true; | ||
| 462 | + } | ||
| 463 | + } | ||
| 464 | + if (!createOrExistsDir(destDir)) return false; | ||
| 465 | + File[] files = srcDir.listFiles(); | ||
| 466 | + for (File file : files) { | ||
| 467 | + File oneDestFile = new File(destPath + file.getName()); | ||
| 468 | + if (file.isFile()) { | ||
| 469 | + if (!copyOrMoveFile(file, oneDestFile, listener, isMove)) return false; | ||
| 470 | + } else if (file.isDirectory()) { | ||
| 471 | + if (!copyOrMoveDir(file, oneDestFile, listener, isMove)) return false; | ||
| 472 | + } | ||
| 473 | + } | ||
| 474 | + return !isMove || deleteDir(srcDir); | ||
| 475 | + } | ||
| 476 | + | ||
| 477 | + private static boolean copyOrMoveFile(final File srcFile, | ||
| 478 | + final File destFile, | ||
| 479 | + final boolean isMove) { | ||
| 480 | + return copyOrMoveFile(srcFile, destFile, new OnReplaceListener() { | ||
| 481 | + @Override | ||
| 482 | + public boolean onReplace() { | ||
| 483 | + return true; | ||
| 484 | + } | ||
| 485 | + }, isMove); | ||
| 486 | + } | ||
| 487 | + | ||
| 488 | + private static boolean copyOrMoveFile(final File srcFile, | ||
| 489 | + final File destFile, | ||
| 490 | + final OnReplaceListener listener, | ||
| 491 | + final boolean isMove) { | ||
| 492 | + if (srcFile == null || destFile == null) return false; | ||
| 493 | + // srcFile equals destFile then return false | ||
| 494 | + if (srcFile.equals(destFile)) return false; | ||
| 495 | + // srcFile doesn't exist or isn't a file then return false | ||
| 496 | + if (!srcFile.exists() || !srcFile.isFile()) return false; | ||
| 497 | + if (destFile.exists()) { | ||
| 498 | + if (listener == null || listener.onReplace()) {// require delete the old file | ||
| 499 | + if (!destFile.delete()) {// unsuccessfully delete then return false | ||
| 500 | + return false; | ||
| 501 | + } | ||
| 502 | + } else { | ||
| 503 | + return true; | ||
| 504 | + } | ||
| 505 | + } | ||
| 506 | + if (!createOrExistsDir(destFile.getParentFile())) return false; | ||
| 507 | + try { | ||
| 508 | + return writeFileFromIS(destFile, new FileInputStream(srcFile)) | ||
| 509 | + && !(isMove && !deleteFile(srcFile)); | ||
| 510 | + } catch (FileNotFoundException e) { | ||
| 511 | + e.printStackTrace(); | ||
| 512 | + return false; | ||
| 513 | + } | ||
| 514 | + } | ||
| 515 | + | ||
| 516 | + /** | ||
| 517 | + * Delete the directory. | ||
| 518 | + * | ||
| 519 | + * @param dirPath The path of directory. | ||
| 520 | + * @return {@code true}: success<br>{@code false}: fail | ||
| 521 | + */ | ||
| 522 | + public static boolean deleteDir(final String dirPath) { | ||
| 523 | + return deleteDir(getFileByPath(dirPath)); | ||
| 524 | + } | ||
| 525 | + | ||
| 526 | + /** | ||
| 527 | + * Delete the directory. | ||
| 528 | + * | ||
| 529 | + * @param dir The directory. | ||
| 530 | + * @return {@code true}: success<br>{@code false}: fail | ||
| 531 | + */ | ||
| 532 | + public static boolean deleteDir(final File dir) { | ||
| 533 | + if (dir == null) return false; | ||
| 534 | + // dir doesn't exist then return true | ||
| 535 | + if (!dir.exists()) return true; | ||
| 536 | + // dir isn't a directory then return false | ||
| 537 | + if (!dir.isDirectory()) return false; | ||
| 538 | + File[] files = dir.listFiles(); | ||
| 539 | + if (files != null && files.length != 0) { | ||
| 540 | + for (File file : files) { | ||
| 541 | + if (file.isFile()) { | ||
| 542 | + if (!file.delete()) return false; | ||
| 543 | + } else if (file.isDirectory()) { | ||
| 544 | + if (!deleteDir(file)) return false; | ||
| 545 | + } | ||
| 546 | + } | ||
| 547 | + } | ||
| 548 | + return dir.delete(); | ||
| 549 | + } | ||
| 550 | + | ||
| 551 | + /** | ||
| 552 | + * Delete the file. | ||
| 553 | + * | ||
| 554 | + * @param srcFilePath The path of source file. | ||
| 555 | + * @return {@code true}: success<br>{@code false}: fail | ||
| 556 | + */ | ||
| 557 | + public static boolean deleteFile(final String srcFilePath) { | ||
| 558 | + return deleteFile(getFileByPath(srcFilePath)); | ||
| 559 | + } | ||
| 560 | + | ||
| 561 | + /** | ||
| 562 | + * Delete the file. | ||
| 563 | + * | ||
| 564 | + * @param file The file. | ||
| 565 | + * @return {@code true}: success<br>{@code false}: fail | ||
| 566 | + */ | ||
| 567 | + public static boolean deleteFile(final File file) { | ||
| 568 | + return file != null && (!file.exists() || file.isFile() && file.delete()); | ||
| 569 | + } | ||
| 570 | + | ||
| 571 | + /** | ||
| 572 | + * Delete the all in directory. | ||
| 573 | + * | ||
| 574 | + * @param dirPath The path of directory. | ||
| 575 | + * @return {@code true}: success<br>{@code false}: fail | ||
| 576 | + */ | ||
| 577 | + public static boolean deleteAllInDir(final String dirPath) { | ||
| 578 | + return deleteAllInDir(getFileByPath(dirPath)); | ||
| 579 | + } | ||
| 580 | + | ||
| 581 | + /** | ||
| 582 | + * Delete the all in directory. | ||
| 583 | + * | ||
| 584 | + * @param dir The directory. | ||
| 585 | + * @return {@code true}: success<br>{@code false}: fail | ||
| 586 | + */ | ||
| 587 | + public static boolean deleteAllInDir(final File dir) { | ||
| 588 | + return deleteFilesInDirWithFilter(dir, new FileFilter() { | ||
| 589 | + @Override | ||
| 590 | + public boolean accept(File pathname) { | ||
| 591 | + return true; | ||
| 592 | + } | ||
| 593 | + }); | ||
| 594 | + } | ||
| 595 | + | ||
| 596 | + /** | ||
| 597 | + * Delete all files in directory. | ||
| 598 | + * | ||
| 599 | + * @param dirPath The path of directory. | ||
| 600 | + * @return {@code true}: success<br>{@code false}: fail | ||
| 601 | + */ | ||
| 602 | + public static boolean deleteFilesInDir(final String dirPath) { | ||
| 603 | + return deleteFilesInDir(getFileByPath(dirPath)); | ||
| 604 | + } | ||
| 605 | + | ||
| 606 | + /** | ||
| 607 | + * Delete all files in directory. | ||
| 608 | + * | ||
| 609 | + * @param dir The directory. | ||
| 610 | + * @return {@code true}: success<br>{@code false}: fail | ||
| 611 | + */ | ||
| 612 | + public static boolean deleteFilesInDir(final File dir) { | ||
| 613 | + return deleteFilesInDirWithFilter(dir, new FileFilter() { | ||
| 614 | + @Override | ||
| 615 | + public boolean accept(File pathname) { | ||
| 616 | + return pathname.isFile(); | ||
| 617 | + } | ||
| 618 | + }); | ||
| 619 | + } | ||
| 620 | + | ||
| 621 | + /** | ||
| 622 | + * Delete all files that satisfy the filter in directory. | ||
| 623 | + * | ||
| 624 | + * @param dirPath The path of directory. | ||
| 625 | + * @param filter The filter. | ||
| 626 | + * @return {@code true}: success<br>{@code false}: fail | ||
| 627 | + */ | ||
| 628 | + public static boolean deleteFilesInDirWithFilter(final String dirPath, | ||
| 629 | + final FileFilter filter) { | ||
| 630 | + return deleteFilesInDirWithFilter(getFileByPath(dirPath), filter); | ||
| 631 | + } | ||
| 632 | + | ||
| 633 | + /** | ||
| 634 | + * Delete all files that satisfy the filter in directory. | ||
| 635 | + * | ||
| 636 | + * @param dir The directory. | ||
| 637 | + * @param filter The filter. | ||
| 638 | + * @return {@code true}: success<br>{@code false}: fail | ||
| 639 | + */ | ||
| 640 | + public static boolean deleteFilesInDirWithFilter(final File dir, final FileFilter filter) { | ||
| 641 | + if (dir == null) return false; | ||
| 642 | + // dir doesn't exist then return true | ||
| 643 | + if (!dir.exists()) return true; | ||
| 644 | + // dir isn't a directory then return false | ||
| 645 | + if (!dir.isDirectory()) return false; | ||
| 646 | + File[] files = dir.listFiles(); | ||
| 647 | + if (files != null && files.length != 0) { | ||
| 648 | + for (File file : files) { | ||
| 649 | + if (filter.accept(file)) { | ||
| 650 | + if (file.isFile()) { | ||
| 651 | + if (!file.delete()) return false; | ||
| 652 | + } else if (file.isDirectory()) { | ||
| 653 | + if (!deleteDir(file)) return false; | ||
| 654 | + } | ||
| 655 | + } | ||
| 656 | + } | ||
| 657 | + } | ||
| 658 | + return true; | ||
| 659 | + } | ||
| 660 | + | ||
| 661 | + /** | ||
| 662 | + * Return the files in directory. | ||
| 663 | + * <p>Doesn't traverse subdirectories</p> | ||
| 664 | + * | ||
| 665 | + * @param dirPath The path of directory. | ||
| 666 | + * @return the files in directory | ||
| 667 | + */ | ||
| 668 | + public static List<File> listFilesInDir(final String dirPath) { | ||
| 669 | + return listFilesInDir(dirPath, false); | ||
| 670 | + } | ||
| 671 | + | ||
| 672 | + /** | ||
| 673 | + * Return the files in directory. | ||
| 674 | + * <p>Doesn't traverse subdirectories</p> | ||
| 675 | + * | ||
| 676 | + * @param dir The directory. | ||
| 677 | + * @return the files in directory | ||
| 678 | + */ | ||
| 679 | + public static List<File> listFilesInDir(final File dir) { | ||
| 680 | + return listFilesInDir(dir, false); | ||
| 681 | + } | ||
| 682 | + | ||
| 683 | + /** | ||
| 684 | + * Return the files in directory. | ||
| 685 | + * | ||
| 686 | + * @param dirPath The path of directory. | ||
| 687 | + * @param isRecursive True to traverse subdirectories, false otherwise. | ||
| 688 | + * @return the files in directory | ||
| 689 | + */ | ||
| 690 | + public static List<File> listFilesInDir(final String dirPath, final boolean isRecursive) { | ||
| 691 | + return listFilesInDir(getFileByPath(dirPath), isRecursive); | ||
| 692 | + } | ||
| 693 | + | ||
| 694 | + /** | ||
| 695 | + * Return the files in directory. | ||
| 696 | + * | ||
| 697 | + * @param dir The directory. | ||
| 698 | + * @param isRecursive True to traverse subdirectories, false otherwise. | ||
| 699 | + * @return the files in directory | ||
| 700 | + */ | ||
| 701 | + public static List<File> listFilesInDir(final File dir, final boolean isRecursive) { | ||
| 702 | + return listFilesInDirWithFilter(dir, new FileFilter() { | ||
| 703 | + @Override | ||
| 704 | + public boolean accept(File pathname) { | ||
| 705 | + return true; | ||
| 706 | + } | ||
| 707 | + }, isRecursive); | ||
| 708 | + } | ||
| 709 | + | ||
| 710 | + /** | ||
| 711 | + * Return the files that satisfy the filter in directory. | ||
| 712 | + * <p>Doesn't traverse subdirectories</p> | ||
| 713 | + * | ||
| 714 | + * @param dirPath The path of directory. | ||
| 715 | + * @param filter The filter. | ||
| 716 | + * @return the files that satisfy the filter in directory | ||
| 717 | + */ | ||
| 718 | + public static List<File> listFilesInDirWithFilter(final String dirPath, | ||
| 719 | + final FileFilter filter) { | ||
| 720 | + return listFilesInDirWithFilter(getFileByPath(dirPath), filter, false); | ||
| 721 | + } | ||
| 722 | + | ||
| 723 | + /** | ||
| 724 | + * Return the files that satisfy the filter in directory. | ||
| 725 | + * <p>Doesn't traverse subdirectories</p> | ||
| 726 | + * | ||
| 727 | + * @param dir The directory. | ||
| 728 | + * @param filter The filter. | ||
| 729 | + * @return the files that satisfy the filter in directory | ||
| 730 | + */ | ||
| 731 | + public static List<File> listFilesInDirWithFilter(final File dir, | ||
| 732 | + final FileFilter filter) { | ||
| 733 | + return listFilesInDirWithFilter(dir, filter, false); | ||
| 734 | + } | ||
| 735 | + | ||
| 736 | + /** | ||
| 737 | + * Return the files that satisfy the filter in directory. | ||
| 738 | + * | ||
| 739 | + * @param dirPath The path of directory. | ||
| 740 | + * @param filter The filter. | ||
| 741 | + * @param isRecursive True to traverse subdirectories, false otherwise. | ||
| 742 | + * @return the files that satisfy the filter in directory | ||
| 743 | + */ | ||
| 744 | + public static List<File> listFilesInDirWithFilter(final String dirPath, | ||
| 745 | + final FileFilter filter, | ||
| 746 | + final boolean isRecursive) { | ||
| 747 | + return listFilesInDirWithFilter(getFileByPath(dirPath), filter, isRecursive); | ||
| 748 | + } | ||
| 749 | + | ||
| 750 | + /** | ||
| 751 | + * Return the files that satisfy the filter in directory. | ||
| 752 | + * | ||
| 753 | + * @param dir The directory. | ||
| 754 | + * @param filter The filter. | ||
| 755 | + * @param isRecursive True to traverse subdirectories, false otherwise. | ||
| 756 | + * @return the files that satisfy the filter in directory | ||
| 757 | + */ | ||
| 758 | + public static List<File> listFilesInDirWithFilter(final File dir, | ||
| 759 | + final FileFilter filter, | ||
| 760 | + final boolean isRecursive) { | ||
| 761 | + if (!isDir(dir)) return null; | ||
| 762 | + List<File> list = new ArrayList<>(); | ||
| 763 | + File[] files = dir.listFiles(); | ||
| 764 | + if (files != null && files.length != 0) { | ||
| 765 | + for (File file : files) { | ||
| 766 | + if (filter.accept(file)) { | ||
| 767 | + list.add(file); | ||
| 768 | + } | ||
| 769 | + if (isRecursive && file.isDirectory()) { | ||
| 770 | + //noinspection ConstantConditions | ||
| 771 | + list.addAll(listFilesInDirWithFilter(file, filter, true)); | ||
| 772 | + } | ||
| 773 | + } | ||
| 774 | + } | ||
| 775 | + return list; | ||
| 776 | + } | ||
| 777 | + | ||
| 778 | + /** | ||
| 779 | + * Return the time that the file was last modified. | ||
| 780 | + * | ||
| 781 | + * @param filePath The path of file. | ||
| 782 | + * @return the time that the file was last modified | ||
| 783 | + */ | ||
| 784 | + | ||
| 785 | + public static long getFileLastModified(final String filePath) { | ||
| 786 | + return getFileLastModified(getFileByPath(filePath)); | ||
| 787 | + } | ||
| 788 | + | ||
| 789 | + /** | ||
| 790 | + * Return the time that the file was last modified. | ||
| 791 | + * | ||
| 792 | + * @param file The file. | ||
| 793 | + * @return the time that the file was last modified | ||
| 794 | + */ | ||
| 795 | + public static long getFileLastModified(final File file) { | ||
| 796 | + if (file == null) return -1; | ||
| 797 | + return file.lastModified(); | ||
| 798 | + } | ||
| 799 | + | ||
| 800 | + /** | ||
| 801 | + * Return the charset of file simply. | ||
| 802 | + * | ||
| 803 | + * @param filePath The path of file. | ||
| 804 | + * @return the charset of file simply | ||
| 805 | + */ | ||
| 806 | + public static String getFileCharsetSimple(final String filePath) { | ||
| 807 | + return getFileCharsetSimple(getFileByPath(filePath)); | ||
| 808 | + } | ||
| 809 | + | ||
| 810 | + /** | ||
| 811 | + * Return the charset of file simply. | ||
| 812 | + * | ||
| 813 | + * @param file The file. | ||
| 814 | + * @return the charset of file simply | ||
| 815 | + */ | ||
| 816 | + public static String getFileCharsetSimple(final File file) { | ||
| 817 | + int p = 0; | ||
| 818 | + InputStream is = null; | ||
| 819 | + try { | ||
| 820 | + is = new BufferedInputStream(new FileInputStream(file)); | ||
| 821 | + p = (is.read() << 8) + is.read(); | ||
| 822 | + } catch (IOException e) { | ||
| 823 | + e.printStackTrace(); | ||
| 824 | + } finally { | ||
| 825 | + try { | ||
| 826 | + if (is != null) { | ||
| 827 | + is.close(); | ||
| 828 | + } | ||
| 829 | + } catch (IOException e) { | ||
| 830 | + e.printStackTrace(); | ||
| 831 | + } | ||
| 832 | + } | ||
| 833 | + switch (p) { | ||
| 834 | + case 0xefbb: | ||
| 835 | + return "UTF-8"; | ||
| 836 | + case 0xfffe: | ||
| 837 | + return "Unicode"; | ||
| 838 | + case 0xfeff: | ||
| 839 | + return "UTF-16BE"; | ||
| 840 | + default: | ||
| 841 | + return "GBK"; | ||
| 842 | + } | ||
| 843 | + } | ||
| 844 | + | ||
| 845 | + /** | ||
| 846 | + * Return the number of lines of file. | ||
| 847 | + * | ||
| 848 | + * @param filePath The path of file. | ||
| 849 | + * @return the number of lines of file | ||
| 850 | + */ | ||
| 851 | + public static int getFileLines(final String filePath) { | ||
| 852 | + return getFileLines(getFileByPath(filePath)); | ||
| 853 | + } | ||
| 854 | + | ||
| 855 | + /** | ||
| 856 | + * Return the number of lines of file. | ||
| 857 | + * | ||
| 858 | + * @param file The file. | ||
| 859 | + * @return the number of lines of file | ||
| 860 | + */ | ||
| 861 | + public static int getFileLines(final File file) { | ||
| 862 | + int count = 1; | ||
| 863 | + InputStream is = null; | ||
| 864 | + try { | ||
| 865 | + is = new BufferedInputStream(new FileInputStream(file)); | ||
| 866 | + byte[] buffer = new byte[1024]; | ||
| 867 | + int readChars; | ||
| 868 | + if (LINE_SEP.endsWith("\n")) { | ||
| 869 | + while ((readChars = is.read(buffer, 0, 1024)) != -1) { | ||
| 870 | + for (int i = 0; i < readChars; ++i) { | ||
| 871 | + if (buffer[i] == '\n') ++count; | ||
| 872 | + } | ||
| 873 | + } | ||
| 874 | + } else { | ||
| 875 | + while ((readChars = is.read(buffer, 0, 1024)) != -1) { | ||
| 876 | + for (int i = 0; i < readChars; ++i) { | ||
| 877 | + if (buffer[i] == '\r') ++count; | ||
| 878 | + } | ||
| 879 | + } | ||
| 880 | + } | ||
| 881 | + } catch (IOException e) { | ||
| 882 | + e.printStackTrace(); | ||
| 883 | + } finally { | ||
| 884 | + try { | ||
| 885 | + if (is != null) { | ||
| 886 | + is.close(); | ||
| 887 | + } | ||
| 888 | + } catch (IOException e) { | ||
| 889 | + e.printStackTrace(); | ||
| 890 | + } | ||
| 891 | + } | ||
| 892 | + return count; | ||
| 893 | + } | ||
| 894 | + | ||
| 895 | + /** | ||
| 896 | + * Return the size of directory. | ||
| 897 | + * | ||
| 898 | + * @param dirPath The path of directory. | ||
| 899 | + * @return the size of directory | ||
| 900 | + */ | ||
| 901 | + public static String getDirSize(final String dirPath) { | ||
| 902 | + return getDirSize(getFileByPath(dirPath)); | ||
| 903 | + } | ||
| 904 | + | ||
| 905 | + /** | ||
| 906 | + * Return the size of directory. | ||
| 907 | + * | ||
| 908 | + * @param dir The directory. | ||
| 909 | + * @return the size of directory | ||
| 910 | + */ | ||
| 911 | + public static String getDirSize(final File dir) { | ||
| 912 | + long len = getDirLength(dir); | ||
| 913 | + return len == -1 ? "" : byte2FitMemorySize(len); | ||
| 914 | + } | ||
| 915 | + | ||
| 916 | + /** | ||
| 917 | + * Return the length of file. | ||
| 918 | + * | ||
| 919 | + * @param filePath The path of file. | ||
| 920 | + * @return the length of file | ||
| 921 | + */ | ||
| 922 | + public static String getFileSize(final String filePath) { | ||
| 923 | + long len = getFileLength(filePath); | ||
| 924 | + return len == -1 ? "" : byte2FitMemorySize(len); | ||
| 925 | + } | ||
| 926 | + | ||
| 927 | + /** | ||
| 928 | + * Return the length of file. | ||
| 929 | + * | ||
| 930 | + * @param file The file. | ||
| 931 | + * @return the length of file | ||
| 932 | + */ | ||
| 933 | + public static String getFileSize(final File file) { | ||
| 934 | + long len = getFileLength(file); | ||
| 935 | + return len == -1 ? "" : byte2FitMemorySize(len); | ||
| 936 | + } | ||
| 937 | + | ||
| 938 | + /** | ||
| 939 | + * Return the length of directory. | ||
| 940 | + * | ||
| 941 | + * @param dirPath The path of directory. | ||
| 942 | + * @return the length of directory | ||
| 943 | + */ | ||
| 944 | + public static long getDirLength(final String dirPath) { | ||
| 945 | + return getDirLength(getFileByPath(dirPath)); | ||
| 946 | + } | ||
| 947 | + | ||
| 948 | + /** | ||
| 949 | + * Return the length of directory. | ||
| 950 | + * | ||
| 951 | + * @param dir The directory. | ||
| 952 | + * @return the length of directory | ||
| 953 | + */ | ||
| 954 | + public static long getDirLength(final File dir) { | ||
| 955 | + if (!isDir(dir)) return -1; | ||
| 956 | + long len = 0; | ||
| 957 | + File[] files = dir.listFiles(); | ||
| 958 | + if (files != null && files.length != 0) { | ||
| 959 | + for (File file : files) { | ||
| 960 | + if (file.isDirectory()) { | ||
| 961 | + len += getDirLength(file); | ||
| 962 | + } else { | ||
| 963 | + len += file.length(); | ||
| 964 | + } | ||
| 965 | + } | ||
| 966 | + } | ||
| 967 | + return len; | ||
| 968 | + } | ||
| 969 | + | ||
| 970 | + /** | ||
| 971 | + * Return the length of file. | ||
| 972 | + * | ||
| 973 | + * @param filePath The path of file. | ||
| 974 | + * @return the length of file | ||
| 975 | + */ | ||
| 976 | + public static long getFileLength(final String filePath) { | ||
| 977 | + boolean isURL = filePath.matches("[a-zA-z]+://[^\\s]*"); | ||
| 978 | + if (isURL) { | ||
| 979 | + try { | ||
| 980 | + HttpURLConnection conn = (HttpURLConnection) new URL(filePath).openConnection(); | ||
| 981 | + conn.setRequestProperty("Accept-Encoding", "identity"); | ||
| 982 | + conn.connect(); | ||
| 983 | + if (conn.getResponseCode() == 200) { | ||
| 984 | + return conn.getContentLength(); | ||
| 985 | + } | ||
| 986 | + return -1; | ||
| 987 | + } catch (IOException e) { | ||
| 988 | + e.printStackTrace(); | ||
| 989 | + } | ||
| 990 | + } | ||
| 991 | + return getFileLength(getFileByPath(filePath)); | ||
| 992 | + } | ||
| 993 | + | ||
| 994 | + /** | ||
| 995 | + * Return the length of file. | ||
| 996 | + * | ||
| 997 | + * @param file The file. | ||
| 998 | + * @return the length of file | ||
| 999 | + */ | ||
| 1000 | + public static long getFileLength(final File file) { | ||
| 1001 | + if (!isFile(file)) return -1; | ||
| 1002 | + return file.length(); | ||
| 1003 | + } | ||
| 1004 | + | ||
| 1005 | + /** | ||
| 1006 | + * Return the MD5 of file. | ||
| 1007 | + * | ||
| 1008 | + * @param filePath The path of file. | ||
| 1009 | + * @return the md5 of file | ||
| 1010 | + */ | ||
| 1011 | + public static String getFileMD5ToString(final String filePath) { | ||
| 1012 | + File file = isSpace(filePath) ? null : new File(filePath); | ||
| 1013 | + return getFileMD5ToString(file); | ||
| 1014 | + } | ||
| 1015 | + | ||
| 1016 | + /** | ||
| 1017 | + * Return the MD5 of file. | ||
| 1018 | + * | ||
| 1019 | + * @param file The file. | ||
| 1020 | + * @return the md5 of file | ||
| 1021 | + */ | ||
| 1022 | + public static String getFileMD5ToString(final File file) { | ||
| 1023 | + return bytes2HexString(getFileMD5(file)); | ||
| 1024 | + } | ||
| 1025 | + | ||
| 1026 | + /** | ||
| 1027 | + * Return the MD5 of file. | ||
| 1028 | + * | ||
| 1029 | + * @param filePath The path of file. | ||
| 1030 | + * @return the md5 of file | ||
| 1031 | + */ | ||
| 1032 | + public static byte[] getFileMD5(final String filePath) { | ||
| 1033 | + return getFileMD5(getFileByPath(filePath)); | ||
| 1034 | + } | ||
| 1035 | + | ||
| 1036 | + /** | ||
| 1037 | + * Return the MD5 of file. | ||
| 1038 | + * | ||
| 1039 | + * @param file The file. | ||
| 1040 | + * @return the md5 of file | ||
| 1041 | + */ | ||
| 1042 | + public static byte[] getFileMD5(final File file) { | ||
| 1043 | + if (file == null) return null; | ||
| 1044 | + DigestInputStream dis = null; | ||
| 1045 | + try { | ||
| 1046 | + FileInputStream fis = new FileInputStream(file); | ||
| 1047 | + MessageDigest md = MessageDigest.getInstance("MD5"); | ||
| 1048 | + dis = new DigestInputStream(fis, md); | ||
| 1049 | + byte[] buffer = new byte[1024 * 256]; | ||
| 1050 | + while (true) { | ||
| 1051 | + if (!(dis.read(buffer) > 0)) break; | ||
| 1052 | + } | ||
| 1053 | + md = dis.getMessageDigest(); | ||
| 1054 | + return md.digest(); | ||
| 1055 | + } catch (NoSuchAlgorithmException | IOException e) { | ||
| 1056 | + e.printStackTrace(); | ||
| 1057 | + } finally { | ||
| 1058 | + try { | ||
| 1059 | + if (dis != null) { | ||
| 1060 | + dis.close(); | ||
| 1061 | + } | ||
| 1062 | + } catch (IOException e) { | ||
| 1063 | + e.printStackTrace(); | ||
| 1064 | + } | ||
| 1065 | + } | ||
| 1066 | + return null; | ||
| 1067 | + } | ||
| 1068 | + | ||
| 1069 | + /** | ||
| 1070 | + * Return the file's path of directory. | ||
| 1071 | + * | ||
| 1072 | + * @param file The file. | ||
| 1073 | + * @return the file's path of directory | ||
| 1074 | + */ | ||
| 1075 | + public static String getDirName(final File file) { | ||
| 1076 | + if (file == null) return ""; | ||
| 1077 | + return getDirName(file.getAbsolutePath()); | ||
| 1078 | + } | ||
| 1079 | + | ||
| 1080 | + /** | ||
| 1081 | + * Return the file's path of directory. | ||
| 1082 | + * | ||
| 1083 | + * @param filePath The path of file. | ||
| 1084 | + * @return the file's path of directory | ||
| 1085 | + */ | ||
| 1086 | + public static String getDirName(final String filePath) { | ||
| 1087 | + if (isSpace(filePath)) return ""; | ||
| 1088 | + int lastSep = filePath.lastIndexOf(File.separator); | ||
| 1089 | + return lastSep == -1 ? "" : filePath.substring(0, lastSep + 1); | ||
| 1090 | + } | ||
| 1091 | + | ||
| 1092 | + /** | ||
| 1093 | + * Return the name of file. | ||
| 1094 | + * | ||
| 1095 | + * @param file The file. | ||
| 1096 | + * @return the name of file | ||
| 1097 | + */ | ||
| 1098 | + public static String getFileName(final File file) { | ||
| 1099 | + if (file == null) return ""; | ||
| 1100 | + return getFileName(file.getAbsolutePath()); | ||
| 1101 | + } | ||
| 1102 | + | ||
| 1103 | + /** | ||
| 1104 | + * Return the name of file. | ||
| 1105 | + * | ||
| 1106 | + * @param filePath The path of file. | ||
| 1107 | + * @return the name of file | ||
| 1108 | + */ | ||
| 1109 | + public static String getFileName(final String filePath) { | ||
| 1110 | + if (isSpace(filePath)) return ""; | ||
| 1111 | + int lastSep = filePath.lastIndexOf(File.separator); | ||
| 1112 | + return lastSep == -1 ? filePath : filePath.substring(lastSep + 1); | ||
| 1113 | + } | ||
| 1114 | + | ||
| 1115 | + /** | ||
| 1116 | + * Return the name of file without extension. | ||
| 1117 | + * | ||
| 1118 | + * @param file The file. | ||
| 1119 | + * @return the name of file without extension | ||
| 1120 | + */ | ||
| 1121 | + public static String getFileNameNoExtension(final File file) { | ||
| 1122 | + if (file == null) return ""; | ||
| 1123 | + return getFileNameNoExtension(file.getPath()); | ||
| 1124 | + } | ||
| 1125 | + | ||
| 1126 | + /** | ||
| 1127 | + * Return the name of file without extension. | ||
| 1128 | + * | ||
| 1129 | + * @param filePath The path of file. | ||
| 1130 | + * @return the name of file without extension | ||
| 1131 | + */ | ||
| 1132 | + public static String getFileNameNoExtension(final String filePath) { | ||
| 1133 | + if (isSpace(filePath)) return ""; | ||
| 1134 | + int lastPoi = filePath.lastIndexOf('.'); | ||
| 1135 | + int lastSep = filePath.lastIndexOf(File.separator); | ||
| 1136 | + if (lastSep == -1) { | ||
| 1137 | + return (lastPoi == -1 ? filePath : filePath.substring(0, lastPoi)); | ||
| 1138 | + } | ||
| 1139 | + if (lastPoi == -1 || lastSep > lastPoi) { | ||
| 1140 | + return filePath.substring(lastSep + 1); | ||
| 1141 | + } | ||
| 1142 | + return filePath.substring(lastSep + 1, lastPoi); | ||
| 1143 | + } | ||
| 1144 | + | ||
| 1145 | + /** | ||
| 1146 | + * Return the extension of file. | ||
| 1147 | + * | ||
| 1148 | + * @param file The file. | ||
| 1149 | + * @return the extension of file | ||
| 1150 | + */ | ||
| 1151 | + public static String getFileExtension(final File file) { | ||
| 1152 | + if (file == null) return ""; | ||
| 1153 | + return getFileExtension(file.getPath()); | ||
| 1154 | + } | ||
| 1155 | + | ||
| 1156 | + /** | ||
| 1157 | + * Return the extension of file. | ||
| 1158 | + * | ||
| 1159 | + * @param filePath The path of file. | ||
| 1160 | + * @return the extension of file | ||
| 1161 | + */ | ||
| 1162 | + public static String getFileExtension(final String filePath) { | ||
| 1163 | + if (isSpace(filePath)) return ""; | ||
| 1164 | + int lastPoi = filePath.lastIndexOf('.'); | ||
| 1165 | + int lastSep = filePath.lastIndexOf(File.separator); | ||
| 1166 | + if (lastPoi == -1 || lastSep >= lastPoi) return ""; | ||
| 1167 | + return filePath.substring(lastPoi + 1); | ||
| 1168 | + } | ||
| 1169 | + | ||
| 1170 | + /////////////////////////////////////////////////////////////////////////// | ||
| 1171 | + // interface | ||
| 1172 | + /////////////////////////////////////////////////////////////////////////// | ||
| 1173 | + | ||
| 1174 | + public interface OnReplaceListener { | ||
| 1175 | + boolean onReplace(); | ||
| 1176 | + } | ||
| 1177 | + | ||
| 1178 | + /////////////////////////////////////////////////////////////////////////// | ||
| 1179 | + // other utils methods | ||
| 1180 | + /////////////////////////////////////////////////////////////////////////// | ||
| 1181 | + | ||
| 1182 | + private static final char HEX_DIGITS[] = | ||
| 1183 | + {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'}; | ||
| 1184 | + | ||
| 1185 | + private static String bytes2HexString(final byte[] bytes) { | ||
| 1186 | + if (bytes == null) return ""; | ||
| 1187 | + int len = bytes.length; | ||
| 1188 | + if (len <= 0) return ""; | ||
| 1189 | + char[] ret = new char[len << 1]; | ||
| 1190 | + for (int i = 0, j = 0; i < len; i++) { | ||
| 1191 | + ret[j++] = HEX_DIGITS[bytes[i] >> 4 & 0x0f]; | ||
| 1192 | + ret[j++] = HEX_DIGITS[bytes[i] & 0x0f]; | ||
| 1193 | + } | ||
| 1194 | + return new String(ret); | ||
| 1195 | + } | ||
| 1196 | + | ||
| 1197 | + private static String byte2FitMemorySize(final long byteNum) { | ||
| 1198 | + if (byteNum < 0) { | ||
| 1199 | + return "shouldn't be less than zero!"; | ||
| 1200 | + } else if (byteNum < 1024) { | ||
| 1201 | + return String.format(Locale.getDefault(), "%.3fB", (double) byteNum); | ||
| 1202 | + } else if (byteNum < 1048576) { | ||
| 1203 | + return String.format(Locale.getDefault(), "%.3fKB", (double) byteNum / 1024); | ||
| 1204 | + } else if (byteNum < 1073741824) { | ||
| 1205 | + return String.format(Locale.getDefault(), "%.3fMB", (double) byteNum / 1048576); | ||
| 1206 | + } else { | ||
| 1207 | + return String.format(Locale.getDefault(), "%.3fGB", (double) byteNum / 1073741824); | ||
| 1208 | + } | ||
| 1209 | + } | ||
| 1210 | + | ||
| 1211 | + private static boolean isSpace(final String s) { | ||
| 1212 | + if (s == null) return true; | ||
| 1213 | + for (int i = 0, len = s.length(); i < len; ++i) { | ||
| 1214 | + if (!Character.isWhitespace(s.charAt(i))) { | ||
| 1215 | + return false; | ||
| 1216 | + } | ||
| 1217 | + } | ||
| 1218 | + return true; | ||
| 1219 | + } | ||
| 1220 | + | ||
| 1221 | + private static boolean writeFileFromIS(final File file, | ||
| 1222 | + final InputStream is) { | ||
| 1223 | + OutputStream os = null; | ||
| 1224 | + try { | ||
| 1225 | + os = new BufferedOutputStream(new FileOutputStream(file)); | ||
| 1226 | + byte data[] = new byte[8192]; | ||
| 1227 | + int len; | ||
| 1228 | + while ((len = is.read(data, 0, 8192)) != -1) { | ||
| 1229 | + os.write(data, 0, len); | ||
| 1230 | + } | ||
| 1231 | + return true; | ||
| 1232 | + } catch (IOException e) { | ||
| 1233 | + e.printStackTrace(); | ||
| 1234 | + return false; | ||
| 1235 | + } finally { | ||
| 1236 | + try { | ||
| 1237 | + is.close(); | ||
| 1238 | + } catch (IOException e) { | ||
| 1239 | + e.printStackTrace(); | ||
| 1240 | + } | ||
| 1241 | + try { | ||
| 1242 | + if (os != null) { | ||
| 1243 | + os.close(); | ||
| 1244 | + } | ||
| 1245 | + } catch (IOException e) { | ||
| 1246 | + e.printStackTrace(); | ||
| 1247 | + } | ||
| 1248 | + } | ||
| 1249 | + } | ||
| 1250 | + | ||
| 1251 | + public static boolean isExternalStorageWritable() { | ||
| 1252 | + String state = Environment.getExternalStorageState(); | ||
| 1253 | + if (Environment.MEDIA_MOUNTED.equals(state)) { | ||
| 1254 | + return true; | ||
| 1255 | + } | ||
| 1256 | + return false; | ||
| 1257 | + } | ||
| 1258 | + | ||
| 1259 | +} |
cloud/wjj_lib/src/main/java/com/cnlive/libs/base/util/ImageUtil.java
0 → 100644
| 1 | +package com.cnlive.libs.base.util; | ||
| 2 | + | ||
| 3 | +import android.content.Context; | ||
| 4 | +import android.graphics.Bitmap; | ||
| 5 | +import android.graphics.Canvas; | ||
| 6 | +import android.graphics.Color; | ||
| 7 | +import android.graphics.Matrix; | ||
| 8 | +import android.graphics.Paint; | ||
| 9 | +import android.graphics.Path; | ||
| 10 | +import android.graphics.Rect; | ||
| 11 | + | ||
| 12 | +/** | ||
| 13 | + * 图片添加水印工具类 | ||
| 14 | + * | ||
| 15 | + * @author Lynn | ||
| 16 | + * @date 2018/1/29 | ||
| 17 | + */ | ||
| 18 | + | ||
| 19 | +public class ImageUtil { | ||
| 20 | + /** | ||
| 21 | + * 设置水印图片在左上角 | ||
| 22 | + * | ||
| 23 | + * @param context | ||
| 24 | + * @param src | ||
| 25 | + * @param watermark | ||
| 26 | + * @param paddingLeft | ||
| 27 | + * @param paddingTop | ||
| 28 | + * @return | ||
| 29 | + */ | ||
| 30 | + public static Bitmap createWaterMaskLeftTop( | ||
| 31 | + Context context, Bitmap src, Bitmap watermark, | ||
| 32 | + int paddingLeft, int paddingTop) { | ||
| 33 | + return createWaterMaskBitmap(src, watermark, | ||
| 34 | + dp2px(context, paddingLeft), dp2px(context, paddingTop)); | ||
| 35 | + } | ||
| 36 | + | ||
| 37 | + private static Bitmap createWaterMaskBitmap(Bitmap src, Bitmap watermark, | ||
| 38 | + int paddingLeft, int paddingTop) { | ||
| 39 | + if (src == null) { | ||
| 40 | + return null; | ||
| 41 | + } | ||
| 42 | + int width = src.getWidth(); | ||
| 43 | + int height = src.getHeight(); | ||
| 44 | + //创建一个bitmap | ||
| 45 | + Bitmap newb = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);// 创建一个新的和SRC长度宽度一样的位图 | ||
| 46 | + //将该图片作为画布 | ||
| 47 | + Canvas canvas = new Canvas(newb); | ||
| 48 | + //在画布 0,0坐标上开始绘制原始图片 | ||
| 49 | + canvas.drawBitmap(src, 0, 0, null); | ||
| 50 | + //在画布上绘制水印图片 | ||
| 51 | + canvas.drawBitmap(watermark, paddingLeft, paddingTop, null); | ||
| 52 | + // 保存 | ||
| 53 | +// canvas.save(Canvas.ALL_SAVE_FLAG); | ||
| 54 | + canvas.save(); | ||
| 55 | + // 存储 | ||
| 56 | + canvas.restore(); | ||
| 57 | + return newb; | ||
| 58 | + } | ||
| 59 | + | ||
| 60 | + /** | ||
| 61 | + * 设置水印图片在右下角 | ||
| 62 | + * | ||
| 63 | + * @param context | ||
| 64 | + * @param src | ||
| 65 | + * @param watermark | ||
| 66 | + * @param paddingRight | ||
| 67 | + * @param paddingBottom | ||
| 68 | + * @return | ||
| 69 | + */ | ||
| 70 | + public static Bitmap createWaterMaskRightBottom( | ||
| 71 | + Context context, Bitmap src, Bitmap watermark, | ||
| 72 | + int paddingRight, int paddingBottom) { | ||
| 73 | + return createWaterMaskBitmap(src, watermark, | ||
| 74 | + src.getWidth() - watermark.getWidth() - dp2px(context, paddingRight), | ||
| 75 | + src.getHeight() - watermark.getHeight() - dp2px(context, paddingBottom)); | ||
| 76 | + } | ||
| 77 | + | ||
| 78 | + /** | ||
| 79 | + * 设置水印图片到右上角 | ||
| 80 | + * | ||
| 81 | + * @param context | ||
| 82 | + * @param src | ||
| 83 | + * @param watermark | ||
| 84 | + * @param paddingRight | ||
| 85 | + * @param paddingTop | ||
| 86 | + * @return | ||
| 87 | + */ | ||
| 88 | + public static Bitmap createWaterMaskRightTop( | ||
| 89 | + Context context, Bitmap src, Bitmap watermark, | ||
| 90 | + int paddingRight, int paddingTop) { | ||
| 91 | + return createWaterMaskBitmap(src, watermark, | ||
| 92 | + src.getWidth() - watermark.getWidth() - dp2px(context, paddingRight), | ||
| 93 | + dp2px(context, paddingTop)); | ||
| 94 | + } | ||
| 95 | + | ||
| 96 | + /** | ||
| 97 | + * 设置水印图片到左下角 | ||
| 98 | + * | ||
| 99 | + * @param context | ||
| 100 | + * @param src | ||
| 101 | + * @param watermark | ||
| 102 | + * @param paddingLeft | ||
| 103 | + * @param paddingBottom | ||
| 104 | + * @return | ||
| 105 | + */ | ||
| 106 | + public static Bitmap createWaterMaskLeftBottom( | ||
| 107 | + Context context, Bitmap src, Bitmap watermark, | ||
| 108 | + int paddingLeft, int paddingBottom) { | ||
| 109 | + return createWaterMaskBitmap(src, watermark, dp2px(context, paddingLeft), | ||
| 110 | + src.getHeight() - watermark.getHeight() - dp2px(context, paddingBottom)); | ||
| 111 | + } | ||
| 112 | + | ||
| 113 | + /** | ||
| 114 | + * 设置水印图片到中间 | ||
| 115 | + * | ||
| 116 | + * @param src | ||
| 117 | + * @param watermark | ||
| 118 | + * @return | ||
| 119 | + */ | ||
| 120 | + public static Bitmap createWaterMaskCenter(Bitmap src, Bitmap watermark) { | ||
| 121 | + return createWaterMaskBitmap(src, watermark, | ||
| 122 | + (src.getWidth() - watermark.getWidth()) / 2, | ||
| 123 | + (src.getHeight() - watermark.getHeight()) / 2); | ||
| 124 | + } | ||
| 125 | + | ||
| 126 | + /** | ||
| 127 | + * 给图片添加文字到左上角 | ||
| 128 | + * | ||
| 129 | + * @param context | ||
| 130 | + * @param bitmap | ||
| 131 | + * @param text | ||
| 132 | + * @return | ||
| 133 | + */ | ||
| 134 | + public static Bitmap drawTextToLeftTop(Context context, Bitmap bitmap, String text, | ||
| 135 | + int size, int color, int paddingLeft, int paddingTop) { | ||
| 136 | + Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); | ||
| 137 | + paint.setColor(color); | ||
| 138 | + paint.setTextSize(dp2px(context, size)); | ||
| 139 | + Rect bounds = new Rect(); | ||
| 140 | + paint.getTextBounds(text, 0, text.length(), bounds); | ||
| 141 | + return drawTextToBitmap(context, bitmap, text, paint, bounds, | ||
| 142 | + dp2px(context, paddingLeft), | ||
| 143 | + dp2px(context, paddingTop) + bounds.height()); | ||
| 144 | + } | ||
| 145 | + | ||
| 146 | + /** | ||
| 147 | + * 绘制文字到右下角 | ||
| 148 | + * | ||
| 149 | + * @param context | ||
| 150 | + * @param bitmap | ||
| 151 | + * @param text | ||
| 152 | + * @param size | ||
| 153 | + * @param color | ||
| 154 | + * @param paddingRight | ||
| 155 | + * @param paddingBottom | ||
| 156 | + * @return | ||
| 157 | + */ | ||
| 158 | + public static Bitmap drawTextToRightBottom(Context context, Bitmap bitmap, String text, | ||
| 159 | + int size, int color, int paddingRight, int paddingBottom) { | ||
| 160 | + Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); | ||
| 161 | + paint.setColor(color); | ||
| 162 | + paint.setTextSize(dp2px(context, size)); | ||
| 163 | + Rect bounds = new Rect(); | ||
| 164 | + paint.getTextBounds(text, 0, text.length(), bounds); | ||
| 165 | + return drawTextToBitmap(context, bitmap, text, paint, bounds, | ||
| 166 | + bitmap.getWidth() - bounds.width() - dp2px(context, paddingRight), | ||
| 167 | + bitmap.getHeight() - dp2px(context, paddingBottom)); | ||
| 168 | + } | ||
| 169 | + | ||
| 170 | + /** | ||
| 171 | + * 绘制文字到右上方 | ||
| 172 | + * | ||
| 173 | + * @param context | ||
| 174 | + * @param bitmap | ||
| 175 | + * @param text | ||
| 176 | + * @param size | ||
| 177 | + * @param color | ||
| 178 | + * @param paddingRight | ||
| 179 | + * @param paddingTop | ||
| 180 | + * @return | ||
| 181 | + */ | ||
| 182 | + public static Bitmap drawTextToRightTop(Context context, Bitmap bitmap, String text, | ||
| 183 | + int size, int color, int paddingRight, int paddingTop) { | ||
| 184 | + Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); | ||
| 185 | + paint.setColor(color); | ||
| 186 | + paint.setTextSize(dp2px(context, size)); | ||
| 187 | + Rect bounds = new Rect(); | ||
| 188 | + paint.getTextBounds(text, 0, text.length(), bounds); | ||
| 189 | + return drawTextToBitmap(context, bitmap, text, paint, bounds, | ||
| 190 | + bitmap.getWidth() - bounds.width() - dp2px(context, paddingRight), | ||
| 191 | + dp2px(context, paddingTop) + bounds.height()); | ||
| 192 | + } | ||
| 193 | + | ||
| 194 | + /** | ||
| 195 | + * 绘制文字到左下方 | ||
| 196 | + * | ||
| 197 | + * @param context | ||
| 198 | + * @param bitmap | ||
| 199 | + * @param text | ||
| 200 | + * @param size | ||
| 201 | + * @param color | ||
| 202 | + * @param paddingLeft | ||
| 203 | + * @param paddingBottom | ||
| 204 | + * @return | ||
| 205 | + */ | ||
| 206 | + public static Bitmap drawTextToLeftBottom(Context context, Bitmap bitmap, String text, | ||
| 207 | + int size, int color, int paddingLeft, int paddingBottom) { | ||
| 208 | + Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); | ||
| 209 | + paint.setColor(color); | ||
| 210 | + paint.setTextSize(dp2px(context, size)); | ||
| 211 | + Rect bounds = new Rect(); | ||
| 212 | + paint.getTextBounds(text, 0, text.length(), bounds); | ||
| 213 | + return drawTextToBitmap(context, bitmap, text, paint, bounds, | ||
| 214 | + dp2px(context, paddingLeft), | ||
| 215 | + bitmap.getHeight() - dp2px(context, paddingBottom)); | ||
| 216 | + } | ||
| 217 | + | ||
| 218 | + /** | ||
| 219 | + * 绘制文字到中间 | ||
| 220 | + * | ||
| 221 | + * @param context | ||
| 222 | + * @param bitmap | ||
| 223 | + * @param text | ||
| 224 | + * @param size | ||
| 225 | + * @param color | ||
| 226 | + * @return | ||
| 227 | + */ | ||
| 228 | + public static Bitmap drawTextToCenter(Context context, Bitmap bitmap, String text, | ||
| 229 | + int size, int color) { | ||
| 230 | + Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); | ||
| 231 | + paint.setColor(color); | ||
| 232 | + paint.setTextSize(dp2px(context, size)); | ||
| 233 | + Rect bounds = new Rect(); | ||
| 234 | + paint.getTextBounds(text, 0, text.length(), bounds); | ||
| 235 | + return drawTextToBitmap(context, bitmap, text, paint, bounds, | ||
| 236 | + (bitmap.getWidth() - bounds.width()) / 2, | ||
| 237 | + (bitmap.getHeight() + bounds.height()) / 2); | ||
| 238 | + } | ||
| 239 | + | ||
| 240 | + //图片上绘制文字 | ||
| 241 | + private static Bitmap drawTextToBitmap(Context context, Bitmap bitmap, String text, | ||
| 242 | + Paint paint, Rect bounds, int paddingLeft, int paddingTop) { | ||
| 243 | + Bitmap.Config bitmapConfig = bitmap.getConfig(); | ||
| 244 | + | ||
| 245 | + paint.setDither(true); // 获取跟清晰的图像采样 | ||
| 246 | + paint.setFilterBitmap(true);// 过滤一些 | ||
| 247 | + if (bitmapConfig == null) { | ||
| 248 | + bitmapConfig = Bitmap.Config.ARGB_8888; | ||
| 249 | + } | ||
| 250 | + bitmap = bitmap.copy(bitmapConfig, true); | ||
| 251 | + Canvas canvas = new Canvas(bitmap); | ||
| 252 | +// canvas.rotate(-45); | ||
| 253 | +// canvas.drawText(text, paddingLeft, paddingTop, paint); | ||
| 254 | + | ||
| 255 | + Path path = new Path(); | ||
| 256 | + path.moveTo(bitmap.getWidth() / 2, bitmap.getHeight()); | ||
| 257 | + path.lineTo(bitmap.getWidth(), 50); | ||
| 258 | + | ||
| 259 | + canvas.drawTextOnPath(text, path, 20, 20, paint); | ||
| 260 | + | ||
| 261 | + return bitmap; | ||
| 262 | + } | ||
| 263 | + | ||
| 264 | + public static void addBitmap(String gText) { | ||
| 265 | + Bitmap bitmap = Bitmap.createBitmap(420, 240, Bitmap.Config.ARGB_8888); | ||
| 266 | + Canvas canvas = new Canvas(bitmap); | ||
| 267 | + canvas.drawColor(Color.WHITE); | ||
| 268 | + Paint paint = new Paint(); | ||
| 269 | + paint.setColor(Color.GRAY); | ||
| 270 | + paint.setAlpha(80); | ||
| 271 | + paint.setAntiAlias(true); | ||
| 272 | + paint.setTextAlign(Paint.Align.LEFT); | ||
| 273 | + paint.setTextSize(40); | ||
| 274 | + Path path = new Path(); | ||
| 275 | + path.moveTo(0, 150); | ||
| 276 | + path.lineTo(160 * 2, 0); | ||
| 277 | + canvas.drawTextOnPath(gText, path, 0, 20, paint); | ||
| 278 | +// canvas.save(Canvas.ALL_SAVE_FLAG); | ||
| 279 | + canvas.save(); | ||
| 280 | + canvas.restore(); | ||
| 281 | + bitmap.recycle(); | ||
| 282 | + } | ||
| 283 | + | ||
| 284 | + /** | ||
| 285 | + * 缩放图片 | ||
| 286 | + * | ||
| 287 | + * @param src | ||
| 288 | + * @param w | ||
| 289 | + * @param h | ||
| 290 | + * @return | ||
| 291 | + */ | ||
| 292 | + public static Bitmap scaleWithWH(Bitmap src, double w, double h) { | ||
| 293 | + if (w == 0 || h == 0 || src == null) { | ||
| 294 | + return src; | ||
| 295 | + } else { | ||
| 296 | + // 记录src的宽高 | ||
| 297 | + int width = src.getWidth(); | ||
| 298 | + int height = src.getHeight(); | ||
| 299 | + // 创建一个matrix容器 | ||
| 300 | + Matrix matrix = new Matrix(); | ||
| 301 | + // 计算缩放比例 | ||
| 302 | + float scaleWidth = (float) (w / width); | ||
| 303 | + float scaleHeight = (float) (h / height); | ||
| 304 | + // 开始缩放 | ||
| 305 | + matrix.postScale(scaleWidth, scaleHeight); | ||
| 306 | + // 创建缩放后的图片 | ||
| 307 | + return Bitmap.createBitmap(src, 0, 0, width, height, matrix, true); | ||
| 308 | + } | ||
| 309 | + } | ||
| 310 | + | ||
| 311 | + /** | ||
| 312 | + * dip转pix | ||
| 313 | + * | ||
| 314 | + * @param context | ||
| 315 | + * @param dp | ||
| 316 | + * @return | ||
| 317 | + */ | ||
| 318 | + public static int dp2px(Context context, float dp) { | ||
| 319 | + final float scale = context.getResources().getDisplayMetrics().density; | ||
| 320 | + return (int) (dp * scale + 0.5f); | ||
| 321 | + } | ||
| 322 | +} |
cloud/wjj_lib/src/main/java/com/cnlive/libs/base/util/LambdaUtil.java
0 → 100644
| 1 | +package com.cnlive.libs.base.util; | ||
| 2 | + | ||
| 3 | +import java.util.Collection; | ||
| 4 | + | ||
| 5 | +import java8.util.stream.RefStreams; | ||
| 6 | +import java8.util.stream.Stream; | ||
| 7 | + | ||
| 8 | +public class LambdaUtil { | ||
| 9 | + public static <T> Stream<T> stream(Collection<T> collection) { | ||
| 10 | + if (collection == null) return null; | ||
| 11 | + return RefStreams.of((T[]) collection.toArray()); | ||
| 12 | + } | ||
| 13 | +} |
cloud/wjj_lib/src/main/java/com/cnlive/libs/base/util/LogUtil.java
0 → 100644
| 1 | +package com.cnlive.libs.base.util; | ||
| 2 | + | ||
| 3 | +import android.util.Log; | ||
| 4 | + | ||
| 5 | +import com.cnlive.libs.base.application.AppConfig; | ||
| 6 | + | ||
| 7 | +public class LogUtil { | ||
| 8 | + private static boolean ENABLED = AppConfig.isDebug(); | ||
| 9 | + | ||
| 10 | + public LogUtil() { | ||
| 11 | + } | ||
| 12 | + | ||
| 13 | + public static void setDebug(boolean debug) { | ||
| 14 | + ENABLED = debug; | ||
| 15 | + } | ||
| 16 | + | ||
| 17 | + public static void e(String tag, String msg) { | ||
| 18 | + if (ENABLED) { | ||
| 19 | + Log.e(tag, msg); | ||
| 20 | + } | ||
| 21 | + | ||
| 22 | + } | ||
| 23 | + | ||
| 24 | + public static void e(String tag, String msg, Throwable tr) { | ||
| 25 | + if (ENABLED) { | ||
| 26 | + Log.e(tag, msg, tr); | ||
| 27 | + } | ||
| 28 | + | ||
| 29 | + } | ||
| 30 | + | ||
| 31 | + public static void d(String tag, String msg) { | ||
| 32 | + if (ENABLED) { | ||
| 33 | + Log.d(tag, msg); | ||
| 34 | + } | ||
| 35 | + | ||
| 36 | + } | ||
| 37 | + | ||
| 38 | + public static void d(String tag, String msg, Throwable tr) { | ||
| 39 | + if (ENABLED) { | ||
| 40 | + Log.d(tag, msg, tr); | ||
| 41 | + } | ||
| 42 | + | ||
| 43 | + } | ||
| 44 | +} |
cloud/wjj_lib/src/main/java/com/cnlive/libs/base/util/MD5Util.java
0 → 100644
| 1 | +package com.cnlive.libs.base.util; | ||
| 2 | + | ||
| 3 | +import java.io.File; | ||
| 4 | +import java.io.FileInputStream; | ||
| 5 | +import java.io.IOException; | ||
| 6 | +import java.io.InputStream; | ||
| 7 | +import java.security.MessageDigest; | ||
| 8 | +import java.security.NoSuchAlgorithmException; | ||
| 9 | + | ||
| 10 | +/** | ||
| 11 | + * 提供一系列获取和校验MD5的方法 | ||
| 12 | + */ | ||
| 13 | +public class MD5Util { | ||
| 14 | + | ||
| 15 | + /** | ||
| 16 | + * 获取该输入流的MD5值 | ||
| 17 | + * | ||
| 18 | + * @param is | ||
| 19 | + * @return | ||
| 20 | + * @throws NoSuchAlgorithmException | ||
| 21 | + * @throws IOException | ||
| 22 | + */ | ||
| 23 | + public static String getMD5(InputStream is) throws NoSuchAlgorithmException, IOException { | ||
| 24 | + StringBuffer md5 = new StringBuffer(); | ||
| 25 | + MessageDigest md = MessageDigest.getInstance("MD5"); | ||
| 26 | + byte[] dataBytes = new byte[1024]; | ||
| 27 | + | ||
| 28 | + int nread = 0; | ||
| 29 | + while ((nread = is.read(dataBytes)) != -1) { | ||
| 30 | + md.update(dataBytes, 0, nread); | ||
| 31 | + } | ||
| 32 | + byte[] mdbytes = md.digest(); | ||
| 33 | + | ||
| 34 | + // convert the byte to hex format | ||
| 35 | + for (int i = 0; i < mdbytes.length; i++) { | ||
| 36 | + md5.append(Integer.toString((mdbytes[i] & 0xff) + 0x100, 16).substring(1)); | ||
| 37 | + } | ||
| 38 | + return md5.toString(); | ||
| 39 | + } | ||
| 40 | + | ||
| 41 | + /** | ||
| 42 | + * 获取该文件的MD5值 | ||
| 43 | + * | ||
| 44 | + * @param file | ||
| 45 | + * @return | ||
| 46 | + * @throws NoSuchAlgorithmException | ||
| 47 | + * @throws IOException | ||
| 48 | + */ | ||
| 49 | + public static String getMD5(File file) throws NoSuchAlgorithmException, IOException { | ||
| 50 | + FileInputStream fis = new FileInputStream(file); | ||
| 51 | + return getMD5(fis); | ||
| 52 | + } | ||
| 53 | + | ||
| 54 | + /** | ||
| 55 | + * 获取指定路径文件的MD5值 | ||
| 56 | + * | ||
| 57 | + * @param path | ||
| 58 | + * @return | ||
| 59 | + * @throws NoSuchAlgorithmException | ||
| 60 | + * @throws IOException | ||
| 61 | + */ | ||
| 62 | + public static String getMD5(String path) throws NoSuchAlgorithmException, IOException { | ||
| 63 | + FileInputStream fis = new FileInputStream(path); | ||
| 64 | + return getMD5(fis); | ||
| 65 | + } | ||
| 66 | + | ||
| 67 | + /** | ||
| 68 | + * 校验该输入流的MD5值 | ||
| 69 | + * | ||
| 70 | + * @param is | ||
| 71 | + * @param toBeCheckSum | ||
| 72 | + * @return | ||
| 73 | + * @throws NoSuchAlgorithmException | ||
| 74 | + * @throws IOException | ||
| 75 | + */ | ||
| 76 | + public static boolean md5CheckSum(InputStream is, String toBeCheckSum) throws NoSuchAlgorithmException, IOException { | ||
| 77 | + return getMD5(is).equals(toBeCheckSum); | ||
| 78 | + } | ||
| 79 | + | ||
| 80 | + /** | ||
| 81 | + * 校验该文件的MD5值 | ||
| 82 | + * | ||
| 83 | + * @param file | ||
| 84 | + * @param toBeCheckSum | ||
| 85 | + * @return | ||
| 86 | + * @throws NoSuchAlgorithmException | ||
| 87 | + * @throws IOException | ||
| 88 | + */ | ||
| 89 | + public static boolean md5CheckSum(File file, String toBeCheckSum) throws NoSuchAlgorithmException, IOException { | ||
| 90 | + return getMD5(file).equals(toBeCheckSum); | ||
| 91 | + } | ||
| 92 | + | ||
| 93 | + /** | ||
| 94 | + * 校验指定路径文件的MD5值 | ||
| 95 | + * | ||
| 96 | + * @param path | ||
| 97 | + * @param toBeCheckSum | ||
| 98 | + * @return | ||
| 99 | + * @throws NoSuchAlgorithmException | ||
| 100 | + * @throws IOException | ||
| 101 | + */ | ||
| 102 | + public static boolean md5CheckSum(String path, String toBeCheckSum) throws NoSuchAlgorithmException, IOException { | ||
| 103 | + return getMD5(path).equals(toBeCheckSum); | ||
| 104 | + } | ||
| 105 | + | ||
| 106 | + /* MD5 TEST | ||
| 107 | + public static void main(String[] args) { | ||
| 108 | + try { | ||
| 109 | + System.out.println(getMD5("D:/work/BJ/ESB_CSS_CSS_ImportCustCompFormRejectInfoSrv.xml")); | ||
| 110 | + } catch (NoSuchAlgorithmException e) { | ||
| 111 | + e.printStackTrace(); | ||
| 112 | + } catch (IOException e) { | ||
| 113 | + e.printStackTrace(); | ||
| 114 | + } | ||
| 115 | + } | ||
| 116 | + */ | ||
| 117 | +} | ||
| 0 | \ No newline at end of file | 118 | \ No newline at end of file |
cloud/wjj_lib/src/main/java/com/cnlive/libs/base/util/NetworkUtil.java
0 → 100644
| 1 | +package com.cnlive.libs.base.util; | ||
| 2 | + | ||
| 3 | +import android.content.Context; | ||
| 4 | +import android.net.ConnectivityManager; | ||
| 5 | +import android.net.NetworkInfo; | ||
| 6 | + | ||
| 7 | +public class NetworkUtil { | ||
| 8 | + | ||
| 9 | + | ||
| 10 | + public static boolean isConnectInternet(Context context) { | ||
| 11 | + if (context == null) return false; | ||
| 12 | + ConnectivityManager connectManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); | ||
| 13 | + | ||
| 14 | + if (connectManager != null) { | ||
| 15 | + NetworkInfo networkinfo = connectManager.getActiveNetworkInfo(); | ||
| 16 | + return networkinfo != null && networkinfo.isAvailable(); | ||
| 17 | + } | ||
| 18 | + return false; | ||
| 19 | + } | ||
| 20 | + | ||
| 21 | +} | ||
| 0 | \ No newline at end of file | 22 | \ No newline at end of file |
cloud/wjj_lib/src/main/java/com/cnlive/libs/base/util/NotificationUtils.java
0 → 100644
| 1 | +package com.cnlive.libs.base.util; | ||
| 2 | + | ||
| 3 | + | ||
| 4 | +import android.app.AppOpsManager; | ||
| 5 | +import android.app.Notification; | ||
| 6 | +import android.app.NotificationChannel; | ||
| 7 | +import android.app.NotificationManager; | ||
| 8 | +import android.app.PendingIntent; | ||
| 9 | +import android.content.Context; | ||
| 10 | +import android.content.Intent; | ||
| 11 | +import android.content.pm.ApplicationInfo; | ||
| 12 | +import android.graphics.Color; | ||
| 13 | +import android.media.RingtoneManager; | ||
| 14 | +import android.net.Uri; | ||
| 15 | +import android.os.Build; | ||
| 16 | +import android.text.TextUtils; | ||
| 17 | +import android.util.Log; | ||
| 18 | + | ||
| 19 | +import androidx.annotation.RequiresApi; | ||
| 20 | +import androidx.core.content.FileProvider; | ||
| 21 | + | ||
| 22 | +import com.cnlive.libs.base.R; | ||
| 23 | +import com.cnlive.libs.base.util.badger.BadgeUtil; | ||
| 24 | + | ||
| 25 | +import java.io.File; | ||
| 26 | +import java.lang.reflect.Field; | ||
| 27 | +import java.lang.reflect.Method; | ||
| 28 | +import java.util.ArrayList; | ||
| 29 | +import java.util.List; | ||
| 30 | + | ||
| 31 | + | ||
| 32 | +/** | ||
| 33 | + * 创建:wukuiqing | ||
| 34 | + * <p> | ||
| 35 | + * 时间:2018/4/4 | ||
| 36 | + * <p> | ||
| 37 | + * 描述: Notification | ||
| 38 | + */ | ||
| 39 | + | ||
| 40 | +public class NotificationUtils { | ||
| 41 | + Notification.Builder builder; | ||
| 42 | + //通知Id | ||
| 43 | + int mNotificationID = 0x10000; | ||
| 44 | + //记录消息发送的时间 | ||
| 45 | + long notificationTime = 0; | ||
| 46 | + private static NotificationUtils instance; | ||
| 47 | + long[] pattern = {100, 400, 100, 400}; // 停止 开启 停止 开启 | ||
| 48 | + | ||
| 49 | + public static NotificationUtils getInstance() { | ||
| 50 | + if (instance == null) instance = new NotificationUtils(); | ||
| 51 | + return instance; | ||
| 52 | + } | ||
| 53 | + | ||
| 54 | + /** | ||
| 55 | + * 这是版本更新用的 不能手动销毁掉的 Nitification setOngoing未true | ||
| 56 | + * | ||
| 57 | + * @param mContext | ||
| 58 | + * @param NotificationID id | ||
| 59 | + * @param title 标题 | ||
| 60 | + * @param content 内容 | ||
| 61 | + */ | ||
| 62 | + public void initNotification(Context mContext, int NotificationID, String title, String content) { | ||
| 63 | + mNotificationID = NotificationID; | ||
| 64 | + NotificationManager mNotificationManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE); | ||
| 65 | + if (mNotificationManager == null) return; | ||
| 66 | + //26(O版本)版本以上需要增加 channel | ||
| 67 | + if (Build.VERSION.SDK_INT >= 26) { | ||
| 68 | + try { | ||
| 69 | + NotificationChannel channel = new NotificationChannel(2 + "", "版本更新", NotificationManager.IMPORTANCE_DEFAULT); | ||
| 70 | + channel.enableLights(true); | ||
| 71 | + channel.setLightColor(Color.GREEN); | ||
| 72 | + channel.setShowBadge(true); | ||
| 73 | + channel.enableVibration(true); | ||
| 74 | + channel.setDescription("网家家 版本更新"); | ||
| 75 | + channel.setVibrationPattern(pattern); | ||
| 76 | + channel.setLightColor(Color.GREEN); | ||
| 77 | + channel.setLockscreenVisibility(Notification.FLAG_ONLY_ALERT_ONCE); | ||
| 78 | + mNotificationManager.createNotificationChannel(channel); | ||
| 79 | + builder = new Notification.Builder(mContext, 2 + ""); //与channelId对应 | ||
| 80 | + } catch (Exception e) { | ||
| 81 | + Log.e("推送适配8.0异常*************:", e.getMessage()); | ||
| 82 | + } | ||
| 83 | + } else { | ||
| 84 | + builder = new Notification.Builder(mContext); //与channelId对应 | ||
| 85 | + if (Build.VERSION.SDK_INT > 16) { | ||
| 86 | + //设置显示时间 | ||
| 87 | + builder.setShowWhen(true); | ||
| 88 | + } | ||
| 89 | + } | ||
| 90 | + | ||
| 91 | + builder.setSmallIcon(R.drawable.ic_notifi); | ||
| 92 | + builder.setTicker(title); | ||
| 93 | + builder.setContentTitle(title); | ||
| 94 | + builder.setContentText(content); | ||
| 95 | + builder.setWhen(System.currentTimeMillis());//设置通知时间,一般设置的是收到通知时的System.currentTimeMillis() | ||
| 96 | + builder.setNumber(0); | ||
| 97 | + builder.setOngoing(true); //设置 只能代码调用取消 | ||
| 98 | + builder.setProgress(100, 0, false); | ||
| 99 | + builder.setOnlyAlertOnce(true);//设置只展示一次 | ||
| 100 | + } | ||
| 101 | + | ||
| 102 | + /** | ||
| 103 | + * 设置普通的 notification(设置角标) | ||
| 104 | + * | ||
| 105 | + * @param mContext | ||
| 106 | + * @param NotificationID id | ||
| 107 | + * @param title 标题 | ||
| 108 | + * @param content 内容 | ||
| 109 | + * @param mclass 跳转的页面 | ||
| 110 | + */ | ||
| 111 | + public void initOrdinaryNotification(Context mContext, int NotificationID, int number, String title, String content, String targetId, String chatType, String specialGroupData, Class mclass) { | ||
| 112 | + initOrdinaryNotification(mContext, NotificationID, number, title, content, targetId, chatType, specialGroupData, mclass, null); | ||
| 113 | + } | ||
| 114 | + | ||
| 115 | + public void initOrdinaryNotification(Context mContext, int NotificationID, int number, String title, String content, String targetId, String chatType, String specialGroupData, Class mclass, boolean showBigTextStyle) { | ||
| 116 | + initOrdinaryNotification(mContext, NotificationID, number, title, content, targetId, chatType, specialGroupData, mclass, null, showBigTextStyle); | ||
| 117 | + } | ||
| 118 | + | ||
| 119 | + | ||
| 120 | + public void initOrdinaryNotification(Context mContext, int NotificationID, int number, String title, String content, String targetId, String chatType, String specialGroupData, Class mclass, | ||
| 121 | + Class mainClass) { | ||
| 122 | + initOrdinaryNotification(mContext, NotificationID, number, title, content, targetId, chatType, specialGroupData, mclass, mainClass, false); | ||
| 123 | + } | ||
| 124 | + | ||
| 125 | + public void initOrdinaryNotification(Context mContext, int NotificationID, int number, String title, String content, String targetId, String chatType, String specialGroupData, Class mclass, | ||
| 126 | + Class mainClass, boolean showBigTextStyle) { | ||
| 127 | + List<Intent> intents = new ArrayList<Intent>(); | ||
| 128 | + | ||
| 129 | + if (mainClass != null) { | ||
| 130 | + Intent intentMain = new Intent(mContext, mainClass); | ||
| 131 | + intentMain.putExtra("showFirstTab", true); | ||
| 132 | + intents.add(intentMain); | ||
| 133 | + } | ||
| 134 | + | ||
| 135 | + if (null != targetId && !"".equals(targetId)) { | ||
| 136 | + Intent intent = new Intent(mContext, mclass); | ||
| 137 | + intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); | ||
| 138 | + intent.putExtra("targetId", targetId); | ||
| 139 | + intent.putExtra("chatType", chatType); | ||
| 140 | + intent.putExtra("conversationName", title); | ||
| 141 | + intent.putExtra("specialGroupData", specialGroupData); | ||
| 142 | + intents.add(intent); | ||
| 143 | + } else { | ||
| 144 | + Intent intent = new Intent(mContext, mclass); | ||
| 145 | + intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); | ||
| 146 | + intents.add(intent); | ||
| 147 | + } | ||
| 148 | + initOrdinaryNotification(mContext, NotificationID, number, title, content, targetId, chatType, specialGroupData, intents.toArray(new Intent[]{}), showBigTextStyle); | ||
| 149 | + } | ||
| 150 | + | ||
| 151 | + public void initOrdinaryNotification(Context mContext, int NotificationID, int number, String title, String content, String targetId, String chatType, String specialGroupData, Intent[] intents) { | ||
| 152 | + initOrdinaryNotification(mContext, NotificationID, number, title, content, targetId, chatType, specialGroupData, intents, false); | ||
| 153 | + } | ||
| 154 | + | ||
| 155 | + public void initOrdinaryNotification(Context mContext, int NotificationID, int number, String title, String content, String targetId, String chatType, String specialGroupData, Intent[] intents, boolean showBigTextStyle) { | ||
| 156 | + initOrdinaryNotification(mContext, NotificationID, number, title, content, targetId, chatType, specialGroupData, intents, showBigTextStyle, null); | ||
| 157 | + } | ||
| 158 | + | ||
| 159 | + public void initOrdinaryNotification(Context mContext, int NotificationID, int number, String title, String content, String targetId, String chatType, String specialGroupData, Intent[] intents, boolean showBigTextStyle, String summary) { | ||
| 160 | + NotificationManager mNotificationManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE); | ||
| 161 | + Notification.Builder mBulider = null; | ||
| 162 | + if (mNotificationManager == null) return; | ||
| 163 | + if (null == title || "".equals(title)) { | ||
| 164 | + title = "新消息"; | ||
| 165 | + } | ||
| 166 | + | ||
| 167 | + if (Build.VERSION.SDK_INT >= 26) { | ||
| 168 | + try { | ||
| 169 | + if (NotificationID == -1) this.mNotificationID = NotificationID; | ||
| 170 | + if (TextUtils.isEmpty(title)) title = "中国 网家家"; | ||
| 171 | + NotificationChannel channel = new NotificationChannel(mNotificationID + "", | ||
| 172 | + "消息", NotificationManager.IMPORTANCE_DEFAULT); | ||
| 173 | + channel.enableLights(true); | ||
| 174 | + channel.setLightColor(Color.GREEN); | ||
| 175 | + channel.setShowBadge(true); | ||
| 176 | + channel.enableVibration(true); | ||
| 177 | + channel.setDescription("会话消息通知"); | ||
| 178 | + channel.setVibrationPattern(pattern); | ||
| 179 | + if (channel != null) { | ||
| 180 | + mNotificationManager.createNotificationChannel(channel); | ||
| 181 | + mBulider = new Notification.Builder(mContext, mNotificationID + ""); | ||
| 182 | + mBulider.setShowWhen(true); | ||
| 183 | + } | ||
| 184 | + | ||
| 185 | + } catch (Exception e) { | ||
| 186 | + Log.e("推送适配8.0异常*************:", e.getMessage()); | ||
| 187 | + } | ||
| 188 | + } else { | ||
| 189 | + mBulider = new Notification.Builder(mContext); //与channelId对应 | ||
| 190 | + if (Build.VERSION.SDK_INT > 16) { | ||
| 191 | + mBulider.setShowWhen(true); | ||
| 192 | + } | ||
| 193 | + } | ||
| 194 | + | ||
| 195 | + PendingIntent pi = PendingIntent.getActivities(mContext, 0, intents, PendingIntent.FLAG_CANCEL_CURRENT); | ||
| 196 | + //处理 多个通知同时触发的状况 一秒内通知不触发 设置声音的操作 | ||
| 197 | + if (System.currentTimeMillis() - notificationTime > 1000) | ||
| 198 | + mBulider.setDefaults(Notification.DEFAULT_SOUND); | ||
| 199 | + else | ||
| 200 | + mBulider.setDefaults(Notification.DEFAULT_VIBRATE); | ||
| 201 | + Uri notificationUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); | ||
| 202 | + | ||
| 203 | + mBulider | ||
| 204 | + .setSmallIcon(R.drawable.ic_notifi) | ||
| 205 | + .setTicker(title) | ||
| 206 | + .setWhen(System.currentTimeMillis())//设置通知时间,一般设置的是收到通知时的System.currentTimeMillis() | ||
| 207 | + .setContentTitle(title) | ||
| 208 | + .setContentText(content) | ||
| 209 | + .setSound(notificationUri) | ||
| 210 | + .setContentIntent(pi); | ||
| 211 | + if (showBigTextStyle) { | ||
| 212 | + //创建大文本样式 | ||
| 213 | + Notification.BigTextStyle bigTextStyle = new Notification.BigTextStyle(); | ||
| 214 | + bigTextStyle | ||
| 215 | + .setBigContentTitle(title) | ||
| 216 | + .bigText(content); | ||
| 217 | + if (!TextUtils.isEmpty(summary)) bigTextStyle.setSummaryText(summary); | ||
| 218 | + mBulider.setStyle(bigTextStyle); //设置大文本样式 | ||
| 219 | + } | ||
| 220 | + | ||
| 221 | + Notification notification = mBulider.build(); //创建通知栏对象,显示通知信息 | ||
| 222 | + notification.flags |= Notification.FLAG_AUTO_CANCEL; | ||
| 223 | + BadgeUtil.sendBadgeNotification(notification, NotificationID, mContext, number, 0); //设置角标 | ||
| 224 | + | ||
| 225 | + notificationTime = System.currentTimeMillis(); | ||
| 226 | + } | ||
| 227 | + | ||
| 228 | + /** | ||
| 229 | + * Notification 更新进度 | ||
| 230 | + * | ||
| 231 | + * @param progress | ||
| 232 | + */ | ||
| 233 | + public void upProgress(Context context, int progress) { | ||
| 234 | + // 这里是处理 Notification 频繁更新卡顿问题.(部分手机可以开线程 小部分手机不兼容 华为p8 不兼容) | ||
| 235 | + if (progress % 5 == 0) { | ||
| 236 | + builder.setProgress(100, progress, false); | ||
| 237 | + NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); | ||
| 238 | + if (mNotificationManager != null) | ||
| 239 | + mNotificationManager.notify(mNotificationID, builder.build()); | ||
| 240 | + } | ||
| 241 | + } | ||
| 242 | + | ||
| 243 | + /** | ||
| 244 | + * 代码取消 Notification | ||
| 245 | + * | ||
| 246 | + * @param context | ||
| 247 | + */ | ||
| 248 | + public void cancleNotification(Context context) { | ||
| 249 | + if (context == null) return; | ||
| 250 | + try { | ||
| 251 | + NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); | ||
| 252 | + if (mNotificationManager != null) mNotificationManager.cancel(mNotificationID); | ||
| 253 | + if (builder != null) builder = null; | ||
| 254 | + } catch (Exception e) { | ||
| 255 | + } | ||
| 256 | + | ||
| 257 | + | ||
| 258 | + } | ||
| 259 | + | ||
| 260 | + /** | ||
| 261 | + * 代码取消 Notification | ||
| 262 | + * | ||
| 263 | + * @param context | ||
| 264 | + */ | ||
| 265 | + public void cancleNotification(Context context, int notificationId) { | ||
| 266 | + if (context == null) return; | ||
| 267 | + try { | ||
| 268 | + NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); | ||
| 269 | + if (mNotificationManager != null) mNotificationManager.cancel(notificationId); | ||
| 270 | + if (builder != null) builder = null; | ||
| 271 | + } catch (Exception e) { | ||
| 272 | + } | ||
| 273 | + | ||
| 274 | + | ||
| 275 | + } | ||
| 276 | + | ||
| 277 | + /** | ||
| 278 | + * 代码取消App发送的所有Notification(不包含app进程结束后 小米sdk 华为sdk 魅族sdk 发送的离线推送) | ||
| 279 | + * | ||
| 280 | + * @param context | ||
| 281 | + */ | ||
| 282 | + public void cancleAllNotification(Context context) { | ||
| 283 | + try { | ||
| 284 | + NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); | ||
| 285 | + notificationManager.cancelAll(); | ||
| 286 | + } catch (Exception e) { | ||
| 287 | + | ||
| 288 | + } | ||
| 289 | + | ||
| 290 | + } | ||
| 291 | + | ||
| 292 | + /** | ||
| 293 | + * 拉起 App安装器 | ||
| 294 | + * | ||
| 295 | + * @param mContext | ||
| 296 | + * @param content | ||
| 297 | + * @param apkFile 文件 | ||
| 298 | + */ | ||
| 299 | + public void updateSucess(Context mContext, String content, File apkFile) { | ||
| 300 | + Intent installIntent = new Intent(Intent.ACTION_VIEW); | ||
| 301 | + installIntent.setAction(Intent.ACTION_VIEW); | ||
| 302 | + installIntent.addCategory(Intent.CATEGORY_DEFAULT); | ||
| 303 | + installIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); | ||
| 304 | + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { | ||
| 305 | + //判读版本是否在7.0以上 | ||
| 306 | + String authority = mContext.getApplicationInfo().packageName + ".fileprovider"; | ||
| 307 | + //添加这一句表示对目标应用临时授权该Uri所代表的文件 | ||
| 308 | + installIntent.setDataAndType(FileProvider.getUriForFile(mContext, authority, apkFile), "application/vnd.android.package-archive"); | ||
| 309 | + installIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); | ||
| 310 | + } else { | ||
| 311 | + installIntent.setDataAndType(Uri.fromFile(apkFile), "application/vnd.android.package-archive"); | ||
| 312 | + } | ||
| 313 | + //隐式意图拉起安装器 | ||
| 314 | + PendingIntent mPendingIntent = PendingIntent.getActivity(mContext, 0, installIntent, 0); | ||
| 315 | + builder.setContentText(content); | ||
| 316 | + builder.setContentIntent(mPendingIntent); | ||
| 317 | + NotificationManager mNotificationManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE); | ||
| 318 | + if (mNotificationManager != null) | ||
| 319 | + mNotificationManager.notify(mNotificationID, builder.build()); | ||
| 320 | + mContext.startActivity(installIntent);// 下载完成之后自动弹出安装界面 | ||
| 321 | + cancleNotification(mContext); | ||
| 322 | + } | ||
| 323 | + | ||
| 324 | + /** | ||
| 325 | + * 判断通知是否开启 | ||
| 326 | + * | ||
| 327 | + * @param context | ||
| 328 | + * @return | ||
| 329 | + */ | ||
| 330 | + public boolean isNotificationEnabled(Context context) { | ||
| 331 | + ApplicationInfo appInfo = context.getApplicationInfo(); | ||
| 332 | + String pkg = context.getApplicationContext().getPackageName(); | ||
| 333 | + int uid = appInfo.uid; | ||
| 334 | + if (Build.VERSION.SDK_INT >= 26) { | ||
| 335 | + return isEnableV26(context, pkg, uid); | ||
| 336 | + } else { | ||
| 337 | + return isEnableV19(context, pkg, uid); | ||
| 338 | + } | ||
| 339 | + | ||
| 340 | + } | ||
| 341 | + | ||
| 342 | + @RequiresApi(api = Build.VERSION_CODES.KITKAT) | ||
| 343 | + private static boolean isEnableV19(Context context, String pkg, int uid) { | ||
| 344 | + try { | ||
| 345 | + String CHECK_OP_NO_THROW = "checkOpNoThrow"; | ||
| 346 | + String OP_POST_NOTIFICATION = "OP_POST_NOTIFICATION"; | ||
| 347 | + Class appOpsClass = null; | ||
| 348 | + AppOpsManager mAppOps = null; | ||
| 349 | + mAppOps = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE); | ||
| 350 | + appOpsClass = Class.forName(AppOpsManager.class.getName()); | ||
| 351 | + Method checkOpNoThrowMethod = appOpsClass.getMethod(CHECK_OP_NO_THROW, Integer.TYPE, | ||
| 352 | + Integer.TYPE, String.class); | ||
| 353 | + Field opPostNotificationValue = appOpsClass.getDeclaredField(OP_POST_NOTIFICATION); | ||
| 354 | + | ||
| 355 | + int value = (Integer) opPostNotificationValue.get(Integer.class); | ||
| 356 | + return ((Integer) checkOpNoThrowMethod.invoke(mAppOps, value, uid, pkg) == | ||
| 357 | + AppOpsManager.MODE_ALLOWED); | ||
| 358 | + } catch (Exception e) { | ||
| 359 | + return true; | ||
| 360 | + } | ||
| 361 | + } | ||
| 362 | + | ||
| 363 | + private static boolean isEnableV26(Context context, String pkg, int uid) { | ||
| 364 | + try { | ||
| 365 | + NotificationManager notificationManager = (NotificationManager) | ||
| 366 | + context.getSystemService(Context.NOTIFICATION_SERVICE); | ||
| 367 | + Method sServiceField = notificationManager.getClass().getDeclaredMethod("getService"); | ||
| 368 | + sServiceField.setAccessible(true); | ||
| 369 | + Object sService = sServiceField.invoke(notificationManager); | ||
| 370 | + | ||
| 371 | + Method method = sService.getClass().getDeclaredMethod("areNotificationsEnabledForPackage" | ||
| 372 | + , String.class, Integer.TYPE); | ||
| 373 | + method.setAccessible(true); | ||
| 374 | + return (boolean) method.invoke(sService, pkg, uid); | ||
| 375 | + } catch (Exception e) { | ||
| 376 | + return true; | ||
| 377 | + } | ||
| 378 | + } | ||
| 379 | + | ||
| 380 | + /** | ||
| 381 | + * 设置通知权限 | ||
| 382 | + * | ||
| 383 | + * @param context | ||
| 384 | + */ | ||
| 385 | + public void gotoSet(Context context) { | ||
| 386 | + Intent intent = new Intent(); | ||
| 387 | + if (Build.VERSION.SDK_INT >= 26) { | ||
| 388 | + // android 8.0引导 | ||
| 389 | + intent.setAction("android.settings.APP_NOTIFICATION_SETTINGS"); | ||
| 390 | + intent.putExtra("android.provider.extra.APP_PACKAGE", context.getPackageName()); | ||
| 391 | + } else if (Build.VERSION.SDK_INT >= 21) { | ||
| 392 | + // android 5.0-7.0 | ||
| 393 | + intent.setAction("android.settings.APP_NOTIFICATION_SETTINGS"); | ||
| 394 | + intent.putExtra("app_package", context.getPackageName()); | ||
| 395 | + intent.putExtra("app_uid", context.getApplicationInfo().uid); | ||
| 396 | + } else { | ||
| 397 | + // 其他 | ||
| 398 | + intent.setAction("android.settings.APPLICATION_DETAILS_SETTINGS"); | ||
| 399 | + intent.setData(Uri.fromParts("package", context.getPackageName(), null)); | ||
| 400 | + } | ||
| 401 | + intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); | ||
| 402 | + context.startActivity(intent); | ||
| 403 | + | ||
| 404 | + } | ||
| 405 | +} | ||
| 0 | \ No newline at end of file | 406 | \ No newline at end of file |
cloud/wjj_lib/src/main/java/com/cnlive/libs/base/util/OpenServiceHelpUtil.java
0 → 100644
| 1 | +package com.cnlive.libs.base.util; | ||
| 2 | + | ||
| 3 | +import android.content.Context; | ||
| 4 | + | ||
| 5 | +import com.alibaba.android.arouter.launcher.ARouter; | ||
| 6 | +import com.cnlive.libs.base.arouter.ar.CNLiveArService; | ||
| 7 | +import com.cnlive.libs.base.arouter.pay.CNLivePayService; | ||
| 8 | +import com.cnlive.libs.base.arouter.share.CNLiveShareService; | ||
| 9 | +import com.cnlive.libs.base.arouter.user.CNLiveUserService; | ||
| 10 | +import com.cnlive.libs.base.arouter.user.OpenUserService; | ||
| 11 | +import com.cnlive.libs.base.logic.Config; | ||
| 12 | + | ||
| 13 | +public class OpenServiceHelpUtil { | ||
| 14 | + /** | ||
| 15 | + * 获取AR服务 | ||
| 16 | + * | ||
| 17 | + * @param context | ||
| 18 | + * @return | ||
| 19 | + */ | ||
| 20 | + public static CNLiveArService getArService(Context context) { | ||
| 21 | + CNLiveArService cnLiveArService = null; | ||
| 22 | + cnLiveArService = (CNLiveArService) ARouter.getInstance().build(CNLiveArService.PATH).navigation(context); | ||
| 23 | + return cnLiveArService; | ||
| 24 | + } | ||
| 25 | + | ||
| 26 | + /** | ||
| 27 | + * 获取用户库 | ||
| 28 | + * | ||
| 29 | + * @param context | ||
| 30 | + * @return | ||
| 31 | + */ | ||
| 32 | + public static CNLiveUserService getUserService(Context context) { | ||
| 33 | + CNLiveUserService cnLiveUserService = null; | ||
| 34 | + cnLiveUserService = (CNLiveUserService) ARouter.getInstance().build(CNLiveUserService.PATH).navigation(context); | ||
| 35 | + return cnLiveUserService; | ||
| 36 | + } | ||
| 37 | + | ||
| 38 | + /** | ||
| 39 | + * 获取支付库 | ||
| 40 | + * | ||
| 41 | + * @param context | ||
| 42 | + * @return | ||
| 43 | + */ | ||
| 44 | + public static CNLivePayService getPayService(Context context) { | ||
| 45 | + CNLivePayService cnLivePayService = null; | ||
| 46 | + cnLivePayService = (CNLivePayService) ARouter.getInstance().build(CNLivePayService.PATH).navigation(context); | ||
| 47 | + return cnLivePayService; | ||
| 48 | + } | ||
| 49 | + | ||
| 50 | + /** | ||
| 51 | + * 获取分享库 | ||
| 52 | + * | ||
| 53 | + * @param context | ||
| 54 | + * @return | ||
| 55 | + */ | ||
| 56 | + public static CNLiveShareService getShareService(Context context) { | ||
| 57 | + CNLiveShareService cnLiveShareService = null; | ||
| 58 | + cnLiveShareService = (CNLiveShareService) ARouter.getInstance().build(CNLiveShareService.PATH).navigation(context); | ||
| 59 | + return cnLiveShareService; | ||
| 60 | + } | ||
| 61 | +} |
cloud/wjj_lib/src/main/java/com/cnlive/libs/base/util/PixelsUtil.java
0 → 100644
| 1 | +package com.cnlive.libs.base.util; | ||
| 2 | + | ||
| 3 | +import android.content.res.Resources; | ||
| 4 | +import android.util.TypedValue; | ||
| 5 | + | ||
| 6 | +public class PixelsUtil { | ||
| 7 | + public PixelsUtil() { | ||
| 8 | + } | ||
| 9 | + | ||
| 10 | + public static int dip2px(float dipValue) { | ||
| 11 | + float scale = Resources.getSystem().getDisplayMetrics().density; | ||
| 12 | + return (int)(dipValue * scale + 0.5F); | ||
| 13 | + } | ||
| 14 | + | ||
| 15 | + public static int px2dip(float pxValue) { | ||
| 16 | + float scale = Resources.getSystem().getDisplayMetrics().density; | ||
| 17 | + return (int)(pxValue / scale + 0.5F); | ||
| 18 | + } | ||
| 19 | + | ||
| 20 | + public static int sp2px(float spVal) { | ||
| 21 | + return (int)TypedValue.applyDimension(2, spVal, Resources.getSystem().getDisplayMetrics()); | ||
| 22 | + } | ||
| 23 | + | ||
| 24 | + public static float px2sp(float pxVal) { | ||
| 25 | + return pxVal / Resources.getSystem().getDisplayMetrics().scaledDensity; | ||
| 26 | + } | ||
| 27 | + | ||
| 28 | + /** | ||
| 29 | + * 根据手机的分辨率从 dp 的单位 转成为 px(像素) | ||
| 30 | + * @param dpValue 虚拟像素 | ||
| 31 | + * @return 像素 | ||
| 32 | + */ | ||
| 33 | + public static int dp2px(float dpValue) { | ||
| 34 | + return (int) (0.5f + dpValue * Resources.getSystem().getDisplayMetrics().density); | ||
| 35 | + } | ||
| 36 | +} |
cloud/wjj_lib/src/main/java/com/cnlive/libs/base/util/ProbeUtils.java
0 → 100644
| 1 | +package com.cnlive.libs.base.util; | ||
| 2 | + | ||
| 3 | +import com.cnlive.libs.util.ProbeUtil; | ||
| 4 | + | ||
| 5 | +/** | ||
| 6 | + * Created by Lynn on 2018/8/10. | ||
| 7 | + * 探针 | ||
| 8 | + */ | ||
| 9 | + | ||
| 10 | +public class ProbeUtils { | ||
| 11 | + private static String EVENT_ID = "2200"; | ||
| 12 | + private static String SDK_WJIAJIA = "2010"; | ||
| 13 | + private static String SDK_VERSION = "1.0"; | ||
| 14 | + | ||
| 15 | + public static void probeUploadVideo() { | ||
| 16 | + ProbeUtil.probeApp(SDK_WJIAJIA, SDK_VERSION, EVENT_ID, null, null, null); | ||
| 17 | + } | ||
| 18 | +} |
cloud/wjj_lib/src/main/java/com/cnlive/libs/base/util/ShareReleaseInfoUtil.java
0 → 100644
| 1 | +package com.cnlive.libs.base.util; | ||
| 2 | + | ||
| 3 | +import android.content.Context; | ||
| 4 | +import android.content.Intent; | ||
| 5 | +import android.net.Uri; | ||
| 6 | + | ||
| 7 | +import com.cnlive.libs.base.application.AppConfig; | ||
| 8 | + | ||
| 9 | +import java.io.Serializable; | ||
| 10 | + | ||
| 11 | +public class ShareReleaseInfoUtil { | ||
| 12 | + | ||
| 13 | + public static final String SHARE_TYPE = "strike.intent.extra.TYPE"; | ||
| 14 | + public static final String SHARE_IMAGE = "strike.intent.extra.IMAGE"; | ||
| 15 | + | ||
| 16 | + public static final String ACTION_SHARE_SEND = "netpp.intent.action.SHARE_SEND"; | ||
| 17 | + public static final String ACTION_SHARE_RELEASE = "netpp.intent.action.SHARE_RELEASE"; | ||
| 18 | + | ||
| 19 | + //分享类型 | ||
| 20 | + public static final String TYPE_HTML = "strike.intent.type.HTML"; | ||
| 21 | + | ||
| 22 | + private ShareConfig config; | ||
| 23 | + | ||
| 24 | + public static final class ShareConfig implements Serializable { | ||
| 25 | + | ||
| 26 | + public static ShareConfig newInstance() { | ||
| 27 | + return new ShareConfig(); | ||
| 28 | + } | ||
| 29 | + | ||
| 30 | + public static ShareConfig parse(Intent intent) { | ||
| 31 | + if (intent == null) return new ShareConfig(); | ||
| 32 | + | ||
| 33 | + String title = intent.getStringExtra(Intent.EXTRA_TITLE); | ||
| 34 | + String subTitle = intent.getStringExtra(Intent.EXTRA_TEXT); | ||
| 35 | + String url = intent.getStringExtra(Intent.EXTRA_SUBJECT); | ||
| 36 | + String type = intent.getStringExtra(ShareReleaseInfoUtil.SHARE_TYPE); | ||
| 37 | + String image = intent.getStringExtra(ShareReleaseInfoUtil.SHARE_IMAGE); | ||
| 38 | + | ||
| 39 | + return new ShareConfig(title, subTitle, image, url, type); | ||
| 40 | + } | ||
| 41 | + | ||
| 42 | + private ShareConfig() { | ||
| 43 | + | ||
| 44 | + } | ||
| 45 | + | ||
| 46 | + private ShareConfig(String title, String subTitle, String image, String url, String type) { | ||
| 47 | + this.title = title; | ||
| 48 | + this.subTitle = subTitle; | ||
| 49 | + this.image = image; | ||
| 50 | + this.url = url; | ||
| 51 | + this.type = type; | ||
| 52 | + } | ||
| 53 | + | ||
| 54 | + //分享标题 | ||
| 55 | + private String title = ""; | ||
| 56 | + //分享副标题 | ||
| 57 | + private String subTitle = ""; | ||
| 58 | + //分享图标 | ||
| 59 | + private String image = ""; | ||
| 60 | + //分享URL地址 | ||
| 61 | + private String url = ""; | ||
| 62 | + //分享类型 | ||
| 63 | + private String type = ""; | ||
| 64 | + //分享文件地址(通过输入流读取) | ||
| 65 | + private Uri uri; | ||
| 66 | + | ||
| 67 | + public ShareReleaseInfoUtil build() { | ||
| 68 | + return new ShareReleaseInfoUtil(this); | ||
| 69 | + } | ||
| 70 | + | ||
| 71 | + public void shareSend(Context context) { | ||
| 72 | + new ShareReleaseInfoUtil(this).share(context, ACTION_SHARE_SEND); | ||
| 73 | + } | ||
| 74 | + | ||
| 75 | + public void shareRelease(Context context) { | ||
| 76 | + new ShareReleaseInfoUtil(this).share(context, ACTION_SHARE_RELEASE); | ||
| 77 | + } | ||
| 78 | + | ||
| 79 | + public String getTitle() { | ||
| 80 | + return title; | ||
| 81 | + } | ||
| 82 | + | ||
| 83 | + public ShareConfig setTitle(String title) { | ||
| 84 | + this.title = title; | ||
| 85 | + return this; | ||
| 86 | + } | ||
| 87 | + | ||
| 88 | + public String getSubTitle() { | ||
| 89 | + return subTitle; | ||
| 90 | + } | ||
| 91 | + | ||
| 92 | + public ShareConfig setSubTitle(String subTitle) { | ||
| 93 | + this.subTitle = subTitle; | ||
| 94 | + return this; | ||
| 95 | + } | ||
| 96 | + | ||
| 97 | + public String getImage() { | ||
| 98 | + return image; | ||
| 99 | + } | ||
| 100 | + | ||
| 101 | + public ShareConfig setImage(String image) { | ||
| 102 | + this.image = image; | ||
| 103 | + return this; | ||
| 104 | + } | ||
| 105 | + | ||
| 106 | + public String getUrl() { | ||
| 107 | + return url; | ||
| 108 | + } | ||
| 109 | + | ||
| 110 | + public ShareConfig setUrl(String url) { | ||
| 111 | + this.url = url; | ||
| 112 | + return this; | ||
| 113 | + } | ||
| 114 | + | ||
| 115 | + public String getType() { | ||
| 116 | + return type; | ||
| 117 | + } | ||
| 118 | + | ||
| 119 | + public ShareConfig setType(String type) { | ||
| 120 | + this.type = type; | ||
| 121 | + return this; | ||
| 122 | + } | ||
| 123 | + | ||
| 124 | + public Uri getUri() { | ||
| 125 | + return uri; | ||
| 126 | + } | ||
| 127 | + | ||
| 128 | + public void setUri(Uri uri) { | ||
| 129 | + this.uri = uri; | ||
| 130 | + } | ||
| 131 | + } | ||
| 132 | + | ||
| 133 | + private ShareReleaseInfoUtil(ShareConfig config) { | ||
| 134 | + this.config = config; | ||
| 135 | + } | ||
| 136 | + | ||
| 137 | + public void shareSend(Context context) { | ||
| 138 | + share(context, ACTION_SHARE_SEND); | ||
| 139 | + } | ||
| 140 | + | ||
| 141 | + public void shareRelease(Context context) { | ||
| 142 | + share(context, ACTION_SHARE_RELEASE); | ||
| 143 | + } | ||
| 144 | + | ||
| 145 | + public void share(Context context, String action) { | ||
| 146 | + Intent intent = new Intent(action); | ||
| 147 | + intent.setPackage(AppConfig.getAppPackeg()); | ||
| 148 | + intent.setType("text/plain"); | ||
| 149 | + intent.putExtra(Intent.EXTRA_TITLE, config.title); | ||
| 150 | + intent.putExtra(Intent.EXTRA_TEXT, config.subTitle); | ||
| 151 | + intent.putExtra(Intent.EXTRA_SUBJECT, config.url); | ||
| 152 | + intent.putExtra(ShareReleaseInfoUtil.SHARE_TYPE, config.type); | ||
| 153 | + intent.putExtra(ShareReleaseInfoUtil.SHARE_IMAGE, config.image); | ||
| 154 | + context.startActivity(intent); | ||
| 155 | + } | ||
| 156 | +} |
cloud/wjj_lib/src/main/java/com/cnlive/libs/base/util/SharedPreferencesHelper.java
0 → 100644
| 1 | +package com.cnlive.libs.base.util; | ||
| 2 | + | ||
| 3 | +import android.content.Context; | ||
| 4 | +import android.content.SharedPreferences; | ||
| 5 | +import android.content.SharedPreferences.Editor; | ||
| 6 | +import java.util.Set; | ||
| 7 | + | ||
| 8 | +public class SharedPreferencesHelper { | ||
| 9 | + public static SharedPreferencesHelper instance; | ||
| 10 | + protected Context mContext; | ||
| 11 | + protected SharedPreferences sharedPreferences; | ||
| 12 | + | ||
| 13 | + private SharedPreferencesHelper(Context var1) { | ||
| 14 | + this.mContext = var1; | ||
| 15 | + this.sharedPreferences = this.mContext.getSharedPreferences(var1.getPackageName(), 0); | ||
| 16 | + } | ||
| 17 | + | ||
| 18 | + public static synchronized SharedPreferencesHelper getInstance(Context var0) { | ||
| 19 | + if(null == var0) { | ||
| 20 | + return null; | ||
| 21 | + } else { | ||
| 22 | + if(null == instance) { | ||
| 23 | + instance = new SharedPreferencesHelper(var0.getApplicationContext()); | ||
| 24 | + } | ||
| 25 | + | ||
| 26 | + return instance; | ||
| 27 | + } | ||
| 28 | + } | ||
| 29 | + | ||
| 30 | + public String getValue(String var1) { | ||
| 31 | + return this.sharedPreferences.getString(var1, ""); | ||
| 32 | + } | ||
| 33 | + | ||
| 34 | + public Boolean getBoolValue(String var1) { | ||
| 35 | + return Boolean.valueOf(this.sharedPreferences.getBoolean(var1, false)); | ||
| 36 | + } | ||
| 37 | + | ||
| 38 | + public Boolean getBoolean(String var1, boolean var2) { | ||
| 39 | + return Boolean.valueOf(this.sharedPreferences.getBoolean(var1, var2)); | ||
| 40 | + } | ||
| 41 | + | ||
| 42 | + public Long getLong(String var1) { | ||
| 43 | + return Long.valueOf(this.sharedPreferences.getLong(var1, 0L)); | ||
| 44 | + } | ||
| 45 | + | ||
| 46 | + public int getIntValue(String var1) { | ||
| 47 | + return this.sharedPreferences.getInt(var1, 0); | ||
| 48 | + } | ||
| 49 | + | ||
| 50 | + public int getIntValue(String var1, int var2) { | ||
| 51 | + return this.sharedPreferences.getInt(var1, var2); | ||
| 52 | + } | ||
| 53 | + | ||
| 54 | + public void setValue(String var1, Boolean var2) { | ||
| 55 | + Editor var3 = this.sharedPreferences.edit(); | ||
| 56 | + var3.putBoolean(var1, var2.booleanValue()); | ||
| 57 | + var3.apply(); | ||
| 58 | + } | ||
| 59 | + | ||
| 60 | + public void setValue(String var1, String var2) { | ||
| 61 | + Editor var3 = this.sharedPreferences.edit(); | ||
| 62 | + var3.putString(var1, var2); | ||
| 63 | + var3.apply(); | ||
| 64 | + } | ||
| 65 | + | ||
| 66 | + public void setValue(String var1, int var2) { | ||
| 67 | + Editor var3 = this.sharedPreferences.edit(); | ||
| 68 | + var3.putInt(var1, var2); | ||
| 69 | + var3.apply(); | ||
| 70 | + } | ||
| 71 | + | ||
| 72 | + public void setValue(String var1, long var2) { | ||
| 73 | + Editor var4 = this.sharedPreferences.edit(); | ||
| 74 | + var4.putLong(var1, var2); | ||
| 75 | + var4.apply(); | ||
| 76 | + } | ||
| 77 | + | ||
| 78 | + public void remove(String var1) { | ||
| 79 | + Editor var2 = this.sharedPreferences.edit(); | ||
| 80 | + var2.remove(var1); | ||
| 81 | + var2.apply(); | ||
| 82 | + } | ||
| 83 | + | ||
| 84 | + public void clear() { | ||
| 85 | + Editor var1 = this.sharedPreferences.edit(); | ||
| 86 | + var1.clear(); | ||
| 87 | + var1.apply(); | ||
| 88 | + } | ||
| 89 | + | ||
| 90 | + public Set<String> getSaveKeys() { | ||
| 91 | + return this.sharedPreferences.getAll().keySet(); | ||
| 92 | + } | ||
| 93 | + | ||
| 94 | + public boolean contains(String var1) { | ||
| 95 | + return this.sharedPreferences.contains(var1); | ||
| 96 | + } | ||
| 97 | +} |
cloud/wjj_lib/src/main/java/com/cnlive/libs/base/util/SimpleDES.java
0 → 100644
| 1 | +package com.cnlive.libs.base.util; | ||
| 2 | + | ||
| 3 | +import android.util.Base64; | ||
| 4 | + | ||
| 5 | +import java.security.Key; | ||
| 6 | + | ||
| 7 | +import javax.crypto.Cipher; | ||
| 8 | +import javax.crypto.SecretKeyFactory; | ||
| 9 | +import javax.crypto.spec.DESKeySpec; | ||
| 10 | + | ||
| 11 | +import static javax.crypto.Cipher.getInstance; | ||
| 12 | + | ||
| 13 | +/** | ||
| 14 | + * 加密工具 | ||
| 15 | + */ | ||
| 16 | +public class SimpleDES { | ||
| 17 | + //key 的长度得大于8 | ||
| 18 | + public static final String DES_KEY = "cnliveIm"; | ||
| 19 | + private static String encoding = "UTF-8"; | ||
| 20 | + | ||
| 21 | + /** | ||
| 22 | + * 加密字符串 | ||
| 23 | + */ | ||
| 24 | + public static String ebotongEncrypto(String str, String key) { | ||
| 25 | + String result = str; | ||
| 26 | + if (str != null && str.length() > 0) { | ||
| 27 | + try { | ||
| 28 | + byte[] encodeByte = symmetricEncrypto(str.getBytes(encoding), key); | ||
| 29 | + result = Base64.encodeToString(encodeByte,Base64.DEFAULT); | ||
| 30 | + | ||
| 31 | + } catch (Exception e) { | ||
| 32 | + // e.printStackTrace(); | ||
| 33 | + } | ||
| 34 | + } | ||
| 35 | + return result; | ||
| 36 | + } | ||
| 37 | + | ||
| 38 | + /** | ||
| 39 | + * 解密字符串 | ||
| 40 | + */ | ||
| 41 | + public static String ebotongDecrypto(String str, String key) { | ||
| 42 | + String result = str; | ||
| 43 | + if (str != null && str.length() > 0) { | ||
| 44 | + try { | ||
| 45 | + byte[] encodeByte = Base64.decode(str,Base64.DEFAULT); | ||
| 46 | + | ||
| 47 | + byte[] decoder = symmetricDecrypto(encodeByte, key); | ||
| 48 | + result = new String(decoder, encoding); | ||
| 49 | + } catch (Exception e) { | ||
| 50 | + // e.printStackTrace(); | ||
| 51 | + } | ||
| 52 | + } | ||
| 53 | + return result; | ||
| 54 | + } | ||
| 55 | + | ||
| 56 | + /** | ||
| 57 | + * 加密byte[] | ||
| 58 | + */ | ||
| 59 | + public static byte[] ebotongEncrypto(byte[] str, String key) { | ||
| 60 | + byte[] result = null; | ||
| 61 | + if (str != null && str.length > 0) { | ||
| 62 | + try { | ||
| 63 | + byte[] encodeByte = symmetricEncrypto(str, key); | ||
| 64 | + result = Base64.encode(encodeByte, Base64.DEFAULT); | ||
| 65 | + | ||
| 66 | + } catch (Exception e) { | ||
| 67 | + // e.printStackTrace(); | ||
| 68 | + } | ||
| 69 | + } | ||
| 70 | + return result; | ||
| 71 | + } | ||
| 72 | + | ||
| 73 | + /** | ||
| 74 | + * 解密byte[] | ||
| 75 | + */ | ||
| 76 | + public static byte[] ebotongDecrypto(byte[] str, String key) { | ||
| 77 | + byte[] result = null; | ||
| 78 | + if (str != null && str.length > 0) { | ||
| 79 | + try { | ||
| 80 | + | ||
| 81 | + byte[] encodeByte = Base64.decode(new String(str, encoding),Base64.DEFAULT); | ||
| 82 | + //byte[] encodeByte = base64decoder.decodeBuffer(new String(str)); | ||
| 83 | + byte[] decoder = symmetricDecrypto(encodeByte, key); | ||
| 84 | + result = new String(decoder).getBytes(encoding); | ||
| 85 | + result = new String(decoder).getBytes(); | ||
| 86 | + } catch (Exception e) { | ||
| 87 | + // e.printStackTrace(); | ||
| 88 | + } | ||
| 89 | + } | ||
| 90 | + return result; | ||
| 91 | + } | ||
| 92 | + | ||
| 93 | + /** | ||
| 94 | + * 对称加密字节数组并返回 | ||
| 95 | + * | ||
| 96 | + * @param byteSource 需要加密的数据 | ||
| 97 | + * @return 经过加密的数据 | ||
| 98 | + * @throws Exception | ||
| 99 | + */ | ||
| 100 | + public static byte[] symmetricEncrypto(byte[] byteSource, String sKey) throws Exception { | ||
| 101 | + try { | ||
| 102 | + int mode = Cipher.ENCRYPT_MODE; | ||
| 103 | + SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES"); | ||
| 104 | + byte[] keyData = sKey.getBytes(); | ||
| 105 | + DESKeySpec keySpec = new DESKeySpec(keyData); | ||
| 106 | + Key key = keyFactory.generateSecret(keySpec); | ||
| 107 | + Cipher cipher = getInstance("DES"); | ||
| 108 | + cipher.init(mode, key); | ||
| 109 | + | ||
| 110 | + return cipher.doFinal(byteSource); | ||
| 111 | + } catch (Exception e) { | ||
| 112 | + return null; | ||
| 113 | + } | ||
| 114 | + } | ||
| 115 | + | ||
| 116 | + /** | ||
| 117 | + * 对称解密字节数组并返回 | ||
| 118 | + * | ||
| 119 | + * @param byteSource 需要解密的数据 | ||
| 120 | + * @return 经过解密的数据 | ||
| 121 | + * @throws Exception | ||
| 122 | + */ | ||
| 123 | + public static byte[] symmetricDecrypto(byte[] byteSource, String sKey) throws Exception { | ||
| 124 | + try { | ||
| 125 | + int mode = Cipher.DECRYPT_MODE; | ||
| 126 | + SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES"); | ||
| 127 | + byte[] keyData = sKey.getBytes(); | ||
| 128 | + DESKeySpec keySpec = new DESKeySpec(keyData); | ||
| 129 | + Key key = keyFactory.generateSecret(keySpec); | ||
| 130 | + Cipher cipher = getInstance("DES"); | ||
| 131 | + cipher.init(mode, key); | ||
| 132 | + return cipher.doFinal(byteSource); | ||
| 133 | + } catch (Exception e) { | ||
| 134 | + return null; | ||
| 135 | + } | ||
| 136 | + } | ||
| 137 | +} |
cloud/wjj_lib/src/main/java/com/cnlive/libs/base/util/SimpleSharedPreferencesUtil.java
0 → 100644
| 1 | +package com.cnlive.libs.base.util; | ||
| 2 | + | ||
| 3 | +import android.content.Context; | ||
| 4 | +import android.content.SharedPreferences; | ||
| 5 | +import android.text.TextUtils; | ||
| 6 | +import android.util.Log; | ||
| 7 | + | ||
| 8 | +/** | ||
| 9 | + * Sharepreference操作类 | ||
| 10 | + * Code by Conan | ||
| 11 | + * data:2018-10-12 | ||
| 12 | + * | ||
| 13 | + * 使用方法: | ||
| 14 | + * SharepreferenceUtil sharepreference = SharepreferenceUtil.getInstance(String filename); //这里传入null或者""都默认文件名为:AegisFile | ||
| 15 | + * sharepreference.putData("key",Object value); | ||
| 16 | + * sharepreference.getData("key",String.class); //返回值为第二个传入参数类型 | ||
| 17 | + */ | ||
| 18 | +public class SimpleSharedPreferencesUtil { | ||
| 19 | + private static String FILE_NAME = "StrikeFile"; | ||
| 20 | + private static SharedPreferences.Editor editor = null; | ||
| 21 | + private static SharedPreferences sp = null; | ||
| 22 | + private static volatile SimpleSharedPreferencesUtil instance = null; | ||
| 23 | + private static final String TAG = SimpleSharedPreferencesUtil.class.getName(); | ||
| 24 | + | ||
| 25 | + public SimpleSharedPreferencesUtil(Context context,String filename){ | ||
| 26 | + if(filename != null && !TextUtils.isEmpty(filename)){ | ||
| 27 | + FILE_NAME = filename; | ||
| 28 | + }else{ | ||
| 29 | + FILE_NAME = "StrikeFile"; | ||
| 30 | + } | ||
| 31 | + if(context == null){ | ||
| 32 | + return; | ||
| 33 | + } | ||
| 34 | + sp = context.getSharedPreferences(FILE_NAME,Context.MODE_PRIVATE); | ||
| 35 | + editor = sp.edit(); | ||
| 36 | + }; | ||
| 37 | + | ||
| 38 | + /** | ||
| 39 | + * This method is used to set the data for sharepreference | ||
| 40 | + * @param key | ||
| 41 | + * @param value | ||
| 42 | + * @return void | ||
| 43 | + */ | ||
| 44 | + public <T> void putData(String key,T value){ | ||
| 45 | + //判空操作 | ||
| 46 | + if(TextUtils.isEmpty(key) || value == null){ | ||
| 47 | + Log.d(TAG,"保存的字符串为空,请检查"); | ||
| 48 | + return; | ||
| 49 | + } | ||
| 50 | + if(editor == null){ | ||
| 51 | + Log.d(TAG,"editor为空,请检查初始化时context环境变量是否为空"); | ||
| 52 | + } | ||
| 53 | + //写入数据 | ||
| 54 | + if (value instanceof String) { | ||
| 55 | + editor.putString(key, (String) value); | ||
| 56 | + } else if (value instanceof Integer) { | ||
| 57 | + editor.putInt(key, (Integer) value); | ||
| 58 | + } else if (value instanceof Boolean) { | ||
| 59 | + editor.putBoolean(key, (Boolean) value); | ||
| 60 | + } else if (value instanceof Long) { | ||
| 61 | + editor.putLong(key, (Long) value); | ||
| 62 | + } else if (value instanceof Float) { | ||
| 63 | + editor.putFloat(key, (Float) value); | ||
| 64 | + } | ||
| 65 | + editor.commit(); | ||
| 66 | + } | ||
| 67 | + | ||
| 68 | + /** | ||
| 69 | + * This method is used to get the data from sharepreference | ||
| 70 | + * @param key | ||
| 71 | + * @param cls | ||
| 72 | + * @return value | ||
| 73 | + */ | ||
| 74 | + public <T> T getData(String key,Class<T> cls){ | ||
| 75 | + T result = null; | ||
| 76 | + //判空操作 | ||
| 77 | + if(TextUtils.isEmpty(key) || cls == null){ | ||
| 78 | + Log.d(TAG,"读取的key为空,请检查"); | ||
| 79 | + return result; | ||
| 80 | + } | ||
| 81 | + if(sp == null){ | ||
| 82 | + Log.d(TAG,"sp为空,请检查初始化时context环境变量是否为空"); | ||
| 83 | + } | ||
| 84 | + //获取数据 | ||
| 85 | + if (cls.equals(String.class)){ | ||
| 86 | + String str = sp.getString(key,""); | ||
| 87 | + result = (T)str; | ||
| 88 | + }else if(cls.equals(Integer.class)){ | ||
| 89 | + Integer num = sp.getInt(key,0); | ||
| 90 | + result = (T)num; | ||
| 91 | + }else if(cls.equals(Float.class)){ | ||
| 92 | + Float flo = sp.getFloat(key,0.0f); | ||
| 93 | + result = (T)flo; | ||
| 94 | + }else if(cls.equals(Long.class)){ | ||
| 95 | + Long lon = sp.getLong(key,0l); | ||
| 96 | + result = (T)lon; | ||
| 97 | + }else if(cls.equals(Boolean.class)){ | ||
| 98 | + Boolean flag = sp.getBoolean(key,false); | ||
| 99 | + result = (T)flag; | ||
| 100 | + } | ||
| 101 | + return result; | ||
| 102 | + } | ||
| 103 | + | ||
| 104 | + | ||
| 105 | + /** | ||
| 106 | + * This method is used to remove the data from sharepreference | ||
| 107 | + * @param key | ||
| 108 | + * @return value | ||
| 109 | + */ | ||
| 110 | + public void removeData(String key){ | ||
| 111 | + if(editor == null){ | ||
| 112 | + Log.d(TAG,"editor为空,请检查初始化时context环境变量是否为空"); | ||
| 113 | + } | ||
| 114 | + editor.remove(key).commit(); | ||
| 115 | + } | ||
| 116 | + | ||
| 117 | + | ||
| 118 | + /** | ||
| 119 | + * 增加一个写数组的功能,读功能就不写了,读出来的数组根据需求自行split | ||
| 120 | + * 根据传入的key不覆盖,一直追加在后面。用"#"分离每个字符串 | ||
| 121 | + */ | ||
| 122 | + public void putStringArray(String key,String value){ | ||
| 123 | + //判空操作 | ||
| 124 | + if(TextUtils.isEmpty(key) || value == null){ | ||
| 125 | + Log.d(TAG,"保存的字符串为空,请检查"); | ||
| 126 | + return; | ||
| 127 | + } | ||
| 128 | + String result = getData(key,String.class); | ||
| 129 | + //用一个StringBuffer拼接字符串,但StringBuffer不是线程安全的,需要注意 | ||
| 130 | + StringBuffer buffer = new StringBuffer(); | ||
| 131 | + if(!TextUtils.isEmpty(result)){ | ||
| 132 | + buffer.append(result); | ||
| 133 | + buffer.append("#"); | ||
| 134 | + } | ||
| 135 | + buffer.append(value); | ||
| 136 | + putData(key,buffer.toString()); | ||
| 137 | + //清理 | ||
| 138 | + buffer = null; | ||
| 139 | + result = null; | ||
| 140 | + } | ||
| 141 | + | ||
| 142 | + /** | ||
| 143 | + * 从array列表里面删除某个值 | ||
| 144 | + * @param key | ||
| 145 | + * @param value | ||
| 146 | + */ | ||
| 147 | + public void removeStringArray(String key,String value){ | ||
| 148 | + //判空操作 | ||
| 149 | + if(TextUtils.isEmpty(key) || value == null){ | ||
| 150 | + Log.d(TAG,"保存的字符串为空,请检查"); | ||
| 151 | + return; | ||
| 152 | + } | ||
| 153 | + String result = getData(key,String.class); | ||
| 154 | + //用一个StringBuffer拼接字符串,但StringBuffer不是线程安全的,需要注意 | ||
| 155 | + StringBuffer buffer = new StringBuffer(); | ||
| 156 | + if(TextUtils.isEmpty(result)){return;} | ||
| 157 | + String temp[] = result.split("#"); | ||
| 158 | + for(String args:temp){ | ||
| 159 | + if(!value.equals(args)){ | ||
| 160 | + buffer.append(args); | ||
| 161 | + } | ||
| 162 | + } | ||
| 163 | + putData(key,buffer.toString()); | ||
| 164 | + } | ||
| 165 | +} |
cloud/wjj_lib/src/main/java/com/cnlive/libs/base/util/StatusBarUtil.java
0 → 100644
| 1 | +package com.cnlive.libs.base.util; | ||
| 2 | + | ||
| 3 | +import android.annotation.TargetApi; | ||
| 4 | +import android.app.Activity; | ||
| 5 | + | ||
| 6 | +import com.qmuiteam.qmui.util.QMUIStatusBarHelper; | ||
| 7 | + | ||
| 8 | +/** | ||
| 9 | + * 修改状态栏颜色 和字体颜色的方法 | ||
| 10 | + */ | ||
| 11 | + | ||
| 12 | +@SuppressWarnings("unused") | ||
| 13 | +public class StatusBarUtil { | ||
| 14 | + | ||
| 15 | + /** | ||
| 16 | + * 设置状态栏黑色色字体图标 | ||
| 17 | + * 支持 4.4 以上版本 MIUI 和 Flyme,以及 6.0 以上版本的其他 Android | ||
| 18 | + */ | ||
| 19 | + public static void setStatusBarWrite(Activity activity) { | ||
| 20 | + //修改背景色颜色 | ||
| 21 | + QMUIStatusBarHelper.setStatusBarLightMode(activity); | ||
| 22 | + | ||
| 23 | + } | ||
| 24 | + | ||
| 25 | + /** | ||
| 26 | + * 设置状态栏白色字体图标 | ||
| 27 | + * 支持 4.4 以上版本 MIUI 和 Flyme,以及 6.0 以上版本的其他 Android | ||
| 28 | + */ | ||
| 29 | + public static void setStatusBarDarkMode(Activity activity) { | ||
| 30 | + QMUIStatusBarHelper.setStatusBarDarkMode(activity); | ||
| 31 | + | ||
| 32 | + } | ||
| 33 | + | ||
| 34 | + | ||
| 35 | + /** | ||
| 36 | + * @param activity | ||
| 37 | + * @param | ||
| 38 | + */ | ||
| 39 | + @TargetApi(19) | ||
| 40 | + public static void setStatusBar(Activity activity, int colorOn5x) { | ||
| 41 | + //修改背景色颜色 | ||
| 42 | + QMUIStatusBarHelper.translucent(activity, activity.getResources().getColor(colorOn5x)); | ||
| 43 | + //设置 字体颜色为深色字体 | ||
| 44 | + QMUIStatusBarHelper.setStatusBarLightMode(activity); | ||
| 45 | + | ||
| 46 | + } | ||
| 47 | + | ||
| 48 | + | ||
| 49 | +} |
cloud/wjj_lib/src/main/java/com/cnlive/libs/base/util/StatusBarUtil2.java
0 → 100644
| 1 | +package com.cnlive.libs.base.util; | ||
| 2 | + | ||
| 3 | +import android.annotation.TargetApi; | ||
| 4 | +import android.app.Activity; | ||
| 5 | +import android.content.Context; | ||
| 6 | +import android.graphics.Color; | ||
| 7 | +import android.os.Build; | ||
| 8 | +import android.view.View; | ||
| 9 | +import android.view.ViewGroup; | ||
| 10 | +import android.view.Window; | ||
| 11 | +import android.view.WindowManager; | ||
| 12 | +import android.widget.LinearLayout; | ||
| 13 | + | ||
| 14 | +import androidx.annotation.ColorInt; | ||
| 15 | +import androidx.annotation.IntRange; | ||
| 16 | +import androidx.annotation.NonNull; | ||
| 17 | +import androidx.coordinatorlayout.widget.CoordinatorLayout; | ||
| 18 | +import androidx.drawerlayout.widget.DrawerLayout; | ||
| 19 | + | ||
| 20 | +import com.cnlive.libs.base.R; | ||
| 21 | + | ||
| 22 | +import java.lang.reflect.Field; | ||
| 23 | +import java.lang.reflect.Method; | ||
| 24 | + | ||
| 25 | +/** | ||
| 26 | + * Created by Jaeger on 16/2/14. | ||
| 27 | + * <p> | ||
| 28 | + * Email: chjie.jaeger@gmail.com | ||
| 29 | + * GitHub: https://github.com/laobie | ||
| 30 | + */ | ||
| 31 | +public class StatusBarUtil2 { | ||
| 32 | + | ||
| 33 | + public static final int DEFAULT_STATUS_BAR_ALPHA = 112; | ||
| 34 | + private static final int FAKE_STATUS_BAR_VIEW_ID = R.id.statusbarutil_fake_status_bar_view; | ||
| 35 | + private static final int FAKE_TRANSLUCENT_VIEW_ID = R.id.statusbarutil_translucent_view; | ||
| 36 | + private static final int TAG_KEY_HAVE_SET_OFFSET = -123; | ||
| 37 | + | ||
| 38 | + /** | ||
| 39 | + * 设置状态栏颜色 | ||
| 40 | + * | ||
| 41 | + * @param activity 需要设置的 activity | ||
| 42 | + * @param color 状态栏颜色值 | ||
| 43 | + */ | ||
| 44 | + public static void setColor(Activity activity, @ColorInt int color) { | ||
| 45 | + setColor(activity, color, DEFAULT_STATUS_BAR_ALPHA); | ||
| 46 | + } | ||
| 47 | + | ||
| 48 | + /** | ||
| 49 | + * 设置状态栏颜色 | ||
| 50 | + * | ||
| 51 | + * @param activity 需要设置的activity | ||
| 52 | + * @param color 状态栏颜色值 | ||
| 53 | + * @param statusBarAlpha 状态栏透明度 | ||
| 54 | + */ | ||
| 55 | + | ||
| 56 | + public static void setColor(Activity activity, @ColorInt int color, @IntRange(from = 0, to = 255) int statusBarAlpha) { | ||
| 57 | + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { | ||
| 58 | + activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); | ||
| 59 | + activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); | ||
| 60 | + activity.getWindow().setStatusBarColor(calculateStatusColor(color, statusBarAlpha)); | ||
| 61 | + } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { | ||
| 62 | + activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); | ||
| 63 | + ViewGroup decorView = (ViewGroup) activity.getWindow().getDecorView(); | ||
| 64 | + View fakeStatusBarView = decorView.findViewById(FAKE_STATUS_BAR_VIEW_ID); | ||
| 65 | + if (fakeStatusBarView != null) { | ||
| 66 | + if (fakeStatusBarView.getVisibility() == View.GONE) { | ||
| 67 | + fakeStatusBarView.setVisibility(View.VISIBLE); | ||
| 68 | + } | ||
| 69 | + fakeStatusBarView.setBackgroundColor(calculateStatusColor(color, statusBarAlpha)); | ||
| 70 | + } else { | ||
| 71 | + decorView.addView(createStatusBarView(activity, color, statusBarAlpha)); | ||
| 72 | + } | ||
| 73 | + setRootView(activity); | ||
| 74 | + } | ||
| 75 | + } | ||
| 76 | + | ||
| 77 | + /** | ||
| 78 | + * 为滑动返回界面设置状态栏颜色 | ||
| 79 | + * | ||
| 80 | + * @param activity 需要设置的activity | ||
| 81 | + * @param color 状态栏颜色值 | ||
| 82 | + */ | ||
| 83 | + public static void setColorForSwipeBack(Activity activity, int color) { | ||
| 84 | + setColorForSwipeBack(activity, color, DEFAULT_STATUS_BAR_ALPHA); | ||
| 85 | + } | ||
| 86 | + | ||
| 87 | + /** | ||
| 88 | + * 为滑动返回界面设置状态栏颜色 | ||
| 89 | + * | ||
| 90 | + * @param activity 需要设置的activity | ||
| 91 | + * @param color 状态栏颜色值 | ||
| 92 | + * @param statusBarAlpha 状态栏透明度 | ||
| 93 | + */ | ||
| 94 | + public static void setColorForSwipeBack(Activity activity, @ColorInt int color, | ||
| 95 | + @IntRange(from = 0, to = 255) int statusBarAlpha) { | ||
| 96 | + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { | ||
| 97 | + | ||
| 98 | + ViewGroup contentView = ((ViewGroup) activity.findViewById(android.R.id.content)); | ||
| 99 | + View rootView = contentView.getChildAt(0); | ||
| 100 | + int statusBarHeight = getStatusBarHeight(activity); | ||
| 101 | + if (rootView != null && rootView instanceof CoordinatorLayout) { | ||
| 102 | + final CoordinatorLayout coordinatorLayout = (CoordinatorLayout) rootView; | ||
| 103 | + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { | ||
| 104 | + coordinatorLayout.setFitsSystemWindows(false); | ||
| 105 | + contentView.setBackgroundColor(calculateStatusColor(color, statusBarAlpha)); | ||
| 106 | + boolean isNeedRequestLayout = contentView.getPaddingTop() < statusBarHeight; | ||
| 107 | + if (isNeedRequestLayout) { | ||
| 108 | + contentView.setPadding(0, statusBarHeight, 0, 0); | ||
| 109 | + coordinatorLayout.post(new Runnable() { | ||
| 110 | + @Override | ||
| 111 | + public void run() { | ||
| 112 | + coordinatorLayout.requestLayout(); | ||
| 113 | + } | ||
| 114 | + }); | ||
| 115 | + } | ||
| 116 | + } else { | ||
| 117 | + coordinatorLayout.setStatusBarBackgroundColor(calculateStatusColor(color, statusBarAlpha)); | ||
| 118 | + } | ||
| 119 | + } else { | ||
| 120 | + contentView.setPadding(0, statusBarHeight, 0, 0); | ||
| 121 | + contentView.setBackgroundColor(calculateStatusColor(color, statusBarAlpha)); | ||
| 122 | + } | ||
| 123 | + setTransparentForWindow(activity); | ||
| 124 | + } | ||
| 125 | + } | ||
| 126 | + | ||
| 127 | + /** | ||
| 128 | + * 设置状态栏纯色 不加半透明效果 | ||
| 129 | + * | ||
| 130 | + * @param activity 需要设置的 activity | ||
| 131 | + * @param color 状态栏颜色值 | ||
| 132 | + */ | ||
| 133 | + public static void setColorNoTranslucent(Activity activity, @ColorInt int color) { | ||
| 134 | + setColor(activity, color, 0); | ||
| 135 | + } | ||
| 136 | + | ||
| 137 | + /** | ||
| 138 | + * 设置状态栏颜色(5.0以下无半透明效果,不建议使用) | ||
| 139 | + * | ||
| 140 | + * @param activity 需要设置的 activity | ||
| 141 | + * @param color 状态栏颜色值 | ||
| 142 | + */ | ||
| 143 | + @Deprecated | ||
| 144 | + public static void setColorDiff(Activity activity, @ColorInt int color) { | ||
| 145 | + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) { | ||
| 146 | + return; | ||
| 147 | + } | ||
| 148 | + transparentStatusBar(activity); | ||
| 149 | + ViewGroup contentView = (ViewGroup) activity.findViewById(android.R.id.content); | ||
| 150 | + // 移除半透明矩形,以免叠加 | ||
| 151 | + View fakeStatusBarView = contentView.findViewById(FAKE_STATUS_BAR_VIEW_ID); | ||
| 152 | + if (fakeStatusBarView != null) { | ||
| 153 | + if (fakeStatusBarView.getVisibility() == View.GONE) { | ||
| 154 | + fakeStatusBarView.setVisibility(View.VISIBLE); | ||
| 155 | + } | ||
| 156 | + fakeStatusBarView.setBackgroundColor(color); | ||
| 157 | + } else { | ||
| 158 | + contentView.addView(createStatusBarView(activity, color)); | ||
| 159 | + } | ||
| 160 | + setRootView(activity); | ||
| 161 | + } | ||
| 162 | + | ||
| 163 | + /** | ||
| 164 | + * 使状态栏半透明 | ||
| 165 | + * <p> | ||
| 166 | + * 适用于图片作为背景的界面,此时需要图片填充到状态栏 | ||
| 167 | + * | ||
| 168 | + * @param activity 需要设置的activity | ||
| 169 | + */ | ||
| 170 | + public static void setTranslucent(Activity activity) { | ||
| 171 | + setTranslucent(activity, DEFAULT_STATUS_BAR_ALPHA); | ||
| 172 | + } | ||
| 173 | + | ||
| 174 | + /** | ||
| 175 | + * 使状态栏半透明 | ||
| 176 | + * <p> | ||
| 177 | + * 适用于图片作为背景的界面,此时需要图片填充到状态栏 | ||
| 178 | + * | ||
| 179 | + * @param activity 需要设置的activity | ||
| 180 | + * @param statusBarAlpha 状态栏透明度 | ||
| 181 | + */ | ||
| 182 | + public static void setTranslucent(Activity activity, @IntRange(from = 0, to = 255) int statusBarAlpha) { | ||
| 183 | + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) { | ||
| 184 | + return; | ||
| 185 | + } | ||
| 186 | + setTransparent(activity); | ||
| 187 | + addTranslucentView(activity, statusBarAlpha); | ||
| 188 | + } | ||
| 189 | + | ||
| 190 | + /** | ||
| 191 | + * 针对根布局是 CoordinatorLayout, 使状态栏半透明 | ||
| 192 | + * <p> | ||
| 193 | + * 适用于图片作为背景的界面,此时需要图片填充到状态栏 | ||
| 194 | + * | ||
| 195 | + * @param activity 需要设置的activity | ||
| 196 | + * @param statusBarAlpha 状态栏透明度 | ||
| 197 | + */ | ||
| 198 | + public static void setTranslucentForCoordinatorLayout(Activity activity, @IntRange(from = 0, to = 255) int statusBarAlpha) { | ||
| 199 | + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) { | ||
| 200 | + return; | ||
| 201 | + } | ||
| 202 | + transparentStatusBar(activity); | ||
| 203 | + addTranslucentView(activity, statusBarAlpha); | ||
| 204 | + } | ||
| 205 | + | ||
| 206 | + /** | ||
| 207 | + * 设置状态栏全透明 | ||
| 208 | + * | ||
| 209 | + * @param activity 需要设置的activity | ||
| 210 | + */ | ||
| 211 | + public static void setTransparent(Activity activity) { | ||
| 212 | + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) { | ||
| 213 | + return; | ||
| 214 | + } | ||
| 215 | + transparentStatusBar(activity); | ||
| 216 | + setRootView(activity); | ||
| 217 | + } | ||
| 218 | + | ||
| 219 | + /** | ||
| 220 | + * 使状态栏透明(5.0以上半透明效果,不建议使用) | ||
| 221 | + * <p> | ||
| 222 | + * 适用于图片作为背景的界面,此时需要图片填充到状态栏 | ||
| 223 | + * | ||
| 224 | + * @param activity 需要设置的activity | ||
| 225 | + */ | ||
| 226 | + @Deprecated | ||
| 227 | + public static void setTranslucentDiff(Activity activity) { | ||
| 228 | + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { | ||
| 229 | + // 设置状态栏透明 | ||
| 230 | + activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); | ||
| 231 | + setRootView(activity); | ||
| 232 | + } | ||
| 233 | + } | ||
| 234 | + | ||
| 235 | + /** | ||
| 236 | + * 为DrawerLayout 布局设置状态栏变色 | ||
| 237 | + * | ||
| 238 | + * @param activity 需要设置的activity | ||
| 239 | + * @param drawerLayout DrawerLayout | ||
| 240 | + * @param color 状态栏颜色值 | ||
| 241 | + */ | ||
| 242 | + public static void setColorForDrawerLayout(Activity activity, DrawerLayout drawerLayout, @ColorInt int color) { | ||
| 243 | + setColorForDrawerLayout(activity, drawerLayout, color, DEFAULT_STATUS_BAR_ALPHA); | ||
| 244 | + } | ||
| 245 | + | ||
| 246 | + /** | ||
| 247 | + * 为DrawerLayout 布局设置状态栏颜色,纯色 | ||
| 248 | + * | ||
| 249 | + * @param activity 需要设置的activity | ||
| 250 | + * @param drawerLayout DrawerLayout | ||
| 251 | + * @param color 状态栏颜色值 | ||
| 252 | + */ | ||
| 253 | + public static void setColorNoTranslucentForDrawerLayout(Activity activity, DrawerLayout drawerLayout, @ColorInt int color) { | ||
| 254 | + setColorForDrawerLayout(activity, drawerLayout, color, 0); | ||
| 255 | + } | ||
| 256 | + | ||
| 257 | + /** | ||
| 258 | + * 为DrawerLayout 布局设置状态栏变色 | ||
| 259 | + * | ||
| 260 | + * @param activity 需要设置的activity | ||
| 261 | + * @param drawerLayout DrawerLayout | ||
| 262 | + * @param color 状态栏颜色值 | ||
| 263 | + * @param statusBarAlpha 状态栏透明度 | ||
| 264 | + */ | ||
| 265 | + public static void setColorForDrawerLayout(Activity activity, DrawerLayout drawerLayout, @ColorInt int color, | ||
| 266 | + @IntRange(from = 0, to = 255) int statusBarAlpha) { | ||
| 267 | + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) { | ||
| 268 | + return; | ||
| 269 | + } | ||
| 270 | + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { | ||
| 271 | + activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); | ||
| 272 | + activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); | ||
| 273 | + activity.getWindow().setStatusBarColor(Color.TRANSPARENT); | ||
| 274 | + } else { | ||
| 275 | + activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); | ||
| 276 | + } | ||
| 277 | + // 生成一个状态栏大小的矩形 | ||
| 278 | + // 添加 statusBarView 到布局中 | ||
| 279 | + ViewGroup contentLayout = (ViewGroup) drawerLayout.getChildAt(0); | ||
| 280 | + View fakeStatusBarView = contentLayout.findViewById(FAKE_STATUS_BAR_VIEW_ID); | ||
| 281 | + if (fakeStatusBarView != null) { | ||
| 282 | + if (fakeStatusBarView.getVisibility() == View.GONE) { | ||
| 283 | + fakeStatusBarView.setVisibility(View.VISIBLE); | ||
| 284 | + } | ||
| 285 | + fakeStatusBarView.setBackgroundColor(color); | ||
| 286 | + } else { | ||
| 287 | + contentLayout.addView(createStatusBarView(activity, color), 0); | ||
| 288 | + } | ||
| 289 | + // 内容布局不是 LinearLayout 时,设置padding top | ||
| 290 | + if (!(contentLayout instanceof LinearLayout) && contentLayout.getChildAt(1) != null) { | ||
| 291 | + contentLayout.getChildAt(1) | ||
| 292 | + .setPadding(contentLayout.getPaddingLeft(), getStatusBarHeight(activity) + contentLayout.getPaddingTop(), | ||
| 293 | + contentLayout.getPaddingRight(), contentLayout.getPaddingBottom()); | ||
| 294 | + } | ||
| 295 | + // 设置属性 | ||
| 296 | + setDrawerLayoutProperty(drawerLayout, contentLayout); | ||
| 297 | + addTranslucentView(activity, statusBarAlpha); | ||
| 298 | + } | ||
| 299 | + | ||
| 300 | + /** | ||
| 301 | + * 设置 DrawerLayout 属性 | ||
| 302 | + * | ||
| 303 | + * @param drawerLayout DrawerLayout | ||
| 304 | + * @param drawerLayoutContentLayout DrawerLayout 的内容布局 | ||
| 305 | + */ | ||
| 306 | + private static void setDrawerLayoutProperty(DrawerLayout drawerLayout, ViewGroup drawerLayoutContentLayout) { | ||
| 307 | + ViewGroup drawer = (ViewGroup) drawerLayout.getChildAt(1); | ||
| 308 | + drawerLayout.setFitsSystemWindows(false); | ||
| 309 | + drawerLayoutContentLayout.setFitsSystemWindows(false); | ||
| 310 | + drawerLayoutContentLayout.setClipToPadding(true); | ||
| 311 | + drawer.setFitsSystemWindows(false); | ||
| 312 | + } | ||
| 313 | + | ||
| 314 | + /** | ||
| 315 | + * 为DrawerLayout 布局设置状态栏变色(5.0以下无半透明效果,不建议使用) | ||
| 316 | + * | ||
| 317 | + * @param activity 需要设置的activity | ||
| 318 | + * @param drawerLayout DrawerLayout | ||
| 319 | + * @param color 状态栏颜色值 | ||
| 320 | + */ | ||
| 321 | + @Deprecated | ||
| 322 | + public static void setColorForDrawerLayoutDiff(Activity activity, DrawerLayout drawerLayout, @ColorInt int color) { | ||
| 323 | + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { | ||
| 324 | + activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); | ||
| 325 | + // 生成一个状态栏大小的矩形 | ||
| 326 | + ViewGroup contentLayout = (ViewGroup) drawerLayout.getChildAt(0); | ||
| 327 | + View fakeStatusBarView = contentLayout.findViewById(FAKE_STATUS_BAR_VIEW_ID); | ||
| 328 | + if (fakeStatusBarView != null) { | ||
| 329 | + if (fakeStatusBarView.getVisibility() == View.GONE) { | ||
| 330 | + fakeStatusBarView.setVisibility(View.VISIBLE); | ||
| 331 | + } | ||
| 332 | + fakeStatusBarView.setBackgroundColor(calculateStatusColor(color, DEFAULT_STATUS_BAR_ALPHA)); | ||
| 333 | + } else { | ||
| 334 | + // 添加 statusBarView 到布局中 | ||
| 335 | + contentLayout.addView(createStatusBarView(activity, color), 0); | ||
| 336 | + } | ||
| 337 | + // 内容布局不是 LinearLayout 时,设置padding top | ||
| 338 | + if (!(contentLayout instanceof LinearLayout) && contentLayout.getChildAt(1) != null) { | ||
| 339 | + contentLayout.getChildAt(1).setPadding(0, getStatusBarHeight(activity), 0, 0); | ||
| 340 | + } | ||
| 341 | + // 设置属性 | ||
| 342 | + setDrawerLayoutProperty(drawerLayout, contentLayout); | ||
| 343 | + } | ||
| 344 | + } | ||
| 345 | + | ||
| 346 | + /** | ||
| 347 | + * 为 DrawerLayout 布局设置状态栏透明 | ||
| 348 | + * | ||
| 349 | + * @param activity 需要设置的activity | ||
| 350 | + * @param drawerLayout DrawerLayout | ||
| 351 | + */ | ||
| 352 | + public static void setTranslucentForDrawerLayout(Activity activity, DrawerLayout drawerLayout) { | ||
| 353 | + setTranslucentForDrawerLayout(activity, drawerLayout, DEFAULT_STATUS_BAR_ALPHA); | ||
| 354 | + } | ||
| 355 | + | ||
| 356 | + /** | ||
| 357 | + * 为 DrawerLayout 布局设置状态栏透明 | ||
| 358 | + * | ||
| 359 | + * @param activity 需要设置的activity | ||
| 360 | + * @param drawerLayout DrawerLayout | ||
| 361 | + */ | ||
| 362 | + public static void setTranslucentForDrawerLayout(Activity activity, DrawerLayout drawerLayout, | ||
| 363 | + @IntRange(from = 0, to = 255) int statusBarAlpha) { | ||
| 364 | + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) { | ||
| 365 | + return; | ||
| 366 | + } | ||
| 367 | + setTransparentForDrawerLayout(activity, drawerLayout); | ||
| 368 | + addTranslucentView(activity, statusBarAlpha); | ||
| 369 | + } | ||
| 370 | + | ||
| 371 | + /** | ||
| 372 | + * 为 DrawerLayout 布局设置状态栏透明 | ||
| 373 | + * | ||
| 374 | + * @param activity 需要设置的activity | ||
| 375 | + * @param drawerLayout DrawerLayout | ||
| 376 | + */ | ||
| 377 | + public static void setTransparentForDrawerLayout(Activity activity, DrawerLayout drawerLayout) { | ||
| 378 | + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) { | ||
| 379 | + return; | ||
| 380 | + } | ||
| 381 | + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { | ||
| 382 | + activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); | ||
| 383 | + activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); | ||
| 384 | + activity.getWindow().setStatusBarColor(Color.TRANSPARENT); | ||
| 385 | + } else { | ||
| 386 | + activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); | ||
| 387 | + } | ||
| 388 | + | ||
| 389 | + ViewGroup contentLayout = (ViewGroup) drawerLayout.getChildAt(0); | ||
| 390 | + // 内容布局不是 LinearLayout 时,设置padding top | ||
| 391 | + if (!(contentLayout instanceof LinearLayout) && contentLayout.getChildAt(1) != null) { | ||
| 392 | + contentLayout.getChildAt(1).setPadding(0, getStatusBarHeight(activity), 0, 0); | ||
| 393 | + } | ||
| 394 | + | ||
| 395 | + // 设置属性 | ||
| 396 | + setDrawerLayoutProperty(drawerLayout, contentLayout); | ||
| 397 | + } | ||
| 398 | + | ||
| 399 | + /** | ||
| 400 | + * 为 DrawerLayout 布局设置状态栏透明(5.0以上半透明效果,不建议使用) | ||
| 401 | + * | ||
| 402 | + * @param activity 需要设置的activity | ||
| 403 | + * @param drawerLayout DrawerLayout | ||
| 404 | + */ | ||
| 405 | + @Deprecated | ||
| 406 | + public static void setTranslucentForDrawerLayoutDiff(Activity activity, DrawerLayout drawerLayout) { | ||
| 407 | + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { | ||
| 408 | + // 设置状态栏透明 | ||
| 409 | + activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); | ||
| 410 | + // 设置内容布局属性 | ||
| 411 | + ViewGroup contentLayout = (ViewGroup) drawerLayout.getChildAt(0); | ||
| 412 | + contentLayout.setFitsSystemWindows(true); | ||
| 413 | + contentLayout.setClipToPadding(true); | ||
| 414 | + // 设置抽屉布局属性 | ||
| 415 | + ViewGroup vg = (ViewGroup) drawerLayout.getChildAt(1); | ||
| 416 | + vg.setFitsSystemWindows(false); | ||
| 417 | + // 设置 DrawerLayout 属性 | ||
| 418 | + drawerLayout.setFitsSystemWindows(false); | ||
| 419 | + } | ||
| 420 | + } | ||
| 421 | + | ||
| 422 | + /** | ||
| 423 | + * 为头部是 ImageView 的界面设置状态栏全透明 | ||
| 424 | + * | ||
| 425 | + * @param activity 需要设置的activity | ||
| 426 | + * @param needOffsetView 需要向下偏移的 View | ||
| 427 | + */ | ||
| 428 | + public static void setTransparentForImageView(Activity activity, View needOffsetView) { | ||
| 429 | + setTranslucentForImageView(activity, 0, needOffsetView); | ||
| 430 | + } | ||
| 431 | + | ||
| 432 | + /** | ||
| 433 | + * 为头部是 ImageView 的界面设置状态栏透明(使用默认透明度) | ||
| 434 | + * | ||
| 435 | + * @param activity 需要设置的activity | ||
| 436 | + * @param needOffsetView 需要向下偏移的 View | ||
| 437 | + */ | ||
| 438 | + public static void setTranslucentForImageView(Activity activity, View needOffsetView) { | ||
| 439 | + setTranslucentForImageView(activity, DEFAULT_STATUS_BAR_ALPHA, needOffsetView); | ||
| 440 | + } | ||
| 441 | + | ||
| 442 | + /** | ||
| 443 | + * 为头部是 ImageView 的界面设置状态栏透明 | ||
| 444 | + * | ||
| 445 | + * @param activity 需要设置的activity | ||
| 446 | + * @param statusBarAlpha 状态栏透明度 | ||
| 447 | + * @param needOffsetView 需要向下偏移的 View | ||
| 448 | + */ | ||
| 449 | + public static void setTranslucentForImageView(Activity activity, @IntRange(from = 0, to = 255) int statusBarAlpha, | ||
| 450 | + View needOffsetView) { | ||
| 451 | + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) { | ||
| 452 | + return; | ||
| 453 | + } | ||
| 454 | + setTransparentForWindow(activity); | ||
| 455 | + addTranslucentView(activity, statusBarAlpha); | ||
| 456 | + if (needOffsetView != null) { | ||
| 457 | + Object haveSetOffset = needOffsetView.getTag(TAG_KEY_HAVE_SET_OFFSET); | ||
| 458 | + if (haveSetOffset != null && (Boolean) haveSetOffset) { | ||
| 459 | + return; | ||
| 460 | + } | ||
| 461 | + ViewGroup.MarginLayoutParams layoutParams = (ViewGroup.MarginLayoutParams) needOffsetView.getLayoutParams(); | ||
| 462 | + layoutParams.setMargins(layoutParams.leftMargin, layoutParams.topMargin + getStatusBarHeight(activity), | ||
| 463 | + layoutParams.rightMargin, layoutParams.bottomMargin); | ||
| 464 | + needOffsetView.setTag(TAG_KEY_HAVE_SET_OFFSET, true); | ||
| 465 | + } | ||
| 466 | + } | ||
| 467 | + | ||
| 468 | + /** | ||
| 469 | + * 为 fragment 头部是 ImageView 的设置状态栏透明 | ||
| 470 | + * | ||
| 471 | + * @param activity fragment 对应的 activity | ||
| 472 | + * @param needOffsetView 需要向下偏移的 View | ||
| 473 | + */ | ||
| 474 | + public static void setTranslucentForImageViewInFragment(Activity activity, View needOffsetView) { | ||
| 475 | + setTranslucentForImageViewInFragment(activity, DEFAULT_STATUS_BAR_ALPHA, needOffsetView); | ||
| 476 | + } | ||
| 477 | + | ||
| 478 | + /** | ||
| 479 | + * 为 fragment 头部是 ImageView 的设置状态栏透明 | ||
| 480 | + * | ||
| 481 | + * @param activity fragment 对应的 activity | ||
| 482 | + * @param needOffsetView 需要向下偏移的 View | ||
| 483 | + */ | ||
| 484 | + public static void setTransparentForImageViewInFragment(Activity activity, View needOffsetView) { | ||
| 485 | + setTranslucentForImageViewInFragment(activity, 0, needOffsetView); | ||
| 486 | + } | ||
| 487 | + | ||
| 488 | + /** | ||
| 489 | + * 为 fragment 头部是 ImageView 的设置状态栏透明 | ||
| 490 | + * | ||
| 491 | + * @param activity fragment 对应的 activity | ||
| 492 | + * @param statusBarAlpha 状态栏透明度 | ||
| 493 | + * @param needOffsetView 需要向下偏移的 View | ||
| 494 | + */ | ||
| 495 | + public static void setTranslucentForImageViewInFragment(Activity activity, @IntRange(from = 0, to = 255) int statusBarAlpha, | ||
| 496 | + View needOffsetView) { | ||
| 497 | + setTranslucentForImageView(activity, statusBarAlpha, needOffsetView); | ||
| 498 | + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT && Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { | ||
| 499 | + clearPreviousSetting(activity); | ||
| 500 | + } | ||
| 501 | + } | ||
| 502 | + | ||
| 503 | + /** | ||
| 504 | + * 隐藏伪状态栏 View | ||
| 505 | + * | ||
| 506 | + * @param activity 调用的 Activity | ||
| 507 | + */ | ||
| 508 | + public static void hideFakeStatusBarView(Activity activity) { | ||
| 509 | + ViewGroup decorView = (ViewGroup) activity.getWindow().getDecorView(); | ||
| 510 | + View fakeStatusBarView = decorView.findViewById(FAKE_STATUS_BAR_VIEW_ID); | ||
| 511 | + if (fakeStatusBarView != null) { | ||
| 512 | + fakeStatusBarView.setVisibility(View.GONE); | ||
| 513 | + } | ||
| 514 | + View fakeTranslucentView = decorView.findViewById(FAKE_TRANSLUCENT_VIEW_ID); | ||
| 515 | + if (fakeTranslucentView != null) { | ||
| 516 | + fakeTranslucentView.setVisibility(View.GONE); | ||
| 517 | + } | ||
| 518 | + } | ||
| 519 | + | ||
| 520 | + @TargetApi(Build.VERSION_CODES.M) | ||
| 521 | + public static void setLightMode(Activity activity) { | ||
| 522 | + setMIUIStatusBarDarkIcon(activity, true); | ||
| 523 | + setMeizuStatusBarDarkIcon(activity, true); | ||
| 524 | + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { | ||
| 525 | + activity.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN); | ||
| 526 | + } | ||
| 527 | + } | ||
| 528 | + | ||
| 529 | + @TargetApi(Build.VERSION_CODES.M) | ||
| 530 | + public static void setDarkMode(Activity activity) { | ||
| 531 | + setMIUIStatusBarDarkIcon(activity, false); | ||
| 532 | + setMeizuStatusBarDarkIcon(activity, false); | ||
| 533 | + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { | ||
| 534 | + activity.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN); | ||
| 535 | + } | ||
| 536 | + } | ||
| 537 | + | ||
| 538 | + /** | ||
| 539 | + * 修改 MIUI V6 以上状态栏颜色 | ||
| 540 | + */ | ||
| 541 | + private static void setMIUIStatusBarDarkIcon(@NonNull Activity activity, boolean darkIcon) { | ||
| 542 | + Class<? extends Window> clazz = activity.getWindow().getClass(); | ||
| 543 | + try { | ||
| 544 | + Class<?> layoutParams = Class.forName("android.view.MiuiWindowManager$LayoutParams"); | ||
| 545 | + Field field = layoutParams.getField("EXTRA_FLAG_STATUS_BAR_DARK_MODE"); | ||
| 546 | + int darkModeFlag = field.getInt(layoutParams); | ||
| 547 | + Method extraFlagField = clazz.getMethod("setExtraFlags", int.class, int.class); | ||
| 548 | + extraFlagField.invoke(activity.getWindow(), darkIcon ? darkModeFlag : 0, darkModeFlag); | ||
| 549 | + } catch (Exception e) { | ||
| 550 | + //e.printStackTrace(); | ||
| 551 | + } | ||
| 552 | + } | ||
| 553 | + | ||
| 554 | + /** | ||
| 555 | + * 修改魅族状态栏字体颜色 Flyme 4.0 | ||
| 556 | + */ | ||
| 557 | + private static void setMeizuStatusBarDarkIcon(@NonNull Activity activity, boolean darkIcon) { | ||
| 558 | + try { | ||
| 559 | + WindowManager.LayoutParams lp = activity.getWindow().getAttributes(); | ||
| 560 | + Field darkFlag = WindowManager.LayoutParams.class.getDeclaredField("MEIZU_FLAG_DARK_STATUS_BAR_ICON"); | ||
| 561 | + Field meizuFlags = WindowManager.LayoutParams.class.getDeclaredField("meizuFlags"); | ||
| 562 | + darkFlag.setAccessible(true); | ||
| 563 | + meizuFlags.setAccessible(true); | ||
| 564 | + int bit = darkFlag.getInt(null); | ||
| 565 | + int value = meizuFlags.getInt(lp); | ||
| 566 | + if (darkIcon) { | ||
| 567 | + value |= bit; | ||
| 568 | + } else { | ||
| 569 | + value &= ~bit; | ||
| 570 | + } | ||
| 571 | + meizuFlags.setInt(lp, value); | ||
| 572 | + activity.getWindow().setAttributes(lp); | ||
| 573 | + } catch (Exception e) { | ||
| 574 | + //e.printStackTrace(); | ||
| 575 | + } | ||
| 576 | + } | ||
| 577 | + | ||
| 578 | + /////////////////////////////////////////////////////////////////////////////////// | ||
| 579 | + | ||
| 580 | + @TargetApi(Build.VERSION_CODES.KITKAT) | ||
| 581 | + private static void clearPreviousSetting(Activity activity) { | ||
| 582 | + ViewGroup decorView = (ViewGroup) activity.getWindow().getDecorView(); | ||
| 583 | + View fakeStatusBarView = decorView.findViewById(FAKE_STATUS_BAR_VIEW_ID); | ||
| 584 | + if (fakeStatusBarView != null) { | ||
| 585 | + decorView.removeView(fakeStatusBarView); | ||
| 586 | + ViewGroup rootView = (ViewGroup) ((ViewGroup) activity.findViewById(android.R.id.content)).getChildAt(0); | ||
| 587 | + rootView.setPadding(0, 0, 0, 0); | ||
| 588 | + } | ||
| 589 | + } | ||
| 590 | + | ||
| 591 | + /** | ||
| 592 | + * 添加半透明矩形条 | ||
| 593 | + * | ||
| 594 | + * @param activity 需要设置的 activity | ||
| 595 | + * @param statusBarAlpha 透明值 | ||
| 596 | + */ | ||
| 597 | + public static void addTranslucentView(Activity activity, @IntRange(from = 0, to = 255) int statusBarAlpha) { | ||
| 598 | + ViewGroup contentView = (ViewGroup) activity.findViewById(android.R.id.content); | ||
| 599 | + View fakeTranslucentView = contentView.findViewById(FAKE_TRANSLUCENT_VIEW_ID); | ||
| 600 | + if (fakeTranslucentView != null) { | ||
| 601 | + if (fakeTranslucentView.getVisibility() == View.GONE) { | ||
| 602 | + fakeTranslucentView.setVisibility(View.VISIBLE); | ||
| 603 | + } | ||
| 604 | + fakeTranslucentView.setBackgroundColor(Color.argb(statusBarAlpha, 0, 0, 0)); | ||
| 605 | + } else { | ||
| 606 | + contentView.addView(createTranslucentStatusBarView(activity, statusBarAlpha)); | ||
| 607 | + } | ||
| 608 | + } | ||
| 609 | + | ||
| 610 | + /** | ||
| 611 | + * 生成一个和状态栏大小相同的彩色矩形条 | ||
| 612 | + * | ||
| 613 | + * @param activity 需要设置的 activity | ||
| 614 | + * @param color 状态栏颜色值 | ||
| 615 | + * @return 状态栏矩形条 | ||
| 616 | + */ | ||
| 617 | + private static View createStatusBarView(Activity activity, @ColorInt int color) { | ||
| 618 | + return createStatusBarView(activity, color, 0); | ||
| 619 | + } | ||
| 620 | + | ||
| 621 | + /** | ||
| 622 | + * 生成一个和状态栏大小相同的半透明矩形条 | ||
| 623 | + * | ||
| 624 | + * @param activity 需要设置的activity | ||
| 625 | + * @param color 状态栏颜色值 | ||
| 626 | + * @param alpha 透明值 | ||
| 627 | + * @return 状态栏矩形条 | ||
| 628 | + */ | ||
| 629 | + private static View createStatusBarView(Activity activity, @ColorInt int color, int alpha) { | ||
| 630 | + // 绘制一个和状态栏一样高的矩形 | ||
| 631 | + View statusBarView = new View(activity); | ||
| 632 | + LinearLayout.LayoutParams params = | ||
| 633 | + new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, getStatusBarHeight(activity)); | ||
| 634 | + statusBarView.setLayoutParams(params); | ||
| 635 | + statusBarView.setBackgroundColor(calculateStatusColor(color, alpha)); | ||
| 636 | + statusBarView.setId(FAKE_STATUS_BAR_VIEW_ID); | ||
| 637 | + return statusBarView; | ||
| 638 | + } | ||
| 639 | + | ||
| 640 | + /** | ||
| 641 | + * 设置根布局参数 | ||
| 642 | + */ | ||
| 643 | + private static void setRootView(Activity activity) { | ||
| 644 | + ViewGroup parent = (ViewGroup) activity.findViewById(android.R.id.content); | ||
| 645 | + for (int i = 0, count = parent.getChildCount(); i < count; i++) { | ||
| 646 | + View childView = parent.getChildAt(i); | ||
| 647 | + if (childView instanceof ViewGroup) { | ||
| 648 | + childView.setFitsSystemWindows(true); | ||
| 649 | + ((ViewGroup) childView).setClipToPadding(true); | ||
| 650 | + } | ||
| 651 | + } | ||
| 652 | + } | ||
| 653 | + | ||
| 654 | + /** | ||
| 655 | + * 设置透明 | ||
| 656 | + */ | ||
| 657 | + public static void setTransparentForWindow(Activity activity) { | ||
| 658 | + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { | ||
| 659 | + activity.getWindow().setStatusBarColor(Color.TRANSPARENT); | ||
| 660 | + activity.getWindow() | ||
| 661 | + .getDecorView() | ||
| 662 | + .setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN); | ||
| 663 | + } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { | ||
| 664 | + activity.getWindow() | ||
| 665 | + .setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS, WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); | ||
| 666 | + } | ||
| 667 | + } | ||
| 668 | + | ||
| 669 | + /** | ||
| 670 | + * 使状态栏透明 | ||
| 671 | + */ | ||
| 672 | + @TargetApi(Build.VERSION_CODES.KITKAT) | ||
| 673 | + private static void transparentStatusBar(Activity activity) { | ||
| 674 | + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { | ||
| 675 | + activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); | ||
| 676 | + activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); | ||
| 677 | + activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION); | ||
| 678 | + activity.getWindow().setStatusBarColor(Color.TRANSPARENT); | ||
| 679 | + } else { | ||
| 680 | + activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); | ||
| 681 | + } | ||
| 682 | + } | ||
| 683 | + | ||
| 684 | + /** | ||
| 685 | + * 创建半透明矩形 View | ||
| 686 | + * | ||
| 687 | + * @param alpha 透明值 | ||
| 688 | + * @return 半透明 View | ||
| 689 | + */ | ||
| 690 | + private static View createTranslucentStatusBarView(Activity activity, int alpha) { | ||
| 691 | + // 绘制一个和状态栏一样高的矩形 | ||
| 692 | + View statusBarView = new View(activity); | ||
| 693 | + LinearLayout.LayoutParams params = | ||
| 694 | + new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, getStatusBarHeight(activity)); | ||
| 695 | + statusBarView.setLayoutParams(params); | ||
| 696 | + statusBarView.setBackgroundColor(Color.argb(alpha, 0, 0, 0)); | ||
| 697 | + statusBarView.setId(FAKE_TRANSLUCENT_VIEW_ID); | ||
| 698 | + return statusBarView; | ||
| 699 | + } | ||
| 700 | + | ||
| 701 | + /** | ||
| 702 | + * 获取状态栏高度 | ||
| 703 | + * | ||
| 704 | + * @param context context | ||
| 705 | + * @return 状态栏高度 | ||
| 706 | + */ | ||
| 707 | + public static int getStatusBarHeight(Context context) { | ||
| 708 | + // 获得状态栏高度 | ||
| 709 | + int resourceId = context.getResources().getIdentifier("status_bar_height", "dimen", "android"); | ||
| 710 | + return context.getResources().getDimensionPixelSize(resourceId); | ||
| 711 | + } | ||
| 712 | + | ||
| 713 | + /** | ||
| 714 | + * 计算状态栏颜色 | ||
| 715 | + * | ||
| 716 | + * @param color color值 | ||
| 717 | + * @param alpha alpha值 | ||
| 718 | + * @return 最终的状态栏颜色 | ||
| 719 | + */ | ||
| 720 | + private static int calculateStatusColor(@ColorInt int color, int alpha) { | ||
| 721 | + if (alpha == 0) { | ||
| 722 | + return color; | ||
| 723 | + } | ||
| 724 | + float a = 1 - alpha / 255f; | ||
| 725 | + int red = color >> 16 & 0xff; | ||
| 726 | + int green = color >> 8 & 0xff; | ||
| 727 | + int blue = color & 0xff; | ||
| 728 | + red = (int) (red * a + 0.5); | ||
| 729 | + green = (int) (green * a + 0.5); | ||
| 730 | + blue = (int) (blue * a + 0.5); | ||
| 731 | + return 0xff << 24 | red << 16 | green << 8 | blue; | ||
| 732 | + } | ||
| 733 | +} |
cloud/wjj_lib/src/main/java/com/cnlive/libs/base/util/StringUtils.java
0 → 100644
| 1 | +package com.cnlive.libs.base.util; | ||
| 2 | + | ||
| 3 | +import android.annotation.TargetApi; | ||
| 4 | +import android.nfc.NdefRecord; | ||
| 5 | +import android.os.Build; | ||
| 6 | +import android.text.TextPaint; | ||
| 7 | +import android.util.Base64; | ||
| 8 | +import android.util.Log; | ||
| 9 | + | ||
| 10 | +import java.net.URLDecoder; | ||
| 11 | +import java.net.URLEncoder; | ||
| 12 | +import java.nio.charset.Charset; | ||
| 13 | +import java.text.DecimalFormat; | ||
| 14 | +import java.text.SimpleDateFormat; | ||
| 15 | +import java.util.ArrayList; | ||
| 16 | +import java.util.Calendar; | ||
| 17 | +import java.util.Date; | ||
| 18 | +import java.util.Iterator; | ||
| 19 | +import java.util.Locale; | ||
| 20 | +import java.util.TimeZone; | ||
| 21 | +import java.util.regex.Matcher; | ||
| 22 | +import java.util.regex.Pattern; | ||
| 23 | + | ||
| 24 | + | ||
| 25 | +/** | ||
| 26 | + * 字符串工具类 | ||
| 27 | + * | ||
| 28 | + * @author tangjun | ||
| 29 | + */ | ||
| 30 | +public class StringUtils { | ||
| 31 | + | ||
| 32 | + public static final String EMPTY = ""; | ||
| 33 | + public static final SimpleDateFormat DATE_FORMAT_PART = new SimpleDateFormat( | ||
| 34 | + "HH:mm", Locale.getDefault()); | ||
| 35 | + private static final String TAG = StringUtils.class.getSimpleName(); | ||
| 36 | + private static final String DEFAULT_DATE_PATTERN = "yyyy-MM-dd"; | ||
| 37 | + private static final String DEFAULT_DATETIME_PATTERN = "yyyy-MM-dd hh:mm:ss"; | ||
| 38 | + /** | ||
| 39 | + * 用于生成文件 | ||
| 40 | + */ | ||
| 41 | + private static final String DEFAULT_FILE_PATTERN = "yyyy-MM-dd-HH-mm-ss"; | ||
| 42 | + private static final double KB = 1024.0; | ||
| 43 | + private static final double MB = 1048576.0; | ||
| 44 | + private static final double GB = 1073741824.0; | ||
| 45 | + | ||
| 46 | + public static String currentTimeString() { | ||
| 47 | + return DATE_FORMAT_PART.format(Calendar.getInstance().getTime()); | ||
| 48 | + } | ||
| 49 | + | ||
| 50 | + public static char chatAt(String pinyin, int index) { | ||
| 51 | + if (pinyin != null && pinyin.length() > 0) | ||
| 52 | + return pinyin.charAt(index); | ||
| 53 | + return ' '; | ||
| 54 | + } | ||
| 55 | + | ||
| 56 | + /** | ||
| 57 | + * 获取字符串宽度 | ||
| 58 | + */ | ||
| 59 | + public static float GetTextWidth(String Sentence, float Size) { | ||
| 60 | + if (isEmpty(Sentence)) | ||
| 61 | + return 0; | ||
| 62 | + TextPaint FontPaint = new TextPaint(); | ||
| 63 | + FontPaint.setTextSize(Size); | ||
| 64 | + return FontPaint.measureText(Sentence.trim()) + (int) (Size * 0.1); // 留点余地 | ||
| 65 | + } | ||
| 66 | + | ||
| 67 | + /** | ||
| 68 | + * 格式化日期字符串 | ||
| 69 | + * | ||
| 70 | + * @param date | ||
| 71 | + * @param pattern | ||
| 72 | + * @return | ||
| 73 | + */ | ||
| 74 | + public static String formatDate(Date date, String pattern) { | ||
| 75 | + SimpleDateFormat format = new SimpleDateFormat(pattern, Locale.getDefault()); | ||
| 76 | + return format.format(date); | ||
| 77 | + } | ||
| 78 | + | ||
| 79 | + /** | ||
| 80 | + * 格式化日期字符串 | ||
| 81 | + * | ||
| 82 | + * @param date | ||
| 83 | + * @return 例如2011-3-24 | ||
| 84 | + */ | ||
| 85 | + public static String formatDate(Date date) { | ||
| 86 | + return formatDate(date, DEFAULT_DATE_PATTERN); | ||
| 87 | + } | ||
| 88 | + | ||
| 89 | + public static String formatDate(long date) { | ||
| 90 | + return formatDate(new Date(date), DEFAULT_DATE_PATTERN); | ||
| 91 | + } | ||
| 92 | + | ||
| 93 | + /** | ||
| 94 | + * 获取当前时间 格式为yyyy-MM-dd 例如2011-07-08 | ||
| 95 | + * | ||
| 96 | + * @return | ||
| 97 | + */ | ||
| 98 | + public static String getDate() { | ||
| 99 | + return formatDate(new Date(), DEFAULT_DATE_PATTERN); | ||
| 100 | + } | ||
| 101 | + | ||
| 102 | + /** | ||
| 103 | + * 生成一个文件名,不含后缀 | ||
| 104 | + */ | ||
| 105 | + public static String createFileName() { | ||
| 106 | + Date date = new Date(System.currentTimeMillis()); | ||
| 107 | + SimpleDateFormat format = new SimpleDateFormat(DEFAULT_FILE_PATTERN, Locale.getDefault()); | ||
| 108 | + return format.format(date); | ||
| 109 | + } | ||
| 110 | + | ||
| 111 | + /** | ||
| 112 | + * 获取当前时间 | ||
| 113 | + * | ||
| 114 | + * @return | ||
| 115 | + */ | ||
| 116 | + public static String getDateTime() { | ||
| 117 | + return formatDate(new Date(), DEFAULT_DATETIME_PATTERN); | ||
| 118 | + } | ||
| 119 | + | ||
| 120 | + /** | ||
| 121 | + * 格式化日期时间字符串 | ||
| 122 | + * | ||
| 123 | + * @param date | ||
| 124 | + * @return 例如2011-11-30 16:06:54 | ||
| 125 | + */ | ||
| 126 | + public static String formatDateTime(Date date) { | ||
| 127 | + return formatDate(date, DEFAULT_DATETIME_PATTERN); | ||
| 128 | + } | ||
| 129 | + | ||
| 130 | + public static String formatDateTime(long date) { | ||
| 131 | + return formatDate(new Date(date), DEFAULT_DATETIME_PATTERN); | ||
| 132 | + } | ||
| 133 | + | ||
| 134 | + /** | ||
| 135 | + * 格林威时间转换 | ||
| 136 | + * | ||
| 137 | + * @param gmt | ||
| 138 | + * @return | ||
| 139 | + */ | ||
| 140 | + public static String formatGMTDate(String gmt) { | ||
| 141 | + TimeZone timeZoneLondon = TimeZone.getTimeZone(gmt); | ||
| 142 | + return formatDate(Calendar.getInstance(timeZoneLondon) | ||
| 143 | + .getTimeInMillis()); | ||
| 144 | + } | ||
| 145 | + | ||
| 146 | + /** | ||
| 147 | + * 拼接数组 | ||
| 148 | + * | ||
| 149 | + * @param array | ||
| 150 | + * @param separator | ||
| 151 | + * @return | ||
| 152 | + */ | ||
| 153 | + public static String join(final ArrayList<String> array, | ||
| 154 | + final String separator) { | ||
| 155 | + StringBuffer result = new StringBuffer(); | ||
| 156 | + if (array != null && array.size() > 0) { | ||
| 157 | + for (String str : array) { | ||
| 158 | + result.append(str); | ||
| 159 | + result.append(separator); | ||
| 160 | + } | ||
| 161 | + result.delete(result.length() - 1, result.length()); | ||
| 162 | + } | ||
| 163 | + return result.toString(); | ||
| 164 | + } | ||
| 165 | + | ||
| 166 | + public static String join(final Iterator<String> iter, | ||
| 167 | + final String separator) { | ||
| 168 | + StringBuffer result = new StringBuffer(); | ||
| 169 | + if (iter != null) { | ||
| 170 | + while (iter.hasNext()) { | ||
| 171 | + String key = iter.next(); | ||
| 172 | + result.append(key); | ||
| 173 | + result.append(separator); | ||
| 174 | + } | ||
| 175 | + if (result.length() > 0) | ||
| 176 | + result.delete(result.length() - 1, result.length()); | ||
| 177 | + } | ||
| 178 | + return result.toString(); | ||
| 179 | + } | ||
| 180 | + | ||
| 181 | + /** | ||
| 182 | + * 判断字符串是否为空 | ||
| 183 | + * | ||
| 184 | + * @param str | ||
| 185 | + * @return | ||
| 186 | + */ | ||
| 187 | + public static boolean isEmpty(String str) { | ||
| 188 | + return str == null || str.length() == 0 || str.equals("null"); | ||
| 189 | + } | ||
| 190 | + | ||
| 191 | + /** | ||
| 192 | + * @param str | ||
| 193 | + * @return | ||
| 194 | + */ | ||
| 195 | + public static String trim(String str) { | ||
| 196 | + return str == null ? EMPTY : str.trim(); | ||
| 197 | + } | ||
| 198 | + | ||
| 199 | + /** | ||
| 200 | + * 转换时间显示 | ||
| 201 | + * | ||
| 202 | + * @param time 毫秒 | ||
| 203 | + * @return | ||
| 204 | + */ | ||
| 205 | + public static String generateTime(long time) { | ||
| 206 | + int totalSeconds = (int) (time / 1000); | ||
| 207 | + int seconds = totalSeconds % 60; | ||
| 208 | + int minutes = (totalSeconds / 60) % 60; | ||
| 209 | + int hours = totalSeconds / 3600; | ||
| 210 | + | ||
| 211 | + return hours > 0 ? String.format(Locale.getDefault(), "%02d:%02d:%02d", hours, minutes, | ||
| 212 | + seconds) : String.format(Locale.getDefault(), "%02d:%02d", minutes, seconds); | ||
| 213 | + } | ||
| 214 | + | ||
| 215 | + /** | ||
| 216 | + * 根据秒速获取时间格式 | ||
| 217 | + */ | ||
| 218 | + public static String gennerTime(int totalSeconds) { | ||
| 219 | + int seconds = totalSeconds % 60; | ||
| 220 | + int minutes = (totalSeconds / 60) % 60; | ||
| 221 | + return String.format(Locale.getDefault(), "%02d:%02d", minutes, seconds); | ||
| 222 | + } | ||
| 223 | + | ||
| 224 | + /** | ||
| 225 | + * 转换文件大小 | ||
| 226 | + * | ||
| 227 | + * @param size | ||
| 228 | + * @return | ||
| 229 | + */ | ||
| 230 | + public static String generateFileSize(long size) { | ||
| 231 | + String fileSize; | ||
| 232 | + if (size < KB) | ||
| 233 | + fileSize = size + "B"; | ||
| 234 | + else if (size < MB) | ||
| 235 | + fileSize = String.format("%.1f", size / KB) + "KB"; | ||
| 236 | + else if (size < GB) | ||
| 237 | + fileSize = String.format("%.1f", size / MB) + "MB"; | ||
| 238 | + else | ||
| 239 | + fileSize = String.format("%.1f", size / GB) + "GB"; | ||
| 240 | + | ||
| 241 | + return fileSize; | ||
| 242 | + } | ||
| 243 | + | ||
| 244 | + public static String getTimeDiff(long time) { | ||
| 245 | + // Calendar cal = Calendar.getInstance(); | ||
| 246 | + long diff = 0; | ||
| 247 | + // Date dnow = cal.getTime(); | ||
| 248 | + String str = ""; | ||
| 249 | + diff = System.currentTimeMillis() - time; | ||
| 250 | + | ||
| 251 | + if (diff > 2592000000L) {// 30 * 24 * 60 * 60 * 1000=2592000000 毫秒 | ||
| 252 | + str = "1个月前"; | ||
| 253 | + } else if (diff > 1814400000) {// 21 * 24 * 60 * 60 * 1000=1814400000 毫秒 | ||
| 254 | + str = "3周前"; | ||
| 255 | + } else if (diff > 1209600000) {// 14 * 24 * 60 * 60 * 1000=1209600000 毫秒 | ||
| 256 | + str = "2周前"; | ||
| 257 | + } else if (diff > 604800000) {// 7 * 24 * 60 * 60 * 1000=604800000 毫秒 | ||
| 258 | + str = "1周前"; | ||
| 259 | + } else if (diff > 86400000) { // 24 * 60 * 60 * 1000=86400000 毫秒 | ||
| 260 | + // System.out.println("X天前"); | ||
| 261 | + str = (int) Math.floor(diff / 86400000f) + "天前"; | ||
| 262 | + } else if (diff > 18000000) {// 5 * 60 * 60 * 1000=18000000 毫秒 | ||
| 263 | + // System.out.println("X小时前"); | ||
| 264 | + str = (int) Math.floor(diff / 18000000f) + "小时前"; | ||
| 265 | + } else if (diff > 60000) {// 1 * 60 * 1000=60000 毫秒 | ||
| 266 | + // System.out.println("X分钟前"); | ||
| 267 | + str = (int) Math.floor(diff / 60000) + "分钟前"; | ||
| 268 | + } else { | ||
| 269 | + str = (int) Math.floor(diff / 1000) + "秒前"; | ||
| 270 | + } | ||
| 271 | + return str; | ||
| 272 | + } | ||
| 273 | + | ||
| 274 | + /** | ||
| 275 | + * 截取字符串 | ||
| 276 | + * | ||
| 277 | + * @param search 待搜索的字符串 | ||
| 278 | + * @param start 起始字符串 例如:<title> | ||
| 279 | + * @param end 结束字符串 例如:</title> | ||
| 280 | + * @param defaultValue | ||
| 281 | + * @return | ||
| 282 | + */ | ||
| 283 | + public static String substring(String search, String start, String end, | ||
| 284 | + String defaultValue) { | ||
| 285 | + int start_len = start.length(); | ||
| 286 | + int start_pos = StringUtils.isEmpty(start) ? 0 : search.indexOf(start); | ||
| 287 | + if (start_pos > -1) { | ||
| 288 | + int end_pos = StringUtils.isEmpty(end) ? -1 : search.indexOf(end, | ||
| 289 | + start_pos + start_len); | ||
| 290 | + if (end_pos > -1) | ||
| 291 | + return search.substring(start_pos + start.length(), end_pos); | ||
| 292 | + else | ||
| 293 | + return search.substring(start_pos + start.length()); | ||
| 294 | + } | ||
| 295 | + return defaultValue; | ||
| 296 | + } | ||
| 297 | + | ||
| 298 | + /** | ||
| 299 | + * 截取字符串 | ||
| 300 | + * | ||
| 301 | + * @param search 待搜索的字符串 | ||
| 302 | + * @param start 起始字符串 例如:<title> | ||
| 303 | + * @param end 结束字符串 例如:</title> | ||
| 304 | + * @return | ||
| 305 | + */ | ||
| 306 | + public static String substring(String search, String start, String end) { | ||
| 307 | + return substring(search, start, end, ""); | ||
| 308 | + } | ||
| 309 | + | ||
| 310 | + /** | ||
| 311 | + * 拼接字符串 | ||
| 312 | + * | ||
| 313 | + * @param strs | ||
| 314 | + * @return | ||
| 315 | + */ | ||
| 316 | + public static String concat(String... strs) { | ||
| 317 | + StringBuffer result = new StringBuffer(); | ||
| 318 | + if (strs != null) { | ||
| 319 | + for (String str : strs) { | ||
| 320 | + if (str != null) | ||
| 321 | + result.append(str); | ||
| 322 | + } | ||
| 323 | + } | ||
| 324 | + return result.toString(); | ||
| 325 | + } | ||
| 326 | + | ||
| 327 | + /** | ||
| 328 | + * 获取中文字符个数 | ||
| 329 | + */ | ||
| 330 | + public static int getChineseCharCount(String str) { | ||
| 331 | + String tempStr; | ||
| 332 | + int count = 0; | ||
| 333 | + for (int i = 0; i < str.length(); i++) { | ||
| 334 | + tempStr = String.valueOf(str.charAt(i)); | ||
| 335 | + if (tempStr.getBytes().length == 3) { | ||
| 336 | + count++; | ||
| 337 | + } | ||
| 338 | + } | ||
| 339 | + return count; | ||
| 340 | + } | ||
| 341 | + | ||
| 342 | + /** | ||
| 343 | + * 获取英文字符个数 | ||
| 344 | + */ | ||
| 345 | + public static int getEnglishCount(String str) { | ||
| 346 | + String tempStr; | ||
| 347 | + int count = 0; | ||
| 348 | + for (int i = 0; i < str.length(); i++) { | ||
| 349 | + tempStr = String.valueOf(str.charAt(i)); | ||
| 350 | + if (!(tempStr.getBytes().length == 3)) { | ||
| 351 | + count++; | ||
| 352 | + } | ||
| 353 | + } | ||
| 354 | + return count; | ||
| 355 | + } | ||
| 356 | + | ||
| 357 | + public static String encode(String url) { | ||
| 358 | + try { | ||
| 359 | + return URLEncoder.encode(url, "UTF-8"); | ||
| 360 | + } catch (Exception e) { | ||
| 361 | + Log.e(TAG, e.getMessage(), e); | ||
| 362 | + } | ||
| 363 | + return url; | ||
| 364 | + } | ||
| 365 | + | ||
| 366 | + public static String base64encode(String value) { | ||
| 367 | + try { | ||
| 368 | + return new String(Base64.encode(value.getBytes(), Base64.DEFAULT)); | ||
| 369 | + } catch (Exception e) { | ||
| 370 | + Log.e(TAG, e.getMessage(), e); | ||
| 371 | + } | ||
| 372 | + return value; | ||
| 373 | + } | ||
| 374 | + | ||
| 375 | + public static String decode(String url) { | ||
| 376 | + try { | ||
| 377 | + return URLDecoder.decode(url, "UTF-8"); | ||
| 378 | + } catch (Exception e) { | ||
| 379 | + Log.e(TAG, e.getMessage(), e); | ||
| 380 | + } | ||
| 381 | + return url; | ||
| 382 | + } | ||
| 383 | + | ||
| 384 | + public static String base64decode(String value) { | ||
| 385 | + try { | ||
| 386 | + | ||
| 387 | + return new String(Base64.decode(value, Base64.DEFAULT)); | ||
| 388 | + } catch (Exception e) { | ||
| 389 | + Log.e(TAG, e.getMessage(), e); | ||
| 390 | + } | ||
| 391 | + return value; | ||
| 392 | + } | ||
| 393 | + | ||
| 394 | + @TargetApi(Build.VERSION_CODES.GINGERBREAD) | ||
| 395 | + public static NdefRecord createTextRecord(String payload, Locale locale, boolean encodeInUtf8) { | ||
| 396 | + byte[] langBytes = locale.getLanguage().getBytes(Charset.forName("US-ASCII")); | ||
| 397 | + Charset utfEncoding = encodeInUtf8 ? Charset.forName("UTF-8") : Charset.forName("UTF-16"); | ||
| 398 | + byte[] textBytes = payload.getBytes(utfEncoding); | ||
| 399 | + int utfBit = encodeInUtf8 ? 0 : (1 << 7); | ||
| 400 | + char status = (char) (utfBit + langBytes.length); | ||
| 401 | + byte[] data = new byte[1 + langBytes.length + textBytes.length]; | ||
| 402 | + data[0] = (byte) status; | ||
| 403 | + System.arraycopy(langBytes, 0, data, 1, langBytes.length); | ||
| 404 | + System.arraycopy(textBytes, 0, data, 1 + langBytes.length, textBytes.length); | ||
| 405 | + NdefRecord record = new NdefRecord(NdefRecord.TNF_WELL_KNOWN, | ||
| 406 | + NdefRecord.RTD_TEXT, new byte[0], data); | ||
| 407 | + return record; | ||
| 408 | + } | ||
| 409 | + | ||
| 410 | + /** | ||
| 411 | + * 转换中国币文字显示 | ||
| 412 | + * | ||
| 413 | + * @param gold | ||
| 414 | + * @return | ||
| 415 | + */ | ||
| 416 | + public static String generateGoldValue(int gold) { | ||
| 417 | + String goldstr; | ||
| 418 | + if (gold < 10000) { | ||
| 419 | + goldstr = gold + "中国币"; | ||
| 420 | + } else if (gold < 100000000) { | ||
| 421 | + goldstr = String.format(Locale.getDefault(), "%.1f万中国币", gold / 10000); | ||
| 422 | + } else | ||
| 423 | + goldstr = String.format(Locale.getDefault(), "%.1f亿中国币", gold / 100000000); | ||
| 424 | + return goldstr; | ||
| 425 | + } | ||
| 426 | + | ||
| 427 | + /** | ||
| 428 | + * 数量转换为万 | ||
| 429 | + */ | ||
| 430 | + public static String getNumDiff(int count, String sub) { | ||
| 431 | + String afterNum = ""; | ||
| 432 | + if (count >= 0 && count < 10000) { | ||
| 433 | + afterNum = count + sub; | ||
| 434 | + } else if (count >= 10000 && count < 10000000) { | ||
| 435 | + if (count / 1000 % 10 != 0) { | ||
| 436 | + float num = (float) count / 10000; | ||
| 437 | + DecimalFormat decimalFormat = new DecimalFormat("0.0"); | ||
| 438 | + afterNum = decimalFormat.format(num).concat("万" + sub); | ||
| 439 | + } else { | ||
| 440 | + afterNum = (count / 10000) + "万" + sub; | ||
| 441 | + } | ||
| 442 | + } else if (count >= 10000000) { | ||
| 443 | + afterNum = "1000万" + sub; | ||
| 444 | + } | ||
| 445 | + return afterNum; | ||
| 446 | + } | ||
| 447 | + | ||
| 448 | + /** | ||
| 449 | + * 利用正则表达式判断字符串是否是数字 | ||
| 450 | + * | ||
| 451 | + * @param str | ||
| 452 | + * @return | ||
| 453 | + */ | ||
| 454 | + public static boolean isNumeric(String str) { | ||
| 455 | + if (str == null || str.trim().length() == 0) return false; | ||
| 456 | + Pattern pattern = Pattern.compile("[0-9]*"); | ||
| 457 | + Matcher isNum = pattern.matcher(str); | ||
| 458 | + if (!isNum.matches()) { | ||
| 459 | + return false; | ||
| 460 | + } | ||
| 461 | + return true; | ||
| 462 | + } | ||
| 463 | + | ||
| 464 | + | ||
| 465 | + // private static final char[] cnNumbers = {'零', '壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖'}; | ||
| 466 | + private static final char[] cnNumbers = {'零', '一', '二', '三', '四', '五', '六', '七', '八', '九'}; | ||
| 467 | + // private static final char[] series = {' ', '拾', '百', '仟', '万', '拾', '百', '仟', '亿'}; | ||
| 468 | + private static final char[] series = {' ', '十', '百', '千', '万', '十', '百', '千', '亿'}; | ||
| 469 | + | ||
| 470 | + /** | ||
| 471 | + * 取得大写形式的字符串 | ||
| 472 | + */ | ||
| 473 | + public static String getCnString(Integer value) { | ||
| 474 | + // 整数部分 | ||
| 475 | + String integerPart = ""; | ||
| 476 | + // 小数部分 | ||
| 477 | + String floatPart = ""; | ||
| 478 | + | ||
| 479 | + String original = value.toString(); | ||
| 480 | + | ||
| 481 | + if (original.contains(".")) { | ||
| 482 | + // 如果包含小数点 | ||
| 483 | + int dotIndex = original.indexOf("."); | ||
| 484 | + integerPart = original.substring(0, dotIndex); | ||
| 485 | + floatPart = original.substring(dotIndex + 1); | ||
| 486 | + } else { | ||
| 487 | + // 不包含小数点 | ||
| 488 | + integerPart = original; | ||
| 489 | + } | ||
| 490 | + // 因为是累加所以用StringBuffer | ||
| 491 | + StringBuffer sb = new StringBuffer(); | ||
| 492 | + | ||
| 493 | + // 整数部分处理 | ||
| 494 | + for (int i = 0; i < integerPart.length(); i++) { | ||
| 495 | + int number = Integer.parseInt(String.valueOf(integerPart.charAt(i))); | ||
| 496 | + | ||
| 497 | + sb.append(cnNumbers[number]); | ||
| 498 | + sb.append(series[integerPart.length() - 1 - i]); | ||
| 499 | + } | ||
| 500 | + // 小数部分处理 | ||
| 501 | + if (floatPart.length() > 0) { | ||
| 502 | + sb.append("点"); | ||
| 503 | + for (int i = 0; i < floatPart.length(); i++) { | ||
| 504 | + int number = Integer.parseInt(String.valueOf(floatPart.charAt(i))); | ||
| 505 | + | ||
| 506 | + sb.append(cnNumbers[number]); | ||
| 507 | + } | ||
| 508 | + } | ||
| 509 | + | ||
| 510 | + // 返回拼接好的字符串 | ||
| 511 | + return sb.toString().trim(); | ||
| 512 | + } | ||
| 513 | + | ||
| 514 | + | ||
| 515 | +} |
cloud/wjj_lib/src/main/java/com/cnlive/libs/base/util/TimeUtil.java
0 → 100644
| 1 | +package com.cnlive.libs.base.util; | ||
| 2 | + | ||
| 3 | +import java.text.SimpleDateFormat; | ||
| 4 | +import java.util.Calendar; | ||
| 5 | +import java.util.Date; | ||
| 6 | + | ||
| 7 | +/** | ||
| 8 | + * 时间转换工具 | ||
| 9 | + */ | ||
| 10 | +public class TimeUtil { | ||
| 11 | + | ||
| 12 | + private static String dayNames[] = {"周日", "周一", "周二", "周三", "周四", "周五", "周六"}; | ||
| 13 | + | ||
| 14 | + /** | ||
| 15 | + * 时间戳格式转换,会话列表页面,单位s | ||
| 16 | + */ | ||
| 17 | + public static String getConversationTimeStr(long timeS) { | ||
| 18 | + if (timeS <= 0) return ""; | ||
| 19 | + long timesamp = timeS * 1000; | ||
| 20 | + String result = ""; | ||
| 21 | + Calendar todayCalendar = Calendar.getInstance(); | ||
| 22 | + Calendar otherCalendar = Calendar.getInstance(); | ||
| 23 | + otherCalendar.setTimeInMillis(timesamp); | ||
| 24 | + | ||
| 25 | + String timeFormat = "M月d日"; | ||
| 26 | + String yearTimeFormat = "yyyy年M月d日"; | ||
| 27 | + | ||
| 28 | + boolean yearTemp = todayCalendar.get(Calendar.YEAR) == otherCalendar.get(Calendar.YEAR); | ||
| 29 | + if (yearTemp) { | ||
| 30 | + int todayMonth = todayCalendar.get(Calendar.MONTH); | ||
| 31 | + int otherMonth = otherCalendar.get(Calendar.MONTH); | ||
| 32 | + if (todayMonth == otherMonth) {//表示是同一个月 | ||
| 33 | + int temp = todayCalendar.get(Calendar.DATE) - otherCalendar.get(Calendar.DATE); | ||
| 34 | + switch (temp) { | ||
| 35 | + case 0: | ||
| 36 | + result = getHourAndMin(timesamp); | ||
| 37 | + break; | ||
| 38 | + case 1: | ||
| 39 | + result = "昨天 "; | ||
| 40 | + break; | ||
| 41 | + case 2: | ||
| 42 | + case 3: | ||
| 43 | + case 4: | ||
| 44 | + case 5: | ||
| 45 | + case 6: | ||
| 46 | + int dayOfMonth = otherCalendar.get(Calendar.WEEK_OF_MONTH); | ||
| 47 | + int todayOfMonth = todayCalendar.get(Calendar.WEEK_OF_MONTH); | ||
| 48 | + if (dayOfMonth == todayOfMonth) {//表示是同一周 | ||
| 49 | + int dayOfWeek = otherCalendar.get(Calendar.DAY_OF_WEEK); | ||
| 50 | + if (dayOfWeek != 1) {//判断当前是不是星期日 如想显示为:周日 12:09 可去掉此判断 | ||
| 51 | + result = dayNames[otherCalendar.get(Calendar.DAY_OF_WEEK) - 1]; | ||
| 52 | + } else { | ||
| 53 | + result = getTime(timesamp, timeFormat); | ||
| 54 | + } | ||
| 55 | + } else { | ||
| 56 | + result = getTime(timesamp, timeFormat); | ||
| 57 | + } | ||
| 58 | + break; | ||
| 59 | + default: | ||
| 60 | + result = getTime(timesamp, timeFormat); | ||
| 61 | + break; | ||
| 62 | + } | ||
| 63 | + } else { | ||
| 64 | + result = getTime(timesamp, timeFormat); | ||
| 65 | + } | ||
| 66 | + } else { | ||
| 67 | + result = getYearTime(timesamp, yearTimeFormat); | ||
| 68 | + } | ||
| 69 | + return result; | ||
| 70 | + } | ||
| 71 | + | ||
| 72 | + /** | ||
| 73 | + * 时间戳格式转换,聊天页面,单位s | ||
| 74 | + */ | ||
| 75 | + public static String getChatTimeStr(long timeS) { | ||
| 76 | + long timesamp = timeS * 1000; | ||
| 77 | + String result = ""; | ||
| 78 | + Calendar todayCalendar = Calendar.getInstance(); | ||
| 79 | + Calendar otherCalendar = Calendar.getInstance(); | ||
| 80 | + otherCalendar.setTimeInMillis(timesamp); | ||
| 81 | + | ||
| 82 | + String timeFormat = "M月d日 HH:mm"; | ||
| 83 | + String yearTimeFormat = "yyyy年M月d日 HH:mm"; | ||
| 84 | + String am_pm = ""; | ||
| 85 | + int hour = otherCalendar.get(Calendar.HOUR_OF_DAY); | ||
| 86 | + if (hour >= 0 && hour < 6) { | ||
| 87 | + am_pm = "凌晨"; | ||
| 88 | + } else if (hour >= 6 && hour < 12) { | ||
| 89 | + am_pm = "早上"; | ||
| 90 | + } else if (hour == 12) { | ||
| 91 | + am_pm = "中午"; | ||
| 92 | + } else if (hour > 12 && hour < 18) { | ||
| 93 | + am_pm = "下午"; | ||
| 94 | + } else if (hour >= 18) { | ||
| 95 | + am_pm = "晚上"; | ||
| 96 | + } | ||
| 97 | + timeFormat = "M月d日 " + am_pm + "HH:mm"; | ||
| 98 | + yearTimeFormat = "yyyy年M月d日 " + am_pm + "HH:mm"; | ||
| 99 | + | ||
| 100 | + boolean yearTemp = todayCalendar.get(Calendar.YEAR) == otherCalendar.get(Calendar.YEAR); | ||
| 101 | + if (yearTemp) { | ||
| 102 | + int todayMonth = todayCalendar.get(Calendar.MONTH); | ||
| 103 | + int otherMonth = otherCalendar.get(Calendar.MONTH); | ||
| 104 | + if (todayMonth == otherMonth) {//表示是同一个月 | ||
| 105 | + int temp = todayCalendar.get(Calendar.DATE) - otherCalendar.get(Calendar.DATE); | ||
| 106 | + switch (temp) { | ||
| 107 | + case 0: | ||
| 108 | + result = getHourAndMin(timesamp); | ||
| 109 | + break; | ||
| 110 | + case 1: | ||
| 111 | + result = "昨天 " + getHourAndMin(timesamp); | ||
| 112 | + break; | ||
| 113 | + case 2: | ||
| 114 | + case 3: | ||
| 115 | + case 4: | ||
| 116 | + case 5: | ||
| 117 | + case 6: | ||
| 118 | + int dayOfMonth = otherCalendar.get(Calendar.WEEK_OF_MONTH); | ||
| 119 | + int todayOfMonth = todayCalendar.get(Calendar.WEEK_OF_MONTH); | ||
| 120 | + if (dayOfMonth == todayOfMonth) {//表示是同一周 | ||
| 121 | + int dayOfWeek = otherCalendar.get(Calendar.DAY_OF_WEEK); | ||
| 122 | + if (dayOfWeek != 1) {//判断当前是不是星期日 如想显示为:周日 12:09 可去掉此判断 | ||
| 123 | + result = dayNames[otherCalendar.get(Calendar.DAY_OF_WEEK) - 1] + getHourAndMin(timesamp); | ||
| 124 | + } else { | ||
| 125 | + result = getTime(timesamp, timeFormat); | ||
| 126 | + } | ||
| 127 | + } else { | ||
| 128 | + result = getTime(timesamp, timeFormat); | ||
| 129 | + } | ||
| 130 | + break; | ||
| 131 | + default: | ||
| 132 | + result = getTime(timesamp, timeFormat); | ||
| 133 | + break; | ||
| 134 | + } | ||
| 135 | + } else { | ||
| 136 | + result = getTime(timesamp, timeFormat); | ||
| 137 | + } | ||
| 138 | + } else { | ||
| 139 | + result = getYearTime(timesamp, yearTimeFormat); | ||
| 140 | + } | ||
| 141 | + return result; | ||
| 142 | + } | ||
| 143 | + | ||
| 144 | + /** | ||
| 145 | + * 当天的显示时间格式 | ||
| 146 | + * | ||
| 147 | + * @param time | ||
| 148 | + * @return | ||
| 149 | + */ | ||
| 150 | + public static String getHourAndMin(long time) { | ||
| 151 | + SimpleDateFormat format = new SimpleDateFormat("HH:mm"); | ||
| 152 | + return format.format(new Date(time)); | ||
| 153 | + } | ||
| 154 | + | ||
| 155 | + /** | ||
| 156 | + * 不同一周的显示时间格式 | ||
| 157 | + * | ||
| 158 | + * @param time | ||
| 159 | + * @param timeFormat | ||
| 160 | + * @return | ||
| 161 | + */ | ||
| 162 | + public static String getTime(long time, String timeFormat) { | ||
| 163 | + SimpleDateFormat format = new SimpleDateFormat(timeFormat); | ||
| 164 | + return format.format(new Date(time)); | ||
| 165 | + } | ||
| 166 | + | ||
| 167 | + /** | ||
| 168 | + * 不同年的显示时间格式 | ||
| 169 | + * | ||
| 170 | + * @param time | ||
| 171 | + * @param yearTimeFormat | ||
| 172 | + * @return | ||
| 173 | + */ | ||
| 174 | + public static String getYearTime(long time, String yearTimeFormat) { | ||
| 175 | + SimpleDateFormat format = new SimpleDateFormat(yearTimeFormat); | ||
| 176 | + return format.format(new Date(time)); | ||
| 177 | + } | ||
| 178 | +} |
cloud/wjj_lib/src/main/java/com/cnlive/libs/base/util/TimerUtil.java
0 → 100644
| 1 | +package com.cnlive.libs.base.util; | ||
| 2 | + | ||
| 3 | +import android.os.Handler; | ||
| 4 | +import android.os.Message; | ||
| 5 | +import android.os.SystemClock; | ||
| 6 | + | ||
| 7 | +import java.lang.ref.WeakReference; | ||
| 8 | + | ||
| 9 | +public class TimerUtil { | ||
| 10 | + private long totalTime = -1L; | ||
| 11 | + private long intervalTime = 0L; | ||
| 12 | + private long remainTime; | ||
| 13 | + private long systemAddTotalTime; | ||
| 14 | + private static final int TIME = 1; | ||
| 15 | + private TimeListener listener; | ||
| 16 | + private long curReminTime; | ||
| 17 | + private boolean isPause = false; | ||
| 18 | + private MyHandler mHandler = new MyHandler(this); | ||
| 19 | + | ||
| 20 | + public TimerUtil() { | ||
| 21 | + } | ||
| 22 | + | ||
| 23 | + public void setIntervalTime(long intervalTime) { | ||
| 24 | + this.intervalTime = intervalTime; | ||
| 25 | + } | ||
| 26 | + | ||
| 27 | + public void setTotalTime(long totalTime) { | ||
| 28 | + this.totalTime = totalTime; | ||
| 29 | + } | ||
| 30 | + | ||
| 31 | + public long getIntervalTime() { | ||
| 32 | + return this.intervalTime; | ||
| 33 | + } | ||
| 34 | + | ||
| 35 | + public long getTotalTime() { | ||
| 36 | + return this.totalTime; | ||
| 37 | + } | ||
| 38 | + | ||
| 39 | + public void start() { | ||
| 40 | + if (this.totalTime <= 0L && this.intervalTime <= 0L) { | ||
| 41 | + throw new RuntimeException("you must set the totalTime > 0 or intervalTime >0"); | ||
| 42 | + } else { | ||
| 43 | + this.systemAddTotalTime = SystemClock.elapsedRealtime() + this.totalTime; | ||
| 44 | + if (null != this.mHandler) { | ||
| 45 | + this.mHandler.sendEmptyMessage(1); | ||
| 46 | + } | ||
| 47 | + | ||
| 48 | + } | ||
| 49 | + } | ||
| 50 | + | ||
| 51 | + public void cancel() { | ||
| 52 | + if (this.mHandler != null) { | ||
| 53 | + this.mHandler.removeMessages(1); | ||
| 54 | + } | ||
| 55 | + | ||
| 56 | + } | ||
| 57 | + | ||
| 58 | + public void release() { | ||
| 59 | + if (this.mHandler != null) { | ||
| 60 | + this.mHandler.removeMessages(0); | ||
| 61 | + this.mHandler.removeCallbacks((Runnable) null); | ||
| 62 | + this.mHandler = null; | ||
| 63 | + } | ||
| 64 | + | ||
| 65 | + } | ||
| 66 | + | ||
| 67 | + public void pause() { | ||
| 68 | + if (this.mHandler != null) { | ||
| 69 | + this.mHandler.removeMessages(1); | ||
| 70 | + this.isPause = true; | ||
| 71 | + this.curReminTime = this.remainTime; | ||
| 72 | + } | ||
| 73 | + | ||
| 74 | + } | ||
| 75 | + | ||
| 76 | + public void resume() { | ||
| 77 | + if (this.isPause) { | ||
| 78 | + this.isPause = false; | ||
| 79 | + this.totalTime = this.curReminTime; | ||
| 80 | + this.start(); | ||
| 81 | + } | ||
| 82 | + | ||
| 83 | + } | ||
| 84 | + | ||
| 85 | + private void soloveTime() { | ||
| 86 | + this.remainTime = this.systemAddTotalTime - SystemClock.elapsedRealtime(); | ||
| 87 | + if (this.remainTime <= 0L) { | ||
| 88 | + if (this.listener != null) { | ||
| 89 | + this.listener.onFinish(); | ||
| 90 | + this.cancel(); | ||
| 91 | + } | ||
| 92 | + } else if (this.remainTime < this.intervalTime) { | ||
| 93 | + if (null != this.mHandler) { | ||
| 94 | + this.mHandler.sendEmptyMessageDelayed(1, this.remainTime); | ||
| 95 | + } | ||
| 96 | + } else { | ||
| 97 | + long curSystemTime = SystemClock.elapsedRealtime(); | ||
| 98 | + if (this.listener != null) { | ||
| 99 | + this.listener.onInterval(this.remainTime); | ||
| 100 | + } | ||
| 101 | + | ||
| 102 | + long delay; | ||
| 103 | + for (delay = curSystemTime + this.intervalTime - SystemClock.elapsedRealtime(); delay < 0L; delay += this.intervalTime) { | ||
| 104 | + ; | ||
| 105 | + } | ||
| 106 | + | ||
| 107 | + if (null != this.mHandler) { | ||
| 108 | + this.mHandler.sendEmptyMessageDelayed(1, delay); | ||
| 109 | + } | ||
| 110 | + } | ||
| 111 | + | ||
| 112 | + } | ||
| 113 | + | ||
| 114 | + public void setTimerLiener(TimeListener listener) { | ||
| 115 | + this.listener = listener; | ||
| 116 | + } | ||
| 117 | + | ||
| 118 | + public interface TimeListener { | ||
| 119 | + void onFinish(); | ||
| 120 | + | ||
| 121 | + void onInterval(long var1); | ||
| 122 | + } | ||
| 123 | + | ||
| 124 | + private static class MyHandler extends Handler { | ||
| 125 | + WeakReference<TimerUtil> mActivity; | ||
| 126 | + | ||
| 127 | + MyHandler(TimerUtil activity) { | ||
| 128 | + this.mActivity = new WeakReference<>(activity); | ||
| 129 | + } | ||
| 130 | + | ||
| 131 | + public void handleMessage(Message msg) { | ||
| 132 | + TimerUtil theActivity = mActivity == null ? null : this.mActivity.get(); | ||
| 133 | + | ||
| 134 | + if (theActivity == null) return; | ||
| 135 | + | ||
| 136 | + switch (msg.what) { | ||
| 137 | + case 1: | ||
| 138 | + if (!theActivity.isPause) { | ||
| 139 | + theActivity.soloveTime(); | ||
| 140 | + } | ||
| 141 | + break; | ||
| 142 | + case 2: | ||
| 143 | + theActivity.isPause = true; | ||
| 144 | + } | ||
| 145 | + | ||
| 146 | + } | ||
| 147 | + } | ||
| 148 | +} |
cloud/wjj_lib/src/main/java/com/cnlive/libs/base/util/ToastUtil.java
0 → 100644
| 1 | +package com.cnlive.libs.base.util; | ||
| 2 | + | ||
| 3 | +import android.content.Context; | ||
| 4 | +import android.os.Build; | ||
| 5 | +import android.text.TextUtils; | ||
| 6 | +import android.view.LayoutInflater; | ||
| 7 | +import android.view.View; | ||
| 8 | +import android.view.ViewGroup; | ||
| 9 | +import android.widget.TextView; | ||
| 10 | +import android.widget.Toast; | ||
| 11 | + | ||
| 12 | +import com.cnlive.libs.base.util.toast.ToastCompat; | ||
| 13 | + | ||
| 14 | +public class ToastUtil { | ||
| 15 | + private static final String TAG = "ToastUtil"; | ||
| 16 | + private static long show_time; | ||
| 17 | + private static String show_msg = ""; | ||
| 18 | + private Context context; | ||
| 19 | + private Build config; | ||
| 20 | + | ||
| 21 | + public static Build newBuild() { | ||
| 22 | + return new Build(); | ||
| 23 | + } | ||
| 24 | + | ||
| 25 | + private ToastUtil(Context context) { | ||
| 26 | + this.context = context; | ||
| 27 | + } | ||
| 28 | + | ||
| 29 | + public ToastUtil(Context context, Build config) { | ||
| 30 | + this.context = context; | ||
| 31 | + this.config = config; | ||
| 32 | + } | ||
| 33 | + | ||
| 34 | + public void showToast(String str, int duration) { | ||
| 35 | + if (this.context != null && !TextUtils.isEmpty(str)) { | ||
| 36 | + if (show_time + 2000L < System.currentTimeMillis() || !show_msg.equals(str)) { | ||
| 37 | + show_msg = str; | ||
| 38 | + View view = this.getView(str); | ||
| 39 | + Context var10000 = this.context; | ||
| 40 | + show_msg = str; | ||
| 41 | + Toast toast = | ||
| 42 | +// (android.os.Build.VERSION.SDK_INT == 25 || android.os.Build.VERSION.SDK_INT == 24) ? | ||
| 43 | +// Toast.makeText(var10000, str, duration) : | ||
| 44 | + ToastCompat.makeText(var10000, str, duration); | ||
| 45 | + toast.setGravity(this.config == null ? 0 : this.config.gravity, this.config == null ? 0 : this.config.xOffset, this.config == null ? 0 : this.config.yOffset); | ||
| 46 | + if (view != null) { | ||
| 47 | + toast.setView(view); | ||
| 48 | + } | ||
| 49 | + | ||
| 50 | + toast.show(); | ||
| 51 | + } | ||
| 52 | + | ||
| 53 | + show_time = System.currentTimeMillis(); | ||
| 54 | + } | ||
| 55 | + } | ||
| 56 | + | ||
| 57 | + public void showToastAgriculture(String str, int duration) { | ||
| 58 | + if (this.context != null && !TextUtils.isEmpty(str)) { | ||
| 59 | + View view = this.getView(str); | ||
| 60 | + Context var10000 = this.context; | ||
| 61 | + Toast toast = | ||
| 62 | +// (android.os.Build.VERSION.SDK_INT == 25 || android.os.Build.VERSION.SDK_INT == 24) ? | ||
| 63 | +// Toast.makeText(var10000, str, duration) : | ||
| 64 | + ToastCompat.makeText(var10000, str, duration); | ||
| 65 | + toast.setGravity(this.config == null ? 0 : this.config.gravity, this.config == null ? 0 : this.config.xOffset, this.config == null ? 0 : this.config.yOffset); | ||
| 66 | + if (view != null) { | ||
| 67 | + toast.setView(view); | ||
| 68 | + } | ||
| 69 | + toast.show(); | ||
| 70 | + } | ||
| 71 | + } | ||
| 72 | + | ||
| 73 | + public void showToast(String str) { | ||
| 74 | + this.showToast(str, 0); | ||
| 75 | + } | ||
| 76 | + | ||
| 77 | + public void showNoEqulesToast(String str) { | ||
| 78 | + this.showToastAgriculture(str, 0); | ||
| 79 | + } | ||
| 80 | + | ||
| 81 | + private View getView(String message) { | ||
| 82 | + View view = null; | ||
| 83 | + | ||
| 84 | + try { | ||
| 85 | + view = LayoutInflater.from(this.context).inflate(this.config == null ? 0 : this.config.layoutId, (ViewGroup) null, false); | ||
| 86 | + TextView textView = (TextView) view.findViewById(this.config.viewId); | ||
| 87 | + textView.setText(message); | ||
| 88 | + } catch (Exception var4) { | ||
| 89 | + LogUtil.d("ToastUtil", "", var4); | ||
| 90 | + } | ||
| 91 | + | ||
| 92 | + return view; | ||
| 93 | + } | ||
| 94 | + | ||
| 95 | + public static class Build { | ||
| 96 | + private int gravity; | ||
| 97 | + private int xOffset; | ||
| 98 | + private int yOffset; | ||
| 99 | + private int layoutId; | ||
| 100 | + private int viewId; | ||
| 101 | + | ||
| 102 | + private Build() { | ||
| 103 | + this.gravity = 0; | ||
| 104 | + this.xOffset = 0; | ||
| 105 | + this.yOffset = 0; | ||
| 106 | + this.layoutId = 0; | ||
| 107 | + this.viewId = 0; | ||
| 108 | + } | ||
| 109 | + | ||
| 110 | + public int getGravity() { | ||
| 111 | + return this.gravity; | ||
| 112 | + } | ||
| 113 | + | ||
| 114 | + public Build setGravity(int gravity) { | ||
| 115 | + this.gravity = gravity; | ||
| 116 | + return this; | ||
| 117 | + } | ||
| 118 | + | ||
| 119 | + public Build setGravity(int gravity, int xOffset, int yOffset) { | ||
| 120 | + this.gravity = gravity; | ||
| 121 | + this.xOffset = xOffset; | ||
| 122 | + this.yOffset = yOffset; | ||
| 123 | + return this; | ||
| 124 | + } | ||
| 125 | + | ||
| 126 | + public int getxOffset() { | ||
| 127 | + return this.xOffset; | ||
| 128 | + } | ||
| 129 | + | ||
| 130 | + public Build setxOffset(int xOffset) { | ||
| 131 | + this.xOffset = xOffset; | ||
| 132 | + return this; | ||
| 133 | + } | ||
| 134 | + | ||
| 135 | + public int getyOffset() { | ||
| 136 | + return this.yOffset; | ||
| 137 | + } | ||
| 138 | + | ||
| 139 | + public Build setyOffset(int yOffset) { | ||
| 140 | + this.yOffset = yOffset; | ||
| 141 | + return this; | ||
| 142 | + } | ||
| 143 | + | ||
| 144 | + public int getViewId() { | ||
| 145 | + return this.viewId; | ||
| 146 | + } | ||
| 147 | + | ||
| 148 | + public Build setViewId(int viewId) { | ||
| 149 | + this.viewId = viewId; | ||
| 150 | + return this; | ||
| 151 | + } | ||
| 152 | + | ||
| 153 | + public Build setView(int layoutId, int viewId) { | ||
| 154 | + this.viewId = viewId; | ||
| 155 | + this.layoutId = layoutId; | ||
| 156 | + return this; | ||
| 157 | + } | ||
| 158 | + | ||
| 159 | + public int getLayoutId() { | ||
| 160 | + return this.layoutId; | ||
| 161 | + } | ||
| 162 | + | ||
| 163 | + public Build setLayoutId(int layoutId) { | ||
| 164 | + this.layoutId = layoutId; | ||
| 165 | + return this; | ||
| 166 | + } | ||
| 167 | + | ||
| 168 | + public ToastUtil build(Context context) { | ||
| 169 | + return new ToastUtil(context, this); | ||
| 170 | + } | ||
| 171 | + } | ||
| 172 | +} |
cloud/wjj_lib/src/main/java/com/cnlive/libs/base/util/UUIDUtils.java
0 → 100644
| 1 | +package com.cnlive.libs.base.util; | ||
| 2 | + | ||
| 3 | +import android.annotation.SuppressLint; | ||
| 4 | +import android.content.Context; | ||
| 5 | +import android.os.Environment; | ||
| 6 | +import android.telephony.TelephonyManager; | ||
| 7 | +import android.text.TextUtils; | ||
| 8 | +import android.util.Log; | ||
| 9 | + | ||
| 10 | +import java.io.BufferedReader; | ||
| 11 | +import java.io.File; | ||
| 12 | +import java.io.FileInputStream; | ||
| 13 | +import java.io.FileOutputStream; | ||
| 14 | +import java.io.InputStreamReader; | ||
| 15 | +import java.io.OutputStreamWriter; | ||
| 16 | +import java.util.UUID; | ||
| 17 | + | ||
| 18 | +public class UUIDUtils { | ||
| 19 | + public UUIDUtils() { | ||
| 20 | + } | ||
| 21 | + | ||
| 22 | + private static String a() { | ||
| 23 | + if (b()) { | ||
| 24 | + return a(Environment.getExternalStorageDirectory().getAbsolutePath() + "/.com.cnlive.id/uuid.dat"); | ||
| 25 | + } else { | ||
| 26 | + String var0 = UUID.randomUUID().toString().replaceAll("-", ""); | ||
| 27 | + a(Environment.getExternalStorageDirectory().getAbsolutePath() + "/.com.cnlive.id/uuid.dat", var0); | ||
| 28 | + return var0; | ||
| 29 | + } | ||
| 30 | + } | ||
| 31 | + | ||
| 32 | + private static boolean b() { | ||
| 33 | + File var0 = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/.com.cnlive.id"); | ||
| 34 | + if (var0.exists()) { | ||
| 35 | + File var1 = new File(var0, "uuid.dat"); | ||
| 36 | + return var1.exists(); | ||
| 37 | + } else { | ||
| 38 | + if (var0.mkdirs()) { | ||
| 39 | + Log.e("UUIDUtils", "mkdirs failure."); | ||
| 40 | + } | ||
| 41 | + | ||
| 42 | + return false; | ||
| 43 | + } | ||
| 44 | + } | ||
| 45 | + | ||
| 46 | + private static String a(String var0) { | ||
| 47 | + try { | ||
| 48 | + File var1 = new File(var0); | ||
| 49 | + InputStreamReader var2 = new InputStreamReader(new FileInputStream(var1), "UTF-8"); | ||
| 50 | + BufferedReader var3 = new BufferedReader(var2); | ||
| 51 | + | ||
| 52 | + String var4; | ||
| 53 | + String var5; | ||
| 54 | + for (var4 = ""; (var5 = var3.readLine()) != null; var4 = var4 + var5) { | ||
| 55 | + ; | ||
| 56 | + } | ||
| 57 | + | ||
| 58 | + return var4; | ||
| 59 | + } catch (Exception var6) { | ||
| 60 | + Log.e("UUIDUtils", "file read error.", var6); | ||
| 61 | + return "uuid"; | ||
| 62 | + } | ||
| 63 | + } | ||
| 64 | + | ||
| 65 | + private static void a(String var0, String var1) { | ||
| 66 | + try { | ||
| 67 | + FileOutputStream var2 = new FileOutputStream(var0, true); | ||
| 68 | + OutputStreamWriter var3 = new OutputStreamWriter(var2, "utf-8"); | ||
| 69 | + var3.write(var1); | ||
| 70 | + var3.flush(); | ||
| 71 | + var3.close(); | ||
| 72 | + var2.close(); | ||
| 73 | + } catch (Exception var4) { | ||
| 74 | + Log.e("UUIDUtils", "file write error.", var4); | ||
| 75 | + } | ||
| 76 | + | ||
| 77 | + } | ||
| 78 | + | ||
| 79 | + @SuppressLint("MissingPermission") | ||
| 80 | + private static String getPhoneUUID(Context context) { | ||
| 81 | + try { | ||
| 82 | + TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); | ||
| 83 | + String tmDevice, tmSerial, androidId; | ||
| 84 | + tmDevice = "" + tm.getDeviceId(); | ||
| 85 | + tmSerial = "" + tm.getSimSerialNumber(); | ||
| 86 | + androidId = "" + android.provider.Settings.Secure.getString(context.getContentResolver(), android.provider.Settings.Secure.ANDROID_ID); | ||
| 87 | + UUID deviceUuid = new UUID(androidId.hashCode(), ((long) tmDevice.hashCode() << 32) | tmSerial.hashCode()); | ||
| 88 | + return deviceUuid.toString().replaceAll("-", ""); | ||
| 89 | + } catch (Exception e) { | ||
| 90 | + Log.e("UUIDUtil", "", e); | ||
| 91 | + } | ||
| 92 | + return ""; | ||
| 93 | + } | ||
| 94 | + | ||
| 95 | + private static String getRandomUUID() { | ||
| 96 | + return UUID.randomUUID().toString().replaceAll("-", ""); | ||
| 97 | + } | ||
| 98 | + | ||
| 99 | + private static String initUUID(Context context) { | ||
| 100 | + String v1 = getPhoneUUID(context); | ||
| 101 | + if (!TextUtils.isEmpty(v1)) return v1; | ||
| 102 | + String v2 = getRandomUUID(); | ||
| 103 | + if (!TextUtils.isEmpty(v2)) return v2; | ||
| 104 | + String v3 = a(); | ||
| 105 | + if (!TextUtils.isEmpty(v3)) return v3; | ||
| 106 | + return "uuid"; | ||
| 107 | + } | ||
| 108 | + | ||
| 109 | + public static String getUUID(Context context) { | ||
| 110 | + SharedPreferencesHelper sph = SharedPreferencesHelper.getInstance(context); | ||
| 111 | + if (sph == null) { | ||
| 112 | + return ""; | ||
| 113 | + } else { | ||
| 114 | + String cacheUUID = sph.getValue("cnlive_uuid"); | ||
| 115 | + if (TextUtils.isEmpty(cacheUUID)) { | ||
| 116 | + String uuid = initUUID(context).concat("_").concat(String.valueOf(System.currentTimeMillis())); | ||
| 117 | + sph.setValue("cnlive_uuid", uuid); | ||
| 118 | + return uuid; | ||
| 119 | + | ||
| 120 | + } else return cacheUUID; | ||
| 121 | + } | ||
| 122 | + } | ||
| 123 | +} | ||
| 0 | \ No newline at end of file | 124 | \ No newline at end of file |
cloud/wjj_lib/src/main/java/com/cnlive/libs/base/util/badger/BadgeUtil.java
0 → 100644
| 1 | +package com.cnlive.libs.base.util.badger; | ||
| 2 | + | ||
| 3 | +import android.app.Notification; | ||
| 4 | +import android.content.Context; | ||
| 5 | +import android.content.Intent; | ||
| 6 | +import android.content.pm.PackageManager; | ||
| 7 | +import android.content.pm.ResolveInfo; | ||
| 8 | + | ||
| 9 | +import com.cnlive.libs.util.Config; | ||
| 10 | + | ||
| 11 | +import java.util.ArrayList; | ||
| 12 | +import java.util.List; | ||
| 13 | + | ||
| 14 | + | ||
| 15 | +public class BadgeUtil { | ||
| 16 | + | ||
| 17 | + private static final String TAG = BadgeUtil.class.getSimpleName(); | ||
| 18 | + private static List<Integer> notifyIdList = new ArrayList<>(); | ||
| 19 | + private static Badger badger; | ||
| 20 | + | ||
| 21 | + /** | ||
| 22 | + * @param notification 更新角标一般都是和发送notification并行的。如果不想发notification只是更新角标,这里传null | ||
| 23 | + * @param notifyID notification id | ||
| 24 | + * @param context | ||
| 25 | + * @param thisNotifyCount notifyID对应的notification的未读总数(XiaoMi 发送的是这个count,XiaoMI 会自动计算所有notification 未读数量只和) | ||
| 26 | + * @param count 整个app所有的未读数量(其他的是使用这个count) | ||
| 27 | + */ | ||
| 28 | + public static void sendBadgeNotification(Notification notification, int notifyID, Context context, int thisNotifyCount, int count) { | ||
| 29 | + if (count <= 0) { | ||
| 30 | + count = 0; | ||
| 31 | + } else { | ||
| 32 | + count = Math.max(0, Math.min(count, 99)); | ||
| 33 | + } | ||
| 34 | + | ||
| 35 | + String currentHomePackage = getLauncherName(context); | ||
| 36 | + | ||
| 37 | + if (badger == null) | ||
| 38 | + badger = BadgerType.getBadgerByLauncherName(currentHomePackage); | ||
| 39 | + if (badger != null) | ||
| 40 | + badger.executeBadge(context, notification, notifyID, thisNotifyCount, count); | ||
| 41 | + } | ||
| 42 | + | ||
| 43 | + | ||
| 44 | + /** | ||
| 45 | + * 重置、清除Badge未读显示数<br/> | ||
| 46 | + */ | ||
| 47 | + public static void resetBadgeCount(Context context) { | ||
| 48 | + sendBadgeNotification(null, 0, context, 0, 0); | ||
| 49 | + } | ||
| 50 | + | ||
| 51 | + public static void resetBadgeCount(int thisNotifyCount) { | ||
| 52 | + sendBadgeNotification(null, 0, Config.getContext(), thisNotifyCount, 0); | ||
| 53 | + } | ||
| 54 | + | ||
| 55 | + /** | ||
| 56 | + * 获取手机的launcher name | ||
| 57 | + * | ||
| 58 | + * @param context | ||
| 59 | + * @return | ||
| 60 | + */ | ||
| 61 | + private static String getLauncherName(Context context) { | ||
| 62 | + Intent intent = new Intent(Intent.ACTION_MAIN); | ||
| 63 | + intent.addCategory(Intent.CATEGORY_HOME); | ||
| 64 | + ResolveInfo resolveInfo = context.getPackageManager().resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY); | ||
| 65 | + if (resolveInfo != null) | ||
| 66 | + return resolveInfo.activityInfo.packageName; | ||
| 67 | + else | ||
| 68 | + return ""; | ||
| 69 | + } | ||
| 70 | +} |
cloud/wjj_lib/src/main/java/com/cnlive/libs/base/util/badger/Badger.java
0 → 100644
| 1 | +package com.cnlive.libs.base.util.badger; | ||
| 2 | + | ||
| 3 | +import android.app.Notification; | ||
| 4 | +import android.app.NotificationChannel; | ||
| 5 | +import android.app.NotificationManager; | ||
| 6 | +import android.content.Context; | ||
| 7 | +import android.content.Intent; | ||
| 8 | +import android.content.pm.PackageManager; | ||
| 9 | +import android.content.pm.ResolveInfo; | ||
| 10 | +import android.graphics.Color; | ||
| 11 | +import android.os.Build; | ||
| 12 | + | ||
| 13 | +import java.util.List; | ||
| 14 | + | ||
| 15 | +public abstract class Badger { | ||
| 16 | + | ||
| 17 | + /** | ||
| 18 | + * @param context | ||
| 19 | + * @param notification 更新角标一般都是和发送notification并行的。如果不想发notification只是更新角标,这里传null | ||
| 20 | + * @param notificationId | ||
| 21 | + * @param thisNotificationCount | ||
| 22 | + * @param count | ||
| 23 | + */ | ||
| 24 | + public abstract void executeBadge(Context context, Notification notification, int notificationId, int thisNotificationCount, int count); | ||
| 25 | + | ||
| 26 | + public abstract List<String> getSupportLaunchers(); | ||
| 27 | + | ||
| 28 | + /** | ||
| 29 | + * 获取当前app 的启动页面activity的classname | ||
| 30 | + * | ||
| 31 | + * @param context | ||
| 32 | + * @return | ||
| 33 | + */ | ||
| 34 | + protected static String getLauncherClassName(Context context) { | ||
| 35 | + PackageManager packageManager = context.getPackageManager(); | ||
| 36 | + | ||
| 37 | + Intent intent = new Intent(Intent.ACTION_MAIN); | ||
| 38 | + // To limit the components this Intent will resolve to, by setting an | ||
| 39 | + // explicit package name. | ||
| 40 | + intent.setPackage(context.getPackageName()); | ||
| 41 | + intent.addCategory(Intent.CATEGORY_LAUNCHER); | ||
| 42 | + | ||
| 43 | + // All Application must have 1 Activity at least. | ||
| 44 | + // Launcher activity must be found! | ||
| 45 | + ResolveInfo info = packageManager | ||
| 46 | + .resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY); | ||
| 47 | + | ||
| 48 | + // get a ResolveInfo containing ACTION_MAIN, CATEGORY_LAUNCHER | ||
| 49 | + // if there is no Activity which has filtered by CATEGORY_DEFAULT | ||
| 50 | + if (info == null) { | ||
| 51 | + info = packageManager.resolveActivity(intent, 0); | ||
| 52 | + } | ||
| 53 | + | ||
| 54 | + if (info == null || info.activityInfo == null) { | ||
| 55 | + return null; | ||
| 56 | + } | ||
| 57 | + | ||
| 58 | + return info.activityInfo.name; | ||
| 59 | + } | ||
| 60 | + | ||
| 61 | + protected void setNotification(Notification notification, int notificationId, Context context) { | ||
| 62 | + if (notification != null) { | ||
| 63 | + NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); | ||
| 64 | + | ||
| 65 | + notificationManager.notify(notificationId, notification); | ||
| 66 | + } | ||
| 67 | + } | ||
| 68 | +} |
cloud/wjj_lib/src/main/java/com/cnlive/libs/base/util/badger/BadgerType.java
0 → 100644
| 1 | +package com.cnlive.libs.base.util.badger; | ||
| 2 | + | ||
| 3 | +import android.text.TextUtils; | ||
| 4 | + | ||
| 5 | + | ||
| 6 | +import com.cnlive.libs.base.util.badger.impl.AdwHomeBadger; | ||
| 7 | +import com.cnlive.libs.base.util.badger.impl.ApexHomeBadger; | ||
| 8 | +import com.cnlive.libs.base.util.badger.impl.AsusHomeLauncher; | ||
| 9 | +import com.cnlive.libs.base.util.badger.impl.DefaultBadger; | ||
| 10 | +import com.cnlive.libs.base.util.badger.impl.HuaWeiBadger; | ||
| 11 | +import com.cnlive.libs.base.util.badger.impl.LGHomeBadger; | ||
| 12 | +import com.cnlive.libs.base.util.badger.impl.NewHtcHomeBadger; | ||
| 13 | +import com.cnlive.libs.base.util.badger.impl.NovaHomeBadger; | ||
| 14 | +import com.cnlive.libs.base.util.badger.impl.SamsungHomeBadger; | ||
| 15 | +import com.cnlive.libs.base.util.badger.impl.SolidHomeBadger; | ||
| 16 | +import com.cnlive.libs.base.util.badger.impl.SonyHomeBadger; | ||
| 17 | +import com.cnlive.libs.base.util.badger.impl.VIVOBadger; | ||
| 18 | +import com.cnlive.libs.base.util.badger.impl.XiaomiHomeBadger; | ||
| 19 | + | ||
| 20 | +import java.util.List; | ||
| 21 | + | ||
| 22 | +public enum BadgerType { | ||
| 23 | + DEFAULT { | ||
| 24 | + @Override | ||
| 25 | + public Badger initBadger() { | ||
| 26 | + return new DefaultBadger(); | ||
| 27 | + } | ||
| 28 | + }, ADW { | ||
| 29 | + @Override | ||
| 30 | + public Badger initBadger() { | ||
| 31 | + return new AdwHomeBadger(); | ||
| 32 | + } | ||
| 33 | + }, APEX { | ||
| 34 | + @Override | ||
| 35 | + public Badger initBadger() { | ||
| 36 | + return new ApexHomeBadger(); | ||
| 37 | + } | ||
| 38 | + }, ASUS { | ||
| 39 | + @Override | ||
| 40 | + public Badger initBadger() { | ||
| 41 | + return new AsusHomeLauncher(); | ||
| 42 | + } | ||
| 43 | + }, LG { | ||
| 44 | + @Override | ||
| 45 | + public Badger initBadger() { | ||
| 46 | + return new LGHomeBadger(); | ||
| 47 | + } | ||
| 48 | + }, HTC { | ||
| 49 | + @Override | ||
| 50 | + public Badger initBadger() { | ||
| 51 | + return new NewHtcHomeBadger(); | ||
| 52 | + } | ||
| 53 | + }, NOVA { | ||
| 54 | + @Override | ||
| 55 | + public Badger initBadger() { | ||
| 56 | + return new NovaHomeBadger(); | ||
| 57 | + } | ||
| 58 | + }, SAMSUNG { | ||
| 59 | + @Override | ||
| 60 | + public Badger initBadger() { | ||
| 61 | + return new SamsungHomeBadger(); | ||
| 62 | + } | ||
| 63 | + }, SOLID { | ||
| 64 | + @Override | ||
| 65 | + public Badger initBadger() { | ||
| 66 | + return new SolidHomeBadger(); | ||
| 67 | + } | ||
| 68 | + }, SONY { | ||
| 69 | + @Override | ||
| 70 | + public Badger initBadger() { | ||
| 71 | + return new SonyHomeBadger(); | ||
| 72 | + } | ||
| 73 | + }, XIAO_MI { | ||
| 74 | + @Override | ||
| 75 | + public Badger initBadger() { | ||
| 76 | + return new XiaomiHomeBadger(); | ||
| 77 | + } | ||
| 78 | + },ViVO { | ||
| 79 | + @Override | ||
| 80 | + public Badger initBadger() { | ||
| 81 | + return new VIVOBadger(); | ||
| 82 | + } | ||
| 83 | + | ||
| 84 | + },HuaWei { | ||
| 85 | + @Override | ||
| 86 | + public Badger initBadger() { | ||
| 87 | + return new HuaWeiBadger(); | ||
| 88 | + } | ||
| 89 | + }; | ||
| 90 | + | ||
| 91 | + public Badger badger; | ||
| 92 | + | ||
| 93 | + public static Badger getBadgerByLauncherName(String launcherName) { | ||
| 94 | + Badger result = new DefaultBadger(); | ||
| 95 | + if (!TextUtils.isEmpty(launcherName)) | ||
| 96 | + for (BadgerType badgerType : BadgerType.values()) { | ||
| 97 | + if (badgerType.getSupportLaunchers().contains(launcherName)) { | ||
| 98 | + result = badgerType.getBadger(); | ||
| 99 | + break; | ||
| 100 | + } | ||
| 101 | + } | ||
| 102 | + return result; | ||
| 103 | + } | ||
| 104 | + | ||
| 105 | + public Badger getBadger() { | ||
| 106 | + if (badger == null) | ||
| 107 | + badger = initBadger(); | ||
| 108 | + return badger; | ||
| 109 | + } | ||
| 110 | + | ||
| 111 | + public abstract Badger initBadger(); | ||
| 112 | + | ||
| 113 | + public List<String> getSupportLaunchers() { | ||
| 114 | + return getBadger().getSupportLaunchers(); | ||
| 115 | + } | ||
| 116 | +} |
cloud/wjj_lib/src/main/java/com/cnlive/libs/base/util/badger/impl/AdwHomeBadger.java
0 → 100644
| 1 | +package com.cnlive.libs.base.util.badger.impl; | ||
| 2 | + | ||
| 3 | +import android.app.Notification; | ||
| 4 | +import android.content.Context; | ||
| 5 | +import android.content.Intent; | ||
| 6 | + | ||
| 7 | + | ||
| 8 | +import com.cnlive.libs.base.util.badger.Badger; | ||
| 9 | + | ||
| 10 | +import java.util.Arrays; | ||
| 11 | +import java.util.List; | ||
| 12 | + | ||
| 13 | + | ||
| 14 | +public class AdwHomeBadger extends Badger { | ||
| 15 | + | ||
| 16 | + public static final String INTENT_UPDATE_COUNTER = "org.adw.launcher.counter.SEND"; | ||
| 17 | + public static final String PACKAGENAME = "PNAME"; | ||
| 18 | + public static final String COUNT = "COUNT"; | ||
| 19 | + | ||
| 20 | + @Override | ||
| 21 | + public void executeBadge(Context context, Notification notification, int notificationId, int thisNotificationCount, int count) { | ||
| 22 | + setNotification(notification, notificationId, context); | ||
| 23 | + String launcherClassName = getLauncherClassName(context); | ||
| 24 | + if (launcherClassName == null) { | ||
| 25 | + return; | ||
| 26 | + } | ||
| 27 | + | ||
| 28 | + Intent intent = new Intent(INTENT_UPDATE_COUNTER); | ||
| 29 | + intent.putExtra(PACKAGENAME, context.getPackageName()); | ||
| 30 | + intent.putExtra(COUNT, thisNotificationCount); | ||
| 31 | + context.sendBroadcast(intent); | ||
| 32 | + } | ||
| 33 | + | ||
| 34 | + @Override | ||
| 35 | + public List<String> getSupportLaunchers() { | ||
| 36 | + return Arrays.asList( | ||
| 37 | + "org.adw.launcher", | ||
| 38 | + "org.adwfreak.launcher" | ||
| 39 | + ); | ||
| 40 | + } | ||
| 41 | +} |
cloud/wjj_lib/src/main/java/com/cnlive/libs/base/util/badger/impl/ApexHomeBadger.java
0 → 100644
| 1 | +package com.cnlive.libs.base.util.badger.impl; | ||
| 2 | + | ||
| 3 | +import android.app.Notification; | ||
| 4 | +import android.content.Context; | ||
| 5 | +import android.content.Intent; | ||
| 6 | + | ||
| 7 | + | ||
| 8 | +import com.cnlive.libs.base.util.badger.Badger; | ||
| 9 | + | ||
| 10 | +import java.util.Arrays; | ||
| 11 | +import java.util.List; | ||
| 12 | + | ||
| 13 | +public class ApexHomeBadger extends Badger { | ||
| 14 | + | ||
| 15 | + private static final String INTENT_UPDATE_COUNTER = "com.anddoes.launcher.COUNTER_CHANGED"; | ||
| 16 | + private static final String PACKAGENAME = "package"; | ||
| 17 | + private static final String COUNT = "count"; | ||
| 18 | + private static final String CLASS = "class"; | ||
| 19 | + | ||
| 20 | + @Override | ||
| 21 | + public void executeBadge(Context context, Notification notification, int notificationId, int thisNotificationCount, int count) { | ||
| 22 | + setNotification(notification, notificationId, context); | ||
| 23 | + String launcherClassName = getLauncherClassName(context); | ||
| 24 | + if (launcherClassName == null) { | ||
| 25 | + return; | ||
| 26 | + } | ||
| 27 | + | ||
| 28 | + Intent intent = new Intent(INTENT_UPDATE_COUNTER); | ||
| 29 | + intent.putExtra(PACKAGENAME, context.getPackageName()); | ||
| 30 | + intent.putExtra(COUNT, thisNotificationCount); | ||
| 31 | + intent.putExtra(CLASS, launcherClassName); | ||
| 32 | + context.sendBroadcast(intent); | ||
| 33 | + } | ||
| 34 | + | ||
| 35 | + @Override | ||
| 36 | + public List<String> getSupportLaunchers() { | ||
| 37 | + return Arrays.asList("com.anddoes.launcher"); | ||
| 38 | + } | ||
| 39 | +} |
cloud/wjj_lib/src/main/java/com/cnlive/libs/base/util/badger/impl/AsusHomeLauncher.java
0 → 100644
| 1 | +package com.cnlive.libs.base.util.badger.impl; | ||
| 2 | + | ||
| 3 | +import android.app.Notification; | ||
| 4 | +import android.content.Context; | ||
| 5 | +import android.content.Intent; | ||
| 6 | + | ||
| 7 | + | ||
| 8 | +import com.cnlive.libs.base.util.badger.Badger; | ||
| 9 | + | ||
| 10 | +import java.util.Arrays; | ||
| 11 | +import java.util.List; | ||
| 12 | + | ||
| 13 | + | ||
| 14 | +public class AsusHomeLauncher extends Badger { | ||
| 15 | + | ||
| 16 | + private static final String INTENT_ACTION = "android.intent.action.BADGE_COUNT_UPDATE"; | ||
| 17 | + private static final String INTENT_EXTRA_BADGE_COUNT = "badge_count"; | ||
| 18 | + private static final String INTENT_EXTRA_PACKAGENAME = "badge_count_package_name"; | ||
| 19 | + private static final String INTENT_EXTRA_ACTIVITY_NAME = "badge_count_class_name"; | ||
| 20 | + | ||
| 21 | + @Override | ||
| 22 | + public void executeBadge(Context context, Notification notification, int notificationId, int thisNotificationCount, int count) { | ||
| 23 | + setNotification(notification, notificationId, context); | ||
| 24 | + String launcherClassName = getLauncherClassName(context); | ||
| 25 | + if (launcherClassName == null) { | ||
| 26 | + return; | ||
| 27 | + } | ||
| 28 | + | ||
| 29 | + Intent intent = new Intent(INTENT_ACTION); | ||
| 30 | + intent.putExtra(INTENT_EXTRA_BADGE_COUNT, thisNotificationCount); | ||
| 31 | + intent.putExtra(INTENT_EXTRA_PACKAGENAME, context.getPackageName()); | ||
| 32 | + intent.putExtra(INTENT_EXTRA_ACTIVITY_NAME, launcherClassName); | ||
| 33 | + intent.putExtra("badge_vip_count", 0); | ||
| 34 | + context.sendBroadcast(intent); | ||
| 35 | + } | ||
| 36 | + | ||
| 37 | + @Override | ||
| 38 | + public List<String> getSupportLaunchers() { | ||
| 39 | + return Arrays.asList("com.asus.launcher"); | ||
| 40 | + } | ||
| 41 | +} |
cloud/wjj_lib/src/main/java/com/cnlive/libs/base/util/badger/impl/DefaultBadger.java
0 → 100644
| 1 | +package com.cnlive.libs.base.util.badger.impl; | ||
| 2 | + | ||
| 3 | +import android.app.Notification; | ||
| 4 | +import android.content.Context; | ||
| 5 | +import android.content.Intent; | ||
| 6 | + | ||
| 7 | +import com.cnlive.libs.base.util.badger.Badger; | ||
| 8 | +import java.util.ArrayList; | ||
| 9 | +import java.util.List; | ||
| 10 | + | ||
| 11 | + | ||
| 12 | +public class DefaultBadger extends Badger { | ||
| 13 | + private static final String INTENT_ACTION = "android.intent.action.BADGE_COUNT_UPDATE"; | ||
| 14 | + private static final String INTENT_EXTRA_BADGE_COUNT = "badge_count"; | ||
| 15 | + private static final String INTENT_EXTRA_PACKAGENAME = "badge_count_package_name"; | ||
| 16 | + private static final String INTENT_EXTRA_ACTIVITY_NAME = "badge_count_class_name"; | ||
| 17 | + | ||
| 18 | + @Override | ||
| 19 | + public void executeBadge(Context context, Notification notification, int notificationId, int thisNotificationCount, int count) { | ||
| 20 | + setNotification(notification, notificationId, context); | ||
| 21 | + String launcherClassName = getLauncherClassName(context); | ||
| 22 | + if (launcherClassName == null) { | ||
| 23 | + return; | ||
| 24 | + } | ||
| 25 | + | ||
| 26 | + Intent intent = new Intent(INTENT_ACTION); | ||
| 27 | + intent.putExtra(INTENT_EXTRA_BADGE_COUNT, thisNotificationCount); | ||
| 28 | + intent.putExtra(INTENT_EXTRA_PACKAGENAME, context.getPackageName()); | ||
| 29 | + intent.putExtra(INTENT_EXTRA_ACTIVITY_NAME, launcherClassName); | ||
| 30 | + context.sendBroadcast(intent); | ||
| 31 | + } | ||
| 32 | + | ||
| 33 | + @Override | ||
| 34 | + public List<String> getSupportLaunchers() { | ||
| 35 | + return new ArrayList<String>(0); | ||
| 36 | + } | ||
| 37 | +} |
cloud/wjj_lib/src/main/java/com/cnlive/libs/base/util/badger/impl/HuaWeiBadger.java
0 → 100644
| 1 | +package com.cnlive.libs.base.util.badger.impl; | ||
| 2 | + | ||
| 3 | +import android.app.Notification; | ||
| 4 | +import android.content.ContentResolver; | ||
| 5 | +import android.content.Context; | ||
| 6 | +import android.content.Intent; | ||
| 7 | +import android.content.pm.PackageInfo; | ||
| 8 | +import android.content.pm.PackageManager; | ||
| 9 | +import android.net.Uri; | ||
| 10 | +import android.os.Bundle; | ||
| 11 | + | ||
| 12 | +import com.cnlive.libs.base.util.badger.Badger; | ||
| 13 | + | ||
| 14 | +import java.util.Arrays; | ||
| 15 | +import java.util.List; | ||
| 16 | + | ||
| 17 | + | ||
| 18 | +public class HuaWeiBadger extends Badger { | ||
| 19 | + | ||
| 20 | + | ||
| 21 | + | ||
| 22 | + @Override | ||
| 23 | + public void executeBadge(Context context, Notification notification, int notificationId, int thisNotificationCount, int count) { | ||
| 24 | + setNotification(notification, notificationId, context); | ||
| 25 | + checkIsSupportedByVersion(context); | ||
| 26 | + if(!isSupportedBade){ | ||
| 27 | + return; | ||
| 28 | + } | ||
| 29 | + | ||
| 30 | + try{ | ||
| 31 | + String launcherClassName = getLauncherClassName(context); | ||
| 32 | + Bundle bunlde =new Bundle(); | ||
| 33 | + bunlde.putString("package", context.getPackageName()); | ||
| 34 | + bunlde.putString("class", launcherClassName); | ||
| 35 | + bunlde.putInt("badgenumber",thisNotificationCount); | ||
| 36 | + context.getContentResolver().call(Uri.parse("content://com.huawei.android.launcher.settings/badge/"), "change_badge", null, bunlde); | ||
| 37 | + | ||
| 38 | + }catch(Exception e){ | ||
| 39 | + e.printStackTrace(); | ||
| 40 | + } | ||
| 41 | + } | ||
| 42 | + | ||
| 43 | + @Override | ||
| 44 | + public List<String> getSupportLaunchers() { | ||
| 45 | + return Arrays.asList( | ||
| 46 | + "com.huawei.android.launcher" | ||
| 47 | + ); | ||
| 48 | + } | ||
| 49 | + | ||
| 50 | +boolean isSupportedBade; | ||
| 51 | + //检测EMUI版本是否支持 | ||
| 52 | + public void checkIsSupportedByVersion( Context context){ | ||
| 53 | + try { | ||
| 54 | + PackageManager manager =context. getPackageManager(); | ||
| 55 | + PackageInfo info = manager.getPackageInfo("com.huawei.android.launcher", 0); | ||
| 56 | + if(info.versionCode>=63029){ | ||
| 57 | + isSupportedBade = true; | ||
| 58 | + } | ||
| 59 | + } catch (Exception e) { | ||
| 60 | + e.printStackTrace(); | ||
| 61 | + } | ||
| 62 | + } | ||
| 63 | + | ||
| 64 | + | ||
| 65 | + | ||
| 66 | + | ||
| 67 | + | ||
| 68 | +} |
cloud/wjj_lib/src/main/java/com/cnlive/libs/base/util/badger/impl/LGHomeBadger.java
0 → 100644
| 1 | +package com.cnlive.libs.base.util.badger.impl; | ||
| 2 | + | ||
| 3 | +import android.app.Notification; | ||
| 4 | +import android.content.Context; | ||
| 5 | +import android.content.Intent; | ||
| 6 | + | ||
| 7 | + | ||
| 8 | +import com.cnlive.libs.base.util.badger.Badger; | ||
| 9 | + | ||
| 10 | +import java.util.Arrays; | ||
| 11 | +import java.util.List; | ||
| 12 | + | ||
| 13 | + | ||
| 14 | +public class LGHomeBadger extends Badger { | ||
| 15 | + | ||
| 16 | + private static final String INTENT_ACTION = "android.intent.action.BADGE_COUNT_UPDATE"; | ||
| 17 | + private static final String INTENT_EXTRA_BADGE_COUNT = "badge_count"; | ||
| 18 | + private static final String INTENT_EXTRA_PACKAGENAME = "badge_count_package_name"; | ||
| 19 | + private static final String INTENT_EXTRA_ACTIVITY_NAME = "badge_count_class_name"; | ||
| 20 | + | ||
| 21 | + @Override | ||
| 22 | + public void executeBadge(Context context, Notification notification, int notificationId, int thisNotificationCount, int count) { | ||
| 23 | + setNotification(notification, notificationId, context); | ||
| 24 | + String launcherClassName = getLauncherClassName(context); | ||
| 25 | + if (launcherClassName == null) { | ||
| 26 | + return; | ||
| 27 | + } | ||
| 28 | + | ||
| 29 | + Intent intent = new Intent(INTENT_ACTION); | ||
| 30 | + intent.putExtra(INTENT_EXTRA_BADGE_COUNT, thisNotificationCount); | ||
| 31 | + intent.putExtra(INTENT_EXTRA_PACKAGENAME, context.getPackageName()); | ||
| 32 | + intent.putExtra(INTENT_EXTRA_ACTIVITY_NAME, launcherClassName); | ||
| 33 | + context.sendBroadcast(intent); | ||
| 34 | + } | ||
| 35 | + | ||
| 36 | + @Override | ||
| 37 | + public List<String> getSupportLaunchers() { | ||
| 38 | + return Arrays.asList( | ||
| 39 | + "com.lge.launcher", | ||
| 40 | + "com.lge.launcher2" | ||
| 41 | + ); | ||
| 42 | + } | ||
| 43 | +} |
cloud/wjj_lib/src/main/java/com/cnlive/libs/base/util/badger/impl/NewHtcHomeBadger.java
0 → 100644
| 1 | +package com.cnlive.libs.base.util.badger.impl; | ||
| 2 | + | ||
| 3 | +import android.app.Notification; | ||
| 4 | +import android.content.ComponentName; | ||
| 5 | +import android.content.Context; | ||
| 6 | +import android.content.Intent; | ||
| 7 | + | ||
| 8 | +import com.cnlive.libs.base.util.badger.Badger; | ||
| 9 | +import java.util.Arrays; | ||
| 10 | +import java.util.List; | ||
| 11 | + | ||
| 12 | + | ||
| 13 | +public class NewHtcHomeBadger extends Badger { | ||
| 14 | + | ||
| 15 | + public static final String INTENT_UPDATE_SHORTCUT = "com.htc.launcher.action.UPDATE_SHORTCUT"; | ||
| 16 | + public static final String INTENT_SET_NOTIFICATION = "com.htc.launcher.action.SET_NOTIFICATION"; | ||
| 17 | + public static final String PACKAGENAME = "packagename"; | ||
| 18 | + public static final String COUNT = "count"; | ||
| 19 | + public static final String EXTRA_COMPONENT = "com.htc.launcher.extra.COMPONENT"; | ||
| 20 | + public static final String EXTRA_COUNT = "com.htc.launcher.extra.COUNT"; | ||
| 21 | + | ||
| 22 | + @Override | ||
| 23 | + public void executeBadge(Context context, Notification notification, int notificationId, int thisNotificationCount, int count) { | ||
| 24 | + setNotification(notification, notificationId, context); | ||
| 25 | + String launcherClassName = getLauncherClassName(context); | ||
| 26 | + if (launcherClassName == null) { | ||
| 27 | + return; | ||
| 28 | + } | ||
| 29 | + ComponentName localComponentName = new ComponentName(context.getPackageName(), | ||
| 30 | + getLauncherClassName(context)); | ||
| 31 | + | ||
| 32 | + Intent intent1 = new Intent(INTENT_SET_NOTIFICATION); | ||
| 33 | + intent1.putExtra(EXTRA_COMPONENT, localComponentName.flattenToShortString()); | ||
| 34 | + intent1.putExtra(EXTRA_COUNT, count); | ||
| 35 | + context.sendBroadcast(intent1); | ||
| 36 | + | ||
| 37 | + Intent intent = new Intent(INTENT_UPDATE_SHORTCUT); | ||
| 38 | + intent.putExtra(PACKAGENAME, context.getPackageName()); | ||
| 39 | + intent.putExtra(COUNT, thisNotificationCount); | ||
| 40 | + context.sendBroadcast(intent); | ||
| 41 | + } | ||
| 42 | + | ||
| 43 | + @Override | ||
| 44 | + public List<String> getSupportLaunchers() { | ||
| 45 | + return Arrays.asList("com.htc.launcher"); | ||
| 46 | + } | ||
| 47 | +} |
cloud/wjj_lib/src/main/java/com/cnlive/libs/base/util/badger/impl/NovaHomeBadger.java
0 → 100644
| 1 | +package com.cnlive.libs.base.util.badger.impl; | ||
| 2 | + | ||
| 3 | +import android.app.Notification; | ||
| 4 | +import android.content.ContentValues; | ||
| 5 | +import android.content.Context; | ||
| 6 | +import android.net.Uri; | ||
| 7 | + | ||
| 8 | +import com.cnlive.libs.base.util.badger.Badger; | ||
| 9 | +import java.util.Arrays; | ||
| 10 | +import java.util.List; | ||
| 11 | + | ||
| 12 | + | ||
| 13 | +public class NovaHomeBadger extends Badger { | ||
| 14 | + | ||
| 15 | + private static final String CONTENT_URI = "content://com.teslacoilsw.notifier/unread_count"; | ||
| 16 | + private static final String COUNT = "count"; | ||
| 17 | + private static final String TAG = "tag"; | ||
| 18 | + | ||
| 19 | + @Override | ||
| 20 | + public void executeBadge(Context context, Notification notification, int notificationId, int thisNotificationCount, int count) { | ||
| 21 | + setNotification(notification, notificationId, context); | ||
| 22 | + | ||
| 23 | + ContentValues contentValues = new ContentValues(); | ||
| 24 | + contentValues.put(TAG, context.getPackageName() + "/" + | ||
| 25 | + getLauncherClassName(context)); | ||
| 26 | + contentValues.put(COUNT, thisNotificationCount); | ||
| 27 | + try { | ||
| 28 | + context.getContentResolver().insert(Uri.parse(CONTENT_URI), | ||
| 29 | + contentValues); | ||
| 30 | + } catch (Exception e) { | ||
| 31 | + e.printStackTrace(); | ||
| 32 | + } | ||
| 33 | + } | ||
| 34 | + | ||
| 35 | + @Override | ||
| 36 | + public List<String> getSupportLaunchers() { | ||
| 37 | + return Arrays.asList("com.teslacoilsw.launcher"); | ||
| 38 | + } | ||
| 39 | +} |
cloud/wjj_lib/src/main/java/com/cnlive/libs/base/util/badger/impl/SamsungHomeBadger.java
0 → 100644
| 1 | +package com.cnlive.libs.base.util.badger.impl; | ||
| 2 | + | ||
| 3 | +import android.app.Notification; | ||
| 4 | +import android.content.Context; | ||
| 5 | +import android.content.Intent; | ||
| 6 | + | ||
| 7 | +import com.cnlive.libs.base.util.badger.Badger; | ||
| 8 | +import java.util.Arrays; | ||
| 9 | +import java.util.List; | ||
| 10 | + | ||
| 11 | + | ||
| 12 | +public class SamsungHomeBadger extends Badger { | ||
| 13 | + | ||
| 14 | + @Override | ||
| 15 | + public void executeBadge(Context context, Notification notification, int notificationId, int thisNotificationCount, int count) { | ||
| 16 | + setNotification(notification, notificationId, context); | ||
| 17 | + String launcherClassName = getLauncherClassName(context); | ||
| 18 | + if (launcherClassName == null) { | ||
| 19 | + return; | ||
| 20 | + } | ||
| 21 | + Intent intent = new Intent("android.intent.action.BADGE_COUNT_UPDATE"); | ||
| 22 | + intent.putExtra("badge_count", thisNotificationCount); | ||
| 23 | + intent.putExtra("badge_count_package_name", context.getPackageName()); | ||
| 24 | + intent.putExtra("badge_count_class_name", launcherClassName); | ||
| 25 | + context.sendBroadcast(intent); | ||
| 26 | + } | ||
| 27 | + | ||
| 28 | + @Override | ||
| 29 | + public List<String> getSupportLaunchers() { | ||
| 30 | + return Arrays.asList( | ||
| 31 | + "com.sec.android.app.launcher", | ||
| 32 | + "com.sec.android.app.twlauncher" | ||
| 33 | + ); | ||
| 34 | + } | ||
| 35 | +} |
cloud/wjj_lib/src/main/java/com/cnlive/libs/base/util/badger/impl/SolidHomeBadger.java
0 → 100644
| 1 | +package com.cnlive.libs.base.util.badger.impl; | ||
| 2 | + | ||
| 3 | +import android.app.Notification; | ||
| 4 | +import android.content.Context; | ||
| 5 | +import android.content.Intent; | ||
| 6 | + | ||
| 7 | +import com.cnlive.libs.base.util.badger.Badger; | ||
| 8 | +import java.util.Arrays; | ||
| 9 | +import java.util.List; | ||
| 10 | + | ||
| 11 | + | ||
| 12 | +public class SolidHomeBadger extends Badger { | ||
| 13 | + | ||
| 14 | + private static final String INTENT_ACTION_UPDATE_COUNTER = "com.majeur.launcher.intent.action.UPDATE_BADGE"; | ||
| 15 | + private static final String INTENT_EXTRA_PACKAGENAME = "com.majeur.launcher.intent.extra.BADGE_PACKAGE"; | ||
| 16 | + private static final String INTENT_EXTRA_COUNT = "com.majeur.launcher.intent.extra.BADGE_COUNT"; | ||
| 17 | + private static final String INTENT_EXTRA_CLASS = "com.majeur.launcher.intent.extra.BADGE_CLASS"; | ||
| 18 | + | ||
| 19 | + @Override | ||
| 20 | + public void executeBadge(Context context, Notification notification, int notificationId, int thisNotificationCount, int count) { | ||
| 21 | + setNotification(notification, notificationId, context); | ||
| 22 | + String launcherClassName = getLauncherClassName(context); | ||
| 23 | + if (launcherClassName == null) { | ||
| 24 | + return; | ||
| 25 | + } | ||
| 26 | + | ||
| 27 | + Intent intent = new Intent(INTENT_ACTION_UPDATE_COUNTER); | ||
| 28 | + intent.putExtra(INTENT_EXTRA_PACKAGENAME, context.getPackageName()); | ||
| 29 | + intent.putExtra(INTENT_EXTRA_COUNT, thisNotificationCount); | ||
| 30 | + intent.putExtra(INTENT_EXTRA_CLASS, launcherClassName); | ||
| 31 | + context.sendBroadcast(intent); | ||
| 32 | + } | ||
| 33 | + | ||
| 34 | + @Override | ||
| 35 | + public List<String> getSupportLaunchers() { | ||
| 36 | + return Arrays.asList("com.majeur.launcher"); | ||
| 37 | + } | ||
| 38 | +} |
cloud/wjj_lib/src/main/java/com/cnlive/libs/base/util/badger/impl/SonyHomeBadger.java
0 → 100644
| 1 | +package com.cnlive.libs.base.util.badger.impl; | ||
| 2 | + | ||
| 3 | +import android.app.Notification; | ||
| 4 | +import android.content.Context; | ||
| 5 | +import android.content.Intent; | ||
| 6 | + | ||
| 7 | +import com.cnlive.libs.base.util.badger.Badger; | ||
| 8 | +import java.util.Arrays; | ||
| 9 | +import java.util.List; | ||
| 10 | + | ||
| 11 | + | ||
| 12 | +public class SonyHomeBadger extends Badger { | ||
| 13 | + | ||
| 14 | + private static final String INTENT_ACTION = "com.sonyericsson.home.action.UPDATE_BADGE"; | ||
| 15 | + private static final String INTENT_EXTRA_PACKAGE_NAME = "com.sonyericsson.home.intent.extra.badge.PACKAGE_NAME"; | ||
| 16 | + private static final String INTENT_EXTRA_ACTIVITY_NAME = "com.sonyericsson.home.intent.extra.badge.ACTIVITY_NAME"; | ||
| 17 | + private static final String INTENT_EXTRA_MESSAGE = "com.sonyericsson.home.intent.extra.badge.MESSAGE"; | ||
| 18 | + private static final String INTENT_EXTRA_SHOW_MESSAGE = "com.sonyericsson.home.intent.extra.badge.SHOW_MESSAGE"; | ||
| 19 | + | ||
| 20 | + @Override | ||
| 21 | + public void executeBadge(Context context, Notification notification, int notificationId, int thisNotificationCount, int count) { | ||
| 22 | + setNotification(notification, notificationId, context); | ||
| 23 | + String launcherClassName = getLauncherClassName(context); | ||
| 24 | + if (launcherClassName == null) { | ||
| 25 | + return; | ||
| 26 | + } | ||
| 27 | + Intent intent = new Intent(INTENT_ACTION); | ||
| 28 | + intent.putExtra(INTENT_EXTRA_PACKAGE_NAME, context.getPackageName()); | ||
| 29 | + intent.putExtra(INTENT_EXTRA_ACTIVITY_NAME, launcherClassName); | ||
| 30 | + intent.putExtra(INTENT_EXTRA_MESSAGE, String.valueOf(thisNotificationCount)); | ||
| 31 | + intent.putExtra(INTENT_EXTRA_SHOW_MESSAGE, count > 0); | ||
| 32 | + context.sendBroadcast(intent); | ||
| 33 | + } | ||
| 34 | + | ||
| 35 | + @Override | ||
| 36 | + public List<String> getSupportLaunchers() { | ||
| 37 | + return Arrays.asList("com.sonyericsson.home"); | ||
| 38 | + } | ||
| 39 | +} |
cloud/wjj_lib/src/main/java/com/cnlive/libs/base/util/badger/impl/VIVOBadger.java
0 → 100644
| 1 | +package com.cnlive.libs.base.util.badger.impl; | ||
| 2 | + | ||
| 3 | +import android.app.Notification; | ||
| 4 | +import android.content.Context; | ||
| 5 | +import android.content.Intent; | ||
| 6 | + | ||
| 7 | +import com.cnlive.libs.base.util.badger.Badger; | ||
| 8 | + | ||
| 9 | +import java.util.Arrays; | ||
| 10 | +import java.util.List; | ||
| 11 | + | ||
| 12 | +/** | ||
| 13 | + * 创建:wukuiqing | ||
| 14 | + * <p> | ||
| 15 | + * 时间:2018/4/24 | ||
| 16 | + * <p> | ||
| 17 | + * 描述: | ||
| 18 | + */ | ||
| 19 | + | ||
| 20 | +public class VIVOBadger extends Badger { | ||
| 21 | + | ||
| 22 | + | ||
| 23 | + | ||
| 24 | + public static final String INTENT_UPDATE_COUNTER = "launcher.action.CHANGE_APPLICATION_NOTIFICATION_NUM"; | ||
| 25 | + public static final String PACKAGENAME = "packageName"; | ||
| 26 | + public static final String COUNT = "notificationNum"; | ||
| 27 | + | ||
| 28 | + @Override | ||
| 29 | + public void executeBadge(Context context, Notification notification, int notificationId, int thisNotificationCount, int count) { | ||
| 30 | + setNotification(notification, notificationId, context); | ||
| 31 | + String launcherClassName = getLauncherClassName(context); | ||
| 32 | + if (launcherClassName == null) { | ||
| 33 | + return; | ||
| 34 | + } | ||
| 35 | + | ||
| 36 | + Intent intent = new Intent(INTENT_UPDATE_COUNTER); | ||
| 37 | + intent.putExtra(PACKAGENAME, context.getPackageName()); | ||
| 38 | + intent.putExtra(COUNT, thisNotificationCount); | ||
| 39 | + intent.putExtra("className", launcherClassName); | ||
| 40 | + context.sendBroadcast(intent); | ||
| 41 | + } | ||
| 42 | + | ||
| 43 | + @Override | ||
| 44 | + public List<String> getSupportLaunchers() { | ||
| 45 | + return Arrays.asList( | ||
| 46 | + "com.bbk.launcher2" | ||
| 47 | + ); | ||
| 48 | + } | ||
| 49 | +} |
cloud/wjj_lib/src/main/java/com/cnlive/libs/base/util/badger/impl/XiaomiHomeBadger.java
0 → 100644
| 1 | +package com.cnlive.libs.base.util.badger.impl; | ||
| 2 | + | ||
| 3 | +import android.app.Notification; | ||
| 4 | +import android.content.Context; | ||
| 5 | + | ||
| 6 | +import com.cnlive.libs.base.util.badger.Badger; | ||
| 7 | +import java.lang.reflect.Field; | ||
| 8 | +import java.lang.reflect.Method; | ||
| 9 | +import java.util.Arrays; | ||
| 10 | +import java.util.List; | ||
| 11 | + | ||
| 12 | +public class XiaomiHomeBadger extends Badger { | ||
| 13 | + | ||
| 14 | + @Override | ||
| 15 | + public void executeBadge(Context context, Notification notification, int notificationId, int thisNotificationCount, int count) { | ||
| 16 | + try { | ||
| 17 | + Field field = notification.getClass().getDeclaredField("extraNotification"); | ||
| 18 | + Object extraNotification = field.get(notification); | ||
| 19 | + Method method = extraNotification.getClass().getDeclaredMethod("setMessageCount", int.class); | ||
| 20 | + method.invoke(extraNotification, thisNotificationCount);//小米这里只要这个notificationId 对应的count,而不是所有notification count | ||
| 21 | + } catch (Exception e) { | ||
| 22 | + e.printStackTrace(); | ||
| 23 | + } finally { | ||
| 24 | + setNotification(notification, notificationId, context); | ||
| 25 | + } | ||
| 26 | + } | ||
| 27 | + | ||
| 28 | + @Override | ||
| 29 | + public List<String> getSupportLaunchers() { | ||
| 30 | + return Arrays.asList( | ||
| 31 | + "com.miui.miuilite", | ||
| 32 | + "com.miui.home", | ||
| 33 | + "com.miui.miuihome", | ||
| 34 | + "com.miui.miuihome2", | ||
| 35 | + "com.miui.mihome", | ||
| 36 | + "com.miui.mihome2" | ||
| 37 | + ); | ||
| 38 | + } | ||
| 39 | +} |
cloud/wjj_lib/src/main/java/com/cnlive/libs/base/util/search/CharacterParser.java
0 → 100644
| 1 | +package com.cnlive.libs.base.util.search; | ||
| 2 | + | ||
| 3 | +public class CharacterParser { | ||
| 4 | + private static int[] pyvalue = new int[]{-20319, -20317, -20304, -20295, | ||
| 5 | + -20292, -20283, -20265, -20257, -20242, -20230, -20051, -20036, | ||
| 6 | + -20032, -20026, -20002, -19990, -19986, -19982, -19976, -19805, | ||
| 7 | + -19784, -19775, -19774, -19763, -19756, -19751, -19746, -19741, | ||
| 8 | + -19739, -19728, -19725, -19715, -19540, -19531, -19525, -19515, | ||
| 9 | + -19500, -19484, -19479, -19467, -19289, -19288, -19281, -19275, | ||
| 10 | + -19270, -19263, -19261, -19249, -19243, -19242, -19238, -19235, | ||
| 11 | + -19227, -19224, -19218, -19212, -19038, -19023, -19018, -19006, | ||
| 12 | + -19003, -18996, -18977, -18961, -18952, -18783, -18774, -18773, | ||
| 13 | + -18763, -18756, -18741, -18735, -18731, -18722, -18710, -18697, | ||
| 14 | + -18696, -18526, -18518, -18501, -18490, -18478, -18463, -18448, | ||
| 15 | + -18447, -18446, -18239, -18237, -18231, -18220, -18211, -18201, | ||
| 16 | + -18184, -18183, -18181, -18012, -17997, -17988, -17970, -17964, | ||
| 17 | + -17961, -17950, -17947, -17931, -17928, -17922, -17759, -17752, | ||
| 18 | + -17733, -17730, -17721, -17703, -17701, -17697, -17692, -17683, | ||
| 19 | + -17676, -17496, -17487, -17482, -17468, -17454, -17433, -17427, | ||
| 20 | + -17417, -17202, -17185, -16983, -16970, -16942, -16915, -16733, | ||
| 21 | + -16708, -16706, -16689, -16664, -16657, -16647, -16474, -16470, | ||
| 22 | + -16465, -16459, -16452, -16448, -16433, -16429, -16427, -16423, | ||
| 23 | + -16419, -16412, -16407, -16403, -16401, -16393, -16220, -16216, | ||
| 24 | + -16212, -16205, -16202, -16187, -16180, -16171, -16169, -16158, | ||
| 25 | + -16155, -15959, -15958, -15944, -15933, -15920, -15915, -15903, | ||
| 26 | + -15889, -15878, -15707, -15701, -15681, -15667, -15661, -15659, | ||
| 27 | + -15652, -15640, -15631, -15625, -15454, -15448, -15436, -15435, | ||
| 28 | + -15419, -15416, -15408, -15394, -15385, -15377, -15375, -15369, | ||
| 29 | + -15363, -15362, -15183, -15180, -15165, -15158, -15153, -15150, | ||
| 30 | + -15149, -15144, -15143, -15141, -15140, -15139, -15128, -15121, | ||
| 31 | + -15119, -15117, -15110, -15109, -14941, -14937, -14933, -14930, | ||
| 32 | + -14929, -14928, -14926, -14922, -14921, -14914, -14908, -14902, | ||
| 33 | + -14894, -14889, -14882, -14873, -14871, -14857, -14678, -14674, | ||
| 34 | + -14670, -14668, -14663, -14654, -14645, -14630, -14594, -14429, | ||
| 35 | + -14407, -14399, -14384, -14379, -14368, -14355, -14353, -14345, | ||
| 36 | + -14170, -14159, -14151, -14149, -14145, -14140, -14137, -14135, | ||
| 37 | + -14125, -14123, -14122, -14112, -14109, -14099, -14097, -14094, | ||
| 38 | + -14092, -14090, -14087, -14083, -13917, -13914, -13910, -13907, | ||
| 39 | + -13906, -13905, -13896, -13894, -13878, -13870, -13859, -13847, | ||
| 40 | + -13831, -13658, -13611, -13601, -13406, -13404, -13400, -13398, | ||
| 41 | + -13395, -13391, -13387, -13383, -13367, -13359, -13356, -13343, | ||
| 42 | + -13340, -13329, -13326, -13318, -13147, -13138, -13120, -13107, | ||
| 43 | + -13096, -13095, -13091, -13076, -13068, -13063, -13060, -12888, | ||
| 44 | + -12875, -12871, -12860, -12858, -12852, -12849, -12838, -12831, | ||
| 45 | + -12829, -12812, -12802, -12607, -12597, -12594, -12585, -12556, | ||
| 46 | + -12359, -12346, -12320, -12300, -12120, -12099, -12089, -12074, | ||
| 47 | + -12067, -12058, -12039, -11867, -11861, -11847, -11831, -11798, | ||
| 48 | + -11781, -11604, -11589, -11536, -11358, -11340, -11339, -11324, | ||
| 49 | + -11303, -11097, -11077, -11067, -11055, -11052, -11045, -11041, | ||
| 50 | + -11038, -11024, -11020, -11019, -11018, -11014, -10838, -10832, | ||
| 51 | + -10815, -10800, -10790, -10780, -10764, -10587, -10544, -10533, | ||
| 52 | + -10519, -10331, -10329, -10328, -10322, -10315, -10309, -10307, | ||
| 53 | + -10296, -10281, -10274, -10270, -10262, -10260, -10256, -10254}; | ||
| 54 | + public static String[] pystr = new String[]{"a", "ai", "an", "ang", "ao", | ||
| 55 | + "ba", "bai", "ban", "bang", "bao", "bei", "ben", "beng", "bi", | ||
| 56 | + "bian", "biao", "bie", "bin", "bing", "bo", "bu", "ca", "cai", | ||
| 57 | + "can", "cang", "cao", "ce", "ceng", "cha", "chai", "chan", "chang", | ||
| 58 | + "chao", "che", "chen", "cheng", "chi", "chong", "chou", "chu", | ||
| 59 | + "chuai", "chuan", "chuang", "chui", "chun", "chuo", "ci", "cong", | ||
| 60 | + "cou", "cu", "cuan", "cui", "cun", "cuo", "da", "dai", "dan", | ||
| 61 | + "dang", "dao", "de", "deng", "di", "dian", "diao", "die", "ding", | ||
| 62 | + "diu", "dong", "dou", "du", "duan", "dui", "dun", "duo", "e", "en", | ||
| 63 | + "er", "fa", "fan", "fang", "fei", "fen", "feng", "fo", "fou", "fu", | ||
| 64 | + "ga", "gai", "gan", "gang", "gao", "ge", "gei", "gen", "geng", | ||
| 65 | + "gong", "gou", "gu", "gua", "guai", "guan", "guang", "gui", "gun", | ||
| 66 | + "guo", "ha", "hai", "han", "hang", "hao", "he", "hei", "hen", | ||
| 67 | + "heng", "hong", "hou", "hu", "hua", "huai", "huan", "huang", "hui", | ||
| 68 | + "hun", "huo", "ji", "jia", "jian", "jiang", "jiao", "jie", "jin", | ||
| 69 | + "jing", "jiong", "jiu", "ju", "juan", "jue", "jun", "ka", "kai", | ||
| 70 | + "kan", "kang", "kao", "ke", "ken", "keng", "kong", "kou", "ku", | ||
| 71 | + "kua", "kuai", "kuan", "kuang", "kui", "kun", "kuo", "la", "lai", | ||
| 72 | + "lan", "lang", "lao", "le", "lei", "leng", "li", "lia", "lian", | ||
| 73 | + "liang", "liao", "lie", "lin", "ling", "liu", "long", "lou", "lu", | ||
| 74 | + "lv", "luan", "lue", "lun", "luo", "ma", "mai", "man", "mang", | ||
| 75 | + "mao", "me", "mei", "men", "meng", "mi", "mian", "miao", "mie", | ||
| 76 | + "min", "ming", "miu", "mo", "mou", "mu", "na", "nai", "nan", | ||
| 77 | + "nang", "nao", "ne", "nei", "nen", "neng", "ni", "nian", "niang", | ||
| 78 | + "niao", "nie", "nin", "ning", "niu", "nong", "nu", "nv", "nuan", | ||
| 79 | + "nue", "nuo", "o", "ou", "pa", "pai", "pan", "pang", "pao", "pei", | ||
| 80 | + "pen", "peng", "pi", "pian", "piao", "pie", "pin", "ping", "po", | ||
| 81 | + "pu", "qi", "qia", "qian", "qiang", "qiao", "qie", "qin", "qing", | ||
| 82 | + "qiong", "qiu", "qu", "quan", "que", "qun", "ran", "rang", "rao", | ||
| 83 | + "re", "ren", "reng", "ri", "rong", "rou", "ru", "ruan", "rui", | ||
| 84 | + "run", "ruo", "sa", "sai", "san", "sang", "sao", "se", "sen", | ||
| 85 | + "seng", "sha", "shai", "shan", "shang", "shao", "she", "shen", | ||
| 86 | + "sheng", "shi", "shou", "shu", "shua", "shuai", "shuan", "shuang", | ||
| 87 | + "shui", "shun", "shuo", "si", "song", "sou", "su", "suan", "sui", | ||
| 88 | + "sun", "suo", "ta", "tai", "tan", "tang", "tao", "te", "teng", | ||
| 89 | + "ti", "tian", "tiao", "tie", "ting", "tong", "tou", "tu", "tuan", | ||
| 90 | + "tui", "tun", "tuo", "wa", "wai", "wan", "wang", "wei", "wen", | ||
| 91 | + "weng", "wo", "wu", "xi", "xia", "xian", "xiang", "xiao", "xie", | ||
| 92 | + "xin", "xing", "xiong", "xiu", "xu", "xuan", "xue", "xun", "ya", | ||
| 93 | + "yan", "yang", "yao", "ye", "yi", "yin", "ying", "yo", "yong", | ||
| 94 | + "you", "yu", "yuan", "yue", "yun", "za", "zai", "zan", "zang", | ||
| 95 | + "zao", "ze", "zei", "zen", "zeng", "zha", "zhai", "zhan", "zhang", | ||
| 96 | + "zhao", "zhe", "zhen", "zheng", "zhi", "zhong", "zhou", "zhu", | ||
| 97 | + "zhua", "zhuai", "zhuan", "zhuang", "zhui", "zhun", "zhuo", "zi", | ||
| 98 | + "zong", "zou", "zu", "zuan", "zui", "zun", "zuo"}; | ||
| 99 | + private StringBuilder buffer; | ||
| 100 | + private String resource; | ||
| 101 | + private static CharacterParser characterParser = new CharacterParser(); | ||
| 102 | + | ||
| 103 | + public static CharacterParser getInstance() { | ||
| 104 | + return characterParser; | ||
| 105 | + } | ||
| 106 | + | ||
| 107 | + public String getResource() { | ||
| 108 | + return resource; | ||
| 109 | + } | ||
| 110 | + | ||
| 111 | + public void setResource(String resource) { | ||
| 112 | + this.resource = resource; | ||
| 113 | + } | ||
| 114 | + | ||
| 115 | + /** | ||
| 116 | + * 汉字转成ASCII码 | ||
| 117 | + * | ||
| 118 | + * @param chs | ||
| 119 | + * @return | ||
| 120 | + */ | ||
| 121 | + private int getChsAscii(String chs) { | ||
| 122 | + int asc = 0; | ||
| 123 | + try { | ||
| 124 | + byte[] bytes = chs.getBytes("gb2312"); | ||
| 125 | + if (bytes == null || bytes.length > 2 || bytes.length <= 0) { | ||
| 126 | + throw new RuntimeException("illegal resource string"); | ||
| 127 | + } | ||
| 128 | + if (bytes.length == 1) { | ||
| 129 | + asc = bytes[0]; | ||
| 130 | + } | ||
| 131 | + if (bytes.length == 2) { | ||
| 132 | + int hightByte = 256 + bytes[0]; | ||
| 133 | + int lowByte = 256 + bytes[1]; | ||
| 134 | + asc = (256 * hightByte + lowByte) - 256 * 256; | ||
| 135 | + } | ||
| 136 | + } catch (Exception e) { | ||
| 137 | + System.out | ||
| 138 | + .println("ERROR:ChineseSpelling.class-getChsAscii(String chs)" | ||
| 139 | + + e); | ||
| 140 | + } | ||
| 141 | + return asc; | ||
| 142 | + } | ||
| 143 | + | ||
| 144 | + /** | ||
| 145 | + * 单字解析 | ||
| 146 | + **/ | ||
| 147 | + public String convert(String str) { | ||
| 148 | + String result = null; | ||
| 149 | + int ascii = getChsAscii(str); | ||
| 150 | + if (ascii > 0 && ascii < 160) { | ||
| 151 | + result = String.valueOf((char) ascii); | ||
| 152 | + } else { | ||
| 153 | + for (int i = (pyvalue.length - 1); i >= 0; i--) { | ||
| 154 | + if (pyvalue[i] <= ascii) { | ||
| 155 | + result = pystr[i]; | ||
| 156 | + break; | ||
| 157 | + } | ||
| 158 | + } | ||
| 159 | + } | ||
| 160 | + return result; | ||
| 161 | + } | ||
| 162 | + | ||
| 163 | + /** | ||
| 164 | + * 词组解析 | ||
| 165 | + * | ||
| 166 | + * @param chs | ||
| 167 | + * @return | ||
| 168 | + */ | ||
| 169 | + public String getSelling(String chs) { | ||
| 170 | + String key, value; | ||
| 171 | + buffer = new StringBuilder(); | ||
| 172 | + for (int i = 0; i < chs.length(); i++) { | ||
| 173 | + key = chs.substring(i, i + 1); | ||
| 174 | + if (key.getBytes().length >= 2) { | ||
| 175 | + value = (String) convert(key); | ||
| 176 | + if (value == null) { | ||
| 177 | + value = "unknown"; | ||
| 178 | + } | ||
| 179 | + } else { | ||
| 180 | + value = key; | ||
| 181 | + } | ||
| 182 | + buffer.append(value); | ||
| 183 | + } | ||
| 184 | + return buffer.toString(); | ||
| 185 | + } | ||
| 186 | + | ||
| 187 | + public String getSpelling() { | ||
| 188 | + return this.getSelling(this.getResource()); | ||
| 189 | + } | ||
| 190 | + | ||
| 191 | +} | ||
| 0 | \ No newline at end of file | 192 | \ No newline at end of file |
cloud/wjj_lib/src/main/java/com/cnlive/libs/base/util/search/FirstLetterUtil.java
0 → 100644
| 1 | +package com.cnlive.libs.base.util.search; | ||
| 2 | + | ||
| 3 | +public class FirstLetterUtil { | ||
| 4 | + private static int BEGIN = 45217; | ||
| 5 | + private static int END = 63486; | ||
| 6 | + // 按照声母表示,这个表是在GB2312中的出现的第一个汉字,也就是说“啊”是代表首字母a的第一个汉字。 | ||
| 7 | + // i, u, v都不做声母, 自定规则跟随前面的字母 | ||
| 8 | + private static char[] chartable = {'啊', '芭', '擦', '搭', '蛾', '发', '噶', '哈', | ||
| 9 | + '哈', '击', '喀', '垃', '妈', '拿', '哦', '啪', '期', '然', '撒', '塌', '塌', | ||
| 10 | + '塌', '挖', '昔', '压', '匝',}; | ||
| 11 | + // 二十六个字母区间对应二十七个端点 | ||
| 12 | + // GB2312码汉字区间十进制表示 | ||
| 13 | + private static int[] table = new int[27]; | ||
| 14 | + // 对应首字母区间表 | ||
| 15 | + private static char[] initialtable = {'a', 'b', 'c', 'd', 'e', 'f', 'g', | ||
| 16 | + 'h', 'h', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', | ||
| 17 | + 't', 't', 'w', 'x', 'y', 'z',}; | ||
| 18 | + | ||
| 19 | + // 初始化 | ||
| 20 | + static { | ||
| 21 | + for (int i = 0; i < 26; i++) { | ||
| 22 | + table[i] = gbValue(chartable[i]);// 得到GB2312码的首字母区间端点表,十进制。 | ||
| 23 | + } | ||
| 24 | + table[26] = END;// 区间表结尾 | ||
| 25 | + } | ||
| 26 | + | ||
| 27 | + /** | ||
| 28 | + * 根据一个包含汉字的字符串返回一个汉字拼音首字母的字符串 最重要的一个方法,思路如下:一个个字符读入、判断、输出 | ||
| 29 | + */ | ||
| 30 | + public static String getFirstLetter(String sourceStr) { | ||
| 31 | + String result = ""; | ||
| 32 | + String str = sourceStr.toLowerCase(); | ||
| 33 | + int StrLength = str.length(); | ||
| 34 | + int i; | ||
| 35 | + try { | ||
| 36 | + for (i = 0; i < StrLength; i++) { | ||
| 37 | + result += Char2Initial(str.charAt(i)); | ||
| 38 | + } | ||
| 39 | + } catch (Exception e) { | ||
| 40 | + result = ""; | ||
| 41 | + } | ||
| 42 | + return result; | ||
| 43 | + } | ||
| 44 | + | ||
| 45 | + /** | ||
| 46 | + * 输入字符,得到他的声母,英文字母返回对应的大写字母,其他非简体汉字返回 '0' | ||
| 47 | + */ | ||
| 48 | + private static char Char2Initial(char ch) { | ||
| 49 | + // 对英文字母的处理:小写字母转换为大写,大写的直接返回 | ||
| 50 | + if (ch >= 'a' && ch <= 'z') { | ||
| 51 | + return ch; | ||
| 52 | + } | ||
| 53 | + if (ch >= 'A' && ch <= 'Z') { | ||
| 54 | + | ||
| 55 | + return ch; | ||
| 56 | + } | ||
| 57 | + // 对非英文字母的处理:转化为首字母,然后判断是否在码表范围内, | ||
| 58 | + // 若不是,则直接返回。 | ||
| 59 | + // 若是,则在码表内的进行判断。 | ||
| 60 | + int gb = gbValue(ch);// 汉字转换首字母 | ||
| 61 | + | ||
| 62 | + if ((gb < BEGIN) || (gb > END))// 在码表区间之前,直接返回 | ||
| 63 | + { | ||
| 64 | + return ch; | ||
| 65 | + } | ||
| 66 | + | ||
| 67 | + int i; | ||
| 68 | + for (i = 0; i < 26; i++) {// 判断匹配码表区间,匹配到就break,判断区间形如“[,)” | ||
| 69 | + if ((gb >= table[i]) && (gb < table[i + 1])) { | ||
| 70 | + break; | ||
| 71 | + } | ||
| 72 | + } | ||
| 73 | + | ||
| 74 | + if (gb == END) {// 补上GB2312区间最右端 | ||
| 75 | + i = 25; | ||
| 76 | + } | ||
| 77 | + return initialtable[i]; // 在码表区间中,返回首字母 | ||
| 78 | + } | ||
| 79 | + | ||
| 80 | + /** | ||
| 81 | + * 取出汉字的编码 cn 汉字 | ||
| 82 | + */ | ||
| 83 | + private static int gbValue(char ch) {// 将一个汉字(GB2312)转换为十进制表示。 | ||
| 84 | + String str = new String(); | ||
| 85 | + str += ch; | ||
| 86 | + try { | ||
| 87 | + byte[] bytes = str.getBytes("GB2312"); | ||
| 88 | + if (bytes.length < 2) { | ||
| 89 | + return 0; | ||
| 90 | + } | ||
| 91 | + return (bytes[0] << 8 & 0xff00) + (bytes[1] & 0xff); | ||
| 92 | + } catch (Exception e) { | ||
| 93 | + return 0; | ||
| 94 | + } | ||
| 95 | + } | ||
| 96 | + | ||
| 97 | + | ||
| 98 | +} | ||
| 0 | \ No newline at end of file | 99 | \ No newline at end of file |
cloud/wjj_lib/src/main/java/com/cnlive/libs/base/util/search/SearchData.java
0 → 100644
| 1 | +package com.cnlive.libs.base.util.search; | ||
| 2 | + | ||
| 3 | +import java.io.Serializable; | ||
| 4 | + | ||
| 5 | +/** | ||
| 6 | + * author gujun | ||
| 7 | + * date: 2019/4/2 | ||
| 8 | + * desc: | ||
| 9 | + */ | ||
| 10 | +public class SearchData implements Serializable { | ||
| 11 | + | ||
| 12 | + private String searchContent; | ||
| 13 | + private int spannableNickStartIndex; | ||
| 14 | + private int spannableNickEndIndex; | ||
| 15 | + | ||
| 16 | + public String getSearchContent() { | ||
| 17 | + return searchContent; | ||
| 18 | + } | ||
| 19 | + | ||
| 20 | + public void setSearchContent(String searchContent) { | ||
| 21 | + this.searchContent = searchContent; | ||
| 22 | + } | ||
| 23 | + | ||
| 24 | + public int getSpannableNickStartIndex() { | ||
| 25 | + return spannableNickStartIndex; | ||
| 26 | + } | ||
| 27 | + | ||
| 28 | + public void setSpannableNickStartIndex(int spannableNickStartIndex) { | ||
| 29 | + this.spannableNickStartIndex = spannableNickStartIndex; | ||
| 30 | + } | ||
| 31 | + | ||
| 32 | + public int getSpannableNickEndIndex() { | ||
| 33 | + return spannableNickEndIndex; | ||
| 34 | + } | ||
| 35 | + | ||
| 36 | + public void setSpannableNickEndIndex(int spannableNickEndIndex) { | ||
| 37 | + this.spannableNickEndIndex = spannableNickEndIndex; | ||
| 38 | + } | ||
| 39 | +} |
cloud/wjj_lib/src/main/java/com/cnlive/libs/base/util/search/SearchUtil.java
0 → 100644
| 1 | +package com.cnlive.libs.base.util.search; | ||
| 2 | + | ||
| 3 | +import android.text.TextUtils; | ||
| 4 | + | ||
| 5 | +import java.util.ArrayList; | ||
| 6 | +import java.util.List; | ||
| 7 | +import java.util.regex.Matcher; | ||
| 8 | +import java.util.regex.Pattern; | ||
| 9 | + | ||
| 10 | +/** | ||
| 11 | + * Created by gujun on 2018/1/9. | ||
| 12 | + */ | ||
| 13 | + | ||
| 14 | +public class SearchUtil { | ||
| 15 | + | ||
| 16 | + /** | ||
| 17 | + * 获取联系人模糊查询列表 | ||
| 18 | + * | ||
| 19 | + * @param filter 过滤条件 | ||
| 20 | + * @param list 原始列表 | ||
| 21 | + * @return | ||
| 22 | + */ | ||
| 23 | + public static <T extends SearchData> List<T> getFilterContactList(CharSequence filter, List<T> list) { | ||
| 24 | + if (list == null || list.size() <= 0) return null; | ||
| 25 | + List<T> filterList = new ArrayList<>(); | ||
| 26 | + | ||
| 27 | + for (T contactInfo : list) { | ||
| 28 | + if (!TextUtils.isEmpty(filter)) { | ||
| 29 | + if (contains(contactInfo, filter.toString())) { | ||
| 30 | + filterList.add(contactInfo); | ||
| 31 | + } | ||
| 32 | + } else { | ||
| 33 | + contactInfo.setSpannableNickEndIndex(0); | ||
| 34 | + contactInfo.setSpannableNickStartIndex(0); | ||
| 35 | + filterList.add(contactInfo); | ||
| 36 | + } | ||
| 37 | + } | ||
| 38 | + return filterList; | ||
| 39 | + } | ||
| 40 | + | ||
| 41 | + /** | ||
| 42 | + * 判断某个联系人昵称是否包含查询字段 | ||
| 43 | + * | ||
| 44 | + * @param searchData | ||
| 45 | + * @param filter | ||
| 46 | + * @return | ||
| 47 | + */ | ||
| 48 | + private static boolean contains(SearchData searchData, String filter) { | ||
| 49 | + String name = searchData.getSearchContent(); | ||
| 50 | + if (TextUtils.isEmpty(name) | ||
| 51 | + && TextUtils.isEmpty(name)) { | ||
| 52 | + return false; | ||
| 53 | + } | ||
| 54 | + | ||
| 55 | + int startIndex = 0; | ||
| 56 | + int endIndex = 0; | ||
| 57 | + boolean flag = false; | ||
| 58 | + | ||
| 59 | + if (!isAllEnglish(filter)) { | ||
| 60 | + // 只要不全是英文就字符串对比 | ||
| 61 | + if (name.contains(filter)) { | ||
| 62 | + flag = true; | ||
| 63 | + startIndex = name.indexOf(filter); | ||
| 64 | + endIndex = startIndex + filter.length(); | ||
| 65 | + } | ||
| 66 | + } else { | ||
| 67 | + String key = ""; | ||
| 68 | + String searchPinYin = ""; | ||
| 69 | + if (!flag) { | ||
| 70 | + CharacterParser finder = CharacterParser.getInstance(); | ||
| 71 | + // 先将输入的字符串转换为拼音 | ||
| 72 | + finder.setResource(filter); | ||
| 73 | + searchPinYin = finder.getSpelling(); | ||
| 74 | + //处理通配符 | ||
| 75 | + key = processingWildcards(searchPinYin); | ||
| 76 | + | ||
| 77 | + // 简拼匹配,如果输入在字符串长度大于6就不按首字母匹配了 | ||
| 78 | + if (key.length() < 6) { | ||
| 79 | + String firstLetters = FirstLetterUtil | ||
| 80 | + .getFirstLetter(name); | ||
| 81 | + // 不区分大小写 | ||
| 82 | + Pattern firstLetterPattern = Pattern.compile(key, | ||
| 83 | + Pattern.CASE_INSENSITIVE); | ||
| 84 | + Matcher firstLetterMatcher = firstLetterPattern.matcher(firstLetters); | ||
| 85 | + flag = firstLetterMatcher.find(); | ||
| 86 | + if (flag) { | ||
| 87 | + startIndex = firstLetterMatcher.start(); | ||
| 88 | + endIndex = firstLetterMatcher.end(); | ||
| 89 | + } | ||
| 90 | + } | ||
| 91 | + } | ||
| 92 | + | ||
| 93 | + if (!flag && key.length() > 1) { | ||
| 94 | + //key.length() > 1代表:仅有一个字母时必须匹配首字母,不能使用全拼 | ||
| 95 | + // 全拼匹配 | ||
| 96 | + CharacterParser finder = CharacterParser.getInstance(); | ||
| 97 | + finder.setResource(name); | ||
| 98 | + // 不区分大小写 | ||
| 99 | + Pattern pattern = Pattern | ||
| 100 | + .compile(key, Pattern.CASE_INSENSITIVE); | ||
| 101 | + Matcher matcher = pattern.matcher(finder.getSpelling()); | ||
| 102 | + flag = matcher.find(); | ||
| 103 | + if (flag) { | ||
| 104 | + int matcherStart = matcher.start(); | ||
| 105 | + int matcherEnd = matcher.end(); | ||
| 106 | + if (matcherStart < matcherEnd) { | ||
| 107 | + int scanPinYinCount = 0; | ||
| 108 | + char nickNameChar[] = name.toCharArray(); | ||
| 109 | + for (int i = 0; i < nickNameChar.length; i++) { | ||
| 110 | + CharacterParser finderNick = CharacterParser.getInstance(); | ||
| 111 | + finderNick.setResource(String.valueOf(nickNameChar[i])); | ||
| 112 | + String nickNamePinYin = finderNick.getSpelling(); | ||
| 113 | + if (matcherStart >= scanPinYinCount && matcherStart < scanPinYinCount + nickNamePinYin.length()) { | ||
| 114 | + startIndex = i; | ||
| 115 | + } | ||
| 116 | + if (matcherEnd > scanPinYinCount && matcherEnd <= scanPinYinCount + nickNamePinYin.length()) { | ||
| 117 | + endIndex = i + 1; | ||
| 118 | + } | ||
| 119 | + scanPinYinCount += nickNamePinYin.length(); | ||
| 120 | + } | ||
| 121 | + } | ||
| 122 | + } | ||
| 123 | + } | ||
| 124 | + } | ||
| 125 | + | ||
| 126 | + if (flag) { | ||
| 127 | + searchData.setSpannableNickStartIndex(startIndex); | ||
| 128 | + searchData.setSpannableNickEndIndex(endIndex); | ||
| 129 | + } | ||
| 130 | + | ||
| 131 | + return flag; | ||
| 132 | + } | ||
| 133 | + | ||
| 134 | + /** | ||
| 135 | + * 处理转义字符包括 * . ? + $ ^ [ ] ( ) { } | \ | ||
| 136 | + * | ||
| 137 | + * @param searchPinYin | ||
| 138 | + * @return | ||
| 139 | + */ | ||
| 140 | + private static String processingWildcards(String searchPinYin) { | ||
| 141 | + String key = ""; | ||
| 142 | + // 处理通配符问题 | ||
| 143 | + if (searchPinYin.contains("*") || | ||
| 144 | + searchPinYin.contains(".") || | ||
| 145 | + searchPinYin.contains("?") || | ||
| 146 | + searchPinYin.contains("+") || | ||
| 147 | + searchPinYin.contains("$") || | ||
| 148 | + searchPinYin.contains("^") || | ||
| 149 | + searchPinYin.contains("[") || | ||
| 150 | + searchPinYin.contains("]") || | ||
| 151 | + searchPinYin.contains("(") || | ||
| 152 | + searchPinYin.contains(")") || | ||
| 153 | + searchPinYin.contains("{") || | ||
| 154 | + searchPinYin.contains("}") || | ||
| 155 | + searchPinYin.contains("|") || | ||
| 156 | + searchPinYin.contains("\\")) { | ||
| 157 | + char[] chars = searchPinYin.toCharArray(); | ||
| 158 | + for (int k = 0; k < chars.length; k++) { | ||
| 159 | + if (chars[k] == '*') { | ||
| 160 | + key = key + "\\*"; | ||
| 161 | + } else if (chars[k] == '(') { | ||
| 162 | + key = key + "\\("; | ||
| 163 | + } else if (chars[k] == ')') { | ||
| 164 | + key = key + "\\)"; | ||
| 165 | + } else if (chars[k] == '?') { | ||
| 166 | + key = key + "\\?"; | ||
| 167 | + } else if (chars[k] == '.') { | ||
| 168 | + key = key + "\\."; | ||
| 169 | + } else if (chars[k] == '+') { | ||
| 170 | + key = key + "\\+"; | ||
| 171 | + } else if (chars[k] == '$') { | ||
| 172 | + key = key + "\\$"; | ||
| 173 | + } else if (chars[k] == '^') { | ||
| 174 | + key = key + "\\^"; | ||
| 175 | + } else if (chars[k] == '[') { | ||
| 176 | + key = key + "\\["; | ||
| 177 | + } else if (chars[k] == ']') { | ||
| 178 | + key = key + "\\]"; | ||
| 179 | + } else if (chars[k] == '{') { | ||
| 180 | + key = key + "\\{"; | ||
| 181 | + } else if (chars[k] == '}') { | ||
| 182 | + key = key + "\\}"; | ||
| 183 | + } else if (chars[k] == '|') { | ||
| 184 | + key = key + "\\|"; | ||
| 185 | + } else if (chars[k] == '\\') { | ||
| 186 | + key = key + "\\\\"; | ||
| 187 | + } else { | ||
| 188 | + key = key + String.valueOf(chars[k]); | ||
| 189 | + } | ||
| 190 | + } | ||
| 191 | + } else { | ||
| 192 | + key = searchPinYin; | ||
| 193 | + } | ||
| 194 | + return key; | ||
| 195 | + } | ||
| 196 | + | ||
| 197 | + /** | ||
| 198 | + * 是否全是英文 | ||
| 199 | + * | ||
| 200 | + * @param str | ||
| 201 | + * @return | ||
| 202 | + */ | ||
| 203 | + public static boolean isAllEnglish(String str) { | ||
| 204 | + Pattern p = Pattern.compile("[a-zA-Z]"); | ||
| 205 | + Matcher m = p.matcher(str); | ||
| 206 | + if (m.find()) { | ||
| 207 | + return true; | ||
| 208 | + } | ||
| 209 | + return false; | ||
| 210 | + } | ||
| 211 | +} |
cloud/wjj_lib/src/main/java/com/cnlive/libs/base/util/toast/SafeToastContext.java
0 → 100644
| 1 | +package com.cnlive.libs.base.util.toast; | ||
| 2 | + | ||
| 3 | +import android.content.Context; | ||
| 4 | +import android.content.ContextWrapper; | ||
| 5 | +import android.util.Log; | ||
| 6 | +import android.view.Display; | ||
| 7 | +import android.view.View; | ||
| 8 | +import android.view.ViewGroup; | ||
| 9 | +import android.view.WindowManager; | ||
| 10 | +import android.widget.Toast; | ||
| 11 | + | ||
| 12 | +import androidx.annotation.NonNull; | ||
| 13 | + | ||
| 14 | +/** | ||
| 15 | + * @author drakeet | ||
| 16 | + */ | ||
| 17 | +final class SafeToastContext extends ContextWrapper { | ||
| 18 | + | ||
| 19 | + private @NonNull | ||
| 20 | + Toast toast; | ||
| 21 | + | ||
| 22 | + | ||
| 23 | + SafeToastContext(@NonNull Context base, @NonNull Toast toast) { | ||
| 24 | + super(base); | ||
| 25 | + this.toast = toast; | ||
| 26 | + } | ||
| 27 | + | ||
| 28 | + | ||
| 29 | + @Override | ||
| 30 | + public Context getApplicationContext() { | ||
| 31 | + return new ApplicationContextWrapper(getBaseContext().getApplicationContext()); | ||
| 32 | + } | ||
| 33 | + | ||
| 34 | + | ||
| 35 | + private final class ApplicationContextWrapper extends ContextWrapper { | ||
| 36 | + | ||
| 37 | + private ApplicationContextWrapper(@NonNull Context base) { | ||
| 38 | + super(base); | ||
| 39 | + } | ||
| 40 | + | ||
| 41 | + | ||
| 42 | + @Override | ||
| 43 | + public Object getSystemService(@NonNull String name) { | ||
| 44 | + if (Context.WINDOW_SERVICE.equals(name)) { | ||
| 45 | + // noinspection ConstantConditions | ||
| 46 | + return new WindowManagerWrapper((WindowManager) getBaseContext().getSystemService(name)); | ||
| 47 | + } | ||
| 48 | + return super.getSystemService(name); | ||
| 49 | + } | ||
| 50 | + } | ||
| 51 | + | ||
| 52 | + | ||
| 53 | + private final class WindowManagerWrapper implements WindowManager { | ||
| 54 | + | ||
| 55 | + private static final String TAG = "WindowManagerWrapper"; | ||
| 56 | + private final @NonNull WindowManager base; | ||
| 57 | + | ||
| 58 | + | ||
| 59 | + private WindowManagerWrapper(@NonNull WindowManager base) { | ||
| 60 | + this.base = base; | ||
| 61 | + } | ||
| 62 | + | ||
| 63 | + | ||
| 64 | + @Override | ||
| 65 | + public Display getDefaultDisplay() { | ||
| 66 | + return base.getDefaultDisplay(); | ||
| 67 | + } | ||
| 68 | + | ||
| 69 | + | ||
| 70 | + @Override | ||
| 71 | + public void removeViewImmediate(View view) { | ||
| 72 | + base.removeViewImmediate(view); | ||
| 73 | + } | ||
| 74 | + | ||
| 75 | + | ||
| 76 | + @Override | ||
| 77 | + public void addView(View view, ViewGroup.LayoutParams params) { | ||
| 78 | + try { | ||
| 79 | + Log.d(TAG, "WindowManager's addView(view, params) has been hooked."); | ||
| 80 | + base.addView(view, params); | ||
| 81 | + } catch (BadTokenException e) { | ||
| 82 | + Log.i(TAG, e.getMessage()); | ||
| 83 | + } catch (Throwable throwable) { | ||
| 84 | + Log.e(TAG, "[addView]", throwable); | ||
| 85 | + } | ||
| 86 | + } | ||
| 87 | + | ||
| 88 | + | ||
| 89 | + @Override | ||
| 90 | + public void updateViewLayout(View view, ViewGroup.LayoutParams params) { | ||
| 91 | + base.updateViewLayout(view, params); | ||
| 92 | + } | ||
| 93 | + | ||
| 94 | + | ||
| 95 | + @Override | ||
| 96 | + public void removeView(View view) { | ||
| 97 | + base.removeView(view); | ||
| 98 | + } | ||
| 99 | + } | ||
| 100 | +} | ||
| 0 | \ No newline at end of file | 101 | \ No newline at end of file |
cloud/wjj_lib/src/main/java/com/cnlive/libs/base/util/toast/ToastCompat.java
0 → 100644
| 1 | +package com.cnlive.libs.base.util.toast; | ||
| 2 | + | ||
| 3 | +import android.annotation.SuppressLint; | ||
| 4 | +import android.app.Activity; | ||
| 5 | +import android.app.Application; | ||
| 6 | +import android.content.Context; | ||
| 7 | +import android.content.res.Resources; | ||
| 8 | +import android.os.Build; | ||
| 9 | +import android.view.View; | ||
| 10 | +import android.widget.Toast; | ||
| 11 | + | ||
| 12 | +import androidx.annotation.NonNull; | ||
| 13 | +import androidx.annotation.StringRes; | ||
| 14 | + | ||
| 15 | +import java.lang.reflect.Field; | ||
| 16 | + | ||
| 17 | +/** | ||
| 18 | + * @author drakeet | ||
| 19 | + */ | ||
| 20 | +public final class ToastCompat extends Toast { | ||
| 21 | + | ||
| 22 | + private final @NonNull | ||
| 23 | + Toast toast; | ||
| 24 | + | ||
| 25 | + | ||
| 26 | + /** | ||
| 27 | + * Construct an empty Toast object. You must call {@link #setView} before you | ||
| 28 | + * can call {@link #show}. | ||
| 29 | + * | ||
| 30 | + * @param context The context to use. Usually your {@link Application} | ||
| 31 | + * or {@link Activity} object. | ||
| 32 | + * @param base The base toast | ||
| 33 | + */ | ||
| 34 | + private ToastCompat(Context context, @NonNull Toast base) { | ||
| 35 | + super(context); | ||
| 36 | + this.toast = base; | ||
| 37 | + } | ||
| 38 | + | ||
| 39 | + | ||
| 40 | + /** | ||
| 41 | + * Make a standard toast that just contains a text view. | ||
| 42 | + * | ||
| 43 | + * @param context The context to use. Usually your {@link android.app.Application} | ||
| 44 | + * or {@link android.app.Activity} object. | ||
| 45 | + * @param text The text to show. Can be formatted text. | ||
| 46 | + * @param duration How long to display the message. Either {@link #LENGTH_SHORT} or | ||
| 47 | + * {@link #LENGTH_LONG} | ||
| 48 | + */ | ||
| 49 | + public static ToastCompat makeText(Context context, CharSequence text, int duration) { | ||
| 50 | + // We cannot pass the SafeToastContext to Toast.makeText() because | ||
| 51 | + // the View will unwrap the base context and we are in vain. | ||
| 52 | + @SuppressLint("ShowToast") | ||
| 53 | + Toast toast = Toast.makeText(context, text, duration); | ||
| 54 | + setContextCompat(toast.getView(), new SafeToastContext(context, toast)); | ||
| 55 | + return new ToastCompat(context, toast); | ||
| 56 | + } | ||
| 57 | + | ||
| 58 | + | ||
| 59 | + /** | ||
| 60 | + * Make a standard toast that just contains a text view with the text from a resource. | ||
| 61 | + * | ||
| 62 | + * @param context The context to use. Usually your {@link android.app.Application} | ||
| 63 | + * or {@link android.app.Activity} object. | ||
| 64 | + * @param resId The resource id of the string resource to use. Can be formatted text. | ||
| 65 | + * @param duration How long to display the message. Either {@link #LENGTH_SHORT} or | ||
| 66 | + * {@link #LENGTH_LONG} | ||
| 67 | + * @throws Resources.NotFoundException if the resource can't be found. | ||
| 68 | + */ | ||
| 69 | + public static Toast makeText(Context context, @StringRes int resId, int duration) | ||
| 70 | + throws Resources.NotFoundException { | ||
| 71 | + return makeText(context, context.getResources().getText(resId), duration); | ||
| 72 | + } | ||
| 73 | + | ||
| 74 | + @Override | ||
| 75 | + public void show() { | ||
| 76 | + toast.show(); | ||
| 77 | + } | ||
| 78 | + | ||
| 79 | + | ||
| 80 | + @Override | ||
| 81 | + public void setDuration(int duration) { | ||
| 82 | + toast.setDuration(duration); | ||
| 83 | + } | ||
| 84 | + | ||
| 85 | + | ||
| 86 | + @Override | ||
| 87 | + public void setGravity(int gravity, int xOffset, int yOffset) { | ||
| 88 | + toast.setGravity(gravity, xOffset, yOffset); | ||
| 89 | + } | ||
| 90 | + | ||
| 91 | + | ||
| 92 | + @Override | ||
| 93 | + public void setMargin(float horizontalMargin, float verticalMargin) { | ||
| 94 | + toast.setMargin(horizontalMargin, verticalMargin); | ||
| 95 | + } | ||
| 96 | + | ||
| 97 | + | ||
| 98 | + @Override | ||
| 99 | + public void setText(int resId) { | ||
| 100 | + toast.setText(resId); | ||
| 101 | + } | ||
| 102 | + | ||
| 103 | + | ||
| 104 | + @Override | ||
| 105 | + public void setText(CharSequence s) { | ||
| 106 | + toast.setText(s); | ||
| 107 | + } | ||
| 108 | + | ||
| 109 | + | ||
| 110 | + @Override | ||
| 111 | + public void setView(View view) { | ||
| 112 | + toast.setView(view); | ||
| 113 | + setContextCompat(view, new SafeToastContext(view.getContext(), this)); | ||
| 114 | + } | ||
| 115 | + | ||
| 116 | + | ||
| 117 | + @Override | ||
| 118 | + public float getHorizontalMargin() { | ||
| 119 | + return toast.getHorizontalMargin(); | ||
| 120 | + } | ||
| 121 | + | ||
| 122 | + | ||
| 123 | + @Override | ||
| 124 | + public float getVerticalMargin() { | ||
| 125 | + return toast.getVerticalMargin(); | ||
| 126 | + } | ||
| 127 | + | ||
| 128 | + | ||
| 129 | + @Override | ||
| 130 | + public int getDuration() { | ||
| 131 | + return toast.getDuration(); | ||
| 132 | + } | ||
| 133 | + | ||
| 134 | + | ||
| 135 | + @Override | ||
| 136 | + public int getGravity() { | ||
| 137 | + return toast.getGravity(); | ||
| 138 | + } | ||
| 139 | + | ||
| 140 | + | ||
| 141 | + @Override | ||
| 142 | + public int getXOffset() { | ||
| 143 | + return toast.getXOffset(); | ||
| 144 | + } | ||
| 145 | + | ||
| 146 | + | ||
| 147 | + @Override | ||
| 148 | + public int getYOffset() { | ||
| 149 | + return toast.getYOffset(); | ||
| 150 | + } | ||
| 151 | + | ||
| 152 | + | ||
| 153 | + @Override | ||
| 154 | + public View getView() { | ||
| 155 | + return toast.getView(); | ||
| 156 | + } | ||
| 157 | + | ||
| 158 | + | ||
| 159 | + public @NonNull | ||
| 160 | + Toast getBaseToast() { | ||
| 161 | + return toast; | ||
| 162 | + } | ||
| 163 | + | ||
| 164 | + | ||
| 165 | + private static void setContextCompat(@NonNull View view, @NonNull Context context) { | ||
| 166 | + if (Build.VERSION.SDK_INT == 25 || Build.VERSION.SDK_INT == 24) { | ||
| 167 | + try { | ||
| 168 | + Field field = View.class.getDeclaredField("mContext"); | ||
| 169 | + field.setAccessible(true); | ||
| 170 | + field.set(view, context); | ||
| 171 | + } catch (Throwable throwable) { | ||
| 172 | + throwable.printStackTrace(); | ||
| 173 | + } | ||
| 174 | + } | ||
| 175 | + } | ||
| 176 | +} | ||
| 0 | \ No newline at end of file | 177 | \ No newline at end of file |
cloud/wjj_lib/src/main/res/drawable-hdpi/ic_notifi.png
0 → 100644
2.17 KB
cloud/wjj_lib/src/main/res/drawable-hdpi/tanchuang_cuowu.png
0 → 100644
2.03 KB
cloud/wjj_lib/src/main/res/drawable-hdpi/xx_chenggong.png
0 → 100644
2.02 KB
cloud/wjj_lib/src/main/res/drawable-xhdpi/ic_notifi.png
0 → 100644
3.05 KB
cloud/wjj_lib/src/main/res/drawable-xhdpi/tanchuang_cuowu.png
0 → 100644
2.54 KB
cloud/wjj_lib/src/main/res/drawable-xhdpi/xx_chenggong.png
0 → 100644
2.29 KB
cloud/wjj_lib/src/main/res/drawable-xxhdpi/ic_notifi.png
0 → 100644
4.5 KB
cloud/wjj_lib/src/main/res/drawable-xxhdpi/tanchuang_cuowu.png
0 → 100644
3.55 KB
cloud/wjj_lib/src/main/res/drawable-xxhdpi/xx_chenggong.png
0 → 100644
4.27 KB
cloud/wjj_lib/src/main/res/drawable/bg_toast_1_background.xml
0 → 100644
| 1 | +<?xml version="1.0" encoding="utf-8"?> | ||
| 2 | +<shape xmlns:android="http://schemas.android.com/apk/res/android" | ||
| 3 | + android:shape="rectangle" | ||
| 4 | + android:useLevel="false"> | ||
| 5 | + <solid android:color="#b2000000" /> | ||
| 6 | + <padding | ||
| 7 | + android:bottom="4dp" | ||
| 8 | + android:left="4dp" | ||
| 9 | + android:right="4dp" | ||
| 10 | + android:top="4dp" /> | ||
| 11 | + <size | ||
| 12 | + android:width="36dp" | ||
| 13 | + android:height="36dp" /> | ||
| 14 | + <corners android:radius="5dp" /> | ||
| 15 | +</shape> | ||
| 0 | \ No newline at end of file | 16 | \ No newline at end of file |
cloud/wjj_lib/src/main/res/drawable/bg_toast_image_background.xml
0 → 100644
| 1 | +<?xml version="1.0" encoding="utf-8"?> | ||
| 2 | +<shape xmlns:android="http://schemas.android.com/apk/res/android" | ||
| 3 | + android:shape="rectangle" | ||
| 4 | + android:useLevel="false"> | ||
| 5 | + <solid android:color="#b2000000" /> | ||
| 6 | + <corners android:radius="10dp" /> | ||
| 7 | +</shape> | ||
| 0 | \ No newline at end of file | 8 | \ No newline at end of file |
cloud/wjj_lib/src/main/res/layout/layout_toast_1.xml
0 → 100644
| 1 | +<?xml version="1.0" encoding="utf-8"?> | ||
| 2 | +<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
| 3 | + android:layout_width="wrap_content" | ||
| 4 | + android:layout_height="wrap_content" | ||
| 5 | + android:background="@drawable/bg_toast_1_background"> | ||
| 6 | + | ||
| 7 | + <TextView | ||
| 8 | + android:id="@+id/text" | ||
| 9 | + android:layout_width="wrap_content" | ||
| 10 | + android:layout_height="wrap_content" | ||
| 11 | + android:padding="4dp" | ||
| 12 | + android:text="Hello World!" | ||
| 13 | + android:textColor="@android:color/white" | ||
| 14 | + android:textSize="15sp" | ||
| 15 | + android:layout_centerInParent="true"/> | ||
| 16 | + | ||
| 17 | +</RelativeLayout> |
cloud/wjj_lib/src/main/res/layout/layout_toast_failed.xml
0 → 100644
| 1 | +<?xml version="1.0" encoding="utf-8"?> | ||
| 2 | +<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
| 3 | + android:layout_width="wrap_content" | ||
| 4 | + android:layout_height="wrap_content" | ||
| 5 | + android:background="@drawable/bg_toast_image_background"> | ||
| 6 | + | ||
| 7 | + <ImageView | ||
| 8 | + android:id="@+id/image" | ||
| 9 | + android:layout_width="31dp" | ||
| 10 | + android:layout_height="31dp" | ||
| 11 | + android:layout_centerHorizontal="true" | ||
| 12 | + android:layout_marginTop="15dp" | ||
| 13 | + android:src="@drawable/tanchuang_cuowu" /> | ||
| 14 | + | ||
| 15 | + <TextView | ||
| 16 | + android:id="@+id/text" | ||
| 17 | + android:layout_width="wrap_content" | ||
| 18 | + android:layout_height="wrap_content" | ||
| 19 | + android:layout_below="@+id/image" | ||
| 20 | + android:layout_centerHorizontal="true" | ||
| 21 | + android:layout_marginBottom="15dp" | ||
| 22 | + android:layout_marginLeft="30dp" | ||
| 23 | + android:layout_marginRight="30dp" | ||
| 24 | + android:layout_marginTop="15dp" | ||
| 25 | + android:gravity="center_horizontal" | ||
| 26 | + android:text="Hello World!" | ||
| 27 | + android:textColor="@android:color/white" | ||
| 28 | + android:textSize="15sp" /> | ||
| 29 | + | ||
| 30 | +</RelativeLayout> | ||
| 0 | \ No newline at end of file | 31 | \ No newline at end of file |
cloud/wjj_lib/src/main/res/layout/layout_toast_success.xml
0 → 100644
| 1 | +<?xml version="1.0" encoding="utf-8"?> | ||
| 2 | +<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
| 3 | + android:layout_width="125dp" | ||
| 4 | + android:layout_height="125dp" | ||
| 5 | + android:background="@drawable/bg_toast_image_background"> | ||
| 6 | + | ||
| 7 | + <ImageView | ||
| 8 | + android:id="@+id/image" | ||
| 9 | + android:layout_width="40dp" | ||
| 10 | + android:layout_height="40dp" | ||
| 11 | + android:layout_centerHorizontal="true" | ||
| 12 | + android:layout_marginTop="25dp" | ||
| 13 | + android:src="@drawable/xx_chenggong" /> | ||
| 14 | + | ||
| 15 | + <TextView | ||
| 16 | + android:id="@+id/text" | ||
| 17 | + android:layout_width="125dp" | ||
| 18 | + android:layout_height="wrap_content" | ||
| 19 | + android:layout_below="@+id/image" | ||
| 20 | + android:layout_centerHorizontal="true" | ||
| 21 | + android:layout_marginBottom="20dp" | ||
| 22 | + android:layout_marginTop="20dp" | ||
| 23 | + android:gravity="center_horizontal" | ||
| 24 | + android:text="Hello World!" | ||
| 25 | + android:textSize="15sp" | ||
| 26 | + android:textColor="@android:color/white" /> | ||
| 27 | + | ||
| 28 | +</RelativeLayout> |
cloud/wjj_lib/src/main/res/values/ids.xml
0 → 100644
cloud/wjj_lib/src/main/res/values/strings.xml
0 → 100644
| 1 | +<resources> | ||
| 2 | + <string name="app_name">lib_base</string> | ||
| 3 | + | ||
| 4 | + <string name="load_success_message">接口请求成功</string> | ||
| 5 | + <string name="load_failure_message">接口请求失败</string> | ||
| 6 | + <string name="load_error_message">接口请求错误</string> | ||
| 7 | + <string name="no_network_message">无法连接网络</string> | ||
| 8 | + <string name="unknown_error_message">未知错误</string> | ||
| 9 | +</resources> |
core/base/src/main/java/com/cnlive/core/libs/base/frame/activity/BaseActivity.java
| @@ -115,7 +115,7 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | @@ -115,7 +115,7 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | ||
| 115 | 115 | ||
| 116 | 116 | ||
| 117 | @Override | 117 | @Override |
| 118 | - public final void onCreate(@Nullable Bundle savedInstanceState) { | 118 | + public void onCreate(@Nullable Bundle savedInstanceState) { |
| 119 | super.onCreate(savedInstanceState); | 119 | super.onCreate(savedInstanceState); |
| 120 | if (0 != getBindLayoutId()) { | 120 | if (0 != getBindLayoutId()) { |
| 121 | baseBinding = DataBindingUtil.setContentView(this, getBindLayoutId()); | 121 | baseBinding = DataBindingUtil.setContentView(this, getBindLayoutId()); |
| @@ -125,8 +125,8 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | @@ -125,8 +125,8 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | ||
| 125 | context = this; | 125 | context = this; |
| 126 | me = this; | 126 | me = this; |
| 127 | this.savedInstanceState = savedInstanceState; | 127 | this.savedInstanceState = savedInstanceState; |
| 128 | - //路由参数初始化 | ||
| 129 | - ARouter.getInstance().inject(this); | 128 | +// //路由参数初始化 |
| 129 | +// ARouter.getInstance().inject(this); | ||
| 130 | //activity管理 | 130 | //activity管理 |
| 131 | AppManager.getInstance().pushActivity(me); | 131 | AppManager.getInstance().pushActivity(me); |
| 132 | //创建订阅映射 | 132 | //创建订阅映射 |
| @@ -172,7 +172,7 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | @@ -172,7 +172,7 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | ||
| 172 | /** | 172 | /** |
| 173 | * 显示白色通知栏 | 173 | * 显示白色通知栏 |
| 174 | */ | 174 | */ |
| 175 | - public final void showDefaultWhiteStatusBar() { | 175 | + public void showDefaultWhiteStatusBar() { |
| 176 | setStatusBarTextColor(StatusBarConfig.BLACK); | 176 | setStatusBarTextColor(StatusBarConfig.BLACK); |
| 177 | setStatusBarColor(R.color.white, 0); | 177 | setStatusBarColor(R.color.white, 0); |
| 178 | } | 178 | } |
| @@ -180,7 +180,7 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | @@ -180,7 +180,7 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | ||
| 180 | /** | 180 | /** |
| 181 | * 显示黑色通知栏 | 181 | * 显示黑色通知栏 |
| 182 | */ | 182 | */ |
| 183 | - public final void showDefaultBlackStatusBar() { | 183 | + public void showDefaultBlackStatusBar() { |
| 184 | setStatusBarTextColor(StatusBarConfig.WHITE); | 184 | setStatusBarTextColor(StatusBarConfig.WHITE); |
| 185 | setStatusBarColor(R.color.black, 0); | 185 | setStatusBarColor(R.color.black, 0); |
| 186 | } | 186 | } |
| @@ -190,11 +190,11 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | @@ -190,11 +190,11 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | ||
| 190 | * | 190 | * |
| 191 | * @param enable | 191 | * @param enable |
| 192 | */ | 192 | */ |
| 193 | - public final void setEnableCreateDefultEmptyView(boolean enable) { | 193 | + public void setEnableCreateDefultEmptyView(boolean enable) { |
| 194 | isCreateDefultEmptyView = enable; | 194 | isCreateDefultEmptyView = enable; |
| 195 | } | 195 | } |
| 196 | 196 | ||
| 197 | - public final Handler getMyActHandler() { | 197 | + public Handler getMyActHandler() { |
| 198 | if (null == myActHandler) { | 198 | if (null == myActHandler) { |
| 199 | myActHandler = new Handler() { | 199 | myActHandler = new Handler() { |
| 200 | @Override | 200 | @Override |
| @@ -222,7 +222,7 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | @@ -222,7 +222,7 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | ||
| 222 | } | 222 | } |
| 223 | 223 | ||
| 224 | //添加观察者 | 224 | //添加观察者 |
| 225 | - public final void addObservable(Observable... observable) { | 225 | + public void addObservable(Observable... observable) { |
| 226 | Observable[] result = observable; | 226 | Observable[] result = observable; |
| 227 | if (null != observable) { | 227 | if (null != observable) { |
| 228 | if (null != result) { | 228 | if (null != result) { |
| @@ -259,14 +259,14 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | @@ -259,14 +259,14 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | ||
| 259 | /** | 259 | /** |
| 260 | * 显示竖屏 | 260 | * 显示竖屏 |
| 261 | */ | 261 | */ |
| 262 | - public final void showPortraitScreen() { | 262 | + public void showPortraitScreen() { |
| 263 | setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); | 263 | setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); |
| 264 | } | 264 | } |
| 265 | 265 | ||
| 266 | /** | 266 | /** |
| 267 | * 显示横屏 | 267 | * 显示横屏 |
| 268 | */ | 268 | */ |
| 269 | - public final void showLandscapeScreen() { | 269 | + public void showLandscapeScreen() { |
| 270 | setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); | 270 | setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); |
| 271 | } | 271 | } |
| 272 | 272 | ||
| @@ -292,7 +292,7 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | @@ -292,7 +292,7 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | ||
| 292 | 292 | ||
| 293 | } | 293 | } |
| 294 | 294 | ||
| 295 | - public final boolean isOpenSwipBack() { | 295 | + public boolean isOpenSwipBack() { |
| 296 | return isOpenSwipBack; | 296 | return isOpenSwipBack; |
| 297 | } | 297 | } |
| 298 | 298 | ||
| @@ -301,7 +301,7 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | @@ -301,7 +301,7 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | ||
| 301 | * | 301 | * |
| 302 | * @param showTitle true or false | 302 | * @param showTitle true or false |
| 303 | */ | 303 | */ |
| 304 | - public final void setShowTitle(boolean showTitle) { | 304 | + public void setShowTitle(boolean showTitle) { |
| 305 | isShowTitle = showTitle; | 305 | isShowTitle = showTitle; |
| 306 | } | 306 | } |
| 307 | 307 | ||
| @@ -310,17 +310,16 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | @@ -310,17 +310,16 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | ||
| 310 | * | 310 | * |
| 311 | * @param showStatusBar true or false | 311 | * @param showStatusBar true or false |
| 312 | */ | 312 | */ |
| 313 | - public final void setShowStatusBar(boolean showStatusBar) { | 313 | + public void setShowStatusBar(boolean showStatusBar) { |
| 314 | isShowStatusBar = showStatusBar; | 314 | isShowStatusBar = showStatusBar; |
| 315 | } | 315 | } |
| 316 | 316 | ||
| 317 | 317 | ||
| 318 | - | ||
| 319 | /** | 318 | /** |
| 320 | * 设置屏幕为横屏 | 319 | * 设置屏幕为横屏 |
| 321 | * Set the screen to landscape. | 320 | * Set the screen to landscape. |
| 322 | */ | 321 | */ |
| 323 | - public final void setLandscape() { | 322 | + public void setLandscape() { |
| 324 | setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); | 323 | setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); |
| 325 | } | 324 | } |
| 326 | 325 | ||
| @@ -328,7 +327,7 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | @@ -328,7 +327,7 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | ||
| 328 | * 设置屏幕为竖屏 | 327 | * 设置屏幕为竖屏 |
| 329 | * Set the screen to portrait. | 328 | * Set the screen to portrait. |
| 330 | */ | 329 | */ |
| 331 | - public final void setPortrait() { | 330 | + public void setPortrait() { |
| 332 | setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); | 331 | setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); |
| 333 | } | 332 | } |
| 334 | 333 | ||
| @@ -339,7 +338,7 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | @@ -339,7 +338,7 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | ||
| 339 | * | 338 | * |
| 340 | * @return {@code true}: yes<br>{@code false}: no | 339 | * @return {@code true}: yes<br>{@code false}: no |
| 341 | */ | 340 | */ |
| 342 | - public final boolean isLandscape() { | 341 | + public boolean isLandscape() { |
| 343 | return getResources().getConfiguration().orientation | 342 | return getResources().getConfiguration().orientation |
| 344 | == Configuration.ORIENTATION_LANDSCAPE; | 343 | == Configuration.ORIENTATION_LANDSCAPE; |
| 345 | } | 344 | } |
| @@ -350,7 +349,7 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | @@ -350,7 +349,7 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | ||
| 350 | * | 349 | * |
| 351 | * @return {@code true}: yes<br>{@code false}: no | 350 | * @return {@code true}: yes<br>{@code false}: no |
| 352 | */ | 351 | */ |
| 353 | - public final boolean isPortrait() { | 352 | + public boolean isPortrait() { |
| 354 | return getResources().getConfiguration().orientation | 353 | return getResources().getConfiguration().orientation |
| 355 | == Configuration.ORIENTATION_PORTRAIT; | 354 | == Configuration.ORIENTATION_PORTRAIT; |
| 356 | } | 355 | } |
| @@ -361,11 +360,11 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | @@ -361,11 +360,11 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | ||
| 361 | * | 360 | * |
| 362 | * @return the bitmap of screen | 361 | * @return the bitmap of screen |
| 363 | */ | 362 | */ |
| 364 | - public final Bitmap screenShot() { | 363 | + public Bitmap screenShot() { |
| 365 | return screenShot(this, false); | 364 | return screenShot(this, false); |
| 366 | } | 365 | } |
| 367 | 366 | ||
| 368 | - public final Bitmap screenShot(boolean isDeleteStatusBar) { | 367 | + public Bitmap screenShot(boolean isDeleteStatusBar) { |
| 369 | return screenShot(this, isDeleteStatusBar); | 368 | return screenShot(this, isDeleteStatusBar); |
| 370 | } | 369 | } |
| 371 | 370 | ||
| @@ -426,7 +425,7 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | @@ -426,7 +425,7 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | ||
| 426 | /** | 425 | /** |
| 427 | * 隐藏软键盘 | 426 | * 隐藏软键盘 |
| 428 | */ | 427 | */ |
| 429 | - public final void hideSoftInput() { | 428 | + public void hideSoftInput() { |
| 430 | InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE); | 429 | InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE); |
| 431 | if (getCurrentFocus() != null && null != imm) { | 430 | if (getCurrentFocus() != null && null != imm) { |
| 432 | imm.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0); | 431 | imm.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0); |
| @@ -436,7 +435,7 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | @@ -436,7 +435,7 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | ||
| 436 | /** | 435 | /** |
| 437 | * 显示软键盘 | 436 | * 显示软键盘 |
| 438 | */ | 437 | */ |
| 439 | - public final void showSoftInput() { | 438 | + public void showSoftInput() { |
| 440 | InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE); | 439 | InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE); |
| 441 | if (getCurrentFocus() != null && null != imm) { | 440 | if (getCurrentFocus() != null && null != imm) { |
| 442 | imm.showSoftInputFromInputMethod(getCurrentFocus().getWindowToken(), 0); | 441 | imm.showSoftInputFromInputMethod(getCurrentFocus().getWindowToken(), 0); |
| @@ -446,7 +445,7 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | @@ -446,7 +445,7 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | ||
| 446 | /** | 445 | /** |
| 447 | * 显示软键盘 | 446 | * 显示软键盘 |
| 448 | */ | 447 | */ |
| 449 | - public final void showSoftInput(View view) { | 448 | + public void showSoftInput(View view) { |
| 450 | InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE); | 449 | InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE); |
| 451 | imm.showSoftInput(view, InputMethodManager.SHOW_FORCED); | 450 | imm.showSoftInput(view, InputMethodManager.SHOW_FORCED); |
| 452 | } | 451 | } |
| @@ -472,7 +471,7 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | @@ -472,7 +471,7 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | ||
| 472 | } | 471 | } |
| 473 | } | 472 | } |
| 474 | 473 | ||
| 475 | - public final void registerEventBus() { | 474 | + public void registerEventBus() { |
| 476 | //注册eventbus | 475 | //注册eventbus |
| 477 | if (!EventBus.getDefault().isRegistered(this)) { | 476 | if (!EventBus.getDefault().isRegistered(this)) { |
| 478 | EventBus.getDefault().register(this); | 477 | EventBus.getDefault().register(this); |
| @@ -486,11 +485,11 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | @@ -486,11 +485,11 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | ||
| 486 | } | 485 | } |
| 487 | } | 486 | } |
| 488 | 487 | ||
| 489 | - public final void postEvent(Object object) { | 488 | + public void postEvent(Object object) { |
| 490 | EventBus.getDefault().post(object); | 489 | EventBus.getDefault().post(object); |
| 491 | } | 490 | } |
| 492 | 491 | ||
| 493 | - public final void postStickyEvent(Object object) { | 492 | + public void postStickyEvent(Object object) { |
| 494 | EventBus.getDefault().postSticky(object); | 493 | EventBus.getDefault().postSticky(object); |
| 495 | } | 494 | } |
| 496 | 495 | ||
| @@ -524,8 +523,8 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | @@ -524,8 +523,8 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | ||
| 524 | * @param color | 523 | * @param color |
| 525 | * @param statusBarAlpha | 524 | * @param statusBarAlpha |
| 526 | */ | 525 | */ |
| 527 | - public final void setStatusBarColor(@ColorRes int color, | ||
| 528 | - @IntRange(from = 0, to = 255) int statusBarAlpha) { | 526 | + public void setStatusBarColor(@ColorRes int color, |
| 527 | + @IntRange(from = 0, to = 255) int statusBarAlpha) { | ||
| 529 | StatusBarUtil.setColor(this, ContextCompat.getColor(this, color), statusBarAlpha); | 528 | StatusBarUtil.setColor(this, ContextCompat.getColor(this, color), statusBarAlpha); |
| 530 | } | 529 | } |
| 531 | 530 | ||
| @@ -535,8 +534,8 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | @@ -535,8 +534,8 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | ||
| 535 | * @param color | 534 | * @param color |
| 536 | * @param statusBarAlpha | 535 | * @param statusBarAlpha |
| 537 | */ | 536 | */ |
| 538 | - public final void setStatusBarColor(@ColorRes int color, | ||
| 539 | - @IntRange(from = 0, to = 255) int statusBarAlpha, @StatusBarConfig.Unit final int textColor) { | 537 | + public void setStatusBarColor(@ColorRes int color, |
| 538 | + @IntRange(from = 0, to = 255) int statusBarAlpha, @StatusBarConfig.Unit final int textColor) { | ||
| 540 | StatusBarUtil.setColor(this, ContextCompat.getColor(this, color), statusBarAlpha); | 539 | StatusBarUtil.setColor(this, ContextCompat.getColor(this, color), statusBarAlpha); |
| 541 | if (textColor == StatusBarConfig.BLACK) { | 540 | if (textColor == StatusBarConfig.BLACK) { |
| 542 | StatusBarUtil.setStatusBarWrite(this); | 541 | StatusBarUtil.setStatusBarWrite(this); |
| @@ -545,15 +544,15 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | @@ -545,15 +544,15 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | ||
| 545 | } | 544 | } |
| 546 | } | 545 | } |
| 547 | 546 | ||
| 548 | - public final void setTransparentForWindow() { | 547 | + public void setTransparentForWindow() { |
| 549 | StatusBarUtil.setTransparentForWindow(this); | 548 | StatusBarUtil.setTransparentForWindow(this); |
| 550 | } | 549 | } |
| 551 | 550 | ||
| 552 | - public final void addTranslucentView(@IntRange(from = 0, to = 255) int statusBarAlpha) { | 551 | + public void addTranslucentView(@IntRange(from = 0, to = 255) int statusBarAlpha) { |
| 553 | StatusBarUtil.addTranslucentView(this, statusBarAlpha); | 552 | StatusBarUtil.addTranslucentView(this, statusBarAlpha); |
| 554 | } | 553 | } |
| 555 | 554 | ||
| 556 | - public final void setDecorViewBgColor(@ColorInt int color) { | 555 | + public void setDecorViewBgColor(@ColorInt int color) { |
| 557 | getWindow().getDecorView().setBackgroundColor(color); | 556 | getWindow().getDecorView().setBackgroundColor(color); |
| 558 | } | 557 | } |
| 559 | 558 | ||
| @@ -561,7 +560,7 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | @@ -561,7 +560,7 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | ||
| 561 | * 设置状态栏字体颜色 | 560 | * 设置状态栏字体颜色 |
| 562 | */ | 561 | */ |
| 563 | // 定义适用于参数的注解,限定取值范围为{STATUS_OPEN, STATUS_CLOSE} | 562 | // 定义适用于参数的注解,限定取值范围为{STATUS_OPEN, STATUS_CLOSE} |
| 564 | - public final void setStatusBarTextColor(@StatusBarConfig.Unit final int type) { | 563 | + public void setStatusBarTextColor(@StatusBarConfig.Unit final int type) { |
| 565 | if (type == StatusBarConfig.BLACK) { | 564 | if (type == StatusBarConfig.BLACK) { |
| 566 | StatusBarUtil.setStatusBarWrite(this); | 565 | StatusBarUtil.setStatusBarWrite(this); |
| 567 | } else if (type == StatusBarConfig.WHITE) { | 566 | } else if (type == StatusBarConfig.WHITE) { |
| @@ -599,21 +598,31 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | @@ -599,21 +598,31 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | ||
| 599 | 598 | ||
| 600 | /********************************************************/ | 599 | /********************************************************/ |
| 601 | //用于进行dip和px转换 | 600 | //用于进行dip和px转换 |
| 602 | - public final int dp2px(float dpValue) { | 601 | + public int dp2px(float dpValue) { |
| 603 | final float scale = getResources().getDisplayMetrics().density; | 602 | final float scale = getResources().getDisplayMetrics().density; |
| 604 | return (int) (dpValue * scale + 0.5f); | 603 | return (int) (dpValue * scale + 0.5f); |
| 605 | } | 604 | } |
| 606 | 605 | ||
| 607 | //用于进行px和dip转换 | 606 | //用于进行px和dip转换 |
| 608 | - public final int px2dp(float pxValue) { | 607 | + public int px2dp(float pxValue) { |
| 609 | final float scale = getResources().getDisplayMetrics().density; | 608 | final float scale = getResources().getDisplayMetrics().density; |
| 610 | return (int) (pxValue / scale + 0.5f); | 609 | return (int) (pxValue / scale + 0.5f); |
| 611 | } | 610 | } |
| 612 | 611 | ||
| 613 | 612 | ||
| 614 | - //网络传输文本判空规则 | ||
| 615 | - public final boolean isNull(String s) { | ||
| 616 | - if (TextUtils.isEmpty(s)) { | 613 | + /** |
| 614 | + * 判空 | ||
| 615 | + * | ||
| 616 | + * @param o | ||
| 617 | + * @return | ||
| 618 | + */ | ||
| 619 | + public boolean isNull(Object o) { | ||
| 620 | + if (o instanceof String) { | ||
| 621 | + String s = (String) o; | ||
| 622 | + if (s == null || s.trim().isEmpty() || "null".equals(s) || "(null)".equals(s)) { | ||
| 623 | + return true; | ||
| 624 | + } | ||
| 625 | + } else if (null == o) { | ||
| 617 | return true; | 626 | return true; |
| 618 | } | 627 | } |
| 619 | return false; | 628 | return false; |
| @@ -629,11 +638,11 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | @@ -629,11 +638,11 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | ||
| 629 | } | 638 | } |
| 630 | } | 639 | } |
| 631 | 640 | ||
| 632 | - public final void finishActivity() { | 641 | + public void finishActivity() { |
| 633 | super.finish(); | 642 | super.finish(); |
| 634 | } | 643 | } |
| 635 | 644 | ||
| 636 | - public final Bundle getSavedInstanceState() { | 645 | + public Bundle getSavedInstanceState() { |
| 637 | return savedInstanceState; | 646 | return savedInstanceState; |
| 638 | } | 647 | } |
| 639 | 648 | ||
| @@ -647,7 +656,7 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | @@ -647,7 +656,7 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | ||
| 647 | * @param permissions 请求的权限 | 656 | * @param permissions 请求的权限 |
| 648 | * @param onPermissionResponseListener 回调监听器 | 657 | * @param onPermissionResponseListener 回调监听器 |
| 649 | */ | 658 | */ |
| 650 | - public final void requestPermission(String[] permissions, OnPermissionResponseListener | 659 | + public void requestPermission(String[] permissions, OnPermissionResponseListener |
| 651 | onPermissionResponseListener) { | 660 | onPermissionResponseListener) { |
| 652 | this.onPermissionResponseListener = onPermissionResponseListener; | 661 | this.onPermissionResponseListener = onPermissionResponseListener; |
| 653 | this.userSetPermission = permissions; | 662 | this.userSetPermission = permissions; |
| @@ -661,7 +670,7 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | @@ -661,7 +670,7 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | ||
| 661 | } | 670 | } |
| 662 | } | 671 | } |
| 663 | 672 | ||
| 664 | - public final void requestPermission(String[] permissions, boolean isShowRefuseDialog, OnPermissionResponseListener | 673 | + public void requestPermission(String[] permissions, boolean isShowRefuseDialog, OnPermissionResponseListener |
| 665 | onPermissionResponseListener) { | 674 | onPermissionResponseListener) { |
| 666 | this.onPermissionResponseListener = onPermissionResponseListener; | 675 | this.onPermissionResponseListener = onPermissionResponseListener; |
| 667 | this.isShowRefuseDialog = isShowRefuseDialog; | 676 | this.isShowRefuseDialog = isShowRefuseDialog; |
| @@ -686,7 +695,7 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | @@ -686,7 +695,7 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | ||
| 686 | * @param onPermissionResponseListener 回调监听器 | 695 | * @param onPermissionResponseListener 回调监听器 |
| 687 | */ | 696 | */ |
| 688 | 697 | ||
| 689 | - public final void requestPermission(boolean isDefineActivity, String[] permissions, OnPermissionResponseListener | 698 | + public void requestPermission(boolean isDefineActivity, String[] permissions, OnPermissionResponseListener |
| 690 | onPermissionResponseListener) { | 699 | onPermissionResponseListener) { |
| 691 | this.onPermissionResponseListener = onPermissionResponseListener; | 700 | this.onPermissionResponseListener = onPermissionResponseListener; |
| 692 | this.isDefinePermissionCloseActivity = isDefineActivity; | 701 | this.isDefinePermissionCloseActivity = isDefineActivity; |
| @@ -701,7 +710,7 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | @@ -701,7 +710,7 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | ||
| 701 | } | 710 | } |
| 702 | } | 711 | } |
| 703 | 712 | ||
| 704 | - public final void requestPermission(boolean isDefineActivity, String[] permissions, boolean isShowRefuseDialog, OnPermissionResponseListener | 713 | + public void requestPermission(boolean isDefineActivity, String[] permissions, boolean isShowRefuseDialog, OnPermissionResponseListener |
| 705 | onPermissionResponseListener) { | 714 | onPermissionResponseListener) { |
| 706 | this.onPermissionResponseListener = onPermissionResponseListener; | 715 | this.onPermissionResponseListener = onPermissionResponseListener; |
| 707 | this.isDefinePermissionCloseActivity = isDefineActivity; | 716 | this.isDefinePermissionCloseActivity = isDefineActivity; |
| @@ -727,7 +736,7 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | @@ -727,7 +736,7 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | ||
| 727 | * @param onPermissionResponseListener 回调监听器 | 736 | * @param onPermissionResponseListener 回调监听器 |
| 728 | */ | 737 | */ |
| 729 | 738 | ||
| 730 | - public final void requestPermission(String defineTip, boolean isDefineActivity, String[] permissions, OnPermissionResponseListener | 739 | + public void requestPermission(String defineTip, boolean isDefineActivity, String[] permissions, OnPermissionResponseListener |
| 731 | onPermissionResponseListener) { | 740 | onPermissionResponseListener) { |
| 732 | this.isDefinePermissionCloseActivity = isDefineActivity; | 741 | this.isDefinePermissionCloseActivity = isDefineActivity; |
| 733 | this.userSetDefinePermissionTip = defineTip; | 742 | this.userSetDefinePermissionTip = defineTip; |
| @@ -743,7 +752,7 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | @@ -743,7 +752,7 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | ||
| 743 | } | 752 | } |
| 744 | } | 753 | } |
| 745 | 754 | ||
| 746 | - public final void requestPermission(String defineTip, boolean isDefineActivity, String[] permissions, boolean isShowRefuseDialog, OnPermissionResponseListener | 755 | + public void requestPermission(String defineTip, boolean isDefineActivity, String[] permissions, boolean isShowRefuseDialog, OnPermissionResponseListener |
| 747 | onPermissionResponseListener) { | 756 | onPermissionResponseListener) { |
| 748 | this.isDefinePermissionCloseActivity = isDefineActivity; | 757 | this.isDefinePermissionCloseActivity = isDefineActivity; |
| 749 | this.userSetDefinePermissionTip = defineTip; | 758 | this.userSetDefinePermissionTip = defineTip; |
| @@ -769,7 +778,7 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | @@ -769,7 +778,7 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | ||
| 769 | * @param permissions 请求的权限 | 778 | * @param permissions 请求的权限 |
| 770 | * @param onPermissionResponseListener 回调监听器 | 779 | * @param onPermissionResponseListener 回调监听器 |
| 771 | */ | 780 | */ |
| 772 | - public final void requestPermission(String defineTip, String[] permissions, OnPermissionResponseListener | 781 | + public void requestPermission(String defineTip, String[] permissions, OnPermissionResponseListener |
| 773 | onPermissionResponseListener) { | 782 | onPermissionResponseListener) { |
| 774 | this.userSetDefinePermissionTip = defineTip; | 783 | this.userSetDefinePermissionTip = defineTip; |
| 775 | this.onPermissionResponseListener = onPermissionResponseListener; | 784 | this.onPermissionResponseListener = onPermissionResponseListener; |
| @@ -784,7 +793,7 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | @@ -784,7 +793,7 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | ||
| 784 | } | 793 | } |
| 785 | } | 794 | } |
| 786 | 795 | ||
| 787 | - public final void requestPermission(String defineTip, String[] permissions, boolean isShowRefuseDialog, OnPermissionResponseListener | 796 | + public void requestPermission(String defineTip, String[] permissions, boolean isShowRefuseDialog, OnPermissionResponseListener |
| 788 | onPermissionResponseListener) { | 797 | onPermissionResponseListener) { |
| 789 | this.userSetDefinePermissionTip = defineTip; | 798 | this.userSetDefinePermissionTip = defineTip; |
| 790 | this.onPermissionResponseListener = onPermissionResponseListener; | 799 | this.onPermissionResponseListener = onPermissionResponseListener; |
| @@ -807,7 +816,7 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | @@ -807,7 +816,7 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | ||
| 807 | * @param permissions | 816 | * @param permissions |
| 808 | * @param onPermissionResponseListener | 817 | * @param onPermissionResponseListener |
| 809 | */ | 818 | */ |
| 810 | - public final void requestPermission(int requestCode, boolean isDefineActivity, String[] | 819 | + public void requestPermission(int requestCode, boolean isDefineActivity, String[] |
| 811 | permissions, OnPermissionResponseListener onPermissionResponseListener) { | 820 | permissions, OnPermissionResponseListener onPermissionResponseListener) { |
| 812 | this.onPermissionResponseListener = onPermissionResponseListener; | 821 | this.onPermissionResponseListener = onPermissionResponseListener; |
| 813 | this.USER_SET_REQUEST_CODE_PERMISSION = requestCode; | 822 | this.USER_SET_REQUEST_CODE_PERMISSION = requestCode; |
| @@ -823,7 +832,7 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | @@ -823,7 +832,7 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | ||
| 823 | } | 832 | } |
| 824 | } | 833 | } |
| 825 | 834 | ||
| 826 | - public final void requestPermission(int requestCode, boolean isDefineActivity, String[] | 835 | + public void requestPermission(int requestCode, boolean isDefineActivity, String[] |
| 827 | permissions, boolean isShowRefuseDialog, OnPermissionResponseListener onPermissionResponseListener) { | 836 | permissions, boolean isShowRefuseDialog, OnPermissionResponseListener onPermissionResponseListener) { |
| 828 | this.onPermissionResponseListener = onPermissionResponseListener; | 837 | this.onPermissionResponseListener = onPermissionResponseListener; |
| 829 | this.USER_SET_REQUEST_CODE_PERMISSION = requestCode; | 838 | this.USER_SET_REQUEST_CODE_PERMISSION = requestCode; |
| @@ -847,7 +856,7 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | @@ -847,7 +856,7 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | ||
| 847 | * @param permissions | 856 | * @param permissions |
| 848 | * @param onPermissionResponseListener | 857 | * @param onPermissionResponseListener |
| 849 | */ | 858 | */ |
| 850 | - public final void requestPermission(int requestCode, String[] | 859 | + public void requestPermission(int requestCode, String[] |
| 851 | permissions, OnPermissionResponseListener onPermissionResponseListener) { | 860 | permissions, OnPermissionResponseListener onPermissionResponseListener) { |
| 852 | this.onPermissionResponseListener = onPermissionResponseListener; | 861 | this.onPermissionResponseListener = onPermissionResponseListener; |
| 853 | this.USER_SET_REQUEST_CODE_PERMISSION = requestCode; | 862 | this.USER_SET_REQUEST_CODE_PERMISSION = requestCode; |
| @@ -862,7 +871,7 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | @@ -862,7 +871,7 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | ||
| 862 | } | 871 | } |
| 863 | } | 872 | } |
| 864 | 873 | ||
| 865 | - public final void requestPermission(int requestCode, String[] | 874 | + public void requestPermission(int requestCode, String[] |
| 866 | permissions, boolean isShowRefuseDialog, OnPermissionResponseListener onPermissionResponseListener) { | 875 | permissions, boolean isShowRefuseDialog, OnPermissionResponseListener onPermissionResponseListener) { |
| 867 | this.onPermissionResponseListener = onPermissionResponseListener; | 876 | this.onPermissionResponseListener = onPermissionResponseListener; |
| 868 | this.USER_SET_REQUEST_CODE_PERMISSION = requestCode; | 877 | this.USER_SET_REQUEST_CODE_PERMISSION = requestCode; |
| @@ -885,7 +894,7 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | @@ -885,7 +894,7 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | ||
| 885 | * @param permissions | 894 | * @param permissions |
| 886 | * @param onPermissionResponseListener | 895 | * @param onPermissionResponseListener |
| 887 | */ | 896 | */ |
| 888 | - public final void requestPermission(int requestCode, String defineTip, boolean isDefineActivity, String[] | 897 | + public void requestPermission(int requestCode, String defineTip, boolean isDefineActivity, String[] |
| 889 | permissions, OnPermissionResponseListener onPermissionResponseListener) { | 898 | permissions, OnPermissionResponseListener onPermissionResponseListener) { |
| 890 | this.onPermissionResponseListener = onPermissionResponseListener; | 899 | this.onPermissionResponseListener = onPermissionResponseListener; |
| 891 | this.USER_SET_REQUEST_CODE_PERMISSION = requestCode; | 900 | this.USER_SET_REQUEST_CODE_PERMISSION = requestCode; |
| @@ -902,7 +911,7 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | @@ -902,7 +911,7 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | ||
| 902 | } | 911 | } |
| 903 | } | 912 | } |
| 904 | 913 | ||
| 905 | - public final void requestPermission(int requestCode, String defineTip, boolean isDefineActivity, String[] | 914 | + public void requestPermission(int requestCode, String defineTip, boolean isDefineActivity, String[] |
| 906 | permissions, boolean isShowRefuseDialog, OnPermissionResponseListener onPermissionResponseListener) { | 915 | permissions, boolean isShowRefuseDialog, OnPermissionResponseListener onPermissionResponseListener) { |
| 907 | this.onPermissionResponseListener = onPermissionResponseListener; | 916 | this.onPermissionResponseListener = onPermissionResponseListener; |
| 908 | this.USER_SET_REQUEST_CODE_PERMISSION = requestCode; | 917 | this.USER_SET_REQUEST_CODE_PERMISSION = requestCode; |
| @@ -927,7 +936,7 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | @@ -927,7 +936,7 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | ||
| 927 | * @param permissions | 936 | * @param permissions |
| 928 | * @param onPermissionResponseListener | 937 | * @param onPermissionResponseListener |
| 929 | */ | 938 | */ |
| 930 | - public final void requestPermission(int requestCode, String defineTip, String[] | 939 | + public void requestPermission(int requestCode, String defineTip, String[] |
| 931 | permissions, OnPermissionResponseListener onPermissionResponseListener) { | 940 | permissions, OnPermissionResponseListener onPermissionResponseListener) { |
| 932 | this.onPermissionResponseListener = onPermissionResponseListener; | 941 | this.onPermissionResponseListener = onPermissionResponseListener; |
| 933 | this.USER_SET_REQUEST_CODE_PERMISSION = requestCode; | 942 | this.USER_SET_REQUEST_CODE_PERMISSION = requestCode; |
| @@ -943,7 +952,7 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | @@ -943,7 +952,7 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | ||
| 943 | } | 952 | } |
| 944 | } | 953 | } |
| 945 | 954 | ||
| 946 | - public final void requestPermission(int requestCode, String defineTip, String[] | 955 | + public void requestPermission(int requestCode, String defineTip, String[] |
| 947 | permissions, boolean isShowRefuseDialog, OnPermissionResponseListener onPermissionResponseListener) { | 956 | permissions, boolean isShowRefuseDialog, OnPermissionResponseListener onPermissionResponseListener) { |
| 948 | this.onPermissionResponseListener = onPermissionResponseListener; | 957 | this.onPermissionResponseListener = onPermissionResponseListener; |
| 949 | this.USER_SET_REQUEST_CODE_PERMISSION = requestCode; | 958 | this.USER_SET_REQUEST_CODE_PERMISSION = requestCode; |
| @@ -968,7 +977,7 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | @@ -968,7 +977,7 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | ||
| 968 | * @param permissions | 977 | * @param permissions |
| 969 | * @param onPermissionResponseListener | 978 | * @param onPermissionResponseListener |
| 970 | */ | 979 | */ |
| 971 | - public final void requestPermission(int requestCode, @StringRes int defineTip, boolean isDefineActivity, String[] | 980 | + public void requestPermission(int requestCode, @StringRes int defineTip, boolean isDefineActivity, String[] |
| 972 | permissions, OnPermissionResponseListener onPermissionResponseListener) { | 981 | permissions, OnPermissionResponseListener onPermissionResponseListener) { |
| 973 | this.onPermissionResponseListener = onPermissionResponseListener; | 982 | this.onPermissionResponseListener = onPermissionResponseListener; |
| 974 | this.USER_SET_REQUEST_CODE_PERMISSION = requestCode; | 983 | this.USER_SET_REQUEST_CODE_PERMISSION = requestCode; |
| @@ -985,7 +994,7 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | @@ -985,7 +994,7 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | ||
| 985 | } | 994 | } |
| 986 | } | 995 | } |
| 987 | 996 | ||
| 988 | - public final void requestPermission(int requestCode, @StringRes int defineTip, boolean isDefineActivity, String[] | 997 | + public void requestPermission(int requestCode, @StringRes int defineTip, boolean isDefineActivity, String[] |
| 989 | permissions, boolean isShowRefuseDialog, OnPermissionResponseListener onPermissionResponseListener) { | 998 | permissions, boolean isShowRefuseDialog, OnPermissionResponseListener onPermissionResponseListener) { |
| 990 | this.onPermissionResponseListener = onPermissionResponseListener; | 999 | this.onPermissionResponseListener = onPermissionResponseListener; |
| 991 | this.USER_SET_REQUEST_CODE_PERMISSION = requestCode; | 1000 | this.USER_SET_REQUEST_CODE_PERMISSION = requestCode; |
| @@ -1011,7 +1020,7 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | @@ -1011,7 +1020,7 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | ||
| 1011 | * @param permissions | 1020 | * @param permissions |
| 1012 | * @param onPermissionResponseListener | 1021 | * @param onPermissionResponseListener |
| 1013 | */ | 1022 | */ |
| 1014 | - public final void requestPermission(int requestCode, @StringRes int defineTip, String[] | 1023 | + public void requestPermission(int requestCode, @StringRes int defineTip, String[] |
| 1015 | permissions, OnPermissionResponseListener onPermissionResponseListener) { | 1024 | permissions, OnPermissionResponseListener onPermissionResponseListener) { |
| 1016 | this.onPermissionResponseListener = onPermissionResponseListener; | 1025 | this.onPermissionResponseListener = onPermissionResponseListener; |
| 1017 | this.USER_SET_REQUEST_CODE_PERMISSION = requestCode; | 1026 | this.USER_SET_REQUEST_CODE_PERMISSION = requestCode; |
| @@ -1027,7 +1036,7 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | @@ -1027,7 +1036,7 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | ||
| 1027 | } | 1036 | } |
| 1028 | } | 1037 | } |
| 1029 | 1038 | ||
| 1030 | - public final void requestPermission(int requestCode, @StringRes int defineTip, String[] | 1039 | + public void requestPermission(int requestCode, @StringRes int defineTip, String[] |
| 1031 | permissions, boolean isShowRefuseDialog, OnPermissionResponseListener onPermissionResponseListener) { | 1040 | permissions, boolean isShowRefuseDialog, OnPermissionResponseListener onPermissionResponseListener) { |
| 1032 | this.onPermissionResponseListener = onPermissionResponseListener; | 1041 | this.onPermissionResponseListener = onPermissionResponseListener; |
| 1033 | this.USER_SET_REQUEST_CODE_PERMISSION = requestCode; | 1042 | this.USER_SET_REQUEST_CODE_PERMISSION = requestCode; |
| @@ -1145,7 +1154,7 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | @@ -1145,7 +1154,7 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | ||
| 1145 | * @param permissions | 1154 | * @param permissions |
| 1146 | * @return | 1155 | * @return |
| 1147 | */ | 1156 | */ |
| 1148 | - public final boolean checkPermissions(String[] permissions) { | 1157 | + public boolean checkPermissions(String[] permissions) { |
| 1149 | boolean isAllow = true; | 1158 | boolean isAllow = true; |
| 1150 | if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { | 1159 | if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { |
| 1151 | isAllow = true; | 1160 | isAllow = true; |
| @@ -1162,7 +1171,7 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | @@ -1162,7 +1171,7 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | ||
| 1162 | } | 1171 | } |
| 1163 | 1172 | ||
| 1164 | //单权限检查 | 1173 | //单权限检查 |
| 1165 | - public final boolean checkPermissions(String permission) { | 1174 | + public boolean checkPermissions(String permission) { |
| 1166 | if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { | 1175 | if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { |
| 1167 | return true; | 1176 | return true; |
| 1168 | } | 1177 | } |
| @@ -1226,7 +1235,7 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | @@ -1226,7 +1235,7 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | ||
| 1226 | 1235 | ||
| 1227 | 1236 | ||
| 1228 | //启动当前应用设置页面 | 1237 | //启动当前应用设置页面 |
| 1229 | - public final void startAppSettings() { | 1238 | + public void startAppSettings() { |
| 1230 | Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS); | 1239 | Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS); |
| 1231 | intent.setData(Uri.parse("package:" + getPackageName())); | 1240 | intent.setData(Uri.parse("package:" + getPackageName())); |
| 1232 | startActivity(intent); | 1241 | startActivity(intent); |
| @@ -1267,31 +1276,31 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | @@ -1267,31 +1276,31 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | ||
| 1267 | // } | 1276 | // } |
| 1268 | 1277 | ||
| 1269 | 1278 | ||
| 1270 | - public final void logError(String info) { | 1279 | + public void logError(String info) { |
| 1271 | Logger.e(info); | 1280 | Logger.e(info); |
| 1272 | } | 1281 | } |
| 1273 | 1282 | ||
| 1274 | - public final void logDebug(String info) { | 1283 | + public void logDebug(String info) { |
| 1275 | Logger.d(info); | 1284 | Logger.d(info); |
| 1276 | } | 1285 | } |
| 1277 | 1286 | ||
| 1278 | - public final void logWarn(String info) { | 1287 | + public void logWarn(String info) { |
| 1279 | Logger.w(info); | 1288 | Logger.w(info); |
| 1280 | } | 1289 | } |
| 1281 | 1290 | ||
| 1282 | - public final void logInfo(String info) { | 1291 | + public void logInfo(String info) { |
| 1283 | Logger.i(info); | 1292 | Logger.i(info); |
| 1284 | } | 1293 | } |
| 1285 | 1294 | ||
| 1286 | - public final void logVerbose(String info) { | 1295 | + public void logVerbose(String info) { |
| 1287 | Logger.v(info); | 1296 | Logger.v(info); |
| 1288 | } | 1297 | } |
| 1289 | 1298 | ||
| 1290 | - public final void logJson(String json) { | 1299 | + public void logJson(String json) { |
| 1291 | Logger.json(json); | 1300 | Logger.json(json); |
| 1292 | } | 1301 | } |
| 1293 | 1302 | ||
| 1294 | - public final void logXml(String xml) { | 1303 | + public void logXml(String xml) { |
| 1295 | Logger.xml(xml); | 1304 | Logger.xml(xml); |
| 1296 | } | 1305 | } |
| 1297 | 1306 |
core/base/src/main/java/com/cnlive/core/libs/base/frame/fragment/BaseFragment.java
| @@ -77,7 +77,7 @@ public abstract class BaseFragment<V extends BaseView, P extends BasePresenter<V | @@ -77,7 +77,7 @@ public abstract class BaseFragment<V extends BaseView, P extends BasePresenter<V | ||
| 77 | } | 77 | } |
| 78 | 78 | ||
| 79 | @Override | 79 | @Override |
| 80 | - public final void onCreate(Bundle savedInstanceState) { | 80 | + public void onCreate(Bundle savedInstanceState) { |
| 81 | super.onCreate(savedInstanceState); | 81 | super.onCreate(savedInstanceState); |
| 82 | if (getActivity() == null) return; | 82 | if (getActivity() == null) return; |
| 83 | me = (BaseActivity) getActivity(); | 83 | me = (BaseActivity) getActivity(); |
| @@ -99,7 +99,7 @@ public abstract class BaseFragment<V extends BaseView, P extends BasePresenter<V | @@ -99,7 +99,7 @@ public abstract class BaseFragment<V extends BaseView, P extends BasePresenter<V | ||
| 99 | 99 | ||
| 100 | @Nullable | 100 | @Nullable |
| 101 | @Override | 101 | @Override |
| 102 | - public final View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { | 102 | + public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { |
| 103 | if (0 != getBindLayoutId()) { | 103 | if (0 != getBindLayoutId()) { |
| 104 | baseBinding = DataBindingUtil.inflate(inflater, getBindLayoutId(), container, false); | 104 | baseBinding = DataBindingUtil.inflate(inflater, getBindLayoutId(), container, false); |
| 105 | if (me.isOpenSwipBack()) { | 105 | if (me.isOpenSwipBack()) { |
| @@ -129,17 +129,22 @@ public abstract class BaseFragment<V extends BaseView, P extends BasePresenter<V | @@ -129,17 +129,22 @@ public abstract class BaseFragment<V extends BaseView, P extends BasePresenter<V | ||
| 129 | return super.onCreateView(inflater, container, savedInstanceState); | 129 | return super.onCreateView(inflater, container, savedInstanceState); |
| 130 | } | 130 | } |
| 131 | 131 | ||
| 132 | + | ||
| 133 | + public boolean isNull(Object o) { | ||
| 134 | + return me.isNull(o); | ||
| 135 | + } | ||
| 136 | + | ||
| 132 | /** | 137 | /** |
| 133 | * 显示白色通知栏 | 138 | * 显示白色通知栏 |
| 134 | */ | 139 | */ |
| 135 | - public final void showDefaultWhiteStatusBar() { | 140 | + public void showDefaultWhiteStatusBar() { |
| 136 | me.showDefaultWhiteStatusBar(); | 141 | me.showDefaultWhiteStatusBar(); |
| 137 | } | 142 | } |
| 138 | 143 | ||
| 139 | /** | 144 | /** |
| 140 | * 显示黑色通知栏 | 145 | * 显示黑色通知栏 |
| 141 | */ | 146 | */ |
| 142 | - public final void showDefaultBlackStatusBar() { | 147 | + public void showDefaultBlackStatusBar() { |
| 143 | me.showDefaultBlackStatusBar(); | 148 | me.showDefaultBlackStatusBar(); |
| 144 | } | 149 | } |
| 145 | 150 | ||
| @@ -148,12 +153,12 @@ public abstract class BaseFragment<V extends BaseView, P extends BasePresenter<V | @@ -148,12 +153,12 @@ public abstract class BaseFragment<V extends BaseView, P extends BasePresenter<V | ||
| 148 | * | 153 | * |
| 149 | * @param enable | 154 | * @param enable |
| 150 | */ | 155 | */ |
| 151 | - public final void setEnableCreateDefultEmptyView(boolean enable) { | 156 | + public void setEnableCreateDefultEmptyView(boolean enable) { |
| 152 | isCreateDefultEmptyView = enable; | 157 | isCreateDefultEmptyView = enable; |
| 153 | } | 158 | } |
| 154 | 159 | ||
| 155 | @Override | 160 | @Override |
| 156 | - public final void onViewCreated(View view, @Nullable Bundle savedInstanceState) { | 161 | + public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { |
| 157 | super.onViewCreated(view, savedInstanceState); | 162 | super.onViewCreated(view, savedInstanceState); |
| 158 | mSwipeDelegate.onViewCreated(view, savedInstanceState); | 163 | mSwipeDelegate.onViewCreated(view, savedInstanceState); |
| 159 | if (null != getMvpView() && null != getPresenter()) { | 164 | if (null != getMvpView() && null != getPresenter()) { |
| @@ -187,12 +192,12 @@ public abstract class BaseFragment<V extends BaseView, P extends BasePresenter<V | @@ -187,12 +192,12 @@ public abstract class BaseFragment<V extends BaseView, P extends BasePresenter<V | ||
| 187 | return view; | 192 | return view; |
| 188 | } | 193 | } |
| 189 | 194 | ||
| 190 | - public final Bundle getSavedInstanceState() { | 195 | + public Bundle getSavedInstanceState() { |
| 191 | return savedInstanceState; | 196 | return savedInstanceState; |
| 192 | } | 197 | } |
| 193 | 198 | ||
| 194 | //添加观察者 | 199 | //添加观察者 |
| 195 | - public final void addObservable(Observable... observable) { | 200 | + public void addObservable(Observable... observable) { |
| 196 | Observable[] result = observable; | 201 | Observable[] result = observable; |
| 197 | if (null != observable) { | 202 | if (null != observable) { |
| 198 | if (null != result) { | 203 | if (null != result) { |
| @@ -224,7 +229,7 @@ public abstract class BaseFragment<V extends BaseView, P extends BasePresenter<V | @@ -224,7 +229,7 @@ public abstract class BaseFragment<V extends BaseView, P extends BasePresenter<V | ||
| 224 | } | 229 | } |
| 225 | } | 230 | } |
| 226 | 231 | ||
| 227 | - public final void registerEventBus() { | 232 | + public void registerEventBus() { |
| 228 | //注册eventbus | 233 | //注册eventbus |
| 229 | if (!EventBus.getDefault().isRegistered(this)) { | 234 | if (!EventBus.getDefault().isRegistered(this)) { |
| 230 | EventBus.getDefault().register(this); | 235 | EventBus.getDefault().register(this); |
| @@ -238,15 +243,15 @@ public abstract class BaseFragment<V extends BaseView, P extends BasePresenter<V | @@ -238,15 +243,15 @@ public abstract class BaseFragment<V extends BaseView, P extends BasePresenter<V | ||
| 238 | } | 243 | } |
| 239 | } | 244 | } |
| 240 | 245 | ||
| 241 | - public final void postEvent(Object object) { | 246 | + public void postEvent(Object object) { |
| 242 | EventBus.getDefault().post(object); | 247 | EventBus.getDefault().post(object); |
| 243 | } | 248 | } |
| 244 | 249 | ||
| 245 | - public final void postStickyEvent(Object object) { | 250 | + public void postStickyEvent(Object object) { |
| 246 | EventBus.getDefault().postSticky(object); | 251 | EventBus.getDefault().postSticky(object); |
| 247 | } | 252 | } |
| 248 | 253 | ||
| 249 | - public final Handler getMyFragHandler() { | 254 | + public Handler getMyFragHandler() { |
| 250 | if (null == myFragHandler) { | 255 | if (null == myFragHandler) { |
| 251 | myFragHandler = new Handler() { | 256 | myFragHandler = new Handler() { |
| 252 | @Override | 257 | @Override |
| @@ -330,7 +335,7 @@ public abstract class BaseFragment<V extends BaseView, P extends BasePresenter<V | @@ -330,7 +335,7 @@ public abstract class BaseFragment<V extends BaseView, P extends BasePresenter<V | ||
| 330 | /** | 335 | /** |
| 331 | * 隐藏软键盘 | 336 | * 隐藏软键盘 |
| 332 | */ | 337 | */ |
| 333 | - public final void hideSoftInput() { | 338 | + public void hideSoftInput() { |
| 334 | me.hideSoftInput(); | 339 | me.hideSoftInput(); |
| 335 | } | 340 | } |
| 336 | 341 | ||
| @@ -338,14 +343,14 @@ public abstract class BaseFragment<V extends BaseView, P extends BasePresenter<V | @@ -338,14 +343,14 @@ public abstract class BaseFragment<V extends BaseView, P extends BasePresenter<V | ||
| 338 | /** | 343 | /** |
| 339 | * 显示竖屏 | 344 | * 显示竖屏 |
| 340 | */ | 345 | */ |
| 341 | - public final void showPortraitScreen() { | 346 | + public void showPortraitScreen() { |
| 342 | me.showPortraitScreen(); | 347 | me.showPortraitScreen(); |
| 343 | } | 348 | } |
| 344 | 349 | ||
| 345 | /** | 350 | /** |
| 346 | * 显示横屏 | 351 | * 显示横屏 |
| 347 | */ | 352 | */ |
| 348 | - public final void showLandscapeScreen() { | 353 | + public void showLandscapeScreen() { |
| 349 | me.showLandscapeScreen(); | 354 | me.showLandscapeScreen(); |
| 350 | } | 355 | } |
| 351 | 356 | ||
| @@ -355,7 +360,7 @@ public abstract class BaseFragment<V extends BaseView, P extends BasePresenter<V | @@ -355,7 +360,7 @@ public abstract class BaseFragment<V extends BaseView, P extends BasePresenter<V | ||
| 355 | * @param color | 360 | * @param color |
| 356 | * @param statusBarAlpha | 361 | * @param statusBarAlpha |
| 357 | */ | 362 | */ |
| 358 | - public final void setStatusBarColor(@ColorRes int color, | 363 | + public void setStatusBarColor(@ColorRes int color, |
| 359 | @IntRange(from = 0, to = 255) int statusBarAlpha) { | 364 | @IntRange(from = 0, to = 255) int statusBarAlpha) { |
| 360 | me.setStatusBarColor(color, statusBarAlpha); | 365 | me.setStatusBarColor(color, statusBarAlpha); |
| 361 | } | 366 | } |
| @@ -366,20 +371,20 @@ public abstract class BaseFragment<V extends BaseView, P extends BasePresenter<V | @@ -366,20 +371,20 @@ public abstract class BaseFragment<V extends BaseView, P extends BasePresenter<V | ||
| 366 | * @param color | 371 | * @param color |
| 367 | * @param statusBarAlpha | 372 | * @param statusBarAlpha |
| 368 | */ | 373 | */ |
| 369 | - public final void setStatusBarColor(@ColorRes int color, | 374 | + public void setStatusBarColor(@ColorRes int color, |
| 370 | @IntRange(from = 0, to = 255) int statusBarAlpha, @StatusBarConfig.Unit final int textColor) { | 375 | @IntRange(from = 0, to = 255) int statusBarAlpha, @StatusBarConfig.Unit final int textColor) { |
| 371 | me.setStatusBarColor(color, statusBarAlpha, textColor); | 376 | me.setStatusBarColor(color, statusBarAlpha, textColor); |
| 372 | } | 377 | } |
| 373 | 378 | ||
| 374 | - public final void setTransparentForWindow() { | 379 | + public void setTransparentForWindow() { |
| 375 | me.setTransparentForWindow(); | 380 | me.setTransparentForWindow(); |
| 376 | } | 381 | } |
| 377 | 382 | ||
| 378 | - public final void addTranslucentView(@IntRange(from = 0, to = 255) int statusBarAlpha) { | 383 | + public void addTranslucentView(@IntRange(from = 0, to = 255) int statusBarAlpha) { |
| 379 | me.addTranslucentView(statusBarAlpha); | 384 | me.addTranslucentView(statusBarAlpha); |
| 380 | } | 385 | } |
| 381 | 386 | ||
| 382 | - public final void setDecorViewBgColor(@ColorInt int color) { | 387 | + public void setDecorViewBgColor(@ColorInt int color) { |
| 383 | me.setDecorViewBgColor(color); | 388 | me.setDecorViewBgColor(color); |
| 384 | } | 389 | } |
| 385 | 390 | ||
| @@ -403,7 +408,7 @@ public abstract class BaseFragment<V extends BaseView, P extends BasePresenter<V | @@ -403,7 +408,7 @@ public abstract class BaseFragment<V extends BaseView, P extends BasePresenter<V | ||
| 403 | /** | 408 | /** |
| 404 | * 设置状态栏字体颜色 | 409 | * 设置状态栏字体颜色 |
| 405 | */ | 410 | */ |
| 406 | - public final void setStatusBarTextColor(@StatusBarConfig.Unit int type) { | 411 | + public void setStatusBarTextColor(@StatusBarConfig.Unit int type) { |
| 407 | me.setStatusBarTextColor(type); | 412 | me.setStatusBarTextColor(type); |
| 408 | } | 413 | } |
| 409 | 414 | ||
| @@ -411,14 +416,14 @@ public abstract class BaseFragment<V extends BaseView, P extends BasePresenter<V | @@ -411,14 +416,14 @@ public abstract class BaseFragment<V extends BaseView, P extends BasePresenter<V | ||
| 411 | /** | 416 | /** |
| 412 | * 显示软键盘 | 417 | * 显示软键盘 |
| 413 | */ | 418 | */ |
| 414 | - public final void showSoftInput() { | 419 | + public void showSoftInput() { |
| 415 | me.showSoftInput(); | 420 | me.showSoftInput(); |
| 416 | } | 421 | } |
| 417 | 422 | ||
| 418 | /** | 423 | /** |
| 419 | * 显示软键盘 | 424 | * 显示软键盘 |
| 420 | */ | 425 | */ |
| 421 | - public final void showSoftInput(View view) { | 426 | + public void showSoftInput(View view) { |
| 422 | me.showSoftInput(view); | 427 | me.showSoftInput(view); |
| 423 | } | 428 | } |
| 424 | 429 | ||
| @@ -426,7 +431,7 @@ public abstract class BaseFragment<V extends BaseView, P extends BasePresenter<V | @@ -426,7 +431,7 @@ public abstract class BaseFragment<V extends BaseView, P extends BasePresenter<V | ||
| 426 | * 设置屏幕为横屏 | 431 | * 设置屏幕为横屏 |
| 427 | * Set the screen to landscape. | 432 | * Set the screen to landscape. |
| 428 | */ | 433 | */ |
| 429 | - public final void setLandscape() { | 434 | + public void setLandscape() { |
| 430 | me.setLandscape(); | 435 | me.setLandscape(); |
| 431 | } | 436 | } |
| 432 | 437 | ||
| @@ -434,7 +439,7 @@ public abstract class BaseFragment<V extends BaseView, P extends BasePresenter<V | @@ -434,7 +439,7 @@ public abstract class BaseFragment<V extends BaseView, P extends BasePresenter<V | ||
| 434 | * 设置屏幕为竖屏 | 439 | * 设置屏幕为竖屏 |
| 435 | * Set the screen to portrait. | 440 | * Set the screen to portrait. |
| 436 | */ | 441 | */ |
| 437 | - public final void setPortrait() { | 442 | + public void setPortrait() { |
| 438 | me.setPortrait(); | 443 | me.setPortrait(); |
| 439 | } | 444 | } |
| 440 | 445 | ||
| @@ -445,7 +450,7 @@ public abstract class BaseFragment<V extends BaseView, P extends BasePresenter<V | @@ -445,7 +450,7 @@ public abstract class BaseFragment<V extends BaseView, P extends BasePresenter<V | ||
| 445 | * | 450 | * |
| 446 | * @return {@code true}: yes<br>{@code false}: no | 451 | * @return {@code true}: yes<br>{@code false}: no |
| 447 | */ | 452 | */ |
| 448 | - public final boolean isLandscape() { | 453 | + public boolean isLandscape() { |
| 449 | return me.isLandscape(); | 454 | return me.isLandscape(); |
| 450 | } | 455 | } |
| 451 | 456 | ||
| @@ -455,123 +460,123 @@ public abstract class BaseFragment<V extends BaseView, P extends BasePresenter<V | @@ -455,123 +460,123 @@ public abstract class BaseFragment<V extends BaseView, P extends BasePresenter<V | ||
| 455 | * | 460 | * |
| 456 | * @return {@code true}: yes<br>{@code false}: no | 461 | * @return {@code true}: yes<br>{@code false}: no |
| 457 | */ | 462 | */ |
| 458 | - public final boolean isPortrait() { | 463 | + public boolean isPortrait() { |
| 459 | return me.isPortrait(); | 464 | return me.isPortrait(); |
| 460 | } | 465 | } |
| 461 | 466 | ||
| 462 | 467 | ||
| 463 | /*********************************************************/ | 468 | /*********************************************************/ |
| 464 | //用于进行dip和px转换 | 469 | //用于进行dip和px转换 |
| 465 | - public final int dp2px(float dpValue) { | 470 | + public int dp2px(float dpValue) { |
| 466 | return me.dp2px(dpValue); | 471 | return me.dp2px(dpValue); |
| 467 | } | 472 | } |
| 468 | 473 | ||
| 469 | //用于进行px和dip转换 | 474 | //用于进行px和dip转换 |
| 470 | - public final int px2dp(float pxValue) { | 475 | + public int px2dp(float pxValue) { |
| 471 | return me.px2dp(pxValue); | 476 | return me.px2dp(pxValue); |
| 472 | } | 477 | } |
| 473 | 478 | ||
| 474 | //权限申请 | 479 | //权限申请 |
| 475 | - public final void requestPermission(String[] permissions, OnPermissionResponseListener onPermissionResponseListener) { | 480 | + public void requestPermission(String[] permissions, OnPermissionResponseListener onPermissionResponseListener) { |
| 476 | me.requestPermission(permissions, onPermissionResponseListener); | 481 | me.requestPermission(permissions, onPermissionResponseListener); |
| 477 | } | 482 | } |
| 478 | 483 | ||
| 479 | - public final void requestPermission(String[] permissions, boolean isShowRefuseDialog, OnPermissionResponseListener onPermissionResponseListener) { | 484 | + public void requestPermission(String[] permissions, boolean isShowRefuseDialog, OnPermissionResponseListener onPermissionResponseListener) { |
| 480 | me.requestPermission(permissions, isShowRefuseDialog, onPermissionResponseListener); | 485 | me.requestPermission(permissions, isShowRefuseDialog, onPermissionResponseListener); |
| 481 | } | 486 | } |
| 482 | 487 | ||
| 483 | //权限申请 | 488 | //权限申请 |
| 484 | - public final void requestPermission(boolean isDefineActivity, String[] permissions, OnPermissionResponseListener onPermissionResponseListener) { | 489 | + public void requestPermission(boolean isDefineActivity, String[] permissions, OnPermissionResponseListener onPermissionResponseListener) { |
| 485 | me.requestPermission(isDefineActivity, permissions, onPermissionResponseListener); | 490 | me.requestPermission(isDefineActivity, permissions, onPermissionResponseListener); |
| 486 | } | 491 | } |
| 487 | 492 | ||
| 488 | - public final void requestPermission(boolean isDefineActivity, String[] permissions, boolean isShowRefuseDialog, OnPermissionResponseListener onPermissionResponseListener) { | 493 | + public void requestPermission(boolean isDefineActivity, String[] permissions, boolean isShowRefuseDialog, OnPermissionResponseListener onPermissionResponseListener) { |
| 489 | me.requestPermission(isDefineActivity, permissions, isShowRefuseDialog, onPermissionResponseListener); | 494 | me.requestPermission(isDefineActivity, permissions, isShowRefuseDialog, onPermissionResponseListener); |
| 490 | } | 495 | } |
| 491 | 496 | ||
| 492 | //权限申请 | 497 | //权限申请 |
| 493 | - public final void requestPermission(int requestCode, String[] permissions, OnPermissionResponseListener onPermissionResponseListener) { | 498 | + public void requestPermission(int requestCode, String[] permissions, OnPermissionResponseListener onPermissionResponseListener) { |
| 494 | me.requestPermission(requestCode, permissions, onPermissionResponseListener); | 499 | me.requestPermission(requestCode, permissions, onPermissionResponseListener); |
| 495 | } | 500 | } |
| 496 | 501 | ||
| 497 | - public final void requestPermission(int requestCode, String[] permissions, boolean isShowRefuseDialog, OnPermissionResponseListener onPermissionResponseListener) { | 502 | + public void requestPermission(int requestCode, String[] permissions, boolean isShowRefuseDialog, OnPermissionResponseListener onPermissionResponseListener) { |
| 498 | me.requestPermission(requestCode, permissions, isShowRefuseDialog, onPermissionResponseListener); | 503 | me.requestPermission(requestCode, permissions, isShowRefuseDialog, onPermissionResponseListener); |
| 499 | } | 504 | } |
| 500 | 505 | ||
| 501 | //权限申请 | 506 | //权限申请 |
| 502 | - public final void requestPermission(int requestCode, boolean isDefineActivity, String[] permissions, OnPermissionResponseListener onPermissionResponseListener) { | 507 | + public void requestPermission(int requestCode, boolean isDefineActivity, String[] permissions, OnPermissionResponseListener onPermissionResponseListener) { |
| 503 | me.requestPermission(requestCode, isDefineActivity, permissions, onPermissionResponseListener); | 508 | me.requestPermission(requestCode, isDefineActivity, permissions, onPermissionResponseListener); |
| 504 | } | 509 | } |
| 505 | 510 | ||
| 506 | - public final void requestPermission(int requestCode, boolean isDefineActivity, String[] permissions, boolean isShowRefuseDialog, OnPermissionResponseListener onPermissionResponseListener) { | 511 | + public void requestPermission(int requestCode, boolean isDefineActivity, String[] permissions, boolean isShowRefuseDialog, OnPermissionResponseListener onPermissionResponseListener) { |
| 507 | me.requestPermission(requestCode, isDefineActivity, permissions, isShowRefuseDialog, onPermissionResponseListener); | 512 | me.requestPermission(requestCode, isDefineActivity, permissions, isShowRefuseDialog, onPermissionResponseListener); |
| 508 | } | 513 | } |
| 509 | 514 | ||
| 510 | //权限申请 | 515 | //权限申请 |
| 511 | - public final void requestPermission(int requestCode, String defineTip, String[] permissions, OnPermissionResponseListener onPermissionResponseListener) { | 516 | + public void requestPermission(int requestCode, String defineTip, String[] permissions, OnPermissionResponseListener onPermissionResponseListener) { |
| 512 | me.requestPermission(requestCode, defineTip, permissions, onPermissionResponseListener); | 517 | me.requestPermission(requestCode, defineTip, permissions, onPermissionResponseListener); |
| 513 | } | 518 | } |
| 514 | 519 | ||
| 515 | - public final void requestPermission(int requestCode, String defineTip, String[] permissions, boolean isShowRefuseDialog, OnPermissionResponseListener onPermissionResponseListener) { | 520 | + public void requestPermission(int requestCode, String defineTip, String[] permissions, boolean isShowRefuseDialog, OnPermissionResponseListener onPermissionResponseListener) { |
| 516 | me.requestPermission(requestCode, defineTip, permissions, isShowRefuseDialog, onPermissionResponseListener); | 521 | me.requestPermission(requestCode, defineTip, permissions, isShowRefuseDialog, onPermissionResponseListener); |
| 517 | } | 522 | } |
| 518 | 523 | ||
| 519 | //权限申请 | 524 | //权限申请 |
| 520 | - public final void requestPermission(int requestCode, String defineTip, boolean isDefineActivity, String[] permissions, OnPermissionResponseListener onPermissionResponseListener) { | 525 | + public void requestPermission(int requestCode, String defineTip, boolean isDefineActivity, String[] permissions, OnPermissionResponseListener onPermissionResponseListener) { |
| 521 | me.requestPermission(requestCode, defineTip, isDefineActivity, permissions, onPermissionResponseListener); | 526 | me.requestPermission(requestCode, defineTip, isDefineActivity, permissions, onPermissionResponseListener); |
| 522 | } | 527 | } |
| 523 | 528 | ||
| 524 | - public final void requestPermission(int requestCode, String defineTip, boolean isDefineActivity, String[] permissions, boolean isShowRefuseDialog, OnPermissionResponseListener onPermissionResponseListener) { | 529 | + public void requestPermission(int requestCode, String defineTip, boolean isDefineActivity, String[] permissions, boolean isShowRefuseDialog, OnPermissionResponseListener onPermissionResponseListener) { |
| 525 | me.requestPermission(requestCode, defineTip, isDefineActivity, permissions, isShowRefuseDialog, onPermissionResponseListener); | 530 | me.requestPermission(requestCode, defineTip, isDefineActivity, permissions, isShowRefuseDialog, onPermissionResponseListener); |
| 526 | } | 531 | } |
| 527 | 532 | ||
| 528 | - public final void requestPermission(String defineTip, String[] permissions, OnPermissionResponseListener | 533 | + public void requestPermission(String defineTip, String[] permissions, OnPermissionResponseListener |
| 529 | onPermissionResponseListener) { | 534 | onPermissionResponseListener) { |
| 530 | me.requestPermission(defineTip, permissions, onPermissionResponseListener); | 535 | me.requestPermission(defineTip, permissions, onPermissionResponseListener); |
| 531 | } | 536 | } |
| 532 | 537 | ||
| 533 | - public final void requestPermission(String defineTip, String[] permissions, boolean isShowRefuseDialog, OnPermissionResponseListener | 538 | + public void requestPermission(String defineTip, String[] permissions, boolean isShowRefuseDialog, OnPermissionResponseListener |
| 534 | onPermissionResponseListener) { | 539 | onPermissionResponseListener) { |
| 535 | me.requestPermission(defineTip, permissions, isShowRefuseDialog, onPermissionResponseListener); | 540 | me.requestPermission(defineTip, permissions, isShowRefuseDialog, onPermissionResponseListener); |
| 536 | } | 541 | } |
| 537 | 542 | ||
| 538 | - public final void requestPermission(String defineTip, boolean isDefineActivity, String[] permissions, OnPermissionResponseListener | 543 | + public void requestPermission(String defineTip, boolean isDefineActivity, String[] permissions, OnPermissionResponseListener |
| 539 | onPermissionResponseListener) { | 544 | onPermissionResponseListener) { |
| 540 | me.requestPermission(defineTip, isDefineActivity, permissions, onPermissionResponseListener); | 545 | me.requestPermission(defineTip, isDefineActivity, permissions, onPermissionResponseListener); |
| 541 | } | 546 | } |
| 542 | 547 | ||
| 543 | - public final void requestPermission(String defineTip, boolean isDefineActivity, String[] permissions, boolean isShowRefuseDialog, OnPermissionResponseListener | 548 | + public void requestPermission(String defineTip, boolean isDefineActivity, String[] permissions, boolean isShowRefuseDialog, OnPermissionResponseListener |
| 544 | onPermissionResponseListener) { | 549 | onPermissionResponseListener) { |
| 545 | me.requestPermission(defineTip, isDefineActivity, permissions, isShowRefuseDialog, onPermissionResponseListener); | 550 | me.requestPermission(defineTip, isDefineActivity, permissions, isShowRefuseDialog, onPermissionResponseListener); |
| 546 | } | 551 | } |
| 547 | 552 | ||
| 548 | - public final void requestPermission(int requestCode, @StringRes int defineTip, String[] | 553 | + public void requestPermission(int requestCode, @StringRes int defineTip, String[] |
| 549 | permissions, OnPermissionResponseListener onPermissionResponseListener) { | 554 | permissions, OnPermissionResponseListener onPermissionResponseListener) { |
| 550 | me.requestPermission(requestCode, defineTip, permissions, onPermissionResponseListener); | 555 | me.requestPermission(requestCode, defineTip, permissions, onPermissionResponseListener); |
| 551 | } | 556 | } |
| 552 | 557 | ||
| 553 | - public final void requestPermission(int requestCode, @StringRes int defineTip, String[] | 558 | + public void requestPermission(int requestCode, @StringRes int defineTip, String[] |
| 554 | permissions, boolean isShowRefuseDialog, OnPermissionResponseListener onPermissionResponseListener) { | 559 | permissions, boolean isShowRefuseDialog, OnPermissionResponseListener onPermissionResponseListener) { |
| 555 | me.requestPermission(requestCode, defineTip, permissions, isShowRefuseDialog, onPermissionResponseListener); | 560 | me.requestPermission(requestCode, defineTip, permissions, isShowRefuseDialog, onPermissionResponseListener); |
| 556 | } | 561 | } |
| 557 | 562 | ||
| 558 | - public final void requestPermission(int requestCode, @StringRes int defineTip, boolean isDefineActivity, String[] | 563 | + public void requestPermission(int requestCode, @StringRes int defineTip, boolean isDefineActivity, String[] |
| 559 | permissions, OnPermissionResponseListener onPermissionResponseListener) { | 564 | permissions, OnPermissionResponseListener onPermissionResponseListener) { |
| 560 | me.requestPermission(requestCode, defineTip, isDefineActivity, permissions, onPermissionResponseListener); | 565 | me.requestPermission(requestCode, defineTip, isDefineActivity, permissions, onPermissionResponseListener); |
| 561 | } | 566 | } |
| 562 | 567 | ||
| 563 | - public final void requestPermission(int requestCode, @StringRes int defineTip, boolean isDefineActivity, String[] | 568 | + public void requestPermission(int requestCode, @StringRes int defineTip, boolean isDefineActivity, String[] |
| 564 | permissions, boolean isShowRefuseDialog, OnPermissionResponseListener onPermissionResponseListener) { | 569 | permissions, boolean isShowRefuseDialog, OnPermissionResponseListener onPermissionResponseListener) { |
| 565 | me.requestPermission(requestCode, defineTip, isDefineActivity, permissions, isShowRefuseDialog, onPermissionResponseListener); | 570 | me.requestPermission(requestCode, defineTip, isDefineActivity, permissions, isShowRefuseDialog, onPermissionResponseListener); |
| 566 | } | 571 | } |
| 567 | 572 | ||
| 568 | //多权限检查 | 573 | //多权限检查 |
| 569 | - public final boolean checkPermissions(String[] permissions) { | 574 | + public boolean checkPermissions(String[] permissions) { |
| 570 | return me.checkPermissions(permissions); | 575 | return me.checkPermissions(permissions); |
| 571 | } | 576 | } |
| 572 | 577 | ||
| 573 | //单权限检查 | 578 | //单权限检查 |
| 574 | - public final boolean checkPermissions(String permission) { | 579 | + public boolean checkPermissions(String permission) { |
| 575 | return me.checkPermissions(permission); | 580 | return me.checkPermissions(permission); |
| 576 | } | 581 | } |
| 577 | 582 |
core/base/src/main/java/com/cnlive/core/libs/base/frame/presenter/BasePresenter.java
| @@ -6,6 +6,9 @@ import com.orhanobut.logger.Logger; | @@ -6,6 +6,9 @@ import com.orhanobut.logger.Logger; | ||
| 6 | 6 | ||
| 7 | import org.greenrobot.eventbus.EventBus; | 7 | import org.greenrobot.eventbus.EventBus; |
| 8 | 8 | ||
| 9 | +/** | ||
| 10 | + * @param <V> | ||
| 11 | + */ | ||
| 9 | public class BasePresenter<V extends BaseView> extends MvpBasePresenter<V> { | 12 | public class BasePresenter<V extends BaseView> extends MvpBasePresenter<V> { |
| 10 | protected final String TAG = this.getClass().getSimpleName(); | 13 | protected final String TAG = this.getClass().getSimpleName(); |
| 11 | 14 | ||
| @@ -17,9 +20,13 @@ public class BasePresenter<V extends BaseView> extends MvpBasePresenter<V> { | @@ -17,9 +20,13 @@ public class BasePresenter<V extends BaseView> extends MvpBasePresenter<V> { | ||
| 17 | EventBus.getDefault().postSticky(object); | 20 | EventBus.getDefault().postSticky(object); |
| 18 | } | 21 | } |
| 19 | 22 | ||
| 20 | - //网络传输文本判空规则 | ||
| 21 | - public static boolean isNull(String s) { | ||
| 22 | - if (s == null || s.trim().isEmpty() || "null".equals(s) || "(null)".equals(s)) { | 23 | + public boolean isNull(Object o) { |
| 24 | + if (o instanceof String) { | ||
| 25 | + String s = (String) o; | ||
| 26 | + if (s == null || s.trim().isEmpty() || "null".equals(s) || "(null)".equals(s)) { | ||
| 27 | + return true; | ||
| 28 | + } | ||
| 29 | + } else if (null == o) { | ||
| 23 | return true; | 30 | return true; |
| 24 | } | 31 | } |
| 25 | return false; | 32 | return false; |
core/base/src/main/java/com/cnlive/core/libs/base/frame/view/BaseView.java
| @@ -31,9 +31,13 @@ public class BaseView implements MvpView { | @@ -31,9 +31,13 @@ public class BaseView implements MvpView { | ||
| 31 | public void initData() { | 31 | public void initData() { |
| 32 | } | 32 | } |
| 33 | 33 | ||
| 34 | - //网络传输文本判空规则 | ||
| 35 | - public final boolean isNull(String s) { | ||
| 36 | - if (TextUtils.isEmpty(s)) { | 34 | + public boolean isNull(Object o) { |
| 35 | + if (o instanceof String) { | ||
| 36 | + String s = (String) o; | ||
| 37 | + if (s == null || s.trim().isEmpty() || "null".equals(s) || "(null)".equals(s)) { | ||
| 38 | + return true; | ||
| 39 | + } | ||
| 40 | + } else if (null == o) { | ||
| 37 | return true; | 41 | return true; |
| 38 | } | 42 | } |
| 39 | return false; | 43 | return false; |
| @@ -47,31 +51,31 @@ public class BaseView implements MvpView { | @@ -47,31 +51,31 @@ public class BaseView implements MvpView { | ||
| 47 | 51 | ||
| 48 | } | 52 | } |
| 49 | 53 | ||
| 50 | - public final void logError(String info) { | 54 | + public void logError(String info) { |
| 51 | Logger.e(info); | 55 | Logger.e(info); |
| 52 | } | 56 | } |
| 53 | 57 | ||
| 54 | - public final void logDebug(String info) { | 58 | + public void logDebug(String info) { |
| 55 | Logger.d(info); | 59 | Logger.d(info); |
| 56 | } | 60 | } |
| 57 | 61 | ||
| 58 | - public final void logWarn(String info) { | 62 | + public void logWarn(String info) { |
| 59 | Logger.w(info); | 63 | Logger.w(info); |
| 60 | } | 64 | } |
| 61 | 65 | ||
| 62 | - public final void logInfo(String info) { | 66 | + public void logInfo(String info) { |
| 63 | Logger.i(info); | 67 | Logger.i(info); |
| 64 | } | 68 | } |
| 65 | 69 | ||
| 66 | - public final void logVerbose(String info) { | 70 | + public void logVerbose(String info) { |
| 67 | Logger.v(info); | 71 | Logger.v(info); |
| 68 | } | 72 | } |
| 69 | 73 | ||
| 70 | - public final void logJson(String json) { | 74 | + public void logJson(String json) { |
| 71 | Logger.json(json); | 75 | Logger.json(json); |
| 72 | } | 76 | } |
| 73 | 77 | ||
| 74 | - public final void logXml(String xml) { | 78 | + public void logXml(String xml) { |
| 75 | Logger.xml(xml); | 79 | Logger.xml(xml); |
| 76 | } | 80 | } |
| 77 | } | 81 | } |
settings.gradle
| 1 | include ':app:strike' | 1 | include ':app:strike' |
| 2 | //基础库 | 2 | //基础库 |
| 3 | include ':core:base',':core:network',':core:imageload' ,':core:app_qr',':core:database' | 3 | include ':core:base',':core:network',':core:imageload' ,':core:app_qr',':core:database' |
| 4 | -include ':cloud:user',':cloud:pay',':cloud:third_tool',':cloud:video',':cloud:app_pay' | 4 | +include ':cloud:user',':cloud:pay',':cloud:third_tool',':cloud:video',':cloud:app_pay',':cloud:wjj_lib' |
| 5 | include ':module:xiaojiasoundbox',':module:pedometer',':module:shanghaishop',':module:shopcity' | 5 | include ':module:xiaojiasoundbox',':module:pedometer',':module:shanghaishop',':module:shopcity' |
| 6 | include ':library_baidumap' | 6 | include ':library_baidumap' |
| 7 | rootProject.name='ModuleStrike' | 7 | rootProject.name='ModuleStrike' |