debug_fix_screen_change #2
@@ -1,7 +1,8 @@
|
||||
plugins {
|
||||
//alias(libs.plugins.android.application)
|
||||
alias(libs.plugins.android.library)
|
||||
id 'org.jetbrains.kotlin.android'
|
||||
alias(libs.plugins.kotlin.android)
|
||||
//id 'org.jetbrains.kotlin.android'
|
||||
}
|
||||
|
||||
ext.vvl_version='1.4.321.0'
|
||||
@@ -43,13 +44,13 @@ android {
|
||||
}
|
||||
|
||||
// 添加 Kotlin 编译选项
|
||||
kotlinOptions {
|
||||
jvmTarget = '17' // 与 Java 版本保持一致
|
||||
}
|
||||
// kotlinOptions {
|
||||
// jvmTarget = '17' // 与 Java 版本保持一致
|
||||
// }
|
||||
|
||||
kotlin {
|
||||
jvmToolchain(17)
|
||||
}
|
||||
// kotlin {
|
||||
// jvmToolchain(17)
|
||||
// }
|
||||
|
||||
buildFeatures {
|
||||
prefab true
|
||||
@@ -83,6 +84,9 @@ android {
|
||||
packagingOptions {
|
||||
pickFirst '**/*.jar'
|
||||
}
|
||||
kotlinOptions {
|
||||
jvmTarget = '17'
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
@@ -90,6 +94,7 @@ dependencies {
|
||||
implementation libs.appcompat
|
||||
implementation libs.material
|
||||
implementation libs.games.activity
|
||||
implementation libs.androidx.core.core.ktx
|
||||
testImplementation libs.junit
|
||||
androidTestImplementation libs.ext.junit
|
||||
androidTestImplementation libs.espresso.core
|
||||
|
||||
@@ -1,6 +1,19 @@
|
||||
// Top-level build file where you can add configuration options common to all sub-projects/modules.
|
||||
buildscript {
|
||||
repositories {
|
||||
google()
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:8.3.2'
|
||||
}
|
||||
}
|
||||
|
||||
plugins {
|
||||
alias(libs.plugins.android.application) apply false
|
||||
alias(libs.plugins.android.library) apply false // 添加这行
|
||||
id 'org.jetbrains.kotlin.android' version '1.9.0' apply false
|
||||
alias(libs.plugins.android.library) apply false
|
||||
alias(libs.plugins.kotlin.android) apply false // 添加这行
|
||||
//alias(libs.plugins.kotlin.android) apply false
|
||||
//id 'org.jetbrains.kotlin.android' version '2.2.0' apply false
|
||||
}
|
||||
@@ -1,13 +1,15 @@
|
||||
plugins {
|
||||
alias(libs.plugins.android.application)
|
||||
alias(libs.plugins.kotlin.android)
|
||||
//alias(libs.plugins.kotlin.android)
|
||||
}
|
||||
|
||||
android {
|
||||
namespace 'com.hmwl.example'
|
||||
namespace 'com.inewme.uvmirror'
|
||||
compileSdk 36
|
||||
|
||||
defaultConfig {
|
||||
applicationId "com.hmwl.f20251110"
|
||||
applicationId "com.inewme.uvmirror.f20251112"
|
||||
minSdk 30
|
||||
targetSdk 36
|
||||
versionCode 1
|
||||
@@ -26,6 +28,20 @@ android {
|
||||
sourceCompatibility JavaVersion.VERSION_17
|
||||
targetCompatibility JavaVersion.VERSION_17
|
||||
}
|
||||
|
||||
buildFeatures {
|
||||
compose true
|
||||
}
|
||||
|
||||
composeOptions {
|
||||
kotlinCompilerExtensionVersion '1.5.1'
|
||||
}
|
||||
kotlinOptions {
|
||||
jvmTarget = '17'
|
||||
}
|
||||
// kotlinOptions {
|
||||
// jvmTarget = '17'
|
||||
// }
|
||||
}
|
||||
|
||||
dependencies {
|
||||
@@ -33,11 +49,21 @@ dependencies {
|
||||
implementation libs.appcompat
|
||||
implementation libs.material
|
||||
implementation libs.games.activity
|
||||
implementation libs.core.ktx
|
||||
implementation libs.androidx.core.ktx
|
||||
testImplementation libs.junit
|
||||
androidTestImplementation libs.ext.junit
|
||||
androidTestImplementation libs.espresso.core
|
||||
|
||||
implementation project(':app')
|
||||
// Jetpack Compose
|
||||
implementation "androidx.compose.ui:ui:1.5.0"
|
||||
implementation "androidx.compose.material3:material3:1.0.0"
|
||||
implementation "androidx.compose.foundation:foundation:1.5.0"
|
||||
implementation "androidx.compose.runtime:runtime:1.5.0"
|
||||
implementation "androidx.activity:activity-compose:1.7.2" // �ؼ����ṩ setContent
|
||||
|
||||
debugImplementation("androidx.compose.ui:ui-tooling:1.5.4")
|
||||
|
||||
def camerax_version = '1.4.2'
|
||||
implementation "androidx.camera:camera-core:$camerax_version"
|
||||
|
||||
@@ -20,6 +20,10 @@
|
||||
android:name="android.app.lib_name"
|
||||
android:value="face_sdk" />
|
||||
</activity>
|
||||
|
||||
<activity
|
||||
android:name=".MakeupActivity"
|
||||
android:exported="false" />
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
|
Before Width: | Height: | Size: 20 KiB |
|
Before Width: | Height: | Size: 24 KiB |
|
Before Width: | Height: | Size: 20 KiB |
|
Before Width: | Height: | Size: 26 KiB |
|
Before Width: | Height: | Size: 22 KiB |
|
Before Width: | Height: | Size: 29 KiB |
|
Before Width: | Height: | Size: 24 KiB |
|
Before Width: | Height: | Size: 28 KiB |
|
Before Width: | Height: | Size: 24 KiB |
|
Before Width: | Height: | Size: 32 KiB |
|
Before Width: | Height: | Size: 15 KiB |
@@ -1,150 +0,0 @@
|
||||
package com.hmwl.example;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.MotionEvent;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.hmwl.face_sdk.InitArg;
|
||||
import com.hmwl.face_sdk.Motion;
|
||||
|
||||
|
||||
import com.hmwl.face_sdk.FaceActivity;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class MainActivity extends FaceActivity
|
||||
{
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState)
|
||||
{
|
||||
Motion motion = new Motion();
|
||||
motion.type = "4";
|
||||
motion.png_names.add("4.png");
|
||||
InitArg initArg = new InitArg();
|
||||
initArg.action_fps = 29;
|
||||
initArg.zoom = 1.5f;
|
||||
initArg.motion = motion;
|
||||
SetInitArg(initArg.toJson());
|
||||
|
||||
|
||||
super.onCreate(savedInstanceState);
|
||||
FaceInit(this);
|
||||
Toast.makeText(this, "4.png", Toast.LENGTH_LONG).show();
|
||||
}
|
||||
|
||||
String GetCurMotionState(int index)
|
||||
{
|
||||
Motion motion = new Motion();
|
||||
motion.type = pngFilesByFolder.get(index).folderName;
|
||||
motion.png_names = pngFilesByFolder.get(index).getFileList();
|
||||
return motion.toJson();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onTouchEvent(MotionEvent event) {
|
||||
// 获取触控动作
|
||||
int action = event.getAction();
|
||||
|
||||
switch (action) {
|
||||
case MotionEvent.ACTION_DOWN:
|
||||
// 手指按下
|
||||
Log.d("TouchEvent", "手指按下 - X: " + event.getX() + ", Y: " + event.getY());
|
||||
break;
|
||||
|
||||
case MotionEvent.ACTION_MOVE:
|
||||
// 手指移动
|
||||
Log.d("TouchEvent", "手指移动 - X: " + event.getX() + ", Y: " + event.getY());
|
||||
break;
|
||||
|
||||
case MotionEvent.ACTION_UP:
|
||||
// 手指抬起
|
||||
Log.d("TouchEvent", "手指抬起");
|
||||
curIndex++;
|
||||
if(curIndex > pngFilesByFolder.size()-1)
|
||||
{
|
||||
curIndex = 0;
|
||||
}
|
||||
ChangeState(GetCurMotionState(curIndex));
|
||||
Toast.makeText(this, pngFilesByFolder.get(curIndex).folderName, Toast.LENGTH_LONG).show();
|
||||
break;
|
||||
}
|
||||
|
||||
return true; // 表示已处理该事件
|
||||
}
|
||||
|
||||
private class FolderInfo {
|
||||
private String folderName;
|
||||
private List<String> fileList;
|
||||
|
||||
public FolderInfo(String folderName, List<String> fileList) {
|
||||
this.folderName = folderName;
|
||||
this.fileList = fileList;
|
||||
}
|
||||
|
||||
public String getFolderName() {
|
||||
return folderName;
|
||||
}
|
||||
|
||||
public List<String> getFileList() {
|
||||
return fileList;
|
||||
}
|
||||
}
|
||||
|
||||
private List<FolderInfo> readPngFilenamesFromAssets(Context context, String filename) {
|
||||
List<FolderInfo> folderList = new ArrayList<>();
|
||||
|
||||
try {
|
||||
InputStream is = context.getAssets().open(filename);
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
stringBuilder.append(line);
|
||||
}
|
||||
|
||||
JSONObject jsonObject = new JSONObject(stringBuilder.toString());
|
||||
|
||||
// 遍历所有文件夹
|
||||
Iterator<String> folderIterator = jsonObject.keys();
|
||||
while (folderIterator.hasNext()) {
|
||||
String folderName = folderIterator.next();
|
||||
JSONArray fileArray = jsonObject.getJSONArray(folderName);
|
||||
|
||||
List<String> filesInFolder = new ArrayList<>();
|
||||
for (int i = 0; i < fileArray.length(); i++) {
|
||||
filesInFolder.add(fileArray.getString(i));
|
||||
}
|
||||
|
||||
folderList.add(new FolderInfo(folderName, filesInFolder));
|
||||
}
|
||||
|
||||
reader.close();
|
||||
is.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return folderList;
|
||||
}
|
||||
int curIndex = 0;
|
||||
List<FolderInfo> pngFilesByFolder = null;
|
||||
private void FaceInit(Context context){
|
||||
pngFilesByFolder = readPngFilenamesFromAssets(context, "pic/motion_data.json");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
package com.inewme.uvmirror
|
||||
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import androidx.activity.ComponentActivity
|
||||
import androidx.activity.compose.setContent
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.material3.Button
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Surface
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
|
||||
class MainActivity : ComponentActivity() {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContent {
|
||||
MyApp()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun MyApp(modifier: Modifier = Modifier) {
|
||||
MaterialTheme {
|
||||
Surface(modifier = modifier) {
|
||||
Greeting("Android")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun Greeting(name: String, modifier: Modifier = Modifier) {
|
||||
val context = LocalContext.current // 获取上下文用于启动 Activity
|
||||
|
||||
Column(
|
||||
modifier = modifier.padding(16.dp)
|
||||
) {
|
||||
Text(text = "Hello $name!")
|
||||
|
||||
Button(
|
||||
onClick = {
|
||||
// 跳转到 MakeupActivity
|
||||
val intent = Intent(context, MakeupActivity::class.java)
|
||||
context.startActivity(intent)
|
||||
}
|
||||
) {
|
||||
Text("Go to Makeup")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Preview(showBackground = true)
|
||||
@Composable
|
||||
fun GreetingPreview() {
|
||||
MaterialTheme {
|
||||
Greeting("Android")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,123 @@
|
||||
|
||||
package com.inewme.uvmirror
|
||||
|
||||
import android.content.Context
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import android.view.MotionEvent
|
||||
import android.widget.Toast
|
||||
import com.hmwl.face_sdk.FaceActivity
|
||||
import com.hmwl.face_sdk.InitArg
|
||||
import com.hmwl.face_sdk.Motion
|
||||
import org.json.JSONArray
|
||||
import org.json.JSONObject
|
||||
import java.io.BufferedReader
|
||||
import java.io.InputStreamReader
|
||||
|
||||
|
||||
class MakeupActivity : FaceActivity() {
|
||||
|
||||
private var curIndex = 0
|
||||
private var pngFilesByFolder: List<FolderInfo>? = null
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
val motion = Motion().apply {
|
||||
type = "4"
|
||||
png_names.add("4.png")
|
||||
}
|
||||
|
||||
val initArg = InitArg().apply {
|
||||
action_fps = 29
|
||||
zoom = 1.5f
|
||||
this.motion = motion
|
||||
}
|
||||
|
||||
SetInitArg(initArg.toJson())
|
||||
|
||||
super.onCreate(savedInstanceState)
|
||||
FaceInit(this)
|
||||
Toast.makeText(this, "4.png", Toast.LENGTH_LONG).show()
|
||||
}
|
||||
|
||||
private fun getCurMotionState(index: Int): String {
|
||||
pngFilesByFolder?.let { folders ->
|
||||
val motion = Motion().apply {
|
||||
type = folders[index].folderName
|
||||
png_names = folders[index].fileList
|
||||
}
|
||||
return motion.toJson()
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
override fun onTouchEvent(event: MotionEvent): Boolean {
|
||||
when (event.action) {
|
||||
MotionEvent.ACTION_DOWN -> {
|
||||
Log.d("TouchEvent", "手指按下 - X: ${event.x}, Y: ${event.y}")
|
||||
if(curIndex == 1)
|
||||
{
|
||||
finish();
|
||||
}
|
||||
}
|
||||
MotionEvent.ACTION_MOVE -> {
|
||||
Log.d("TouchEvent", "手指移动 - X: ${event.x}, Y: ${event.y}")
|
||||
}
|
||||
MotionEvent.ACTION_UP -> {
|
||||
Log.d("TouchEvent", "手指抬起")
|
||||
curIndex++
|
||||
pngFilesByFolder?.let { folders ->
|
||||
if (curIndex > folders.size - 1) {
|
||||
curIndex = 0
|
||||
}
|
||||
ChangeState(getCurMotionState(curIndex))
|
||||
Toast.makeText(this, folders[curIndex].folderName, Toast.LENGTH_LONG).show()
|
||||
}
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
private inner class FolderInfo(
|
||||
val folderName: String,
|
||||
val fileList: List<String>
|
||||
)
|
||||
|
||||
private fun readPngFilenamesFromAssets(context: Context, filename: String): List<FolderInfo> {
|
||||
val folderList = mutableListOf<FolderInfo>()
|
||||
|
||||
try {
|
||||
context.assets.open(filename).use { inputStream ->
|
||||
BufferedReader(InputStreamReader(inputStream)).use { reader ->
|
||||
val stringBuilder = StringBuilder()
|
||||
var line: String?
|
||||
while (reader.readLine().also { line = it } != null) {
|
||||
stringBuilder.append(line)
|
||||
}
|
||||
|
||||
val jsonObject = JSONObject(stringBuilder.toString())
|
||||
val folderIterator = jsonObject.keys()
|
||||
|
||||
while (folderIterator.hasNext()) {
|
||||
val folderName = folderIterator.next()
|
||||
val fileArray = jsonObject.getJSONArray(folderName)
|
||||
val filesInFolder = mutableListOf<String>()
|
||||
|
||||
for (i in 0 until fileArray.length()) {
|
||||
filesInFolder.add(fileArray.getString(i))
|
||||
}
|
||||
|
||||
folderList.add(FolderInfo(folderName, filesInFolder))
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
|
||||
return folderList
|
||||
}
|
||||
|
||||
private fun FaceInit(context: Context) {
|
||||
pngFilesByFolder = readPngFilenamesFromAssets(context, "pic/motion_data.json")
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,3 @@
|
||||
<resources>
|
||||
<string name="app_name">f20251110</string>
|
||||
<string name="app_name">f20251112</string>
|
||||
</resources>
|
||||
@@ -1,17 +0,0 @@
|
||||
package com.hmwl.example;
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,11 @@ espressoCore = "3.7.0"
|
||||
appcompat = "1.7.1"
|
||||
material = "1.13.0"
|
||||
gamesActivity = "2.0.2"
|
||||
kotlin = "1.9.0"
|
||||
coreKtx = "1.12.0"
|
||||
kotlinVersion = "1.9.0"
|
||||
coreKtxVersion = "1.12.0"
|
||||
androidxCoreKtx = "1.12.0"
|
||||
|
||||
[libraries]
|
||||
junit = { group = "junit", name = "junit", version.ref = "junit" }
|
||||
@@ -14,7 +19,11 @@ espresso-core = { group = "androidx.test.espresso", name = "espresso-core", vers
|
||||
appcompat = { group = "androidx.appcompat", name = "appcompat", version.ref = "appcompat" }
|
||||
material = { group = "com.google.android.material", name = "material", version.ref = "material" }
|
||||
games-activity = { group = "androidx.games", name = "games-activity", version.ref = "gamesActivity" }
|
||||
core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" }
|
||||
androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtxVersion" }
|
||||
androidx-core-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "androidxCoreKtx" }
|
||||
|
||||
[plugins]
|
||||
android-application = { id = "com.android.application", version.ref = "agp" }
|
||||
android-library = { id = "com.android.library", version.ref = "agp" }
|
||||
kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlinVersion" }
|
||||
|
||||