BannerOptions.java 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. package com.zhpan.bannerview.manager;
  2. import android.graphics.Path;
  3. import android.graphics.RectF;
  4. import android.view.View;
  5. import androidx.viewpager2.widget.ViewPager2;
  6. import com.zhpan.bannerview.constants.PageStyle;
  7. import com.zhpan.bannerview.utils.BannerUtils;
  8. import com.zhpan.indicator.enums.IndicatorOrientation;
  9. import com.zhpan.indicator.option.IndicatorOptions;
  10. import java.util.Arrays;
  11. import static com.zhpan.bannerview.transform.ScaleInTransformer.DEFAULT_MIN_SCALE;
  12. /**
  13. * <pre>
  14. * Created by zhpan on 2019/11/20.
  15. * Description:BannerViewPager的配置参数
  16. * </pre>
  17. */
  18. @SuppressWarnings("unused")
  19. public class BannerOptions {
  20. public BannerOptions() {
  21. mIndicatorOptions = new IndicatorOptions();
  22. pageMargin = BannerUtils.dp2px(20);
  23. rightRevealWidth = DEFAULT_REVEAL_WIDTH;
  24. leftRevealWidth = DEFAULT_REVEAL_WIDTH;
  25. roundRadius = new float[8];
  26. }
  27. public static final int DEFAULT_REVEAL_WIDTH = -1000;
  28. private int offScreenPageLimit = ViewPager2.OFFSCREEN_PAGE_LIMIT_DEFAULT;
  29. private int interval;
  30. private boolean isCanLoop;
  31. private boolean isAutoPlay = false;
  32. private int indicatorGravity;
  33. private int pageMargin;
  34. private int rightRevealWidth;
  35. private int leftRevealWidth;
  36. private int pageStyle = PageStyle.NORMAL;
  37. private float pageScale = DEFAULT_MIN_SCALE;
  38. private IndicatorMargin mIndicatorMargin;
  39. private int mIndicatorVisibility = View.VISIBLE;
  40. private int scrollDuration;
  41. private float[] roundRadius;
  42. private boolean userInputEnabled = true;
  43. private int orientation = ViewPager2.ORIENTATION_HORIZONTAL;
  44. private boolean rtl;
  45. private boolean disallowParentInterceptDownEvent;
  46. private final IndicatorOptions mIndicatorOptions;
  47. public int getInterval() {
  48. return interval;
  49. }
  50. public void setInterval(int interval) {
  51. this.interval = interval;
  52. }
  53. public boolean isCanLoop() {
  54. return isCanLoop;
  55. }
  56. public void setCanLoop(boolean canLoop) {
  57. isCanLoop = canLoop;
  58. }
  59. public boolean isAutoPlay() {
  60. return isAutoPlay;
  61. }
  62. public void setAutoPlay(boolean autoPlay) {
  63. isAutoPlay = autoPlay;
  64. }
  65. public int getIndicatorGravity() {
  66. return indicatorGravity;
  67. }
  68. public void setIndicatorGravity(int indicatorGravity) {
  69. this.indicatorGravity = indicatorGravity;
  70. }
  71. public int getIndicatorNormalColor() {
  72. return mIndicatorOptions.getNormalSliderColor();
  73. }
  74. public int getIndicatorCheckedColor() {
  75. return mIndicatorOptions.getCheckedSliderColor();
  76. }
  77. public int getNormalIndicatorWidth() {
  78. return (int) mIndicatorOptions.getNormalSliderWidth();
  79. }
  80. public void setIndicatorSliderColor(int normalColor, int checkedColor) {
  81. mIndicatorOptions.setSliderColor(normalColor, checkedColor);
  82. }
  83. public void setIndicatorSliderWidth(int normalWidth, int checkedWidth) {
  84. mIndicatorOptions.setSliderWidth(normalWidth, checkedWidth);
  85. }
  86. public int getCheckedIndicatorWidth() {
  87. return (int) mIndicatorOptions.getCheckedSliderWidth();
  88. }
  89. public IndicatorOptions getIndicatorOptions() {
  90. return mIndicatorOptions;
  91. }
  92. public int getPageMargin() {
  93. return pageMargin;
  94. }
  95. public void setPageMargin(int pageMargin) {
  96. this.pageMargin = pageMargin;
  97. }
  98. public int getRightRevealWidth() {
  99. return rightRevealWidth;
  100. }
  101. public void setRightRevealWidth(int rightRevealWidth) {
  102. this.rightRevealWidth = rightRevealWidth;
  103. }
  104. public int getLeftRevealWidth() {
  105. return leftRevealWidth;
  106. }
  107. public void setLeftRevealWidth(int leftRevealWidth) {
  108. this.leftRevealWidth = leftRevealWidth;
  109. }
  110. public int getIndicatorStyle() {
  111. return mIndicatorOptions.getIndicatorStyle();
  112. }
  113. public void setIndicatorStyle(int indicatorStyle) {
  114. mIndicatorOptions.setIndicatorStyle(indicatorStyle);
  115. }
  116. public int getIndicatorSlideMode() {
  117. return mIndicatorOptions.getSlideMode();
  118. }
  119. public void setIndicatorSlideMode(int indicatorSlideMode) {
  120. mIndicatorOptions.setSlideMode(indicatorSlideMode);
  121. }
  122. public float getIndicatorGap() {
  123. return mIndicatorOptions.getSliderGap();
  124. }
  125. public void setIndicatorGap(float indicatorGap) {
  126. mIndicatorOptions.setSliderGap(indicatorGap);
  127. }
  128. public float getIndicatorHeight() {
  129. return mIndicatorOptions.getSliderHeight();
  130. }
  131. public void setIndicatorHeight(int indicatorHeight) {
  132. mIndicatorOptions.setSliderHeight(indicatorHeight);
  133. }
  134. public int getPageStyle() {
  135. return pageStyle;
  136. }
  137. public void setPageStyle(int pageStyle) {
  138. this.pageStyle = pageStyle;
  139. }
  140. public float getPageScale() {
  141. return pageScale;
  142. }
  143. public void setPageScale(float pageScale) {
  144. this.pageScale = pageScale;
  145. }
  146. public IndicatorMargin getIndicatorMargin() {
  147. return mIndicatorMargin;
  148. }
  149. public void setIndicatorMargin(int left, int top, int right, int bottom) {
  150. mIndicatorMargin = new IndicatorMargin(left, top, right, bottom);
  151. }
  152. public float[] getRoundRectRadius() {
  153. return roundRadius;
  154. }
  155. public void setRoundRectRadius(int radius) {
  156. setRoundRectRadius(radius, radius, radius, radius);
  157. }
  158. public void setRoundRectRadius(int topLeftRadius, int topRightRadius, int bottomLeftRadius,
  159. int bottomRightRadius) {
  160. roundRadius[0] = topLeftRadius;
  161. roundRadius[1] = topLeftRadius;
  162. roundRadius[2] = topRightRadius;
  163. roundRadius[3] = topRightRadius;
  164. roundRadius[4] = bottomRightRadius;
  165. roundRadius[5] = bottomRightRadius;
  166. roundRadius[6] = bottomLeftRadius;
  167. roundRadius[7] = bottomLeftRadius;
  168. }
  169. public int getScrollDuration() {
  170. return scrollDuration;
  171. }
  172. public void setScrollDuration(int scrollDuration) {
  173. this.scrollDuration = scrollDuration;
  174. }
  175. public int getIndicatorVisibility() {
  176. return mIndicatorVisibility;
  177. }
  178. public void setIndicatorVisibility(int indicatorVisibility) {
  179. mIndicatorVisibility = indicatorVisibility;
  180. }
  181. public int getOrientation() {
  182. return orientation;
  183. }
  184. public void setOrientation(int orientation) {
  185. this.orientation = orientation;
  186. mIndicatorOptions.setOrientation(orientation);
  187. }
  188. public boolean isUserInputEnabled() {
  189. return userInputEnabled;
  190. }
  191. public void setUserInputEnabled(boolean userInputEnabled) {
  192. this.userInputEnabled = userInputEnabled;
  193. }
  194. public void resetIndicatorOptions() {
  195. mIndicatorOptions.setCurrentPosition(0);
  196. mIndicatorOptions.setSlideProgress(0);
  197. }
  198. public boolean isDisallowParentInterceptDownEvent() {
  199. return disallowParentInterceptDownEvent;
  200. }
  201. public void setDisallowParentInterceptDownEvent(boolean disallowParentInterceptDownEvent) {
  202. this.disallowParentInterceptDownEvent = disallowParentInterceptDownEvent;
  203. }
  204. public int getOffScreenPageLimit() {
  205. return offScreenPageLimit;
  206. }
  207. public void setOffScreenPageLimit(int offScreenPageLimit) {
  208. this.offScreenPageLimit = offScreenPageLimit;
  209. }
  210. public boolean isRtl() {
  211. return rtl;
  212. }
  213. public void setRtl(boolean rtl) {
  214. this.rtl = rtl;
  215. mIndicatorOptions.setOrientation(rtl ? IndicatorOrientation.INDICATOR_RTL : IndicatorOrientation.INDICATOR_HORIZONTAL);
  216. }
  217. public static class IndicatorMargin {
  218. private final int left, right, top, bottom;
  219. public IndicatorMargin(int left, int top, int right, int bottom) {
  220. this.left = left;
  221. this.right = right;
  222. this.top = top;
  223. this.bottom = bottom;
  224. }
  225. public int getLeft() {
  226. return left;
  227. }
  228. public int getRight() {
  229. return right;
  230. }
  231. public int getTop() {
  232. return top;
  233. }
  234. public int getBottom() {
  235. return bottom;
  236. }
  237. }
  238. }