Android: minor update java part

This commit is contained in:
MoNTE48 2020-10-04 20:07:15 +02:00
parent 349823afa0
commit 9b82dbd2cc
15 changed files with 39 additions and 55 deletions

View File

@ -71,7 +71,7 @@ dependencies {
//noinspection GradleDependency
implementation 'commons-io:commons-io:2.5'
implementation 'gun0912.ted:tedpermission-rx2:2.2.3'
implementation 'net.lingala.zip4j:zip4j:2.6.2'
implementation 'net.lingala.zip4j:zip4j:2.6.3'
/* Analytics libraries */
//noinspection GradleDynamicVersion

View File

@ -38,15 +38,14 @@
<meta-data
android:name="android.max_aspect"
android:value="3" />
android:value="3.0" />
<activity
android:name="com.multicraft.game.MainActivity"
android:configChanges="orientation|keyboardHidden|navigation|screenSize"
android:maxAspectRatio="3"
android:maxAspectRatio="3.0"
android:screenOrientation="sensorLandscape"
android:theme="@style/AppTheme"
tools:ignore="LockedOrientationActivity">
android:theme="@style/AppTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
@ -58,10 +57,9 @@
android:configChanges="orientation|keyboard|keyboardHidden|navigation|screenSize|smallestScreenSize"
android:hardwareAccelerated="true"
android:launchMode="singleTask"
android:maxAspectRatio="3"
android:maxAspectRatio="3.0"
android:screenOrientation="sensorLandscape"
android:theme="@style/AppTheme"
tools:ignore="LockedOrientationActivity">
android:theme="@style/AppTheme">
<meta-data
android:name="android.app.lib_name"
android:value="MultiCraft" />

View File

@ -24,10 +24,9 @@ import android.content.Context;
import android.view.KeyEvent;
import android.view.inputmethod.InputMethodManager;
import java.util.Objects;
public class CustomEditText extends androidx.appcompat.widget.AppCompatEditText {
import androidx.appcompat.widget.AppCompatEditText;
public class CustomEditText extends AppCompatEditText {
public CustomEditText(Context context) {
super(context);
}
@ -37,7 +36,7 @@ public class CustomEditText extends androidx.appcompat.widget.AppCompatEditText
if (keyCode == KeyEvent.KEYCODE_BACK) {
InputMethodManager mgr = (InputMethodManager)
getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
Objects.requireNonNull(mgr).hideSoftInputFromWindow(this.getWindowToken(), 0);
mgr.hideSoftInputFromWindow(this.getWindowToken(), 0);
}
return false;
}

View File

@ -24,6 +24,7 @@ import android.app.ActivityManager;
import android.app.NativeActivity;
import android.content.Context;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.os.Bundle;
import android.text.InputType;
import android.view.KeyEvent;
@ -36,8 +37,6 @@ import androidx.appcompat.app.AlertDialog;
import com.bugsnag.android.Bugsnag;
import com.multicraft.game.helpers.PreferencesHelper;
import java.util.Objects;
import io.reactivex.Completable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
@ -62,8 +61,8 @@ public class GameActivity extends NativeActivity {
} catch (IllegalArgumentException i) {
Bugsnag.notify(i);
System.exit(0);
} catch (Error | Exception error) {
Bugsnag.notify(error);
} catch (Error | Exception e) {
Bugsnag.notify(e);
System.exit(0);
}
}
@ -86,11 +85,12 @@ public class GameActivity extends NativeActivity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Bundle bundle = getIntent().getExtras();
height = bundle != null ? bundle.getInt("height", 0) : getResources().getDisplayMetrics().heightPixels;
width = bundle != null ? bundle.getInt("width", 0) : getResources().getDisplayMetrics().widthPixels;
Resources resources = getResources();
height = bundle != null ? bundle.getInt("height", 0) : resources.getDisplayMetrics().heightPixels;
width = bundle != null ? bundle.getInt("width", 0) : resources.getDisplayMetrics().widthPixels;
consent = bundle == null || bundle.getBoolean("consent", true);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
hasKeyboard = !(getResources().getConfiguration().hardKeyboardHidden == KEYBOARD_QWERTY);
hasKeyboard = !(resources.getConfiguration().hardKeyboardHidden == KEYBOARD_QWERTY);
keyboardEvent(hasKeyboard);
pf = getInstance(this);
if (pf.isAdsEnable()) {
@ -124,6 +124,10 @@ public class GameActivity extends NativeActivity {
adInitSub.dispose();
}
public void showDialog(String acceptButton, String hint, String current, int editType) {
runOnUiThread(() -> showDialogUI(hint, current, editType));
}
@Override
protected void onPause() {
super.onPause();
@ -140,10 +144,6 @@ public class GameActivity extends NativeActivity {
}
}
public void showDialog(String acceptButton, String hint, String current, int editType) {
runOnUiThread(() -> showDialogUI(hint, current, editType));
}
private void showDialogUI(String hint, String current, int editType) {
final AlertDialog.Builder builder = new AlertDialog.Builder(this);
EditText editText = new CustomEditText(this);
@ -153,7 +153,7 @@ public class GameActivity extends NativeActivity {
editText.setHint(hint);
editText.setText(current);
final InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
Objects.requireNonNull(imm).toggleSoftInput(InputMethodManager.SHOW_FORCED,
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED,
InputMethodManager.HIDE_IMPLICIT_ONLY);
if (editType == 1)
editText.setInputType(InputType.TYPE_CLASS_TEXT |

View File

@ -71,7 +71,6 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
import io.reactivex.Completable;
@ -399,7 +398,7 @@ public class MainActivity extends AppCompatActivity implements CallBackListener,
.observeOn(AndroidSchedulers.mainThread())
.subscribe(() -> startUnzipService(zips),
throwable -> {
if (Objects.requireNonNull(throwable.getLocalizedMessage()).contains("ENOSPC"))
if (throwable.getLocalizedMessage().contains("ENOSPC"))
showRestartDialog("ENOSPC");
else showRestartDialog("UKNWN");
});

View File

@ -38,7 +38,6 @@ import com.multicraft.game.helpers.PreferencesHelper;
import java.lang.ref.WeakReference;
import java.util.Date;
import java.util.Objects;
import static com.multicraft.game.helpers.ApiLevelHelper.isGreaterOrEqualKitkat;
@ -87,7 +86,7 @@ class RateMe {
final Dialog dialog = new Dialog(activity, R.style.RateMe);
dialog.setCancelable(false);
if (isGreaterOrEqualKitkat())
Objects.requireNonNull(dialog.getWindow()).getDecorView().setSystemUiVisibility(
dialog.getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);

View File

@ -39,7 +39,6 @@ import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Objects;
import static com.multicraft.game.MainActivity.zipLocations;
import static com.multicraft.game.helpers.ApiLevelHelper.isGreaterOrEqualOreo;
@ -105,7 +104,7 @@ public class UnzipService extends IntentService {
private void unzip(Intent intent) {
String[] zips = intent.getStringArrayExtra(EXTRA_KEY_IN_FILE);
int per = 0;
int size = getSummarySize(Objects.requireNonNull(zips));
int size = getSummarySize(zips);
for (String zip : zips) {
File zipFile = new File(zip);
LocalFileHeader localFileHeader;

View File

@ -20,26 +20,30 @@ with this program; if not, write to the Free Software Foundation, Inc.,
package com.multicraft.game.helpers;
import android.os.Build;
import static android.os.Build.VERSION.SDK_INT;
import static android.os.Build.VERSION_CODES.KITKAT;
import static android.os.Build.VERSION_CODES.LOLLIPOP;
import static android.os.Build.VERSION_CODES.O;
import static android.os.Build.VERSION_CODES.Q;
public class ApiLevelHelper {
public static boolean isGreaterOrEqual(int versionCode) {
return Build.VERSION.SDK_INT >= versionCode;
return SDK_INT >= versionCode;
}
public static boolean isGreaterOrEqualKitkat() {
return isGreaterOrEqual(Build.VERSION_CODES.KITKAT);
return isGreaterOrEqual(KITKAT);
}
public static boolean isGreaterOrEqualLollipop() {
return isGreaterOrEqual(Build.VERSION_CODES.LOLLIPOP);
return isGreaterOrEqual(LOLLIPOP);
}
public static boolean isGreaterOrEqualOreo() {
return isGreaterOrEqual(Build.VERSION_CODES.O);
return isGreaterOrEqual(O);
}
public static boolean isGreaterOrEqualQ() {
return isGreaterOrEqual(Build.VERSION_CODES.Q);
return isGreaterOrEqual(Q);
}
}

View File

@ -28,7 +28,6 @@ import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.view.View;
import com.bugsnag.android.Bugsnag;
@ -45,7 +44,6 @@ import java.net.URL;
import java.util.List;
import static com.multicraft.game.helpers.ApiLevelHelper.isGreaterOrEqualKitkat;
import static com.multicraft.game.helpers.ApiLevelHelper.isGreaterOrEqualLollipop;
import static com.multicraft.game.helpers.PreferencesHelper.TAG_SHORTCUT_EXIST;
public class Utilities {

View File

@ -43,7 +43,6 @@ import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import java.util.Locale;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
import okhttp3.OkHttpClient;
@ -136,7 +135,7 @@ public class VersionManagerHelper {
.build();
try {
Response response = client.newCall(request).execute();
return Objects.requireNonNull(response.body()).string();
return response.body().string();
} catch (IOException | NullPointerException e) {
// nothing
}

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/background">
<item>
<shape>
<stroke
android:width="2.5dp"
@ -17,7 +17,7 @@
</shape>
</item>
<item android:id="@+id/progress">
<item>
<clip>
<shape>
<corners android:radius="40dip" />

Binary file not shown.

Before

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

View File

@ -1,19 +1,7 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/imageView"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_marginLeft="80dp"
android:layout_marginTop="25dp"
android:layout_marginRight="80dp"
android:contentDescription="@string/loading"
app:srcCompat="@drawable/logo" />
<ProgressBar
android:id="@+id/PB1"
style="@style/CustomProgressBar"
@ -43,7 +31,7 @@
android:layout_centerInParent="true"
android:text="@string/loading"
android:textColor="#fefefe"
android:textSize="17sp"
android:textSize="14sp"
android:visibility="gone" />
</RelativeLayout>

View File

@ -7,6 +7,7 @@
<item name="android:windowFullscreen">true</item>
<item name="android:windowLayoutInDisplayCutoutMode" tools:targetApi="p">shortEdges
</item>
<item name="android:fontFamily">@font/retron2000</item>
</style>
<style name="RateMe" parent="Theme.AppCompat.Light.Dialog">