1
0
Fork 0
mirror of https://github.com/M66B/FairEmail.git synced 2024-12-29 03:05:31 +00:00

Attempt to resolve spinner focus issue

This commit is contained in:
M66B 2024-07-24 20:46:12 +02:00
parent b352814b24
commit f0932039cc

View file

@ -21,12 +21,11 @@ package eu.faircode.email;
import android.content.Context; import android.content.Context;
import android.content.res.Resources; import android.content.res.Resources;
import android.graphics.Rect;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Spinner; import android.widget.Spinner;
import androidx.annotation.Nullable;
public class SpinnerEx extends Spinner { public class SpinnerEx extends Spinner {
public SpinnerEx(Context context) { public SpinnerEx(Context context) {
super(context); super(context);
@ -67,14 +66,23 @@ public class SpinnerEx extends Spinner {
this.setFocusableInTouchMode(true); this.setFocusableInTouchMode(true);
} }
@Override private final OnFocusChangeListener listener = new OnFocusChangeListener() {
protected void onFocusChanged(boolean gainFocus, int direction, @Nullable Rect previouslyFocusedRect) { @Override
try { public void onFocusChange(View v, boolean hasFocus) {
super.onFocusChanged(gainFocus, direction, previouslyFocusedRect); setOnFocusChangeListener(null);
if (gainFocus && getWindowToken() != null) performClick();
performClick();
} catch (Throwable ex) {
Log.e(ex);
} }
};
@Override
public boolean onTouchEvent(MotionEvent event) {
int action = event.getAction();
if (action == MotionEvent.ACTION_DOWN) {
if (!hasFocus())
setOnFocusChangeListener(listener);
} else if (action == MotionEvent.ACTION_CANCEL)
setOnFocusChangeListener(null);
return super.onTouchEvent(event);
} }
} }