Skip to content
This repository was archived by the owner on Feb 28, 2024. It is now read-only.

Dev #102

Merged
merged 23 commits into from
May 14, 2015
Merged

Dev #102

Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
6e31290
Fix scroll bug in DatePicker class due to not handle touch event in M…
Apr 10, 2015
14a92b8
Fix bug not set neutralActionClickListener in onCreateDialog() of Dia…
rey5137 Apr 16, 2015
f02ff96
Fix bug not remove prefix when load font from asset folder in Typefac…
rey5137 Apr 16, 2015
faa73c1
Fix bug Null Metrics in ContactChipSpan, ContactChipDrawable class.
rey5137 Apr 23, 2015
b73f730
Add getSelectedItem() method to Spinner class.
rey5137 May 6, 2015
f65c0cb
Add support for tp_24Hour attribute to TimePickerDialog class.
rey5137 May 6, 2015
b28f4ec
Fix bug not support pv_progress, pv_secondaryProgress, pv_progressMod…
rey5137 May 7, 2015
d44ffd4
Change rd_delayClick to integer attribute.
rey5137 May 7, 2015
c4adbc7
Fix bug menuView == null in ToolbarManager class.
rey5137 May 8, 2015
4c46682
Add tp_leadingZero attribute for TimePickerDialog class.
rey5137 May 8, 2015
c4fe8cc
Add support RTL to Spinner class.
rey5137 May 8, 2015
26bfca8
Fix bug not check mArrowDrawable null in showPopup() and onPopupDismi…
rey5137 May 11, 2015
69e4f5f
Add support RTL to Switch class.
rey5137 May 11, 2015
8113733
Add support RTL to Slider class.
rey5137 May 11, 2015
6b9e37e
Add support RTL to EditText class.
rey5137 May 11, 2015
d24e533
Add support RTL to SnackBar class.
rey5137 May 11, 2015
4728490
Add support RTL to Dialog and SimpleDialog class.
rey5137 May 11, 2015
197f3ad
Fix bug text not center on Lolipop of YearPicker class.
rey5137 May 12, 2015
dd929a5
Add support for arabic number to Picker classes.
rey5137 May 12, 2015
3337951
Add lmd_layoutDirection attribute to LineMorphingDrawable class.
rey5137 May 12, 2015
53b3ee0
Add setBackground(0 method to ViewUtil class.
rey5137 May 13, 2015
e8717e5
Change sb_marginLeft attribute to sb_marginStart.
May 13, 2015
3737a2e
Add javadoc.
May 14, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add support RTL to Slider class.
rey5137 committed May 11, 2015
commit 81137330bacd03af820a7f163214633db3aebb05
37 changes: 28 additions & 9 deletions lib/src/main/java/com/rey/material/widget/Slider.java
Original file line number Diff line number Diff line change
@@ -80,6 +80,8 @@ public class Slider extends View{
private ThumbStrokeAnimator mThumbStrokeAnimator;
private ThumbMoveAnimator mThumbMoveAnimator;

private boolean mIsRtl = false;

/**
* Interface definition for a callback to be invoked when thumb's position changed.
*/
@@ -351,6 +353,15 @@ public int getSuggestedMinimumHeight() {
return (mDiscreteMode ? (int)(mThumbRadius * (4 + Math.sqrt(2))) : mThumbFocusRadius * 2) + getPaddingTop() + getPaddingBottom();
}

@Override
public void onRtlPropertiesChanged(int layoutDirection) {
boolean rtl = layoutDirection == LAYOUT_DIRECTION_RTL;
if(mIsRtl != rtl) {
mIsRtl = rtl;
invalidate();
}
}

@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
mDrawRect.left = getPaddingLeft() + mThumbRadius;
@@ -432,24 +443,29 @@ public boolean onTouchEvent(@NonNull MotionEvent event) {
if(!isEnabled())
return false;

float x = event.getX();
float y = event.getY();
if(mIsRtl)
x = 2 * mDrawRect.centerX() - x;

switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
mIsDragging = isThumbHit(event.getX(), event.getY(), mThumbRadius) && !mThumbMoveAnimator.isRunning();
mMemoPoint.set(event.getX(), event.getY());
mIsDragging = isThumbHit(x, y, mThumbRadius) && !mThumbMoveAnimator.isRunning();
mMemoPoint.set(x, y);
if(mIsDragging)
mThumbRadiusAnimator.startAnimation(mDiscreteMode ? 0 : mThumbFocusRadius);
break;
case MotionEvent.ACTION_MOVE:
if(mIsDragging) {
if(mDiscreteMode) {
float position = correctPosition(Math.min(1f, Math.max(0f, (event.getX() - mDrawRect.left) / mDrawRect.width())));
float position = correctPosition(Math.min(1f, Math.max(0f, (x - mDrawRect.left) / mDrawRect.width())));
setPosition(position, true, true, true);
}
else{
float offset = (event.getX() - mMemoPoint.x) / mDrawRect.width();
float offset = (x - mMemoPoint.x) / mDrawRect.width();
float position = Math.min(1f, Math.max(0f, mThumbPosition + offset));
setPosition(position, false, true, true);
mMemoPoint.x = event.getX();
mMemoPoint.x = x;
invalidate();
}
}
@@ -459,8 +475,8 @@ public boolean onTouchEvent(@NonNull MotionEvent event) {
mIsDragging = false;
setPosition(getPosition(), true, true, true);
}
else if(distance(mMemoPoint.x, mMemoPoint.y, event.getX(), event.getY()) <= mTouchSlop){
float position = correctPosition(Math.min(1f, Math.max(0f, (event.getX() - mDrawRect.left) / mDrawRect.width())));
else if(distance(mMemoPoint.x, mMemoPoint.y, x, y) <= mTouchSlop){
float position = correctPosition(Math.min(1f, Math.max(0f, (x - mDrawRect.left) / mDrawRect.width())));
setPosition(position, true, true, true);
}
break;
@@ -627,16 +643,19 @@ public void draw(@NonNull Canvas canvas) {
super.draw(canvas);

float x = mDrawRect.width() * mThumbPosition + mDrawRect.left;
if(mIsRtl)
x = 2 * mDrawRect.centerX() - x;
float y = mDrawRect.centerY();
int filledPrimaryColor = ColorUtil.getMiddleColor(mSecondaryColor, isEnabled() ? mPrimaryColor : mSecondaryColor, mThumbFillPercent);

getTrackPath(x, y, mThumbCurrentRadius);
mPaint.setStyle(Paint.Style.FILL);
mPaint.setColor(mSecondaryColor);
mPaint.setColor(mIsRtl ? filledPrimaryColor : mSecondaryColor);
canvas.drawPath(mRightTrackPath, mPaint);
mPaint.setColor(filledPrimaryColor);
mPaint.setColor(mIsRtl ? mSecondaryColor : filledPrimaryColor);
canvas.drawPath(mLeftTrackPath, mPaint);

mPaint.setColor(filledPrimaryColor);
if(mDiscreteMode){
float factor = 1f - mThumbCurrentRadius / mThumbRadius;

8 changes: 2 additions & 6 deletions lib/src/main/java/com/rey/material/widget/Switch.java
Original file line number Diff line number Diff line change
@@ -435,11 +435,9 @@ private void getTrackPath(float x, float y, float radius){
public void draw(@NonNull Canvas canvas) {
super.draw(canvas);

int save = canvas.save();
if(mIsRtl)
canvas.scale(-1f, 1f, mDrawRect.centerX(), mDrawRect.centerY());

float x = (mDrawRect.width() - mThumbRadius * 2) * mThumbPosition + mDrawRect.left + mThumbRadius;
if(mIsRtl)
x = 2 * mDrawRect.centerX() - x;
float y = mDrawRect.centerY();

getTrackPath(x, y, mThumbRadius);
@@ -457,8 +455,6 @@ public void draw(@NonNull Canvas canvas) {
mPaint.setColor(ColorUtil.getMiddleColor(getThumbColor(false), getThumbColor(true), mThumbPosition));
mPaint.setStyle(Paint.Style.FILL);
canvas.drawCircle(x, y, mThumbRadius, mPaint);

canvas.restoreToCount(save);
}

private void resetAnimation(){