Skip to content

Commit

Permalink
rect switch box added
Browse files Browse the repository at this point in the history
  • Loading branch information
Mahfa committed Mar 16, 2019
1 parent 4d48255 commit 00b91bb
Show file tree
Hide file tree
Showing 11 changed files with 57 additions and 76 deletions.
4 changes: 3 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.2'
classpath 'com.android.tools.build:gradle:3.3.2'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand All @@ -15,6 +16,7 @@ buildscript {
allprojects {
repositories {
jcenter()
google()
}
}

Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Wed Oct 21 11:34:03 PDT 2015
#Mon Jan 21 10:32:21 GMT+03:30 2019
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip
10 changes: 5 additions & 5 deletions library/build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
apply plugin: 'com.android.library'

android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
compileSdkVersion 28
buildToolsVersion '28.0.3'

defaultConfig {
minSdkVersion 14
targetSdkVersion 23
targetSdkVersion 26
versionCode 1
versionName "1.0"
}
Expand All @@ -19,6 +19,6 @@ android {
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.1.1'
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
}

This file was deleted.

43 changes: 38 additions & 5 deletions library/src/main/java/cn/refactor/library/SmoothCheckBox.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.Point;
import android.graphics.Rect;
import android.graphics.RectF;
import android.os.Build;
import android.os.Bundle;
import android.os.Parcelable;
Expand Down Expand Up @@ -53,15 +55,16 @@ public class SmoothCheckBox extends View implements Checkable {
private static final int DEF_ANIM_DURATION = 300;

private Paint mPaint, mTickPaint, mFloorPaint;
private RectF mRect, mFloorRect;
private Point[] mTickPoints;
private Point mCenterPoint;
private Path mTickPath;


private float mLeftLineDistance, mRightLineDistance, mDrewDistance;
private float mScaleVal = 1.0f, mFloorScale = 1.0f;
private int mWidth, mAnimDuration, mStrokeWidth;
private int mCheckedColor, mUnCheckedColor, mFloorColor, mFloorUnCheckedColor;
private boolean isRect;

private boolean mChecked;
private boolean mTickDrawing;
Expand Down Expand Up @@ -95,6 +98,7 @@ private void init(AttributeSet attrs) {
mCheckedColor = ta.getColor(R.styleable.SmoothCheckBox_color_checked, COLOR_CHECKED);
mUnCheckedColor = ta.getColor(R.styleable.SmoothCheckBox_color_unchecked, COLOR_UNCHECKED);
mStrokeWidth = ta.getDimensionPixelSize(R.styleable.SmoothCheckBox_stroke_width, CompatUtils.dp2px(getContext(), 0));
isRect = ta.getBoolean(R.styleable.SmoothCheckBox_is_rect, false);
ta.recycle();

mFloorUnCheckedColor = mFloorColor;
Expand All @@ -111,6 +115,9 @@ private void init(AttributeSet attrs) {
mPaint.setStyle(Paint.Style.FILL);
mPaint.setColor(mCheckedColor);

mRect = new RectF(0, 0, 0, 0);
mFloorRect = new RectF(0, 0, 0, 0);

mTickPath = new Path();
mCenterPoint = new Point();
mTickPoints = new Point[3];
Expand Down Expand Up @@ -175,6 +182,7 @@ public void setChecked(boolean checked) {

/**
* checked with animation
*
* @param checked checked
* @param animate change with animation
*/
Expand Down Expand Up @@ -261,14 +269,37 @@ protected void onDraw(Canvas canvas) {

private void drawCenter(Canvas canvas) {
mPaint.setColor(mUnCheckedColor);
float radius = (mCenterPoint.x - mStrokeWidth) * mScaleVal;
canvas.drawCircle(mCenterPoint.x, mCenterPoint.y, radius, mPaint);
if (isRect) {
float v = (mCenterPoint.x - mStrokeWidth) * mScaleVal;
mRect.set(
mCenterPoint.x - v,
mCenterPoint.y - v,
mCenterPoint.x + v,
mCenterPoint.y + v
);
canvas.drawRect(mRect, mPaint);
} else {
float radius = (mCenterPoint.x - mStrokeWidth) * mScaleVal;
canvas.drawCircle(mCenterPoint.x, mCenterPoint.y, radius, mPaint);
}
}

private void drawBorder(Canvas canvas) {
mFloorPaint.setColor(mFloorColor);
int radius = mCenterPoint.x;
canvas.drawCircle(mCenterPoint.x, mCenterPoint.y, radius * mFloorScale, mFloorPaint);
if (isRect) {
float v = mCenterPoint.x * mFloorScale;
mFloorRect.set(
mCenterPoint.x - v,
mCenterPoint.y - v,
mCenterPoint.x + v,
mCenterPoint.y + v
);
canvas.drawRect(mFloorRect, mFloorPaint);
} else {
int radius = mCenterPoint.x;
canvas.drawCircle(mCenterPoint.x, mCenterPoint.y, radius * mFloorScale, mFloorPaint);
}

}

private void drawTick(Canvas canvas) {
Expand Down Expand Up @@ -421,4 +452,6 @@ public void setOnCheckedChangeListener(OnCheckedChangeListener l) {
public interface OnCheckedChangeListener {
void onCheckedChanged(SmoothCheckBox checkBox, boolean isChecked);
}


}
1 change: 1 addition & 0 deletions library/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
<attr name="color_checked" format="color"/>
<attr name="color_unchecked" format="color"/>
<attr name="color_unchecked_stroke" format="color"/>
<attr name="is_rect" format="boolean"/>
</declare-styleable>
</resources>
15 changes: 0 additions & 15 deletions library/src/test/java/cn/refactor/library/ExampleUnitTest.java

This file was deleted.

12 changes: 6 additions & 6 deletions sample/build.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
compileSdkVersion 28
buildToolsVersion '28.0.3'

defaultConfig {
applicationId "cn.refactor.smoothcheckbox"
minSdkVersion 14
targetSdkVersion 23
targetSdkVersion 26
versionCode 1
versionName "1.0"
}
Expand All @@ -20,7 +20,7 @@ android {
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.1.1'
compile project(':library')
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation project(':library')
}

This file was deleted.

3 changes: 2 additions & 1 deletion sample/src/main/res/layout/activity_sample.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_margin="5dp"
app:color_checked="#447eeb" />
app:color_checked="#447eeb"
app:is_rect="true"/>

<cn.refactor.library.SmoothCheckBox
android:layout_width="40dp"
Expand Down

This file was deleted.

0 comments on commit 00b91bb

Please sign in to comment.