更细增加两个生命周期管理的方法,增加tpush
This commit is contained in:
@@ -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
|
||||
*/
|
||||
|
||||
}
|
||||
129
app/src/main/java/com/tt/ttutils/base/BaseActivity.java
Normal file
129
app/src/main/java/com/tt/ttutils/base/BaseActivity.java
Normal file
@@ -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() {
|
||||
114
app/src/main/java/com/tt/ttutils/base/BaseFragment.java
Normal file
114
app/src/main/java/com/tt/ttutils/base/BaseFragment.java
Normal file
@@ -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
|
||||
24
app/src/main/java/com/tt/ttutils/bean/BaseResponse.java
Normal file
24
app/src/main/java/com/tt/ttutils/bean/BaseResponse.java
Normal file
@@ -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();
|
||||
}
|
||||
}
|
||||
36
app/src/main/java/com/tt/ttutils/db/LogDBHelper.java
Normal file
36
app/src/main/java/com/tt/ttutils/db/LogDBHelper.java
Normal file
@@ -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) {
|
||||
|
||||
}
|
||||
}
|
||||
23
app/src/main/java/com/tt/ttutils/db/OpenHelper.java
Normal file
23
app/src/main/java/com/tt/ttutils/db/OpenHelper.java
Normal file
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
7
app/src/main/java/com/tt/ttutils/network/UrlAddress.java
Normal file
7
app/src/main/java/com/tt/ttutils/network/UrlAddress.java
Normal file
@@ -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);
|
||||
223
app/src/main/java/com/tt/ttutils/server/main/MainSPresenter.java
Normal file
223
app/src/main/java/com/tt/ttutils/server/main/MainSPresenter.java
Normal file
@@ -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;
|
||||
}
|
||||
17
app/src/main/java/com/tt/ttutils/tpush/Constants.java
Normal file
17
app/src/main/java/com/tt/ttutils/tpush/Constants.java
Normal file
@@ -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";
|
||||
}
|
||||
275
app/src/main/java/com/tt/ttutils/tpush/MessageReceiver.java
Normal file
275
app/src/main/java/com/tt/ttutils/tpush/MessageReceiver.java
Normal file
@@ -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;
|
||||
}
|
||||
}
|
||||
72
app/src/main/java/com/tt/ttutils/utils/java/ApkUtils.java
Normal file
72
app/src/main/java/com/tt/ttutils/utils/java/ApkUtils.java
Normal file
@@ -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;
|
||||
112
app/src/main/java/com/tt/ttutils/utils/java/MD5Util.java
Normal file
112
app/src/main/java/com/tt/ttutils/utils/java/MD5Util.java
Normal file
@@ -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 {
|
||||
6
app/src/main/java/com/tt/ttutils/utils/kt/ApkUtils.kt
Normal file
6
app/src/main/java/com/tt/ttutils/utils/kt/ApkUtils.kt
Normal file
@@ -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 {
|
||||
Reference in New Issue
Block a user