Skip to content

Commit

Permalink
Stopped pins appearing on initialisation when temporary. Margin corre…
Browse files Browse the repository at this point in the history
…ct even if pin radius = 0. PR to correct motion down
  • Loading branch information
Oli committed Nov 11, 2015
1 parent 3c7b24b commit 7b1bf56
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 29 deletions.
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ Developers can customize the following attributes (both via XML and programatica

### Change Log
```
1.3 - Stopped pins appearing on initialisation when temporary. Margin correct even if pin radius = 0. PR to correct motion down
1.2 - NPE fixed for movePin
1.1 - Merged pull requests
1.0 - Merged pull requests to fix range bar issues and issues in scrollview, promoted to 1.0 release due to few other PRs.
0.1 - released onto Maven Central. Fixed color pickers in sample. Added ability to set pin color via XML and pin text color via XML or programatically
Expand All @@ -35,7 +37,7 @@ tickColor | color
```
rangeBar | boolean
barWeight | dimension
barColor | reference or color
rangeBarColor | reference or color
barPaddingBottom | dimension
connectingLineWeight | dimension
connectingLineColor | reference or color
Expand All @@ -47,6 +49,7 @@ pinPadding | dimension
pinRadius | dimension
pinColor | reference or color
textColor | reference or color
temporaryPins | boolean
```

### Selector Properties
Expand Down Expand Up @@ -123,7 +126,7 @@ Installation

```groovy
dependencies {
compile 'com.appyvet:materialrangebar:1.1'
compile 'com.appyvet:materialrangebar:1.3'
}
```

Expand Down
1 change: 1 addition & 0 deletions RangeBarSample/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
custom:tickStart="5"
custom:tickInterval="1"
custom:tickEnd="10"
custom:temporaryPins="false"
custom:pinMaxFont="10sp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,14 +264,9 @@ public void onStopTrackingTouch(SeekBar seekBar) {
SeekBar thumbRadiusSeek = (SeekBar) findViewById(R.id.thumbRadiusSeek);
thumbRadiusSeek.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar thumbRadiusSeek, int progress, boolean fromUser) {
if (progress == 0) {
rangebar.setPinRadius(-1);
thumbRadius.setText("Pin Radius = 30");
} else {
public void onProgressChanged(SeekBar thumbRadiusSeek, int progress, boolean fromUser){
rangebar.setPinRadius(progress);
thumbRadius.setText("Pin Radius = " + progress);
}
}

@Override
Expand Down
4 changes: 2 additions & 2 deletions rangebar/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.appyvet.rangebar"
android:versionCode="1"
android:versionName="1.0">
android:versionCode="2"
android:versionName="1.1">

</manifest>
4 changes: 2 additions & 2 deletions rangebar/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ apply plugin: 'maven'
apply plugin: 'signing'
apply from: '../maven_push.gradle'

version = "1.1"
version = "1.3"
group = "com.appyvet"
dependencies {
compile 'com.android.support:support-v4:23.0.1'
compile 'com.android.support:support-v4:23.1.0'
}
android {

Expand Down
18 changes: 12 additions & 6 deletions rangebar/src/com/appyvet/rangebar/PinView.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.support.v4.content.ContextCompat;
import android.util.Log;
import android.util.TypedValue;
import android.view.View;

Expand Down Expand Up @@ -90,6 +89,10 @@ class PinView extends View {

private float mMaxPinFont = RangeBar.DEFAULT_MAX_PIN_FONT_SP;

private boolean mPinsAreTemporary;

private boolean mHasBeenPressed = false;

// Constructors ////////////////////////////////////////////////////////////

public PinView(Context context) {
Expand All @@ -112,17 +115,20 @@ public void setFormatter(IRangeBarFormatter mFormatter) {
* @param pinColor the color of the pin
* @param textColor the color of the value text in the pin
* @param circleRadius the radius of the selector circle
* @param circleColor the color of the selector circle
* @param minFont the minimum font size for the pin text
* @param maxFont the maximum font size for the pin text
* @param pinsAreTemporary whether to show the pin initially or just the circle
*/
public void init(Context ctx, float y, float pinRadiusDP, int pinColor, int textColor,
float circleRadius, int circleColor, float minFont, float maxFont) {
float circleRadius, int circleColor, float minFont, float maxFont, boolean pinsAreTemporary) {

mRes = ctx.getResources();
mPin = ContextCompat.getDrawable(ctx, R.drawable.rotate);
mPin = ContextCompat.getDrawable(ctx, R.drawable.rotate);

mDensity = getResources().getDisplayMetrics().density;
mMinPinFont = minFont / mDensity;
mMaxPinFont = maxFont / mDensity;
mPinsAreTemporary = pinsAreTemporary;

mPinPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
15, mRes.getDisplayMetrics());
Expand Down Expand Up @@ -214,6 +220,7 @@ public boolean isPressed() {
*/
public void press() {
mIsPressed = true;
mHasBeenPressed = true;
}

/**
Expand Down Expand Up @@ -254,7 +261,7 @@ public boolean isInTargetZone(float x, float y) {
public void draw(Canvas canvas) {
canvas.drawCircle(mX, mY, mCircleRadiusPx, mCirclePaint);
//Draw pin if pressed
if (mPinRadiusPx > 0) {
if (mPinRadiusPx > 0 && (mHasBeenPressed || !mPinsAreTemporary)) {
mBounds.set((int) mX - mPinRadiusPx,
(int) mY - (mPinRadiusPx * 2) - (int) mPinPadding,
(int) mX + mPinRadiusPx, (int) mY - (int) mPinPadding);
Expand Down Expand Up @@ -291,7 +298,6 @@ private void calibrateTextSize(Paint paint, String text, float boxWidth) {
} else if (estimatedFontSize > mMaxPinFont) {
estimatedFontSize = mMaxPinFont;
}
Log.d("pin", "size = " + estimatedFontSize * mDensity);
paint.setTextSize(estimatedFontSize * mDensity);
}
}
46 changes: 35 additions & 11 deletions rangebar/src/com/appyvet/rangebar/RangeBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -349,15 +349,15 @@ protected void onSizeChanged(int w, int h, int oldw, int oldh) {
mLeftThumb = new PinView(ctx);
mLeftThumb.setFormatter(mFormatter);
mLeftThumb.init(ctx, yPos, expandedPinRadius, mPinColor, mTextColor, mCircleSize,
mCircleColor, mMinPinFont, mMaxPinFont);
mCircleColor, mMinPinFont, mMaxPinFont, mArePinsTemporary);
}
mRightThumb = new PinView(ctx);
mRightThumb.setFormatter(mFormatter);
mRightThumb.init(ctx, yPos, expandedPinRadius, mPinColor, mTextColor, mCircleSize,
mCircleColor, mMinPinFont, mMaxPinFont);
mCircleColor, mMinPinFont, mMaxPinFont, mArePinsTemporary);

// Create the underlying bar.
final float marginLeft = mExpandedPinRadius;
final float marginLeft = Math.max(mExpandedPinRadius, mCircleSize);

final float barLength = w - (2 * marginLeft);
mBar = new Bar(ctx, marginLeft, yPos, barLength, mTickCount, mTickHeightDP, mTickColor,
Expand Down Expand Up @@ -431,6 +431,10 @@ public boolean onTouchEvent(MotionEvent event) {
return true;

case MotionEvent.ACTION_UP:
this.getParent().requestDisallowInterceptTouchEvent(false);
onActionUp(event.getX(), event.getY());
return true;

case MotionEvent.ACTION_CANCEL:
this.getParent().requestDisallowInterceptTouchEvent(false);
onActionUp(event.getX(), event.getY());
Expand Down Expand Up @@ -477,7 +481,7 @@ public void setOnRangeBarChangeListener(OnRangeBarChangeListener listener) {
* Sets a listener to modify the text
*
* @param mPinTextListener the RangeBar pin text notification listener; null to remove any
* existing listener
* existing listener
*/
public void setPinTextListener(OnRangeBarTextListener mPinTextListener) {
this.mPinTextListener = mPinTextListener;
Expand Down Expand Up @@ -689,7 +693,8 @@ public void setRangeBarEnabled(boolean isRangeBar) {
/**
* Set if the pins should dissapear after released
*
* @param arePinsTemporary Boolean - true if pins shoudl dissapear after released, false to stay
* @param arePinsTemporary Boolean - true if pins shoudl dissapear after released, false to
* stay
* drawn
*/
public void setTemporaryPins(boolean arePinsTemporary) {
Expand Down Expand Up @@ -934,6 +939,24 @@ public boolean isRangeBar() {
return mIsRangeBar;
}

/**
* Gets the value of the left pin.
*
* @return the string value of the left pin.
*/
public String getLeftPinValue() {
return getPinValue(mLeftIndex);
}

/**
* Gets the value of the right pin.
*
* @return the string value of the right pin.
*/
public String getRightPinValue() {
return getPinValue(mRightIndex);
}

/**
* Gets the index of the left-most pin.
*
Expand Down Expand Up @@ -1055,8 +1078,9 @@ private void rangeBarInit(Context context, AttributeSet attrs) {
mConnectingLineColor = ta.getColor(R.styleable.RangeBar_connectingLineColor,
DEFAULT_CONNECTING_LINE_COLOR);
mActiveConnectingLineColor = mConnectingLineColor;
mExpandedPinRadius = ta.getDimension(R.styleable.RangeBar_pinRadius,
TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
mExpandedPinRadius = ta
.getDimension(R.styleable.RangeBar_pinRadius, TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_DIP,
DEFAULT_EXPANDED_PIN_RADIUS_DP, getResources().getDisplayMetrics()));
mPinPadding = ta.getDimension(R.styleable.RangeBar_pinPadding, TypedValue
.applyDimension(TypedValue.COMPLEX_UNIT_DIP, DEFAULT_PIN_PADDING_DP,
Expand Down Expand Up @@ -1117,12 +1141,12 @@ private void createPins() {
if (mIsRangeBar) {
mLeftThumb = new PinView(ctx);
mLeftThumb.init(ctx, yPos, 0, mPinColor, mTextColor, mCircleSize, mCircleColor,
mMinPinFont, mMaxPinFont);
mMinPinFont, mMaxPinFont, false);
}
mRightThumb = new PinView(ctx);
mRightThumb
.init(ctx, yPos, 0, mPinColor, mTextColor, mCircleSize, mCircleColor, mMinPinFont,
mMaxPinFont);
mMaxPinFont, false);

float marginLeft = getMarginLeft();
float barLength = getBarLength();
Expand All @@ -1144,7 +1168,7 @@ private void createPins() {
* @return float marginLeft
*/
private float getMarginLeft() {
return mExpandedPinRadius;
return Math.max(mExpandedPinRadius, mCircleSize);
}

/**
Expand Down Expand Up @@ -1422,7 +1446,7 @@ private void movePin(PinView thumb, float x) {
// do not move the thumbs past the edge.
if (x < mBar.getLeftX() || x > mBar.getRightX()) {
// Do nothing.
} else {
} else if (thumb != null) {
thumb.setX(x);
invalidate();
}
Expand Down

0 comments on commit 7b1bf56

Please sign in to comment.