From 04999718b2b37cc3bdcdfe12d2c71055f4563ab2 Mon Sep 17 00:00:00 2001 From: SerpentSpirale Date: Mon, 3 May 2021 19:59:26 +0200 Subject: [PATCH] Add a custom scrollView that have the ability to disable the auto-refocus. --- .../java/com/kdt/DefocusableScrollView.java | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 app_pojavlauncher/src/main/java/com/kdt/DefocusableScrollView.java diff --git a/app_pojavlauncher/src/main/java/com/kdt/DefocusableScrollView.java b/app_pojavlauncher/src/main/java/com/kdt/DefocusableScrollView.java new file mode 100644 index 000000000..9bbde79b4 --- /dev/null +++ b/app_pojavlauncher/src/main/java/com/kdt/DefocusableScrollView.java @@ -0,0 +1,50 @@ +package com.kdt; + +import android.content.Context; +import android.graphics.Rect; +import android.util.AttributeSet; +import android.widget.ScrollView; + +public class DefocusableScrollView extends ScrollView { + + /* + What is this class for ? + It allows to ignore the focusing from an item such an EditText. + Ignoring it will stop the scrollView from refocusing on the view + */ + + private boolean keepFocusing = false; + + + public DefocusableScrollView(Context context) { + super(context); + } + + public DefocusableScrollView(Context context, AttributeSet attrs) { + super(context, attrs); + } + + public DefocusableScrollView(Context context, AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + } + + public DefocusableScrollView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { + super(context, attrs, defStyleAttr, defStyleRes); + } + + public void setKeepFocusing(boolean shouldKeepFocusing){ + keepFocusing = shouldKeepFocusing; + } + + public boolean isKeepFocusing(){ + return keepFocusing; + } + + @Override + protected int computeScrollDeltaToGetChildRectOnScreen(Rect rect) { + if(!keepFocusing) return 0; + return super.computeScrollDeltaToGetChildRectOnScreen(rect); + } + + +}