Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
Appyown committed Sep 23, 2019
1 parent 63882bd commit fe6d1ec
Show file tree
Hide file tree
Showing 20 changed files with 1,531 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.dvinfosys.WidgetsExample.Fragments.NumberCounterFragment;
import com.dvinfosys.WidgetsExample.Fragments.ProgressViewFragment;
import com.dvinfosys.WidgetsExample.Fragments.RadioButtonFragment;
import com.dvinfosys.WidgetsExample.Fragments.SearchableSpinnerFragment;
import com.dvinfosys.WidgetsExample.Fragments.SeekbarFragment;
import com.dvinfosys.WidgetsExample.Fragments.SwitchFragment;
import com.dvinfosys.WidgetsExample.Fragments.TextViewFragment;
Expand Down Expand Up @@ -122,6 +123,8 @@ public boolean onNavigationItemSelected(MenuItem item) {
fragment = new ToggleButtonFragment();
} else if (id == R.id.nav_folding_cell) {
fragment = new FoldingCellFragment();
} else if (id == R.id.nav_searchable_spinner) {
fragment = new SearchableSpinnerFragment();
} else if (id == R.id.nav_share) {

} else if (id == R.id.nav_send) {
Expand Down
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
}
}
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");
}

}
26 changes: 26 additions & 0 deletions app/src/main/res/layout/fragment_searchable_spinner.xml
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>
28 changes: 28 additions & 0 deletions app/src/main/res/layout/view_list_item.xml
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>
21 changes: 21 additions & 0 deletions app/src/main/res/layout/view_list_no_selection_item.xml
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>
10 changes: 7 additions & 3 deletions app/src/main/res/menu/activity_home_drawer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,18 @@
android:icon="@drawable/ic_progressview"
android:title="@string/menu_progressview" />
<item
android:id="@+id/nav_color_picker"
android:icon="@drawable/ic_color_picker"
android:title="@string/menu_color_picker" />
android:id="@+id/nav_color_picker"
android:icon="@drawable/ic_color_picker"
android:title="@string/menu_color_picker" />

<item
android:id="@+id/nav_folding_cell"
android:title="@string/menu_folding_cell" />

<item
android:id="@+id/nav_searchable_spinner"
android:title="@string/menu_searchable_spinner" />

</group>

<item android:title="Communicate">
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,7 @@
<string name="content_to1_mock">46th Ave</string>
<string name="content_to2_mock">Woodside, NY 11101</string>
<string name="title_activity_main2">Main2Activity</string>
<string name="menu_searchable_spinner">Searchable Spinner</string>
<string name="no_selection">No Selection</string>

</resources>
Loading

0 comments on commit fe6d1ec

Please sign in to comment.