diff --git a/mpres/build.gradle b/mpres/build.gradle index 44f2b453..23e7eba3 100644 --- a/mpres/build.gradle +++ b/mpres/build.gradle @@ -47,12 +47,14 @@ android { dependencies { - implementation 'androidx.appcompat:appcompat:1.6.1' - implementation 'com.google.android.material:material:1.10.0' - implementation 'androidx.activity:activity:1.8.0' - implementation 'androidx.constraintlayout:constraintlayout:2.1.4' + implementation 'androidx.appcompat:appcompat:1.3.0' + implementation 'com.google.android.material:material:1.4.0' + // implementation 'androidx.activity:activity:1.8.0' + implementation 'androidx.constraintlayout:constraintlayout:2.0.4' + implementation project(':common') testImplementation 'junit:junit:4.13.2' androidTestImplementation 'androidx.test.ext:junit:1.1.5' androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1' implementation project(path: ':common') + implementation files('../app/libs/devapi.aar') } \ No newline at end of file diff --git a/mpres/src/main/AndroidManifest.xml b/mpres/src/main/AndroidManifest.xml index 2c6246be..05bdb1d4 100644 --- a/mpres/src/main/AndroidManifest.xml +++ b/mpres/src/main/AndroidManifest.xml @@ -1,5 +1,6 @@ diff --git a/mpres/src/main/java/com/xypower/mpres/MainActivity.java b/mpres/src/main/java/com/xypower/mpres/MainActivity.java index 04659197..6da2d116 100644 --- a/mpres/src/main/java/com/xypower/mpres/MainActivity.java +++ b/mpres/src/main/java/com/xypower/mpres/MainActivity.java @@ -1,34 +1,54 @@ package com.xypower.mpres; import android.content.Context; +import android.content.Intent; import android.content.res.AssetManager; import android.os.Bundle; +import android.os.Handler; +import android.text.TextUtils; -import androidx.activity.EdgeToEdge; import androidx.appcompat.app.AppCompatActivity; import androidx.core.graphics.Insets; import androidx.core.view.ViewCompat; 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.FileOutputStream; import java.io.InputStream; public class MainActivity extends AppCompatActivity { + private Handler mHandler; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - EdgeToEdge.enable(this); setContentView(R.layout.activity_main); - ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> { - Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars()); - v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom); - return insets; - }); + + Intent intent = getIntent(); + int initres = intent.getIntExtra("initres", 0); + 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; String destPath = MicroPhotoContext.buildMpAppDir(context); @@ -65,13 +85,13 @@ public class MainActivity extends AppCompatActivity { return false; } - Runnable runnable = new Runnable() { + Runnable thRunnable = new Runnable() { @Override public void run() { sleep(5000); - File tmpDestPath = new File(MicroPhotoContext.buildMasterAppDir(context)); + File tmpDestPath = new File(MicroPhotoContext.buildMpResAppDir(context)); tmpDestPath = new File(tmpDestPath, "mpdata"); if (tmpDestPath.exists()) { try { @@ -81,11 +101,12 @@ public class MainActivity extends AppCompatActivity { } } 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(); return true; @@ -187,4 +208,31 @@ public class MainActivity extends AppCompatActivity { 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(); + } + } } \ No newline at end of file diff --git a/mpres/src/main/res/values-night/themes.xml b/mpres/src/main/res/values-night/themes.xml index 1ab943e1..b85d6fb3 100644 --- a/mpres/src/main/res/values-night/themes.xml +++ b/mpres/src/main/res/values-night/themes.xml @@ -1,6 +1,6 @@ - diff --git a/mpres/src/main/res/values/themes.xml b/mpres/src/main/res/values/themes.xml index 5a496713..2df1e837 100644 --- a/mpres/src/main/res/values/themes.xml +++ b/mpres/src/main/res/values/themes.xml @@ -1,6 +1,6 @@ -