99
1010import com .matpag .clickdrawabletextview .ClickDrawableAutoCompleteTextView ;
1111import com .matpag .clickdrawabletextview .ClickDrawableEditText ;
12- import com .matpag .clickdrawabletextview .ClickDrawableTextView ;
1312import com .matpag .clickdrawabletextview .CsDrawable ;
1413import com .matpag .clickdrawabletextview .DrawablePosition ;
1514import com .matpag .clickdrawabletextview .interfaces .OnDrawableClickListener ;
1615
17-
16+ /**
17+ * Showcase activity
18+ */
1819public class MainActivity extends AppCompatActivity {
1920
20- private ClickDrawableAutoCompleteTextView mCdAutoComplete ;
21-
22- private ClickDrawableTextView mCdTextView ;
23-
24- private ClickDrawableEditText mCdEditText , mCdEditText2 ;
25-
2621 @ Override
2722 protected void onCreate (Bundle savedInstanceState ) {
2823 super .onCreate (savedInstanceState );
@@ -31,47 +26,22 @@ protected void onCreate(Bundle savedInstanceState) {
3126 //####### ClickDrawableEditText example ########
3227 //In this example we got the view from the XML, so go watch R.layout.activity_main to
3328 //understand more on how the properties were configured
34- mCdEditText = (ClickDrawableEditText )
29+ final ClickDrawableEditText mCdEditText = (ClickDrawableEditText )
3530 findViewById (R .id .click_drawable_edit_text );
3631 mCdEditText .setOnDrawableClickListener (new OnDrawableClickListener () {
3732 @ Override
3833 public void onClick (View view , DrawablePosition position ) {
3934 Toast .makeText (MainActivity .this , position .name (), Toast .LENGTH_SHORT ).show ();
40- }
41- });
42-
43- mCdEditText2 = (ClickDrawableEditText )
44- findViewById (R .id .click_drawable_edit_text2 );
45- mCdEditText2 .setOnDrawableClickListener (new OnDrawableClickListener () {
46- @ Override
47- public void onClick (View view , DrawablePosition position ) {
48- Toast .makeText (MainActivity .this , position .name (), Toast .LENGTH_SHORT ).show ();
49- }
50- });
51-
52- //####### ClickDrawableTextView example ########
53- //In this example we got the view from the XML, so go watch R.layout.activity_main to
54- //understand more on how the properties were configured
55- mCdTextView = (ClickDrawableTextView )
56- findViewById (R .id .click_drawable_text_view );
57- mCdTextView .setOnDrawableClickListener (new OnDrawableClickListener () {
58- @ Override
59- public void onClick (View view , DrawablePosition position ) {
60- Toast .makeText (MainActivity .this , position .name (), Toast .LENGTH_SHORT ).show ();
35+ //close the keyboard if opened
36+ mCdEditText .closeKeyboard ();
6137 }
6238 });
6339
6440
6541 //######## ClickDrawableAutoCompleteTextView example ############
66- mCdAutoComplete = (ClickDrawableAutoCompleteTextView )
67- findViewById (R .id .click_drawable_auto_text_view );
68- setUpClickDrawableAutoCompleteTextView ();
69- }
42+ final ClickDrawableAutoCompleteTextView mCdAutoComplete =
43+ (ClickDrawableAutoCompleteTextView ) findViewById (R .id .click_drawable_auto_text_view );
7044
71- /**
72- * An advanced sample on how to use a {@link ClickDrawableAutoCompleteTextView}
73- */
74- private void setUpClickDrawableAutoCompleteTextView (){
7545 //build a CsDrawable object with a PGN drawable
7646 CsDrawable csDrawable1 = new CsDrawable .Builder (this , R .drawable .ic_close_red_24dp )
7747 .setDrawableDpSize (30 , 30 )
@@ -91,7 +61,9 @@ private void setUpClickDrawableAutoCompleteTextView(){
9161 mCdAutoComplete .setOnItemClickListener (new AdapterView .OnItemClickListener () {
9262 @ Override
9363 public void onItemClick (AdapterView <?> parent , View view , int position , long id ) {
64+ //show the cancel drawable
9465 mCdAutoComplete .showEndCsDrawable (true );
66+ //prevent user to change the value without prior clicking on the cancel drawable
9567 mCdAutoComplete .disableFocusOnText (true , true );
9668 }
9769 });
@@ -103,13 +75,15 @@ public void onItemClick(AdapterView<?> parent, View view, int position, long id)
10375 public void onClick (View view , DrawablePosition position ) {
10476 switch (position ){
10577 case END : //if we touched the END drawable
78+ //hide the close drawable
10679 mCdAutoComplete .showEndCsDrawable (false );
80+ //get focus on input (opening the keyboard)
10781 mCdAutoComplete .enableFocusOnText (true );
82+ //reset text
10883 mCdAutoComplete .setText ("" );
10984 break ;
11085 }
11186 }
11287 });
113-
11488 }
11589}
0 commit comments