first commit
|
|
@ -0,0 +1,15 @@
|
|||
*.iml
|
||||
.gradle
|
||||
/local.properties
|
||||
/.idea/caches
|
||||
/.idea/libraries
|
||||
/.idea/modules.xml
|
||||
/.idea/workspace.xml
|
||||
/.idea/navEditor.xml
|
||||
/.idea/assetWizardSettings.xml
|
||||
.DS_Store
|
||||
/build
|
||||
/captures
|
||||
.externalNativeBuild
|
||||
.cxx
|
||||
local.properties
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="CompilerConfiguration">
|
||||
<bytecodeTargetLevel target="1.8" />
|
||||
</component>
|
||||
</project>
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="GradleMigrationSettings" migrationVersion="1" />
|
||||
<component name="GradleSettings">
|
||||
<option name="linkedExternalProjectsSettings">
|
||||
<GradleProjectSettings>
|
||||
<option name="testRunner" value="PLATFORM" />
|
||||
<option name="distributionType" value="DEFAULT_WRAPPED" />
|
||||
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
||||
<option name="gradleHome" value="$PROJECT_DIR$/../../gradle" />
|
||||
<option name="gradleJvm" value="1.8 (2)" />
|
||||
<option name="modules">
|
||||
<set>
|
||||
<option value="$PROJECT_DIR$" />
|
||||
<option value="$PROJECT_DIR$/app" />
|
||||
<option value="$PROJECT_DIR$/libs" />
|
||||
</set>
|
||||
</option>
|
||||
<option name="resolveModulePerSourceSet" value="false" />
|
||||
<option name="useQualifiedModuleNames" value="true" />
|
||||
</GradleProjectSettings>
|
||||
</option>
|
||||
</component>
|
||||
</project>
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
<component name="InspectionProjectProfileManager">
|
||||
<profile version="1.0">
|
||||
<option name="myName" value="Project Default" />
|
||||
<inspection_tool class="JavaDoc" enabled="true" level="WARNING" enabled_by_default="true">
|
||||
<option name="TOP_LEVEL_CLASS_OPTIONS">
|
||||
<value>
|
||||
<option name="ACCESS_JAVADOC_REQUIRED_FOR" value="none" />
|
||||
<option name="REQUIRED_TAGS" value="" />
|
||||
</value>
|
||||
</option>
|
||||
<option name="INNER_CLASS_OPTIONS">
|
||||
<value>
|
||||
<option name="ACCESS_JAVADOC_REQUIRED_FOR" value="none" />
|
||||
<option name="REQUIRED_TAGS" value="" />
|
||||
</value>
|
||||
</option>
|
||||
<option name="METHOD_OPTIONS">
|
||||
<value>
|
||||
<option name="ACCESS_JAVADOC_REQUIRED_FOR" value="none" />
|
||||
<option name="REQUIRED_TAGS" value="@return@param@throws or @exception" />
|
||||
</value>
|
||||
</option>
|
||||
<option name="FIELD_OPTIONS">
|
||||
<value>
|
||||
<option name="ACCESS_JAVADOC_REQUIRED_FOR" value="none" />
|
||||
<option name="REQUIRED_TAGS" value="" />
|
||||
</value>
|
||||
</option>
|
||||
<option name="IGNORE_DEPRECATED" value="false" />
|
||||
<option name="IGNORE_JAVADOC_PERIOD" value="true" />
|
||||
<option name="IGNORE_DUPLICATED_THROWS" value="false" />
|
||||
<option name="IGNORE_POINT_TO_ITSELF" value="false" />
|
||||
<option name="myAdditionalJavadocTags" value="date" />
|
||||
</inspection_tool>
|
||||
</profile>
|
||||
</component>
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="RemoteRepositoriesConfiguration">
|
||||
<remote-repository>
|
||||
<option name="id" value="central" />
|
||||
<option name="name" value="Maven Central repository" />
|
||||
<option name="url" value="https://repo1.maven.org/maven2" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="jboss.community" />
|
||||
<option name="name" value="JBoss Community repository" />
|
||||
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="BintrayJCenter" />
|
||||
<option name="name" value="BintrayJCenter" />
|
||||
<option name="url" value="https://jcenter.bintray.com/" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="Google" />
|
||||
<option name="name" value="Google" />
|
||||
<option name="url" value="https://dl.google.com/dl/android/maven2/" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="maven" />
|
||||
<option name="name" value="maven" />
|
||||
<option name="url" value="https://jitpack.io" />
|
||||
</remote-repository>
|
||||
</component>
|
||||
</project>
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/build/classes" />
|
||||
</component>
|
||||
<component name="ProjectType">
|
||||
<option name="id" value="Android" />
|
||||
</component>
|
||||
</project>
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
|
|
@ -0,0 +1 @@
|
|||
/build
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
plugins {
|
||||
id 'com.android.application'
|
||||
}
|
||||
|
||||
android {
|
||||
compileSdkVersion 28
|
||||
buildToolsVersion "29.0.2"
|
||||
|
||||
defaultConfig {
|
||||
applicationId "com.skipping"
|
||||
minSdkVersion 21
|
||||
targetSdkVersion 28
|
||||
versionCode 1
|
||||
versionName "1.0"
|
||||
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
release {
|
||||
minifyEnabled false
|
||||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
||||
}
|
||||
}
|
||||
compileOptions {
|
||||
sourceCompatibility JavaVersion.VERSION_1_8
|
||||
targetCompatibility JavaVersion.VERSION_1_8
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation fileTree(dir: 'libs', include: ['*.jar', '*.aar'])
|
||||
implementation 'androidx.appcompat:appcompat:1.2.0'
|
||||
implementation 'com.google.android.material:material:1.3.0'
|
||||
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
|
||||
implementation project(path: ':libs')
|
||||
testImplementation 'junit:junit:4.+'
|
||||
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
|
||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
|
||||
implementation 'com.github.felHR85:UsbSerial:6.1.0'
|
||||
}
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
# Add project specific ProGuard rules here.
|
||||
# You can control the set of applied configuration files using the
|
||||
# proguardFiles setting in build.gradle.
|
||||
#
|
||||
# For more details, see
|
||||
# http://developer.android.com/guide/developing/tools/proguard.html
|
||||
|
||||
# If your project uses WebView with JS, uncomment the following
|
||||
# and specify the fully qualified class name to the JavaScript interface
|
||||
# class:
|
||||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
|
||||
# public *;
|
||||
#}
|
||||
|
||||
# Uncomment this to preserve the line number information for
|
||||
# debugging stack traces.
|
||||
#-keepattributes SourceFile,LineNumberTable
|
||||
|
||||
# If you keep the line number information, uncomment this to
|
||||
# hide the original source file name.
|
||||
#-renamesourcefileattribute SourceFile
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
package com.skipping;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.test.platform.app.InstrumentationRegistry;
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Instrumented test, which will execute on an Android device.
|
||||
*
|
||||
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
|
||||
*/
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class ExampleInstrumentedTest {
|
||||
@Test
|
||||
public void useAppContext() {
|
||||
// Context of the app under test.
|
||||
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
|
||||
assertEquals("com.skipping", appContext.getPackageName());
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.skipping">
|
||||
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-feature
|
||||
android:name="android.hardware.usb.host"
|
||||
android:required="true" />
|
||||
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
android:name=".APP"
|
||||
android:roundIcon="@mipmap/ic_launcher_round"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/Theme.Skipping">
|
||||
<activity android:name=".activity.MainActivity">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity android:name=".activity.MainActivity2"
|
||||
android:exported="true"/>
|
||||
<activity android:name=".activity.HostActivity" />
|
||||
<activity android:name=".activity.NetActivity" />
|
||||
|
||||
<service
|
||||
android:name="com.loop.loopminisdk.LoopMini"
|
||||
android:enabled="true">
|
||||
</service>
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
package com.skipping;
|
||||
|
||||
|
||||
|
||||
import com.libs.fragment.BaseApplication;
|
||||
|
||||
/**
|
||||
* @author Ming
|
||||
* 3/14/22
|
||||
*/
|
||||
public class APP extends BaseApplication {
|
||||
}
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
package com.skipping;
|
||||
|
||||
/**
|
||||
* @author Ming
|
||||
* 3/14/22
|
||||
*/
|
||||
public class Contants {
|
||||
|
||||
/**
|
||||
* url路径
|
||||
*/
|
||||
public final static String BASE_URL = "https://api.xintijiao.com/ijustjump/";
|
||||
|
||||
|
||||
public final static String CLASS = "class";
|
||||
|
||||
public final static String GRADE = "grade";
|
||||
|
||||
public final static String UNFINISHED = "未完成";
|
||||
}
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
package com.skipping;
|
||||
|
||||
import com.libs.fragment.BaseApplication;
|
||||
|
||||
/**
|
||||
* @author Ming
|
||||
* 3/14/22
|
||||
*/
|
||||
public class MainPresenter extends BaseApplication {
|
||||
}
|
||||
|
|
@ -0,0 +1,269 @@
|
|||
package com.skipping.activity;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.ServiceConnection;
|
||||
import android.os.Handler;
|
||||
import android.os.IBinder;
|
||||
import android.os.Message;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
|
||||
import com.libs.fragment.BaseActivity;
|
||||
import com.libs.utils.LogUtil;
|
||||
import com.libs.utils.ToastUtil;
|
||||
import com.loop.loopminisdk.LoopDevice;
|
||||
import com.loop.loopminisdk.LoopHost;
|
||||
import com.loop.loopminisdk.LoopMessage;
|
||||
import com.loop.loopminisdk.LoopMini;
|
||||
import com.skipping.R;
|
||||
import com.skipping.utils.ThreadPoolUtil;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author Ming
|
||||
* 3/15/22
|
||||
*/
|
||||
public class HostActivity extends BaseActivity {
|
||||
private LoopMini loopMax;
|
||||
private Set<LoopDevice> loopDeviceSet = new HashSet<>();
|
||||
private LoopDevice loopDevice;
|
||||
private EditText editText;
|
||||
private LoopHost loopHost;
|
||||
private MyHandler mHandler;
|
||||
private int position;
|
||||
private ScheduledFuture scheduledFuture;
|
||||
private Button btn, btn2, btn3, btn4, btn5;
|
||||
private final BroadcastReceiver mUsbReceiver = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
switch (intent.getAction()) {
|
||||
case LoopMini.ACTION_USB_PERMISSION_GRANTED:
|
||||
ToastUtil.longToast("确认设备权限");
|
||||
break;
|
||||
case LoopMini.ACTION_USB_PERMISSION_NOT_GRANTED:
|
||||
ToastUtil.longToast("取消设备权限");
|
||||
break;
|
||||
case LoopMini.ACTION_NO_USB:
|
||||
ToastUtil.longToast("没有插入设备");
|
||||
break;
|
||||
case LoopMini.ACTION_USB_DISCONNECTED:
|
||||
ToastUtil.longToast("拔出设备");
|
||||
break;
|
||||
case LoopMini.ACTION_USB_NOT_SUPPORTED:
|
||||
ToastUtil.longToast("设备无法识别");
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
private final ServiceConnection usbConnection = new ServiceConnection() {
|
||||
@Override
|
||||
public void onServiceConnected(ComponentName arg0, IBinder arg1) {
|
||||
loopMax = ((LoopMini.UsbBinder) arg1).getService();
|
||||
loopMax.setHandler(mHandler);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onServiceDisconnected(ComponentName arg0) {
|
||||
loopMax = null;
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
protected int getContentViewResId() {
|
||||
return R.layout.activity_host;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initView() {
|
||||
btn = findViewById(R.id.btn);
|
||||
btn2 = findViewById(R.id.btn2);
|
||||
btn3 = findViewById(R.id.btn3);
|
||||
btn4 = findViewById(R.id.btn4);
|
||||
btn5 = findViewById(R.id.btn5);
|
||||
editText = findViewById(R.id.edittext);
|
||||
btn.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
getHostInfo();
|
||||
openPairMode();
|
||||
}
|
||||
});
|
||||
btn2.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
pairDevice(Integer.valueOf(editText.getText().toString()));
|
||||
}
|
||||
});
|
||||
btn3.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
LogUtil.e("设备数据", loopDeviceSet);
|
||||
}
|
||||
});
|
||||
btn4.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
closePairMode();
|
||||
connectDevice();
|
||||
}
|
||||
});
|
||||
btn5.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
closePairMode();
|
||||
disconnectDevice();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initData() {
|
||||
mHandler = new MyHandler();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 连接主机
|
||||
*/
|
||||
private void getHostInfo() {
|
||||
loopMax.getHostInfo();
|
||||
}
|
||||
|
||||
/**
|
||||
* 开启配对模式
|
||||
*/
|
||||
private void openPairMode() {
|
||||
loopMax.openPairMode();
|
||||
}
|
||||
|
||||
/**
|
||||
* 关闭配对模式
|
||||
*/
|
||||
private void closePairMode() {
|
||||
loopMax.closePairMode();
|
||||
}
|
||||
|
||||
/**
|
||||
* 匹配设备到指定id
|
||||
*
|
||||
* @param id
|
||||
*/
|
||||
private void pairDevice(int id) {
|
||||
loopMax.pairDevice(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 连接设备
|
||||
*/
|
||||
private void connectDevice() {
|
||||
connectDeviceInner(loopDevice -> loopMax.connectDevice(loopDevice));
|
||||
}
|
||||
|
||||
private void disconnectDevice() {
|
||||
connectDeviceInner(loopDevice -> loopMax.disconnectDevice(loopDevice));
|
||||
}
|
||||
|
||||
|
||||
private void connectDeviceInner(ConnectInterface connectInterface) {
|
||||
if (loopDeviceSet.size() == 0) {
|
||||
return;
|
||||
}
|
||||
if (scheduledFuture != null) {
|
||||
scheduledFuture.cancel(false);
|
||||
}
|
||||
List<LoopDevice> deviceList = loopDeviceSet.stream().collect(Collectors.toList());
|
||||
position = 0;
|
||||
scheduledFuture = ThreadPoolUtil.getSingleton().scheduleAtFixedRate(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (position > deviceList.size()) {
|
||||
scheduledFuture.cancel(false);
|
||||
}
|
||||
connectInterface.connect(deviceList.get(position));
|
||||
position++;
|
||||
}
|
||||
}, 0, 10);
|
||||
}
|
||||
|
||||
public interface ConnectInterface {
|
||||
void connect(LoopDevice loopDevice);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
setFilters();
|
||||
startService(usbConnection);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
unregisterReceiver(mUsbReceiver);
|
||||
unbindService(usbConnection);
|
||||
}
|
||||
|
||||
private void startService(ServiceConnection serviceConnection) {
|
||||
if (!LoopMini.SERVICE_CONNECTED) {
|
||||
Intent startService = new Intent(this, LoopMini.class);
|
||||
startService(startService);
|
||||
}
|
||||
Intent bindingIntent = new Intent(this, LoopMini.class);
|
||||
bindService(bindingIntent, serviceConnection, Context.BIND_AUTO_CREATE);
|
||||
}
|
||||
|
||||
private void setFilters() {
|
||||
IntentFilter filter = new IntentFilter();
|
||||
filter.addAction(LoopMini.ACTION_USB_PERMISSION_GRANTED);
|
||||
filter.addAction(LoopMini.ACTION_NO_USB);
|
||||
filter.addAction(LoopMini.ACTION_USB_DISCONNECTED);
|
||||
filter.addAction(LoopMini.ACTION_USB_NOT_SUPPORTED);
|
||||
filter.addAction(LoopMini.ACTION_USB_PERMISSION_NOT_GRANTED);
|
||||
registerReceiver(mUsbReceiver, filter);
|
||||
}
|
||||
|
||||
|
||||
private class MyHandler extends Handler {
|
||||
@Override
|
||||
public void handleMessage(Message msg) {
|
||||
super.handleMessage(msg);
|
||||
switch (msg.what) {
|
||||
case LoopMini.LOOP_PAIR_DEVICE_INFO:
|
||||
loopDevice = (LoopDevice) msg.obj;
|
||||
addDevice(loopDevice);
|
||||
LogUtil.e("连接LoopDevice", loopDevice.toString());
|
||||
break;
|
||||
case LoopMini.Loop_GET_HOST_INFO:
|
||||
loopHost = (LoopHost) msg.obj;
|
||||
LogUtil.e("LoopHost", loopHost.toString());
|
||||
break;
|
||||
case LoopMini.LOOP_GET_DEVICE_INFO:
|
||||
loopDevice = (LoopDevice) msg.obj;
|
||||
addDevice(loopDevice);
|
||||
LogUtil.e("获取LoopDevice", loopDevice.toString());
|
||||
break;
|
||||
case LoopMini.LOOP_MESSAGE:
|
||||
LoopMessage loopMessage = (LoopMessage) msg.obj;
|
||||
LogUtil.e("LoopMessage", loopMessage.toString());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void addDevice(LoopDevice loopDevice) {
|
||||
loopDeviceSet.add(loopDevice);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,70 @@
|
|||
package com.skipping.activity;
|
||||
|
||||
|
||||
import android.content.Intent;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
|
||||
import com.libs.fragment.BaseActivity;
|
||||
import com.libs.network.CallBack;
|
||||
import com.libs.network.Concise;
|
||||
import com.skipping.Contants;
|
||||
import com.skipping.R;
|
||||
import com.skipping.net.API;
|
||||
import com.skipping.net.BaseBean;
|
||||
import com.skipping.net.TokenBean;
|
||||
import com.skipping.net.TokenReqBean;
|
||||
|
||||
public class MainActivity extends BaseActivity {
|
||||
private Concise<API> concise;
|
||||
private Button btn, btn2;
|
||||
|
||||
@Override
|
||||
protected int getContentViewResId() {
|
||||
return R.layout.activity_main;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initView() {
|
||||
btn = findViewById(R.id.btn);
|
||||
btn2 = findViewById(R.id.btn2);
|
||||
btn.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Intent intent = new Intent(MainActivity.this, HostActivity.class);
|
||||
startActivity(intent);
|
||||
}
|
||||
});
|
||||
btn2.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Intent intent = new Intent(MainActivity.this, NetActivity.class);
|
||||
startActivity(intent);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initData() {
|
||||
concise = new Concise<API>(Contants.BASE_URL) {
|
||||
}
|
||||
.build();
|
||||
}
|
||||
|
||||
|
||||
private void login() {
|
||||
TokenReqBean tokenReqBean = new TokenReqBean();
|
||||
concise.request(this, concise.api.token(tokenReqBean), new CallBack<BaseBean<TokenBean>>() {
|
||||
@Override
|
||||
public void onSuccess(BaseBean<TokenBean> tokenBeanBaseBean) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailed(Throwable e) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,163 @@
|
|||
package com.skipping.activity;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.ServiceConnection;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.IBinder;
|
||||
import android.os.Message;
|
||||
import android.util.Log;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import com.loop.loopminisdk.LoopDevice;
|
||||
import com.loop.loopminisdk.LoopHost;
|
||||
import com.loop.loopminisdk.LoopMessage;
|
||||
import com.loop.loopminisdk.LoopMini;
|
||||
import com.skipping.R;
|
||||
|
||||
/**
|
||||
* @author Ming
|
||||
* 3/14/22
|
||||
*/
|
||||
public class MainActivity2 extends AppCompatActivity {
|
||||
private LoopMini loopMax;
|
||||
private LoopDevice loopDevice;
|
||||
private EditText editText;
|
||||
private LoopHost loopHost;
|
||||
private final BroadcastReceiver mUsbReceiver = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
switch (intent.getAction()) {
|
||||
case LoopMini.ACTION_USB_PERMISSION_GRANTED: // USB PERMISSION GRANTED
|
||||
Toast.makeText(context, "USB Ready", Toast.LENGTH_SHORT).show();
|
||||
break;
|
||||
case LoopMini.ACTION_USB_PERMISSION_NOT_GRANTED: // USB PERMISSION NOT GRANTED
|
||||
Toast.makeText(context, "USB Permission not granted", Toast.LENGTH_SHORT).show();
|
||||
break;
|
||||
case LoopMini.ACTION_NO_USB: // NO USB CONNECTED
|
||||
Toast.makeText(context, "No USB connected", Toast.LENGTH_SHORT).show();
|
||||
break;
|
||||
case LoopMini.ACTION_USB_DISCONNECTED: // USB DISCONNECTED
|
||||
Toast.makeText(context, "USB disconnected", Toast.LENGTH_SHORT).show();
|
||||
break;
|
||||
case LoopMini.ACTION_USB_NOT_SUPPORTED: // USB NOT SUPPORTED
|
||||
Toast.makeText(context, "USB device not supported", Toast.LENGTH_SHORT).show();
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
private MyHandler mHandler;
|
||||
private final ServiceConnection usbConnection = new ServiceConnection() {
|
||||
@Override
|
||||
public void onServiceConnected(ComponentName arg0, IBinder arg1) {
|
||||
loopMax = ((LoopMini.UsbBinder) arg1).getService();
|
||||
loopMax.setHandler(mHandler);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onServiceDisconnected(ComponentName arg0) {
|
||||
loopMax = null;
|
||||
}
|
||||
};
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_main2);
|
||||
mHandler = new MyHandler();
|
||||
editText = findViewById(R.id.edittext);
|
||||
Button button1 = findViewById(R.id.button);
|
||||
Button button2 = findViewById(R.id.button2);
|
||||
Button button3 = findViewById(R.id.button3);
|
||||
Button button4 = findViewById(R.id.button4);
|
||||
Button button5 = findViewById(R.id.button5);
|
||||
Button button6 = findViewById(R.id.button6);
|
||||
Button button7 = findViewById(R.id.button7);
|
||||
Button button8 = findViewById(R.id.button8);
|
||||
Button button9 = findViewById(R.id.button9);
|
||||
Button button10 = findViewById(R.id.button10);
|
||||
button1.setOnClickListener(v -> loopMax.getHostInfo());
|
||||
button2.setOnClickListener(v -> loopMax.openPairMode());
|
||||
button3.setOnClickListener(v -> loopMax.closePairMode());
|
||||
button4.setOnClickListener(v -> loopMax.pairDevice(Integer.valueOf(editText.getText().toString())));
|
||||
button5.setOnClickListener(v -> {
|
||||
if (loopDevice != null) {
|
||||
loopMax.connectDevice(loopDevice);
|
||||
}
|
||||
});
|
||||
button6.setOnClickListener(v -> {
|
||||
if (loopDevice != null) {
|
||||
loopMax.disconnectDevice(loopDevice);
|
||||
}
|
||||
});
|
||||
button7.setOnClickListener(v -> loopMax.getPower());
|
||||
button8.setOnClickListener(v -> loopMax.getCount());
|
||||
button9.setOnClickListener(v -> loopMax.startJumpLimitTime(30));
|
||||
button10.setOnClickListener(v -> loopMax.stopJump());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
setFilters(); // Start listening notifications from UsbService
|
||||
startService(usbConnection); // Start UsbService(if it was not started before) and Bind it
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
unregisterReceiver(mUsbReceiver);
|
||||
unbindService(usbConnection);
|
||||
}
|
||||
|
||||
private void startService(ServiceConnection serviceConnection) {
|
||||
if (!LoopMini.SERVICE_CONNECTED) {
|
||||
Intent startService = new Intent(this, LoopMini.class);
|
||||
startService(startService);
|
||||
}
|
||||
Intent bindingIntent = new Intent(this, LoopMini.class);
|
||||
bindService(bindingIntent, serviceConnection, Context.BIND_AUTO_CREATE);
|
||||
}
|
||||
|
||||
private void setFilters() {
|
||||
IntentFilter filter = new IntentFilter();
|
||||
filter.addAction(LoopMini.ACTION_USB_PERMISSION_GRANTED);
|
||||
filter.addAction(LoopMini.ACTION_NO_USB);
|
||||
filter.addAction(LoopMini.ACTION_USB_DISCONNECTED);
|
||||
filter.addAction(LoopMini.ACTION_USB_NOT_SUPPORTED);
|
||||
filter.addAction(LoopMini.ACTION_USB_PERMISSION_NOT_GRANTED);
|
||||
registerReceiver(mUsbReceiver, filter);
|
||||
}
|
||||
|
||||
private class MyHandler extends Handler {
|
||||
@Override
|
||||
public void handleMessage(Message msg) {
|
||||
super.handleMessage(msg);
|
||||
switch (msg.what) {
|
||||
case LoopMini.LOOP_PAIR_DEVICE_INFO:
|
||||
loopDevice = (LoopDevice) msg.obj;
|
||||
Log.d("LoopDevice", loopDevice.toString());
|
||||
break;
|
||||
case LoopMini.Loop_GET_HOST_INFO:
|
||||
loopHost = (LoopHost) msg.obj;
|
||||
Log.d("LoopHost", loopHost.toString());
|
||||
break;
|
||||
case LoopMini.LOOP_GET_DEVICE_INFO:
|
||||
LoopDevice loopDevice = (LoopDevice) msg.obj;
|
||||
Log.d("LoopDevice", loopDevice.toString());
|
||||
break;
|
||||
case LoopMini.LOOP_MESSAGE:
|
||||
LoopMessage loopMessage = (LoopMessage) msg.obj;
|
||||
Log.d("LoopMessage", loopMessage.toString());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,215 @@
|
|||
package com.skipping.activity;
|
||||
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
|
||||
import com.libs.fragment.BaseActivity;
|
||||
import com.libs.network.CallBack;
|
||||
import com.libs.network.Concise;
|
||||
import com.libs.utils.LogUtil;
|
||||
import com.skipping.Contants;
|
||||
import com.skipping.R;
|
||||
import com.skipping.net.API;
|
||||
import com.skipping.net.ActivityBean;
|
||||
import com.skipping.net.ActivityReqBean;
|
||||
import com.skipping.net.AddActivityBean;
|
||||
import com.skipping.net.AddActivityReqBean;
|
||||
import com.skipping.net.BaseBean;
|
||||
import com.skipping.net.DetailActivityBean;
|
||||
import com.skipping.net.GradleBean;
|
||||
import com.skipping.net.ScoreReqBean;
|
||||
import com.skipping.net.TokenBean;
|
||||
import com.skipping.net.TokenReqBean;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Ming
|
||||
* 3/15/22
|
||||
*/
|
||||
public class NetActivity extends BaseActivity {
|
||||
private Button btn, btn2, btn3, btn4, btn5, btn6, btn7;
|
||||
private Concise<API> tokenConcise = new Concise<API>(Contants.BASE_URL) {
|
||||
}.build();
|
||||
private Concise<API> concise;
|
||||
|
||||
@Override
|
||||
protected int getContentViewResId() {
|
||||
return R.layout.activity_net;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initView() {
|
||||
btn = findViewById(R.id.btn);
|
||||
btn2 = findViewById(R.id.btn2);
|
||||
btn3 = findViewById(R.id.btn3);
|
||||
btn4 = findViewById(R.id.btn4);
|
||||
btn5 = findViewById(R.id.btn5);
|
||||
btn6 = findViewById(R.id.btn6);
|
||||
btn7 = findViewById(R.id.btn7);
|
||||
|
||||
btn.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
TokenReqBean tokenReqBean = new TokenReqBean();
|
||||
tokenReqBean.setDeviceID("466e9c");
|
||||
tokenReqBean.setLogName("loop");
|
||||
tokenReqBean.setLogPwd("123456");
|
||||
tokenConcise.request(NetActivity.this, tokenConcise.api.token(tokenReqBean), new CallBack<BaseBean<TokenBean>>() {
|
||||
@Override
|
||||
public void onSuccess(BaseBean<TokenBean> tokenBeanBaseBean) {
|
||||
concise = new Concise<API>(Contants.BASE_URL) {
|
||||
}.addHeader("Token", tokenBeanBaseBean.getData().getToken()).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailed(Throwable e) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
btn2.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
concise.request(NetActivity.this, concise.api.getGrade(), new CallBack<BaseBean<List<GradleBean>>>() {
|
||||
@Override
|
||||
public void onSuccess(BaseBean<List<GradleBean>> listBaseBean) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailed(Throwable e) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
btn3.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
concise.request(NetActivity.this, concise.api.getClass("6b76e9770a4eafbcee213121d4ad6b"), new CallBack<BaseBean<List<GradleBean>>>() {
|
||||
@Override
|
||||
public void onSuccess(BaseBean<List<GradleBean>> listBaseBean) {
|
||||
LogUtil.e("数据",listBaseBean.getData());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailed(Throwable e) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
btn4.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
ActivityReqBean bean = new ActivityReqBean();
|
||||
bean.setGenre(Contants.CLASS);
|
||||
bean.setActivityType("timing");
|
||||
bean.setGroupID("77bba9124a4281bc9f92f965561cd5");
|
||||
bean.setIndex(1);
|
||||
bean.setPageSize(10);
|
||||
bean.setStatus(Contants.UNFINISHED);
|
||||
concise.request(NetActivity.this, concise.api.getActivityList(bean), new CallBack<BaseBean<List<ActivityBean>>>() {
|
||||
@Override
|
||||
public void onSuccess(BaseBean<List<ActivityBean>> listBaseBean) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailed(Throwable e) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
btn5.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
AddActivityReqBean bean = new AddActivityReqBean();
|
||||
bean.setName("test001");
|
||||
bean.setActivityType("timing");
|
||||
bean.setValue(60);
|
||||
bean.setGroupID("77bba9124a4281bc9f92f965561cd5");
|
||||
bean.setPersonNumber(6);
|
||||
bean.setStep(2);
|
||||
concise.request(NetActivity.this, concise.api.addActivity(bean), new CallBack<BaseBean<List<AddActivityBean>>>() {
|
||||
@Override
|
||||
public void onSuccess(BaseBean<List<AddActivityBean>> listBaseBean) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailed(Throwable e) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
btn6.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
concise.request(NetActivity.this, concise.api.detailActivity("15"), new CallBack<BaseBean<List<DetailActivityBean>>>() {
|
||||
@Override
|
||||
public void onSuccess(BaseBean<List<DetailActivityBean>> listBaseBean) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailed(Throwable e) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
btn7.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
ScoreReqBean bean = new ScoreReqBean();
|
||||
bean.setId(15);
|
||||
bean.setStep(2);
|
||||
List<ScoreReqBean.CandidatesBean> candidatesBeanList = new ArrayList<>();
|
||||
ScoreReqBean.CandidatesBean candidatesBean = new ScoreReqBean.CandidatesBean();
|
||||
candidatesBean.setComplateTime(1646975055);
|
||||
ScoreReqBean.CandidatesBean.InfoBean infoBean = new ScoreReqBean.CandidatesBean.InfoBean();
|
||||
List<Integer> list = new ArrayList<>();
|
||||
list.add(1);
|
||||
list.add(1);
|
||||
list.add(1);
|
||||
list.add(1);
|
||||
infoBean.setDetail(list);
|
||||
infoBean.setPersonID("a12e6f5a4383855caa2bd36958a2");
|
||||
infoBean.setScore(10);
|
||||
List<ScoreReqBean.CandidatesBean.InfoBean> infoBeans = new ArrayList<>();
|
||||
infoBeans.add(infoBean);
|
||||
candidatesBean.setInfo(infoBeans);
|
||||
candidatesBeanList.add(new ScoreReqBean.CandidatesBean());
|
||||
bean.setCandidates(candidatesBeanList);
|
||||
concise.request(NetActivity.this, concise.api.score(bean), new CallBack<BaseBean>() {
|
||||
@Override
|
||||
public void onSuccess(BaseBean baseBean) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailed(Throwable e) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initData() {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,78 @@
|
|||
package com.skipping.net;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import io.reactivex.rxjava3.core.Observable;
|
||||
import retrofit2.http.Body;
|
||||
import retrofit2.http.GET;
|
||||
import retrofit2.http.POST;
|
||||
import retrofit2.http.Path;
|
||||
import retrofit2.http.Query;
|
||||
|
||||
/**
|
||||
* @author Ming
|
||||
* 1/24/22
|
||||
*/
|
||||
public interface API {
|
||||
|
||||
/**
|
||||
* 登录
|
||||
* @param tokenReq
|
||||
* @return
|
||||
*/
|
||||
@POST("auth")
|
||||
Observable<BaseBean<TokenBean>> token(@Body TokenReqBean tokenReq);
|
||||
|
||||
|
||||
/**
|
||||
* 获取年级列表
|
||||
* @return
|
||||
*/
|
||||
@GET("groupmap?genre=grade")
|
||||
Observable<BaseBean<List<GradleBean>>> getGrade();
|
||||
|
||||
|
||||
/**
|
||||
* 获取班级列表
|
||||
* @param pid
|
||||
* @return
|
||||
*/
|
||||
@GET("groupmap?genre=class")
|
||||
Observable<BaseBean<List<GradleBean>>> getClass(@Query("pid") String pid);
|
||||
|
||||
|
||||
/**
|
||||
* 获取活动列表
|
||||
* @param activityReqBean
|
||||
* @return
|
||||
*/
|
||||
@POST("activity/list")
|
||||
Observable<BaseBean<List<ActivityBean>>> getActivityList(@Body ActivityReqBean activityReqBean);
|
||||
|
||||
|
||||
/**
|
||||
* 添加活动
|
||||
* @param addActivityReqBean
|
||||
* @return
|
||||
*/
|
||||
@POST("activity/create")
|
||||
Observable<BaseBean<List<AddActivityBean>>> addActivity(@Body AddActivityReqBean addActivityReqBean);
|
||||
|
||||
/**
|
||||
* 活动详情
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@GET("activity/detail")
|
||||
Observable<BaseBean<List<DetailActivityBean>>> detailActivity(@Query("activityid") String id);
|
||||
|
||||
/**
|
||||
* 上报
|
||||
* @param scoreReqBean
|
||||
* @return
|
||||
*/
|
||||
@POST("activity/score")
|
||||
Observable<BaseBean> score(@Body ScoreReqBean scoreReqBean);
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,165 @@
|
|||
package com.skipping.net;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author Ming
|
||||
* 3/15/22
|
||||
*/
|
||||
public class ActivityBean implements Serializable {
|
||||
|
||||
/**
|
||||
* ID : 13
|
||||
* Name : loop2
|
||||
* ActivityType : timing
|
||||
* Value : 60
|
||||
* OrgID : ae428145b8a466e9c72f6047b8
|
||||
* GreadID : 6b76e9770a4eafbcee213121d4ad6b
|
||||
* ClassID : 77bba9124a4281bc9f92f965561cd5
|
||||
* Status : 未完成
|
||||
* Step : 2
|
||||
* CompleteTime : null
|
||||
* PersonNumber : 6
|
||||
* GroupID :
|
||||
* CreatedAt : 2022-03-14T08:38:21.495+08:00
|
||||
*/
|
||||
|
||||
private Integer id;
|
||||
private String Name;
|
||||
private String ActivityType;
|
||||
private Integer Value;
|
||||
private String OrgID;
|
||||
private String GreadID;
|
||||
private String ClassID;
|
||||
private String Status;
|
||||
private Integer Step;
|
||||
private Object CompleteTime;
|
||||
private Integer PersonNumber;
|
||||
private String GroupID;
|
||||
private String CreatedAt;
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return Name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
Name = name;
|
||||
}
|
||||
|
||||
public String getActivityType() {
|
||||
return ActivityType;
|
||||
}
|
||||
|
||||
public void setActivityType(String activityType) {
|
||||
ActivityType = activityType;
|
||||
}
|
||||
|
||||
public Integer getValue() {
|
||||
return Value;
|
||||
}
|
||||
|
||||
public void setValue(Integer value) {
|
||||
Value = value;
|
||||
}
|
||||
|
||||
public String getOrgID() {
|
||||
return OrgID;
|
||||
}
|
||||
|
||||
public void setOrgID(String orgID) {
|
||||
OrgID = orgID;
|
||||
}
|
||||
|
||||
public String getGreadID() {
|
||||
return GreadID;
|
||||
}
|
||||
|
||||
public void setGreadID(String greadID) {
|
||||
GreadID = greadID;
|
||||
}
|
||||
|
||||
public String getClassID() {
|
||||
return ClassID;
|
||||
}
|
||||
|
||||
public void setClassID(String classID) {
|
||||
ClassID = classID;
|
||||
}
|
||||
|
||||
public String getStatus() {
|
||||
return Status;
|
||||
}
|
||||
|
||||
public void setStatus(String status) {
|
||||
Status = status;
|
||||
}
|
||||
|
||||
public Integer getStep() {
|
||||
return Step;
|
||||
}
|
||||
|
||||
public void setStep(Integer step) {
|
||||
Step = step;
|
||||
}
|
||||
|
||||
public Object getCompleteTime() {
|
||||
return CompleteTime;
|
||||
}
|
||||
|
||||
public void setCompleteTime(Object completeTime) {
|
||||
CompleteTime = completeTime;
|
||||
}
|
||||
|
||||
public Integer getPersonNumber() {
|
||||
return PersonNumber;
|
||||
}
|
||||
|
||||
public void setPersonNumber(Integer personNumber) {
|
||||
PersonNumber = personNumber;
|
||||
}
|
||||
|
||||
public String getGroupID() {
|
||||
return GroupID;
|
||||
}
|
||||
|
||||
public void setGroupID(String groupID) {
|
||||
GroupID = groupID;
|
||||
}
|
||||
|
||||
public String getCreatedAt() {
|
||||
return CreatedAt;
|
||||
}
|
||||
|
||||
public void setCreatedAt(String createdAt) {
|
||||
CreatedAt = createdAt;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ActivityBean{" +
|
||||
"id=" + id +
|
||||
", Name='" + Name + '\'' +
|
||||
", ActivityType='" + ActivityType + '\'' +
|
||||
", Value=" + Value +
|
||||
", OrgID='" + OrgID + '\'' +
|
||||
", GreadID='" + GreadID + '\'' +
|
||||
", ClassID='" + ClassID + '\'' +
|
||||
", Status='" + Status + '\'' +
|
||||
", Step=" + Step +
|
||||
", CompleteTime=" + CompleteTime +
|
||||
", PersonNumber=" + PersonNumber +
|
||||
", GroupID='" + GroupID + '\'' +
|
||||
", CreatedAt='" + CreatedAt + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,108 @@
|
|||
package com.skipping.net;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author Ming
|
||||
* 3/15/22
|
||||
*/
|
||||
public class ActivityReqBean implements Serializable {
|
||||
|
||||
/**
|
||||
* Genre : class
|
||||
* ActivityType : timing
|
||||
* GroupID : f3f80d8e934e0d85a01f608978d64d
|
||||
* Index : 1
|
||||
* PageSize : 10
|
||||
* Status : 未完成
|
||||
* STime : 1646975055
|
||||
* ETime : 1646986281
|
||||
*/
|
||||
|
||||
private String Genre;
|
||||
private String ActivityType;
|
||||
private String GroupID;
|
||||
private Integer Index;
|
||||
private Integer PageSize;
|
||||
private String Status;
|
||||
private Integer STime;
|
||||
private Integer ETime;
|
||||
|
||||
public String getGenre() {
|
||||
return Genre;
|
||||
}
|
||||
|
||||
public void setGenre(String genre) {
|
||||
Genre = genre;
|
||||
}
|
||||
|
||||
public String getActivityType() {
|
||||
return ActivityType;
|
||||
}
|
||||
|
||||
public void setActivityType(String activityType) {
|
||||
ActivityType = activityType;
|
||||
}
|
||||
|
||||
public String getGroupID() {
|
||||
return GroupID;
|
||||
}
|
||||
|
||||
public void setGroupID(String groupID) {
|
||||
GroupID = groupID;
|
||||
}
|
||||
|
||||
public Integer getIndex() {
|
||||
return Index;
|
||||
}
|
||||
|
||||
public void setIndex(Integer index) {
|
||||
Index = index;
|
||||
}
|
||||
|
||||
public Integer getPageSize() {
|
||||
return PageSize;
|
||||
}
|
||||
|
||||
public void setPageSize(Integer pageSize) {
|
||||
PageSize = pageSize;
|
||||
}
|
||||
|
||||
public String getStatus() {
|
||||
return Status;
|
||||
}
|
||||
|
||||
public void setStatus(String status) {
|
||||
Status = status;
|
||||
}
|
||||
|
||||
public Integer getSTime() {
|
||||
return STime;
|
||||
}
|
||||
|
||||
public void setSTime(Integer STime) {
|
||||
this.STime = STime;
|
||||
}
|
||||
|
||||
public Integer getETime() {
|
||||
return ETime;
|
||||
}
|
||||
|
||||
public void setETime(Integer ETime) {
|
||||
this.ETime = ETime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ActivityReqBean{" +
|
||||
"Genre='" + Genre + '\'' +
|
||||
", ActivityType='" + ActivityType + '\'' +
|
||||
", GroupID='" + GroupID + '\'' +
|
||||
", Index=" + Index +
|
||||
", PageSize=" + PageSize +
|
||||
", Status='" + Status + '\'' +
|
||||
", STime=" + STime +
|
||||
", ETime=" + ETime +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,156 @@
|
|||
package com.skipping.net;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Ming
|
||||
* 3/15/22
|
||||
*/
|
||||
public class AddActivityBean implements Serializable {
|
||||
|
||||
/**
|
||||
* ID : 14
|
||||
* ActivityName : test001
|
||||
* ActivityType : timing
|
||||
* ActivityValue : 60
|
||||
* Step : 2
|
||||
* Candidates : [[{"PersonID":"4414550b40b38fd171ba2e319dc2","Name":"xiaowang","StudentID":"1005","Score":0,"Detail":[]},{"PersonID":"8d34508b457780a298efba2a9c28","Name":"xiaohua","StudentID":"1006","Score":0,"Detail":[]}]]
|
||||
*/
|
||||
|
||||
private Integer id;
|
||||
private String ActivityName;
|
||||
private String ActivityType;
|
||||
private Integer ActivityValue;
|
||||
private Integer Step;
|
||||
private List<List<CandidatesBean>> Candidates;
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getActivityName() {
|
||||
return ActivityName;
|
||||
}
|
||||
|
||||
public void setActivityName(String activityName) {
|
||||
ActivityName = activityName;
|
||||
}
|
||||
|
||||
public String getActivityType() {
|
||||
return ActivityType;
|
||||
}
|
||||
|
||||
public void setActivityType(String activityType) {
|
||||
ActivityType = activityType;
|
||||
}
|
||||
|
||||
public Integer getActivityValue() {
|
||||
return ActivityValue;
|
||||
}
|
||||
|
||||
public void setActivityValue(Integer activityValue) {
|
||||
ActivityValue = activityValue;
|
||||
}
|
||||
|
||||
public Integer getStep() {
|
||||
return Step;
|
||||
}
|
||||
|
||||
public void setStep(Integer step) {
|
||||
Step = step;
|
||||
}
|
||||
|
||||
public List<List<CandidatesBean>> getCandidates() {
|
||||
return Candidates;
|
||||
}
|
||||
|
||||
public void setCandidates(List<List<CandidatesBean>> candidates) {
|
||||
Candidates = candidates;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "AddActivityBean{" +
|
||||
"id=" + id +
|
||||
", ActivityName='" + ActivityName + '\'' +
|
||||
", ActivityType='" + ActivityType + '\'' +
|
||||
", ActivityValue=" + ActivityValue +
|
||||
", Step=" + Step +
|
||||
", Candidates=" + Candidates +
|
||||
'}';
|
||||
}
|
||||
|
||||
public static class CandidatesBean implements Serializable {
|
||||
/**
|
||||
* PersonID : 4414550b40b38fd171ba2e319dc2
|
||||
* Name : xiaowang
|
||||
* StudentID : 1005
|
||||
* Score : 0
|
||||
* Detail : []
|
||||
*/
|
||||
|
||||
private String PersonID;
|
||||
private String Name;
|
||||
private String StudentID;
|
||||
private Integer Score;
|
||||
private List<?> Detail;
|
||||
|
||||
public String getPersonID() {
|
||||
return PersonID;
|
||||
}
|
||||
|
||||
public void setPersonID(String personID) {
|
||||
PersonID = personID;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return Name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
Name = name;
|
||||
}
|
||||
|
||||
public String getStudentID() {
|
||||
return StudentID;
|
||||
}
|
||||
|
||||
public void setStudentID(String studentID) {
|
||||
StudentID = studentID;
|
||||
}
|
||||
|
||||
public Integer getScore() {
|
||||
return Score;
|
||||
}
|
||||
|
||||
public void setScore(Integer score) {
|
||||
Score = score;
|
||||
}
|
||||
|
||||
public List<?> getDetail() {
|
||||
return Detail;
|
||||
}
|
||||
|
||||
public void setDetail(List<?> detail) {
|
||||
Detail = detail;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "CandidatesBean{" +
|
||||
"PersonID='" + PersonID + '\'' +
|
||||
", Name='" + Name + '\'' +
|
||||
", StudentID='" + StudentID + '\'' +
|
||||
", Score=" + Score +
|
||||
", Detail=" + Detail +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,86 @@
|
|||
package com.skipping.net;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author Ming
|
||||
* 3/15/22
|
||||
*/
|
||||
public class AddActivityReqBean implements Serializable {
|
||||
|
||||
/**
|
||||
* Name : loop2
|
||||
* ActivityType : timing
|
||||
* Value : 60
|
||||
* GroupID : f3f80d8e934e0d85a01f608978d64d
|
||||
* PersonNumber : 6
|
||||
* Step : 2
|
||||
*/
|
||||
|
||||
private String Name;
|
||||
private String ActivityType;
|
||||
private Integer Value;
|
||||
private String GroupID;
|
||||
private Integer PersonNumber;
|
||||
private Integer Step;
|
||||
|
||||
public String getName() {
|
||||
return Name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
Name = name;
|
||||
}
|
||||
|
||||
public String getActivityType() {
|
||||
return ActivityType;
|
||||
}
|
||||
|
||||
public void setActivityType(String activityType) {
|
||||
ActivityType = activityType;
|
||||
}
|
||||
|
||||
public Integer getValue() {
|
||||
return Value;
|
||||
}
|
||||
|
||||
public void setValue(Integer value) {
|
||||
Value = value;
|
||||
}
|
||||
|
||||
public String getGroupID() {
|
||||
return GroupID;
|
||||
}
|
||||
|
||||
public void setGroupID(String groupID) {
|
||||
GroupID = groupID;
|
||||
}
|
||||
|
||||
public Integer getPersonNumber() {
|
||||
return PersonNumber;
|
||||
}
|
||||
|
||||
public void setPersonNumber(Integer personNumber) {
|
||||
PersonNumber = personNumber;
|
||||
}
|
||||
|
||||
public Integer getStep() {
|
||||
return Step;
|
||||
}
|
||||
|
||||
public void setStep(Integer step) {
|
||||
Step = step;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "AddActivityReqBean{" +
|
||||
"Name='" + Name + '\'' +
|
||||
", ActivityType='" + ActivityType + '\'' +
|
||||
", Value=" + Value +
|
||||
", GroupID='" + GroupID + '\'' +
|
||||
", PersonNumber=" + PersonNumber +
|
||||
", Step=" + Step +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,47 @@
|
|||
package com.skipping.net;
|
||||
|
||||
/**
|
||||
* @author Ming
|
||||
* 3/14/22
|
||||
*/
|
||||
public class BaseBean<T> {
|
||||
private Integer code;
|
||||
private String msg;
|
||||
private T data;
|
||||
|
||||
public BaseBean() {
|
||||
}
|
||||
|
||||
public Integer getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setCode(Integer code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public String getMsg() {
|
||||
return msg;
|
||||
}
|
||||
|
||||
public void setMsg(String msg) {
|
||||
this.msg = msg;
|
||||
}
|
||||
|
||||
public T getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public void setData(T data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "BaseBean{" +
|
||||
"code=" + code +
|
||||
", msg='" + msg + '\'' +
|
||||
", data=" + data +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,189 @@
|
|||
package com.skipping.net;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Ming
|
||||
* 3/15/22
|
||||
*/
|
||||
public class DetailActivityBean implements Serializable {
|
||||
|
||||
/**
|
||||
* ID : 1
|
||||
* ActivityName : 活动1
|
||||
* ActivityType : timing
|
||||
* ActivityValue : 60
|
||||
* Step : 2
|
||||
* Max : 12
|
||||
* Avg : 9.75
|
||||
* Median : 9.5
|
||||
* Candidates : [[{"PersonID":"329b20b046f5888bcd5165d115f1","Name":"xiaofang","StudentID":"1002","Score":12,"Detail":null},{"PersonID":"4557de13408aaf9057752285c81a","Name":"xiaohai","StudentID":"1003","Score":8,"Detail":null},{"PersonID":"4dee38df466fa8469f0e62f672fb","Name":"xiaoli","StudentID":"1004","Score":9,"Detail":null}]]
|
||||
*/
|
||||
|
||||
private Integer id;
|
||||
private String ActivityName;
|
||||
private String ActivityType;
|
||||
private Integer ActivityValue;
|
||||
private Integer Step;
|
||||
private Integer Max;
|
||||
private Double Avg;
|
||||
private Double Median;
|
||||
private List<List<CandidatesBean>> Candidates;
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getActivityName() {
|
||||
return ActivityName;
|
||||
}
|
||||
|
||||
public void setActivityName(String activityName) {
|
||||
ActivityName = activityName;
|
||||
}
|
||||
|
||||
public String getActivityType() {
|
||||
return ActivityType;
|
||||
}
|
||||
|
||||
public void setActivityType(String activityType) {
|
||||
ActivityType = activityType;
|
||||
}
|
||||
|
||||
public Integer getActivityValue() {
|
||||
return ActivityValue;
|
||||
}
|
||||
|
||||
public void setActivityValue(Integer activityValue) {
|
||||
ActivityValue = activityValue;
|
||||
}
|
||||
|
||||
public Integer getStep() {
|
||||
return Step;
|
||||
}
|
||||
|
||||
public void setStep(Integer step) {
|
||||
Step = step;
|
||||
}
|
||||
|
||||
public Integer getMax() {
|
||||
return Max;
|
||||
}
|
||||
|
||||
public void setMax(Integer max) {
|
||||
Max = max;
|
||||
}
|
||||
|
||||
public Double getAvg() {
|
||||
return Avg;
|
||||
}
|
||||
|
||||
public void setAvg(Double avg) {
|
||||
Avg = avg;
|
||||
}
|
||||
|
||||
public Double getMedian() {
|
||||
return Median;
|
||||
}
|
||||
|
||||
public void setMedian(Double median) {
|
||||
Median = median;
|
||||
}
|
||||
|
||||
public List<List<CandidatesBean>> getCandidates() {
|
||||
return Candidates;
|
||||
}
|
||||
|
||||
public void setCandidates(List<List<CandidatesBean>> candidates) {
|
||||
Candidates = candidates;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "DetailActivityBean{" +
|
||||
"id=" + id +
|
||||
", ActivityName='" + ActivityName + '\'' +
|
||||
", ActivityType='" + ActivityType + '\'' +
|
||||
", ActivityValue=" + ActivityValue +
|
||||
", Step=" + Step +
|
||||
", Max=" + Max +
|
||||
", Avg=" + Avg +
|
||||
", Median=" + Median +
|
||||
", Candidates=" + Candidates +
|
||||
'}';
|
||||
}
|
||||
|
||||
public static class CandidatesBean implements Serializable {
|
||||
/**
|
||||
* PersonID : 329b20b046f5888bcd5165d115f1
|
||||
* Name : xiaofang
|
||||
* StudentID : 1002
|
||||
* Score : 12
|
||||
* Detail : null
|
||||
*/
|
||||
|
||||
private String PersonID;
|
||||
private String Name;
|
||||
private String StudentID;
|
||||
private Integer Score;
|
||||
private Object Detail;
|
||||
|
||||
public String getPersonID() {
|
||||
return PersonID;
|
||||
}
|
||||
|
||||
public void setPersonID(String personID) {
|
||||
PersonID = personID;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return Name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
Name = name;
|
||||
}
|
||||
|
||||
public String getStudentID() {
|
||||
return StudentID;
|
||||
}
|
||||
|
||||
public void setStudentID(String studentID) {
|
||||
StudentID = studentID;
|
||||
}
|
||||
|
||||
public Integer getScore() {
|
||||
return Score;
|
||||
}
|
||||
|
||||
public void setScore(Integer score) {
|
||||
Score = score;
|
||||
}
|
||||
|
||||
public Object getDetail() {
|
||||
return Detail;
|
||||
}
|
||||
|
||||
public void setDetail(Object detail) {
|
||||
Detail = detail;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "CandidatesBean{" +
|
||||
"PersonID='" + PersonID + '\'' +
|
||||
", Name='" + Name + '\'' +
|
||||
", StudentID='" + StudentID + '\'' +
|
||||
", Score=" + Score +
|
||||
", Detail=" + Detail +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,42 @@
|
|||
package com.skipping.net;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author Ming
|
||||
* 3/15/22
|
||||
*/
|
||||
public class GradleBean implements Serializable {
|
||||
|
||||
/**
|
||||
* GroupID : 6b76e9770a4eafbcee213121d4ad6b
|
||||
* GroupName : 101
|
||||
*/
|
||||
|
||||
private String GroupID;
|
||||
private String GroupName;
|
||||
|
||||
public String getGroupID() {
|
||||
return GroupID;
|
||||
}
|
||||
|
||||
public void setGroupID(String groupID) {
|
||||
GroupID = groupID;
|
||||
}
|
||||
|
||||
public String getGroupName() {
|
||||
return GroupName;
|
||||
}
|
||||
|
||||
public void setGroupName(String groupName) {
|
||||
GroupName = groupName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "GradleBean{" +
|
||||
"GroupID='" + GroupID + '\'' +
|
||||
", GroupName='" + GroupName + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,135 @@
|
|||
package com.skipping.net;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Ming
|
||||
* 3/15/22
|
||||
*/
|
||||
public class ScoreReqBean implements Serializable {
|
||||
|
||||
/**
|
||||
* ID : 4
|
||||
* Step : 2
|
||||
* Candidates : [{"ComplateTime":1646975055,"Info":[{"PersonID":"a12e6f5a4383855caa2bd36958a2","Score":10,"Detail":[0,0,0,0,1,2,3,4]},{"PersonID":"329b20b046f5888bcd5165d115f1","Score":12,"Detail":[1,2,2,1,1,2,3,0]},{"PersonID":"4557de13408aaf9057752285c81a","Score":8,"Detail":[0,0,0,0,1,2,3,2]}]}]
|
||||
*/
|
||||
|
||||
private Integer id;
|
||||
private Integer Step;
|
||||
private List<CandidatesBean> Candidates;
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Integer getStep() {
|
||||
return Step;
|
||||
}
|
||||
|
||||
public void setStep(Integer step) {
|
||||
Step = step;
|
||||
}
|
||||
|
||||
public List<CandidatesBean> getCandidates() {
|
||||
return Candidates;
|
||||
}
|
||||
|
||||
public void setCandidates(List<CandidatesBean> candidates) {
|
||||
Candidates = candidates;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ScoreReqBean{" +
|
||||
"id=" + id +
|
||||
", Step=" + Step +
|
||||
", Candidates=" + Candidates +
|
||||
'}';
|
||||
}
|
||||
|
||||
public static class CandidatesBean implements Serializable {
|
||||
/**
|
||||
* ComplateTime : 1646975055
|
||||
* Info : [{"PersonID":"a12e6f5a4383855caa2bd36958a2","Score":10,"Detail":[0,0,0,0,1,2,3,4]},{"PersonID":"329b20b046f5888bcd5165d115f1","Score":12,"Detail":[1,2,2,1,1,2,3,0]},{"PersonID":"4557de13408aaf9057752285c81a","Score":8,"Detail":[0,0,0,0,1,2,3,2]}]
|
||||
*/
|
||||
|
||||
private Integer ComplateTime;
|
||||
private List<InfoBean> Info;
|
||||
|
||||
public Integer getComplateTime() {
|
||||
return ComplateTime;
|
||||
}
|
||||
|
||||
public void setComplateTime(Integer complateTime) {
|
||||
ComplateTime = complateTime;
|
||||
}
|
||||
|
||||
public List<InfoBean> getInfo() {
|
||||
return Info;
|
||||
}
|
||||
|
||||
public void setInfo(List<InfoBean> info) {
|
||||
Info = info;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "CandidatesBean{" +
|
||||
"ComplateTime=" + ComplateTime +
|
||||
", Info=" + Info +
|
||||
'}';
|
||||
}
|
||||
|
||||
public static class InfoBean implements Serializable {
|
||||
/**
|
||||
* PersonID : a12e6f5a4383855caa2bd36958a2
|
||||
* Score : 10
|
||||
* Detail : [0,0,0,0,1,2,3,4]
|
||||
*/
|
||||
|
||||
private String PersonID;
|
||||
private Integer Score;
|
||||
private List<Integer> Detail;
|
||||
|
||||
public String getPersonID() {
|
||||
return PersonID;
|
||||
}
|
||||
|
||||
public void setPersonID(String personID) {
|
||||
PersonID = personID;
|
||||
}
|
||||
|
||||
public Integer getScore() {
|
||||
return Score;
|
||||
}
|
||||
|
||||
public void setScore(Integer score) {
|
||||
Score = score;
|
||||
}
|
||||
|
||||
public List<Integer> getDetail() {
|
||||
return Detail;
|
||||
}
|
||||
|
||||
public void setDetail(List<Integer> detail) {
|
||||
Detail = detail;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "InfoBean{" +
|
||||
"PersonID='" + PersonID + '\'' +
|
||||
", Score=" + Score +
|
||||
", Detail=" + Detail +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
package com.skipping.net;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author Ming
|
||||
* 3/14/22
|
||||
*/
|
||||
public class TokenBean implements Serializable {
|
||||
|
||||
private String Token;
|
||||
private Integer ExpireIn;
|
||||
|
||||
public TokenBean() {
|
||||
}
|
||||
|
||||
public String getToken() {
|
||||
return Token;
|
||||
}
|
||||
|
||||
public void setToken(String token) {
|
||||
Token = token;
|
||||
}
|
||||
|
||||
public Integer getExpireIn() {
|
||||
return ExpireIn;
|
||||
}
|
||||
|
||||
public void setExpireIn(Integer expireIn) {
|
||||
ExpireIn = expireIn;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "TokenBean{" +
|
||||
"Token='" + Token + '\'' +
|
||||
", ExpireIn=" + ExpireIn +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,44 @@
|
|||
package com.skipping.net;
|
||||
|
||||
/**
|
||||
* @author Ming
|
||||
* 3/14/22
|
||||
*/
|
||||
public class TokenReqBean {
|
||||
private String LogName;
|
||||
private String LogPwd;
|
||||
private String DeviceID;
|
||||
|
||||
public String getLogName() {
|
||||
return LogName;
|
||||
}
|
||||
|
||||
public void setLogName(String logName) {
|
||||
LogName = logName;
|
||||
}
|
||||
|
||||
public String getLogPwd() {
|
||||
return LogPwd;
|
||||
}
|
||||
|
||||
public void setLogPwd(String logPwd) {
|
||||
LogPwd = logPwd;
|
||||
}
|
||||
|
||||
public String getDeviceID() {
|
||||
return DeviceID;
|
||||
}
|
||||
|
||||
public void setDeviceID(String deviceID) {
|
||||
DeviceID = deviceID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "TokenReq{" +
|
||||
"LogName='" + LogName + '\'' +
|
||||
", LogPwd='" + LogPwd + '\'' +
|
||||
", DeviceID='" + DeviceID + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,130 @@
|
|||
package com.skipping.utils;
|
||||
|
||||
import com.libs.threadpool.Pool;
|
||||
import com.libs.threadpool.Type;
|
||||
import com.libs.threadpool.callback.DefLogCallBack;
|
||||
import com.libs.utils.MainLooper;
|
||||
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* @author Ming
|
||||
* 12/22/21
|
||||
* 线程池管理类
|
||||
*/
|
||||
public class ThreadPoolUtil {
|
||||
private ScheduledExecutorService scheduledPool;
|
||||
private static volatile ThreadPoolUtil threadPoolManager;
|
||||
|
||||
public ThreadPoolUtil() {
|
||||
initPool();
|
||||
}
|
||||
|
||||
public static ThreadPoolUtil getSingleton() {
|
||||
if (threadPoolManager == null) {
|
||||
synchronized (ThreadPoolUtil.class) {
|
||||
if (threadPoolManager == null) {
|
||||
threadPoolManager = new ThreadPoolUtil();
|
||||
}
|
||||
}
|
||||
}
|
||||
return threadPoolManager;
|
||||
}
|
||||
|
||||
|
||||
private void initPool() {
|
||||
scheduledPool = (ScheduledExecutorService) new Pool.Builder()
|
||||
.setThreadType(Type.SCHEDULED)
|
||||
.setLog(new DefLogCallBack())
|
||||
.setSize(12)
|
||||
.build()
|
||||
.getThreadPool();
|
||||
}
|
||||
|
||||
/**
|
||||
* 单次延迟任务
|
||||
*
|
||||
* @param command Runnable
|
||||
* @param delay 延迟时间
|
||||
*/
|
||||
public ScheduledFuture schedule(Runnable command, long delay) {
|
||||
if (scheduledPool == null) {
|
||||
initPool();
|
||||
}
|
||||
return scheduledPool.schedule(command, delay, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
/**
|
||||
* 单次延迟任务
|
||||
*
|
||||
* @param command Runnable
|
||||
* @param delay 延迟时间
|
||||
*/
|
||||
public ScheduledFuture scheduleMain(Runnable command, long delay) {
|
||||
if (scheduledPool == null) {
|
||||
initPool();
|
||||
}
|
||||
return scheduledPool.schedule(() -> MainLooper.runOnUiThread(command), delay, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 重复任务
|
||||
*
|
||||
* @param command Runnable
|
||||
* @param initDelay 首次延迟时间
|
||||
* @param delay 间隔时间
|
||||
*/
|
||||
public ScheduledFuture scheduleWithFixedDelay(Runnable command, long initDelay, long delay) {
|
||||
if (scheduledPool == null) {
|
||||
initPool();
|
||||
}
|
||||
return scheduledPool.scheduleWithFixedDelay(command, initDelay, delay, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
/**
|
||||
* 重复任务
|
||||
*
|
||||
* @param command Runnable
|
||||
* @param initDelay 首次延迟时间
|
||||
* @param delay 间隔时间
|
||||
*/
|
||||
public ScheduledFuture scheduleWithFixedDelayMain(Runnable command, long initDelay, long delay) {
|
||||
if (scheduledPool == null) {
|
||||
initPool();
|
||||
}
|
||||
return scheduledPool.scheduleWithFixedDelay(() -> MainLooper.runOnUiThread(command), initDelay, delay, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
/**
|
||||
* 重复任务 第一个执行之后定时再执行
|
||||
*
|
||||
* @param command Runnable
|
||||
* @param initDelay 首次延迟时间
|
||||
* @param delay 间隔时间
|
||||
*/
|
||||
public ScheduledFuture scheduleAtFixedRate(Runnable command, long initDelay, long delay) {
|
||||
if (scheduledPool == null) {
|
||||
initPool();
|
||||
}
|
||||
return scheduledPool.scheduleAtFixedRate(command, initDelay, delay, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 重复任务 第一个执行之后定时再执行
|
||||
*
|
||||
* @param command Runnable
|
||||
* @param initDelay 首次延迟时间
|
||||
* @param delay 间隔时间
|
||||
*/
|
||||
public ScheduledFuture scheduleAtFixedRateMain(Runnable command, long initDelay, long delay) {
|
||||
if (scheduledPool == null) {
|
||||
initPool();
|
||||
}
|
||||
return scheduledPool.scheduleAtFixedRate(() -> MainLooper.runOnUiThread(command), initDelay, delay, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:aapt="http://schemas.android.com/aapt"
|
||||
android:width="108dp"
|
||||
android:height="108dp"
|
||||
android:viewportWidth="108"
|
||||
android:viewportHeight="108">
|
||||
<path android:pathData="M31,63.928c0,0 6.4,-11 12.1,-13.1c7.2,-2.6 26,-1.4 26,-1.4l38.1,38.1L107,108.928l-32,-1L31,63.928z">
|
||||
<aapt:attr name="android:fillColor">
|
||||
<gradient
|
||||
android:endX="85.84757"
|
||||
android:endY="92.4963"
|
||||
android:startX="42.9492"
|
||||
android:startY="49.59793"
|
||||
android:type="linear">
|
||||
<item
|
||||
android:color="#44000000"
|
||||
android:offset="0.0" />
|
||||
<item
|
||||
android:color="#00000000"
|
||||
android:offset="1.0" />
|
||||
</gradient>
|
||||
</aapt:attr>
|
||||
</path>
|
||||
<path
|
||||
android:fillColor="#FFFFFF"
|
||||
android:fillType="nonZero"
|
||||
android:pathData="M65.3,45.828l3.8,-6.6c0.2,-0.4 0.1,-0.9 -0.3,-1.1c-0.4,-0.2 -0.9,-0.1 -1.1,0.3l-3.9,6.7c-6.3,-2.8 -13.4,-2.8 -19.7,0l-3.9,-6.7c-0.2,-0.4 -0.7,-0.5 -1.1,-0.3C38.8,38.328 38.7,38.828 38.9,39.228l3.8,6.6C36.2,49.428 31.7,56.028 31,63.928h46C76.3,56.028 71.8,49.428 65.3,45.828zM43.4,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2c-0.3,-0.7 -0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C45.3,56.528 44.5,57.328 43.4,57.328L43.4,57.328zM64.6,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2s-0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C66.5,56.528 65.6,57.328 64.6,57.328L64.6,57.328z"
|
||||
android:strokeWidth="1"
|
||||
android:strokeColor="#00000000" />
|
||||
</vector>
|
||||
|
|
@ -0,0 +1,170 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="108dp"
|
||||
android:height="108dp"
|
||||
android:viewportWidth="108"
|
||||
android:viewportHeight="108">
|
||||
<path
|
||||
android:fillColor="#3DDC84"
|
||||
android:pathData="M0,0h108v108h-108z" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M9,0L9,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,0L19,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M29,0L29,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M39,0L39,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M49,0L49,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M59,0L59,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M69,0L69,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M79,0L79,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M89,0L89,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M99,0L99,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,9L108,9"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,19L108,19"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,29L108,29"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,39L108,39"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,49L108,49"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,59L108,59"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,69L108,69"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,79L108,79"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,89L108,89"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,99L108,99"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,29L89,29"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,39L89,39"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,49L89,49"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,59L89,59"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,69L89,69"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,79L89,79"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M29,19L29,89"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M39,19L39,89"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M49,19L49,89"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M59,19L59,89"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M69,19L69,89"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M79,19L79,89"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
</vector>
|
||||
|
|
@ -0,0 +1,47 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout 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"
|
||||
android:orientation="vertical"
|
||||
tools:context=".activity.MainActivity">
|
||||
|
||||
<EditText
|
||||
android:id="@+id/edittext"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="10dp"
|
||||
app:layout_constraintRight_toRightOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/button6" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/btn"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="连接" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/btn2"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="连接" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/btn3"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="获取数据" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/btn4"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="设备连接" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/btn5"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="设备断开连接" />
|
||||
</LinearLayout>
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout 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:orientation="vertical"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="center"
|
||||
tools:context=".activity.MainActivity">
|
||||
|
||||
<Button
|
||||
android:id="@+id/btn"
|
||||
android:text="设备"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/btn2"
|
||||
android:text="网络"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
</LinearLayout>
|
||||
|
|
@ -0,0 +1,105 @@
|
|||
<?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.MainActivity">
|
||||
|
||||
<Button
|
||||
android:id="@+id/button5"
|
||||
android:layout_width="141dp"
|
||||
android:layout_height="48dp"
|
||||
android:layout_marginTop="156dp"
|
||||
android:text="连接手柄"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/button2" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/button6"
|
||||
android:layout_width="141dp"
|
||||
android:layout_height="48dp"
|
||||
android:layout_marginTop="224dp"
|
||||
android:text="断开手柄"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/button2" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/button7"
|
||||
android:layout_width="141dp"
|
||||
android:layout_height="46dp"
|
||||
android:text="获取电量"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/button8"
|
||||
android:layout_width="141dp"
|
||||
android:layout_height="48dp"
|
||||
android:layout_marginTop="68dp"
|
||||
android:text="获取个数"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/button9"
|
||||
android:layout_width="141dp"
|
||||
android:layout_height="48dp"
|
||||
android:layout_marginTop="136dp"
|
||||
android:text="定时计数"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/button10"
|
||||
android:layout_width="141dp"
|
||||
android:layout_height="48dp"
|
||||
android:layout_marginTop="204dp"
|
||||
android:text="停止跳绳"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/button"
|
||||
android:layout_width="121dp"
|
||||
android:layout_height="47dp"
|
||||
android:text="连接主机"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/button2"
|
||||
android:layout_width="141dp"
|
||||
android:layout_height="48dp"
|
||||
android:layout_marginTop="24dp"
|
||||
android:text="打开配对模式"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/button" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/button3"
|
||||
android:layout_width="141dp"
|
||||
android:layout_height="48dp"
|
||||
android:layout_marginTop="20dp"
|
||||
android:text="关闭配对模式"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/button2" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/button4"
|
||||
android:layout_width="141dp"
|
||||
android:layout_height="48dp"
|
||||
android:layout_marginTop="88dp"
|
||||
android:text="配对手柄"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/button2" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/edittext"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="10dp"
|
||||
app:layout_constraintRight_toRightOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/button6" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
|
@ -0,0 +1,51 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout 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"
|
||||
android:orientation="vertical"
|
||||
tools:context=".activity.MainActivity">
|
||||
|
||||
<Button
|
||||
android:id="@+id/btn"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="登录" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/btn2"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="组织下对应年级map" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/btn3"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="年级下对应班级map" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/btn4"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="活动列表接口" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/btn5"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="活动创建接口" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/btn6"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="活动详情接口" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/btn7"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="活动成绩上传接口" />
|
||||
</LinearLayout>
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<background android:drawable="@drawable/ic_launcher_background" />
|
||||
<foreground android:drawable="@drawable/ic_launcher_foreground" />
|
||||
</adaptive-icon>
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<background android:drawable="@drawable/ic_launcher_background" />
|
||||
<foreground android:drawable="@drawable/ic_launcher_foreground" />
|
||||
</adaptive-icon>
|
||||
|
After Width: | Height: | Size: 3.5 KiB |
|
After Width: | Height: | Size: 5.2 KiB |
|
After Width: | Height: | Size: 2.6 KiB |
|
After Width: | Height: | Size: 3.3 KiB |
|
After Width: | Height: | Size: 4.8 KiB |
|
After Width: | Height: | Size: 7.3 KiB |
|
After Width: | Height: | Size: 7.7 KiB |
|
After Width: | Height: | Size: 12 KiB |
|
After Width: | Height: | Size: 10 KiB |
|
After Width: | Height: | Size: 16 KiB |
|
|
@ -0,0 +1,16 @@
|
|||
<resources xmlns:tools="http://schemas.android.com/tools">
|
||||
<!-- Base application theme. -->
|
||||
<style name="Theme.Skipping" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
|
||||
<!-- Primary brand color. -->
|
||||
<item name="colorPrimary">@color/purple_200</item>
|
||||
<item name="colorPrimaryVariant">@color/purple_700</item>
|
||||
<item name="colorOnPrimary">@color/black</item>
|
||||
<!-- Secondary brand color. -->
|
||||
<item name="colorSecondary">@color/teal_200</item>
|
||||
<item name="colorSecondaryVariant">@color/teal_200</item>
|
||||
<item name="colorOnSecondary">@color/black</item>
|
||||
<!-- Status bar color. -->
|
||||
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
|
||||
<!-- Customize your theme here. -->
|
||||
</style>
|
||||
</resources>
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<color name="purple_200">#FFBB86FC</color>
|
||||
<color name="purple_500">#FF6200EE</color>
|
||||
<color name="purple_700">#FF3700B3</color>
|
||||
<color name="teal_200">#FF03DAC5</color>
|
||||
<color name="teal_700">#FF018786</color>
|
||||
<color name="black">#FF000000</color>
|
||||
<color name="white">#FFFFFFFF</color>
|
||||
</resources>
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
<resources>
|
||||
<string name="app_name">Skipping</string>
|
||||
</resources>
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
<resources xmlns:tools="http://schemas.android.com/tools">
|
||||
<!-- Base application theme. -->
|
||||
<style name="Theme.Skipping" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
|
||||
<!-- Primary brand color. -->
|
||||
<item name="colorPrimary">@color/purple_500</item>
|
||||
<item name="colorPrimaryVariant">@color/purple_700</item>
|
||||
<item name="colorOnPrimary">@color/white</item>
|
||||
<!-- Secondary brand color. -->
|
||||
<item name="colorSecondary">@color/teal_200</item>
|
||||
<item name="colorSecondaryVariant">@color/teal_700</item>
|
||||
<item name="colorOnSecondary">@color/black</item>
|
||||
<!-- Status bar color. -->
|
||||
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
|
||||
<!-- Customize your theme here. -->
|
||||
</style>
|
||||
</resources>
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
package com.skipping;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Example local unit test, which will execute on the development machine (host).
|
||||
*
|
||||
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
|
||||
*/
|
||||
public class ExampleUnitTest {
|
||||
@Test
|
||||
public void addition_isCorrect() {
|
||||
assertEquals(4, 2 + 2);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
// Top-level build file where you can add configuration options common to all sub-projects/modules.
|
||||
buildscript {
|
||||
repositories {
|
||||
google()
|
||||
mavenCentral()
|
||||
maven { url "https://jitpack.io" }
|
||||
}
|
||||
dependencies {
|
||||
classpath "com.android.tools.build:gradle:4.1.2"
|
||||
|
||||
// NOTE: Do not place your application dependencies here; they belong
|
||||
// in the individual module build.gradle files
|
||||
}
|
||||
}
|
||||
|
||||
allprojects {
|
||||
repositories {
|
||||
google()
|
||||
jcenter()
|
||||
maven { url 'https://jitpack.io' }
|
||||
}
|
||||
}
|
||||
|
||||
task clean(type: Delete) {
|
||||
delete rootProject.buildDir
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
# Project-wide Gradle settings.
|
||||
# IDE (e.g. Android Studio) users:
|
||||
# Gradle settings configured through the IDE *will override*
|
||||
# any settings specified in this file.
|
||||
# For more details on how to configure your build environment visit
|
||||
# http://www.gradle.org/docs/current/userguide/build_environment.html
|
||||
# Specifies the JVM arguments used for the daemon process.
|
||||
# The setting is particularly useful for tweaking memory settings.
|
||||
org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
|
||||
# When configured, Gradle will run in incubating parallel mode.
|
||||
# This option should only be used with decoupled projects. More details, visit
|
||||
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
|
||||
# org.gradle.parallel=true
|
||||
# AndroidX package structure to make it clearer which packages are bundled with the
|
||||
# Android operating system, and which are packaged with your app"s APK
|
||||
# https://developer.android.com/topic/libraries/support-library/androidx-rn
|
||||
android.useAndroidX=true
|
||||
# Automatically convert third-party libraries to use AndroidX
|
||||
android.enableJetifier=true
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
#Mon Mar 14 14:30:39 CST 2022
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip
|
||||
|
|
@ -0,0 +1,172 @@
|
|||
#!/usr/bin/env sh
|
||||
|
||||
##############################################################################
|
||||
##
|
||||
## Gradle start up script for UN*X
|
||||
##
|
||||
##############################################################################
|
||||
|
||||
# Attempt to set APP_HOME
|
||||
# Resolve links: $0 may be a link
|
||||
PRG="$0"
|
||||
# Need this for relative symlinks.
|
||||
while [ -h "$PRG" ] ; do
|
||||
ls=`ls -ld "$PRG"`
|
||||
link=`expr "$ls" : '.*-> \(.*\)$'`
|
||||
if expr "$link" : '/.*' > /dev/null; then
|
||||
PRG="$link"
|
||||
else
|
||||
PRG=`dirname "$PRG"`"/$link"
|
||||
fi
|
||||
done
|
||||
SAVED="`pwd`"
|
||||
cd "`dirname \"$PRG\"`/" >/dev/null
|
||||
APP_HOME="`pwd -P`"
|
||||
cd "$SAVED" >/dev/null
|
||||
|
||||
APP_NAME="Gradle"
|
||||
APP_BASE_NAME=`basename "$0"`
|
||||
|
||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
DEFAULT_JVM_OPTS=""
|
||||
|
||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||
MAX_FD="maximum"
|
||||
|
||||
warn () {
|
||||
echo "$*"
|
||||
}
|
||||
|
||||
die () {
|
||||
echo
|
||||
echo "$*"
|
||||
echo
|
||||
exit 1
|
||||
}
|
||||
|
||||
# OS specific support (must be 'true' or 'false').
|
||||
cygwin=false
|
||||
msys=false
|
||||
darwin=false
|
||||
nonstop=false
|
||||
case "`uname`" in
|
||||
CYGWIN* )
|
||||
cygwin=true
|
||||
;;
|
||||
Darwin* )
|
||||
darwin=true
|
||||
;;
|
||||
MINGW* )
|
||||
msys=true
|
||||
;;
|
||||
NONSTOP* )
|
||||
nonstop=true
|
||||
;;
|
||||
esac
|
||||
|
||||
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
||||
|
||||
# Determine the Java command to use to start the JVM.
|
||||
if [ -n "$JAVA_HOME" ] ; then
|
||||
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
||||
# IBM's JDK on AIX uses strange locations for the executables
|
||||
JAVACMD="$JAVA_HOME/jre/sh/java"
|
||||
else
|
||||
JAVACMD="$JAVA_HOME/bin/java"
|
||||
fi
|
||||
if [ ! -x "$JAVACMD" ] ; then
|
||||
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
else
|
||||
JAVACMD="java"
|
||||
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
|
||||
# Increase the maximum file descriptors if we can.
|
||||
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
|
||||
MAX_FD_LIMIT=`ulimit -H -n`
|
||||
if [ $? -eq 0 ] ; then
|
||||
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
|
||||
MAX_FD="$MAX_FD_LIMIT"
|
||||
fi
|
||||
ulimit -n $MAX_FD
|
||||
if [ $? -ne 0 ] ; then
|
||||
warn "Could not set maximum file descriptor limit: $MAX_FD"
|
||||
fi
|
||||
else
|
||||
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
|
||||
fi
|
||||
fi
|
||||
|
||||
# For Darwin, add options to specify how the application appears in the dock
|
||||
if $darwin; then
|
||||
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
|
||||
fi
|
||||
|
||||
# For Cygwin, switch paths to Windows format before running java
|
||||
if $cygwin ; then
|
||||
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
|
||||
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
|
||||
JAVACMD=`cygpath --unix "$JAVACMD"`
|
||||
|
||||
# We build the pattern for arguments to be converted via cygpath
|
||||
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
|
||||
SEP=""
|
||||
for dir in $ROOTDIRSRAW ; do
|
||||
ROOTDIRS="$ROOTDIRS$SEP$dir"
|
||||
SEP="|"
|
||||
done
|
||||
OURCYGPATTERN="(^($ROOTDIRS))"
|
||||
# Add a user-defined pattern to the cygpath arguments
|
||||
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
|
||||
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
|
||||
fi
|
||||
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
||||
i=0
|
||||
for arg in "$@" ; do
|
||||
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
|
||||
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
|
||||
|
||||
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
|
||||
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
|
||||
else
|
||||
eval `echo args$i`="\"$arg\""
|
||||
fi
|
||||
i=$((i+1))
|
||||
done
|
||||
case $i in
|
||||
(0) set -- ;;
|
||||
(1) set -- "$args0" ;;
|
||||
(2) set -- "$args0" "$args1" ;;
|
||||
(3) set -- "$args0" "$args1" "$args2" ;;
|
||||
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
|
||||
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
|
||||
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
|
||||
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
|
||||
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
|
||||
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
|
||||
esac
|
||||
fi
|
||||
|
||||
# Escape application args
|
||||
save () {
|
||||
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
|
||||
echo " "
|
||||
}
|
||||
APP_ARGS=$(save "$@")
|
||||
|
||||
# Collect all arguments for the java command, following the shell quoting and substitution rules
|
||||
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
|
||||
|
||||
# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
|
||||
if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
|
||||
cd "$(dirname "$0")"
|
||||
fi
|
||||
|
||||
exec "$JAVACMD" "$@"
|
||||
|
|
@ -0,0 +1,84 @@
|
|||
@if "%DEBUG%" == "" @echo off
|
||||
@rem ##########################################################################
|
||||
@rem
|
||||
@rem Gradle startup script for Windows
|
||||
@rem
|
||||
@rem ##########################################################################
|
||||
|
||||
@rem Set local scope for the variables with windows NT shell
|
||||
if "%OS%"=="Windows_NT" setlocal
|
||||
|
||||
set DIRNAME=%~dp0
|
||||
if "%DIRNAME%" == "" set DIRNAME=.
|
||||
set APP_BASE_NAME=%~n0
|
||||
set APP_HOME=%DIRNAME%
|
||||
|
||||
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
set DEFAULT_JVM_OPTS=
|
||||
|
||||
@rem Find java.exe
|
||||
if defined JAVA_HOME goto findJavaFromJavaHome
|
||||
|
||||
set JAVA_EXE=java.exe
|
||||
%JAVA_EXE% -version >NUL 2>&1
|
||||
if "%ERRORLEVEL%" == "0" goto init
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:findJavaFromJavaHome
|
||||
set JAVA_HOME=%JAVA_HOME:"=%
|
||||
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||
|
||||
if exist "%JAVA_EXE%" goto init
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:init
|
||||
@rem Get command-line arguments, handling Windows variants
|
||||
|
||||
if not "%OS%" == "Windows_NT" goto win9xME_args
|
||||
|
||||
:win9xME_args
|
||||
@rem Slurp the command line arguments.
|
||||
set CMD_LINE_ARGS=
|
||||
set _SKIP=2
|
||||
|
||||
:win9xME_args_slurp
|
||||
if "x%~1" == "x" goto execute
|
||||
|
||||
set CMD_LINE_ARGS=%*
|
||||
|
||||
:execute
|
||||
@rem Setup the command line
|
||||
|
||||
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
||||
|
||||
@rem Execute Gradle
|
||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
|
||||
|
||||
:end
|
||||
@rem End local scope for the variables with windows NT shell
|
||||
if "%ERRORLEVEL%"=="0" goto mainEnd
|
||||
|
||||
:fail
|
||||
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
||||
rem the _cmd.exe /c_ return code!
|
||||
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
|
||||
exit /b 1
|
||||
|
||||
:mainEnd
|
||||
if "%OS%"=="Windows_NT" endlocal
|
||||
|
||||
:omega
|
||||
|
|
@ -0,0 +1 @@
|
|||
/build
|
||||
|
|
@ -0,0 +1,47 @@
|
|||
plugins {
|
||||
id 'com.android.library'
|
||||
}
|
||||
|
||||
android {
|
||||
compileSdkVersion 28
|
||||
buildToolsVersion "29.0.2"
|
||||
|
||||
defaultConfig {
|
||||
minSdkVersion 21
|
||||
targetSdkVersion 28
|
||||
versionCode 1
|
||||
versionName "1.0"
|
||||
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
consumerProguardFiles "consumer-rules.pro"
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
release {
|
||||
minifyEnabled false
|
||||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
||||
}
|
||||
}
|
||||
compileOptions {
|
||||
sourceCompatibility JavaVersion.VERSION_1_8
|
||||
targetCompatibility JavaVersion.VERSION_1_8
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation 'androidx.appcompat:appcompat:1.2.0'
|
||||
implementation 'com.google.android.material:material:1.3.0'
|
||||
testImplementation 'junit:junit:4.+'
|
||||
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
|
||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
|
||||
api 'com.squareup.retrofit2:retrofit:2.9.0'
|
||||
api 'io.reactivex.rxjava3:rxjava:3.1.3'
|
||||
api 'io.reactivex.rxjava3:rxandroid:3.0.0'
|
||||
api 'com.squareup.retrofit2:converter-gson:2.9.0'
|
||||
api 'com.squareup.retrofit2:adapter-rxjava3:2.9.0'
|
||||
api 'com.squareup.okhttp3:okhttp:4.9.3'
|
||||
api 'com.squareup.okhttp3:logging-interceptor:4.9.3'
|
||||
api 'com.qiniu:happy-dns:0.2.13'
|
||||
api 'com.trello.rxlifecycle4:rxlifecycle-components:4.0.2'
|
||||
api 'com.uber.autodispose2:autodispose-androidx-lifecycle:2.1.1'
|
||||
}
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
# Add project specific ProGuard rules here.
|
||||
# You can control the set of applied configuration files using the
|
||||
# proguardFiles setting in build.gradle.
|
||||
#
|
||||
# For more details, see
|
||||
# http://developer.android.com/guide/developing/tools/proguard.html
|
||||
|
||||
# If your project uses WebView with JS, uncomment the following
|
||||
# and specify the fully qualified class name to the JavaScript interface
|
||||
# class:
|
||||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
|
||||
# public *;
|
||||
#}
|
||||
|
||||
# Uncomment this to preserve the line number information for
|
||||
# debugging stack traces.
|
||||
#-keepattributes SourceFile,LineNumberTable
|
||||
|
||||
# If you keep the line number information, uncomment this to
|
||||
# hide the original source file name.
|
||||
#-renamesourcefileattribute SourceFile
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
package com.libs;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.test.platform.app.InstrumentationRegistry;
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Instrumented test, which will execute on an Android device.
|
||||
*
|
||||
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
|
||||
*/
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class ExampleInstrumentedTest {
|
||||
@Test
|
||||
public void useAppContext() {
|
||||
// Context of the app under test.
|
||||
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
|
||||
assertEquals("com.libs.test", appContext.getPackageName());
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.libs">
|
||||
|
||||
</manifest>
|
||||
|
|
@ -0,0 +1,208 @@
|
|||
package com.libs.fragment;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import androidx.annotation.LayoutRes;
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.libs.threadpool.Pool;
|
||||
import com.libs.threadpool.TaskBean;
|
||||
import com.libs.threadpool.ThreadManager;
|
||||
import com.libs.threadpool.callback.AsyncCallback;
|
||||
import com.libs.utils.ActivityManager;
|
||||
import com.libs.views.toolbar.CommonToolBar;
|
||||
import com.trello.rxlifecycle4.LifecycleTransformer;
|
||||
import com.trello.rxlifecycle4.components.support.RxFragmentActivity;
|
||||
|
||||
|
||||
import java.lang.reflect.ParameterizedType;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Created by Ming
|
||||
* 2020-08-20
|
||||
*/
|
||||
public abstract class BaseActivity<P extends BasePresenter> extends RxFragmentActivity implements BaseView {
|
||||
private long createTime;
|
||||
private String method;
|
||||
private List<Future> futureList = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* P层
|
||||
*/
|
||||
protected P p;
|
||||
|
||||
/**
|
||||
* CommonToolBar
|
||||
*/
|
||||
protected CommonToolBar toolBar;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
ActivityManager.getInstance().pushActivity(this);
|
||||
createTime = System.currentTimeMillis();
|
||||
method = "onCreate";
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(getContentViewResId());
|
||||
toolBar = searchToolBar(findViewById(android.R.id.content));
|
||||
initView();
|
||||
initData();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取布局
|
||||
*/
|
||||
protected abstract int getContentViewResId();
|
||||
|
||||
/**
|
||||
* 初始化P层
|
||||
*/
|
||||
protected void initPresnter() {
|
||||
p = getInstanceP();
|
||||
if (p != null) {
|
||||
p.attachView(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 查找是否有CommonToolBar
|
||||
*
|
||||
* @param viewGroup
|
||||
* @return
|
||||
*/
|
||||
private CommonToolBar searchToolBar(ViewGroup viewGroup) {
|
||||
for (int i = 0; i < viewGroup.getChildCount(); i++) {
|
||||
View v = viewGroup.getChildAt(i);
|
||||
if (v instanceof CommonToolBar) {
|
||||
return (CommonToolBar) v;
|
||||
} else if (v instanceof ViewGroup) {
|
||||
View view = searchToolBar((ViewGroup) v);
|
||||
if (view instanceof CommonToolBar) {
|
||||
return (CommonToolBar) view;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建泛型实例
|
||||
*/
|
||||
private P getInstanceP() {
|
||||
try {
|
||||
Type superclass = getClass().getGenericSuperclass();
|
||||
ParameterizedType parameterizedType = null;
|
||||
if (superclass instanceof ParameterizedType) {
|
||||
parameterizedType = (ParameterizedType) superclass;
|
||||
Type[] typeArray = parameterizedType.getActualTypeArguments();
|
||||
if (typeArray != null && typeArray.length > 0) {
|
||||
Class<P> clazz = (Class<P>) typeArray[0];
|
||||
return clazz.newInstance();
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.e("genericity error", e.toString());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始布局
|
||||
*/
|
||||
protected abstract void initView();
|
||||
|
||||
/**
|
||||
* 初始数据
|
||||
*/
|
||||
protected abstract void initData();
|
||||
|
||||
@Override
|
||||
public void setContentView(@LayoutRes int layoutResID) {
|
||||
super.setContentView(layoutResID);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setContentView(View view) {
|
||||
super.setContentView(view);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void setContentView(View view, ViewGroup.LayoutParams params) {
|
||||
super.setContentView(view, params);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
stopCurrentThread();
|
||||
getExecutor().stop(futureList);
|
||||
super.onDestroy();
|
||||
if (p != null) {
|
||||
p.detachView();
|
||||
p = null;
|
||||
}
|
||||
ActivityManager.getInstance().popActivity(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
if (createTime == 0) {
|
||||
method = "onResume";
|
||||
createTime = System.currentTimeMillis();
|
||||
}
|
||||
super.onResume();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onRestart() {
|
||||
createTime = System.currentTimeMillis();
|
||||
method = "onRestart";
|
||||
super.onRestart();
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> LifecycleTransformer<T> bindRecycler() {
|
||||
LifecycleTransformer objectLifecycleTransformer = bindToLifecycle();
|
||||
return objectLifecycleTransformer;
|
||||
}
|
||||
|
||||
protected Pool getExecutor() {
|
||||
return BaseApplication.getInstance().getExecutor();
|
||||
}
|
||||
|
||||
|
||||
protected TaskBean execute(Runnable runnable) {
|
||||
return ThreadManager.getInstance().execute(this, runnable);
|
||||
}
|
||||
|
||||
protected TaskBean execute(int delay, Runnable runnable) {
|
||||
return ThreadManager.getInstance().execute(this, delay, runnable);
|
||||
}
|
||||
|
||||
protected <T> TaskBean execute(@NonNull Callable<T> callable, AsyncCallback<T> callback) {
|
||||
return ThreadManager.getInstance().execute(this, callable, callback);
|
||||
}
|
||||
|
||||
|
||||
protected <T> TaskBean execute(int delay, @NonNull Callable<T> callable, AsyncCallback<T> callback) {
|
||||
return ThreadManager.getInstance().execute(this, delay, callable, callback);
|
||||
}
|
||||
|
||||
protected void stopCurrentThread() {
|
||||
ThreadManager.getInstance().remove(this);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,104 @@
|
|||
package com.libs.fragment;
|
||||
|
||||
import android.app.ActivityManager;
|
||||
import android.app.Application;
|
||||
import android.content.Context;
|
||||
|
||||
|
||||
import com.libs.threadpool.Pool;
|
||||
import com.libs.threadpool.Type;
|
||||
import com.libs.threadpool.callback.DefLogCallBack;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
|
||||
|
||||
/**
|
||||
* @author Ming
|
||||
* 1/12/21
|
||||
*/
|
||||
public abstract class BaseApplication extends Application {
|
||||
|
||||
protected Pool pool;
|
||||
private static BaseApplication baseApplication = null;
|
||||
|
||||
public static BaseApplication getInstance() {
|
||||
return baseApplication;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
baseApplication = this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化线程池
|
||||
*/
|
||||
protected void initThreadPool(@Type int type) {
|
||||
pool = new Pool.Builder()
|
||||
.setThreadType(type)
|
||||
.setLog(new DefLogCallBack())
|
||||
.build();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取线程池
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public Pool getExecutor() {
|
||||
if (pool == null) {
|
||||
initThreadPool(Type.FIXED);
|
||||
}
|
||||
return pool;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断当前进程是否为主进程
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private boolean isMainProcess() {
|
||||
int pid = android.os.Process.myPid();
|
||||
String processName = "";
|
||||
ActivityManager mActivityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
|
||||
for (ActivityManager.RunningAppProcessInfo appProcess : mActivityManager.getRunningAppProcesses()) {
|
||||
if (appProcess.pid == pid) {
|
||||
processName = appProcess.processName;
|
||||
break;
|
||||
}
|
||||
}
|
||||
String packageName = this.getPackageName();
|
||||
if (processName.equals(packageName)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerActivityLifecycleCallbacks(ActivityLifecycleCallbacks callback) {
|
||||
try {
|
||||
Field field = getClass().getSuperclass().getSuperclass().getDeclaredField("mActivityLifecycleCallbacks");
|
||||
field.setAccessible(true);
|
||||
ArrayList<ActivityLifecycleCallbacks> activityLifecycleCallbacks = (ArrayList<ActivityLifecycleCallbacks>) field.get(this);
|
||||
boolean contain = false;
|
||||
for (ActivityLifecycleCallbacks activityLifecycleCallback : activityLifecycleCallbacks) {
|
||||
if (activityLifecycleCallback.getClass().equals(callback.getClass())) {
|
||||
contain = true;
|
||||
}
|
||||
}
|
||||
if (!contain) {
|
||||
super.registerActivityLifecycleCallbacks(callback);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean showMonitor() {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,114 @@
|
|||
package com.libs.fragment;
|
||||
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
|
||||
import com.trello.rxlifecycle4.LifecycleTransformer;
|
||||
import com.trello.rxlifecycle4.components.RxFragment;
|
||||
|
||||
import java.lang.reflect.ParameterizedType;
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
|
||||
/**
|
||||
* Created by Ming
|
||||
* 2020-09-09
|
||||
*/
|
||||
public abstract class BaseFragment<P extends BasePresenter> extends RxFragment implements BaseView {
|
||||
private View mRootView;
|
||||
private P p;
|
||||
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
|
||||
if (mRootView == null) {
|
||||
mRootView = inflater.inflate(getLayoutId(), container, false);
|
||||
}
|
||||
ViewGroup parent = (ViewGroup) mRootView.getParent();
|
||||
if (parent != null) {
|
||||
parent.removeView(mRootView);
|
||||
}
|
||||
return mRootView;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
initView(view, savedInstanceState);
|
||||
initData();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取布局
|
||||
*/
|
||||
protected abstract int getLayoutId();
|
||||
|
||||
/**
|
||||
* 初始布局
|
||||
*/
|
||||
protected abstract void initView(View view, Bundle savedInstanceState);
|
||||
|
||||
/**
|
||||
* 初始数据
|
||||
*/
|
||||
protected abstract void initData();
|
||||
|
||||
/**
|
||||
* 初始p层
|
||||
*/
|
||||
protected void initPresnter() {
|
||||
p = getInstanceP();
|
||||
if (p != null) {
|
||||
p.attachView(this);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建泛型实例
|
||||
*/
|
||||
private P getInstanceP() {
|
||||
try {
|
||||
Type superclass = getClass().getGenericSuperclass();
|
||||
ParameterizedType parameterizedType = null;
|
||||
if (superclass instanceof ParameterizedType) {
|
||||
parameterizedType = (ParameterizedType) superclass;
|
||||
Type[] typeArray = parameterizedType.getActualTypeArguments();
|
||||
if (typeArray != null && typeArray.length > 0) {
|
||||
Class<P> clazz = (Class<P>) typeArray[0];
|
||||
return clazz.newInstance();
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.e("泛型创建错误", e.toString());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> LifecycleTransformer<T> bindRecycler() {
|
||||
return this.bindToLifecycle();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
super.onDestroyView();
|
||||
if (p != null) {
|
||||
p.detachView();
|
||||
p = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
package com.libs.fragment;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
|
||||
/**
|
||||
* @author Ming
|
||||
* 1/11/21
|
||||
* P层基类
|
||||
*/
|
||||
public class BasePresenter<V extends BaseView> {
|
||||
protected V v;
|
||||
private WeakReference<V> mViewRef;
|
||||
|
||||
public BasePresenter() {
|
||||
|
||||
}
|
||||
|
||||
protected void attachView(V view) {
|
||||
mViewRef = new WeakReference<>(view);
|
||||
v = mViewRef != null ? mViewRef.get() : null;
|
||||
}
|
||||
|
||||
|
||||
protected void detachView() {
|
||||
if (mViewRef != null) {
|
||||
mViewRef.clear();
|
||||
}
|
||||
mViewRef = null;
|
||||
v = null;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
package com.libs.fragment;
|
||||
|
||||
|
||||
import com.trello.rxlifecycle4.LifecycleTransformer;
|
||||
|
||||
/**
|
||||
* @author Ming
|
||||
* 1/11/21
|
||||
* V层基类
|
||||
*/
|
||||
public interface BaseView {
|
||||
<T> LifecycleTransformer<T> bindRecycler();
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
package com.libs.network;
|
||||
|
||||
|
||||
/**
|
||||
* Created by Ming
|
||||
* 2020-09-08
|
||||
*/
|
||||
public interface CallBack<K>{
|
||||
/**
|
||||
* 成功
|
||||
*/
|
||||
void onSuccess(K k);
|
||||
|
||||
/**
|
||||
* 失败
|
||||
*/
|
||||
void onFailed(Throwable e);
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,223 @@
|
|||
package com.libs.network;
|
||||
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
|
||||
import com.libs.network.interceptor.ErrCodeInterceptor;
|
||||
import com.libs.network.interceptor.ErrorCodeCallBack;
|
||||
import com.libs.network.interceptor.HeaderInterceptor;
|
||||
import com.trello.rxlifecycle4.components.RxActivity;
|
||||
import com.trello.rxlifecycle4.components.RxFragment;
|
||||
|
||||
import java.lang.reflect.ParameterizedType;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import autodispose2.AutoDispose;
|
||||
import autodispose2.androidx.lifecycle.AndroidLifecycleScopeProvider;
|
||||
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.rxjava3.annotations.NonNull;
|
||||
import io.reactivex.rxjava3.core.Observable;
|
||||
import io.reactivex.rxjava3.core.Observer;
|
||||
import io.reactivex.rxjava3.schedulers.Schedulers;
|
||||
import okhttp3.Interceptor;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.logging.HttpLoggingInterceptor;
|
||||
import retrofit2.Retrofit;
|
||||
import retrofit2.adapter.rxjava3.RxJava3CallAdapterFactory;
|
||||
import retrofit2.converter.gson.GsonConverterFactory;
|
||||
|
||||
|
||||
/**
|
||||
* @author Ming
|
||||
* 1/20/22
|
||||
*/
|
||||
public class Concise<I> {
|
||||
public I api;
|
||||
private String path;
|
||||
private Executor executor;
|
||||
private boolean showLog = true;
|
||||
private List<Interceptor> interceptorList = new ArrayList<>();
|
||||
private Map<String, String> headMap = new HashMap<>();
|
||||
|
||||
public Concise(String path) {
|
||||
this.path = path;
|
||||
}
|
||||
|
||||
public Concise addHeader(String key, String value) {
|
||||
headMap.put(key, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Map<String, String> getHeadMap() {
|
||||
return headMap;
|
||||
}
|
||||
|
||||
public Concise setToken(String token) {
|
||||
headMap.put("Authorization", token);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Concise setPath(String path) {
|
||||
this.path = path;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Concise showLog(boolean b) {
|
||||
showLog = b;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Concise setThreadPool(Executor executor) {
|
||||
this.executor = executor;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Concise addInterceptors(Interceptor... interceptors) {
|
||||
for (Interceptor interceptor : interceptors) {
|
||||
interceptorList.add(interceptor);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public Concise setErrCodeListener(String errCode, String tokenKey, ErrorCodeCallBack tokenCallBack) {
|
||||
interceptorList.add(new ErrCodeInterceptor(errCode, tokenKey, tokenCallBack));
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getPath() {
|
||||
return path;
|
||||
}
|
||||
|
||||
|
||||
public Concise build() {
|
||||
Class<I> tClass = (Class<I>) ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[0];
|
||||
api = new Retrofit.Builder()
|
||||
.client(createClient())
|
||||
.addConverterFactory(GsonConverterFactory.create())
|
||||
.addCallAdapterFactory(RxJava3CallAdapterFactory.create())
|
||||
.baseUrl(path)
|
||||
.build()
|
||||
.create(tClass);
|
||||
return this;
|
||||
}
|
||||
|
||||
public <S> void request(Observable<S> observable, @NonNull CallBack<S> callBack) {
|
||||
if (callBack != null && observable != null) {
|
||||
initObservable(observable)
|
||||
.subscribe(new DefaultObserver(callBack));
|
||||
}
|
||||
}
|
||||
|
||||
public <S> void request(Fragment fragment, Observable<S> observable, @NonNull CallBack<S> callBack) {
|
||||
if (callBack != null && observable != null) {
|
||||
initObservable(observable)
|
||||
.to(AutoDispose.autoDisposable(AndroidLifecycleScopeProvider.from(fragment)))
|
||||
.subscribe(new DefaultObserver(callBack));
|
||||
}
|
||||
}
|
||||
|
||||
public <S> void request(RxFragment rxFragment, Observable<S> observable, @NonNull CallBack<S> callBack) {
|
||||
if (callBack != null && observable != null) {
|
||||
initObservable(observable)
|
||||
.compose(rxFragment.bindToLifecycle())
|
||||
.subscribe(new DefaultObserver(callBack));
|
||||
}
|
||||
}
|
||||
|
||||
public <S> void request(FragmentActivity activity, Observable<S> observable, @NonNull CallBack<S> callBack) {
|
||||
if (callBack != null && observable != null) {
|
||||
initObservable(observable)
|
||||
.to(AutoDispose.autoDisposable(AndroidLifecycleScopeProvider.from(activity)))
|
||||
.subscribe(new DefaultObserver(callBack));
|
||||
}
|
||||
}
|
||||
|
||||
public <S> void request(RxActivity rxActivity, Observable<S> observable, @NonNull CallBack<S> callBack) {
|
||||
if (callBack != null && observable != null) {
|
||||
initObservable(observable)
|
||||
.compose(rxActivity.bindToLifecycle())
|
||||
.subscribe(new DefaultObserver(callBack));
|
||||
}
|
||||
}
|
||||
|
||||
public <S> void request(Observable<S> observable, @NonNull Observer<S> observer) {
|
||||
if (observer != null) {
|
||||
initObservable(observable)
|
||||
.subscribe(observer);
|
||||
}
|
||||
}
|
||||
|
||||
public <S> void request(Fragment fragment, Observable<S> observable, @NonNull Observer<S> observer) {
|
||||
if (observer != null) {
|
||||
initObservable(observable)
|
||||
.to(AutoDispose.autoDisposable(AndroidLifecycleScopeProvider.from(fragment)))
|
||||
.subscribe(observer);
|
||||
}
|
||||
}
|
||||
|
||||
public <S> void request(RxFragment rxFragment, Observable<S> observable, @NonNull Observer<S> observer) {
|
||||
if (observer != null) {
|
||||
initObservable(observable)
|
||||
.compose(rxFragment.bindToLifecycle())
|
||||
.subscribe(observer);
|
||||
}
|
||||
}
|
||||
|
||||
public <S> void request(FragmentActivity activity, Observable<S> observable, @NonNull Observer<S> observer) {
|
||||
if (observer != null) {
|
||||
initObservable(observable)
|
||||
.to(AutoDispose.autoDisposable(AndroidLifecycleScopeProvider.from(activity)))
|
||||
.subscribe(observer);
|
||||
}
|
||||
}
|
||||
|
||||
public <S> void request(RxActivity rxActivity, Observable<S> observable, @NonNull Observer<S> observer) {
|
||||
if (observer != null) {
|
||||
initObservable(observable)
|
||||
.compose(rxActivity.bindToLifecycle())
|
||||
.subscribe(observer);
|
||||
}
|
||||
}
|
||||
|
||||
private <S> Observable<S> initObservable(Observable<S> observable) {
|
||||
if (executor == null) {
|
||||
return observable
|
||||
.delay(5, TimeUnit.MILLISECONDS)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.unsubscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread());
|
||||
}
|
||||
return observable
|
||||
.subscribeOn(Schedulers.from(executor))
|
||||
.unsubscribeOn(Schedulers.from(executor))
|
||||
.observeOn(AndroidSchedulers.mainThread());
|
||||
}
|
||||
|
||||
|
||||
public OkHttpClient createClient() {
|
||||
OkHttpClient.Builder builder = new OkHttpClient.Builder();
|
||||
//添加拦截器获取log
|
||||
if (showLog) {
|
||||
HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
|
||||
logging.setLevel(HttpLoggingInterceptor.Level.BODY);
|
||||
builder.addInterceptor(logging);
|
||||
for (Interceptor interceptor : interceptorList) {
|
||||
builder.addInterceptor(interceptor);
|
||||
}
|
||||
}
|
||||
if (headMap.size() > 0) {
|
||||
builder.addInterceptor(new HeaderInterceptor(headMap));
|
||||
}
|
||||
builder.dns(new HttpDns());
|
||||
// builder.connectTimeout(outTime, TimeUnit.SECONDS);
|
||||
// builder.readTimeout(outTime, TimeUnit.SECONDS);
|
||||
// builder.writeTimeout(outTime, TimeUnit.SECONDS);
|
||||
// builder.addInterceptor(new TokenInterceptor(tokenKey, token));
|
||||
return builder.build();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
package com.libs.network;
|
||||
|
||||
import io.reactivex.rxjava3.annotations.NonNull;
|
||||
import io.reactivex.rxjava3.core.Observer;
|
||||
import io.reactivex.rxjava3.disposables.Disposable;
|
||||
|
||||
/**
|
||||
* @author Ming
|
||||
* 2/23/22
|
||||
*/
|
||||
public class DefaultObserver<S> implements Observer<S> {
|
||||
private CallBack<S> callBack;
|
||||
|
||||
|
||||
public DefaultObserver(@NonNull CallBack<S> callBack) {
|
||||
this.callBack = callBack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSubscribe(@NonNull Disposable d) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(@NonNull S s) {
|
||||
callBack.onSuccess(s);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(@NonNull Throwable e) {
|
||||
callBack.onFailed(e);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,68 @@
|
|||
package com.libs.network;
|
||||
|
||||
import com.qiniu.android.dns.DnsManager;
|
||||
import com.qiniu.android.dns.IResolver;
|
||||
import com.qiniu.android.dns.NetworkInfo;
|
||||
import com.qiniu.android.dns.local.Resolver;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.FutureTask;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import okhttp3.Dns;
|
||||
|
||||
import static java.net.InetAddress.getAllByName;
|
||||
import static java.net.InetAddress.getByName;
|
||||
|
||||
/**
|
||||
* @author Ming
|
||||
* 7/27/21
|
||||
*/
|
||||
public class HttpDns implements Dns {
|
||||
private DnsManager dnsManager;
|
||||
|
||||
public HttpDns() {
|
||||
IResolver[] resolvers = new IResolver[1];
|
||||
try {
|
||||
resolvers[0] = new Resolver(getByName("119.29.29.29"));
|
||||
dnsManager = new DnsManager(NetworkInfo.normal, resolvers);
|
||||
} catch (UnknownHostException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<InetAddress> lookup(String hostname) throws UnknownHostException {
|
||||
if (dnsManager == null) {
|
||||
return Dns.SYSTEM.lookup(hostname);
|
||||
}
|
||||
|
||||
try {
|
||||
String[] ips = dnsManager.query(hostname);
|
||||
if (ips == null || ips.length == 0) {
|
||||
return Dns.SYSTEM.lookup(hostname);
|
||||
}
|
||||
FutureTask<List<InetAddress>> task = new FutureTask<>(
|
||||
new Callable<List<InetAddress>>() {
|
||||
@Override
|
||||
public List<InetAddress> call() throws Exception {
|
||||
List<InetAddress> result = new ArrayList<>();
|
||||
for (String ip : ips) {
|
||||
result.addAll(Arrays.asList(getAllByName(ip)));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
});
|
||||
new Thread(task).start();
|
||||
return task.get(5000, TimeUnit.MILLISECONDS);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return Dns.SYSTEM.lookup(hostname);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,59 @@
|
|||
package com.libs.network.interceptor;
|
||||
|
||||
import android.text.TextUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
import okhttp3.Interceptor;
|
||||
import okhttp3.MediaType;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
import okhttp3.ResponseBody;
|
||||
import okio.Buffer;
|
||||
import okio.BufferedSource;
|
||||
|
||||
/**
|
||||
* @author Ming
|
||||
* 3/2/22
|
||||
*/
|
||||
public class ErrCodeInterceptor implements Interceptor {
|
||||
private String errCode;
|
||||
private String tokenKey;
|
||||
private ErrorCodeCallBack tokenCallBack;
|
||||
private static final Charset UTF8 = Charset.forName("UTF-8");
|
||||
|
||||
public ErrCodeInterceptor(String errCode, String tokenKey, ErrorCodeCallBack tokenCallBack) {
|
||||
this.errCode = errCode;
|
||||
this.tokenKey = tokenKey;
|
||||
this.tokenCallBack = tokenCallBack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response intercept(Chain chain) throws IOException {
|
||||
Request request = chain.request();
|
||||
Response originalResponse = chain.proceed(request);
|
||||
ResponseBody responseBody = originalResponse.body();
|
||||
BufferedSource source = responseBody.source();
|
||||
source.request(Long.MAX_VALUE);
|
||||
Buffer buffer = source.buffer();
|
||||
Charset charset = UTF8;
|
||||
MediaType contentType = responseBody.contentType();
|
||||
if (contentType != null) {
|
||||
charset = contentType.charset(UTF8);
|
||||
}
|
||||
String bodyString = buffer.clone().readString(charset);
|
||||
if (bodyString.contains(errCode)) {
|
||||
String newToken = tokenCallBack.token();
|
||||
if (TextUtils.isEmpty(newToken)) {
|
||||
return originalResponse;
|
||||
}
|
||||
Request newRequest = request.newBuilder().header(tokenKey, newToken).build();
|
||||
originalResponse.body().close();
|
||||
return chain.proceed(newRequest);
|
||||
}
|
||||
return originalResponse;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
package com.libs.network.interceptor;
|
||||
|
||||
/**
|
||||
* @author Ming
|
||||
* 3/2/22
|
||||
*/
|
||||
public interface ErrorCodeCallBack {
|
||||
String token();
|
||||
}
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
package com.libs.network.interceptor;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
import okhttp3.Interceptor;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
|
||||
|
||||
public class HeaderInterceptor implements Interceptor {
|
||||
private Map<String,String> map;
|
||||
|
||||
public HeaderInterceptor(Map<String,String> map) {
|
||||
this.map = map;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response intercept(Chain chain) throws IOException {
|
||||
Request.Builder builder = chain.request().newBuilder();
|
||||
Iterator<Map.Entry<String, String>> entries = map.entrySet().iterator();
|
||||
while (entries.hasNext()) {
|
||||
Map.Entry<String, String> entry = entries.next();
|
||||
if (entry != null) {
|
||||
builder.addHeader(entry.getKey(),entry.getValue());
|
||||
}
|
||||
}
|
||||
Request interRequest = builder.build();
|
||||
return chain.proceed(interRequest);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,143 @@
|
|||
package com.libs.threadpool;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.libs.threadpool.callback.AsyncCallback;
|
||||
import com.libs.threadpool.callback.OnTaskStart;
|
||||
import com.libs.threadpool.callback.ThreadCallback;
|
||||
import com.libs.utils.DataUtil;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
|
||||
/**
|
||||
* @author Ming
|
||||
* 1/13/21
|
||||
*/
|
||||
public class Pool {
|
||||
/**
|
||||
* 线程池类型
|
||||
*/
|
||||
private int type;
|
||||
private int size = 5;
|
||||
private int time = 0;
|
||||
private String defName = "DefThreadName";
|
||||
private ThreadCallback defCallback;
|
||||
private AsyncCallback defAsyncCallback;
|
||||
private ExecutorService executorServicePool;
|
||||
private ThreadLocal<ThreadConfigs> local;
|
||||
|
||||
public static class Builder {
|
||||
private Pool pool;
|
||||
|
||||
public Builder() {
|
||||
pool = new Pool();
|
||||
}
|
||||
|
||||
public Builder setThreadType(@Type int type) {
|
||||
pool.type = type;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setLog(ThreadCallback threadCallback) {
|
||||
pool.defCallback = threadCallback;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setSize(int size) {
|
||||
pool.size = size;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Pool build() {
|
||||
pool.local = new ThreadLocal<>();
|
||||
pool.executorServicePool = pool.createThreadPool();
|
||||
return pool;
|
||||
}
|
||||
}
|
||||
|
||||
public Pool setName(String name) {
|
||||
defName = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Pool setDelay(int time) {
|
||||
this.time = time;
|
||||
return this;
|
||||
}
|
||||
|
||||
private synchronized ThreadConfigs getThreadConfigs() {
|
||||
ThreadConfigs threadConfigs = local.get();
|
||||
if (threadConfigs == null) {
|
||||
threadConfigs = new ThreadConfigs();
|
||||
threadConfigs.name = defName;
|
||||
threadConfigs.callback = defCallback;
|
||||
threadConfigs.asyncCallback = defAsyncCallback;
|
||||
}
|
||||
return threadConfigs;
|
||||
}
|
||||
|
||||
public Future execute(Runnable runnable, OnTaskStart onTaskStart) {
|
||||
ThreadConfigs configs = getThreadConfigs();
|
||||
runnable = new RunnableWrapper(configs).setRunnable(runnable);
|
||||
local.set(null);
|
||||
return ThreadPoolInternal.getInstance().postDelay(time, executorServicePool, (RunnableWrapper) runnable, onTaskStart);
|
||||
}
|
||||
|
||||
public <T> Future execute(@NonNull Callable<T> callable, AsyncCallback<T> callback, OnTaskStart onTaskStart) {
|
||||
ThreadConfigs configs = getThreadConfigs();
|
||||
configs.asyncCallback = callback;
|
||||
Runnable runnable = new RunnableWrapper(configs).setCallable(callable);
|
||||
local.set(null);
|
||||
return ThreadPoolInternal.getInstance().postDelay(time, executorServicePool, (RunnableWrapper) runnable, onTaskStart);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Executor getThreadPool() {
|
||||
return executorServicePool;
|
||||
}
|
||||
|
||||
/**
|
||||
* 暂停全部任务
|
||||
*/
|
||||
public void stop() {
|
||||
executorServicePool.shutdownNow();
|
||||
}
|
||||
|
||||
/**
|
||||
* 暂停任务
|
||||
*
|
||||
* @param futureList
|
||||
*/
|
||||
public void stop(List<Future> futureList) {
|
||||
if (!DataUtil.isNull(futureList)) {
|
||||
for (Future future : futureList) {
|
||||
if (future != null) {
|
||||
future.cancel(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private synchronized ExecutorService createThreadPool() {
|
||||
switch (type) {
|
||||
case Type.CACHE:
|
||||
return Executors.newCachedThreadPool();
|
||||
case Type.FIXED:
|
||||
return Executors.newFixedThreadPool(size);
|
||||
case Type.SCHEDULED:
|
||||
return Executors.newScheduledThreadPool(size);
|
||||
case Type.SINGLE:
|
||||
return Executors.newSingleThreadExecutor();
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,47 @@
|
|||
package com.libs.threadpool;
|
||||
|
||||
import com.libs.threadpool.callback.MergeCallback;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
/**
|
||||
* @author Ming
|
||||
* 1/13/21
|
||||
*/
|
||||
public class RunnableWrapper implements Runnable {
|
||||
private ThreadConfigs threadConfigs;
|
||||
private MergeCallback mergeCallback;
|
||||
private Runnable runnable;
|
||||
private Callable callable;
|
||||
|
||||
public RunnableWrapper(ThreadConfigs threadConfigs) {
|
||||
this.threadConfigs = threadConfigs;
|
||||
mergeCallback = new MergeCallback(threadConfigs.callback, TranRunnable.getInstance(), threadConfigs.asyncCallback);
|
||||
}
|
||||
|
||||
public RunnableWrapper setRunnable(Runnable runnable) {
|
||||
this.runnable = runnable;
|
||||
return this;
|
||||
}
|
||||
|
||||
public RunnableWrapper setCallable(Callable callable) {
|
||||
this.callable = callable;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
mergeCallback.onStart(threadConfigs.name);
|
||||
try {
|
||||
if (runnable != null) {
|
||||
runnable.run();
|
||||
} else if (callable != null) {
|
||||
Object result = callable.call();
|
||||
mergeCallback.onSuccess(result);
|
||||
}
|
||||
mergeCallback.onCompleted(threadConfigs.name);
|
||||
} catch (Exception e) {
|
||||
mergeCallback.onError(threadConfigs.name, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,43 @@
|
|||
package com.libs.threadpool;
|
||||
|
||||
import com.libs.utils.DataUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
|
||||
/**
|
||||
* @author Ming
|
||||
* 7/29/21
|
||||
*/
|
||||
public class TaskBean {
|
||||
private List<Future> futureList;
|
||||
|
||||
public TaskBean() {
|
||||
futureList = new ArrayList<>();
|
||||
}
|
||||
|
||||
public void addFuture(Future future) {
|
||||
futureList.add(future);
|
||||
}
|
||||
|
||||
public void removeFuture(Future future) {
|
||||
futureList.remove(future);
|
||||
}
|
||||
|
||||
public void stopTask() {
|
||||
if (!DataUtil.isNull(futureList)) {
|
||||
for (Future future : futureList) {
|
||||
future.cancel(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "TaskBean{" +
|
||||
"futureList=" + futureList.toString() +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
package com.libs.threadpool;
|
||||
|
||||
|
||||
import com.libs.threadpool.callback.AsyncCallback;
|
||||
import com.libs.threadpool.callback.ThreadCallback;
|
||||
|
||||
/**
|
||||
* @author Ming
|
||||
* 1/13/21
|
||||
*/
|
||||
public final class ThreadConfigs {
|
||||
|
||||
/**
|
||||
* 线程的名称
|
||||
*/
|
||||
public String name;
|
||||
/**
|
||||
* 线程执行延迟的时间
|
||||
*/
|
||||
public long delay;
|
||||
|
||||
/**
|
||||
* 用户任务的状态回调callback
|
||||
*/
|
||||
public ThreadCallback callback;
|
||||
|
||||
/**
|
||||
* 异步callback回调callback
|
||||
*/
|
||||
public AsyncCallback asyncCallback;
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,156 @@
|
|||
package com.libs.threadpool;
|
||||
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.libs.fragment.BaseApplication;
|
||||
import com.libs.threadpool.callback.AsyncCallback;
|
||||
import com.libs.threadpool.callback.OnTaskStart;
|
||||
import com.libs.utils.LogUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
/**
|
||||
* 线程池管理类
|
||||
*
|
||||
* @author Ming
|
||||
* 7/29/21
|
||||
*/
|
||||
public class ThreadManager {
|
||||
private Map<Integer, List<TaskBean>> futureMap = new HashMap<>();
|
||||
|
||||
/**
|
||||
* 添加Future
|
||||
*
|
||||
* @param object
|
||||
* @param taskBeans
|
||||
*/
|
||||
public void add(Object object, TaskBean... taskBeans) {
|
||||
if (futureMap.containsKey(object.hashCode())) {
|
||||
List<TaskBean> taskBeanList = futureMap.get(object.hashCode());
|
||||
for (TaskBean taskBean : taskBeans) {
|
||||
taskBeanList.add(taskBean);
|
||||
}
|
||||
} else {
|
||||
List<TaskBean> taskBeanList = new ArrayList<>();
|
||||
for (TaskBean taskBean : taskBeans) {
|
||||
taskBeanList.add(taskBean);
|
||||
}
|
||||
futureMap.put(object.hashCode(), taskBeanList);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 移除Future
|
||||
*
|
||||
* @param object
|
||||
* @param taskBeans
|
||||
*/
|
||||
public void remove(Object object, TaskBean... taskBeans) {
|
||||
if (futureMap.containsKey(object.hashCode())) {
|
||||
List<TaskBean> taskBeanList = futureMap.get(object.hashCode());
|
||||
for (TaskBean taskBean : taskBeans) {
|
||||
taskBean.stopTask();
|
||||
taskBeanList.remove(taskBean);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 移除批量Future
|
||||
*
|
||||
* @param object
|
||||
*/
|
||||
public void remove(Object object) {
|
||||
if (futureMap.containsKey(object.hashCode())) {
|
||||
for (TaskBean taskBean : futureMap.get(object.hashCode())) {
|
||||
taskBean.stopTask();
|
||||
}
|
||||
futureMap.remove(object.hashCode());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 非延迟任务
|
||||
*
|
||||
* @param runnable
|
||||
*/
|
||||
public TaskBean execute(Object obj, Runnable runnable) {
|
||||
TaskBean taskBean = new TaskBean();
|
||||
Future mainFuture = BaseApplication.getInstance().getExecutor().execute(runnable, null);
|
||||
taskBean.addFuture(mainFuture);
|
||||
add(obj.hashCode(), taskBean);
|
||||
return taskBean;
|
||||
}
|
||||
|
||||
/**
|
||||
* 延迟任务
|
||||
*
|
||||
* @param delay
|
||||
* @param runnable
|
||||
*/
|
||||
public TaskBean execute(Object obj, int delay, Runnable runnable) {
|
||||
TaskBean taskBean = new TaskBean();
|
||||
Future mainFuture = BaseApplication.getInstance().getExecutor().setDelay(delay).execute(runnable, new OnTaskStart() {
|
||||
@Override
|
||||
public void onStart(Future future) {
|
||||
LogUtil.e("耗时操作");
|
||||
taskBean.addFuture(future);
|
||||
}
|
||||
});
|
||||
taskBean.addFuture(mainFuture);
|
||||
add(obj.hashCode(), taskBean);
|
||||
return taskBean;
|
||||
}
|
||||
|
||||
/**
|
||||
* 非延迟任务
|
||||
*
|
||||
* @param callable
|
||||
* @param callback
|
||||
* @param <T>
|
||||
*/
|
||||
public <T> TaskBean execute(Object obj, @NonNull Callable<T> callable, AsyncCallback<T> callback) {
|
||||
TaskBean taskBean = new TaskBean();
|
||||
Future mainFuture = BaseApplication.getInstance().getExecutor().execute(callable, callback, null);
|
||||
mainFuture.cancel(true);
|
||||
taskBean.addFuture(mainFuture);
|
||||
add(obj.hashCode(), taskBean);
|
||||
return taskBean;
|
||||
}
|
||||
|
||||
/**
|
||||
* 延迟任务
|
||||
*
|
||||
* @param delay
|
||||
* @param callable
|
||||
* @param callback
|
||||
* @param <T>
|
||||
*/
|
||||
public <T> TaskBean execute(Object obj, int delay, @NonNull Callable<T> callable, AsyncCallback<T> callback) {
|
||||
TaskBean taskBean = new TaskBean();
|
||||
Future mainFuture = BaseApplication.getInstance().getExecutor().setDelay(delay).execute(callable, callback, new OnTaskStart() {
|
||||
@Override
|
||||
public void onStart(Future future) {
|
||||
LogUtil.e("耗时操作");
|
||||
taskBean.addFuture(future);
|
||||
}
|
||||
});
|
||||
taskBean.addFuture(mainFuture);
|
||||
add(obj.hashCode(), taskBean);
|
||||
return taskBean;
|
||||
}
|
||||
|
||||
public static ThreadManager getInstance() {
|
||||
return ThreadManagerHolder.mInstance;
|
||||
}
|
||||
|
||||
private static class ThreadManagerHolder {
|
||||
private final static ThreadManager mInstance = new ThreadManager();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,56 @@
|
|||
package com.libs.threadpool;
|
||||
|
||||
import com.libs.threadpool.callback.OnTaskStart;
|
||||
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.ThreadFactory;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* @author Ming
|
||||
* 1/13/21
|
||||
*/
|
||||
public class ThreadPoolInternal {
|
||||
private ScheduledExecutorService dispatcher;
|
||||
private volatile Future future;
|
||||
|
||||
private ThreadPoolInternal() {
|
||||
dispatcher = Executors.newScheduledThreadPool(1, new ThreadFactory() {
|
||||
@Override
|
||||
public Thread newThread(Runnable runnable) {
|
||||
Thread thread = new Thread(runnable);
|
||||
thread.setName("Delay-Thread");
|
||||
thread.setPriority(Thread.MAX_PRIORITY);
|
||||
return thread;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static ThreadPoolInternal getInstance() {
|
||||
return ThreadPoolInternalHolder.mInstance;
|
||||
}
|
||||
|
||||
public Future post(final ExecutorService pool, final RunnableWrapper task) {
|
||||
return pool.submit(task);
|
||||
}
|
||||
|
||||
public Future postDelay(long delay, final ExecutorService pool, final RunnableWrapper task, OnTaskStart onTaskStart) {
|
||||
if (delay == 0) {
|
||||
return post(pool, task);
|
||||
}
|
||||
Future delayFuture = dispatcher.schedule(() -> {
|
||||
future = pool.submit(task);
|
||||
onTaskStart.onStart(future);
|
||||
// task.setOnStartListener(future);
|
||||
}, delay, TimeUnit.MILLISECONDS);
|
||||
return delayFuture;
|
||||
}
|
||||
|
||||
|
||||
private static class ThreadPoolInternalHolder {
|
||||
private final static ThreadPoolInternal mInstance = new ThreadPoolInternal();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
package com.libs.threadpool;
|
||||
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
/**
|
||||
* @author Ming
|
||||
* 1/13/21
|
||||
*/
|
||||
public class TranRunnable implements Executor {
|
||||
private Handler main = new Handler(Looper.getMainLooper());
|
||||
|
||||
public static TranRunnable getInstance() {
|
||||
return TranRunnableHolder.mInstance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(Runnable runnable) {
|
||||
if (Looper.myLooper() == Looper.getMainLooper() && runnable != null) {
|
||||
runnable.run();
|
||||
return;
|
||||
}
|
||||
main.post(() -> {
|
||||
if (runnable != null) {
|
||||
runnable.run();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static class TranRunnableHolder {
|
||||
private final static TranRunnable mInstance = new TranRunnable();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
package com.libs.threadpool;
|
||||
|
||||
import androidx.annotation.IntDef;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
/**
|
||||
* @author ming
|
||||
* 1/13/21
|
||||
*/
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
@IntDef({Type.FIXED, Type.CACHE, Type.SCHEDULED, Type.SINGLE})
|
||||
public @interface Type {
|
||||
/**
|
||||
* 线程数量固定的线程池,全部为核心线程,响应较快,不用担心线程会被回收。
|
||||
*/
|
||||
int FIXED = 0;
|
||||
/**
|
||||
* 它是一个数量无限多的线程池,都是非核心线程,适合执行大量耗时小的任务
|
||||
*/
|
||||
int CACHE = 1;
|
||||
/**
|
||||
* 有数量固定的核心线程,且有数量无限多的非核心线程,适合用于执行定时任务和固定周期的重复任务
|
||||
*/
|
||||
int SCHEDULED = 2;
|
||||
/**
|
||||
* 有数量固定的核心线程,且有数量无限多的非核心线程,适合用于执行定时任务和固定周期的重复任务
|
||||
*/
|
||||
int SINGLE = 3;
|
||||
}
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
package com.libs.threadpool.callback;
|
||||
|
||||
|
||||
/**
|
||||
* @author Ming
|
||||
* 1/13/21
|
||||
*/
|
||||
public interface AsyncCallback<T> {
|
||||
|
||||
/**
|
||||
* 开始执行回调
|
||||
*
|
||||
* @param threadName
|
||||
*/
|
||||
void onStart(String threadName);
|
||||
|
||||
/**
|
||||
* 成功时调用
|
||||
*
|
||||
* @param t
|
||||
*/
|
||||
void onSuccess(T t);
|
||||
|
||||
/**
|
||||
* 异常时调用
|
||||
*
|
||||
* @param t 异常
|
||||
*/
|
||||
void onFailed(Throwable t);
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
package com.libs.threadpool.callback;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
/**
|
||||
* @author Ming
|
||||
* 1/13/21
|
||||
*/
|
||||
public class DefLogCallBack implements ThreadCallback {
|
||||
private final String TAG = "DefLogCallBack";
|
||||
|
||||
@Override
|
||||
public void onError(String name, Throwable t) {
|
||||
Log.i(TAG, "------onError" + "-----" + name + "----" + Thread.currentThread() + "----" + t.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCompleted(String name) {
|
||||
Log.i(TAG, "------onCompleted" + "-----" + name + "----" + Thread.currentThread());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart(String threadName) {
|
||||
Log.i(TAG, "------onStart" + "-----" + threadName + "----" + Thread.currentThread());
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,98 @@
|
|||
package com.libs.threadpool.callback;
|
||||
|
||||
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
/**
|
||||
* @author Ming
|
||||
* 1/13/21
|
||||
*/
|
||||
public final class MergeCallback implements ThreadCallback, AsyncCallback {
|
||||
|
||||
|
||||
private ThreadCallback callback;
|
||||
private AsyncCallback async;
|
||||
private Executor deliver;
|
||||
|
||||
public MergeCallback(ThreadCallback callback, Executor deliver, AsyncCallback async) {
|
||||
this.callback = callback;
|
||||
this.deliver = deliver;
|
||||
this.async = async;
|
||||
}
|
||||
|
||||
/**
|
||||
* 回调成功
|
||||
*
|
||||
* @param o
|
||||
*/
|
||||
@Override
|
||||
public void onSuccess(final Object o) {
|
||||
if (async == null) {
|
||||
return;
|
||||
}
|
||||
deliver.execute(() -> {
|
||||
try {
|
||||
async.onSuccess(o);
|
||||
} catch (Throwable t) {
|
||||
onFailed(t);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 回调失败
|
||||
*
|
||||
* @param t 异常
|
||||
*/
|
||||
@Override
|
||||
public void onFailed(final Throwable t) {
|
||||
if (async == null) {
|
||||
return;
|
||||
}
|
||||
deliver.execute(() -> async.onFailed(t));
|
||||
}
|
||||
|
||||
/**
|
||||
* 回调异常
|
||||
*
|
||||
* @param name 线程name
|
||||
* @param t 异常
|
||||
*/
|
||||
@Override
|
||||
public void onError(final String name, final Throwable t) {
|
||||
onFailed(t);
|
||||
if (callback == null) {
|
||||
return;
|
||||
}
|
||||
deliver.execute(() -> callback.onError(name, t));
|
||||
}
|
||||
|
||||
/**
|
||||
* 回调完成
|
||||
*
|
||||
* @param name 线程name
|
||||
*/
|
||||
@Override
|
||||
public void onCompleted(final String name) {
|
||||
if (callback == null) {
|
||||
return;
|
||||
}
|
||||
deliver.execute(() -> callback.onCompleted(name));
|
||||
}
|
||||
|
||||
/**
|
||||
* 回调开始
|
||||
*
|
||||
* @param threadName 线程name
|
||||
*/
|
||||
@Override
|
||||
public void onStart(final String threadName) {
|
||||
if (async != null) {
|
||||
async.onStart(threadName);
|
||||
}
|
||||
if (callback == null) {
|
||||
return;
|
||||
}
|
||||
deliver.execute(() -> callback.onStart(threadName));
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
package com.libs.threadpool.callback;
|
||||
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
/**
|
||||
* @author Ming
|
||||
* 7/29/21
|
||||
*/
|
||||
public interface OnTaskStart {
|
||||
void onStart(Future future);
|
||||
}
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
package com.libs.threadpool.callback;
|
||||
|
||||
/**
|
||||
* @author Ming
|
||||
* 1/13/21
|
||||
*/
|
||||
public interface ThreadCallback {
|
||||
|
||||
/**
|
||||
* 当线程发生错误时,将调用此方法。
|
||||
*
|
||||
* @param threadName 正在运行线程的名字
|
||||
* @param t 异常
|
||||
*/
|
||||
void onError(String threadName, Throwable t);
|
||||
|
||||
/**
|
||||
* 通知用户知道它已经完成
|
||||
*
|
||||
* @param threadName 正在运行线程的名字
|
||||
*/
|
||||
void onCompleted(String threadName);
|
||||
|
||||
/**
|
||||
* 通知用户任务开始运行
|
||||
*/
|
||||
void onStart(String threadName);
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,172 @@
|
|||
package com.libs.utils;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.util.Log;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Stack;
|
||||
|
||||
|
||||
public class ActivityManager {
|
||||
private static Stack<Activity> activityStack;
|
||||
private static ActivityManager instance;
|
||||
/**
|
||||
* 行为轨迹
|
||||
*/
|
||||
private static List<Activity> behaviorTrackList;
|
||||
|
||||
private ActivityManager() {
|
||||
}
|
||||
|
||||
public static ActivityManager getInstance() {
|
||||
if (instance == null) {
|
||||
instance = new ActivityManager();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将指定activity压入栈中
|
||||
*
|
||||
* @param activity
|
||||
*/
|
||||
public void pushActivity(Activity activity) {
|
||||
if (activityStack == null) {
|
||||
activityStack = new Stack<>();
|
||||
}
|
||||
// 防止重复入栈
|
||||
if (!activityStack.contains(activity)) {
|
||||
activityStack.add(activity);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 销毁最顶层的activity
|
||||
*/
|
||||
public void popActivity() {
|
||||
Activity activity = activityStack.lastElement();
|
||||
popActivity(activity);
|
||||
}
|
||||
|
||||
/**
|
||||
* 销毁指定activity
|
||||
*
|
||||
* @param activity
|
||||
*/
|
||||
public void popActivity(Activity activity) {
|
||||
if (activity != null) {
|
||||
activityStack.remove(activity);
|
||||
if (!activity.isFinishing()) {
|
||||
activity.finish();
|
||||
}
|
||||
activity = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回最顶层activity实例
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public Activity currentActivity() {
|
||||
Activity activity = null;
|
||||
if (activityStack != null && !activityStack.isEmpty()) {
|
||||
activity = activityStack.lastElement();
|
||||
}
|
||||
return activity;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断栈中是否有某个Activity
|
||||
*
|
||||
* @param cls
|
||||
* @return
|
||||
*/
|
||||
public boolean hasActivity(Class<Activity> cls) {
|
||||
for (Activity act : activityStack) {
|
||||
if (act.getComponentName().getClassName().equals(cls.getName())) {
|
||||
Log.i("ScreenManager", cls.getName() + " is found.");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回栈中某个Activity
|
||||
*
|
||||
* @param cls
|
||||
* @return
|
||||
*/
|
||||
private Activity getActivity(Class<Activity> cls) {
|
||||
for (Activity act : activityStack) {
|
||||
if (act.getComponentName().getClassName().equals(cls.getName())) {
|
||||
Log.i("ScreenManager", cls.getName() + " is found.");
|
||||
return act;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 除了指定activity其余的全部销毁
|
||||
*
|
||||
* @param cls
|
||||
*/
|
||||
public void popAllActivityExceptOne(Class cls) {
|
||||
while (true) {
|
||||
Activity activity = currentActivity();
|
||||
if (activity == null) {
|
||||
break;
|
||||
}
|
||||
if (cls != null && activity.getClass().getName().equals(cls.getName())) {
|
||||
break;
|
||||
}
|
||||
popActivity(activity);
|
||||
}
|
||||
}
|
||||
|
||||
public void popActivities(Class... clss) {
|
||||
int len = clss.length;
|
||||
for (Class cls : clss) {
|
||||
Activity activity = getActivity(cls);
|
||||
if (activity != null) {
|
||||
popActivity(activity);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void startActivity(Activity activity, Class<?> cls) {
|
||||
activity.startActivity(new Intent(activity, cls));
|
||||
}
|
||||
|
||||
public Activity isAppShow() {
|
||||
Stack<Activity> activityStacks = activityStack;
|
||||
if (!DataUtil.isNull(activityStacks)) {
|
||||
for (Activity activity : activityStacks) {
|
||||
try {
|
||||
Method isResumed = activity.getClass().getMethod("isResumed");
|
||||
boolean resumed = (boolean) isResumed.invoke(activity, new Object[]{});
|
||||
if (resumed == true) {
|
||||
return activity;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public void behaviorTrack(Activity activity) {
|
||||
if (behaviorTrackList == null) {
|
||||
behaviorTrackList = new ArrayList<>();
|
||||
}
|
||||
behaviorTrackList.add(activity);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,85 @@
|
|||
package com.libs.utils;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.Stack;
|
||||
|
||||
/**
|
||||
* @author Ming
|
||||
* 7/21/21
|
||||
*/
|
||||
public class DataUtil {
|
||||
|
||||
public static boolean isNull(Object object) {
|
||||
if (object == null) {
|
||||
return true;
|
||||
}
|
||||
if (object instanceof List) {
|
||||
if (((List) object).size() == 0) {
|
||||
return true;
|
||||
}
|
||||
} else if (object instanceof Stack) {
|
||||
if (((Stack) object).size() == 0) {
|
||||
return true;
|
||||
}
|
||||
} else if (object instanceof Map) {
|
||||
if (((Map) object).size() == 0) {
|
||||
return true;
|
||||
}
|
||||
} else if (object instanceof Set) {
|
||||
if (((Set) object).size() == 0) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static int getLength(Object obj) {
|
||||
if (obj == null) {
|
||||
return 0;
|
||||
}
|
||||
if (obj instanceof List) {
|
||||
return ((List) obj).size();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
public static Object getData(Object obj, int position) {
|
||||
if (obj == null) {
|
||||
return null;
|
||||
}
|
||||
if (obj instanceof List) {
|
||||
return ((List) obj).get(position);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public static Object mergeList(List... lists) {
|
||||
if (lists == null) {
|
||||
return null;
|
||||
}
|
||||
if (lists.length == 0) {
|
||||
return null;
|
||||
}
|
||||
List<Object> list = new ArrayList<>();
|
||||
for (List l : lists) {
|
||||
list.add(l);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public static Double divide(int n1, int n2) {
|
||||
if (n1 == 0 || n2 == 0) {
|
||||
return 0.0;
|
||||
}
|
||||
BigDecimal all = new BigDecimal(n1);
|
||||
BigDecimal num = new BigDecimal(n2);
|
||||
BigDecimal average = all.divide(num, 3, BigDecimal.ROUND_HALF_UP);
|
||||
return average.doubleValue();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,210 @@
|
|||
package com.libs.utils;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.IntDef;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.Stack;
|
||||
|
||||
/**
|
||||
* @author Ming
|
||||
* 1/26/21
|
||||
*/
|
||||
public class LogUtil {
|
||||
private final static String TAG = "——————————| log |—————————— Thread";
|
||||
private final static String EMPTY = "-";
|
||||
|
||||
public static void v(Object object) {
|
||||
LogUtilInternal(LogType.v, object, EMPTY);
|
||||
}
|
||||
|
||||
public static void v(Object tag, Object object) {
|
||||
LogUtilInternal(LogType.v, tag, object);
|
||||
}
|
||||
|
||||
public static void d(Object object) {
|
||||
LogUtilInternal(LogType.d, object, EMPTY);
|
||||
}
|
||||
|
||||
public static void d(Object tag, Object object) {
|
||||
LogUtilInternal(LogType.d, tag, object);
|
||||
}
|
||||
|
||||
public static void i(Object object) {
|
||||
LogUtilInternal(LogType.i, object, EMPTY);
|
||||
}
|
||||
|
||||
public static void i(Object tag, Object object) {
|
||||
LogUtilInternal(LogType.i, tag, object);
|
||||
}
|
||||
|
||||
public static void w(Object object) {
|
||||
LogUtilInternal(LogType.w, object, EMPTY);
|
||||
}
|
||||
|
||||
public static void w(Object tag, Object object) {
|
||||
LogUtilInternal(LogType.w, tag, object);
|
||||
}
|
||||
|
||||
public static void e(Object object) {
|
||||
LogUtilInternal(LogType.e, object, EMPTY);
|
||||
}
|
||||
|
||||
public static void e(Object tag, Object object) {
|
||||
LogUtilInternal(LogType.e, tag, object);
|
||||
}
|
||||
|
||||
@SuppressLint("LongLogTag")
|
||||
private static void LogUtilInternal(@LogType int type, Object key, Object value) {
|
||||
String logKey = "Thread: " + Thread.currentThread().getName();
|
||||
String keyStr = getString(key);
|
||||
String valueStr = "";
|
||||
if (!EMPTY.equals(value)) {
|
||||
valueStr = getString(value);
|
||||
}
|
||||
StringBuffer logStr = new StringBuffer();
|
||||
logStr.append(Thread.currentThread().getName());
|
||||
StringBuffer keySpace = new StringBuffer();
|
||||
StringBuffer valueSpace = new StringBuffer();
|
||||
if (keyStr.length() > valueStr.length()) {
|
||||
for (int i = 0; i < keyStr.length() - valueStr.length(); i++) {
|
||||
valueSpace.append(" ");
|
||||
}
|
||||
} else if (keyStr.length() < valueStr.length()) {
|
||||
for (int i = 0; i < valueStr.length() - keyStr.length(); i++) {
|
||||
keySpace.append(" ");
|
||||
}
|
||||
}
|
||||
keySpace.append("\t\t\t\t");
|
||||
valueSpace.append("\t\t\t\t");
|
||||
|
||||
String keyClz = "";
|
||||
if (key != null) {
|
||||
if (key.getClass() != null) {
|
||||
keyClz = key.getClass().getName();
|
||||
}
|
||||
}
|
||||
|
||||
String valueClz = "";
|
||||
if (value != null) {
|
||||
if (value.getClass() != null) {
|
||||
valueClz = value.getClass().getName();
|
||||
}
|
||||
}
|
||||
|
||||
if (!EMPTY.equals(keyStr)) {
|
||||
logStr.append("\n" + "K : " + keyStr + keySpace + "ClassName:" + keyClz);
|
||||
}
|
||||
if (!EMPTY.equals(value)) {
|
||||
if (EMPTY.equals(valueStr)) {
|
||||
logStr.append("\n" + "V : " + "");
|
||||
} else {
|
||||
logStr.append("\n" + "V : " + valueStr + valueSpace + "ClassName:" + valueClz);
|
||||
}
|
||||
}
|
||||
switch (type) {
|
||||
case LogType.v:
|
||||
Log.v(logKey, TAG);
|
||||
Log.v(getString(key), getString(value));
|
||||
break;
|
||||
case LogType.d:
|
||||
Log.d(logKey, TAG);
|
||||
Log.d(getString(key), getString(value));
|
||||
break;
|
||||
case LogType.i:
|
||||
Log.i(logKey, TAG);
|
||||
Log.i(getString(key), getString(value));
|
||||
break;
|
||||
case LogType.w:
|
||||
Log.w(logKey, TAG);
|
||||
Log.w(getString(key), getString(value));
|
||||
break;
|
||||
case LogType.e:
|
||||
Log.e(TAG, logStr.toString());
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
@IntDef({LogType.v, LogType.d, LogType.i, LogType.w, LogType.e})
|
||||
private @interface LogType {
|
||||
int v = 0;
|
||||
int d = 1;
|
||||
int i = 2;
|
||||
int w = 3;
|
||||
int e = 4;
|
||||
}
|
||||
|
||||
private static String getString(Object object) {
|
||||
StringBuffer stringBuffer = new StringBuffer();
|
||||
if (object == null) {
|
||||
stringBuffer.append("null");
|
||||
} else if (object instanceof List) {
|
||||
for (Object o : (List) object) {
|
||||
if (o != null) {
|
||||
stringBuffer.append(o.toString());
|
||||
stringBuffer.append(",");
|
||||
}
|
||||
}
|
||||
} else if (object instanceof Set) {
|
||||
for (Object o : (Set) object) {
|
||||
if (o != null) {
|
||||
stringBuffer.append(o.toString());
|
||||
stringBuffer.append(",");
|
||||
}
|
||||
}
|
||||
} else if (object instanceof Map) {
|
||||
Iterator<Map.Entry<Integer, Integer>> entries = ((Map) object).entrySet().iterator();
|
||||
while (entries.hasNext()) {
|
||||
Map.Entry<Integer, Integer> entry = entries.next();
|
||||
if (entry != null) {
|
||||
stringBuffer.append("Key = ");
|
||||
stringBuffer.append(entry.getKey());
|
||||
stringBuffer.append(",Value = ");
|
||||
stringBuffer.append(entry.getValue());
|
||||
stringBuffer.append("; ");
|
||||
}
|
||||
}
|
||||
} else if (object instanceof Stack) {
|
||||
for (Object o : (Stack) object) {
|
||||
stringBuffer.append(o.toString());
|
||||
stringBuffer.append(",");
|
||||
}
|
||||
} else if (object instanceof String) {
|
||||
if (object.equals("")) {
|
||||
stringBuffer.append(EMPTY);
|
||||
} else {
|
||||
stringBuffer.append((String) object);
|
||||
}
|
||||
} else if (object instanceof Class) {
|
||||
if (object.equals("")) {
|
||||
stringBuffer.append(EMPTY);
|
||||
} else {
|
||||
stringBuffer.append(((Class) object).getName());
|
||||
}
|
||||
} else if (object instanceof Object[]) {
|
||||
Object[] objects = (Object[]) object;
|
||||
stringBuffer.append("[");
|
||||
if (objects.length != 0) {
|
||||
for (Object o : objects) {
|
||||
stringBuffer.append(o.toString());
|
||||
}
|
||||
}
|
||||
stringBuffer.append("]");
|
||||
} else {
|
||||
stringBuffer.append(object.toString());
|
||||
}
|
||||
return stringBuffer.toString();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
package com.libs.utils;
|
||||
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
|
||||
/**
|
||||
* @author Ming
|
||||
* 7/16/21
|
||||
*/
|
||||
public class MainLooper extends Handler {
|
||||
private static MainLooper instance = new MainLooper(Looper.getMainLooper());
|
||||
|
||||
protected MainLooper(Looper looper) {
|
||||
super(looper);
|
||||
}
|
||||
|
||||
public static MainLooper getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
public static void runOnUiThread(Runnable runnable) {
|
||||
if (Looper.getMainLooper().equals(Looper.myLooper())) {
|
||||
runnable.run();
|
||||
} else {
|
||||
instance.post(runnable);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,194 @@
|
|||
package com.libs.utils;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Point;
|
||||
import android.os.Build;
|
||||
import android.util.TypedValue;
|
||||
import android.view.Display;
|
||||
import android.view.View;
|
||||
import android.view.Window;
|
||||
import android.view.WindowManager;
|
||||
|
||||
/**
|
||||
* Created by Ming
|
||||
* 2020-08-18
|
||||
*/
|
||||
public class ScreenUtil {
|
||||
|
||||
/**
|
||||
* dp转px
|
||||
*/
|
||||
@Deprecated
|
||||
public static int dp2px(Context context, float dpValue) {
|
||||
final float scale = context.getResources().getDisplayMetrics().density;
|
||||
return (int) (dpValue * scale + 0.5f);
|
||||
}
|
||||
|
||||
/**
|
||||
* dp转px
|
||||
*/
|
||||
public static float dp2px(float dpValue) {
|
||||
return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dpValue, Resources.getSystem().getDisplayMetrics());
|
||||
}
|
||||
|
||||
/**
|
||||
* px转dp
|
||||
*/
|
||||
public static int px2dp(Context context, float pxValue) {
|
||||
final float scale = context.getResources().getDisplayMetrics().density;
|
||||
return (int) (pxValue / scale + 0.5f);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 获取屏幕宽度
|
||||
*/
|
||||
public static int getScreenWidth(Activity activity) {
|
||||
Display defaultDisplay = activity.getWindowManager().getDefaultDisplay();
|
||||
Point point = new Point();
|
||||
defaultDisplay.getSize(point);
|
||||
return point.x;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取屏幕宽度
|
||||
*/
|
||||
public static int getScreenWidth(WindowManager windowManager) {
|
||||
Display defaultDisplay = windowManager.getDefaultDisplay();
|
||||
Point point = new Point();
|
||||
defaultDisplay.getSize(point);
|
||||
return point.x;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取屏幕高度 不包含StatusBar 不包含NavigationBar
|
||||
*/
|
||||
public static int getScreenHeight(Activity activity) {
|
||||
Display defaultDisplay = activity.getWindowManager().getDefaultDisplay();
|
||||
Point point = new Point();
|
||||
defaultDisplay.getSize(point);
|
||||
return point.y;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取屏幕高度 不包含StatusBar 不包含NavigationBar
|
||||
*/
|
||||
public static int getScreenHeight(WindowManager windowManager) {
|
||||
Display defaultDisplay = windowManager.getDefaultDisplay();
|
||||
Point point = new Point();
|
||||
defaultDisplay.getSize(point);
|
||||
return point.y;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取状态栏高度
|
||||
*/
|
||||
public static int getStatusBarHeight(Activity context) {
|
||||
Resources resources = context.getResources();
|
||||
int resourceId = resources.getIdentifier("status_bar_height", "dimen", "android");
|
||||
int height = resources.getDimensionPixelSize(resourceId);
|
||||
return height;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取标题栏
|
||||
*/
|
||||
public static int getContentTopHeight(Activity context) {
|
||||
int contentTop = context.getWindow().findViewById(Window.ID_ANDROID_CONTENT).getTop();
|
||||
return contentTop - getStatusBarHeight(context);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取虚拟按键的高度
|
||||
*/
|
||||
public static int getNavigationBarHeight(Context context) {
|
||||
int result = 0;
|
||||
Resources res = context.getResources();
|
||||
if (isNavigationBar(res)) {
|
||||
int resourceId = res.getIdentifier("navigation_bar_height", "dimen", "android");
|
||||
if (resourceId > 0) {
|
||||
result = res.getDimensionPixelSize(resourceId);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否有虚拟按键
|
||||
*/
|
||||
public static boolean isNavigationBar(Resources resources) {
|
||||
int id = resources.getIdentifier("config_showNavigationBar", "bool", "android");
|
||||
return id > 0 && resources.getBoolean(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过设置全屏,设置状态栏透明
|
||||
*
|
||||
* @param activity
|
||||
*/
|
||||
private void fullScreen(Activity activity) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
//5.x开始需要把颜色设置透明,否则导航栏会呈现系统默认的浅灰色
|
||||
Window window = activity.getWindow();
|
||||
View decorView = window.getDecorView();
|
||||
//两个 flag 要结合使用,表示让应用的主体内容占用系统状态栏的空间
|
||||
int option = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
|
||||
| View.SYSTEM_UI_FLAG_LAYOUT_STABLE;
|
||||
decorView.setSystemUiVisibility(option);
|
||||
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
|
||||
window.setStatusBarColor(Color.TRANSPARENT);
|
||||
//导航栏颜色也可以正常设置
|
||||
// window.setNavigationBarColor(Color.TRANSPARENT);
|
||||
} else {
|
||||
Window window = activity.getWindow();
|
||||
WindowManager.LayoutParams attributes = window.getAttributes();
|
||||
int flagTranslucentStatus = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS;
|
||||
int flagTranslucentNavigation = WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION;
|
||||
attributes.flags |= flagTranslucentStatus;
|
||||
// attributes.flags |= flagTranslucentNavigation;
|
||||
window.setAttributes(attributes);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static int getActionBarHeight(Context context) {
|
||||
TypedValue tv = new TypedValue();
|
||||
int actionBarHeight = 0;
|
||||
if (context.getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true)) {
|
||||
actionBarHeight = TypedValue.complexToDimensionPixelSize(tv.data, context.getResources().getDisplayMetrics());
|
||||
}
|
||||
return actionBarHeight;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取View的位置,其中高度包含状态栏
|
||||
*
|
||||
* @param view
|
||||
* @return
|
||||
*/
|
||||
public static int[] getViewLocation(View view) {
|
||||
int[] windowLocation = new int[2];
|
||||
view.getLocationOnScreen(windowLocation);
|
||||
return windowLocation;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取ToolBar高度
|
||||
*
|
||||
* @param activity
|
||||
* @return
|
||||
*/
|
||||
public static int getToolBarHeight(Activity activity) {
|
||||
TypedValue tv = new TypedValue();
|
||||
int actionBarHeight = 0;
|
||||
if (activity.getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true)) {
|
||||
actionBarHeight = TypedValue.complexToDimensionPixelSize(tv.data, activity.getResources().getDisplayMetrics());
|
||||
}
|
||||
return actionBarHeight;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,38 @@
|
|||
package com.libs.utils;
|
||||
|
||||
import android.view.Gravity;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.libs.fragment.BaseApplication;
|
||||
|
||||
|
||||
/**
|
||||
* @author Ming
|
||||
* 1/25/21
|
||||
*/
|
||||
public class ToastUtil {
|
||||
private static Toast toast;
|
||||
|
||||
public static void longToast(String text) {
|
||||
toastInternal(text, Toast.LENGTH_LONG);
|
||||
}
|
||||
|
||||
public static void shortToast(String text) {
|
||||
toastInternal(text, Toast.LENGTH_SHORT);
|
||||
}
|
||||
|
||||
private static void toastInternal(String text, int toastType) {
|
||||
MainLooper.runOnUiThread(() -> {
|
||||
if (toast != null) {
|
||||
toast.cancel();
|
||||
}
|
||||
toast = Toast.makeText(BaseApplication.getInstance(), text, toastType);
|
||||
toast.show();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,246 @@
|
|||
package com.libs.views.toolbar;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.TypedArray;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.DrawableRes;
|
||||
import androidx.annotation.LayoutRes;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.core.content.ContextCompat;
|
||||
|
||||
import com.libs.R;
|
||||
import com.libs.utils.ScreenUtil;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
/**
|
||||
* @author Ming
|
||||
* 1/12/21
|
||||
*/
|
||||
public class CommonToolBar extends RelativeLayout {
|
||||
private LinearLayout left_view;
|
||||
private LinearLayout center_view;
|
||||
private LinearLayout right_view;
|
||||
private OnToolBarClick onToolBarClick;
|
||||
private Map<String, View> viewMap = new HashMap<>();
|
||||
|
||||
private final int PADDINGHEIGHT = ScreenUtil.dp2px(getContext(), 7);
|
||||
|
||||
private int PADDING;
|
||||
|
||||
public CommonToolBar(@NonNull Context context) {
|
||||
this(context, null);
|
||||
}
|
||||
|
||||
public CommonToolBar(@NonNull Context context, @Nullable AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
initAttr(attrs);
|
||||
initView();
|
||||
}
|
||||
|
||||
private void initAttr(AttributeSet attrs) {
|
||||
if (attrs != null) {
|
||||
TypedArray arr = getContext().obtainStyledAttributes(attrs, R.styleable.CommonToolBar);
|
||||
PADDING = ScreenUtil.dp2px(getContext(), arr.getInt(R.styleable.CommonToolBar_space, 7));
|
||||
arr.recycle();
|
||||
}
|
||||
}
|
||||
|
||||
private void initView() {
|
||||
View view = LayoutInflater.from(getContext()).inflate(R.layout.commontoolbar, this, true);
|
||||
left_view = view.findViewById(R.id.left_view);
|
||||
center_view = view.findViewById(R.id.center_view);
|
||||
right_view = view.findViewById(R.id.right_view);
|
||||
}
|
||||
|
||||
/**
|
||||
* 左侧添加图片
|
||||
*
|
||||
* @param tag tag
|
||||
* @param drawRes 图片资源
|
||||
*/
|
||||
public void setLeftImg(String tag, @DrawableRes int drawRes) {
|
||||
ImageView imageView = new ImageView(getContext());
|
||||
imageView.setImageDrawable(ContextCompat.getDrawable(getContext(), drawRes));
|
||||
addViewInternal(left_view, imageView, tag);
|
||||
}
|
||||
|
||||
/**
|
||||
* 左侧添加文本
|
||||
*
|
||||
* @param tag tag
|
||||
* @param text 文本
|
||||
*/
|
||||
public void setLeftText(String tag, String text) {
|
||||
TextView textView = new TextView(getContext());
|
||||
textView.setText(text);
|
||||
addViewInternal(left_view, textView, tag);
|
||||
}
|
||||
|
||||
/**
|
||||
* 左侧添加view
|
||||
*
|
||||
* @param tag tag tag
|
||||
* @param view view view
|
||||
*/
|
||||
public void setLeftView(String tag, View view) {
|
||||
addViewInternal(left_view, view, tag);
|
||||
}
|
||||
|
||||
/**
|
||||
* 左侧添加布局
|
||||
*
|
||||
* @param tag tag
|
||||
* @param layout 布局id
|
||||
*/
|
||||
public void setLeftView(String tag, @LayoutRes int layout) {
|
||||
addViewByLayout(left_view, layout, tag);
|
||||
}
|
||||
|
||||
/**
|
||||
* 中心添加图片
|
||||
*
|
||||
* @param tag tag
|
||||
* @param drawRes 图片资源
|
||||
*/
|
||||
public void setCenterImg(String tag, @DrawableRes int drawRes) {
|
||||
ImageView imageView = new ImageView(getContext());
|
||||
imageView.setImageDrawable(ContextCompat.getDrawable(getContext(), drawRes));
|
||||
addViewInternal(center_view, imageView, tag);
|
||||
}
|
||||
|
||||
/**
|
||||
* 中心添加文本
|
||||
*
|
||||
* @param tag tag
|
||||
* @param text 文本
|
||||
*/
|
||||
public void setCenterText(String tag, String text) {
|
||||
TextView textView = new TextView(getContext());
|
||||
textView.setText(text);
|
||||
addViewInternal(center_view, textView, tag);
|
||||
}
|
||||
|
||||
/**
|
||||
* 中心添加view
|
||||
*
|
||||
* @param tag tag
|
||||
* @param view view
|
||||
*/
|
||||
public void setCenterView(String tag, View view) {
|
||||
addViewInternal(center_view, view, tag);
|
||||
}
|
||||
|
||||
/**
|
||||
* 中心添加布局
|
||||
*
|
||||
* @param tag tag
|
||||
* @param layout 布局id
|
||||
*/
|
||||
public void setCenterView(String tag, @LayoutRes int layout) {
|
||||
addViewByLayout(center_view, layout, tag);
|
||||
}
|
||||
|
||||
/**
|
||||
* 右侧添加图片
|
||||
*
|
||||
* @param tag tag
|
||||
* @param drawRes 图片资源
|
||||
*/
|
||||
public void setRightImg(String tag, @DrawableRes int drawRes) {
|
||||
ImageView imageView = new ImageView(getContext());
|
||||
imageView.setImageDrawable(ContextCompat.getDrawable(getContext(), drawRes));
|
||||
addViewInternal(right_view, imageView, tag);
|
||||
}
|
||||
|
||||
/**
|
||||
* 右侧添加文本
|
||||
*
|
||||
* @param tag tag
|
||||
* @param text 文本
|
||||
*/
|
||||
public void setRightText(String tag, String text) {
|
||||
TextView textView = new TextView(getContext());
|
||||
textView.setText(text);
|
||||
addViewInternal(right_view, textView, tag);
|
||||
}
|
||||
|
||||
/**
|
||||
* 右侧添加view
|
||||
*
|
||||
* @param tag tag
|
||||
* @param view view
|
||||
*/
|
||||
public void setRightView(String tag, View view) {
|
||||
addViewInternal(right_view, view, tag);
|
||||
}
|
||||
|
||||
/**
|
||||
* 右侧添加布局
|
||||
*
|
||||
* @param tag tag
|
||||
* @param layout 布局id
|
||||
*/
|
||||
public void setRightView(String tag, @LayoutRes int layout) {
|
||||
addViewByLayout(right_view, layout, tag);
|
||||
}
|
||||
|
||||
/**
|
||||
* 点击事件
|
||||
*
|
||||
* @param onToolBarClick
|
||||
*/
|
||||
public void setOnToolBarClickListener(OnToolBarClick onToolBarClick) {
|
||||
this.onToolBarClick = onToolBarClick;
|
||||
}
|
||||
|
||||
private void addViewByLayout(ViewGroup viewGroup, int layout, String tag) {
|
||||
View view = LayoutInflater.from(getContext()).inflate(layout, null, false);
|
||||
addViewInternal(viewGroup, view, tag);
|
||||
}
|
||||
|
||||
public View getView(String tag) {
|
||||
return viewMap.get(tag);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加view
|
||||
*
|
||||
* @param viewGroup 父view
|
||||
* @param view 子view
|
||||
*/
|
||||
private void addViewInternal(ViewGroup viewGroup, View view, String tag) {
|
||||
viewMap.put(tag, view);
|
||||
viewGroup.addView(view);
|
||||
if (viewGroup == left_view && left_view.getChildCount() == 1) {
|
||||
view.setPadding(0, PADDINGHEIGHT, PADDING, PADDINGHEIGHT);
|
||||
} else if (viewGroup == right_view) {
|
||||
for (int i = 0; i < right_view.getChildCount(); i++) {
|
||||
View v = right_view.getChildAt(i);
|
||||
if (i != right_view.getChildCount() - 1) {
|
||||
v.setPadding(PADDING, PADDINGHEIGHT, PADDING, PADDINGHEIGHT);
|
||||
} else {
|
||||
v.setPadding(PADDING, PADDINGHEIGHT, 0, PADDINGHEIGHT);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
view.setPadding(PADDING, PADDINGHEIGHT, PADDING, PADDINGHEIGHT);
|
||||
}
|
||||
view.setOnClickListener(v -> {
|
||||
if (onToolBarClick != null) {
|
||||
onToolBarClick.onClick(view, tag);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||