1
1
package com .example .dhananjay .dailygoals ;
2
2
3
+ import android .content .Context ;
3
4
import android .support .v7 .app .AppCompatActivity ;
4
5
import android .os .Bundle ;
5
6
import android .support .v7 .widget .LinearLayoutManager ;
6
7
import android .support .v7 .widget .RecyclerView ;
7
8
import android .content .Intent ;
9
+ import android .view .GestureDetector ;
10
+ import android .view .MotionEvent ;
8
11
import android .view .View ;
12
+ import android .widget .Toast ;
9
13
10
14
import com .stephentuso .welcome .WelcomeHelper ;
11
15
@@ -50,21 +54,25 @@ protected void onCreate(Bundle savedInstanceState) {
50
54
item2List .add (new Items2 (R .drawable .tick ));
51
55
item2List .add (new Items2 (R .drawable .wrong ));
52
56
item3List .add (new Items3 (R .drawable .achievements ));
57
+
53
58
LinearLayoutManager layoutmanager =new LinearLayoutManager (this ,LinearLayoutManager .HORIZONTAL ,false );
54
59
RecyclerView .LayoutManager rvlayoutmanager =layoutmanager ;
55
60
recyclerView .setLayoutManager (rvlayoutmanager );
56
61
TextAdapter adapter =new TextAdapter (this ,itemList );
57
62
recyclerView .setAdapter (adapter );
63
+
58
64
LinearLayoutManager layoutmanager1 =new LinearLayoutManager (this ,LinearLayoutManager .HORIZONTAL ,false );
59
65
RecyclerView .LayoutManager rvlayoutmanager1 =layoutmanager1 ;
60
66
recyclerView1 .setLayoutManager (rvlayoutmanager1 );
61
67
TextAdapter1 adapter1 =new TextAdapter1 (this ,item1List );
62
68
recyclerView1 .setAdapter (adapter1 );
69
+
63
70
LinearLayoutManager layoutmanager2 =new LinearLayoutManager (this ,LinearLayoutManager .HORIZONTAL ,false );
64
71
RecyclerView .LayoutManager rvlayoutmanager2 =layoutmanager2 ;
65
72
recyclerView2 .setLayoutManager (rvlayoutmanager2 );
66
73
TextAdapter2 adapter2 =new TextAdapter2 (this ,item2List );
67
74
recyclerView2 .setAdapter (adapter2 );
75
+
68
76
LinearLayoutManager layoutmanager3 =new LinearLayoutManager (this ,LinearLayoutManager .HORIZONTAL ,false );
69
77
RecyclerView .LayoutManager rvlayoutmanager3 =layoutmanager3 ;
70
78
recyclerView3 .setLayoutManager (rvlayoutmanager3 );
@@ -78,11 +86,118 @@ public void onItemClicked(RecyclerView recyclerView, int position, View v) {
78
86
}
79
87
} );
80
88
89
+
90
+
91
+
92
+
93
+ recyclerView2 .addOnItemTouchListener (new RecyclerTouchListener (this ,
94
+ recyclerView2 , new ClickListener () {
95
+ @ Override
96
+ public void onClick (View view , final int position ) {
97
+ //Values are passing to activity & to fragment as well
98
+
99
+
100
+ if (position == 0 )
101
+ {
102
+ Intent intent = new Intent (getApplicationContext (), Goals_Completed .class );
103
+ startActivity (intent );
104
+ }
105
+ if (position == 1 )
106
+ {
107
+ Intent intent = new Intent (getApplicationContext (), Goals_Missed .class );
108
+ startActivity (intent );
109
+ }
110
+
111
+ }
112
+ @ Override
113
+ public void onLongClick (View view , int position ) {
114
+
115
+ if (position == 0 )
116
+ {
117
+ Toast .makeText (getApplicationContext (), "Daily Goals Completed by You" ,
118
+ Toast .LENGTH_SHORT ).show ();
119
+ }
120
+ if (position == 1 )
121
+ {
122
+ Toast .makeText (getApplicationContext (), "Daily Goals Missed by You" ,
123
+ Toast .LENGTH_SHORT ).show ();
124
+ }
125
+ }
126
+ }));
127
+ recyclerView3 .addOnItemTouchListener (new RecyclerTouchListener (this ,
128
+ recyclerView3 , new ClickListener () {
129
+ @ Override
130
+ public void onClick (View view , final int position ) {
131
+ //Values are passing to activity & to fragment as well
132
+
133
+
134
+
135
+ Intent intent = new Intent (getApplicationContext (), Achievements .class );
136
+ startActivity (intent );
137
+
138
+
139
+ }
140
+ @ Override
141
+ public void onLongClick (View view , int position ) {
142
+
143
+
144
+ Toast .makeText (getApplicationContext (), "Your Achievements" ,
145
+ Toast .LENGTH_SHORT ).show ();
146
+
147
+ }
148
+ }));
149
+
81
150
// Show the welcome screen
82
151
welcomeScreen = new WelcomeHelper (this , WelcomeScreenActivity .class );
83
152
welcomeScreen .show (savedInstanceState );
84
153
}
85
154
155
+
156
+ class RecyclerTouchListener implements RecyclerView .OnItemTouchListener {
157
+
158
+ private ClickListener clicklistener ;
159
+ private GestureDetector gestureDetector ;
160
+
161
+ public RecyclerTouchListener (Context context , final RecyclerView recycleView , final ClickListener clicklistener ){
162
+
163
+ this .clicklistener =clicklistener ;
164
+ gestureDetector =new GestureDetector (context ,new GestureDetector .SimpleOnGestureListener (){
165
+ @ Override
166
+ public boolean onSingleTapUp (MotionEvent e ) {
167
+ return true ;
168
+ }
169
+
170
+ @ Override
171
+ public void onLongPress (MotionEvent e ) {
172
+ View child =recycleView .findChildViewUnder (e .getX (),e .getY ());
173
+ if (child !=null && clicklistener !=null ){
174
+ clicklistener .onLongClick (child ,recycleView .getChildAdapterPosition (child ));
175
+ }
176
+ }
177
+ });
178
+ }
179
+
180
+ @ Override
181
+ public boolean onInterceptTouchEvent (RecyclerView rv , MotionEvent e ) {
182
+ View child =rv .findChildViewUnder (e .getX (),e .getY ());
183
+ if (child !=null && clicklistener !=null && gestureDetector .onTouchEvent (e )){
184
+ clicklistener .onClick (child ,rv .getChildAdapterPosition (child ));
185
+ }
186
+
187
+ return false ;
188
+ }
189
+
190
+ @ Override
191
+ public void onTouchEvent (RecyclerView rv , MotionEvent e ) {
192
+
193
+ }
194
+
195
+ @ Override
196
+ public void onRequestDisallowInterceptTouchEvent (boolean disallowIntercept ) {
197
+
198
+ }
199
+ }
200
+
86
201
@ Override
87
202
protected void onSaveInstanceState (Bundle outState ) {
88
203
super .onSaveInstanceState (outState );
0 commit comments