[Android] Avoid focus issue on BottomeSheet
Nicolas Pomepuy
git at videolan.org
Thu Apr 11 10:12:43 CEST 2019
vlc-android | branch: master | Nicolas Pomepuy <nicolas.pomepuy at gmail.com> | Wed Apr 3 10:24:56 2019 +0200| [960f6398807c535532e636744f0f409f4593c2f9] | committer: Geoffrey Métais
Avoid focus issue on BottomeSheet
> https://code.videolan.org/videolan/vlc-android/commit/960f6398807c535532e636744f0f409f4593c2f9
---
vlc-android/res/layout/dialog_select_chapter.xml | 3 +++
vlc-android/res/layout/dialog_time_picker.xml | 1 +
.../src/org/videolan/vlc/gui/dialogs/ContextSheet.kt | 5 ++++-
.../videolan/vlc/gui/dialogs/PickTimeFragment.java | 7 +++++++
.../videolan/vlc/gui/dialogs/PlaybackSpeedDialog.java | 7 +++++++
.../videolan/vlc/gui/dialogs/SavePlaylistDialog.kt | 2 ++
.../videolan/vlc/gui/dialogs/SelectChapterDialog.kt | 3 +++
.../vlc/gui/dialogs/VLCBottomSheetDialogFragment.kt | 19 +++++++++++++++++++
8 files changed, 46 insertions(+), 1 deletion(-)
diff --git a/vlc-android/res/layout/dialog_select_chapter.xml b/vlc-android/res/layout/dialog_select_chapter.xml
index eaf915779..84c16928b 100644
--- a/vlc-android/res/layout/dialog_select_chapter.xml
+++ b/vlc-android/res/layout/dialog_select_chapter.xml
@@ -32,6 +32,9 @@
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:choiceMode="singleChoice"
+ android:focusableInTouchMode="true"
+ android:focusable="true"
+ android:descendantFocusability="afterDescendants"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
diff --git a/vlc-android/res/layout/dialog_time_picker.xml b/vlc-android/res/layout/dialog_time_picker.xml
index 1067b4976..3df46579f 100644
--- a/vlc-android/res/layout/dialog_time_picker.xml
+++ b/vlc-android/res/layout/dialog_time_picker.xml
@@ -71,6 +71,7 @@
android:layout_weight="1"
android:clickable="true"
android:focusable="true"
+ android:focusableInTouchMode="true"
android:gravity="center"
android:text="1"
android:textSize="18sp"
diff --git a/vlc-android/src/org/videolan/vlc/gui/dialogs/ContextSheet.kt b/vlc-android/src/org/videolan/vlc/gui/dialogs/ContextSheet.kt
index 67233ff6a..51e4a3a48 100644
--- a/vlc-android/src/org/videolan/vlc/gui/dialogs/ContextSheet.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/dialogs/ContextSheet.kt
@@ -47,6 +47,9 @@ class ContextSheet : VLCBottomSheetDialogFragment() {
private lateinit var options : List<CtxOption>
lateinit var receiver : CtxActionReceiver
private var itemPosition = -1
+ private lateinit var list: RecyclerView
+
+ override fun initialFocusedView(): View = list
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
@@ -74,7 +77,7 @@ class ContextSheet : VLCBottomSheetDialogFragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
view.findViewById<TextView>(R.id.ctx_title).text = arguments?.getString(CTX_TITLE_KEY) ?: ""
- val list = view.findViewById<RecyclerView>(R.id.ctx_list)
+ list = view.findViewById<RecyclerView>(R.id.ctx_list)
list.layoutManager = LinearLayoutManager(requireContext())
list.adapter = ContextAdapter()
val flags = arguments?.getInt(CTX_FLAGS_KEY) ?: 0
diff --git a/vlc-android/src/org/videolan/vlc/gui/dialogs/PickTimeFragment.java b/vlc-android/src/org/videolan/vlc/gui/dialogs/PickTimeFragment.java
index 2c36e55d4..a9792c41f 100644
--- a/vlc-android/src/org/videolan/vlc/gui/dialogs/PickTimeFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/dialogs/PickTimeFragment.java
@@ -28,6 +28,7 @@ import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
+import org.jetbrains.annotations.NotNull;
import org.videolan.vlc.PlaybackService;
import org.videolan.vlc.R;
import org.videolan.vlc.gui.helpers.BottomSheetBehavior;
@@ -112,6 +113,12 @@ public abstract class PickTimeFragment extends VLCBottomSheetDialogFragment impl
return view;
}
+ @NotNull
+ @Override
+ public View initialFocusedView() {
+ return getView().findViewById(R.id.tim_pic_1);
+ }
+
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
PlaybackService.Companion.getService().observe(this, this);
diff --git a/vlc-android/src/org/videolan/vlc/gui/dialogs/PlaybackSpeedDialog.java b/vlc-android/src/org/videolan/vlc/gui/dialogs/PlaybackSpeedDialog.java
index f5898a696..72055b39f 100644
--- a/vlc-android/src/org/videolan/vlc/gui/dialogs/PlaybackSpeedDialog.java
+++ b/vlc-android/src/org/videolan/vlc/gui/dialogs/PlaybackSpeedDialog.java
@@ -29,6 +29,7 @@ import android.widget.ImageView;
import android.widget.SeekBar;
import android.widget.TextView;
+import org.jetbrains.annotations.NotNull;
import org.videolan.vlc.PlaybackService;
import org.videolan.vlc.R;
import org.videolan.vlc.gui.helpers.BottomSheetBehavior;
@@ -53,6 +54,12 @@ public class PlaybackSpeedDialog extends VLCBottomSheetDialogFragment implements
return new PlaybackSpeedDialog();
}
+ @NotNull
+ @Override
+ public View initialFocusedView() {
+ return mSeekSpeed;
+ }
+
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
diff --git a/vlc-android/src/org/videolan/vlc/gui/dialogs/SavePlaylistDialog.kt b/vlc-android/src/org/videolan/vlc/gui/dialogs/SavePlaylistDialog.kt
index 6450f4510..038eeb794 100644
--- a/vlc-android/src/org/videolan/vlc/gui/dialogs/SavePlaylistDialog.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/dialogs/SavePlaylistDialog.kt
@@ -62,6 +62,8 @@ class SavePlaylistDialog : VLCBottomSheetDialogFragment(), View.OnClickListener,
private lateinit var mMedialibrary: Medialibrary
private var mPlaylistId: Long = 0
+ override fun initialFocusedView(): View = mListView
+
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
mMedialibrary = VLCApplication.getMLInstance()
diff --git a/vlc-android/src/org/videolan/vlc/gui/dialogs/SelectChapterDialog.kt b/vlc-android/src/org/videolan/vlc/gui/dialogs/SelectChapterDialog.kt
index c44d06e1a..a63cb7718 100644
--- a/vlc-android/src/org/videolan/vlc/gui/dialogs/SelectChapterDialog.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/dialogs/SelectChapterDialog.kt
@@ -54,6 +54,8 @@ class SelectChapterDialog : VLCBottomSheetDialogFragment(), Observer<PlaybackSer
private var service: PlaybackService? = null
+ override fun initialFocusedView(): View = chapterList
+
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?): View? {
val view = inflater.inflate(R.layout.dialog_select_chapter, container)
@@ -63,6 +65,7 @@ class SelectChapterDialog : VLCBottomSheetDialogFragment(), Observer<PlaybackSer
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
+ super.onViewCreated(view, savedInstanceState)
PlaybackService.service.observe(this, this)
}
diff --git a/vlc-android/src/org/videolan/vlc/gui/dialogs/VLCBottomSheetDialogFragment.kt b/vlc-android/src/org/videolan/vlc/gui/dialogs/VLCBottomSheetDialogFragment.kt
index c03ff9c40..a813c665d 100644
--- a/vlc-android/src/org/videolan/vlc/gui/dialogs/VLCBottomSheetDialogFragment.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/dialogs/VLCBottomSheetDialogFragment.kt
@@ -25,12 +25,24 @@ abstract class VLCBottomSheetDialogFragment : BottomSheetDialogFragment() {
val bsb = BottomSheetBehavior.from(it)
if (bsb.state == BottomSheetBehavior.STATE_COLLAPSED) bsb.state = getDefaultState()
}
+ dialog?.findViewById<View>(R.id.touch_outside)?.isFocusable = false
+ dialog?.findViewById<View>(R.id.touch_outside)?.isFocusableInTouchMode = false
}
}
+ override fun onResume() {
+ super.onResume()
+
+ initialFocusedView().isFocusable = true
+ initialFocusedView().isFocusableInTouchMode = true
+
+ initialFocusedView().requestFocus()
+ }
+
+
override fun onConfigurationChanged(newConfig: Configuration?) {
if (!needToManageOrientation()) {
super.onConfigurationChanged(newConfig)
@@ -57,6 +69,13 @@ abstract class VLCBottomSheetDialogFragment : BottomSheetDialogFragment() {
*/
abstract fun needToManageOrientation(): Boolean
+ /**
+ * The initial view to be focused to avoid BottomSheetDialogFragment to steal it
+ * Both fields [isFocusable] and [isFocusableInTouchMode] will be set to true
+ */
+ abstract fun initialFocusedView(): View
+
+
}
\ No newline at end of file
More information about the Android
mailing list