[Android] Restore adv options size setting

Geoffrey Métais git at videolan.org
Tue Sep 26 16:35:39 CEST 2017


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Tue Sep 26 14:00:23 2017 +0200| [1c8ffaed5fcfa8bbb8396e5f2ca92cdf8369268f] | committer: Geoffrey Métais

Restore adv options size setting

It's broken on Oreo otherwise

> https://code.videolan.org/videolan/vlc-android/commit/1c8ffaed5fcfa8bbb8396e5f2ca92cdf8369268f
---

 vlc-android/res/layout/adv_option_item.xml          |  2 +-
 .../res/layout/fragment_advanced_options.xml        |  7 ++++---
 .../videolan/vlc/gui/dialogs/AdvOptionsDialog.java  | 21 +++++++++++++++++++--
 3 files changed, 24 insertions(+), 6 deletions(-)

diff --git a/vlc-android/res/layout/adv_option_item.xml b/vlc-android/res/layout/adv_option_item.xml
index f1b688ebf..699c96357 100644
--- a/vlc-android/res/layout/adv_option_item.xml
+++ b/vlc-android/res/layout/adv_option_item.xml
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="utf-8"?>
 <TextView xmlns:android="http://schemas.android.com/apk/res/android"
-    android:layout_width="match_parent"
+    android:layout_width="@dimen/option_width"
     android:layout_height="@dimen/option_height"
     android:clickable="true"
     android:longClickable="true"
diff --git a/vlc-android/res/layout/fragment_advanced_options.xml b/vlc-android/res/layout/fragment_advanced_options.xml
index 8ebbd0fd1..07c158ccc 100644
--- a/vlc-android/res/layout/fragment_advanced_options.xml
+++ b/vlc-android/res/layout/fragment_advanced_options.xml
@@ -1,6 +1,7 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<org.videolan.vlc.gui.view.AutoFitRecyclerView xmlns:android="http://schemas.android.com/apk/res/android"
-    android:layout_width="match_parent"
-    android:layout_height="match_parent"
+<org.videolan.vlc.gui.view.AutoFitRecyclerView
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="wrap_content"
+    android:layout_height="wrap_content"
     android:padding="@dimen/adv_options_margin"
     android:background="?attr/rounded_bg"/>
diff --git a/vlc-android/src/org/videolan/vlc/gui/dialogs/AdvOptionsDialog.java b/vlc-android/src/org/videolan/vlc/gui/dialogs/AdvOptionsDialog.java
index 91a0805bb..a55ea2484 100644
--- a/vlc-android/src/org/videolan/vlc/gui/dialogs/AdvOptionsDialog.java
+++ b/vlc-android/src/org/videolan/vlc/gui/dialogs/AdvOptionsDialog.java
@@ -25,6 +25,7 @@ package org.videolan.vlc.gui.dialogs;
 import android.annotation.TargetApi;
 import android.app.Activity;
 import android.app.AlarmManager;
+import android.app.Dialog;
 import android.app.PendingIntent;
 import android.content.Context;
 import android.content.DialogInterface;
@@ -70,7 +71,7 @@ public class AdvOptionsDialog extends DialogFragment implements View.OnClickList
     public static final int MODE_VIDEO = 0;
     public static final int MODE_AUDIO = 1;
 
-    private static final int SPAN_COUNT = 3;
+    private static final int SPAN_COUNT = 4;
 
     public static final int ACTION_AUDIO_DELAY = 2 ;
     public static final int ACTION_SPU_DELAY = 3 ;
@@ -504,6 +505,7 @@ public class AdvOptionsDialog extends DialogFragment implements View.OnClickList
         mAdapter.clear();
         mService = service;
         boolean tvUi = VLCApplication.showTvUi();
+        int large_items = 0;
 
         mAdapter.addOption(new Option(ID_SLEEP, R.attr.ic_sleep_normal_style, getString(R.string.sleep_title)));
         mAdapter.addOption(new Option(ID_PLAYBACK_SPEED, R.attr.ic_speed_normal_style, getString(R.string.playback_speed)));
@@ -523,11 +525,14 @@ public class AdvOptionsDialog extends DialogFragment implements View.OnClickList
 
             final MediaPlayer.Chapter[] chapters = mService.getChapters(-1);
             final int chaptersCount = chapters != null ? chapters.length : 0;
-            if (chaptersCount > 1)
+            if (chaptersCount > 1) {
                 mAdapter.addOption(new Option(ID_CHAPTER_TITLE, R.attr.ic_chapter_normal_style, getString(R.string.go_to_chapter)));
+                ++large_items;
+            }
         } else {
             mAdapter.addOption(new Option(ID_SAVE_PLAYLIST, R.attr.ic_save, getString(R.string.playlist_save)));
         }
+        setDialogDimensions(large_items);
     }
 
     @Override
@@ -574,6 +579,18 @@ public class AdvOptionsDialog extends DialogFragment implements View.OnClickList
         return false;
     }
 
+    private void setDialogDimensions(int offset) {
+    final Dialog dialog = getDialog();
+    if (dialog == null)
+        return;
+    final int dialogWidth = getResources().getDimensionPixelSize(R.dimen.option_width) * SPAN_COUNT + mRecyclerView.getPaddingLeft()+ mRecyclerView.getRight();
+    final int count = mAdapter.getItemCount()-offset;
+    final int rows = offset + (count + SPAN_COUNT-1) / SPAN_COUNT;
+    final int dialogHeight = getResources().getDimensionPixelSize(R.dimen.option_height) * rows + mRecyclerView.getPaddingBottom()+ mRecyclerView.getPaddingTop();
+
+    dialog.getWindow().setLayout(dialogWidth, dialogHeight);
+}
+
     private class AdvOptionsAdapter extends RecyclerView.Adapter<AdvOptionsAdapter.ViewHolder> {
 
         private final ArrayList<Option> mList = new ArrayList<>();



More information about the Android mailing list