[Android] Fix More screen button sizes
Nicolas Pomepuy
git at videolan.org
Thu May 14 15:04:09 CEST 2020
vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Wed May 13 13:39:24 2020 +0200| [a9ecb388ef898d3e25f9d06793a9bcb4c3ca9372] | committer: Nicolas Pomepuy
Fix More screen button sizes
> https://code.videolan.org/videolan/vlc-android/commit/a9ecb388ef898d3e25f9d06793a9bcb4c3ca9372
---
.../vlc-android/res/layout/more_fragment.xml | 18 ++++--
.../src/org/videolan/vlc/gui/view/AutofitButton.kt | 65 ++++++++++++++++++++++
2 files changed, 78 insertions(+), 5 deletions(-)
diff --git a/application/vlc-android/res/layout/more_fragment.xml b/application/vlc-android/res/layout/more_fragment.xml
index 58a401bfc..7fd439bd6 100644
--- a/application/vlc-android/res/layout/more_fragment.xml
+++ b/application/vlc-android/res/layout/more_fragment.xml
@@ -42,7 +42,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent">
- <Button
+ <org.videolan.vlc.gui.view.AutofitButton
android:id="@+id/settingsButton"
style="@style/Widget.MaterialComponents.Button.OutlinedButton.Icon"
android:layout_width="0dp"
@@ -50,15 +50,19 @@
android:layout_marginStart="16dp"
android:layout_marginTop="24dp"
android:layout_marginEnd="8dp"
+ android:ellipsize="middle"
+ android:singleLine="true"
android:text="@string/preferences"
+ app:iconSize="24dp"
app:icon="@drawable/ic_more_preferences"
app:layout_constraintEnd_toStartOf="@+id/aboutButton"
app:layout_constraintHorizontal_bias="0.5"
- app:layout_constraintHorizontal_chainStyle="spread"
+ app:layout_constraintHorizontal_chainStyle="packed"
app:layout_constraintStart_toStartOf="parent"
- app:layout_constraintTop_toTopOf="parent" />
+ app:layout_constraintTop_toTopOf="parent"
+ app:layout_constraintWidth_max="200dp" />
- <Button
+ <org.videolan.vlc.gui.view.AutofitButton
android:id="@+id/aboutButton"
style="@style/Widget.MaterialComponents.Button.OutlinedButton.Icon"
android:layout_width="0dp"
@@ -66,12 +70,16 @@
android:layout_marginStart="8dp"
android:layout_marginTop="24dp"
android:layout_marginEnd="16dp"
+ android:ellipsize="middle"
+ android:singleLine="true"
+ app:iconSize="24dp"
android:text="@string/about"
app:icon="@drawable/ic_more_about"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="@+id/settingsButton"
- app:layout_constraintTop_toTopOf="parent" />
+ app:layout_constraintTop_toTopOf="parent"
+ app:layout_constraintWidth_max="200dp" />
<org.videolan.vlc.gui.view.TitleListView
android:id="@+id/streams_entry"
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/view/AutofitButton.kt b/application/vlc-android/src/org/videolan/vlc/gui/view/AutofitButton.kt
new file mode 100644
index 000000000..5a1842137
--- /dev/null
+++ b/application/vlc-android/src/org/videolan/vlc/gui/view/AutofitButton.kt
@@ -0,0 +1,65 @@
+/*
+ * ************************************************************************
+ * AutofitButton.kt
+ * *************************************************************************
+ * Copyright © 2020 VLC authors and VideoLAN
+ * Author: Nicolas POMEPUY
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ * **************************************************************************
+ *
+ *
+ */
+
+package org.videolan.vlc.gui.view
+
+import android.content.Context
+import android.graphics.Canvas
+import android.util.AttributeSet
+import android.util.TypedValue
+import com.google.android.material.button.MaterialButton
+
+class AutofitButton : MaterialButton {
+
+ var size = 14
+
+ constructor(context: Context) : super(context)
+
+ constructor(context: Context, attrs: AttributeSet) : super(context, attrs)
+
+ constructor(context: Context, attrs: AttributeSet, defStyle: Int) : super(context, attrs, defStyle)
+
+ override fun setText(text: CharSequence?, type: BufferType?) {
+ if (width != 0) computeTextSize()
+
+ super.setText(text, type)
+ }
+
+ override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) {
+ computeTextSize()
+ super.onSizeChanged(w, h, oldw, oldh)
+ }
+
+ override fun onDraw(canvas: Canvas?) {
+ super.onDraw(canvas)
+ computeTextSize()
+ }
+
+ private fun computeTextSize() {
+ if (layout.getEllipsisCount(maxLines) > 0 && size > 10) {
+ size--
+ setTextSize(TypedValue.COMPLEX_UNIT_DIP, size.toFloat())
+ }
+ }
+}
\ No newline at end of file
More information about the Android
mailing list