From 2eb88ff0ba6b28df39eda662f4834ed80637f7b3 Mon Sep 17 00:00:00 2001 From: SerpentSpirale Date: Sun, 21 Feb 2021 21:34:00 +0100 Subject: [PATCH] - Improved scaling of the select account menu for portrait/split screen mode and small scren devices. --- .../net/kdt/pojavlaunch/PojavLoginActivity.java | 14 +++++--------- .../res/layout/simple_account_list_holder.xml | 15 ++++++++++----- .../main/res/layout/simple_account_list_item.xml | 2 +- 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/PojavLoginActivity.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/PojavLoginActivity.java index 6bbdf6f40..265ef1027 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/PojavLoginActivity.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/PojavLoginActivity.java @@ -23,6 +23,7 @@ import android.util.Base64; import android.util.Log; import android.view.LayoutInflater; import android.view.View; +import android.view.ViewGroup; import android.view.WindowManager; import android.widget.AdapterView; import android.widget.ArrayAdapter; @@ -675,12 +676,8 @@ public class PojavLoginActivity extends BaseActivity final Dialog accountDialog = new Dialog(PojavLoginActivity.this); - int xScreen = PojavLoginActivity.this.getResources().getDisplayMetrics().widthPixels; - int yScreen = PojavLoginActivity.this.getResources().getDisplayMetrics().heightPixels; - accountDialog.setContentView(R.layout.simple_account_list_holder); - LinearLayout accountListLayout = accountDialog.findViewById(R.id.accountListLayout); LayoutInflater inflater = (LayoutInflater) this.getSystemService(LAYOUT_INFLATER_SERVICE); @@ -764,12 +761,14 @@ public class PojavLoginActivity extends BaseActivity public void onClick(DialogInterface p1, int p2) { new InvalidateTokenTask(PojavLoginActivity.this).execute(selectedAccName); accountListLayout.removeViewsInLayout(accountIndex_final, 1); - //Resize the window + if (accountListLayout.getChildCount() == 0) { accountDialog.dismiss(); //No need to keep it, since there is no account return; } - accountDialog.getWindow().setLayout((int)(xScreen*0.4),(int) Math.min((yScreen*0.8), (73 + accountListLayout.getChildCount()*55)*(PojavLoginActivity.this.getResources().getDisplayMetrics().densityDpi/160f) )); + //Refreshes the layout with the same settings so it take the missing child into account. + accountListLayout.setLayoutParams(accountListLayout.getLayoutParams()); + } }); builder2.setNegativeButton(android.R.string.cancel, null); @@ -778,9 +777,6 @@ public class PojavLoginActivity extends BaseActivity }); } - - //The value 73 and 56 are dp numbers, converted into px in order to resize the layout. - accountDialog.getWindow().setLayout((int)(xScreen*0.4),(int)Math.min((yScreen*0.8), (73 + accountListLayout.getChildCount()*56)*(PojavLoginActivity.this.getResources().getDisplayMetrics().densityDpi/160f) )); accountDialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); accountDialog.show(); } diff --git a/app_pojavlauncher/src/main/res/layout/simple_account_list_holder.xml b/app_pojavlauncher/src/main/res/layout/simple_account_list_holder.xml index d8dcb4e8c..bb33c8565 100644 --- a/app_pojavlauncher/src/main/res/layout/simple_account_list_holder.xml +++ b/app_pojavlauncher/src/main/res/layout/simple_account_list_holder.xml @@ -3,19 +3,21 @@ xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:background="#424242" - android:layout_width="match_parent" + android:layout_width="300dp" android:layout_height="match_parent">