From 5799a99feb8b750c4ff9018263d275561e4ffc8f Mon Sep 17 00:00:00 2001 From: M66B Date: Tue, 9 Jul 2024 20:15:46 +0200 Subject: [PATCH] Focusable spinner --- .../java/eu/faircode/email/FragmentRule.java | 9 --- .../java/eu/faircode/email/SpinnerEx.java | 76 +++++++++++++++++++ app/src/main/res/layout/activity_widget.xml | 6 +- .../res/layout/activity_widget_unified.xml | 10 +-- app/src/main/res/layout/dialog_add_image.xml | 2 +- .../main/res/layout/dialog_answer_button.xml | 4 +- .../main/res/layout/dialog_contact_group.xml | 6 +- app/src/main/res/layout/dialog_debug.xml | 2 +- .../main/res/layout/dialog_edit_contact.xml | 2 +- app/src/main/res/layout/dialog_folder_add.xml | 2 +- app/src/main/res/layout/dialog_identity.xml | 2 +- app/src/main/res/layout/dialog_open_link.xml | 2 +- app/src/main/res/layout/dialog_search.xml | 2 +- app/src/main/res/layout/dialog_send.xml | 6 +- app/src/main/res/layout/dialog_swipes.xml | 4 +- app/src/main/res/layout/dialog_translate.xml | 2 +- app/src/main/res/layout/fragment_account.xml | 18 ++--- app/src/main/res/layout/fragment_compose.xml | 2 +- app/src/main/res/layout/fragment_identity.xml | 8 +- .../res/layout/fragment_options_behavior.xml | 6 +- .../layout/fragment_options_connection.xml | 2 +- .../res/layout/fragment_options_display.xml | 20 ++--- .../layout/fragment_options_encryption.xml | 6 +- .../main/res/layout/fragment_options_misc.xml | 2 +- .../res/layout/fragment_options_privacy.xml | 2 +- .../main/res/layout/fragment_options_send.xml | 12 +-- .../layout/fragment_options_synchronize.xml | 2 +- app/src/main/res/layout/fragment_pop.xml | 4 +- app/src/main/res/layout/fragment_rule.xml | 14 ++-- 29 files changed, 151 insertions(+), 84 deletions(-) create mode 100644 app/src/main/java/eu/faircode/email/SpinnerEx.java diff --git a/app/src/main/java/eu/faircode/email/FragmentRule.java b/app/src/main/java/eu/faircode/email/FragmentRule.java index 9bd97e7764..ad9a884fd2 100644 --- a/app/src/main/java/eu/faircode/email/FragmentRule.java +++ b/app/src/main/java/eu/faircode/email/FragmentRule.java @@ -533,15 +533,6 @@ public class FragmentRule extends FragmentBase { adapterAction.setDropDownViewResource(R.layout.spinner_item1_dropdown); spAction.setAdapter(adapterAction); - spAction.setFocusableInTouchMode(true); - spAction.setOnFocusChangeListener(new View.OnFocusChangeListener() { - @Override - public void onFocusChange(View v, boolean hasFocus) { - if (hasFocus && spAction.getWindowToken() != null) - spAction.performClick(); - } - }); - btnFolder.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { diff --git a/app/src/main/java/eu/faircode/email/SpinnerEx.java b/app/src/main/java/eu/faircode/email/SpinnerEx.java new file mode 100644 index 0000000000..c240935cf4 --- /dev/null +++ b/app/src/main/java/eu/faircode/email/SpinnerEx.java @@ -0,0 +1,76 @@ +package eu.faircode.email; + +/* + This file is part of FairEmail. + + FairEmail is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + FairEmail is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with FairEmail. If not, see . + + Copyright 2018-2024 by Marcel Bokhorst (M66B) +*/ + +import android.content.Context; +import android.content.res.Resources; +import android.graphics.Rect; +import android.util.AttributeSet; +import android.widget.Spinner; + +import androidx.annotation.Nullable; + +public class SpinnerEx extends Spinner { + public SpinnerEx(Context context) { + super(context); + init(context); + } + + public SpinnerEx(Context context, int mode) { + super(context, mode); + init(context); + } + + public SpinnerEx(Context context, AttributeSet attrs) { + super(context, attrs); + init(context); + } + + public SpinnerEx(Context context, AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + init(context); + } + + public SpinnerEx(Context context, AttributeSet attrs, int defStyleAttr, int mode) { + super(context, attrs, defStyleAttr, mode); + init(context); + } + + public SpinnerEx(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes, int mode) { + super(context, attrs, defStyleAttr, defStyleRes, mode); + init(context); + } + + public SpinnerEx(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes, int mode, Resources.Theme popupTheme) { + super(context, attrs, defStyleAttr, defStyleRes, mode, popupTheme); + init(context); + } + + private void init(Context context) { + this.setFocusableInTouchMode(true); + } + + @Override + protected void onFocusChanged(boolean gainFocus, int direction, @Nullable Rect previouslyFocusedRect) { + super.onFocusChanged(gainFocus, direction, previouslyFocusedRect); + if (gainFocus && getWindowToken() != null) + performClick(); + } +} diff --git a/app/src/main/res/layout/activity_widget.xml b/app/src/main/res/layout/activity_widget.xml index 5f846febe0..95b3da81ed 100644 --- a/app/src/main/res/layout/activity_widget.xml +++ b/app/src/main/res/layout/activity_widget.xml @@ -22,7 +22,7 @@ app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" /> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -