Load a config and smaller scale steps

This commit is contained in:
downthecrop 2021-12-23 11:07:55 -08:00
parent a0afe5d587
commit b09dddfb56
5 changed files with 178 additions and 107 deletions

View file

@ -17,6 +17,7 @@ public class AWTCanvasView extends TextureView implements TextureView.SurfaceTex
public int offsetY = 0;
private float[] stretchOffsets;
private float[] stretchScales;
private boolean streched = false;
private int mWidth, mHeight;
private boolean mIsDestroyed = false;
@ -56,8 +57,7 @@ public class AWTCanvasView extends TextureView implements TextureView.SurfaceTex
void initScaleFactors(float forcedScale){
//Could be optimized
if(forcedScale < 1) { //Auto scale
int minDimension = Math.min(CallbackBridge.physicalHeight, CallbackBridge.physicalWidth);
mScaleFactor = 2;
mScaleFactor = 2.166F;
}else{
mScaleFactor = forcedScale;
}
@ -72,31 +72,6 @@ public class AWTCanvasView extends TextureView implements TextureView.SurfaceTex
mScales = scales;
}
void initStretchedModes(){
float[] offsets = new float[2];
float[] scales = new float[4];
// Full screen stretched
offsets[0] -= mScales[0]*1.33F;
offsets[1] -= mScales[1]*1.02F;
// 16:9 Stretched
// Fullscreen stretched
scales[0] = (CallbackBridge.physicalWidth/2)/765;
scales[1] = (CallbackBridge.physicalHeight/2)/503;
// 16:9 stretched
scales[2] = (CallbackBridge.physicalWidth/2)/894.22F;
scales[3] = (CallbackBridge.physicalHeight/2)/503;
stretchScales = scales;
stretchOffsets = offsets;
}
public AWTCanvasView(Context ctx) {
this(ctx, null);
@ -112,14 +87,12 @@ public class AWTCanvasView extends TextureView implements TextureView.SurfaceTex
setSurfaceTextureListener(this);
initScaleFactors();
initStretchedModes();
}
@Override
public void onSurfaceTextureAvailable(SurfaceTexture texture, int w, int h) {
mWidth = w;
mHeight = h;
mIsDestroyed = false;
new Thread(this, "AndroidAWTRenderer").start();
}
@ -158,19 +131,16 @@ public class AWTCanvasView extends TextureView implements TextureView.SurfaceTex
int[] rgbArray = JREUtils.renderAWTScreenFrame(/* canvas, mWidth, mHeight */);
mDrawing = rgbArray != null;
if (rgbArray != null) {
canvas.save();
// 16:9~ Scaled
//System.out.println("Factor: "+mScaleFactor);
//canvas.scale(mScaleFactor*1.17F, mScaleFactor);
//canvas.translate(-mScales[0]*1.17F,-mScales[1]);
//
canvas.scale(mScaleFactor, mScaleFactor);
canvas.translate(-mScales[0],-mScales[1]);
if(streched){
canvas.scale(mScaleFactor*1.17F, mScaleFactor);
canvas.translate(-mScales[0]*1.115F,-mScales[1]);
} else {
canvas.scale(mScaleFactor, mScaleFactor);
canvas.translate(-mScales[0],-mScales[1]);
}
canvas.drawBitmap(rgbArray, 0, CallbackBridge.physicalWidth, offsetX, offsetY, CallbackBridge.physicalWidth, CallbackBridge.physicalHeight, true, null);
canvas.restore();
}
}
canvas.drawText("FPS: " + (Math.round(fps() * 10) / 10) + ", attached=" + attached + ", drawing=" + mDrawing, 50, 50, fpsPaint);

View file

@ -51,7 +51,7 @@ public class JavaGUILauncherActivity extends BaseActivity implements View.OnTou
private boolean isVirtualMouseEnabled;
private int scaleFactor;
private float scaleFactor;
public float[] scaleFactors = initScaleFactors();
private final int fingerStillThreshold = 8;
@ -415,8 +415,17 @@ public class JavaGUILauncherActivity extends BaseActivity implements View.OnTou
}
void sendScaledMousePosition(float x, float y){
AWTInputBridge.sendMousePos((int) map(x,0,CallbackBridge.physicalWidth, scaleFactors[0], scaleFactors[2]),
(int) map(y,0,CallbackBridge.physicalHeight, scaleFactors[1], scaleFactors[3]));
AWTInputBridge.sendMousePos(
(int) map(x,0,CallbackBridge.physicalWidth, scaleFactors[0], scaleFactors[2]),
(int) map(y,0,CallbackBridge.physicalHeight, scaleFactors[1], scaleFactors[3])
);
}
void sendScaledMousePositionStretch(float x, float y){
AWTInputBridge.sendMousePos(
(int) map(x,0,CallbackBridge.physicalWidth, scaleFactors[0]*1.17F, scaleFactors[2]*1.17F),
(int) map(y,0,CallbackBridge.physicalHeight, scaleFactors[1], scaleFactors[3])
);
}
public void toggleVirtualMouse(View v) {
@ -491,8 +500,7 @@ public class JavaGUILauncherActivity extends BaseActivity implements View.OnTou
//Could be optimized
if(autoScale) { //Auto scale
int minDimension = Math.min(CallbackBridge.physicalHeight, CallbackBridge.physicalWidth);
scaleFactor = Math.max(((3 * minDimension) / 1080) - 1, 1);
scaleFactor = 2.166F;
}
float[] scales = new float[4]; //Left, Top, Right, Bottom
@ -513,14 +521,14 @@ public class JavaGUILauncherActivity extends BaseActivity implements View.OnTou
}
public void scaleDown(View view) {
scaleFactor = Math.max(scaleFactor - 1, 1);
scaleFactor = Math.max(scaleFactor - .2F, 1);
scaleFactors = initScaleFactors(false);
mTextureView.initScaleFactors(scaleFactor);
sendScaledMousePosition(mousePointer.getX(),mousePointer.getY());
}
public void scaleUp(View view) {
scaleFactor = Math.min(scaleFactor + 1, 6);
scaleFactor = Math.min(scaleFactor + .2F, 6);
scaleFactors = initScaleFactors(false);
mTextureView.initScaleFactors(scaleFactor);
sendScaledMousePosition(mousePointer.getX(),mousePointer.getY());

View file

@ -204,32 +204,12 @@ public class PojavLoginActivity extends BaseActivity {
}
}
private void initMain() throws Throwable {
// Copy config.json to writable storage
// https://stackoverflow.com/questions/38590996/copy-xml-from-raw-folder-to-internal-storage-and-use-it-in-android
File file = new File(getFilesDir(), "config.json");
try {
Context context = getApplicationContext();
InputStream inputStream = context.getResources().openRawResource(R.raw.config);
FileOutputStream fileOutputStream = new FileOutputStream(file);
byte buf[]=new byte[1024];
int len;
while((len=inputStream.read(buf))>0) {
fileOutputStream.write(buf,0,len);
}
fileOutputStream.close();
inputStream.close();
System.out.println("Write to Local");
} catch (IOException e1) {}
mkdirs(Tools.DIR_ACCOUNT_NEW);
mkdirs(Tools.DIR_GAME_HOME);
mkdirs(Tools.DIR_GAME_HOME + "/lwjgl3");
mkdirs(Tools.DIR_GAME_HOME + "/config");
mkdirs(Tools.CTRLMAP_PATH);
try {
Tools.copyAssetFile(this, "components/security/pro-grade.jar", Tools.DIR_DATA, true);
Tools.copyAssetFile(this, "components/security/java_sandbox.policy", Tools.DIR_DATA, true);
Tools.copyAssetFile(this, "options.txt", Tools.DIR_GAME_NEW, false);
@ -267,6 +247,23 @@ public class PojavLoginActivity extends BaseActivity {
MultiRTUtils.installRuntimeNamedBinpack(am.open("components/jre/universal.tar.xz"), am.open("components/jre/bin-" + archAsString(Tools.DEVICE_ARCHITECTURE) + ".tar.xz"), "Internal", rt_version,
(resid, vararg) -> runOnUiThread(()->{if(startupTextView!=null)startupTextView.setText(getString(resid,vararg));}));
MultiRTUtils.postPrepare(PojavLoginActivity.this,"Internal");
// Copy config.json to writable storage
// https://stackoverflow.com/questions/38590996/copy-xml-from-raw-folder-to-internal-storage-and-use-it-in-android
File file = new File(getFilesDir(), "config.json");
try {
Context context = getApplicationContext();
InputStream inputStream = context.getResources().openRawResource(R.raw.config);
FileOutputStream fileOutputStream = new FileOutputStream(file);
byte buf[]=new byte[1024];
int len;
while((len=inputStream.read(buf))>0) {
fileOutputStream.write(buf,0,len);
}
fileOutputStream.close();
inputStream.close();
System.out.println("Write to Local");
} catch (IOException e1) {}
return true;
}catch (IOException e) {
Log.e("JREAuto", "Internal JRE unpack failed", e);

View file

@ -1,20 +1,85 @@
package net.kdt.pojavlaunch;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri;
import android.os.Bundle;
import android.os.FileUtils;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.Switch;
import android.widget.Toast;
import androidx.annotation.Nullable;
import androidx.preference.PreferenceManager;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
public class SettingsMenu extends Activity {
private static final int FILE_SELECT_CODE = 0;
private void showFileChooser() {
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("*/*");
intent.addCategory(Intent.CATEGORY_OPENABLE);
try {
startActivityForResult(
Intent.createChooser(intent, "Select a File to Upload"),
FILE_SELECT_CODE);
} catch (android.content.ActivityNotFoundException ex) {
// Potentially direct the user to the Market with a Dialog
Toast.makeText(this, "Please install a File Manager.",
Toast.LENGTH_SHORT).show();
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
case FILE_SELECT_CODE:
if (resultCode == RESULT_OK) {
// Get the Uri of the selected file
Uri uri = data.getData();
Log.d("TAG", "File Uri: " + uri.toString());
// Get the path
Log.d("TAG", "File Path: " + uri.getPath());
// Get the file instance
File config = new File(getFilesDir(), "config.json");
try {
Log.d("TAG", "Starting copy: " + uri.getPath());
InputStream inputStream = getContentResolver().openInputStream(uri);
FileOutputStream fileOutputStream = new FileOutputStream(config);
byte buf[]=new byte[1024];
int len;
while((len=inputStream.read(buf))>0) {
fileOutputStream.write(buf,0,len);
}
fileOutputStream.close();
inputStream.close();
System.out.println("Wrote new config to Local");
} catch (IOException e1) {
Log.d("error", "Error with file " + e1);
}
}
break;
}
super.onActivityResult(requestCode, resultCode, data);
}
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@ -28,6 +93,23 @@ public class SettingsMenu extends Activity {
final EditText username = findViewById(R.id.username);
final EditText password = findViewById(R.id.password);
final Switch righthanded = findViewById(R.id.righthanded);
final Button loadConfig = findViewById(R.id.loadconfig);
loadConfig.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
switch(event.getAction()) {
case MotionEvent.ACTION_DOWN:
Log.i("Pressed","Button");
showFileChooser();
return true; // if you want to handle the touch event
case MotionEvent.ACTION_UP:
// RELEASED
return true; // if you want to handle the touch event
}
return false;
}
});
//For storing string value in sharedPreference

View file

@ -1,50 +1,64 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/loginText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_marginStart="16dp"
android:layout_marginTop="32dp"
android:text="Auto Login (Requires relaunch)"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/username"
<LinearLayout
android:layout_height="match_parent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/loginText"
android:layout_marginTop="43dp"
android:hint="Username"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/loginText" />
android:orientation="vertical">
<TextView
android:id="@+id/loginText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_marginStart="16dp"
android:layout_marginTop="32dp"
android:text="Auto Login (Requires relaunch)"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/username"
android:layout_marginTop="28dp"
android:hint="Password"
android:inputType="textPassword"
app:layout_constraintTop_toBottomOf="@+id/username"
tools:layout_editor_absoluteX="-1dp" />
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/username"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/loginText"
android:layout_marginTop="43dp"
android:hint="Username"
app:layout_constraintTop_toBottomOf="@+id/loginText" />
<Switch
android:id="@+id/righthanded"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="35dp"
android:text="Right Handed Mode"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/password" />
</androidx.constraintlayout.widget.ConstraintLayout>
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/username"
android:layout_marginTop="28dp"
android:hint="Password"
android:inputType="textPassword"
app:layout_constraintTop_toBottomOf="@+id/username"
tools:layout_editor_absoluteX="-1dp" />
<Switch
android:id="@+id/righthanded"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="35dp"
android:text="Right Handed Mode"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/password" />
<Button
android:id="@+id/loadconfig"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="24dp"
android:text="Load Config"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/righthanded" />
</LinearLayout>
</ScrollView>