update android bg, min spec

This commit is contained in:
Anthony Calosa
2024-10-31 20:45:20 +08:00
parent 52d77c6862
commit c55c07b8dd
4 changed files with 116 additions and 104 deletions

View File

@@ -3,6 +3,7 @@ package forge.app;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.AnimatorSet;
import android.animation.ArgbEvaluator;
import android.animation.ObjectAnimator;
import android.app.Activity;
import android.app.ActivityManager;
@@ -31,6 +32,7 @@ import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.provider.Settings;
import android.text.SpannableString;
import android.text.TextUtils;
@@ -293,96 +295,102 @@ public class Main extends AndroidApplication {
private void loadGame(final String title, final String steps, boolean isLandscape, AndroidAdapter adapter, boolean permissiongranted, int totalRAM, boolean isTabletDevice, AndroidApplicationConfiguration config, boolean exception, String msg) {
try {
final Handler handler = new Handler();
forgeLogo = findViewById(getResources().getIdentifier("logo_id", "id", getPackageName()));
activeView = findViewById(getResources().getIdentifier("mainview", "id", getPackageName()));
activeView.setBackgroundColor(Color.WHITE);
forgeView = initializeForView(Forge.getApp(getAndroidClipboard(), adapter, ASSETS_DIR, false, !isLandscape, totalRAM, isTabletDevice, Build.VERSION.SDK_INT, Build.VERSION.RELEASE, getDeviceName()), config);
getAnimator(ObjectAnimator.ofFloat(forgeLogo, "alpha", 0f, 1f).setDuration(1800), null, new AnimatorListenerAdapter() {
getAnimator(ObjectAnimator.ofFloat(forgeLogo, "alpha", 1f, 1f).setDuration(800), ObjectAnimator.ofObject(activeView, "backgroundColor", new ArgbEvaluator(), Color.WHITE, Color.BLACK).setDuration(1600), new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
super.onAnimationEnd(animation);
if (!permissiongranted || exception) {
displayMessage(forgeLogo, adapter, exception, msg, false);
} else if (title.isEmpty() && steps.isEmpty()) {
if (isLandscape) {
Main.this.setRequestedOrientation(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O ?
ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE : //Oreo and above has virtual back/menu buttons
ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
} else {
Main.this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT);
}
crossfade(forgeView, forgeLogo);
} else {
if (sharedPreferences.getBoolean("run_anyway", false)) {
handler.postDelayed(() -> {
if (!permissiongranted || exception) {
displayMessage(forgeLogo, adapter, exception, msg, false);
} else if (title.isEmpty() && steps.isEmpty()) {
if (isLandscape) {
Main.this.setRequestedOrientation(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O ?
ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE : //Oreo and above has virtual back/menu buttons
ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
} else {
Main.this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT);
}
crossfade(forgeView, forgeLogo);
return;
} else {
if (sharedPreferences.getBoolean("run_anyway", false)) {
crossfade(forgeView, forgeLogo);
return;
}
TableLayout TL = new TableLayout(getContext());
TL.setBackgroundResource(android.R.color.black);
TableRow messageRow = new TableRow(getContext());
TableRow checkboxRow = new TableRow(getContext());
TableRow buttonRow = new TableRow(getContext());
TextView text = new TextView(getContext());
text.setGravity(Gravity.LEFT);
text.setTypeface(Typeface.SERIF);
SpannableString ss1 = new SpannableString(title);
ss1.setSpan(new StyleSpan(Typeface.BOLD), 0, ss1.length(), 0);
text.append(ss1);
text.append(steps + "\n");
messageRow.addView(text);
messageRow.setGravity(Gravity.CENTER);
CheckBox checkBox = new CheckBox(getContext());
checkBox.setTypeface(Typeface.SERIF);
checkBox.setGravity(Gravity.TOP);
checkBox.setChecked(false);
checkBox.setPadding(30, 30, 30, 30);
checkBox.setTypeface(Typeface.SERIF);
checkBox.setText(" Don't remind me next time. ");
checkBox.setScaleX(0.9f);
checkBox.setScaleY(0.9f);
checkBox.setOnCheckedChangeListener((buttonView, isChecked) ->
sharedPreferences.edit().putBoolean("run_anyway", isChecked).apply());
checkboxRow.addView(checkBox);
checkboxRow.setGravity(Gravity.CENTER);
int[] colors = {Color.TRANSPARENT, Color.TRANSPARENT};
int[] pressed = {Color.GREEN, Color.GREEN};
GradientDrawable gd = new GradientDrawable(
GradientDrawable.Orientation.TOP_BOTTOM, colors);
gd.setStroke(3, Color.DKGRAY);
gd.setCornerRadius(100);
GradientDrawable gd2 = new GradientDrawable(
GradientDrawable.Orientation.TOP_BOTTOM, pressed);
gd2.setStroke(3, Color.DKGRAY);
gd2.setCornerRadius(100);
Button button = new Button(getContext());
button.setText("Run Forge..");
button.setTypeface(Typeface.DEFAULT_BOLD);
StateListDrawable states = new StateListDrawable();
states.addState(new int[]{android.R.attr.state_pressed}, gd2);
states.addState(new int[]{}, gd);
button.setBackground(states);
button.setTextColor(Color.RED);
button.setOnClickListener(v -> {
button.setClickable(false);
crossfade(forgeView, TL);
});
buttonRow.addView(button);
buttonRow.setGravity(Gravity.CENTER);
TL.addView(messageRow, new TableLayout.LayoutParams(TableLayout.LayoutParams.WRAP_CONTENT, TableLayout.LayoutParams.WRAP_CONTENT));
TL.addView(checkboxRow, new TableLayout.LayoutParams(TableLayout.LayoutParams.WRAP_CONTENT, TableLayout.LayoutParams.WRAP_CONTENT));
TL.addView(buttonRow, new TableLayout.LayoutParams(TableLayout.LayoutParams.WRAP_CONTENT, TableLayout.LayoutParams.WRAP_CONTENT));
TL.setGravity(Gravity.CENTER);
crossfade(TL, forgeLogo);
}
TableLayout TL = new TableLayout(getContext());
TL.setBackgroundResource(android.R.color.black);
TableRow messageRow = new TableRow(getContext());
TableRow checkboxRow = new TableRow(getContext());
TableRow buttonRow = new TableRow(getContext());
TextView text = new TextView(getContext());
text.setGravity(Gravity.LEFT);
text.setTypeface(Typeface.SERIF);
SpannableString ss1 = new SpannableString(title);
ss1.setSpan(new StyleSpan(Typeface.BOLD), 0, ss1.length(), 0);
text.append(ss1);
text.append(steps + "\n");
messageRow.addView(text);
messageRow.setGravity(Gravity.CENTER);
CheckBox checkBox = new CheckBox(getContext());
checkBox.setTypeface(Typeface.SERIF);
checkBox.setGravity(Gravity.TOP);
checkBox.setChecked(false);
checkBox.setPadding(30, 30, 30, 30);
checkBox.setTypeface(Typeface.SERIF);
checkBox.setText(" Don't remind me next time. ");
checkBox.setScaleX(0.9f);
checkBox.setScaleY(0.9f);
checkBox.setOnCheckedChangeListener((buttonView, isChecked) ->
sharedPreferences.edit().putBoolean("run_anyway", isChecked).apply());
checkboxRow.addView(checkBox);
checkboxRow.setGravity(Gravity.CENTER);
int[] colors = {Color.TRANSPARENT, Color.TRANSPARENT};
int[] pressed = {Color.GREEN, Color.GREEN};
GradientDrawable gd = new GradientDrawable(
GradientDrawable.Orientation.TOP_BOTTOM, colors);
gd.setStroke(3, Color.DKGRAY);
gd.setCornerRadius(100);
GradientDrawable gd2 = new GradientDrawable(
GradientDrawable.Orientation.TOP_BOTTOM, pressed);
gd2.setStroke(3, Color.DKGRAY);
gd2.setCornerRadius(100);
Button button = new Button(getContext());
button.setText("Run Forge..");
button.setTypeface(Typeface.DEFAULT_BOLD);
StateListDrawable states = new StateListDrawable();
states.addState(new int[]{android.R.attr.state_pressed}, gd2);
states.addState(new int[]{}, gd);
button.setBackground(states);
button.setTextColor(Color.RED);
button.setOnClickListener(v -> {
button.setClickable(false);
crossfade(forgeView, TL);
});
buttonRow.addView(button);
buttonRow.setGravity(Gravity.CENTER);
TL.addView(messageRow, new TableLayout.LayoutParams(TableLayout.LayoutParams.WRAP_CONTENT, TableLayout.LayoutParams.WRAP_CONTENT));
TL.addView(checkboxRow, new TableLayout.LayoutParams(TableLayout.LayoutParams.WRAP_CONTENT, TableLayout.LayoutParams.WRAP_CONTENT));
TL.addView(buttonRow, new TableLayout.LayoutParams(TableLayout.LayoutParams.WRAP_CONTENT, TableLayout.LayoutParams.WRAP_CONTENT));
TL.setGravity(Gravity.CENTER);
crossfade(TL, forgeLogo);
}
}, 600);
}
}).start();
} catch (Exception e) {
@@ -393,9 +401,8 @@ public class Main extends AndroidApplication {
private AnimatorSet getAnimator(Animator play, Animator with, AnimatorListenerAdapter adapter) {
AnimatorSet animatorSet = new AnimatorSet();
if (with != null) {
animatorSet.playTogether(play, with);
}
else
animatorSet.playSequentially(play, with);
} else
animatorSet.play(play);
animatorSet.addListener(adapter);
return animatorSet;
@@ -465,9 +472,11 @@ public class Main extends AndroidApplication {
adapter.switchOrientationFile = ASSETS_DIR + "switch_orientation.ini";
boolean landscapeMode = adapter.isTablet == !FileUtil.doesFileExist(adapter.switchOrientationFile);
String info = totalRAM < 3500 || Build.VERSION.SDK_INT < Build.VERSION_CODES.Q ? "Device Specification Check\n" + getDeviceName()
+ "\n" + "Android " + Build.VERSION.RELEASE + "\n" + "RAM " + totalRAM + "MB\n\nMinimum Requirements:" : "";
String lowV = Build.VERSION.SDK_INT < Build.VERSION_CODES.Q ? "\nAPI: Android 10 or higher" : "";
String info = totalRAM < 3500 || Build.VERSION.SDK_INT < Build.VERSION_CODES.R ? "Device Specification Check\n" + getDeviceName()
+ "\n" + "Android " + Build.VERSION.RELEASE + "\n" + "RAM " + totalRAM + "MB\n\nRecommended API:" : "";
// Even though Forge runs on Android 8 as minimum, just show indicator that Android 11 is recommended
String lowV = Build.VERSION.SDK_INT < Build.VERSION_CODES.R ? "\nAPI: Android 11 or higher" : "";
// also show minimum Device RAM
String lowM = totalRAM < 3500 ? "\nRAM: 4GB RAM or higher" : "";
if (landscapeMode && Build.VERSION.SDK_INT > Build.VERSION_CODES.Q) { //Android 11 onwards
Main.this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE);
@@ -561,29 +570,32 @@ public class Main extends AndroidApplication {
try {
if (connManager != null) {
connManager.registerDefaultNetworkCallback(
new ConnectivityManager.NetworkCallback() {
@Override
public void onAvailable(Network network) {
connected = true;
}
new ConnectivityManager.NetworkCallback() {
@Override
public void onAvailable(Network network) {
connected = true;
}
@Override
public void onLost(Network network) {
connected = false;
@Override
public void onLost(Network network) {
connected = false;
}
}
}
);
}
} catch (Exception e) {
connected = false;
}
}
private boolean hasInternet() {
return isNetworkConnected(false);
}
private boolean hasWiFiInternet() {
return isNetworkConnected(true);
}
private boolean isNetworkConnected(boolean wifiOnly) {
boolean result = false;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
@@ -612,6 +624,7 @@ public class Main extends AndroidApplication {
}
return result;
}
@Override
public boolean isConnectedToInternet() {
//if it can't determine Internet connection within two seconds, assume not connected