浏览代码

Remove OvalViewOutlineProvider.java

zhpanvip 3 年之前
父节点
当前提交
0e3220d492

+ 0 - 28
app/src/main/java/com/example/zhpan/banner/recyclerview/listener/ICustomScrollListener.java

@@ -1,28 +0,0 @@
-package com.example.zhpan.banner.recyclerview.listener;
-
-/**
- * 2018.11.4
- * 使用了自己的刷新加载view时,需要实现改接口,不然接受不到数据
- * 如果不需要使用自定义的刷新View,可使用{@link IScrollListener}
- */
-public interface ICustomScrollListener {
-  /**
-   * 下拉刷新时候的回调
-   */
-  void scrollRefreshState(int state);
-
-  /**
-   * 上拉加载时候的回调
-   */
-  void scrollLoadMoreState(int state);
-
-  /**
-   * 在此方法内写刷新的逻辑
-   */
-  void refresh();
-
-  /**
-   * 在此方法内写加载的逻辑
-   */
-  void loadMore();
-}

+ 0 - 20
app/src/main/java/com/example/zhpan/banner/recyclerview/listener/IScrollListener.java

@@ -1,20 +0,0 @@
-package com.example.zhpan.banner.recyclerview.listener;
-
-/**
- * 2018.11.4
- * 当使用默认刷新是调用该接口
- * 该接口只用于回调刷新和加载数据
- * 优先级小于{@link ICustomScrollListener}
- */
-public interface IScrollListener {
-
-  /**
-   * 在此方法内写刷新的逻辑
-   */
-  void refresh();
-
-  /**
-   * 在此方法内写加载的逻辑
-   */
-  void loadMore();
-}

+ 1 - 1
app/src/main/java/com/example/zhpan/banner/recyclerview/module/ViewConfig.java → app/src/main/java/com/example/zhpan/banner/recyclerview/module/RecyclerViewConfig.java

@@ -2,7 +2,7 @@ package com.example.zhpan.banner.recyclerview.module;
 
 
 import android.view.View;
 import android.view.View;
 
 
-public class ViewConfig {
+public class RecyclerViewConfig {
   public static final String HEADVIEW = "_head_";
   public static final String HEADVIEW = "_head_";
   public static final String FOOTVIEW = "_foot_";
   public static final String FOOTVIEW = "_foot_";
   public static final int HEADVIEW_TYPE = 100000;
   public static final int HEADVIEW_TYPE = 100000;

+ 10 - 9
app/src/main/java/com/example/zhpan/banner/recyclerview/ui/CustomAdapter.java

@@ -16,22 +16,22 @@ import android.widget.FrameLayout;
 
 
 import com.example.zhpan.banner.R;
 import com.example.zhpan.banner.R;
 import com.example.zhpan.banner.recyclerview.listener.ICustomClickListener;
 import com.example.zhpan.banner.recyclerview.listener.ICustomClickListener;
-import com.example.zhpan.banner.recyclerview.module.ViewConfig;
+import com.example.zhpan.banner.recyclerview.module.RecyclerViewConfig;
 
 
 import java.util.ArrayList;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.List;
 
 
 final class CustomAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
 final class CustomAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
-  private final List<ViewConfig> headConfig;
-  private final List<ViewConfig> footConfig;
+  private final List<RecyclerViewConfig> headConfig;
+  private final List<RecyclerViewConfig> footConfig;
   private final LayoutInflater inflater;
   private final LayoutInflater inflater;
   private final RecyclerView.Adapter mAdapter;
   private final RecyclerView.Adapter mAdapter;
   private int headCount = 0;
   private int headCount = 0;
   private int footerCount = 0;
   private int footerCount = 0;
   private ICustomClickListener customClickListener;
   private ICustomClickListener customClickListener;
 
 
-  public CustomAdapter(List<ViewConfig> headConfig, List<ViewConfig> footConfig,
-      RecyclerView.Adapter mAdapter, Context mContext, RecyclerView mRecyclerView) {
+  public CustomAdapter(List<RecyclerViewConfig> headConfig, List<RecyclerViewConfig> footConfig,
+      RecyclerView.Adapter mAdapter, Context mContext, RecyclerView recyclerView) {
     this.mAdapter = mAdapter;
     this.mAdapter = mAdapter;
     this.inflater = LayoutInflater.from(mContext);
     this.inflater = LayoutInflater.from(mContext);
     if (headConfig == null) {
     if (headConfig == null) {
@@ -57,7 +57,7 @@ final class CustomAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
   @NonNull
   @NonNull
   @Override
   @Override
   public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int index) {
   public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int index) {
-    if (index == ViewConfig.HEADVIEW_TYPE) {
+    if (index == RecyclerViewConfig.HEADVIEW_TYPE) {
       FrameLayout contentView =
       FrameLayout contentView =
           (FrameLayout) inflater.inflate(R.layout.item_head_foot_parent, viewGroup, false);
           (FrameLayout) inflater.inflate(R.layout.item_head_foot_parent, viewGroup, false);
       contentView.setTag(contentView.getClass() + "_head_" + headCount);
       contentView.setTag(contentView.getClass() + "_head_" + headCount);
@@ -74,7 +74,7 @@ final class CustomAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
         headCount = 0;
         headCount = 0;
       }
       }
       return customViewHolder;
       return customViewHolder;
-    } else if (index == ViewConfig.FOOTVIEW_TYPE) {
+    } else if (index == RecyclerViewConfig.FOOTVIEW_TYPE) {
       FrameLayout contentView =
       FrameLayout contentView =
           (FrameLayout) inflater.inflate(R.layout.item_head_foot_parent, viewGroup, false);
           (FrameLayout) inflater.inflate(R.layout.item_head_foot_parent, viewGroup, false);
       contentView.setTag(contentView.getClass() + "_foot_" + footerCount);
       contentView.setTag(contentView.getClass() + "_foot_" + footerCount);
@@ -96,6 +96,7 @@ final class CustomAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
     }
     }
   }
   }
 
 
+  @SuppressWarnings("unchecked")
   @Override
   @Override
   public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, final int position) {
   public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, final int position) {
     CustomViewHolder customViewHolder;
     CustomViewHolder customViewHolder;
@@ -153,9 +154,9 @@ final class CustomAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
     int headSize = getHeadSize();
     int headSize = getHeadSize();
     int adapterCount = getItemCount();//获取实际的个数
     int adapterCount = getItemCount();//获取实际的个数
     if (position < headSize) {
     if (position < headSize) {
-      return ViewConfig.HEADVIEW_TYPE;
+      return RecyclerViewConfig.HEADVIEW_TYPE;
     } else if (position >= headSize + mAdapter.getItemCount() && position < adapterCount) {
     } else if (position >= headSize + mAdapter.getItemCount() && position < adapterCount) {
-      return ViewConfig.FOOTVIEW_TYPE;
+      return RecyclerViewConfig.FOOTVIEW_TYPE;
     }
     }
     return mAdapter.getItemViewType(position - headSize);
     return mAdapter.getItemViewType(position - headSize);
   }
   }

+ 34 - 27
app/src/main/java/com/example/zhpan/banner/recyclerview/ui/CustomRecyclerView.java

@@ -12,18 +12,21 @@ import android.view.ViewGroup;
 
 
 import com.example.zhpan.banner.R;
 import com.example.zhpan.banner.R;
 import com.example.zhpan.banner.recyclerview.listener.ICustomClickListener;
 import com.example.zhpan.banner.recyclerview.listener.ICustomClickListener;
-import com.example.zhpan.banner.recyclerview.module.ViewConfig;
+import com.example.zhpan.banner.recyclerview.module.RecyclerViewConfig;
 
 
 import java.util.ArrayList;
 import java.util.ArrayList;
 
 
+import static com.example.zhpan.banner.recyclerview.module.RecyclerViewConfig.FOOTVIEW_TYPE;
+import static com.example.zhpan.banner.recyclerview.module.RecyclerViewConfig.HEADVIEW_TYPE;
+
 /**
 /**
  * 自定义RecyclerView,主要用于添加不同类型的Head和Foot
  * 自定义RecyclerView,主要用于添加不同类型的Head和Foot
  */
  */
 public class CustomRecyclerView extends RecyclerView {
 public class CustomRecyclerView extends RecyclerView {
   //保存头部的view
   //保存头部的view
-  private ArrayList<ViewConfig> mHeaderCouListInfo;
+  private ArrayList<RecyclerViewConfig> mHeaderCouListInfo;
   //保存尾部的view
   //保存尾部的view
-  private ArrayList<ViewConfig> mFooterCouListInfo;
+  private ArrayList<RecyclerViewConfig> mFooterCouListInfo;
   //记录head的个数
   //记录head的个数
   private int headerCount;
   private int headerCount;
   //记录foot的个数
   //记录foot的个数
@@ -31,7 +34,7 @@ public class CustomRecyclerView extends RecyclerView {
   //adapter,可能是CustomAdapter, 可能是自定义adapter
   //adapter,可能是CustomAdapter, 可能是自定义adapter
   private Adapter mAdapter;
   private Adapter mAdapter;
   private Context mContext;
   private Context mContext;
-  private ICustomClickListener customClickListener;
+  //private ICustomClickListener customClickListener;
 
 
   public CustomRecyclerView(@NonNull Context context) {
   public CustomRecyclerView(@NonNull Context context) {
     this(context, null);
     this(context, null);
@@ -52,24 +55,23 @@ public class CustomRecyclerView extends RecyclerView {
     mContext = context;
     mContext = context;
   }
   }
 
 
-  public ArrayList<ViewConfig> getmHeadCouListInfo() {
+  public ArrayList<RecyclerViewConfig> getHeadCouListInfo() {
     return mHeaderCouListInfo;
     return mHeaderCouListInfo;
   }
   }
 
 
-  public ArrayList<ViewConfig> getmFootCouListInfo() {
+  public ArrayList<RecyclerViewConfig> getFootCouListInfo() {
     return mFooterCouListInfo;
     return mFooterCouListInfo;
   }
   }
 
 
   /**
   /**
    * 添加HeadView的方法
    * 添加HeadView的方法
    */
    */
-
   public void addHeaderView(View view) {
   public void addHeaderView(View view) {
     addHeaderView(view, false);
     addHeaderView(view, false);
   }
   }
 
 
   public void addHeaderView(View view, boolean isCache) {
   public void addHeaderView(View view, boolean isCache) {
-    setHeadViewConfig(view, ViewConfig.HEADVIEW, headerCount, 100000, isCache);
+    setHeadViewConfig(view, RecyclerViewConfig.HEADVIEW, headerCount, HEADVIEW_TYPE, isCache);
     headerCount = mHeaderCouListInfo.size();
     headerCount = mHeaderCouListInfo.size();
 
 
     if (mAdapter != null) {
     if (mAdapter != null) {
@@ -80,7 +82,7 @@ public class CustomRecyclerView extends RecyclerView {
   }
   }
 
 
   public void addFootView(View view) {
   public void addFootView(View view) {
-    setFootViewConfig(view, ViewConfig.FOOTVIEW, footerCount, 100000);
+    setFootViewConfig(view, RecyclerViewConfig.FOOTVIEW, footerCount, FOOTVIEW_TYPE);
     footerCount = mFooterCouListInfo.size();
     footerCount = mFooterCouListInfo.size();
     if (mAdapter != null) {
     if (mAdapter != null) {
       if (!(mAdapter instanceof CustomAdapter)) {
       if (!(mAdapter instanceof CustomAdapter)) {
@@ -98,17 +100,16 @@ public class CustomRecyclerView extends RecyclerView {
 
 
   @Override
   @Override
   public void setAdapter(@Nullable Adapter adapter) {
   public void setAdapter(@Nullable Adapter adapter) {
-    if (mHeaderCouListInfo.size() > 0 || mFooterCouListInfo.size() > 0) {
+    //if (mHeaderCouListInfo.size() > 0 || mFooterCouListInfo.size() > 0) {
       mAdapter = new CustomAdapter(mHeaderCouListInfo, mFooterCouListInfo, adapter, mContext, this);
       mAdapter = new CustomAdapter(mHeaderCouListInfo, mFooterCouListInfo, adapter, mContext, this);
-    } else {
-      mAdapter = adapter;
-    }
-    /**
-     * 设置头尾的两个缓存为size  变相解决复用问题
-     */
-    getRecycledViewPool().setMaxRecycledViews(ViewConfig.FOOTVIEW_TYPE,
+    //} else {
+    //  mAdapter = adapter;
+    //}
+
+    // 设置头尾的两个缓存为size  变相解决复用问题
+    getRecycledViewPool().setMaxRecycledViews(FOOTVIEW_TYPE,
         mFooterCouListInfo.size() + 1);
         mFooterCouListInfo.size() + 1);
-    getRecycledViewPool().setMaxRecycledViews(ViewConfig.HEADVIEW_TYPE,
+    getRecycledViewPool().setMaxRecycledViews(HEADVIEW_TYPE,
         mHeaderCouListInfo.size() + 1);
         mHeaderCouListInfo.size() + 1);
 
 
     super.setAdapter(mAdapter);
     super.setAdapter(mAdapter);
@@ -119,7 +120,7 @@ public class CustomRecyclerView extends RecyclerView {
    */
    */
   private void setHeadViewConfig(View view, String type, int count, int headCount,
   private void setHeadViewConfig(View view, String type, int count, int headCount,
       boolean isCache) {
       boolean isCache) {
-    ViewConfig viewConfig = new ViewConfig();
+    RecyclerViewConfig viewConfig = new RecyclerViewConfig();
     viewConfig.setTag(view.getClass() + type + count);
     viewConfig.setTag(view.getClass() + type + count);
     viewConfig.setType(headCount);
     viewConfig.setType(headCount);
     viewConfig.setView(R.layout.item_head_foot_parent);
     viewConfig.setView(R.layout.item_head_foot_parent);
@@ -136,7 +137,7 @@ public class CustomRecyclerView extends RecyclerView {
    * 配置尾部view的信息
    * 配置尾部view的信息
    */
    */
   private void setFootViewConfig(View view, String type, int count, int headCount) {
   private void setFootViewConfig(View view, String type, int count, int headCount) {
-    ViewConfig viewConfig = new ViewConfig();
+    RecyclerViewConfig viewConfig = new RecyclerViewConfig();
     viewConfig.setTag(view.getClass() + type + count);
     viewConfig.setTag(view.getClass() + type + count);
     viewConfig.setType(headCount);
     viewConfig.setType(headCount);
     viewConfig.setView(R.layout.item_head_foot_parent);
     viewConfig.setView(R.layout.item_head_foot_parent);
@@ -153,20 +154,26 @@ public class CustomRecyclerView extends RecyclerView {
   }
   }
 
 
   public void setCustomClickListener(ICustomClickListener customClickListener) {
   public void setCustomClickListener(ICustomClickListener customClickListener) {
-    this.customClickListener = customClickListener;
+    //this.customClickListener = customClickListener;
     getHeadAndFootAdapter().setCustomClickListener(customClickListener);
     getHeadAndFootAdapter().setCustomClickListener(customClickListener);
   }
   }
 
 
   /**
   /**
    * 移除最后一个View, 就是加载更多的哪一个
    * 移除最后一个View, 就是加载更多的哪一个
    */
    */
-  public void removeLastFootView(int foorIndex) {
-    this.mFooterCouListInfo.remove(foorIndex);
-    footerCount = mFooterCouListInfo.size();
+  public void removeFooterView(int footerIndex) {
+    if (footerIndex < mFooterCouListInfo.size()) {
+      this.mFooterCouListInfo.remove(footerIndex);
+      footerCount = mFooterCouListInfo.size();
+      mAdapter.notifyDataSetChanged();
+    }
   }
   }
 
 
-  public void removeFirstHeadView() {
-    this.mHeaderCouListInfo.remove(0);
-    headerCount = mHeaderCouListInfo.size();
+  public void removeFirstHeaderView() {
+    if (mHeaderCouListInfo.size() > 0) {
+      this.mHeaderCouListInfo.remove(0);
+      headerCount = mHeaderCouListInfo.size();
+      mAdapter.notifyDataSetChanged();
+    }
   }
   }
 }
 }

+ 3 - 7
bannerview/src/main/java/com/zhpan/bannerview/BannerViewPager.java

@@ -2,10 +2,7 @@ package com.zhpan.bannerview;
 
 
 import android.content.Context;
 import android.content.Context;
 import android.graphics.Canvas;
 import android.graphics.Canvas;
-import android.graphics.Paint;
 import android.graphics.Path;
 import android.graphics.Path;
-import android.graphics.PorterDuff;
-import android.graphics.PorterDuffXfermode;
 import android.graphics.RectF;
 import android.graphics.RectF;
 import android.os.Build;
 import android.os.Build;
 import android.os.Bundle;
 import android.os.Bundle;
@@ -357,12 +354,11 @@ public class BannerViewPager<T> extends RelativeLayout implements LifecycleObser
 
 
   @Override
   @Override
   protected void dispatchDraw(Canvas canvas) {
   protected void dispatchDraw(Canvas canvas) {
-    if (mRadiusRectF != null && mRadiusPath != null) {
+    float[] roundRectRadiusArray = mBannerManager.getBannerOptions().getRoundRectRadiusArray();
+    if (mRadiusRectF != null && mRadiusPath != null && roundRectRadiusArray != null) {
       mRadiusRectF.right = this.getWidth();
       mRadiusRectF.right = this.getWidth();
       mRadiusRectF.bottom = this.getHeight();
       mRadiusRectF.bottom = this.getHeight();
-      mRadiusPath.addRoundRect(mRadiusRectF,
-          mBannerManager.getBannerOptions().getRoundRectRadiusArray(),
-          Path.Direction.CW);
+      mRadiusPath.addRoundRect(mRadiusRectF, roundRectRadiusArray, Path.Direction.CW);
       canvas.clipPath(mRadiusPath);
       canvas.clipPath(mRadiusPath);
     }
     }
     super.dispatchDraw(canvas);
     super.dispatchDraw(canvas);

+ 0 - 60
bannerview/src/main/java/com/zhpan/bannerview/provider/OvalViewOutlineProvider.java

@@ -1,60 +0,0 @@
-
-package com.zhpan.bannerview.provider;
-
-import android.annotation.TargetApi;
-import android.graphics.Outline;
-import android.graphics.Rect;
-import android.os.Build;
-import android.view.View;
-import android.view.ViewOutlineProvider;
-
-/**
- * <pre>
- *   Created by zhangpan on 2018/12/26.
- *   Description:圆形效果
- * </pre>
- */
-
-@TargetApi(Build.VERSION_CODES.LOLLIPOP)
-public class OvalViewOutlineProvider extends ViewOutlineProvider {
-
-
-    public OvalViewOutlineProvider() {}
-
-    @Override
-    public void getOutline(final View view, final Outline outline) {
-        Rect ovalRect = convertToCircleRect(new Rect(0, 0, view.getWidth(), view.getHeight()));
-        outline.setOval(ovalRect);
-    }
-
-    /**
-     * 以矩形的中心点为圆心,较短的边为直径画圆
-     *
-     * 注意, 由于整除省略了小数, (x/2)*2不一定等于x
-     * 
-     * Currently, only Outlines that can be represented as a rectangle, circle, or round rect
-     * support clipping.
-     * 
-     * @param rect
-     * @return
-     */
-    private Rect convertToCircleRect(Rect rect) {
-        int left, top, right, bottom;
-        if(rect.width() > rect.height()) {
-            int dH = rect.height() / 2;
-            left = rect.centerX() - dH;
-            top = 0;
-            right = rect.centerX() + dH;
-            bottom = dH * 2;
-        } else {
-            int dW = rect.width() / 2;
-            left = 0;
-            top = rect.centerY() - dW;
-            right = dW * 2;
-            bottom = rect.centerY() + dW;
-        }
-        rect.set(left, top, right, bottom);
-        return rect;
-    }
-
-}

+ 0 - 1
bannerview/src/main/java/com/zhpan/bannerview/provider/ScrollDurationManger.java

@@ -14,7 +14,6 @@ import androidx.viewpager2.widget.ViewPager2;
 
 
 import com.zhpan.bannerview.utils.BannerUtils;
 import com.zhpan.bannerview.utils.BannerUtils;
 
 
-import java.lang.reflect.Field;
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 import java.lang.reflect.Method;
 
 

+ 1 - 5
bannerview/src/main/java/com/zhpan/bannerview/provider/ViewStyleSetter.java

@@ -9,15 +9,11 @@ import android.view.View;
 /**
 /**
  * <pre>
  * <pre>
  *   Created by zhangpan on 2018/12/26.
  *   Created by zhangpan on 2018/12/26.
- *   Description:为View设置圆角/圆形效果,支持View及ViewGroup,适用Android 5.1及以上系统。
+ *   Description:为View设置圆角,支持View及ViewGroup,适用Android 5.1及以上系统。
  * </pre>
  * </pre>
  */
  */
-
 public class ViewStyleSetter {
 public class ViewStyleSetter {
 
 
-  private ViewStyleSetter() {
-  }
-
   /**
   /**
    * 为View设置圆角效果
    * 为View设置圆角效果
    *
    *