Skip to content

Commit

Permalink
Version 7.1.0
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
turing-tech committed Jan 30, 2016
1 parent ae3d68b commit a01c5ae
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 45 deletions.
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.TypedValue;
import android.view.Menu;
import android.view.MenuItem;

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

@Override
Expand Down
8 changes: 5 additions & 3 deletions lib/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
apply plugin: 'com.android.library'

def version = '7.1.0'

ext {
bintrayRepo = 'maven'
bintrayName = 'material-scroll-bar'
Expand All @@ -13,7 +15,7 @@ ext {
siteUrl = 'https://github.com/krimin-killr21/MaterialScrollBar'
gitUrl = 'https://github.com/krimin-killr21/MaterialScrollBar.git'

libraryVersion = '7.0.1'
libraryVersion = version

developerId = 'krimin-killr21'
developerName = 'Turing Technologies'
Expand All @@ -31,8 +33,8 @@ android {
defaultConfig {
minSdkVersion 7
targetSdkVersion 23
versionCode 14
versionName "7.0.1"
versionCode 15
versionName version
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@

import com.nineoldandroids.view.ViewHelper;

public class DragScrollBar extends MaterialScrollBar{
public class DragScrollBar extends MaterialScrollBar<DragScrollBar>{

public DragScrollBar(Context context, RecyclerView recyclerView, boolean lightOnTouch){
super(context, recyclerView, lightOnTouch);
}

@Override
void setTouchIntercept() {
handle.setOnTouchListener(new OnTouchListener() {
OnTouchListener otl = new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (!totallyHidden) {
Expand Down Expand Up @@ -94,7 +94,13 @@ public boolean onTouch(View v, MotionEvent event) {
}
return false;
}
});
};
//For APIs <8, the valid touch area will not follow the button and thus the entire bar must be a valid touch area
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB){
handle.setOnTouchListener(otl);
} else {
setOnTouchListener(otl);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,13 @@ public class Handle extends View {
RectF rectF;
Paint p = new Paint();
Integer mode;
boolean expanded = false;
Context context;

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

context = c;
mode = m;
p.setFlags(Paint.ANTI_ALIAS_FLAG);
}
Expand All @@ -45,6 +48,7 @@ public void setBackgroundColor(int color) {
}

public void collapseHandle(){
expanded = true;
rectF = new RectF(new Rect(getLeft(),getTop(),getLeft(),getBottom()));
invalidate();
}
Expand All @@ -55,7 +59,8 @@ protected void onAnimationEnd() {
}

public void expandHandle(){
rectF = new RectF(new Rect(getLeft() - 20,getTop(),getLeft() - 9,getBottom()));
expanded = false;
rectF = makeRect();
invalidate();
}

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

if(mode == 0){
rectF = new RectF(new Rect(getLeft() - 20,getTop(),getLeft() - 9,getBottom()));
rectF = makeRect();
}
}

private RectF makeRect(){
return new RectF(new Rect(getLeft() - Utils.getDP(11, context),getTop(),getLeft()-Utils.getDP(4, context),getBottom()));
}

@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);

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

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

canvas.drawArc(rectF, 335F, 360F, false, p);
canvas.drawArc(rectF, 90F, 180F, false, p); //335
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
import com.nineoldandroids.view.ViewHelper;

@SuppressLint("ViewConstructor")
abstract class MaterialScrollBar extends RelativeLayout {
abstract class MaterialScrollBar<T> extends RelativeLayout {

private View background;
Handle handle;
Expand Down Expand Up @@ -143,30 +143,30 @@ public MaterialScrollBar getMe(){
* Provides the ability to programmatically set the colour of the scrollbar handle.
* @param colour to set the handle.
*/
public MaterialScrollBar setHandleColour(String colour){
public T setHandleColour(String colour){
handleColour = Color.parseColor(colour);
setHandleColour();
return this;
return (T)this;
}

/**
* Provides the ability to programmatically set the colour of the scrollbar handle.
* @param colour to set the handle.
*/
public MaterialScrollBar setHandleColour(int colour){
public T setHandleColour(int colour){
handleColour = colour;
setHandleColour();
return this;
return (T)this;
}

/**
* Provides the ability to programmatically set the colour of the scrollbar handle.
* @param colourResId to set the handle.
*/
public MaterialScrollBar setHandleColourRes(int colourResId){
public T setHandleColourRes(int colourResId){
handleColour = ContextCompat.getColor(getContext(), colourResId);
setHandleColour();
return this;
return (T)this;
}

private void setHandleColour(){
Expand All @@ -182,126 +182,126 @@ private void setHandleColour(){
* Provides the ability to programmatically set the colour of the scrollbar handle when unpressed. Only applies if lightOnTouch is true.
* @param colour to set the handle when unpressed.
*/
public MaterialScrollBar setHandleOffColour(String colour){
public T setHandleOffColour(String colour){
handleOffColour = Color.parseColor(colour);
if(lightOnTouch){
handle.setBackgroundColor(handleOffColour);
}
return this;
return (T)this;
}

/**
* Provides the ability to programmatically set the colour of the scrollbar handle when unpressed. Only applies if lightOnTouch is true.
* @param colour to set the handle when unpressed.
*/
public MaterialScrollBar setHandleOffColour(int colour){
public T setHandleOffColour(int colour){
handleOffColour = colour;
if(lightOnTouch){
handle.setBackgroundColor(handleOffColour);
}
return this;
return (T)this;
}

/**
* Provides the ability to programmatically set the colour of the scrollbar handle when unpressed. Only applies if lightOnTouch is true.
* @param colourResId to set the handle when unpressed.
*/
public MaterialScrollBar setHandleOffColourRes(int colourResId){
public T setHandleOffColourRes(int colourResId){
handleOffColour = ContextCompat.getColor(getContext(), colourResId);
if(lightOnTouch){
handle.setBackgroundColor(handleOffColour);
}
return this;
return (T)this;
}

/**
* Provides the ability to programmatically set the colour of the scrollbar.
* @param colour to set the bar.
*/
public MaterialScrollBar setBarColour(String colour){
public T setBarColour(String colour){
background.setBackgroundColor(Color.parseColor(colour));
return this;
return (T)this;
}

/**
* Provides the ability to programmatically set the colour of the scrollbar.
* @param colour to set the bar.
*/
public MaterialScrollBar setBarColour(int colour){
public T setBarColour(int colour){
background.setBackgroundColor(colour);
return this;
return (T)this;
}

/**
* Provides the ability to programmatically set the colour of the scrollbar.
* @param colourResId to set the bar.
*/
public MaterialScrollBar setBarColourRes(int colourResId){
public T setBarColourRes(int colourResId){
background.setBackgroundColor(ContextCompat.getColor(getContext(), colourResId));
return this;
return (T)this;
}

/**
* Provides the ability to programmatically set the text colour of the indicator. Will do nothing if there is no section indicator.
* @param colour to set the text of the indicator.
*/
public MaterialScrollBar setTextColour(int colour){
public T setTextColour(int colour){
textColour = colour;
if(indicator != null){
indicator.setTextColour(textColour);
}
return this;
return(T)this;
}


/**
* Provides the ability to programmatically set the text colour of the indicator. Will do nothing if there is no section indicator.
* @param colourResId to set the text of the indicator.
*/
public MaterialScrollBar setTextColourRes(int colourResId){
public T setTextColourRes(int colourResId){
textColour = ContextCompat.getColor(getContext(), colourResId);
if(indicator != null){
indicator.setTextColour(textColour);
}
return this;
return (T)this;
}

/**
* Provides the ability to programmatically set the text colour of the indicator. Will do nothing if there is no section indicator.
* @param colour to set the text of the indicator.
*/
public MaterialScrollBar setTextColour(String colour){
public T setTextColour(String colour){
textColour = Color.parseColor(colour);
if(indicator != null){
indicator.setTextColour(textColour);
}
return this;
return (T)this;
}

/**
* Removes any indicator.
*/
public MaterialScrollBar removeIndicator(){
public T removeIndicator(){
this.indicator = null;
return this;
return (T)this;
}

/**
* Adds an indicator which accompanies this scroll bar.
*/
public MaterialScrollBar addIndicator(Indicator indicator, boolean addSpace) {
public T addIndicator(Indicator indicator, boolean addSpace) {
indicator.testAdapter(recyclerView.getAdapter());
this.indicator = indicator;
indicator.linkToScrollBar(this, addSpace);
indicator.setTextColour(textColour);
return this;
return (T)this;
}

/**
* Allows the developer to set a custom bar thickness.
* @param thickness The desired bar thickness.
*/
public MaterialScrollBar setBarThickness(int thickness){
public T setBarThickness(int thickness){
thickness = Utils.getDP(thickness, this);
LayoutParams layoutParams = (LayoutParams) handle.getLayoutParams();
layoutParams.width = thickness;
Expand All @@ -314,7 +314,7 @@ public MaterialScrollBar setBarThickness(int thickness){
if(indicator != null){
indicator.setSizeCustom(thickness);
}
return this;
return (T)this;
}

//Fetch accent colour on devices running Lollipop or newer.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

import com.nineoldandroids.view.ViewHelper;

public class TouchScrollBar extends MaterialScrollBar{
public class TouchScrollBar extends MaterialScrollBar<TouchScrollBar>{

boolean hide = true;
private int hideDuration = 2500;
Expand Down

0 comments on commit a01c5ae

Please sign in to comment.