|
|
@ -11,7 +11,8 @@ import com.android.base.R; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.List; |
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
|
|
|
|
import androidx.viewpager.widget.PagerAdapter; |
|
|
|
import javax.annotation.Nullable; |
|
|
|
|
|
|
|
|
|
|
|
import androidx.viewpager.widget.ViewPager; |
|
|
|
import androidx.viewpager.widget.ViewPager; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -28,7 +29,6 @@ public class BannerViewPager extends FrameLayout { |
|
|
|
|
|
|
|
|
|
|
|
private OnBannerPositionChangedListener mOnBannerPositionChangedListener; |
|
|
|
private OnBannerPositionChangedListener mOnBannerPositionChangedListener; |
|
|
|
|
|
|
|
|
|
|
|
private boolean mScalable; |
|
|
|
|
|
|
|
private String mTransitionName; |
|
|
|
private String mTransitionName; |
|
|
|
private OnPageClickListener mOnPageClickListener; |
|
|
|
private OnPageClickListener mOnPageClickListener; |
|
|
|
|
|
|
|
|
|
|
@ -45,8 +45,6 @@ public class BannerViewPager extends FrameLayout { |
|
|
|
|
|
|
|
|
|
|
|
TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.BannerViewPager); |
|
|
|
TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.BannerViewPager); |
|
|
|
|
|
|
|
|
|
|
|
/*是否可以缩放*/ |
|
|
|
|
|
|
|
mScalable = typedArray.getBoolean(R.styleable.BannerViewPager_zvp_scale_enable, false); |
|
|
|
|
|
|
|
/*用于支持5.0的transition动画*/ |
|
|
|
/*用于支持5.0的transition动画*/ |
|
|
|
mTransitionName = typedArray.getString(R.styleable.BannerViewPager_zvp_item_transition_name); |
|
|
|
mTransitionName = typedArray.getString(R.styleable.BannerViewPager_zvp_item_transition_name); |
|
|
|
int pageId = typedArray.getResourceId(R.styleable.BannerViewPager_zvp_pager_number_id, -1); |
|
|
|
int pageId = typedArray.getResourceId(R.styleable.BannerViewPager_zvp_pager_number_id, -1); |
|
|
@ -74,7 +72,7 @@ public class BannerViewPager extends FrameLayout { |
|
|
|
mPageNumberView = pageNumberView; |
|
|
|
mPageNumberView = pageNumberView; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void setImages(List<String> entities) { |
|
|
|
public void setImages(List<String> entities, @Nullable BannerPagerAdapter adapter) { |
|
|
|
if (entities == null || entities.isEmpty()) { |
|
|
|
if (entities == null || entities.isEmpty()) { |
|
|
|
mImageUrlList.clear(); |
|
|
|
mImageUrlList.clear(); |
|
|
|
mViewPager.setAdapter(null); |
|
|
|
mViewPager.setAdapter(null); |
|
|
@ -83,16 +81,21 @@ public class BannerViewPager extends FrameLayout { |
|
|
|
} |
|
|
|
} |
|
|
|
mImageUrlList.clear(); |
|
|
|
mImageUrlList.clear(); |
|
|
|
setPageSize(entities.size()); |
|
|
|
setPageSize(entities.size()); |
|
|
|
|
|
|
|
|
|
|
|
if (entities.size() > 1) { |
|
|
|
if (entities.size() > 1) { |
|
|
|
addExtraPage(entities); |
|
|
|
addExtraPage(entities); |
|
|
|
showBanner(); |
|
|
|
showBanner(adapter); |
|
|
|
setLooper(); |
|
|
|
setLooper(); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
mImageUrlList.addAll(entities); |
|
|
|
mImageUrlList.addAll(entities); |
|
|
|
showBanner(); |
|
|
|
showBanner(adapter); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void setImages(List<String> entities) { |
|
|
|
|
|
|
|
setImages(entities, null); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void setPageSize(int pageSize) { |
|
|
|
private void setPageSize(int pageSize) { |
|
|
|
if (mPageNumberView != null) { |
|
|
|
if (mPageNumberView != null) { |
|
|
|
mPageNumberView.setPageSize(pageSize); |
|
|
|
mPageNumberView.setPageSize(pageSize); |
|
|
@ -169,18 +172,18 @@ public class BannerViewPager extends FrameLayout { |
|
|
|
mImageUrlList.add(entities.get(0)); |
|
|
|
mImageUrlList.add(entities.get(0)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void showBanner() { |
|
|
|
private void showBanner(BannerPagerAdapter adapter) { |
|
|
|
PagerAdapter adapter; |
|
|
|
if (adapter != null) { |
|
|
|
if (mScalable) { |
|
|
|
adapter.setContext(getContext()); |
|
|
|
BannerPagerAdapter bannerPagerAdapter = new BannerPagerAdapter(getContext(), mImageUrlList, mTransitionName); |
|
|
|
adapter.setEntities(mImageUrlList); |
|
|
|
bannerPagerAdapter.setOnBannerClickListener(mOnPageClickListener); |
|
|
|
adapter.setTransitionName(mTransitionName); |
|
|
|
adapter = bannerPagerAdapter; |
|
|
|
adapter.setOnBannerClickListener(mOnPageClickListener); |
|
|
|
|
|
|
|
mViewPager.setAdapter(adapter); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
OptimizeBannerPagerAdapter optimizeBannerPagerAdapter = new OptimizeBannerPagerAdapter(getContext(), mImageUrlList, mTransitionName); |
|
|
|
OptimizeBannerPagerAdapter optimizeBannerPagerAdapter = new OptimizeBannerPagerAdapter(getContext(), mImageUrlList, mTransitionName); |
|
|
|
optimizeBannerPagerAdapter.setOnBannerClickListener(mOnPageClickListener); |
|
|
|
optimizeBannerPagerAdapter.setOnBannerClickListener(mOnPageClickListener); |
|
|
|
adapter = optimizeBannerPagerAdapter; |
|
|
|
mViewPager.setAdapter(optimizeBannerPagerAdapter); |
|
|
|
} |
|
|
|
} |
|
|
|
mViewPager.setAdapter(adapter); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void setOnPageClickListener(OnPageClickListener onPageClickListener) { |
|
|
|
public void setOnPageClickListener(OnPageClickListener onPageClickListener) { |
|
|
@ -199,8 +202,4 @@ public class BannerViewPager extends FrameLayout { |
|
|
|
void onPagePositionChanged(int position); |
|
|
|
void onPagePositionChanged(int position); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static void setScalableBannerPagerFactory(ScalableBannerPagerFactory scalableBannerPagerFactory) { |
|
|
|
|
|
|
|
BannerPagerAdapter.sBannerPagerFactory = scalableBannerPagerFactory; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |