-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Appyown
committed
Sep 23, 2019
1 parent
63882bd
commit fe6d1ec
Showing
20 changed files
with
1,531 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
134 changes: 134 additions & 0 deletions
134
app/src/main/java/com/dvinfosys/WidgetsExample/Adapter/SimpleListAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
package com.dvinfosys.WidgetsExample.Adapter; | ||
|
||
import android.content.Context; | ||
import android.text.TextUtils; | ||
import android.util.Log; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import android.widget.BaseAdapter; | ||
import android.widget.Filter; | ||
import android.widget.Filterable; | ||
import android.widget.ImageView; | ||
import android.widget.TextView; | ||
|
||
import com.dvinfosys.WidgetsExample.R; | ||
import com.dvinfosys.widgets.SearchableSpinner.interfaces.ISpinnerSelectedView; | ||
|
||
import java.util.ArrayList; | ||
|
||
public class SimpleListAdapter extends BaseAdapter implements Filterable, ISpinnerSelectedView { | ||
|
||
private Context mContext; | ||
private ArrayList<String> mBackupStrings; | ||
private ArrayList<String> mStrings; | ||
private StringFilter mStringFilter = new StringFilter(); | ||
|
||
public SimpleListAdapter(Context context, ArrayList<String> strings) { | ||
mContext = context; | ||
mStrings = strings; | ||
mBackupStrings = strings; | ||
} | ||
|
||
@Override | ||
public int getCount() { | ||
return mStrings == null ? 0 : mStrings.size() + 1; | ||
} | ||
|
||
@Override | ||
public Object getItem(int position) { | ||
if (mStrings != null && position > 0) | ||
return mStrings.get(position - 1); | ||
else | ||
return null; | ||
} | ||
|
||
@Override | ||
public long getItemId(int position) { | ||
if (mStrings == null && position > 0) | ||
return mStrings.get(position).hashCode(); | ||
else | ||
return -1; | ||
} | ||
|
||
@Override | ||
public View getView(int position, View convertView, ViewGroup parent) { | ||
View view = null; | ||
if (position == 0) { | ||
view = getNoSelectionView(); | ||
} else { | ||
view = View.inflate(mContext, R.layout.view_list_item, null); | ||
TextView letters = view.findViewById(R.id.ImgVw_Letters); | ||
TextView dispalyName = view.findViewById(R.id.TxtVw_DisplayName); | ||
String FirstChar = mStrings.get(position - 1); | ||
String getFir = String.valueOf(FirstChar.charAt(0)); | ||
letters.setText(getFir + ""); | ||
dispalyName.setText(mStrings.get(position - 1)); | ||
} | ||
return view; | ||
} | ||
|
||
@Override | ||
public View getSelectedView(int position) { | ||
View view = null; | ||
if (position == 0) { | ||
view = getNoSelectionView(); | ||
} else { | ||
view = View.inflate(mContext, R.layout.view_list_item, null); | ||
TextView letters = view.findViewById(R.id.ImgVw_Letters); | ||
TextView dispalyName = view.findViewById(R.id.TxtVw_DisplayName); | ||
String FirstChar = mStrings.get(position - 1); | ||
String getFir = String.valueOf(FirstChar.charAt(0)); | ||
letters.setText(getFir + ""); | ||
dispalyName.setText(mStrings.get(position - 1)); | ||
} | ||
return view; | ||
} | ||
|
||
@Override | ||
public View getNoSelectionView() { | ||
View view = View.inflate(mContext, R.layout.view_list_no_selection_item, null); | ||
return view; | ||
} | ||
|
||
@Override | ||
public Filter getFilter() { | ||
return mStringFilter; | ||
} | ||
|
||
public class StringFilter extends Filter { | ||
|
||
@Override | ||
protected FilterResults performFiltering(CharSequence constraint) { | ||
final FilterResults filterResults = new FilterResults(); | ||
if (TextUtils.isEmpty(constraint)) { | ||
filterResults.count = mBackupStrings.size(); | ||
filterResults.values = mBackupStrings; | ||
return filterResults; | ||
} | ||
final ArrayList<String> filterStrings = new ArrayList<>(); | ||
for (String text : mBackupStrings) { | ||
if (text.toLowerCase().contains(constraint)) { | ||
filterStrings.add(text); | ||
} | ||
} | ||
filterResults.count = filterStrings.size(); | ||
filterResults.values = filterStrings; | ||
return filterResults; | ||
} | ||
|
||
@Override | ||
protected void publishResults(CharSequence constraint, FilterResults results) { | ||
mStrings = (ArrayList) results.values; | ||
notifyDataSetChanged(); | ||
} | ||
} | ||
|
||
private class ItemView { | ||
public ImageView mImageView; | ||
public TextView mTextView; | ||
} | ||
|
||
public enum ItemViewType { | ||
ITEM, NO_SELECTION_ITEM | ||
} | ||
} |
118 changes: 118 additions & 0 deletions
118
app/src/main/java/com/dvinfosys/WidgetsExample/Fragments/SearchableSpinnerFragment.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
package com.dvinfosys.WidgetsExample.Fragments; | ||
|
||
import android.os.Bundle; | ||
import android.support.annotation.Nullable; | ||
import android.support.v4.app.Fragment; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import android.widget.Toast; | ||
|
||
import com.dvinfosys.WidgetsExample.Adapter.SimpleListAdapter; | ||
import com.dvinfosys.WidgetsExample.R; | ||
import com.dvinfosys.widgets.SearchableSpinner.SearchableSpinner; | ||
import com.dvinfosys.widgets.SearchableSpinner.interfaces.IStatusListener; | ||
import com.dvinfosys.widgets.SearchableSpinner.interfaces.OnItemSelectedListener; | ||
|
||
import java.util.ArrayList; | ||
|
||
public class SearchableSpinnerFragment extends Fragment { | ||
|
||
private SearchableSpinner mSearchableSpinner; | ||
private ArrayList<String> mStrings = new ArrayList<>(); | ||
private SimpleListAdapter mSimpleListAdapter; | ||
|
||
@Override | ||
public void onCreate(@Nullable Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
initListValues(); | ||
} | ||
|
||
@Override | ||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { | ||
View v = inflater.inflate(R.layout.fragment_searchable_spinner, container, false); | ||
mSimpleListAdapter = new SimpleListAdapter(getContext(), mStrings); | ||
mSearchableSpinner = v.findViewById(R.id.SearchableSpinner); | ||
mSearchableSpinner.setAdapter(mSimpleListAdapter); | ||
mSearchableSpinner.setOnItemSelectedListener(new OnItemSelectedListener() { | ||
@Override | ||
public void onItemSelected(View view, int position, long id) { | ||
Toast.makeText(getContext(), "Item on position " + position + " : " + mSimpleListAdapter.getItem(position) + " Selected", Toast.LENGTH_SHORT).show(); | ||
} | ||
|
||
@Override | ||
public void onNothingSelected() { | ||
Toast.makeText(getContext(), "Nothing Selected", Toast.LENGTH_SHORT).show(); | ||
} | ||
}); | ||
mSearchableSpinner.setStatusListener(new IStatusListener() { | ||
@Override | ||
public void spinnerIsOpening() { | ||
/*mSearchableSpinner1.hideEdit(); | ||
mSearchableSpinner2.hideEdit();*/ | ||
} | ||
|
||
@Override | ||
public void spinnerIsClosing() { | ||
|
||
} | ||
}); | ||
|
||
return v; | ||
} | ||
|
||
private void initListValues() { | ||
mStrings = new ArrayList<>(); | ||
mStrings.add("Brigida Kurz"); | ||
mStrings.add("Tracy Mckim"); | ||
mStrings.add("Iesha Davids"); | ||
mStrings.add("Ozella Provenza"); | ||
mStrings.add("Florentina Carriere"); | ||
mStrings.add("Geri Eiler"); | ||
mStrings.add("Tammara Belgrave"); | ||
mStrings.add("Ashton Ridinger"); | ||
mStrings.add("Jodee Dawkins"); | ||
mStrings.add("Florine Cruzan"); | ||
mStrings.add("Latia Stead"); | ||
mStrings.add("Kai Urbain"); | ||
mStrings.add("Liza Chi"); | ||
mStrings.add("Clayton Laprade"); | ||
mStrings.add("Wilfredo Mooney"); | ||
mStrings.add("Roseline Cain"); | ||
mStrings.add("Chadwick Gauna"); | ||
mStrings.add("Carmela Bourn"); | ||
mStrings.add("Valeri Dedios"); | ||
mStrings.add("Calista Mcneese"); | ||
mStrings.add("Willard Cuccia"); | ||
mStrings.add("Ngan Blakey"); | ||
mStrings.add("Reina Medlen"); | ||
mStrings.add("Fabian Steenbergen"); | ||
mStrings.add("Edmond Pine"); | ||
mStrings.add("Teri Quesada"); | ||
mStrings.add("Vernetta Fulgham"); | ||
mStrings.add("Winnifred Kiefer"); | ||
mStrings.add("Chiquita Lichty"); | ||
mStrings.add("Elna Stiltner"); | ||
mStrings.add("Carly Landon"); | ||
mStrings.add("Hans Morford"); | ||
mStrings.add("Shawanna Kapoor"); | ||
mStrings.add("Thomasina Naron"); | ||
mStrings.add("Melba Massi"); | ||
mStrings.add("Sal Mangano"); | ||
mStrings.add("Mika Weitzel"); | ||
mStrings.add("Phylis France"); | ||
mStrings.add("Illa Winzer"); | ||
mStrings.add("Kristofer Boyden"); | ||
mStrings.add("Idalia Cryan"); | ||
mStrings.add("Jenni Sousa"); | ||
mStrings.add("Eda Forkey"); | ||
mStrings.add("Birgit Rispoli"); | ||
mStrings.add("Janiece Mcguffey"); | ||
mStrings.add("Barton Busick"); | ||
mStrings.add("Gerald Westerman"); | ||
mStrings.add("Shalanda Baran"); | ||
mStrings.add("Margherita Pazos"); | ||
mStrings.add("Yuk Fitts"); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:orientation="vertical" | ||
tools:context=".Fragments.SearchableSpinnerFragment"> | ||
|
||
<com.dvinfosys.widgets.SearchableSpinner.SearchableSpinner | ||
android:id="@+id/SearchableSpinner" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:layout_marginStart="24dp" | ||
android:layout_marginLeft="24dp" | ||
android:layout_marginTop="24dp" | ||
android:layout_marginEnd="24dp" | ||
android:layout_marginRight="24dp" | ||
android:gravity="center_horizontal" | ||
app:BoarderColor="@color/colorPrimary" | ||
app:BordersSize="1dp" | ||
app:RevealEmptyText="Touch to select" | ||
app:ShowBorders="false" | ||
app:SpinnerExpandHeight="250dp" /> | ||
|
||
</LinearLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:paddingTop="4dp" | ||
android:paddingBottom="4dp" | ||
android:paddingRight="4dp" | ||
android:paddingLeft="8dp" | ||
android:orientation="horizontal" | ||
app:layout_collapseMode="parallax" | ||
app:layout_collapseParallaxMultiplier="0.5"> | ||
|
||
<TextView | ||
android:id="@+id/ImgVw_Letters" | ||
android:layout_width="32dp" | ||
android:text="A" | ||
android:gravity="center" | ||
android:layout_height="32dp"/> | ||
|
||
<TextView | ||
android:id="@+id/TxtVw_DisplayName" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_marginLeft="8dp" | ||
android:layout_gravity="center_vertical"/> | ||
|
||
</LinearLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:paddingTop="8dp" | ||
android:paddingBottom="8dp" | ||
android:paddingRight="4dp" | ||
android:paddingLeft="8dp" | ||
android:orientation="horizontal" | ||
app:layout_collapseMode="parallax" | ||
app:layout_collapseParallaxMultiplier="0.5"> | ||
|
||
<TextView | ||
android:id="@+id/TxtVw_NoSelection" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_marginLeft="8dp" | ||
android:layout_gravity="center_vertical" | ||
android:text="@string/no_selection"/> | ||
</LinearLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.