mirror of
https://github.com/AngelAuraMC/Amethyst-Android.git
synced 2025-09-16 16:16:04 -04:00
Merge pull request #1110 from Mathias-Boulay/Installer_scaler
QoL UI updates
This commit is contained in:
commit
bc7de9bacd
@ -10,6 +10,9 @@ import net.kdt.pojavlaunch.utils.*;
|
|||||||
import org.lwjgl.glfw.*;
|
import org.lwjgl.glfw.*;
|
||||||
|
|
||||||
public class AWTCanvasView extends TextureView implements TextureView.SurfaceTextureListener, Runnable {
|
public class AWTCanvasView extends TextureView implements TextureView.SurfaceTextureListener, Runnable {
|
||||||
|
private int mScaleFactor;
|
||||||
|
private int[] mScales;
|
||||||
|
|
||||||
private int mWidth, mHeight;
|
private int mWidth, mHeight;
|
||||||
private boolean mIsDestroyed = false;
|
private boolean mIsDestroyed = false;
|
||||||
|
|
||||||
@ -33,6 +36,22 @@ public class AWTCanvasView extends TextureView implements TextureView.SurfaceTex
|
|||||||
return difference > 0 ? times.size() / difference : 0.0;
|
return difference > 0 ? times.size() / difference : 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Computes the scale to better fit the screen */
|
||||||
|
int[] initScaleFactors(){
|
||||||
|
//Could be optimized
|
||||||
|
int minDimension = Math.min(CallbackBridge.physicalHeight,CallbackBridge.physicalWidth);
|
||||||
|
mScaleFactor = (3*minDimension)/1080;
|
||||||
|
int[] scales = new int[2]; //Left, Top
|
||||||
|
|
||||||
|
scales[0] = (CallbackBridge.physicalWidth/2);
|
||||||
|
scales[0] -= scales[0]/mScaleFactor;
|
||||||
|
|
||||||
|
scales[1] = (CallbackBridge.physicalHeight/2);
|
||||||
|
scales[1] -= scales[1]/mScaleFactor;
|
||||||
|
|
||||||
|
return scales;
|
||||||
|
}
|
||||||
|
|
||||||
public AWTCanvasView(Context ctx) {
|
public AWTCanvasView(Context ctx) {
|
||||||
this(ctx, null);
|
this(ctx, null);
|
||||||
}
|
}
|
||||||
@ -46,6 +65,7 @@ public class AWTCanvasView extends TextureView implements TextureView.SurfaceTex
|
|||||||
fpsPaint.setTextSize(20);
|
fpsPaint.setTextSize(20);
|
||||||
|
|
||||||
setSurfaceTextureListener(this);
|
setSurfaceTextureListener(this);
|
||||||
|
mScales = initScaleFactors();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -91,7 +111,15 @@ public class AWTCanvasView extends TextureView implements TextureView.SurfaceTex
|
|||||||
int[] rgbArray = JREUtils.renderAWTScreenFrame(/* canvas, mWidth, mHeight */);
|
int[] rgbArray = JREUtils.renderAWTScreenFrame(/* canvas, mWidth, mHeight */);
|
||||||
mDrawing = rgbArray != null;
|
mDrawing = rgbArray != null;
|
||||||
if (rgbArray != null) {
|
if (rgbArray != null) {
|
||||||
|
|
||||||
|
canvas.save();
|
||||||
|
canvas.scale(mScaleFactor, mScaleFactor);
|
||||||
|
canvas.translate(-mScales[0],-mScales[1]);
|
||||||
|
|
||||||
|
|
||||||
canvas.drawBitmap(rgbArray, 0, CallbackBridge.physicalWidth, 0, 0, CallbackBridge.physicalWidth, CallbackBridge.physicalHeight, true, null);
|
canvas.drawBitmap(rgbArray, 0, CallbackBridge.physicalWidth, 0, 0, CallbackBridge.physicalWidth, CallbackBridge.physicalHeight, true, null);
|
||||||
|
canvas.restore();
|
||||||
|
|
||||||
}
|
}
|
||||||
rgbArray = null;
|
rgbArray = null;
|
||||||
// System.gc();
|
// System.gc();
|
||||||
|
@ -1,20 +1,20 @@
|
|||||||
package net.kdt.pojavlaunch;
|
package net.kdt.pojavlaunch;
|
||||||
|
|
||||||
import android.*;
|
|
||||||
import android.content.*;
|
|
||||||
import android.graphics.*;
|
import android.graphics.*;
|
||||||
import android.os.*;
|
import android.os.*;
|
||||||
import android.util.*;
|
import android.util.*;
|
||||||
import android.view.*;
|
import android.view.*;
|
||||||
import android.view.View.*;
|
import android.view.View.*;
|
||||||
import android.widget.*;
|
import android.widget.*;
|
||||||
import androidx.appcompat.app.*;
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import net.kdt.pojavlaunch.prefs.*;
|
import net.kdt.pojavlaunch.prefs.*;
|
||||||
import net.kdt.pojavlaunch.utils.*;
|
import net.kdt.pojavlaunch.utils.*;
|
||||||
import org.lwjgl.glfw.*;
|
import org.lwjgl.glfw.*;
|
||||||
|
|
||||||
|
import static net.kdt.pojavlaunch.utils.MathUtils.map;
|
||||||
|
|
||||||
public class JavaGUILauncherActivity extends LoggableActivity implements View.OnTouchListener {
|
public class JavaGUILauncherActivity extends LoggableActivity implements View.OnTouchListener {
|
||||||
private static final int MSG_LEFT_MOUSE_BUTTON_CHECK = 1028;
|
private static final int MSG_LEFT_MOUSE_BUTTON_CHECK = 1028;
|
||||||
|
|
||||||
@ -33,12 +33,11 @@ public class JavaGUILauncherActivity extends LoggableActivity implements View.On
|
|||||||
|
|
||||||
private final Object mDialogLock = new Object();
|
private final Object mDialogLock = new Object();
|
||||||
|
|
||||||
private DisplayMetrics displayMetrics;
|
|
||||||
private boolean isLogAllow, mSkipDetectMod;
|
private boolean isLogAllow, mSkipDetectMod;
|
||||||
|
|
||||||
private boolean rightOverride = false;
|
private boolean rightOverride = false;
|
||||||
private float scaleFactor = 1;
|
private int[] scaleFactor = initScaleFactors();
|
||||||
private int fingerStillThreshold = 8;
|
private final int fingerStillThreshold = 8;
|
||||||
private int initialX;
|
private int initialX;
|
||||||
private int initialY;
|
private int initialY;
|
||||||
private static boolean triggeredLeftMouseButton = false;
|
private static boolean triggeredLeftMouseButton = false;
|
||||||
@ -69,11 +68,6 @@ public class JavaGUILauncherActivity extends LoggableActivity implements View.On
|
|||||||
try {
|
try {
|
||||||
gestureDetector = new GestureDetector(this, new SingleTapConfirm());
|
gestureDetector = new GestureDetector(this, new SingleTapConfirm());
|
||||||
|
|
||||||
this.displayMetrics = Tools.getDisplayMetrics(this);
|
|
||||||
CallbackBridge.windowWidth = (int) ((float)displayMetrics.widthPixels * scaleFactor);
|
|
||||||
CallbackBridge.windowHeight = (int) ((float)displayMetrics.heightPixels * scaleFactor);
|
|
||||||
System.out.println("WidthHeight: " + CallbackBridge.windowWidth + ":" + CallbackBridge.windowHeight);
|
|
||||||
|
|
||||||
findViewById(R.id.installmod_mouse_pri).setOnTouchListener(this);
|
findViewById(R.id.installmod_mouse_pri).setOnTouchListener(this);
|
||||||
findViewById(R.id.installmod_mouse_sec).setOnTouchListener(this);
|
findViewById(R.id.installmod_mouse_sec).setOnTouchListener(this);
|
||||||
|
|
||||||
@ -81,24 +75,13 @@ public class JavaGUILauncherActivity extends LoggableActivity implements View.On
|
|||||||
touchPad.setFocusable(false);
|
touchPad.setFocusable(false);
|
||||||
|
|
||||||
this.mousePointer = findViewById(R.id.main_mouse_pointer);
|
this.mousePointer = findViewById(R.id.main_mouse_pointer);
|
||||||
this.mousePointer.post(new Runnable(){
|
this.mousePointer.post(() -> {
|
||||||
|
ViewGroup.LayoutParams params = mousePointer.getLayoutParams();
|
||||||
@Override
|
params.width = (int) (36 / 100f * LauncherPreferences.PREF_MOUSESCALE);
|
||||||
public void run() {
|
params.height = (int) (54 / 100f * LauncherPreferences.PREF_MOUSESCALE);
|
||||||
ViewGroup.LayoutParams params = mousePointer.getLayoutParams();
|
|
||||||
params.width = (int) (36 / 100f * LauncherPreferences.PREF_MOUSESCALE);
|
|
||||||
params.height = (int) (54 / 100f * LauncherPreferences.PREF_MOUSESCALE);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
/*
|
|
||||||
touchPad.setOnHoverListener(new OnHoverListener() {
|
|
||||||
@Override
|
|
||||||
public boolean onHover(View v, MotionEvent event) {
|
|
||||||
AWTInputBridge.sendMousePos((int) event.getX(), (int) event.getY());
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
*/
|
|
||||||
|
|
||||||
touchPad.setOnTouchListener(new OnTouchListener(){
|
touchPad.setOnTouchListener(new OnTouchListener(){
|
||||||
private float prevX, prevY;
|
private float prevX, prevY;
|
||||||
@Override
|
@Override
|
||||||
@ -124,7 +107,8 @@ public class JavaGUILauncherActivity extends LoggableActivity implements View.On
|
|||||||
|
|
||||||
if (gestureDetector.onTouchEvent(event)) {
|
if (gestureDetector.onTouchEvent(event)) {
|
||||||
|
|
||||||
AWTInputBridge.sendMousePos((int) (mouseX * scaleFactor), (int) (mouseY *scaleFactor));
|
sendScaledMousePosition(mouseX,mouseY);
|
||||||
|
|
||||||
AWTInputBridge.sendMousePress(rightOverride ? AWTInputEvent.BUTTON3_DOWN_MASK : AWTInputEvent.BUTTON1_DOWN_MASK);
|
AWTInputBridge.sendMousePress(rightOverride ? AWTInputEvent.BUTTON3_DOWN_MASK : AWTInputEvent.BUTTON1_DOWN_MASK);
|
||||||
if (!rightOverride) {
|
if (!rightOverride) {
|
||||||
CallbackBridge.mouseLeft = true;
|
CallbackBridge.mouseLeft = true;
|
||||||
@ -140,11 +124,11 @@ public class JavaGUILauncherActivity extends LoggableActivity implements View.On
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case MotionEvent.ACTION_MOVE: // 2
|
case MotionEvent.ACTION_MOVE: // 2
|
||||||
mouseX = Math.max(0, Math.min(displayMetrics.widthPixels, mouseX + x - prevX));
|
mouseX = Math.max(0, Math.min(CallbackBridge.physicalWidth, mouseX + x - prevX));
|
||||||
mouseY = Math.max(0, Math.min(displayMetrics.heightPixels, mouseY + y - prevY));
|
mouseY = Math.max(0, Math.min(CallbackBridge.physicalHeight, mouseY + y - prevY));
|
||||||
placeMouseAt(mouseX, mouseY);
|
placeMouseAt(mouseX, mouseY);
|
||||||
|
|
||||||
AWTInputBridge.sendMousePos((int) (mouseX * scaleFactor), (int) (mouseY *scaleFactor));
|
sendScaledMousePosition(mouseX,mouseY);
|
||||||
/*
|
/*
|
||||||
if (!CallbackBridge.isGrabbing()) {
|
if (!CallbackBridge.isGrabbing()) {
|
||||||
CallbackBridge.sendMouseKeycode(LWJGLGLFWKeycode.GLFW_MOUSE_BUTTON_LEFT, 0, isLeftMouseDown);
|
CallbackBridge.sendMouseKeycode(LWJGLGLFWKeycode.GLFW_MOUSE_BUTTON_LEFT, 0, isLeftMouseDown);
|
||||||
@ -269,6 +253,11 @@ public class JavaGUILauncherActivity extends LoggableActivity implements View.On
|
|||||||
this.mousePointer.setTranslationY(y);
|
this.mousePointer.setTranslationY(y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void sendScaledMousePosition(float x, float y){
|
||||||
|
AWTInputBridge.sendMousePos((int) map(x,0,CallbackBridge.physicalWidth,scaleFactor[0],scaleFactor[2]),
|
||||||
|
(int) map(y,0,CallbackBridge.physicalHeight,scaleFactor[1],scaleFactor[3]));
|
||||||
|
}
|
||||||
|
|
||||||
public void forceClose(View v) {
|
public void forceClose(View v) {
|
||||||
BaseMainActivity.dialogForceClose(this);
|
BaseMainActivity.dialogForceClose(this);
|
||||||
}
|
}
|
||||||
@ -334,12 +323,31 @@ public class JavaGUILauncherActivity extends LoggableActivity implements View.On
|
|||||||
public void appendToLog(final String text, boolean checkAllow) {
|
public void appendToLog(final String text, boolean checkAllow) {
|
||||||
logStream.print(text);
|
logStream.print(text);
|
||||||
if (checkAllow && !isLogAllow) return;
|
if (checkAllow && !isLogAllow) return;
|
||||||
textLog.post(new Runnable(){
|
textLog.post(() -> {
|
||||||
@Override
|
textLog.append(text);
|
||||||
public void run() {
|
contentScroll.fullScroll(ScrollView.FOCUS_DOWN);
|
||||||
textLog.append(text);
|
});
|
||||||
contentScroll.fullScroll(ScrollView.FOCUS_DOWN);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int[] initScaleFactors(){
|
||||||
|
//Could be optimized
|
||||||
|
int minDimension = Math.min(CallbackBridge.physicalHeight,CallbackBridge.physicalWidth);
|
||||||
|
int scaleFactor = (3*minDimension)/1080;
|
||||||
|
int[] scales = new int[4]; //Left, Top, Right, Bottom
|
||||||
|
|
||||||
|
scales[0] = (CallbackBridge.physicalWidth/2);
|
||||||
|
scales[0] -= scales[0]/scaleFactor;
|
||||||
|
|
||||||
|
scales[1] = (CallbackBridge.physicalHeight/2);
|
||||||
|
scales[1] -= scales[1]/scaleFactor;
|
||||||
|
|
||||||
|
scales[2] = (CallbackBridge.physicalWidth/2);
|
||||||
|
scales[2] += scales[2]/scaleFactor;
|
||||||
|
|
||||||
|
scales[3] = (CallbackBridge.physicalHeight/2);
|
||||||
|
scales[3] += scales[3]/scaleFactor;
|
||||||
|
|
||||||
|
return scales;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -32,6 +32,7 @@ import android.widget.CompoundButton;
|
|||||||
import android.widget.CompoundButton.OnCheckedChangeListener;
|
import android.widget.CompoundButton.OnCheckedChangeListener;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
import android.widget.ImageButton;
|
import android.widget.ImageButton;
|
||||||
|
import android.widget.ImageView;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
import android.widget.ProgressBar;
|
import android.widget.ProgressBar;
|
||||||
@ -651,6 +652,7 @@ public class PojavLoginActivity extends BaseActivity
|
|||||||
View child = inflater.inflate(R.layout.simple_account_list_item, null);
|
View child = inflater.inflate(R.layout.simple_account_list_item, null);
|
||||||
TextView accountName = child.findViewById(R.id.accountitem_text_name);
|
TextView accountName = child.findViewById(R.id.accountitem_text_name);
|
||||||
ImageButton removeButton = child.findViewById(R.id.accountitem_button_remove);
|
ImageButton removeButton = child.findViewById(R.id.accountitem_button_remove);
|
||||||
|
ImageView imageView = child.findViewById(R.id.account_head);
|
||||||
|
|
||||||
String accNameStr = s.substring(0, s.length() - 5);
|
String accNameStr = s.substring(0, s.length() - 5);
|
||||||
String skinFaceBase64 = MinecraftAccount.load(accNameStr).skinFaceBase64;
|
String skinFaceBase64 = MinecraftAccount.load(accNameStr).skinFaceBase64;
|
||||||
@ -658,8 +660,8 @@ public class PojavLoginActivity extends BaseActivity
|
|||||||
byte[] faceIconBytes = Base64.decode(skinFaceBase64, Base64.DEFAULT);
|
byte[] faceIconBytes = Base64.decode(skinFaceBase64, Base64.DEFAULT);
|
||||||
Bitmap bitmap = BitmapFactory.decodeByteArray(faceIconBytes, 0, faceIconBytes.length);
|
Bitmap bitmap = BitmapFactory.decodeByteArray(faceIconBytes, 0, faceIconBytes.length);
|
||||||
|
|
||||||
accountName.setCompoundDrawablesWithIntrinsicBounds(new BitmapDrawable(getResources(),
|
imageView.setImageDrawable(new BitmapDrawable(getResources(),
|
||||||
bitmap), null, null, null);
|
bitmap));
|
||||||
}
|
}
|
||||||
accountName.setText(accNameStr);
|
accountName.setText(accNameStr);
|
||||||
|
|
||||||
|
@ -0,0 +1,10 @@
|
|||||||
|
package net.kdt.pojavlaunch.utils;
|
||||||
|
|
||||||
|
public class MathUtils {
|
||||||
|
|
||||||
|
//Ported from https://www.arduino.cc/reference/en/language/functions/math/map/
|
||||||
|
public static float map(float x, float in_min, float in_max, float out_min, float out_max) {
|
||||||
|
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,6 +1,5 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<androidx.constraintlayout.widget.ConstraintLayout
|
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
@ -8,20 +7,19 @@
|
|||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/accountitem_text_name"
|
android:id="@+id/accountitem_text_name"
|
||||||
android:layout_width="240dp"
|
android:layout_width="185dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:background="?attr/selectableItemBackground"
|
android:background="?attr/selectableItemBackground"
|
||||||
android:gravity="center_vertical"
|
android:gravity="center_vertical"
|
||||||
|
android:maxHeight="?android:attr/listPreferredItemHeightSmall"
|
||||||
android:minHeight="?android:attr/listPreferredItemHeightSmall"
|
android:minHeight="?android:attr/listPreferredItemHeightSmall"
|
||||||
android:paddingStart="?android:attr/listPreferredItemPaddingStart"
|
android:paddingStart="?android:attr/listPreferredItemPaddingStart"
|
||||||
android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
|
android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
|
||||||
android:text="Name Placeholder"
|
|
||||||
|
|
||||||
|
android:text="Name Placeholder"
|
||||||
android:textAppearance="?android:attr/textAppearanceListItemSmall"
|
android:textAppearance="?android:attr/textAppearanceListItemSmall"
|
||||||
android:drawablePadding="20dp"
|
|
||||||
|
|
||||||
app:layout_constraintEnd_toStartOf="@+id/accountitem_button_remove"
|
app:layout_constraintEnd_toStartOf="@+id/accountitem_button_remove"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
|
||||||
app:layout_constraintTop_toTopOf="parent" />
|
app:layout_constraintTop_toTopOf="parent" />
|
||||||
|
|
||||||
<ImageButton
|
<ImageButton
|
||||||
@ -37,5 +35,15 @@
|
|||||||
app:layout_constraintTop_toTopOf="parent"
|
app:layout_constraintTop_toTopOf="parent"
|
||||||
app:srcCompat="@drawable/ic_remove" />
|
app:srcCompat="@drawable/ic_remove" />
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/account_head"
|
||||||
|
android:layout_width="48dp"
|
||||||
|
android:layout_height="48dp"
|
||||||
|
android:maxHeight="?android:attr/listPreferredItemHeightSmall"
|
||||||
|
android:minHeight="?android:attr/listPreferredItemHeightSmall"
|
||||||
|
app:layout_constraintEnd_toStartOf="@+id/accountitem_text_name"
|
||||||
|
app:layout_constraintTop_toTopOf="parent"
|
||||||
|
tools:srcCompat="@tools:sample/avatars" />
|
||||||
|
|
||||||
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user