mirror of
https://github.com/M66B/FairEmail.git
synced 2024-12-29 19:25:34 +00:00
Attempt to resolve spinner focus issue
This commit is contained in:
parent
b352814b24
commit
f0932039cc
1 changed files with 19 additions and 11 deletions
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private final OnFocusChangeListener listener = new OnFocusChangeListener() {
|
||||||
@Override
|
@Override
|
||||||
protected void onFocusChanged(boolean gainFocus, int direction, @Nullable Rect previouslyFocusedRect) {
|
public void onFocusChange(View v, boolean hasFocus) {
|
||||||
try {
|
setOnFocusChangeListener(null);
|
||||||
super.onFocusChanged(gainFocus, direction, previouslyFocusedRect);
|
|
||||||
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue