Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
warkiz committed Sep 2, 2018
1 parent 0be6122 commit 26c45fe
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 47 deletions.
45 changes: 14 additions & 31 deletions app/src/main/java/com/warkiz/indicatorseekbar/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,34 @@
import com.warkiz.indicatorseekbar.fragment.IndicatorFragment;
import com.warkiz.indicatorseekbar.fragment.JavaBuildFragment;

import java.util.ArrayList;
import java.util.List;

/**
* created by zhuangguangquan on 2017/9/6
*/

public class MainActivity extends AppCompatActivity {

private static String[] sType = new String[]{"continuous", "discrete", "custom", "java", "indicator"};
private ContinuousFragment mContinuousFragment;
private DiscreteFragment mDiscreteFragment;
private CustomFragment mCustomFragment;
private Fragment mJavaBuildFragment;
private IndicatorFragment mIndicatorFragment;
private List<Fragment> mFragmentList = new ArrayList<>();

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initFragment();
initViews();
}

private void initFragment() {
mFragmentList.add(new ContinuousFragment());
mFragmentList.add(new DiscreteFragment());
mFragmentList.add(new CustomFragment());
mFragmentList.add(new JavaBuildFragment());
mFragmentList.add(new IndicatorFragment());
}

private void initViews() {
ViewPager viewPager = (ViewPager) findViewById(R.id.viewPager);
TabLayout tabLayout = (TabLayout) findViewById(R.id.tabLayout);
Expand All @@ -58,32 +66,7 @@ public PagerAdapter(FragmentManager fm) {

@Override
public Fragment getItem(int position) {
if (position == 0) {
if (mContinuousFragment == null) {
mContinuousFragment = new ContinuousFragment();
}
return mContinuousFragment;
} else if (position == 1) {
if (mDiscreteFragment == null) {
mDiscreteFragment = new DiscreteFragment();
}
return mDiscreteFragment;
} else if (position == 2) {
if (mCustomFragment == null) {
mCustomFragment = new CustomFragment();
}
return mCustomFragment;
} else if (position == 3) {
if (mJavaBuildFragment == null) {
mJavaBuildFragment = new JavaBuildFragment();
}
return mJavaBuildFragment;
}

if (mIndicatorFragment == null) {
mIndicatorFragment = new IndicatorFragment();
}
return mIndicatorFragment;
return mFragmentList.get(position);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ protected void initView(View root) {
IndicatorSeekBar scale = root.findViewById(R.id.scale);
scale.setDecimalScale(4);
View contentView = scale.getIndicator().getContentView();
Log.i("asasa", "initView: "+contentView.toString());

//thumb_drawable
IndicatorSeekBar thumb_drawable = root.findViewById(R.id.thumb_drawable);
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/res/layout/continuous.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,18 @@
android:layout_height="match_parent"
android:orientation="vertical">

<TextView
style="@style/title_text_style"
android:text="Continuous" />

<TextView
style="@style/subtitle_text_style"
android:text="1.default, progress = 50" />

<com.warkiz.widget.IndicatorSeekBar
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:isb_indicator_text_size="28sp"
app:isb_progress="50" />

<TextView
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/custom_indicator.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

<TextView
style="@style/title_text_style"
android:text="Custom_Indicator/stay_always" />
android:text="Custom Indicator, Indicator stay always" />

<TextView
style="@style/subtitle_text_style"
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/res/layout/discrete.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@

<TextView
style="@style/subtitle_text_style"
android:text="4. seek_smoothly=true, show_tick_marks_type=oval,\n customTickTexts" />
android:text="4. seek_smoothly=true, show_tick_marks_type=oval,\n customTickTexts,thumb_adjust_auto=false" />

<com.warkiz.widget.IndicatorSeekBar
android:id="@+id/custom_text"
Expand All @@ -71,6 +71,7 @@
app:isb_show_indicator="rounded_rectangle"
app:isb_show_tick_marks_type="oval"
app:isb_show_tick_texts="true"
app:isb_thumb_adjust_auto="false"
app:isb_ticks_count="7"
app:isb_track_progress_color="@color/color_blue" />

Expand Down
5 changes: 2 additions & 3 deletions app/src/main/res/layout/java_build.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
<ScrollView 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"
Expand All @@ -14,7 +13,7 @@

<TextView
style="@style/title_text_style"
android:text="Java_Build" />
android:text="Build by java code" />

</LinearLayout>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import android.text.TextPaint;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewParent;
Expand Down Expand Up @@ -197,7 +196,7 @@ private void initAttrs(Context context, AttributeSet attrs) {
//thumb
mThumbSize = ta.getDimensionPixelSize(R.styleable.IndicatorSeekBar_isb_thumb_size, builder.thumbSize);
mThumbDrawable = ta.getDrawable(R.styleable.IndicatorSeekBar_isb_thumb_drawable);
mAdjustAuto = ta.getBoolean(R.styleable.IndicatorSeekBar_isb_thumb_adjust_auto,true);
mAdjustAuto = ta.getBoolean(R.styleable.IndicatorSeekBar_isb_thumb_adjust_auto, true);
initThumbColor(ta.getColorStateList(R.styleable.IndicatorSeekBar_isb_thumb_color), builder.thumbColor);
//thumb text
mShowThumbText = ta.getBoolean(R.styleable.IndicatorSeekBar_isb_show_thumb_text, builder.showThumbText);
Expand Down Expand Up @@ -233,9 +232,6 @@ private void initAttrs(Context context, AttributeSet attrs) {
}

private void initParams() {
if (mTicksCount < 0 || mTicksCount > 50) {
throw new IllegalArgumentException("the Argument: TICK COUNT must be limited between 0-50, Now is " + mTicksCount);
}
initProgressRangeValue();
if (mBackgroundTrackSize > mProgressTrackSize) {
mBackgroundTrackSize = mProgressTrackSize;
Expand Down Expand Up @@ -266,6 +262,9 @@ private void initParams() {
}

private void collectTicksInfo() {
if (mTicksCount < 0 || mTicksCount > 50) {
throw new IllegalArgumentException("the Argument: TICK COUNT must be limited between (0-50), Now is " + mTicksCount);
}
if (mTicksCount != 0) {
mTickMarksX = new float[mTicksCount];
if (mShowTickText) {
Expand Down Expand Up @@ -391,11 +390,11 @@ private void initTextsArray() {
if (mTicksCount == 0) {
return;
}
if (mShowTickText) {
mTickTextsArr = new String[mTicksCount];
}
for (int i = 0; i < mTickMarksX.length; i++) {
if (mShowTickText) {
if (mTickTextsArr == null) {
mTickTextsArr = new String[mTicksCount];
}
mTickTextsArr[i] = getTickTextByPosition(i);
mTextPaint.getTextBounds(mTickTextsArr[i], 0, mTickTextsArr[i].length(), mRect);
mTickTextsWidth[i] = mRect.width();
Expand Down Expand Up @@ -1374,7 +1373,7 @@ private boolean autoAdjustThumb() {
if (mTicksCount < 3 || !mSeekSmoothly) {//it is not necessary to adjust while count less than 3 .
return false;
}
if (!mAdjustAuto){
if (!mAdjustAuto) {
return false;
}
final int closestIndex = getClosestIndex();
Expand Down Expand Up @@ -1977,8 +1976,13 @@ public void setUserSeekAble(boolean seekAble) {
* @param tickCount
*/
public synchronized void setTickCount(int tickCount) {
if (mTicksCount < 0 || mTicksCount > 50) {
throw new IllegalArgumentException("the Argument: TICK COUNT must be limited between (0-50), Now is " + mTicksCount);
}
mTicksCount = tickCount;
initParams();
collectTicksInfo();
initTextsArray();
initSeekBarInfo();
refreshSeekBarLocation();
invalidate();
updateStayIndicator();
Expand Down

0 comments on commit 26c45fe

Please sign in to comment.