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.
This commit is contained in:
parent
36b2bea25f
commit
506d1dc1f2
|
@ -33,6 +33,7 @@ import android.view.LayoutInflater;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
import android.view.Window;
|
import android.view.Window;
|
||||||
import android.view.WindowManager;
|
import android.view.WindowManager;
|
||||||
import android.widget.AdapterView;
|
import android.widget.AdapterView;
|
||||||
|
@ -301,6 +302,20 @@ public class MainActivity extends AppCompatActivity {
|
||||||
headerServiceView = hView.findViewById(R.id.drawer_header_service_view);
|
headerServiceView = hView.findViewById(R.id.drawer_header_service_view);
|
||||||
toggleServiceButton = hView.findViewById(R.id.drawer_header_action_button);
|
toggleServiceButton = hView.findViewById(R.id.drawer_header_action_button);
|
||||||
toggleServiceButton.setOnClickListener(view -> toggleServices());
|
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() {
|
private void toggleServices() {
|
||||||
|
|
|
@ -45,22 +45,21 @@
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/drawer_header_newpipe_title"
|
android:id="@+id/drawer_header_newpipe_title"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="@dimen/drawer_header_newpipe_title_default_width"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:layout_marginEnd="@dimen/drawer_header_newpipe_icon_title_space"
|
android:layout_marginEnd="@dimen/drawer_header_newpipe_icon_title_space"
|
||||||
android:ellipsize="end"
|
android:ellipsize="end"
|
||||||
android:gravity="start|center_vertical"
|
android:gravity="start|center_vertical"
|
||||||
android:hyphenationFrequency="full"
|
android:hyphenationFrequency="full"
|
||||||
android:maxWidth="@dimen/drawer_header_newpipe_title_max_width"
|
android:maxLines="1"
|
||||||
android:maxLines="2"
|
|
||||||
android:minWidth="@dimen/drawer_header_newpipe_title_min_width"
|
|
||||||
android:text="@string/app_name"
|
android:text="@string/app_name"
|
||||||
android:textColor="@color/drawer_header_font_color"
|
android:textColor="@color/drawer_header_font_color"
|
||||||
android:textStyle="bold"
|
android:textStyle="bold"
|
||||||
app:autoSizeMaxTextSize="@dimen/drawer_header_newpipe_title_max_text_size"
|
app:autoSizeMaxTextSize="@dimen/drawer_header_newpipe_title_max_text_size"
|
||||||
app:autoSizeMinTextSize="@dimen/drawer_header_newpipe_title_min_text_size"
|
app:autoSizeMinTextSize="@dimen/drawer_header_newpipe_title_min_text_size"
|
||||||
app:autoSizeTextType="uniform"
|
app:autoSizeTextType="uniform"
|
||||||
tools:ignore="UnusedAttribute" />
|
tools:ignore="UnusedAttribute"
|
||||||
|
tools:text="NewPipe" />
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
|
|
|
@ -5,8 +5,8 @@
|
||||||
<dimen name="drawer_header_padding_top">16dp</dimen>
|
<dimen name="drawer_header_padding_top">16dp</dimen>
|
||||||
<dimen name="drawer_header_newpipe_icon_size">48dp</dimen>
|
<dimen name="drawer_header_newpipe_icon_size">48dp</dimen>
|
||||||
<dimen name="drawer_header_newpipe_icon_title_space">12dp</dimen>
|
<dimen name="drawer_header_newpipe_icon_title_space">12dp</dimen>
|
||||||
<dimen name="drawer_header_newpipe_title_min_width">120dp</dimen>
|
<dimen name="drawer_header_newpipe_title_default_width">130dp</dimen>
|
||||||
<dimen name="drawer_header_newpipe_title_max_width">220dp</dimen>
|
<dimen name="drawer_header_newpipe_title_max_width">200dp</dimen>
|
||||||
<dimen name="drawer_header_newpipe_title_min_text_size">18sp</dimen>
|
<dimen name="drawer_header_newpipe_title_min_text_size">18sp</dimen>
|
||||||
<dimen name="drawer_header_newpipe_title_max_text_size">32sp</dimen>
|
<dimen name="drawer_header_newpipe_title_max_text_size">32sp</dimen>
|
||||||
<dimen name="drawer_header_service_icon_size">16dp</dimen>
|
<dimen name="drawer_header_service_icon_size">16dp</dimen>
|
||||||
|
|
Loading…
Reference in New Issue