Skip to content

Commit 0503330

Browse files
committed
Version 9.1.0
- Added name of offending adapter class to AdapterNotSetupForIndicatorExceptions for easier dev debugging. - The DragScrollBar handle will now stop jerking the centre of itself to the finger when pressed but instead remember where on itself it was pressed and allow user to drag from there. Indicator offsets to extend from the fingertip. Disabled if dev has activated draggableFromAnywhere. - Indicators moved upward to move out from under finger. - Instead of inverting indicators now simply stick to the top of the screen when user goes above level which would otherwise hide the indicator. - Indicators for RecyclerViews with GridLayoutManagers will now request data for the first element of the first visible row instead of the incorrect element.
1 parent b309571 commit 0503330

File tree

14 files changed

+151
-131
lines changed

14 files changed

+151
-131
lines changed

app/build.gradle

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ android {
88
applicationId "com.turingtechnologies.materialscrollbardemo"
99
minSdkVersion 11
1010
targetSdkVersion 23
11-
versionCode 4
12-
versionName "4.0"
11+
versionCode 5
12+
versionName "5.0"
1313
}
1414
buildTypes {
1515
release {
@@ -21,10 +21,7 @@ android {
2121

2222
dependencies {
2323
compile project(':lib')
24-
compile fileTree(include: ['*.jar'], dir: 'libs')
2524
compile "com.android.support:recyclerview-v7:${supportLibVersion}"
26-
compile 'org.apache.commons:commons-lang3:3.4'
27-
compile 'com.pnikosis:materialish-progress:1.5'
25+
compile 'com.pnikosis:materialish-progress:1.7'
2826
compile "com.android.support:appcompat-v7:${supportLibVersion}"
29-
androidTestCompile 'com.jayway.android.robotium:robotium-solo:5.2.1'
3027
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import android.view.Menu;
2525
import android.view.MenuItem;
2626

27+
import com.turingtechnologies.materialscrollbar.CustomIndicator;
2728
import com.turingtechnologies.materialscrollbar.TouchScrollBar;
2829

2930
public class IconActivity extends AppCompatActivity {
@@ -36,7 +37,7 @@ protected void onCreate(Bundle savedInstanceState) {
3637
RecyclerView recyclerView = ((RecyclerView)findViewById(R.id.recyclerView));
3738
recyclerView.setAdapter(new IconAdapter(this));
3839
recyclerView.setLayoutManager(new GridLayoutManager(this, 4));
39-
new TouchScrollBar(this, recyclerView, true).setHandleOffColour(Utils.fetchAccentColor(this));
40+
new TouchScrollBar(this, recyclerView, true).setHandleOffColour(Utils.fetchAccentColor(this)).addIndicator(new CustomIndicator(this), true);
4041
}
4142

4243
@Override

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,21 @@
99
import android.view.ViewGroup;
1010
import android.widget.ImageView;
1111

12-
public class IconAdapter extends RecyclerView.Adapter<IconAdapter.ViewHolder> {
12+
import com.turingtechnologies.materialscrollbar.ICustomAdapter;
13+
14+
public class IconAdapter extends RecyclerView.Adapter<IconAdapter.ViewHolder> implements ICustomAdapter {
1315

1416
private Activity act;
1517

1618
IconAdapter(Activity a){
1719
act = a;
1820
}
1921

22+
@Override
23+
public String getCustomStringForElement(int element) {
24+
return SplashActivity.pkgLabelList.get(element);
25+
}
26+
2027
public static class ViewHolder extends RecyclerView.ViewHolder {
2128
// each data item is just a string in this case
2229
public ImageView icon;

build.gradle

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
// Top-level build file where you can add configuration options common to all sub-projects/modules.
2+
apply plugin: 'com.github.ben-manes.versions'
23

34
buildscript {
45
repositories {
56
jcenter()
67
}
78
dependencies {
8-
classpath 'com.github.ben-manes:gradle-versions-plugin:0.11.3'
9-
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.2'
9+
classpath 'com.github.ben-manes:gradle-versions-plugin:0.12.0'
10+
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.6'
1011
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3'
1112
classpath 'com.android.tools.build:gradle:2.0.0-beta7'
1213

lib/build.gradle

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

3-
def version = '9.0.0'
3+
def version = '9.1.0'
44

55
ext {
66
bintrayRepo = 'maven'
@@ -33,13 +33,12 @@ android {
3333
defaultConfig {
3434
minSdkVersion 11
3535
targetSdkVersion 23
36-
versionCode 20
36+
versionCode 21
3737
versionName version
3838
}
3939
}
4040

4141
dependencies {
42-
compile fileTree(include: ['*.jar'], dir: 'libs')
4342
compile "com.android.support:recyclerview-v7:${supportLibVersion}"
4443
}
4544

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ int getIndicatorWidth() {
4949
@Override
5050
void testAdapter(RecyclerView.Adapter adapter) {
5151
if(!(adapter instanceof INameableAdapter)){
52-
throw new CustomExceptions.AdapterNotSetupForIndicatorException("INameableAdapter");
52+
throw new CustomExceptions.AdapterNotSetupForIndicatorException(adapter.getClass(), "INameableAdapter");
5353
}
5454
}
5555

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ class CustomExceptions {
2222

2323
static class AdapterNotSetupForIndicatorException extends RuntimeException {
2424

25-
AdapterNotSetupForIndicatorException(String shouldExtend){
26-
super("In order to add this indicator, the adapter for your recyclerView MUST implement " + shouldExtend + ".");
25+
AdapterNotSetupForIndicatorException(Class aClass, String shouldExtend){
26+
super("In order to add this indicator, the adapter for your recyclerView, " + aClass.getName() + ", MUST implement " + shouldExtend + ".");
2727
}
2828

2929
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ int getIndicatorWidth() {
6464
@Override
6565
void testAdapter(RecyclerView.Adapter adapter) {
6666
if(!(adapter instanceof ICustomAdapter)){
67-
throw new CustomExceptions.AdapterNotSetupForIndicatorException("ICustomAdapter");
67+
throw new CustomExceptions.AdapterNotSetupForIndicatorException(adapter.getClass(), "ICustomAdapter");
6868
}
6969
}
7070

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ int getIndicatorWidth() {
110110
@Override
111111
void testAdapter(RecyclerView.Adapter adapter) {
112112
if(!(adapter instanceof IDateableAdapter)){
113-
throw new CustomExceptions.AdapterNotSetupForIndicatorException("IDateableAdapter");
113+
throw new CustomExceptions.AdapterNotSetupForIndicatorException(adapter.getClass(), "IDateableAdapter");
114114
}
115115
}
116116

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

Lines changed: 23 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,8 @@
1616

1717
package com.turingtechnologies.materialscrollbar;
1818

19-
import android.animation.Animator;
20-
import android.animation.AnimatorListenerAdapter;
21-
import android.annotation.TargetApi;
2219
import android.content.Context;
2320
import android.content.res.TypedArray;
24-
import android.os.Build;
2521
import android.support.v4.view.ViewCompat;
2622
import android.support.v7.widget.RecyclerView;
2723
import android.util.AttributeSet;
@@ -31,6 +27,8 @@
3127
public class DragScrollBar extends MaterialScrollBar<DragScrollBar>{
3228

3329
Boolean draggableFromAnywhere = false;
30+
float handleOffset = 0;
31+
float indicatorOffset = 0;
3432

3533
public DragScrollBar(Context context, RecyclerView recyclerView, boolean lightOnTouch){
3634
super(context, recyclerView, lightOnTouch);
@@ -58,64 +56,28 @@ private boolean validTouch(MotionEvent event){
5856

5957
@Override
6058
void setTouchIntercept() {
59+
final Handle handle = super.handle;
6160
OnTouchListener otl = new OnTouchListener() {
6261
@Override
6362
public boolean onTouch(View v, MotionEvent event) {
6463
if (!hiddenByUser) {
6564
if(event.getAction() == MotionEvent.ACTION_DOWN && validTouch(event)){
6665
held = true;
66+
67+
indicatorOffset = event.getY() - handle.getY() - handle.getLayoutParams().height / 2;
68+
float offset2 = event.getY() - handle.getY();
69+
float balance = handle.getY() / scrollUtils.getAvailableScrollBarHeight();
70+
handleOffset = (offset2 * balance) + (indicatorOffset * (1 - balance));
6771
}
72+
//On Down
6873
if ((event.getAction() == MotionEvent.ACTION_MOVE || event.getAction() == MotionEvent.ACTION_DOWN) && held) {
69-
if (indicator != null && indicator.getVisibility() == INVISIBLE) {
70-
indicator.setVisibility(VISIBLE);
71-
if(Build.VERSION.SDK_INT >= 12){
72-
indicator.setAlpha(0F);
73-
indicator.animate().alpha(1F).setDuration(150).setListener(new AnimatorListenerAdapter() {
74-
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
75-
@Override
76-
public void onAnimationEnd(Animator animation) {
77-
super.onAnimationEnd(animation);
78-
79-
indicator.setAlpha(1F);
80-
}
81-
});
82-
}
83-
}
84-
int top = handle.getHeight() / 2;
85-
int bottom = recyclerView.getHeight() - Utils.getDP(72, recyclerView.getContext());
86-
float boundedY = Math.max(top, Math.min(bottom, event.getY()));
87-
scrollUtils.scrollToPositionAtProgress((boundedY - top) / (bottom - top));
88-
scrollUtils.scrollHandleAndIndicator();
89-
recyclerView.onScrolled(0, 0);
90-
91-
if (lightOnTouch) {
92-
handle.setBackgroundColor(handleColour);
93-
}
94-
74+
onDown(event);
9575
fadeIn();
76+
//On Up
9677
} else {
78+
onUp();
79+
9780
held = false;
98-
if (indicator != null && indicator.getVisibility() == VISIBLE) {
99-
if (Build.VERSION.SDK_INT <= 12) {
100-
indicator.clearAnimation();
101-
}
102-
if(Build.VERSION.SDK_INT >= 12){
103-
indicator.animate().alpha(0F).setDuration(150).setListener(new AnimatorListenerAdapter() {
104-
@Override
105-
public void onAnimationEnd(Animator animation) {
106-
super.onAnimationEnd(animation);
107-
108-
indicator.setVisibility(INVISIBLE);
109-
}
110-
});
111-
} else {
112-
indicator.setVisibility(INVISIBLE);
113-
}
114-
}
115-
116-
if (lightOnTouch) {
117-
handle.setBackgroundColor(handleOffColour);
118-
}
11981

12082
fadeOut();
12183
}
@@ -151,4 +113,14 @@ boolean getHide() {
151113

152114
@Override
153115
void implementFlavourPreferences(TypedArray a) {}
116+
117+
@Override
118+
float getHandleOffset(){
119+
return draggableFromAnywhere ? 0 : handleOffset;
120+
}
121+
122+
@Override
123+
float getIndicatorOffset(){
124+
return draggableFromAnywhere ? 0 : indicatorOffset;
125+
}
154126
}

0 commit comments

Comments
 (0)