Skip to content

Commit

Permalink
IndicatorView优化,更加灵活的使用
Browse files Browse the repository at this point in the history
  • Loading branch information
zguop committed Feb 2, 2020
1 parent f0733c0 commit d07da3a
Show file tree
Hide file tree
Showing 7 changed files with 289 additions and 110 deletions.
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ dependencies {
implementation 'com.zhy:magic-viewpager:1.0.1'
implementation 'com.github.lihangleo2:ShadowLayout:2.1.5'
implementation 'com.blankj:utilcode:1.25.9'
api 'com.romandanylyk:pageindicatorview:1.0.2'


implementation project(":banner")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,22 @@
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.blankj.utilcode.util.SizeUtils;
import com.rd.PageIndicatorView;
import com.rd.animation.type.AnimationType;
import com.to.aboomy.banner.Banner;
import com.to.aboomy.banner.Indicator;
import com.to.aboomy.banner.IndicatorView;
import com.to.aboomy.bannersample.R;
import com.to.aboomy.bannersample.creator.ImageTest1ChildHolderCreator;
import com.to.aboomy.bannersample.indicator.LineIndicatorView;
import com.to.aboomy.bannersample.indicator.CircleIndicatorView;
import com.to.aboomy.bannersample.indicator.DashPointView;
import com.to.aboomy.bannersample.indicator.DashReverseView;
import com.to.aboomy.bannersample.indicator.LineIndicatorView;
import com.to.aboomy.bannersample.indicator.LinePagerTitleIndicatorView;
import com.to.aboomy.bannersample.util.ArrayStringItemSelectDialog;
import com.to.aboomy.bannersample.util.Utils;
Expand All @@ -32,11 +37,14 @@ public class Indicator2Activity extends AppCompatActivity {
"CircleIndicatorView",
"CircleIndicatorView-FollowTouch",
"LinePagerTitleIndicatorView",
"LineIndicatorView"
"LineIndicatorView",
"PageIndicatorView-FILL",
"PageIndicatorView-THIN_WORM",
"PageIndicatorView-DROP",
"PageIndicatorView-SWAP",
};
private int choose;


@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand Down Expand Up @@ -67,31 +75,87 @@ public void onItemClick(int position, String value) {
}).show();
}
});

}


public Indicator getIndicator(int position) {
switch (position) {
case 0:
return new DashPointView(this);
case 1:
return new DashReverseView(this);
case 2:
CircleIndicatorView c = new CircleIndicatorView(this);
c.setCircleColor(Color.WHITE);
c.setFollowTouch(false);
return c;
return getCircleIndicatorView(false);
case 3:
CircleIndicatorView c1 = new CircleIndicatorView(this);
c1.setCircleColor(Color.WHITE);
return c1;
return getCircleIndicatorView(true);
case 4:
return new LinePagerTitleIndicatorView(this);
case 5:
return new LineIndicatorView(this);
case 6:
return getPageIndicatorView(AnimationType.FILL);
case 7:
return getPageIndicatorView(AnimationType.THIN_WORM);
case 8:
return getPageIndicatorView(AnimationType.DROP);
case 9:
return getPageIndicatorView(AnimationType.SWAP);
default:
return new IndicatorView(this);
}
}

private CircleIndicatorView getCircleIndicatorView(boolean followTouch){
CircleIndicatorView circleIndicatorView = new CircleIndicatorView(this);
circleIndicatorView.setCircleColor(Color.RED);
circleIndicatorView.setFollowTouch(followTouch);
return circleIndicatorView;
}

/**
* 集成 https://github.com/romandanylyk/PageIndicatorView
*/
private Indicator getPageIndicatorView(AnimationType type) {
final PageIndicatorView pageIndicatorView = new PageIndicatorView(this);
pageIndicatorView.setAnimationType(type);
pageIndicatorView.setInteractiveAnimation(true);
pageIndicatorView.setSelectedColor(Color.RED);
pageIndicatorView.setUnselectedColor(Color.GRAY);
pageIndicatorView.setPadding(10);
pageIndicatorView.setRadius(8);
return new Indicator() {
@Override
public void onPageScrolled(int i, float v, int i1) {

}

@Override
public void onPageSelected(int position) {
pageIndicatorView.setSelection(position);
}

@Override
public void onPageScrollStateChanged(int i) {

}

@Override
public void initIndicatorCount(int pagerCount) {
pageIndicatorView.setCount(pagerCount);
}

@Override
public View getView() {
return pageIndicatorView;
}

@Override
public RelativeLayout.LayoutParams getParams() {
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
params.addRule(RelativeLayout.CENTER_HORIZONTAL);
params.bottomMargin = SizeUtils.dp2px(20);
return params;
}
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ protected void onCreate(Bundle savedInstanceState) {
list.add(Utils.getRandom());
banner = findViewById(R.id.banner);
final IndicatorView indicatorView = new IndicatorView(this)
// .setIndicatorRatio(1.5f)
// .setIndicatorSelectedRadius(4)
.setIndicatorRadius(5.5f)
// .setIndicatorStyle(IndicatorView.IndicatorStyle.INDICATOR_BEZIER)
.setIndicatorColor(Color.GRAY)
.setIndicatorSelectorColor(Color.WHITE);
banner.setIndicator(indicatorView)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import android.content.Context;
import android.support.annotation.NonNull;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;

Expand All @@ -18,7 +17,6 @@ public class ImageHolderCreator implements HolderCreator {
@NonNull
@Override
public View createView(final Context context, final int index, Object o) {
Log.e("aa", "index " + index);
ImageView iv = new ImageView(context);
iv.setScaleType(ImageView.ScaleType.FIT_XY);
Glide.with(iv).load(o).into(iv);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
public class DashPointView extends LinearLayout implements Indicator {

private int pointRadius = dip2px(3);
private int pointSelectColor = Color.WHITE;
private int pointSelectColor = Color.RED;
private int pointColor = Color.GRAY;
private int maxPointWidth = pointRadius * 6;
private int pointWidth = pointRadius * 2;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
public class DashReverseView extends LinearLayout implements Indicator {

private int pointRadius = dip2px(2);
private int pointSelectColor = Color.WHITE;
private int pointSelectColor = Color.RED;
private int pointColor = Color.GRAY;
private int pointWidth = pointRadius * 6;
private int pointHeight = pointRadius * 2;
Expand Down
Loading

0 comments on commit d07da3a

Please sign in to comment.