diff --git a/README.md b/README.md index abd788b..b69096a 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,9 @@ # SpringIndicator +![icon](https://raw.githubusercontent.com/chenupt/SpringIndicator/master/img/icon.png) + An indicator like Morning Routine guide.It was originally based on [BezierDemo](https://github.com/chenupt/BezierDemo). -The sample app: [click me](https://github.com/chenupt/SpringIndicator/raw/master/img/springindicator_1.0.0.apk) +The sample app: [click me](https://github.com/chenupt/SpringIndicator/raw/master/img/springindicator_1.0.1.apk) ![gif](https://raw.githubusercontent.com/chenupt/SpringIndicator/master/img/si_1.0.0.gif) @@ -10,7 +12,7 @@ The sample app: [click me](https://github.com/chenupt/SpringIndicator/raw/master Add the dependency to your build.gradle. ``` dependencies { - compile 'com.github.chenupt.android:springindicator:1.0.0@aar' + compile 'com.github.chenupt.android:springindicator:1.0.1@aar' } ``` Add the indicator to your layout. @@ -18,11 +20,11 @@ Add the indicator to your layout. ``` diff --git a/img/icon.png b/img/icon.png new file mode 100755 index 0000000..a57cf5b Binary files /dev/null and b/img/icon.png differ diff --git a/img/springindicator_1.0.1.apk b/img/springindicator_1.0.1.apk new file mode 100644 index 0000000..173b104 Binary files /dev/null and b/img/springindicator_1.0.1.apk differ diff --git a/lib/build.gradle b/lib/build.gradle index 01598ae..2fb2600 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -26,7 +26,7 @@ apply plugin: 'maven' ext { groupId = 'com.github.chenupt.android' artifactId = 'springindicator' - version = '1.0.0-SNAPSHOT' + version = '1.0.1-SNAPSHOT' } configurations { diff --git a/lib/src/main/java/github/chenupt/springindicator/SpringIndicator.java b/lib/src/main/java/github/chenupt/springindicator/SpringIndicator.java index 38d7035..c153935 100644 --- a/lib/src/main/java/github/chenupt/springindicator/SpringIndicator.java +++ b/lib/src/main/java/github/chenupt/springindicator/SpringIndicator.java @@ -84,14 +84,14 @@ private void initAttrs(AttributeSet attrs){ radiusMin = getResources().getDimension(R.dimen.si_default_radius_min); TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.SpringIndicator); - textColorId = a.getResourceId(R.styleable.SpringIndicator_textColor, textColorId); - selectedTextColorId = a.getResourceId(R.styleable.SpringIndicator_selectedTextColor, selectedTextColorId); - textSize = a.getDimension(R.styleable.SpringIndicator_textSize, textSize); - textBgResId = a.getResourceId(R.styleable.SpringIndicator_textBg, 0); - indicatorColorId = a.getResourceId(R.styleable.SpringIndicator_indicatorColor, indicatorColorId); - indicatorColorsId = a.getResourceId(R.styleable.SpringIndicator_indicatorColors, 0); - radiusMax = a.getDimension(R.styleable.SpringIndicator_radiusMax, radiusMax); - radiusMin = a.getDimension(R.styleable.SpringIndicator_radiusMin, radiusMin); + textColorId = a.getResourceId(R.styleable.SpringIndicator_siTextColor, textColorId); + selectedTextColorId = a.getResourceId(R.styleable.SpringIndicator_siSelectedTextColor, selectedTextColorId); + textSize = a.getDimension(R.styleable.SpringIndicator_siTextSize, textSize); + textBgResId = a.getResourceId(R.styleable.SpringIndicator_siTextBg, 0); + indicatorColorId = a.getResourceId(R.styleable.SpringIndicator_siIndicatorColor, indicatorColorId); + indicatorColorsId = a.getResourceId(R.styleable.SpringIndicator_siIndicatorColors, 0); + radiusMax = a.getDimension(R.styleable.SpringIndicator_siRadiusMax, radiusMax); + radiusMin = a.getDimension(R.styleable.SpringIndicator_siRadiusMin, radiusMin); a.recycle(); if(indicatorColorsId != 0){ @@ -292,7 +292,7 @@ public List getTabs(){ return tabs; } - public void setOnPagerChangeListener(ViewPager.OnPageChangeListener listener){ + public void setOnPageChangeListener(ViewPager.OnPageChangeListener listener){ this.delegateListener = listener; } diff --git a/lib/src/main/java/github/chenupt/springindicator/SpringView.java b/lib/src/main/java/github/chenupt/springindicator/SpringView.java index be8c2c1..1624cac 100644 --- a/lib/src/main/java/github/chenupt/springindicator/SpringView.java +++ b/lib/src/main/java/github/chenupt/springindicator/SpringView.java @@ -20,10 +20,8 @@ import android.animation.ObjectAnimator; import android.content.Context; import android.graphics.Canvas; -import android.graphics.Color; import android.graphics.Paint; import android.graphics.Path; -import android.graphics.PorterDuff; import android.util.AttributeSet; import android.view.View; import android.view.animation.OvershootInterpolator; @@ -101,7 +99,6 @@ private void makePath(){ @Override protected void onDraw(Canvas canvas) { makePath(); - canvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.OVERLAY); canvas.drawPath(path, paint); canvas.drawCircle(headPoint.getX(), headPoint.getY(), headPoint.getRadius(), paint); canvas.drawCircle(footPoint.getX(), footPoint.getY(), footPoint.getRadius(), paint); diff --git a/lib/src/main/java/github/chenupt/springindicator/viewpager/FixedSpeedScroller.java b/lib/src/main/java/github/chenupt/springindicator/viewpager/FixedSpeedScroller.java new file mode 100644 index 0000000..5a71437 --- /dev/null +++ b/lib/src/main/java/github/chenupt/springindicator/viewpager/FixedSpeedScroller.java @@ -0,0 +1,61 @@ +/* + * Copyright 2015 chenupt + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package github.chenupt.springindicator.viewpager; + +import android.content.Context; +import android.view.animation.Interpolator; +import android.widget.Scroller; + +public class FixedSpeedScroller extends Scroller { + + private int mDuration = 1000; + boolean useFixedSpeed = false; + + public FixedSpeedScroller(Context context) { + super(context); + } + + public FixedSpeedScroller(Context context, Interpolator interpolator) { + super(context, interpolator); + } + + public FixedSpeedScroller(Context context, Interpolator interpolator, boolean flywheel) { + super(context, interpolator, flywheel); + } + + public void setScrollAtFixedSpeed(int paramInt) { + this.useFixedSpeed = true; + this.mDuration = paramInt; + } + + @Override + public void startScroll(int startX, int startY, int dx, int dy, int duration) { + // Ignore received duration, use fixed one instead + super.startScroll(startX, startY, dx, dy, mDuration); + + } + + @Override + public void startScroll(int startX, int startY, int dx, int dy) { + // Ignore received duration, use fixed one instead + super.startScroll(startX, startY, dx, dy, mDuration); + } + + public void setDuration(int timeMilli){ + this.mDuration = timeMilli; + } +} \ No newline at end of file diff --git a/lib/src/main/java/github/chenupt/springindicator/viewpager/ScrollerViewPager.java b/lib/src/main/java/github/chenupt/springindicator/viewpager/ScrollerViewPager.java new file mode 100644 index 0000000..190aeab --- /dev/null +++ b/lib/src/main/java/github/chenupt/springindicator/viewpager/ScrollerViewPager.java @@ -0,0 +1,80 @@ +/* + * Copyright 2015 chenupt + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package github.chenupt.springindicator.viewpager; + +import android.content.Context; +import android.support.v4.view.ViewPager; +import android.util.AttributeSet; +import android.util.Log; +import android.view.MotionEvent; +import android.view.animation.DecelerateInterpolator; + +import java.lang.reflect.Field; + +/** + * Created by chenupt@gmail.com on 2015/3/7. + * Description TODO + */ +public class ScrollerViewPager extends ViewPager { + + private static final String TAG = ScrollerViewPager.class.getSimpleName(); + + private int duration = 1000; + + public ScrollerViewPager(Context context) { + super(context); + } + + public ScrollerViewPager(Context context, AttributeSet attrs) { + super(context, attrs); + } + + + public void fixScrollSpeed(){ + fixScrollSpeed(duration); + } + + public void fixScrollSpeed(int duration){ + this.duration = duration; + setScrollSpeedUsingRefection(duration); + } + + + private void setScrollSpeedUsingRefection(int duration) { + try { + Field localField = ViewPager.class.getDeclaredField("mScroller"); + localField.setAccessible(true); + FixedSpeedScroller scroller = new FixedSpeedScroller(getContext(), new DecelerateInterpolator(1.5F)); + scroller.setDuration(duration); + localField.set(this, scroller); + return; + } catch (IllegalAccessException localIllegalAccessException) { + } catch (IllegalArgumentException localIllegalArgumentException) { + } catch (NoSuchFieldException localNoSuchFieldException) { + } + } + + @Override + public boolean onInterceptTouchEvent(MotionEvent ev) { + try { + return super.onInterceptTouchEvent(ev); + } catch (IllegalArgumentException e) { + Log.e(TAG, "onInterceptTouchEvent in IllegalArgumentException"); + return false; + } + } +} diff --git a/lib/src/main/res/values/attrs.xml b/lib/src/main/res/values/attrs.xml index cb244b0..3d8c35a 100644 --- a/lib/src/main/res/values/attrs.xml +++ b/lib/src/main/res/values/attrs.xml @@ -3,28 +3,28 @@ - + - + - + - + - + - + - + - + \ No newline at end of file diff --git a/sample/src/main/java/github/chenupt/springindicator/sample/MainActivity.java b/sample/src/main/java/github/chenupt/springindicator/sample/MainActivity.java index a69ce1f..d0af4ff 100644 --- a/sample/src/main/java/github/chenupt/springindicator/sample/MainActivity.java +++ b/sample/src/main/java/github/chenupt/springindicator/sample/MainActivity.java @@ -2,7 +2,6 @@ import android.content.Intent; import android.os.Bundle; -import android.support.v4.view.ViewPager; import android.support.v7.app.ActionBarActivity; import android.support.v7.widget.Toolbar; import android.view.Menu; @@ -15,18 +14,19 @@ import github.chenupt.multiplemodel.viewpager.ModelPagerAdapter; import github.chenupt.multiplemodel.viewpager.PagerModelManager; import github.chenupt.springindicator.SpringIndicator; +import github.chenupt.springindicator.viewpager.ScrollerViewPager; public class MainActivity extends ActionBarActivity { - ViewPager viewPager; + ScrollerViewPager viewPager; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); - viewPager = (ViewPager) findViewById(R.id.view_pager); + viewPager = (ScrollerViewPager) findViewById(R.id.view_pager); SpringIndicator springIndicator = (SpringIndicator) findViewById(R.id.indicator); Toolbar toolbar = (Toolbar) findViewById(R.id.tool_bar); setSupportActionBar(toolbar); @@ -35,9 +35,11 @@ protected void onCreate(Bundle savedInstanceState) { manager.addCommonFragment(GuideFragment.class, getBgRes(), getTitles()); ModelPagerAdapter adapter = new ModelPagerAdapter(getSupportFragmentManager(), manager); viewPager.setAdapter(adapter); + viewPager.fixScrollSpeed(); // just set viewPager springIndicator.setViewPager(viewPager); + } private List getTitles(){ @@ -67,4 +69,6 @@ public boolean onOptionsItemSelected(MenuItem item) { return super.onOptionsItemSelected(item); } + + } diff --git a/sample/src/main/res/layout/activity_main.xml b/sample/src/main/res/layout/activity_main.xml index efd22d3..38fe34e 100644 --- a/sample/src/main/res/layout/activity_main.xml +++ b/sample/src/main/res/layout/activity_main.xml @@ -19,18 +19,18 @@ android:layout_width="match_parent" android:layout_height="match_parent"> -