Commit 82720300 authored by Bartek Fabiszewski's avatar Bartek Fabiszewski
Browse files

Exclude system gestures for swipe switch area

parent c7e02c08
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -42,6 +42,7 @@
        android:supportsRtl="true"
        android:theme="@style/AppTheme"
        tools:ignore="UnusedAttribute"
        android:enableOnBackInvokedCallback="true"
        android:dataExtractionRules="@xml/data_extraction_rules">
        <activity
            android:name=".MainActivity"
+27 −0
Original line number Diff line number Diff line
@@ -11,13 +11,23 @@ package net.fabiszewski.ulogger;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Rect;
import android.os.Build;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;

import androidx.annotation.RequiresApi;
import androidx.appcompat.widget.SwitchCompat;

import java.util.Collections;

public class SwipeSwitch extends SwitchCompat {

    private final String TAG = SwipeSwitch.class.getSimpleName();
    private final Rect exclusionRect = new Rect();


    public SwipeSwitch(Context context) {
        super(context);
    }
@@ -47,4 +57,21 @@ public class SwipeSwitch extends SwitchCompat {
        }
        return ret;
    }

    @Override
    protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
        super.onLayout(changed, left, top, right, bottom);
        if (Build.VERSION.SDK_INT >= 29) {
            setGestureExclusionRects();
        }

    }

    @RequiresApi(api = Build.VERSION_CODES.Q)
    private void setGestureExclusionRects() {
        exclusionRect.set(0, 0, getWidth(), getHeight());
        if (Logger.DEBUG) { Log.d(TAG, "[setGestureExclusionRects: " + exclusionRect + "]"); }
        setSystemGestureExclusionRects(Collections.singletonList(exclusionRect));
    }

}
+0 −1
Original line number Diff line number Diff line
@@ -78,7 +78,6 @@
            android:id="@+id/switchLogger"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginEnd="30dp"
            android:checked="false"
            android:paddingTop="30dp"
            android:paddingBottom="20dp"