Skip to content

Commit

Permalink
v1.0.3_add restore min&max value methods
Browse files Browse the repository at this point in the history
  • Loading branch information
zouyulong committed Dec 11, 2017
1 parent cda684c commit 09ac423
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,23 @@

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;

public class MainActivity extends AppCompatActivity {
import com.zyl.customrangeseekbar.CustomRangeSeekBar;

public class MainActivity extends AppCompatActivity {
CustomRangeSeekBar mSeekbar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mSeekbar = (CustomRangeSeekBar) findViewById(R.id.seekbar_time);
findViewById(R.id.btn_restore).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mSeekbar.restorePercentSelectedMinValue();
mSeekbar.restorePercentSelectedMaxValue();
}
});
}
}
9 changes: 6 additions & 3 deletions CustomRangeSeekBar/app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:rangeseekbar="http://schemas.android.com/apk/res-auto"
tools:context="com.zyl.myapplication.MainActivity">
xmlns:rangeseekbar="http://schemas.android.com/apk/res-auto">

<com.zyl.customrangeseekbar.CustomRangeSeekBar
android:id="@+id/seekbar_time"
Expand Down Expand Up @@ -40,4 +38,9 @@
rangeseekbar:betweenAbsoluteValue="2000"
/>

<Button
android:id="@+id/btn_restore"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="还原时间选取控件滑块"/>
</RelativeLayout>
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ public class CustomRangeSeekBar extends View {
private int mWordHeight;
//文本字体大小
private float mWordSize;

private float mStartMinPercent;
private float mStartMaxPercent;
public CustomRangeSeekBar(Context context) {
super(context);
}
Expand All @@ -80,8 +81,8 @@ public CustomRangeSeekBar(Context context, AttributeSet attrs) {
TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.CustomRangeSeekBar, 0, 0);
mAbsoluteMinValue = a.getFloat(R.styleable.CustomRangeSeekBar_absoluteMin, (float) 0.0);
mAbsoluteMaxValue = a.getFloat(R.styleable.CustomRangeSeekBar_absolutemMax, (float) 100.0);
float startMinPercent = a.getFloat(R.styleable.CustomRangeSeekBar_startMinPercent, 0);
float startMaxPercent = a.getFloat(R.styleable.CustomRangeSeekBar_startMaxPercent, 1);
mStartMinPercent = a.getFloat(R.styleable.CustomRangeSeekBar_startMinPercent, 0);
mStartMaxPercent = a.getFloat(R.styleable.CustomRangeSeekBar_startMaxPercent, 1);
mThumbImage = BitmapFactory.decodeResource(getResources(), a.getResourceId(R.styleable.CustomRangeSeekBar_thumbImage, R.mipmap.btn_seekbar_normal));
mProgressBarBg = BitmapFactory.decodeResource(getResources(), a.getResourceId(R.styleable.CustomRangeSeekBar_progressBarBg, R.mipmap.seekbar_bg));
mProgressBarSelBg = BitmapFactory.decodeResource(getResources(), a.getResourceId(R.styleable.CustomRangeSeekBar_progressBarSelBg, R.mipmap.seekbar_sel_bg));
Expand All @@ -97,11 +98,25 @@ public CustomRangeSeekBar(Context context, AttributeSet attrs) {
mWidthPadding = mThumbHalfHeight;
Paint.FontMetrics metrics = mPaint.getFontMetrics();
mWordHeight = (int) (metrics.descent - metrics.ascent);
setPercentSelectedMinValue(startMinPercent);
setPercentSelectedMaxValue(startMaxPercent);
restorePercentSelectedMinValue();
restorePercentSelectedMaxValue();
a.recycle();
}

/**
* 还原min滑块到初始值
*/
public void restorePercentSelectedMinValue(){
setPercentSelectedMinValue(mStartMinPercent);
}

/**
* 还原max滑块到初始值
*/
public void restorePercentSelectedMaxValue(){
setPercentSelectedMaxValue(mStartMaxPercent);
}

@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ build.gradle in app module

```
dependencies {
compile 'com.github.zyl409214686:CustomRangeSeekBar:v1.0.1'
compile 'com.github.zyl409214686:CustomRangeSeekBar:v1.0.3'
}
```

Expand Down Expand Up @@ -68,7 +68,8 @@ dependencies {
| version | message |
| :-----: | :--------------------------------------- |
| v1.0.1 | add startMinPercent、startMaxPercent Attributes |
| v1.0.2 | add demo module and refactor code |
| v1.0.2 | add demo module and refactor code |
| v1.0.3 | add restore min&max selected value methods |



Expand Down

0 comments on commit 09ac423

Please sign in to comment.