Skip to content

Commit

Permalink
Remove OvalViewOutlineProvider.java
Browse files Browse the repository at this point in the history
  • Loading branch information
zhpanvip committed Jul 15, 2021
1 parent c47d7e4 commit 0e3220d
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 158 deletions.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import android.view.View;

public class ViewConfig {
public class RecyclerViewConfig {
public static final String HEADVIEW = "_head_";
public static final String FOOTVIEW = "_foot_";
public static final int HEADVIEW_TYPE = 100000;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,22 @@

import com.example.zhpan.banner.R;
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.List;

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 RecyclerView.Adapter mAdapter;
private int headCount = 0;
private int footerCount = 0;
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.inflater = LayoutInflater.from(mContext);
if (headConfig == null) {
Expand All @@ -57,7 +57,7 @@ public void setCustomClickListener(ICustomClickListener customClickListener) {
@NonNull
@Override
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int index) {
if (index == ViewConfig.HEADVIEW_TYPE) {
if (index == RecyclerViewConfig.HEADVIEW_TYPE) {
FrameLayout contentView =
(FrameLayout) inflater.inflate(R.layout.item_head_foot_parent, viewGroup, false);
contentView.setTag(contentView.getClass() + "_head_" + headCount);
Expand All @@ -74,7 +74,7 @@ public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup,
headCount = 0;
}
return customViewHolder;
} else if (index == ViewConfig.FOOTVIEW_TYPE) {
} else if (index == RecyclerViewConfig.FOOTVIEW_TYPE) {
FrameLayout contentView =
(FrameLayout) inflater.inflate(R.layout.item_head_foot_parent, viewGroup, false);
contentView.setTag(contentView.getClass() + "_foot_" + footerCount);
Expand All @@ -96,6 +96,7 @@ public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup,
}
}

@SuppressWarnings("unchecked")
@Override
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, final int position) {
CustomViewHolder customViewHolder;
Expand Down Expand Up @@ -153,9 +154,9 @@ public int getItemViewType(int position) {
int headSize = getHeadSize();
int adapterCount = getItemCount();//获取实际的个数
if (position < headSize) {
return ViewConfig.HEADVIEW_TYPE;
return RecyclerViewConfig.HEADVIEW_TYPE;
} else if (position >= headSize + mAdapter.getItemCount() && position < adapterCount) {
return ViewConfig.FOOTVIEW_TYPE;
return RecyclerViewConfig.FOOTVIEW_TYPE;
}
return mAdapter.getItemViewType(position - headSize);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,29 @@

import com.example.zhpan.banner.R;
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 static com.example.zhpan.banner.recyclerview.module.RecyclerViewConfig.FOOTVIEW_TYPE;
import static com.example.zhpan.banner.recyclerview.module.RecyclerViewConfig.HEADVIEW_TYPE;

/**
* 自定义RecyclerView,主要用于添加不同类型的Head和Foot
*/
public class CustomRecyclerView extends RecyclerView {
//保存头部的view
private ArrayList<ViewConfig> mHeaderCouListInfo;
private ArrayList<RecyclerViewConfig> mHeaderCouListInfo;
//保存尾部的view
private ArrayList<ViewConfig> mFooterCouListInfo;
private ArrayList<RecyclerViewConfig> mFooterCouListInfo;
//记录head的个数
private int headerCount;
//记录foot的个数
private int footerCount;
//adapter,可能是CustomAdapter, 可能是自定义adapter
private Adapter mAdapter;
private Context mContext;
private ICustomClickListener customClickListener;
//private ICustomClickListener customClickListener;

public CustomRecyclerView(@NonNull Context context) {
this(context, null);
Expand All @@ -52,24 +55,23 @@ private void init(Context context) {
mContext = context;
}

public ArrayList<ViewConfig> getmHeadCouListInfo() {
public ArrayList<RecyclerViewConfig> getHeadCouListInfo() {
return mHeaderCouListInfo;
}

public ArrayList<ViewConfig> getmFootCouListInfo() {
public ArrayList<RecyclerViewConfig> getFootCouListInfo() {
return mFooterCouListInfo;
}

/**
* 添加HeadView的方法
*/

public void addHeaderView(View view) {
addHeaderView(view, false);
}

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();

if (mAdapter != null) {
Expand All @@ -80,7 +82,7 @@ public void addHeaderView(View view, boolean isCache) {
}

public void addFootView(View view) {
setFootViewConfig(view, ViewConfig.FOOTVIEW, footerCount, 100000);
setFootViewConfig(view, RecyclerViewConfig.FOOTVIEW, footerCount, FOOTVIEW_TYPE);
footerCount = mFooterCouListInfo.size();
if (mAdapter != null) {
if (!(mAdapter instanceof CustomAdapter)) {
Expand All @@ -98,17 +100,16 @@ private void wrapHeadAdapter() {

@Override
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);
} else {
mAdapter = adapter;
}
/**
* 设置头尾的两个缓存为size 变相解决复用问题
*/
getRecycledViewPool().setMaxRecycledViews(ViewConfig.FOOTVIEW_TYPE,
//} else {
// mAdapter = adapter;
//}

// 设置头尾的两个缓存为size 变相解决复用问题
getRecycledViewPool().setMaxRecycledViews(FOOTVIEW_TYPE,
mFooterCouListInfo.size() + 1);
getRecycledViewPool().setMaxRecycledViews(ViewConfig.HEADVIEW_TYPE,
getRecycledViewPool().setMaxRecycledViews(HEADVIEW_TYPE,
mHeaderCouListInfo.size() + 1);

super.setAdapter(mAdapter);
Expand All @@ -119,7 +120,7 @@ public void setAdapter(@Nullable Adapter adapter) {
*/
private void setHeadViewConfig(View view, String type, int count, int headCount,
boolean isCache) {
ViewConfig viewConfig = new ViewConfig();
RecyclerViewConfig viewConfig = new RecyclerViewConfig();
viewConfig.setTag(view.getClass() + type + count);
viewConfig.setType(headCount);
viewConfig.setView(R.layout.item_head_foot_parent);
Expand All @@ -136,7 +137,7 @@ private void setHeadViewConfig(View view, String type, int count, int headCount,
* 配置尾部view的信息
*/
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.setType(headCount);
viewConfig.setView(R.layout.item_head_foot_parent);
Expand All @@ -153,20 +154,26 @@ public CustomAdapter getHeadAndFootAdapter() {
}

public void setCustomClickListener(ICustomClickListener customClickListener) {
this.customClickListener = customClickListener;
//this.customClickListener = customClickListener;
getHeadAndFootAdapter().setCustomClickListener(customClickListener);
}

/**
* 移除最后一个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();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffXfermode;
import android.graphics.RectF;
import android.os.Build;
import android.os.Bundle;
Expand Down Expand Up @@ -357,12 +354,11 @@ private void initIndicatorSliderMargin() {

@Override
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.bottom = this.getHeight();
mRadiusPath.addRoundRect(mRadiusRectF,
mBannerManager.getBannerOptions().getRoundRectRadiusArray(),
Path.Direction.CW);
mRadiusPath.addRoundRect(mRadiusRectF, roundRectRadiusArray, Path.Direction.CW);
canvas.clipPath(mRadiusPath);
}
super.dispatchDraw(canvas);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

import com.zhpan.bannerview.utils.BannerUtils;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,11 @@
/**
* <pre>
* Created by zhangpan on 2018/12/26.
* Description:为View设置圆角/圆形效果,支持View及ViewGroup,适用Android 5.1及以上系统。
* Description:为View设置圆角,支持View及ViewGroup,适用Android 5.1及以上系统。
* </pre>
*/

public class ViewStyleSetter {

private ViewStyleSetter() {
}

/**
* 为View设置圆角效果
*
Expand Down

0 comments on commit 0e3220d

Please sign in to comment.