Skip to content

Commit

Permalink
优化,升级版本
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaomsh committed May 9, 2019
1 parent 847fc8d commit 04a5224
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 16 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ repositories {
}
dependencies{
implementation 'com.github.wenchaosong:Banner:2.3.9'
implementation 'com.github.wenchaosong:Banner:2.3.10'
// 或者
implementation('com.github.wenchaosong:Banner:2.3.9') {
implementation('com.github.wenchaosong:Banner:2.3.10') {
exclude group: 'com.android.support'
}
}
Expand Down
4 changes: 4 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ android {
versionName "1.0"
}

lintOptions {
abortOnError false
}

buildTypes {
release {
minifyEnabled false
Expand Down
2 changes: 0 additions & 2 deletions banner/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ android {
defaultConfig {
minSdkVersion 14
targetSdkVersion 28
versionCode 1
versionName "1.0"
}

buildTypes {
Expand Down
2 changes: 1 addition & 1 deletion banner/src/main/java/com/ms/banner/Banner.java
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ public Banner setCurrentPage(@IntRange(from = 0) int page) {
if (count == 0)
return this;
if (page > count) {
throw new RuntimeException("[Banner] --> The current page is out of adapter's count");
throw new RuntimeException("[Banner] --> The current page is out of range");
}
if (isLoop) {
this.currentItem = NUM / 2 - ((NUM / 2) % count) + 1 + page;
Expand Down
40 changes: 31 additions & 9 deletions banner/src/main/java/com/ms/banner/BannerNew.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.support.annotation.IntRange;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.util.AttributeSet;
Expand Down Expand Up @@ -57,7 +58,7 @@ public class BannerNew extends FrameLayout implements OnPageChangeListener {
private int titleTextColor;
private int titleTextSize;
private int count = 0;
private int currentItem;
private int currentItem = -1;
private int gravity = -1;
private int lastPosition;
private List<String> titles;
Expand Down Expand Up @@ -237,6 +238,20 @@ public BannerNew setViewPagerIsScroll(boolean isScroll) {
return this;
}

public BannerNew setCurrentPage(@IntRange(from = 0) int page) {
if (count == 0)
return this;
if (page > count) {
throw new RuntimeException("[Banner] --> The current page is out of range");
}
if (isLoop) {
this.currentItem = page + 1;
} else {
this.currentItem = page;
}
return this;
}

public BannerNew setPages(List<?> datas, BannerViewHolder creator) {
this.mDatas = datas;
this.creator = creator;
Expand Down Expand Up @@ -302,7 +317,6 @@ public boolean isStart() {
return isStart;
}


public BannerNew setIndicatorRes(int select, int unSelect) {
if (select < 0)
throw new RuntimeException("[Banner] --> The select res is not exist");
Expand Down Expand Up @@ -430,10 +444,14 @@ else if (bannerStyle == BannerConfig.CUSTOM_INDICATOR)

private void setData() {
if (isLoop) {
currentItem = 1;
if (currentItem < 0) {
currentItem = 1;
}
lastPosition = 1;
} else {
currentItem = 0;
if (currentItem < 0) {
currentItem = 0;
}
lastPosition = 0;
}
if (adapter == null) {
Expand Down Expand Up @@ -501,15 +519,19 @@ public boolean dispatchTouchEvent(MotionEvent ev) {
startAutoPlay();
break;
case MotionEvent.ACTION_DOWN:
stopAutoPlay();
float downX = ev.getX();
if (mPageLeftMargin != 0 || mPageRightMargin != 0) {
if (downX > mPageLeftMargin && downX < getWidth() - mPageRightMargin) {
stopAutoPlay();
}
} else {
stopAutoPlay();
}
break;
}
return super.dispatchTouchEvent(ev);
}

/**
* @param position
*/
private int toRealPosition(int position) {
int realPosition;
if (isLoop) {
Expand Down Expand Up @@ -603,10 +625,10 @@ public void onPageScrolled(int position, float positionOffset, int positionOffse

@Override
public void onPageSelected(int position) {
currentItem = position;
if (mOnPageChangeListener != null && currentItem < count + 1 && currentItem > 0) {
mOnPageChangeListener.onPageSelected(toRealPosition(position));
}
currentItem = position;
if (bannerStyle == BannerConfig.CIRCLE_INDICATOR ||
bannerStyle == BannerConfig.CIRCLE_INDICATOR_TITLE ||
bannerStyle == BannerConfig.CIRCLE_INDICATOR_TITLE_INSIDE ||
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.0'
classpath 'com.android.tools.build:gradle:3.2.0'
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.0'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.1'
}
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip

0 comments on commit 04a5224

Please sign in to comment.