Skip to content

Commit a01c5ae

Browse files
committed
Version 7.1.0
- Fixed the appearance of the drag handle on all devices with different resolutions from the Nexus 7. - Fixed dragging of the drag handle on APIs 8-10 - Fixed chaining of settings.
1 parent ae3d68b commit a01c5ae

File tree

7 files changed

+63
-45
lines changed

7 files changed

+63
-45
lines changed

.idea/misc.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/src/main/java/com/turingtechnologies/materialscrollbardemo/MainActivity.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import android.support.v7.app.AppCompatActivity;
66
import android.support.v7.widget.LinearLayoutManager;
77
import android.support.v7.widget.RecyclerView;
8+
import android.util.TypedValue;
89
import android.view.Menu;
910
import android.view.MenuItem;
1011

@@ -21,7 +22,7 @@ protected void onCreate(Bundle savedInstanceState) {
2122
RecyclerView recyclerView = ((RecyclerView)findViewById(R.id.recyclerView));
2223
recyclerView.setAdapter(new DemoAdapter(this));
2324
recyclerView.setLayoutManager(new LinearLayoutManager(this));
24-
new DragScrollBar(this, recyclerView, false).addIndicator(new AlphabetIndicator(this), true);
25+
new DragScrollBar(this, recyclerView, false).setHandleColour(obtainStyledAttributes(new TypedValue().data, new int[] { R.attr.colorAccent }).getColor(0,0)).addIndicator(new AlphabetIndicator(this), true);
2526
}
2627

2728
@Override

lib/build.gradle

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
apply plugin: 'com.android.library'
22

3+
def version = '7.1.0'
4+
35
ext {
46
bintrayRepo = 'maven'
57
bintrayName = 'material-scroll-bar'
@@ -13,7 +15,7 @@ ext {
1315
siteUrl = 'https://github.com/krimin-killr21/MaterialScrollBar'
1416
gitUrl = 'https://github.com/krimin-killr21/MaterialScrollBar.git'
1517

16-
libraryVersion = '7.0.1'
18+
libraryVersion = version
1719

1820
developerId = 'krimin-killr21'
1921
developerName = 'Turing Technologies'
@@ -31,8 +33,8 @@ android {
3133
defaultConfig {
3234
minSdkVersion 7
3335
targetSdkVersion 23
34-
versionCode 14
35-
versionName "7.0.1"
36+
versionCode 15
37+
versionName version
3638
}
3739
}
3840

lib/src/main/java/com/turingtechnologies/materialscrollbar/DragScrollBar.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@
2525

2626
import com.nineoldandroids.view.ViewHelper;
2727

28-
public class DragScrollBar extends MaterialScrollBar{
28+
public class DragScrollBar extends MaterialScrollBar<DragScrollBar>{
2929

3030
public DragScrollBar(Context context, RecyclerView recyclerView, boolean lightOnTouch){
3131
super(context, recyclerView, lightOnTouch);
3232
}
3333

3434
@Override
3535
void setTouchIntercept() {
36-
handle.setOnTouchListener(new OnTouchListener() {
36+
OnTouchListener otl = new OnTouchListener() {
3737
@Override
3838
public boolean onTouch(View v, MotionEvent event) {
3939
if (!totallyHidden) {
@@ -94,7 +94,13 @@ public boolean onTouch(View v, MotionEvent event) {
9494
}
9595
return false;
9696
}
97-
});
97+
};
98+
//For APIs <8, the valid touch area will not follow the button and thus the entire bar must be a valid touch area
99+
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB){
100+
handle.setOnTouchListener(otl);
101+
} else {
102+
setOnTouchListener(otl);
103+
}
98104
}
99105

100106
@Override

lib/src/main/java/com/turingtechnologies/materialscrollbar/Handle.java

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,13 @@ public class Handle extends View {
2929
RectF rectF;
3030
Paint p = new Paint();
3131
Integer mode;
32+
boolean expanded = false;
33+
Context context;
3234

3335
public Handle(Context c, int m){
3436
super(c);
3537

38+
context = c;
3639
mode = m;
3740
p.setFlags(Paint.ANTI_ALIAS_FLAG);
3841
}
@@ -45,6 +48,7 @@ public void setBackgroundColor(int color) {
4548
}
4649

4750
public void collapseHandle(){
51+
expanded = true;
4852
rectF = new RectF(new Rect(getLeft(),getTop(),getLeft(),getBottom()));
4953
invalidate();
5054
}
@@ -55,7 +59,8 @@ protected void onAnimationEnd() {
5559
}
5660

5761
public void expandHandle(){
58-
rectF = new RectF(new Rect(getLeft() - 20,getTop(),getLeft() - 9,getBottom()));
62+
expanded = false;
63+
rectF = makeRect();
5964
invalidate();
6065
}
6166

@@ -64,21 +69,25 @@ protected void onLayout(boolean changed, int left, int top, int right, int botto
6469
super.onLayout(changed, left, top, right, bottom);
6570

6671
if(mode == 0){
67-
rectF = new RectF(new Rect(getLeft() - 20,getTop(),getLeft() - 9,getBottom()));
72+
rectF = makeRect();
6873
}
6974
}
7075

76+
private RectF makeRect(){
77+
return new RectF(new Rect(getLeft() - Utils.getDP(11, context),getTop(),getLeft()-Utils.getDP(4, context),getBottom()));
78+
}
79+
7180
@Override
7281
protected void onDraw(Canvas canvas) {
7382
super.onDraw(canvas);
7483

75-
if(mode == 0){
84+
if(mode == 0 && !expanded){
7685
Rect newRect = canvas.getClipBounds();
77-
newRect.inset(getLeft() - 20, 0); //make the rect larger
86+
newRect.inset(getLeft() - Utils.getDP(30, context), 0); //make the rect larger
7887

7988
canvas.clipRect(newRect, Region.Op.REPLACE);
8089

81-
canvas.drawArc(rectF, 335F, 360F, false, p);
90+
canvas.drawArc(rectF, 90F, 180F, false, p); //335
8291
}
8392
}
8493
}

lib/src/main/java/com/turingtechnologies/materialscrollbar/MaterialScrollBar.java

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
import 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.

lib/src/main/java/com/turingtechnologies/materialscrollbar/TouchScrollBar.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
import com.nineoldandroids.view.ViewHelper;
3131

32-
public class TouchScrollBar extends MaterialScrollBar{
32+
public class TouchScrollBar extends MaterialScrollBar<TouchScrollBar>{
3333

3434
boolean hide = true;
3535
private int hideDuration = 2500;

0 commit comments

Comments
 (0)