feat:切换flutter版本
This commit is contained in:
1 parent
ee761ccc48
commit
72443f7abf
32 files changed
+536
-375
No files matched your search
@@ -22,13 +22,19 @@
|
||||
android:name="${applicationName}"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:label="智慧食堂"
|
||||
android:largeHeap="true"
|
||||
android:requestLegacyExternalStorage="true">
|
||||
|
||||
<activity
|
||||
android:name="io.flutter.embedding.android.FlutterActivity"
|
||||
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
|
||||
android:hardwareAccelerated="true"
|
||||
android:windowSoftInputMode="adjustResize" />
|
||||
|
||||
<activity
|
||||
android:name=".MainActivity"
|
||||
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
|
||||
android:exported="true"
|
||||
android:launchMode="singleTop"
|
||||
android:theme="@style/LaunchTheme">
|
||||
<meta-data
|
||||
android:name="io.flutter.embedding.android.NormalTheme"
|
||||
@@ -41,8 +47,8 @@
|
||||
|
||||
<activity
|
||||
android:name="io.flutter.plugins.facediscern.ui.FaceDiscern"
|
||||
android:exported="false"
|
||||
android:hardwareAccelerated="false"
|
||||
android:exported="true"
|
||||
android:hardwareAccelerated="true"
|
||||
android:launchMode="singleTop"
|
||||
android:theme="@style/Theme.AppCompat.NoActionBar" />
|
||||
|
||||
|
||||
+1
-8
@@ -5,8 +5,6 @@ import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.os.Build;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
@@ -76,15 +74,10 @@ public class FlutterFaceDiscernPlugin implements FlutterPlugin, MethodChannel.Me
|
||||
switch (method) {
|
||||
case "jumpFaceDiscern":
|
||||
try {
|
||||
// Intent intent = new Intent(context, FaceDiscern.class);
|
||||
// intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
// intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
|
||||
// context.startActivity(intent);
|
||||
|
||||
Intent intent = new Intent(context, FaceDiscern.class);
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
|
||||
new Handler(Looper.getMainLooper()).post(() -> context.startActivity(intent));
|
||||
context.startActivity(intent);
|
||||
result.success(true);
|
||||
} catch (Exception e) {
|
||||
result.success(false);
|
||||
|
||||
@@ -4,10 +4,7 @@ import android.Manifest;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Point;
|
||||
import android.hardware.Camera;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
@@ -18,9 +15,9 @@ import androidx.core.app.ActivityCompat;
|
||||
import androidx.databinding.DataBindingUtil;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
|
||||
import com.example.pj_supermarket_cloud.MainActivity;
|
||||
import com.example.pj_supermarket_cloud.R;
|
||||
import com.example.pj_supermarket_cloud.databinding.ActivityFaceDiscernBinding;
|
||||
import com.example.pj_supermarket_cloud.tool.FlutterRouterManager;
|
||||
|
||||
import io.flutter.Log;
|
||||
import io.flutter.embedding.android.FlutterActivity;
|
||||
@@ -96,12 +93,6 @@ public class FaceDiscern extends BaseActivity implements ViewTreeObserver.OnGlob
|
||||
initRgbCamera();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onNewIntent(Intent intent) {
|
||||
super.onNewIntent(intent);
|
||||
Log.e(TAG, "相机触发onNewIntent");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
@@ -133,10 +124,13 @@ public class FaceDiscern extends BaseActivity implements ViewTreeObserver.OnGlob
|
||||
if (Objects.nonNull(channel)) {
|
||||
channel.invokeMethod("faceDiscernPageInit", null);
|
||||
}
|
||||
if (rgbCameraHelper != null) {
|
||||
rgbCameraHelper.resumePreview();
|
||||
}
|
||||
scheduler.schedule(() -> {
|
||||
try {
|
||||
if (rgbCameraHelper != null) {
|
||||
rgbCameraHelper.resumePreview();
|
||||
if (viewModel != null) {
|
||||
viewModel.stop();
|
||||
previewLock = false;
|
||||
Log.i(TAG, "相机开始识别");
|
||||
}
|
||||
@@ -155,26 +149,33 @@ public class FaceDiscern extends BaseActivity implements ViewTreeObserver.OnGlob
|
||||
}
|
||||
}
|
||||
|
||||
// 以前的方式
|
||||
// intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
|
||||
// 推荐的方式
|
||||
// intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
// intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
|
||||
|
||||
// 手机返回按钮
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
Log.e(TAG, "相机onBackPressed");
|
||||
|
||||
if (rgbCameraHelper != null) {
|
||||
rgbCameraHelper.stop();
|
||||
}
|
||||
if (viewModel != null) {
|
||||
viewModel.stop();
|
||||
}
|
||||
binding.dualCameraFaceRectView.clearFaceInfo();
|
||||
previewLock = true;
|
||||
|
||||
MethodChannel channel = FlutterFaceDiscernPlugin.staticChannel;
|
||||
if (Objects.nonNull(channel)) {
|
||||
channel.invokeMethod("faceDiscernBack", null);
|
||||
}
|
||||
|
||||
// FlutterRouterManager loadEngine = new FlutterRouterManager("/load", "login_engine", this);
|
||||
// loadEngine.push();
|
||||
// loadEngine.destroy();
|
||||
|
||||
Intent intent = new Intent();
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
|
||||
intent.setClassName(this.getPackageName(), this.getPackageName() + ".MainActivity");
|
||||
this.startActivity(intent);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
+7
-7
@@ -20,10 +20,8 @@ import com.arcsoft.face.LivenessInfo;
|
||||
import com.arcsoft.face.LivenessParam;
|
||||
import com.arcsoft.face.enums.DetectFaceOrientPriority;
|
||||
import com.arcsoft.face.enums.DetectMode;
|
||||
import com.example.pj_supermarket_cloud.MainActivity;
|
||||
import com.google.gson.Gson;
|
||||
|
||||
import io.flutter.embedding.android.FlutterActivity;
|
||||
import io.flutter.plugins.facediscern.tool.camera.DualCameraHelper;
|
||||
import io.flutter.plugins.facediscern.tool.camera.config.PreviewConfig;
|
||||
import io.flutter.plugins.facediscern.tool.face.constants.FaceBrodConstant;
|
||||
@@ -293,15 +291,17 @@ public class FaceDiscernViewModel extends ViewModel implements RecognizeCallback
|
||||
if (flutterFaceCallbackIntent == null) {
|
||||
flutterFaceCallbackIntent = new Intent(FaceBrodConstant.FACE_GLOBAL_INTENT);
|
||||
}
|
||||
flutterFaceCallbackIntent.putExtra("json", new Gson().toJson(faceDiscern));
|
||||
Log.i(TAG, "人脸识别成功json:" + new Gson().toJson(faceDiscern));
|
||||
flutterFaceCallbackIntent.putExtra("json", new Gson().toJson(faceDiscern));
|
||||
context.sendBroadcast(flutterFaceCallbackIntent);
|
||||
faceDiscern = null;
|
||||
if (context instanceof Activity) {
|
||||
Thread.sleep(500);
|
||||
Intent intent = new Intent(context, MainActivity.class);
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
|
||||
String packageName = context.getPackageName();
|
||||
Intent intent = new Intent();
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
|
||||
intent.setClassName(packageName, packageName + ".MainActivity");
|
||||
context.startActivity(intent);
|
||||
context.sendBroadcast(flutterFaceCallbackIntent);
|
||||
faceDiscern = null;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "提示文字变更的回调,错误error:" + e.getMessage(), e);
|
||||
|
||||
@@ -17,4 +17,4 @@ class MainActivity : FlutterActivity() {
|
||||
GeneratedPluginRegistrant.registerWith(flutterEngine)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
+75
@@ -0,0 +1,75 @@
|
||||
package com.example.pj_supermarket_cloud.tool
|
||||
|
||||
import android.app.Activity
|
||||
import io.flutter.embedding.android.FlutterActivity
|
||||
import io.flutter.embedding.android.FlutterActivityLaunchConfigs
|
||||
import io.flutter.embedding.engine.FlutterEngine
|
||||
import io.flutter.embedding.engine.FlutterEngineCache
|
||||
import io.flutter.embedding.engine.dart.DartExecutor
|
||||
|
||||
class FlutterRouterManager(val targetRoute: String, val mEngineId: String, val mContext: Activity) {
|
||||
|
||||
var mEngine: FlutterEngine? = null
|
||||
|
||||
init {
|
||||
createCachedEngine()
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
/**
|
||||
* 获取缓存中的 Flutter引擎
|
||||
*/
|
||||
@JvmStatic
|
||||
fun getEngineCacheInstance(engineId: String): FlutterEngine? {
|
||||
return FlutterEngineCache.getInstance().get(engineId)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 1、创建Flutter引擎
|
||||
* 2、将初始命名路由,修改为目标页面路由
|
||||
* 3、缓存Flutter引擎
|
||||
*/
|
||||
fun createCachedEngine(): FlutterEngine {
|
||||
val flutterEngine = FlutterEngine(mContext) // 创建Flutter引擎
|
||||
|
||||
// 将初始命名路由,修改为目标页面路由
|
||||
flutterEngine.navigationChannel.setInitialRoute(targetRoute)
|
||||
|
||||
// 这一步,是在执行相关Dart文件入口的 main函数,将Flutter页面渲染出结果
|
||||
// 原生端获取结果,进行最终渲染上屏
|
||||
flutterEngine.dartExecutor.executeDartEntrypoint(
|
||||
DartExecutor.DartEntrypoint.createDefault()
|
||||
)
|
||||
|
||||
// 将加载好的引擎,存储起来
|
||||
FlutterEngineCache.getInstance().put(mEngineId, flutterEngine)
|
||||
|
||||
mEngine = flutterEngine
|
||||
|
||||
return flutterEngine
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据引擎ID,前往指定的Flutter页面
|
||||
*/
|
||||
fun push() {
|
||||
// 使用缓存好的引擎(推荐)
|
||||
mContext.startActivity(
|
||||
FlutterActivity
|
||||
.withCachedEngine(mEngineId)
|
||||
.backgroundMode(FlutterActivityLaunchConfigs.BackgroundMode.transparent)
|
||||
.build(mContext)
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* 销毁当前Flutter引擎
|
||||
*/
|
||||
fun destroy() {
|
||||
mEngine?.destroy()
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<!-- 是否在初始化时自动显示副屏 -->
|
||||
<bool name="autoShowSubScreenWhenInit">true</bool>
|
||||
</resources>
|
||||
Reference in new issue
Block a user