Przeglądaj źródła

Merge branch 'master' of https://github.com/zhpanvip/BannerViewPager

zhpanvip 2 lat temu
rodzic
commit
236d4b9251

+ 1 - 1
README.md

@@ -88,7 +88,7 @@ It's also support to custom indicator style,just need extends BaseIndicatorView
  **If you have any question regard to BannerViewPager, please scan the QR code and join the QQ group to communicate.** <a target="_blank" href="https://qm.qq.com/cgi-bin/qm/qr?k=yHQU7OuoIazbu8vXGt1wC37RsPzhnR61&jump_from=webapi"><img border="0" 
                                                                                                                          src="https://pub.idqqimg.com/wpa/images/group.png" alt="QQ群60902509" title="QQ群60902509">
  
-| QQ群 | 微信 |
+| QQ群 | 入群加微信 |
 |--|--|
 | ![QQ Group](https://cdn.jsdelivr.net/gh/zhpanvip/images/project/group/qq_group.png) |  ![WeChat](https://github.com/zhpanvip/images/blob/master/project/group/wechat.png) |
 

+ 68 - 69
app/build.gradle

@@ -1,85 +1,84 @@
 apply plugin: 'com.android.application'
 apply plugin: 'kotlin-android'
 android {
-    compileSdkVersion 30
-    buildToolsVersion '28.0.3'
-    defaultConfig {
-        applicationId "com.example.zhpan.bannerviewpager"
-        minSdkVersion 21
-        targetSdkVersion 30
-        versionCode 1
-        versionName "3.5.2"
-        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
-    }
-    buildTypes {
-        release {
-            debuggable false
-            minifyEnabled true
-            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
-        }
+  compileSdkVersion 33
+  defaultConfig {
+    applicationId "com.example.zhpan.bannerviewpager"
+    minSdkVersion 21
+    targetSdkVersion 33
+    versionCode 2
+    versionName "3.5.10"
+    testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
+  }
+  buildTypes {
+    release {
+      debuggable false
+      minifyEnabled true
+      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
     }
+  }
 
-    sourceSets {
-        main {
-            jniLibs.srcDirs = ['libs']
-        }
+  sourceSets {
+    main {
+      jniLibs.srcDirs = ['libs']
     }
+  }
 
-    compileOptions {
-        sourceCompatibility JavaVersion.VERSION_1_8
-        targetCompatibility JavaVersion.VERSION_1_8
-    }
+  compileOptions {
+    sourceCompatibility JavaVersion.VERSION_1_8
+    targetCompatibility JavaVersion.VERSION_1_8
+  }
 
-    viewBinding {
-        enabled = true
-    }
-    dataBinding {
-        //noinspection DataBindingWithoutKapt
-        enabled = true
-    }
+  viewBinding {
+    enabled = true
+  }
+  dataBinding {
+    //noinspection DataBindingWithoutKapt
+    enabled = true
+  }
 }
 
 repositories {
-    flatDir {
-        dirs 'libs'
-    }
+  flatDir {
+    dirs 'libs'
+  }
 }
 
 dependencies {
-    implementation fileTree(include: ['*.jar'], dir: 'libs')
-    implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
-    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
-    androidTestImplementation('androidx.test.espresso:espresso-core:3.1.0', {
-        exclude group: 'com.android.support', module: 'support-annotations'
-    })
-    implementation "io.reactivex.rxjava2:rxjava:$rootProject.ext.rxjava2Version"
-    implementation "com.squareup.retrofit2:retrofit:$rootProject.ext.retrofit2Version"
-    implementation "com.squareup.retrofit2:converter-scalars:$rootProject.ext.retrofit2Version"
-    implementation "com.squareup.retrofit2:converter-gson:$rootProject.ext.retrofit2Version"
-    implementation "com.squareup.retrofit2:adapter-rxjava2:$rootProject.ext.retrofit2Version"
-    implementation "com.trello.rxlifecycle2:rxlifecycle:$rootProject.ext.rxlifecycle"
-    implementation "com.trello.rxlifecycle2:rxlifecycle-components:$rootProject.ext.rxlifecycle"
-    implementation 'com.jakewharton.retrofit:retrofit2-rxjava2-adapter:1.0.0'
-    implementation 'io.reactivex.rxjava2:rxandroid:2.1.1'
-    implementation 'com.squareup.okhttp3:logging-interceptor:4.8.1'
+  implementation fileTree(include: ['*.jar'], dir: 'libs')
+  implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
+  implementation 'androidx.legacy:legacy-support-v4:1.0.0'
+  androidTestImplementation('androidx.test.espresso:espresso-core:3.1.0', {
+    exclude group: 'com.android.support', module: 'support-annotations'
+  })
+  implementation "io.reactivex.rxjava2:rxjava:$rootProject.ext.rxjava2Version"
+  implementation "com.squareup.retrofit2:retrofit:$rootProject.ext.retrofit2Version"
+  implementation "com.squareup.retrofit2:converter-scalars:$rootProject.ext.retrofit2Version"
+  implementation "com.squareup.retrofit2:converter-gson:$rootProject.ext.retrofit2Version"
+  implementation "com.squareup.retrofit2:adapter-rxjava2:$rootProject.ext.retrofit2Version"
+  implementation "com.trello.rxlifecycle2:rxlifecycle:$rootProject.ext.rxlifecycle"
+  implementation "com.trello.rxlifecycle2:rxlifecycle-components:$rootProject.ext.rxlifecycle"
+  implementation 'com.jakewharton.retrofit:retrofit2-rxjava2-adapter:1.0.0'
+  implementation 'io.reactivex.rxjava2:rxandroid:2.1.1'
+  implementation 'com.squareup.okhttp3:logging-interceptor:4.8.1'
 
-    implementation 'androidx.appcompat:appcompat:1.3.0'
-    implementation 'androidx.recyclerview:recyclerview:1.2.1'
-    implementation 'com.github.bumptech.glide:glide:4.11.0'
-    implementation 'com.scwang.smartrefresh:SmartRefreshLayout:1.1.0'
-    implementation 'com.scwang.smartrefresh:SmartRefreshHeader:1.1.0'
-    debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.3'
-    implementation 'androidx.core:core-ktx:1.6.0'
-    implementation 'androidx.cardview:cardview:1.0.0'
-    implementation 'androidx.viewpager2:viewpager2:1.0.0'
-    implementation 'com.github.CymChad:BaseRecyclerViewAdapterHelper:3.0.4'
-    implementation 'com.google.android.material:material:1.3.0'
-    implementation "androidx.navigation:navigation-fragment-ktx:2.3.5"
-    implementation "androidx.navigation:navigation-ui-ktx:2.3.5"
-    implementation 'com.tencent.bugly:crashreport:3.2.1'
-    implementation 'com.google.android.material:material:1.3.0'
-    implementation 'com.blankj:utilcodex:1.30.6'
-    implementation 'com.airbnb.android:lottie:3.4.1'
-//    implementation 'com.github.zhpanvip:bannerviewpager:3.5.6'
-    implementation project(path: ':bannerview')
+  implementation 'androidx.appcompat:appcompat:1.3.0'
+  implementation 'androidx.recyclerview:recyclerview:1.2.1'
+  implementation 'com.github.bumptech.glide:glide:4.11.0'
+  implementation 'com.scwang.smartrefresh:SmartRefreshLayout:1.1.0'
+  implementation 'com.scwang.smartrefresh:SmartRefreshHeader:1.1.0'
+  debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.10'
+  implementation 'androidx.core:core-ktx:1.6.0'
+  implementation 'androidx.cardview:cardview:1.0.0'
+  implementation 'androidx.viewpager2:viewpager2:1.0.0'
+  implementation 'com.github.CymChad:BaseRecyclerViewAdapterHelper:3.0.4'
+  implementation 'com.google.android.material:material:1.3.0'
+  implementation "androidx.navigation:navigation-fragment-ktx:2.3.5"
+  implementation "androidx.navigation:navigation-ui-ktx:2.3.5"
+  implementation 'com.tencent.bugly:crashreport:3.2.1'
+  implementation 'com.google.android.material:material:1.3.0'
+  implementation 'com.blankj:utilcodex:1.30.6'
+  implementation 'com.airbnb.android:lottie:3.4.1'
+  //    implementation 'com.github.zhpanvip:bannerviewpager:3.5.6'
+  implementation project(path: ':bannerview')
 }

+ 1 - 0
app/src/main/AndroidManifest.xml

@@ -16,6 +16,7 @@
         android:theme="@style/AppTheme">
         <activity
             android:name="com.example.zhpan.banner.activity.WelcomeActivity"
+            android:exported="true"
             android:theme="@style/FullScreenTheme">
             <intent-filter>
                 <action android:name="android.intent.action.MAIN" />

+ 0 - 32
app/src/main/java/com/example/zhpan/banner/adapter/DataBindingSampleAdapter.java

@@ -1,32 +0,0 @@
-package com.example.zhpan.banner.adapter;
-
-import androidx.databinding.DataBindingUtil;
-
-import com.example.zhpan.banner.R;
-import com.example.zhpan.banner.databinding.ItemSlideModelDataBindingBinding;
-import com.example.zhpan.banner.net.BannerData;
-import com.zhpan.bannerview.BaseBannerAdapter;
-import com.zhpan.bannerview.BaseViewHolder;
-
-/**
- * <pre>
- *   Created by zhpan on 2020/4/5.
- *   Description:使用DataBinding示例
- * </pre>
- */
-public class DataBindingSampleAdapter extends BaseBannerAdapter<BannerData> {
-
-  @Override
-  protected void bindData(BaseViewHolder<BannerData> holder, BannerData data, int position,
-      int pageSize) {
-    ItemSlideModelDataBindingBinding dataBinding = DataBindingUtil.bind(holder.itemView);
-    if (dataBinding != null) {
-      dataBinding.setBannerData(data);
-    }
-  }
-
-  @Override
-  public int getLayoutId(int viewType) {
-    return R.layout.item_slide_model_data_binding;
-  }
-}

+ 46 - 0
app/src/main/java/com/example/zhpan/banner/adapter/DataBindingSampleAdapter.kt

@@ -0,0 +1,46 @@
+package com.example.zhpan.banner.adapter
+
+import android.view.View
+import android.view.ViewGroup
+import com.zhpan.bannerview.BaseBannerAdapter
+import com.example.zhpan.banner.net.BannerData
+import androidx.databinding.DataBindingUtil
+import com.example.zhpan.banner.R.layout
+import com.example.zhpan.banner.databinding.ItemSlideModelDataBindingBinding
+import com.zhpan.bannerview.BaseViewHolder
+import java.lang.NullPointerException
+
+/**
+ * <pre>
+ * Created by zhpan on 2020/4/5.
+ * Description:使用DataBinding示例
+</pre> *
+ */
+class DataBindingSampleAdapter : BaseBannerAdapter<BannerData?>() {
+
+  override fun createViewHolder(
+    parent: ViewGroup, itemView: View,
+    viewType: Int
+  ): BaseViewHolder<BannerData?> {
+    val binding = DataBindingUtil.bind<ItemSlideModelDataBindingBinding>(itemView)
+      ?: throw NullPointerException("binding is Null")
+    return DataBindingViewHolder(binding)
+  }
+
+  override fun bindData(
+    holder: BaseViewHolder<BannerData?>?,
+    data: BannerData?,
+    position: Int,
+    pageSize: Int
+  ) {
+    if (holder is DataBindingViewHolder) {
+      holder.binding.bannerData = data
+    }
+  }
+
+  override fun getLayoutId(viewType: Int): Int {
+    return layout.item_slide_model_data_binding
+  }
+}
+
+internal class DataBindingViewHolder(var binding: ItemSlideModelDataBindingBinding) : BaseViewHolder<BannerData?>(binding.root)

+ 0 - 35
app/src/main/java/com/example/zhpan/banner/adapter/ViewBindingSampleAdapter.java

@@ -1,35 +0,0 @@
-package com.example.zhpan.banner.adapter;
-
-import com.example.zhpan.banner.R;
-import com.example.zhpan.banner.databinding.ItemSlideModeBinding;
-import com.zhpan.bannerview.BaseBannerAdapter;
-import com.zhpan.bannerview.BaseViewHolder;
-
-/**
- * @author DBoy
- * @date 2020/12/11
- * Class 描述 : 使用ViewBinding示例
- */
-public class ViewBindingSampleAdapter extends BaseBannerAdapter<Integer> {
-
-  private final int mRoundCorner;
-
-  public ViewBindingSampleAdapter(int roundCorner) {
-    mRoundCorner = roundCorner;
-  }
-
-  @Override
-  protected void bindData(BaseViewHolder<Integer> holder, Integer data, int position,
-      int pageSize) {
-    //示例使用ViewBinding
-    ItemSlideModeBinding viewBinding = ItemSlideModeBinding.bind(holder.itemView);
-    viewBinding.bannerImage.setRoundCorner(mRoundCorner);
-    viewBinding.bannerImage.setImageResource(data);
-  }
-
-  @Override
-  public int getLayoutId(int viewType) {
-    return R.layout.item_slide_mode;
-  }
-}
-

+ 39 - 0
app/src/main/java/com/example/zhpan/banner/adapter/ViewBindingSampleAdapter.kt

@@ -0,0 +1,39 @@
+package com.example.zhpan.banner.adapter
+
+import android.view.View
+import android.view.ViewGroup
+import com.example.zhpan.banner.R.layout
+import com.example.zhpan.banner.databinding.ItemSlideModeBinding
+import com.zhpan.bannerview.BaseBannerAdapter
+import com.zhpan.bannerview.BaseViewHolder
+
+/**
+ * @author DBoy
+ * @date 2020/12/11
+ * Class 描述 : 使用ViewBinding示例
+ */
+class ViewBindingSampleAdapter(private val mRoundCorner: Int) : BaseBannerAdapter<Int>() {
+
+  override fun createViewHolder(
+    parent: ViewGroup,
+    itemView: View,
+    viewType: Int
+  ): BaseViewHolder<Int> {
+    return ViewBindingViewHolder(ItemSlideModeBinding.bind(itemView))
+  }
+
+  override fun bindData(holder: BaseViewHolder<Int>, data: Int, position: Int, pageSize: Int) {
+    if (holder is ViewBindingViewHolder) {
+      holder.viewBinding.bannerImage.setRoundCorner(mRoundCorner)
+      holder.viewBinding.bannerImage.setImageResource(data)
+    }
+  }
+
+  override fun getLayoutId(viewType: Int): Int {
+    return layout.item_slide_mode
+  }
+}
+
+internal class ViewBindingViewHolder(var viewBinding: ItemSlideModeBinding) :
+  BaseViewHolder<Int>(viewBinding.root)
+

+ 4 - 2
app/src/main/java/com/example/zhpan/banner/fragment/OthersFragment.java

@@ -23,6 +23,7 @@ import com.zhpan.indicator.IndicatorView;
 import com.zhpan.indicator.base.IIndicator;
 import com.zhpan.indicator.enums.IndicatorSlideMode;
 
+import java.util.List;
 import java.util.Random;
 
 /**
@@ -168,8 +169,9 @@ public class OthersFragment extends BaseFragment implements View.OnClickListener
   }
 
   private void updateData() {
-    mViewPager.refreshData(getPicList(new Random().nextInt(5) - 1));
-    ToastUtils.showShort("size=" + mViewPager.getData().size());
+    List<Integer> picList = getPicList(new Random().nextInt(5) - 1);
+    ToastUtils.showShort("size=" +picList.size());
+    mViewPager.refreshData(picList);
   }
 
   @Override

+ 168 - 159
app/src/main/java/com/example/zhpan/banner/fragment/PageFragment.kt

@@ -2,6 +2,7 @@ package com.example.zhpan.banner.fragment
 
 import android.os.Bundle
 import android.view.View
+import android.widget.Button
 import android.widget.RadioGroup
 import com.blankj.utilcode.util.ToastUtils
 import com.example.zhpan.banner.R
@@ -18,178 +19,186 @@ import com.zhpan.indicator.enums.IndicatorSlideMode
  * Created by zhpan on 2018/7/24.
  */
 class PageFragment : BaseFragment() {
-    private lateinit var mViewPager: BannerViewPager<Int>
-    private lateinit var mRadioGroupPageStyle: RadioGroup
-    private lateinit var mRadioGroupMoreStyle: RadioGroup
-    override val layout: Int
-        get() = R.layout.fragment_find
+  private lateinit var mViewPager: BannerViewPager<Int>
+  private lateinit var mRadioGroupPageStyle: RadioGroup
+  private lateinit var mRadioGroupMoreStyle: RadioGroup
+  override val layout: Int
+    get() = R.layout.fragment_find
 
-    override fun initTitle() {}
-    override fun initView(savedInstanceState: Bundle?, view: View) {
-        mViewPager = view.findViewById(R.id.banner_view)
-        mRadioGroupPageStyle = view.findViewById(R.id.rg_page_style)
-        mRadioGroupMoreStyle = view.findViewById(R.id.rg_more_page_style)
-        initBVP()
-        initRadioGroup()
-        view.findViewById<View>(R.id.rb_multi_page_overlap).performClick()
+  override fun initTitle() {}
+  override fun initView(savedInstanceState: Bundle?, view: View) {
+    mViewPager = view.findViewById(R.id.banner_view)
+    mRadioGroupPageStyle = view.findViewById(R.id.rg_page_style)
+    mRadioGroupMoreStyle = view.findViewById(R.id.rg_more_page_style)
+    view.findViewById<Button>(R.id.btn_next).setOnClickListener {
+      mViewPager.currentItem = mViewPager.currentItem + 1
+      itemClick(mViewPager.currentItem)
     }
+    view.findViewById<Button>(R.id.btn_pre).setOnClickListener {
+      mViewPager.currentItem = mViewPager.currentItem - 1
+      itemClick(mViewPager.currentItem)
+    }
+    initBVP()
+    initRadioGroup()
+    view.findViewById<View>(R.id.rb_multi_page_overlap).performClick()
+  }
 
-    private fun initBVP() {
-        mViewPager.apply {
-            registerLifecycleObserver(lifecycle)
-            adapter = ViewBindingSampleAdapter(resources.getDimensionPixelOffset(dimen.dp_8))
-            setIndicatorSlideMode(IndicatorSlideMode.SCALE)
-            setIndicatorSliderColor(
-                getColor(color.red_normal_color),
-                getColor(color.red_checked_color)
-            )
-            setIndicatorSliderRadius(
-                resources.getDimensionPixelOffset(dimen.dp_4),
-                resources.getDimensionPixelOffset(dimen.dp_5)
-            )
-            setOnPageClickListener ({ _: View, position: Int -> itemClick(position) },true)
-            setInterval(5000)
-        }
+  private fun initBVP() {
+    mViewPager.apply {
+      registerLifecycleObserver(lifecycle)
+      adapter = ViewBindingSampleAdapter(resources.getDimensionPixelOffset(dimen.dp_8))
+      setIndicatorSlideMode(IndicatorSlideMode.SCALE)
+      setIndicatorSliderColor(
+        getColor(color.red_normal_color),
+        getColor(color.red_checked_color)
+      )
+      setIndicatorSliderRadius(
+        resources.getDimensionPixelOffset(dimen.dp_4),
+        resources.getDimensionPixelOffset(dimen.dp_5)
+      )
+      setOnPageClickListener({ _: View, position: Int -> itemClick(position) }, true)
+      setInterval(5000)
     }
+  }
 
-    private fun initRadioGroup() {
-        mRadioGroupPageStyle.setOnCheckedChangeListener { _: RadioGroup?, checkedId: Int ->
-            when (checkedId) {
-                R.id.rb_multi_page_overlap ->
-                    setupBanner(
-                        PageStyle.MULTI_PAGE_OVERLAP,
-                        resources.getDimensionPixelOffset(dimen.dp_10)
-                    )
-                R.id.rb_multi_page_overlap1 ->
-                    setupBanner(
-                        PageStyle.MULTI_PAGE_OVERLAP,
-                        resources.getDimensionPixelOffset(dimen.dp_100)
-                    )
-                R.id.rb_multi_page_scale ->
-                    setupBanner(
-                        PageStyle.MULTI_PAGE_SCALE,
-                        resources.getDimensionPixelOffset(dimen.dp_10)
-                    )
-                R.id.rb_multi_scale_page2 ->
-                    setupBanner(
-                        PageStyle.MULTI_PAGE_SCALE,
-                        resources.getDimensionPixelOffset(dimen.dp_120)
-                    )
-                R.id.rb_multi_scale_page3 -> {
-                    setupBanner(
-                        PageStyle.MULTI_PAGE_SCALE,
-                        resources.getDimensionPixelOffset(dimen.dp_0),
-                        resources.getDimensionPixelOffset(dimen.dp_200)
-                    )
-                }
-            }
-        }
-        mRadioGroupMoreStyle.setOnCheckedChangeListener { _: RadioGroup?, checkedId: Int ->
-            when (checkedId) {
-                R.id.rb_multi_page3 ->
-                    setupMultiPageBanner()
-                R.id.rb_multi_page4 ->
-                    setupRightPageReveal()
-                R.id.rb_netease_music_style ->
-                    setNetEaseMusicStyle()
-                R.id.rb_qq_music_style ->
-                    setQQMusicStyle()
-            }
+  private fun initRadioGroup() {
+    mRadioGroupPageStyle.setOnCheckedChangeListener { _: RadioGroup?, checkedId: Int ->
+      when (checkedId) {
+        R.id.rb_multi_page_overlap ->
+          setupBanner(
+            PageStyle.MULTI_PAGE_OVERLAP,
+            resources.getDimensionPixelOffset(dimen.dp_10)
+          )
+        R.id.rb_multi_page_overlap1 ->
+          setupBanner(
+            PageStyle.MULTI_PAGE_OVERLAP,
+            resources.getDimensionPixelOffset(dimen.dp_100)
+          )
+        R.id.rb_multi_page_scale ->
+          setupBanner(
+            PageStyle.MULTI_PAGE_SCALE,
+            resources.getDimensionPixelOffset(dimen.dp_10)
+          )
+        R.id.rb_multi_scale_page2 ->
+          setupBanner(
+            PageStyle.MULTI_PAGE_SCALE,
+            resources.getDimensionPixelOffset(dimen.dp_120)
+          )
+        R.id.rb_multi_scale_page3 -> {
+          setupBanner(
+            PageStyle.MULTI_PAGE_SCALE,
+            resources.getDimensionPixelOffset(dimen.dp_0),
+            resources.getDimensionPixelOffset(dimen.dp_200)
+          )
         }
+      }
     }
-
-    /**
-     * Different page styles can be implement by use [BannerViewPager.setPageStyle] and
-     * [BannerViewPager.setRevealWidth]
-     *
-     * @param pageStyle Optional params [PageStyle.MULTI_PAGE_SCALE] and [PageStyle.MULTI_PAGE_OVERLAP]
-     * @param revealWidth In the multi-page mode, The exposed width of the items on the left and right sides
-     */
-    private fun setupBanner(@APageStyle pageStyle: Int, revealWidth: Int) {
-        setupBanner(pageStyle, revealWidth, revealWidth)
+    mRadioGroupMoreStyle.setOnCheckedChangeListener { _: RadioGroup?, checkedId: Int ->
+      when (checkedId) {
+        R.id.rb_multi_page3 ->
+          setupMultiPageBanner()
+        R.id.rb_multi_page4 ->
+          setupRightPageReveal()
+        R.id.rb_netease_music_style ->
+          setNetEaseMusicStyle()
+        R.id.rb_qq_music_style ->
+          setQQMusicStyle()
+      }
     }
+  }
 
-    private fun setupBanner(
-        @APageStyle pageStyle: Int,
-        leftRevealWidth: Int,
-        rightRevealWidth: Int
-    ) {
-        mViewPager
-            .setPageMargin(resources.getDimensionPixelOffset(dimen.dp_15))
-            .setScrollDuration(800)
-            .setRevealWidth(leftRevealWidth, rightRevealWidth)
-            .setPageStyle(pageStyle)
-            .create(getPicList(4))
-    }
+  /**
+   * Different page styles can be implement by use [BannerViewPager.setPageStyle] and
+   * [BannerViewPager.setRevealWidth]
+   *
+   * @param pageStyle Optional params [PageStyle.MULTI_PAGE_SCALE] and [PageStyle.MULTI_PAGE_OVERLAP]
+   * @param revealWidth In the multi-page mode, The exposed width of the items on the left and right sides
+   */
+  private fun setupBanner(@APageStyle pageStyle: Int, revealWidth: Int) {
+    setupBanner(pageStyle, revealWidth, revealWidth)
+  }
 
-    /**
-     * Multi Page Style 1
-     */
-    private fun setupMultiPageBanner() {
-        mViewPager
-            .setPageMargin(resources.getDimensionPixelOffset(dimen.dp_10))
-            .setRevealWidth(resources.getDimensionPixelOffset(dimen.dp_10))
-            .create(getPicList(4))
-        mViewPager.removeDefaultPageTransformer()
-    }
+  private fun setupBanner(
+    @APageStyle pageStyle: Int,
+    leftRevealWidth: Int,
+    rightRevealWidth: Int
+  ) {
+    mViewPager
+      .setPageMargin(resources.getDimensionPixelOffset(dimen.dp_15))
+      .setScrollDuration(800)
+      .setRevealWidth(leftRevealWidth, rightRevealWidth)
+      .setPageStyle(pageStyle,0.85f)
+      .create(getPicList(4))
+  }
 
-    /**
-     * Multi Page Style 2
-     */
-    private fun setupRightPageReveal() {
-        mViewPager
-            .setPageMargin(resources.getDimensionPixelOffset(dimen.dp_10))
-            .setRevealWidth(0, resources.getDimensionPixelOffset(dimen.dp_30))
-            .create(getPicList(4))
-        mViewPager.removeDefaultPageTransformer()
-    }
+  /**
+   * Multi Page Style 1
+   */
+  private fun setupMultiPageBanner() {
+    mViewPager
+      .setPageMargin(resources.getDimensionPixelOffset(dimen.dp_10))
+      .setRevealWidth(resources.getDimensionPixelOffset(dimen.dp_10))
+      .create(getPicList(4))
+    mViewPager.removeDefaultPageTransformer()
+  }
 
-    /**
-     * QQ Music Banner Style
-     */
-    private fun setNetEaseMusicStyle() {
-        mViewPager
-            .setPageMargin(resources.getDimensionPixelOffset(dimen.dp_20))
-            .setRevealWidth(resources.getDimensionPixelOffset(dimen.dp_m_10))
-            .setIndicatorSliderColor(
-                getColor(color.red_normal_color),
-                getColor(color.red_checked_color)
-            )
-            .setOnPageClickListener { view: View?, position: Int ->
-                ToastUtils.showShort(
-                    "position:$position"
-                )
-            }
-            .setInterval(5000).create(getPicList(4))
-        mViewPager.removeDefaultPageTransformer()
-    }
+  /**
+   * Multi Page Style 2
+   */
+  private fun setupRightPageReveal() {
+    mViewPager
+      .setPageMargin(resources.getDimensionPixelOffset(dimen.dp_10))
+      .setRevealWidth(0, resources.getDimensionPixelOffset(dimen.dp_30))
+      .create(getPicList(4))
+    mViewPager.removeDefaultPageTransformer()
+  }
 
-    /**
-     * NetEase Music Banner Style
-     */
-    private fun setQQMusicStyle() {
-        mViewPager
-            .setPageMargin(resources.getDimensionPixelOffset(dimen.dp_15))
-            .setRevealWidth(BannerUtils.dp2px(0f))
-            .setIndicatorSliderColor(
-                getColor(color.red_normal_color),
-                getColor(color.red_checked_color)
-            )
-            .setOnPageClickListener { _: View?, position: Int ->
-                ToastUtils.showShort(
-                    "position:$position"
-                )
-            }
-            .setInterval(5000).create(getPicList(4))
-        mViewPager.removeDefaultPageTransformer()
-    }
+  /**
+   * QQ Music Banner Style
+   */
+  private fun setNetEaseMusicStyle() {
+    mViewPager
+      .setPageMargin(resources.getDimensionPixelOffset(dimen.dp_20))
+      .setRevealWidth(resources.getDimensionPixelOffset(dimen.dp_m_10))
+      .setIndicatorSliderColor(
+        getColor(color.red_normal_color),
+        getColor(color.red_checked_color)
+      )
+      .setOnPageClickListener { view: View?, position: Int ->
+        ToastUtils.showShort(
+          "position:$position"
+        )
+      }
+      .setInterval(5000).create(getPicList(4))
+    mViewPager.removeDefaultPageTransformer()
+  }
 
-    private fun itemClick(position: Int) {
-        ToastUtils.showShort("position:$position")
-    }
+  /**
+   * NetEase Music Banner Style
+   */
+  private fun setQQMusicStyle() {
+    mViewPager
+      .setPageMargin(resources.getDimensionPixelOffset(dimen.dp_15))
+      .setRevealWidth(BannerUtils.dp2px(0f))
+      .setIndicatorSliderColor(
+        getColor(color.red_normal_color),
+        getColor(color.red_checked_color)
+      )
+      .setOnPageClickListener { _: View?, position: Int ->
+        ToastUtils.showShort(
+          "position:$position"
+        )
+      }
+      .setInterval(5000).create(getPicList(4))
+    mViewPager.removeDefaultPageTransformer()
+  }
 
-    companion object {
-        val instance: PageFragment
-            get() = PageFragment()
-    }
+  private fun itemClick(position: Int) {
+    ToastUtils.showShort("position:$position")
+  }
+
+  companion object {
+    val instance: PageFragment
+      get() = PageFragment()
+  }
 }

+ 1 - 4
app/src/main/java/com/example/zhpan/banner/view/CornerImageView.kt

@@ -1,7 +1,6 @@
 package com.example.zhpan.banner.view
 
 import android.content.Context
-import android.os.Build
 import android.util.AttributeSet
 
 import androidx.appcompat.widget.AppCompatImageView
@@ -14,8 +13,6 @@ class CornerImageView @JvmOverloads constructor(
 ) : AppCompatImageView(context, attrs, defStyleAttr) {
 
   fun setRoundCorner(radius: Int) {
-    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
-      ViewStyleSetter.applyRoundCorner(this, radius.toFloat())
-    }
+    ViewStyleSetter.applyRoundCorner(this, radius.toFloat())
   }
 }

+ 19 - 2
app/src/main/res/layout/fragment_find.xml

@@ -16,6 +16,25 @@
         app:bvp_indicator_slide_mode="worm"
         app:bvp_page_style="multi_page" />
 
+    <androidx.appcompat.widget.LinearLayoutCompat
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:orientation="horizontal"
+        android:gravity="center_horizontal">
+      <Button
+          android:id="@+id/btn_pre"
+          android:layout_width="wrap_content"
+          android:layout_height="wrap_content"
+          android:text="@string/pre"/>
+
+      <Button
+          android:id="@+id/btn_next"
+          android:layout_width="wrap_content"
+          android:layout_height="wrap_content"
+          android:text="@string/next"
+          />
+    </androidx.appcompat.widget.LinearLayoutCompat>
+
     <TextView
         android:id="@+id/tv_page_style"
         android:layout_width="wrap_content"
@@ -132,8 +151,6 @@
           android:layout_marginTop="@dimen/dp_15"
           android:text="NetEase Music Banner Style"
           android:textSize="@dimen/sp_16" />
-
-
     </RadioGroup>
 
   </LinearLayout>

+ 2 - 0
app/src/main/res/values/strings.xml

@@ -43,4 +43,6 @@
     <string name="wrong_password">密码错误</string>
     <string name="remote_login">您的账号已在其它设备上登录,如非本人操作,请及时修改密码!</string>
   <string name="text_page_style_more">More Page Styles:</string>
+  <string name="next">下一个</string>
+    <string name="pre">上一个</string>
 </resources>

+ 0 - 1
bannerview/build.gradle

@@ -1,5 +1,4 @@
 apply plugin: 'com.android.library'
-apply plugin: 'com.github.dcendents.android-maven'
 apply plugin: 'kotlin-android'
 android {
     compileSdkVersion 28

+ 11 - 17
bannerview/src/main/java/com/zhpan/bannerview/BannerViewPager.java

@@ -423,6 +423,8 @@ public class BannerViewPager<T> extends RelativeLayout implements LifecycleObser
       int orientation = bannerOptions.getOrientation();
       int padding2 = bannerOptions.getPageMargin() + rightRevealWidth;
       int padding1 = bannerOptions.getPageMargin() + leftRevealWidth;
+      if (padding1 < 0) padding1 = 0;
+      if (padding2 < 0) padding2 = 0;
       if (orientation == ViewPager2.ORIENTATION_HORIZONTAL) {
         recyclerView.setPadding(padding1, 0, padding2, 0);
       } else if (orientation == ViewPager2.ORIENTATION_VERTICAL) {
@@ -515,10 +517,10 @@ public class BannerViewPager<T> extends RelativeLayout implements LifecycleObser
     if (!isLooping
         && isAutoPlay()
         && mBannerPagerAdapter != null
-        &&
-        mBannerPagerAdapter.getListSize() > 1
-        && isAttachedToWindow()
-        && lifecycleRegistry.getCurrentState() == Lifecycle.State.RESUMED) {
+        && mBannerPagerAdapter.getListSize() > 1
+        && isAttachedToWindow() && (lifecycleRegistry == null
+        || lifecycleRegistry.getCurrentState() == Lifecycle.State.RESUMED
+        || lifecycleRegistry.getCurrentState() == Lifecycle.State.CREATED)) {
       mHandler.postDelayed(mRunnable, getInterval());
       isLooping = true;
     }
@@ -989,20 +991,12 @@ public class BannerViewPager<T> extends RelativeLayout implements LifecycleObser
    */
   public void setCurrentItem(int item, boolean smoothScroll) {
     if (isCanLoopSafely()) {
-      int pageSize = mBannerPagerAdapter.getListSize();
-      item = item >= pageSize ? pageSize - 1 : item;
+      stopLoop();
       int currentItem = mViewPager.getCurrentItem();
-      boolean canLoop = mBannerManager.getBannerOptions().isCanLoop();
-      int realPosition = BannerUtils.getRealPosition(currentItem, pageSize);
-      if (currentItem != item) {
-        if (item == 0 && realPosition == pageSize - 1) {
-          mViewPager.setCurrentItem(currentItem + 1, smoothScroll);
-        } else if (realPosition == 0 && item == pageSize - 1) {
-          mViewPager.setCurrentItem(currentItem - 1, smoothScroll);
-        } else {
-          mViewPager.setCurrentItem(currentItem + (item - realPosition), smoothScroll);
-        }
-      }
+      int realPosition =
+          BannerUtils.getRealPosition(currentItem, mBannerPagerAdapter.getListSize());
+      mViewPager.setCurrentItem(currentItem + (item - realPosition), smoothScroll);
+      startLoop();
     } else {
       mViewPager.setCurrentItem(item, smoothScroll);
     }

+ 1 - 1
bannerview/src/main/java/com/zhpan/bannerview/BaseBannerAdapter.java

@@ -108,7 +108,7 @@ public abstract class BaseBannerAdapter<T> extends RecyclerView.Adapter<BaseView
   }
 
   /**
-   * Generally,there is no need to override this method in subclasses.
+   * Generally,subclasses do not need to override this method,Unless you want to use a custom ViewHolder.
    *
    * This method called by {@link #onCreateViewHolder(ViewGroup, int)} to create a default {@link
    * BaseViewHolder}

+ 16 - 10
bannerview/src/main/java/com/zhpan/bannerview/transform/OverlapPageTransformer.kt

@@ -43,15 +43,21 @@ class OverlapPageTransformer(
     ) { "unSelectedItemAlpha value should be between 1.0 to 0.0" }
   }
 
-  private val scalingValue = 0.2f
+  private var scalingValue = 0.2f
 
   override fun transformPage(
     page: View,
     position: Float
   ) {
     page.apply {
+      scalingValue = if (minScale >= 0.8) {
+        0.2f
+      } else if (minScale >= 0.6) {
+        0.3f
+      } else {
+        0.4f
+      }
       elevation = -abs(position)
-
       val delta = max(1f - abs(position * (1 - 0.5f)), 0.5f)
 
       if (unSelectedItemRotation != 0f) {
@@ -72,20 +78,20 @@ class OverlapPageTransformer(
         ViewPager2.ORIENTATION_HORIZONTAL -> {
           translationX =
             position * dp2px +
-                if (position > 0) {
-                  (-width * (1f - scale))
-                } else {
-                  (width * (1f - scale))
-                }
-        }
-        ViewPager2.ORIENTATION_VERTICAL -> {
-          translationY = position * dp2px +
               if (position > 0) {
                 (-width * (1f - scale))
               } else {
                 (width * (1f - scale))
               }
         }
+        ViewPager2.ORIENTATION_VERTICAL -> {
+          translationY = position * dp2px +
+            if (position > 0) {
+              (-width * (1f - scale))
+            } else {
+              (width * (1f - scale))
+            }
+        }
         else -> throw IllegalArgumentException(
           "Gives correct orientation value, ViewPager2.ORIENTATION_HORIZONTAL or ViewPager2.ORIENTATION_VERTICAL"
         )

+ 2 - 2
build.gradle

@@ -1,14 +1,14 @@
 // Top-level build file where you can add configuration options common to all sub-projects/modules.
 
 buildscript {
-    ext.kotlin_version = '1.5.0'
+    ext.kotlin_version = '1.7.20'
     repositories {
         jcenter()
         mavenCentral()
         google()
     }
     dependencies {
-        classpath 'com.android.tools.build:gradle:4.2.1'
+        classpath 'com.android.tools.build:gradle:7.1.2'
         classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
 //        classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4'
         classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

+ 1 - 1
gradle/wrapper/gradle-wrapper.properties

@@ -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-6.7.1-all.zip
+distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-all.zip