Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The great refactor #2811

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
8ed40a2
Refactor ExtraCore
Mathias-Boulay Feb 25, 2022
6f2f780
Refactor ConsoleFragment.java
Mathias-Boulay Feb 25, 2022
c706c88
Refactor CrashFragment.java
Mathias-Boulay Feb 25, 2022
b3d8873
Refactor LauncherFragment.java
Mathias-Boulay Feb 25, 2022
5c251c3
Refactor multiRT
Mathias-Boulay Feb 25, 2022
3914d3b
Refactor ControlOffsetPreference.java
Mathias-Boulay Feb 25, 2022
0b1141b
Refactor CustomSeekBarPreference.java
Mathias-Boulay Feb 25, 2022
cbf4778
Refactor PerVersionConfigDialog.java
Mathias-Boulay Feb 26, 2022
95b67c7
Update RuntimeManagerPreference.java
Mathias-Boulay Feb 26, 2022
64b0856
Refactor AWTCanvasView.java
Mathias-Boulay Feb 26, 2022
20e1e96
Update AWTInputEvent.java
Mathias-Boulay Feb 26, 2022
0eea5f6
Refactor BaseActivity.java
Mathias-Boulay Feb 26, 2022
f3d8e1f
Remove CustomTabs.java, GLTextureView.java, and InstallerTask.java
Mathias-Boulay Feb 26, 2022
c5257a9
Refactor ExitActivity.java
Mathias-Boulay Feb 26, 2022
8e55ade
Refactor FatalErrorActivity.java
Mathias-Boulay Feb 26, 2022
ff2587b
Refactor JavaGUILauncherActivity.java
Mathias-Boulay Feb 26, 2022
3653c4b
Refactor Logger.java
Mathias-Boulay Feb 26, 2022
45228d5
Refactor PojavApplication.java
Mathias-Boulay Feb 26, 2022
d0b0417
Refactor Touchpad.java
Mathias-Boulay Feb 26, 2022
da6120c
Refactor CallbackBridge.java
Mathias-Boulay Feb 26, 2022
f8be333
Refactor GameFolderProvider.java
Mathias-Boulay Feb 26, 2022
44cc8d1
Rename LWJGLGLFWKeycode class
Mathias-Boulay Feb 26, 2022
b67c939
Refactor EfficientAndroidLWJGLKeycode.java
Mathias-Boulay Feb 26, 2022
6d7f85d
Refactor MinecraftGLView.java
Mathias-Boulay Feb 26, 2022
dda99e9
Update ImportControlActivity.java
Mathias-Boulay Feb 26, 2022
0960127
Refactor CustomControlsActivity.java
Mathias-Boulay Feb 26, 2022
4a39687
Update PojavLoginActivity.java
Mathias-Boulay Feb 26, 2022
63c98d6
Refactor JAssets.java
Mathias-Boulay Feb 26, 2022
c71889c
Refactor LoggerView.java
Mathias-Boulay Feb 26, 2022
f590f3e
Refactor DefocusableScrollView.java
Mathias-Boulay Feb 26, 2022
c766464
Update MineButton.java
Mathias-Boulay Feb 26, 2022
8ba5252
Update MineEditText.java
Mathias-Boulay Feb 26, 2022
de43758
Update PojavMigrator.java
Mathias-Boulay Feb 26, 2022
0d0b113
Refactor TapDetector.java
Mathias-Boulay Feb 26, 2022
0ec8cbf
Refactor Tools.java
Mathias-Boulay Feb 26, 2022
8b35a9c
Refactor TouchCharInput.java
Mathias-Boulay Feb 26, 2022
0bdddbd
Update SingleTapConfirm.java
Mathias-Boulay Feb 26, 2022
3c3493c
Refactor MCOptionUtils.java
Mathias-Boulay Feb 26, 2022
cb69e6a
Refactor PojavProfile.java
Mathias-Boulay Feb 26, 2022
6eafba8
Refactor JREUtils.java
Mathias-Boulay Feb 26, 2022
9529b24
Refactor V117CompatUtil.java
Mathias-Boulay Feb 26, 2022
5b2ff18
Refactor gamepad related files
Mathias-Boulay Feb 26, 2022
2b01295
Refactor editing button dialogs
Mathias-Boulay Feb 26, 2022
28fb4cb
Refactor HandleView related files
Mathias-Boulay Feb 26, 2022
d0e1195
Refactor control button related files
Mathias-Boulay Feb 26, 2022
155ac09
Fix some naming; Rename many resources
Mathias-Boulay Mar 6, 2022
f162057
Rename more resources
Mathias-Boulay Mar 6, 2022
79fc9f7
Fix improper array filling
Mathias-Boulay Mar 6, 2022
450ff0c
Update layout names
Mathias-Boulay Mar 8, 2022
30777cd
Update drawable names
Mathias-Boulay Mar 8, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app_pojavlauncher/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@
</activity>

<activity
android:theme="@style/MenuDialog"
android:theme="@style/Theme.AppCompat.DayNight.Dialog"
android:screenOrientation="sensorLandscape"
android:name=".FatalErrorActivity"
android:configChanges="keyboardHidden|orientation|screenSize|keyboard|navigation"/>
<activity
android:theme="@style/MenuDialog"
android:theme="@style/Theme.AppCompat.DayNight.Dialog"
android:screenOrientation="sensorLandscape"
android:name=".ExitActivity"
android:configChanges="keyboardHidden|orientation|screenSize|keyboard|navigation"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
import android.util.AttributeSet;
import android.widget.ScrollView;

/**
Class allowing to ignore the focusing from an item such an EditText within it.
Ignoring it will stop the scrollView from refocusing on the view
*/
public class DefocusableScrollView extends ScrollView {

/*
What is this class for ?
It allows to ignore the focusing from an item such an EditText.
Ignoring it will stop the scrollView from refocusing on the view
*/

private boolean keepFocusing = false;

private boolean mKeepFocusing = false;


public DefocusableScrollView(Context context) {
Expand All @@ -33,16 +33,16 @@ public DefocusableScrollView(Context context, AttributeSet attrs, int defStyleAt
}

public void setKeepFocusing(boolean shouldKeepFocusing){
keepFocusing = shouldKeepFocusing;
mKeepFocusing = shouldKeepFocusing;
}

public boolean isKeepFocusing(){
return keepFocusing;
return mKeepFocusing;
}

@Override
protected int computeScrollDeltaToGetChildRectOnScreen(Rect rect) {
if(!keepFocusing) return 0;
if(!mKeepFocusing) return 0;
return super.computeScrollDeltaToGetChildRectOnScreen(rect);
}

Expand Down
55 changes: 28 additions & 27 deletions app_pojavlauncher/src/main/java/com/kdt/LoggerView.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
* It has support for the Logger class
*/
public class LoggerView extends ConstraintLayout {
private Logger.eventLogListener logListener;
private ToggleButton toggleButton;
private ScrollView scrollView;
private TextView log;
private Logger.eventLogListener mLogListener;
private ToggleButton mToggleButton;
private ScrollView mScrollView;
private TextView mLogTextView;


public LoggerView(@NonNull Context context) {
Expand All @@ -36,50 +36,51 @@ public LoggerView(@NonNull Context context, @Nullable AttributeSet attrs) {
init();
}

@Override
public void setVisibility(int visibility) {
super.setVisibility(visibility);
// Triggers the log view shown state by default when viewing it
mToggleButton.setChecked(visibility == VISIBLE);
}

/**
* Inflate the layout, and add component behaviors
*/
private void init(){
inflate(getContext(), R.layout.loggerview_layout, this);
log = findViewById(R.id.content_log_view);
log.setTypeface(Typeface.MONOSPACE);
inflate(getContext(), R.layout.view_logger, this);
mLogTextView = findViewById(R.id.content_log_view);
mLogTextView.setTypeface(Typeface.MONOSPACE);
//TODO clamp the max text so it doesn't go oob
log.setMaxLines(Integer.MAX_VALUE);
log.setEllipsize(null);
log.setVisibility(GONE);
mLogTextView.setMaxLines(Integer.MAX_VALUE);
mLogTextView.setEllipsize(null);
mLogTextView.setVisibility(GONE);

// Toggle log visibility
toggleButton = findViewById(R.id.content_log_toggle_log);
toggleButton.setOnCheckedChangeListener(
mToggleButton = findViewById(R.id.content_log_toggle_log);
mToggleButton.setOnCheckedChangeListener(
(compoundButton, isChecked) -> {
log.setVisibility(isChecked ? VISIBLE : GONE);
if(!isChecked) log.setText("");
mLogTextView.setVisibility(isChecked ? VISIBLE : GONE);
if(!isChecked) mLogTextView.setText("");
});
toggleButton.setChecked(false);
mToggleButton.setChecked(false);

// Remove the loggerView from the user View
ImageButton cancelButton = findViewById(R.id.log_view_cancel);
cancelButton.setOnClickListener(view -> LoggerView.this.setVisibility(GONE));

// Set the scroll view
scrollView = findViewById(R.id.content_log_scroll);
mScrollView = findViewById(R.id.content_log_scroll);

// Listen to logs
logListener = text -> {
if(log.getVisibility() != VISIBLE) return;
mLogListener = text -> {
if(mLogTextView.getVisibility() != VISIBLE) return;
post(() -> {
log.append(text + '\n');
scrollView.fullScroll(View.FOCUS_DOWN);
mLogTextView.append(text + '\n');
mScrollView.fullScroll(View.FOCUS_DOWN);
});

};
Logger.getInstance().setLogListener(logListener);
Logger.getInstance().setLogListener(mLogListener);
}

@Override
public void setVisibility(int visibility) {
super.setVisibility(visibility);
// Triggers the log view shown state by default when viewing it
toggleButton.setChecked(visibility == VISIBLE);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@

import net.kdt.pojavlaunch.R;

public class MineButton extends androidx.appcompat.widget.AppCompatButton
{
public class MineButton extends androidx.appcompat.widget.AppCompatButton {

public MineButton(Context ctx) {
this(ctx, null);
Expand Down
12 changes: 4 additions & 8 deletions app_pojavlauncher/src/main/java/com/kdt/mcgui/MineEditText.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,18 @@
import android.util.*;
import android.graphics.*;

public class MineEditText extends com.google.android.material.textfield.TextInputEditText
{
public MineEditText(Context ctx)
{
public class MineEditText extends com.google.android.material.textfield.TextInputEditText {
public MineEditText(Context ctx) {
super(ctx);
init();
}

public MineEditText(Context ctx, AttributeSet attrs)
{
public MineEditText(Context ctx, AttributeSet attrs) {
super(ctx, attrs);
init();
}

public void init()
{
public void init() {
setBackgroundColor(Color.parseColor("#131313"));
setPadding(5, 5, 5, 5);
}
Expand Down
124 changes: 59 additions & 65 deletions app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/AWTCanvasView.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,68 +10,31 @@
import org.lwjgl.glfw.*;

public class AWTCanvasView extends TextureView implements TextureView.SurfaceTextureListener, Runnable {
private final int MAX_SIZE = 100;
private final double NANOS = 1000000000.0;

private int mScaleFactor;
private int[] mScales;

private int mWidth, mHeight;
private boolean mIsDestroyed = false;

private TextPaint fpsPaint;
private boolean attached = false;
private final TextPaint mFpsPaint;
private boolean mAttached = false;
private boolean mDrawing;

// Temporary count fps https://stackoverflow.com/a/13729241
private LinkedList<Long> times = new LinkedList<Long>(){{add(System.nanoTime());}};
private final int MAX_SIZE = 100;
private final double NANOS = 1000000000.0;

/** Calculates and returns frames per second */
private double fps() {
long lastTime = System.nanoTime();
double difference = (lastTime - times.getFirst()) / NANOS;
times.addLast(lastTime);
int size = times.size();
if (size > MAX_SIZE) {
times.removeFirst();
}
return difference > 0 ? times.size() / difference : 0.0;
}

/** Computes the scale to better fit the screen */
void initScaleFactors(){
initScaleFactors(0);
}

void initScaleFactors(int forcedScale){
//Could be optimized
if(forcedScale < 1) { //Auto scale
int minDimension = Math.min(CallbackBridge.physicalHeight, CallbackBridge.physicalWidth);
mScaleFactor = Math.max(((3 * minDimension) / 1080) - 1, 1);
}else{
mScaleFactor = forcedScale;
}

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;

mScales = scales;
}
private final LinkedList<Long> mTimes = new LinkedList<Long>(){{add(System.nanoTime());}};

public AWTCanvasView(Context ctx) {
this(ctx, null);
}

public AWTCanvasView(Context ctx, AttributeSet attrs) {
super(ctx, attrs);
// setWillNotDraw(false);

fpsPaint = new TextPaint();
fpsPaint.setColor(Color.WHITE);
fpsPaint.setTextSize(20);
mFpsPaint = new TextPaint();
mFpsPaint.setColor(Color.WHITE);
mFpsPaint.setTextSize(20);

setSurfaceTextureListener(this);
initScaleFactors();
Expand Down Expand Up @@ -101,44 +64,75 @@ public void onSurfaceTextureSizeChanged(SurfaceTexture texture, int w, int h) {
@Override
public void onSurfaceTextureUpdated(SurfaceTexture texture) {
}

private boolean mDrawing;
private Surface mSurface;

@Override
public void run() {
Canvas canvas;
mSurface = new Surface(getSurfaceTexture());
Surface surface = new Surface(getSurfaceTexture());

try {
while (!mIsDestroyed && mSurface.isValid()) {
canvas = mSurface.lockCanvas(null);
while (!mIsDestroyed && surface.isValid()) {
canvas = surface.lockCanvas(null);
canvas.drawRGB(0, 0, 0);

if (!attached) {
attached = CallbackBridge.nativeAttachThreadToOther(true, BaseMainActivity.isInputStackCall);
if (!mAttached) {
mAttached = CallbackBridge.nativeAttachThreadToOther(true, BaseMainActivity.isInputStackCall);
} else {
int[] rgbArray = JREUtils.renderAWTScreenFrame(/* canvas, mWidth, mHeight */);
mDrawing = rgbArray != null;
if (rgbArray != null) {

canvas.save();
canvas.scale(mScaleFactor, mScaleFactor);
canvas.translate(-mScales[0],-mScales[1]);

canvas.translate(-mScales[0], -mScales[1]);

canvas.drawBitmap(rgbArray, 0, CallbackBridge.physicalWidth, 0, 0, CallbackBridge.physicalWidth, CallbackBridge.physicalHeight, true, null);
canvas.restore();

}
rgbArray = null;
// System.gc();
}
canvas.drawText("FPS: " + (Math.round(fps() * 10) / 10) + ", attached=" + attached + ", drawing=" + mDrawing, 50, 50, fpsPaint);

mSurface.unlockCanvasAndPost(canvas);
canvas.drawText("FPS: " + (Math.round(fps() * 10) / 10) + ", attached=" + mAttached + ", drawing=" + mDrawing, 50, 50, mFpsPaint);
surface.unlockCanvasAndPost(canvas);
}
} catch (Throwable th) {
Tools.showError(getContext(), th);
} catch (Throwable throwable) {
Tools.showError(getContext(), throwable);
}
surface.release();
}

/** Computes the scale to better fit the screen */
void initScaleFactors(){
initScaleFactors(0);
}

void initScaleFactors(int forcedScale){
//Could be optimized
if(forcedScale < 1) { //Auto scale
int minDimension = Math.min(CallbackBridge.physicalHeight, CallbackBridge.physicalWidth);
mScaleFactor = Math.max(((3 * minDimension) / 1080) - 1, 1);
}else{
mScaleFactor = forcedScale;
}

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;

mScales = scales;
}

/** Calculates and returns frames per second */
private double fps() {
long lastTime = System.nanoTime();
double difference = (lastTime - mTimes.getFirst()) / NANOS;
mTimes.addLast(lastTime);
int size = mTimes.size();
if (size > MAX_SIZE) {
mTimes.removeFirst();
}
return difference > 0 ? mTimes.size() / difference : 0.0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
public class AWTInputEvent
{
public class AWTInputEvent {
// InputEvent
/**
* This flag indicates that the Shift key was down when the event
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@

import static net.kdt.pojavlaunch.prefs.LauncherPreferences.PREF_IGNORE_NOTCH;

public class BaseActivity extends AppCompatActivity
{
public abstract class BaseActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand All @@ -24,7 +23,7 @@ protected void attachBaseContext(Context base) {
@Override
public void startActivity(Intent i) {
super.startActivity(i);
new Throwable("StartActivity").printStackTrace();
//new Throwable("StartActivity").printStackTrace();
}

@Override
Expand Down
Loading