Skip to content

Commit

Permalink
Custom controls: fix wrong pos
Browse files Browse the repository at this point in the history
  • Loading branch information
khanhduytran0 committed Sep 22, 2020
1 parent 89545f9 commit d6988fe
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ private void save(final boolean exit) {
builder.setPositiveButton(android.R.string.ok, null);
builder.setNegativeButton(android.R.string.cancel, null);
if (exit) {
builder.setNeutralButton("Exit without save", new AlertDialog.OnClickListener(){
builder.setNeutralButton(R.string.mcn_exit_call, new AlertDialog.OnClickListener(){
@Override
public void onClick(DialogInterface p1, int p2) {
CustomControlsActivity.super.onBackPressed();
Expand Down
7 changes: 2 additions & 5 deletions app/src/main/java/net/kdt/pojavlaunch/MCLauncherActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,6 @@ protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
gson = new Gson();

DisplayMetrics dm = Tools.getDisplayMetrics(this);
CallbackBridge.windowWidth = dm.widthPixels;
CallbackBridge.windowHeight = dm.heightPixels;
viewInit();

final View decorView = getWindow().getDecorView();
Expand Down Expand Up @@ -267,9 +264,9 @@ public boolean onMenuItemClick(MenuItem item) {
}

@Override
protected void onPostResume()
{
protected void onPostResume() {
super.onPostResume();
Tools.updateWindowSize(this);
}

private float updateWidthHeight() {
Expand Down
1 change: 0 additions & 1 deletion app/src/main/java/net/kdt/pojavlaunch/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,6 @@ public void onSystemUiVisibilityChange(int visibility) {
}

this.displayMetrics = Tools.getDisplayMetrics(this);

CallbackBridge.windowWidth = displayMetrics.widthPixels / scaleFactor;
CallbackBridge.windowHeight = displayMetrics.heightPixels / scaleFactor;
System.out.println("WidthHeight: " + CallbackBridge.windowWidth + ":" + CallbackBridge.windowHeight);
Expand Down
11 changes: 0 additions & 11 deletions app/src/main/java/net/kdt/pojavlaunch/PojavApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,6 @@ public void uncaughtException(Thread thread, Throwable th) {
LauncherPreferences.DEFAULT_PREF = PreferenceManager.getDefaultSharedPreferences(this);
LauncherPreferences.loadPreferences();

ControlButton.pixelOf2dp = (int) Tools.dpToPx(this, 2);
ControlButton.pixelOf30dp = (int) Tools.dpToPx(this, 30);
ControlButton.pixelOf50dp = (int) Tools.dpToPx(this, 50);
ControlButton.pixelOf80dp = (int) Tools.dpToPx(this, 80);
ControlButton[] specialButtons = ControlButton.getSpecialButtons();
specialButtons[0].name = getString(R.string.control_keyboard);
specialButtons[1].name = getString(R.string.control_toggle);
specialButtons[2].name = getString(R.string.control_primary);
specialButtons[3].name = getString(R.string.control_secondary);
specialButtons[4].name = getString(R.string.control_mouse);

FontChanger.initFonts(this);
} catch (Throwable th) {
Intent ferrorIntent = new Intent(this, FatalErrorActivity.class);
Expand Down
17 changes: 16 additions & 1 deletion app/src/main/java/net/kdt/pojavlaunch/PojavLoginActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,19 @@ public class PojavLoginActivity extends AppCompatActivity
@Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState); // false);


Tools.updateWindowSize(this);
ControlButton.pixelOf2dp = (int) Tools.dpToPx(this, 2);
ControlButton.pixelOf30dp = (int) Tools.dpToPx(this, 30);
ControlButton.pixelOf50dp = (int) Tools.dpToPx(this, 50);
ControlButton.pixelOf80dp = (int) Tools.dpToPx(this, 80);
ControlButton[] specialButtons = ControlButton.getSpecialButtons();
specialButtons[0].name = getString(R.string.control_keyboard);
specialButtons[1].name = getString(R.string.control_toggle);
specialButtons[2].name = getString(R.string.control_primary);
specialButtons[3].name = getString(R.string.control_secondary);
specialButtons[4].name = getString(R.string.control_mouse);

final View decorView = getWindow().getDecorView();
decorView.setOnSystemUiVisibilityChangeListener (new View.OnSystemUiVisibilityChangeListener() {
@Override
Expand Down Expand Up @@ -278,6 +290,9 @@ public void onCheckedChanged(CompoundButton p1, boolean p2) {
@Override
public void onResume() {
super.onResume();

Tools.updateWindowSize(this);

final int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
final View decorView = getWindow().getDecorView();
decorView.setSystemUiVisibility(uiOptions);
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/java/net/kdt/pojavlaunch/Tools.java
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,12 @@ public static DisplayMetrics getDisplayMetrics(Activity ctx) {
ctx.getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
return displayMetrics;
}

public static void updateWindowSize(Activity ctx) {
DisplayMetrics dm = getDisplayMetrics(ctx);
CallbackBridge.windowWidth = dm.widthPixels;
CallbackBridge.windowHeight = dm.heightPixels;
}

public static float pxToDp(Context ctx, float px) {
return (px / ctx.getResources().getDisplayMetrics().density);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public CustomControls(List<ControlButton> button) {
// Generate default control
public CustomControls(Context ctx) {
this();
this.button.add(ControlButton.getSpecialButtons()[0].clone()); // LWJGLGLFWKeycode
this.button.add(ControlButton.getSpecialButtons()[0].clone()); // Keyboard
this.button.add(ControlButton.getSpecialButtons()[1].clone()); // GUI
this.button.add(ControlButton.getSpecialButtons()[2].clone()); // Primary Mouse button
this.button.add(ControlButton.getSpecialButtons()[3].clone()); // Secondary Mouse button
Expand Down

0 comments on commit d6988fe

Please sign in to comment.