diff --git a/.idea/compiler.xml b/.idea/compiler.xml index 8f32900..371736b 100644 --- a/.idea/compiler.xml +++ b/.idea/compiler.xml @@ -1,37 +1,37 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml index d2bb3ed..18758f4 100644 --- a/.idea/gradle.xml +++ b/.idea/gradle.xml @@ -1,30 +1,27 @@ - - - - - - + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index 498c646..d5621d1 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -29,7 +29,7 @@ - + diff --git a/app/build.gradle b/app/build.gradle index b520770..e2e3c53 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,133 +1,158 @@ -apply plugin: 'com.android.application' - -// 定义变量,同学们注意:可以定义变量,也可以不定义变量 -def app_android = this.getRootProject().ext.app_android; -def app_dependencies = this.rootProject.ext.app_dependencies; - -android { - // compileOptions.encoding = "GBK" - compileSdkVersion app_android.compileSdkVersion - buildToolsVersion app_android.buildToolsVersion - defaultConfig { - applicationId app_android.applicationId - minSdkVersion app_android.minSdkVersion - targetSdkVersion app_android.targetSdkVersion - versionCode app_android.versionCode - versionName app_android.versionName - testInstrumentationRunner app_android.testInstrumentationRunner - - // 这个方法接收三个非空的参数,第一个:确定值的类型,第二个:指定key的名字,第三个:传值(必须是String) - // 为什么需要定义这个?因为src代码中有可能需要用到跨模块交互,如果是组件化模块显然不行 - // 切记:不能在android根节点,只能在defaultConfig或buildTypes节点下 - buildConfigField("boolean", "isRelease", String.valueOf(isRelease)) - - // 在gradle文件中配置选项参数值(用于APT传参接收) - // 同学们注意:切记:必须写在defaultConfig节点下 - javaCompileOptions { - annotationProcessorOptions { - // project.getName() == app - arguments = [moduleName: project.getName(), packageNameForAPT: packageNameForAPT] - } - } - } - buildTypes { - - debug { - buildConfigField("String", "debug", "\"${url.debug}\"") - - minifyEnabled false - debuggable true - } - release { - buildConfigField("String", "release", "\"${url.release}\"") - - minifyEnabled false - proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' - aaptOptions.cruncherEnabled = false - aaptOptions.useNewCruncher = false - applicationVariants.all { variant -> - variant.outputs.all { - // 输出apk名称为dc_v1.0_wandoujia.apk - def fileName = "atom-latest.apk" - outputFileName = fileName - } - } - } - } - lintOptions { - checkReleaseBuilds false - abortOnError false - } - //签名 - signingConfigs { - release { - - storeFile file('fuzhu.jks') - storePassword "123456" - keyAlias "fuzhu" - keyPassword "123456" - } - - } - dataBinding { - enabled = true - } - compileOptions { - sourceCompatibility = '1.8' - targetCompatibility = '1.8' - } -} - -this.android.sourceSets { - main { - jniLibs.srcDirs = ['libs'] - res.srcDirs = ['src/main/res', 'src/main/res_zxing'] - } -} -dependencies { - implementation fileTree(dir: 'libs', include: ['*.jar']) - - // 循环引入第三方库 - app_dependencies.each {k, v -> - // if (k != "aa" && v != "cc") {} - implementation v - } - - - testImplementation 'junit:junit:4.12' - androidTestImplementation 'androidx.test:runner:1.2.0' - androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' - - implementation files('libs\\eventbus-2.4.0.jar') - implementation files('lib\\XposedBridgeApi-54.jar') - androidTestImplementation 'androidx.test:runner:1.2.0' - androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' - api 'com.blankj:utilcode:1.23.7' - api 'com.tencent.bugly:crashreport:latest.release' - // 公共基础库 - implementation project(":common") - - // arouter 专用 注解模块 - implementation project(":arouter_annotation") - - // 使用注解处理器 - // arouter 专用 注解处理器 - annotationProcessor project(':arouter_compiler') - - // 如果是集成化模式,做发布版本时。各个模块都不能独立运行了 - if (isRelease) { - // 进if,集成,融为一体(order,personal) - - // 订单模块 - implementation project(":order") - - // 个人中心模块 - implementation project(":personal") - - // 个人中心模块 - implementation project(":wechat") - - } - implementation 'com.github.gzu-liyujiang:Android_CN_OAID:4.0.0' -} - +apply plugin: 'com.android.application' + +// 定义变量,同学们注意:可以定义变量,也可以不定义变量 +def app_android = this.getRootProject().ext.app_android; +def app_dependencies = this.rootProject.ext.app_dependencies; + +android { + namespace 'com.fisherbone.fuzhu' + // compileOptions.encoding = "GBK" + compileSdk app_android.compileSdkVersion + compileSdkVersion app_android.compileSdkVersion + buildToolsVersion app_android.buildToolsVersion + defaultConfig { + applicationId app_android.applicationId + minSdk app_android.minSdkVersion + minSdkVersion app_android.minSdkVersion + targetSdk app_android.targetSdkVersion + targetSdkVersion app_android.targetSdkVersion + versionCode app_android.versionCode + versionName app_android.versionName + testInstrumentationRunner app_android.testInstrumentationRunner + multiDexEnabled true //突破应用方法数65535的一个限制 + + // 这个方法接收三个非空的参数,第一个:确定值的类型,第二个:指定key的名字,第三个:传值(必须是String) + // 为什么需要定义这个?因为src代码中有可能需要用到跨模块交互,如果是组件化模块显然不行 + // 切记:不能在android根节点,只能在defaultConfig或buildTypes节点下 + buildConfigField("boolean", "isRelease", String.valueOf(isRelease)) + + // 在gradle文件中配置选项参数值(用于APT传参接收) + // 同学们注意:切记:必须写在defaultConfig节点下 + javaCompileOptions { + annotationProcessorOptions { + // project.getName() == app + arguments = [moduleName: project.getName(), packageNameForAPT: packageNameForAPT] + } + } + } + buildTypes { + + debug { + buildConfigField("String", "debug", "\"${url.debug}\"") + + minifyEnabled false + debuggable true + } + release { + buildConfigField("String", "release", "\"${url.release}\"") + + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + applicationVariants.all { variant -> + variant.outputs.all { + // 输出apk名称为dc_v1.0_wandoujia.apk + def fileName = "atom-latest.apk" + outputFileName = fileName + } + } + } + } + lintOptions { + checkReleaseBuilds false + abortOnError false + } + //签名 + signingConfigs { + release { + + storeFile file('fuzhu.jks') + storePassword "123456" + keyAlias "fuzhu" + keyPassword "123456" + } + + } + buildFeatures { + buildConfig true + dataBinding true + } + + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } + + packagingOptions { + jniLibs { + useLegacyPackaging = true + } + } +} + +this.android.sourceSets { + main { + jniLibs.srcDirs = ['libs'] + res.srcDirs = ['src/main/res', 'src/main/res_zxing'] + } +} +configurations.all { + exclude group: 'org.jetbrains.kotlin', module: 'kotlin-stdlib-jdk7' + exclude group: 'org.jetbrains.kotlin', module: 'kotlin-stdlib-jdk8' +} + +dependencies { + implementation fileTree(dir: 'libs', include: ['*.jar']) + + // 循环引入第三方库 + app_dependencies.each {k, v -> + // if (k != "aa" && v != "cc") {} + implementation v + } + + + testImplementation 'junit:junit:4.12' + androidTestImplementation 'androidx.test:runner:1.2.0' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' + + implementation files('libs\\eventbus-2.4.0.jar') + implementation files('lib\\XposedBridgeApi-54.jar') + androidTestImplementation 'androidx.test:runner:1.2.0' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' + api 'com.blankj:utilcode:1.30.6' + api 'com.tencent.bugly:crashreport:latest.release' + // 公共基础库 + implementation project(":common") + + // arouter 专用 注解模块 + implementation project(":arouter_annotation") + + // 使用注解处理器 + // arouter 专用 注解处理器 + annotationProcessor project(':arouter_compiler') + + // 将 Kotlin 标准库添加到注解处理器的 classpath(DataBinding 编译器需要) + annotationProcessor 'org.jetbrains.kotlin:kotlin-stdlib:1.9.22' + + // 如果是集成化模式,做发布版本时。各个模块都不能独立运行了 + if (isRelease) { + // 进if,集成,融为一体(order,personal) + + // 订单模块 + implementation project(":order") + + // 个人中心模块 + implementation project(":personal") + + // 个人中心模块 + implementation project(":wechat") + + } + implementation 'com.github.gzu-liyujiang:Android_CN_OAID:4.0.0' + + // Kotlin 标准库(DataBinding 在 AGP 8.x 中需要,版本需要与 AGP 兼容) + // 使用 compileOnly 确保在编译时可用,但不会打包到 APK 中(如果项目不使用 Kotlin) + compileOnly 'org.jetbrains.kotlin:kotlin-stdlib:1.9.22' + // 同时添加到 implementation 以确保运行时可用(如果 DataBinding 生成的代码需要) + implementation 'org.jetbrains.kotlin:kotlin-stdlib:1.9.22' +} + diff --git a/app/release/atom-latest.apk b/app/release/atom-latest.apk index 672e56a..e420e56 100644 Binary files a/app/release/atom-latest.apk and b/app/release/atom-latest.apk differ diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index b012814..5cae96e 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,163 +1,191 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/fisherbone/fuzhu/FuzhuApplication.java b/app/src/main/java/com/fisherbone/fuzhu/FuzhuApplication.java index d8ec86c..91578f4 100644 --- a/app/src/main/java/com/fisherbone/fuzhu/FuzhuApplication.java +++ b/app/src/main/java/com/fisherbone/fuzhu/FuzhuApplication.java @@ -1,170 +1,175 @@ -package com.fisherbone.fuzhu; - -import android.app.Application; -import android.content.Context; - -import com.fisherbone.fuzhu.db.dao.DataBaseHelper; -import com.fisherbone.fuzhu.utils.ProfileSpUtils; -import com.github.gzuliyujiang.oaid.DeviceID; -import com.lzy.okgo.OkGo; -import com.lzy.okgo.cache.CacheEntity; -import com.lzy.okgo.cache.CacheMode; -import com.lzy.okgo.cookie.CookieJarImpl; -import com.lzy.okgo.cookie.store.DBCookieStore; -import com.lzy.okgo.https.HttpsUtils; -import com.lzy.okgo.interceptor.HttpLoggingInterceptor; -import com.lzy.okgo.model.HttpHeaders; -import com.lzy.okgo.model.HttpParams; -import com.tencent.bugly.crashreport.CrashReport; -import com.xiangxue.common.network.base.NetworkApi; - -import java.security.cert.CertificateException; -import java.security.cert.X509Certificate; -import java.util.concurrent.TimeUnit; -import java.util.logging.Level; - -import javax.net.ssl.HostnameVerifier; -import javax.net.ssl.SSLSession; -import javax.net.ssl.X509TrustManager; - -import okhttp3.OkHttpClient; - - -/** - * Created by: xudiwei - *

- * on: 2017/3/13. - *

- * 描述:Base Application - * 123 - */ - -public class FuzhuApplication extends Application { - - private static Context mContext; - private static FuzhuApplication baseApplication; - public static FuzhuApplication getInstance() { - return baseApplication; - } - - public static Context getContext() { - return mContext; - } - private boolean privacyPolicyAgreed = true; - - @Override - public void onCreate() { - super.onCreate(); - baseApplication = this; - mContext = this; - CrashReport.initCrashReport(getApplicationContext(), "e940e41c92", false); - //用户资料存储工具 - ProfileSpUtils.init(this); - DataBaseHelper.initOrmLite(this); - initOkGo(); - MyCrashHandler.getInstance().init(this); - NetworkApi.init(new XiangxueNetwork(this)); - - if (privacyPolicyAgreed) { - DeviceID.register(this); - privacyPolicyAgreed = true; - } - - } - - private void initOkGo() { - //---------这里给出的是示例代码,告诉你可以这么传,实际使用的时候,根据需要传,不需要就不传-------------// - HttpHeaders headers = new HttpHeaders(); - headers.put("commonHeaderKey1", "commonHeaderValue1"); //header不支持中文,不允许有特殊字符 - headers.put("commonHeaderKey2", "commonHeaderValue2"); - HttpParams params = new HttpParams(); - params.put("commonParamsKey1", "commonParamsValue1"); //param支持中文,直接传,不要自己编码 - params.put("commonParamsKey2", "这里支持中文参数"); - //----------------------------------------------------------------------------------------// - - OkHttpClient.Builder builder = new OkHttpClient.Builder(); - //log相关 - HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor("OkGo"); - loggingInterceptor.setPrintLevel(HttpLoggingInterceptor.Level.BODY); //log打印级别,决定了log显示的详细程度 - loggingInterceptor.setColorLevel(Level.INFO); //log颜色级别,决定了log在控制台显示的颜色 - builder.addInterceptor(loggingInterceptor); //添加OkGo默认debug日志 - //第三方的开源库,使用通知显示当前请求的log,不过在做文件下载的时候,这个库好像有问题,对文件判断不准确 - //builder.addInterceptor(new ChuckInterceptor(this)); - - //超时时间设置,默认60秒 - builder.readTimeout(OkGo.DEFAULT_MILLISECONDS, TimeUnit.MILLISECONDS); //全局的读取超时时间 - builder.writeTimeout(OkGo.DEFAULT_MILLISECONDS, TimeUnit.MILLISECONDS); //全局的写入超时时间 - builder.connectTimeout(OkGo.DEFAULT_MILLISECONDS, TimeUnit.MILLISECONDS); //全局的连接超时时间 - - //自动管理cookie(或者叫session的保持),以下几种任选其一就行 - //builder.cookieJar(new CookieJarImpl(new SPCookieStore(this))); //使用sp保持cookie,如果cookie不过期,则一直有效 - builder.cookieJar(new CookieJarImpl(new DBCookieStore(this))); //使用数据库保持cookie,如果cookie不过期,则一直有效 - //builder.cookieJar(new CookieJarImpl(new MemoryCookieStore())); //使用内存保持cookie,app退出后,cookie消失 - - //https相关设置,以下几种方案根据需要自己设置 - //方法一:信任所有证书,不安全有风险 - HttpsUtils.SSLParams sslParams1 = HttpsUtils.getSslSocketFactory(); - //方法二:自定义信任规则,校验服务端证书 - HttpsUtils.SSLParams sslParams2 = HttpsUtils.getSslSocketFactory(new SafeTrustManager()); - //方法三:使用预埋证书,校验服务端证书(自签名证书) - //HttpsUtils.SSLParams sslParams3 = HttpsUtils.getSslSocketFactory(getAssets().open("srca.cer")); - //方法四:使用bks证书和密码管理客户端证书(双向认证),使用预埋证书,校验服务端证书(自签名证书) - //HttpsUtils.SSLParams sslParams4 = HttpsUtils.getSslSocketFactory(getAssets().open("xxx.bks"), "123456", getAssets().open("yyy.cer")); - builder.sslSocketFactory(sslParams1.sSLSocketFactory, sslParams1.trustManager); - //配置https的域名匹配规则,详细看demo的初始化介绍,不需要就不要加入,使用不当会导致https握手失败 - builder.hostnameVerifier(new SafeHostnameVerifier()); - - // 其他统一的配置 - // 详细说明看GitHub文档:https://github.com/jeasonlzy/ - OkGo.getInstance().init(this) //必须调用初始化 - .setOkHttpClient(builder.build()) //建议设置OkHttpClient,不设置会使用默认的 - .setCacheMode(CacheMode.NO_CACHE) //全局统一缓存模式,默认不使用缓存,可以不传 - .setCacheTime(CacheEntity.CACHE_NEVER_EXPIRE) //全局统一缓存时间,默认永不过期,可以不传 - .setRetryCount(3); //全局统一超时重连次数,默认为三次,那么最差的情况会请求4次(一次原始请求,三次重连请求),不需要可以设置为0 -// .addCommonHeaders(headers) //全局公共头 -// .addCommonParams(params); //全局公共参数 - } - - /** - * 这里只是我谁便写的认证规则,具体每个业务是否需要验证,以及验证规则是什么,请与服务端或者leader确定 - * 这里只是我谁便写的认证规则,具体每个业务是否需要验证,以及验证规则是什么,请与服务端或者leader确定 - * 这里只是我谁便写的认证规则,具体每个业务是否需要验证,以及验证规则是什么,请与服务端或者leader确定 - * 重要的事情说三遍,以下代码不要直接使用 - */ - private class SafeTrustManager implements X509TrustManager { - @Override - public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException { - } - - @Override - public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException { - try { - for (X509Certificate certificate : chain) { - certificate.checkValidity(); //检查证书是否过期,签名是否通过等 - } - } catch (Exception e) { - throw new CertificateException(e); - } - } - - @Override - public X509Certificate[] getAcceptedIssuers() { - return new X509Certificate[0]; - } - } - - /** - * 这里只是我谁便写的认证规则,具体每个业务是否需要验证,以及验证规则是什么,请与服务端或者leader确定 - * 这里只是我谁便写的认证规则,具体每个业务是否需要验证,以及验证规则是什么,请与服务端或者leader确定 - * 这里只是我谁便写的认证规则,具体每个业务是否需要验证,以及验证规则是什么,请与服务端或者leader确定 - * 重要的事情说三遍,以下代码不要直接使用 - */ - private class SafeHostnameVerifier implements HostnameVerifier { - @Override - public boolean verify(String hostname, SSLSession session) { - //验证主机名是否匹配 - //return hostname.equals("server.jeasonlzy.com"); - return true; - } - } -} +package com.fisherbone.fuzhu; + +import android.app.Application; +import android.content.Context; + +import com.fisherbone.fuzhu.db.dao.DataBaseHelper; +import com.fisherbone.fuzhu.utils.ProfileSpUtils; +import com.github.gzuliyujiang.oaid.DeviceID; +import com.lzy.okgo.OkGo; +import com.lzy.okgo.cache.CacheEntity; +import com.lzy.okgo.cache.CacheMode; +import com.lzy.okgo.cookie.CookieJarImpl; +import com.lzy.okgo.cookie.store.DBCookieStore; +import com.lzy.okgo.https.HttpsUtils; +import com.lzy.okgo.interceptor.HttpLoggingInterceptor; +import com.lzy.okgo.model.HttpHeaders; +import com.lzy.okgo.model.HttpParams; +import com.blankj.utilcode.util.Utils; +import com.tencent.bugly.crashreport.CrashReport; +import com.xiangxue.common.network.base.NetworkApi; + +import java.security.cert.CertificateException; +import java.security.cert.X509Certificate; +import java.util.concurrent.TimeUnit; +import java.util.logging.Level; + +import javax.net.ssl.HostnameVerifier; +import javax.net.ssl.SSLSession; +import javax.net.ssl.X509TrustManager; + +import okhttp3.OkHttpClient; + + +/** + * Created by: xudiwei + *

+ * on: 2017/3/13. + *

+ * 描述:Base Application + * 123 + */ + +public class FuzhuApplication extends Application { + + private static Context mContext; + private static FuzhuApplication baseApplication; + public static FuzhuApplication getInstance() { + return baseApplication; + } + + public static Context getContext() { + return mContext; + } + private boolean privacyPolicyAgreed = true; + + @Override + public void onCreate() { + super.onCreate(); + baseApplication = this; + mContext = this; + + // 初始化 utilcode 工具库(必须在最前面,其他工具可能依赖它) + // Utils.init(this); + + CrashReport.initCrashReport(getApplicationContext(), "e940e41c92", false); + //用户资料存储工具 + ProfileSpUtils.init(this); + DataBaseHelper.initOrmLite(this); + initOkGo(); + MyCrashHandler.getInstance().init(this); + NetworkApi.init(new XiangxueNetwork(this)); + + if (privacyPolicyAgreed) { + DeviceID.register(this); + privacyPolicyAgreed = true; + } + + } + + private void initOkGo() { + //---------这里给出的是示例代码,告诉你可以这么传,实际使用的时候,根据需要传,不需要就不传-------------// + HttpHeaders headers = new HttpHeaders(); + headers.put("commonHeaderKey1", "commonHeaderValue1"); //header不支持中文,不允许有特殊字符 + headers.put("commonHeaderKey2", "commonHeaderValue2"); + HttpParams params = new HttpParams(); + params.put("commonParamsKey1", "commonParamsValue1"); //param支持中文,直接传,不要自己编码 + params.put("commonParamsKey2", "这里支持中文参数"); + //----------------------------------------------------------------------------------------// + + OkHttpClient.Builder builder = new OkHttpClient.Builder(); + //log相关 + HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor("OkGo"); + loggingInterceptor.setPrintLevel(HttpLoggingInterceptor.Level.BODY); //log打印级别,决定了log显示的详细程度 + loggingInterceptor.setColorLevel(Level.INFO); //log颜色级别,决定了log在控制台显示的颜色 + builder.addInterceptor(loggingInterceptor); //添加OkGo默认debug日志 + //第三方的开源库,使用通知显示当前请求的log,不过在做文件下载的时候,这个库好像有问题,对文件判断不准确 + //builder.addInterceptor(new ChuckInterceptor(this)); + + //超时时间设置,默认60秒 + builder.readTimeout(OkGo.DEFAULT_MILLISECONDS, TimeUnit.MILLISECONDS); //全局的读取超时时间 + builder.writeTimeout(OkGo.DEFAULT_MILLISECONDS, TimeUnit.MILLISECONDS); //全局的写入超时时间 + builder.connectTimeout(OkGo.DEFAULT_MILLISECONDS, TimeUnit.MILLISECONDS); //全局的连接超时时间 + + //自动管理cookie(或者叫session的保持),以下几种任选其一就行 + //builder.cookieJar(new CookieJarImpl(new SPCookieStore(this))); //使用sp保持cookie,如果cookie不过期,则一直有效 + builder.cookieJar(new CookieJarImpl(new DBCookieStore(this))); //使用数据库保持cookie,如果cookie不过期,则一直有效 + //builder.cookieJar(new CookieJarImpl(new MemoryCookieStore())); //使用内存保持cookie,app退出后,cookie消失 + + //https相关设置,以下几种方案根据需要自己设置 + //方法一:信任所有证书,不安全有风险 + HttpsUtils.SSLParams sslParams1 = HttpsUtils.getSslSocketFactory(); + //方法二:自定义信任规则,校验服务端证书 + HttpsUtils.SSLParams sslParams2 = HttpsUtils.getSslSocketFactory(new SafeTrustManager()); + //方法三:使用预埋证书,校验服务端证书(自签名证书) + //HttpsUtils.SSLParams sslParams3 = HttpsUtils.getSslSocketFactory(getAssets().open("srca.cer")); + //方法四:使用bks证书和密码管理客户端证书(双向认证),使用预埋证书,校验服务端证书(自签名证书) + //HttpsUtils.SSLParams sslParams4 = HttpsUtils.getSslSocketFactory(getAssets().open("xxx.bks"), "123456", getAssets().open("yyy.cer")); + builder.sslSocketFactory(sslParams1.sSLSocketFactory, sslParams1.trustManager); + //配置https的域名匹配规则,详细看demo的初始化介绍,不需要就不要加入,使用不当会导致https握手失败 + builder.hostnameVerifier(new SafeHostnameVerifier()); + + // 其他统一的配置 + // 详细说明看GitHub文档:https://github.com/jeasonlzy/ + OkGo.getInstance().init(this) //必须调用初始化 + .setOkHttpClient(builder.build()) //建议设置OkHttpClient,不设置会使用默认的 + .setCacheMode(CacheMode.NO_CACHE) //全局统一缓存模式,默认不使用缓存,可以不传 + .setCacheTime(CacheEntity.CACHE_NEVER_EXPIRE) //全局统一缓存时间,默认永不过期,可以不传 + .setRetryCount(3); //全局统一超时重连次数,默认为三次,那么最差的情况会请求4次(一次原始请求,三次重连请求),不需要可以设置为0 +// .addCommonHeaders(headers) //全局公共头 +// .addCommonParams(params); //全局公共参数 + } + + /** + * 这里只是我谁便写的认证规则,具体每个业务是否需要验证,以及验证规则是什么,请与服务端或者leader确定 + * 这里只是我谁便写的认证规则,具体每个业务是否需要验证,以及验证规则是什么,请与服务端或者leader确定 + * 这里只是我谁便写的认证规则,具体每个业务是否需要验证,以及验证规则是什么,请与服务端或者leader确定 + * 重要的事情说三遍,以下代码不要直接使用 + */ + private class SafeTrustManager implements X509TrustManager { + @Override + public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException { + } + + @Override + public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException { + try { + for (X509Certificate certificate : chain) { + certificate.checkValidity(); //检查证书是否过期,签名是否通过等 + } + } catch (Exception e) { + throw new CertificateException(e); + } + } + + @Override + public X509Certificate[] getAcceptedIssuers() { + return new X509Certificate[0]; + } + } + + /** + * 这里只是我谁便写的认证规则,具体每个业务是否需要验证,以及验证规则是什么,请与服务端或者leader确定 + * 这里只是我谁便写的认证规则,具体每个业务是否需要验证,以及验证规则是什么,请与服务端或者leader确定 + * 这里只是我谁便写的认证规则,具体每个业务是否需要验证,以及验证规则是什么,请与服务端或者leader确定 + * 重要的事情说三遍,以下代码不要直接使用 + */ + private class SafeHostnameVerifier implements HostnameVerifier { + @Override + public boolean verify(String hostname, SSLSession session) { + //验证主机名是否匹配 + //return hostname.equals("server.jeasonlzy.com"); + return true; + } + } +} diff --git a/app/src/main/java/com/fisherbone/fuzhu/PhoneActivity.java b/app/src/main/java/com/fisherbone/fuzhu/PhoneActivity.java index 8d2f6be..5ee276f 100644 --- a/app/src/main/java/com/fisherbone/fuzhu/PhoneActivity.java +++ b/app/src/main/java/com/fisherbone/fuzhu/PhoneActivity.java @@ -1,625 +1,606 @@ -package com.fisherbone.fuzhu; - -import android.content.ContentProviderOperation; -import android.content.ContentResolver; -import android.content.ContentUris; -import android.content.ContentValues; -import android.content.Intent; -import android.content.OperationApplicationException; -import android.database.Cursor; -import android.net.Uri; -import android.os.Bundle; -import android.os.Handler; -import android.os.Message; -import android.os.RemoteException; -import android.provider.ContactsContract; -import android.util.Log; -import android.view.View; -import android.widget.Button; -import android.widget.ImageView; -import android.widget.RadioButton; -import android.widget.RadioGroup; -import android.widget.RelativeLayout; -import android.widget.TextView; -import android.widget.Toast; - -import androidx.recyclerview.widget.RecyclerView; - -import com.fisherbone.fuzhu.config.Callback; -import com.fisherbone.fuzhu.utils.MyToast; -import com.fisherbone.fuzhu.utils.PrefUtils; -import com.fisherbone.fuzhu.views.ConfirmDialog; -import com.fisherbone.fuzhu.views.LoadingDialog; - -import java.util.ArrayList; -import java.util.List; - -import butterknife.BindView; -import butterknife.ButterKnife; -import butterknife.OnClick; - -/** - * Created by Eren on 2017/6/23. - *

- * 通讯录 - */ -public class PhoneActivity extends BaseActivity implements RadioGroup.OnCheckedChangeListener { - @BindView(R.id.iv_back) - ImageView mIvBack; - @BindView(R.id.tv_content_city) - TextView mTvContentCity; - @BindView(R.id.rl_city) - RelativeLayout mRlCity; - @BindView(R.id.rv_phone) - RecyclerView mRvPhone; - @BindView(R.id.but_begin) - Button mButBegin; - @BindView(R.id.clean_phone) - RelativeLayout mCleanPhone; - @BindView(R.id.open_phone) - RelativeLayout mOpenPhone; - @BindView(R.id.import_phone) - RelativeLayout mImportPhone; - @BindView(R.id.smash_phone) - RelativeLayout mSmashPhone; - @BindView(R.id.mobile) - RadioButton mMobile; - @BindView(R.id.telecom) - RadioButton mTelecom; - @BindView(R.id.unicom) - RadioButton mUnicom; - @BindView(R.id.rg_opera) - RadioGroup mRgOpera; - // private MyApplication mApp; - /** - * 自定义对话框 - */ - private ConfirmDialog mConfirmDialog; - /** - * 跳转返回时的flag - */ - private static final int REQUEST_CODE_PICK_CITY = 0; - /** - * 选中的城市 - */ - private String city; - /** - * 获取所有符合号段集合 - */ - // private List mCityPhoneList; - - private List phoneNumber = new ArrayList<>(); - // private PhoneRvAdapter mRvAdapter; - - private LoadingDialog mLoadingDialog; - - /** - * 导入通讯录 - */ - public static final int IMPORT_PHONE = 0; - /** - * 导入完成 - */ - public static final int IMPORT_PHONE_OVER = 1; - /** - * 清空号码段 - */ - public static final int CLEAN_PHONE = 2; - /** - * 清空通讯录 - */ - public static final int CLEAN_PHONE_BOOK = 3; - /** - * 通讯录清空完成 - */ - public static final int CLEAN_PHONE_OVER = 4; - - - private Handler myHandler = new Handler() { - @Override - public void handleMessage(Message msg) { - super.handleMessage(msg); - switch (msg.what) { - case IMPORT_PHONE: - //加载进度 - mLoadingDialog = new LoadingDialog(PhoneActivity.this); - mLoadingDialog.setContent("正在导入通讯录..."); - mLoadingDialog.setCancelable(false); - mLoadingDialog.show(); - break; - - case IMPORT_PHONE_OVER: - mLoadingDialog.dismiss(); - - MyToast.show(PhoneActivity.this, "导入成功"); - break; - - case CLEAN_PHONE: - MyToast.show(PhoneActivity.this, "清空成功"); - - break; - - case CLEAN_PHONE_BOOK: - //清空通讯录 - mLoadingDialog = new LoadingDialog(PhoneActivity.this); - mLoadingDialog.setContent("正在清空通讯录..."); - mLoadingDialog.setCancelable(false); - mLoadingDialog.show(); - break; - - case CLEAN_PHONE_OVER: - mLoadingDialog.dismiss(); - MyToast.show(PhoneActivity.this, "清空成功"); - break; - default: - } - } - }; - // private CityNumberBean.AutoCityBean mCityNumberBean = new CityNumberBean.AutoCityBean(); - - - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_phone); - ButterKnife.bind(this); -// mApp = (MyApplication) getApplication(); -// initRg(); -// initRv(); - - - findViewById(R.id.clean_phone).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - phoneNumber.add("18133922189"); - phoneNumber.add("18133922190"); - phoneNumber.add("18133922191"); - phoneNumber.add("18133922192"); - phoneNumber.add("18133922193"); - phoneNumber.add("18133922194"); - - if (phoneNumber.size() == 0) { - MyToast.show(PhoneActivity.this, "号码不能为空"); - } else { - mConfirmDialog = new ConfirmDialog(PhoneActivity.this, new Callback() { - @Override - public void Positive() { - new Thread( new Runnable() { - @Override - public void run() { - myHandler.sendEmptyMessage(IMPORT_PHONE); - try { - testAddContactsInTransaction(); - // writeContact(); - // addContacts("ddd","18133988585"); - } catch (Exception e) { - e.printStackTrace(); - } - myHandler.sendEmptyMessage(IMPORT_PHONE_OVER); - } - }).start(); - } - @Override - public void Negative() { - mConfirmDialog.dismiss(); - } - }); - mConfirmDialog.setContent("提示:" + "\n是否导入通讯录"); - mConfirmDialog.setCancelable(true); - mConfirmDialog.show(); - } - } - }); - } - - /** - * 初始化运营商 - */ -// private void initRg() { -// if (mApp.mCityNumberList.size() > 0 && mApp.mCityNumberList != null) { //如果网络获取成功 -// mCityNumberBean = mApp.mCityNumberList.get(0); -// //从网络里获取城市 -// city = mCityNumberBean.getCity(); -// mTvContentCity.setText(city); -// -// PrefUtils.putString(PhoneActivity.this, "phone_area", city); -// -// //从网络里获取运营商 -// String operator = mCityNumberBean.getOperator(); -// Log.i("123", operator); -// PrefUtils.putString(PhoneActivity.this, "phone_opera", operator); //如果网络获取成功,设置成网络运营商 -// } else { -// PrefUtils.putString(PhoneActivity.this, "phone_opera", "移动"); //如果网络获取失败,第一次默认是移动,不设置会出现空白状态 -// PrefUtils.putString(PhoneActivity.this, "phone_area", "无锡"); -// city = "无锡"; -// mTvContentCity.setText("无锡"); -// Log.i("123", "AAAA"); -// } -// //从网络获取的运营商选中状态 -// switch (PrefUtils.getString(PhoneActivity.this, "phone_opera", "移动")) { -// case "移动": -// mMobile.setChecked(true); -// break; -// -// case "电信": -// mTelecom.setChecked(true); -// break; -// -// case "联通": -// mUnicom.setChecked(true); -// break; -// } -// mRgOpera.setOnCheckedChangeListener(this); -// } - - /** - * 初始化RecyclerView - */ -// private void initRv() { -// mRvPhone.setLayoutManager(new GridLayoutManager(this, 2)); -// mRvAdapter = new PhoneRvAdapter(PhoneActivity.this, phoneNumber); -// mRvPhone.setAdapter(mRvAdapter); -// mRvPhone.addItemDecoration(new SpaceItemDecoration(10)); -// -// } - - @OnClick({R.id.iv_back, R.id.rl_city, R.id.but_begin, R.id.clean_phone, R.id.open_phone, R.id.import_phone, R.id.smash_phone}) - public void onViewClicked(View view) { - switch (view.getId()) { - case R.id.iv_back: //返回按钮 - // outAnimation(); - break; - case R.id.rl_city: //选择城市 -// startActivityForResult(new Intent(PhoneActivity.this, CityPickerActivity.class), REQUEST_CODE_PICK_CITY); -// overridePendingTransition(R.anim.anim_in, R.anim.anim_out); - break; - case R.id.but_begin: //生成号码段 -// phoneNumber.clear(); -// if (city == null) { // 判断有没有选择城市 -// MyToast.show(PhoneActivity.this, "未选择城市"); -// } else { -// mRvPhone.setVisibility(View.VISIBLE); -// CityPhoneDao cityPhoneDao = new CityPhoneDao(PhoneActivity.this); -// mCityPhoneList = cityPhoneDao.findAll(); -// // 循环加入集合,后四位随机生成 -// for (int i = 0; i < mCityPhoneList.size(); i++) { -// for (int j = 0; j < 5; j++) { -// String phoneNum = mCityPhoneList.get(i).getName() + (int) (Math.random() * 9000 + 1000); -// phoneNumber.add(phoneNum); -// } -// } -// //刷新适配器 -// mRvAdapter = new PhoneRvAdapter(PhoneActivity.this, phoneNumber); -// mRvPhone.setAdapter(mRvAdapter); -// } - break; - - case R.id.clean_phone: //导入通讯录 - phoneNumber.add("18133922190"); - phoneNumber.add("18133922188"); - - if (phoneNumber.size() == 0) { - MyToast.show(PhoneActivity.this, "号码不能为空"); - } else { - mConfirmDialog = new ConfirmDialog(PhoneActivity.this, new Callback() { - @Override - public void Positive() { - new Thread( new Runnable() { - @Override - public void run() { - myHandler.sendEmptyMessage(IMPORT_PHONE); - try { - testAddContactsInTransaction(); - } catch (Exception e) { - e.printStackTrace(); - } - myHandler.sendEmptyMessage(IMPORT_PHONE_OVER); - } - }).start(); - } - @Override - public void Negative() { - mConfirmDialog.dismiss(); - } - }); - mConfirmDialog.setContent("提示:" + "\n是否导入通讯录"); - mConfirmDialog.setCancelable(true); - mConfirmDialog.show(); - } - break; - - case R.id.open_phone: // 打开联系人界面 - - Intent intent = new Intent(); - intent.setClassName("com.android.contacts", "com.android.contacts.activities.PeopleActivity"); - startActivity(intent); - break; - case R.id.import_phone: //清空号码段 - if (phoneNumber.size() == 0) { - MyToast.show(PhoneActivity.this, "号码为空"); - } else { - mConfirmDialog = new ConfirmDialog(PhoneActivity.this, new Callback() { - @Override - public void Positive() { - phoneNumber.clear(); - mRvPhone.setVisibility(View.GONE); - myHandler.sendEmptyMessage(CLEAN_PHONE); - } - @Override - public void Negative() { - mConfirmDialog.dismiss(); - } - }); - mConfirmDialog.setContent("提示:" + "\n是否清空电话号码"); - mConfirmDialog.setCancelable(true); - mConfirmDialog.show(); - } - break; - case R.id.smash_phone: //清空通讯录 - mConfirmDialog = new ConfirmDialog(PhoneActivity.this, new Callback() { - @Override - public void Positive() { - new Thread(new Runnable() { - @Override - public void run() { - myHandler.sendEmptyMessage(CLEAN_PHONE_BOOK); - clearContent(); -// cleanphone(); - myHandler.sendEmptyMessage(CLEAN_PHONE_OVER); - } - }).start(); - } - - @Override - public void Negative() { - mConfirmDialog.dismiss(); - } - }); - mConfirmDialog.setContent("提示:" + "\n是否清空通讯录"); - mConfirmDialog.setCancelable(true); - mConfirmDialog.show(); - break; - default: - } - - } - -// @Override -// protected void onActivityResult(int requestCode, int resultCode, Intent data) { -// if (requestCode == REQUEST_CODE_PICK_CITY && resultCode == RESULT_OK) { -// if (data != null) { -// city = data.getStringExtra(CityPickerActivity.KEY_PICKED_CITY); -// mTvContentCity.setText(city); -// PrefUtils.putString(PhoneActivity.this, "phone_area", city); -// } -// } -// } -// - @Override - public void onCheckedChanged(RadioGroup group, int checkedId) { - switch (checkedId) { - case R.id.mobile: - PrefUtils.putString(PhoneActivity.this, "phone_opera", "移动"); - break; - - case R.id.telecom: - PrefUtils.putString(PhoneActivity.this, "phone_opera", "电信"); - break; - - case R.id.unicom: - PrefUtils.putString(PhoneActivity.this, "phone_opera", "联通"); - break; - default: - } - } - - - /** - * 清空系统通信录数据 - */ - public void clearContent() { - ContentResolver cr = PhoneActivity.this.getContentResolver();// 获取 - // ContentResolver对象查询在ContentProvider里定义的共享对象 - // 根据URI对象ContactsContract.Contacts.CONTENT_URI查询所有联系人 - Cursor cursor = cr.query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null); - try { - // 如果记录不为空 - if (cursor != null) { - // 游标初始指向查询结果的第一条记录的上方,执行moveToNext函数会判断 - // 下一条记录是否存在,如果存在,指向下一条记录。否则,返回false。 - // 循环 - while (cursor.moveToNext()) { - String name = cursor - .getString(cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME)); - // 根据姓名求id - Uri uri = Uri.parse("content://com.android.contacts/raw_contacts"); - - Cursor cursor1 = cr.query(uri, new String[]{ContactsContract.Data._ID}, "display_name=?", new String[]{name}, - null); - // 除去姓名对应的号码 - if (cursor1.moveToFirst()) { - int id = cursor1.getInt(0); - cr.delete(uri, "display_name=?", new String[]{name}); - // 根据id删除data中的相应数据 - uri = Uri.parse("content://com.android.contacts/data"); - cr.delete(uri, "raw_contact_id=?", new String[]{id + ""}); - } - cursor1.close();// Cursor循环内再申请Cursor,记得将内部申请的每个Cursor都加上close - } - cursor.close(); - - } else { - Toast.makeText(PhoneActivity.this, "通讯录为空", Toast.LENGTH_SHORT).show(); - } - } catch (Exception e) { - // TODO: handle exception - } - } - -// private void cleanphone(){ -// ContentResolver cr = PhoneActivity.this.getContentResolver();// 获取 -// Cursor contactsCur = cr.query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null); -// while(contactsCur.moveToNext()){ -// //获取ID -// String rawId = contactsCur.getString(contactsCur.getColumnIndex(ContactsContract.Contacts._ID)); -// //删除 -// String where = ContactsContract.Data._ID + " =?"; -// String[] whereparams = new String[]{rawId}; -// getContentResolver().delete(ContactsContract.RawContacts.CONTENT_URI, where, whereparams); -// } -// } - - - /** - * 批量添加联系人到通讯录中 - * - * @throws Exception - */ - public void testAddContactsInTransaction() throws Exception { - ArrayList mOperations = new ArrayList<>(); - ContentResolver resolver = PhoneActivity.this.getContentResolver(); - int rawContactInsertIndex; - // 循环添加 - for (int i = 0; i < phoneNumber.size(); i++) { - Uri uri = Uri.parse("content://com.android.contacts/raw_contacts"); - rawContactInsertIndex = mOperations.size();// 这句好很重要,有了它才能给真正的实现批量添加。 - // 向raw_contact表添加一条记录 - // 此处.withValue("account_name", null)一定要加,不然会抛NullPointerException - ContentProviderOperation operation1 = ContentProviderOperation.newInsert(uri) - .withValue("account_name", null).build(); - mOperations.add(operation1); - // 向data添加数据 - uri = Uri.parse("content://com.android.contacts/data"); - // 添加姓名 - ContentProviderOperation operation2 = ContentProviderOperation.newInsert(uri) - .withValueBackReference("raw_contact_id", rawContactInsertIndex) - // withValueBackReference的第二个参数表示引用operations[0]的操作的返回id作为此值 - .withValue("mimetype", "vnd.android.cursor.item/name").withValue("data2", phoneNumber.get(i)) - .withYieldAllowed(true).build(); - mOperations.add(operation2); - // 添加手机数据 - ContentProviderOperation operation3 = ContentProviderOperation.newInsert(uri) - .withValueBackReference("raw_contact_id", rawContactInsertIndex) - .withValue("mimetype", "vnd.android.cursor.item/phone_v2").withValue("data2", "2") - .withValue("data1", phoneNumber.get(i)).withYieldAllowed(true).build(); - mOperations.add(operation3); - - } - try { - // 这里才调用的批量添加 - resolver.applyBatch("com.android.contacts", mOperations); - - } catch (RemoteException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (OperationApplicationException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - - @Override - protected void onDestroy() { - super.onDestroy(); - myHandler.removeCallbacksAndMessages(null); - } - - - - /** - * 导入到通讯录 - */ - public void addContacts(String name , String tel){ - name = name+"@客户管理"; - //插入raw_contacts表,并获取_id属性 - Uri uri = Uri.parse("content://com.android.contacts/raw_contacts"); - ContentResolver resolver = getContentResolver(); - ContentValues values = new ContentValues(); - long contact_id = ContentUris.parseId(resolver.insert(uri, values)); - //插入data表 - uri = Uri.parse("content://com.android.contacts/data"); - //add Name - values.put("raw_contact_id", contact_id); - values.put(ContactsContract.Data.MIMETYPE,"vnd.android.cursor.item/name"); - values.put("data2", name); - values.put("data1", name); - resolver.insert(uri, values); - values.clear(); - //add Phone - values.put("raw_contact_id", contact_id); - values.put(ContactsContract.Data.MIMETYPE,"vnd.android.cursor.item/phone_v2"); - values.put("data2", "2"); //手机 - values.put("data1", tel); - resolver.insert(uri, values); - values.clear(); - /*//add email - values.put("raw_contact_id", contact_id); - values.put(ContactsContract.Data.MIMETYPE,"vnd.android.cursor.item/email_v2"); - values.put("data2", "2"); //单位 - values.put("data1", "xzdong@xzdong.com"); - resolver.insert(uri, values);*/ - } - - - /** - * 写入手机联系人 - */ - private void writeContact() { - String name = "test"; - String number = "13666668888"; - - //先查询要添加的号码是否已存在通讯录中, 不存在则添加. 存在则提示用户 - Uri uri = Uri.parse("content://com.android.contacts/data/phones/filter/" + number); - ContentResolver resolver = getContentResolver(); - //从raw_contact表中返回display_name - Cursor cursor = resolver.query(uri, new String[]{ContactsContract.Data.DISPLAY_NAME}, null, null, null); - if (cursor == null) - return; - - if (cursor.moveToFirst()) { - Log.i("nn", "name=" + cursor.getString(0)); - Toast.makeText(this, "存在相同号码", Toast.LENGTH_SHORT).show(); - } else { - uri = Uri.parse("content://com.android.contacts/raw_contacts"); - ContentValues values = new ContentValues(); - long contact_id = ContentUris.parseId(resolver.insert(uri, values)); - //插入data表 - uri = Uri.parse("content://com.android.contacts/data"); - //add Name - values.put("raw_contact_id", contact_id); - values.put(ContactsContract.Data.MIMETYPE, "vnd.android.cursor.item/name"); - values.put("data2", "qq"); - values.put("data1", name); - resolver.insert(uri, values); - values.clear(); - - //add Phone - values.put("raw_contact_id", contact_id); - values.put(ContactsContract.Data.MIMETYPE, "vnd.android.cursor.item/phone_v2"); - values.put("data2", "2"); //手机 - values.put("data1", number); - resolver.insert(uri, values); - values.clear(); - - //add email - values.put("raw_contact_id", contact_id); - values.put(ContactsContract.Data.MIMETYPE, "vnd.android.cursor.item/email_v2"); - values.put("data2", "1"); //邮箱 - values.put("data1", "xxxx@qq.com"); - resolver.insert(uri, values); - values.clear(); - - //add organization - values.put("raw_contact_id", contact_id); - values.put(ContactsContract.Data.MIMETYPE, "vnd.android.cursor.item/organization"); - values.put("data4", "产品经理"); //职务 - values.put("data1", "腾讯科技"); //公司 - resolver.insert(uri, values); - values.clear(); - - Toast.makeText(this, "插入号码成功", Toast.LENGTH_SHORT).show(); - } - cursor.close(); - } - -} +package com.fisherbone.fuzhu; + +import android.content.ContentProviderOperation; +import android.content.ContentResolver; +import android.content.ContentUris; +import android.content.ContentValues; +import android.content.Intent; +import android.content.OperationApplicationException; +import android.database.Cursor; +import android.net.Uri; +import android.os.Bundle; +import android.os.Handler; +import android.os.Message; +import android.os.RemoteException; +import android.provider.ContactsContract; +import android.util.Log; +import android.view.View; +import android.widget.Button; +import android.widget.ImageView; +import android.widget.RadioButton; +import android.widget.RadioGroup; +import android.widget.RelativeLayout; +import android.widget.TextView; +import android.widget.Toast; + +import androidx.recyclerview.widget.RecyclerView; + +import com.fisherbone.fuzhu.config.Callback; +import com.fisherbone.fuzhu.utils.MyToast; +import com.fisherbone.fuzhu.utils.PrefUtils; +import com.fisherbone.fuzhu.views.ConfirmDialog; +import com.fisherbone.fuzhu.views.LoadingDialog; + +import java.util.ArrayList; +import java.util.List; + +import butterknife.BindView; +import butterknife.ButterKnife; +import butterknife.OnClick; + +/** + * Created by Eren on 2017/6/23. + *

+ * 通讯录 + */ +public class PhoneActivity extends BaseActivity implements RadioGroup.OnCheckedChangeListener { + @BindView(R.id.iv_back) + ImageView mIvBack; + @BindView(R.id.tv_content_city) + TextView mTvContentCity; + @BindView(R.id.rl_city) + RelativeLayout mRlCity; + @BindView(R.id.rv_phone) + RecyclerView mRvPhone; + @BindView(R.id.but_begin) + Button mButBegin; + @BindView(R.id.clean_phone) + RelativeLayout mCleanPhone; + @BindView(R.id.open_phone) + RelativeLayout mOpenPhone; + @BindView(R.id.import_phone) + RelativeLayout mImportPhone; + @BindView(R.id.smash_phone) + RelativeLayout mSmashPhone; + @BindView(R.id.mobile) + RadioButton mMobile; + @BindView(R.id.telecom) + RadioButton mTelecom; + @BindView(R.id.unicom) + RadioButton mUnicom; + @BindView(R.id.rg_opera) + RadioGroup mRgOpera; + // private MyApplication mApp; + /** + * 自定义对话框 + */ + private ConfirmDialog mConfirmDialog; + /** + * 跳转返回时的flag + */ + private static final int REQUEST_CODE_PICK_CITY = 0; + /** + * 选中的城市 + */ + private String city; + /** + * 获取所有符合号段集合 + */ + // private List mCityPhoneList; + + private List phoneNumber = new ArrayList<>(); + // private PhoneRvAdapter mRvAdapter; + + private LoadingDialog mLoadingDialog; + + /** + * 导入通讯录 + */ + public static final int IMPORT_PHONE = 0; + /** + * 导入完成 + */ + public static final int IMPORT_PHONE_OVER = 1; + /** + * 清空号码段 + */ + public static final int CLEAN_PHONE = 2; + /** + * 清空通讯录 + */ + public static final int CLEAN_PHONE_BOOK = 3; + /** + * 通讯录清空完成 + */ + public static final int CLEAN_PHONE_OVER = 4; + + + private Handler myHandler = new Handler() { + @Override + public void handleMessage(Message msg) { + super.handleMessage(msg); + switch (msg.what) { + case IMPORT_PHONE: + //加载进度 + mLoadingDialog = new LoadingDialog(PhoneActivity.this); + mLoadingDialog.setContent("正在导入通讯录..."); + mLoadingDialog.setCancelable(false); + mLoadingDialog.show(); + break; + + case IMPORT_PHONE_OVER: + mLoadingDialog.dismiss(); + + MyToast.show(PhoneActivity.this, "导入成功"); + break; + + case CLEAN_PHONE: + MyToast.show(PhoneActivity.this, "清空成功"); + + break; + + case CLEAN_PHONE_BOOK: + //清空通讯录 + mLoadingDialog = new LoadingDialog(PhoneActivity.this); + mLoadingDialog.setContent("正在清空通讯录..."); + mLoadingDialog.setCancelable(false); + mLoadingDialog.show(); + break; + + case CLEAN_PHONE_OVER: + mLoadingDialog.dismiss(); + MyToast.show(PhoneActivity.this, "清空成功"); + break; + default: + } + } + }; + // private CityNumberBean.AutoCityBean mCityNumberBean = new CityNumberBean.AutoCityBean(); + + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_phone); + ButterKnife.bind(this); +// mApp = (MyApplication) getApplication(); +// initRg(); +// initRv(); + + + findViewById(R.id.clean_phone).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + phoneNumber.add("18133922189"); + phoneNumber.add("18133922190"); + phoneNumber.add("18133922191"); + phoneNumber.add("18133922192"); + phoneNumber.add("18133922193"); + phoneNumber.add("18133922194"); + + if (phoneNumber.size() == 0) { + MyToast.show(PhoneActivity.this, "号码不能为空"); + } else { + mConfirmDialog = new ConfirmDialog(PhoneActivity.this, new Callback() { + @Override + public void Positive() { + new Thread( new Runnable() { + @Override + public void run() { + myHandler.sendEmptyMessage(IMPORT_PHONE); + try { + testAddContactsInTransaction(); + // writeContact(); + // addContacts("ddd","18133988585"); + } catch (Exception e) { + e.printStackTrace(); + } + myHandler.sendEmptyMessage(IMPORT_PHONE_OVER); + } + }).start(); + } + @Override + public void Negative() { + mConfirmDialog.dismiss(); + } + }); + mConfirmDialog.setContent("提示:" + "\n是否导入通讯录"); + mConfirmDialog.setCancelable(true); + mConfirmDialog.show(); + } + } + }); + } + + /** + * 初始化运营商 + */ +// private void initRg() { +// if (mApp.mCityNumberList.size() > 0 && mApp.mCityNumberList != null) { //如果网络获取成功 +// mCityNumberBean = mApp.mCityNumberList.get(0); +// //从网络里获取城市 +// city = mCityNumberBean.getCity(); +// mTvContentCity.setText(city); +// +// PrefUtils.putString(PhoneActivity.this, "phone_area", city); +// +// //从网络里获取运营商 +// String operator = mCityNumberBean.getOperator(); +// Log.i("123", operator); +// PrefUtils.putString(PhoneActivity.this, "phone_opera", operator); //如果网络获取成功,设置成网络运营商 +// } else { +// PrefUtils.putString(PhoneActivity.this, "phone_opera", "移动"); //如果网络获取失败,第一次默认是移动,不设置会出现空白状态 +// PrefUtils.putString(PhoneActivity.this, "phone_area", "无锡"); +// city = "无锡"; +// mTvContentCity.setText("无锡"); +// Log.i("123", "AAAA"); +// } +// //从网络获取的运营商选中状态 +// switch (PrefUtils.getString(PhoneActivity.this, "phone_opera", "移动")) { +// case "移动": +// mMobile.setChecked(true); +// break; +// +// case "电信": +// mTelecom.setChecked(true); +// break; +// +// case "联通": +// mUnicom.setChecked(true); +// break; +// } +// mRgOpera.setOnCheckedChangeListener(this); +// } + + /** + * 初始化RecyclerView + */ +// private void initRv() { +// mRvPhone.setLayoutManager(new GridLayoutManager(this, 2)); +// mRvAdapter = new PhoneRvAdapter(PhoneActivity.this, phoneNumber); +// mRvPhone.setAdapter(mRvAdapter); +// mRvPhone.addItemDecoration(new SpaceItemDecoration(10)); +// +// } + + @OnClick({R.id.iv_back, R.id.rl_city, R.id.but_begin, R.id.clean_phone, R.id.open_phone, R.id.import_phone, R.id.smash_phone}) + public void onViewClicked(View view) { + int id = view.getId(); + if (id == R.id.iv_back) { //返回按钮 + // outAnimation(); + } else if (id == R.id.rl_city) { //选择城市 +// startActivityForResult(new Intent(PhoneActivity.this, CityPickerActivity.class), REQUEST_CODE_PICK_CITY); +// overridePendingTransition(R.anim.anim_in, R.anim.anim_out); + } else if (id == R.id.but_begin) { //生成号码段 +// phoneNumber.clear(); +// if (city == null) { // 判断有没有选择城市 +// MyToast.show(PhoneActivity.this, "未选择城市"); +// } else { +// mRvPhone.setVisibility(View.VISIBLE); +// CityPhoneDao cityPhoneDao = new CityPhoneDao(PhoneActivity.this); +// mCityPhoneList = cityPhoneDao.findAll(); +// // 循环加入集合,后四位随机生成 +// for (int i = 0; i < mCityPhoneList.size(); i++) { +// for (int j = 0; j < 5; j++) { +// String phoneNum = mCityPhoneList.get(i).getName() + (int) (Math.random() * 9000 + 1000); +// phoneNumber.add(phoneNum); +// } +// } +// //刷新适配器 +// mRvAdapter = new PhoneRvAdapter(PhoneActivity.this, phoneNumber); +// mRvPhone.setAdapter(mRvAdapter); +// } + } else if (id == R.id.clean_phone) { //导入通讯录 + phoneNumber.add("18133922190"); + phoneNumber.add("18133922188"); + + if (phoneNumber.size() == 0) { + MyToast.show(PhoneActivity.this, "号码不能为空"); + } else { + mConfirmDialog = new ConfirmDialog(PhoneActivity.this, new Callback() { + @Override + public void Positive() { + new Thread( new Runnable() { + @Override + public void run() { + myHandler.sendEmptyMessage(IMPORT_PHONE); + try { + testAddContactsInTransaction(); + } catch (Exception e) { + e.printStackTrace(); + } + myHandler.sendEmptyMessage(IMPORT_PHONE_OVER); + } + }).start(); + } + @Override + public void Negative() { + mConfirmDialog.dismiss(); + } + }); + mConfirmDialog.setContent("提示:" + "\n是否导入通讯录"); + mConfirmDialog.setCancelable(true); + mConfirmDialog.show(); + } + } else if (id == R.id.open_phone) { // 打开联系人界面 + Intent intent = new Intent(); + intent.setClassName("com.android.contacts", "com.android.contacts.activities.PeopleActivity"); + startActivity(intent); + } else if (id == R.id.import_phone) { //清空号码段 + if (phoneNumber.size() == 0) { + MyToast.show(PhoneActivity.this, "号码为空"); + } else { + mConfirmDialog = new ConfirmDialog(PhoneActivity.this, new Callback() { + @Override + public void Positive() { + phoneNumber.clear(); + mRvPhone.setVisibility(View.GONE); + myHandler.sendEmptyMessage(CLEAN_PHONE); + } + @Override + public void Negative() { + mConfirmDialog.dismiss(); + } + }); + mConfirmDialog.setContent("提示:" + "\n是否清空电话号码"); + mConfirmDialog.setCancelable(true); + mConfirmDialog.show(); + } + } else if (id == R.id.smash_phone) { //清空通讯录 + mConfirmDialog = new ConfirmDialog(PhoneActivity.this, new Callback() { + @Override + public void Positive() { + new Thread(new Runnable() { + @Override + public void run() { + myHandler.sendEmptyMessage(CLEAN_PHONE_BOOK); + clearContent(); +// cleanphone(); + myHandler.sendEmptyMessage(CLEAN_PHONE_OVER); + } + }).start(); + } + + @Override + public void Negative() { + mConfirmDialog.dismiss(); + } + }); + mConfirmDialog.setContent("提示:" + "\n是否清空通讯录"); + mConfirmDialog.setCancelable(true); + mConfirmDialog.show(); + } + } + +// @Override +// protected void onActivityResult(int requestCode, int resultCode, Intent data) { +// if (requestCode == REQUEST_CODE_PICK_CITY && resultCode == RESULT_OK) { +// if (data != null) { +// city = data.getStringExtra(CityPickerActivity.KEY_PICKED_CITY); +// mTvContentCity.setText(city); +// PrefUtils.putString(PhoneActivity.this, "phone_area", city); +// } +// } +// } +// + @Override + public void onCheckedChanged(RadioGroup group, int checkedId) { + if (checkedId == R.id.mobile) { + PrefUtils.putString(PhoneActivity.this, "phone_opera", "移动"); + } else if (checkedId == R.id.telecom) { + PrefUtils.putString(PhoneActivity.this, "phone_opera", "电信"); + } else if (checkedId == R.id.unicom) { + PrefUtils.putString(PhoneActivity.this, "phone_opera", "联通"); + } + } + + + /** + * 清空系统通信录数据 + */ + public void clearContent() { + ContentResolver cr = PhoneActivity.this.getContentResolver();// 获取 + // ContentResolver对象查询在ContentProvider里定义的共享对象 + // 根据URI对象ContactsContract.Contacts.CONTENT_URI查询所有联系人 + Cursor cursor = cr.query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null); + try { + // 如果记录不为空 + if (cursor != null) { + // 游标初始指向查询结果的第一条记录的上方,执行moveToNext函数会判断 + // 下一条记录是否存在,如果存在,指向下一条记录。否则,返回false。 + // 循环 + while (cursor.moveToNext()) { + String name = cursor + .getString(cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME)); + // 根据姓名求id + Uri uri = Uri.parse("content://com.android.contacts/raw_contacts"); + + Cursor cursor1 = cr.query(uri, new String[]{ContactsContract.Data._ID}, "display_name=?", new String[]{name}, + null); + // 除去姓名对应的号码 + if (cursor1.moveToFirst()) { + int id = cursor1.getInt(0); + cr.delete(uri, "display_name=?", new String[]{name}); + // 根据id删除data中的相应数据 + uri = Uri.parse("content://com.android.contacts/data"); + cr.delete(uri, "raw_contact_id=?", new String[]{id + ""}); + } + cursor1.close();// Cursor循环内再申请Cursor,记得将内部申请的每个Cursor都加上close + } + cursor.close(); + + } else { + Toast.makeText(PhoneActivity.this, "通讯录为空", Toast.LENGTH_SHORT).show(); + } + } catch (Exception e) { + // TODO: handle exception + } + } + +// private void cleanphone(){ +// ContentResolver cr = PhoneActivity.this.getContentResolver();// 获取 +// Cursor contactsCur = cr.query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null); +// while(contactsCur.moveToNext()){ +// //获取ID +// String rawId = contactsCur.getString(contactsCur.getColumnIndex(ContactsContract.Contacts._ID)); +// //删除 +// String where = ContactsContract.Data._ID + " =?"; +// String[] whereparams = new String[]{rawId}; +// getContentResolver().delete(ContactsContract.RawContacts.CONTENT_URI, where, whereparams); +// } +// } + + + /** + * 批量添加联系人到通讯录中 + * + * @throws Exception + */ + public void testAddContactsInTransaction() throws Exception { + ArrayList mOperations = new ArrayList<>(); + ContentResolver resolver = PhoneActivity.this.getContentResolver(); + int rawContactInsertIndex; + // 循环添加 + for (int i = 0; i < phoneNumber.size(); i++) { + Uri uri = Uri.parse("content://com.android.contacts/raw_contacts"); + rawContactInsertIndex = mOperations.size();// 这句好很重要,有了它才能给真正的实现批量添加。 + // 向raw_contact表添加一条记录 + // 此处.withValue("account_name", null)一定要加,不然会抛NullPointerException + ContentProviderOperation operation1 = ContentProviderOperation.newInsert(uri) + .withValue("account_name", null).build(); + mOperations.add(operation1); + // 向data添加数据 + uri = Uri.parse("content://com.android.contacts/data"); + // 添加姓名 + ContentProviderOperation operation2 = ContentProviderOperation.newInsert(uri) + .withValueBackReference("raw_contact_id", rawContactInsertIndex) + // withValueBackReference的第二个参数表示引用operations[0]的操作的返回id作为此值 + .withValue("mimetype", "vnd.android.cursor.item/name").withValue("data2", phoneNumber.get(i)) + .withYieldAllowed(true).build(); + mOperations.add(operation2); + // 添加手机数据 + ContentProviderOperation operation3 = ContentProviderOperation.newInsert(uri) + .withValueBackReference("raw_contact_id", rawContactInsertIndex) + .withValue("mimetype", "vnd.android.cursor.item/phone_v2").withValue("data2", "2") + .withValue("data1", phoneNumber.get(i)).withYieldAllowed(true).build(); + mOperations.add(operation3); + + } + try { + // 这里才调用的批量添加 + resolver.applyBatch("com.android.contacts", mOperations); + + } catch (RemoteException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (OperationApplicationException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + @Override + protected void onDestroy() { + super.onDestroy(); + myHandler.removeCallbacksAndMessages(null); + } + + + + /** + * 导入到通讯录 + */ + public void addContacts(String name , String tel){ + name = name+"@客户管理"; + //插入raw_contacts表,并获取_id属性 + Uri uri = Uri.parse("content://com.android.contacts/raw_contacts"); + ContentResolver resolver = getContentResolver(); + ContentValues values = new ContentValues(); + long contact_id = ContentUris.parseId(resolver.insert(uri, values)); + //插入data表 + uri = Uri.parse("content://com.android.contacts/data"); + //add Name + values.put("raw_contact_id", contact_id); + values.put(ContactsContract.Data.MIMETYPE,"vnd.android.cursor.item/name"); + values.put("data2", name); + values.put("data1", name); + resolver.insert(uri, values); + values.clear(); + //add Phone + values.put("raw_contact_id", contact_id); + values.put(ContactsContract.Data.MIMETYPE,"vnd.android.cursor.item/phone_v2"); + values.put("data2", "2"); //手机 + values.put("data1", tel); + resolver.insert(uri, values); + values.clear(); + /*//add email + values.put("raw_contact_id", contact_id); + values.put(ContactsContract.Data.MIMETYPE,"vnd.android.cursor.item/email_v2"); + values.put("data2", "2"); //单位 + values.put("data1", "xzdong@xzdong.com"); + resolver.insert(uri, values);*/ + } + + + /** + * 写入手机联系人 + */ + private void writeContact() { + String name = "test"; + String number = "13666668888"; + + //先查询要添加的号码是否已存在通讯录中, 不存在则添加. 存在则提示用户 + Uri uri = Uri.parse("content://com.android.contacts/data/phones/filter/" + number); + ContentResolver resolver = getContentResolver(); + //从raw_contact表中返回display_name + Cursor cursor = resolver.query(uri, new String[]{ContactsContract.Data.DISPLAY_NAME}, null, null, null); + if (cursor == null) + return; + + if (cursor.moveToFirst()) { + Log.i("nn", "name=" + cursor.getString(0)); + Toast.makeText(this, "存在相同号码", Toast.LENGTH_SHORT).show(); + } else { + uri = Uri.parse("content://com.android.contacts/raw_contacts"); + ContentValues values = new ContentValues(); + long contact_id = ContentUris.parseId(resolver.insert(uri, values)); + //插入data表 + uri = Uri.parse("content://com.android.contacts/data"); + //add Name + values.put("raw_contact_id", contact_id); + values.put(ContactsContract.Data.MIMETYPE, "vnd.android.cursor.item/name"); + values.put("data2", "qq"); + values.put("data1", name); + resolver.insert(uri, values); + values.clear(); + + //add Phone + values.put("raw_contact_id", contact_id); + values.put(ContactsContract.Data.MIMETYPE, "vnd.android.cursor.item/phone_v2"); + values.put("data2", "2"); //手机 + values.put("data1", number); + resolver.insert(uri, values); + values.clear(); + + //add email + values.put("raw_contact_id", contact_id); + values.put(ContactsContract.Data.MIMETYPE, "vnd.android.cursor.item/email_v2"); + values.put("data2", "1"); //邮箱 + values.put("data1", "xxxx@qq.com"); + resolver.insert(uri, values); + values.clear(); + + //add organization + values.put("raw_contact_id", contact_id); + values.put(ContactsContract.Data.MIMETYPE, "vnd.android.cursor.item/organization"); + values.put("data4", "产品经理"); //职务 + values.put("data1", "腾讯科技"); //公司 + resolver.insert(uri, values); + values.clear(); + + Toast.makeText(this, "插入号码成功", Toast.LENGTH_SHORT).show(); + } + cursor.close(); + } + +} diff --git a/app/src/main/java/com/fisherbone/fuzhu/abllib/utils/AblUtil.java b/app/src/main/java/com/fisherbone/fuzhu/abllib/utils/AblUtil.java index ec82473..0918ab6 100644 --- a/app/src/main/java/com/fisherbone/fuzhu/abllib/utils/AblUtil.java +++ b/app/src/main/java/com/fisherbone/fuzhu/abllib/utils/AblUtil.java @@ -1,249 +1,250 @@ -package com.fisherbone.fuzhu.abllib.utils; - -import android.Manifest; -import android.app.Activity; -import android.app.ActivityManager; -import android.content.Context; -import android.content.Intent; -import android.graphics.PixelFormat; -import android.net.Uri; -import android.os.Build; -import android.provider.Settings; -import android.util.Log; -import android.view.Gravity; -import android.view.View; -import android.view.ViewGroup; -import android.view.WindowManager; -import android.widget.Toast; - -import com.blankj.utilcode.util.LogUtils; -import com.blankj.utilcode.util.ToastUtils; -import com.fisherbone.fuzhu.FZConfig; -import com.fisherbone.fuzhu.abllib.AblConfig; -import com.fisherbone.fuzhu.abllib.AblService; -import com.fisherbone.fuzhu.entity.addWinEntity; -import com.fisherbone.fuzhu.utils.DeviceUtils; -import com.fisherbone.fuzhu.utils.SPUtils; -import com.lzy.okgo.OkGo; -import com.lzy.okgo.model.HttpParams; -import com.tbruyelle.rxpermissions2.RxPermissions; - -import java.security.NoSuchAlgorithmException; -import java.util.List; - -import io.reactivex.disposables.Disposable; - -import static com.blankj.utilcode.util.ActivityUtils.startActivity; - -/** - * 2019/4/21 - * 18:21 - * Levine - * wechat 1483232332 - */ -public class AblUtil { - - /** - * 添加悬浮界面 - * - * @param context - * @param view - */ - public static void addSuspensionWindowView(Context context, View view) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { - if (Settings.canDrawOverlays(context)) { - if(!addWinEntity.isopen){ - Log.e("TIAOSHI###", "temp7"); - addSuspensionView(context, view); - Log.e("TIAOSHI###", "temp8"); - addWinEntity.isopen=true; - } - - } else { - ToastUtils.showShort("请先开启允许显示在其他应用上权限"); - AblUtil.openDrawOverlaysAnth(context); - } - } else { - addSuspensionView(context, view); - } - } - - - - /** - * 添加悬浮界面 - * - * @param context - * @param view - */ - private static void addSuspensionView(Context context, View view) { - WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); - WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams(); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - layoutParams.type = WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY; - } else { - layoutParams.type = WindowManager.LayoutParams.TYPE_PHONE; - } - layoutParams.format = PixelFormat.TRANSLUCENT;// 支持透明 - layoutParams.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;// 焦点 - layoutParams.width = ViewGroup.LayoutParams.WRAP_CONTENT;//窗口的宽和高 - layoutParams.height = ViewGroup.LayoutParams.WRAP_CONTENT; - layoutParams.x = 0;//窗口位置的偏移量 - layoutParams.y = -500; - layoutParams.gravity = Gravity.LEFT; - windowManager.addView(view, layoutParams);//添加窗口 - } - - - /** - * 添加底部悬浮界面 - * - * @param context - * @param view - */ - public static void addSuWindowView(Context context, View view) { - showFloatingWindow(context, view); - } - - /** - * 添加底部悬浮界面 - * - * @param context - * @param view - */ - private static void showFloatingWindow(Context context, View view) { - if (Settings.canDrawOverlays(context)) { - // 获取WindowManager服务 - WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); - // 根据android版本设置悬浮窗类型 - WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams(); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - layoutParams.type = WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY; - layoutParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL; - } else { - layoutParams.type = WindowManager.LayoutParams.TYPE_PHONE; - } - - // layoutParams.format = PixelFormat.RGBA_8888; - layoutParams.format = PixelFormat.TRANSLUCENT;// 支持透明 - layoutParams.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;// 焦点 - //设置大小 - layoutParams.width = 300; - layoutParams.height = 100; - - //设置位置 - layoutParams.x = 0; - layoutParams.y = 688; - - // 将悬浮窗控件添加到WindowManager - windowManager.addView(view, layoutParams); - } - } - - - - /** - * 打开悬浮窗授权界面 - * - * @param context - */ - public static void openDrawOverlaysAnth(Context context) { - Intent intent = new Intent( - Settings.ACTION_MANAGE_OVERLAY_PERMISSION, - Uri.parse("package:" + context.getPackageName()) - ); - context.startActivity(intent); - } - - /** - * 检查是否是需要监听的APP包名 - * - * @param thisPackageName APP包名 - * @return - */ - public static boolean checkPackageName(String thisPackageName) { - if (AblConfig.sMonitoringPackageNames != null && AblConfig.sMonitoringPackageNames.length > 0) { - for (String packageName : AblConfig.sMonitoringPackageNames) { - if (packageName.contentEquals(thisPackageName)) { - return true; - } - } - return false; - } - return true; - } - - /** - * 打开无障碍服务设置 - */ - public static void openAccessibilitySettings() { - Intent intent = new Intent(Settings.ACTION_ACCESSIBILITY_SETTINGS); - startActivity(intent); - } - - /** - * 辅助服务是否开启 - * - * @return - */ - public static boolean isAccessibilityServiceOpen(Context context) { - ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); - List services = am.getRunningServices(Short.MAX_VALUE); - for (ActivityManager.RunningServiceInfo info : services) { - LogUtils.v(info.service.getClassName()); - if (info.service.getClassName().equals(AblService.class.getName())) { - return true; - } - } - return false; - } - - public static void getPermissions(Context context) { - - - RxPermissions rxPermissions = new RxPermissions((Activity) context); - rxPermissions.request(Manifest.permission.READ_PHONE_STATE,Manifest.permission.WRITE_EXTERNAL_STORAGE,Manifest.permission.READ_EXTERNAL_STORAGE) - .subscribe(new io.reactivex.Observer() { - @Override - public void onSubscribe(Disposable d) { - - } - - @Override - public void onNext(Boolean aBoolean) { - if (aBoolean) { - String device_id = (String) SPUtils.getSp(context, FZConfig.KEY_DEVICE_ID, ""); - Log.e("设备imei为sp:", device_id);//小米8==548ec01ca14763927b10defb19371f81 - if(device_id.equals("")) { - String imei = DeviceUtils.getIMEI(context); - try { - String s = DeviceUtils.toMD5(imei); - Log.e("设备imei为:", s);//小米8==548ec01ca14763927b10defb19371f81 - //红米7a==7228bdb66fed66c60d961e30a9dc06d3 - SPUtils.setSP(context, FZConfig.KEY_DEVICE_ID, s); - OkGo.getInstance().addCommonParams(new HttpParams("device_id", s)); - } catch (NoSuchAlgorithmException e) { - e.printStackTrace(); - } - } - //红米7a==865367043276309 - } else { - Toast.makeText(context, "获取权限失败,请重新授权",Toast.LENGTH_SHORT).show(); - } - } - - @Override - public void onError(Throwable e) { - - } - - @Override - public void onComplete() { - - } - }); - } - - - -} +package com.fisherbone.fuzhu.abllib.utils; + +import android.Manifest; +import android.app.Activity; +import android.app.ActivityManager; +import android.content.Context; +import android.content.Intent; +import android.graphics.PixelFormat; +import android.net.Uri; +import android.os.Build; +import android.provider.Settings; +import android.util.Log; +import android.view.Gravity; +import android.view.View; +import android.view.ViewGroup; +import android.view.WindowManager; +import android.widget.Toast; + +import com.blankj.utilcode.util.LogUtils; +import com.blankj.utilcode.util.ToastUtils; +import com.fisherbone.fuzhu.FZConfig; +import com.fisherbone.fuzhu.abllib.AblConfig; +import com.fisherbone.fuzhu.abllib.AblService; +import com.fisherbone.fuzhu.entity.addWinEntity; +import com.fisherbone.fuzhu.utils.DeviceUtils; +import com.fisherbone.fuzhu.utils.SPUtils; +import com.lzy.okgo.OkGo; +import com.lzy.okgo.model.HttpParams; +import com.tbruyelle.rxpermissions2.RxPermissions; + +import java.security.NoSuchAlgorithmException; +import java.util.List; + +import io.reactivex.disposables.Disposable; + +import static com.blankj.utilcode.util.ActivityUtils.startActivity; + +/** + * 2019/4/21 + * 18:21 + * Levine + * wechat 1483232332 + */ +public class AblUtil { + + /** + * 添加悬浮界面 + * + * @param context + * @param view + */ + public static void addSuspensionWindowView(Context context, View view) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + if (Settings.canDrawOverlays(context)) { + if(!addWinEntity.isopen){ + Log.e("TIAOSHI###", "temp7"); + addSuspensionView(context, view); + Log.e("TIAOSHI###", "temp8"); + addWinEntity.isopen=true; + } + + } else { + // 使用原生 Toast 替代 blankj 的 ToastUtils,避免在 Activity 未完全初始化时崩溃 + Toast.makeText(context, "请先开启允许显示在其他应用上权限", Toast.LENGTH_SHORT).show(); + AblUtil.openDrawOverlaysAnth(context); + } + } else { + addSuspensionView(context, view); + } + } + + + + /** + * 添加悬浮界面 + * + * @param context + * @param view + */ + private static void addSuspensionView(Context context, View view) { + WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); + WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams(); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + layoutParams.type = WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY; + } else { + layoutParams.type = WindowManager.LayoutParams.TYPE_PHONE; + } + layoutParams.format = PixelFormat.TRANSLUCENT;// 支持透明 + layoutParams.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;// 焦点 + layoutParams.width = ViewGroup.LayoutParams.WRAP_CONTENT;//窗口的宽和高 + layoutParams.height = ViewGroup.LayoutParams.WRAP_CONTENT; + layoutParams.x = 0;//窗口位置的偏移量 + layoutParams.y = -500; + layoutParams.gravity = Gravity.LEFT; + windowManager.addView(view, layoutParams);//添加窗口 + } + + + /** + * 添加底部悬浮界面 + * + * @param context + * @param view + */ + public static void addSuWindowView(Context context, View view) { + showFloatingWindow(context, view); + } + + /** + * 添加底部悬浮界面 + * + * @param context + * @param view + */ + private static void showFloatingWindow(Context context, View view) { + if (Settings.canDrawOverlays(context)) { + // 获取WindowManager服务 + WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); + // 根据android版本设置悬浮窗类型 + WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams(); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + layoutParams.type = WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY; + layoutParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL; + } else { + layoutParams.type = WindowManager.LayoutParams.TYPE_PHONE; + } + + // layoutParams.format = PixelFormat.RGBA_8888; + layoutParams.format = PixelFormat.TRANSLUCENT;// 支持透明 + layoutParams.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;// 焦点 + //设置大小 + layoutParams.width = 300; + layoutParams.height = 100; + + //设置位置 + layoutParams.x = 0; + layoutParams.y = 688; + + // 将悬浮窗控件添加到WindowManager + windowManager.addView(view, layoutParams); + } + } + + + + /** + * 打开悬浮窗授权界面 + * + * @param context + */ + public static void openDrawOverlaysAnth(Context context) { + Intent intent = new Intent( + Settings.ACTION_MANAGE_OVERLAY_PERMISSION, + Uri.parse("package:" + context.getPackageName()) + ); + context.startActivity(intent); + } + + /** + * 检查是否是需要监听的APP包名 + * + * @param thisPackageName APP包名 + * @return + */ + public static boolean checkPackageName(String thisPackageName) { + if (AblConfig.sMonitoringPackageNames != null && AblConfig.sMonitoringPackageNames.length > 0) { + for (String packageName : AblConfig.sMonitoringPackageNames) { + if (packageName.contentEquals(thisPackageName)) { + return true; + } + } + return false; + } + return true; + } + + /** + * 打开无障碍服务设置 + */ + public static void openAccessibilitySettings() { + Intent intent = new Intent(Settings.ACTION_ACCESSIBILITY_SETTINGS); + startActivity(intent); + } + + /** + * 辅助服务是否开启 + * + * @return + */ + public static boolean isAccessibilityServiceOpen(Context context) { + ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); + List services = am.getRunningServices(Short.MAX_VALUE); + for (ActivityManager.RunningServiceInfo info : services) { + LogUtils.v(info.service.getClassName()); + if (info.service.getClassName().equals(AblService.class.getName())) { + return true; + } + } + return false; + } + + public static void getPermissions(Context context) { + + + RxPermissions rxPermissions = new RxPermissions((Activity) context); + rxPermissions.request(Manifest.permission.READ_PHONE_STATE,Manifest.permission.WRITE_EXTERNAL_STORAGE,Manifest.permission.READ_EXTERNAL_STORAGE) + .subscribe(new io.reactivex.Observer() { + @Override + public void onSubscribe(Disposable d) { + + } + + @Override + public void onNext(Boolean aBoolean) { + if (aBoolean) { + String device_id = (String) SPUtils.getSp(context, FZConfig.KEY_DEVICE_ID, ""); + Log.e("设备imei为sp:", device_id);//小米8==548ec01ca14763927b10defb19371f81 + if(device_id.equals("")) { + String imei = DeviceUtils.getIMEI(context); + try { + String s = DeviceUtils.toMD5(imei); + Log.e("设备imei为:", s);//小米8==548ec01ca14763927b10defb19371f81 + //红米7a==7228bdb66fed66c60d961e30a9dc06d3 + SPUtils.setSP(context, FZConfig.KEY_DEVICE_ID, s); + OkGo.getInstance().addCommonParams(new HttpParams("device_id", s)); + } catch (NoSuchAlgorithmException e) { + e.printStackTrace(); + } + } + //红米7a==865367043276309 + } else { + Toast.makeText(context, "获取权限失败,请重新授权",Toast.LENGTH_SHORT).show(); + } + } + + @Override + public void onError(Throwable e) { + + } + + @Override + public void onComplete() { + + } + }); + } + + + +} diff --git a/app/src/main/java/com/fisherbone/fuzhu/activity/MainActivity.java b/app/src/main/java/com/fisherbone/fuzhu/activity/MainActivity.java index c37a591..5c32aed 100644 --- a/app/src/main/java/com/fisherbone/fuzhu/activity/MainActivity.java +++ b/app/src/main/java/com/fisherbone/fuzhu/activity/MainActivity.java @@ -1,1424 +1,1421 @@ -package com.fisherbone.fuzhu.activity; - -import android.Manifest; -import android.accessibilityservice.AccessibilityServiceInfo; -import android.annotation.SuppressLint; -import android.app.Activity; -import android.app.ActivityManager; -import android.content.ComponentName; -import android.content.Context; -import android.content.Intent; -import android.content.IntentFilter; -import android.content.ServiceConnection; -import android.content.pm.PackageManager; -import android.net.Uri; -import android.os.Build; -import android.os.Bundle; -import android.os.Handler; -import android.os.IBinder; -import android.provider.Settings; -import android.util.Log; -import android.view.View; -import android.view.accessibility.AccessibilityManager; -import android.widget.PopupWindow; -import android.widget.TextView; - -import com.blankj.utilcode.util.ToastUtils; -import com.fisherbone.fuzhu.BaseActivity; -import com.derry.wechat.debug.BuildConfig; -import com.fisherbone.fuzhu.ChangLiang; -import com.fisherbone.fuzhu.FZConfig; -import com.fisherbone.fuzhu.FuzhuApplication; -import com.fisherbone.fuzhu.InfoMessage; -import com.fisherbone.fuzhu.LiveActivity; -import com.fisherbone.fuzhu.LiveSuiJiActivity; -import com.fisherbone.fuzhu.R; -import com.fisherbone.fuzhu.TestTwoService; -import com.fisherbone.fuzhu.abllib.AblConfig; -import com.fisherbone.fuzhu.abllib.AblService; -import com.fisherbone.fuzhu.abllib.AblStepHandler; -import com.fisherbone.fuzhu.abllib.AblSteps; -import com.fisherbone.fuzhu.abllib.utils.AblUtil; -import com.fisherbone.fuzhu.abllib.utils.AblViewUtil; -import com.fisherbone.fuzhu.api.GetVesionResponseBean; -import com.fisherbone.fuzhu.api.NewsApiInterface; -import com.fisherbone.fuzhu.db.CommentBeanData; -import com.fisherbone.fuzhu.db.KeyWordBean; -import com.fisherbone.fuzhu.db.LetterBean; -import com.fisherbone.fuzhu.db.dao.CommentDao; -import com.fisherbone.fuzhu.db.dao.RedenvDao; -import com.fisherbone.fuzhu.db.dao.ZhanghaoDao; -import com.fisherbone.fuzhu.db.dao.daoutil; -import com.fisherbone.fuzhu.db.zhuanghaoBeanData; -import com.fisherbone.fuzhu.entity.FourEvent; -import com.fisherbone.fuzhu.entity.HusshuBean; -import com.fisherbone.fuzhu.entity.MessageBean; -import com.fisherbone.fuzhu.entity.PotCusBean; -import com.fisherbone.fuzhu.entity.SixEvent; -import com.fisherbone.fuzhu.entity.UrgentTaskBean; -import com.fisherbone.fuzhu.entity.dakaVideoListBean; -import com.fisherbone.fuzhu.entity.letterListBean; -import com.fisherbone.fuzhu.entity.touchTaskBean; -import com.fisherbone.fuzhu.okgonet.HttpConstants; -import com.fisherbone.fuzhu.okgonet.NetApi; -import com.fisherbone.fuzhu.quzan.AblStep1; -import com.fisherbone.fuzhu.reflect.InjectUtils; -import com.fisherbone.fuzhu.reflect.OnClickk; -import com.fisherbone.fuzhu.step.TestAblStep0; -import com.fisherbone.fuzhu.step.TestAblStep1; -import com.fisherbone.fuzhu.step.TestAblStep10; -import com.fisherbone.fuzhu.step.TestAblStep12; -import com.fisherbone.fuzhu.step.TestAblStep13; -import com.fisherbone.fuzhu.step.TestAblStep18; -import com.fisherbone.fuzhu.step.TestAblStep19; -import com.fisherbone.fuzhu.step.TestAblStep2; -import com.fisherbone.fuzhu.step.TestAblStep23; -import com.fisherbone.fuzhu.step.TestAblStep24; -import com.fisherbone.fuzhu.step.TestAblStep25; -import com.fisherbone.fuzhu.step.TestAblStep26; -import com.fisherbone.fuzhu.step.TestAblStep27; -import com.fisherbone.fuzhu.step.TestAblStep28; -import com.fisherbone.fuzhu.step.TestAblStep29; -import com.fisherbone.fuzhu.step.TestAblStep31; -import com.fisherbone.fuzhu.step.TestAblStep32; -import com.fisherbone.fuzhu.step.TestAblStep33; -import com.fisherbone.fuzhu.step.TestAblStep6; -import com.fisherbone.fuzhu.step.TestAblStep8; -import com.fisherbone.fuzhu.step.TestAblStep9; -import com.fisherbone.fuzhu.utils.JsonUtils; -import com.fisherbone.fuzhu.utils.JumpUtils; -import com.fisherbone.fuzhu.utils.Observerlife; -import com.fisherbone.fuzhu.utils.ProfileSpUtils; -import com.fisherbone.fuzhu.utils.SPUtils; -import com.fisherbone.fuzhu.utils.SystemUtil; -import com.fisherbone.fuzhu.utils.UpdateManager; -import com.fisherbone.fuzhu.utils.VersionUtils; -import com.github.gzuliyujiang.oaid.DeviceID; -import com.google.gson.Gson; -import com.gyf.immersionbar.ImmersionBar; -import com.jeremyliao.liveeventbus.LiveEventBus; -import com.lzy.okgo.OkGo; -import com.lzy.okgo.model.HttpParams; -import com.lzy.okgo.model.Response; -import com.xiangxue.arouter_annotation.ARouter; -import com.xiangxue.arouter_api.RouterManager; -import com.xiangxue.common.network.TecentNetworkApi; -import com.xiangxue.common.network.observer.BaseObserver; - -import org.json.JSONException; -import org.json.JSONObject; - -import java.util.ArrayList; -import java.util.List; -import java.util.concurrent.TimeUnit; - -import de.greenrobot.event.EventBus; -import io.reactivex.Flowable; -import io.reactivex.Observable; -import io.reactivex.Observer; -import io.reactivex.android.schedulers.AndroidSchedulers; -import io.reactivex.disposables.Disposable; -import io.reactivex.functions.Action; -import io.reactivex.functions.Consumer; - - -/** - * dddddd - */ -@ARouter(path = "/app/MainActivity") -public class MainActivity extends BaseActivity implements InfoMessage { - private TestTwoService service = null; - private boolean isBind = false; - private UpdateManager mUpdateManager;//版本更新 - private CommentDao commentDao; - private ControlWindow controlWindow; - private RedenvDao redenvDao; - private StartTask startTask; - private PopupWindow mPopCut; - - private ServiceConnection conn = new ServiceConnection() { - @Override - public void onServiceConnected(ComponentName name, IBinder binder) { - isBind = true; - TestTwoService.MyBinder myBinder = (TestTwoService.MyBinder) binder; - service = myBinder.getService(); - Log.i("TIAOSHI###--Kathy", "ActivityA - onServiceConnected"); - String isactivation = (String) SPUtils.getSp(MainActivity.this, FZConfig.IS_ACTIVATION, ""); - if (VALUE_ZERO.equals(isactivation)) { - fivelunxun(); - if (VALUE_ZERO.equals(isactivation)) { - Log.e("TIAOSHI###--Kathy", "设备已激活"); - tvStutas.setText("设备在线"); - } - Log.e("TIAOSHI###--Kathy", "轮询请求"); - - } else { - if ("1".equals(isactivation)) { - Log.e("TIAOSHI###--Kathy", "设备未激活"); - } - Log.e("TIAOSHI###--Kathy", "未轮询请求" + "设备是否已激活==" + isactivation + "云端本地==" + ChangLiang.control_status);//01为激活并且云端开启 - } - } - - @Override - public void onServiceDisconnected(ComponentName name) { - isBind = false; - Log.i("TIAOSHI###--", "ActivityA - onServiceDisconnected"); - } - }; - private Disposable mdDisposable; - final private int REQUEST_CODE_ASK_PERMISSIONS = 123; - private TextView tvShowInfo, tvStutas,yunduanStu,tv_ifcunzai; - private ZhanghaoDao zhanghaoDao; - - @SuppressLint("ObsoleteSdkInt") - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_main); - if (BuildConfig.isRelease) { - Log.d(TAG, "onCreate: 当前是:集成化 线上环境,以app壳为主导运行的方式"); - // Toast.makeText(this, "当前是:集成化 线上环境,以app壳为主导运行的方式", Toast.LENGTH_SHORT).show(); - } else { - Log.d(TAG, "onCreate: 当前是:组件化 测试环境,所有的子模块都可以独立运行"); - // Toast.makeText(this, "当前是:组件化 测试环境,所有的子模块都可以独立运行", Toast.LENGTH_SHORT).show(); - } - ImmersionBar.with(this).statusBarDarkFont(true).init();//设置状态栏颜色 - IntentFilter intentFilter = new IntentFilter(); - intentFilter.addAction(Intent.ACTION_TIME_TICK); - String systemModel = SystemUtil.getSystemModel(); - Log.e("手机型号", systemModel); - if ("M2103K19C".equals(systemModel)) { - ChangLiang.phonetype = "2"; - } else if ("Redmi 7A".equals(systemModel)) { - ChangLiang.phonetype = "0"; - } else if ("M2007J22C".equals(systemModel)) { - ChangLiang.phonetype = "3"; - } else { - ChangLiang.phonetype = "1"; - } - //新修改的获取唯一标识方法 -// String clientId = DeviceID.getClientIdMD5(); -// Log.e("TIAOSHI###", "设备唯一标识"+clientId); -// SPUtils.setSP(this, FZConfig.KEY_DEVICE_ID, clientId); -// OkGo.getInstance().addCommonParams(new HttpParams("device_id", clientId)); - AblUtil.getPermissions(MainActivity.this); - - //adb shell pm grant com.fisherbone.fuzhu android.permission.WRITE_SECURE_SETTINGS - Settings.Secure.putString(getContentResolver(), Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES, "com.fisherbone.fuzhu/com.fisherbone.fuzhu.abllib.AblService"); - Settings.Secure.putString(getContentResolver(), Settings.Secure.ACCESSIBILITY_ENABLED, "1");//1表示开启 - if (AblUtil.isAccessibilityServiceOpen(MainActivity.this)) { - // Log.e("TIAOSHI###", "无障碍服务正常"); - ToastUtils.showShort( "无障碍服务正常"); - }else { - ToastUtils.showShort( "无障碍服务异常"); - Settings.Secure.putString(getContentResolver(), Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES, "com.fisherbone.fuzhu/com.fisherbone.fuzhu.abllib.AblService"); - Settings.Secure.putString(getContentResolver(), Settings.Secure.ACCESSIBILITY_ENABLED, "0");//1表示开启 - } - - ChangLiang.task_id = "";//当前执行任务id - ChangLiang.id = "";//当前执行任务功能id - ChangLiang.task_type = "";//当前执行任务类型 - ChangLiang.isstart = "0"; - ChangLiang.isstarttwo = "0"; - controlWindow = new ControlWindow(MainActivity.this); - LiveEventBus.get("some_key", String.class).observe(this, new Observerlife() { - @Override - public void onChanged(Object o) { - controlWindow.showRunInfo((String) o); - } - }); - LiveEventBus.get("run_time", String.class).observe(this, new Observerlife() { - @Override - public void onChanged(Object o) { - controlWindow.showRunTimeInfo((String) o); - } - }); - LiveEventBus.get("success", String.class).observe(this, new Observerlife() { - @Override - public void onChanged(Object o) { - Log.e("TIAOSHI###", "getcontrolStatus==执行了"); - getcontrolStatus(); - } - }); - LiveEventBus.get("ablservice", String.class).observe(this, new Observerlife() { - @Override - public void onChanged(Object o) { - tvShowInfo.setText((String)o); - if("无障碍服务被销毁".equals((String)o)){ - againStart("0"); - } - } - }); - LiveEventBus.get("jiaguantime", String.class).observe(this, new Observerlife() { - @Override - public void onChanged(Object o) { - Log.w("TIAOSHI###运行时长", (String) o); - //开启运行倒计时 - daojishitwo(Integer.parseInt((String) o)); - } - }); - LiveEventBus.get("closedtime", String.class).observe(this, new Observerlife() { - @Override - public void onChanged(Object o) { - if(mdDisposable!=null) { - mdDisposable.dispose(); - } - } - }); - LiveEventBus.get("runningstate", String.class).observe(this, new Observerlife() { - @Override - public void onChanged(Object o) { - againStart((String) o); - } - }); - LiveEventBus.get("yunkong", String.class).observe(this, new Observerlife() { - @Override - public void onChanged(Object o) { - if("open".equals((String) o)){ - }else { - closeService(); - } - } - }); - LiveEventBus.get("task_runtime", MessageBean.class).observe(this, new Observerlife() { - @Override - public void onChanged(Object o) { - MessageBean mesg = (MessageBean) o; - taskDaojishi(mesg.getRuntime(),mesg); - } - }); - InjectUtils.injectEvent(this); - requestVersion(); - - zhanghaoDao = new ZhanghaoDao(MainActivity.this); - commentDao = new CommentDao(MainActivity.this); - redenvDao = new RedenvDao(MainActivity.this); - startTask = new StartTask(MainActivity.this, controlWindow, zhanghaoDao); - madeData(); - EventBus.getDefault().register(this); - displayBriefMemory(); - //设置公共参数 - String device_id = (String) SPUtils.getSp(MainActivity.this, FZConfig.KEY_DEVICE_ID, ""); - if (!"".equals(device_id)) { - OkGo.getInstance().addCommonParams(new HttpParams("device_id", device_id)); - } - checkDevice(); - Log.e("TIAOSHI###", "getcontrolStatus==执行了2"); - getcontrolStatus(); - renewType("1"); - new AblViewUtil().rigist(MainActivity.this); - AblConfig.Builder() - .setLogTag("123456")//logtag,不设置默认是abllib - .setStepMsgDelayMillis(2000)//步骤延迟时间 - .setFindViewMillisInFuture(10000)//寻找界面超时时间 - .setFindViewCountDownInterval(200)//寻找界面间隔时间 - .build().init(); - AblStepHandler.getInstance().initStepClass(new TestAblStep0(), new TestAblStep1(), new TestAblStep2(), new TestAblStep8(), new TestAblStep9(), new TestAblStep10(), new TestAblStep12(), new TestAblStep13(), new TestAblStep18(), new TestAblStep19(), new TestAblStep23(), new TestAblStep25(), new TestAblStep26(), new TestAblStep27(), new TestAblStep28(), new TestAblStep29(), new TestAblStep31(), new TestAblStep32(), new TestAblStep33()); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { - int hasWriteContactsPermission = checkSelfPermission(Manifest.permission.READ_CONTACTS); - if (hasWriteContactsPermission != PackageManager.PERMISSION_GRANTED) { - requestPermissions(new String[]{Manifest.permission.WRITE_CONTACTS}, REQUEST_CODE_ASK_PERMISSIONS); - } - } - tvShowInfo = findViewById(R.id.tv_showinfo); - tvStutas = findViewById(R.id.tv_stutas); - yunduanStu = findViewById(R.id.tv_yunduanstutas); - tv_ifcunzai = findViewById(R.id.tv_ifcunzai); - - findViewById( R.id.rl_bottom_02).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - JumpUtils.gotoActivity(MainActivity.this, ScrSetActivity.class, false, "", ""); - } - }); - findViewById( R.id.rl_bottom_04).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - JumpUtils.gotoActivity(MainActivity.this, SettingActivity.class, false, "", ""); - } - }); - findViewById( R.id.rl_bottom_03).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { -// @SuppressLint("InflateParams") View v = getLayoutInflater().inflate(com.derry.wechat.R.layout.layout_pop,null); -// TextView viewById = v.findViewById(R.id.wechat_cut); -// viewById.setOnClickListener(new View.OnClickListener() { -// @Override -// public void onClick(View view) { -// Intent intent = new Intent(MainActivity.this, WeChatPlate.class); -// intent.putExtra("name", "Derry"); -// startActivity(intent); -// } -// }); -// mPopCut = new PopupWindow(v, ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.WRAP_CONTENT); -// mPopCut.setTouchable(true); -// mPopCut.setFocusable(true); -// mPopCut.showAtLocation(getWindow().getDecorView(), Gravity.BOTTOM,0,0); - } - }); - - } - - @OnClickk({R.id.rl_05, R.id.rl_12, R.id.rl_011, R.id.rl_10, R.id.rl_09, R.id.rl_08, R.id.rl_07, R.id.rl_06, R.id.rl_04, R.id.rl_03, R.id.rl_01, R.id.rl_02 ,R.id.rl_16}) - public void click(View view) { - if(ProfileSpUtils.getInstance().getSetBean().isRedswitchone()){ - ToastUtils.showShort( "请关闭云端控制"); - return; - } - switch (view.getId()) { - case R.id.rl_05: - JumpUtils.gotoActivity(MainActivity.this, DavActivity.class, false, "", ""); - break; - case R.id.rl_12: - JumpUtils.gotoActivity(MainActivity.this, HongBaoActivity.class, false, "", ""); - break; - case R.id.rl_011: - JumpUtils.gotoActivity(MainActivity.this, AppointActivity.class, false, "", ""); - break; - case R.id.rl_10: - JumpUtils.gotoActivity(MainActivity.this, LiveSuiJiActivity.class, false, "", ""); - break; - case R.id.rl_09: - JumpUtils.gotoActivity(MainActivity.this, LiveActivity.class, false, "", ""); - break; - case R.id.rl_08: - JumpUtils.gotoActivity(MainActivity.this, noticeActivity.class, false, "", ""); - break; - case R.id.rl_07: - JumpUtils.gotoActivity(MainActivity.this, KeyWordActivity.class, false, "", ""); - break; - case R.id.rl_06: - JumpUtils.gotoActivity(MainActivity.this, InteraActivity.class, false, "", ""); - break; - case R.id.rl_04: - JumpUtils.gotoActivity(MainActivity.this, CancleFollowActivity.class, false, "", ""); - break; - case R.id.rl_03: - JumpUtils.gotoActivity(MainActivity.this, KeyWordActivity.class, false, "", ""); - break; - case R.id.rl_01: - JumpUtils.gotoActivity(MainActivity.this, RecFollowActivity.class, false, "", ""); - // JumpUtils.gotoActivity(MainActivity.this, MainActivityy.class, false, "", ""); - break; - case R.id.rl_16: - JumpUtils.gotoActivity(MainActivity.this,CancelThumbUpActivity.class, false, "", ""); - break; - case R.id.rl_02: - // service.stopSelf(); - - // CrashReport.testJavaCrash(); - - // 使用我们自己写的路由 跳转交互 -// RouterManager.getInstance() -// .build("/order/Order_MainActivity") -// .withString("name", "杜子腾") -// .navigation(this); // 组件和组件通信 - - RouterManager.getInstance() - .build("/wechat/W_MainActivity") - .withString("name", "杜子腾") - .navigation(this); // 组件和组件通信 - break; - default: - } - } - - private void closeService() { - //单击了“unbindService”按钮 - if (isBind) { - Log.i("TIAOSHI###--Kathy", - "----------------------------------------------------------------------"); - Log.i("TIAOSHI###--Kathy", "ActivityA 执行 unbindService"); - tvStutas.setText(""); - unbindService(conn); - } - } - - /** - * 模拟结束任务 - * - * @param a - */ - private void daojishitwo(final int a) { - //启动计时器 - //从0开始发射11个数字为:0-10依次输出,延时0s执行,每1s发射一次。 - mdDisposable= Flowable.intervalRange(0, a + 1, 0, 1, TimeUnit.SECONDS) - .observeOn(AndroidSchedulers.mainThread()) - .doOnNext(new Consumer() { - @Override - public void accept(Long aLong) throws Exception { - long b = a - aLong; - Log.w("TIAOSHI###运行剩余时长", b + ""); - } - }) - .doOnComplete(new Action() { - @Override - public void run() throws Exception { - Log.e("TIAOSHI###", "运行时间已到,停止自动加关"); - ToastUtils.showLong("运行时间已到,停止自动加关"); - AblStepHandler.getInstance().setStop(true); - AblViewUtil.onMessage("停止"); - - } - }) - .subscribe(); - } - - - /** - * @param - * @return - * @description 接收tost通知栏消息 - */ - public void onEvent(SixEvent event) { - if (null != event) { - String msg = event.getMsg(); - if ("success".equals(msg)) { - String toastMsg = event.getToastMsg(); - if (toastMsg.contains("关注太快了,先休息一下")) { - AblStepHandler.getInstance().setStop(true); - AblViewUtil.onMessage("停止"); - }else if (toastMsg.contains("下线提醒")) { - UpdateTuoguan("1"); - } else if (toastMsg.contains("账号下线")) { - UpdateTuoguan("1"); - }else if(toastMsg.contains("已切换到")){ - UpdateTuoguan("0"); - } - else if(toastMsg.contains("由于该用户隐私设置,粉丝列表不可见")){ - AblStepHandler.getInstance().setStop(true); - AblViewUtil.onMessage("停止"); - } - } - } - } - - public void onEventMainThread(PotCusBean potCusBean) { - if ("1".equals(potCusBean.getSelect())) { - if (potCusBean.getBigshotdatas().size() > 0) { - execute("71"); - } - } - if (VALUE_TWO.equals(potCusBean.getSelect())) { - if (potCusBean.getKeyworddatas().size() > 0) { - execute("8"); - } - } - } - - public void onEventMainThread(FourEvent event) { - if (null != event) { - String msg = event.getMsg(); - if ("success".equals(msg)) { - String type = event.getType(); - switch (type) { - case "1": - List CommentBeanDatas = CommentDao.queryInByCustom("type", "1"); - if (CommentBeanDatas.size() > 0) { - execute("1"); - } else { - com.fisherbone.fuzhu.utils.ToastUtils.showToast(MainActivity.this, "请先添加评论话术"); - } - break; - case "2": - execute("2"); - break; - case "3": - execute("51"); - break; - case "4": - execute("61"); - break; - case "5": - execute("9"); - break; - case "6": - execute("6"); - break; - case "7": - execute("12"); - break; - case "8": - execute("13"); - break; - case "9": - execute("14"); - break; - case "10": - execute("5"); - break; - case "11": - execute("16"); - default: - } - } - } - } - - private void execute(String s) { - if (AblUtil.isAccessibilityServiceOpen(MainActivity.this)) { - AblUtil.addSuspensionWindowView(MainActivity.this, controlWindow.initWindowView(s)); - } else { - ToastUtils.showShort("点到了"); - ToastUtils.showShort("请先开启辅助服务"); - AblUtil.openAccessibilitySettings(); - } - } - - private void openService() { - //单击了“bindService”按钮 - Intent intent = new Intent(MainActivity.this, TestTwoService.class); - // intent.putExtra("from", "ActivityA"); - Log.i("TIAOSHI###--Kathy", "----------------------------------------------------------------------"); - Log.i("TIAOSHI###--Kathy", "ActivityA 执行 bindService"); - bindService(intent, conn, BIND_AUTO_CREATE); - } - - private void fivelunxun() { - Observable.interval(2, 10, TimeUnit.SECONDS) - .doOnNext(new Consumer() { - @Override - public void accept(Long integer) throws Exception { - Log.w("TIAOSHI###", "第 " + integer + " 次轮询"); - Log.w("TIAOSHI###", "第查看参数1 " + ChangLiang.control_status + "======"+ProfileSpUtils.getInstance().getSetBean().isRedswitchone()); - if (VALUE_ONE.equals(ChangLiang.control_status)&&ProfileSpUtils.getInstance().getSetBean().isRedswitchone()) { - getUrgentTask(); - } - if (AblUtil.isAccessibilityServiceOpen(MainActivity.this)) { - // Log.e("TIAOSHI###", "无障碍服务正常"); - } else { - Log.e("TIAOSHI###", "无障碍服务异常"); - Settings.Secure.putString(getContentResolver(), - Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES, "com.fisherbone.fuzhu/com.fisherbone.fuzhu.abllib.AblService"); - Settings.Secure.putString(getContentResolver(), - Settings.Secure.ACCESSIBILITY_ENABLED, "0");//1表示开启 - againStart("0"); - } - boolean destroy = isDestroy(MainActivity.this); - if(destroy) { - Log.e("TIAOSHI###", "MainActivity已经被销毁"); - closeService(); - Settings.Secure.putString(getContentResolver(), Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES, "com.fisherbone.fuzhu/com.fisherbone.fuzhu.abllib.AblService"); - Settings.Secure.putString(getContentResolver(), Settings.Secure.ACCESSIBILITY_ENABLED, "0");//1表示开启 - } - } - }).subscribe(new Observer() { - @Override - public void onSubscribe(Disposable d) { - - } - - @Override - public void onNext(Long value) { - - } - - @Override - public void onError(Throwable e) { - Log.d(TAG, "对Error事件作出响应"); - } - - @Override - public void onComplete() { - Log.d(TAG, "对Complete事件作出响应"); - } - }); - } - /** - * 判断Activity是否Destroy - * @param mActivity - * @return true:已销毁 - */ - public static boolean isDestroy(Activity mActivity) { - if (mActivity == null || - mActivity.isFinishing() || - (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1 && mActivity.isDestroyed())) { - return true; - } else { - return false; - } - } - - /** - * 1代表正常 - * 0代表异常 - * @param str - */ - private void againStart(String str) { - final HttpParams paramsPost = new HttpParams(); - paramsPost.put("task_status", str); - paramsPost.put("task_id", ChangLiang.task_id); - paramsPost.put("task_type", ChangLiang.task_type); - new NetApi().getPostData(paramsPost, HttpConstants.URi_Device_Appscanlogin_againStart).subscribe(new com.fisherbone.fuzhu.okgonet.Observer() { - @Override - public void onNext(Response response) { - String body = (String) response.body(); - Log.e("需通知后台重新启动", body); - } - - @Override - public void onError(Exception e) { - e.printStackTrace(); - - } - }); - } - - private void getUrgentTask() { - final HttpParams paramsPost = new HttpParams(); - paramsPost.put("short_id", ChangLiang.short_id); - paramsPost.put("task_id", ChangLiang.task_id); - paramsPost.put("id", ChangLiang.id); - paramsPost.put("task_type", ChangLiang.task_type); - //是否有当前有执行任务,有则传下面4个参数,无则不需用传。 - new NetApi().getPostData(paramsPost, HttpConstants.URi_device_Appscanlogin_urgentTask).subscribe(new com.fisherbone.fuzhu.okgonet.Observer() { - @Override - public void onNext(Response response) { - String body = (String) response.body(); - if (AblUtil.isAccessibilityServiceOpen(MainActivity.this)) { - startTask.startTask(body); - } - } - - @Override - public void onError(Exception e) { - e.printStackTrace(); - } - }); - } - - //倒计时2秒开启服务 - private void daojishifirst(final int a) { - //启动计时器 - //从0开始发射11个数字为:0-10依次输出,延时0s执行,每1s发射一次。 - mdDisposable = Flowable.intervalRange(0, a + 1, 0, 1, TimeUnit.SECONDS) - .observeOn(AndroidSchedulers.mainThread()) - .doOnNext(new Consumer() { - @Override - public void accept(Long aLong) throws Exception { - long b = a - aLong; - Log.w("TIAOSHI###", b + ""); - } - }) - .doOnComplete(new Action() { - @Override - public void run() throws Exception { - openService(); - Log.e("TIAOSHI###", "轮询开启服务"); - } - }) - .subscribe(); - } - - - @Override - public void mesagesuccess(String str) { - if ("停止".equals(str)) { - if(mdDisposable!=null) { - mdDisposable.dispose(); - } - AblStepHandler.getInstance().setStop(true); - FinishTask(); - } - } - - /** - * 撞号任务完成的通知 - * - * @param str - */ - @Override - public void mesagezhuang(String str) { - if ("停止".equals(str)) { - if(mdDisposable!=null) { - mdDisposable.dispose(); - } - AblStepHandler.getInstance().setStop(true); - touchResult(); - controlWindow.stutas(true); - } - } - - /** - * 粉丝通知停止 - * - * @param str - */ - @Override - public void potgegin(String str) { - if ("停止".equals(str)) { - if(mdDisposable!=null) { - mdDisposable.dispose(); - } - AblStepHandler.getInstance().setStop(true); - controlWindow.stutas(true); - controlWindow.closedWin(); - AblViewUtil.mySleep(2); -// AblStepHandler.getInstance().setStop(false); -// Log.e("step###", "开始执行关闭抖音程序"); -// AblStepHandler.sendMsg(192); - - FinishTask(); - } - } - - @Override - public void onDestroy() { - super.onDestroy(); - Settings.Secure.putString(getContentResolver(), Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES, "com.fisherbone.fuzhu/com.fisherbone.fuzhu.abllib.AblService"); - Settings.Secure.putString(getContentResolver(), Settings.Secure.ACCESSIBILITY_ENABLED, "0");//1表示开启 - - if(mdDisposable!=null) { - mdDisposable.dispose(); - } - EventBus.getDefault().unregister(this); - closeService(); - - Log.e("TIAOSHI###", "执行了onDestroy"); - killAppProcess(); - } - - /** - * 获取设备控制状态 -- 云端还是本地 - */ - private void getcontrolStatus() { - final HttpParams paramsPost = new HttpParams(); - new NetApi().getPostData(paramsPost, HttpConstants.URi_device_Appoperate_controlStatus).subscribe(new com.fisherbone.fuzhu.okgonet.Observer() { - @Override - public void onNext(Response response) { - String body = (String) response.body(); - try { - JSONObject jsonObject = new JSONObject(body); - String msg = jsonObject.getString("msg"); - String success = jsonObject.getString("success"); - String control_status = jsonObject.getString("control_status"); - //{"success":0,"msg":"调取蜂狐成功"} - if (VALUE_ZERO.equals(success)) { - ChangLiang.control_status = control_status; - if (VALUE_ONE.equals(control_status)) { - Log.e("TIAOSHI###", "倒计时开启服务"); - if(ProfileSpUtils.getInstance().getSetBean().isRedswitchone()) { - Log.i("Kathy","云控状态 " + ProfileSpUtils.getInstance().getSetBean().isRedswitchone()); - Log.i("Kathy","倒计时开始执行了"); - daojishifirst(2); - } - } - } - - } catch (JSONException e) { - e.printStackTrace(); - } - } - - @Override - public void onError(Exception e) { - e.printStackTrace(); - } - }); - } - - /** - * app每执行完一个任务成功后调取接口 - */ - private void FinishTask() { - final HttpParams paramsPost = new HttpParams(); - paramsPost.put("short_id", ChangLiang.short_id);// 拿到的抖音id - paramsPost.put("task_id", ChangLiang.task_id);//拿到的任务id - paramsPost.put("id", ChangLiang.id);//功能id - paramsPost.put("task_type", ChangLiang.task_type);//拿到的任务类型 1:代表账号登录 2:停任务 3:代表紧急任务,4:代表固定任务 - - new NetApi().getPostData(paramsPost, HttpConstants.URi_device_Appscanlogin_FinishTask).subscribe(new com.fisherbone.fuzhu.okgonet.Observer() { - @Override - public void onNext(Response response) { - String body = (String) response.body(); - try { - JSONObject jsonObject = new JSONObject(body); - String msg = jsonObject.getString("msg"); - String success = jsonObject.getString("success"); - if (VALUE_ZERO.equals(success)) { - Log.e("TIAOSHI###", "每执行完一个任务成功后调取接口==" + msg); - Log.e("TIAOSHI###", "任务执行完毕,领取新的任务。"); - ChangLiang.isstarttwo = "0"; - ChangLiang.isstart = "0"; - fixedTask(); - } - } catch (JSONException e) { - e.printStackTrace(); - } - } - - @Override - public void onError(Exception e) { - e.printStackTrace(); - } - }); - } - - /** - * 撞号返回结果[{'id':'1','phone':'15029224225','record_id':'1'},{'id':'2','phone':'14712354698','record_id':'1'}] - */ - private void touchResult() { - String zhuanghao = ""; - ZhanghaoDao instance1 = daoutil.getInstance(FuzhuApplication.getContext()); - List zhuanghaoBeanData = instance1.queryByCustom("isjiaguan", "1"); - if (zhuanghaoBeanData.size() > 0) { - Gson gson = new Gson(); - zhuanghao = gson.toJson(zhuanghaoBeanData); - Log.e("TIAOSHI###", "撞号返回结果==" + zhuanghao); - } else { - zhuanghao = ""; - Log.e("TIAOSHI###", "撞号返回结果==" + zhuanghao); - } - final HttpParams paramsPost = new HttpParams(); - paramsPost.put("short_id", ChangLiang.short_id);// 拿到的抖音id - paramsPost.put("zhuanghao", zhuanghao); - - new NetApi().getPostData(paramsPost, HttpConstants.URi_device_Appscanlogin_touchResult).subscribe(new com.fisherbone.fuzhu.okgonet.Observer() { - @Override - public void onNext(Response response) { - String body = (String) response.body(); - try { - JSONObject jsonObject = new JSONObject(body); - String msg = jsonObject.getString("msg"); - //success=0,表示撞号继续,同时返回需要请求的数量,去获取撞号账号去请求数据 - //success=-2,表示撞号结束,可以去请求其他任务 - String success = jsonObject.getString("success"); - - if (VALUE_ZERO.equals(success)) { - String data = jsonObject.getString("data"); - com.fisherbone.fuzhu.utils.ToastUtils.showToast(MainActivity.this, msg); - Log.e("TIAOSHI###", "撞号结果==" + msg); - touchTask(data, new Zhuanhaoretren() { - @Override - public void call(touchTaskBean urgentTaskBean, String success) { - if (VALUE_ZERO.equals(success)) { - daojishifour(20, "3"); - } else if ("-2".equals(success)) { - Log.e("TIAOSHI###", "获取撞号账号==" + urgentTaskBean.getMsg()); - //表示撞号结束,可以去请求其他任务 - FinishTask(); - } - } - }); - - } else if ("-1".equals(success)) { - String data = jsonObject.getString("data"); - Log.e("TIAOSHI###", "撞号结果==" + msg); - touchTask(data, new Zhuanhaoretren() { - @Override - public void call(touchTaskBean urgentTaskBean, String success) { - if (VALUE_ZERO.equals(success)) { - daojishifour(20, "3"); - } else if ("-2".equals(success)) { - Log.e("TIAOSHI###", "获取撞号账号==" + urgentTaskBean.getMsg()); - //表示撞号结束,可以去请求其他任务 - FinishTask(); - } - } - }); - daojishifour(20, "3"); - } else { - com.fisherbone.fuzhu.utils.ToastUtils.showToast(MainActivity.this, msg); - Log.e("TIAOSHI###", "撞号结果==" + msg); - //表示撞号结束,可以去请求其他任务 - FinishTask(); - } - } catch (JSONException e) { - e.printStackTrace(); - } - } - - @Override - public void onError(Exception e) { - e.printStackTrace(); - } - }); - } - - /** - * 固定任务(当前任务执行完请求下一个任务接口) - * 此处有一个核心逻辑,最后三个参数,传值分两种情况,一、如果来的紧急任务是一个停任务,那么就传空。二、如果来的紧急任务是一个其它任务。那么就传值 - */ - private void fixedTask() { - if (VALUE_TWO.equals(ChangLiang.task_type)) { - Log.e("TIAOSHI###", "执行了传值分两种情况第一种情况"); - final HttpParams paramsPost = new HttpParams(); - paramsPost.put("short_id", ChangLiang.short_id);// 拿到的抖音id - paramsPost.put("task_id", ChangLiang.task_id);//拿到的任务id - paramsPost.put("id", ChangLiang.id);//功能id - paramsPost.put("task_type", ChangLiang.task_type);//拿到的任务类型 1:代表账号登录 2:停任务 3:代表紧急任务,4:代表固定任务 - paramsPost.put("urgent_short_id", "");//未处理完成紧急任务抖音id - paramsPost.put("urgent_task_id", "");//未处理完成紧急任务id - paramsPost.put("urgent_id", "");// 未处理完成紧急功能id - paramsPost.put("fixed_short_id", "");//未处理完成固定任务抖音id - paramsPost.put("fixed_task_id", "");//未处理完成固定任务id - paramsPost.put("fixed_id", "");//未处理完成固定功能id - new NetApi().getPostData(paramsPost, HttpConstants.URi_device_Appscanlogin_fixedTask).subscribe(new com.fisherbone.fuzhu.okgonet.Observer() { - @Override - public void onNext(Response response) { - String body = (String) response.body(); - UrgentTaskBean urgentTaskBean = JsonUtils.fromJson(body, UrgentTaskBean.class); - int success = urgentTaskBean.getSuccess(); - if (success == 0) { - //初始化5秒的接口参数 - ChangLiang.task_id = "";//当前执行任务id - ChangLiang.id = "";//当前执行任务功能id - ChangLiang.task_type = "";//当前执行任务类型 - } - startTask.startTask(body); - } - - @Override - public void onError(Exception e) { - e.printStackTrace(); - } - }); - } else { - final HttpParams paramsPost = new HttpParams(); - paramsPost.put("short_id", ChangLiang.short_id);// 拿到的抖音id - paramsPost.put("task_id", ChangLiang.task_id);//拿到的任务id - paramsPost.put("id", ChangLiang.id);//功能id - paramsPost.put("task_type", ChangLiang.task_type);//拿到的任务类型 1:代表账号登录 2:停任务 3:代表紧急任务,4:代表固定任务 - paramsPost.put("urgent_short_id", ChangLiang.short_id_jf);//未处理完成紧急任务抖音id - paramsPost.put("urgent_task_id", ChangLiang.task_id_jf);//未处理完成紧急任务id - paramsPost.put("urgent_id", ChangLiang.id_jf);// 未处理完成紧急功能id - paramsPost.put("fixed_short_id", ChangLiang.short_id_f);//未处理完成固定任务抖音id - paramsPost.put("fixed_task_id", ChangLiang.task_id_f);//未处理完成固定任务id - paramsPost.put("fixed_id", ChangLiang.id_f);//未处理完成固定功能id - new NetApi().getPostData(paramsPost, HttpConstants.URi_device_Appscanlogin_fixedTask).subscribe(new com.fisherbone.fuzhu.okgonet.Observer() { - @Override - public void onNext(Response response) { - String body = (String) response.body(); - startTask.startTask(body); - } - - @Override - public void onError(Exception e) { - e.printStackTrace(); - } - }); - } - } - - /** - * 倒计时开始执行任务 - * - * @param a - */ - private void daojishifour(final int a, String func_type) { - //启动计时器 - //从0开始发射11个数字为:0-10依次输出,延时0s执行,每1s发射一次。 - mdDisposable = Flowable.intervalRange(0, a + 1, 0, 1, TimeUnit.SECONDS) - .observeOn(AndroidSchedulers.mainThread()) - .doOnNext(new Consumer() { - @Override - public void accept(Long aLong) throws Exception { - long b = a - aLong; - Log.w("TIAOSHI###", b + ""); - } - }) - .doOnComplete(new Action() { - @Override - public void run() throws Exception { - //先判断无障碍是否开启 - Log.e("TIAOSHI###", "temp3"); - // ControlWindow controlWindow = new ControlWindow(MainActivity.this); - AblUtil.addSuspensionWindowView(MainActivity.this, controlWindow.initWindowView(func_type)); - } - }) - .subscribe(); - } - - /** - * 获取撞号账号 - * 如果{"success":-2,"msg":"暂无需要撞号的账号"}停止撞号任务 - */ - private void touchTask(String touch_num, Zhuanhaoretren zhuanhaoretren) { - final HttpParams paramsPost = new HttpParams(); - paramsPost.put("short_id", ChangLiang.short_id);// 拿到的抖音id - paramsPost.put("touch_num", touch_num);//功能id - new NetApi().getPostData(paramsPost, HttpConstants.URi_device_Appscanlogin_touchTask).subscribe(new com.fisherbone.fuzhu.okgonet.Observer() { - @Override - public void onNext(Response response) { - String body = (String) response.body(); - touchTaskBean urgentTaskBean = JsonUtils.fromJson(body, touchTaskBean.class); - int success = urgentTaskBean.getSuccess(); - zhuanhaoretren.call(urgentTaskBean, urgentTaskBean.getSuccess() + ""); - } - - @Override - public void onError(Exception e) { - e.printStackTrace(); - } - }); - } - - interface Zhuanhaoretren { - /** - * 幢号结果的回调 - */ - void call(touchTaskBean urgentTaskBean, String success); - } - - @Override - protected void onResume() { - super.onResume(); - againStart("0"); - if(ProfileSpUtils.getInstance().getSetBean().isRedswitchone()){ - yunduanStu.setText("云端开启"); - }else { - yunduanStu.setText(""); - } - } - - /** - * 检查设备是否存在 - */ - private void checkDevice() { - final HttpParams paramsPost = new HttpParams(); - new NetApi().getPostData(paramsPost, HttpConstants.URi_device_Appoperate_checkDevice).subscribe(new com.fisherbone.fuzhu.okgonet.Observer() { - @Override - public void onNext(Response response) { - String body = (String) response.body(); - try { - JSONObject jsonObject = new JSONObject(body); - String msg = jsonObject.getString("msg"); - String success = jsonObject.getString("success"); - if (VALUE_ZERO.equals(success)) { - tv_ifcunzai.setText("设备已注册"); - SPUtils.setSP(MainActivity.this, FZConfig.IS_ACTIVATION, "0"); - } else { - tv_ifcunzai.setText("设备未注册"); - SPUtils.setSP(MainActivity.this, FZConfig.IS_ACTIVATION, "1"); - } - - } catch (JSONException e) { - e.printStackTrace(); - } - } - - @Override - public void onError(Exception e) { - e.printStackTrace(); - } - }); - } - - /** - * 请求最新版本号 - */ - private void requestVersion() { - TecentNetworkApi.getService(NewsApiInterface.class) - .getNowVersion() - .subscribe(new BaseObserver() { - @Override - public void onSuccess(GetVesionResponseBean newsChannelsBean) { - Log.e("MainActivity", new Gson().toJson(newsChannelsBean)); - String newVersion = newsChannelsBean.getVersion(); - if (newVersion != null) { - String versionn = getVersionn(); - int versionUpdate = VersionUtils.compareVersion(versionn, newVersion); - if (VALUE_ZERO.equals(newsChannelsBean.getSuccess() + "")) { - if (versionUpdate == -1) {//两个版本相同 - mUpdateManager = new UpdateManager(MainActivity.this, "http://139.186.151.48/apk/atom-latest.apk"); - mUpdateManager.checkUpdateDownload(); - } - } - } - } - - @Override - public void onFailure(Throwable e) { - Log.e("Error", "Message:" + e.getMessage()); - } - }); - - } - - private void UpdateTuoguan(String str) { - final HttpParams paramsPost = new HttpParams(); - paramsPost.put("short_id", ChangLiang.short_id); - paramsPost.put("tuoguan_type", str);//1是离线,2是正常 - new NetApi().getPostData(paramsPost, HttpConstants.URi_Device_Appscanlogin_UpdateTuoguan).subscribe(new com.fisherbone.fuzhu.okgonet.Observer() { - @Override - public void onNext(Response response) { - String body = (String) response.body(); - try { - JSONObject jsonObject = new JSONObject(body); - String msg = jsonObject.getString("msg"); - String success = jsonObject.getString("success"); - if (VALUE_ZERO.equals(success)) { - Log.e("TIAOSHI###", "提交帐号异常" + msg); - } - } catch (JSONException e) { - e.printStackTrace(); - } - } - - @Override - public void onError(Exception e) { - e.printStackTrace(); - } - }); - } - - /** - * 潜在客户加关停止 - * - * @param str - */ - @Override - public void potfinish(String id, String str, String type) { - updatType(id, type); - } - - private void updatType(String id, String type) { - final HttpParams paramsPost = new HttpParams(); - paramsPost.put("id", id); - paramsPost.put("type", type); - new NetApi().getPostData(paramsPost, HttpConstants.URi_Device_Appoperate_updatType).subscribe(new com.fisherbone.fuzhu.okgonet.Observer() { - - @Override - public void onNext(Response response) { - String body = (String) response.body(); - try { - JSONObject jsonObject = new JSONObject(body); - String msg = jsonObject.getString("msg"); - String success = jsonObject.getString("success"); - if (VALUE_ZERO.equals(success)) { - getdakaVideoList(type); - com.fisherbone.fuzhu.utils.ToastUtils.showToast(MainActivity.this, msg); - } - - } catch (JSONException e) { - e.printStackTrace(); - } - } - - @Override - public void onError(Exception e) { - e.printStackTrace(); - } - }); - } - - private void renewType(String type) { - final HttpParams paramsPost = new HttpParams(); - paramsPost.put("type", type); - new NetApi().getPostData(paramsPost, HttpConstants.URi_Device_Appoperate_renewType).subscribe(new com.fisherbone.fuzhu.okgonet.Observer() { - - @Override - public void onNext(Response response) { - String body = (String) response.body(); - } - - @Override - public void onError(Exception e) { - e.printStackTrace(); - } - }); - } - - private void getdakaVideoList(String page_type) { - final HttpParams paramsPost = new HttpParams(); - paramsPost.put("type", page_type);//1:大咖,2:视频关键词 - new NetApi().getPostData(paramsPost, HttpConstants.URi_Device_Appoperate_dakaVideoList).subscribe(new com.fisherbone.fuzhu.okgonet.Observer() { - - @Override - public void onNext(Response response) { - String body = (String) response.body(); - dakaVideoListBean dakaVideoListBean = JsonUtils.fromJson(body, dakaVideoListBean.class); - if (dakaVideoListBean.getSuccess() == 0) { - List datavideo = dakaVideoListBean.getData(); - if (datavideo.size() > 0) { - boolean ifzhixing = ifzhixing(datavideo); - if (!ifzhixing) { - for (int i = 0; i < datavideo.size(); i++) { - com.fisherbone.fuzhu.entity.dakaVideoListBean.DataBean dataBean = datavideo.get(i); - //type:0么有执行,1:已执行 - if (VALUE_ZERO.equals(dataBean.getType())) { - String name = dataBean.getName();//搜索内容 - ChangLiang.dav_douyinname = name; - Log.e("TIAOSHI###", "赋值==" + name); - ChangLiang.dav_douyinname_id = dataBean.getId(); - Log.e("TIAOSHI###", "得到的大咖或者视频==" + ChangLiang.dav_douyinname); - List key = dataBean.getKey(); - final HttpParams paramsPost = new HttpParams(); - new NetApi().getPostData(paramsPost, HttpConstants.URi_Device_Appoperate_letterList).subscribe(new com.fisherbone.fuzhu.okgonet.Observer() { - @Override - public void onNext(Response response) { - String body = (String) response.body(); - letterListBean letterListBean = JsonUtils.fromJson(body, letterListBean.class); - if (letterListBean.getSuccess() == 0) { - List data = letterListBean.getData(); - PotCusBean potCusBean = new PotCusBean(); - potCusBean.setBigshotdatas(datavideo); - ArrayList keyWordBeans = new ArrayList<>(); - for (int i = 0; i < key.size(); i++) { - KeyWordBean keyWordBean = new KeyWordBean(); - keyWordBean.setComment(key.get(i).getKey_name()); - keyWordBeans.add(keyWordBean); - } - potCusBean.setKeyworddatas(keyWordBeans); - ArrayList letterBeans = new ArrayList<>(); - for (int i = 0; i < data.size(); i++) { - LetterBean letterBean = new LetterBean(); - letterBean.setComment(data.get(i).getContent()); - letterBeans.add(letterBean); - } - potCusBean.setLetterdatas(letterBeans); - ProfileSpUtils.getInstance().savePot(potCusBean); - //判断还有没有未加关的号 - Handler handler = new Handler(); - handler.postDelayed(new Runnable() { - @Override - public void run() { - controlWindow.stutas(ChangLiang.isrun); - AblStepHandler.getInstance().setStop(false); - if (VALUE_ONE.equals(page_type)) { - StartExecution(MainActivity.this, AblSteps.STEP_170); - } else { - StartExecution(MainActivity.this, AblSteps.STEP_160); - } - } - }, 5000);//3秒后执行Runnable中的run方法 - } - } - - @Override - public void onError(Exception e) { - e.printStackTrace(); - } - }); - break; - } - } - } else { - com.fisherbone.fuzhu.utils.ToastUtils.showToast(MainActivity.this, "所有大v或者关键词已经执行完毕"); - } - } - } - } - - @Override - public void onError(Exception e) { - e.printStackTrace(); - } - }); - } - - /** - * 是否全部执行 - */ - private boolean ifzhixing(List datavideo) { - boolean isallrun = true;//是否已经全部执行完毕 - for (int i = 0; i < datavideo.size(); i++) { - if (VALUE_ZERO.equals(datavideo.get(i).getType())) { - isallrun = false; - } - } - return isallrun; - } - - private void madeData() { - final HttpParams paramsPost = new HttpParams(); - new NetApi().getPostData(paramsPost, HttpConstants.URi_Device_Appoperate_liveScript).subscribe(new com.fisherbone.fuzhu.okgonet.Observer() { - @Override - public void onNext(Response response) { - String body = (String) response.body(); - HusshuBean result = JsonUtils.fromJson(body, HusshuBean.class); - List data = result.getData(); - for (int i = 0; i < data.size(); i++) { - CommentBeanData commentBeanData = data.get(i); - commentBeanData.setId(0 + "" + i); - if (null != commentDao.queryByCustom("Id", commentBeanData.getId()) && commentDao.queryByCustom("Id", commentBeanData.getId()).size() > 0) { - commentDao.updateData(commentBeanData); - } else { - commentDao.addInsert(commentBeanData); - } - } - } - - @Override - public void onError(Exception e) { - e.printStackTrace(); - } - }); - } - - - public void killAppProcess() - { - //注意:不能先杀掉主进程,否则逻辑代码无法继续执行,需先杀掉相关进程最后杀掉主进程 - ActivityManager mActivityManager = (ActivityManager) MainActivity.this.getSystemService(Context.ACTIVITY_SERVICE); - List mList = mActivityManager.getRunningAppProcesses(); - for (ActivityManager.RunningAppProcessInfo runningAppProcessInfo : mList) - { - if (runningAppProcessInfo.pid != android.os.Process.myPid()) - { - android.os.Process.killProcess(runningAppProcessInfo.pid); - } - } - android.os.Process.killProcess(android.os.Process.myPid()); - System.exit(0); - } - - /** - * Check当前辅助服务是否启用 - *com.fisherbone.fuzhu/.abllib.AblService - * @param serviceName serviceName - * @return 是否启用 - */ - private boolean checkAccessibilityEnabled(String serviceName) { - AccessibilityManager mAccessibilityManager = (AccessibilityManager) getSystemService(Context.ACCESSIBILITY_SERVICE); - List accessibilityServices = mAccessibilityManager.getEnabledAccessibilityServiceList(AccessibilityServiceInfo.FEEDBACK_GENERIC); - for (AccessibilityServiceInfo info : accessibilityServices) { - Log.e("TIAOSHI###", "服务进程" + info.getId()); - if (info.getId().equals(serviceName)) { - return true; - } - } - return false; - } - - - /** - * 全局统一任务倒计时 - * - * @param a - */ - private void taskDaojishi(final int a,MessageBean mesg ) { - - //启动计时器 - //从0开始发射11个数字为:0-10依次输出,延时0s执行,每1s发射一次。 - mdDisposable = Flowable.intervalRange(0, a + 1, 0, 1, TimeUnit.SECONDS) - .observeOn(AndroidSchedulers.mainThread()) - .doOnNext(new Consumer() { - @Override - public void accept(Long aLong) throws Exception { - long b = a - aLong; - long c = 0 + aLong; - Log.e("TIAOSHI###运行剩余时长", b + ""); - LiveEventBus.get("run_time").post("任务已运行"+c/60+"分钟"); - } - }) - .doOnComplete(new Action() { - @Override - public void run() throws Exception { - switch (mesg.getFromtype()) { - case "5": - ChangLiang.dav_ishuadong = "F"; - AblViewUtil.potgegin("停止"); - break; - case "6": - LiveEventBus.get("some_key").post("任务运行即将结束"); - break; - - default: - } - } - }) - .subscribe(); - } -} +package com.fisherbone.fuzhu.activity; + +import android.Manifest; +import android.accessibilityservice.AccessibilityServiceInfo; +import android.annotation.SuppressLint; +import android.app.Activity; +import android.app.ActivityManager; +import android.content.ComponentName; +import android.content.Context; +import android.content.Intent; +import android.content.IntentFilter; +import android.content.ServiceConnection; +import android.content.pm.PackageManager; +import android.net.Uri; +import android.os.Build; +import android.os.Bundle; +import android.os.Handler; +import android.os.IBinder; +import android.provider.Settings; +import android.util.Log; +import android.view.View; +import android.view.accessibility.AccessibilityManager; +import android.widget.PopupWindow; +import android.widget.TextView; +import android.widget.Toast; + +import com.blankj.utilcode.util.ToastUtils; +import com.fisherbone.fuzhu.utils.SafeToastUtils; +import com.fisherbone.fuzhu.BaseActivity; +import com.derry.wechat.debug.BuildConfig; +import com.fisherbone.fuzhu.ChangLiang; +import com.fisherbone.fuzhu.FZConfig; +import com.fisherbone.fuzhu.FuzhuApplication; +import com.fisherbone.fuzhu.InfoMessage; +import com.fisherbone.fuzhu.LiveActivity; +import com.fisherbone.fuzhu.LiveSuiJiActivity; +import com.fisherbone.fuzhu.R; +import com.fisherbone.fuzhu.TestTwoService; +import com.fisherbone.fuzhu.abllib.AblConfig; +import com.fisherbone.fuzhu.abllib.AblService; +import com.fisherbone.fuzhu.abllib.AblStepHandler; +import com.fisherbone.fuzhu.abllib.AblSteps; +import com.fisherbone.fuzhu.abllib.utils.AblUtil; +import com.fisherbone.fuzhu.abllib.utils.AblViewUtil; +import com.fisherbone.fuzhu.api.GetVesionResponseBean; +import com.fisherbone.fuzhu.api.NewsApiInterface; +import com.fisherbone.fuzhu.db.CommentBeanData; +import com.fisherbone.fuzhu.db.KeyWordBean; +import com.fisherbone.fuzhu.db.LetterBean; +import com.fisherbone.fuzhu.db.dao.CommentDao; +import com.fisherbone.fuzhu.db.dao.RedenvDao; +import com.fisherbone.fuzhu.db.dao.ZhanghaoDao; +import com.fisherbone.fuzhu.db.dao.daoutil; +import com.fisherbone.fuzhu.db.zhuanghaoBeanData; +import com.fisherbone.fuzhu.entity.FourEvent; +import com.fisherbone.fuzhu.entity.HusshuBean; +import com.fisherbone.fuzhu.entity.MessageBean; +import com.fisherbone.fuzhu.entity.PotCusBean; +import com.fisherbone.fuzhu.entity.SixEvent; +import com.fisherbone.fuzhu.entity.UrgentTaskBean; +import com.fisherbone.fuzhu.entity.dakaVideoListBean; +import com.fisherbone.fuzhu.entity.letterListBean; +import com.fisherbone.fuzhu.entity.touchTaskBean; +import com.fisherbone.fuzhu.okgonet.HttpConstants; +import com.fisherbone.fuzhu.okgonet.NetApi; +import com.fisherbone.fuzhu.quzan.AblStep1; +import com.fisherbone.fuzhu.reflect.InjectUtils; +import com.fisherbone.fuzhu.reflect.OnClickk; +import com.fisherbone.fuzhu.step.TestAblStep0; +import com.fisherbone.fuzhu.step.TestAblStep1; +import com.fisherbone.fuzhu.step.TestAblStep10; +import com.fisherbone.fuzhu.step.TestAblStep12; +import com.fisherbone.fuzhu.step.TestAblStep13; +import com.fisherbone.fuzhu.step.TestAblStep18; +import com.fisherbone.fuzhu.step.TestAblStep19; +import com.fisherbone.fuzhu.step.TestAblStep2; +import com.fisherbone.fuzhu.step.TestAblStep23; +import com.fisherbone.fuzhu.step.TestAblStep24; +import com.fisherbone.fuzhu.step.TestAblStep25; +import com.fisherbone.fuzhu.step.TestAblStep26; +import com.fisherbone.fuzhu.step.TestAblStep27; +import com.fisherbone.fuzhu.step.TestAblStep28; +import com.fisherbone.fuzhu.step.TestAblStep29; +import com.fisherbone.fuzhu.step.TestAblStep31; +import com.fisherbone.fuzhu.step.TestAblStep32; +import com.fisherbone.fuzhu.step.TestAblStep33; +import com.fisherbone.fuzhu.step.TestAblStep6; +import com.fisherbone.fuzhu.step.TestAblStep8; +import com.fisherbone.fuzhu.step.TestAblStep9; +import com.fisherbone.fuzhu.utils.JsonUtils; +import com.fisherbone.fuzhu.utils.JumpUtils; +import com.fisherbone.fuzhu.utils.Observerlife; +import com.fisherbone.fuzhu.utils.ProfileSpUtils; +import com.fisherbone.fuzhu.utils.SPUtils; +import com.fisherbone.fuzhu.utils.SystemUtil; +import com.fisherbone.fuzhu.utils.UpdateManager; +import com.fisherbone.fuzhu.utils.VersionUtils; +import com.github.gzuliyujiang.oaid.DeviceID; +import com.google.gson.Gson; +import com.gyf.immersionbar.ImmersionBar; +import com.jeremyliao.liveeventbus.LiveEventBus; +import com.lzy.okgo.OkGo; +import com.lzy.okgo.model.HttpParams; +import com.lzy.okgo.model.Response; +import com.xiangxue.arouter_annotation.ARouter; +import com.xiangxue.arouter_api.RouterManager; +import com.xiangxue.common.network.TecentNetworkApi; +import com.xiangxue.common.network.observer.BaseObserver; + +import org.json.JSONException; +import org.json.JSONObject; + +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.TimeUnit; + +import de.greenrobot.event.EventBus; +import io.reactivex.Flowable; +import io.reactivex.Observable; +import io.reactivex.Observer; +import io.reactivex.android.schedulers.AndroidSchedulers; +import io.reactivex.disposables.Disposable; +import io.reactivex.functions.Action; +import io.reactivex.functions.Consumer; + + +/** + * dddddd + */ +@ARouter(path = "/app/MainActivity") +public class MainActivity extends BaseActivity implements InfoMessage { + private TestTwoService service = null; + private boolean isBind = false; + private UpdateManager mUpdateManager;//版本更新 + private CommentDao commentDao; + private ControlWindow controlWindow; + private RedenvDao redenvDao; + private StartTask startTask; + private PopupWindow mPopCut; + + private ServiceConnection conn = new ServiceConnection() { + @Override + public void onServiceConnected(ComponentName name, IBinder binder) { + isBind = true; + TestTwoService.MyBinder myBinder = (TestTwoService.MyBinder) binder; + service = myBinder.getService(); + Log.i("TIAOSHI###--Kathy", "ActivityA - onServiceConnected"); + String isactivation = (String) SPUtils.getSp(MainActivity.this, FZConfig.IS_ACTIVATION, ""); + if (VALUE_ZERO.equals(isactivation)) { + fivelunxun(); + if (VALUE_ZERO.equals(isactivation)) { + Log.e("TIAOSHI###--Kathy", "设备已激活"); + tvStutas.setText("设备在线"); + } + Log.e("TIAOSHI###--Kathy", "轮询请求"); + + } else { + if ("1".equals(isactivation)) { + Log.e("TIAOSHI###--Kathy", "设备未激活"); + } + Log.e("TIAOSHI###--Kathy", "未轮询请求" + "设备是否已激活==" + isactivation + "云端本地==" + ChangLiang.control_status);//01为激活并且云端开启 + } + } + + @Override + public void onServiceDisconnected(ComponentName name) { + isBind = false; + Log.i("TIAOSHI###--", "ActivityA - onServiceDisconnected"); + } + }; + private Disposable mdDisposable; + final private int REQUEST_CODE_ASK_PERMISSIONS = 123; + private TextView tvShowInfo, tvStutas,yunduanStu,tv_ifcunzai; + private ZhanghaoDao zhanghaoDao; + + @SuppressLint("ObsoleteSdkInt") + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + if (BuildConfig.isRelease) { + Log.d(TAG, "onCreate: 当前是:集成化 线上环境,以app壳为主导运行的方式"); + // Toast.makeText(this, "当前是:集成化 线上环境,以app壳为主导运行的方式", Toast.LENGTH_SHORT).show(); + } else { + Log.d(TAG, "onCreate: 当前是:组件化 测试环境,所有的子模块都可以独立运行"); + // Toast.makeText(this, "当前是:组件化 测试环境,所有的子模块都可以独立运行", Toast.LENGTH_SHORT).show(); + } + ImmersionBar.with(this).statusBarDarkFont(true).init();//设置状态栏颜色 + IntentFilter intentFilter = new IntentFilter(); + intentFilter.addAction(Intent.ACTION_TIME_TICK); + String systemModel = SystemUtil.getSystemModel(); + Log.e("手机型号", systemModel); + if ("M2103K19C".equals(systemModel)) { + ChangLiang.phonetype = "2"; + } else if ("Redmi 7A".equals(systemModel)) { + ChangLiang.phonetype = "0"; + } else if ("M2007J22C".equals(systemModel)) { + ChangLiang.phonetype = "3"; + } else { + ChangLiang.phonetype = "1"; + } + //新修改的获取唯一标识方法 +// String clientId = DeviceID.getClientIdMD5(); +// Log.e("TIAOSHI###", "设备唯一标识"+clientId); +// SPUtils.setSP(this, FZConfig.KEY_DEVICE_ID, clientId); +// OkGo.getInstance().addCommonParams(new HttpParams("device_id", clientId)); + AblUtil.getPermissions(MainActivity.this); + + //adb shell pm grant com.fisherbone.fuzhu android.permission.WRITE_SECURE_SETTINGS +// Settings.Secure.putString(getContentResolver(), Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES, "com.fisherbone.fuzhu/com.fisherbone.fuzhu.abllib.AblService"); +// Settings.Secure.putString(getContentResolver(), Settings.Secure.ACCESSIBILITY_ENABLED, "1");//1表示开启 + + // 延迟 Toast 显示,确保 Activity 完全初始化后再显示,使用原生 Toast 避免 blankj ToastUtils 的崩溃问题 + getWindow().getDecorView().post(new Runnable() { + @Override + public void run() { + if (AblUtil.isAccessibilityServiceOpen(MainActivity.this)) { + // Log.e("TIAOSHI###", "无障碍服务正常"); + Toast.makeText(MainActivity.this, "无障碍服务正常", Toast.LENGTH_SHORT).show(); + }else { + Toast.makeText(MainActivity.this, "无障碍服务异常", Toast.LENGTH_SHORT).show(); +// Settings.Secure.putString(getContentResolver(), Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES, "com.fisherbone.fuzhu/com.fisherbone.fuzhu.abllib.AblService"); +// Settings.Secure.putString(getContentResolver(), Settings.Secure.ACCESSIBILITY_ENABLED, "0");//1表示开启 + } + } + }); + + ChangLiang.task_id = "";//当前执行任务id + ChangLiang.id = "";//当前执行任务功能id + ChangLiang.task_type = "";//当前执行任务类型 + ChangLiang.isstart = "0"; + ChangLiang.isstarttwo = "0"; + controlWindow = new ControlWindow(MainActivity.this); + LiveEventBus.get("some_key", String.class).observe(this, new Observerlife() { + @Override + public void onChanged(Object o) { + controlWindow.showRunInfo((String) o); + } + }); + LiveEventBus.get("run_time", String.class).observe(this, new Observerlife() { + @Override + public void onChanged(Object o) { + controlWindow.showRunTimeInfo((String) o); + } + }); + LiveEventBus.get("success", String.class).observe(this, new Observerlife() { + @Override + public void onChanged(Object o) { + Log.e("TIAOSHI###", "getcontrolStatus==执行了"); + getcontrolStatus(); + } + }); + LiveEventBus.get("ablservice", String.class).observe(this, new Observerlife() { + @Override + public void onChanged(Object o) { + tvShowInfo.setText((String)o); + if("无障碍服务被销毁".equals((String)o)){ + againStart("0"); + } + } + }); + LiveEventBus.get("jiaguantime", String.class).observe(this, new Observerlife() { + @Override + public void onChanged(Object o) { + Log.w("TIAOSHI###运行时长", (String) o); + //开启运行倒计时 + daojishitwo(Integer.parseInt((String) o)); + } + }); + LiveEventBus.get("closedtime", String.class).observe(this, new Observerlife() { + @Override + public void onChanged(Object o) { + if(mdDisposable!=null) { + mdDisposable.dispose(); + } + } + }); + LiveEventBus.get("runningstate", String.class).observe(this, new Observerlife() { + @Override + public void onChanged(Object o) { + againStart((String) o); + } + }); + LiveEventBus.get("yunkong", String.class).observe(this, new Observerlife() { + @Override + public void onChanged(Object o) { + if("open".equals((String) o)){ + }else { + closeService(); + } + } + }); + LiveEventBus.get("task_runtime", MessageBean.class).observe(this, new Observerlife() { + @Override + public void onChanged(Object o) { + MessageBean mesg = (MessageBean) o; + taskDaojishi(mesg.getRuntime(),mesg); + } + }); + InjectUtils.injectEvent(this); + requestVersion(); + + zhanghaoDao = new ZhanghaoDao(MainActivity.this); + commentDao = new CommentDao(MainActivity.this); + redenvDao = new RedenvDao(MainActivity.this); + startTask = new StartTask(MainActivity.this, controlWindow, zhanghaoDao); +// madeData(); + EventBus.getDefault().register(this); + displayBriefMemory(); + //设置公共参数 + String device_id = (String) SPUtils.getSp(MainActivity.this, FZConfig.KEY_DEVICE_ID, ""); + if (!"".equals(device_id)) { + OkGo.getInstance().addCommonParams(new HttpParams("device_id", device_id)); + } + checkDevice(); + Log.e("TIAOSHI###", "getcontrolStatus==执行了2"); + getcontrolStatus(); + renewType("1"); + new AblViewUtil().rigist(MainActivity.this); + AblConfig.Builder() + .setLogTag("123456")//logtag,不设置默认是abllib + .setStepMsgDelayMillis(2000)//步骤延迟时间 + .setFindViewMillisInFuture(10000)//寻找界面超时时间 + .setFindViewCountDownInterval(200)//寻找界面间隔时间 + .build().init(); + AblStepHandler.getInstance().initStepClass(new TestAblStep0(), new TestAblStep1(), new TestAblStep2(), new TestAblStep8(), new TestAblStep9(), new TestAblStep10(), new TestAblStep12(), new TestAblStep13(), new TestAblStep18(), new TestAblStep19(), new TestAblStep23(), new TestAblStep25(), new TestAblStep26(), new TestAblStep27(), new TestAblStep28(), new TestAblStep29(), new TestAblStep31(), new TestAblStep32(), new TestAblStep33()); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + int hasWriteContactsPermission = checkSelfPermission(Manifest.permission.READ_CONTACTS); + if (hasWriteContactsPermission != PackageManager.PERMISSION_GRANTED) { + requestPermissions(new String[]{Manifest.permission.WRITE_CONTACTS}, REQUEST_CODE_ASK_PERMISSIONS); + } + } + tvShowInfo = findViewById(R.id.tv_showinfo); + tvStutas = findViewById(R.id.tv_stutas); + yunduanStu = findViewById(R.id.tv_yunduanstutas); + tv_ifcunzai = findViewById(R.id.tv_ifcunzai); + + findViewById( R.id.rl_bottom_02).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + JumpUtils.gotoActivity(MainActivity.this, ScrSetActivity.class, false, "", ""); + } + }); + findViewById( R.id.rl_bottom_04).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + JumpUtils.gotoActivity(MainActivity.this, SettingActivity.class, false, "", ""); + } + }); + findViewById( R.id.rl_bottom_03).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { +// @SuppressLint("InflateParams") View v = getLayoutInflater().inflate(com.derry.wechat.R.layout.layout_pop,null); +// TextView viewById = v.findViewById(R.id.wechat_cut); +// viewById.setOnClickListener(new View.OnClickListener() { +// @Override +// public void onClick(View view) { +// Intent intent = new Intent(MainActivity.this, WeChatPlate.class); +// intent.putExtra("name", "Derry"); +// startActivity(intent); +// } +// }); +// mPopCut = new PopupWindow(v, ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.WRAP_CONTENT); +// mPopCut.setTouchable(true); +// mPopCut.setFocusable(true); +// mPopCut.showAtLocation(getWindow().getDecorView(), Gravity.BOTTOM,0,0); + } + }); + + } + + @OnClickk({R.id.rl_05, R.id.rl_12, R.id.rl_011, R.id.rl_10, R.id.rl_09, R.id.rl_08, R.id.rl_07, R.id.rl_06, R.id.rl_04, R.id.rl_03, R.id.rl_01, R.id.rl_02, R.id.rl_16}) + public void click(View view) { + if(ProfileSpUtils.getInstance().getSetBean().isRedswitchone()){ + SafeToastUtils.showShort(MainActivity.this, "请关闭云端控制"); + return; + } + int id = view.getId(); + if (id == R.id.rl_05) { + JumpUtils.gotoActivity(MainActivity.this, DavActivity.class, false, "", ""); + } else if (id == R.id.rl_12) { + JumpUtils.gotoActivity(MainActivity.this, HongBaoActivity.class, false, "", ""); + } else if (id == R.id.rl_011) { + JumpUtils.gotoActivity(MainActivity.this, AppointActivity.class, false, "", ""); + } else if (id == R.id.rl_10) { + JumpUtils.gotoActivity(MainActivity.this, LiveSuiJiActivity.class, false, "", ""); + } else if (id == R.id.rl_09) { + JumpUtils.gotoActivity(MainActivity.this, LiveActivity.class, false, "", ""); + } else if (id == R.id.rl_08) { + JumpUtils.gotoActivity(MainActivity.this, noticeActivity.class, false, "", ""); + } else if (id == R.id.rl_07) { + JumpUtils.gotoActivity(MainActivity.this, KeyWordActivity.class, false, "", ""); + } else if (id == R.id.rl_06) { + JumpUtils.gotoActivity(MainActivity.this, InteraActivity.class, false, "", ""); + } else if (id == R.id.rl_04) { + JumpUtils.gotoActivity(MainActivity.this, CancleFollowActivity.class, false, "", ""); + } else if (id == R.id.rl_03) { + JumpUtils.gotoActivity(MainActivity.this, KeyWordActivity.class, false, "", ""); + } else if (id == R.id.rl_01) { + JumpUtils.gotoActivity(MainActivity.this, RecFollowActivity.class, false, "", ""); + // JumpUtils.gotoActivity(MainActivity.this, MainActivityy.class, false, "", ""); + } else if (id == R.id.rl_16) { + JumpUtils.gotoActivity(MainActivity.this,CancelThumbUpActivity.class, false, "", ""); + } else if (id == R.id.rl_02) { + // service.stopSelf(); + + // CrashReport.testJavaCrash(); + + // 使用我们自己写的路由 跳转交互 +// RouterManager.getInstance() +// .build("/order/Order_MainActivity") +// .withString("name", "杜子腾") +// .navigation(this); // 组件和组件通信 + + RouterManager.getInstance() + .build("/wechat/W_MainActivity") + .withString("name", "杜子腾") + .navigation(this); // 组件和组件通信 + } + } + + private void closeService() { + //单击了“unbindService”按钮 + if (isBind) { + Log.i("TIAOSHI###--Kathy", + "----------------------------------------------------------------------"); + Log.i("TIAOSHI###--Kathy", "ActivityA 执行 unbindService"); + tvStutas.setText(""); + unbindService(conn); + } + } + + /** + * 模拟结束任务 + * + * @param a + */ + private void daojishitwo(final int a) { + //启动计时器 + //从0开始发射11个数字为:0-10依次输出,延时0s执行,每1s发射一次。 + mdDisposable= Flowable.intervalRange(0, a + 1, 0, 1, TimeUnit.SECONDS) + .observeOn(AndroidSchedulers.mainThread()) + .doOnNext(new Consumer() { + @Override + public void accept(Long aLong) throws Exception { + long b = a - aLong; + Log.w("TIAOSHI###运行剩余时长", b + ""); + } + }) + .doOnComplete(new Action() { + @Override + public void run() throws Exception { + Log.e("TIAOSHI###", "运行时间已到,停止自动加关"); + SafeToastUtils.showLong(MainActivity.this, "运行时间已到,停止自动加关"); + AblStepHandler.getInstance().setStop(true); + AblViewUtil.onMessage("停止"); + + } + }) + .subscribe(); + } + + + /** + * @param + * @return + * @description 接收tost通知栏消息 + */ + public void onEvent(SixEvent event) { + if (null != event) { + String msg = event.getMsg(); + if ("success".equals(msg)) { + String toastMsg = event.getToastMsg(); + if (toastMsg.contains("关注太快了,先休息一下")) { + AblStepHandler.getInstance().setStop(true); + AblViewUtil.onMessage("停止"); + }else if (toastMsg.contains("下线提醒")) { + UpdateTuoguan("1"); + } else if (toastMsg.contains("账号下线")) { + UpdateTuoguan("1"); + }else if(toastMsg.contains("已切换到")){ + UpdateTuoguan("0"); + } + else if(toastMsg.contains("由于该用户隐私设置,粉丝列表不可见")){ + AblStepHandler.getInstance().setStop(true); + AblViewUtil.onMessage("停止"); + } + } + } + } + + public void onEventMainThread(PotCusBean potCusBean) { + if ("1".equals(potCusBean.getSelect())) { + if (potCusBean.getBigshotdatas().size() > 0) { + execute("71"); + } + } + if (VALUE_TWO.equals(potCusBean.getSelect())) { + if (potCusBean.getKeyworddatas().size() > 0) { + execute("8"); + } + } + } + + public void onEventMainThread(FourEvent event) { + if (null != event) { + String msg = event.getMsg(); + if ("success".equals(msg)) { + String type = event.getType(); + switch (type) { + case "1": + List CommentBeanDatas = CommentDao.queryInByCustom("type", "1"); + if (CommentBeanDatas.size() > 0) { + execute("1"); + } else { + com.fisherbone.fuzhu.utils.ToastUtils.showToast(MainActivity.this, "请先添加评论话术"); + } + break; + case "2": + execute("2"); + break; + case "3": + execute("51"); + break; + case "4": + execute("61"); + break; + case "5": + execute("9"); + break; + case "6": + execute("6"); + break; + case "7": + execute("12"); + break; + case "8": + execute("13"); + break; + case "9": + execute("14"); + break; + case "10": + execute("5"); + break; + case "11": + execute("16"); + break; + default: + break; + } + } + } + } + + private void execute(String s) { + if (AblUtil.isAccessibilityServiceOpen(MainActivity.this)) { + AblUtil.addSuspensionWindowView(MainActivity.this, controlWindow.initWindowView(s)); + } else { + SafeToastUtils.showShort(MainActivity.this, "点到了"); + SafeToastUtils.showShort(MainActivity.this, "请先开启辅助服务"); + AblUtil.openAccessibilitySettings(); + } + } + + private void openService() { + //单击了“bindService”按钮 + Intent intent = new Intent(MainActivity.this, TestTwoService.class); + // intent.putExtra("from", "ActivityA"); + Log.i("TIAOSHI###--Kathy", "----------------------------------------------------------------------"); + Log.i("TIAOSHI###--Kathy", "ActivityA 执行 bindService"); + bindService(intent, conn, BIND_AUTO_CREATE); + } + + private void fivelunxun() { + Observable.interval(2, 10, TimeUnit.SECONDS) + .doOnNext(new Consumer() { + @Override + public void accept(Long integer) throws Exception { + Log.w("TIAOSHI###", "第 " + integer + " 次轮询"); + Log.w("TIAOSHI###", "第查看参数1 " + ChangLiang.control_status + "======"+ProfileSpUtils.getInstance().getSetBean().isRedswitchone()); + if (VALUE_ONE.equals(ChangLiang.control_status)&&ProfileSpUtils.getInstance().getSetBean().isRedswitchone()) { + getUrgentTask(); + } + if (AblUtil.isAccessibilityServiceOpen(MainActivity.this)) { + // Log.e("TIAOSHI###", "无障碍服务正常"); + } else { + Log.e("TIAOSHI###", "无障碍服务异常"); + Settings.Secure.putString(getContentResolver(), + Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES, "com.fisherbone.fuzhu/com.fisherbone.fuzhu.abllib.AblService"); + Settings.Secure.putString(getContentResolver(), + Settings.Secure.ACCESSIBILITY_ENABLED, "0");//1表示开启 + againStart("0"); + } + boolean destroy = isDestroy(MainActivity.this); + if(destroy) { + Log.e("TIAOSHI###", "MainActivity已经被销毁"); + closeService(); + Settings.Secure.putString(getContentResolver(), Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES, "com.fisherbone.fuzhu/com.fisherbone.fuzhu.abllib.AblService"); + Settings.Secure.putString(getContentResolver(), Settings.Secure.ACCESSIBILITY_ENABLED, "0");//1表示开启 + } + } + }).subscribe(new Observer() { + @Override + public void onSubscribe(Disposable d) { + + } + + @Override + public void onNext(Long value) { + + } + + @Override + public void onError(Throwable e) { + Log.d(TAG, "对Error事件作出响应"); + } + + @Override + public void onComplete() { + Log.d(TAG, "对Complete事件作出响应"); + } + }); + } + /** + * 判断Activity是否Destroy + * @param mActivity + * @return true:已销毁 + */ + public static boolean isDestroy(Activity mActivity) { + if (mActivity == null || + mActivity.isFinishing() || + (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1 && mActivity.isDestroyed())) { + return true; + } else { + return false; + } + } + + /** + * 1代表正常 + * 0代表异常 + * @param str + */ + private void againStart(String str) { + final HttpParams paramsPost = new HttpParams(); + paramsPost.put("task_status", str); + paramsPost.put("task_id", ChangLiang.task_id); + paramsPost.put("task_type", ChangLiang.task_type); + new NetApi().getPostData(paramsPost, HttpConstants.URi_Device_Appscanlogin_againStart).subscribe(new com.fisherbone.fuzhu.okgonet.Observer() { + @Override + public void onNext(Response response) { + String body = (String) response.body(); + Log.e("需通知后台重新启动", body); + } + + @Override + public void onError(Exception e) { + e.printStackTrace(); + + } + }); + } + + private void getUrgentTask() { + final HttpParams paramsPost = new HttpParams(); + paramsPost.put("short_id", ChangLiang.short_id); + paramsPost.put("task_id", ChangLiang.task_id); + paramsPost.put("id", ChangLiang.id); + paramsPost.put("task_type", ChangLiang.task_type); + //是否有当前有执行任务,有则传下面4个参数,无则不需用传。 + new NetApi().getPostData(paramsPost, HttpConstants.URi_device_Appscanlogin_urgentTask).subscribe(new com.fisherbone.fuzhu.okgonet.Observer() { + @Override + public void onNext(Response response) { + String body = (String) response.body(); + if (AblUtil.isAccessibilityServiceOpen(MainActivity.this)) { + startTask.startTask(body); + } + } + + @Override + public void onError(Exception e) { + e.printStackTrace(); + } + }); + } + + //倒计时2秒开启服务 + private void daojishifirst(final int a) { + //启动计时器 + //从0开始发射11个数字为:0-10依次输出,延时0s执行,每1s发射一次。 + mdDisposable = Flowable.intervalRange(0, a + 1, 0, 1, TimeUnit.SECONDS) + .observeOn(AndroidSchedulers.mainThread()) + .doOnNext(new Consumer() { + @Override + public void accept(Long aLong) throws Exception { + long b = a - aLong; + Log.w("TIAOSHI###", b + ""); + } + }) + .doOnComplete(new Action() { + @Override + public void run() throws Exception { + openService(); + Log.e("TIAOSHI###", "轮询开启服务"); + } + }) + .subscribe(); + } + + + @Override + public void mesagesuccess(String str) { + if ("停止".equals(str)) { + if(mdDisposable!=null) { + mdDisposable.dispose(); + } + AblStepHandler.getInstance().setStop(true); + FinishTask(); + } + } + + /** + * 撞号任务完成的通知 + * + * @param str + */ + @Override + public void mesagezhuang(String str) { + if ("停止".equals(str)) { + if(mdDisposable!=null) { + mdDisposable.dispose(); + } + AblStepHandler.getInstance().setStop(true); + touchResult(); + controlWindow.stutas(true); + } + } + + /** + * 粉丝通知停止 + * + * @param str + */ + @Override + public void potgegin(String str) { + if ("停止".equals(str)) { + if(mdDisposable!=null) { + mdDisposable.dispose(); + } + AblStepHandler.getInstance().setStop(true); + controlWindow.stutas(true); + controlWindow.closedWin(); + AblViewUtil.mySleep(2); +// AblStepHandler.getInstance().setStop(false); +// Log.e("step###", "开始执行关闭抖音程序"); +// AblStepHandler.sendMsg(192); + + FinishTask(); + } + } + + @Override + public void onDestroy() { + super.onDestroy(); + Settings.Secure.putString(getContentResolver(), Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES, "com.fisherbone.fuzhu/com.fisherbone.fuzhu.abllib.AblService"); + Settings.Secure.putString(getContentResolver(), Settings.Secure.ACCESSIBILITY_ENABLED, "0");//1表示开启 + + if(mdDisposable!=null) { + mdDisposable.dispose(); + } + EventBus.getDefault().unregister(this); + closeService(); + + Log.e("TIAOSHI###", "执行了onDestroy"); + killAppProcess(); + } + + /** + * 获取设备控制状态 -- 云端还是本地 + */ + private void getcontrolStatus() { + final HttpParams paramsPost = new HttpParams(); + new NetApi().getPostData(paramsPost, HttpConstants.URi_device_Appoperate_controlStatus).subscribe(new com.fisherbone.fuzhu.okgonet.Observer() { + @Override + public void onNext(Response response) { + String body = (String) response.body(); + try { + JSONObject jsonObject = new JSONObject(body); + String msg = jsonObject.getString("msg"); + String success = jsonObject.getString("success"); + String control_status = jsonObject.getString("control_status"); + //{"success":0,"msg":"调取蜂狐成功"} + if (VALUE_ZERO.equals(success)) { + ChangLiang.control_status = control_status; + if (VALUE_ONE.equals(control_status)) { + Log.e("TIAOSHI###", "倒计时开启服务"); + if(ProfileSpUtils.getInstance().getSetBean().isRedswitchone()) { + Log.i("Kathy","云控状态 " + ProfileSpUtils.getInstance().getSetBean().isRedswitchone()); + Log.i("Kathy","倒计时开始执行了"); + daojishifirst(2); + } + } + } + + } catch (JSONException e) { + e.printStackTrace(); + } + } + + @Override + public void onError(Exception e) { + e.printStackTrace(); + } + }); + } + + /** + * app每执行完一个任务成功后调取接口 + */ + private void FinishTask() { + final HttpParams paramsPost = new HttpParams(); + paramsPost.put("short_id", ChangLiang.short_id);// 拿到的抖音id + paramsPost.put("task_id", ChangLiang.task_id);//拿到的任务id + paramsPost.put("id", ChangLiang.id);//功能id + paramsPost.put("task_type", ChangLiang.task_type);//拿到的任务类型 1:代表账号登录 2:停任务 3:代表紧急任务,4:代表固定任务 + + new NetApi().getPostData(paramsPost, HttpConstants.URi_device_Appscanlogin_FinishTask).subscribe(new com.fisherbone.fuzhu.okgonet.Observer() { + @Override + public void onNext(Response response) { + String body = (String) response.body(); + try { + JSONObject jsonObject = new JSONObject(body); + String msg = jsonObject.getString("msg"); + String success = jsonObject.getString("success"); + if (VALUE_ZERO.equals(success)) { + Log.e("TIAOSHI###", "每执行完一个任务成功后调取接口==" + msg); + Log.e("TIAOSHI###", "任务执行完毕,领取新的任务。"); + ChangLiang.isstarttwo = "0"; + ChangLiang.isstart = "0"; + fixedTask(); + } + } catch (JSONException e) { + e.printStackTrace(); + } + } + + @Override + public void onError(Exception e) { + e.printStackTrace(); + } + }); + } + + /** + * 撞号返回结果[{'id':'1','phone':'15029224225','record_id':'1'},{'id':'2','phone':'14712354698','record_id':'1'}] + */ + private void touchResult() { + String zhuanghao = ""; + ZhanghaoDao instance1 = daoutil.getInstance(FuzhuApplication.getContext()); + List zhuanghaoBeanData = instance1.queryByCustom("isjiaguan", "1"); + if (zhuanghaoBeanData.size() > 0) { + Gson gson = new Gson(); + zhuanghao = gson.toJson(zhuanghaoBeanData); + Log.e("TIAOSHI###", "撞号返回结果==" + zhuanghao); + } else { + zhuanghao = ""; + Log.e("TIAOSHI###", "撞号返回结果==" + zhuanghao); + } + final HttpParams paramsPost = new HttpParams(); + paramsPost.put("short_id", ChangLiang.short_id);// 拿到的抖音id + paramsPost.put("zhuanghao", zhuanghao); + + new NetApi().getPostData(paramsPost, HttpConstants.URi_device_Appscanlogin_touchResult).subscribe(new com.fisherbone.fuzhu.okgonet.Observer() { + @Override + public void onNext(Response response) { + String body = (String) response.body(); + try { + JSONObject jsonObject = new JSONObject(body); + String msg = jsonObject.getString("msg"); + //success=0,表示撞号继续,同时返回需要请求的数量,去获取撞号账号去请求数据 + //success=-2,表示撞号结束,可以去请求其他任务 + String success = jsonObject.getString("success"); + + if (VALUE_ZERO.equals(success)) { + String data = jsonObject.getString("data"); + com.fisherbone.fuzhu.utils.ToastUtils.showToast(MainActivity.this, msg); + Log.e("TIAOSHI###", "撞号结果==" + msg); + touchTask(data, new Zhuanhaoretren() { + @Override + public void call(touchTaskBean urgentTaskBean, String success) { + if (VALUE_ZERO.equals(success)) { + daojishifour(20, "3"); + } else if ("-2".equals(success)) { + Log.e("TIAOSHI###", "获取撞号账号==" + urgentTaskBean.getMsg()); + //表示撞号结束,可以去请求其他任务 + FinishTask(); + } + } + }); + + } else if ("-1".equals(success)) { + String data = jsonObject.getString("data"); + Log.e("TIAOSHI###", "撞号结果==" + msg); + touchTask(data, new Zhuanhaoretren() { + @Override + public void call(touchTaskBean urgentTaskBean, String success) { + if (VALUE_ZERO.equals(success)) { + daojishifour(20, "3"); + } else if ("-2".equals(success)) { + Log.e("TIAOSHI###", "获取撞号账号==" + urgentTaskBean.getMsg()); + //表示撞号结束,可以去请求其他任务 + FinishTask(); + } + } + }); + daojishifour(20, "3"); + } else { + com.fisherbone.fuzhu.utils.ToastUtils.showToast(MainActivity.this, msg); + Log.e("TIAOSHI###", "撞号结果==" + msg); + //表示撞号结束,可以去请求其他任务 + FinishTask(); + } + } catch (JSONException e) { + e.printStackTrace(); + } + } + + @Override + public void onError(Exception e) { + e.printStackTrace(); + } + }); + } + + /** + * 固定任务(当前任务执行完请求下一个任务接口) + * 此处有一个核心逻辑,最后三个参数,传值分两种情况,一、如果来的紧急任务是一个停任务,那么就传空。二、如果来的紧急任务是一个其它任务。那么就传值 + */ + private void fixedTask() { + if (VALUE_TWO.equals(ChangLiang.task_type)) { + Log.e("TIAOSHI###", "执行了传值分两种情况第一种情况"); + final HttpParams paramsPost = new HttpParams(); + paramsPost.put("short_id", ChangLiang.short_id);// 拿到的抖音id + paramsPost.put("task_id", ChangLiang.task_id);//拿到的任务id + paramsPost.put("id", ChangLiang.id);//功能id + paramsPost.put("task_type", ChangLiang.task_type);//拿到的任务类型 1:代表账号登录 2:停任务 3:代表紧急任务,4:代表固定任务 + paramsPost.put("urgent_short_id", "");//未处理完成紧急任务抖音id + paramsPost.put("urgent_task_id", "");//未处理完成紧急任务id + paramsPost.put("urgent_id", "");// 未处理完成紧急功能id + paramsPost.put("fixed_short_id", "");//未处理完成固定任务抖音id + paramsPost.put("fixed_task_id", "");//未处理完成固定任务id + paramsPost.put("fixed_id", "");//未处理完成固定功能id + new NetApi().getPostData(paramsPost, HttpConstants.URi_device_Appscanlogin_fixedTask).subscribe(new com.fisherbone.fuzhu.okgonet.Observer() { + @Override + public void onNext(Response response) { + String body = (String) response.body(); + UrgentTaskBean urgentTaskBean = JsonUtils.fromJson(body, UrgentTaskBean.class); + int success = urgentTaskBean.getSuccess(); + if (success == 0) { + //初始化5秒的接口参数 + ChangLiang.task_id = "";//当前执行任务id + ChangLiang.id = "";//当前执行任务功能id + ChangLiang.task_type = "";//当前执行任务类型 + } + startTask.startTask(body); + } + + @Override + public void onError(Exception e) { + e.printStackTrace(); + } + }); + } else { + final HttpParams paramsPost = new HttpParams(); + paramsPost.put("short_id", ChangLiang.short_id);// 拿到的抖音id + paramsPost.put("task_id", ChangLiang.task_id);//拿到的任务id + paramsPost.put("id", ChangLiang.id);//功能id + paramsPost.put("task_type", ChangLiang.task_type);//拿到的任务类型 1:代表账号登录 2:停任务 3:代表紧急任务,4:代表固定任务 + paramsPost.put("urgent_short_id", ChangLiang.short_id_jf);//未处理完成紧急任务抖音id + paramsPost.put("urgent_task_id", ChangLiang.task_id_jf);//未处理完成紧急任务id + paramsPost.put("urgent_id", ChangLiang.id_jf);// 未处理完成紧急功能id + paramsPost.put("fixed_short_id", ChangLiang.short_id_f);//未处理完成固定任务抖音id + paramsPost.put("fixed_task_id", ChangLiang.task_id_f);//未处理完成固定任务id + paramsPost.put("fixed_id", ChangLiang.id_f);//未处理完成固定功能id + new NetApi().getPostData(paramsPost, HttpConstants.URi_device_Appscanlogin_fixedTask).subscribe(new com.fisherbone.fuzhu.okgonet.Observer() { + @Override + public void onNext(Response response) { + String body = (String) response.body(); + startTask.startTask(body); + } + + @Override + public void onError(Exception e) { + e.printStackTrace(); + } + }); + } + } + + /** + * 倒计时开始执行任务 + * + * @param a + */ + private void daojishifour(final int a, String func_type) { + //启动计时器 + //从0开始发射11个数字为:0-10依次输出,延时0s执行,每1s发射一次。 + mdDisposable = Flowable.intervalRange(0, a + 1, 0, 1, TimeUnit.SECONDS) + .observeOn(AndroidSchedulers.mainThread()) + .doOnNext(new Consumer() { + @Override + public void accept(Long aLong) throws Exception { + long b = a - aLong; + Log.w("TIAOSHI###", b + ""); + } + }) + .doOnComplete(new Action() { + @Override + public void run() throws Exception { + //先判断无障碍是否开启 + Log.e("TIAOSHI###", "temp3"); + // ControlWindow controlWindow = new ControlWindow(MainActivity.this); + AblUtil.addSuspensionWindowView(MainActivity.this, controlWindow.initWindowView(func_type)); + } + }) + .subscribe(); + } + + /** + * 获取撞号账号 + * 如果{"success":-2,"msg":"暂无需要撞号的账号"}停止撞号任务 + */ + private void touchTask(String touch_num, Zhuanhaoretren zhuanhaoretren) { + final HttpParams paramsPost = new HttpParams(); + paramsPost.put("short_id", ChangLiang.short_id);// 拿到的抖音id + paramsPost.put("touch_num", touch_num);//功能id + new NetApi().getPostData(paramsPost, HttpConstants.URi_device_Appscanlogin_touchTask).subscribe(new com.fisherbone.fuzhu.okgonet.Observer() { + @Override + public void onNext(Response response) { + String body = (String) response.body(); + touchTaskBean urgentTaskBean = JsonUtils.fromJson(body, touchTaskBean.class); + int success = urgentTaskBean.getSuccess(); + zhuanhaoretren.call(urgentTaskBean, urgentTaskBean.getSuccess() + ""); + } + + @Override + public void onError(Exception e) { + e.printStackTrace(); + } + }); + } + + interface Zhuanhaoretren { + /** + * 幢号结果的回调 + */ + void call(touchTaskBean urgentTaskBean, String success); + } + + @Override + protected void onResume() { + super.onResume(); + againStart("0"); + if(ProfileSpUtils.getInstance().getSetBean().isRedswitchone()){ + yunduanStu.setText("云端开启"); + }else { + yunduanStu.setText(""); + } + } + + /** + * 检查设备是否存在 + */ + private void checkDevice() { + final HttpParams paramsPost = new HttpParams(); + new NetApi().getPostData(paramsPost, HttpConstants.URi_device_Appoperate_checkDevice).subscribe(new com.fisherbone.fuzhu.okgonet.Observer() { + @Override + public void onNext(Response response) { + String body = (String) response.body(); + try { + JSONObject jsonObject = new JSONObject(body); + String msg = jsonObject.getString("msg"); + String success = jsonObject.getString("success"); + if (VALUE_ZERO.equals(success)) { + tv_ifcunzai.setText("设备已注册"); + SPUtils.setSP(MainActivity.this, FZConfig.IS_ACTIVATION, "0"); + } else { + tv_ifcunzai.setText("设备未注册"); + SPUtils.setSP(MainActivity.this, FZConfig.IS_ACTIVATION, "1"); + } + + } catch (JSONException e) { + e.printStackTrace(); + } + } + + @Override + public void onError(Exception e) { + e.printStackTrace(); + } + }); + } + + /** + * 请求最新版本号 + */ + private void requestVersion() { + TecentNetworkApi.getService(NewsApiInterface.class) + .getNowVersion() + .subscribe(new BaseObserver() { + @Override + public void onSuccess(GetVesionResponseBean newsChannelsBean) { + Log.e("MainActivity", new Gson().toJson(newsChannelsBean)); + String newVersion = newsChannelsBean.getVersion(); + if (newVersion != null) { + String versionn = getVersionn(); + int versionUpdate = VersionUtils.compareVersion(versionn, newVersion); + if (VALUE_ZERO.equals(newsChannelsBean.getSuccess() + "")) { + if (versionUpdate == -1) {//两个版本相同 + mUpdateManager = new UpdateManager(MainActivity.this, "http://139.186.151.48/apk/atom-latest.apk"); + mUpdateManager.checkUpdateDownload(); + } + } + } + } + + @Override + public void onFailure(Throwable e) { + Log.e("Error", "Message:" + e.getMessage()); + } + }); + + } + + private void UpdateTuoguan(String str) { + final HttpParams paramsPost = new HttpParams(); + paramsPost.put("short_id", ChangLiang.short_id); + paramsPost.put("tuoguan_type", str);//1是离线,2是正常 + new NetApi().getPostData(paramsPost, HttpConstants.URi_Device_Appscanlogin_UpdateTuoguan).subscribe(new com.fisherbone.fuzhu.okgonet.Observer() { + @Override + public void onNext(Response response) { + String body = (String) response.body(); + try { + JSONObject jsonObject = new JSONObject(body); + String msg = jsonObject.getString("msg"); + String success = jsonObject.getString("success"); + if (VALUE_ZERO.equals(success)) { + Log.e("TIAOSHI###", "提交帐号异常" + msg); + } + } catch (JSONException e) { + e.printStackTrace(); + } + } + + @Override + public void onError(Exception e) { + e.printStackTrace(); + } + }); + } + + /** + * 潜在客户加关停止 + * + * @param str + */ + @Override + public void potfinish(String id, String str, String type) { + updatType(id, type); + } + + private void updatType(String id, String type) { + final HttpParams paramsPost = new HttpParams(); + paramsPost.put("id", id); + paramsPost.put("type", type); + new NetApi().getPostData(paramsPost, HttpConstants.URi_Device_Appoperate_updatType).subscribe(new com.fisherbone.fuzhu.okgonet.Observer() { + + @Override + public void onNext(Response response) { + String body = (String) response.body(); + try { + JSONObject jsonObject = new JSONObject(body); + String msg = jsonObject.getString("msg"); + String success = jsonObject.getString("success"); + if (VALUE_ZERO.equals(success)) { + getdakaVideoList(type); + com.fisherbone.fuzhu.utils.ToastUtils.showToast(MainActivity.this, msg); + } + + } catch (JSONException e) { + e.printStackTrace(); + } + } + + @Override + public void onError(Exception e) { + e.printStackTrace(); + } + }); + } + + private void renewType(String type) { + final HttpParams paramsPost = new HttpParams(); + paramsPost.put("type", type); + new NetApi().getPostData(paramsPost, HttpConstants.URi_Device_Appoperate_renewType).subscribe(new com.fisherbone.fuzhu.okgonet.Observer() { + + @Override + public void onNext(Response response) { + String body = (String) response.body(); + } + + @Override + public void onError(Exception e) { + e.printStackTrace(); + } + }); + } + + private void getdakaVideoList(String page_type) { + final HttpParams paramsPost = new HttpParams(); + paramsPost.put("type", page_type);//1:大咖,2:视频关键词 + new NetApi().getPostData(paramsPost, HttpConstants.URi_Device_Appoperate_dakaVideoList).subscribe(new com.fisherbone.fuzhu.okgonet.Observer() { + + @Override + public void onNext(Response response) { + String body = (String) response.body(); + dakaVideoListBean dakaVideoListBean = JsonUtils.fromJson(body, dakaVideoListBean.class); + if (dakaVideoListBean.getSuccess() == 0) { + List datavideo = dakaVideoListBean.getData(); + if (datavideo.size() > 0) { + boolean ifzhixing = ifzhixing(datavideo); + if (!ifzhixing) { + for (int i = 0; i < datavideo.size(); i++) { + com.fisherbone.fuzhu.entity.dakaVideoListBean.DataBean dataBean = datavideo.get(i); + //type:0么有执行,1:已执行 + if (VALUE_ZERO.equals(dataBean.getType())) { + String name = dataBean.getName();//搜索内容 + ChangLiang.dav_douyinname = name; + Log.e("TIAOSHI###", "赋值==" + name); + ChangLiang.dav_douyinname_id = dataBean.getId(); + Log.e("TIAOSHI###", "得到的大咖或者视频==" + ChangLiang.dav_douyinname); + List key = dataBean.getKey(); + final HttpParams paramsPost = new HttpParams(); + new NetApi().getPostData(paramsPost, HttpConstants.URi_Device_Appoperate_letterList).subscribe(new com.fisherbone.fuzhu.okgonet.Observer() { + @Override + public void onNext(Response response) { + String body = (String) response.body(); + letterListBean letterListBean = JsonUtils.fromJson(body, letterListBean.class); + if (letterListBean.getSuccess() == 0) { + List data = letterListBean.getData(); + PotCusBean potCusBean = new PotCusBean(); + potCusBean.setBigshotdatas(datavideo); + ArrayList keyWordBeans = new ArrayList<>(); + for (int i = 0; i < key.size(); i++) { + KeyWordBean keyWordBean = new KeyWordBean(); + keyWordBean.setComment(key.get(i).getKey_name()); + keyWordBeans.add(keyWordBean); + } + potCusBean.setKeyworddatas(keyWordBeans); + ArrayList letterBeans = new ArrayList<>(); + for (int i = 0; i < data.size(); i++) { + LetterBean letterBean = new LetterBean(); + letterBean.setComment(data.get(i).getContent()); + letterBeans.add(letterBean); + } + potCusBean.setLetterdatas(letterBeans); + ProfileSpUtils.getInstance().savePot(potCusBean); + //判断还有没有未加关的号 + Handler handler = new Handler(); + handler.postDelayed(new Runnable() { + @Override + public void run() { + controlWindow.stutas(ChangLiang.isrun); + AblStepHandler.getInstance().setStop(false); + if (VALUE_ONE.equals(page_type)) { + StartExecution(MainActivity.this, AblSteps.STEP_170); + } else { + StartExecution(MainActivity.this, AblSteps.STEP_160); + } + } + }, 5000);//3秒后执行Runnable中的run方法 + } + } + + @Override + public void onError(Exception e) { + e.printStackTrace(); + } + }); + break; + } + } + } else { + com.fisherbone.fuzhu.utils.ToastUtils.showToast(MainActivity.this, "所有大v或者关键词已经执行完毕"); + } + } + } + } + + @Override + public void onError(Exception e) { + e.printStackTrace(); + } + }); + } + + /** + * 是否全部执行 + */ + private boolean ifzhixing(List datavideo) { + boolean isallrun = true;//是否已经全部执行完毕 + for (int i = 0; i < datavideo.size(); i++) { + if (VALUE_ZERO.equals(datavideo.get(i).getType())) { + isallrun = false; + } + } + return isallrun; + } + + private void madeData() { + final HttpParams paramsPost = new HttpParams(); + new NetApi().getPostData(paramsPost, HttpConstants.URi_Device_Appoperate_liveScript).subscribe(new com.fisherbone.fuzhu.okgonet.Observer() { + @Override + public void onNext(Response response) { + String body = (String) response.body(); + HusshuBean result = JsonUtils.fromJson(body, HusshuBean.class); + List data = result.getData(); + for (int i = 0; i < data.size(); i++) { + CommentBeanData commentBeanData = data.get(i); + commentBeanData.setId(0 + "" + i); + if (null != commentDao.queryByCustom("Id", commentBeanData.getId()) && commentDao.queryByCustom("Id", commentBeanData.getId()).size() > 0) { + commentDao.updateData(commentBeanData); + } else { + commentDao.addInsert(commentBeanData); + } + } + } + + @Override + public void onError(Exception e) { + e.printStackTrace(); + } + }); + } + + + public void killAppProcess() + { + //注意:不能先杀掉主进程,否则逻辑代码无法继续执行,需先杀掉相关进程最后杀掉主进程 + ActivityManager mActivityManager = (ActivityManager) MainActivity.this.getSystemService(Context.ACTIVITY_SERVICE); + List mList = mActivityManager.getRunningAppProcesses(); + for (ActivityManager.RunningAppProcessInfo runningAppProcessInfo : mList) + { + if (runningAppProcessInfo.pid != android.os.Process.myPid()) + { + android.os.Process.killProcess(runningAppProcessInfo.pid); + } + } + android.os.Process.killProcess(android.os.Process.myPid()); + System.exit(0); + } + + /** + * Check当前辅助服务是否启用 + *com.fisherbone.fuzhu/.abllib.AblService + * @param serviceName serviceName + * @return 是否启用 + */ + private boolean checkAccessibilityEnabled(String serviceName) { + AccessibilityManager mAccessibilityManager = (AccessibilityManager) getSystemService(Context.ACCESSIBILITY_SERVICE); + List accessibilityServices = mAccessibilityManager.getEnabledAccessibilityServiceList(AccessibilityServiceInfo.FEEDBACK_GENERIC); + for (AccessibilityServiceInfo info : accessibilityServices) { + Log.e("TIAOSHI###", "服务进程" + info.getId()); + if (info.getId().equals(serviceName)) { + return true; + } + } + return false; + } + + + /** + * 全局统一任务倒计时 + * + * @param a + */ + private void taskDaojishi(final int a,MessageBean mesg ) { + + //启动计时器 + //从0开始发射11个数字为:0-10依次输出,延时0s执行,每1s发射一次。 + mdDisposable = Flowable.intervalRange(0, a + 1, 0, 1, TimeUnit.SECONDS) + .observeOn(AndroidSchedulers.mainThread()) + .doOnNext(new Consumer() { + @Override + public void accept(Long aLong) throws Exception { + long b = a - aLong; + long c = 0 + aLong; + Log.e("TIAOSHI###运行剩余时长", b + ""); + LiveEventBus.get("run_time").post("任务已运行"+c/60+"分钟"); + } + }) + .doOnComplete(new Action() { + @Override + public void run() throws Exception { + switch (mesg.getFromtype()) { + case "5": + ChangLiang.dav_ishuadong = "F"; + AblViewUtil.potgegin("停止"); + break; + case "6": + LiveEventBus.get("some_key").post("任务运行即将结束"); + break; + + default: + } + } + }) + .subscribe(); + } +} diff --git a/app/src/main/java/com/fisherbone/fuzhu/activity/SettingActivity.java b/app/src/main/java/com/fisherbone/fuzhu/activity/SettingActivity.java index c314f7e..611610c 100644 --- a/app/src/main/java/com/fisherbone/fuzhu/activity/SettingActivity.java +++ b/app/src/main/java/com/fisherbone/fuzhu/activity/SettingActivity.java @@ -1,703 +1,700 @@ -package com.fisherbone.fuzhu.activity; - -import android.Manifest; -import android.app.Activity; -import android.app.Dialog; -import android.content.Context; -import android.content.Intent; -import android.graphics.Color; -import android.graphics.drawable.ColorDrawable; -import android.os.Build; -import android.os.Bundle; -import android.text.Html; -import android.util.Log; -import android.view.View; -import android.view.Window; -import android.view.WindowManager; -import android.widget.Button; -import android.widget.CompoundButton; -import android.widget.ImageView; -import android.widget.TextView; - -import androidx.annotation.NonNull; -import androidx.annotation.StyleRes; -import androidx.databinding.DataBindingUtil; -import androidx.recyclerview.widget.LinearLayoutManager; -import androidx.recyclerview.widget.RecyclerView; - -import com.blankj.utilcode.util.ToastUtils; -import com.chad.library.adapter.base.BaseQuickAdapter; -import com.chad.library.adapter.base.BaseViewHolder; -import com.fisherbone.ContactsHelp; -import com.fisherbone.fuzhu.BaseActivity; -import com.fisherbone.fuzhu.ChangLiang; -import com.fisherbone.fuzhu.FZConfig; -import com.fisherbone.fuzhu.R; -import com.fisherbone.fuzhu.abllib.AblStepHandler; -import com.fisherbone.fuzhu.abllib.AblSteps; -import com.fisherbone.fuzhu.abllib.utils.AblUtil; -import com.fisherbone.fuzhu.api.GetVesionResponseBean; -import com.fisherbone.fuzhu.api.NewsApiInterface; -import com.fisherbone.fuzhu.databinding.ActivitySettingBinding; -import com.fisherbone.fuzhu.db.DouyinBean; -import com.fisherbone.fuzhu.db.dao.DouyinDao; -import com.fisherbone.fuzhu.db.zhuanghaoBeanData; -import com.fisherbone.fuzhu.dialog.BaseTipsDialog; -import com.fisherbone.fuzhu.entity.DakaVideoBean; -import com.fisherbone.fuzhu.entity.DeviceByDouyinBean; -import com.fisherbone.fuzhu.entity.SettingBean; -import com.fisherbone.fuzhu.entity.touchTaskBean; -import com.fisherbone.fuzhu.okgonet.HttpConstants; -import com.fisherbone.fuzhu.okgonet.NetApi; -import com.fisherbone.fuzhu.okgonet.Observer; -import com.fisherbone.fuzhu.reflect.InjectUtils; -import com.fisherbone.fuzhu.reflect.OnClickk; -import com.fisherbone.fuzhu.utils.EmojiFilter; -import com.fisherbone.fuzhu.utils.JsonUtils; -import com.fisherbone.fuzhu.utils.ProfileSpUtils; -import com.fisherbone.fuzhu.utils.QrCode; -import com.fisherbone.fuzhu.utils.SPUtils; -import com.fisherbone.fuzhu.utils.SystemUtil; -import com.fisherbone.fuzhu.utils.UpdateManager; -import com.fisherbone.fuzhu.utils.VersionUtils; -import com.fisherbone.fuzhu.utils.WidgetTools; -import com.fisherbone.fuzhu.widget.TitleBar; -import com.fisherbone.fuzhu.widget.streamlist.dataBean; -import com.google.gson.Gson; -import com.jeremyliao.liveeventbus.LiveEventBus; -import com.lzy.okgo.model.HttpParams; -import com.lzy.okgo.model.Response; -import com.tbruyelle.rxpermissions2.RxPermissions; -import com.xiangxue.common.network.TecentNetworkApi; -import com.xiangxue.common.network.observer.BaseObserver; - -import org.json.JSONException; -import org.json.JSONObject; - -import java.util.ArrayList; -import java.util.List; - -import io.reactivex.disposables.Disposable; - -/** - * 系统设置 - */ -public class SettingActivity extends BaseActivity { - private ActivitySettingBinding binding; - private TitleBar mTitleBar; - private static final int REQUEST_QRCODE = 0x01; - private UpdateManager mUpdateManager;//版本更新 - private DouyinDao douyinDao; - private String selectType="1"; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - binding = DataBindingUtil.setContentView(this, R.layout.activity_setting); - mTitleBar = (TitleBar) findViewById(R.id.title_bar); - mTitleBar.setTitle("系统设置"); - initNormalBack(); - douyinDao = new DouyinDao(SettingActivity.this); - InjectUtils.injectEvent(this); - if (ChangLiang.control_status.equals("1") && ProfileSpUtils.getInstance().getSetBean().isRedswitchone()) { - binding.setSwitch1.setChecked(true); - } else { - binding.setSwitch1.setChecked(false); - } - binding.tvVewsion.setText("v." + getVersionn()); - // 添加监听 - binding.setSwitch1.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { - @Override - public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { - if (isChecked) { - ToastUtils.showShort(isChecked + ""); - SettingBean settingBean = new SettingBean(true); - ProfileSpUtils.getInstance().saveSetBean(settingBean); - updateControlStatus("1"); - LiveEventBus.get("yunkong").post("open"); - ToastUtils.showShort("群控状态1" + ProfileSpUtils.getInstance().getSetBean().isRedswitchone() + ""); - } else { - ToastUtils.showShort(isChecked + ""); - SettingBean settingBean = new SettingBean(false); - updateControlStatus("0"); - ProfileSpUtils.getInstance().saveSetBean(settingBean); - LiveEventBus.get("yunkong").post("closed"); - ToastUtils.showShort("群控状态2" + ProfileSpUtils.getInstance().getSetBean().isRedswitchone() + ""); - } - } - }); - - binding.rlVersion.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - requestVersion(); - } - }); - binding.rlAut.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - ArrayList douyinBeans = douyinDao.queryAll(); - if (douyinBeans.size() != 3) { - ToastUtils.showShort("未获得3个抖音帐号"); - return; - } - String isactivation = (String) SPUtils.getSp(SettingActivity.this, FZConfig.IS_ACTIVATION, ""); - if (isactivation.equals("0")) { - ToastUtils.showShort("设备已激活"); - } else { - getPermissions(); - } - } - }); - binding.rlCan.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - new BaseTipsDialog().showDownloadDialog(SettingActivity.this, "确认注销该设备吗?", "确定", new BaseTipsDialog.ClickListener() { - @Override - public void confirm() { - String device_id = (String) SPUtils.getSp(SettingActivity.this, FZConfig.KEY_DEVICE_ID, ""); - zhuxiao(device_id); - } - - @Override - public void cancle() { - - } - }); - } - }); - - binding.rlOpenwuzhangai.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - AblUtil.openAccessibilitySettings(); - } - }); - - binding.rlOpenfuchuang.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - AblUtil.openDrawOverlaysAnth(SettingActivity.this); - } - }); - binding.rlGetdouyin.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - if (AblUtil.isAccessibilityServiceOpen(SettingActivity.this)) { - AblStepHandler.getInstance().setStop(false); - AblStepHandler.sendMsg(AblSteps.STEP_1); - - } else { - AblUtil.openAccessibilitySettings(); - } - } - }); - binding.rlJihuo.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - SPUtils.setSP(SettingActivity.this, FZConfig.IS_ACTIVATION, "0"); - } - }); - binding.rlDaoru.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - String s = binding.etLianxiren.getText().toString(); - if ("".equals(s)) { - ToastUtils.showShort("请输入导入通讯录的个数"); - return; - } - getPhoneNum(s); - - } - }); - binding.rlCeshi.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - Gson gson = new Gson(); - ArrayList douyinBeans1 = douyinDao.queryAll(); - String s1 = gson.toJson(douyinBeans1); - Log.e("TIAOSHI###提交的字符串", s1);//[{"login_status":"1","short_id":"xiao629972576","short_name":""}] - } - }); - } - - private void infoTv() { - String isactivation = (String) SPUtils.getSp(SettingActivity.this, FZConfig.IS_ACTIVATION, ""); - ArrayList douyinBeans = douyinDao.queryAll(); - if (douyinBeans.size() == 3 && isactivation.equals("0")) { - binding.tvAut.setText("激活授权(可授权)"); - } - } - - - @Override - protected void onResume() { - super.onResume(); - infoTv(); - } - - private void getPermissions() { - RxPermissions rxPermissions = new RxPermissions(this); - rxPermissions.request(Manifest.permission.CAMERA) - .subscribe(new io.reactivex.Observer() { - @Override - public void onSubscribe(Disposable d) { - - } - - @Override - public void onNext(Boolean aBoolean) { - if (aBoolean) { - QrCode qrCode = new QrCode(SettingActivity.this); - qrCode.startQrCode(); - } else { - ToastUtils.showShort("获取权限失败,请重新授权"); - } - } - - @Override - public void onError(Throwable e) { - - } - - @Override - public void onComplete() { - - } - }); - } - - - @OnClickk({R.id.rl_env}) - public void click(View view) { - switch (view.getId()) { - case R.id.rl_env: - ArrayList douyinBeans = douyinDao.queryAll(); - douyinDao.delete(douyinBeans); - if (AblUtil.isAccessibilityServiceOpen(SettingActivity.this)) { - AblStepHandler.getInstance().setStop(false); - AblStepHandler.sendMsg(AblSteps.STEP_50); - } else { - ToastUtils.showShort("请先开启辅助服务)))))))"); - } - - break; - default: - } - } - - @Override - protected void onActivityResult(int requestCode, int resultCode, Intent data) { - super.onActivityResult(requestCode, resultCode, data); - switch (requestCode) { - - case REQUEST_QRCODE: - if (resultCode == Activity.RESULT_OK) { - String code = data.getStringExtra("SCAN_RESULT"); - Log.e("扫码后的内容", code + ""); - jihuo(code); - } - break; - default: - } - } - - private void jihuo(String code) { - String device_id = (String) SPUtils.getSp(SettingActivity.this, FZConfig.KEY_DEVICE_ID, ""); - Gson gson = new Gson(); - ArrayList douyinBeans1 = douyinDao.queryAll(); - String s1 = gson.toJson(douyinBeans1); - Log.e("提交的字符串", s1);//[{"login_status":"1","short_id":"xiao629972576","short_name":""}] - String s = EmojiFilter.filterEmoji(s1);//去除字符串中包含的表情符号 - Log.e("提交的字符串(不包含表情符号)", s); - final HttpParams paramsPost = new HttpParams(); - paramsPost.put("device_id", device_id);//扫码(设备)id - paramsPost.put("douyin", s);// 抖音号 - // paramsPost.put("douyin", "[{\"short_id\":\"tangjie0501\",\"short_name\":\"软件工程师蝴蝶剑\",\"login_status\":\"1\"}]");// 抖音号[{"short_id":"tangjie0501","short_name":"软件工程师蝴蝶剑","login_status":"1"}] - paramsPost.put("online_status", "");//阿童木在线状态 - paramsPost.put("control_status", "");//控制状态 - paramsPost.put("network_type", "");//网络类型 - paramsPost.put("app_version", "1.0");//app版本 - paramsPost.put("douyin_version", "");//抖音版本 - paramsPost.put("system_version", Build.MODEL);//系统版本 - paramsPost.put("device_qrcode", code);//授权码 - paramsPost.put("phone_type", SystemUtil.getSystemModel());//手机型号 - new NetApi().getPostData(paramsPost, HttpConstants.URi_device_Appscanlogin_scanInfo).subscribe(new Observer() { - @Override - public void onNext(Response response) { - String body = (String) response.body(); - Log.e("返回的数据", body); - try { - JSONObject jsonObject = new JSONObject(body); - String msg = jsonObject.getString("msg"); - ToastUtils.showShort(msg); - String success = jsonObject.getString("success"); - if (success.equals("0")) { - SPUtils.setSP(SettingActivity.this, FZConfig.IS_ACTIVATION, "0"); - LiveEventBus.get("success").post("str"); - finish(); - } else { - com.fisherbone.fuzhu.utils.ToastUtils.showToast(SettingActivity.this, msg); - SPUtils.setSP(SettingActivity.this, FZConfig.IS_ACTIVATION, "0"); - } - - } catch (JSONException e) { - e.printStackTrace(); - } - - } - - @Override - public void onError(Exception e) { - e.printStackTrace(); - } - }); - } - - /** - * 修改设备控制状态 -- 云端还是本地 - */ - private void updateControlStatus(String control_status) { - final HttpParams paramsPost = new HttpParams(); - paramsPost.put("control_status", control_status);//网络类型1:云端 0:本地 - new NetApi().getPostData(paramsPost, HttpConstants.URi_device_Appoperate_updateControlStatus).subscribe(new Observer() { - @Override - public void onNext(Response response) { - String body = (String) response.body(); - try { - JSONObject jsonObject = new JSONObject(body); - String msg = jsonObject.getString("msg"); - String success = jsonObject.getString("success"); - if (success.equals("0")) { - LiveEventBus.get("success").post("str"); - } - - } catch (JSONException e) { - e.printStackTrace(); - } - - } - - @Override - public void onError(Exception e) { - e.printStackTrace(); - } - }); - } - - /** - * 获取电话号码 - */ - private void getPhoneNum(String s) { - String device_id = (String) SPUtils.getSp(SettingActivity.this, FZConfig.KEY_DEVICE_ID, ""); - TecentNetworkApi.getService(NewsApiInterface.class) - .getPhoneNum(device_id, s) - .subscribe(new BaseObserver() { - @Override - public void onSuccess(touchTaskBean urgentTaskBean) { - int success = urgentTaskBean.getSuccess(); - if (success == 0) { - List phoneNumber = urgentTaskBean.getData(); - //phoneNumber = urgentTaskBean.getData(); - //导入通讯录 - ContactsHelp.getInstance(SettingActivity.this).importContacts(phoneNumber); - } - } - - @Override - public void onFailure(Throwable e) { - Log.e("Error", "Message:" + e.getMessage()); - } - }); - } - - - /** - * 获取要注销的设备id - */ - private void getDeviceByDouyin() { - Gson gson = new Gson(); - ArrayList douyinBeans1 = douyinDao.queryAll(); - String s1 = gson.toJson(douyinBeans1); - Log.e("提交的字符串", s1);//[{"login_status":"1","short_id":"xiao629972576","short_name":""}] - String s = EmojiFilter.filterEmoji(s1);//去除字符串中包含的表情符号 - Log.e("提交的字符串(不包含表情符号)", s); - TecentNetworkApi.getService(NewsApiInterface.class) - .getDeviceByDouyin(s) - .subscribe(new BaseObserver() { - @Override - public void onSuccess(DeviceByDouyinBean urgentTaskBean) { - String s1 = gson.toJson(urgentTaskBean); - Log.e("jisdfsdfsdfsdf", s1);//[{"login_status":"1","short_id":"xiao629972576","short_name":""}] - int success = urgentTaskBean.getSuccess(); - if (success == 0) { - List data = urgentTaskBean.getData(); - SelectADialog selectADialog = new SelectADialog(SettingActivity.this, 0, data); - selectADialog.show(); - } - } - - @Override - public void onFailure(Throwable e) { - Log.e("Error", "Message:" + e.getMessage()); - } - }); - } - - /** - * 请求最新版本号 - */ - private void requestVersion() { - TecentNetworkApi.getService(NewsApiInterface.class) - .getNowVersion() - .subscribe(new BaseObserver() { - @Override - public void onSuccess(GetVesionResponseBean newsChannelsBean) { - Log.e("MainActivity", new Gson().toJson(newsChannelsBean)); - String newVersion = newsChannelsBean.getVersion(); - if (newVersion != null) { - String versionn = getVersionn(); - int versionUpdate = VersionUtils.compareVersion(versionn, newVersion); - if (VALUE_ZERO.equals(newsChannelsBean.getSuccess() + "")) { - if (versionUpdate == -1) {//两个版本相同 - ADialog mShareWechatDialog = new ADialog(SettingActivity.this, 0, newsChannelsBean); - mShareWechatDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);//代码中取消标题栏 - mShareWechatDialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); - Window win = mShareWechatDialog.getWindow(); - win.getDecorView().setPadding(0, 0, 0, 0); - WindowManager.LayoutParams lp = win.getAttributes(); - lp.width = WindowManager.LayoutParams.FILL_PARENT; - lp.height = WindowManager.LayoutParams.WRAP_CONTENT; - win.setAttributes(lp); - mShareWechatDialog.setCancelable(false); - mShareWechatDialog.show(); - } else {//没有最新版本 - ToastUtils.showShort("当前已是最新版本"); - } - } - } - } - - @Override - public void onFailure(Throwable e) { - Log.e("Error", "Message:" + e.getMessage()); - } - }); - - } - - class ADialog extends Dialog implements View.OnClickListener { - - private Context context; - GetVesionResponseBean mGetVesionResponseBean; - - public ADialog(@NonNull Context context, @StyleRes int themeResId, GetVesionResponseBean mGetVesionResponseBean) { - super(context, themeResId); - this.context = context; - this.mGetVesionResponseBean = mGetVesionResponseBean; - } - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - this.setContentView(R.layout.version_dailog); - - if (isHuaWei()) { - launchAppDetail(SettingActivity.this, "com.fanghoo.mendian", "com.huawei.appmarket"); - } else { - launchAppDetail(SettingActivity.this, "com.fanghoo.mendian", "com.tencent.android.qqdownloader"); - } - } - - public void launchAppDetail(final Context context, final String appPkg, final String marketPkg) { - - String content = mGetVesionResponseBean.getContent(); - content = content.replace("
", "
"); - TextView mContentTv = (TextView) findViewById(R.id.tv_content); - mContentTv.setText(Html.fromHtml(content)); - TextView mVersionTv = (TextView) findViewById(R.id.tv_version); - mVersionTv.setText("V" + mGetVesionResponseBean.getVersion()); - Button mUpdateBtn = (Button) findViewById(R.id.btn_update); - Button btn_update_one = (Button) findViewById(R.id.btn_update_one); - mUpdateBtn.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - dismiss(); - // 这里来检测版本是否需要更新 - mUpdateManager = new UpdateManager(SettingActivity.this, "http://139.186.151.48/apk/atom-latest.apk"); - mUpdateManager.checkUpdateDownload(); - // Log.d("apkUrl", apkUrl); - } - }); - btn_update_one.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - dismiss(); - } - }); - } - - @Override - public void onClick(View v) { - } - } - - - class SelectADialog extends Dialog implements View.OnClickListener { - - private Context context; - List data; - - public SelectADialog(@NonNull Context context, @StyleRes int themeResId, List data) { - super(context, themeResId); - this.context = context; - this.data = data; - } - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - this.setContentView(R.layout.douyindevice_dialog); - RecyclerView reply_rcey = findViewById(R.id.device_recy); - TextView tvSexCancel = findViewById(R.id.tvSexCancel); - TextView tvSexSend = findViewById(R.id.tvSexSend); - tvSexCancel.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - dismiss(); - } - }); - tvSexSend.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - dismiss(); - for (int i = 0; i < data.size(); i++) { - DeviceByDouyinBean.DataBean dataBean = data.get(i); - if (dataBean.getIf_sel_del().equals("1")) { - String device_id = dataBean.getDevice_id(); - zhuxiao(device_id); - } - } - } - }); - - LinearLayoutManager manager = new LinearLayoutManager(SettingActivity.this); - reply_rcey.setLayoutManager(manager); - reply_rcey.setAdapter(new BaseQuickAdapter(R.layout.item_reply_dialog, data) { - @Override - protected void convert(final BaseViewHolder helper, final DeviceByDouyinBean.DataBean item) { - WidgetTools.setTextfive((TextView) helper.getView(R.id.img_modify), "", helper.getAdapterPosition()+1+"."+item.getDevice_name()); - ImageView ima_word = helper.getView(R.id.ima_word); - if (item.getIf_sel_del().equals("0")) { - ima_word.setImageResource(R.mipmap.icon_cheched_false); - } else { - ima_word.setImageResource(R.mipmap.icon_cheched_true); - } - helper.getView(R.id.ima_word).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - //本次选择 - if (IsSelecet(helper.getAdapterPosition())) { - cancalchoose(helper.getAdapterPosition()); - } else { - //selectType 0为单选 1为多选 - if (selectType.equals("0")) { - //先清除上次选中状态 - for (int i = 0; i < data.size(); i++) { - DeviceByDouyinBean.DataBean dataBean = data.get(i); - if (dataBean.getIf_sel_del().equals("1")) { - cancalchoose(i); - } - } - } - selecttrue(helper.getAdapterPosition()); - - } - notifyDataSetChanged(); - } - }); - - } - }); - - } - - @Override - public void onClick(View v) { - } - - /** - * 选中(单选) - * - * @return - */ - private void selecttrue(int position) { - data.get(position).setIf_sel_del("1"); - } - /** - * 取消 - * - * @return - */ - private void cancalchoose(int childposition) { - data.get(childposition).setIf_sel_del("0"); - } - - /** - * 当前条目是否选中 - * - * @return - */ - public boolean IsSelecet(int childposition) { - - if (data.get(childposition).getIf_sel_del().equals("1")) { - return true; - } else { - return false; - } - } - } - - - public static boolean isHuaWei() { - String manufacturer = Build.MANUFACTURER; - //这个字符串可以自己定义,例如判断华为就填写huawei,魅族就填写meizu - if ("huawei".equalsIgnoreCase(manufacturer)) { - return true; - } - return false; - } - - private void zhuxiao(String device_id) { - - final HttpParams paramsPost = new HttpParams(); - paramsPost.put("device_id", device_id);//扫码(设备)id - new NetApi().getPostData(paramsPost, HttpConstants.URi_Device_Appscanlogin_cancellationDevice).subscribe(new Observer() { - @Override - public void onNext(Response response) { - String body = (String) response.body(); - Log.e("返回的数据", body); - SPUtils.setSP(SettingActivity.this, FZConfig.IS_ACTIVATION, "1"); - try { - JSONObject jsonObject = new JSONObject(body); - String success = jsonObject.getString("success"); - String msg = jsonObject.getString("msg"); - ToastUtils.showShort(msg); - if("1".equals(success)){ - - }else if("2".equals(success)){ - getDeviceByDouyin(); - } - - } catch (JSONException e) { - e.printStackTrace(); - } - } - - @Override - public void onError(Exception e) { - e.printStackTrace(); - } - }); - } +package com.fisherbone.fuzhu.activity; + +import android.Manifest; +import android.app.Activity; +import android.app.Dialog; +import android.content.Context; +import android.content.Intent; +import android.graphics.Color; +import android.graphics.drawable.ColorDrawable; +import android.os.Build; +import android.os.Bundle; +import android.text.Html; +import android.util.Log; +import android.view.View; +import android.view.Window; +import android.view.WindowManager; +import android.widget.Button; +import android.widget.CompoundButton; +import android.widget.ImageView; +import android.widget.TextView; + +import androidx.annotation.NonNull; +import androidx.annotation.StyleRes; +import androidx.databinding.DataBindingUtil; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; + +import com.blankj.utilcode.util.ToastUtils; +import com.chad.library.adapter.base.BaseQuickAdapter; +import com.chad.library.adapter.base.BaseViewHolder; +import com.fisherbone.ContactsHelp; +import com.fisherbone.fuzhu.BaseActivity; +import com.fisherbone.fuzhu.ChangLiang; +import com.fisherbone.fuzhu.FZConfig; +import com.fisherbone.fuzhu.R; +import com.fisherbone.fuzhu.abllib.AblStepHandler; +import com.fisherbone.fuzhu.abllib.AblSteps; +import com.fisherbone.fuzhu.abllib.utils.AblUtil; +import com.fisherbone.fuzhu.api.GetVesionResponseBean; +import com.fisherbone.fuzhu.api.NewsApiInterface; +import com.fisherbone.fuzhu.databinding.ActivitySettingBinding; +import com.fisherbone.fuzhu.db.DouyinBean; +import com.fisherbone.fuzhu.db.dao.DouyinDao; +import com.fisherbone.fuzhu.db.zhuanghaoBeanData; +import com.fisherbone.fuzhu.dialog.BaseTipsDialog; +import com.fisherbone.fuzhu.entity.DakaVideoBean; +import com.fisherbone.fuzhu.entity.DeviceByDouyinBean; +import com.fisherbone.fuzhu.entity.SettingBean; +import com.fisherbone.fuzhu.entity.touchTaskBean; +import com.fisherbone.fuzhu.okgonet.HttpConstants; +import com.fisherbone.fuzhu.okgonet.NetApi; +import com.fisherbone.fuzhu.okgonet.Observer; +import com.fisherbone.fuzhu.reflect.InjectUtils; +import com.fisherbone.fuzhu.reflect.OnClickk; +import com.fisherbone.fuzhu.utils.EmojiFilter; +import com.fisherbone.fuzhu.utils.JsonUtils; +import com.fisherbone.fuzhu.utils.ProfileSpUtils; +import com.fisherbone.fuzhu.utils.QrCode; +import com.fisherbone.fuzhu.utils.SPUtils; +import com.fisherbone.fuzhu.utils.SystemUtil; +import com.fisherbone.fuzhu.utils.UpdateManager; +import com.fisherbone.fuzhu.utils.VersionUtils; +import com.fisherbone.fuzhu.utils.WidgetTools; +import com.fisherbone.fuzhu.widget.TitleBar; +import com.fisherbone.fuzhu.widget.streamlist.dataBean; +import com.google.gson.Gson; +import com.jeremyliao.liveeventbus.LiveEventBus; +import com.lzy.okgo.model.HttpParams; +import com.lzy.okgo.model.Response; +import com.tbruyelle.rxpermissions2.RxPermissions; +import com.xiangxue.common.network.TecentNetworkApi; +import com.xiangxue.common.network.observer.BaseObserver; + +import org.json.JSONException; +import org.json.JSONObject; + +import java.util.ArrayList; +import java.util.List; + +import io.reactivex.disposables.Disposable; + +/** + * 系统设置 + */ +public class SettingActivity extends BaseActivity { + private ActivitySettingBinding binding; + private TitleBar mTitleBar; + private static final int REQUEST_QRCODE = 0x01; + private UpdateManager mUpdateManager;//版本更新 + private DouyinDao douyinDao; + private String selectType="1"; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + binding = DataBindingUtil.setContentView(this, R.layout.activity_setting); + mTitleBar = (TitleBar) findViewById(R.id.title_bar); + mTitleBar.setTitle("系统设置"); + initNormalBack(); + douyinDao = new DouyinDao(SettingActivity.this); + InjectUtils.injectEvent(this); + if (ChangLiang.control_status.equals("1") && ProfileSpUtils.getInstance().getSetBean().isRedswitchone()) { + binding.switchMsgNotification.setChecked(true); + } else { + binding.switchMsgNotification.setChecked(false); + } + binding.tvVewsion.setText("v." + getVersionn()); + // 添加监听 + binding.switchMsgNotification.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { + if (isChecked) { + ToastUtils.showShort(isChecked + ""); + SettingBean settingBean = new SettingBean(true); + ProfileSpUtils.getInstance().saveSetBean(settingBean); + updateControlStatus("1"); + LiveEventBus.get("yunkong").post("open"); + ToastUtils.showShort("群控状态1" + ProfileSpUtils.getInstance().getSetBean().isRedswitchone() + ""); + } else { + ToastUtils.showShort(isChecked + ""); + SettingBean settingBean = new SettingBean(false); + updateControlStatus("0"); + ProfileSpUtils.getInstance().saveSetBean(settingBean); + LiveEventBus.get("yunkong").post("closed"); + ToastUtils.showShort("群控状态2" + ProfileSpUtils.getInstance().getSetBean().isRedswitchone() + ""); + } + } + }); + + binding.rlVersion.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + requestVersion(); + } + }); + binding.rlAut.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + ArrayList douyinBeans = douyinDao.queryAll(); + if (douyinBeans.size() != 3) { + ToastUtils.showShort("未获得3个抖音帐号"); + return; + } + String isactivation = (String) SPUtils.getSp(SettingActivity.this, FZConfig.IS_ACTIVATION, ""); + if (isactivation.equals("0")) { + ToastUtils.showShort("设备已激活"); + } else { + getPermissions(); + } + } + }); + binding.rlCan.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + new BaseTipsDialog().showDownloadDialog(SettingActivity.this, "确认注销该设备吗?", "确定", new BaseTipsDialog.ClickListener() { + @Override + public void confirm() { + String device_id = (String) SPUtils.getSp(SettingActivity.this, FZConfig.KEY_DEVICE_ID, ""); + zhuxiao(device_id); + } + + @Override + public void cancle() { + + } + }); + } + }); + + binding.rlOpenwuzhangai.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + AblUtil.openAccessibilitySettings(); + } + }); + + binding.rlOpenfuchuang.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + AblUtil.openDrawOverlaysAnth(SettingActivity.this); + } + }); + binding.rlGetdouyin.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + if (AblUtil.isAccessibilityServiceOpen(SettingActivity.this)) { + AblStepHandler.getInstance().setStop(false); + AblStepHandler.sendMsg(AblSteps.STEP_1); + + } else { + AblUtil.openAccessibilitySettings(); + } + } + }); + binding.rlJihuo.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + SPUtils.setSP(SettingActivity.this, FZConfig.IS_ACTIVATION, "0"); + } + }); + binding.rlDaoru.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + String s = binding.etLianxiren.getText().toString(); + if ("".equals(s)) { + ToastUtils.showShort("请输入导入通讯录的个数"); + return; + } + getPhoneNum(s); + + } + }); + binding.rlCeshi.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + Gson gson = new Gson(); + ArrayList douyinBeans1 = douyinDao.queryAll(); + String s1 = gson.toJson(douyinBeans1); + Log.e("TIAOSHI###提交的字符串", s1);//[{"login_status":"1","short_id":"xiao629972576","short_name":""}] + } + }); + } + + private void infoTv() { + String isactivation = (String) SPUtils.getSp(SettingActivity.this, FZConfig.IS_ACTIVATION, ""); + ArrayList douyinBeans = douyinDao.queryAll(); + if (douyinBeans.size() == 3 && isactivation.equals("0")) { + binding.tvAut.setText("激活授权(可授权)"); + } + } + + + @Override + protected void onResume() { + super.onResume(); + infoTv(); + } + + private void getPermissions() { + RxPermissions rxPermissions = new RxPermissions(this); + rxPermissions.request(Manifest.permission.CAMERA) + .subscribe(new io.reactivex.Observer() { + @Override + public void onSubscribe(Disposable d) { + + } + + @Override + public void onNext(Boolean aBoolean) { + if (aBoolean) { + QrCode qrCode = new QrCode(SettingActivity.this); + qrCode.startQrCode(); + } else { + ToastUtils.showShort("获取权限失败,请重新授权"); + } + } + + @Override + public void onError(Throwable e) { + + } + + @Override + public void onComplete() { + + } + }); + } + + + @OnClickk({R.id.rl_env}) + public void click(View view) { + int id = view.getId(); + if (id == R.id.rl_env) { + ArrayList douyinBeans = douyinDao.queryAll(); + douyinDao.delete(douyinBeans); + if (AblUtil.isAccessibilityServiceOpen(SettingActivity.this)) { + AblStepHandler.getInstance().setStop(false); + AblStepHandler.sendMsg(AblSteps.STEP_50); + } else { + ToastUtils.showShort("请先开启辅助服务)))))))"); + } + } + } + + @Override + protected void onActivityResult(int requestCode, int resultCode, Intent data) { + super.onActivityResult(requestCode, resultCode, data); + switch (requestCode) { + + case REQUEST_QRCODE: + if (resultCode == Activity.RESULT_OK) { + String code = data.getStringExtra("SCAN_RESULT"); + Log.e("扫码后的内容", code + ""); + jihuo(code); + } + break; + default: + } + } + + private void jihuo(String code) { + String device_id = (String) SPUtils.getSp(SettingActivity.this, FZConfig.KEY_DEVICE_ID, ""); + Gson gson = new Gson(); + ArrayList douyinBeans1 = douyinDao.queryAll(); + String s1 = gson.toJson(douyinBeans1); + Log.e("提交的字符串", s1);//[{"login_status":"1","short_id":"xiao629972576","short_name":""}] + String s = EmojiFilter.filterEmoji(s1);//去除字符串中包含的表情符号 + Log.e("提交的字符串(不包含表情符号)", s); + final HttpParams paramsPost = new HttpParams(); + paramsPost.put("device_id", device_id);//扫码(设备)id + paramsPost.put("douyin", s);// 抖音号 + // paramsPost.put("douyin", "[{\"short_id\":\"tangjie0501\",\"short_name\":\"软件工程师蝴蝶剑\",\"login_status\":\"1\"}]");// 抖音号[{"short_id":"tangjie0501","short_name":"软件工程师蝴蝶剑","login_status":"1"}] + paramsPost.put("online_status", "");//阿童木在线状态 + paramsPost.put("control_status", "");//控制状态 + paramsPost.put("network_type", "");//网络类型 + paramsPost.put("app_version", "1.0");//app版本 + paramsPost.put("douyin_version", "");//抖音版本 + paramsPost.put("system_version", Build.MODEL);//系统版本 + paramsPost.put("device_qrcode", code);//授权码 + paramsPost.put("phone_type", SystemUtil.getSystemModel());//手机型号 + new NetApi().getPostData(paramsPost, HttpConstants.URi_device_Appscanlogin_scanInfo).subscribe(new Observer() { + @Override + public void onNext(Response response) { + String body = (String) response.body(); + Log.e("返回的数据", body); + try { + JSONObject jsonObject = new JSONObject(body); + String msg = jsonObject.getString("msg"); + ToastUtils.showShort(msg); + String success = jsonObject.getString("success"); + if (success.equals("0")) { + SPUtils.setSP(SettingActivity.this, FZConfig.IS_ACTIVATION, "0"); + LiveEventBus.get("success").post("str"); + finish(); + } else { + com.fisherbone.fuzhu.utils.ToastUtils.showToast(SettingActivity.this, msg); + SPUtils.setSP(SettingActivity.this, FZConfig.IS_ACTIVATION, "0"); + } + + } catch (JSONException e) { + e.printStackTrace(); + } + + } + + @Override + public void onError(Exception e) { + e.printStackTrace(); + } + }); + } + + /** + * 修改设备控制状态 -- 云端还是本地 + */ + private void updateControlStatus(String control_status) { + final HttpParams paramsPost = new HttpParams(); + paramsPost.put("control_status", control_status);//网络类型1:云端 0:本地 + new NetApi().getPostData(paramsPost, HttpConstants.URi_device_Appoperate_updateControlStatus).subscribe(new Observer() { + @Override + public void onNext(Response response) { + String body = (String) response.body(); + try { + JSONObject jsonObject = new JSONObject(body); + String msg = jsonObject.getString("msg"); + String success = jsonObject.getString("success"); + if (success.equals("0")) { + LiveEventBus.get("success").post("str"); + } + + } catch (JSONException e) { + e.printStackTrace(); + } + + } + + @Override + public void onError(Exception e) { + e.printStackTrace(); + } + }); + } + + /** + * 获取电话号码 + */ + private void getPhoneNum(String s) { + String device_id = (String) SPUtils.getSp(SettingActivity.this, FZConfig.KEY_DEVICE_ID, ""); + TecentNetworkApi.getService(NewsApiInterface.class) + .getPhoneNum(device_id, s) + .subscribe(new BaseObserver() { + @Override + public void onSuccess(touchTaskBean urgentTaskBean) { + int success = urgentTaskBean.getSuccess(); + if (success == 0) { + List phoneNumber = urgentTaskBean.getData(); + //phoneNumber = urgentTaskBean.getData(); + //导入通讯录 + ContactsHelp.getInstance(SettingActivity.this).importContacts(phoneNumber); + } + } + + @Override + public void onFailure(Throwable e) { + Log.e("Error", "Message:" + e.getMessage()); + } + }); + } + + + /** + * 获取要注销的设备id + */ + private void getDeviceByDouyin() { + Gson gson = new Gson(); + ArrayList douyinBeans1 = douyinDao.queryAll(); + String s1 = gson.toJson(douyinBeans1); + Log.e("提交的字符串", s1);//[{"login_status":"1","short_id":"xiao629972576","short_name":""}] + String s = EmojiFilter.filterEmoji(s1);//去除字符串中包含的表情符号 + Log.e("提交的字符串(不包含表情符号)", s); + TecentNetworkApi.getService(NewsApiInterface.class) + .getDeviceByDouyin(s) + .subscribe(new BaseObserver() { + @Override + public void onSuccess(DeviceByDouyinBean urgentTaskBean) { + String s1 = gson.toJson(urgentTaskBean); + Log.e("jisdfsdfsdfsdf", s1);//[{"login_status":"1","short_id":"xiao629972576","short_name":""}] + int success = urgentTaskBean.getSuccess(); + if (success == 0) { + List data = urgentTaskBean.getData(); + SelectADialog selectADialog = new SelectADialog(SettingActivity.this, 0, data); + selectADialog.show(); + } + } + + @Override + public void onFailure(Throwable e) { + Log.e("Error", "Message:" + e.getMessage()); + } + }); + } + + /** + * 请求最新版本号 + */ + private void requestVersion() { + TecentNetworkApi.getService(NewsApiInterface.class) + .getNowVersion() + .subscribe(new BaseObserver() { + @Override + public void onSuccess(GetVesionResponseBean newsChannelsBean) { + Log.e("MainActivity", new Gson().toJson(newsChannelsBean)); + String newVersion = newsChannelsBean.getVersion(); + if (newVersion != null) { + String versionn = getVersionn(); + int versionUpdate = VersionUtils.compareVersion(versionn, newVersion); + if (VALUE_ZERO.equals(newsChannelsBean.getSuccess() + "")) { + if (versionUpdate == -1) {//两个版本相同 + ADialog mShareWechatDialog = new ADialog(SettingActivity.this, 0, newsChannelsBean); + mShareWechatDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);//代码中取消标题栏 + mShareWechatDialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); + Window win = mShareWechatDialog.getWindow(); + win.getDecorView().setPadding(0, 0, 0, 0); + WindowManager.LayoutParams lp = win.getAttributes(); + lp.width = WindowManager.LayoutParams.FILL_PARENT; + lp.height = WindowManager.LayoutParams.WRAP_CONTENT; + win.setAttributes(lp); + mShareWechatDialog.setCancelable(false); + mShareWechatDialog.show(); + } else {//没有最新版本 + ToastUtils.showShort("当前已是最新版本"); + } + } + } + } + + @Override + public void onFailure(Throwable e) { + Log.e("Error", "Message:" + e.getMessage()); + } + }); + + } + + class ADialog extends Dialog implements View.OnClickListener { + + private Context context; + GetVesionResponseBean mGetVesionResponseBean; + + public ADialog(@NonNull Context context, @StyleRes int themeResId, GetVesionResponseBean mGetVesionResponseBean) { + super(context, themeResId); + this.context = context; + this.mGetVesionResponseBean = mGetVesionResponseBean; + } + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + this.setContentView(R.layout.version_dailog); + + if (isHuaWei()) { + launchAppDetail(SettingActivity.this, "com.fanghoo.mendian", "com.huawei.appmarket"); + } else { + launchAppDetail(SettingActivity.this, "com.fanghoo.mendian", "com.tencent.android.qqdownloader"); + } + } + + public void launchAppDetail(final Context context, final String appPkg, final String marketPkg) { + + String content = mGetVesionResponseBean.getContent(); + content = content.replace("
", "
"); + TextView mContentTv = (TextView) findViewById(R.id.tv_content); + mContentTv.setText(Html.fromHtml(content)); + TextView mVersionTv = (TextView) findViewById(R.id.tv_version); + mVersionTv.setText("V" + mGetVesionResponseBean.getVersion()); + Button mUpdateBtn = (Button) findViewById(R.id.btn_update); + Button btn_update_one = (Button) findViewById(R.id.btn_update_one); + mUpdateBtn.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + dismiss(); + // 这里来检测版本是否需要更新 + mUpdateManager = new UpdateManager(SettingActivity.this, "http://139.186.151.48/apk/atom-latest.apk"); + mUpdateManager.checkUpdateDownload(); + // Log.d("apkUrl", apkUrl); + } + }); + btn_update_one.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + dismiss(); + } + }); + } + + @Override + public void onClick(View v) { + } + } + + + class SelectADialog extends Dialog implements View.OnClickListener { + + private Context context; + List data; + + public SelectADialog(@NonNull Context context, @StyleRes int themeResId, List data) { + super(context, themeResId); + this.context = context; + this.data = data; + } + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + this.setContentView(R.layout.douyindevice_dialog); + RecyclerView reply_rcey = findViewById(R.id.device_recy); + TextView tvSexCancel = findViewById(R.id.tvSexCancel); + TextView tvSexSend = findViewById(R.id.tvSexSend); + tvSexCancel.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + dismiss(); + } + }); + tvSexSend.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + dismiss(); + for (int i = 0; i < data.size(); i++) { + DeviceByDouyinBean.DataBean dataBean = data.get(i); + if (dataBean.getIf_sel_del().equals("1")) { + String device_id = dataBean.getDevice_id(); + zhuxiao(device_id); + } + } + } + }); + + LinearLayoutManager manager = new LinearLayoutManager(SettingActivity.this); + reply_rcey.setLayoutManager(manager); + reply_rcey.setAdapter(new BaseQuickAdapter(R.layout.item_reply_dialog, data) { + @Override + protected void convert(final BaseViewHolder helper, final DeviceByDouyinBean.DataBean item) { + WidgetTools.setTextfive((TextView) helper.getView(R.id.img_modify), "", helper.getAdapterPosition()+1+"."+item.getDevice_name()); + ImageView ima_word = helper.getView(R.id.ima_word); + if (item.getIf_sel_del().equals("0")) { + ima_word.setImageResource(R.mipmap.icon_cheched_false); + } else { + ima_word.setImageResource(R.mipmap.icon_cheched_true); + } + helper.getView(R.id.ima_word).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + //本次选择 + if (IsSelecet(helper.getAdapterPosition())) { + cancalchoose(helper.getAdapterPosition()); + } else { + //selectType 0为单选 1为多选 + if (selectType.equals("0")) { + //先清除上次选中状态 + for (int i = 0; i < data.size(); i++) { + DeviceByDouyinBean.DataBean dataBean = data.get(i); + if (dataBean.getIf_sel_del().equals("1")) { + cancalchoose(i); + } + } + } + selecttrue(helper.getAdapterPosition()); + + } + notifyDataSetChanged(); + } + }); + + } + }); + + } + + @Override + public void onClick(View v) { + } + + /** + * 选中(单选) + * + * @return + */ + private void selecttrue(int position) { + data.get(position).setIf_sel_del("1"); + } + /** + * 取消 + * + * @return + */ + private void cancalchoose(int childposition) { + data.get(childposition).setIf_sel_del("0"); + } + + /** + * 当前条目是否选中 + * + * @return + */ + public boolean IsSelecet(int childposition) { + + if (data.get(childposition).getIf_sel_del().equals("1")) { + return true; + } else { + return false; + } + } + } + + + public static boolean isHuaWei() { + String manufacturer = Build.MANUFACTURER; + //这个字符串可以自己定义,例如判断华为就填写huawei,魅族就填写meizu + if ("huawei".equalsIgnoreCase(manufacturer)) { + return true; + } + return false; + } + + private void zhuxiao(String device_id) { + + final HttpParams paramsPost = new HttpParams(); + paramsPost.put("device_id", device_id);//扫码(设备)id + new NetApi().getPostData(paramsPost, HttpConstants.URi_Device_Appscanlogin_cancellationDevice).subscribe(new Observer() { + @Override + public void onNext(Response response) { + String body = (String) response.body(); + Log.e("返回的数据", body); + SPUtils.setSP(SettingActivity.this, FZConfig.IS_ACTIVATION, "1"); + try { + JSONObject jsonObject = new JSONObject(body); + String success = jsonObject.getString("success"); + String msg = jsonObject.getString("msg"); + ToastUtils.showShort(msg); + if("1".equals(success)){ + + }else if("2".equals(success)){ + getDeviceByDouyin(); + } + + } catch (JSONException e) { + e.printStackTrace(); + } + } + + @Override + public void onError(Exception e) { + e.printStackTrace(); + } + }); + } } \ No newline at end of file diff --git a/app/src/main/java/com/fisherbone/fuzhu/step/TestAblStep2.java b/app/src/main/java/com/fisherbone/fuzhu/step/TestAblStep2.java index 514786f..6582f55 100644 --- a/app/src/main/java/com/fisherbone/fuzhu/step/TestAblStep2.java +++ b/app/src/main/java/com/fisherbone/fuzhu/step/TestAblStep2.java @@ -1,231 +1,231 @@ -package com.fisherbone.fuzhu.step; - -import android.graphics.Rect; -import android.os.Message; -import android.util.Log; -import android.view.accessibility.AccessibilityNodeInfo; - -import com.fisherbone.fuzhu.ChangLiang; -import com.fisherbone.fuzhu.abllib.AblService; -import com.fisherbone.fuzhu.abllib.AblStepHandler; -import com.fisherbone.fuzhu.abllib.AblSteps; -import com.fisherbone.fuzhu.abllib.BaseAblStep; -import com.fisherbone.fuzhu.abllib.utils.AblViewUtil; -import com.fisherbone.fuzhu.okgonet.HttpConstants; -import com.fisherbone.fuzhu.okgonet.NetApi; -import com.lzy.okgo.model.HttpParams; -import com.lzy.okgo.model.Response; - -import org.json.JSONException; -import org.json.JSONObject; - -import java.util.List; - - -public class TestAblStep2 extends BaseAblStep { - @Override - public void onStep(int step, Message msg) { - switch (step) { - case AblSteps.STEP_3: - AblViewUtil.startApplication(); - AblViewUtil.mySleep(2); - allowed(); - AblViewUtil.mySleep(6); - AblStepHandler.sendMsg(AblSteps.STEP_4); - // AblService.getInstance().performGlobalAction(AccessibilityService.GLOBAL_ACTION_POWER_DIALOG); - //打开快速设置 - // AblService.getInstance().performGlobalAction(AccessibilityService.GLOBAL_ACTION_QUICK_SETTINGS); - // AblService.getInstance().performGlobalAction(AccessibilityService.GLOBAL_ACTION_RECENTS); - break; - case AblSteps.STEP_4: - closedtjDialog(AblService.getInstance()); - AblViewUtil.mySleep(1); - setdoyinQDialog(AblService.getInstance()); - AblViewUtil.mySleep(1); - //1.关闭检测到更新的弹框 - closedJDialog(AblService.getInstance()); - AblViewUtil.mySleep(1); - //2.关闭青少年弹窗 - closedQDialog(AblService.getInstance()); - AblViewUtil.mySleep(1); - closedBDialog(AblService.getInstance()); - AblViewUtil.mySleep(1); - - AblStepHandler.sendMsg(AblSteps.STEP_5); - break; - case AblSteps.STEP_5: - - AblService instance = AblService.getInstance(); - AblViewUtil.mySleep(2); - instance.clickPoint(972, 2112, 300); - Log.e("TIAOSHI###", "点击了我按钮"); - AblViewUtil.mySleep(2); - //Xiaomi M2007J22C Android 10, API 29 - //atom运行检查 - boolean normaa = wodeNorma(); - if (normaa) { - Log.e("TIAOSHI###", "页面在我的页面运行正常"); - againStart("1"); - } else { - Log.e("TIAOSHI###", "页面在我的页面运行异常"); - againStart("0"); - } - - - //等待2秒点击更多按钮([624,75][688,139]) - AblViewUtil.mySleep(2); - - instance.clickPoint(989, 170, 300); - Log.e("TIAOSHI###", "点击了更多按钮"); - - - //等待2秒点击设置按钮([220,1023][720,1143]) - AblViewUtil.mySleep(2); - - instance.clickPoint(584, 1790, 300); - Log.e("TIAOSHI###", "点击了设置按钮"); - - - //等待2秒向上滑动 - AblViewUtil.mySleep(2); - instance.randomSwipe(); - - //等待2秒点击切换账户 - AblViewUtil.mySleep(2); - AccessibilityNodeInfo zhaohao = AblViewUtil.findByText("切换帐号", 0); - if(zhaohao==null){ - Log.e("TIAOSHI###", "没有找到切换帐号" ); - }else { - Log.e("TIAOSHI###", "弹出了个人信息保护指引的弹窗" ); - clickNodeInfo(zhaohao,"切换帐号"); - } - - AblViewUtil.mySleep(2); - //atom运行检查 - boolean norma = ZhongHaoNorma(); - if (norma) { - Log.e("TIAOSHI###", "页面在切换账号页面运行正常"); - againStart("1"); - } else { - Log.e("TIAOSHI###", "页面在切换账号页面运行异常"); - againStart("0"); - } - //获取一屏幕数据:快照 - AccessibilityNodeInfo roott = instance.getRootInActiveWindow(); - String shortname = ChangLiang.task_short_name; - if(shortname.contains("T")){ - shortname = shortname.substring(0, shortname.indexOf("T")-1); - Log.e("TIAOSHI###", "----获取用户昵称:" +shortname); - } - List idsj = roott.findAccessibilityNodeInfosByText(shortname); - if(idsj.size()>0) { - String nodeInfofir = getNodeInfofir(); - Log.e("TIAOSHI###", "获得的昵称"+nodeInfofir+" shortname=="+shortname); - if (nodeInfofir.contains(shortname)) { - Log.e("TIAOSHI###", "有任务派的抖音号,并且在第一个位置上"); - AblViewUtil.mySleep(1); - AblViewUtil.back(); - AblViewUtil.mySleep(1); - AblViewUtil.back(); - AblViewUtil.mySleep(1); - AblViewUtil.back(); - } else { - instance.clickcommon(idsj, ChangLiang.task_short_name); - } - }else { - Log.e("TIAOSHI###", "没有任务派的抖音号"); - UpdateTuoguan(); - } - break; - default: - } - } - private void UpdateTuoguan() { - final HttpParams paramsPost = new HttpParams(); - paramsPost.put("short_id", ChangLiang.short_id); - paramsPost.put("tuoguan_type", "1"); - new NetApi().getPostData(paramsPost, HttpConstants.URi_Device_Appscanlogin_UpdateTuoguan).subscribe(new com.fisherbone.fuzhu.okgonet.Observer() { - @Override - public void onNext(Response response) { - String body = (String) response.body(); - try { - JSONObject jsonObject = new JSONObject(body); - String msg = jsonObject.getString("msg"); - String success = jsonObject.getString("success"); - if ("0".equals(success)) { - Log.e("TIAOSHI###", "提交帐号异常" + msg); - } - } catch (JSONException e) { - e.printStackTrace(); - } - } - - @Override - public void onError(Exception e) { - e.printStackTrace(); - } - }); - } - - - /** - * 寻找控件 - */ - public String getNodeInfofir() { - String name = ""; - AccessibilityNodeInfo root = AblService.getInstance().getRootInActiveWindow(); - for (int i = 0; i < root.getChildCount(); i++) { - AccessibilityNodeInfo child = root.getChild(i); - // Log.e("TIAOSHI###", "----oneNode:" + child.getClassName() + ":" + child.getText() + ":" + child.getContentDescription()); - // nodeZuobiao(child); - for (int y = 0; y < child.getChildCount(); y++) { - AccessibilityNodeInfo child1 = child.getChild(y); -// Log.e("TIAOSHI###", "----twoNode:" + child1.getClassName() + ":" + child1.getText() + ":" + child1.getContentDescription()); -// nodeZuobiao(child1); - for (int j = 0; j < child1.getChildCount(); j++) { - AccessibilityNodeInfo child2 = child1.getChild(j); - Log.e("TIAOSHI###", "----threeNode:" + child2.getClassName() + ":" + child2.getText() + ":" + child2.getContentDescription()); - nodeZuobiao(child2); - Rect rect = new Rect(); - if (child2 != null) { - child2.getBoundsInScreen(rect); - if (rect.top >= 253 && rect.bottom <= 404) { - Log.e("TIAOSHI###", "----fourNode:" + child2.getClassName() + ":" + child2.getText() + ":" + child2.getContentDescription()); - if ("android.widget.TextView".equals(child2.getClassName())) { - if (child2.getText() != null) { - String s = child2.getText().toString(); - name = s; - } - } - } - } - } - } - } - return name; - } - - @Override - public boolean allowed() { - boolean ifOpen = false; - AccessibilityNodeInfo root = AblService.getInstance().getRootInActiveWindow(); - for (int i = 0; i < root.getChildCount(); i++) { - AccessibilityNodeInfo child = root.getChild(i); - if(child!=null) { - // Log.e("TIAOSHI###", "----oneNode:" + child.getClassName() + ":" + child.getText() + ":" + child.getContentDescription()); - if ("android.widget.TextView".equals(child.getClassName())) { - if (child.getText() != null) { - if (child.getText().toString().contains("正在尝试开启") || child.getText().toString().contains("是否允许")) { - int childCount = root.getChildCount(); - AccessibilityNodeInfo child1 = root.getChild(childCount - 1); - clickNodeInfo(child1, "点击了允许"); - } - } - ifOpen = true; - } - } - } - return ifOpen; - } - -} +package com.fisherbone.fuzhu.step; + +import android.graphics.Rect; +import android.os.Message; +import android.util.Log; +import android.view.accessibility.AccessibilityNodeInfo; + +import com.fisherbone.fuzhu.ChangLiang; +import com.fisherbone.fuzhu.abllib.AblService; +import com.fisherbone.fuzhu.abllib.AblStepHandler; +import com.fisherbone.fuzhu.abllib.AblSteps; +import com.fisherbone.fuzhu.abllib.BaseAblStep; +import com.fisherbone.fuzhu.abllib.utils.AblViewUtil; +import com.fisherbone.fuzhu.okgonet.HttpConstants; +import com.fisherbone.fuzhu.okgonet.NetApi; +import com.lzy.okgo.model.HttpParams; +import com.lzy.okgo.model.Response; + +import org.json.JSONException; +import org.json.JSONObject; + +import java.util.List; + + +public class TestAblStep2 extends BaseAblStep { + @Override + public void onStep(int step, Message msg) { + switch (step) { + case AblSteps.STEP_3: + AblViewUtil.startApplication(); + AblViewUtil.mySleep(2); + allowed(); + AblViewUtil.mySleep(6); + AblStepHandler.sendMsg(AblSteps.STEP_4); + // AblService.getInstance().performGlobalAction(AccessibilityService.GLOBAL_ACTION_POWER_DIALOG); + //打开快速设置 + // AblService.getInstance().performGlobalAction(AccessibilityService.GLOBAL_ACTION_QUICK_SETTINGS); + // AblService.getInstance().performGlobalAction(AccessibilityService.GLOBAL_ACTION_RECENTS); + break; + case AblSteps.STEP_4: + closedtjDialog(AblService.getInstance()); + AblViewUtil.mySleep(1); + setdoyinQDialog(AblService.getInstance()); + AblViewUtil.mySleep(1); + //1.关闭检测到更新的弹框 + closedJDialog(AblService.getInstance()); + AblViewUtil.mySleep(1); + //2.关闭青少年弹窗 + closedQDialog(AblService.getInstance()); + AblViewUtil.mySleep(1); + closedBDialog(AblService.getInstance()); + AblViewUtil.mySleep(1); + + AblStepHandler.sendMsg(AblSteps.STEP_5); + break; + case AblSteps.STEP_5: + + AblService instance = AblService.getInstance(); + AblViewUtil.mySleep(2); + instance.clickPoint(972, 2112, 300); + Log.e("TIAOSHI###", "点击了我按钮"); + AblViewUtil.mySleep(2); + //Xiaomi M2007J22C Android 10, API 29 + //atom运行检查 + boolean normaa = wodeNorma(); + if (normaa) { + Log.e("TIAOSHI###", "页面在我的页面运行正常"); + againStart("1"); + } else { + Log.e("TIAOSHI###", "页面在我的页面运行异常"); + againStart("0"); + } + + + //等待2秒点击更多按钮([624,75][688,139]) + AblViewUtil.mySleep(2); + + instance.clickPoint(989, 170, 300); + Log.e("TIAOSHI###", "点击了更多按钮"); + + + //等待2秒点击设置按钮([220,1023][720,1143]) + AblViewUtil.mySleep(2); + + instance.clickPoint(584, 1790, 300); + Log.e("TIAOSHI###", "点击了设置按钮"); + + + //等待2秒向上滑动 + AblViewUtil.mySleep(2); + instance.randomSwipe(); + + //等待2秒点击切换账户 + AblViewUtil.mySleep(2); + AccessibilityNodeInfo zhaohao = AblViewUtil.findByText("切换帐号", 0); + if(zhaohao==null){ + Log.e("TIAOSHI###", "没有找到切换帐号" ); + }else { + Log.e("TIAOSHI###", "弹出了个人信息保护指引的弹窗" ); + clickNodeInfo(zhaohao,"切换帐号"); + } + + AblViewUtil.mySleep(2); + //atom运行检查 + boolean norma = ZhongHaoNorma(); + if (norma) { + Log.e("TIAOSHI###", "页面在切换账号页面运行正常"); + againStart("1"); + } else { + Log.e("TIAOSHI###", "页面在切换账号页面运行异常"); + againStart("0"); + } + //获取一屏幕数据:快照 + AccessibilityNodeInfo roott = instance.getRootInActiveWindow(); + String shortname = ChangLiang.task_short_name; + if(shortname.contains("T")){ + shortname = shortname.substring(0, shortname.indexOf("T")-1); + Log.e("TIAOSHI###", "----获取用户昵称:" +shortname); + } + List idsj = roott.findAccessibilityNodeInfosByText(shortname); + if(idsj.size()>0) { + String nodeInfofir = getNodeInfofir(); + Log.e("TIAOSHI###", "获得的昵称"+nodeInfofir+" shortname=="+shortname); + if (nodeInfofir.contains(shortname)) { + Log.e("TIAOSHI###", "有任务派的抖音号,并且在第一个位置上"); + AblViewUtil.mySleep(1); + AblViewUtil.back(); + AblViewUtil.mySleep(1); + AblViewUtil.back(); + AblViewUtil.mySleep(1); + AblViewUtil.back(); + } else { + instance.clickcommon(idsj, ChangLiang.task_short_name); + } + }else { + Log.e("TIAOSHI###", "没有任务派的抖音号"); + UpdateTuoguan(); + } + break; + default: + } + } + private void UpdateTuoguan() { + final HttpParams paramsPost = new HttpParams(); + paramsPost.put("short_id", ChangLiang.short_id); + paramsPost.put("tuoguan_type", "1"); + new NetApi().getPostData(paramsPost, HttpConstants.URi_Device_Appscanlogin_UpdateTuoguan).subscribe(new com.fisherbone.fuzhu.okgonet.Observer() { + @Override + public void onNext(Response response) { + String body = (String) response.body(); + try { + JSONObject jsonObject = new JSONObject(body); + String msg = jsonObject.getString("msg"); + String success = jsonObject.getString("success"); + if ("0".equals(success)) { + Log.e("TIAOSHI###", "提交帐号异常" + msg); + } + } catch (JSONException e) { + e.printStackTrace(); + } + } + + @Override + public void onError(Exception e) { + e.printStackTrace(); + } + }); + } + + + /** + * 寻找控件 + */ + public String getNodeInfofir() { + String name = ""; + AccessibilityNodeInfo root = AblService.getInstance().getRootInActiveWindow(); + for (int i = 0; i < root.getChildCount(); i++) { + AccessibilityNodeInfo child = root.getChild(i); + // Log.e("TIAOSHI###", "----oneNode:" + child.getClassName() + ":" + child.getText() + ":" + child.getContentDescription()); + // nodeZuobiao(child); + for (int y = 0; y < child.getChildCount(); y++) { + AccessibilityNodeInfo child1 = child.getChild(y); +// Log.e("TIAOSHI###", "----twoNode:" + child1.getClassName() + ":" + child1.getText() + ":" + child1.getContentDescription()); +// nodeZuobiao(child1); + for (int j = 0; j < child1.getChildCount(); j++) { + AccessibilityNodeInfo child2 = child1.getChild(j); + Log.e("TIAOSHI###", "----threeNode:" + child2.getClassName() + ":" + child2.getText() + ":" + child2.getContentDescription()); + nodeZuobiao(child2); + Rect rect = new Rect(); + if (child2 != null) { + child2.getBoundsInScreen(rect); + if (rect.top >= 253 && rect.bottom <= 409) { + Log.e("TIAOSHI###", "----fourNode:" + child2.getClassName() + ":" + child2.getText() + ":" + child2.getContentDescription()); + if ("android.widget.TextView".equals(child2.getClassName())) { + if (child2.getText() != null) { + String s = child2.getText().toString(); + name = s; + } + } + } + } + } + } + } + return name; + } + + @Override + public boolean allowed() { + boolean ifOpen = false; + AccessibilityNodeInfo root = AblService.getInstance().getRootInActiveWindow(); + for (int i = 0; i < root.getChildCount(); i++) { + AccessibilityNodeInfo child = root.getChild(i); + if(child!=null) { + // Log.e("TIAOSHI###", "----oneNode:" + child.getClassName() + ":" + child.getText() + ":" + child.getContentDescription()); + if ("android.widget.TextView".equals(child.getClassName())) { + if (child.getText() != null) { + if (child.getText().toString().contains("正在尝试开启") || child.getText().toString().contains("是否允许")) { + int childCount = root.getChildCount(); + AccessibilityNodeInfo child1 = root.getChild(childCount - 1); + clickNodeInfo(child1, "点击了允许"); + } + } + ifOpen = true; + } + } + } + return ifOpen; + } + +} diff --git a/app/src/main/java/com/fisherbone/fuzhu/utils/SafeToastUtils.java b/app/src/main/java/com/fisherbone/fuzhu/utils/SafeToastUtils.java new file mode 100644 index 0000000..7f275c9 --- /dev/null +++ b/app/src/main/java/com/fisherbone/fuzhu/utils/SafeToastUtils.java @@ -0,0 +1,76 @@ +package com.fisherbone.fuzhu.utils; + +import android.content.Context; +import android.widget.Toast; + +/** + * 安全的 Toast 工具类,用于替代 blankj 的 ToastUtils + * 避免在 Application 上下文中使用 Toast 时出现 NullPointerException + */ +public class SafeToastUtils { + + private static Toast lastToast; + + /** + * 显示短时 Toast + */ + public static void showShort(Context context, CharSequence text) { + if (context == null || text == null) { + return; + } + // 取消之前的 Toast + if (lastToast != null) { + lastToast.cancel(); + } + // 使用原生 Toast,确保使用 Activity 上下文 + lastToast = Toast.makeText(context.getApplicationContext(), text, Toast.LENGTH_SHORT); + lastToast.show(); + } + + /** + * 显示短时 Toast(使用字符串资源 ID) + */ + public static void showShort(Context context, int resId) { + if (context == null) { + return; + } + showShort(context, context.getString(resId)); + } + + /** + * 显示长时 Toast + */ + public static void showLong(Context context, CharSequence text) { + if (context == null || text == null) { + return; + } + // 取消之前的 Toast + if (lastToast != null) { + lastToast.cancel(); + } + // 使用原生 Toast,确保使用 Activity 上下文 + lastToast = Toast.makeText(context.getApplicationContext(), text, Toast.LENGTH_LONG); + lastToast.show(); + } + + /** + * 显示长时 Toast(使用字符串资源 ID) + */ + public static void showLong(Context context, int resId) { + if (context == null) { + return; + } + showLong(context, context.getString(resId)); + } + + /** + * 取消当前显示的 Toast + */ + public static void cancel() { + if (lastToast != null) { + lastToast.cancel(); + lastToast = null; + } + } +} + diff --git a/app/src/main/java/com/fisherbone/fuzhu/views/ConfirmDialog.java b/app/src/main/java/com/fisherbone/fuzhu/views/ConfirmDialog.java index 9b00956..f309d29 100644 --- a/app/src/main/java/com/fisherbone/fuzhu/views/ConfirmDialog.java +++ b/app/src/main/java/com/fisherbone/fuzhu/views/ConfirmDialog.java @@ -1,70 +1,66 @@ -package com.fisherbone.fuzhu.views; - -import android.app.Dialog; -import android.content.Context; -import android.view.LayoutInflater; -import android.view.View; -import android.widget.TextView; - -import com.fisherbone.fuzhu.R; -import com.fisherbone.fuzhu.config.Callback; - - -/** - * Created by Teprinciple on 2016/10/13. - *

- * 自定义对话框 - */ -public class ConfirmDialog extends Dialog implements View.OnClickListener { - - Callback callback; - private TextView content; - private TextView sureBtn; - private TextView cancleBtn; - - /** - * 高仿苹果自定义对话框 - * - * @param context - * @param callback - */ - public ConfirmDialog(Context context, Callback callback) { - super(context, R.style.CustomDialog); - this.callback = callback; - setCustomDialog(); - } - - private void setCustomDialog() { - View mView = LayoutInflater.from(getContext()).inflate(R.layout.dialog_confirm, null); - sureBtn = (TextView) mView.findViewById(R.id.dialog_confirm_sure); - cancleBtn = (TextView) mView.findViewById(R.id.dialog_confirm_cancle); - content = (TextView) mView.findViewById(R.id.dialog_confirm_title); - sureBtn.setOnClickListener(this); - cancleBtn.setOnClickListener(this); - super.setContentView(mView); - } - - - public ConfirmDialog setContent(String s) { - content.setText(s); - return this; - } - - - @Override - public void onClick(View v) { - switch (v.getId()) { - case R.id.dialog_confirm_cancle: - callback.Negative(); - this.cancel(); - break; - - case R.id.dialog_confirm_sure: - callback.Positive(); - this.cancel(); - break; - default: - } - } - -} +package com.fisherbone.fuzhu.views; + +import android.app.Dialog; +import android.content.Context; +import android.view.LayoutInflater; +import android.view.View; +import android.widget.TextView; + +import com.fisherbone.fuzhu.R; +import com.fisherbone.fuzhu.config.Callback; + + +/** + * Created by Teprinciple on 2016/10/13. + *

+ * 自定义对话框 + */ +public class ConfirmDialog extends Dialog implements View.OnClickListener { + + Callback callback; + private TextView content; + private TextView sureBtn; + private TextView cancleBtn; + + /** + * 高仿苹果自定义对话框 + * + * @param context + * @param callback + */ + public ConfirmDialog(Context context, Callback callback) { + super(context, R.style.CustomDialog); + this.callback = callback; + setCustomDialog(); + } + + private void setCustomDialog() { + View mView = LayoutInflater.from(getContext()).inflate(R.layout.dialog_confirm, null); + sureBtn = (TextView) mView.findViewById(R.id.dialog_confirm_sure); + cancleBtn = (TextView) mView.findViewById(R.id.dialog_confirm_cancle); + content = (TextView) mView.findViewById(R.id.dialog_confirm_title); + sureBtn.setOnClickListener(this); + cancleBtn.setOnClickListener(this); + super.setContentView(mView); + } + + + public ConfirmDialog setContent(String s) { + content.setText(s); + return this; + } + + + @Override + public void onClick(View v) { + int id = v.getId(); + if (id == R.id.dialog_confirm_cancle) { + callback.Negative(); + this.cancel(); + } else if (id == R.id.dialog_confirm_sure) { + callback.Positive(); + this.cancel(); + } + } + +} diff --git a/app/src/main/java/com/fisherbone/fuzhu/widget/TitleBar.java b/app/src/main/java/com/fisherbone/fuzhu/widget/TitleBar.java index ce5027a..85cf24f 100644 --- a/app/src/main/java/com/fisherbone/fuzhu/widget/TitleBar.java +++ b/app/src/main/java/com/fisherbone/fuzhu/widget/TitleBar.java @@ -1,318 +1,314 @@ -package com.fisherbone.fuzhu.widget; - -import android.content.Context; -import android.util.AttributeSet; -import android.view.View; -import android.widget.Button; -import android.widget.ImageView; -import android.widget.RelativeLayout; -import android.widget.TextView; - -import androidx.annotation.ColorRes; -import androidx.annotation.DrawableRes; -import androidx.annotation.StringRes; -import androidx.core.content.ContextCompat; - -import com.fisherbone.fuzhu.R; - - -/** - * Created by Administrator on 2016/12/23. - * 作者:xudiwei - *

- * 描述:标题栏组合控件 - *

- * sample: - *

- * .xml: - *

- * - *

- * - *

- * .java: - *

- * TitleBar titleBar ....findViewById(R.id...); - * titleBar.setTitle("...") - * ...... - */ - -public class TitleBar extends RelativeLayout implements View.OnClickListener { - - private ImageView mIvLeftBtn; - private ImageView mIvRightBtn; - private TextView mTvtitle; - private OnTitleBarClickListener mListener; - private OnTitleBarAllClickListener mAllClickListener; - private TextView mTvRightText; - private RelativeLayout mRlMain; - private View mVBottomLine; - private View mRootView; - private Button mBtnRed; - - public TitleBar(Context context) { - this(context, null); - } - - public TitleBar(Context context, AttributeSet attrs) { - this(context, attrs, 0); - } - - public TitleBar(Context context, AttributeSet attrs, int defStyleAttr) { - super(context, attrs, defStyleAttr); - initView(context); - } - /** - * @description 隐藏横线 - * @param - * @return - */ - public void hideline(){ - mVBottomLine.setVisibility(GONE); - } - private void initView(Context context) { - mRootView = inflate(context, R.layout.widget_title_bar, this); - - //左边按钮 - mIvLeftBtn = (ImageView) mRootView.findViewById(R.id.iv_left_btn); - //右边按扭 - mIvRightBtn = (ImageView) mRootView.findViewById(R.id.iv_right_btn); - //标题 - mTvtitle = (TextView) mRootView.findViewById(R.id.tv_title); - //右边文字按钮 - mTvRightText = (TextView) mRootView.findViewById(R.id.tv_right_text); - - //右边红点 - mBtnRed = (Button) mRootView.findViewById(R.id.btn_red); - - mRlMain = (RelativeLayout) mRootView.findViewById(R.id.rl_main); - // 底部线 - mVBottomLine = mRootView.findViewById(R.id.v_bottom_line); - - mIvLeftBtn.setOnClickListener(this); - mIvRightBtn.setOnClickListener(this); - mTvRightText.setOnClickListener(this); - - } - - /** - * 设置暗黑模式 - */ - public void setDarkTheme() { - mRootView.findViewById(R.id.rl_main).setBackgroundColor(ContextCompat.getColor(getContext(), R.color.colorLightBlack)); - mTvtitle.setTextColor(ContextCompat.getColor(getContext(), R.color.colorWhite)); - mIvLeftBtn.setImageResource(R.mipmap.nav_white_back); - } - - @Override - public void onClick(View view) { - switch (view.getId()) { - //左边按钮 - case R.id.iv_left_btn: - if (null != mListener) { - mListener.onLeftButtonClick(view); - } - if (null != mAllClickListener) { - mAllClickListener.onLeftButtonClick(view); - } - break; - //右边按钮 - case R.id.iv_right_btn: - if (null != mListener) { - mListener.onRightButtonClick(view); - } - if (null != mAllClickListener) { - mAllClickListener.onRightButtonClick(view); - } - break; - //右边文本按钮 - case R.id.tv_right_text: - if (null != mAllClickListener) { - mAllClickListener.onRightTextButtonClick(view); - } - break; - default: - } - } - - /** - * 底部线是否显示,默认是显示 - * - * @param show - */ - public void showBottomLine(boolean show) { - mVBottomLine.setVisibility(show ? View.VISIBLE : View.GONE); - } - - /** - * 显示或隐藏左边按钮 - * - * @param visible - */ - public void visibleIvLeftBtn(boolean visible) { - mIvLeftBtn.setVisibility(visible ? View.VISIBLE : View.GONE); - } - - /** - * 显示或隐藏右边按钮 - * - * @param visible - */ - public void visibleIvRightBtn(boolean visible) { - mIvRightBtn.setVisibility(visible ? View.VISIBLE : View.GONE); - } - - /** - * 显示或隐藏右边文本按钮 - * - * @param visible - */ - public void visibleTvRightTextBtn(boolean visible) { - mTvRightText.setVisibility(visible ? View.VISIBLE : View.GONE); - } - - /** - * 显示或隐藏右边红点 - * - * @param visible - */ - public void visibleRightRedDot(boolean visible) { - mBtnRed.setVisibility(visible ? View.VISIBLE : View.GONE); - } - - /** - * 设置左边按钮图标 - * - * @param ids - */ - public void setIvLeftBtnDrawable(@DrawableRes int ids) { - mIvLeftBtn.setImageResource(ids); - } - - /** - * 设置右边按钮图标 - * - * @param ids - */ - public void setIvRightBtnDrawable(@DrawableRes int ids) { - mIvRightBtn.setImageResource(ids); - } - - /** - * 设置标题 - * - * @param ids - */ - public void setTitle(@StringRes int ids) { - setTitle(getContext().getResources().getString(ids)); - } - - /** - * 设置标题 - * - * @param titleText - */ - public void setTitle(String titleText) { - mTvtitle.setText(titleText); - } - - /** - * 设置标题颜色 - * - * @param colorIds - */ - public void setTitleColor(@ColorRes int colorIds) { - mTvtitle.setTextColor(getResources().getColor(colorIds)); - } - - /** - * 设置标题背景色 - * - * @param colorIds - */ - public void setTitleBg(@ColorRes int colorIds) { - mRlMain.setBackgroundResource(colorIds); - } - - /** - * 设置右边文本按钮的文本 - * - * @param rightButtonText - */ - public void setTvRightText(String rightButtonText) { - mTvRightText.setText(rightButtonText); - } - - /** - * 设置右边文本按钮的颜色 - * - * @param color - */ - public void setTvRightTextColor(@ColorRes int color) { - mTvRightText.setTextColor(getResources().getColor(color)); - } - - /** - * 设置右边文本使能 - * @param enable - */ - public void setTvRightTextEnable(boolean enable){ - mTvRightText.setEnabled(enable); - } - - /** - * 设置标题栏点击事件监听器这个监听器只响应左边按钮与右边按钮。若还想响应右边 - * 文本按的按钮请使用{@link #setOnTitleBarAllClickListener(OnTitleBarAllClickListener)} - * - * @param clickListener {@link OnTitleBarClickListener} - */ - public void setOnTitleBarClickListener(OnTitleBarClickListener clickListener) { - this.mListener = clickListener; - } - - /** - * 设置标题栏的上的按钮全部点击事件监听器能响应左边按钮,右边按钮,右边文本按钮 - * - * @param clickListener - */ - public void setOnTitleBarAllClickListener(OnTitleBarAllClickListener clickListener) { - this.mAllClickListener = clickListener; - } - - - /** - * 标题栏的点击事件回调接口,响应两个按钮的 - */ - public interface OnTitleBarClickListener { - /** - * 左边按钮被点击 - * - * @param view - */ - void onLeftButtonClick(View view); - - /** - * 右边按钮被点击 - * - * @param view - */ - void onRightButtonClick(View view); - } - - /** - * 标题栏的点击事件回调接口,响应三个按钮的 - */ - public interface OnTitleBarAllClickListener extends OnTitleBarClickListener { - /** - * 右边文本按钮点击事件 - * - * @param view - */ - void onRightTextButtonClick(View view); - - } - -} +package com.fisherbone.fuzhu.widget; + +import android.content.Context; +import android.util.AttributeSet; +import android.view.View; +import android.widget.Button; +import android.widget.ImageView; +import android.widget.RelativeLayout; +import android.widget.TextView; + +import androidx.annotation.ColorRes; +import androidx.annotation.DrawableRes; +import androidx.annotation.StringRes; +import androidx.core.content.ContextCompat; + +import com.fisherbone.fuzhu.R; + + +/** + * Created by Administrator on 2016/12/23. + * 作者:xudiwei + *

+ * 描述:标题栏组合控件 + *

+ * sample: + *

+ * .xml: + *

+ * + *

+ * + *

+ * .java: + *

+ * TitleBar titleBar ....findViewById(R.id...); + * titleBar.setTitle("...") + * ...... + */ + +public class TitleBar extends RelativeLayout implements View.OnClickListener { + + private ImageView mIvLeftBtn; + private ImageView mIvRightBtn; + private TextView mTvtitle; + private OnTitleBarClickListener mListener; + private OnTitleBarAllClickListener mAllClickListener; + private TextView mTvRightText; + private RelativeLayout mRlMain; + private View mVBottomLine; + private View mRootView; + private Button mBtnRed; + + public TitleBar(Context context) { + this(context, null); + } + + public TitleBar(Context context, AttributeSet attrs) { + this(context, attrs, 0); + } + + public TitleBar(Context context, AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + initView(context); + } + /** + * @description 隐藏横线 + * @param + * @return + */ + public void hideline(){ + mVBottomLine.setVisibility(GONE); + } + private void initView(Context context) { + mRootView = inflate(context, R.layout.widget_title_bar, this); + + //左边按钮 + mIvLeftBtn = (ImageView) mRootView.findViewById(R.id.iv_left_btn); + //右边按扭 + mIvRightBtn = (ImageView) mRootView.findViewById(R.id.iv_right_btn); + //标题 + mTvtitle = (TextView) mRootView.findViewById(R.id.tv_title); + //右边文字按钮 + mTvRightText = (TextView) mRootView.findViewById(R.id.tv_right_text); + + //右边红点 + mBtnRed = (Button) mRootView.findViewById(R.id.btn_red); + + mRlMain = (RelativeLayout) mRootView.findViewById(R.id.rl_main); + // 底部线 + mVBottomLine = mRootView.findViewById(R.id.v_bottom_line); + + mIvLeftBtn.setOnClickListener(this); + mIvRightBtn.setOnClickListener(this); + mTvRightText.setOnClickListener(this); + + } + + /** + * 设置暗黑模式 + */ + public void setDarkTheme() { + mRootView.findViewById(R.id.rl_main).setBackgroundColor(ContextCompat.getColor(getContext(), R.color.colorLightBlack)); + mTvtitle.setTextColor(ContextCompat.getColor(getContext(), R.color.colorWhite)); + mIvLeftBtn.setImageResource(R.mipmap.nav_white_back); + } + + @Override + public void onClick(View view) { + int id = view.getId(); + //左边按钮 + if (id == R.id.iv_left_btn) { + if (null != mListener) { + mListener.onLeftButtonClick(view); + } + if (null != mAllClickListener) { + mAllClickListener.onLeftButtonClick(view); + } + } else if (id == R.id.iv_right_btn) { + //右边按钮 + if (null != mListener) { + mListener.onRightButtonClick(view); + } + if (null != mAllClickListener) { + mAllClickListener.onRightButtonClick(view); + } + } else if (id == R.id.tv_right_text) { + //右边文本按钮 + if (null != mAllClickListener) { + mAllClickListener.onRightTextButtonClick(view); + } + } + } + + /** + * 底部线是否显示,默认是显示 + * + * @param show + */ + public void showBottomLine(boolean show) { + mVBottomLine.setVisibility(show ? View.VISIBLE : View.GONE); + } + + /** + * 显示或隐藏左边按钮 + * + * @param visible + */ + public void visibleIvLeftBtn(boolean visible) { + mIvLeftBtn.setVisibility(visible ? View.VISIBLE : View.GONE); + } + + /** + * 显示或隐藏右边按钮 + * + * @param visible + */ + public void visibleIvRightBtn(boolean visible) { + mIvRightBtn.setVisibility(visible ? View.VISIBLE : View.GONE); + } + + /** + * 显示或隐藏右边文本按钮 + * + * @param visible + */ + public void visibleTvRightTextBtn(boolean visible) { + mTvRightText.setVisibility(visible ? View.VISIBLE : View.GONE); + } + + /** + * 显示或隐藏右边红点 + * + * @param visible + */ + public void visibleRightRedDot(boolean visible) { + mBtnRed.setVisibility(visible ? View.VISIBLE : View.GONE); + } + + /** + * 设置左边按钮图标 + * + * @param ids + */ + public void setIvLeftBtnDrawable(@DrawableRes int ids) { + mIvLeftBtn.setImageResource(ids); + } + + /** + * 设置右边按钮图标 + * + * @param ids + */ + public void setIvRightBtnDrawable(@DrawableRes int ids) { + mIvRightBtn.setImageResource(ids); + } + + /** + * 设置标题 + * + * @param ids + */ + public void setTitle(@StringRes int ids) { + setTitle(getContext().getResources().getString(ids)); + } + + /** + * 设置标题 + * + * @param titleText + */ + public void setTitle(String titleText) { + mTvtitle.setText(titleText); + } + + /** + * 设置标题颜色 + * + * @param colorIds + */ + public void setTitleColor(@ColorRes int colorIds) { + mTvtitle.setTextColor(getResources().getColor(colorIds)); + } + + /** + * 设置标题背景色 + * + * @param colorIds + */ + public void setTitleBg(@ColorRes int colorIds) { + mRlMain.setBackgroundResource(colorIds); + } + + /** + * 设置右边文本按钮的文本 + * + * @param rightButtonText + */ + public void setTvRightText(String rightButtonText) { + mTvRightText.setText(rightButtonText); + } + + /** + * 设置右边文本按钮的颜色 + * + * @param color + */ + public void setTvRightTextColor(@ColorRes int color) { + mTvRightText.setTextColor(getResources().getColor(color)); + } + + /** + * 设置右边文本使能 + * @param enable + */ + public void setTvRightTextEnable(boolean enable){ + mTvRightText.setEnabled(enable); + } + + /** + * 设置标题栏点击事件监听器这个监听器只响应左边按钮与右边按钮。若还想响应右边 + * 文本按的按钮请使用{@link #setOnTitleBarAllClickListener(OnTitleBarAllClickListener)} + * + * @param clickListener {@link OnTitleBarClickListener} + */ + public void setOnTitleBarClickListener(OnTitleBarClickListener clickListener) { + this.mListener = clickListener; + } + + /** + * 设置标题栏的上的按钮全部点击事件监听器能响应左边按钮,右边按钮,右边文本按钮 + * + * @param clickListener + */ + public void setOnTitleBarAllClickListener(OnTitleBarAllClickListener clickListener) { + this.mAllClickListener = clickListener; + } + + + /** + * 标题栏的点击事件回调接口,响应两个按钮的 + */ + public interface OnTitleBarClickListener { + /** + * 左边按钮被点击 + * + * @param view + */ + void onLeftButtonClick(View view); + + /** + * 右边按钮被点击 + * + * @param view + */ + void onRightButtonClick(View view); + } + + /** + * 标题栏的点击事件回调接口,响应三个按钮的 + */ + public interface OnTitleBarAllClickListener extends OnTitleBarClickListener { + /** + * 右边文本按钮点击事件 + * + * @param view + */ + void onRightTextButtonClick(View view); + + } + +} diff --git a/app/src/main/java/com/fisherbone/fuzhu/zxing/activity/CaptureActivity.java b/app/src/main/java/com/fisherbone/fuzhu/zxing/activity/CaptureActivity.java index acb6a70..cad26f6 100644 --- a/app/src/main/java/com/fisherbone/fuzhu/zxing/activity/CaptureActivity.java +++ b/app/src/main/java/com/fisherbone/fuzhu/zxing/activity/CaptureActivity.java @@ -1,358 +1,355 @@ -package com.fisherbone.fuzhu.zxing.activity; - -import android.app.ProgressDialog; -import android.content.Intent; -import android.content.res.AssetFileDescriptor; -import android.graphics.Bitmap; -import android.graphics.BitmapFactory; -import android.media.AudioManager; -import android.media.MediaPlayer; -import android.media.MediaPlayer.OnCompletionListener; -import android.os.Bundle; -import android.os.Handler; -import android.os.Vibrator; -import android.text.TextUtils; -import android.view.SurfaceHolder; -import android.view.SurfaceHolder.Callback; -import android.view.SurfaceView; -import android.view.View; -import android.widget.Button; -import android.widget.LinearLayout; -import android.widget.TextView; -import android.widget.Toast; - -import com.fisherbone.fuzhu.BaseActivity; -import com.fisherbone.fuzhu.R; -import com.fisherbone.fuzhu.activity.ShouQuanActivity; -import com.fisherbone.fuzhu.utils.JumpUtils; -import com.fisherbone.fuzhu.utils.ToastUtils; -import com.fisherbone.fuzhu.zxing.camera.CameraManager; -import com.fisherbone.fuzhu.zxing.decoding.CaptureActivityHandler; -import com.fisherbone.fuzhu.zxing.decoding.InactivityTimer; -import com.fisherbone.fuzhu.zxing.decoding.RGBLuminanceSource; -import com.fisherbone.fuzhu.zxing.view.ViewfinderView; -import com.google.zxing.BarcodeFormat; -import com.google.zxing.BinaryBitmap; -import com.google.zxing.ChecksumException; -import com.google.zxing.DecodeHintType; -import com.google.zxing.FormatException; -import com.google.zxing.NotFoundException; -import com.google.zxing.Result; -import com.google.zxing.common.HybridBinarizer; -import com.google.zxing.qrcode.QRCodeReader; - -import java.io.IOException; -import java.util.Hashtable; -import java.util.Vector; - - -/** - * Initial the camera - * - * @author Ryan.Tang - */ -public class CaptureActivity extends BaseActivity implements Callback, View.OnClickListener { - - private static final int REQUEST_CODE_SCAN_GALLERY = 100; - - private CaptureActivityHandler handler; - private ViewfinderView viewfinderView; - - private boolean hasSurface; - private Vector decodeFormats; - private String characterSet; - private InactivityTimer inactivityTimer; - private MediaPlayer mediaPlayer; - private boolean playBeep; - private static final float BEEP_VOLUME = 0.10f; - private boolean vibrate; - private ProgressDialog mProgress; - private String photo_path; - private Bitmap scanBitmap; - // private Button cancelScanButton; - SurfaceView surfaceView; - SurfaceHolder surfaceHolder; - String storeId = "";//商家id - String onlyId = "";//时间戳 - String price = ""; - private Button mBtnBack; - private TextView mTvTitle; - private String type=""; - private LinearLayout ll_scan_code; - - /** - * Called when the activity is first created. - */ - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_scanner); - type = getIntent().getStringExtra("type"); - initView(); - hasSurface = false; - CameraManager.init(getApplication()); - viewfinderView = (ViewfinderView) findViewById(R.id.viewfinder_content); - ll_scan_code = (LinearLayout) findViewById(R.id.ll_scan_code); - inactivityTimer = new InactivityTimer(this); - ll_scan_code.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - ToastUtils.showToast(CaptureActivity.this, "点击了输入激活码"); - JumpUtils.gotoActivity(CaptureActivity.this, ShouQuanActivity.class, false, "", ""); - finish(); - } - }); - - } - - - //方法一:用JAVA自带的函数 - public boolean isNumeric(String str) { - for (int i = str.length(); --i >= 0; ) { - if (!Character.isDigit(str.charAt(i))) { - return false; - } - } - return true; - } - - /** - * 扫描二维码图片的方法 - * - * @param path - * @return - */ - public Result scanningImage(String path) { - if (TextUtils.isEmpty(path)) { - return null; - } - Hashtable hints = new Hashtable<>(); - hints.put(DecodeHintType.CHARACTER_SET, "UTF8"); //设置二维码内容的编码 - - BitmapFactory.Options options = new BitmapFactory.Options(); - options.inJustDecodeBounds = true; // 先获取原大小 - scanBitmap = BitmapFactory.decodeFile(path, options); - options.inJustDecodeBounds = false; // 获取新的大小 - int sampleSize = (int) (options.outHeight / (float) 200); - if (sampleSize <= 0) - sampleSize = 1; - options.inSampleSize = sampleSize; - scanBitmap = BitmapFactory.decodeFile(path, options); - RGBLuminanceSource source = new RGBLuminanceSource(scanBitmap); - BinaryBitmap bitmap1 = new BinaryBitmap(new HybridBinarizer(source)); - QRCodeReader reader = new QRCodeReader(); - try { - return reader.decode(bitmap1, hints); - } catch (NotFoundException e) { - e.printStackTrace(); - } catch (ChecksumException e) { - e.printStackTrace(); - } catch (FormatException e) { - e.printStackTrace(); - } - return null; - } - - @Override - protected void onResume() { - super.onResume(); - surfaceView = (SurfaceView) findViewById(R.id.scanner_view); - surfaceHolder = surfaceView.getHolder(); - if (hasSurface) { - initCamera(surfaceHolder); - } else { - surfaceHolder.addCallback(this); - surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); - } - decodeFormats = null; - characterSet = null; - - playBeep = true; - AudioManager audioService = (AudioManager) getSystemService(AUDIO_SERVICE); - if (audioService.getRingerMode() != AudioManager.RINGER_MODE_NORMAL) { - playBeep = false; - } - initBeepSound(); - vibrate = true; - - //quit the scan view -// cancelScanButton.setOnClickListener(new OnClickListener() { -// -// @Override -// public void onClick(View v) { -// CaptureActivity.this.finish(); -// } -// }); - } - - @Override - protected void onPause() { - super.onPause(); - if (handler != null) { - handler.quitSynchronously(); - handler = null; - } - CameraManager.get().closeDriver(); - } - - @Override - protected void onDestroy() { - inactivityTimer.shutdown(); - super.onDestroy(); - } - - /** - * Handler scan result - * - * @param result - * @param barcode - */ - public void handleDecode(Result result, Bitmap barcode) { - inactivityTimer.onActivity(); - playBeepSoundAndVibrate(); - String resultString = result.getText(); - //FIXME - if (TextUtils.isEmpty(resultString)) { - Toast.makeText(CaptureActivity.this, "扫码失败", Toast.LENGTH_SHORT).show(); - } else { - - -// Intent mIntent = new Intent(); -// mIntent.putExtra("SCAN_RESULT", result.getText()); -// this.setResult(RESULT_OK, mIntent); - - - Intent mIntent = new Intent(); - mIntent.putExtra("SCAN_RESULT", result.getText()); - this.setResult(RESULT_OK, mIntent); - - - } - CaptureActivity.this.finish(); - } - - - @Override - protected void onActivityResult(int requestCode, int resultCode, Intent data) { - super.onActivityResult(requestCode, resultCode, data); - if (resultCode == RESULT_OK) { - - if (requestCode == 0x121) { - this.finish(); - } - - } - } - - private void initCamera(SurfaceHolder surfaceHolder) { - try { - CameraManager.get().openDriver(surfaceHolder); - } catch (IOException ioe) { - return; - } catch (RuntimeException e) { - return; - } - if (handler == null) { - handler = new CaptureActivityHandler(this, decodeFormats, - characterSet); - } - } - - @Override - public void surfaceChanged(SurfaceHolder holder, int format, int width, - int height) { - - } - - @Override - public void surfaceCreated(SurfaceHolder holder) { - if (!hasSurface) { - hasSurface = true; - initCamera(holder); - } - - } - - @Override - public void surfaceDestroyed(SurfaceHolder holder) { - hasSurface = false; - - } - - public ViewfinderView getViewfinderView() { - return viewfinderView; - } - - public Handler getHandler() { - return handler; - } - - public void drawViewfinder() { - viewfinderView.drawViewfinder(); - - } - - private void initBeepSound() { - if (playBeep && mediaPlayer == null) { - // The volume on STREAM_SYSTEM is not adjustable, and users found it - // too loud, - // so we now play on the music stream. - setVolumeControlStream(AudioManager.STREAM_MUSIC); - mediaPlayer = new MediaPlayer(); - mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); - mediaPlayer.setOnCompletionListener(beepListener); - - AssetFileDescriptor file = getResources().openRawResourceFd( - R.raw.beep); - try { - mediaPlayer.setDataSource(file.getFileDescriptor(), - file.getStartOffset(), file.getLength()); - file.close(); - mediaPlayer.setVolume(BEEP_VOLUME, BEEP_VOLUME); - mediaPlayer.prepare(); - } catch (IOException e) { - mediaPlayer = null; - } - } - } - - private static final long VIBRATE_DURATION = 200L; - - private void playBeepSoundAndVibrate() { - if (playBeep && mediaPlayer != null) { - mediaPlayer.start(); - } - if (vibrate) { - Vibrator vibrator = (Vibrator) getSystemService(VIBRATOR_SERVICE); - vibrator.vibrate(VIBRATE_DURATION); - } - } - - /** - * When the beep has finished playing, rewind to queue up another one. - */ - private final OnCompletionListener beepListener = new OnCompletionListener() { - public void onCompletion(MediaPlayer mediaPlayer) { - mediaPlayer.seekTo(0); - } - }; - - - private void initView() { - mBtnBack = (Button) findViewById(R.id.btn_back); - mBtnBack.setOnClickListener(this); - mTvTitle = (TextView) findViewById(R.id.tv_title); - mTvTitle.setText("激活授权"); - } - - @Override - public void onClick(View v) { - switch (v.getId()) { - default: - break; - case R.id.btn_back: - finish(); - break; - } - } +package com.fisherbone.fuzhu.zxing.activity; + +import android.app.ProgressDialog; +import android.content.Intent; +import android.content.res.AssetFileDescriptor; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; +import android.media.AudioManager; +import android.media.MediaPlayer; +import android.media.MediaPlayer.OnCompletionListener; +import android.os.Bundle; +import android.os.Handler; +import android.os.Vibrator; +import android.text.TextUtils; +import android.view.SurfaceHolder; +import android.view.SurfaceHolder.Callback; +import android.view.SurfaceView; +import android.view.View; +import android.widget.Button; +import android.widget.LinearLayout; +import android.widget.TextView; +import android.widget.Toast; + +import com.fisherbone.fuzhu.BaseActivity; +import com.fisherbone.fuzhu.R; +import com.fisherbone.fuzhu.activity.ShouQuanActivity; +import com.fisherbone.fuzhu.utils.JumpUtils; +import com.fisherbone.fuzhu.utils.ToastUtils; +import com.fisherbone.fuzhu.zxing.camera.CameraManager; +import com.fisherbone.fuzhu.zxing.decoding.CaptureActivityHandler; +import com.fisherbone.fuzhu.zxing.decoding.InactivityTimer; +import com.fisherbone.fuzhu.zxing.decoding.RGBLuminanceSource; +import com.fisherbone.fuzhu.zxing.view.ViewfinderView; +import com.google.zxing.BarcodeFormat; +import com.google.zxing.BinaryBitmap; +import com.google.zxing.ChecksumException; +import com.google.zxing.DecodeHintType; +import com.google.zxing.FormatException; +import com.google.zxing.NotFoundException; +import com.google.zxing.Result; +import com.google.zxing.common.HybridBinarizer; +import com.google.zxing.qrcode.QRCodeReader; + +import java.io.IOException; +import java.util.Hashtable; +import java.util.Vector; + + +/** + * Initial the camera + * + * @author Ryan.Tang + */ +public class CaptureActivity extends BaseActivity implements Callback, View.OnClickListener { + + private static final int REQUEST_CODE_SCAN_GALLERY = 100; + + private CaptureActivityHandler handler; + private ViewfinderView viewfinderView; + + private boolean hasSurface; + private Vector decodeFormats; + private String characterSet; + private InactivityTimer inactivityTimer; + private MediaPlayer mediaPlayer; + private boolean playBeep; + private static final float BEEP_VOLUME = 0.10f; + private boolean vibrate; + private ProgressDialog mProgress; + private String photo_path; + private Bitmap scanBitmap; + // private Button cancelScanButton; + SurfaceView surfaceView; + SurfaceHolder surfaceHolder; + String storeId = "";//商家id + String onlyId = "";//时间戳 + String price = ""; + private Button mBtnBack; + private TextView mTvTitle; + private String type=""; + private LinearLayout ll_scan_code; + + /** + * Called when the activity is first created. + */ + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_scanner); + type = getIntent().getStringExtra("type"); + initView(); + hasSurface = false; + CameraManager.init(getApplication()); + viewfinderView = (ViewfinderView) findViewById(R.id.viewfinder_content); + ll_scan_code = (LinearLayout) findViewById(R.id.ll_scan_code); + inactivityTimer = new InactivityTimer(this); + ll_scan_code.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + ToastUtils.showToast(CaptureActivity.this, "点击了输入激活码"); + JumpUtils.gotoActivity(CaptureActivity.this, ShouQuanActivity.class, false, "", ""); + finish(); + } + }); + + } + + + //方法一:用JAVA自带的函数 + public boolean isNumeric(String str) { + for (int i = str.length(); --i >= 0; ) { + if (!Character.isDigit(str.charAt(i))) { + return false; + } + } + return true; + } + + /** + * 扫描二维码图片的方法 + * + * @param path + * @return + */ + public Result scanningImage(String path) { + if (TextUtils.isEmpty(path)) { + return null; + } + Hashtable hints = new Hashtable<>(); + hints.put(DecodeHintType.CHARACTER_SET, "UTF8"); //设置二维码内容的编码 + + BitmapFactory.Options options = new BitmapFactory.Options(); + options.inJustDecodeBounds = true; // 先获取原大小 + scanBitmap = BitmapFactory.decodeFile(path, options); + options.inJustDecodeBounds = false; // 获取新的大小 + int sampleSize = (int) (options.outHeight / (float) 200); + if (sampleSize <= 0) + sampleSize = 1; + options.inSampleSize = sampleSize; + scanBitmap = BitmapFactory.decodeFile(path, options); + RGBLuminanceSource source = new RGBLuminanceSource(scanBitmap); + BinaryBitmap bitmap1 = new BinaryBitmap(new HybridBinarizer(source)); + QRCodeReader reader = new QRCodeReader(); + try { + return reader.decode(bitmap1, hints); + } catch (NotFoundException e) { + e.printStackTrace(); + } catch (ChecksumException e) { + e.printStackTrace(); + } catch (FormatException e) { + e.printStackTrace(); + } + return null; + } + + @Override + protected void onResume() { + super.onResume(); + surfaceView = (SurfaceView) findViewById(R.id.scanner_view); + surfaceHolder = surfaceView.getHolder(); + if (hasSurface) { + initCamera(surfaceHolder); + } else { + surfaceHolder.addCallback(this); + surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); + } + decodeFormats = null; + characterSet = null; + + playBeep = true; + AudioManager audioService = (AudioManager) getSystemService(AUDIO_SERVICE); + if (audioService.getRingerMode() != AudioManager.RINGER_MODE_NORMAL) { + playBeep = false; + } + initBeepSound(); + vibrate = true; + + //quit the scan view +// cancelScanButton.setOnClickListener(new OnClickListener() { +// +// @Override +// public void onClick(View v) { +// CaptureActivity.this.finish(); +// } +// }); + } + + @Override + protected void onPause() { + super.onPause(); + if (handler != null) { + handler.quitSynchronously(); + handler = null; + } + CameraManager.get().closeDriver(); + } + + @Override + protected void onDestroy() { + inactivityTimer.shutdown(); + super.onDestroy(); + } + + /** + * Handler scan result + * + * @param result + * @param barcode + */ + public void handleDecode(Result result, Bitmap barcode) { + inactivityTimer.onActivity(); + playBeepSoundAndVibrate(); + String resultString = result.getText(); + //FIXME + if (TextUtils.isEmpty(resultString)) { + Toast.makeText(CaptureActivity.this, "扫码失败", Toast.LENGTH_SHORT).show(); + } else { + + +// Intent mIntent = new Intent(); +// mIntent.putExtra("SCAN_RESULT", result.getText()); +// this.setResult(RESULT_OK, mIntent); + + + Intent mIntent = new Intent(); + mIntent.putExtra("SCAN_RESULT", result.getText()); + this.setResult(RESULT_OK, mIntent); + + + } + CaptureActivity.this.finish(); + } + + + @Override + protected void onActivityResult(int requestCode, int resultCode, Intent data) { + super.onActivityResult(requestCode, resultCode, data); + if (resultCode == RESULT_OK) { + + if (requestCode == 0x121) { + this.finish(); + } + + } + } + + private void initCamera(SurfaceHolder surfaceHolder) { + try { + CameraManager.get().openDriver(surfaceHolder); + } catch (IOException ioe) { + return; + } catch (RuntimeException e) { + return; + } + if (handler == null) { + handler = new CaptureActivityHandler(this, decodeFormats, + characterSet); + } + } + + @Override + public void surfaceChanged(SurfaceHolder holder, int format, int width, + int height) { + + } + + @Override + public void surfaceCreated(SurfaceHolder holder) { + if (!hasSurface) { + hasSurface = true; + initCamera(holder); + } + + } + + @Override + public void surfaceDestroyed(SurfaceHolder holder) { + hasSurface = false; + + } + + public ViewfinderView getViewfinderView() { + return viewfinderView; + } + + public Handler getHandler() { + return handler; + } + + public void drawViewfinder() { + viewfinderView.drawViewfinder(); + + } + + private void initBeepSound() { + if (playBeep && mediaPlayer == null) { + // The volume on STREAM_SYSTEM is not adjustable, and users found it + // too loud, + // so we now play on the music stream. + setVolumeControlStream(AudioManager.STREAM_MUSIC); + mediaPlayer = new MediaPlayer(); + mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); + mediaPlayer.setOnCompletionListener(beepListener); + + AssetFileDescriptor file = getResources().openRawResourceFd( + R.raw.beep); + try { + mediaPlayer.setDataSource(file.getFileDescriptor(), + file.getStartOffset(), file.getLength()); + file.close(); + mediaPlayer.setVolume(BEEP_VOLUME, BEEP_VOLUME); + mediaPlayer.prepare(); + } catch (IOException e) { + mediaPlayer = null; + } + } + } + + private static final long VIBRATE_DURATION = 200L; + + private void playBeepSoundAndVibrate() { + if (playBeep && mediaPlayer != null) { + mediaPlayer.start(); + } + if (vibrate) { + Vibrator vibrator = (Vibrator) getSystemService(VIBRATOR_SERVICE); + vibrator.vibrate(VIBRATE_DURATION); + } + } + + /** + * When the beep has finished playing, rewind to queue up another one. + */ + private final OnCompletionListener beepListener = new OnCompletionListener() { + public void onCompletion(MediaPlayer mediaPlayer) { + mediaPlayer.seekTo(0); + } + }; + + + private void initView() { + mBtnBack = (Button) findViewById(R.id.btn_back); + mBtnBack.setOnClickListener(this); + mTvTitle = (TextView) findViewById(R.id.tv_title); + mTvTitle.setText("激活授权"); + } + + @Override + public void onClick(View v) { + int id = v.getId(); + if (id == R.id.btn_back) { + finish(); + } + } } \ No newline at end of file diff --git a/app/src/main/java/com/fisherbone/fuzhu/zxing/decoding/CaptureActivityHandler.java b/app/src/main/java/com/fisherbone/fuzhu/zxing/decoding/CaptureActivityHandler.java index 89817ac..abb2be5 100644 --- a/app/src/main/java/com/fisherbone/fuzhu/zxing/decoding/CaptureActivityHandler.java +++ b/app/src/main/java/com/fisherbone/fuzhu/zxing/decoding/CaptureActivityHandler.java @@ -1,140 +1,133 @@ -/* - * Copyright (C) 2008 ZXing authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.fisherbone.fuzhu.zxing.decoding; - -import android.app.Activity; -import android.content.Intent; -import android.graphics.Bitmap; -import android.net.Uri; -import android.os.Bundle; -import android.os.Handler; -import android.os.Message; -import android.util.Log; - -import com.fisherbone.fuzhu.R; -import com.fisherbone.fuzhu.zxing.activity.CaptureActivity; -import com.fisherbone.fuzhu.zxing.camera.CameraManager; -import com.fisherbone.fuzhu.zxing.view.ViewfinderResultPointCallback; -import com.google.zxing.BarcodeFormat; -import com.google.zxing.Result; - -import java.util.Vector; - - -/** - * This class handles all the messaging which comprises the state machine for capture. - */ -public final class CaptureActivityHandler extends Handler { - - private static final String TAG = CaptureActivityHandler.class.getSimpleName(); - - private final CaptureActivity activity; - private final DecodeThread decodeThread; - private State state; - - private enum State { - PREVIEW, - SUCCESS, - DONE - } - - public CaptureActivityHandler(CaptureActivity activity, Vector decodeFormats, - String characterSet) { - this.activity = activity; - decodeThread = new DecodeThread(activity, decodeFormats, characterSet, - new ViewfinderResultPointCallback(activity.getViewfinderView())); - decodeThread.start(); - state = State.SUCCESS; - // Start ourselves capturing previews and decoding. - CameraManager.get().startPreview(); - restartPreviewAndDecode(); - } - - @Override - public void handleMessage(Message message) { - switch (message.what) { - case R.id.auto_focus: - //Log.d(TAG, "Got auto-focus message"); - // When one auto focus pass finishes, start another. This is the closest thing to - // continuous AF. It does seem to hunt a bit, but I'm not sure what else to do. - if (state == State.PREVIEW) { - CameraManager.get().requestAutoFocus(this, R.id.auto_focus); - } - break; - case R.id.restart_preview: - Log.d(TAG, "Got restart preview message"); - restartPreviewAndDecode(); - break; - case R.id.decode_succeeded: - Log.d(TAG, "Got decode succeeded message"); - state = State.SUCCESS; - Bundle bundle = message.getData(); - - /***********************************************************************/ - Bitmap barcode = bundle == null ? null : - (Bitmap) bundle.getParcelable(DecodeThread.BARCODE_BITMAP);//���ñ����߳� - - activity.handleDecode((Result) message.obj, barcode);//���ؽ�� - /***********************************************************************/ - break; - case R.id.decode_failed: - // We're decoding as fast as possible, so when one decode fails, start another. - state = State.PREVIEW; - CameraManager.get().requestPreviewFrame(decodeThread.getHandler(), R.id.decode); - break; - case R.id.return_scan_result: - Log.d(TAG, "Got return scan result message"); - activity.setResult(Activity.RESULT_OK, (Intent) message.obj); - activity.finish(); - break; - case R.id.launch_product_query: - Log.d(TAG, "Got product query message"); - String url = (String) message.obj; - Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); - intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); - activity.startActivity(intent); - break; - default: - } - } - - public void quitSynchronously() { - state = State.DONE; - CameraManager.get().stopPreview(); - Message quit = Message.obtain(decodeThread.getHandler(), R.id.quit); - quit.sendToTarget(); - try { - decodeThread.join(); - } catch (InterruptedException e) { - // continue - } - - // Be absolutely sure we don't send any queued up messages - removeMessages(R.id.decode_succeeded); - removeMessages(R.id.decode_failed); - } - - private void restartPreviewAndDecode() { - if (state == State.SUCCESS) { - state = State.PREVIEW; - CameraManager.get().requestPreviewFrame(decodeThread.getHandler(), R.id.decode); - CameraManager.get().requestAutoFocus(this, R.id.auto_focus); - activity.drawViewfinder(); - } - } - -} +/* + * Copyright (C) 2008 ZXing authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.fisherbone.fuzhu.zxing.decoding; + +import android.app.Activity; +import android.content.Intent; +import android.graphics.Bitmap; +import android.net.Uri; +import android.os.Bundle; +import android.os.Handler; +import android.os.Message; +import android.util.Log; + +import com.fisherbone.fuzhu.R; +import com.fisherbone.fuzhu.zxing.activity.CaptureActivity; +import com.fisherbone.fuzhu.zxing.camera.CameraManager; +import com.fisherbone.fuzhu.zxing.view.ViewfinderResultPointCallback; +import com.google.zxing.BarcodeFormat; +import com.google.zxing.Result; + +import java.util.Vector; + + +/** + * This class handles all the messaging which comprises the state machine for capture. + */ +public final class CaptureActivityHandler extends Handler { + + private static final String TAG = CaptureActivityHandler.class.getSimpleName(); + + private final CaptureActivity activity; + private final DecodeThread decodeThread; + private State state; + + private enum State { + PREVIEW, + SUCCESS, + DONE + } + + public CaptureActivityHandler(CaptureActivity activity, Vector decodeFormats, + String characterSet) { + this.activity = activity; + decodeThread = new DecodeThread(activity, decodeFormats, characterSet, + new ViewfinderResultPointCallback(activity.getViewfinderView())); + decodeThread.start(); + state = State.SUCCESS; + // Start ourselves capturing previews and decoding. + CameraManager.get().startPreview(); + restartPreviewAndDecode(); + } + + @Override + public void handleMessage(Message message) { + int what = message.what; + if (what == R.id.auto_focus) { + //Log.d(TAG, "Got auto-focus message"); + // When one auto focus pass finishes, start another. This is the closest thing to + // continuous AF. It does seem to hunt a bit, but I'm not sure what else to do. + if (state == State.PREVIEW) { + CameraManager.get().requestAutoFocus(this, R.id.auto_focus); + } + } else if (what == R.id.restart_preview) { + Log.d(TAG, "Got restart preview message"); + restartPreviewAndDecode(); + } else if (what == R.id.decode_succeeded) { + Log.d(TAG, "Got decode succeeded message"); + state = State.SUCCESS; + Bundle bundle = message.getData(); + + /***********************************************************************/ + Bitmap barcode = bundle == null ? null : + (Bitmap) bundle.getParcelable(DecodeThread.BARCODE_BITMAP);//���ñ����߳� + + activity.handleDecode((Result) message.obj, barcode);//���ؽ�� + /***********************************************************************/ + } else if (what == R.id.decode_failed) { + // We're decoding as fast as possible, so when one decode fails, start another. + state = State.PREVIEW; + CameraManager.get().requestPreviewFrame(decodeThread.getHandler(), R.id.decode); + } else if (what == R.id.return_scan_result) { + Log.d(TAG, "Got return scan result message"); + activity.setResult(Activity.RESULT_OK, (Intent) message.obj); + activity.finish(); + } else if (what == R.id.launch_product_query) { + Log.d(TAG, "Got product query message"); + String url = (String) message.obj; + Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); + intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); + activity.startActivity(intent); + } + } + + public void quitSynchronously() { + state = State.DONE; + CameraManager.get().stopPreview(); + Message quit = Message.obtain(decodeThread.getHandler(), R.id.quit); + quit.sendToTarget(); + try { + decodeThread.join(); + } catch (InterruptedException e) { + // continue + } + + // Be absolutely sure we don't send any queued up messages + removeMessages(R.id.decode_succeeded); + removeMessages(R.id.decode_failed); + } + + private void restartPreviewAndDecode() { + if (state == State.SUCCESS) { + state = State.PREVIEW; + CameraManager.get().requestPreviewFrame(decodeThread.getHandler(), R.id.decode); + CameraManager.get().requestAutoFocus(this, R.id.auto_focus); + activity.drawViewfinder(); + } + } + +} diff --git a/app/src/main/java/com/fisherbone/fuzhu/zxing/decoding/DecodeHandler.java b/app/src/main/java/com/fisherbone/fuzhu/zxing/decoding/DecodeHandler.java index 6cf0f2a..940b52a 100644 --- a/app/src/main/java/com/fisherbone/fuzhu/zxing/decoding/DecodeHandler.java +++ b/app/src/main/java/com/fisherbone/fuzhu/zxing/decoding/DecodeHandler.java @@ -1,113 +1,110 @@ -/* - * Copyright (C) 2010 ZXing authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.fisherbone.fuzhu.zxing.decoding; - -import android.os.Bundle; -import android.os.Handler; -import android.os.Looper; -import android.os.Message; -import android.util.Log; - -import com.fisherbone.fuzhu.R; -import com.fisherbone.fuzhu.zxing.activity.CaptureActivity; -import com.fisherbone.fuzhu.zxing.camera.CameraManager; -import com.fisherbone.fuzhu.zxing.camera.PlanarYUVLuminanceSource; -import com.google.zxing.BinaryBitmap; -import com.google.zxing.DecodeHintType; -import com.google.zxing.MultiFormatReader; -import com.google.zxing.ReaderException; -import com.google.zxing.Result; -import com.google.zxing.common.HybridBinarizer; - -import java.util.Hashtable; - - -final class DecodeHandler extends Handler { - - private static final String TAG = DecodeHandler.class.getSimpleName(); - - private final CaptureActivity activity; - private final MultiFormatReader multiFormatReader; - - DecodeHandler(CaptureActivity activity, Hashtable hints) { - multiFormatReader = new MultiFormatReader(); - multiFormatReader.setHints(hints); - this.activity = activity; - } - - @Override - public void handleMessage(Message message) { - switch (message.what) { - case R.id.decode: - //Log.d(TAG, "Got decode message"); - decode((byte[]) message.obj, message.arg1, message.arg2); - break; - case R.id.quit: - Looper.myLooper().quit(); - break; - default: - } - } - - /** - * Decode the data within the viewfinder rectangle, and time how long it took. For efficiency, - * reuse the same reader objects from one decode to the next. - * - * @param data The YUV preview frame. - * @param width The width of the preview frame. - * @param height The height of the preview frame. - */ - private void decode(byte[] data, int width, int height) { - long start = System.currentTimeMillis(); - Result rawResult = null; - - //modify here - byte[] rotatedData = new byte[data.length]; - for (int y = 0; y < height; y++) { - for (int x = 0; x < width; x++) - rotatedData[x * height + height - y - 1] = data[x + y * width]; - } - int tmp = width; // Here we are swapping, that's the difference to #11 - width = height; - height = tmp; - - PlanarYUVLuminanceSource source = CameraManager.get().buildLuminanceSource(rotatedData, width, height); - BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source)); - try { - rawResult = multiFormatReader.decodeWithState(bitmap); - } catch (ReaderException re) { - // continue - } finally { - multiFormatReader.reset(); - } - - if (rawResult != null) { - long end = System.currentTimeMillis(); - Log.d(TAG, "Found barcode (" + (end - start) + " ms):\n" + rawResult.toString()); - Message message = Message.obtain(activity.getHandler(), R.id.decode_succeeded, rawResult); - Bundle bundle = new Bundle(); - bundle.putParcelable(DecodeThread.BARCODE_BITMAP, source.renderCroppedGreyscaleBitmap()); - message.setData(bundle); - //Log.d(TAG, "Sending decode succeeded message..."); - message.sendToTarget(); - } else { - Message message = Message.obtain(activity.getHandler(), R.id.decode_failed); - message.sendToTarget(); - } - } - -} +/* + * Copyright (C) 2010 ZXing authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.fisherbone.fuzhu.zxing.decoding; + +import android.os.Bundle; +import android.os.Handler; +import android.os.Looper; +import android.os.Message; +import android.util.Log; + +import com.fisherbone.fuzhu.R; +import com.fisherbone.fuzhu.zxing.activity.CaptureActivity; +import com.fisherbone.fuzhu.zxing.camera.CameraManager; +import com.fisherbone.fuzhu.zxing.camera.PlanarYUVLuminanceSource; +import com.google.zxing.BinaryBitmap; +import com.google.zxing.DecodeHintType; +import com.google.zxing.MultiFormatReader; +import com.google.zxing.ReaderException; +import com.google.zxing.Result; +import com.google.zxing.common.HybridBinarizer; + +import java.util.Hashtable; + + +final class DecodeHandler extends Handler { + + private static final String TAG = DecodeHandler.class.getSimpleName(); + + private final CaptureActivity activity; + private final MultiFormatReader multiFormatReader; + + DecodeHandler(CaptureActivity activity, Hashtable hints) { + multiFormatReader = new MultiFormatReader(); + multiFormatReader.setHints(hints); + this.activity = activity; + } + + @Override + public void handleMessage(Message message) { + int what = message.what; + if (what == R.id.decode) { + //Log.d(TAG, "Got decode message"); + decode((byte[]) message.obj, message.arg1, message.arg2); + } else if (what == R.id.quit) { + Looper.myLooper().quit(); + } + } + + /** + * Decode the data within the viewfinder rectangle, and time how long it took. For efficiency, + * reuse the same reader objects from one decode to the next. + * + * @param data The YUV preview frame. + * @param width The width of the preview frame. + * @param height The height of the preview frame. + */ + private void decode(byte[] data, int width, int height) { + long start = System.currentTimeMillis(); + Result rawResult = null; + + //modify here + byte[] rotatedData = new byte[data.length]; + for (int y = 0; y < height; y++) { + for (int x = 0; x < width; x++) + rotatedData[x * height + height - y - 1] = data[x + y * width]; + } + int tmp = width; // Here we are swapping, that's the difference to #11 + width = height; + height = tmp; + + PlanarYUVLuminanceSource source = CameraManager.get().buildLuminanceSource(rotatedData, width, height); + BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source)); + try { + rawResult = multiFormatReader.decodeWithState(bitmap); + } catch (ReaderException re) { + // continue + } finally { + multiFormatReader.reset(); + } + + if (rawResult != null) { + long end = System.currentTimeMillis(); + Log.d(TAG, "Found barcode (" + (end - start) + " ms):\n" + rawResult.toString()); + Message message = Message.obtain(activity.getHandler(), R.id.decode_succeeded, rawResult); + Bundle bundle = new Bundle(); + bundle.putParcelable(DecodeThread.BARCODE_BITMAP, source.renderCroppedGreyscaleBitmap()); + message.setData(bundle); + //Log.d(TAG, "Sending decode succeeded message..."); + message.sendToTarget(); + } else { + Message message = Message.obtain(activity.getHandler(), R.id.decode_failed); + message.sendToTarget(); + } + } + +} diff --git a/app/src/main/res/layout/activity_setting.xml b/app/src/main/res/layout/activity_setting.xml index 90e5f55..dd6a395 100644 --- a/app/src/main/res/layout/activity_setting.xml +++ b/app/src/main/res/layout/activity_setting.xml @@ -1,394 +1,393 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app_config.gradle b/app_config.gradle index 62d384d..cc7ee68 100644 --- a/app_config.gradle +++ b/app_config.gradle @@ -1,73 +1,73 @@ -ext { - - // 测试环境 / 正式环境 (组件化环境 / 集成化环境) - isRelease = false; - - // 定义一个包名,用于存放APT生成的所有类文件 - packageNameForAPT = "com.fisherbone.fuzhu"; - - app_android = [ - compileSdkVersion : 29, - buildToolsVersion : "29.0.3", - applicationId : "com.fisherbone.fuzhu", - minSdkVersion : 24, - targetSdkVersion : 29, - versionCode : 182, - versionName : "1.8.2", - testInstrumentationRunner: "androidx.test.runner.AndroidJUnitRunner" - ] - - // order,personal,自己的包名 -// app_appid = [ -// "order": "com.fisherbone.fuzhu.order", -// "personal": "com.fisherbone.fuzhu.personal" -// ] - app_appid = [ - app: "com.fisherbone.fuzhu", - wechat: "com.derry.wechat", - register: "com.derry.register" - ] - - // 测试环境的服务器地址,和,正式环境服务器地址 - url = [ - "debug" : "http://139.186.151.48", - "release": "http://139.186.151.48" - ] - - - - // 定义依赖项,体现真实开发项目的过程 - app_dependencies = [ - "appcompat": 'androidx.appcompat:appcompat:1.1.0', - "constraint": 'androidx.constraintlayout:constraintlayout:1.1.3', - "okhttp3" : "com.squareup.okhttp3:okhttp:3.10.0", - "retrofit" : "com.squareup.retrofit2:retrofit:2.5.0", - "fastjson" : "com.alibaba:fastjson:1.2.58", - "cardview" : "androidx.cardview:cardview:1.0.0", - "annotation" : "androidx.annotation:annotation:1.1.0", - "immersionbar" : "com.gyf.immersionbar:immersionbar:3.0.0", - "components" : "com.gyf.immersionbar:immersionbar-components:3.0.0", - "systembartint" : "com.readystatesoftware.systembartint:systembartint:1.0.4", - "BaseRecyclerViewAdapterHelper" : "com.github.CymChad:BaseRecyclerViewAdapterHelper:2.9.30", - "recyclerview" : "androidx.recyclerview:recyclerview:1.0.0", - "okgo" : "com.lzy.net:okgo:3.0.4", - "okrx2" : "com.lzy.net:okrx2:2.0.2", - "okserver" : "com.lzy.net:okserver:2.0.5", - "ormlite-core" : "com.j256.ormlite:ormlite-core:5.1", - "ormlite-android" : "com.j256.ormlite:ormlite-android:5.1", - "rxandroid" : "io.reactivex.rxjava2:rxandroid:2.0.1", - "butterknife" : "com.jakewharton:butterknife:8.0.1", - "zxing:core" : "com.google.zxing:core:3.3.0", - "easypermissions" : "pub.devrel:easypermissions:3.0.0", - "rxpermissions" : "com.tbruyelle.rxpermissions2:rxpermissions:0.9.5@aar", - "rxjava" : "io.reactivex.rxjava2:rxjava:2.0.1", - "retrofit" : "com.squareup.retrofit2:retrofit:2.1.0", - "retrofit2-rxjava2-adapter" : "com.jakewharton.retrofit:retrofit2-rxjava2-adapter:1.0.0", - "converter-gson" : "com.squareup.retrofit2:converter-gson:2.1.0", - "MNPasswordEditText" : "com.github.maning0303:MNPasswordEditText:V1.0.3", - "process-phoenix" : "com.jakewharton:process-phoenix:2.0.0", - "live-event-bus-x" : "com.jeremyliao:live-event-bus-x:1.7.3", - "rxbinding" : "com.jakewharton.rxbinding2:rxbinding:2.1.1", - ] - +ext { + + // 测试环境 / 正式环境 (组件化环境 / 集成化环境) + isRelease = false; + + // 定义一个包名,用于存放APT生成的所有类文件 + packageNameForAPT = "com.fisherbone.fuzhu"; + + app_android = [ + compileSdkVersion : 34, + buildToolsVersion : "30.0.2", + applicationId : "com.fisherbone.fuzhu", + minSdkVersion : 26, + targetSdkVersion : 34, + versionCode : 182, + versionName : "1.8.2", + testInstrumentationRunner: "androidx.test.runner.AndroidJUnitRunner" + ] + + // order,personal,自己的包名 +// app_appid = [ +// "order": "com.fisherbone.fuzhu.order", +// "personal": "com.fisherbone.fuzhu.personal" +// ] + app_appid = [ + app: "com.fisherbone.fuzhu", + wechat: "com.derry.wechat", + register: "com.derry.register" + ] + + // 测试环境的服务器地址,和,正式环境服务器地址 + url = [ + "debug" : "http://139.186.151.48", + "release": "http://139.186.151.48" + ] + + + + // 定义依赖项,体现真实开发项目的过程 + app_dependencies = [ + "appcompat": 'androidx.appcompat:appcompat:1.1.0', + "constraint": 'androidx.constraintlayout:constraintlayout:1.1.3', + "okhttp3" : "com.squareup.okhttp3:okhttp:3.10.0", + "retrofit" : "com.squareup.retrofit2:retrofit:2.5.0", + "fastjson" : "com.alibaba:fastjson:1.2.58", + "cardview" : "androidx.cardview:cardview:1.0.0", + "annotation" : "androidx.annotation:annotation:1.1.0", + "immersionbar" : "com.gyf.immersionbar:immersionbar:3.0.0", + "components" : "com.gyf.immersionbar:immersionbar-components:3.0.0", + "systembartint" : "com.readystatesoftware.systembartint:systembartint:1.0.4", + "BaseRecyclerViewAdapterHelper" : "com.github.CymChad:BaseRecyclerViewAdapterHelper:2.9.30", + "recyclerview" : "androidx.recyclerview:recyclerview:1.0.0", + "okgo" : "com.lzy.net:okgo:3.0.4", + "okrx2" : "com.lzy.net:okrx2:2.0.2", + "okserver" : "com.lzy.net:okserver:2.0.5", + "ormlite-core" : "com.j256.ormlite:ormlite-core:5.1", + "ormlite-android" : "com.j256.ormlite:ormlite-android:5.1", + "rxandroid" : "io.reactivex.rxjava2:rxandroid:2.0.1", + "butterknife" : "com.jakewharton:butterknife:8.0.1", + "zxing:core" : "com.google.zxing:core:3.3.0", + "easypermissions" : "pub.devrel:easypermissions:3.0.0", + "rxpermissions" : "com.tbruyelle.rxpermissions2:rxpermissions:0.9.5@aar", + "rxjava" : "io.reactivex.rxjava2:rxjava:2.0.1", + "retrofit" : "com.squareup.retrofit2:retrofit:2.1.0", + "retrofit2-rxjava2-adapter" : "com.jakewharton.retrofit:retrofit2-rxjava2-adapter:1.0.0", + "converter-gson" : "com.squareup.retrofit2:converter-gson:2.1.0", + "MNPasswordEditText" : "com.github.maning0303:MNPasswordEditText:V1.0.3", + "process-phoenix" : "com.jakewharton:process-phoenix:2.0.0", + "live-event-bus-x" : "com.jeremyliao:live-event-bus-x:1.7.3", + "rxbinding" : "com.jakewharton.rxbinding2:rxbinding:2.1.1", + ] + } \ No newline at end of file diff --git a/arouter_annotation/build.gradle b/arouter_annotation/build.gradle index d933f52..8e34d02 100644 --- a/arouter_annotation/build.gradle +++ b/arouter_annotation/build.gradle @@ -1,14 +1,14 @@ -apply plugin: 'java-library' - -dependencies { - implementation fileTree(dir: 'libs', include: ['*.jar']) -} - -// java控制台输出中文乱码 -tasks.withType(JavaCompile) { - options.encoding = "UTF-8" -} - - -sourceCompatibility = "7" -targetCompatibility = "7" +apply plugin: 'java-library' + +dependencies { + implementation fileTree(dir: 'libs', include: ['*.jar']) +} + +// java控制台输出中文乱码 +tasks.withType(JavaCompile) { + options.encoding = "UTF-8" +} + + +sourceCompatibility = JavaVersion.VERSION_1_8 +targetCompatibility = JavaVersion.VERSION_1_8 diff --git a/arouter_api/build.gradle b/arouter_api/build.gradle index 690a739..c2335f7 100644 --- a/arouter_api/build.gradle +++ b/arouter_api/build.gradle @@ -1,35 +1,44 @@ -apply plugin: 'com.android.library' - -android { - compileSdkVersion 29 - buildToolsVersion "29.0.3" - - - defaultConfig { - minSdkVersion 15 - targetSdkVersion 29 - - testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" - - } - - buildTypes { - release { - minifyEnabled false - proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' - } - } - -} - -dependencies { - implementation fileTree(dir: 'libs', include: ['*.jar']) - - implementation 'androidx.appcompat:appcompat:1.1.0' - testImplementation 'junit:junit:4.12' - androidTestImplementation 'androidx.test:runner:1.2.0' - androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' - - // 引入注解中RouterBean对象(java项目才有javax.lang包) - implementation project(':arouter_annotation') -} +apply plugin: 'com.android.library' + +android { + namespace 'com.xiangxue.arouter_api' + compileSdk 34 + compileSdkVersion 34 + buildToolsVersion "30.0.2" + + + defaultConfig { + minSdk 26 + minSdkVersion 26 + targetSdk 34 + targetSdkVersion 34 + + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + + } + + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } + + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + } + } + +} + +dependencies { + implementation fileTree(dir: 'libs', include: ['*.jar']) + + implementation 'androidx.appcompat:appcompat:1.1.0' + testImplementation 'junit:junit:4.12' + androidTestImplementation 'androidx.test:runner:1.2.0' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' + + // 引入注解中RouterBean对象(java项目才有javax.lang包) + implementation project(':arouter_annotation') +} diff --git a/arouter_compiler/build.gradle b/arouter_compiler/build.gradle index 77eab8b..d78c5ef 100644 --- a/arouter_compiler/build.gradle +++ b/arouter_compiler/build.gradle @@ -20,5 +20,5 @@ tasks.withType(JavaCompile) { options.encoding = "UTF-8" } -sourceCompatibility = "7" -targetCompatibility = "7" +sourceCompatibility = JavaVersion.VERSION_1_8 +targetCompatibility = JavaVersion.VERSION_1_8 diff --git a/arouter_compiler/build/.transforms/17eb5e4bd52cfe966d9ac3821235f180.bin b/arouter_compiler/build/.transforms/17eb5e4bd52cfe966d9ac3821235f180.bin deleted file mode 100644 index afed043..0000000 --- a/arouter_compiler/build/.transforms/17eb5e4bd52cfe966d9ac3821235f180.bin +++ /dev/null @@ -1 +0,0 @@ -o/jetified-arouter_compiler.jar diff --git a/arouter_compiler/build/.transforms/17eb5e4bd52cfe966d9ac3821235f180/jetified-arouter_compiler.jar b/arouter_compiler/build/.transforms/17eb5e4bd52cfe966d9ac3821235f180/jetified-arouter_compiler.jar deleted file mode 100644 index ae11e50..0000000 Binary files a/arouter_compiler/build/.transforms/17eb5e4bd52cfe966d9ac3821235f180/jetified-arouter_compiler.jar and /dev/null differ diff --git a/arouter_compiler/build/.transforms/4df56d52ca327df9f8638b4e5b60405e.bin b/arouter_compiler/build/.transforms/4df56d52ca327df9f8638b4e5b60405e.bin deleted file mode 100644 index 1ed65e0..0000000 --- a/arouter_compiler/build/.transforms/4df56d52ca327df9f8638b4e5b60405e.bin +++ /dev/null @@ -1 +0,0 @@ -i/ diff --git a/arouter_compiler/build/.transforms/5b16662ec16299c18f37d3c75367c3e3.bin b/arouter_compiler/build/.transforms/5b16662ec16299c18f37d3c75367c3e3.bin deleted file mode 100644 index 1ed65e0..0000000 --- a/arouter_compiler/build/.transforms/5b16662ec16299c18f37d3c75367c3e3.bin +++ /dev/null @@ -1 +0,0 @@ -i/ diff --git a/arouter_compiler/build/.transforms/69f676345dfd5d34e6eee49b34321dad.bin b/arouter_compiler/build/.transforms/69f676345dfd5d34e6eee49b34321dad.bin deleted file mode 100644 index 1ed65e0..0000000 --- a/arouter_compiler/build/.transforms/69f676345dfd5d34e6eee49b34321dad.bin +++ /dev/null @@ -1 +0,0 @@ -i/ diff --git a/arouter_compiler/build/.transforms/7986e55c0ba5fa129b1fda1b94a90ca2.bin b/arouter_compiler/build/.transforms/7986e55c0ba5fa129b1fda1b94a90ca2.bin deleted file mode 100644 index 1ed65e0..0000000 --- a/arouter_compiler/build/.transforms/7986e55c0ba5fa129b1fda1b94a90ca2.bin +++ /dev/null @@ -1 +0,0 @@ -i/ diff --git a/arouter_compiler/build/.transforms/d476367ae559214f0f9ca8a2bdba85a3.bin b/arouter_compiler/build/.transforms/d476367ae559214f0f9ca8a2bdba85a3.bin deleted file mode 100644 index 1ed65e0..0000000 --- a/arouter_compiler/build/.transforms/d476367ae559214f0f9ca8a2bdba85a3.bin +++ /dev/null @@ -1 +0,0 @@ -i/ diff --git a/arouter_compiler/build/.transforms/d5bf54c0e3c2134618ea93f35f798d70.bin b/arouter_compiler/build/.transforms/d5bf54c0e3c2134618ea93f35f798d70.bin deleted file mode 100644 index 1ed65e0..0000000 --- a/arouter_compiler/build/.transforms/d5bf54c0e3c2134618ea93f35f798d70.bin +++ /dev/null @@ -1 +0,0 @@ -i/ diff --git a/arouter_compiler/build/classes/java/main/META-INF/services/javax.annotation.processing.Processor b/arouter_compiler/build/classes/java/main/META-INF/services/javax.annotation.processing.Processor index fabe49c..b886d53 100644 --- a/arouter_compiler/build/classes/java/main/META-INF/services/javax.annotation.processing.Processor +++ b/arouter_compiler/build/classes/java/main/META-INF/services/javax.annotation.processing.Processor @@ -1,2 +1,2 @@ -com.xiangxue.arouter_compiler.ARouterProcessor -com.xiangxue.arouter_compiler.ParameterProcessor +com.xiangxue.arouter_compiler.ARouterProcessor +com.xiangxue.arouter_compiler.ParameterProcessor diff --git a/arouter_compiler/build/classes/java/main/com/xiangxue/arouter_compiler/ARouterProcessor.class b/arouter_compiler/build/classes/java/main/com/xiangxue/arouter_compiler/ARouterProcessor.class index 13c43ac..63bc5ee 100644 Binary files a/arouter_compiler/build/classes/java/main/com/xiangxue/arouter_compiler/ARouterProcessor.class and b/arouter_compiler/build/classes/java/main/com/xiangxue/arouter_compiler/ARouterProcessor.class differ diff --git a/arouter_compiler/build/classes/java/main/com/xiangxue/arouter_compiler/ParameterFactory$1.class b/arouter_compiler/build/classes/java/main/com/xiangxue/arouter_compiler/ParameterFactory$1.class index 0ef868f..aa2df2e 100644 Binary files a/arouter_compiler/build/classes/java/main/com/xiangxue/arouter_compiler/ParameterFactory$1.class and b/arouter_compiler/build/classes/java/main/com/xiangxue/arouter_compiler/ParameterFactory$1.class differ diff --git a/arouter_compiler/build/classes/java/main/com/xiangxue/arouter_compiler/ParameterFactory$Builder.class b/arouter_compiler/build/classes/java/main/com/xiangxue/arouter_compiler/ParameterFactory$Builder.class index 70293d6..854662d 100644 Binary files a/arouter_compiler/build/classes/java/main/com/xiangxue/arouter_compiler/ParameterFactory$Builder.class and b/arouter_compiler/build/classes/java/main/com/xiangxue/arouter_compiler/ParameterFactory$Builder.class differ diff --git a/arouter_compiler/build/classes/java/main/com/xiangxue/arouter_compiler/ParameterFactory.class b/arouter_compiler/build/classes/java/main/com/xiangxue/arouter_compiler/ParameterFactory.class index f02141a..54b3706 100644 Binary files a/arouter_compiler/build/classes/java/main/com/xiangxue/arouter_compiler/ParameterFactory.class and b/arouter_compiler/build/classes/java/main/com/xiangxue/arouter_compiler/ParameterFactory.class differ diff --git a/arouter_compiler/build/classes/java/main/com/xiangxue/arouter_compiler/ParameterProcessor.class b/arouter_compiler/build/classes/java/main/com/xiangxue/arouter_compiler/ParameterProcessor.class index 95047e0..9e30d40 100644 Binary files a/arouter_compiler/build/classes/java/main/com/xiangxue/arouter_compiler/ParameterProcessor.class and b/arouter_compiler/build/classes/java/main/com/xiangxue/arouter_compiler/ParameterProcessor.class differ diff --git a/arouter_compiler/build/classes/java/main/com/xiangxue/arouter_compiler/utils/ProcessorConfig.class b/arouter_compiler/build/classes/java/main/com/xiangxue/arouter_compiler/utils/ProcessorConfig.class index 239d240..8c6a71f 100644 Binary files a/arouter_compiler/build/classes/java/main/com/xiangxue/arouter_compiler/utils/ProcessorConfig.class and b/arouter_compiler/build/classes/java/main/com/xiangxue/arouter_compiler/utils/ProcessorConfig.class differ diff --git a/arouter_compiler/build/classes/java/main/com/xiangxue/arouter_compiler/utils/ProcessorUtils.class b/arouter_compiler/build/classes/java/main/com/xiangxue/arouter_compiler/utils/ProcessorUtils.class index 350ba96..4e3b708 100644 Binary files a/arouter_compiler/build/classes/java/main/com/xiangxue/arouter_compiler/utils/ProcessorUtils.class and b/arouter_compiler/build/classes/java/main/com/xiangxue/arouter_compiler/utils/ProcessorUtils.class differ diff --git a/arouter_compiler/build/libs/arouter_compiler.jar b/arouter_compiler/build/libs/arouter_compiler.jar index ae11e50..1f51fcc 100644 Binary files a/arouter_compiler/build/libs/arouter_compiler.jar and b/arouter_compiler/build/libs/arouter_compiler.jar differ diff --git a/arouter_compiler/build/tmp/compileJava/previous-compilation-data.bin b/arouter_compiler/build/tmp/compileJava/previous-compilation-data.bin new file mode 100644 index 0000000..7a3d9d7 Binary files /dev/null and b/arouter_compiler/build/tmp/compileJava/previous-compilation-data.bin differ diff --git a/arouter_compiler/build/tmp/compileJava/source-classes-mapping.txt b/arouter_compiler/build/tmp/compileJava/source-classes-mapping.txt deleted file mode 100644 index 36f1106..0000000 --- a/arouter_compiler/build/tmp/compileJava/source-classes-mapping.txt +++ /dev/null @@ -1,12 +0,0 @@ -com/xiangxue/arouter_compiler/utils/ProcessorConfig.java - com.xiangxue.arouter_compiler.utils.ProcessorConfig -com/xiangxue/arouter_compiler/ARouterProcessor.java - com.xiangxue.arouter_compiler.ARouterProcessor -com/xiangxue/arouter_compiler/ParameterProcessor.java - com.xiangxue.arouter_compiler.ParameterProcessor -com/xiangxue/arouter_compiler/utils/ProcessorUtils.java - com.xiangxue.arouter_compiler.utils.ProcessorUtils -com/xiangxue/arouter_compiler/ParameterFactory.java - com.xiangxue.arouter_compiler.ParameterFactory - com.xiangxue.arouter_compiler.ParameterFactory$1 - com.xiangxue.arouter_compiler.ParameterFactory$Builder diff --git a/arouter_compiler/build/tmp/jar/MANIFEST.MF b/arouter_compiler/build/tmp/jar/MANIFEST.MF index 59499bc..58630c0 100644 --- a/arouter_compiler/build/tmp/jar/MANIFEST.MF +++ b/arouter_compiler/build/tmp/jar/MANIFEST.MF @@ -1,2 +1,2 @@ -Manifest-Version: 1.0 - +Manifest-Version: 1.0 + diff --git a/build.gradle b/build.gradle index 5095cb0..51fc618 100644 --- a/build.gradle +++ b/build.gradle @@ -1,31 +1,63 @@ -// Top-level build file where you can add configuration options common to all sub-projects/modules. - -// 非常重要,根目录的build.gradle头部加入自定义gradle,相当于layout布局中include -apply from : "app_config.gradle" - -buildscript { - ext.kotlin_version = '1.3.72' - repositories { - google() - jcenter() - - } - dependencies { - classpath 'com.android.tools.build:gradle:4.1.0' - classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" - // NOTE: Do not place your application dependencies here; they belong - // in the individual module build.gradle files - } -} - -allprojects { - repositories { - google() - jcenter() - maven { url 'https://jitpack.io' } - } -} - -task clean(type: Delete) { - delete rootProject.buildDir -} +// Top-level build file where you can add configuration options common to all sub-projects/modules. + +// 非常重要,根目录的build.gradle头部加入自定义gradle,相当于layout布局中include +apply from : "app_config.gradle" + +buildscript { + + ext { + agp_version = '8.7.3' + } + repositories { + maven { url 'https://maven.aliyun.com/nexus/content/groups/public/' } + maven { url 'https://maven.aliyun.com/repository/public' }//jcenter + maven { url 'https://maven.aliyun.com/repository/gradle-plugin' }//gradle-plugin + maven { url 'https://maven.aliyun.com/repository/central' }//central + maven { url 'https://maven.aliyun.com/repository/google' }//google + google() + jcenter() + mavenCentral() + + maven { url "https://jitpack.io" } + + maven { + url "https://plugins.gradle.org/m2/" + } + } + dependencies { + + classpath "com.android.tools.build:gradle:$agp_version" + classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5' + classpath "net.ltgt.gradle:gradle-errorprone-plugin:0.6" + // Kotlin 标准库(DataBinding 编译器在 AGP 8.x 中需要) + classpath 'org.jetbrains.kotlin:kotlin-stdlib:1.9.22' + + } +} + +allprojects { + repositories { + maven { url 'https://maven.aliyun.com/nexus/content/groups/public/' } + maven { url 'https://maven.aliyun.com/repository/public' }//jcenter + maven { url 'https://maven.aliyun.com/repository/gradle-plugin' }//gradle-plugin + maven { url 'https://maven.aliyun.com/repository/central' }//central + maven { url 'https://maven.aliyun.com/repository/google' }//google + flatDir { + dirs 'libs' + } + + + google() + jcenter() + maven { url "https://jitpack.io"} + maven { url "https://www.jitpack.io" } +// maven { url 'https://dl.bintray.com/aweme-open-sdk-team/public' } + + + + } +} + +task clean(type: Delete) { + delete rootProject.buildDir +} diff --git a/common/build.gradle b/common/build.gradle index d3c98d7..6fad8a8 100644 --- a/common/build.gradle +++ b/common/build.gradle @@ -1,45 +1,58 @@ -apply plugin: 'com.android.library' - -android { - compileSdkVersion app_android.compileSdkVersion - buildToolsVersion app_android.buildToolsVersion - defaultConfig { - minSdkVersion app_android.minSdkVersion - targetSdkVersion app_android.targetSdkVersion - consumerProguardFiles 'consumer-rules.pro' - } - - buildTypes { - release { - minifyEnabled false - proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' - } - } - -} - -dependencies { - implementation 'com.squareup.retrofit2:retrofit:2.3.0' - api 'com.squareup.retrofit2:converter-gson:2.3.0' - implementation 'com.squareup.okhttp3:logging-interceptor:3.9.0' - implementation 'com.squareup.retrofit2:adapter-rxjava2:2.4.0' - //v1.5 - api 'io.reactivex.rxjava2:rxandroid:2.1.1' - // Because RxAndroid releases are few and far between, it is recommended you also - // explicitly depend on RxJava's latest version for bug fixes and new features. - // (see https://github.com/ReactiveX/RxJava/releases for latest 2.x.x version) - api 'io.reactivex.rxjava2:rxjava:2.2.12' - - - api 'androidx.preference:preference:1.0.0' - - - implementation 'androidx.appcompat:appcompat:1.1.0' - testImplementation 'junit:junit:4.12' - androidTestImplementation 'androidx.test:runner:1.2.0' - androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' - - // 因为每一个 “子Module”都依赖了 common,所有当我们在 common中依赖 arouter_api(柱状) - // 就等于 全部都依赖了 arouter_api - api project(":arouter_api") -} +apply plugin: 'com.android.library' + +android { + namespace 'com.xiangxue.common' + compileSdk app_android.compileSdkVersion + compileSdkVersion app_android.compileSdkVersion + buildToolsVersion app_android.buildToolsVersion + defaultConfig { + minSdk app_android.minSdkVersion + minSdkVersion app_android.minSdkVersion + targetSdk app_android.targetSdkVersion + targetSdkVersion app_android.targetSdkVersion + consumerProguardFiles 'consumer-rules.pro' + } + + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } + + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + } + } + +} + +dependencies { + implementation 'com.squareup.retrofit2:retrofit:2.3.0' + api 'com.squareup.retrofit2:converter-gson:2.3.0' + implementation 'com.squareup.okhttp3:logging-interceptor:3.9.0' + implementation 'com.squareup.retrofit2:adapter-rxjava2:2.4.0' + //v1.5 + api 'io.reactivex.rxjava2:rxandroid:2.1.1' + // Because RxAndroid releases are few and far between, it is recommended you also + // explicitly depend on RxJava's latest version for bug fixes and new features. + // (see https://github.com/ReactiveX/RxJava/releases for latest 2.x.x version) + api 'io.reactivex.rxjava2:rxjava:2.2.12' + + + api 'androidx.preference:preference:1.0.0' + + + implementation 'androidx.appcompat:appcompat:1.1.0' + testImplementation 'junit:junit:4.12' + androidTestImplementation 'androidx.test:runner:1.2.0' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' + + // 因为每一个 "子Module"都依赖了 common,所有当我们在 common中依赖 arouter_api(柱状) + // 就等于 全部都依赖了 arouter_api + api project(":arouter_api") + + // Kotlin 标准库(DataBinding 在 AGP 8.x 中需要,参考 android-im 的做法) + // 使用 api 让所有依赖 common 的模块都能获得 Kotlin 标准库 + api 'org.jetbrains.kotlin:kotlin-stdlib:1.9.22' +} diff --git a/gradle.properties b/gradle.properties index 199d16e..00c1e37 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,20 +1,28 @@ -# Project-wide Gradle settings. -# IDE (e.g. Android Studio) users: -# Gradle settings configured through the IDE *will override* -# any settings specified in this file. -# For more details on how to configure your build environment visit -# http://www.gradle.org/docs/current/userguide/build_environment.html -# Specifies the JVM arguments used for the daemon process. -# The setting is particularly useful for tweaking memory settings. -org.gradle.jvmargs=-Xmx1536m -# When configured, Gradle will run in incubating parallel mode. -# This option should only be used with decoupled projects. More details, visit -# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects -# org.gradle.parallel=true -# AndroidX package structure to make it clearer which packages are bundled with the -# Android operating system, and which are packaged with your app's APK -# https://developer.android.com/topic/libraries/support-library/androidx-rn -android.useAndroidX=true -# Automatically convert third-party libraries to use AndroidX -android.enableJetifier=true - +# Project-wide Gradle settings. +# IDE (e.g. Android Studio) users: +# Gradle settings configured through the IDE *will override* +# any settings specified in this file. +# For more details on how to configure your build environment visit +# http://www.gradle.org/docs/current/userguide/build_environment.html +# Specifies the JVM arguments used for the daemon process. +# The setting is particularly useful for tweaking memory settings. +org.gradle.jvmargs=-Xmx1536m +# When configured, Gradle will run in incubating parallel mode. +# This option should only be used with decoupled projects. More details, visit +# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects +# org.gradle.parallel=true +# AndroidX package structure to make it clearer which packages are bundled with the +# Android operating system, and which are packaged with your app's APK +# https://developer.android.com/topic/libraries/support-library/androidx-rn +android.useAndroidX=true +# Automatically convert third-party libraries to use AndroidX +android.enableJetifier=true +android.nonTransitiveRClass=true +# 使资源 ID 恢复为编译时常量(AGP 8.x 需要) +android.nonFinalResIds=false +# Suppress deprecation warnings for Java 8 source/target +android.javaCompile.suppressSourceTargetDeprecationWarning=true +# Use the JDK from Android Studio (uncomment and set path if needed) +# org.gradle.java.home=C:/Program Files/Android/Android Studio/jbr + + diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 3bffba1..800788a 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Mon Dec 13 11:44:16 CST 2021 -distributionBase=GRADLE_USER_HOME -distributionPath=wrapper/dists -zipStoreBase=GRADLE_USER_HOME -zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip +#Tue Nov 11 10:04:16 CST 2025 +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/order/build.gradle b/order/build.gradle index ec3d184..c5a80d7 100644 --- a/order/build.gradle +++ b/order/build.gradle @@ -1,90 +1,103 @@ -if (isRelease) { // 如果是发布版本时,各个模块都不能独立运行 - apply plugin: 'com.android.library' -} else { - apply plugin: 'com.android.application' -} - -android { - compileSdkVersion app_android.compileSdkVersion - buildToolsVersion app_android.buildToolsVersion - defaultConfig { - // applicationId app_appid.order - if (!isRelease) { // 如果是集成化模式,不能有applicationId - applicationId app_appid.order // 组件化模式能独立运行才能有applicationId - } - - minSdkVersion app_android.minSdkVersion - targetSdkVersion app_android.targetSdkVersion - versionCode app_android.versionCode - versionName app_android.versionName - testInstrumentationRunner app_android.testInstrumentationRunner - - // 这个方法接收三个非空的参数,第一个:确定值的类型,第二个:指定key的名字,第三个:传值(必须是String) - // 为什么需要定义这个?因为src代码中有可能需要用到跨模块交互,如果是组件化模块显然不行 - // 切记:不能在android根节点,只能在defaultConfig或buildTypes节点下 - buildConfigField("boolean", "isRelease", String.valueOf(isRelease)) - - // 都是为了 传递给 注解处理器 - // 在gradle文件中配置选项参数值(用于APT传参接收) - // 同学们注意:切记:必须写在defaultConfig节点下 - javaCompileOptions { - annotationProcessorOptions { - // project.getName() == order - // this.project.getName() == order - // this.getProject().getName() == order - arguments = [moduleName: project.getName(), packageNameForAPT: packageNameForAPT] - } - } - } - - buildTypes { - release { - minifyEnabled false - proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' - } - } - - // 配置资源路径,方便测试环境,打包不集成到正式环境 - sourceSets { - main { - if (!isRelease) { - // 如果是组件化模式,需要单独运行时 - manifest.srcFile 'src/main/debug/AndroidManifest.xml' - } else { - // 集成化模式,整个项目打包apk - manifest.srcFile 'src/main/AndroidManifest.xml' - java { - // release 时 debug 目录下文件不需要合并到主工程 - exclude '**/debug/**' - } - // resources { - // exclude '**/debug/**' - // } - } - } - } -} - -dependencies { - implementation fileTree(dir: 'libs', include: ['*.jar']) - - /*implementation 'androidx.appcompat:appcompat:1.1.0' - implementation 'androidx.constraintlayout:constraintlayout:1.1.3'*/ - - // 循环引入第三方库 - app_dependencies.each {k, v ->implementation v} - - testImplementation 'junit:junit:4.12' - androidTestImplementation 'androidx.test:runner:1.2.0' - androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' - - // 公共基础库 - implementation project(":common") - - // 注解模块 - implementation project(":arouter_annotation") - - // 使用注解处理器 - // 注解处理器 - annotationProcessor project(':arouter_compiler') -} +if (isRelease) { // 如果是发布版本时,各个模块都不能独立运行 + apply plugin: 'com.android.library' +} else { + apply plugin: 'com.android.application' +} + +android { + namespace 'com.fisherbone.fuzhu.order' + compileSdk app_android.compileSdkVersion + compileSdkVersion app_android.compileSdkVersion + buildToolsVersion app_android.buildToolsVersion + defaultConfig { + // applicationId app_appid.order + if (!isRelease) { // 如果是集成化模式,不能有applicationId + applicationId app_appid.order // 组件化模式能独立运行才能有applicationId + } + + minSdk app_android.minSdkVersion + minSdkVersion app_android.minSdkVersion + targetSdk app_android.targetSdkVersion + targetSdkVersion app_android.targetSdkVersion + versionCode app_android.versionCode + versionName app_android.versionName + testInstrumentationRunner app_android.testInstrumentationRunner + + // 这个方法接收三个非空的参数,第一个:确定值的类型,第二个:指定key的名字,第三个:传值(必须是String) + // 为什么需要定义这个?因为src代码中有可能需要用到跨模块交互,如果是组件化模块显然不行 + // 切记:不能在android根节点,只能在defaultConfig或buildTypes节点下 + buildConfigField("boolean", "isRelease", String.valueOf(isRelease)) + + // 都是为了 传递给 注解处理器 + // 在gradle文件中配置选项参数值(用于APT传参接收) + // 同学们注意:切记:必须写在defaultConfig节点下 + javaCompileOptions { + annotationProcessorOptions { + // project.getName() == order + // this.project.getName() == order + // this.getProject().getName() == order + arguments = [moduleName: project.getName(), packageNameForAPT: packageNameForAPT] + } + } + } + + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + } + } + + // 配置资源路径,方便测试环境,打包不集成到正式环境 + sourceSets { + main { + if (!isRelease) { + // 如果是组件化模式,需要单独运行时 + manifest.srcFile 'src/main/debug/AndroidManifest.xml' + } else { + // 集成化模式,整个项目打包apk + manifest.srcFile 'src/main/AndroidManifest.xml' + java { + // release 时 debug 目录下文件不需要合并到主工程 + exclude '**/debug/**' + } + // resources { + // exclude '**/debug/**' + // } + } + } + } + + buildFeatures { + buildConfig true + } + + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } +} + +dependencies { + implementation fileTree(dir: 'libs', include: ['*.jar']) + + /*implementation 'androidx.appcompat:appcompat:1.1.0' + implementation 'androidx.constraintlayout:constraintlayout:1.1.3'*/ + + // 循环引入第三方库 + app_dependencies.each {k, v ->implementation v} + + testImplementation 'junit:junit:4.12' + androidTestImplementation 'androidx.test:runner:1.2.0' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' + + // 公共基础库 + implementation project(":common") + + // 注解模块 + implementation project(":arouter_annotation") + + // 使用注解处理器 + // 注解处理器 + annotationProcessor project(':arouter_compiler') +} diff --git a/order/src/main/AndroidManifest.xml b/order/src/main/AndroidManifest.xml index 96e981d..2db4f0a 100644 --- a/order/src/main/AndroidManifest.xml +++ b/order/src/main/AndroidManifest.xml @@ -1,25 +1,27 @@ - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/personal/build.gradle b/personal/build.gradle index d594517..5aa24a0 100644 --- a/personal/build.gradle +++ b/personal/build.gradle @@ -1,85 +1,98 @@ -if (isRelease) { // 如果是发布版本时,各个模块都不能独立运行 - apply plugin: 'com.android.library' -} else { - apply plugin: 'com.android.application' -} - -android { - compileSdkVersion app_android.compileSdkVersion - buildToolsVersion app_android.buildToolsVersion - defaultConfig { - // applicationId app_appid.personal - if (!isRelease) { // 如果是集成化模式,不能有applicationId - applicationId app_appid.personal // 组件化模式能独立运行才能有applicationId - } - - minSdkVersion app_android.minSdkVersion - targetSdkVersion app_android.targetSdkVersion - versionCode app_android.versionCode - versionName app_android.versionName - testInstrumentationRunner app_android.testInstrumentationRunner - - // 这个方法接收三个非空的参数,第一个:确定值的类型,第二个:指定key的名字,第三个:传值(必须是String) - // 为什么需要定义这个?因为src代码中有可能需要用到跨模块交互,如果是组件化模块显然不行 - // 切记:不能在android根节点,只能在defaultConfig或buildTypes节点下 - buildConfigField("boolean", "isRelease", String.valueOf(isRelease)) - - /// 在gradle文件中配置选项参数值(用于APT传参接收) - // 同学们注意:切记:必须写在defaultConfig节点下 - javaCompileOptions { - annotationProcessorOptions { - arguments = [moduleName: project.getName(), packageNameForAPT: packageNameForAPT] - } - } - } - - buildTypes { - release { - minifyEnabled false - proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' - } - } - - // 配置资源路径,方便测试环境,打包不集成到正式环境 - sourceSets { - main { - if (!isRelease) { - // 如果是组件化模式,需要单独运行时 - manifest.srcFile 'src/main/debug/AndroidManifest.xml' - } else { - // 集成化模式,整个项目打包apk - manifest.srcFile 'src/main/AndroidManifest.xml' - java { - // release 时 debug 目录下文件不需要合并到主工程 - exclude '**/debug/**' - } - /*resources { - exclude '**/ debug/**'}*/ - } - } - } -} - -dependencies { - implementation fileTree(dir: 'libs', include: ['*.jar']) - - /*implementation 'androidx.appcompat:appcompat:1.1.0' - implementation 'androidx.constraintlayout:constraintlayout:1.1.3'*/ - - // 循环引入第三方库 - app_dependencies.each {k, v ->implementation v} - - testImplementation 'junit:junit:4.12' - androidTestImplementation 'androidx.test:runner:1.2.0' - androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' - - // 公共基础库 - implementation project(":common") - - // 注解模块 - implementation project(":arouter_annotation") - - // 使用注解处理器 - // 注解处理器 - annotationProcessor project(':arouter_compiler') -} +if (isRelease) { // 如果是发布版本时,各个模块都不能独立运行 + apply plugin: 'com.android.library' +} else { + apply plugin: 'com.android.application' +} + +android { + namespace 'com.fisherbone.fuzhu.personal' + compileSdk app_android.compileSdkVersion + compileSdkVersion app_android.compileSdkVersion + buildToolsVersion app_android.buildToolsVersion + defaultConfig { + // applicationId app_appid.personal + if (!isRelease) { // 如果是集成化模式,不能有applicationId + applicationId app_appid.personal // 组件化模式能独立运行才能有applicationId + } + + minSdk app_android.minSdkVersion + minSdkVersion app_android.minSdkVersion + targetSdk app_android.targetSdkVersion + targetSdkVersion app_android.targetSdkVersion + versionCode app_android.versionCode + versionName app_android.versionName + testInstrumentationRunner app_android.testInstrumentationRunner + + // 这个方法接收三个非空的参数,第一个:确定值的类型,第二个:指定key的名字,第三个:传值(必须是String) + // 为什么需要定义这个?因为src代码中有可能需要用到跨模块交互,如果是组件化模块显然不行 + // 切记:不能在android根节点,只能在defaultConfig或buildTypes节点下 + buildConfigField("boolean", "isRelease", String.valueOf(isRelease)) + + /// 在gradle文件中配置选项参数值(用于APT传参接收) + // 同学们注意:切记:必须写在defaultConfig节点下 + javaCompileOptions { + annotationProcessorOptions { + arguments = [moduleName: project.getName(), packageNameForAPT: packageNameForAPT] + } + } + } + + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + } + } + + // 配置资源路径,方便测试环境,打包不集成到正式环境 + sourceSets { + main { + if (!isRelease) { + // 如果是组件化模式,需要单独运行时 + manifest.srcFile 'src/main/debug/AndroidManifest.xml' + } else { + // 集成化模式,整个项目打包apk + manifest.srcFile 'src/main/AndroidManifest.xml' + java { + // release 时 debug 目录下文件不需要合并到主工程 + exclude '**/debug/**' + } + /*resources { + exclude '**/ debug/**'}*/ + } + } + } + + buildFeatures { + buildConfig true + } + + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } +} + +dependencies { + implementation fileTree(dir: 'libs', include: ['*.jar']) + + /*implementation 'androidx.appcompat:appcompat:1.1.0' + implementation 'androidx.constraintlayout:constraintlayout:1.1.3'*/ + + // 循环引入第三方库 + app_dependencies.each {k, v ->implementation v} + + testImplementation 'junit:junit:4.12' + androidTestImplementation 'androidx.test:runner:1.2.0' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' + + // 公共基础库 + implementation project(":common") + + // 注解模块 + implementation project(":arouter_annotation") + + // 使用注解处理器 + // 注解处理器 + annotationProcessor project(':arouter_compiler') +} diff --git a/personal/src/main/AndroidManifest.xml b/personal/src/main/AndroidManifest.xml index 02ac527..000710a 100644 --- a/personal/src/main/AndroidManifest.xml +++ b/personal/src/main/AndroidManifest.xml @@ -1,23 +1,26 @@ - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/wechat/build.gradle b/wechat/build.gradle index 7447df2..19ccb2f 100644 --- a/wechat/build.gradle +++ b/wechat/build.gradle @@ -1,101 +1,110 @@ -// apply plugin: 'com.android.application' -if (isRelease) { // 如果是发布版本时,各个模块都不能独立运行 - apply plugin: 'com.android.library' // 正式环境 library不能独立运行 -} else { - apply plugin: 'com.android.application' // 测试环境 application独立运行 -} - -// 完整的方式 性能 -android { - compileSdkVersion app_android.compileSdkVersion - buildToolsVersion app_android.buildToolsVersion - - defaultConfig { - // applicationId app_appid.personal - if (!isRelease) { // 如果是集成化模式,不能有applicationId - applicationId app_appid.personal // 组件化模式能独立运行才能有applicationId - } - - minSdkVersion app_android.minSdkVersion - targetSdkVersion app_android.targetSdkVersion - versionCode app_android.versionCode - versionName app_android.versionName - testInstrumentationRunner app_android.testInstrumentationRunner - - // 这个方法接收三个非空的参数,第一个:确定值的类型,第二个:指定key的名字,第三个:传值(必须是String) - // 为什么需要定义这个?因为src代码中有可能需要用到跨模块交互,如果是组件化模块显然不行 - // 切记:不能在android根节点,只能在defaultConfig或buildTypes节点下 - buildConfigField("boolean", "isRelease", String.valueOf(isRelease)) - - /// 在gradle文件中配置选项参数值(用于APT传参接收) - // 同学们注意:切记:必须写在defaultConfig节点下 - javaCompileOptions { - annotationProcessorOptions { - arguments = [moduleName: project.getName(), packageNameForAPT: packageNameForAPT] - } - } - } - - buildTypes { - release { - minifyEnabled false - proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' - } - } - - sourceSets { - main { - if (!isRelease) { - // 如果是组件化模式,需要单独运行时 Debug - manifest.srcFile 'src/main/debug/AndroidManifest.xml' // 生效 - } else { // 正式环境下 - // 集成化模式,整个项目打包apk - manifest.srcFile 'src/main/AndroidManifest.xml' // 让我们之前 默认的路径下的清单文件再次生效 - - java { - // release 时 debug 目录下文件不需要合并到主工程 - exclude "**/debug/**" - } - } - } - } - compileOptions { - sourceCompatibility JavaVersion.VERSION_1_8 - targetCompatibility JavaVersion.VERSION_1_8 - } -} - -dependencies { - implementation fileTree(dir: 'libs', include: ['*.jar']) - implementation 'com.google.android.material:material:1.3.0' - - /*implementation 'androidx.appcompat:appcompat:1.1.0' - implementation 'androidx.constraintlayout:constraintlayout:1.1.3'*/ - - // 循环引入第三方库 - app_dependencies.each {k, v ->implementation v} - - testImplementation 'junit:junit:4.12' - androidTestImplementation 'androidx.test:runner:1.2.0' - androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' - - // 公共基础库 - implementation project(":common") - - // 注解模块 - implementation project(":arouter_annotation") - - // 使用注解处理器 - // 注解处理器 - annotationProcessor project(':arouter_compiler') - implementation fileTree(dir: "libs", include: ["*.jar"]) - implementation 'androidx.appcompat:appcompat:1.2.0' - implementation 'androidx.constraintlayout:constraintlayout:2.0.4' - testImplementation 'junit:junit:4.12' - androidTestImplementation 'androidx.test.ext:junit:1.1.2' - androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' - implementation 'com.getbase:floatingactionbutton:1.9.0' - //noinspection GradleCompatible - implementation 'com.android.support:appcompat-v7:28.0.0' - api 'com.blankj:utilcode:1.23.7' -} +// apply plugin: 'com.android.application' +if (isRelease) { // 如果是发布版本时,各个模块都不能独立运行 + apply plugin: 'com.android.library' // 正式环境 library不能独立运行 +} else { + apply plugin: 'com.android.application' // 测试环境 application独立运行 +} + +// 完整的方式 性能 +android { + namespace 'com.derry.wechat' + compileSdk app_android.compileSdkVersion + compileSdkVersion app_android.compileSdkVersion + buildToolsVersion app_android.buildToolsVersion + + defaultConfig { + // applicationId app_appid.personal + if (!isRelease) { // 如果是集成化模式,不能有applicationId + applicationId app_appid.personal // 组件化模式能独立运行才能有applicationId + } + + minSdk app_android.minSdkVersion + minSdkVersion app_android.minSdkVersion + targetSdk app_android.targetSdkVersion + targetSdkVersion app_android.targetSdkVersion + versionCode app_android.versionCode + versionName app_android.versionName + testInstrumentationRunner app_android.testInstrumentationRunner + + // 这个方法接收三个非空的参数,第一个:确定值的类型,第二个:指定key的名字,第三个:传值(必须是String) + // 为什么需要定义这个?因为src代码中有可能需要用到跨模块交互,如果是组件化模块显然不行 + // 切记:不能在android根节点,只能在defaultConfig或buildTypes节点下 + buildConfigField("boolean", "isRelease", String.valueOf(isRelease)) + + /// 在gradle文件中配置选项参数值(用于APT传参接收) + // 同学们注意:切记:必须写在defaultConfig节点下 + javaCompileOptions { + annotationProcessorOptions { + arguments = [moduleName: project.getName(), packageNameForAPT: packageNameForAPT] + } + } + } + + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + } + } + + sourceSets { + main { + if (!isRelease) { + // 如果是组件化模式,需要单独运行时 Debug + manifest.srcFile 'src/main/debug/AndroidManifest.xml' // 生效 + } else { // 正式环境下 + // 集成化模式,整个项目打包apk + manifest.srcFile 'src/main/AndroidManifest.xml' // 让我们之前 默认的路径下的清单文件再次生效 + + java { + // release 时 debug 目录下文件不需要合并到主工程 + exclude "**/debug/**" + } + } + } + } + + buildFeatures { + buildConfig true + } + + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } +} + +dependencies { + implementation fileTree(dir: 'libs', include: ['*.jar']) + implementation 'com.google.android.material:material:1.3.0' + + /*implementation 'androidx.appcompat:appcompat:1.1.0' + implementation 'androidx.constraintlayout:constraintlayout:1.1.3'*/ + + // 循环引入第三方库 + app_dependencies.each {k, v ->implementation v} + + testImplementation 'junit:junit:4.12' + androidTestImplementation 'androidx.test:runner:1.2.0' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' + + // 公共基础库 + implementation project(":common") + + // 注解模块 + implementation project(":arouter_annotation") + + // 使用注解处理器 + // 注解处理器 + annotationProcessor project(':arouter_compiler') + implementation fileTree(dir: "libs", include: ["*.jar"]) + implementation 'androidx.appcompat:appcompat:1.2.0' + implementation 'androidx.constraintlayout:constraintlayout:2.0.4' + testImplementation 'junit:junit:4.12' + androidTestImplementation 'androidx.test.ext:junit:1.1.2' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' + implementation 'com.getbase:floatingactionbutton:1.9.0' + //noinspection GradleCompatible + implementation 'com.android.support:appcompat-v7:28.0.0' + api 'com.blankj:utilcode:1.30.6' +} diff --git a/wechat/src/main/AndroidManifest.xml b/wechat/src/main/AndroidManifest.xml index 5a42fc1..c654570 100644 --- a/wechat/src/main/AndroidManifest.xml +++ b/wechat/src/main/AndroidManifest.xml @@ -1,96 +1,98 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/wechat/src/main/java/com/derry/wechat/debug/Login_DebugActivity.java b/wechat/src/main/java/com/derry/wechat/debug/Login_DebugActivity.java index 129c204..a915271 100644 --- a/wechat/src/main/java/com/derry/wechat/debug/Login_DebugActivity.java +++ b/wechat/src/main/java/com/derry/wechat/debug/Login_DebugActivity.java @@ -1,105 +1,105 @@ -package com.derry.wechat.debug; - -import android.annotation.SuppressLint; -import android.content.Intent; -import android.os.Build; -import android.os.Bundle; -import android.provider.Settings; -import android.view.Gravity; -import android.view.View; -import android.view.ViewGroup; -import android.view.WindowManager; -import android.widget.Button; -import android.widget.PopupWindow; - -import androidx.annotation.Nullable; -import androidx.appcompat.app.AppCompatActivity; - -import com.blankj.utilcode.util.ToastUtils; -import com.derry.wechat.Activity.W_MainActivity; -import com.derry.wechat.Activity.WeChatChannelActivity; -import com.derry.wechat.Activity.WeChatPlate; -import com.derry.wechat.steps.TestAblStep1; -import com.derry.wechat.abllib.AblConfig; -import com.derry.wechat.abllib.AblService; -import com.derry.wechat.abllib.AblStepHandler; -import com.derry.wechat.abllib.AblSteps; -import com.derry.wechat.abllib.utils.AblUtil; -import com.derry.wechat.steps.TestAblStep2; - - -/** - * @author Administrator - */ -public class Login_DebugActivity extends AppCompatActivity { - public static String APP_PACKAGE_NAME = "com.tencent.mm"; - private PopupWindow mPopCut; - @Override - public void onCreate(@Nullable Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.w_activity_debug); - //透明状态栏 - getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); - getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION); - - AblConfig.Builder() - .setMonitoringPackageNames("com.tencent.mm")//微信包 - .setLogTag("DDD")//logtag,不设置默认是abllib - .setStepMsgDelayMillis(3000)//步骤延迟时间 - .setFindViewMillisInFuture(10000)//寻找界面超时时间 - .setFindViewCountDownInterval(200)//寻找界面间隔时间 - .build().init(); - AblStepHandler.getInstance().initStepClass(new TestAblStep1() , new TestAblStep2()); - - AblUtil.getPermissions(Login_DebugActivity.this); - - //adb shell pm grant com.derry.wechat.debug android.permission.WRITE_SECURE_SETTINGS - Settings.Secure.putString(getContentResolver(), - Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES, "com.derry.wechat.debug/com.derry.wechat.debug.abllib.AblService"); - Settings.Secure.putString(getContentResolver(), - Settings.Secure.ACCESSIBILITY_ENABLED, "1");//1表示开启 - if (AblUtil.isAccessibilityServiceOpen(Login_DebugActivity.this)) { - // Log.e("TIAOSHI###", "无障碍服务正常"); - ToastUtils.showShort( "无障碍服务正常"); - }else { - ToastUtils.showShort( "无障碍服务异常"); - Settings.Secure.putString(getContentResolver(), Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES, "com.derry.wechat.debug/com.derry.wechat.debug.abllib.AblService"); - Settings.Secure.putString(getContentResolver(), Settings.Secure.ACCESSIBILITY_ENABLED, "0");//1表示开启 - } - /** - * 底部导航栏 - */ - Button mBtnCut = findViewById(R.id.cut); - mBtnCut.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - @SuppressLint("InflateParams") View v = getLayoutInflater().inflate(R.layout.layout_pop,null); - mPopCut = new PopupWindow(v, ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.WRAP_CONTENT); - mPopCut.setTouchable(true); - mPopCut.setFocusable(true); - mPopCut.showAtLocation(getWindow().getDecorView(), Gravity.BOTTOM,0,0); - } - }); - - /** - * 菜单 - */ - Button mBtnRecommend = findViewById(R.id.recommed); - mBtnRecommend.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - Intent intent = new Intent(Login_DebugActivity.this, WeChatPlate.class); - startActivity(intent); - } - }); - Button mBtnChannel = findViewById(R.id.channel); - mBtnChannel.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - Intent intent = new Intent(Login_DebugActivity.this,WeChatChannelActivity.class); - startActivity(intent); - } - }); - - } -} +package com.derry.wechat.debug; + +import android.annotation.SuppressLint; +import android.content.Intent; +import android.os.Build; +import android.os.Bundle; +import android.provider.Settings; +import android.view.Gravity; +import android.view.View; +import android.view.ViewGroup; +import android.view.WindowManager; +import android.widget.Button; +import android.widget.PopupWindow; + +import androidx.annotation.Nullable; +import androidx.appcompat.app.AppCompatActivity; + +import com.blankj.utilcode.util.ToastUtils; +import com.derry.wechat.Activity.W_MainActivity; +import com.derry.wechat.Activity.WeChatChannelActivity; +import com.derry.wechat.Activity.WeChatPlate; +import com.derry.wechat.steps.TestAblStep1; +import com.derry.wechat.abllib.AblConfig; +import com.derry.wechat.abllib.AblService; +import com.derry.wechat.abllib.AblStepHandler; +import com.derry.wechat.abllib.AblSteps; +import com.derry.wechat.abllib.utils.AblUtil; +import com.derry.wechat.steps.TestAblStep2; + + +/** + * @author Administrator + */ +public class Login_DebugActivity extends AppCompatActivity { + public static String APP_PACKAGE_NAME = "com.tencent.mm"; + private PopupWindow mPopCut; + @Override + public void onCreate(@Nullable Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.w_activity_debug); + //透明状态栏 + getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); + getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION); + + AblConfig.Builder() + .setMonitoringPackageNames("com.tencent.mm")//微信包 + .setLogTag("DDD")//logtag,不设置默认是abllib + .setStepMsgDelayMillis(3000)//步骤延迟时间 + .setFindViewMillisInFuture(10000)//寻找界面超时时间 + .setFindViewCountDownInterval(200)//寻找界面间隔时间 + .build().init(); + AblStepHandler.getInstance().initStepClass(new TestAblStep1() , new TestAblStep2()); + + AblUtil.getPermissions(Login_DebugActivity.this); + + //adb shell pm grant com.derry.wechat.debug android.permission.WRITE_SECURE_SETTINGS +// Settings.Secure.putString(getContentResolver(), +// Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES, "com.derry.wechat.debug/com.derry.wechat.debug.abllib.AblService"); +// Settings.Secure.putString(getContentResolver(), +// Settings.Secure.ACCESSIBILITY_ENABLED, "1");//1表示开启 + if (AblUtil.isAccessibilityServiceOpen(Login_DebugActivity.this)) { + // Log.e("TIAOSHI###", "无障碍服务正常"); + ToastUtils.showShort( "无障碍服务正常"); + }else { + ToastUtils.showShort( "无障碍服务异常"); +// Settings.Secure.putString(getContentResolver(), Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES, "com.derry.wechat.debug/com.derry.wechat.debug.abllib.AblService"); +// Settings.Secure.putString(getContentResolver(), Settings.Secure.ACCESSIBILITY_ENABLED, "0");//1表示开启 + } + /** + * 底部导航栏 + */ + Button mBtnCut = findViewById(R.id.cut); + mBtnCut.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + @SuppressLint("InflateParams") View v = getLayoutInflater().inflate(R.layout.layout_pop,null); + mPopCut = new PopupWindow(v, ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.WRAP_CONTENT); + mPopCut.setTouchable(true); + mPopCut.setFocusable(true); + mPopCut.showAtLocation(getWindow().getDecorView(), Gravity.BOTTOM,0,0); + } + }); + + /** + * 菜单 + */ + Button mBtnRecommend = findViewById(R.id.recommed); + mBtnRecommend.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + Intent intent = new Intent(Login_DebugActivity.this, WeChatPlate.class); + startActivity(intent); + } + }); + Button mBtnChannel = findViewById(R.id.channel); + mBtnChannel.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + Intent intent = new Intent(Login_DebugActivity.this,WeChatChannelActivity.class); + startActivity(intent); + } + }); + + } +}