From b6823dbc420e795e62722eed8dd028c6276cb11a Mon Sep 17 00:00:00 2001 From: Joel Date: Tue, 16 Mar 2021 22:02:11 +0100 Subject: [PATCH] dropdown revised --- app/build.gradle | 2 +- .../joel/zoomhelper/AutoSuggestAdapter.java | 73 +++++++++++++++++++ .../java/de/joel/zoomhelper/MainActivity.java | 34 ++++----- .../main/res/layout-land/activity_main.xml | 3 +- app/src/main/res/layout/mainform.xml | 19 +++-- 5 files changed, 102 insertions(+), 29 deletions(-) create mode 100644 app/src/main/java/de/joel/zoomhelper/AutoSuggestAdapter.java diff --git a/app/build.gradle b/app/build.gradle index 7059dd4..e26780d 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -11,7 +11,7 @@ android { minSdkVersion 21 targetSdkVersion 30 versionCode 1 - versionName '0.4' + versionName '0.4.3' testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } diff --git a/app/src/main/java/de/joel/zoomhelper/AutoSuggestAdapter.java b/app/src/main/java/de/joel/zoomhelper/AutoSuggestAdapter.java new file mode 100644 index 0000000..12f0939 --- /dev/null +++ b/app/src/main/java/de/joel/zoomhelper/AutoSuggestAdapter.java @@ -0,0 +1,73 @@ +package de.joel.zoomhelper; + +import android.content.Context; +import android.widget.ArrayAdapter; +import android.widget.Filter; +import android.widget.Filterable; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + +import java.util.ArrayList; +import java.util.List; + +public class AutoSuggestAdapter extends ArrayAdapter implements Filterable { + private List mlistData; + + public AutoSuggestAdapter(@NonNull Context context, int resource) { + super(context, resource); + mlistData = new ArrayList<>(); + } + + public void setData(List list) { + mlistData.clear(); + mlistData.addAll(list); + } + + @Override + public int getCount() { + return mlistData.size(); + } + + @Nullable + @Override + public String getItem(int position) { + return mlistData.get(position); + } + + /** + * Used to Return the full object directly from adapter. + * + * @param position + * @return + */ + public String getObject(int position) { + return mlistData.get(position); + } + + @NonNull + @Override + public Filter getFilter() { + Filter dataFilter = new Filter() { + @Override + protected FilterResults performFiltering(CharSequence constraint) { + FilterResults filterResults = new FilterResults(); + if (constraint != null) { + filterResults.values = mlistData; + filterResults.count = mlistData.size(); + } + return filterResults; + } + + @Override + protected void publishResults(CharSequence constraint, FilterResults results) { + if (results != null && (results.count > 0)) { + notifyDataSetChanged(); + } else { + notifyDataSetInvalidated(); + } + } + }; + return dataFilter; + } +} \ No newline at end of file diff --git a/app/src/main/java/de/joel/zoomhelper/MainActivity.java b/app/src/main/java/de/joel/zoomhelper/MainActivity.java index 02f047c..33b8379 100644 --- a/app/src/main/java/de/joel/zoomhelper/MainActivity.java +++ b/app/src/main/java/de/joel/zoomhelper/MainActivity.java @@ -27,6 +27,7 @@ import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.Serializable; import java.util.ArrayList; +import java.util.Arrays; import java.util.Objects; @@ -44,7 +45,7 @@ class InstantAutoComplete extends com.google.android.material.textfield.Material } @Override public boolean enoughToFilter() { - return true; + return false; } } @@ -146,9 +147,7 @@ public class MainActivity extends AppCompatActivity { } }); - builder.setNegativeButton(R.string.no, (dialog, which) -> { - dialog.dismiss(); - }); + builder.setNegativeButton(R.string.no, (dialog, which) -> dialog.dismiss()); AlertDialog alert = builder.create(); alert.show(); @@ -205,24 +204,22 @@ public class MainActivity extends AppCompatActivity { } AutoCompleteTextView textMeetingName = findViewById(R.id.TextMeetingName); - ImageView dropdown = findViewById(R.id.iconDropdownMeetingName); - ArrayAdapter adapter = new ArrayAdapter<>(this, android.R.layout.simple_dropdown_item_1line, meetingNames); + //ImageView dropdown = findViewById(R.id.iconDropdownMeetingName); + AutoSuggestAdapter adapter = new AutoSuggestAdapter(this, android.R.layout.simple_dropdown_item_1line); + adapter.setData(Arrays.asList(meetingNames)); textMeetingName.setAdapter(adapter); - textMeetingName.setOnTouchListener((View.OnTouchListener) (paramView, paramMotionEvent) -> { - adapter.getFilter().filter(null); - textMeetingName.showDropDown(); - return false; - }); + textMeetingName.setOnTouchListener((View.OnTouchListener) (paramView, paramMotionEvent) -> false); textMeetingName.setOnItemClickListener((arg0, view, arg2, arg3) -> fillWithSelectedMeeting()); - dropdown.setOnClickListener(v -> { + /*dropdown.setOnClickListener(v -> { textMeetingName.showDropDown(); adapter.getFilter().filter(null); - }); + });*/ } + @SuppressLint("ClickableViewAccessibility") public void fillDropdownAttendeeName(int meetingIndex) { Meeting meeting = getMeetings().get(meetingIndex); ArrayList attendees = meeting.attendees; @@ -233,16 +230,19 @@ public class MainActivity extends AppCompatActivity { } AutoCompleteTextView textName = findViewById(R.id.textBoxName); - ImageView dropdown = findViewById(R.id.iconDropdownAttName); - ArrayAdapter adapter = new ArrayAdapter<>(this, android.R.layout.simple_dropdown_item_1line, attNames); + //ImageView dropdown = findViewById(R.id.iconDropdownAttName); + AutoSuggestAdapter adapter = new AutoSuggestAdapter(this, android.R.layout.simple_dropdown_item_1line); + adapter.setData(Arrays.asList(attNames)); textName.setAdapter(adapter); + textName.setOnTouchListener((View.OnTouchListener) (paramView, paramMotionEvent) -> false); + textName.setOnItemClickListener((arg0, view, arg2, arg3) -> fillWithSelectedAtt()); - dropdown.setOnClickListener(v -> { + /*dropdown.setOnClickListener(v -> { textName.showDropDown(); adapter.getFilter().filter(null); - }); + });*/ } private void fillWithSelectedAtt() { diff --git a/app/src/main/res/layout-land/activity_main.xml b/app/src/main/res/layout-land/activity_main.xml index f003a33..880f2b1 100644 --- a/app/src/main/res/layout-land/activity_main.xml +++ b/app/src/main/res/layout-land/activity_main.xml @@ -6,7 +6,7 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginStart="30dp" - android:layout_marginTop="10dp" + android:layout_marginTop="0dp" android:layout_marginEnd="30dp" android:layout_marginBottom="10dp" android:orientation="vertical" @@ -20,6 +20,7 @@ android:layout_marginLeft="8dp" android:layout_marginEnd="8dp" android:layout_marginRight="8dp" + android:layout_marginBottom="15dp" android:layout_weight="1" android:fillViewport="true"> diff --git a/app/src/main/res/layout/mainform.xml b/app/src/main/res/layout/mainform.xml index 9f456e4..0c12d8c 100644 --- a/app/src/main/res/layout/mainform.xml +++ b/app/src/main/res/layout/mainform.xml @@ -17,7 +17,8 @@ app:boxBackgroundColor="@android:color/transparent" app:layout_constraintBottom_toTopOf="@+id/layoutName" app:layout_constraintStart_toStartOf="parent" - app:layout_constraintWidth_percent="0.9"> + app:layout_constraintWidth_percent="0.9" + app:endIconMode="dropdown_menu"> - + app:layout_constraintBottom_toBottomOf="@+id/layoutMeetingName"/>--> + app:layout_constraintWidth_percent="0.9" + app:endIconMode="dropdown_menu"> + android:nextFocusForward="@+id/editAtt" /> - + app:layout_constraintBottom_toBottomOf="@+id/layoutName"/>-->