1
0
Fork 0
mirror of https://github.com/M66B/FairEmail.git synced 2024-12-28 10:47:28 +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.res.Resources;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Spinner;
import androidx.annotation.Nullable;
public class SpinnerEx extends Spinner {
public SpinnerEx(Context context) {
super(context);
@ -67,14 +66,23 @@ public class SpinnerEx extends Spinner {
this.setFocusableInTouchMode(true);
}
@Override
protected void onFocusChanged(boolean gainFocus, int direction, @Nullable Rect previouslyFocusedRect) {
try {
super.onFocusChanged(gainFocus, direction, previouslyFocusedRect);
if (gainFocus && getWindowToken() != null)
performClick();
} catch (Throwable ex) {
Log.e(ex);
private final OnFocusChangeListener listener = new OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
setOnFocusChangeListener(null);
performClick();
}
};
@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);
}
}