From 506d1dc1f23438a06c0d0df426bbeaccc55b1256 Mon Sep 17 00:00:00 2001 From: Mauricio Colli Date: Fri, 10 Apr 2020 10:31:28 -0300 Subject: [PATCH] Improve size handling of the drawer header title Some devices, specially with custom fonts that changed the font width, weren't being correctly adjusted before. --- .../java/org/schabi/newpipe/MainActivity.java | 15 +++++++++++++++ app/src/main/res/layout/drawer_header.xml | 9 ++++----- app/src/main/res/values/dimens.xml | 4 ++-- 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/MainActivity.java b/app/src/main/java/org/schabi/newpipe/MainActivity.java index c004eae4a..e6269dd5f 100644 --- a/app/src/main/java/org/schabi/newpipe/MainActivity.java +++ b/app/src/main/java/org/schabi/newpipe/MainActivity.java @@ -33,6 +33,7 @@ import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuItem; import android.view.View; +import android.view.ViewGroup; import android.view.Window; import android.view.WindowManager; import android.widget.AdapterView; @@ -301,6 +302,20 @@ public class MainActivity extends AppCompatActivity { headerServiceView = hView.findViewById(R.id.drawer_header_service_view); toggleServiceButton = hView.findViewById(R.id.drawer_header_action_button); toggleServiceButton.setOnClickListener(view -> toggleServices()); + + // If the current app name is bigger than the default "NewPipe" (7 chars), + // let the text view grow a little more as well. + if (getString(R.string.app_name).length() > "NewPipe".length()) { + final TextView headerTitle = hView.findViewById(R.id.drawer_header_newpipe_title); + final ViewGroup.LayoutParams layoutParams = headerTitle.getLayoutParams(); + layoutParams.width = ViewGroup.LayoutParams.WRAP_CONTENT; + headerTitle.setLayoutParams(layoutParams); + headerTitle.setMaxLines(2); + headerTitle.setMinWidth(getResources() + .getDimensionPixelSize(R.dimen.drawer_header_newpipe_title_default_width)); + headerTitle.setMaxWidth(getResources() + .getDimensionPixelSize(R.dimen.drawer_header_newpipe_title_max_width)); + } } private void toggleServices() { diff --git a/app/src/main/res/layout/drawer_header.xml b/app/src/main/res/layout/drawer_header.xml index 4abf20c44..a2f447cdf 100644 --- a/app/src/main/res/layout/drawer_header.xml +++ b/app/src/main/res/layout/drawer_header.xml @@ -45,22 +45,21 @@ + tools:ignore="UnusedAttribute" + tools:text="NewPipe" /> 16dp 48dp 12dp - 120dp - 220dp + 130dp + 200dp 18sp 32sp 16dp