3838import com .nineoldandroids .view .ViewHelper ;
3939
4040@ SuppressLint ("ViewConstructor" )
41- abstract class MaterialScrollBar extends RelativeLayout {
41+ abstract class MaterialScrollBar < T > extends RelativeLayout {
4242
4343 private View background ;
4444 Handle handle ;
@@ -143,30 +143,30 @@ public MaterialScrollBar getMe(){
143143 * Provides the ability to programmatically set the colour of the scrollbar handle.
144144 * @param colour to set the handle.
145145 */
146- public MaterialScrollBar setHandleColour (String colour ){
146+ public T setHandleColour (String colour ){
147147 handleColour = Color .parseColor (colour );
148148 setHandleColour ();
149- return this ;
149+ return ( T ) this ;
150150 }
151151
152152 /**
153153 * Provides the ability to programmatically set the colour of the scrollbar handle.
154154 * @param colour to set the handle.
155155 */
156- public MaterialScrollBar setHandleColour (int colour ){
156+ public T setHandleColour (int colour ){
157157 handleColour = colour ;
158158 setHandleColour ();
159- return this ;
159+ return ( T ) this ;
160160 }
161161
162162 /**
163163 * Provides the ability to programmatically set the colour of the scrollbar handle.
164164 * @param colourResId to set the handle.
165165 */
166- public MaterialScrollBar setHandleColourRes (int colourResId ){
166+ public T setHandleColourRes (int colourResId ){
167167 handleColour = ContextCompat .getColor (getContext (), colourResId );
168168 setHandleColour ();
169- return this ;
169+ return ( T ) this ;
170170 }
171171
172172 private void setHandleColour (){
@@ -182,126 +182,126 @@ private void setHandleColour(){
182182 * Provides the ability to programmatically set the colour of the scrollbar handle when unpressed. Only applies if lightOnTouch is true.
183183 * @param colour to set the handle when unpressed.
184184 */
185- public MaterialScrollBar setHandleOffColour (String colour ){
185+ public T setHandleOffColour (String colour ){
186186 handleOffColour = Color .parseColor (colour );
187187 if (lightOnTouch ){
188188 handle .setBackgroundColor (handleOffColour );
189189 }
190- return this ;
190+ return ( T ) this ;
191191 }
192192
193193 /**
194194 * Provides the ability to programmatically set the colour of the scrollbar handle when unpressed. Only applies if lightOnTouch is true.
195195 * @param colour to set the handle when unpressed.
196196 */
197- public MaterialScrollBar setHandleOffColour (int colour ){
197+ public T setHandleOffColour (int colour ){
198198 handleOffColour = colour ;
199199 if (lightOnTouch ){
200200 handle .setBackgroundColor (handleOffColour );
201201 }
202- return this ;
202+ return ( T ) this ;
203203 }
204204
205205 /**
206206 * Provides the ability to programmatically set the colour of the scrollbar handle when unpressed. Only applies if lightOnTouch is true.
207207 * @param colourResId to set the handle when unpressed.
208208 */
209- public MaterialScrollBar setHandleOffColourRes (int colourResId ){
209+ public T setHandleOffColourRes (int colourResId ){
210210 handleOffColour = ContextCompat .getColor (getContext (), colourResId );
211211 if (lightOnTouch ){
212212 handle .setBackgroundColor (handleOffColour );
213213 }
214- return this ;
214+ return ( T ) this ;
215215 }
216216
217217 /**
218218 * Provides the ability to programmatically set the colour of the scrollbar.
219219 * @param colour to set the bar.
220220 */
221- public MaterialScrollBar setBarColour (String colour ){
221+ public T setBarColour (String colour ){
222222 background .setBackgroundColor (Color .parseColor (colour ));
223- return this ;
223+ return ( T ) this ;
224224 }
225225
226226 /**
227227 * Provides the ability to programmatically set the colour of the scrollbar.
228228 * @param colour to set the bar.
229229 */
230- public MaterialScrollBar setBarColour (int colour ){
230+ public T setBarColour (int colour ){
231231 background .setBackgroundColor (colour );
232- return this ;
232+ return ( T ) this ;
233233 }
234234
235235 /**
236236 * Provides the ability to programmatically set the colour of the scrollbar.
237237 * @param colourResId to set the bar.
238238 */
239- public MaterialScrollBar setBarColourRes (int colourResId ){
239+ public T setBarColourRes (int colourResId ){
240240 background .setBackgroundColor (ContextCompat .getColor (getContext (), colourResId ));
241- return this ;
241+ return ( T ) this ;
242242 }
243243
244244 /**
245245 * Provides the ability to programmatically set the text colour of the indicator. Will do nothing if there is no section indicator.
246246 * @param colour to set the text of the indicator.
247247 */
248- public MaterialScrollBar setTextColour (int colour ){
248+ public T setTextColour (int colour ){
249249 textColour = colour ;
250250 if (indicator != null ){
251251 indicator .setTextColour (textColour );
252252 }
253- return this ;
253+ return ( T ) this ;
254254 }
255255
256256
257257 /**
258258 * Provides the ability to programmatically set the text colour of the indicator. Will do nothing if there is no section indicator.
259259 * @param colourResId to set the text of the indicator.
260260 */
261- public MaterialScrollBar setTextColourRes (int colourResId ){
261+ public T setTextColourRes (int colourResId ){
262262 textColour = ContextCompat .getColor (getContext (), colourResId );
263263 if (indicator != null ){
264264 indicator .setTextColour (textColour );
265265 }
266- return this ;
266+ return ( T ) this ;
267267 }
268268
269269 /**
270270 * Provides the ability to programmatically set the text colour of the indicator. Will do nothing if there is no section indicator.
271271 * @param colour to set the text of the indicator.
272272 */
273- public MaterialScrollBar setTextColour (String colour ){
273+ public T setTextColour (String colour ){
274274 textColour = Color .parseColor (colour );
275275 if (indicator != null ){
276276 indicator .setTextColour (textColour );
277277 }
278- return this ;
278+ return ( T ) this ;
279279 }
280280
281281 /**
282282 * Removes any indicator.
283283 */
284- public MaterialScrollBar removeIndicator (){
284+ public T removeIndicator (){
285285 this .indicator = null ;
286- return this ;
286+ return ( T ) this ;
287287 }
288288
289289 /**
290290 * Adds an indicator which accompanies this scroll bar.
291291 */
292- public MaterialScrollBar addIndicator (Indicator indicator , boolean addSpace ) {
292+ public T addIndicator (Indicator indicator , boolean addSpace ) {
293293 indicator .testAdapter (recyclerView .getAdapter ());
294294 this .indicator = indicator ;
295295 indicator .linkToScrollBar (this , addSpace );
296296 indicator .setTextColour (textColour );
297- return this ;
297+ return ( T ) this ;
298298 }
299299
300300 /**
301301 * Allows the developer to set a custom bar thickness.
302302 * @param thickness The desired bar thickness.
303303 */
304- public MaterialScrollBar setBarThickness (int thickness ){
304+ public T setBarThickness (int thickness ){
305305 thickness = Utils .getDP (thickness , this );
306306 LayoutParams layoutParams = (LayoutParams ) handle .getLayoutParams ();
307307 layoutParams .width = thickness ;
@@ -314,7 +314,7 @@ public MaterialScrollBar setBarThickness(int thickness){
314314 if (indicator != null ){
315315 indicator .setSizeCustom (thickness );
316316 }
317- return this ;
317+ return ( T ) this ;
318318 }
319319
320320 //Fetch accent colour on devices running Lollipop or newer.
0 commit comments