启动时如果需要初始化mpapp配置,则从assets中拷贝到特定目录

lowmem
Matthew 2 months ago
parent 75a7c17d62
commit e2c4e51550

@ -47,12 +47,14 @@ android {
dependencies { dependencies {
implementation 'androidx.appcompat:appcompat:1.6.1' implementation 'androidx.appcompat:appcompat:1.3.0'
implementation 'com.google.android.material:material:1.10.0' implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.activity:activity:1.8.0' // implementation 'androidx.activity:activity:1.8.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4' implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation project(':common')
testImplementation 'junit:junit:4.13.2' testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5' androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1' androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
implementation project(path: ':common') implementation project(path: ':common')
implementation files('../app/libs/devapi.aar')
} }

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:sharedUserId="com.xypower.mp" android:sharedUserId="com.xypower.mp"
tools:ignore="Deprecated" > tools:ignore="Deprecated" >

@ -1,34 +1,54 @@
package com.xypower.mpres; package com.xypower.mpres;
import android.content.Context; import android.content.Context;
import android.content.Intent;
import android.content.res.AssetManager; import android.content.res.AssetManager;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler;
import android.text.TextUtils;
import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets; import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat; import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat; import androidx.core.view.WindowInsetsCompat;
import com.dev.devapi.api.SysApi;
import com.xypower.common.FilesUtils;
import com.xypower.common.MicroPhotoContext;
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.InputStream; import java.io.InputStream;
public class MainActivity extends AppCompatActivity { public class MainActivity extends AppCompatActivity {
private Handler mHandler;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
EdgeToEdge.enable(this);
setContentView(R.layout.activity_main); setContentView(R.layout.activity_main);
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars()); Intent intent = getIntent();
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom); int initres = intent.getIntExtra("initres", 0);
return insets; if (initres != 0) {
}); mHandler = new Handler();
Runnable runnable = new Runnable() {
@Override
public void run() {
notifyMpApp();
}
};
initMpAppConfigurations(getApplicationContext(), mHandler, runnable);
}
}
private void notifyMpApp() {
restartMpApp(getApplicationContext(), "FIRST Config Init");
sleep(100);
System.exit(0);
} }
public static boolean initMpAppConfigurations(final Context context) { public static boolean initMpAppConfigurations(final Context context, final Handler handler, final Runnable runnable) {
boolean existed = true; boolean existed = true;
String destPath = MicroPhotoContext.buildMpAppDir(context); String destPath = MicroPhotoContext.buildMpAppDir(context);
@ -65,13 +85,13 @@ public class MainActivity extends AppCompatActivity {
return false; return false;
} }
Runnable runnable = new Runnable() { Runnable thRunnable = new Runnable() {
@Override @Override
public void run() { public void run() {
sleep(5000); sleep(5000);
File tmpDestPath = new File(MicroPhotoContext.buildMasterAppDir(context)); File tmpDestPath = new File(MicroPhotoContext.buildMpResAppDir(context));
tmpDestPath = new File(tmpDestPath, "mpdata"); tmpDestPath = new File(tmpDestPath, "mpdata");
if (tmpDestPath.exists()) { if (tmpDestPath.exists()) {
try { try {
@ -81,11 +101,12 @@ public class MainActivity extends AppCompatActivity {
} }
} }
copyAssetsDir(context, "mpapp/data", tmpDestPath.getAbsolutePath()); copyAssetsDir(context, "mpapp/data", tmpDestPath.getAbsolutePath());
MpMasterService.restartMpApp(context.getApplicationContext(), "FIRST Config Init");
handler.postDelayed(runnable, 0);
} }
}; };
Thread th = new Thread(runnable); Thread th = new Thread(thRunnable);
th.start(); th.start();
return true; return true;
@ -187,4 +208,31 @@ public class MainActivity extends AppCompatActivity {
FilesUtils.closeFriendly(fos); FilesUtils.closeFriendly(fos);
} }
} }
private static void sleep(long ms) {
try {
Thread.sleep(ms);
} catch (Exception ex) {
}
}
public static void restartMpApp(Context context, String reason) {
SysApi.forceStopApp(context, MicroPhotoContext.PACKAGE_NAME_MPAPP);
sleep(100);
try {
Intent intent = context.getPackageManager().getLaunchIntentForPackage(MicroPhotoContext.PACKAGE_NAME_MPAPP);
if (intent != null) {
intent.putExtra("noDelay", 1);
if (!TextUtils.isEmpty(reason)) {
intent.putExtra("reason", reason);
}
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
}
} catch (Exception e) {
e.printStackTrace();
}
}
} }

@ -1,6 +1,6 @@
<resources xmlns:tools="http://schemas.android.com/tools"> <resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. --> <!-- Base application theme. -->
<style name="Base.Theme.MicroPhoto" parent="Theme.Material3.DayNight.NoActionBar"> <style name="Base.Theme.MicroPhoto" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
<!-- Customize your dark theme here. --> <!-- Customize your dark theme here. -->
<!-- <item name="colorPrimary">@color/my_dark_primary</item> --> <!-- <item name="colorPrimary">@color/my_dark_primary</item> -->
</style> </style>

@ -1,6 +1,6 @@
<resources xmlns:tools="http://schemas.android.com/tools"> <resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. --> <!-- Base application theme. -->
<style name="Base.Theme.MicroPhoto" parent="Theme.Material3.DayNight.NoActionBar"> <style name="Base.Theme.MicroPhoto" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
<!-- Customize your light theme here. --> <!-- Customize your light theme here. -->
<!-- <item name="colorPrimary">@color/my_light_primary</item> --> <!-- <item name="colorPrimary">@color/my_light_primary</item> -->
</style> </style>

Loading…
Cancel
Save