diff --git a/.androidide/editor/openedFiles.json b/.androidide/editor/openedFiles.json deleted file mode 100644 index c8d405b..0000000 --- a/.androidide/editor/openedFiles.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "allFiles": [ - { - "file": "/storage/emulated/0/AppProjects/Application/app/src/main/java/com/disney/WMW/WMWActivity.java", - "selection": { - "end": { - "column": 24, - "index": -1, - "line": 27 - }, - "start": { - "column": 24, - "index": -1, - "line": 27 - } - } - } - ], - "selectedFile": "/storage/emulated/0/AppProjects/Application/app/src/main/java/com/disney/WMW/WMWActivity.java" -} \ No newline at end of file diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..7fd2b15 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,31 @@ +name: Android CI Debug + +on: + pull_request: + push: + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Set up JDK 17 + uses: actions/setup-java@v3.9.0 + with: + distribution: 'temurin' + java-version: '17' + + - name: Grant execute permission for gradlew + run: chmod +x gradlew + - name: Build with Gradle + run: ./gradlew assembleDebug + + - name: Upload Debug apk + uses: actions/upload-artifact@v3 + with: + name: apk-debug + path: app/build/outputs/apk/debug diff --git a/.gitignore b/.gitignore index 9ef6120..deaf8e7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /app/build /.gradle -/local.properties \ No newline at end of file +/local.properties +/push.sh diff --git a/app/src/main/assets/wmw-extra.zip b/app/src/main/assets/wmw-extra.zip new file mode 100644 index 0000000..62a9721 Binary files /dev/null and b/app/src/main/assets/wmw-extra.zip differ diff --git a/app/src/main/java/com/disney/WMW/WMWActivity.java b/app/src/main/java/com/disney/WMW/WMWActivity.java index 67f2fb1..0c15b03 100644 --- a/app/src/main/java/com/disney/WMW/WMWActivity.java +++ b/app/src/main/java/com/disney/WMW/WMWActivity.java @@ -392,10 +392,6 @@ protected void onPause() { protected void onResume() { super.onResume(); - if (new File(getObbPath()).exists()) - { - notifyAddObbFilePathToFileManager(getObbPath()); - } this.isRunning = true; if (this._view != null) { this.resumeOnFocus = false; @@ -424,25 +420,7 @@ protected void onResume() { shareHandler.sendMessageDelayed(message, 5000L); } - public String getObbPath() { - PackageManager packageManager = getPackageManager(); - PackageInfo packageInfo = null; - try { - packageInfo = packageManager.getPackageInfo(getPackageName(), 0); - } catch (PackageManager.NameNotFoundException e) {} - - String pn = getPackageName(); - if (Environment.getExternalStorageState().equals("mounted")) { - File file = Environment.getExternalStorageDirectory(); - file = new File(file.toString() + "/Android/obb/" + pn); - if (packageInfo.versionCode > 0) { - String str = file + File.separator + "main." + packageInfo.versionCode + "." + pn + ".obb"; - Log.e("WMW", "obbFilePath: " + str); - return str; - } - } - return null; - } + protected void onStart() { super.onStart(); diff --git a/app/src/main/java/thercn/wmw/AppUtils.java b/app/src/main/java/thercn/wmw/AppUtils.java new file mode 100644 index 0000000..f67b6aa --- /dev/null +++ b/app/src/main/java/thercn/wmw/AppUtils.java @@ -0,0 +1,38 @@ +package thercn.wmw; + +import android.app.Activity; +import android.util.Log; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; + +public class AppUtils { + public static void ExportAssets(Activity activity, String outPath, + String fileName) { + File outdir = new File(outPath); + if (!outdir.exists()) { + outdir.mkdirs(); + } + try { + InputStream inputStream = activity.getAssets().open(fileName); + File outFile = new File(outdir, fileName); + if (outFile.exists()) { + return; + } + FileOutputStream fileOutputStream = new FileOutputStream(outFile); + byte[] buffer = new byte[1024]; + int byteRead; + while (-1 != (byteRead = inputStream.read(buffer))) { + fileOutputStream.write(buffer, 0, byteRead); + } + inputStream.close(); + fileOutputStream.flush(); + fileOutputStream.close(); + } catch (IOException e) { + Log.e("WMW", "", e); + } + } + + +} diff --git a/app/src/main/java/thercn/wmw/MainActivity.java b/app/src/main/java/thercn/wmw/MainActivity.java index ba2f1d4..b7b1b08 100644 --- a/app/src/main/java/thercn/wmw/MainActivity.java +++ b/app/src/main/java/thercn/wmw/MainActivity.java @@ -1,39 +1,84 @@ package thercn.wmw; - + import android.app.Activity; import android.content.Intent; +import android.content.pm.PackageInfo; +import android.content.pm.PackageManager; import android.os.Bundle; +import android.os.Environment; +import android.util.Log; import android.view.View; import android.widget.Button; -import android.widget.Switch; +import android.widget.CheckBox; import com.disney.WMW.WMWActivity; import java.io.File; import java.io.IOException; -import android.widget.CheckBox; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; public class MainActivity extends Activity { - + + public static String appDataDir = Environment.getExternalStorageDirectory().toString() + "/WMW"; public static boolean isIPadScreen = false; static { System.loadLibrary("wmw"); } - + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Permission.申请(this); File obbdir = getObbDir(); - if (!obbdir.exists()) { + + File dataDir = new File(appDataDir); + File extraDataFile = new File(appDataDir + "/wmw-extra.zip"); + if (!obbdir.exists() || !dataDir.exists()) { obbdir.mkdirs(); + dataDir.mkdirs(); + } + String obbPath = getObbPath(); + if (!extraDataFile.exists()) { + AppUtils.ExportAssets(this, appDataDir, "wmw-extra.zip"); } try { - Runtime.getRuntime().exec("logcat >" + "/sdcard/wmw.log"); - } catch (IOException e) {} + Runtime.getRuntime().exec("cp " + extraDataFile.toString() + " " + obbPath); + Runtime.getRuntime().exec("logcat >" + appDataDir + "/wmw.log"); + } catch (IOException e) { + + } finally { + Path source = Paths.get(extraDataFile.toString()); + Path target = Paths.get(obbPath); + try { + Files.copy(source, target); + } catch (IOException e) {} + } initLayout(); - + } + + public String getObbPath() { + PackageManager packageManager = getPackageManager(); + PackageInfo packageInfo = null; + try { + packageInfo = packageManager.getPackageInfo(getPackageName(), 0); + } catch (PackageManager.NameNotFoundException e) {} + + String pn = getPackageName(); + if (Environment.getExternalStorageState().equals("mounted")) { + File file = Environment.getExternalStorageDirectory(); + file = new File(getObbDir().toString() + "/" + pn); + if (packageInfo.versionCode > 0) { + String str = file + File.separator + "main." + packageInfo.versionCode + "." + pn + ".obb"; + Log.e("WMW", "obbFilePath: " + str); + return str; + } + } + return null; + } + private void initLayout() { final CheckBox ipadScreen = findViewById(R.id.resetSize); Button startGame = findViewById(R.id.startGame); @@ -41,8 +86,7 @@ private void initLayout() { @Override public void onClick(View view) { - if (ipadScreen.isChecked()) - { + if (ipadScreen.isChecked()) { isIPadScreen = true; } } @@ -51,10 +95,10 @@ public void onClick(View view) { @Override public void onClick(View view) { - Intent intent = new Intent(MainActivity.this,WMWActivity.class); + Intent intent = new Intent(MainActivity.this, WMWActivity.class); startActivity(intent); } }); } - + }