From 7f023de5cb2299f9ef9e1363afde414fe14ede51 Mon Sep 17 00:00:00 2001 From: MoNTE48 Date: Thu, 7 Nov 2019 00:39:39 +0100 Subject: [PATCH] Android: build fixes & compat fixes --- build/android/build.gradle | 14 ++-- build/android/gradle.properties | 2 + .../gradle/wrapper/gradle-wrapper.properties | 7 +- build/android/src/debug/AndroidManifest.xml | 5 -- build/android/src/main/AndroidManifest.xml | 11 +-- .../net.minetest.minetest/MainActivity.java | 40 +++++------ .../MinetestAssetCopy.java | 72 ++++++++----------- .../MinetestTextEntry.java | 8 +-- .../MtNativeActivity.java | 11 ++- .../src/main/res/values-v21/styles.xml | 13 ++-- build/android/src/main/res/values/styles.xml | 8 ++- 11 files changed, 91 insertions(+), 100 deletions(-) create mode 100644 build/android/gradle.properties delete mode 100644 build/android/src/debug/AndroidManifest.xml diff --git a/build/android/build.gradle b/build/android/build.gradle index 81c99c974..d86598b5b 100644 --- a/build/android/build.gradle +++ b/build/android/build.gradle @@ -4,7 +4,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:3.4.2' + classpath 'com.android.tools.build:gradle:3.5.1' } } @@ -24,13 +24,14 @@ def sqlite3_version = "3240000" apply plugin: "com.android.application" android { - compileSdkVersion 28 + compileSdkVersion 29 + buildToolsVersion '29.0.2' defaultConfig { versionCode 24 versionName "${System.env.VERSION_STR}.${versionCode}" minSdkVersion 14 - targetSdkVersion 28 + targetSdkVersion 29 applicationId "net.minetest.minetest" manifestPlaceholders = [package: "net.minetest.minetest", project: project.name] ndk { @@ -41,6 +42,11 @@ android { } } + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } + lintOptions { disable "OldTargetApi", "GoogleAppIndexingWarning" } @@ -165,5 +171,5 @@ task cleanAll(type: Delete, dependsOn: [clean, cleanAssets, cleanIconv, } dependencies { - implementation 'com.android.support:support-v4:28.0.0' + implementation 'androidx.core:core:1.1.0' } diff --git a/build/android/gradle.properties b/build/android/gradle.properties new file mode 100644 index 000000000..5465fec0e --- /dev/null +++ b/build/android/gradle.properties @@ -0,0 +1,2 @@ +android.enableJetifier=true +android.useAndroidX=true \ No newline at end of file diff --git a/build/android/gradle/wrapper/gradle-wrapper.properties b/build/android/gradle/wrapper/gradle-wrapper.properties index 7ba375433..22ac96460 100644 --- a/build/android/gradle/wrapper/gradle-wrapper.properties +++ b/build/android/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1 @@ -#Fri Aug 09 22:14:33 CEST 2019 -distributionBase=GRADLE_USER_HOME -distributionPath=wrapper/dists -zipStoreBase=GRADLE_USER_HOME -zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-5.5.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-all.zip diff --git a/build/android/src/debug/AndroidManifest.xml b/build/android/src/debug/AndroidManifest.xml deleted file mode 100644 index ee04d1d03..000000000 --- a/build/android/src/debug/AndroidManifest.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - - diff --git a/build/android/src/main/AndroidManifest.xml b/build/android/src/main/AndroidManifest.xml index 7f61cda38..fb1de9cf0 100644 --- a/build/android/src/main/AndroidManifest.xml +++ b/build/android/src/main/AndroidManifest.xml @@ -1,5 +1,6 @@ @@ -11,14 +12,14 @@ + android:resizeableActivity="false" + tools:targetApi="n"> + android:value="2.4" /> + android:windowSoftInputMode="stateAlwaysHidden" /> + android:theme="@style/AppTheme" /> diff --git a/build/android/src/main/java/net.minetest.minetest/MainActivity.java b/build/android/src/main/java/net.minetest.minetest/MainActivity.java index 1baa71668..71b0ce144 100644 --- a/build/android/src/main/java/net.minetest.minetest/MainActivity.java +++ b/build/android/src/main/java/net.minetest.minetest/MainActivity.java @@ -6,17 +6,17 @@ import android.content.Intent; import android.content.pm.PackageManager; import android.os.Build; import android.os.Bundle; -import android.support.annotation.NonNull; -import android.support.v4.app.ActivityCompat; -import android.support.v4.content.ContextCompat;; import android.widget.Toast; +import androidx.annotation.NonNull; +import androidx.core.app.ActivityCompat; +import androidx.core.content.ContextCompat; + import java.util.ArrayList; import java.util.Arrays; import java.util.List; public class MainActivity extends Activity { - private final static int PERMISSIONS = 1; private static final String[] REQUIRED_SDK_PERMISSIONS = new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}; @@ -30,8 +30,8 @@ public class MainActivity extends Activity { } } - protected void checkPermission() { - final List missingPermissions = new ArrayList(); + private void checkPermission() { + final List missingPermissions = new ArrayList<>(); // check required permission for (final String permission : REQUIRED_SDK_PERMISSIONS) { final int result = ContextCompat.checkSelfPermission(this, permission); @@ -42,7 +42,7 @@ public class MainActivity extends Activity { if (!missingPermissions.isEmpty()) { // request permission final String[] permissions = missingPermissions - .toArray(new String[missingPermissions.size()]); + .toArray(new String[0]); ActivityCompat.requestPermissions(this, permissions, PERMISSIONS); } else { final int[] grantResults = new int[REQUIRED_SDK_PERMISSIONS.length]; @@ -53,25 +53,23 @@ public class MainActivity extends Activity { } @Override - public void onRequestPermissionsResult(int requestCode, @NonNull String permissions[], + public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { - switch (requestCode) { - case PERMISSIONS: - for (int index = 0; index < permissions.length; index++) { - if (grantResults[index] != PackageManager.PERMISSION_GRANTED) { - // permission not granted - toast and exit - Toast.makeText(this, R.string.not_granted, Toast.LENGTH_LONG).show(); - finish(); - return; - } + if (requestCode == PERMISSIONS) { + for (int index = 0; index < permissions.length; index++) { + if (grantResults[index] != PackageManager.PERMISSION_GRANTED) { + // permission not granted - toast and exit + Toast.makeText(this, R.string.not_granted, Toast.LENGTH_LONG).show(); + finish(); + return; } - // permission were granted - run - next(); - break; + } + // permission were granted - run + next(); } } - public void next() { + private void next() { Intent intent = new Intent(this, MtNativeActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_CLEAR_TASK); startActivity(intent); diff --git a/build/android/src/main/java/net.minetest.minetest/MinetestAssetCopy.java b/build/android/src/main/java/net.minetest.minetest/MinetestAssetCopy.java index 03b34f705..84cfca796 100644 --- a/build/android/src/main/java/net.minetest.minetest/MinetestAssetCopy.java +++ b/build/android/src/main/java/net.minetest.minetest/MinetestAssetCopy.java @@ -1,5 +1,6 @@ package net.minetest.minetest; +import android.annotation.SuppressLint; import android.app.Activity; import android.content.res.AssetFileDescriptor; import android.os.AsyncTask; @@ -19,13 +20,12 @@ import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; -import java.util.Iterator; import java.util.Vector; public class MinetestAssetCopy extends Activity { - ProgressBar m_ProgressBar; - TextView m_Filename; - copyAssetTask m_AssetCopy; + private ProgressBar m_ProgressBar; + private TextView m_Filename; + private copyAssetTask m_AssetCopy; @Override public void onCreate(Bundle savedInstanceState) { @@ -53,29 +53,26 @@ public class MinetestAssetCopy extends Activity { super.onResume(); makeFullScreen(); } - + @Override - protected void onDestroy() { + protected void onDestroy() { super.onDestroy(); if (m_AssetCopy != null) { m_AssetCopy.cancel(true); } - } + } - public void makeFullScreen() { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { + private void makeFullScreen() { + if (Build.VERSION.SDK_INT >= 19) this.getWindow().getDecorView().setSystemUiVisibility( - View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY - ); - } + View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY); } @Override public void onWindowFocusChanged(boolean hasFocus) { super.onWindowFocusChanged(hasFocus); - if (hasFocus) { + if (hasFocus) makeFullScreen(); - } } /* preserve asset copy background task to prevent restart of copying */ @@ -85,7 +82,8 @@ public class MinetestAssetCopy extends Activity { return this; } - private static class copyAssetTask extends AsyncTask { + @SuppressLint("StaticFieldLeak") + private class copyAssetTask extends AsyncTask { boolean m_copy_started = false; String m_Foldername = "media"; Vector m_foldernames; @@ -99,7 +97,7 @@ public class MinetestAssetCopy extends Activity { InputStream src = getAssets().open(filename); byte[] buf = new byte[4096]; - int len = 0; + int len; while ((len = src.read(buf)) > 0) { size += len; } @@ -111,10 +109,10 @@ public class MinetestAssetCopy extends Activity { @Override protected String doInBackground(String... files) { - m_foldernames = new Vector(); - m_filenames = new Vector(); - m_tocopy = new Vector(); - m_asset_size_unknown = new Vector(); + m_foldernames = new Vector<>(); + m_filenames = new Vector<>(); + m_tocopy = new Vector<>(); + m_asset_size_unknown = new Vector<>(); String baseDir = Environment.getExternalStorageDirectory().getAbsolutePath() + "/"; @@ -128,9 +126,9 @@ public class MinetestAssetCopy extends Activity { } else { File[] todel = TempFolder.listFiles(); - for (int i = 0; i < todel.length; i++) { - Log.v("MinetestAssetCopy", "deleting: " + todel[i].getAbsolutePath()); - todel[i].delete(); + for (File file : todel) { + Log.v("MinetestAssetCopy", "deleting: " + file.getAbsolutePath()); + file.delete(); } } @@ -166,9 +164,9 @@ public class MinetestAssetCopy extends Activity { if (m_asset_size_unknown.contains(filename)) { File testme = new File(baseDir + "/" + filename); - if (testme.exists()) { + if (testme.exists()) filesize = testme.length(); - } + asset_size_unknown = true; } @@ -249,12 +247,10 @@ public class MinetestAssetCopy extends Activity { protected void onProgressUpdate(Integer... progress) { if (m_copy_started) { - boolean shortened = false; String todisplay = m_tocopy.get(progress[0]); m_ProgressBar.setProgress(progress[0]); m_Filename.setText(todisplay); } else { - boolean shortened = false; String todisplay = m_Foldername; String full_text = "scanning " + todisplay + " ..."; m_Filename.setText(full_text); @@ -264,14 +260,11 @@ public class MinetestAssetCopy extends Activity { /** * check all files and folders in filelist */ - protected void ProcessFileList() { + void ProcessFileList() { String FlashBaseDir = Environment.getExternalStorageDirectory().getAbsolutePath(); - Iterator itr = m_filenames.iterator(); - - while (itr.hasNext()) { - String current_path = (String) itr.next(); + for (String current_path : m_filenames) { String FlashPath = FlashBaseDir + "/" + current_path; if (isAssetFolder(current_path)) { @@ -300,7 +293,7 @@ public class MinetestAssetCopy extends Activity { File testme = new File(FlashPath); long asset_filesize = -1; - long stored_filesize = -1; + long stored_filesize; if (testme.exists()) { try { @@ -308,7 +301,6 @@ public class MinetestAssetCopy extends Activity { asset_filesize = fd.getLength(); fd.close(); } catch (IOException e) { - refresh = true; m_asset_size_unknown.add(current_path); Log.e("MinetestAssetCopy", "Failed to open asset file \"" + FlashPath + "\" for size check"); @@ -316,22 +308,20 @@ public class MinetestAssetCopy extends Activity { stored_filesize = testme.length(); - if (asset_filesize == stored_filesize) { + if (asset_filesize == stored_filesize) refresh = false; - } } - if (refresh) { + if (refresh) m_tocopy.add(current_path); - } } } /** * read list of folders prepared on package build */ - protected void BuildFolderList() { + void BuildFolderList() { try { InputStream is = getAssets().open("index.txt"); BufferedReader reader = new BufferedReader(new InputStreamReader(is)); @@ -351,7 +341,7 @@ public class MinetestAssetCopy extends Activity { /** * read list of asset files prepared on package build */ - protected void BuildFileList() { + void BuildFileList() { long entrycount = 0; try { InputStream is = getAssets().open("filelist.txt"); @@ -374,7 +364,7 @@ public class MinetestAssetCopy extends Activity { finish(); } - protected boolean isAssetFolder(String path) { + boolean isAssetFolder(String path) { return m_foldernames.contains(path); } } diff --git a/build/android/src/main/java/net.minetest.minetest/MinetestTextEntry.java b/build/android/src/main/java/net.minetest.minetest/MinetestTextEntry.java index 4cd899025..cb7ba8d3b 100644 --- a/build/android/src/main/java/net.minetest.minetest/MinetestTextEntry.java +++ b/build/android/src/main/java/net.minetest.minetest/MinetestTextEntry.java @@ -15,8 +15,8 @@ public class MinetestTextEntry extends Activity { private final int MultiLineTextInput = 1; private final int SingleLineTextInput = 2; private final int SingleLinePasswordInput = 3; - public AlertDialog mTextInputDialog; - public EditText mTextInputWidget; + private AlertDialog mTextInputDialog; + private EditText mTextInputWidget; @Override public void onCreate(Bundle savedInstanceState) { @@ -71,7 +71,7 @@ public class MinetestTextEntry extends Activity { mTextInputDialog.show(); } - public void pushResult(String text) { + private void pushResult(String text) { Intent resultData = new Intent(); resultData.putExtra("text", text); setResult(Activity.RESULT_OK, resultData); @@ -79,7 +79,7 @@ public class MinetestTextEntry extends Activity { finish(); } - public void cancelDialog() { + private void cancelDialog() { setResult(Activity.RESULT_CANCELED); mTextInputDialog.dismiss(); finish(); diff --git a/build/android/src/main/java/net.minetest.minetest/MtNativeActivity.java b/build/android/src/main/java/net.minetest.minetest/MtNativeActivity.java index b32e97b53..f49d078fe 100644 --- a/build/android/src/main/java/net.minetest.minetest/MtNativeActivity.java +++ b/build/android/src/main/java/net.minetest.minetest/MtNativeActivity.java @@ -37,20 +37,17 @@ public class MtNativeActivity extends NativeActivity { makeFullScreen(); } - public void makeFullScreen() { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { + private void makeFullScreen() { + if (Build.VERSION.SDK_INT >= 19) this.getWindow().getDecorView().setSystemUiVisibility( - View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY - ); - } + View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY); } @Override public void onWindowFocusChanged(boolean hasFocus) { super.onWindowFocusChanged(hasFocus); - if (hasFocus) { + if (hasFocus) makeFullScreen(); - } } public void copyAssets() { diff --git a/build/android/src/main/res/values-v21/styles.xml b/build/android/src/main/res/values-v21/styles.xml index 825ab1d37..8b0777467 100644 --- a/build/android/src/main/res/values-v21/styles.xml +++ b/build/android/src/main/res/values-v21/styles.xml @@ -1,12 +1,17 @@ - + - - diff --git a/build/android/src/main/res/values/styles.xml b/build/android/src/main/res/values/styles.xml index 3e66ff4ba..1bd41ae76 100644 --- a/build/android/src/main/res/values/styles.xml +++ b/build/android/src/main/res/values/styles.xml @@ -1,12 +1,14 @@ - -