Skip to content

Commit

Permalink
SCALE slide mode and COLOR slide mode supported.
Browse files Browse the repository at this point in the history
  • Loading branch information
zhpanvip committed Apr 18, 2020
1 parent 3efdea0 commit c78a83d
Show file tree
Hide file tree
Showing 14 changed files with 95 additions and 82 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ BannerViewPager supports three Indicator Styles and three Indicator Slide mode n
| NORMAL| ![CIRCLE_NORMAL](https://github.com/zhpanvip/Resource/blob/master/image/indicator/slide_circle_normal.gif) | ![DASH_NORMAL](https://github.com/zhpanvip/Resource/blob/master/image/indicator/style_dash_normal.gif) | ![ROUND_RECT_NORMAL](https://github.com/zhpanvip/Resource/blob/master/image/indicator/style_round_rect_normal.gif) |
| SMOOTH| ![CIRCLE_SMOOTH](https://github.com/zhpanvip/Resource/blob/master/image/indicator/slide_circle_smooth.gif) | ![DASH_SMOOTH](https://github.com/zhpanvip/Resource/blob/master/image/indicator/style_dash_smooth.gif) | ![ROUND_RECT_SMOOTH](https://github.com/zhpanvip/Resource/blob/master/image/indicator/style_round_rect_smooth.gif) |
| WORM| ![CIRCLE_WORM](https://github.com/zhpanvip/Resource/blob/master/image/indicator/slide_circle_worm.gif) | ![DASH_WORM](https://github.com/zhpanvip/Resource/blob/master/image/indicator/style_dash_worm.gif) | ![ROUND_WORM](https://github.com/zhpanvip/Resource/blob/master/image/indicator/style_round_rect_worm.gif) |
| COLOR| ![CIRCLE_COLOR](https://github.com/zhpanvip/Resource/blob/master/image/indicator/slide_circle_color.gif) | ![DASH_COLOR](https://github.com/zhpanvip/Resource/blob/master/image/indicator/style_dash_color.gif) | ![ROUND_COLOR](https://github.com/zhpanvip/Resource/blob/master/image/indicator/style_round_rect_color.gif) |
| SCALE| ![CIRCLE_SCALE](https://github.com/zhpanvip/Resource/blob/master/image/indicator/slide_circle_scale.gif) | ![DASH_SCALE](https://github.com/zhpanvip/Resource/blob/master/image/indicator/style_dash_scale.gif) | ![ROUND_SCALE](https://github.com/zhpanvip/Resource/blob/master/image/indicator/style_round_rect_scale.gif) |

#### (2)Custom Indicator

Expand Down Expand Up @@ -179,7 +181,6 @@ implementation 'com.github.zhpanvip:BannerViewPager:latestVersion'
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#66000000"
android:gravity="center_vertical">
<TextView
Expand Down Expand Up @@ -249,6 +250,7 @@ public class HomeAdapter extends BaseBannerAdapter<BannerData, NetViewHolder> {
mBannerViewPager = findViewById(R.id.banner_view);
mViewPager
.setAutoPlay(true)
.setScrollDuration(800)
.setIndicatorStyle(IndicatorStyle.ROUND_RECT)
.setIndicatorSliderGap(getResources().getDimensionPixelOffset(R.dimen.dp_4))
.setIndicatorSliderWidth(getResources().getDimensionPixelOffset(R.dimen.dp_4), getResources().getDimensionPixelOffset(R.dimen.dp_10))
Expand Down
4 changes: 3 additions & 1 deletion README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ BannerViewPager目前已支持三种IndicatorViewStyle,以及三种IndicatorSlid
| NORMAL| ![CIRCLE_NORMAL](https://github.com/zhpanvip/Resource/blob/master/image/indicator/slide_circle_normal.gif) | ![DASH_NORMAL](https://github.com/zhpanvip/Resource/blob/master/image/indicator/style_dash_normal.gif) | ![ROUND_RECT_NORMAL](https://github.com/zhpanvip/Resource/blob/master/image/indicator/style_round_rect_normal.gif) |
| SMOOTH| ![CIRCLE_SMOOTH](https://github.com/zhpanvip/Resource/blob/master/image/indicator/slide_circle_smooth.gif) | ![DASH_SMOOTH](https://github.com/zhpanvip/Resource/blob/master/image/indicator/style_dash_smooth.gif) | ![ROUND_RECT_SMOOTH](https://github.com/zhpanvip/Resource/blob/master/image/indicator/style_round_rect_smooth.gif) |
| WORM| ![CIRCLE_WORM](https://github.com/zhpanvip/Resource/blob/master/image/indicator/slide_circle_worm.gif) | ![DASH_WORM](https://github.com/zhpanvip/Resource/blob/master/image/indicator/style_dash_worm.gif) | ![ROUND_WORM](https://github.com/zhpanvip/Resource/blob/master/image/indicator/style_round_rect_worm.gif) |
| COLOR| ![CIRCLE_COLOR](https://github.com/zhpanvip/Resource/blob/master/image/indicator/slide_circle_color.gif) | ![DASH_COLOR](https://github.com/zhpanvip/Resource/blob/master/image/indicator/style_dash_color.gif) | ![ROUND_COLOR](https://github.com/zhpanvip/Resource/blob/master/image/indicator/style_round_rect_color.gif) |
| SCALE| ![CIRCLE_SCALE](https://github.com/zhpanvip/Resource/blob/master/image/indicator/slide_circle_scale.gif) | ![DASH_SCALE](https://github.com/zhpanvip/Resource/blob/master/image/indicator/style_dash_scale.gif) | ![ROUND_SCALE](https://github.com/zhpanvip/Resource/blob/master/image/indicator/style_round_rect_scale.gif) |

#### (2)Custom Indicator

Expand Down Expand Up @@ -177,7 +179,6 @@ implementation 'com.github.zhpanvip:BannerViewPager:latestVersion'
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#66000000"
android:gravity="center_vertical">
<TextView
Expand Down Expand Up @@ -248,6 +249,7 @@ public class HomeAdapter extends BaseBannerAdapter<BannerData, NetViewHolder> {
mViewPager = findViewById(R.id.banner_view);
mViewPager
.setAutoPlay(true)
.setScrollDuration(800)
.setIndicatorStyle(IndicatorStyle.ROUND_RECT)
.setIndicatorSliderGap(getResources().getDimensionPixelOffset(R.dimen.dp_4))
.setIndicatorSliderWidth(getResources().getDimensionPixelOffset(R.dimen.dp_4), getResources().getDimensionPixelOffset(R.dimen.dp_10))
Expand Down
Binary file modified app/release/app-release.apk
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public class HomeFragment extends BaseFragment {
private IndicatorView mIndicatorView;
private TextView mTvTitle;
private RelativeLayout mRlIndicator;
private View headerView;

@Override
protected int getLayout() {
Expand Down Expand Up @@ -103,7 +104,7 @@ public static HomeFragment getInstance() {
private void initRecyclerView(View view) {
recyclerView = view.findViewById(R.id.recycler_view);
recyclerView.setLayoutManager(new LinearLayoutManager(getMContext()));
recyclerView.addHeadView(getHeaderView(),true);
recyclerView.addHeadView(getHeaderView(), true);
recyclerView.addItemDecoration(new DividerItemDecoration(getMContext(),
DividerItemDecoration.VERTICAL));
articleAdapter = new ArticleAdapter(getMContext(), new ArrayList<>());
Expand All @@ -124,6 +125,7 @@ private void fetchData(boolean showLoading) {
.subscribe(new ResponseObserver<DataWrapper>() {
@Override
public void onSuccess(DataWrapper response) {
headerView.setVisibility(View.VISIBLE);
List<BannerData> dataList = response.getDataBeanList();
BannerData bannerData = new BannerData();
bannerData.setDrawable(R.drawable.bg_card0);
Expand Down Expand Up @@ -165,6 +167,7 @@ private void initBanner() {
mViewPagerHorizontal
.setAutoPlay(true)
.setScrollDuration(600)
.setIndicatorStyle(IndicatorStyle.CIRCLE)
.setIndicatorSlideMode(IndicatorSlideMode.WORM)
.setInterval(3000)
.setIndicatorGravity(IndicatorGravity.END)
Expand All @@ -186,6 +189,7 @@ public void onPageSelected(int position) {
.setAutoPlay(true)
.setScrollDuration(500)
.setIndicatorStyle(IndicatorStyle.ROUND_RECT)
.setIndicatorSlideMode(IndicatorSlideMode.SCALE)
.setIndicatorSliderGap(getResources().getDimensionPixelOffset(R.dimen.dp_4))
.setIndicatorSliderWidth(getResources().getDimensionPixelOffset(R.dimen.dp_4), getResources().getDimensionPixelOffset(R.dimen.dp_10))
.setIndicatorSliderColor(getColor(R.color.red_normal_color), getColor(R.color.red_checked_color))
Expand All @@ -200,7 +204,7 @@ private void onPageClicked(int position) {
}

private View getHeaderView() {
View headerView = LayoutInflater.from(getMContext()).inflate(R.layout.item_header_view, recyclerView, false);
headerView = LayoutInflater.from(getMContext()).inflate(R.layout.item_header_view, recyclerView, false);
mRlIndicator = headerView.findViewById(R.id.layout_indicator);
mViewPagerHorizontal = headerView.findViewById(R.id.banner_view);
mViewPagerVertical = headerView.findViewById(R.id.banner_view2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ protected void initView(Bundle savedInstanceState, View view) {
mRadioGroupMode = view.findViewById(R.id.rg_slide_mode);
mViewPager = view.findViewById(R.id.banner_view);
mViewPager.setIndicatorSliderGap(BannerUtils.dp2px(6))
.setScrollDuration(800)
.setAdapter(new ImageResourceAdapter(0))
.setRoundCorner(BannerUtils.dp2px(6));
initRadioGroup();
Expand All @@ -86,6 +87,12 @@ private void initRadioGroup() {
case R.id.rb_smooth:
mSlideMode = IndicatorSlideMode.SMOOTH;
break;
case R.id.rb_color:
mSlideMode = IndicatorSlideMode.COLOR;
break;
case R.id.rb_scale:
mSlideMode = IndicatorSlideMode.SCALE;
break;
}
checkedChange(mCheckId);
});
Expand All @@ -102,23 +109,9 @@ private void checkedChange(int checkedId) {
case R.id.rb_round_rect:
setupRoundRectIndicator();
break;
case R.id.rb_tmall:
setupTMallIndicator();
break;
}
}

private void setupTMallIndicator() {
mViewPager
.setIndicatorStyle(IndicatorStyle.DASH)
.setIndicatorSliderGap(0)
.setIndicatorSlideMode(mSlideMode)
.setIndicatorSliderColor(getColor(R.color.red_normal_color), getColor(R.color.red_checked_color))
.setIndicatorSliderWidth(getResources().getDimensionPixelOffset(R.dimen.dp_15))
.setIndicatorHeight(getResources().getDimensionPixelOffset(R.dimen.dp_3))
.create(getPicList(4));
}

private void setupRoundRectIndicator() {
int checkedWidth = getResources().getDimensionPixelOffset(R.dimen.dp_10);
int normalWidth = getNormalWidth();
Expand All @@ -133,14 +126,23 @@ private void setupRoundRectIndicator() {
}

private void setupCircleIndicator() {
int checkedWidth;
int normalWidth;
if (mSlideMode == IndicatorSlideMode.SCALE) {
checkedWidth = getResources().getDimensionPixelOffset(R.dimen.dp_5);
normalWidth = getResources().getDimensionPixelOffset(R.dimen.dp_3);
} else {
checkedWidth = getResources().getDimensionPixelOffset(R.dimen.dp_4);
normalWidth = checkedWidth;
}

mViewPager.setIndicatorStyle(IndicatorStyle.CIRCLE)
.setIndicatorSlideMode(mSlideMode)
.setIndicatorGravity(IndicatorGravity.CENTER)
.setIndicatorSliderGap(getResources().getDimensionPixelOffset(R.dimen.dp_6))
.setIndicatorHeight(getResources().getDimensionPixelOffset(R.dimen.dp_4))
.setIndicatorSliderRadius(normalWidth, checkedWidth)
.setOnPageClickListener(position -> ToastUtils.show("position:" + position))
.setIndicatorSliderColor(getColor(R.color.red_normal_color), getColor(R.color.red_checked_color))
.setIndicatorSliderRadius(getResources().getDimensionPixelOffset(R.dimen.dp_4)).create(getPicList(4));
.setIndicatorSliderColor(getColor(R.color.red_normal_color), getColor(R.color.red_checked_color)).create(getPicList(4));
}

private void setupDashIndicator() {
Expand All @@ -157,7 +159,8 @@ private void setupDashIndicator() {
}

private int getNormalWidth() {
if (mSlideMode == IndicatorSlideMode.SMOOTH || mSlideMode == IndicatorSlideMode.WORM) {
if (mSlideMode == IndicatorSlideMode.SMOOTH || mSlideMode == IndicatorSlideMode.WORM
|| mSlideMode == IndicatorSlideMode.COLOR) {
return getResources().getDimensionPixelOffset(R.dimen.dp_10);
} else {
return getResources().getDimensionPixelOffset(R.dimen.dp_4);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ private void setDrawableIndicator(IIndicator indicator) {
.setIndicatorSlideMode(IndicatorSlideMode.NORMAL)
.setIndicatorVisibility(View.VISIBLE)
.setIndicatorGravity(IndicatorGravity.CENTER)
.create(getPicList(4));
.create(getMDrawableList());
}

private IIndicator getDrawableIndicator() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ protected void initView(Bundle savedInstanceState, View view) {
mRadioGroupPageStyle = view.findViewById(R.id.rg_page_style);
radioButton = view.findViewById(R.id.rb_multi_page);
mViewPager
.setIndicatorSlideMode(IndicatorSlideMode.NORMAL)
.setIndicatorSlideMode(IndicatorSlideMode.SCALE)
.setIndicatorSliderColor(getColor(R.color.red_normal_color), getColor(R.color.red_checked_color))
.setIndicatorSliderRadius(getResources().getDimensionPixelOffset(R.dimen.dp_4), getResources().getDimensionPixelOffset(R.dimen.dp_5))
.setOnPageClickListener(position -> ToastUtils.show("position:" + position))
Expand Down
27 changes: 13 additions & 14 deletions app/src/main/res/layout/fragment_indicator.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,6 @@
android:text="ROUND_RECT"
android:textSize="@dimen/sp_16" />

<RadioButton
android:id="@+id/rb_tmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="15dp"
android:layout_marginBottom="@dimen/dp_10"
android:text="Tmall Indicator Style"
android:textSize="@dimen/sp_16" />


</RadioGroup>

Expand Down Expand Up @@ -116,14 +107,13 @@
android:text="WORM"
android:textSize="@dimen/sp_16" />


<RadioButton
android:id="@+id/rb_normal"
android:id="@+id/rb_color"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="15dp"
android:layout_marginBottom="@dimen/dp_10"
android:text="NORMAL"
android:text="COLOR"
android:textSize="@dimen/sp_16" />

<RadioButton
Expand All @@ -133,8 +123,17 @@
android:layout_marginEnd="15dp"
android:layout_marginBottom="@dimen/dp_10"
android:text="SCALE"
android:textSize="@dimen/sp_16"
android:visibility="gone" />
android:textSize="@dimen/sp_16" />

<RadioButton
android:id="@+id/rb_normal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="15dp"
android:layout_marginBottom="@dimen/dp_10"
android:text="NORMAL"
android:textSize="@dimen/sp_16" />


</RadioGroup>

Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/layout/item_header_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone"
android:orientation="vertical">

<RelativeLayout
Expand Down
3 changes: 2 additions & 1 deletion bannerview/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ dependencies {
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation 'androidx.appcompat:appcompat:1.1.0'
api 'com.github.zhpanvip:viewpagerindicator:1.0.2'
api 'com.github.zhpanvip:viewpagerindicator:1.0.3'
implementation 'androidx.viewpager2:viewpager2:1.0.0'
implementation 'androidx.core:core-ktx:1.2.0'
// api project(path: ':indicator')
}
Loading

0 comments on commit c78a83d

Please sign in to comment.