更细增加两个生命周期管理的方法,增加tpush

This commit is contained in:
tt committed 2022-02-24 18:46:38 +08:00
1 parent ea8c4fbbfe
commit 3e83c6b5a5
68 files changed
+2457 -298

No files matched your search

+53 -9
View File
@@ -1,6 +1,7 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: "com.tencent.android.tpns"
def appName() {
return "TT"
@@ -16,7 +17,7 @@ android {
defaultConfig {
applicationId "com.tt.ttutils"
minSdkVersion 24
minSdkVersion 26
targetSdkVersion 30
// versionCode 1
// versionName "1.0"
@@ -41,6 +42,8 @@ android {
// 还可以添加 'armeabi' , 'x86', 'x86_64', 'mips', 'mips64'
}
manifestPlaceholders = [
XG_ACCESS_ID : "1500026407",
XG_ACCESS_KEY: "AQ6C6W1O19LT",
JPUSH_PKGNAME: applicationId,
JPUSH_APPKEY : "731637f412deca8540a1f873", //JPush 上注册的包名对应的 Appkey.
JPUSH_CHANNEL: "developer-default", //暂时填写默认值即可.
@@ -72,13 +75,14 @@ android {
flavorDimensions "default"
versionCode 1
versionName "1.0"
buildConfigField "String", "ROOT_URL", '"https://193.112.158.183"'
}
beta {
flavorDimensions "default"
versionCode 1
versionCode 100
versionName "1.0"
buildConfigField "String", "test", '"测试文本"'
buildConfigField "String", "ROOT_URL", '"https://193.112.158.183"'
}
}
@@ -217,6 +221,8 @@ android {
dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
compileOnly files('libs/framework.jar')
implementation project(':viewlibrary')
implementation project(path: ':niceimageview')
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
@@ -232,6 +238,7 @@ dependencies {
implementation 'androidx.recyclerview:recyclerview:1.2.1'
implementation "androidx.security:security-crypto:1.1.0-alpha03"
implementation 'androidx.multidex:multidex:2.0.1'
implementation 'androidx.localbroadcastmanager:localbroadcastmanager:1.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
@@ -241,14 +248,26 @@ dependencies {
implementation 'cn.jiguang.sdk:jpush:3.8.6' // 此处以JPush 3.7.0 版本为例。
implementation 'cn.jiguang.sdk:jcore:2.6.0' // 此处以JCore 2.4.2 版本为例。
//RxJava
implementation 'io.reactivex.rxjava2:rxjava:2.2.5'
implementation 'io.reactivex.rxjava2:rxandroid:2.1.0'
// implementation 'io.reactivex.rxjava2:rxjava:2.2.5'
// implementation 'io.reactivex.rxjava2:rxandroid:2.1.0'
implementation 'io.reactivex.rxjava3:rxandroid:3.0.0'
// 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 3.x.x version)
implementation 'io.reactivex.rxjava3:rxjava:3.0.0'
//rxlifecycle
implementation 'com.trello.rxlifecycle4:rxlifecycle:4.0.2'
implementation 'com.trello.rxlifecycle4:rxlifecycle-android:4.0.2'
implementation 'com.trello.rxlifecycle4:rxlifecycle-components:4.0.2'
implementation 'com.trello.rxlifecycle4:rxlifecycle-components-preference:4.0.2'
implementation 'com.trello.rxlifecycle4:rxlifecycle-android-lifecycle:4.0.2'
//okhttp
implementation 'com.squareup.okhttp3:okhttp:4.6.0'
//Retrofit
implementation 'com.squareup.retrofit2:retrofit:2.3.0'
implementation 'com.squareup.retrofit2:converter-gson:2.3.0'
implementation 'com.squareup.retrofit2:adapter-rxjava2:2.3.0'
implementation 'com.squareup.retrofit2:retrofit:2.9.0'
implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
// implementation 'com.squareup.retrofit2:adapter-rxjava2:2.3.0'
implementation "com.squareup.retrofit2:adapter-rxjava3:2.9.0"
//Google
implementation 'com.google.code.gson:gson:2.8.6'
implementation 'com.google.zxing:core:3.3.0'
@@ -264,6 +283,9 @@ dependencies {
//MMKV
implementation 'com.tencent:mmkv-static:1.2.10'
//腾讯移动推送 TPNS
implementation 'com.tencent.tpns:tpns:1.2.2.0-release'
//内存泄漏检测
debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.7'
////图片加载框架
@@ -308,4 +330,26 @@ dependencies {
implementation 'com.gyf.immersionbar:immersionbar-ktx:3.0.0'
//网络监听
implementation 'com.github.tianma8023:NetDetector:v0.2.0'
}
}
preBuild {
doLast {
def imlFile = file(project.name + ".iml")
println 'Change ' + project.name + '.iml order'
try {
def parsedXml = (new XmlParser()).parse(imlFile)
def jdkNode = parsedXml.component[1].orderEntry.find { it.'@type' == 'jdk' }
parsedXml.component[1].remove(jdkNode)
def sdkString = "Android API " + android.compileSdkVersion.substring("android-".length()) + " Platform"
println 'what' + sdkString
new Node(parsedXml.component[1], 'orderEntry', ['type': 'jdk', 'jdkName': sdkString, 'jdkType': 'Android SDK'])
groovy.xml.XmlUtil.serialize(parsedXml, new FileOutputStream(imlFile))
} catch (FileNotFoundException e) {
// nop, iml not found
println "no iml found"
}
}
//https://www.pianshen.com/article/93481144911/
//https://blog.csdn.net/dhl_1986/article/details/102856026
//使用系统编译后的framework.jar
}
Binary file not shown.
Binary file not shown.
+143 -59
View File
@@ -1,14 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.tt.ttutils">
package="com.tt.ttutils"
android:sharedUserId="android.uid.system">
<uses-permission android:name="android.permission.READ_PRIVILEGED_PHONE_STATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.INSTALL_PACKAGES" />
<uses-permission android:name="android.permission.DELETE_PACKAGES" />
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
<!-- Required -->
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" /> <!-- 【必须】 移动推送 TPNS SDK 5.0版本所需权限 -->
<permission
android:name="com.tt.ttutils.permission.XGPUSH_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="com.tt.ttutils.permission.XGPUSH_RECEIVE" /> <!-- 【必须】 移动推送 TPNS SDK所需权限 -->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" /> <!-- 【常用】 移动推送 TPNS SDK所需权限 -->
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.RECEIVE_USER_PRESENT" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <!-- Required -->
<permission
android:name="${applicationId}.permission.JPUSH_MESSAGE"
android:protectionLevel="signature" /> <!-- Required 一些系统要求的权限,如访问网络等 -->
@@ -20,49 +35,52 @@
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<!-- 华为角标 -->
<uses-permission android:name="com.huawei.android.launcher.permission.CHANGE_BADGE" />
<!-- Optional for location -->
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> <!-- Optional for location -->
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<!-- 用于开启 debug 版本的应用在6.0 系统上 层叠窗口权限 -->
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" /> <!-- 用于开启 debug 版本的应用在6.0 系统上 层叠窗口权限 -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
<!-- Android Q后台定位权限 -->
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" /> <!-- Android Q后台定位权限 -->
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
<uses-permission android:name="android.permission.GET_TASKS" />
<uses-permission android:name="com.jiaoguanyi.appstore.permissions.INSTALL_APK" />
<application
android:name="com.tt.base.MyApplication"
android:name=".base.KotlinApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/ImmerseTheme">
<activity android:name="com.tt.activity.PackageActivity" />
<activity android:name="com.tt.activity.JMainActivity">
<activity android:name=".activity.retrofit.RetrofitActivity"></activity>
<activity android:name=".activity.PackageActivity" />
<activity android:name=".activity.main.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.tt.activity.MainActivity">
<!-- <intent-filter>-->
<!-- <action android:name="android.intent.action.MAIN" />-->
<activity android:name=".activity.KotlinMainActivity">
<!-- <category android:name="android.intent.category.LAUNCHER" />-->
<!-- </intent-filter>-->
<!-- <intent-filter> -->
<!-- <action android:name="android.intent.action.MAIN" /> -->
<!-- <category android:name="android.intent.category.LAUNCHER" /> -->
<!-- </intent-filter> -->
</activity>
<service
android:name=".server.main.MainService"
android:enabled="true"
android:exported="true"></service>
<receiver
android:name="com.tt.receiver.PackageReceiver"
android:name=".receiver.PackageReceiver"
android:enabled="true"
android:exported="true">
<intent-filter android:priority="1000">
@@ -74,7 +92,7 @@
</intent-filter>
</receiver>
<receiver
android:name="com.tt.receiver.BootReceiver"
android:name=".receiver.BootReceiver"
android:enabled="true"
android:exported="true">
<intent-filter android:priority="1000">
@@ -103,17 +121,98 @@
<!-- 自定义广播 -->
<action android:name="com.jiaoguanyi.appstore.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
</receiver> <!-- -->
<!-- 应用的其它配置 -->
<uses-library
android:name="org.apache.http.legacy"
android:required="false" /> <!-- 【必须】 移动推送 TPNS 默认通知 -->
<activity
android:name="com.tencent.android.tpush.TpnsActivity"
android:theme="@android:style/Theme.Translucent.NoTitleBar">
<intent-filter>
<data
android:host="com.tt.ttutils"
android:scheme="tpns" />
<action android:name="android.intent.action.VIEW" />
<!-- -->
<!-- Rich push 核心功能 since 2.0.6 -->
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity> <!-- 【必须】 移动推送 TPNS receiver广播接收 -->
<receiver
android:name="com.tencent.android.tpush.XGPushReceiver"
android:process=":xg_vip_service">
<intent-filter android:priority="0x7fffffff">
<!-- 【必须】 移动推送 TPNS SDK的内部广播 -->
<action android:name="com.tencent.android.xg.vip.action.SDK" />
<action android:name="com.tencent.android.xg.vip.action.INTERNAL_PUSH_MESSAGE" />
<action android:name="com.tencent.android.xg.vip.action.ACTION_SDK_KEEPALIVE" />
<!-- 【可选】 系统广播:网络切换 -->
<action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
<!-- 【可选】 系统广播:开屏 -->
<action android:name="android.intent.action.USER_PRESENT" />
<!-- 【可选】 一些常用的系统广播,增强移动推送 TPNS service的复活机会,请根据需要选择。当然,您也可以添加App自定义的一些广播让启动service -->
<action android:name="android.bluetooth.adapter.action.STATE_CHANGED" />
<action android:name="android.intent.action.ACTION_POWER_CONNECTED" />
<action android:name="android.intent.action.ACTION_POWER_DISCONNECTED" />
</intent-filter>
</receiver> <!-- 【必须】移动推送 TPNS service -->
<service
android:name="com.tencent.android.tpush.service.XGVipPushService"
android:persistent="true"
android:process=":xg_vip_service" /> <!-- 【必须】通知 service ,android:name 部分改为包名.XGVIP_PUSH_ACTION -->
<service
android:name="com.tencent.android.tpush.rpc.XGRemoteService"
android:exported="false">
<intent-filter>
<!-- 【必须】请修改为当前APP名包.XGVIP_PUSH_ACTION -->
<action android:name="com.tt.ttutils.XGVIP_PUSH_ACTION" />
</intent-filter>
</service> <!-- 【必须】【注意】authorities 修改为包名.XGVIP_PUSH_AUTH -->
<provider
android:name="com.tencent.android.tpush.XGPushProvider"
android:authorities="com.tt.ttutils.XGVIP_PUSH_AUTH" /> <!-- 【必须】【注意】authorities 修改为包名.TPUSH_PROVIDER -->
<provider
android:name="com.tencent.android.tpush.SettingsContentProvider"
android:authorities="com.tt.ttutils.TPUSH_PROVIDER" /> <!-- 【可选】用于增强保活能力 -->
<provider
android:name="com.tencent.android.tpush.XGVipPushKAProvider"
android:authorities="com.tt.ttutils.AUTH_XGPUSH_KEEPALIVE"
android:exported="true" /> <!-- 【可选】APP实现的Receiver,用于接收消息透传和操作结果的回调,请根据需要添加 -->
<!-- YOUR_PACKAGE_PATH.CustomPushReceiver需要改为自己的Receiver: -->
<receiver android:name=".tpush.MessageReceiver">
<intent-filter>
<!-- 接收消息透传 -->
<action android:name="com.tencent.android.xg.vip.action.PUSH_MESSAGE" />
<!-- 监听注册、反注册、设置/删除标签、通知被点击等处理结果 -->
<action android:name="com.tencent.android.xg.vip.action.FEEDBACK" />
</intent-filter>
</receiver> <!-- MQTT START -->
<service
android:name="com.tencent.tpns.mqttchannel.services.MqttService"
android:exported="false"
android:process=":xg_vip_service" />
<provider
android:name="com.tencent.tpns.baseapi.base.SettingsContentProvider"
android:authorities="com.tt.ttutils.XG_SETTINGS_PROVIDER"
android:exported="false" /> <!-- MQTT END -->
<!-- 【必须】 请修改为 APP 的 AccessId,“15”开头的10位数字,中间没空格 -->
<meta-data
android:name="XG_V2_ACCESS_ID"
android:value="1500026407" /> <!-- 【必须】 请修改为APP的AccessKey,“A”开头的12位字符串,中间没空格 -->
<meta-data
android:name="XG_V2_ACCESS_KEY"
android:value="AQ6C6W1O19LT" /> <!-- Rich push 核心功能 since 2.0.6 -->
<activity
android:name="cn.jpush.android.ui.PopWinActivity"
android:exported="false"
android:theme="@style/MyDialogStyle"
tools:replace="android:exported" />
<!-- Required SDK核心功能 -->
tools:replace="android:exported" /> <!-- Required SDK核心功能 -->
<activity
android:name="cn.jpush.android.ui.PushActivity"
android:configChanges="orientation|keyboardHidden"
@@ -126,8 +225,7 @@
<category android:name="android.intent.category.DEFAULT" />
<category android:name="${applicationId}" />
</intent-filter>
</activity>
<!-- Required SDK 核心功能 -->
</activity> <!-- Required SDK 核心功能 -->
<!-- 可配置android:process参数将PushService放在其他进程中 -->
<service
android:name="cn.jpush.android.service.PushService"
@@ -138,14 +236,12 @@
<action android:name="cn.jpush.android.intent.PushService" />
<action android:name="cn.jpush.android.intent.PUSH_TIME" />
</intent-filter>
</service>
<!-- since 3.0.9 Required SDK 核心功能 -->
</service> <!-- since 3.0.9 Required SDK 核心功能 -->
<provider
android:name="cn.jpush.android.service.DataProvider"
android:authorities="${applicationId}.DataProvider"
android:exported="false"
android:process=":pushcore" />
<!-- since 1.8.0 option 可选项。用于同一设备中不同应用的JPush服务相互拉起的功能。 -->
android:process=":pushcore" /> <!-- since 1.8.0 option 可选项。用于同一设备中不同应用的JPush服务相互拉起的功能。 -->
<!-- 若不启用该功能可删除该组件,或把 enabled 设置成 false ;App 不会被其他 App 拉起,但会拉起其他的 App。 -->
<service
android:name="cn.jpush.android.service.DaemonService"
@@ -156,8 +252,7 @@
<category android:name="${applicationId}" />
</intent-filter>
</service>
<!-- 可选,如果使用静态Activity方式拉起,该组件必须声明 -->
</service> <!-- 可选,如果使用静态Activity方式拉起,该组件必须声明 -->
<activity
android:name="cn.jpush.android.service.DActivity"
android:enabled="true"
@@ -169,13 +264,11 @@
<category android:name="${applicationId}" />
</intent-filter>
</activity>
<!-- since 3.1.0 Required SDK 核心功能 -->
</activity> <!-- since 3.1.0 Required SDK 核心功能 -->
<provider
android:name="cn.jpush.android.service.DownloadProvider"
android:authorities="${applicationId}.DownloadProvider"
android:exported="true" />
<!-- Required SDK核心功能 -->
android:exported="true" /> <!-- Required SDK核心功能 -->
<receiver
android:name="cn.jpush.android.service.PushReceiver"
android:enabled="true">
@@ -195,20 +288,16 @@
<data android:scheme="package" />
</intent-filter>
</receiver>
<!-- Required SDK核心功能 -->
</receiver> <!-- Required SDK核心功能 -->
<receiver
android:name="cn.jpush.android.service.AlarmReceiver"
android:exported="false" />
<!-- 3.5.0新增,用于定时展示功能 -->
android:exported="false" /> <!-- 3.5.0新增,用于定时展示功能 -->
<receiver
android:name="cn.jpush.android.service.SchedulerReceiver"
android:exported="false" />
<!-- 3.6.7 新增,用于负反馈组件 -->
<service android:name="cn.jpush.android.service.MessagingIntentService" />
<!-- User defined. For test only 用户自定义的广播接收器 -->
android:exported="false" /> <!-- 3.6.7 新增,用于负反馈组件 -->
<service android:name="cn.jpush.android.service.MessagingIntentService" /> <!-- User defined. For test only 用户自定义的广播接收器 -->
<receiver
android:name="com.tt.sdk.jpush.jpushdemo.MyReceiver"
android:name=".sdk.jpush.jpushdemo.MyReceiver"
android:enabled="true">
<intent-filter>
<action android:name="cn.jpush.android.intent.REGISTRATION" />
@@ -223,17 +312,15 @@
<!-- 接收网络变化 连接/断开 since 1.6.3 -->
<category android:name="${applicationId}" />
</intent-filter>
</receiver>
<!-- User defined. For test only 用户自定义接收消息器,3.0.7开始支持,目前新tag/alias接口设置结果会在该广播接收器对应的方法中回调 -->
</receiver> <!-- User defined. For test only 用户自定义接收消息器,3.0.7开始支持,目前新tag/alias接口设置结果会在该广播接收器对应的方法中回调 -->
<!-- since 3.3.0 接收JPush相关事件 -->
<receiver android:name="com.tt.sdk.jpush.jpushdemo.PushMessageReceiver">
<receiver android:name=".sdk.jpush.jpushdemo.PushMessageReceiver">
<intent-filter>
<action android:name="cn.jpush.android.intent.RECEIVE_MESSAGE" />
<category android:name="${applicationId}" />
</intent-filter>
</receiver>
<!-- since 3.3.0 Required SDK核心功能 -->
</receiver> <!-- since 3.3.0 Required SDK核心功能 -->
<activity
android:name="cn.jpush.android.service.JNotifyActivity"
android:exported="false"
@@ -245,27 +332,24 @@
<category android:name="${applicationId}" />
</intent-filter>
</activity>
<!-- since 3.3.0 Required SDK 核心功能 -->
</activity> <!-- since 3.3.0 Required SDK 核心功能 -->
<!-- 可配置android:process参数将PushService放在其他进程中 -->
<!-- User defined. For test only 继承自cn.jpush.android.service.JCommonService -->
<service
android:name="com.tt.sdk.jpush.jpushdemo.PushService"
android:name=".sdk.jpush.jpushdemo.PushService"
android:process=":pushcore">
<intent-filter>
<action android:name="cn.jiguang.user.service.action" />
</intent-filter>
</service>
<!-- since 3.5.6 新增华硕通道 -->
<receiver android:name="cn.jpush.android.asus.AsusPushMessageReceiver" />
<!-- Required . Enable it you can get statistics data with channel -->
</service> <!-- since 3.5.6 新增华硕通道 -->
<receiver android:name="cn.jpush.android.asus.AsusPushMessageReceiver" /> <!-- Required . Enable it you can get statistics data with channel -->
<!-- 值来自开发者平台取得的AppKey -->
<meta-data
android:name="JPUSH_CHANNEL"
android:value="${JPUSH_CHANNEL}" />
<meta-data
android:name="JPUSH_APPKEY"
android:value="${JPUSH_APPKEY}" />
<!-- </>值来自开发者平台取得的AppKey -->
<meta-data
android:name="design_width_in_dp"
android:value="640" />
+2 -2
View File
@@ -8,8 +8,8 @@ extern "C"
JNIEXPORT jstring
JNICALL
Java_com_tt_ttutils_jni_NDKTools_getStringFromNDK(
JNIEnv *env, jobject /* this */) {
Java_com_tt_ttutils_utils_jni_NDKTools_getStringFromNDK(
JNIEnv *env, jclass /* this */) {
std::string hello = "Hello from C++";
return env->NewStringUTF(hello.c_str());
}
@@ -1,4 +1,4 @@
package com.tt.activity
package com.tt.ttutils.activity
import android.content.ComponentName
import android.content.Context
@@ -12,14 +12,14 @@ import android.widget.Button
import androidx.appcompat.app.AppCompatActivity
import com.notepad.uiui.INoteAidlInterface
import com.tt.ttutils.R
import com.tt.ttutils.java.DevicesUtils
import com.tt.ttutils.utils.java.DevicesUtils
import kotlinx.android.synthetic.main.activity_main.*
import me.jessyan.autosize.internal.CancelAdapt
import java.io.File
import kotlin.math.log
class MainActivity : AppCompatActivity(), CancelAdapt {
class KotlinMainActivity : AppCompatActivity(), CancelAdapt {
lateinit var button: Button
private val INSTALLAPK_ACTION = "JGY_INSTALLAPK_ACTION"
private val INSTALLAPK_PREMISSIONS = "com.jiaoguanyi.appstore.permissions.INSTALL_APK"
@@ -1,4 +1,4 @@
package com.tt.activity;
package com.tt.ttutils.activity;
import androidx.appcompat.app.AppCompatActivity;
@@ -6,7 +6,7 @@ import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import com.tt.receiver.PackageReceiver;
import com.tt.ttutils.receiver.PackageReceiver;
import com.tt.ttutils.R;
public class PackageActivity extends AppCompatActivity {
@@ -0,0 +1,14 @@
package com.tt.ttutils.activity.main;
import com.tt.ttutils.mvp.BasePresenter;
import com.tt.ttutils.mvp.BaseView;
public class MainAContact {
public interface MainView extends BaseView {
void testRetrofit();
}
public interface Presenter extends BasePresenter<MainView> {
void testRetrofitFinish();
}
}
@@ -1,60 +1,65 @@
package com.tt.mvp;
package com.tt.ttutils.activity.main;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Build;
import android.provider.Settings;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import com.trello.rxlifecycle4.LifecycleProvider;
import com.trello.rxlifecycle4.android.ActivityEvent;
import com.google.gson.Gson;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import java.io.IOException;
import java.lang.reflect.Type;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Random;
import java.util.Set;
import cn.jpush.android.api.JPushInterface;
import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.annotations.NonNull;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;
import okhttp3.ResponseBody;
import io.reactivex.rxjava3.subjects.BehaviorSubject;
/**
* MainActivity和MainService 的 Presenter
* MainActivity 的 Presenter
*
* @author jgy02
*/
public class MainPresenter implements MainContact.Presenter {
private static final String TAG = MainPresenter.class.getSimpleName();
private MainContact.MainView mView;
public class MainAPresenter implements MainAContact.Presenter {
private static final String TAG = MainAPresenter.class.getSimpleName();
private MainAContact.MainView mView;
private Context mContext;
private final String DEFAULT_INFO = "暂无信息";
private final int OK = 200;
public MainPresenter(Context context) {
public MainAPresenter(Context context) {
this.mContext = context;
Log.e(TAG, "MainPresenter: " + context.getClass());
Log.e(TAG, "MainSPresenter: " + context.getClass());
}
/**
* Lifecycle start
*/
/*1*/
private LifecycleProvider<ActivityEvent> provider;
public void setProvider(LifecycleProvider<ActivityEvent> provider) {
this.provider = provider;
}
public LifecycleProvider<ActivityEvent> getProvider() {
return provider;
}
/*2*/
private BehaviorSubject<ActivityEvent> lifecycle;
public void setLifecycle(BehaviorSubject<ActivityEvent> lifecycle) {
this.lifecycle = lifecycle;
}
public BehaviorSubject<ActivityEvent> getLifecycle() {
return lifecycle;
}
/**
* Lifecycle end
*/
@Override
public void attachView(@androidx.annotation.NonNull MainContact.MainView view) {
public void attachView(@androidx.annotation.NonNull MainAContact.MainView view) {
this.mView = view;
}
@@ -1,4 +1,4 @@
package com.tt.activity;
package com.tt.ttutils.activity.main;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
@@ -8,11 +8,13 @@ import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.ServiceConnection;
import android.hardware.usb.UsbManager;
import android.net.Uri;
import android.os.Environment;
import android.os.IBinder;
import android.os.RemoteException;
import android.provider.MediaStore;
import android.provider.Settings;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
@@ -23,12 +25,11 @@ import android.widget.Toast;
import com.info.sn.IGetInfoInterface;
import com.jiaoguanyi.appstore.IGetLicenseInterface;
import com.notepad.uiui.INoteAidlInterface;
import com.tt.base.BaseActivity;
import com.tt.base.ImmerseBaseActivity;
import com.tt.ttutils.base.ImmerseBaseActivity;
import com.tt.ttutils.server.main.MainService;
import com.tt.ttutils.R;
import com.tt.ttutils.java.ApkUtils;
import com.tt.ttutils.java.ToastUtil;
import com.tt.ttutils.jni.NDKTools;
import com.tt.ttutils.utils.java.ToastUtil;
import com.tt.ttutils.utils.jni.NDKTools;
import java.util.ArrayList;
import java.util.List;
@@ -36,11 +37,34 @@ import java.util.List;
import butterknife.BindView;
import butterknife.ButterKnife;
public class JMainActivity extends ImmerseBaseActivity {
public class MainActivity extends ImmerseBaseActivity {
@BindView(R.id.textView)
TextView textView;
@BindView(R.id.button)
Button button;
@BindView(R.id.none)
Button none;
@BindView(R.id.adb)
Button adb;
@BindView(R.id.rndis)
Button rndis;
@BindView(R.id.mtp)
Button mtp;
@BindView(R.id.ptp)
Button ptp;
@BindView(R.id.audio_source)
Button audio_source;
@BindView(R.id.midi)
Button midi;
@BindView(R.id.accessory)
Button accessory;
@BindView(R.id.icon_off)
Button icon_off;
@BindView(R.id.icon_on)
Button icon_on;
@BindView(R.id.icon_look)
Button icon_look;
private ServiceConnection mServiceConnection;
private INoteAidlInterface noteAidlInterface;
@@ -48,8 +72,9 @@ public class JMainActivity extends ImmerseBaseActivity {
private IGetLicenseInterface getLicenseInterface;
private ServiceConnection mIGetInfoConnection;
private IGetInfoInterface getInfoInterface;
private String TAG = JMainActivity.class.getSimpleName();
private String TAG = MainActivity.class.getSimpleName();
private UsbManager mUsbManager;
@Override
public int getLayoutId() {
@@ -68,15 +93,60 @@ public class JMainActivity extends ImmerseBaseActivity {
// int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION //导航栏
// | View.SYSTEM_UI_FLAG_FULLSCREEN;//全屏
// decorView.setSystemUiVisibility(uiOptions);
mUsbManager = (UsbManager) getSystemService(Context.USB_SERVICE);
}
@Override
public void setListener() {
// mUsbManager.setCurrentFunction(UsbManager.USB_FUNCTION_NONE, true);
none.setOnClickListener(view -> mUsbManager.setCurrentFunction(UsbManager.USB_FUNCTION_NONE, true));
//报错
adb.setOnClickListener(view -> mUsbManager.setCurrentFunction(UsbManager.USB_FUNCTION_ADB, true));
rndis.setOnClickListener(view -> mUsbManager.setCurrentFunction(UsbManager.USB_FUNCTION_RNDIS, true));
mtp.setOnClickListener(view -> mUsbManager.setCurrentFunction(UsbManager.USB_FUNCTION_MTP, true));
ptp.setOnClickListener(view -> mUsbManager.setCurrentFunction(UsbManager.USB_FUNCTION_PTP, true));
//报错
audio_source.setOnClickListener(view -> mUsbManager.setCurrentFunction(UsbManager.USB_FUNCTION_AUDIO_SOURCE, true));
midi.setOnClickListener(view -> mUsbManager.setCurrentFunction(UsbManager.USB_FUNCTION_MIDI, true));
//报错
accessory.setOnClickListener(view -> mUsbManager.setCurrentFunction(UsbManager.USB_FUNCTION_ACCESSORY, true));
icon_off.setOnClickListener(view -> {
Settings.System.putInt(getContentResolver(), "qch_app_deskclock", 1);
Settings.System.putInt(getContentResolver(), "qch_app_soundrecorder", 1);
Settings.System.putInt(getContentResolver(), "qch_app_music", 1);
Settings.System.putInt(getContentResolver(), "qch_app_gallery", 1);
Settings.System.putInt(getContentResolver(), "qch_app_filemanager", 1);
Settings.System.putInt(getContentResolver(), "qch_app_browser", 1);
});
icon_on.setOnClickListener(view -> {
Settings.System.putInt(getContentResolver(), "qch_app_deskclock", 0);
Settings.System.putInt(getContentResolver(), "qch_app_soundrecorder", 0);
Settings.System.putInt(getContentResolver(), "qch_app_music", 0);
Settings.System.putInt(getContentResolver(), "qch_app_gallery", 0);
Settings.System.putInt(getContentResolver(), "qch_app_filemanager", 0);
Settings.System.putInt(getContentResolver(), "qch_app_browser", 0);
});
icon_look.setOnClickListener(view -> {
int qch_app_deskclock = Settings.System.getInt(getContentResolver(), "qch_app_deskclock", 0);
Log.e(TAG, "debugTest: qch_app_deskclock = " + qch_app_deskclock);
int qch_app_soundrecorder = Settings.System.getInt(getContentResolver(), "qch_app_soundrecorder", 0);
Log.e(TAG, "debugTest: qch_app_soundrecorder = " + qch_app_soundrecorder);
int qch_app_music = Settings.System.getInt(getContentResolver(), "qch_app_music", 0);
Log.e(TAG, "debugTest: qch_app_music = " + qch_app_music);
int qch_app_gallery = Settings.System.getInt(getContentResolver(), "qch_app_gallery", 0);
Log.e(TAG, "debugTest: qch_app_gallery = " + qch_app_gallery);
int qch_app_filemanager = Settings.System.getInt(getContentResolver(), "qch_app_filemanager", 0);
Log.e(TAG, "debugTest: qch_app_filemanager = " + qch_app_filemanager);
int qch_app_browser = Settings.System.getInt(getContentResolver(), "qch_app_browser", 0);
Log.e(TAG, "debugTest: qch_app_browser = " + qch_app_browser);
});
}
@Override
public void initData() {
startService(new Intent(MainActivity.this, MainService.class));
registHideAppReceiver();
registForbidAppReceiver();
registerUserInfoReceiver();
@@ -178,7 +248,7 @@ public class JMainActivity extends ImmerseBaseActivity {
e.printStackTrace();
Log.e("mIGetInfoConnection", "getUserInfo: " + e.getMessage());
}
}else {
} else {
bindinfoService();
}
@@ -0,0 +1,38 @@
package com.tt.ttutils.activity.retrofit;
import com.tt.ttutils.R;
import com.tt.ttutils.base.BaseActivity;
public class RetrofitActivity extends BaseActivity implements RetrofitContact.MainView {
private RetrofitPresenter mRetrofitPresenter;
@Override
public int getLayoutId() {
return R.layout.activity_retrofit;
}
@Override
public void initView() {
mRetrofitPresenter = new RetrofitPresenter(this);
mRetrofitPresenter.attachView(this);
mRetrofitPresenter.setProvider(this);
mRetrofitPresenter.setLifecycle(lifecycleSubject);
}
@Override
public void initData() {
mRetrofitPresenter.testRetrofit();
}
@Override
public void testRetrofitFinish() {
}
@Override
protected void onDestroy() {
super.onDestroy();
mRetrofitPresenter.detachView();
}
}
@@ -0,0 +1,16 @@
package com.tt.ttutils.activity.retrofit;
import com.tt.ttutils.mvp.BasePresenter;
import com.tt.ttutils.mvp.BaseView;
public class RetrofitContact {
public interface Presenter extends BasePresenter<MainView> {
void testRetrofit();
}
public interface MainView extends BaseView {
void testRetrofitFinish();
}
}
@@ -0,0 +1,147 @@
package com.tt.ttutils.activity.retrofit;
import android.content.Context;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import androidx.annotation.NonNull;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.trello.rxlifecycle4.LifecycleProvider;
import com.trello.rxlifecycle4.RxLifecycle;
import com.trello.rxlifecycle4.android.ActivityEvent;
import com.tt.ttutils.activity.main.MainAContact;
import com.tt.ttutils.network.NetInterfaceManager;
import com.tt.ttutils.network.UrlAddress;
import com.tt.ttutils.retrofit.GetPublicIPApi;
import java.io.IOException;
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
import io.reactivex.rxjava3.core.Observer;
import io.reactivex.rxjava3.disposables.Disposable;
import io.reactivex.rxjava3.schedulers.Schedulers;
import io.reactivex.rxjava3.subjects.BehaviorSubject;
import okhttp3.ResponseBody;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava3.RxJava3CallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;
/**
* MainActivity 的 Presenter
*
* @author jgy02
*/
public class RetrofitPresenter implements RetrofitContact.Presenter {
private static final String TAG = RetrofitPresenter.class.getSimpleName();
private RetrofitContact.MainView mView;
private Context mContext;
public RetrofitPresenter(Context context) {
this.mContext = context;
Log.e(TAG, "MainSPresenter: " + context.getClass());
}
/**
* Lifecycle start
*/
/*1*/
private LifecycleProvider<ActivityEvent> provider;
public void setProvider(LifecycleProvider<ActivityEvent> provider) {
this.provider = provider;
}
public LifecycleProvider<ActivityEvent> getProvider() {
return provider;
}
/*2*/
private BehaviorSubject<ActivityEvent> lifecycle;
public void setLifecycle(BehaviorSubject<ActivityEvent> lifecycle) {
this.lifecycle = lifecycle;
}
public BehaviorSubject<ActivityEvent> getLifecycle() {
return lifecycle;
}
@Override
public void testRetrofit() {
Retrofit retrofit = new Retrofit.Builder()
.client(NetInterfaceManager.getInstance().getOkHttpClient())
.baseUrl(UrlAddress.SHOUHU_CITYJSON)
.addConverterFactory(GsonConverterFactory.create())
.addCallAdapterFactory(RxJava3CallAdapterFactory.create())
.build();
retrofit.create(GetPublicIPApi.class)
.getPublicIP()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
//1
.compose(provider.bindUntilEvent(ActivityEvent.DESTROY))
//2
.compose(RxLifecycle.bindUntilEvent(lifecycle, ActivityEvent.DESTROY))
.subscribe(new Observer<ResponseBody>() {
@Override
public void onSubscribe(Disposable d) {
Log.e("getPublicIP", "onSubscribe: ");
}
@Override
public void onNext(ResponseBody responseBody) {
try {
String s = responseBody.string();
Log.e("getPublicIP", "onNext: " + s);
if (!TextUtils.isEmpty(s)) {
//var returnCitySN = {"cip": "183.11.74.141", "cid": "440300", "cname": "广东省深圳市"};
if (s.contains("{")) {
String jsonString = s.substring(s.indexOf("{"), s.lastIndexOf("}") + 1);
JsonObject jsonObject = JsonParser.parseString(jsonString).getAsJsonObject();
String ip = jsonObject.get("cip").getAsString();
if (!TextUtils.isEmpty(ip)) {
// publicIP.set(ip);
} else {
}
} else {
}
} else {
}
} catch (IOException e) {
e.printStackTrace();
Log.e("getPublicIP", "IOException: " + e.getMessage());
}
}
@Override
public void onError(Throwable e) {
Log.e("getPublicIP", "onError: " + e.getMessage());
}
@Override
public void onComplete() {
Log.e("getPublicIP", "onComplete: ");
}
});
}
@Override
public void attachView(@NonNull RetrofitContact.MainView view) {
}
@Override
public void detachView() {
}
/**
* Lifecycle end
*/
}
@@ -0,0 +1,129 @@
package com.tt.ttutils.base;
import android.os.Bundle;
import androidx.annotation.CallSuper;
import androidx.annotation.CheckResult;
import androidx.annotation.ContentView;
import androidx.annotation.LayoutRes;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import com.trello.rxlifecycle4.LifecycleProvider;
import com.trello.rxlifecycle4.LifecycleTransformer;
import com.trello.rxlifecycle4.RxLifecycle;
import com.trello.rxlifecycle4.android.ActivityEvent;
import com.trello.rxlifecycle4.android.RxLifecycleAndroid;
import com.tt.ttutils.R;
import com.zackratos.ultimatebarx.ultimatebarx.java.UltimateBarX;
import io.reactivex.rxjava3.core.Observable;
import io.reactivex.rxjava3.subjects.BehaviorSubject;
public abstract class BaseActivity extends AppCompatActivity implements LifecycleProvider<ActivityEvent> {
public final BehaviorSubject<ActivityEvent> lifecycleSubject = BehaviorSubject.create();
public BaseActivity() {
super();
}
@ContentView
public BaseActivity(@LayoutRes int contentLayoutId) {
super(contentLayoutId);
}
@Override
@NonNull
@CheckResult
public final Observable<ActivityEvent> lifecycle() {
return lifecycleSubject.hide();
}
@Override
@NonNull
@CheckResult
public final <T> LifecycleTransformer<T> bindUntilEvent(@NonNull ActivityEvent event) {
return RxLifecycle.bindUntilEvent(lifecycleSubject, event);
}
@Override
@NonNull
@CheckResult
public final <T> LifecycleTransformer<T> bindToLifecycle() {
return RxLifecycleAndroid.bindActivity(lifecycleSubject);
}
@Override
@CallSuper
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
lifecycleSubject.onNext(ActivityEvent.CREATE);
// StatusBarUtil.init(this);
UltimateBarX.statusBar(this)
.transparent()
.colorRes(R.color.colorPrimaryDark)
.light(true)
.apply();
UltimateBarX.navigationBar(this)
.transparent()
.colorRes(R.color.colorPrimaryDark)
.light(true)
.apply();
setContentView(this.getLayoutId());
initView();
initData();
}
/**
* 设置布局
*/
public abstract int getLayoutId();
/**
* 初始化视图
*/
public abstract void initView();
/**
* 初始化数据
*/
public abstract void initData();
@Override
@CallSuper
protected void onStart() {
super.onStart();
lifecycleSubject.onNext(ActivityEvent.START);
}
@Override
@CallSuper
protected void onResume() {
super.onResume();
lifecycleSubject.onNext(ActivityEvent.RESUME);
}
@Override
@CallSuper
protected void onPause() {
lifecycleSubject.onNext(ActivityEvent.PAUSE);
super.onPause();
}
@Override
@CallSuper
protected void onStop() {
lifecycleSubject.onNext(ActivityEvent.STOP);
super.onStop();
}
@Override
@CallSuper
protected void onDestroy() {
lifecycleSubject.onNext(ActivityEvent.DESTROY);
super.onDestroy();
}
}
@@ -1,20 +1,37 @@
package com.tt.base;
package com.tt.ttutils.base;
import android.app.Application;
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
import com.tencent.android.tpush.XGIOperateCallback;
import com.tencent.android.tpush.XGPushConfig;
import com.tencent.android.tpush.XGPushManager;
import com.tt.ttutils.BuildConfig;
public class JMyApplication extends Application {
public class BaseApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
if (!BuildConfig.DEBUG) {
catchException();
}
XGPushConfig.enableDebug(this, true);
XGPushManager.registerPush(this, new XGIOperateCallback() {
@Override
public void onSuccess(Object data, int flag) {
//token在设备卸载重装的时候有可能会变
Log.d("TPush", "注册成功,设备token为:" + data);
}
@Override
public void onFail(Object data, int errCode, String msg) {
Log.d("TPush", "注册失败,错误码:" + errCode + ",错误信息:" + msg);
}
});
}
private void catchException() {
Thread.setDefaultUncaughtExceptionHandler(
new Thread.UncaughtExceptionHandler() {
@@ -0,0 +1,114 @@
package com.tt.ttutils.base;
import android.os.Bundle;
import android.view.View;
import androidx.annotation.CheckResult;
import androidx.annotation.ContentView;
import androidx.annotation.LayoutRes;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import com.trello.rxlifecycle4.LifecycleProvider;
import com.trello.rxlifecycle4.LifecycleTransformer;
import com.trello.rxlifecycle4.RxLifecycle;
import com.trello.rxlifecycle4.android.FragmentEvent;
import com.trello.rxlifecycle4.android.RxLifecycleAndroid;
import io.reactivex.rxjava3.core.Observable;
import io.reactivex.rxjava3.subjects.BehaviorSubject;
public class BaseFragment extends Fragment implements LifecycleProvider<FragmentEvent> {
private final BehaviorSubject<FragmentEvent> lifecycleSubject = BehaviorSubject.create();
public BaseFragment() {
super();
}
@ContentView
public BaseFragment(@LayoutRes int contentLayoutId) {
super(contentLayoutId);
}
@Override
@NonNull
@CheckResult
public final Observable<FragmentEvent> lifecycle() {
return lifecycleSubject.hide();
}
@Override
@NonNull
@CheckResult
public final <T> LifecycleTransformer<T> bindUntilEvent(@NonNull FragmentEvent event) {
return RxLifecycle.bindUntilEvent(lifecycleSubject, event);
}
@Override
@NonNull
@CheckResult
public final <T> LifecycleTransformer<T> bindToLifecycle() {
return RxLifecycleAndroid.bindFragment(lifecycleSubject);
}
@Override
public void onAttach(android.app.Activity activity) {
super.onAttach(activity);
lifecycleSubject.onNext(FragmentEvent.ATTACH);
}
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
lifecycleSubject.onNext(FragmentEvent.CREATE);
}
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
lifecycleSubject.onNext(FragmentEvent.CREATE_VIEW);
}
@Override
public void onStart() {
super.onStart();
lifecycleSubject.onNext(FragmentEvent.START);
}
@Override
public void onResume() {
super.onResume();
lifecycleSubject.onNext(FragmentEvent.RESUME);
}
@Override
public void onPause() {
lifecycleSubject.onNext(FragmentEvent.PAUSE);
super.onPause();
}
@Override
public void onStop() {
lifecycleSubject.onNext(FragmentEvent.STOP);
super.onStop();
}
@Override
public void onDestroyView() {
lifecycleSubject.onNext(FragmentEvent.DESTROY_VIEW);
super.onDestroyView();
}
@Override
public void onDestroy() {
lifecycleSubject.onNext(FragmentEvent.DESTROY);
super.onDestroy();
}
@Override
public void onDetach() {
lifecycleSubject.onNext(FragmentEvent.DETACH);
super.onDetach();
}
}
@@ -1,4 +1,4 @@
package com.tt.base;
package com.tt.ttutils.base;
import android.os.Bundle;
@@ -8,7 +8,7 @@ import androidx.appcompat.app.AppCompatActivity;
import com.tt.ttutils.R;
import com.zackratos.ultimatebarx.ultimatebarx.java.UltimateBarX;
public abstract class ImmerseBaseActivity extends AppCompatActivity {
public abstract class ImmerseBaseActivity extends BaseActivity {
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
@@ -1,26 +1,41 @@
package com.tt.base
package com.tt.ttutils.base
import android.app.Application
import android.os.Handler
import android.os.Looper
import android.util.Log
import cn.jpush.android.api.JPushInterface
import com.tencent.android.tpush.XGIOperateCallback
import com.tencent.android.tpush.XGPushConfig
import com.tencent.android.tpush.XGPushManager
import com.tt.ttutils.BuildConfig
import com.tt.ttutils.java.ToastUtil
import com.tt.ttutils.utils.java.ToastUtil
class MyApplication : Application() {
class KotlinApplication : Application() {
private val debug = BuildConfig.DEBUG;
override fun onCreate() {
super.onCreate()
ToastUtil.init(this)
JPushInterface.setDebugMode(debug) // 设置开启日志,发布时请关闭日志
JPushInterface.init(this) // 初始化 JPush
XGPushConfig.enableDebug(this, true)
XGPushManager.registerPush(this, object : XGIOperateCallback {
override fun onSuccess(data: Any, flag: Int) {
//token在设备卸载重装的时候有可能会变
Log.d("TPush", "注册成功,设备token为:$data")
}
override fun onFail(data: Any, errCode: Int, msg: String) {
Log.d("TPush", "注册失败,错误码:$errCode,错误信息:$msg")
}
})
if (!BuildConfig.DEBUG) {
catchException();
}
}
private fun catchException() {
Thread.setDefaultUncaughtExceptionHandler { t, e ->
Log.d(
@@ -1,9 +1,7 @@
package com.tt.base;
package com.tt.ttutils.base.old;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.view.Window;
@@ -12,8 +10,7 @@ import android.view.WindowManager;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
public abstract class BaseActivity extends AppCompatActivity {
public abstract class BaseActivity1 extends AppCompatActivity {
private static Handler sHandler;
@Override
@@ -0,0 +1,24 @@
package com.tt.ttutils.bean;
import androidx.annotation.NonNull;
import com.google.gson.Gson;
import com.google.gson.JsonParser;
import java.io.Serializable;
public class BaseResponse<T> implements Serializable {
private static final long serialVersionUID = 5468533687801294972L;
public int code;
public String msg;
public T data;
@NonNull
@Override
public String toString() {
return JsonParser.parseString(new Gson().toJson(this)).getAsJsonObject().toString();
}
}
@@ -0,0 +1,36 @@
package com.tt.ttutils.db;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.os.Environment;
import java.io.File;
public class LogDBHelper extends SQLiteOpenHelper {
public static final String DATABASE_NAME = "requestlog.db";
private static final String DATABASE_FILE_NAME = Environment.getExternalStorageDirectory().getPath() + File.separator + DATABASE_NAME;
private static final int DATABASE_VERSION = 1;
public LogDBHelper(Context context) {
super(context, DATABASE_FILE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase sqLiteDatabase) {
sqLiteDatabase.execSQL("CREATE TABLE IF NOT EXISTS logtable (" +
"id integer primary key autoincrement," +
"code varchar(8)," +
"timestamp integer," +
"event varchar(64)," +
"operate varchar(64)," +
"content text" +
")"
);
}
@Override
public void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i1) {
}
}
@@ -0,0 +1,23 @@
package com.tt.ttutils.db;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
public class OpenHelper extends SQLiteOpenHelper {
public OpenHelper(Context context) {
super(context, "XGExample.db", null, 1);
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("CREATE TABLE notification (id integer primary key autoincrement,msg_id varchar(64),title varchar(128),activity varchar(256),notificationActionType varchar(512),content text,update_time varchar(16))");
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
}
}
@@ -1,15 +0,0 @@
package com.tt.ttutils.java;
import android.content.Context;
import android.content.Intent;
public class ApkUtils {
public static void openApp(Context context, String packageName) {
Intent intent = context.getPackageManager().getLaunchIntentForPackage(packageName);
if (intent != null) {
// intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
}
}
}
@@ -1,4 +0,0 @@
package com.tt.ttutils.java;
public class BitmapUtils {
}
@@ -1,5 +0,0 @@
package com.tt.ttutils.java;
public class OtherUtils {
}
@@ -1,6 +0,0 @@
package com.tt.ttutils.kt
class ApkUtils {
}
@@ -1,4 +1,4 @@
package com.tt.mvp;
package com.tt.ttutils.mvp;
import androidx.annotation.NonNull;
@@ -1,4 +1,4 @@
package com.tt.mvp;
package com.tt.ttutils.mvp;
public interface BaseView {
}
@@ -0,0 +1,129 @@
package com.tt.ttutils.network;
import android.annotation.SuppressLint;
import android.content.Context;
import android.util.Log;
import com.tencent.mmkv.MMKV;
import com.tt.ttutils.BuildConfig;
import com.tt.ttutils.utils.java.MD5Util;
import org.jetbrains.annotations.NotNull;
import java.io.File;
import java.io.IOException;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;
import okhttp3.Cache;
import okhttp3.Interceptor;
import okhttp3.OkHttpClient;
import okhttp3.Protocol;
import okhttp3.Request;
import okhttp3.Response;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava3.RxJava3CallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;
public class NetInterfaceManager {
private static final String TAG = NetInterfaceManager.class.getSimpleName();
@SuppressLint("StaticFieldLeak")
private static NetInterfaceManager INSTANCE;
private Context mContext;
private Retrofit mRetrofit;
private OkHttpClient okHttpClient;
private MMKV mMMKV = MMKV.defaultMMKV();
private final ConcurrentHashMap<String, Long> requestIdsMap = new ConcurrentHashMap<>();
private static final long ONE_MINUTE_TIME = 60 * 1000;
private static final long TEN_MINUTE_TIME = ONE_MINUTE_TIME * 10;
private static final long HALF_HOUR_TIME = TEN_MINUTE_TIME * 3;
private static final long ONE_HOUR_TIME = HALF_HOUR_TIME * 2;
//超时时间
private static int timeOut = 5;
// 缓存文件最大限制大小20M
private static long cacheSize = 1024 * 1024 * 64;
public static final String CUSTOM_REPEAT_REQ_PROTOCOL = "MY_CUSTOM_REPEAT_REQ_PROTOCOL";
private NetInterfaceManager(Context context) {
this.mContext = context;
if (okHttpClient == null) {
Interceptor interceptor = new Interceptor() {
@NotNull
@Override
public Response intercept(@NotNull Chain chain) throws IOException {
Request request = chain.request();
//相同的请求
String requestKey = MD5Util.getUpperMD5Str(request.method() + request.url().toString());
long time = System.currentTimeMillis();//请求时间
try {
if (requestIdsMap.size() > 0 && requestIdsMap.containsKey(requestKey)) {
Log.e("REPEAT-REQUEST", "重复请求:" + requestKey + " Method @" + request.method() + " --- " + " URL = " + request.url());
chain.call().cancel();
return new Response.Builder()
.protocol(Protocol.get(CUSTOM_REPEAT_REQ_PROTOCOL))
.request(request) //multi thread
.build();
}
requestIdsMap.put(requestKey, time);
Log.e("REPEAT-REQUEST", "注册请求:" + requestKey + " Method @" + request.method() + " --- " + " URL = " + request.url());
// Request.Builder builder = request.newBuilder();
// builder.addHeader("header", jsonObject.toString());
return chain.proceed(request);
} catch (IOException e) {
throw e;
} finally {
if (requestIdsMap.containsKey(requestKey) && requestIdsMap.containsValue(time)) {//请求任务完成删除map中的数据
requestIdsMap.remove(requestKey);
Log.e("REPEAT-REQUEST", "移除请求:" + requestKey + " Method @" + request.method() + " --- " + " URL = " + request.url());
}
}
}
};
//如果无法生存缓存文件目录,检测权限使用已经加上,检测手机是否把文件读写权限禁止了
OkHttpClient.Builder builder = new OkHttpClient.Builder();
builder.connectTimeout(timeOut, TimeUnit.SECONDS); // 设置连接超时时间
builder.writeTimeout(timeOut, TimeUnit.SECONDS);// 设置写入超时时间
builder.readTimeout(timeOut, TimeUnit.SECONDS);// 设置读取数据超时时间
builder.retryOnConnectionFailure(true);// 设置进行连接失败重试
builder.addInterceptor(interceptor);
// 设置缓存文件路径
String cacheDirectory = mContext.getExternalCacheDir().getAbsolutePath() + "/OkHttpCache";
Cache cache = new Cache(new File(cacheDirectory), cacheSize);
builder.cache(cache);// 设置缓存
okHttpClient = builder.build();
}
if (mRetrofit == null) {
mRetrofit = new Retrofit.Builder()
.client(okHttpClient)
.baseUrl(BuildConfig.ROOT_URL)
.addConverterFactory(GsonConverterFactory.create())
.addCallAdapterFactory(RxJava3CallAdapterFactory.create())
.build();
}
}
public static void init(Context context) {
if (INSTANCE == null) {
INSTANCE = new NetInterfaceManager(context);
}
}
public static NetInterfaceManager getInstance() {
if (INSTANCE == null) {
throw new IllegalStateException("You must be init NetworkManager first");
}
return INSTANCE;
}
public OkHttpClient getOkHttpClient() {
return okHttpClient;
}
}
@@ -0,0 +1,7 @@
package com.tt.ttutils.network;
public class UrlAddress {
/**获取公网IP*/
public static final String SHOUHU_CITYJSON = "http://pv.sohu.com/cityjson/";
}
@@ -1,4 +1,4 @@
package com.tt.receiver;
package com.tt.ttutils.receiver;
import android.content.BroadcastReceiver;
import android.content.Context;
@@ -1,4 +1,4 @@
package com.tt.receiver;
package com.tt.ttutils.receiver;
import android.content.BroadcastReceiver;
import android.content.Context;
@@ -0,0 +1,20 @@
package com.tt.ttutils.retrofit;
import com.tt.ttutils.network.UrlAddress;
import io.reactivex.rxjava3.core.Observable;
import okhttp3.ResponseBody;
import retrofit2.http.GET;
/**
* @author : fanhuitong
* e-mail :
* @date : 2021/10/1814:39
* desc :
* version: 1.0
*/
public interface GetPublicIPApi {
@GET(UrlAddress.SHOUHU_CITYJSON)
Observable<ResponseBody> getPublicIP();
}
@@ -1,4 +1,4 @@
package com.tt.sdk.jpush.jpushdemo;
package com.tt.ttutils.sdk.jpush.jpushdemo;
import android.content.Context;
import android.content.pm.ApplicationInfo;
@@ -1,4 +1,4 @@
package com.tt.sdk.jpush.jpushdemo;
package com.tt.ttutils.sdk.jpush.jpushdemo;
import android.content.BroadcastReceiver;
import android.content.Context;
@@ -1,4 +1,4 @@
package com.tt.sdk.jpush.jpushdemo;
package com.tt.ttutils.sdk.jpush.jpushdemo;
import android.util.Log;
@@ -1,4 +1,4 @@
package com.tt.sdk.jpush.jpushdemo;
package com.tt.ttutils.sdk.jpush.jpushdemo;
import android.content.BroadcastReceiver;
import android.content.Context;
@@ -1,13 +1,10 @@
package com.tt.sdk.jpush.jpushdemo;
package com.tt.ttutils.sdk.jpush.jpushdemo;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import org.json.JSONException;
import org.json.JSONObject;
import cn.jpush.android.api.CmdMessage;
import cn.jpush.android.api.CustomMessage;
import cn.jpush.android.api.JPushInterface;
@@ -1,4 +1,4 @@
package com.tt.sdk.jpush.jpushdemo;
package com.tt.ttutils.sdk.jpush.jpushdemo;
import cn.jpush.android.service.JCommonService;
@@ -1,4 +1,4 @@
package com.tt.sdk.jpush.jpushdemo;
package com.tt.ttutils.sdk.jpush.jpushdemo;
import android.content.Context;
import android.os.Handler;
@@ -1,4 +1,4 @@
package com.tt.sdk.jpush.jpushdemo;
package com.tt.ttutils.sdk.jpush.jpushdemo;
import android.app.Activity;
import android.content.Intent;
@@ -1,10 +1,12 @@
package com.tt.mvp;
package com.tt.ttutils.server.main;
import android.view.View;
import com.google.gson.JsonObject;
import com.tt.ttutils.mvp.BasePresenter;
import com.tt.ttutils.mvp.BaseView;
public class MainContact {
public class MainSContact {
public interface MainView extends BaseView {
//设置批次信息
void setBatchText(String text, int visibility);
@@ -0,0 +1,223 @@
package com.tt.ttutils.server.main;
import android.content.Context;
import android.util.Log;
import android.view.View;
import com.trello.rxlifecycle4.LifecycleProvider;
import com.trello.rxlifecycle4.android.ActivityEvent;
import com.tt.ttutils.activity.main.MainAContact;
import io.reactivex.rxjava3.subjects.BehaviorSubject;
/**
* MainActivity 的 Presenter
*
* @author jgy02
*/
public class MainSPresenter implements MainSContact.Presenter {
private static final String TAG = MainSPresenter.class.getSimpleName();
private MainSContact.MainView mView;
private Context mContext;
private final String DEFAULT_INFO = "暂无信息";
private final int OK = 200;
public MainSPresenter(Context context) {
this.mContext = context;
Log.e(TAG, "MainSPresenter: " + context.getClass());
}
/**
* Lifecycle start
*/
/*1*/
private LifecycleProvider<ActivityEvent> provider;
public void setProvider(LifecycleProvider<ActivityEvent> provider) {
this.provider = provider;
}
public LifecycleProvider<ActivityEvent> getProvider() {
return provider;
}
/*2*/
private BehaviorSubject<ActivityEvent> lifecycle;
public void setLifecycle(BehaviorSubject<ActivityEvent> lifecycle) {
this.lifecycle = lifecycle;
}
public BehaviorSubject<ActivityEvent> getLifecycle() {
return lifecycle;
}
/**
* Lifecycle end
*/
@Override
public void attachView(@androidx.annotation.NonNull MainSContact.MainView view) {
this.mView = view;
}
@Override
public void detachView() {
this.mView = null;
}
@Override
public void getStudesInfo() {
}
@Override
public void getLockedState() {
}
@Override
public void getFirstConnect() {
}
@Override
public void setDisableSetting() {
}
@Override
public void sendMACAddress() {
}
@Override
public void updateDeviceInfo() {
}
@Override
public void getSnTimeControl() {
}
@Override
public void setJpushAlias() {
}
@Override
public void setJpushTags() {
}
@Override
public void setJpushPlatformTags(int platform) {
mView.setJpushPlatformTagsFinished();
}
@Override
public void checkStoreUpdate() {
}
@Override
public void buttonCheckUpdate(View view) {
}
@Override
public void checkTestUpdate() {
}
@Override
public void getSystemSettingbegin() {
}
@Override
public void getAppLimit() {
}
@Override
public void getDeviceBatch(String packageList) {
}
@Override
public void getForceDownload() {
}
@Override
public void getBrowserList() {
}
@Override
public void getBrowserBookmarks(String whitelist) {
}
@Override
public void getBrowserWhiteList() {
}
@Override
public void getDesktopIcon() {
}
@Override
public void getAppAutoStartUpdateAndNet() {
}
@Override
public void getAppIDControl() {
}
@Override
public void setAppinsideWeb() {
}
@Override
public void setSystemSetting() {
}
@Override
public void getDeveloper() {
}
@Override
public void setLogoImg() {
}
@Override
public void setTopApp() {
}
@Override
public void getScreenLockState() {
}
@Override
public void getDefaultDesktop() {
}
}
@@ -1,13 +1,16 @@
package com.tt.server;
package com.tt.ttutils.server.main;
import android.annotation.SuppressLint;
import android.app.Service;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.Color;
import android.graphics.PixelFormat;
import android.hardware.usb.UsbManager;
import android.os.Build;
import android.os.IBinder;
import android.os.SystemClock;
@@ -19,10 +22,9 @@ import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import com.google.gson.JsonObject;
import com.tt.mvp.MainContact;
import com.tt.mvp.MainPresenter;
import com.tt.ttutils.R;
import java.util.Arrays;
@@ -30,14 +32,15 @@ import java.util.HashSet;
import java.util.concurrent.TimeUnit;
import cn.jpush.android.api.JPushInterface;
import io.reactivex.Observable;
import io.reactivex.ObservableEmitter;
import io.reactivex.ObservableOnSubscribe;
import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;
import io.reactivex.rxjava3.core.Observable;
import io.reactivex.rxjava3.core.ObservableEmitter;
import io.reactivex.rxjava3.core.ObservableOnSubscribe;
import io.reactivex.rxjava3.core.Observer;
import io.reactivex.rxjava3.disposables.Disposable;
public class MainService extends Service implements MainContact.MainView {
private MainPresenter mPresenter;
public class MainService extends Service implements MainSContact.MainView {
private MainSPresenter mPresenter;
private UsbManager mUsbManager;
private static final String TAG = MainService.class.getSimpleName();
public static boolean netWorkIsRunning = false;
@@ -96,19 +99,101 @@ public class MainService extends Service implements MainContact.MainView {
@Override
public void onCreate() {
mPresenter = new MainPresenter(this);
super.onCreate();
mPresenter = new MainSPresenter(this);
mPresenter.attachView(this);
registerReceivers();
Observable.create(subscribe)
.throttleLast(60, TimeUnit.SECONDS)
.subscribe(timeObserver);
// cleanLauncherCache();
super.onCreate();
//注册蓝牙监听
registerReceiver(mReceiver, makeFilter());
registerUsbReceiver(this);
// mUsbManager = (UsbManager) getSystemService(Context.USB_SERVICE);
// mUsbManager.setCurrentFunction(UsbManager.USB_FUNCTION_MTP, true);
}
public void registerUsbReceiver(Context context) {
IntentFilter filter = new IntentFilter();
filter.addAction(UsbManager.ACTION_USB_STATE);
filter.addAction(UsbManager.ACTION_USB_PORT_CHANGED);
context.registerReceiver(usbBroadcastReceiver, filter);
}
BroadcastReceiver usbBroadcastReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
Toast.makeText(context, "aciton =" + action, Toast.LENGTH_SHORT).show();
if (action.equals(UsbManager.ACTION_USB_STATE)) {
boolean connected = intent.getExtras().getBoolean("connected");
Toast.makeText(context, "aciton =" + connected, Toast.LENGTH_SHORT).show();
if (connected) {
} else {
}
}
}
};
private IntentFilter makeFilter() {
IntentFilter filter = new IntentFilter();
filter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED);
filter.addAction(BluetoothDevice.ACTION_ACL_DISCONNECTED);
filter.addAction(BluetoothDevice.ACTION_ACL_CONNECTED);
return filter;
}
private BroadcastReceiver mReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
switch (intent.getAction()) {
case BluetoothAdapter.ACTION_STATE_CHANGED:
int blueState = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, 0);
switch (blueState) {
case BluetoothAdapter.STATE_OFF:
Log.e("TAG", "STATE_OFF");
break;
case BluetoothAdapter.STATE_TURNING_OFF:
Log.e("TAG", "STATE_TURNING_OFF");
break;
case BluetoothAdapter.STATE_ON:
Log.e("TAG", "STATE_ON");
break;
case BluetoothAdapter.STATE_TURNING_ON:
Log.e("TAG", "TURNING_ON");
break;
case BluetoothAdapter.STATE_BLE_TURNING_ON:
Log.e("TAG", "STATE_BLE_TURNING_ON");
break;
case BluetoothAdapter.STATE_BLE_ON:
Log.e("TAG", "STATE_BLE_ON");
break;
case BluetoothAdapter.STATE_BLE_TURNING_OFF:
Log.e("TAG", "STATE_BLE_TURNING_OFF");
break;
}
break;
case BluetoothDevice.ACTION_ACL_CONNECTED:
Log.e("TAG", "ACTION_ACL_CONNECTED");
Toast.makeText(context, "蓝牙设备已连接", Toast.LENGTH_SHORT).show();
break;
case BluetoothDevice.ACTION_ACL_DISCONNECTED:
Log.e("TAG", "ACTION_ACL_DISCONNECTED");
Toast.makeText(context, "蓝牙设备已断开", Toast.LENGTH_SHORT).show();
break;
}
}
};
@Override
public void onDestroy() {
super.onDestroy();
//注销蓝牙监听
unregisterReceiver(mReceiver);
unRegisterReceivers();
mPresenter.detachView();
}
@@ -135,8 +220,8 @@ public class MainService extends Service implements MainContact.MainView {
// Log.e(TAG, "onStartCommand: isForeground: " + MainActivity.isForeground);
// Log.e(TAG, "onStartCommand: " + (SystemClock.elapsedRealtime() - startCommandTime));
// }
start.onstar(SystemClock.elapsedRealtime());
Log.e("timeObserver", "onStartCommand: " + (SystemClock.elapsedRealtime() - startCommandTime) + "ms");
start.onstar(SystemClock.elapsedRealtime());
Log.e("timeObserver", "onStartCommand: " + (SystemClock.elapsedRealtime() - startCommandTime) + "ms");
// }
return START_STICKY;
}
@@ -0,0 +1,17 @@
package com.tt.ttutils.tpush;
/**
* Created by chacewang on 2019/7/5.
*/
public class Constants {
public static final int TEST_LOCAL_NOTIFICATION = 1;
public static final int TEST_NOTIFICATION = 2;
public static final int TEST_SET_TAG = 3;
public static final int TEST_DEL_TAG = 4;
public static final int TEST_SET_ACCOUNT = 5;
public static final int TEST_DEL_ACCOUNT = 6;
public static final String LOCAL_NOTIFICATION_TITLE = "localtest";
public static final String TEST_TAG_NAME = "DiagnosisTag";
}
@@ -0,0 +1,275 @@
package com.tt.ttutils.tpush;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.widget.Toast;
import com.tencent.android.tpush.NotificationAction;
import com.tencent.android.tpush.XGPushBaseReceiver;
import com.tencent.android.tpush.XGPushClickedResult;
import com.tencent.android.tpush.XGPushRegisterResult;
import com.tencent.android.tpush.XGPushShowedResult;
import com.tencent.android.tpush.XGPushTextMessage;
import com.tt.ttutils.tpush.common.NotificationService;
import com.tt.ttutils.tpush.po.XGNotification;
import org.json.JSONException;
import org.json.JSONObject;
import java.text.SimpleDateFormat;
import java.util.Calendar;
public class MessageReceiver extends XGPushBaseReceiver {
public static final String UPDATE_LISTVIEW_ACTION = "com.qq.xgdemo.activity.UPDATE_LISTVIEW";
public static final String TEST_ACTION = "com.qq.xgdemo.activity.TEST_ACTION";
public static final String LogTag = "xg.test";
/**
* 消息透传处理
* @param context
* @param message 解析自定义的 JSON
*/
@Override
public void onTextMessage(Context context, XGPushTextMessage message) {
String text = "收到消息:" + message.toString();
// 获取自定义key-value
String customContent = message.getCustomContent();
if (customContent != null && customContent.length() != 0) {
try {
JSONObject obj = new JSONObject(customContent);
// key1为前台配置的key
if (!obj.isNull("key")) {
String value = obj.getString("key");
Log.d(LogTag, "get custom value:" + value);
}
// ...
} catch (JSONException e) {
e.printStackTrace();
}
}
// APP自主处理消息的过程...
Log.d(LogTag, text);
show(context, text);
}
/**
* 通知展示
* @param context
* @param notifiShowedRlt 包含通知的内容
*/
@Override
public void onNotificationShowedResult(Context context, XGPushShowedResult notifiShowedRlt) {
if (context == null || notifiShowedRlt == null) {
return;
}
XGNotification notific = new XGNotification();
notific.setMsg_id(notifiShowedRlt.getMsgId());
notific.setTitle(notifiShowedRlt.getTitle());
notific.setContent(notifiShowedRlt.getContent());
// notificationActionType==1为Activity,2为url,3为intent
notific.setNotificationActionType(notifiShowedRlt
.getNotificationActionType());
// Activity,url,intent都可以通过getActivity()获得
notific.setActivity(notifiShowedRlt.getActivity());
notific.setUpdate_time(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
.format(Calendar.getInstance().getTime()));
NotificationService.getInstance(context).save(notific);
Intent testIntent = new Intent(TEST_ACTION);
if (notifiShowedRlt.getTitle().equals(Constants.LOCAL_NOTIFICATION_TITLE)) {
testIntent.putExtra("step", Constants.TEST_LOCAL_NOTIFICATION);
} else {
testIntent.putExtra("step", Constants.TEST_NOTIFICATION);
}
context.sendBroadcast(testIntent);
Intent viewIntent = new Intent(UPDATE_LISTVIEW_ACTION);
context.sendBroadcast(viewIntent);
show(context, "您有1条新消息, " + "通知被展示 , " + notifiShowedRlt.toString());
Log.d(LogTag, "您有1条新消息, " + "通知被展示 , " + notifiShowedRlt.toString() + ", PushChannel:" + notifiShowedRlt.getPushChannel());
}
/**
* 注册回调
* @param context
* @param errorCode 0 为成功,其它为错误码
*/
@Override
public void onRegisterResult(Context context, int errorCode, XGPushRegisterResult message) {
if (context == null || message == null) {
return;
}
String text = "";
if (errorCode == XGPushBaseReceiver.SUCCESS) {
// 在这里拿token
String token = message.getToken();
text = "注册成功1. token:" + token;
} else {
text = message + "注册失败,错误码:" + errorCode;
}
Log.d(LogTag, text);
show(context, text);
}
/**
* 反注册回调
* @param context
* @param errorCode 0 为成功,其它为错误码
*/
@Override
public void onUnregisterResult(Context context, int errorCode) {
if (context == null) {
return;
}
String text = "";
if (errorCode == XGPushBaseReceiver.SUCCESS) {
text = "反注册成功";
} else {
text = "反注册失败" + errorCode;
}
Log.d(LogTag, text);
show(context, text);
}
/**
* 设置标签回调
* @param context
* @param errorCode 0 为成功,其它为错误码
* @param tagName 设置的 TAG
*/
@Override
public void onSetTagResult(Context context, int errorCode, String tagName) {
if (context == null) {
return;
}
String text = "";
if (errorCode == XGPushBaseReceiver.SUCCESS) {
text = "\"" + tagName + "\"设置成功";
} else {
text = "\"" + tagName + "\"设置失败,错误码:" + errorCode;
}
Log.d(LogTag, text);
show(context, text);
Intent testIntent = new Intent(TEST_ACTION);
testIntent.putExtra("step", Constants.TEST_SET_TAG);
context.sendBroadcast(testIntent);
}
/**
* 删除标签的回调
* @param context
* @param errorCode 0 为成功,其它为错误码
* @param tagName 设置的 TAG
*/
@Override
public void onDeleteTagResult(Context context, int errorCode, String tagName) {
if (context == null) {
return;
}
String text = "";
if (errorCode == XGPushBaseReceiver.SUCCESS) {
text = "\"" + tagName + "\"删除成功";
} else {
text = "\"" + tagName + "\"删除失败,错误码:" + errorCode;
}
Log.d(LogTag, text);
show(context, text);
Intent testIntent = new Intent(TEST_ACTION);
testIntent.putExtra("step", Constants.TEST_DEL_TAG);
context.sendBroadcast(testIntent);
}
/**
* 设置账号回调
* @param context
* @param errorCode 0 为成功,其它为错误码
* @param account 设置的账号
*/
@Override
public void onSetAccountResult(Context context, int errorCode, String account) {
Intent testIntent = new Intent(TEST_ACTION);
testIntent.putExtra("step", Constants.TEST_SET_ACCOUNT);
context.sendBroadcast(testIntent);
}
/**
* 删除账号回调
* @param context
* @param errorCode 0 为成功,其它为错误码
* @param account 设置的账号
*/
@Override
public void onDeleteAccountResult(Context context, int errorCode, String account) {
Intent testIntent = new Intent(TEST_ACTION);
testIntent.putExtra("step", Constants.TEST_DEL_ACCOUNT);
context.sendBroadcast(testIntent);
}
@Override
public void onSetAttributeResult(Context context, int i, String s) {
}
@Override
public void onDeleteAttributeResult(Context context, int i, String s) {
}
@Override
public void onQueryTagsResult(Context context, int errorCode, String data, String operateName) {
Log.i(LogTag, "action - onQueryTagsResult, errorCode:" + errorCode + ", operateName:" + operateName + ", data: " + data);
}
/**
* 通知点击回调 actionType=1为该消息被清除,actionType=0为该消息被点击
* @param context
* @param message 包含被点击通知的内容
*/
@Override
public void onNotificationClickedResult(Context context, XGPushClickedResult message) {
if (context == null || message == null) {
return;
}
String text = "";
if (message.getActionType() == NotificationAction.clicked.getType()) {
// 通知在通知栏被点击啦。。。。。
// APP自己处理点击的相关动作
// 这个动作可以在activity的onResume也能监听,请看第3点相关内容
text = "通知被打开 :" + message;
} else if (message.getActionType() == NotificationAction.delete.getType()) {
// 通知被清除啦。。。。
// APP自己处理通知被清除后的相关动作
text = "通知被清除 :" + message;
}
Toast.makeText(context, "广播接收到通知被点击:" + message.toString(),
Toast.LENGTH_SHORT).show();
// 获取自定义key-value
String customContent = message.getCustomContent();
if (customContent != null && customContent.length() != 0) {
try {
JSONObject obj = new JSONObject(customContent);
// key1为前台配置的key
if (!obj.isNull("key")) {
String value = obj.getString("key");
Log.d(LogTag, "get custom value:" + value);
}
// ...
} catch (JSONException e) {
e.printStackTrace();
}
}
// APP自主处理的过程。。。
Log.d(LogTag, text);
show(context, text);
}
private void show(Context context, String text) {
// Toast.makeText(context, text, Toast.LENGTH_SHORT).show();
}
}
@@ -0,0 +1,23 @@
package com.tt.ttutils.tpush.common;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
public class DBOpenHelper extends SQLiteOpenHelper {
public DBOpenHelper(Context context) {
super(context, "XGExample.db", null, 1);
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("CREATE TABLE notification (id integer primary key autoincrement,msg_id varchar(64),title varchar(128),activity varchar(256),notificationActionType varchar(512),content text,update_time varchar(16))");
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
}
}
@@ -0,0 +1,135 @@
package com.tt.ttutils.tpush.common;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import com.tt.ttutils.tpush.po.XGNotification;
import java.util.ArrayList;
import java.util.List;
public class NotificationService {
private DBOpenHelper dbOpenHelper;
private static NotificationService instance = null;
public NotificationService(Context context) {
this.dbOpenHelper = new DBOpenHelper(context);
}
public synchronized static NotificationService getInstance(Context ctx) {
if (null == instance) {
instance = new NotificationService(ctx);
}
return instance;
}
public void save(XGNotification notification) {
SQLiteDatabase db = dbOpenHelper.getWritableDatabase();
ContentValues values = new ContentValues();
values.put("msg_id", notification.getMsg_id());
values.put("title", notification.getTitle());
values.put("content", notification.getContent());
values.put("activity", notification.getActivity());
values.put("notificationActionType", notification.getNotificationActionType());
values.put("update_time", notification.getUpdate_time());
db.insert("notification", null, values);
}
public void delete(Integer id) {
SQLiteDatabase db = dbOpenHelper.getWritableDatabase();
db.delete("notification", "id=?", new String[] { id.toString() });
}
public void deleteAll() {
SQLiteDatabase db = dbOpenHelper.getWritableDatabase();
db.delete("notification", "", null);
}
public void update(XGNotification notification) {
SQLiteDatabase db = dbOpenHelper.getWritableDatabase();
ContentValues values = new ContentValues();
values.put("msg_id", notification.getMsg_id());
values.put("title", notification.getTitle());
values.put("content", notification.getContent());
values.put("activity", notification.getActivity());
values.put("notificationActionType", notification.getNotificationActionType());
values.put("update_time", notification.getUpdate_time());
db.update("notification", values, "id=?", new String[] { notification
.getId().toString() });
}
public XGNotification find(Integer id) {
SQLiteDatabase db = dbOpenHelper.getReadableDatabase();
Cursor cursor = db
.query("notification",
new String[] { "id,msg_id,title,content,activity,notificationActionType,update_time" },
"id=?", new String[] { id.toString() }, null, null,
null, "1");
try {
if (cursor.moveToFirst()) {
return new XGNotification(cursor.getInt(cursor
.getColumnIndex("id")), cursor.getLong(cursor
.getColumnIndex("msg_id")), cursor.getString(cursor
.getColumnIndex("title")), cursor.getString(cursor
.getColumnIndex("content")), cursor.getString(cursor
.getColumnIndex("activity")), cursor.getInt(cursor
.getColumnIndex("notificationActionType")), cursor.getString(cursor
.getColumnIndex("update_time")));
}
return null;
} finally {
cursor.close();
}
}
public List<XGNotification> getScrollData(int currentPage, int lineSize,
String msg_id) {
String firstResult = String.valueOf((currentPage - 1) * lineSize);
SQLiteDatabase db = dbOpenHelper.getReadableDatabase();
Cursor cursor = null;
try {
if (msg_id == null || "".equals(msg_id)) {
cursor = db
.query("notification",
new String[] { "id,msg_id,title,content,activity,notificationActionType,update_time" },
null, null, null, null, "update_time DESC",
firstResult + "," + lineSize);
} else {
cursor = db
.query("notification",
new String[] { "id,msg_id,title,content,activity,notificationActionType,update_time" },
"msg_id like ?", new String[] { msg_id + "%" },
null, null, "update_time DESC", firstResult
+ "," + lineSize);
}
List<XGNotification> notifications = new ArrayList<XGNotification>();
while (cursor.moveToNext()) {
notifications.add(new XGNotification(cursor.getInt(cursor
.getColumnIndex("id")), cursor.getLong(cursor
.getColumnIndex("msg_id")), cursor.getString(cursor
.getColumnIndex("title")), cursor.getString(cursor
.getColumnIndex("content")), cursor.getString(cursor
.getColumnIndex("activity")), cursor.getInt(cursor
.getColumnIndex("notificationActionType")), cursor.getString(cursor
.getColumnIndex("update_time"))));
}
return notifications;
} finally {
cursor.close();
}
}
public int getCount() {
SQLiteDatabase db = dbOpenHelper.getReadableDatabase();
Cursor cursor = db.rawQuery("select count(*) from notification", null);
try {
cursor.moveToFirst();
return cursor.getInt(0);
} finally {
cursor.close();
}
}
}
@@ -0,0 +1,83 @@
package com.tt.ttutils.tpush.po;
public class XGNotification {
private Integer id;
private Long msg_id;
private String title;
private String content;
private String activity;
private int notificationActionType;
private String update_time;
public XGNotification() {
}
public XGNotification(Integer id, Long msg_id, String title,
String content, String activity, int notificationActionType, String update_time) {
super();
this.id = id;
this.msg_id = msg_id;
this.title = title;
this.content = content;
this.activity = activity;
this.notificationActionType = notificationActionType;
this.update_time = update_time;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Long getMsg_id() {
return msg_id;
}
public void setMsg_id(Long msg_id) {
this.msg_id = msg_id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public String getUpdate_time() {
return update_time;
}
public void setUpdate_time(String update_time) {
this.update_time = update_time;
}
public String getActivity() {
return activity;
}
public void setActivity(String activity) {
this.activity = activity;
}
public int getNotificationActionType() {
return notificationActionType;
}
public void setNotificationActionType(int notificationActionType) {
this.notificationActionType = notificationActionType;
}
}
@@ -0,0 +1,72 @@
package com.tt.ttutils.utils.java;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.text.TextUtils;
import java.util.List;
public class ApkUtils {
public static void openApp(Context context, String packageName) {
Intent intent = context.getPackageManager().getLaunchIntentForPackage(packageName);
if (intent != null) {
// intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
}
}
public static boolean openPackage(Context context, String packageName) {
Context pkgContext = getPackageContext(context, packageName);
Intent intent = getAppOpenIntentByPackageName(context, packageName);
if (pkgContext != null && intent != null) {
pkgContext.startActivity(intent);
return true;
}
return false;
}
public static Context getPackageContext(Context context, String packageName) {
Context pkgContext = null;
if (context.getPackageName().equals(packageName)) {
pkgContext = context;
} else {
// 创建第三方应用的上下文环境
try {
pkgContext = context.createPackageContext(packageName,
Context.CONTEXT_IGNORE_SECURITY
| Context.CONTEXT_INCLUDE_CODE);
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
}
return pkgContext;
}
public static Intent getAppOpenIntentByPackageName(Context context, String packageName) {
//Activity完整名
String mainAct = null;
//根据包名寻找
PackageManager pkgMag = context.getPackageManager();
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
intent.setFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED | Intent.FLAG_ACTIVITY_NEW_TASK);
List<ResolveInfo> list = pkgMag.queryIntentActivities(intent, PackageManager.GET_ACTIVITIES);
for (int i = 0; i < list.size(); i++) {
ResolveInfo info = list.get(i);
if (info.activityInfo.packageName.equals(packageName)) {
mainAct = info.activityInfo.name;
break;
}
}
if (TextUtils.isEmpty(mainAct)) {
return null;
}
intent.setComponent(new ComponentName(packageName, mainAct));
return intent;
}
}
@@ -0,0 +1,4 @@
package com.tt.ttutils.utils.java;
public class BitmapUtils {
}
@@ -1,4 +1,4 @@
package com.tt.ttutils.java;
package com.tt.ttutils.utils.java;
import android.text.TextUtils;
import android.util.Log;
@@ -1,6 +1,5 @@
package com.tt.ttutils.java;
package com.tt.ttutils.utils.java;
import android.annotation.SuppressLint;
import android.content.Context;
import android.os.Build;
import android.provider.Settings;
@@ -0,0 +1,112 @@
package com.tt.ttutils.utils.java;
import android.annotation.SuppressLint;
import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
public class MD5Util {
public static String packetMD5(String str) {
MessageDigest messageDigest = null;
try {
messageDigest = MessageDigest.getInstance("MD5");
messageDigest.reset();
messageDigest.update(str.getBytes("UTF-8"));
} catch (NoSuchAlgorithmException e) {
System.out.println("NoSuchAlgorithmException caught!");
System.exit(-1);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
byte[] byteArray = messageDigest.digest();
StringBuffer md5StrBuff = new StringBuffer();
for (int i = 0; i < byteArray.length; i++) {
if (Integer.toHexString(0xFF & byteArray[i]).length() == 1)
md5StrBuff.append("0").append(
Integer.toHexString(0xFF & byteArray[i]));
else
md5StrBuff.append(Integer.toHexString(0xFF & byteArray[i]));
}
return md5StrBuff.toString();
}
@SuppressLint("DefaultLocale")
public static String getUpperMD5Str(String str) {
MessageDigest messageDigest = null;
try {
messageDigest = MessageDigest.getInstance("MD5");
messageDigest.reset();
messageDigest.update(str.getBytes("UTF-8"));
} catch (NoSuchAlgorithmException e) {
System.out.println("NoSuchAlgorithmException caught!");
System.exit(-1);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
byte[] byteArray = messageDigest.digest();
StringBuffer md5StrBuff = new StringBuffer();
for (int i = 0; i < byteArray.length; i++) {
if (Integer.toHexString(0xFF & byteArray[i]).length() == 1)
md5StrBuff.append("0").append(
Integer.toHexString(0xFF & byteArray[i]));
else
md5StrBuff.append(Integer.toHexString(0xFF & byteArray[i]));
}
return md5StrBuff.toString().toUpperCase();
}
/**
* 获取16位的MD5 值得
*
* @param str
* @return
*/
@SuppressLint("DefaultLocale")
public static String getUpperMD5Str16(String str) {
MessageDigest messageDigest = null;
try {
messageDigest = MessageDigest.getInstance("MD5");
messageDigest.reset();
messageDigest.update(str.getBytes("UTF-8"));
} catch (NoSuchAlgorithmException e) {
System.out.println("NoSuchAlgorithmException caught!");
System.exit(-1);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
byte[] byteArray = messageDigest.digest();
StringBuffer md5StrBuff = new StringBuffer();
for (int i = 0; i < byteArray.length; i++) {
if (Integer.toHexString(0xFF & byteArray[i]).length() == 1)
md5StrBuff.append("0").append(
Integer.toHexString(0xFF & byteArray[i]));
else
md5StrBuff.append(Integer.toHexString(0xFF & byteArray[i]));
}
return md5StrBuff.toString().toUpperCase().substring(8, 24);
}
}
@@ -0,0 +1,5 @@
package com.tt.ttutils.utils.java;
public class OtherUtils {
}
@@ -1,8 +1,4 @@
package com.tt.ttutils.java;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
package com.tt.ttutils.utils.java;
public class PictrueUtils {
/**{@link }
@@ -1,4 +1,4 @@
package com.tt.ttutils.java;
package com.tt.ttutils.utils.java;
import android.app.Activity;
import android.content.Context;
@@ -1,4 +1,4 @@
package com.tt.ttutils.java;
package com.tt.ttutils.utils.java;
public class SystemSignUtils {
@@ -1,4 +1,4 @@
package com.tt.ttutils.java;
package com.tt.ttutils.utils.java;
import android.annotation.SuppressLint;
import android.content.Context;
@@ -1,4 +1,4 @@
package com.tt.ttutils.jni;
package com.tt.ttutils.utils.jni;
public class NDKTools {
static {
@@ -0,0 +1,6 @@
package com.tt.ttutils.utils.kt
class ApkUtils {
}
@@ -1,10 +1,8 @@
package com.tt.ttutils.kt
package com.tt.ttutils.utils.kt
import android.content.Context
import android.os.Handler
import android.os.Looper
import android.os.Message
import android.widget.Toast
class ToastUtil {
+139 -41
View File
@@ -5,51 +5,149 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.tt.activity.JMainActivity">
tools:context=".activity.main.MainActivity">
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
app:layout_constraintEnd_toEndOf="@+id/textView"
app:layout_constraintStart_toStartOf="@+id/textView"
app:layout_constraintTop_toBottomOf="@+id/textView" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.ttstd.viewlibrary.ToggleButton2
android:id="@+id/disable_switch"
android:layout_width="80dp"
android:layout_height="40dp"
android:layout_marginTop="60dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical">
<com.ttstd.viewlibrary.ToggleButton
android:id="@+id/toggleButton"
android:layout_width="80dp"
android:layout_height="40dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/disable_switch" />
<com.ttstd.viewlibrary.ToggleButton2
android:id="@+id/disable_switch"
android:layout_width="80dp"
android:layout_height="40dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<com.suke.widget.SwitchButton
android:id="@+id/switch_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/toggleButton" />
<com.ttstd.viewlibrary.ToggleButton
android:id="@+id/toggleButton"
android:layout_width="80dp"
android:layout_height="40dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/disable_switch" />
<com.suke.widget.SwitchButton
android:id="@+id/switch_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/toggleButton" />
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.311" />
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
app:layout_constraintEnd_toEndOf="@+id/textView"
app:layout_constraintStart_toStartOf="@+id/textView"
app:layout_constraintTop_toBottomOf="@+id/textView" />
<Button
android:id="@+id/none"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="none"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/adb"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="adb"
app:layout_constraintStart_toEndOf="@+id/none" />
<Button
android:id="@+id/rndis"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="rndis"
app:layout_constraintStart_toEndOf="@+id/adb" />
<Button
android:id="@+id/mtp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="mtp"
app:layout_constraintStart_toEndOf="@+id/rndis" />
<Button
android:id="@+id/ptp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ptp"
app:layout_constraintTop_toBottomOf="@+id/none" />
<Button
android:id="@+id/audio_source"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="audio_source"
app:layout_constraintStart_toEndOf="@+id/ptp"
app:layout_constraintTop_toBottomOf="@+id/none" />
<Button
android:id="@+id/midi"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="midi"
app:layout_constraintStart_toEndOf="@+id/audio_source"
app:layout_constraintTop_toTopOf="@+id/audio_source" />
<Button
android:id="@+id/accessory"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="accessory"
app:layout_constraintTop_toBottomOf="@+id/ptp"
tools:layout_editor_absoluteX="0dp" />
<Button
android:id="@+id/icon_off"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="icon_off"
app:layout_constraintStart_toEndOf="@+id/accessory"
app:layout_constraintTop_toTopOf="@+id/accessory" />
<Button
android:id="@+id/icon_on"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="icon_on"
app:layout_constraintStart_toEndOf="@+id/icon_off"
app:layout_constraintTop_toTopOf="@+id/accessory" />
<Button
android:id="@+id/icon_look"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="icon_on"
app:layout_constraintStart_toEndOf="@+id/icon_on"
app:layout_constraintTop_toTopOf="@+id/accessory" />
</LinearLayout>
</ScrollView>
</androidx.constraintlayout.widget.ConstraintLayout>
+139 -41
View File
@@ -5,51 +5,149 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.tt.activity.JMainActivity">
tools:context=".activity.main.MainActivity">
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
app:layout_constraintEnd_toEndOf="@+id/textView"
app:layout_constraintStart_toStartOf="@+id/textView"
app:layout_constraintTop_toBottomOf="@+id/textView" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.ttstd.viewlibrary.ToggleButton2
android:id="@+id/disable_switch"
android:layout_width="80dp"
android:layout_height="40dp"
android:layout_marginTop="60dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical">
<com.ttstd.viewlibrary.ToggleButton
android:id="@+id/toggleButton"
android:layout_width="80dp"
android:layout_height="40dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/disable_switch" />
<com.ttstd.viewlibrary.ToggleButton2
android:id="@+id/disable_switch"
android:layout_width="80dp"
android:layout_height="40dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<com.suke.widget.SwitchButton
android:id="@+id/switch_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/toggleButton" />
<com.ttstd.viewlibrary.ToggleButton
android:id="@+id/toggleButton"
android:layout_width="80dp"
android:layout_height="40dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/disable_switch" />
<com.suke.widget.SwitchButton
android:id="@+id/switch_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/toggleButton" />
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.311" />
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
app:layout_constraintEnd_toEndOf="@+id/textView"
app:layout_constraintStart_toStartOf="@+id/textView"
app:layout_constraintTop_toBottomOf="@+id/textView" />
<Button
android:id="@+id/none"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="none"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/adb"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="adb"
app:layout_constraintStart_toEndOf="@+id/none" />
<Button
android:id="@+id/rndis"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="rndis"
app:layout_constraintStart_toEndOf="@+id/adb" />
<Button
android:id="@+id/mtp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="mtp"
app:layout_constraintStart_toEndOf="@+id/rndis" />
<Button
android:id="@+id/ptp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ptp"
app:layout_constraintTop_toBottomOf="@+id/none" />
<Button
android:id="@+id/audio_source"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="audio_source"
app:layout_constraintStart_toEndOf="@+id/ptp"
app:layout_constraintTop_toBottomOf="@+id/none" />
<Button
android:id="@+id/midi"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="midi"
app:layout_constraintStart_toEndOf="@+id/audio_source"
app:layout_constraintTop_toTopOf="@+id/audio_source" />
<Button
android:id="@+id/accessory"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="accessory"
app:layout_constraintTop_toBottomOf="@+id/ptp"
tools:layout_editor_absoluteX="0dp" />
<Button
android:id="@+id/icon_off"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="icon_off"
app:layout_constraintStart_toEndOf="@+id/accessory"
app:layout_constraintTop_toTopOf="@+id/accessory" />
<Button
android:id="@+id/icon_on"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="icon_on"
app:layout_constraintStart_toEndOf="@+id/icon_off"
app:layout_constraintTop_toTopOf="@+id/accessory" />
<Button
android:id="@+id/icon_look"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="icon_on"
app:layout_constraintStart_toEndOf="@+id/icon_on"
app:layout_constraintTop_toTopOf="@+id/accessory" />
</LinearLayout>
</ScrollView>
</androidx.constraintlayout.widget.ConstraintLayout>
+1 -1
View File
@@ -4,6 +4,6 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.tt.activity.PackageActivity">
tools:context=".activity.PackageActivity">
</androidx.constraintlayout.widget.ConstraintLayout>
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".activity.retrofit.RetrofitActivity">
</androidx.constraintlayout.widget.ConstraintLayout>
+14
View File
@@ -0,0 +1,14 @@
{
"tpns": {
"access_id": "1500026407",
"access_key": "AQ6C6W1O19LT"
},
"com.tt.ttutils": {
"channel": {
"enable": true
}
},
"debug": false,
"version": "1.2.7.1-release",
"upgrade": true
}