Skip to content

Commit 82aac01

Browse files
author
Appyown
committed
AutoSelect
1 parent e96d487 commit 82aac01

File tree

19 files changed

+864
-0
lines changed

19 files changed

+864
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ you could customize following UI controls in your Android application
4242
* [Expanding Collection](https://github.com/dvinfosys/CustomWidgets/wiki/Expanding-Collection)
4343
* [Seekbar](https://github.com/dvinfosys/CustomWidgets/blob/master/app/src/main/java/com/dvinfosys/WidgetsExample/Fragments/SeekbarFragment.java)
4444
* [ProgressView](https://github.com/dvinfosys/CustomWidgets/blob/master/app/src/main/java/com/dvinfosys/WidgetsExample/Fragments/ProgressViewFragment.java)
45+
* [AutoSelect](https://github.com/dvinfosys/CustomWidgets/blob/master/app/src/main/java/com/dvinfosys/WidgetsExample/Fragments/AutoSelectFragment.java)
4546

4647

4748
## Author

app/src/main/java/com/dvinfosys/WidgetsExample/Activity/HomeActivity.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import android.view.Menu;
1414
import android.view.MenuItem;
1515

16+
import com.dvinfosys.WidgetsExample.Fragments.AutoSelectFragment;
1617
import com.dvinfosys.WidgetsExample.Fragments.ButtonFragment;
1718
import com.dvinfosys.WidgetsExample.Fragments.CheckBoxFragment;
1819
import com.dvinfosys.WidgetsExample.Fragments.ColorPickerFragment;
@@ -133,6 +134,8 @@ public boolean onNavigationItemSelected(MenuItem item) {
133134
fragment = new PaperOnboardingFragment();
134135
} else if (id == R.id.nav_expanding_collection) {
135136
fragment = new ExpandingCollectionFragment();
137+
}else if (id==R.id.nav_auto_select){
138+
fragment=new AutoSelectFragment();
136139
}
137140
if (fragment != null) {
138141
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.dvinfosys.WidgetsExample.Fragments;
2+
3+
import android.os.Bundle;
4+
import android.support.annotation.NonNull;
5+
import android.support.annotation.Nullable;
6+
import android.support.v4.app.Fragment;
7+
import android.view.LayoutInflater;
8+
import android.view.View;
9+
import android.view.ViewGroup;
10+
11+
import com.dvinfosys.WidgetsExample.R;
12+
13+
public class AutoSelectFragment extends Fragment {
14+
15+
@Override
16+
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
17+
View view = inflater.inflate(R.layout.fragment_auto_select, container, false);
18+
19+
return view;
20+
}
21+
22+
@Override
23+
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
24+
super.onViewCreated(view, savedInstanceState);
25+
getActivity().setTitle("Auto Select Example");
26+
}
27+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:tools="http://schemas.android.com/tools"
4+
android:layout_width="match_parent"
5+
android:layout_height="match_parent"
6+
xmlns:as="http://schemas.android.com/apk/res-auto"
7+
tools:context=".Fragments.AutoSelectFragment">
8+
9+
<com.dvinfosys.widgets.AutoSelect.ASListView
10+
android:id="@+id/as_picker"
11+
android:layout_width="match_parent"
12+
android:layout_height="match_parent"
13+
android:background="@color/ds_list_bg"
14+
android:visibility="invisible"
15+
as:cell_font_size="8sp"
16+
as:data_array="@array/months"
17+
as:picker_box_view="@id/picker_box"
18+
as:scale_animations="true"
19+
as:scale_animations_factor="1.3"
20+
as:scale_animations_pivot_center="false"
21+
as:selected_index="2"
22+
as:selector_background="@color/ds_list_selector_bg" />
23+
24+
<com.dvinfosys.widgets.AutoSelect.ASDefaultPickerBox
25+
android:id="@+id/picker_box"
26+
android:layout_width="match_parent"
27+
android:layout_height="wrap_content"
28+
android:layout_marginTop="260dp"
29+
android:background="@color/green"
30+
android:padding="15dp" />
31+
32+
</FrameLayout>

app/src/main/res/menu/activity_home_drawer.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@
8383
<item
8484
android:id="@+id/nav_expanding_collection"
8585
android:title="@string/menu_expanding_collection" />
86+
<item
87+
android:id="@+id/nav_auto_select"
88+
android:title="@string/menu_auto_select" />
8689

8790
</group>
8891
</menu>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<resources>
3+
<string-array name="months">
4+
<item>January</item>
5+
<item>February</item>
6+
<item>March</item>
7+
<item>April</item>
8+
<item>May</item>
9+
<item>June</item>
10+
<item>July</item>
11+
<item>August</item>
12+
<item>September</item>
13+
<item>October</item>
14+
<item>November</item>
15+
<item>December</item>
16+
</string-array>
17+
</resources>

app/src/main/res/values/colors.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,12 @@
3636

3737
<color name="colorListDivider">#e6e6e6</color>
3838
<color name="transparent">#00ffffff</color>
39+
40+
<color name="selector_border">#dedede</color>
41+
<color name="picker_box_border">#9f9f9f</color>
42+
<color name="picker_box_bg">#ffffff</color>
43+
<color name="ds_list_bg">#ffffff</color>
44+
<color name="picker_list_text">#232323</color>
45+
<color name="ds_list_selector_bg">#49067397</color>
46+
<color name="ds_picker_box_bg">#67f45959</color>
3947
</resources>

app/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,5 +74,6 @@
7474
<string name="menu_spotlight">Spotlight</string>
7575
<string name="menu_paper_onboarding">Paper Onboarding</string>
7676
<string name="menu_expanding_collection">Expanding Collection</string>
77+
<string name="menu_auto_select">Auto Select</string>
7778

7879
</resources>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.dvinfosys.widgets.AutoSelect;
2+
3+
import android.content.Context;
4+
import android.support.annotation.NonNull;
5+
import android.support.annotation.Nullable;
6+
import android.util.AttributeSet;
7+
import android.view.View;
8+
import android.widget.FrameLayout;
9+
10+
public abstract class ASAbstractPickerBox<T> extends FrameLayout {
11+
12+
public ASAbstractPickerBox(@NonNull Context context) {
13+
super(context);
14+
}
15+
16+
public ASAbstractPickerBox(@NonNull Context context, @Nullable AttributeSet attrs) {
17+
super(context, attrs);
18+
}
19+
20+
public ASAbstractPickerBox(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
21+
super(context, attrs, defStyleAttr);
22+
}
23+
24+
public abstract void onSelect(T selectedItem, int selectedIndex);
25+
26+
public abstract View getCellRoot();
27+
28+
}
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
package com.dvinfosys.widgets.AutoSelect;
2+
3+
import android.content.Context;
4+
import android.support.annotation.NonNull;
5+
import android.view.LayoutInflater;
6+
import android.view.View;
7+
import android.view.ViewGroup;
8+
import android.widget.ArrayAdapter;
9+
import android.widget.TextView;
10+
11+
import com.dvinfosys.widgets.R;
12+
13+
import java.util.ArrayList;
14+
15+
public class ASDefaultAdapter extends ArrayAdapter<String> {
16+
17+
private ArrayList<String> items;
18+
private Context context;
19+
20+
// Things to provide proper cell configuration comparing to configuration of picker box element
21+
// Any custom implementation doesn't need this three vars
22+
private int cellHeight;
23+
private int cellTextSize;
24+
private ASDefaultPickerBox dsPickerBoxDefault;
25+
26+
ASDefaultAdapter(Context context, int textViewResourceId, ArrayList<String> stringItems, Integer cellHeight, Integer cellTextSize) {
27+
super(context, textViewResourceId, stringItems);
28+
this.items = stringItems;
29+
this.context = context;
30+
this.cellHeight = cellHeight;
31+
this.cellTextSize = cellTextSize;
32+
}
33+
34+
void setDsPickerBoxDefault(ASDefaultPickerBox dsPickerBoxDefault) {
35+
this.dsPickerBoxDefault = dsPickerBoxDefault;
36+
}
37+
38+
void setCellHeight(Integer cellHeight) {
39+
this.cellHeight = cellHeight;
40+
}
41+
42+
void setCellTextSize(Integer cellTextSize) {
43+
this.cellTextSize = cellTextSize;
44+
}
45+
46+
@Override
47+
public long getItemId(int position) {
48+
return position;
49+
}
50+
51+
@Override
52+
public boolean hasStableIds() {
53+
return true;
54+
}
55+
56+
@Override
57+
public int getCount() {
58+
return items.size();
59+
}
60+
61+
@NonNull
62+
@Override
63+
public View getView(int position, View convertView, @NonNull ViewGroup parent) {
64+
ASDefaultAdapter.ViewHolder holder;
65+
66+
if (null == convertView) {
67+
LayoutInflater vi = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
68+
assert vi != null;
69+
convertView = vi.inflate(R.layout.as_default_list_item, parent, false);
70+
holder = new ASDefaultAdapter.ViewHolder();
71+
holder.text = convertView.findViewById(R.id.ds_default_cell_text);
72+
convertView.setTag(holder);
73+
} else {
74+
holder = (ViewHolder) convertView.getTag();
75+
}
76+
77+
if (null != holder) {
78+
holder.text.setText(items.get(position));
79+
80+
if (cellHeight > 0)
81+
convertView.setMinimumHeight(cellHeight);
82+
83+
if (cellTextSize > 0)
84+
holder.text.setTextSize(cellTextSize);
85+
86+
if (null != this.dsPickerBoxDefault)
87+
convertView.setPadding(dsPickerBoxDefault.getPaddingLeft(), dsPickerBoxDefault.getPaddingTop(),
88+
dsPickerBoxDefault.getPaddingRight(), dsPickerBoxDefault.getPaddingBottom());
89+
}
90+
return convertView;
91+
}
92+
93+
private class ViewHolder {
94+
TextView text;
95+
}
96+
97+
}

0 commit comments

Comments
 (0)