优化
This commit is contained in:
@@ -69,39 +69,43 @@ abstract class BaseActivity<VB : ViewBinding> : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
open fun registerDataChange() {
|
open fun registerDataChange() {
|
||||||
lifecycleScope.launch {
|
// lifecycleScope.launch {
|
||||||
viewModel.showLoading.collect {
|
// viewModel.showLoading.collect {
|
||||||
Timber.d("registerDataChange 用户 showLoading = $it")
|
// Timber.d("registerDataChange 用户 showLoading = $it")
|
||||||
if (it) {
|
// if (it) {
|
||||||
showWaitingDialog("")
|
// showWaitingDialog("")
|
||||||
} else {
|
// } else {
|
||||||
hideWaitingDialog()
|
// hideWaitingDialog()
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 显示等待提示框
|
* 显示等待提示框
|
||||||
*/
|
*/
|
||||||
fun showWaitingDialog(tip: String?): Dialog? {
|
fun showWaitingDialog(tip: String?){
|
||||||
hideWaitingDialog()
|
runOnUiThread {
|
||||||
val view = View.inflate(this, R.layout.dialog_waiting, null)
|
hideWaitingDialog()
|
||||||
if (!TextUtils.isEmpty(tip)) (view.findViewById<View?>(R.id.tvTip) as TextView).text = tip
|
val view = View.inflate(this, R.layout.dialog_waiting, null)
|
||||||
mDialogWaiting = CustomDialog(this, view, R.style.MyDialog).apply {
|
if (!TextUtils.isEmpty(tip)) (view.findViewById<View?>(R.id.tvTip) as TextView).text =
|
||||||
setCancelable(true)
|
tip
|
||||||
setCanceledOnTouchOutside(true)
|
mDialogWaiting = CustomDialog(this, view, R.style.MyDialog).apply {
|
||||||
show()
|
setCancelable(true)
|
||||||
|
setCanceledOnTouchOutside(true)
|
||||||
|
show()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return mDialogWaiting
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 隐藏等待提示框
|
* 隐藏等待提示框
|
||||||
*/
|
*/
|
||||||
fun hideWaitingDialog() {
|
fun hideWaitingDialog() {
|
||||||
mDialogWaiting?.dismiss()
|
runOnUiThread {
|
||||||
mDialogWaiting = null
|
mDialogWaiting?.dismiss()
|
||||||
|
mDialogWaiting = null
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun showWaitingDialog2(tip: String?) {
|
fun showWaitingDialog2(tip: String?) {
|
||||||
|
|||||||
@@ -103,6 +103,7 @@ class CollectFragment : BaseFragment<FragmentCollectBinding>() {
|
|||||||
val index = foodCollectionList.indexOfFirst { it.imageFile == null }
|
val index = foodCollectionList.indexOfFirst { it.imageFile == null }
|
||||||
if (index == -1) {
|
if (index == -1) {
|
||||||
ToastUtils.showToast("每次只允许保存${MAX_COUNT}条数据")
|
ToastUtils.showToast("每次只允许保存${MAX_COUNT}条数据")
|
||||||
|
settingActivity?.hideWaitingDialog()
|
||||||
rerurn@cameraCallback
|
rerurn@cameraCallback
|
||||||
}
|
}
|
||||||
ImageUtil.uriToBitmap(requireActivity(), uri)?.let { bitmap ->
|
ImageUtil.uriToBitmap(requireActivity(), uri)?.let { bitmap ->
|
||||||
@@ -117,6 +118,7 @@ class CollectFragment : BaseFragment<FragmentCollectBinding>() {
|
|||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
e.printStackTrace()
|
e.printStackTrace()
|
||||||
ToastUtils.showToast("操作失败")
|
ToastUtils.showToast("操作失败")
|
||||||
|
settingActivity?.hideWaitingDialog()
|
||||||
return@let
|
return@let
|
||||||
}
|
}
|
||||||
val file = BitmapSaver.saveToAppFilesDir(
|
val file = BitmapSaver.saveToAppFilesDir(
|
||||||
@@ -134,10 +136,12 @@ class CollectFragment : BaseFragment<FragmentCollectBinding>() {
|
|||||||
if (bitmap.isRecycled.not()) {
|
if (bitmap.isRecycled.not()) {
|
||||||
bitmap.recycle()
|
bitmap.recycle()
|
||||||
}
|
}
|
||||||
|
settingActivity?.hideWaitingDialog()
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
e.printStackTrace()
|
e.printStackTrace()
|
||||||
ToastUtils.showToast("程序异常")
|
settingActivity?.hideWaitingDialog()
|
||||||
|
ToastUtils.showToast("程序异常${e.message}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -148,7 +152,11 @@ class CollectFragment : BaseFragment<FragmentCollectBinding>() {
|
|||||||
ToastUtils.showToast("每次只允许保存${MAX_COUNT}条数据")
|
ToastUtils.showToast("每次只允许保存${MAX_COUNT}条数据")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
cameraUtils.takePhoto(cameraCallback)
|
settingActivity?.showWaitingDialog("拍照中……")
|
||||||
|
cameraUtils.takePhoto(cameraCallback) { errMsg ->
|
||||||
|
ToastUtils.showToast(errMsg)
|
||||||
|
settingActivity?.hideWaitingDialog()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun initialize() {
|
override fun initialize() {
|
||||||
|
|||||||
@@ -11,16 +11,18 @@ class CameraUtils(private var activity: ComponentActivity) {
|
|||||||
|
|
||||||
private var cameraController: LifecycleCameraController? = null
|
private var cameraController: LifecycleCameraController? = null
|
||||||
private var photoCaptureHelper: PhotoCaptureHelper? = null
|
private var photoCaptureHelper: PhotoCaptureHelper? = null
|
||||||
|
private var failCallback: ((msg: String) -> Unit)? = null
|
||||||
|
|
||||||
// private var isCameraReady = false
|
// private var isCameraReady = false
|
||||||
fun takePhoto(callback: (Uri) -> Unit) {
|
fun takePhoto(succCallback: (Uri) -> Unit, failCallback: (msg: String) -> Unit = { }) {
|
||||||
|
this.failCallback = failCallback
|
||||||
cameraController?.let {
|
cameraController?.let {
|
||||||
if (photoCaptureHelper == null) {
|
if (photoCaptureHelper == null) {
|
||||||
initCaptureHelper()
|
initCaptureHelper()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
photoCaptureHelper?.let {
|
photoCaptureHelper?.let {
|
||||||
it.addSuccessCallback(callback)
|
it.addSuccessCallback(succCallback)
|
||||||
it.bindCameraCallback {
|
it.bindCameraCallback {
|
||||||
bind()
|
bind()
|
||||||
}
|
}
|
||||||
@@ -35,6 +37,7 @@ class CameraUtils(private var activity: ComponentActivity) {
|
|||||||
onSuccess = {},
|
onSuccess = {},
|
||||||
onError = { msg ->
|
onError = { msg ->
|
||||||
//toast(msg)
|
//toast(msg)
|
||||||
|
failCallback?.invoke(msg)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:shape="rectangle">
|
android:shape="rectangle">
|
||||||
<corners android:radius="5dp" />
|
<corners android:radius="8dp" />
|
||||||
<solid android:color="@color/black" />
|
<solid android:color="@color/black" />
|
||||||
</shape>
|
</shape>
|
||||||
@@ -1,32 +1,26 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="match_parent">
|
android:layout_height="wrap_content"
|
||||||
|
android:background="@drawable/dialog_waiting"
|
||||||
|
android:gravity="center_vertical"
|
||||||
|
android:paddingHorizontal="20dp"
|
||||||
|
android:paddingVertical="15dp">
|
||||||
|
|
||||||
<RelativeLayout
|
<ProgressBar
|
||||||
|
android:layout_width="39dp"
|
||||||
|
android:layout_height="39dp"
|
||||||
|
android:indeterminateTint="@color/teal_200"
|
||||||
|
android:indeterminateTintMode="src_atop" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/tvTip"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="80dp"
|
android:layout_height="wrap_content"
|
||||||
android:paddingHorizontal="20dp"
|
android:text="请稍后……"
|
||||||
android:background="@drawable/dialog_waiting">
|
android:gravity="center_vertical"
|
||||||
|
android:layout_marginStart="10dp"
|
||||||
|
android:textColor="@color/white"
|
||||||
|
android:textSize="26sp" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
<TextView
|
|
||||||
android:id="@+id/tvTip"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_centerInParent="true"
|
|
||||||
android:textColor="@color/white"
|
|
||||||
android:text="请稍后……"
|
|
||||||
android:textSize="22sp" />
|
|
||||||
|
|
||||||
<ProgressBar
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_centerVertical="true"
|
|
||||||
android:layout_marginRight="30dp"
|
|
||||||
android:layout_toLeftOf="@id/tvTip"
|
|
||||||
android:indeterminateTint="@color/teal_200"
|
|
||||||
android:indeterminateTintMode="src_atop" />
|
|
||||||
|
|
||||||
</RelativeLayout>
|
|
||||||
</FrameLayout>
|
|
||||||
@@ -134,7 +134,7 @@
|
|||||||
android:layout_marginTop="55dp"
|
android:layout_marginTop="55dp"
|
||||||
android:text="请正视屏幕进行面部识别..."
|
android:text="请正视屏幕进行面部识别..."
|
||||||
android:textColor="#ff5e7585"
|
android:textColor="#ff5e7585"
|
||||||
android:textSize="24sp"
|
android:textSize="22sp"
|
||||||
android:textStyle="bold"
|
android:textStyle="bold"
|
||||||
tools:ignore="HardcodedText" />
|
tools:ignore="HardcodedText" />
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|||||||
@@ -76,7 +76,7 @@
|
|||||||
android:layout_marginBottom="56dp"
|
android:layout_marginBottom="56dp"
|
||||||
android:text="请正视屏幕进行面部识别..."
|
android:text="请正视屏幕进行面部识别..."
|
||||||
android:textColor="@color/white"
|
android:textColor="@color/white"
|
||||||
android:textSize="24sp"
|
android:textSize="22sp"
|
||||||
android:visibility="gone" />
|
android:visibility="gone" />
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import android.annotation.SuppressLint;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.Looper;
|
import android.os.Looper;
|
||||||
|
import android.text.TextUtils;
|
||||||
import android.view.Gravity;
|
import android.view.Gravity;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
@@ -32,6 +33,9 @@ public class ToastUtils {
|
|||||||
* @param text the text
|
* @param text the text
|
||||||
*/
|
*/
|
||||||
public static void showToast(String text) {
|
public static void showToast(String text) {
|
||||||
|
if (TextUtils.isEmpty(text)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
runOnMainThread(()->{
|
runOnMainThread(()->{
|
||||||
Context context = App.getContext();
|
Context context = App.getContext();
|
||||||
if (toast == null) {
|
if (toast == null) {
|
||||||
|
|||||||
@@ -89,7 +89,8 @@ public class ConfigUtil {
|
|||||||
*/
|
*/
|
||||||
// private static final String DEFAULT_PREVIEW_SIZE = "1280x720";
|
// private static final String DEFAULT_PREVIEW_SIZE = "1280x720";
|
||||||
// private static final String DEFAULT_PREVIEW_SIZE = "1080x720";
|
// private static final String DEFAULT_PREVIEW_SIZE = "1080x720";
|
||||||
private static final String DEFAULT_PREVIEW_SIZE = "720x1080";
|
// private static final String DEFAULT_PREVIEW_SIZE = "720x1080";
|
||||||
|
private static final String DEFAULT_PREVIEW_SIZE = "720x1280";
|
||||||
// private static final String DEFAULT_PREVIEW_SIZE = "608x456";
|
// private static final String DEFAULT_PREVIEW_SIZE = "608x456";
|
||||||
// private static final String DEFAULT_PREVIEW_SIZE = "1024x768";
|
// private static final String DEFAULT_PREVIEW_SIZE = "1024x768";
|
||||||
// private static final String DEFAULT_PREVIEW_SIZE = "800x600";
|
// private static final String DEFAULT_PREVIEW_SIZE = "800x600";
|
||||||
|
|||||||
Reference in New Issue
Block a user