[function]基础功能
|
|
@ -1,5 +1,7 @@
|
|||
plugins {
|
||||
id 'com.android.application'
|
||||
id 'kotlin-android'
|
||||
id 'kotlin-android-extensions'
|
||||
}
|
||||
|
||||
android {
|
||||
|
|
|
|||
|
|
@ -24,18 +24,27 @@
|
|||
android:exported="true" />
|
||||
<activity android:name=".activity.HostActivity" />
|
||||
<activity android:name=".activity.NetActivity" />
|
||||
<activity android:name=".activity.SplashActivity"
|
||||
<activity
|
||||
android:name=".activity.SplashActivity"
|
||||
android:theme="@style/AppTheme.SplashTheme">
|
||||
|
||||
</activity>
|
||||
<activity android:name=".activity.grade.GradeActivity" />
|
||||
<activity android:name=".activity.clasz.ClassActivity" />
|
||||
<activity android:name=".activity.list.ListActivity" />
|
||||
<activity android:name=".activity.detail.DetailActivity" />
|
||||
<activity
|
||||
android:name=".activity.home.HomeActivity"
|
||||
android:screenOrientation="landscape">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity android:name=".activity.grade.GradeActivity" />
|
||||
<activity android:name=".activity.clasz.ClassActivity" />
|
||||
<activity android:name=".activity.list.ListActivity" />
|
||||
<activity android:name=".activity.detail.DetailActivity" />
|
||||
<activity
|
||||
android:name=".activity.setting.SettingActivity"
|
||||
android:screenOrientation="landscape" />
|
||||
|
||||
<service
|
||||
android:name="com.loop.loopminisdk.LoopMini"
|
||||
|
|
|
|||
|
|
@ -0,0 +1,28 @@
|
|||
package com.skipping
|
||||
|
||||
/**
|
||||
* @author Ming
|
||||
* 3/25/22
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* url路径
|
||||
*/
|
||||
const val BASE_URL = "https://api.xintijiao.com/ijustjump/"
|
||||
const val CLASS = "class"
|
||||
const val GRADE = "grade"
|
||||
const val UNFINISHED = "未完成"
|
||||
/**
|
||||
* 账号
|
||||
*/
|
||||
const val ACCOUNT = "account"
|
||||
/**
|
||||
* 密码
|
||||
*/
|
||||
const val PASSWORD = "password"
|
||||
/**
|
||||
* token
|
||||
*/
|
||||
const val TOKEN = "token"
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
package com.skipping.activity
|
||||
|
||||
import com.libs.fragment.BaseView
|
||||
|
||||
/**
|
||||
* @author Ming
|
||||
* 3/24/22
|
||||
*
|
||||
*/
|
||||
interface IView :BaseView {
|
||||
}
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
package com.skipping.activity;
|
||||
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ import com.skipping.activity.list.ListActivity;
|
|||
import com.skipping.net.API;
|
||||
import com.skipping.net.BaseBean;
|
||||
import com.skipping.net.GradleBean;
|
||||
import com.skipping.utils.ErrorToken;
|
||||
import com.tencent.mmkv.MMKV;
|
||||
|
||||
import java.util.List;
|
||||
|
|
@ -58,7 +59,8 @@ public class ClassActivity extends BaseActivity {
|
|||
|
||||
MMKV kv = MMKV.defaultMMKV();
|
||||
concise = new Concise<API>(Contants.BASE_URL) {
|
||||
}.addHeader("Token", kv.decodeString(Contants.TOKEN)).build();
|
||||
}.addHeader("Token", kv.decodeString(Contants.TOKEN));
|
||||
ErrorToken.intercept(this, concise);
|
||||
concise.request(ClassActivity.this, concise.api.getClass(id), new CallBack<BaseBean<List<GradleBean>>>() {
|
||||
@Override
|
||||
public void onSuccess(BaseBean<List<GradleBean>> listBaseBean) {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
package com.skipping.activity.detail;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
|
|
@ -12,15 +12,15 @@ import com.libs.network.CallBack;
|
|||
import com.libs.network.Concise;
|
||||
import com.skipping.Contants;
|
||||
import com.skipping.R;
|
||||
import com.skipping.activity.NetActivity;
|
||||
import com.skipping.activity.clasz.ClassActivity;
|
||||
import com.skipping.activity.grade.GradeActivity;
|
||||
import com.skipping.activity.grade.GradeAdapter;
|
||||
import com.skipping.net.API;
|
||||
import com.skipping.net.BaseBean;
|
||||
import com.skipping.net.DetailActivityBean;
|
||||
import com.skipping.utils.ConnectManager;
|
||||
import com.skipping.utils.ErrorToken;
|
||||
import com.skipping.utils.ThreadPoolUtil;
|
||||
import com.tencent.mmkv.MMKV;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
|
|
@ -32,6 +32,8 @@ public class DetailActivity extends BaseActivity {
|
|||
private TextView name, idTV;
|
||||
private RecyclerView recyclerview;
|
||||
private DetailAdapter adapter;
|
||||
private Button open, connect, msg;
|
||||
private ConnectManager connectManager;
|
||||
|
||||
@Override
|
||||
protected int getContentViewResId() {
|
||||
|
|
@ -43,32 +45,98 @@ public class DetailActivity extends BaseActivity {
|
|||
idTV = findViewById(R.id.id);
|
||||
name = findViewById(R.id.name);
|
||||
recyclerview = findViewById(R.id.recyclerview);
|
||||
open = findViewById(R.id.open);
|
||||
connect = findViewById(R.id.connect);
|
||||
msg = findViewById(R.id.msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initData() {
|
||||
connectManager = new ConnectManager(this);
|
||||
String id = (String) getIntent().getBundleExtra("id").get("id");
|
||||
recyclerview.setLayoutManager(new LinearLayoutManager(this));
|
||||
adapter = new DetailAdapter(recyclerview);
|
||||
recyclerview.setAdapter(adapter);
|
||||
|
||||
adapter.setOnClickListener(new DetailAdapter.OnClick() {
|
||||
@Override
|
||||
public void click(int position) {
|
||||
connectManager.pairDevice(position);
|
||||
}
|
||||
});
|
||||
MMKV kv = MMKV.defaultMMKV();
|
||||
concise = new Concise<API>(Contants.BASE_URL) {
|
||||
}.addHeader("Token", kv.decodeString(Contants.TOKEN)).build();
|
||||
concise.request(DetailActivity.this, concise.api.detailActivity(id), new CallBack<BaseBean<DetailActivityBean>>() {
|
||||
@Override
|
||||
public void onSuccess(BaseBean<DetailActivityBean> listBaseBean) {
|
||||
idTV.setText(listBaseBean.getData().getId() + "");
|
||||
name.setText(listBaseBean.getData().getActivityName() + "");
|
||||
adapter.setData(listBaseBean.getData().getCandidates().get(0));
|
||||
adapter.notifyDataSetChanged();
|
||||
}.addHeader("Token", kv.decodeString(Contants.TOKEN));
|
||||
ErrorToken.intercept(this, concise);
|
||||
// concise.request(DetailActivity.this, concise.api.detailActivity(id), new CallBack<BaseBean<DetailActivityBean>>() {
|
||||
// @Override
|
||||
// public void onSuccess(BaseBean<DetailActivityBean> listBaseBean) {
|
||||
// idTV.setText(listBaseBean.getData().getId() + "");
|
||||
// name.setText(listBaseBean.getData().getActivityName() + "");
|
||||
// adapter.setData(listBaseBean.getData().getCandidates().get(0));
|
||||
// adapter.notifyDataSetChanged();
|
||||
//
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onFailed(Throwable e) {
|
||||
//
|
||||
// }
|
||||
// });
|
||||
|
||||
List<DetailActivityBean.CandidatesBean> list = new ArrayList<>();
|
||||
DetailActivityBean.CandidatesBean bean1 = new DetailActivityBean.CandidatesBean();
|
||||
bean1.setName("1111");
|
||||
bean1.setPersonID("11111");
|
||||
bean1.setScore(1);
|
||||
bean1.setStudentID("111");
|
||||
list.add(bean1);
|
||||
DetailActivityBean.CandidatesBean bean2 = new DetailActivityBean.CandidatesBean();
|
||||
bean2.setName("1111");
|
||||
bean2.setPersonID("11111");
|
||||
bean2.setScore(1);
|
||||
bean2.setStudentID("111");
|
||||
list.add(bean2);
|
||||
adapter.setData(list);
|
||||
adapter.notifyDataSetChanged();
|
||||
open.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
connectManager.getHostInfo();
|
||||
connectManager.openPairMode();
|
||||
}
|
||||
});
|
||||
|
||||
connect.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onFailed(Throwable e) {
|
||||
public void onClick(View v) {
|
||||
connectManager.closePairMode();
|
||||
connectManager.connectDevice();
|
||||
}
|
||||
});
|
||||
|
||||
msg.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
ThreadPoolUtil.getSingleton().scheduleAtFixedRate(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
connectManager.getpower();
|
||||
}
|
||||
}, 0, 20);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
connectManager.resume();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
connectManager.pause();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -44,6 +44,12 @@ public class DetailAdapter extends RecyclerView.Adapter<DetailAdapter.RecyclerHo
|
|||
holder.id.setText("ID:" + list.get(position).getPersonID());
|
||||
holder.studentid.setText("学生ID:" + list.get(position).getStudentID());
|
||||
holder.score.setText("分数:" + list.get(position).getScore());
|
||||
holder.itemView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
onClick.click(position);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -68,7 +74,7 @@ public class DetailAdapter extends RecyclerView.Adapter<DetailAdapter.RecyclerHo
|
|||
}
|
||||
|
||||
public interface OnClick {
|
||||
void click(String id);
|
||||
void click(int position);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -16,6 +16,7 @@ import com.skipping.activity.clasz.ClassActivity;
|
|||
import com.skipping.net.API;
|
||||
import com.skipping.net.BaseBean;
|
||||
import com.skipping.net.GradleBean;
|
||||
import com.skipping.utils.ErrorToken;
|
||||
import com.tencent.mmkv.MMKV;
|
||||
|
||||
import java.util.List;
|
||||
|
|
@ -57,7 +58,8 @@ public class GradeActivity extends BaseActivity {
|
|||
|
||||
MMKV kv = MMKV.defaultMMKV();
|
||||
concise = new Concise<API>(Contants.BASE_URL) {
|
||||
}.addHeader("Token", kv.decodeString(Contants.TOKEN)).build();
|
||||
}.addHeader("Token", kv.decodeString(Contants.TOKEN));
|
||||
ErrorToken.intercept(this, concise);
|
||||
concise.request(GradeActivity.this, concise.api.getGrade(), new CallBack<BaseBean<List<GradleBean>>>() {
|
||||
@Override
|
||||
public void onSuccess(BaseBean<List<GradleBean>> listBaseBean) {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,35 @@
|
|||
package com.skipping.activity.home
|
||||
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import com.libs.fragment.BaseActivity
|
||||
import com.skipping.R
|
||||
import com.skipping.activity.setting.SettingActivity
|
||||
import com.skipping.utils.ScreenUtil
|
||||
import kotlinx.android.synthetic.main.activity_home.*
|
||||
|
||||
/**
|
||||
* @author Ming
|
||||
* 3/24/22
|
||||
*
|
||||
*/
|
||||
class HomeActivity : BaseActivity<HomePresenter>() {
|
||||
override fun getContentViewResId(): Int {
|
||||
return R.layout.activity_home
|
||||
}
|
||||
|
||||
override fun initView() {
|
||||
initPresnter()
|
||||
}
|
||||
|
||||
override fun initData() {
|
||||
setting_btn.setOnClickListener {
|
||||
startActivity(Intent(this@HomeActivity, SettingActivity::class.java))
|
||||
}
|
||||
}
|
||||
|
||||
override fun initStart() {
|
||||
ScreenUtil.setCustomDensity(this)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
package com.skipping.activity.home
|
||||
|
||||
import android.os.Parcel
|
||||
import android.os.Parcelable
|
||||
import com.libs.fragment.BasePresenter
|
||||
import com.skipping.activity.IView
|
||||
|
||||
/**
|
||||
* @author Ming
|
||||
* 3/24/22
|
||||
*
|
||||
*/
|
||||
class HomePresenter() :BasePresenter<IView>() {
|
||||
|
||||
}
|
||||
|
|
@ -21,6 +21,7 @@ import com.skipping.net.ActivityBean;
|
|||
import com.skipping.net.ActivityReqBean;
|
||||
import com.skipping.net.BaseBean;
|
||||
import com.skipping.net.GradleBean;
|
||||
import com.skipping.utils.ErrorToken;
|
||||
import com.tencent.mmkv.MMKV;
|
||||
|
||||
import java.util.List;
|
||||
|
|
@ -63,7 +64,8 @@ public class ListActivity extends BaseActivity {
|
|||
|
||||
MMKV kv = MMKV.defaultMMKV();
|
||||
concise = new Concise<API>(Contants.BASE_URL) {
|
||||
}.addHeader("Token", kv.decodeString(Contants.TOKEN)).build();
|
||||
}.addHeader("Token", kv.decodeString(Contants.TOKEN));
|
||||
ErrorToken.intercept(this, concise);
|
||||
ActivityReqBean bean = new ActivityReqBean();
|
||||
bean.setGenre(Contants.CLASS);
|
||||
bean.setActivityType("timing");
|
||||
|
|
|
|||
|
|
@ -0,0 +1,68 @@
|
|||
package com.skipping.activity.setting
|
||||
|
||||
import androidx.fragment.app.Fragment
|
||||
import com.libs.fragment.BaseActivity
|
||||
import com.skipping.R
|
||||
import com.skipping.fragment.login.LoginFragment
|
||||
import com.skipping.fragment.pair.PairFragment
|
||||
import kotlinx.android.synthetic.main.activity_setting.*
|
||||
|
||||
/**
|
||||
* @author Ming
|
||||
* 3/24/22
|
||||
*
|
||||
*/
|
||||
class SettingActivity : BaseActivity<SettingPresenter>() {
|
||||
var position = -1;
|
||||
lateinit var fragment: Fragment
|
||||
|
||||
override fun getContentViewResId(): Int {
|
||||
return R.layout.activity_setting
|
||||
}
|
||||
|
||||
override fun initView() {
|
||||
}
|
||||
|
||||
override fun initData() {
|
||||
clickPair()
|
||||
pair.setOnClickListener {
|
||||
clickPair()
|
||||
}
|
||||
login.setOnClickListener {
|
||||
clickLogin()
|
||||
}
|
||||
back.setOnClickListener {
|
||||
finish()
|
||||
}
|
||||
}
|
||||
|
||||
private fun clickPair(){
|
||||
if (position == 0) {
|
||||
return
|
||||
}
|
||||
position = 0
|
||||
pair.setBackgroundResource(R.color.color_434343)
|
||||
login.setBackgroundResource(R.color.color_2C2C2C)
|
||||
showFragment()
|
||||
}
|
||||
|
||||
private fun clickLogin(){
|
||||
if (position == 1) {
|
||||
return
|
||||
}
|
||||
position = 1
|
||||
login.setBackgroundResource(R.color.color_434343)
|
||||
pair.setBackgroundResource(R.color.color_2C2C2C)
|
||||
showFragment()
|
||||
}
|
||||
|
||||
|
||||
private fun showFragment() {
|
||||
if (position == 0) {
|
||||
fragment = PairFragment()
|
||||
} else if (position == 1) {
|
||||
fragment = LoginFragment()
|
||||
}
|
||||
supportFragmentManager.beginTransaction().replace(R.id.fragment, fragment).commitAllowingStateLoss();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
package com.skipping.activity.setting
|
||||
|
||||
import android.os.Parcel
|
||||
import android.os.Parcelable
|
||||
import com.libs.fragment.BasePresenter
|
||||
import com.skipping.activity.IView
|
||||
|
||||
/**
|
||||
* @author Ming
|
||||
* 3/24/22
|
||||
*
|
||||
*/
|
||||
class SettingPresenter() :BasePresenter<IView>() {
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
package com.skipping.fragment.login
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import com.libs.fragment.BaseFragment
|
||||
import com.libs.utils.ToastUtil
|
||||
import com.skipping.R
|
||||
import kotlinx.android.synthetic.main.fragment_login.*
|
||||
|
||||
/**
|
||||
* @author Ming
|
||||
* 3/24/22
|
||||
*
|
||||
*/
|
||||
class LoginFragment : BaseFragment<LoginPresenter>() {
|
||||
override fun getLayoutId(): Int {
|
||||
return R.layout.fragment_login;
|
||||
}
|
||||
|
||||
override fun initView(view: View?, savedInstanceState: Bundle?) {
|
||||
initPresnter()
|
||||
}
|
||||
|
||||
override fun initData() {
|
||||
login.setOnClickListener {
|
||||
p.login(account.text.toString(), password.text.toString())
|
||||
}
|
||||
}
|
||||
|
||||
fun loginResult() {
|
||||
connectStatusTV.visibility = View.VISIBLE
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,49 @@
|
|||
package com.skipping.fragment.login
|
||||
|
||||
import android.provider.SyncStateContract
|
||||
import com.libs.fragment.BasePresenter
|
||||
import com.libs.network.CallBack
|
||||
import com.libs.network.Concise
|
||||
import com.libs.utils.LogUtil
|
||||
import com.libs.utils.ToastUtil
|
||||
import com.skipping.*
|
||||
import com.skipping.net.API
|
||||
import com.skipping.net.BaseBean
|
||||
import com.skipping.net.TokenBean
|
||||
import com.skipping.net.TokenReqBean
|
||||
import com.tencent.mmkv.MMKV
|
||||
|
||||
|
||||
/**
|
||||
* @author Ming
|
||||
* 3/24/22
|
||||
*
|
||||
*/
|
||||
class LoginPresenter : BasePresenter<LoginFragment>() {
|
||||
companion object {
|
||||
|
||||
}
|
||||
|
||||
fun login(key: String, value: String) {
|
||||
val tokenConcise: Concise<API> = object : Concise<API>(BASE_URL) {}.build() as Concise<API>
|
||||
val tokenReqBean = TokenReqBean()
|
||||
tokenReqBean.deviceID = "466e9c"
|
||||
tokenReqBean.logName = key
|
||||
tokenReqBean.logPwd = value
|
||||
tokenConcise.request(v, tokenConcise.api.token(tokenReqBean), object : CallBack<BaseBean<TokenBean>> {
|
||||
override fun onSuccess(k: BaseBean<TokenBean>?) {
|
||||
val mmkv = MMKV.defaultMMKV()
|
||||
mmkv?.encode(ACCOUNT, key)
|
||||
mmkv?.encode(PASSWORD, value)
|
||||
mmkv?.encode(TOKEN, k?.data?.token)
|
||||
v.loginResult()
|
||||
}
|
||||
|
||||
override fun onFailed(e: Throwable?) {
|
||||
ToastUtil.longToast("连接失败")
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,48 @@
|
|||
package com.skipping.fragment.pair
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import androidx.core.content.ContextCompat
|
||||
import com.libs.fragment.BaseFragment
|
||||
import com.skipping.R
|
||||
import kotlinx.android.synthetic.main.fragment_pair.*
|
||||
|
||||
/**
|
||||
* @author Ming
|
||||
* 3/24/22
|
||||
*
|
||||
*/
|
||||
class PairFragment : BaseFragment<PairPresenter>() {
|
||||
var position = 0
|
||||
override fun getLayoutId(): Int {
|
||||
return R.layout.fragment_pair;
|
||||
}
|
||||
|
||||
override fun initView(view: View?, savedInstanceState: Bundle?) {
|
||||
|
||||
pair_btn.setOnClickListener {
|
||||
if (position == 0) {
|
||||
return@setOnClickListener
|
||||
}
|
||||
position = 0
|
||||
pair_btn.setBackgroundResource(R.drawable.pair_btn_clicked)
|
||||
pair_btn.setTextColor(ContextCompat.getColor(activity!!, R.color.black))
|
||||
connect_btn.setBackgroundResource(R.drawable.connect_btn_unclicked)
|
||||
connect_btn.setTextColor(ContextCompat.getColor(activity!!, R.color.white))
|
||||
}
|
||||
|
||||
connect_btn.setOnClickListener {
|
||||
if (position == 1) {
|
||||
return@setOnClickListener
|
||||
}
|
||||
position = 1
|
||||
pair_btn.setBackgroundResource(R.drawable.pair_btn_unclicked)
|
||||
pair_btn.setTextColor(ContextCompat.getColor(activity!!, R.color.white))
|
||||
connect_btn.setBackgroundResource(R.drawable.connect_btn_clicked)
|
||||
connect_btn.setTextColor(ContextCompat.getColor(activity!!, R.color.black))
|
||||
}
|
||||
}
|
||||
|
||||
override fun initData() {
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
package com.skipping.fragment.pair
|
||||
|
||||
import com.libs.fragment.BasePresenter
|
||||
import com.skipping.activity.IView
|
||||
|
||||
/**
|
||||
* @author Ming
|
||||
* 3/24/22
|
||||
*
|
||||
*/
|
||||
class PairPresenter :BasePresenter<IView>(){
|
||||
}
|
||||
|
|
@ -0,0 +1,228 @@
|
|||
package com.skipping.utils;
|
||||
|
||||
import android.app.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.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.activity.HostActivity;
|
||||
|
||||
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/21/22
|
||||
*/
|
||||
public class ConnectManager {
|
||||
private LoopMini loopMax;
|
||||
private Set<LoopDevice> loopDeviceSet = new HashSet<>();
|
||||
private LoopDevice loopDevice;
|
||||
private EditText editText;
|
||||
private LoopHost loopHost;
|
||||
private Activity activity;
|
||||
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;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
public ConnectManager(Activity activity) {
|
||||
this.activity = activity;
|
||||
mHandler = new MyHandler();
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* 连接主机
|
||||
*/
|
||||
public void getHostInfo() {
|
||||
loopMax.getHostInfo();
|
||||
}
|
||||
|
||||
/**
|
||||
* 开启配对模式
|
||||
*/
|
||||
public void openPairMode() {
|
||||
loopMax.openPairMode();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取电量
|
||||
*/
|
||||
public void getpower() {
|
||||
loopMax.getPower();
|
||||
}
|
||||
|
||||
/**
|
||||
* 关闭配对模式
|
||||
*/
|
||||
public void closePairMode() {
|
||||
loopMax.closePairMode();
|
||||
}
|
||||
|
||||
/**
|
||||
* 匹配设备到指定id
|
||||
*
|
||||
* @param id
|
||||
*/
|
||||
public void pairDevice(int id) {
|
||||
loopMax.pairDevice(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 连接设备
|
||||
*/
|
||||
public void connectDevice() {
|
||||
connectDeviceInner(loopDevice -> loopMax.connectDevice(loopDevice));
|
||||
}
|
||||
|
||||
public void disconnectDevice() {
|
||||
connectDeviceInner(loopDevice -> loopMax.disconnectDevice(loopDevice));
|
||||
}
|
||||
|
||||
|
||||
public void connectDeviceInner(HostActivity.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);
|
||||
}
|
||||
|
||||
|
||||
public void resume(){
|
||||
setFilters();
|
||||
startService(usbConnection);
|
||||
}
|
||||
|
||||
|
||||
public void pause(){
|
||||
activity.unregisterReceiver(mUsbReceiver);
|
||||
activity.unbindService(usbConnection);
|
||||
}
|
||||
|
||||
|
||||
private void startService(ServiceConnection serviceConnection) {
|
||||
if (!LoopMini.SERVICE_CONNECTED) {
|
||||
Intent startService = new Intent(activity, LoopMini.class);
|
||||
activity.startService(startService);
|
||||
}
|
||||
Intent bindingIntent = new Intent(activity, LoopMini.class);
|
||||
activity.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);
|
||||
activity.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,27 @@
|
|||
package com.skipping.utils;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
|
||||
import com.libs.network.Concise;
|
||||
import com.libs.network.interceptor.ErrorCodeCallBack;
|
||||
import com.skipping.Contants;
|
||||
import com.skipping.activity.SplashActivity;
|
||||
import com.skipping.net.API;
|
||||
|
||||
/**
|
||||
* @author Ming
|
||||
* 3/21/22
|
||||
*/
|
||||
public class ErrorToken {
|
||||
public static <T> void intercept(Activity activity,Concise<T> concise) {
|
||||
concise.setErrCodeListener("token无效", new ErrorCodeCallBack() {
|
||||
@Override
|
||||
public void token() {
|
||||
Intent intent = new Intent(activity, SplashActivity.class);
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
activity.startActivity(intent);
|
||||
}
|
||||
}).build();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
package com.skipping.utils
|
||||
|
||||
import android.app.Activity
|
||||
|
||||
/**
|
||||
* @author Ming
|
||||
* 3/24/22
|
||||
*
|
||||
*/
|
||||
object ScreenUtil {
|
||||
fun setCustomDensity(activity: Activity) {
|
||||
activity.resources.displayMetrics.apply {
|
||||
val targetDensity = (widthPixels / 1680).toFloat()
|
||||
density = targetDensity
|
||||
scaledDensity = targetDensity
|
||||
densityDpi = 160 * targetDensity.toInt()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<corners android:radius="42.5dp"/>
|
||||
<solid android:color="@color/color_F7FFF300" />
|
||||
</shape>
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<corners android:radius="36dp"/>
|
||||
<solid android:color="@color/color_F4EA2A" />
|
||||
</shape>
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<corners android:radius="36dp"/>
|
||||
<solid android:color="@color/color_3d3d3d" />
|
||||
</shape>
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<corners
|
||||
android:topRightRadius="22.5dp"
|
||||
android:bottomRightRadius="22.5dp"/>
|
||||
<solid android:color="@color/color_FFF300" />
|
||||
</shape>
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<corners
|
||||
android:topRightRadius="22.5dp"
|
||||
android:bottomRightRadius="22.5dp"/>
|
||||
<solid android:color="@color/black" />
|
||||
</shape>
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<corners android:radius="6dp" />
|
||||
<stroke
|
||||
android:width="2dp"
|
||||
android:color="@color/color_D9D9D9" />
|
||||
<solid android:color="@color/white" />
|
||||
</shape>
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<corners
|
||||
android:topRightRadius="80dp"
|
||||
android:bottomRightRadius="80dp"/>
|
||||
<solid android:color="@color/color_2C2C2C" />
|
||||
</shape>
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<corners
|
||||
android:topLeftRadius="22.5dp"
|
||||
android:bottomLeftRadius="22.5dp"/>
|
||||
<solid android:color="@color/color_FFF300" />
|
||||
</shape>
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<corners
|
||||
android:topLeftRadius="22.5dp"
|
||||
android:bottomLeftRadius="22.5dp"/>
|
||||
<solid android:color="@color/black" />
|
||||
</shape>
|
||||
|
|
@ -7,6 +7,24 @@
|
|||
android:orientation="vertical"
|
||||
tools:context=".activity.MainActivity">
|
||||
|
||||
<Button
|
||||
android:id="@+id/open"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="开始配对" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/connect"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="连接" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/msg"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="获取数据" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/id"
|
||||
android:layout_width="wrap_content"
|
||||
|
|
|
|||
|
|
@ -0,0 +1,52 @@
|
|||
<?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">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="130dp"
|
||||
android:background="@color/color_2C2C2C"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal"
|
||||
android:paddingLeft="40dp"
|
||||
android:paddingRight="40dp">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="xxxxxx学校"
|
||||
android:textColor="@color/white"
|
||||
android:textSize="28dp" />
|
||||
|
||||
<View
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1" />
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="300dp"
|
||||
android:layout_height="85dp"
|
||||
android:background="@drawable/btn_bg"
|
||||
android:gravity="center">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="创建活动"
|
||||
android:textSize="36dp"
|
||||
android:textStyle="bold" />
|
||||
</RelativeLayout>
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/setting_btn"
|
||||
android:layout_width="80dp"
|
||||
android:layout_height="80dp"
|
||||
android:layout_marginLeft="40dp"
|
||||
android:src="@mipmap/setting" />
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
|
@ -0,0 +1,64 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="horizontal"
|
||||
tools:context=".activity.MainActivity">
|
||||
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="484dp"
|
||||
android:layout_height="match_parent"
|
||||
android:background="@drawable/left_bg"
|
||||
android:orientation="vertical">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/back"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="40dp"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<ImageView
|
||||
android:layout_width="30dp"
|
||||
android:layout_height="40dp"
|
||||
android:layout_marginLeft="40dp"
|
||||
android:src="@mipmap/back" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="40dp"
|
||||
android:text="返回"
|
||||
android:textColor="@color/white"
|
||||
android:textSize="36dp" />
|
||||
</LinearLayout>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/pair"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="150dp"
|
||||
android:layout_marginTop="150dp"
|
||||
android:gravity="center"
|
||||
android:text="设备配对"
|
||||
android:textColor="@color/white"
|
||||
android:textSize="28dp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/login"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="150dp"
|
||||
android:gravity="center"
|
||||
android:text="服务设置"
|
||||
android:textColor="@color/white"
|
||||
android:textSize="28dp" />
|
||||
</LinearLayout>
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/fragment"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
|
@ -0,0 +1,162 @@
|
|||
<?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">
|
||||
|
||||
<View
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="130dp" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="360dp"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="right"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1"
|
||||
android:gravity="center_vertical"
|
||||
android:text="服务器域名"
|
||||
android:textColor="@color/color_3d3d3d"
|
||||
android:textSize="36dp" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1"
|
||||
android:gravity="center_vertical"
|
||||
android:text="账号"
|
||||
android:textColor="@color/color_3d3d3d"
|
||||
android:textSize="36dp" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1"
|
||||
android:gravity="center_vertical"
|
||||
android:text="密码"
|
||||
android:textColor="@color/color_3d3d3d"
|
||||
android:textSize="36dp" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginLeft="25dp"
|
||||
android:layout_marginRight="160dp"
|
||||
android:layout_weight="2"
|
||||
android:orientation="vertical">
|
||||
|
||||
<View
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/address"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="94dp"
|
||||
android:background="@drawable/edittext_bg"
|
||||
android:paddingLeft="28dp"
|
||||
android:text="https://api.xintijiao.com/ijustjump"
|
||||
android:textColor="@color/color_3d3d3d"
|
||||
android:textSize="36dp" />
|
||||
|
||||
<View
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="2" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/account"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="94dp"
|
||||
android:background="@drawable/edittext_bg"
|
||||
android:paddingLeft="28dp"
|
||||
android:text="loop"
|
||||
android:textColor="@color/color_3d3d3d"
|
||||
android:textSize="36dp" />
|
||||
|
||||
<View
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="2" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/password"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="94dp"
|
||||
android:background="@drawable/edittext_bg"
|
||||
android:inputType="textPassword"
|
||||
android:paddingLeft="28dp"
|
||||
android:text="123456"
|
||||
android:textColor="@color/color_3d3d3d"
|
||||
android:textSize="36dp" />
|
||||
|
||||
<View
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1" />
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="73dp"
|
||||
android:layout_marginTop="30dp"
|
||||
android:layout_marginLeft="385dp"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/login"
|
||||
android:layout_width="181dp"
|
||||
android:layout_height="72dp"
|
||||
android:background="@drawable/btn_bg_login"
|
||||
android:gravity="center"
|
||||
android:text="确定"
|
||||
android:textColor="@color/color_3d3d3d"
|
||||
android:textSize="36dp" />
|
||||
|
||||
<View
|
||||
android:layout_width="60dp"
|
||||
android:layout_height="0dp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/reset"
|
||||
android:layout_width="181dp"
|
||||
android:layout_height="72dp"
|
||||
android:background="@drawable/btn_bg_login2"
|
||||
android:gravity="center"
|
||||
android:text="重置"
|
||||
android:textColor="@color/color_F4EA2A"
|
||||
android:textSize="36dp" />
|
||||
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/connectStatusTV"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="150dp"
|
||||
android:layout_marginBottom="70dp"
|
||||
android:layout_marginLeft="385dp"
|
||||
android:gravity="center_vertical"
|
||||
android:text="连接成功"
|
||||
android:textColor="@color/color_00FF55"
|
||||
android:visibility="invisible"
|
||||
android:textSize="36dp" />
|
||||
|
||||
</LinearLayout>
|
||||
|
|
@ -0,0 +1,142 @@
|
|||
<?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">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="180dp"
|
||||
android:orientation="vertical"
|
||||
android:paddingLeft="90dp"
|
||||
android:paddingRight="90dp">
|
||||
|
||||
<View
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="主机连接"
|
||||
android:textColor="@color/color_3d3d3d"
|
||||
android:textSize="24dp" />
|
||||
|
||||
<View
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<TextView
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:gravity="center_vertical"
|
||||
android:text="网关地址:"
|
||||
android:textColor="@color/color_50_3d3d3d"
|
||||
android:textSize="20dp" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:gravity="center_vertical"
|
||||
android:text="网关id:"
|
||||
android:textColor="@color/color_50_3d3d3d"
|
||||
android:textSize="20dp" />
|
||||
|
||||
|
||||
<TextView
|
||||
android:id="@+id/pair_btn"
|
||||
android:layout_width="162dp"
|
||||
android:layout_height="45dp"
|
||||
android:background="@drawable/pair_btn_clicked"
|
||||
android:gravity="center"
|
||||
android:text="配对状态"
|
||||
android:textColor="@color/black"
|
||||
android:textSize="24dp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/connect_btn"
|
||||
android:layout_width="162dp"
|
||||
android:layout_height="45dp"
|
||||
android:background="@drawable/connect_btn_unclicked"
|
||||
android:gravity="center"
|
||||
android:text="连接模式"
|
||||
android:textColor="@color/white"
|
||||
android:textSize="24dp" />
|
||||
|
||||
<View
|
||||
android:layout_width="200dp"
|
||||
android:layout_height="0dp" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="主机未连接"
|
||||
android:textColor="@color/color_50_FF0000" />
|
||||
</LinearLayout>
|
||||
|
||||
<View
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1" />
|
||||
</LinearLayout>
|
||||
|
||||
<View
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="18dp"
|
||||
android:background="@color/color_F6F6F6" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="100dp"
|
||||
android:gravity="center_vertical"
|
||||
android:paddingLeft="80dp"
|
||||
android:text="手柄信息"
|
||||
android:textColor="@color/color_3d3d3d"
|
||||
android:textSize="24dp" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="73dp"
|
||||
android:background="@color/color_FFE6E6E6"
|
||||
android:gravity="center_vertical">
|
||||
|
||||
<TextView
|
||||
android:layout_width="0dp"
|
||||
android:paddingLeft="80dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="编号"
|
||||
android:textColor="@color/color_3d3d3d"
|
||||
android:textSize="20dp" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:gravity="center"
|
||||
android:text="MAC"
|
||||
android:textColor="@color/color_3d3d3d"
|
||||
android:textSize="20dp" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:gravity="center"
|
||||
android:text="电量"
|
||||
android:textColor="@color/color_3d3d3d"
|
||||
android:textSize="20dp" />
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
After Width: | Height: | Size: 674 B |
|
After Width: | Height: | Size: 3.5 KiB |
|
After Width: | Height: | Size: 674 B |
|
After Width: | Height: | Size: 3.5 KiB |
|
After Width: | Height: | Size: 674 B |
|
After Width: | Height: | Size: 3.5 KiB |
|
After Width: | Height: | Size: 674 B |
|
After Width: | Height: | Size: 3.5 KiB |
|
|
@ -9,4 +9,19 @@
|
|||
<color name="white">#FFFFFFFF</color>
|
||||
<color name="main_color">#ffc20e</color>
|
||||
<color name="ffc20e">#ffc20e</color>
|
||||
<color name="color_2C2C2C">#2C2C2C</color>
|
||||
<color name="color_F7FFF300">#F7FFF300</color>
|
||||
<color name="color_2BE6E6E6">#2BE6E6E6</color>
|
||||
<color name="color_434343">#434343</color>
|
||||
<color name="color_d4">#d4ffffff</color>
|
||||
<color name="color_3d3d3d">#3d3d3d</color>
|
||||
<color name="color_50_3d3d3d">#803d3d3d</color>
|
||||
<color name="color_FFF300">#FFF300</color>
|
||||
<color name="color_FF0000">#FF0000</color>
|
||||
<color name="color_50_FF0000">#80FF0000</color>
|
||||
<color name="color_F6F6F6">#F6F6F6</color>
|
||||
<color name="color_FFE6E6E6">#FFE6E6E6</color>
|
||||
<color name="color_D9D9D9">#D9D9D9</color>
|
||||
<color name="color_F4EA2A">#F4EA2A</color>
|
||||
<color name="color_00FF55">#00FF55</color>
|
||||
</resources>
|
||||
|
|
@ -7,7 +7,7 @@ buildscript {
|
|||
}
|
||||
dependencies {
|
||||
classpath "com.android.tools.build:gradle:4.1.2"
|
||||
|
||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.4.30"
|
||||
// NOTE: Do not place your application dependencies here; they belong
|
||||
// in the individual module build.gradle files
|
||||
}
|
||||
|
|
|
|||
|
|
@ -52,6 +52,7 @@ public abstract class BaseActivity<P extends BasePresenter> extends RxFragmentAc
|
|||
createTime = System.currentTimeMillis();
|
||||
method = "onCreate";
|
||||
super.onCreate(savedInstanceState);
|
||||
initStart();
|
||||
setContentView(getContentViewResId());
|
||||
toolBar = searchToolBar(findViewById(android.R.id.content));
|
||||
initView();
|
||||
|
|
@ -120,6 +121,13 @@ public abstract class BaseActivity<P extends BasePresenter> extends RxFragmentAc
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载布局前
|
||||
*/
|
||||
public void initStart(){
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* 初始布局
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ import androidx.annotation.Nullable;
|
|||
|
||||
import com.trello.rxlifecycle4.LifecycleTransformer;
|
||||
import com.trello.rxlifecycle4.components.RxFragment;
|
||||
import com.trello.rxlifecycle4.components.support.RxDialogFragment;
|
||||
|
||||
import java.lang.reflect.ParameterizedType;
|
||||
import java.lang.reflect.Type;
|
||||
|
|
@ -21,9 +22,9 @@ import java.lang.reflect.Type;
|
|||
* Created by Ming
|
||||
* 2020-09-09
|
||||
*/
|
||||
public abstract class BaseFragment<P extends BasePresenter> extends RxFragment implements BaseView {
|
||||
public abstract class BaseFragment<P extends BasePresenter> extends RxDialogFragment implements BaseView {
|
||||
private View mRootView;
|
||||
private P p;
|
||||
protected P p;
|
||||
|
||||
|
||||
@Nullable
|
||||
|
|
|
|||
|
|
@ -5,11 +5,14 @@ import androidx.fragment.app.FragmentActivity;
|
|||
|
||||
import com.libs.network.interceptor.ErrCodeInterceptor;
|
||||
import com.libs.network.interceptor.ErrorCodeCallBack;
|
||||
import com.libs.network.interceptor.ErrorCodeCallBackString;
|
||||
import com.libs.network.interceptor.HeaderInterceptor;
|
||||
import com.libs.utils.LogUtil;
|
||||
import com.trello.rxlifecycle4.components.RxActivity;
|
||||
import com.trello.rxlifecycle4.components.RxFragment;
|
||||
|
||||
import java.lang.reflect.ParameterizedType;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
|
@ -84,7 +87,13 @@ public class Concise<I> {
|
|||
return this;
|
||||
}
|
||||
|
||||
public Concise setErrCodeListener(String errCode, String tokenKey, ErrorCodeCallBack tokenCallBack) {
|
||||
|
||||
public Concise setErrCodeListener(String errCode, ErrorCodeCallBack tokenCallBack) {
|
||||
interceptorList.add(new ErrCodeInterceptor(errCode, tokenCallBack));
|
||||
return this;
|
||||
}
|
||||
|
||||
public Concise setErrCodeListener(String errCode, String tokenKey, ErrorCodeCallBackString tokenCallBack) {
|
||||
interceptorList.add(new ErrCodeInterceptor(errCode, tokenKey, tokenCallBack));
|
||||
return this;
|
||||
}
|
||||
|
|
@ -95,6 +104,10 @@ public class Concise<I> {
|
|||
|
||||
|
||||
public Concise build() {
|
||||
Type s = getClass().getGenericSuperclass();
|
||||
LogUtil.e(s);
|
||||
ParameterizedType p = (ParameterizedType) s;
|
||||
Class<I> t = (Class<I>) p.getActualTypeArguments()[0];
|
||||
Class<I> tClass = (Class<I>) ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[0];
|
||||
api = new Retrofit.Builder()
|
||||
.client(createClient())
|
||||
|
|
|
|||
|
|
@ -20,13 +20,20 @@ import okio.BufferedSource;
|
|||
public class ErrCodeInterceptor implements Interceptor {
|
||||
private String errCode;
|
||||
private String tokenKey;
|
||||
private ErrorCodeCallBackString errorCodeCallBackString;
|
||||
private ErrorCodeCallBack tokenCallBack;
|
||||
private static final Charset UTF8 = Charset.forName("UTF-8");
|
||||
|
||||
public ErrCodeInterceptor(String errCode, String tokenKey, ErrorCodeCallBack tokenCallBack) {
|
||||
|
||||
public ErrCodeInterceptor(String errCode, ErrorCodeCallBack tokenCallBack) {
|
||||
this.errCode = errCode;
|
||||
this.tokenCallBack = tokenCallBack;
|
||||
}
|
||||
|
||||
public ErrCodeInterceptor(String errCode, String tokenKey, ErrorCodeCallBackString errorCodeCallBackString) {
|
||||
this.errCode = errCode;
|
||||
this.tokenKey = tokenKey;
|
||||
this.tokenCallBack = tokenCallBack;
|
||||
this.errorCodeCallBackString = errorCodeCallBackString;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -44,13 +51,18 @@ public class ErrCodeInterceptor implements Interceptor {
|
|||
}
|
||||
String bodyString = buffer.clone().readString(charset);
|
||||
if (bodyString.contains(errCode)) {
|
||||
String newToken = tokenCallBack.token();
|
||||
if (TextUtils.isEmpty(newToken)) {
|
||||
return originalResponse;
|
||||
if (tokenKey == null) {
|
||||
tokenCallBack.token();
|
||||
return chain.proceed(null);
|
||||
} else {
|
||||
String newToken = errorCodeCallBackString.token();
|
||||
if (TextUtils.isEmpty(newToken)) {
|
||||
return originalResponse;
|
||||
}
|
||||
Request newRequest = request.newBuilder().header(tokenKey, newToken).build();
|
||||
originalResponse.body().close();
|
||||
return chain.proceed(newRequest);
|
||||
}
|
||||
Request newRequest = request.newBuilder().header(tokenKey, newToken).build();
|
||||
originalResponse.body().close();
|
||||
return chain.proceed(newRequest);
|
||||
}
|
||||
return originalResponse;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,5 +5,5 @@ package com.libs.network.interceptor;
|
|||
* 3/2/22
|
||||
*/
|
||||
public interface ErrorCodeCallBack {
|
||||
String token();
|
||||
void token();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,9 @@
|
|||
package com.libs.network.interceptor;
|
||||
|
||||
/**
|
||||
* @author Ming
|
||||
* 3/2/22
|
||||
*/
|
||||
public interface ErrorCodeCallBackString {
|
||||
String token();
|
||||
}
|
||||