Skip to content

Commit

Permalink
Merge pull request youth5201314#1039 from youth5201314/revert-1037-ma…
Browse files Browse the repository at this point in the history
…ster

Revert "增加一屏多页(大于三页)的功能"
  • Loading branch information
youth5201314 authored May 31, 2021
2 parents f9b2610 + 751223b commit b82bf41
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 140 deletions.
3 changes: 0 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'

android {
compileSdkVersion 30
Expand Down Expand Up @@ -31,8 +30,6 @@ android {

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "androidx.core:core-ktx:+"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.recyclerview:recyclerview:1.2.0'
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'
Expand Down
69 changes: 0 additions & 69 deletions app/src/main/java/com/test/banner/FivePagesOneScreenTransformer.kt

This file was deleted.

23 changes: 7 additions & 16 deletions app/src/main/java/com/test/banner/ui/GalleryActivity.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
package com.test.banner.ui;

import android.os.Bundle;

import androidx.appcompat.app.AppCompatActivity;
import android.view.View;

import com.test.banner.R;
import com.test.banner.FivePagesOneScreenTransformer;
import com.test.banner.adapter.ImageAdapter;
import com.test.banner.adapter.ImageNetAdapter;
import com.test.banner.bean.DataBean;
import com.youth.banner.Banner;
import com.youth.banner.indicator.CircleIndicator;
import com.youth.banner.indicator.DrawableIndicator;
import com.youth.banner.transformer.AlphaPageTransformer;

import androidx.appcompat.app.AppCompatActivity;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class GalleryActivity extends AppCompatActivity {

Expand All @@ -23,8 +25,6 @@ public class GalleryActivity extends AppCompatActivity {
Banner mBanner2;
@BindView(R.id.indicator)
DrawableIndicator indicator;
@BindView(R.id.banner3)
Banner mBanner3;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -48,20 +48,11 @@ protected void onCreate(Bundle savedInstanceState) {
* 魅族效果
*/
mBanner2.setAdapter(new ImageAdapter(DataBean.getTestData()));
mBanner2.setIndicator(indicator, false);
mBanner2.setIndicator(indicator,false);
//添加魅族效果
mBanner2.setBannerGalleryMZ(20);

/**
* 一屏五页
*/
mBanner3.setAdapter(new ImageAdapter(DataBean.getTestData()));
mBanner3.setIndicator(new CircleIndicator(this));
mBanner3.getViewPager2().setOffscreenPageLimit(4);
mBanner3.setIncreaseCount(8);
mBanner3.setPageTransformer(new FivePagesOneScreenTransformer());
mBanner3.setRecyclerViewPadding(350);
mBanner3.setCurrentItem(3);


}

Expand Down
9 changes: 0 additions & 9 deletions app/src/main/res/layout/activity_gallery.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,4 @@
android:layout_gravity="center_horizontal"
banner:normal_drawable="@drawable/indicator_normal"
banner:selected_drawable="@drawable/indicator_selected"/>

<com.youth.banner.Banner
android:id="@+id/banner3"
android:layout_width="match_parent"
android:layout_height="140dp"
android:layout_margin="10dp"
banner:banner_radius="5dp"
banner:banner_indicator_normal_color="@android:color/white"
banner:banner_indicator_selected_color="@color/colorPrimary" />
</LinearLayout>
47 changes: 12 additions & 35 deletions banner/src/main/java/com/youth/banner/Banner.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.PaintFlagsDrawFilter;
import android.graphics.Path;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffXfermode;
Expand Down Expand Up @@ -37,9 +38,10 @@
import com.youth.banner.listener.OnPageChangeListener;
import com.youth.banner.transformer.MZScaleInTransformer;
import com.youth.banner.transformer.ScaleInTransformer;
import com.youth.banner.util.BannerLifecycleObserver;
import com.youth.banner.util.BannerLifecycleObserverAdapter;
import com.youth.banner.util.BannerUtils;
import com.youth.banner.util.BannerLifecycleObserver;
import com.youth.banner.util.LogUtils;
import com.youth.banner.util.ScrollSpeedManger;

import java.lang.annotation.Retention;
Expand Down Expand Up @@ -88,7 +90,6 @@ public class Banner<T, BA extends BannerAdapter<T, ? extends RecyclerView.ViewHo
private int indicatorMarginBottom;
private int indicatorHeight = BannerConfig.INDICATOR_HEIGHT;
private int indicatorRadius = BannerConfig.INDICATOR_RADIUS;
private int increaseCount = BannerConfig.INCREASE_COUNT;

public static final int HORIZONTAL = 0;
public static final int VERTICAL = 1;
Expand All @@ -108,7 +109,7 @@ public class Banner<T, BA extends BannerAdapter<T, ? extends RecyclerView.ViewHo
private Paint mImagePaint;

@Retention(SOURCE)
@IntDef({HORIZONTAL, VERTICAL})
@IntDef( {HORIZONTAL, VERTICAL})
public @interface Orientation {
}

Expand Down Expand Up @@ -390,11 +391,10 @@ public void onPageScrollStateChanged(int state) {
//滑动闲置或滑动结束
isScrolled = false;
if (mTempPosition != INVALID_VALUE && mIsInfiniteLoop) {
int increaseCountHalf = increaseCount / 2;
if (mTempPosition <= increaseCountHalf - 1) {
setCurrentItem(getRealCount() + mTempPosition, false);
} else if (mTempPosition >= getRealCount() + increaseCountHalf) {
setCurrentItem(increaseCountHalf, false);
if (mTempPosition == 0) {
setCurrentItem(getRealCount(), false);
} else if (mTempPosition == getItemCount() - 1) {
setCurrentItem(1, false);
}
}
}
Expand Down Expand Up @@ -462,7 +462,7 @@ private void setInfiniteLoop() {
setStartPosition(isInfiniteLoop() ? mStartPosition : 0);
}

public void setRecyclerViewPadding(int itemPadding) {
private void setRecyclerViewPadding(int itemPadding) {
setRecyclerViewPadding(itemPadding, itemPadding);
}

Expand Down Expand Up @@ -537,7 +537,6 @@ public int getRealCount() {

/**
* 是否要拦截事件
*
* @param intercept
* @return
*/
Expand All @@ -548,7 +547,6 @@ public Banner setIntercept(boolean intercept) {

/**
* 跳转到指定位置(最好在设置了数据后在调用,不然没有意义)
*
* @param position
* @return
*/
Expand All @@ -558,7 +556,6 @@ public Banner setCurrentItem(int position) {

/**
* 跳转到指定位置(最好在设置了数据后在调用,不然没有意义)
*
* @param position
* @param smoothScroll
* @return
Expand Down Expand Up @@ -606,25 +603,6 @@ public Banner setUserInputEnabled(boolean enabled) {
return this;
}

public int getIncreaseCount() {
return increaseCount;
}

/**
* 设置增加的数量,适合一屏多页无限轮播
*
* @param increaseCount
*/
public Banner setIncreaseCount(int increaseCount) {
if (increaseCount % 2 == 0) {
this.increaseCount = increaseCount;
if (getAdapter() != null) {
getAdapter().setIncreaseCount(increaseCount);
}
}
return this;
}

/**
* 添加PageTransformer,可以组合效果
* {@link ViewPager2.PageTransformer}
Expand Down Expand Up @@ -742,13 +720,12 @@ public Banner setAdapter(BA adapter) {

/**
* 设置banner的适配器
*
* @param adapter
* @param isInfiniteLoop 是否支持无限循环
* @return
*/
public Banner setAdapter(BA adapter, boolean isInfiniteLoop) {
mIsInfiniteLoop = isInfiniteLoop;
public Banner setAdapter(BA adapter,boolean isInfiniteLoop) {
mIsInfiniteLoop=isInfiniteLoop;
setInfiniteLoop();
setAdapter(adapter);
return this;
Expand Down Expand Up @@ -848,7 +825,7 @@ public Banner setBannerGalleryEffect(int itemWidth, int pageMargin) {
* @param pageMargin 页面间距,单位dp
*/
public Banner setBannerGalleryEffect(int leftItemWidth, int rightItemWidth, int pageMargin) {
return setBannerGalleryEffect(leftItemWidth, rightItemWidth, pageMargin, .85f);
return setBannerGalleryEffect(leftItemWidth,rightItemWidth, pageMargin, .85f);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
import java.util.ArrayList;
import java.util.List;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;


public abstract class BannerAdapter<T, VH extends RecyclerView.ViewHolder> extends RecyclerView.Adapter<VH> implements IViewHolder<T, VH> {
protected List<T> mDatas = new ArrayList<>();
Expand Down Expand Up @@ -97,7 +100,7 @@ public int getRealCount() {
}

public int getRealPosition(int position) {
return BannerUtils.getRealPosition(mIncreaseCount >= 2, position, getRealCount());
return BannerUtils.getRealPosition(mIncreaseCount == BannerConfig.INCREASE_COUNT, position, getRealCount());
}

public void setOnBannerListener(OnBannerListener<T> listener) {
Expand Down
16 changes: 10 additions & 6 deletions banner/src/main/java/com/youth/banner/util/BannerUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,21 @@ public class BannerUtils {
* 获取真正的位置
*
* @param isIncrease 首尾是否有增加
* @param position 当前位置
* @param realCount 真实数量
* @param position 当前位置
* @param realCount 真实数量
* @return
*/
public static int getRealPosition(boolean isIncrease, int position, int realCount) {
if (!isIncrease || realCount == 0) {
if (!isIncrease) {
return position;
}
int realPosition = position % realCount - 1;
if (realPosition < 0) {
int realPosition;
if (position == 0) {
realPosition = realCount - 1;
} else if (position == realCount + 1) {
realPosition = 0;
} else {
realPosition = position - 1;
}
return realPosition;
}
Expand Down Expand Up @@ -64,7 +68,7 @@ public static int dp2px(float dp) {
* @return
*/
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
public static void setBannerRound(View view, float radius) {
public static void setBannerRound(View view,float radius) {
view.setOutlineProvider(new ViewOutlineProvider() {
@Override
public void getOutline(View view, Outline outline) {
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ allprojects {
maven { url "https://s01.oss.sonatype.org/content/groups/public" }
jcenter()
google()
mavenCentral()

}
}

Expand Down

0 comments on commit b82bf41

Please sign in to comment.