Skip to content

Commit 7f023de

Browse files
MoNTE48nerzhul
MoNTE48
authored andcommittedNov 9, 2019
Android: build fixes & compat fixes
1 parent dfd5f7c commit 7f023de

File tree

11 files changed

+91
-100
lines changed

11 files changed

+91
-100
lines changed
 

Diff for: ‎build/android/build.gradle

+10-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ buildscript {
44
jcenter()
55
}
66
dependencies {
7-
classpath 'com.android.tools.build:gradle:3.4.2'
7+
classpath 'com.android.tools.build:gradle:3.5.1'
88
}
99
}
1010

@@ -24,13 +24,14 @@ def sqlite3_version = "3240000"
2424
apply plugin: "com.android.application"
2525

2626
android {
27-
compileSdkVersion 28
27+
compileSdkVersion 29
28+
buildToolsVersion '29.0.2'
2829

2930
defaultConfig {
3031
versionCode 24
3132
versionName "${System.env.VERSION_STR}.${versionCode}"
3233
minSdkVersion 14
33-
targetSdkVersion 28
34+
targetSdkVersion 29
3435
applicationId "net.minetest.minetest"
3536
manifestPlaceholders = [package: "net.minetest.minetest", project: project.name]
3637
ndk {
@@ -41,6 +42,11 @@ android {
4142
}
4243
}
4344

45+
compileOptions {
46+
sourceCompatibility JavaVersion.VERSION_1_8
47+
targetCompatibility JavaVersion.VERSION_1_8
48+
}
49+
4450
lintOptions {
4551
disable "OldTargetApi", "GoogleAppIndexingWarning"
4652
}
@@ -165,5 +171,5 @@ task cleanAll(type: Delete, dependsOn: [clean, cleanAssets, cleanIconv,
165171
}
166172

167173
dependencies {
168-
implementation 'com.android.support:support-v4:28.0.0'
174+
implementation 'androidx.core:core:1.1.0'
169175
}

Diff for: ‎build/android/gradle.properties

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
android.enableJetifier=true
2+
android.useAndroidX=true
+1-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1 @@
1-
#Fri Aug 09 22:14:33 CEST 2019
2-
distributionBase=GRADLE_USER_HOME
3-
distributionPath=wrapper/dists
4-
zipStoreBase=GRADLE_USER_HOME
5-
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-5.5.1-all.zip
1+
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-all.zip

Diff for: ‎build/android/src/debug/AndroidManifest.xml

-5
This file was deleted.

Diff for: ‎build/android/src/main/AndroidManifest.xml

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:tools="http://schemas.android.com/tools"
34
package="net.minetest.minetest"
45
android:installLocation="auto">
56

@@ -11,14 +12,14 @@
1112
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
1213

1314
<application
14-
android:allowBackup="true"
1515
android:icon="@mipmap/ic_launcher"
1616
android:label="${project}"
17-
android:resizeableActivity="false">
17+
android:resizeableActivity="false"
18+
tools:targetApi="n">
1819

1920
<meta-data
2021
android:name="android.max_aspect"
21-
android:value="2.1" />
22+
android:value="2.4" />
2223

2324
<activity
2425
android:name=".MainActivity"
@@ -50,10 +51,10 @@
5051
android:name=".MinetestTextEntry"
5152
android:configChanges="keyboardHidden|orientation|screenSize"
5253
android:theme="@style/Theme.Dialog"
53-
android:windowSoftInputMode="stateAlwaysHidden"/>
54+
android:windowSoftInputMode="stateAlwaysHidden" />
5455
<activity
5556
android:name=".MinetestAssetCopy"
5657
android:screenOrientation="sensorLandscape"
57-
android:theme="@style/AppTheme"/>
58+
android:theme="@style/AppTheme" />
5859
</application>
5960
</manifest>

Diff for: ‎build/android/src/main/java/net.minetest.minetest/MainActivity.java

+19-21
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@
66
import android.content.pm.PackageManager;
77
import android.os.Build;
88
import android.os.Bundle;
9-
import android.support.annotation.NonNull;
10-
import android.support.v4.app.ActivityCompat;
11-
import android.support.v4.content.ContextCompat;;
129
import android.widget.Toast;
1310

11+
import androidx.annotation.NonNull;
12+
import androidx.core.app.ActivityCompat;
13+
import androidx.core.content.ContextCompat;
14+
1415
import java.util.ArrayList;
1516
import java.util.Arrays;
1617
import java.util.List;
1718

1819
public class MainActivity extends Activity {
19-
2020
private final static int PERMISSIONS = 1;
2121
private static final String[] REQUIRED_SDK_PERMISSIONS = new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE};
2222

@@ -30,8 +30,8 @@ public void onCreate(Bundle savedInstanceState) {
3030
}
3131
}
3232

33-
protected void checkPermission() {
34-
final List<String> missingPermissions = new ArrayList<String>();
33+
private void checkPermission() {
34+
final List<String> missingPermissions = new ArrayList<>();
3535
// check required permission
3636
for (final String permission : REQUIRED_SDK_PERMISSIONS) {
3737
final int result = ContextCompat.checkSelfPermission(this, permission);
@@ -42,7 +42,7 @@ protected void checkPermission() {
4242
if (!missingPermissions.isEmpty()) {
4343
// request permission
4444
final String[] permissions = missingPermissions
45-
.toArray(new String[missingPermissions.size()]);
45+
.toArray(new String[0]);
4646
ActivityCompat.requestPermissions(this, permissions, PERMISSIONS);
4747
} else {
4848
final int[] grantResults = new int[REQUIRED_SDK_PERMISSIONS.length];
@@ -53,25 +53,23 @@ protected void checkPermission() {
5353
}
5454

5555
@Override
56-
public void onRequestPermissionsResult(int requestCode, @NonNull String permissions[],
56+
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,
5757
@NonNull int[] grantResults) {
58-
switch (requestCode) {
59-
case PERMISSIONS:
60-
for (int index = 0; index < permissions.length; index++) {
61-
if (grantResults[index] != PackageManager.PERMISSION_GRANTED) {
62-
// permission not granted - toast and exit
63-
Toast.makeText(this, R.string.not_granted, Toast.LENGTH_LONG).show();
64-
finish();
65-
return;
66-
}
58+
if (requestCode == PERMISSIONS) {
59+
for (int index = 0; index < permissions.length; index++) {
60+
if (grantResults[index] != PackageManager.PERMISSION_GRANTED) {
61+
// permission not granted - toast and exit
62+
Toast.makeText(this, R.string.not_granted, Toast.LENGTH_LONG).show();
63+
finish();
64+
return;
6765
}
68-
// permission were granted - run
69-
next();
70-
break;
66+
}
67+
// permission were granted - run
68+
next();
7169
}
7270
}
7371

74-
public void next() {
72+
private void next() {
7573
Intent intent = new Intent(this, MtNativeActivity.class);
7674
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_CLEAR_TASK);
7775
startActivity(intent);

Diff for: ‎build/android/src/main/java/net.minetest.minetest/MinetestAssetCopy.java

+31-41
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package net.minetest.minetest;
22

3+
import android.annotation.SuppressLint;
34
import android.app.Activity;
45
import android.content.res.AssetFileDescriptor;
56
import android.os.AsyncTask;
@@ -19,13 +20,12 @@
1920
import java.io.InputStream;
2021
import java.io.InputStreamReader;
2122
import java.io.OutputStream;
22-
import java.util.Iterator;
2323
import java.util.Vector;
2424

2525
public class MinetestAssetCopy extends Activity {
26-
ProgressBar m_ProgressBar;
27-
TextView m_Filename;
28-
copyAssetTask m_AssetCopy;
26+
private ProgressBar m_ProgressBar;
27+
private TextView m_Filename;
28+
private copyAssetTask m_AssetCopy;
2929

3030
@Override
3131
public void onCreate(Bundle savedInstanceState) {
@@ -53,29 +53,26 @@ protected void onResume() {
5353
super.onResume();
5454
makeFullScreen();
5555
}
56-
56+
5757
@Override
58-
protected void onDestroy() {
58+
protected void onDestroy() {
5959
super.onDestroy();
6060
if (m_AssetCopy != null) {
6161
m_AssetCopy.cancel(true);
6262
}
63-
}
63+
}
6464

65-
public void makeFullScreen() {
66-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
65+
private void makeFullScreen() {
66+
if (Build.VERSION.SDK_INT >= 19)
6767
this.getWindow().getDecorView().setSystemUiVisibility(
68-
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
69-
);
70-
}
68+
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
7169
}
7270

7371
@Override
7472
public void onWindowFocusChanged(boolean hasFocus) {
7573
super.onWindowFocusChanged(hasFocus);
76-
if (hasFocus) {
74+
if (hasFocus)
7775
makeFullScreen();
78-
}
7976
}
8077

8178
/* preserve asset copy background task to prevent restart of copying */
@@ -85,7 +82,8 @@ public Object onRetainNonConfigurationInstance() {
8582
return this;
8683
}
8784

88-
private static class copyAssetTask extends AsyncTask<String, Integer, String> {
85+
@SuppressLint("StaticFieldLeak")
86+
private class copyAssetTask extends AsyncTask<String, Integer, String> {
8987
boolean m_copy_started = false;
9088
String m_Foldername = "media";
9189
Vector<String> m_foldernames;
@@ -99,7 +97,7 @@ private long getFullSize(String filename) {
9997
InputStream src = getAssets().open(filename);
10098
byte[] buf = new byte[4096];
10199

102-
int len = 0;
100+
int len;
103101
while ((len = src.read(buf)) > 0) {
104102
size += len;
105103
}
@@ -111,10 +109,10 @@ private long getFullSize(String filename) {
111109

112110
@Override
113111
protected String doInBackground(String... files) {
114-
m_foldernames = new Vector<String>();
115-
m_filenames = new Vector<String>();
116-
m_tocopy = new Vector<String>();
117-
m_asset_size_unknown = new Vector<String>();
112+
m_foldernames = new Vector<>();
113+
m_filenames = new Vector<>();
114+
m_tocopy = new Vector<>();
115+
m_asset_size_unknown = new Vector<>();
118116
String baseDir =
119117
Environment.getExternalStorageDirectory().getAbsolutePath()
120118
+ "/";
@@ -128,9 +126,9 @@ protected String doInBackground(String... files) {
128126
} else {
129127
File[] todel = TempFolder.listFiles();
130128

131-
for (int i = 0; i < todel.length; i++) {
132-
Log.v("MinetestAssetCopy", "deleting: " + todel[i].getAbsolutePath());
133-
todel[i].delete();
129+
for (File file : todel) {
130+
Log.v("MinetestAssetCopy", "deleting: " + file.getAbsolutePath());
131+
file.delete();
134132
}
135133
}
136134

@@ -166,9 +164,9 @@ protected String doInBackground(String... files) {
166164
if (m_asset_size_unknown.contains(filename)) {
167165
File testme = new File(baseDir + "/" + filename);
168166

169-
if (testme.exists()) {
167+
if (testme.exists())
170168
filesize = testme.length();
171-
}
169+
172170
asset_size_unknown = true;
173171
}
174172

@@ -249,12 +247,10 @@ protected String doInBackground(String... files) {
249247
protected void onProgressUpdate(Integer... progress) {
250248

251249
if (m_copy_started) {
252-
boolean shortened = false;
253250
String todisplay = m_tocopy.get(progress[0]);
254251
m_ProgressBar.setProgress(progress[0]);
255252
m_Filename.setText(todisplay);
256253
} else {
257-
boolean shortened = false;
258254
String todisplay = m_Foldername;
259255
String full_text = "scanning " + todisplay + " ...";
260256
m_Filename.setText(full_text);
@@ -264,14 +260,11 @@ protected void onProgressUpdate(Integer... progress) {
264260
/**
265261
* check all files and folders in filelist
266262
*/
267-
protected void ProcessFileList() {
263+
void ProcessFileList() {
268264
String FlashBaseDir =
269265
Environment.getExternalStorageDirectory().getAbsolutePath();
270266

271-
Iterator itr = m_filenames.iterator();
272-
273-
while (itr.hasNext()) {
274-
String current_path = (String) itr.next();
267+
for (String current_path : m_filenames) {
275268
String FlashPath = FlashBaseDir + "/" + current_path;
276269

277270
if (isAssetFolder(current_path)) {
@@ -300,38 +293,35 @@ protected void ProcessFileList() {
300293
File testme = new File(FlashPath);
301294

302295
long asset_filesize = -1;
303-
long stored_filesize = -1;
296+
long stored_filesize;
304297

305298
if (testme.exists()) {
306299
try {
307300
AssetFileDescriptor fd = getAssets().openFd(current_path);
308301
asset_filesize = fd.getLength();
309302
fd.close();
310303
} catch (IOException e) {
311-
refresh = true;
312304
m_asset_size_unknown.add(current_path);
313305
Log.e("MinetestAssetCopy", "Failed to open asset file \"" +
314306
FlashPath + "\" for size check");
315307
}
316308

317309
stored_filesize = testme.length();
318310

319-
if (asset_filesize == stored_filesize) {
311+
if (asset_filesize == stored_filesize)
320312
refresh = false;
321-
}
322313

323314
}
324315

325-
if (refresh) {
316+
if (refresh)
326317
m_tocopy.add(current_path);
327-
}
328318
}
329319
}
330320

331321
/**
332322
* read list of folders prepared on package build
333323
*/
334-
protected void BuildFolderList() {
324+
void BuildFolderList() {
335325
try {
336326
InputStream is = getAssets().open("index.txt");
337327
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
@@ -351,7 +341,7 @@ protected void BuildFolderList() {
351341
/**
352342
* read list of asset files prepared on package build
353343
*/
354-
protected void BuildFileList() {
344+
void BuildFileList() {
355345
long entrycount = 0;
356346
try {
357347
InputStream is = getAssets().open("filelist.txt");
@@ -374,7 +364,7 @@ protected void onPostExecute(String result) {
374364
finish();
375365
}
376366

377-
protected boolean isAssetFolder(String path) {
367+
boolean isAssetFolder(String path) {
378368
return m_foldernames.contains(path);
379369
}
380370
}

Diff for: ‎build/android/src/main/java/net.minetest.minetest/MinetestTextEntry.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ public class MinetestTextEntry extends Activity {
1515
private final int MultiLineTextInput = 1;
1616
private final int SingleLineTextInput = 2;
1717
private final int SingleLinePasswordInput = 3;
18-
public AlertDialog mTextInputDialog;
19-
public EditText mTextInputWidget;
18+
private AlertDialog mTextInputDialog;
19+
private EditText mTextInputWidget;
2020

2121
@Override
2222
public void onCreate(Bundle savedInstanceState) {
@@ -71,15 +71,15 @@ public boolean onKey(View view, int KeyCode, KeyEvent event) {
7171
mTextInputDialog.show();
7272
}
7373

74-
public void pushResult(String text) {
74+
private void pushResult(String text) {
7575
Intent resultData = new Intent();
7676
resultData.putExtra("text", text);
7777
setResult(Activity.RESULT_OK, resultData);
7878
mTextInputDialog.dismiss();
7979
finish();
8080
}
8181

82-
public void cancelDialog() {
82+
private void cancelDialog() {
8383
setResult(Activity.RESULT_CANCELED);
8484
mTextInputDialog.dismiss();
8585
finish();

Diff for: ‎build/android/src/main/java/net.minetest.minetest/MtNativeActivity.java

+4-7
Original file line numberDiff line numberDiff line change
@@ -37,20 +37,17 @@ protected void onResume() {
3737
makeFullScreen();
3838
}
3939

40-
public void makeFullScreen() {
41-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
40+
private void makeFullScreen() {
41+
if (Build.VERSION.SDK_INT >= 19)
4242
this.getWindow().getDecorView().setSystemUiVisibility(
43-
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
44-
);
45-
}
43+
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
4644
}
4745

4846
@Override
4947
public void onWindowFocusChanged(boolean hasFocus) {
5048
super.onWindowFocusChanged(hasFocus);
51-
if (hasFocus) {
49+
if (hasFocus)
5250
makeFullScreen();
53-
}
5451
}
5552

5653
public void copyAssets() {

Diff for: ‎build/android/src/main/res/values-v21/styles.xml

+9-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<resources>
2+
<resources xmlns:tools="http://schemas.android.com/tools">
33

4-
<style name="AppTheme" parent="@android:style/android:Theme.Material.Light.NoActionBar.Fullscreen">
4+
<style name="AppTheme" parent="android:Theme.Material.Light.NoActionBar.Fullscreen">
55
<item name="android:windowNoTitle">true</item>
6-
<item name="android:windowAnimationStyle">@null</item>
76
<item name="android:windowBackground">@drawable/bg</item>
7+
<item name="android:windowLayoutInDisplayCutoutMode" tools:ignore="NewApi" tools:targetApi="o_mr1">
8+
shortEdges
9+
</item>
810
</style>
911

10-
<style name="Theme.Dialog" parent="@android:style/Theme.Material.Light.Dialog.NoActionBar"/>
12+
<style name="Theme.Dialog" parent="@android:style/Theme.Material.Light.Dialog.NoActionBar">
13+
<item name="android:windowNoTitle">true</item>
14+
<item name="android:windowBackground">@android:color/transparent</item>
15+
</style>
1116

1217
</resources>

Diff for: ‎build/android/src/main/res/values/styles.xml

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<resources>
33

4-
<style name="AppTheme" parent="@android:style/android:Theme.Holo.Light.NoActionBar.Fullscreen">
4+
<style name="AppTheme" parent="android:Theme.Holo.Light.NoActionBar.Fullscreen">
55
<item name="android:windowNoTitle">true</item>
6-
<item name="android:windowAnimationStyle">@null</item>
76
<item name="android:windowBackground">@drawable/bg</item>
87
</style>
98

10-
<style name="Theme.Dialog" parent="@android:style/android:Theme.Holo.Light.Dialog.NoActionBar"/>
9+
<style name="Theme.Dialog" parent="android:Theme.Holo.Light.Dialog.NoActionBar">
10+
<item name="android:windowNoTitle">true</item>
11+
<item name="android:windowBackground">@android:color/transparent</item>
12+
</style>
1113

1214
</resources>

0 commit comments

Comments
 (0)
Please sign in to comment.