Skip to content

Commit 3ba2353

Browse files
committed
Fix #118
1 parent f9c1849 commit 3ba2353

File tree

6 files changed

+44
-37
lines changed

6 files changed

+44
-37
lines changed

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ buildscript {
99
}
1010
dependencies {
1111
classpath 'com.github.ben-manes:gradle-versions-plugin:0.15.0'
12-
classpath 'com.android.tools.build:gradle:3.0.1'
12+
classpath 'com.android.tools.build:gradle:3.2.0-alpha18'
1313
classpath 'me.tatarka:gradle-retrolambda:3.7.0'
1414
// classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
1515

@@ -25,5 +25,5 @@ allprojects {
2525
google()
2626
}
2727

28-
project.ext.supportLibVersion = '27.1.0'
28+
project.ext.supportLibVersion = '27.1.1'
2929
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#Fri Dec 29 16:08:05 EST 2017
1+
#Thu Jun 21 16:20:59 EDT 2018
22
distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip

lib/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ artifacts {
4343
}
4444

4545
dependencies {
46-
compile "com.android.support:recyclerview-v7:${supportLibVersion}"
47-
compile "com.android.support:design:${supportLibVersion}"
46+
implementation "com.android.support:recyclerview-v7:${supportLibVersion}"
47+
implementation "com.android.support:design:${supportLibVersion}"
4848
// compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
4949
}
5050
repositories {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ int getMode() {
8787

8888
@Override
8989
float getHideRatio() {
90-
return .65F;
90+
return .4F;
9191
}
9292

9393
@Override

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

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,22 @@
2222
import android.graphics.Paint;
2323
import android.graphics.Rect;
2424
import android.graphics.RectF;
25-
import android.graphics.Region;
2625
import android.view.View;
2726

2827
@SuppressLint("ViewConstructor")
2928
public class Handle extends View {
3029

31-
RectF rectF;
30+
final int WIDTH = Utils.getDP(8, this);
31+
RectF handleArc;
32+
RectF handleHold;
3233
Paint p = new Paint();
3334
Integer mode;
3435
boolean expanded = false;
35-
Context context;
3636
Boolean rtl = false;
3737

3838
public Handle(Context c, int m) {
3939
super(c);
4040

41-
context = c;
4241
mode = m;
4342
p.setFlags(Paint.ANTI_ALIAS_FLAG);
4443
}
@@ -49,14 +48,13 @@ void setRightToLeft(boolean rtl) {
4948

5049
@Override
5150
public void setBackgroundColor(int color) {
52-
super.setBackgroundColor(color);
51+
// super.setBackgroundColor(color);
5352

5453
p.setColor(color);
5554
}
5655

5756
public void collapseHandle() {
5857
expanded = true;
59-
rectF = new RectF(new Rect(getRight(),getTop(),getRight(),getBottom()));
6058
invalidate();
6159
}
6260

@@ -67,40 +65,46 @@ protected void onAnimationEnd() {
6765

6866
public void expandHandle() {
6967
expanded = false;
70-
rectF = makeRect();
7168
invalidate();
7269
}
7370

7471
@Override
7572
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
76-
super.onLayout(changed, left, top, right, bottom);
77-
7873
if(mode == 0) {
79-
rectF = makeRect();
74+
makeRect();
75+
} else {
76+
if(rtl) {
77+
handleHold = new RectF(new Rect(getLeft(), getTop(), getRight() - WIDTH / 2 - Utils.getDP(1, this), getBottom()));
78+
} else {
79+
handleHold = new RectF(new Rect(getLeft() + WIDTH / 2 + Utils.getDP(1, this), getTop(), getRight(), getBottom()));
80+
}
8081
}
8182
}
8283

83-
private RectF makeRect() {
84+
private void makeRect() {
8485
if(rtl) {
85-
return new RectF(new Rect(getRight() - Utils.getDP(6, context),getTop(),getRight()+Utils.getDP(4, context),getBottom()));
86-
86+
handleArc = new RectF(new Rect(getRight() - WIDTH,getTop(),getRight(),getBottom()));
87+
handleHold = new RectF(new Rect(getLeft(), getTop(), getRight() - WIDTH / 2, getBottom()));
8788
} else {
88-
return new RectF(new Rect(getLeft() - Utils.getDP(4, context),getTop(),getLeft() + Utils.getDP(6, context),getBottom()));
89+
handleArc = new RectF(new Rect(getLeft(),getTop(),getLeft() + WIDTH,getBottom()));
90+
handleHold = new RectF(new Rect(getLeft() + WIDTH / 2, getTop(), getRight(), getBottom()));
8991
}
9092
}
9193

92-
Rect boundRect = new Rect();
9394
@Override
9495
protected void onDraw(Canvas canvas) {
9596
super.onDraw(canvas);
9697

9798
if(mode == 0 && !expanded) {
98-
canvas.getClipBounds(boundRect);
99-
boundRect.inset(-Utils.getDP(30, context), 0); //make the rect larger
99+
// canvas.getClipBounds(boundRect);
100+
// boundRect.inset(-Utils.getDP(4, context), 0); //make the rect larger
101+
//
102+
// canvas.clipRect(boundRect, Region.Op.REPLACE);
100103

101-
canvas.clipRect(boundRect, Region.Op.REPLACE);
102-
103-
canvas.drawArc(rectF, rtl ? 270F : 90F, 180F, false, p); //335
104+
canvas.drawRect(handleHold, p);
105+
canvas.drawArc(handleArc, rtl ? 270F : 90F, 180F, false, p); //335
106+
} else {
107+
canvas.drawRect(handleHold, p);
104108
}
105109
}
106110
}

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

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,11 @@ public abstract class MaterialScrollBar<T> extends RelativeLayout {
105105

106106
this.recyclerView = recyclerView;
107107

108+
setRightToLeft(Utils.isRightToLeft(context)); //Detects and applies the Right-To-Left status of the app
109+
108110
addView(setUpHandleTrack(context)); //Adds the handle track
109111
addView(setUpHandle(context, lightOnTouch)); //Adds the handle
110112

111-
setRightToLeft(Utils.isRightToLeft(context)); //Detects and applies the Right-To-Left status of the app
112-
113113
generalSetup();
114114
}
115115

@@ -122,12 +122,12 @@ public abstract class MaterialScrollBar<T> extends RelativeLayout {
122122
MaterialScrollBar(Context context, AttributeSet attributeSet, int defStyle) {
123123
super(context, attributeSet, defStyle);
124124

125+
setRightToLeft(Utils.isRightToLeft(context)); //Detects and applies the Right-To-Left status of the app
126+
125127
setUpProps(context, attributeSet); //Discovers and applies some XML attributes
126128

127129
addView(setUpHandleTrack(context)); //Adds the handle track
128130
addView(setUpHandle(context, a.getBoolean(R.styleable.MaterialScrollBar_msb_lightOnTouch, true))); //Adds the handle
129-
130-
setRightToLeft(Utils.isRightToLeft(context)); //Detects and applies the Right-To-Left status of the app
131131
}
132132

133133
//Unpacks XML attributes and ensures that no mandatory attributes are missing, then applies them.
@@ -150,8 +150,8 @@ void setUpProps(Context context, AttributeSet attributes) {
150150
//Sets up bar.
151151
View setUpHandleTrack(Context context) {
152152
handleTrack = new View(context);
153-
LayoutParams lp = new RelativeLayout.LayoutParams(Utils.getDP(12, this), LayoutParams.MATCH_PARENT);
154-
lp.addRule(ALIGN_PARENT_RIGHT);
153+
LayoutParams lp = new RelativeLayout.LayoutParams(Utils.getDP(14, this), LayoutParams.MATCH_PARENT);
154+
lp.addRule(rtl ? ALIGN_PARENT_LEFT : ALIGN_PARENT_RIGHT);
155155
handleTrack.setLayoutParams(lp);
156156
handleTrack.setBackgroundColor(ContextCompat.getColor(context, android.R.color.darker_gray));
157157
handleTrack.setAlpha(0.4F);
@@ -161,9 +161,10 @@ View setUpHandleTrack(Context context) {
161161
//Sets up handleThumb.
162162
Handle setUpHandle(Context context, Boolean lightOnTouch) {
163163
handleThumb = new Handle(context, getMode());
164-
RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(Utils.getDP(12, this),
164+
handleThumb.rtl = rtl;
165+
RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(Utils.getDP(18, this),
165166
Utils.getDP(72, this));
166-
lp.addRule(ALIGN_PARENT_RIGHT);
167+
lp.addRule(rtl ? ALIGN_PARENT_LEFT : ALIGN_PARENT_RIGHT);
167168
handleThumb.setLayoutParams(lp);
168169

169170
this.lightOnTouch = lightOnTouch;
@@ -308,7 +309,7 @@ protected void onLayout(boolean changed, int l, int t, int r, int b) {
308309
// Makes the bar render correctly for XML
309310
@Override
310311
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
311-
int desiredWidth = Utils.getDP(12, this);
312+
int desiredWidth = Utils.getDP(18, this);
312313
int desiredHeight = 100;
313314

314315
int widthMode = MeasureSpec.getMode(widthMeasureSpec);
@@ -631,7 +632,9 @@ public void setScrollBarHidden(boolean hidden) {
631632
*/
632633
public void setRightToLeft(boolean rtl) {
633634
this.rtl = rtl;
634-
handleThumb.setRightToLeft(rtl);
635+
if (handleThumb != null) {
636+
handleThumb.setRightToLeft(rtl);
637+
}
635638
if(indicator != null) {
636639
indicator.setRTL(rtl);
637640
indicator.setLayoutParams(indicator.refreshMargins((LayoutParams) indicator.getLayoutParams()));

0 commit comments

Comments
 (0)