连接蓝牙,配网
This commit is contained in:
@@ -43,6 +43,7 @@ import androidx.appcompat.app.AppCompatDelegate;
|
||||
import androidx.core.app.ActivityCompat;
|
||||
import androidx.viewbinding.ViewBinding;
|
||||
|
||||
import com.ckkj.water.dialog.LoadingProgressDialog;
|
||||
import com.ckkj.water.utils.manager.ThemeManager;
|
||||
import com.esafirm.imagepicker.features.ImagePicker;
|
||||
import com.hjq.permissions.OnPermissionCallback;
|
||||
@@ -275,6 +276,16 @@ public abstract class BaseActivity<T extends ViewBinding, P extends IPresenter>
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
LoadingProgressDialog progressDialog = mProgressLoadingDialog;
|
||||
try {
|
||||
if (progressDialog != null && mContext != null) {
|
||||
mProgressLoadingDialog = null;
|
||||
progressDialog.dismiss();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
//每个activity都需要创建Presenter
|
||||
@@ -317,6 +328,7 @@ public abstract class BaseActivity<T extends ViewBinding, P extends IPresenter>
|
||||
@Override
|
||||
public void hideLoading() {
|
||||
loadingDialog.dismiss();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -359,6 +371,9 @@ public abstract class BaseActivity<T extends ViewBinding, P extends IPresenter>
|
||||
|
||||
protected LoadingDialog mLoadingDialog;
|
||||
|
||||
/**
|
||||
* 普通加载loading
|
||||
*/
|
||||
public void showLoadingDialog() {
|
||||
LoadingDialog dialog = mLoadingDialog;
|
||||
if (dialog == null && mContext != null) {
|
||||
@@ -381,6 +396,33 @@ public abstract class BaseActivity<T extends ViewBinding, P extends IPresenter>
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 进度条加载loading
|
||||
*/
|
||||
protected LoadingProgressDialog mProgressLoadingDialog;
|
||||
public void showProgressLoadingDialog(int progress) {
|
||||
LoadingProgressDialog dialog = mProgressLoadingDialog;
|
||||
if (dialog == null && mContext != null) {
|
||||
dialog = new LoadingProgressDialog(mContext);
|
||||
// 不可触摸取消
|
||||
dialog.setCanceledOnTouchOutside(false);
|
||||
// 强制取消关闭界面
|
||||
dialog.setCancelable(true);
|
||||
dialog.setOnCancelListener(dialog1 -> finish());
|
||||
dialog.setProgress( progress);
|
||||
mProgressLoadingDialog = dialog;
|
||||
} else {
|
||||
dialog.dismiss();
|
||||
}
|
||||
if (dialog != null && mContext != null) {
|
||||
try {
|
||||
dialog.show();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onNetChange(int netModel) {
|
||||
|
||||
@@ -122,6 +122,7 @@ public class AddDeviceActivity_copy extends BaseActivity<AddDeviceLayoutBinding,
|
||||
animationDrawable.start();
|
||||
}
|
||||
initListener();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -9,6 +9,7 @@ import android.content.pm.PackageManager;
|
||||
import android.net.wifi.ScanResult;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
@@ -194,6 +195,7 @@ public class SelectWifiActivity extends BaseActivity<DeviceResetWifiBinding, Dev
|
||||
ToastUtil.showShort(mContext, "设备连接中,请稍后再试");
|
||||
return;
|
||||
}
|
||||
showProgressLoadingDialog(0);
|
||||
espProvisionManager.provisionWifi(mWifiName, viewBinding.etInputPsd.getText().toString());
|
||||
// goTo(mContext,DeviceConnectActivity.class,null);
|
||||
}
|
||||
@@ -217,13 +219,19 @@ public class SelectWifiActivity extends BaseActivity<DeviceResetWifiBinding, Dev
|
||||
@Override
|
||||
public void onProvisioning(int progress) {
|
||||
Log.i("TEST","WIFI连接进度 == " + progress);
|
||||
viewBinding.tvProgress.setText("进度:" + progress + "%");
|
||||
mProgressLoadingDialog.setProgress(progress);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSuccess(String deviceName, String deviceType) {
|
||||
Log.i("TEST","deviceName:" + deviceName + "连接成功");
|
||||
ToastUtil.showShort(mContext, deviceName + "连接成功");
|
||||
new Handler().postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
hideDialogLoading();
|
||||
}
|
||||
}, 800);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -234,12 +242,14 @@ public class SelectWifiActivity extends BaseActivity<DeviceResetWifiBinding, Dev
|
||||
}
|
||||
Log.i("TEST","errorCode == " + errorCode + " message == " + message);
|
||||
ToastUtil.showShort(mContext, message);
|
||||
hideDialogLoading();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisconnected() {
|
||||
isBleConnecting = false;
|
||||
isBleConnected = false;
|
||||
hideDialogLoading();
|
||||
Log.i("TEST","onDisconnected");
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,94 @@
|
||||
package com.ckkj.water.dialog;
|
||||
|
||||
import android.animation.ObjectAnimator;
|
||||
import android.animation.ValueAnimator;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.view.WindowManager;
|
||||
import android.view.animation.LinearInterpolator;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.ckkj.water.R;
|
||||
import com.timqi.sectorprogressview.ColorfulRingProgressView;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
|
||||
/**
|
||||
* author:
|
||||
* time: 2019/9/18 9:34
|
||||
* desc:
|
||||
* version: 1.0.0
|
||||
*/
|
||||
public class LoadingProgressDialog extends Dialog {
|
||||
private Context context;
|
||||
private int mProgress = 0;
|
||||
|
||||
private ColorfulRingProgressView mCircleLoading;
|
||||
|
||||
public LoadingProgressDialog(Context context) {
|
||||
super(context); // 应用透明背景样式
|
||||
this.context=context;
|
||||
}
|
||||
public LoadingProgressDialog(Context context, String s) {
|
||||
super(context);
|
||||
this.context=context;
|
||||
}
|
||||
|
||||
public void setProgress(int progress) {
|
||||
mProgress = progress;
|
||||
if(mCircleLoading != null){
|
||||
mCircleLoading.setPercent( progress);
|
||||
}
|
||||
}
|
||||
|
||||
public LoadingProgressDialog(Context context, int theme) {
|
||||
super(context, theme);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
init();
|
||||
}
|
||||
|
||||
@SuppressLint({"ResourceAsColor", "MissingInflatedId"})
|
||||
private void init() {
|
||||
// 设置对话框背景为透明
|
||||
getWindow().setBackgroundDrawable(context.getResources().getDrawable(R.color.transparent));
|
||||
getWindow().setDimAmount(0f);
|
||||
setCancelable(true);
|
||||
setCanceledOnTouchOutside(false);
|
||||
setContentView(R.layout.dialog_progress_layout);//loading的xml文件
|
||||
mCircleLoading = findViewById(R.id.circle_loading);
|
||||
mCircleLoading.setStartAngle(0);
|
||||
mCircleLoading.setPercent(mProgress);
|
||||
//加载动画资源
|
||||
WindowManager.LayoutParams params = Objects.requireNonNull(getWindow()).getAttributes();
|
||||
params.width = WindowManager.LayoutParams.MATCH_PARENT;
|
||||
params.height = WindowManager.LayoutParams.MATCH_PARENT;
|
||||
getWindow().setAttributes(params);
|
||||
// 可选: 设置窗口大小
|
||||
getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void show() {//开启
|
||||
// if (context==null){
|
||||
// return;
|
||||
// }
|
||||
super.show();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dismiss() {//关闭
|
||||
// if (context==null){
|
||||
// return;
|
||||
// }
|
||||
super.dismiss();
|
||||
}
|
||||
}
|
||||
5
app/src/main/res/drawable/shape_loading_trans_bg.xml
Normal file
5
app/src/main/res/drawable/shape_loading_trans_bg.xml
Normal file
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<corners android:radius="@dimen/dp_8"/>
|
||||
<solid android:color="@color/trans_dark_50"/>
|
||||
</shape>
|
||||
41
app/src/main/res/layout/dialog_progress_layout.xml
Normal file
41
app/src/main/res/layout/dialog_progress_layout.xml
Normal file
@@ -0,0 +1,41 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="170dp"
|
||||
android:layout_height="170dp"
|
||||
android:layout_gravity="center"
|
||||
android:gravity="center"
|
||||
android:orientation="vertical"
|
||||
android:layout_marginBottom="@dimen/dp_80"
|
||||
android:background="@drawable/shape_loading_trans_bg">
|
||||
|
||||
<!-- <ProgressBar-->
|
||||
<!-- android:visibility="gone"-->
|
||||
<!-- android:id="@+id/pb_load"-->
|
||||
<!-- android:layout_width="45dp"-->
|
||||
<!-- android:layout_height="45dp"-->
|
||||
<!-- android:indeterminateDrawable="@drawable/dialog_loading_progress_bar" />-->
|
||||
|
||||
<com.timqi.sectorprogressview.ColorfulRingProgressView
|
||||
android:id="@+id/circle_loading"
|
||||
android:layout_width="@dimen/dp_110"
|
||||
android:layout_height="@dimen/dp_110"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
app:bgColor="#e1e1e1"
|
||||
app:fgColorEnd="@color/color_zhu"
|
||||
app:fgColorStart="#B0F6AA"
|
||||
app:percent="75"
|
||||
app:startAngle="0"
|
||||
app:strokeWidth="8dp"
|
||||
/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_load_dialog"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:text="正在配置网络"
|
||||
android:textColor="@color/color_zhu"
|
||||
android:textSize="13sp"
|
||||
android:layout_marginTop="@dimen/dp_4"/>
|
||||
|
||||
</LinearLayout>
|
||||
Reference in New Issue
Block a user