From e60121739b96c5b65e5b6bc7e9838d4301f71f81 Mon Sep 17 00:00:00 2001 From: ThiagoFontes Date: Mon, 28 Oct 2019 18:12:57 -0300 Subject: [PATCH 1/3] Adding custom last indicator --- .../circleindicator/BaseCircleIndicator.java | 19 +++++++++++++++++- .../java/me/relex/circleindicator/Config.java | 7 +++++++ circleindicator/src/main/res/drawable/add.png | Bin 0 -> 4072 bytes .../src/main/res/drawable/add_unselected.png | Bin 0 -> 4257 bytes 4 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 circleindicator/src/main/res/drawable/add.png create mode 100644 circleindicator/src/main/res/drawable/add_unselected.png diff --git a/circleindicator/src/main/java/me/relex/circleindicator/BaseCircleIndicator.java b/circleindicator/src/main/java/me/relex/circleindicator/BaseCircleIndicator.java index 510b7bd..ba316f6 100644 --- a/circleindicator/src/main/java/me/relex/circleindicator/BaseCircleIndicator.java +++ b/circleindicator/src/main/java/me/relex/circleindicator/BaseCircleIndicator.java @@ -25,6 +25,9 @@ class BaseCircleIndicator extends LinearLayout { protected int mIndicatorBackgroundResId; protected int mIndicatorUnselectedBackgroundResId; + protected int mLastIndicatorBackgroundResId; + protected int mLastIndicatorUnselectedBackgroundResId; + protected Animator mAnimatorOut; protected Animator mAnimatorIn; protected Animator mImmediateAnimatorOut; @@ -51,7 +54,7 @@ public BaseCircleIndicator(Context context, AttributeSet attrs, int defStyleAttr @TargetApi(Build.VERSION_CODES.LOLLIPOP) public BaseCircleIndicator(Context context, AttributeSet attrs, int defStyleAttr, - int defStyleRes) { + int defStyleRes) { super(context, attrs, defStyleAttr, defStyleRes); init(context, attrs); } @@ -116,6 +119,8 @@ public void initialize(Config config) { (config.unselectedBackgroundId == 0) ? config.backgroundResId : config.unselectedBackgroundId; + mLastIndicatorBackgroundResId = (config.backgroundLastResID == 0) ? R.drawable.add : config.backgroundLastResID; + mLastIndicatorUnselectedBackgroundResId = (config.unselectedBackgroundLastId == 0) ? R.drawable.add_unselected : config.unselectedBackgroundLastId; setOrientation(config.orientation == VERTICAL ? VERTICAL : HORIZONTAL); setGravity(config.gravity >= 0 ? config.gravity : Gravity.CENTER); } @@ -182,8 +187,14 @@ public void createIndicators(int count, int currentPosition) { mImmediateAnimatorOut.setTarget(indicator); mImmediateAnimatorOut.start(); mImmediateAnimatorOut.end(); + if(i == count - 1 ) { + indicator.setBackgroundResource(mLastIndicatorBackgroundResId); + } } else { indicator.setBackgroundResource(mIndicatorUnselectedBackgroundResId); + if(i == count - 1 ) { + indicator.setBackgroundResource(mLastIndicatorUnselectedBackgroundResId); + } mImmediateAnimatorIn.setTarget(indicator); mImmediateAnimatorIn.start(); mImmediateAnimatorIn.end(); @@ -231,6 +242,9 @@ public void animatePageSelected(int position) { View currentIndicator; if (mLastPosition >= 0 && (currentIndicator = getChildAt(mLastPosition)) != null) { currentIndicator.setBackgroundResource(mIndicatorUnselectedBackgroundResId); + if(currentIndicator == getChildAt(getChildCount()-1)) { + currentIndicator.setBackgroundResource(mLastIndicatorUnselectedBackgroundResId); + } mAnimatorIn.setTarget(currentIndicator); mAnimatorIn.start(); } @@ -238,6 +252,9 @@ public void animatePageSelected(int position) { View selectedIndicator = getChildAt(position); if (selectedIndicator != null) { selectedIndicator.setBackgroundResource(mIndicatorBackgroundResId); + if(selectedIndicator == getChildAt(getChildCount()-1)) { + selectedIndicator.setBackgroundResource(mLastIndicatorBackgroundResId); + } mAnimatorOut.setTarget(selectedIndicator); mAnimatorOut.start(); } diff --git a/circleindicator/src/main/java/me/relex/circleindicator/Config.java b/circleindicator/src/main/java/me/relex/circleindicator/Config.java index cc5babf..d91a34f 100644 --- a/circleindicator/src/main/java/me/relex/circleindicator/Config.java +++ b/circleindicator/src/main/java/me/relex/circleindicator/Config.java @@ -13,7 +13,9 @@ public class Config { @AnimatorRes int animatorResId = R.animator.scale_with_alpha; @AnimatorRes int animatorReverseResId = 0; @DrawableRes int backgroundResId = R.drawable.white_radius; + @DrawableRes int backgroundLastResID = R.drawable.add; @DrawableRes int unselectedBackgroundId; + @DrawableRes int unselectedBackgroundLastId = R.drawable.add_unselected; int orientation = LinearLayout.HORIZONTAL; int gravity = Gravity.CENTER; @@ -58,6 +60,11 @@ public Builder drawable(@DrawableRes int backgroundResId) { return this; } + public Builder drawableLast(@DrawableRes int backgroundLastResId) { + mConfig.backgroundLastResID = backgroundLastResId; + return this; + } + public Builder drawableUnselected(@DrawableRes int unselectedBackgroundId) { mConfig.unselectedBackgroundId = unselectedBackgroundId; return this; diff --git a/circleindicator/src/main/res/drawable/add.png b/circleindicator/src/main/res/drawable/add.png new file mode 100644 index 0000000000000000000000000000000000000000..cac2d68c90dd7b4ecb9f43d49e7937af453223fd GIT binary patch literal 4072 zcmVP)C^HaDAP!SEEfA-+lfa~8TKthPC6r7ENgD@f2jV0{Q#z#MX&nOCmR2U% zhQSOr`dSHFARJqkC9Smg?H}v4Wm&TJ4icm9 z)7;RBQljZM)QZwAz!O9iEnSNUSyzKJg1QR00+{V`$;UzV1N%X>VI_C6wEn<_V7A~I zYj^i22=f_iZbGpF_ygUNPSFpt6Q#DJc$sC9gSrK|L2!&EqG;<~fwFH!xEWZeTT+G` z1bGPwZ6jK}D=4*D;Tx;1`$|N<2tl)aT`-CMfFXW*~WJ_TgYwzJI5~FK?uK*Rg<#@z#gsqIRg%yz=-C{DO zFpSmGF&``RP2f(TM7JDGjG%ai(XmIldVYs)G1K91W3~1~!2TMF`?zooHIY%^dF0uOsR~V1{lvK4loxV-$xsvUu*GZZQ+_m$5_?vF=qU^(Zh; zx10i@7t{tCYo7DdP=$Yt)z-BTTRn~9dfieA65&;>(3fefKA>9)_`z5^BurV)I*^Ak z&0f9?p?HLW+Q;}~HKtRDUSsWQZy;RsEXXxlbp(%AEbh?xxX98~FtM(C2#5C@Q@KJD zHhYN0zo1Ki_chjz_8F9gp9JppyzC2;XBp)_Rz!xpEYw?Lwf00%_RoPPPs=s@4m*CXn?=pNQEjK>1`XJXx(+$_YM|8Nn- zp7<7ouelQ6;1u7Xv39*1kAmDWR_d=|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v?c4!GN;H5{XJdZ4!WV5EhNh3iXQ~;pMVfl!`_xmsLHSRr@DSri^ghpd&=}AUM%BX z2>h^CZCX}%MIAm+D^o#@$35rv^yJF3)0YE})Uw@e&LcC&k6yC0`M72nTT?rf8^2yu z|H>{F42tUXjH^oh%32p=-3BYNnIF)w~yZ|`nn)pL#S0yv-=Pv^$( zMEE11^6fE}wU|+n&t;N{Ki}*cb-yugtYt<{HH%v=` z5E%Vz>w_ob7`CpWY2FK9w#tYwPDV%uEVyGs|B;n>^b+RUK( z#ip1%uwJ@GlZ4V(%N#5gcg0-&6sorZ+hZf&#w-B)9Q8*7=NLZMGQ z?gnlEnoR34#2m2SbGUCHnGAjApSm#CG6##rU9pn8S44haq58Z-^}%t3Z^hj51C`{Z z3JY~*tYr#?LhHOIS1Ee4z@?`31cAU06!~V8qfdu%47Cw;X{?hOE)>pFS8hb~Y9MV| zPgN*c9G*h>RwkKz-L#x)sC#2AqpC8To48oTyISB%V2^1{74n9{GpKyKmJf-8CNjoa z&B(|^zs9{^RZp)#xRmfL*O^3k4wYvmF5gQh5?RxNf*`WSTFp>C|6YMhRJll0&PO;O z*b#8E#}Iz1s;`OgvcmIWnHdk7ZDXvpIGE3;VxH5FkVd@>LLWFCpdCPmK!-w1ph2M> zK;VQzNx)T@0;WKwz?(uDL7c35nsps-$d4Vx^~(PNu-9d{ARm$500000NkvXXu0mjf D@z7-k literal 0 HcmV?d00001 From b94a1978044c510812c410dcf86d08c6ffb8e062 Mon Sep 17 00:00:00 2001 From: ThiagoFontes Date: Tue, 29 Oct 2019 09:38:26 -0300 Subject: [PATCH 2/3] Parameterizing custom last item and adding an example --- .../circleindicator/BaseCircleIndicator.java | 6 ++-- .../java/me/relex/circleindicator/Config.java | 4 +-- .../src/main/res/drawable/add_unselected.png | Bin 4257 -> 0 bytes circleindicator/src/main/res/values/attrs.xml | 2 ++ .../sample/SampleActivity.java | 2 ++ .../fragment/CustomLastItemFragment.java | 33 ++++++++++++++++++ .../src/main/res/drawable/add.png | Bin .../src/main/res/drawable/add_unselected.png | Bin 0 -> 4297 bytes .../res/layout/fragment_custom_last_item.xml | 23 ++++++++++++ 9 files changed, 66 insertions(+), 4 deletions(-) delete mode 100644 circleindicator/src/main/res/drawable/add_unselected.png create mode 100644 sample/src/main/java/me/relex/circleindicator/sample/fragment/CustomLastItemFragment.java rename {circleindicator => sample}/src/main/res/drawable/add.png (100%) create mode 100644 sample/src/main/res/drawable/add_unselected.png create mode 100644 sample/src/main/res/layout/fragment_custom_last_item.xml diff --git a/circleindicator/src/main/java/me/relex/circleindicator/BaseCircleIndicator.java b/circleindicator/src/main/java/me/relex/circleindicator/BaseCircleIndicator.java index ba316f6..7afcea2 100644 --- a/circleindicator/src/main/java/me/relex/circleindicator/BaseCircleIndicator.java +++ b/circleindicator/src/main/java/me/relex/circleindicator/BaseCircleIndicator.java @@ -93,6 +93,8 @@ private Config handleTypedArray(Context context, AttributeSet attrs) { config.backgroundResId); config.orientation = typedArray.getInt(R.styleable.BaseCircleIndicator_ci_orientation, -1); config.gravity = typedArray.getInt(R.styleable.BaseCircleIndicator_ci_gravity, -1); + config.backgroundLastResID = typedArray.getResourceId(R.styleable.BaseCircleIndicator_ci_drawable_last, 0); + config.unselectedBackgroundLastId = typedArray.getResourceId(R.styleable.BaseCircleIndicator_ci_drawable_last_unselected, 0); typedArray.recycle(); return config; @@ -119,8 +121,8 @@ public void initialize(Config config) { (config.unselectedBackgroundId == 0) ? config.backgroundResId : config.unselectedBackgroundId; - mLastIndicatorBackgroundResId = (config.backgroundLastResID == 0) ? R.drawable.add : config.backgroundLastResID; - mLastIndicatorUnselectedBackgroundResId = (config.unselectedBackgroundLastId == 0) ? R.drawable.add_unselected : config.unselectedBackgroundLastId; + mLastIndicatorBackgroundResId = (config.backgroundLastResID == 0) ? config.backgroundResId : config.backgroundLastResID; + mLastIndicatorUnselectedBackgroundResId = (config.unselectedBackgroundLastId == 0) ? config.backgroundResId: config.unselectedBackgroundLastId; setOrientation(config.orientation == VERTICAL ? VERTICAL : HORIZONTAL); setGravity(config.gravity >= 0 ? config.gravity : Gravity.CENTER); } diff --git a/circleindicator/src/main/java/me/relex/circleindicator/Config.java b/circleindicator/src/main/java/me/relex/circleindicator/Config.java index d91a34f..ed7e4e2 100644 --- a/circleindicator/src/main/java/me/relex/circleindicator/Config.java +++ b/circleindicator/src/main/java/me/relex/circleindicator/Config.java @@ -13,9 +13,9 @@ public class Config { @AnimatorRes int animatorResId = R.animator.scale_with_alpha; @AnimatorRes int animatorReverseResId = 0; @DrawableRes int backgroundResId = R.drawable.white_radius; - @DrawableRes int backgroundLastResID = R.drawable.add; + @DrawableRes int backgroundLastResID = R.drawable.white_radius; @DrawableRes int unselectedBackgroundId; - @DrawableRes int unselectedBackgroundLastId = R.drawable.add_unselected; + @DrawableRes int unselectedBackgroundLastId; int orientation = LinearLayout.HORIZONTAL; int gravity = Gravity.CENTER; diff --git a/circleindicator/src/main/res/drawable/add_unselected.png b/circleindicator/src/main/res/drawable/add_unselected.png deleted file mode 100644 index b0d974f30670974ab42a639be4f37442812c8034..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 4257 zcmV;S5MJ+zP)Dm?vBSEd&Y*1XiJJHAt?|c zwLxuE)GA7$ND!d31a+GV2q;SlY163Xm879uJ`M6&zyVC?YM zCeoD2AZ{9!v_hXkhoBuG9Y6;lKqJt$bm=s(04Oj8I;F^zz?8rUqQhuxSYtYrP9#P| zM9usQ%_61+)B;tN(PHsD^}JtHm5YG)q5K@enZY*9+bX;&@T!QujL7qSU0ttl2eU=i zSc79@=Q_kbBBEC)atUy@X-!K^fjqD3J?r89%Q>mkLDPbQATq{MRT(W5F7Z^Z0i9D4|CTC2m*(`Nstb@hku2{+4i^wNg{Kgi2 zl(%u%ANSk`Q>j$mw46$*3u6rziy5!veMW@qfF{#=3^6alqw2`LnXay3(_%Iv)W$lP z&!=L@ohY}keGRpmlE9P1oj*<|5?Rw?)+3b0di~I$Gn(d0e+b+TG@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d{ARm$500000NkvXXu0mjf D@z7-k diff --git a/circleindicator/src/main/res/values/attrs.xml b/circleindicator/src/main/res/values/attrs.xml index 8157ace..d2a81ff 100644 --- a/circleindicator/src/main/res/values/attrs.xml +++ b/circleindicator/src/main/res/values/attrs.xml @@ -9,6 +9,8 @@ + + diff --git a/sample/src/main/java/me/relex/circleindicator/sample/SampleActivity.java b/sample/src/main/java/me/relex/circleindicator/sample/SampleActivity.java index 31379c5..d139560 100644 --- a/sample/src/main/java/me/relex/circleindicator/sample/SampleActivity.java +++ b/sample/src/main/java/me/relex/circleindicator/sample/SampleActivity.java @@ -18,6 +18,7 @@ import java.util.List; import me.relex.circleindicator.sample.fragment.ChangeColorFragment; import me.relex.circleindicator.sample.fragment.CustomAnimationFragment; +import me.relex.circleindicator.sample.fragment.CustomLastItemFragment; import me.relex.circleindicator.sample.fragment.DefaultFragment; import me.relex.circleindicator.sample.fragment.DynamicAdapterFragment; import me.relex.circleindicator.sample.fragment.LoopRecyclerViewFragment; @@ -75,6 +76,7 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat recyclerView.setAdapter(adapter); adapter.add(new SampleInfo("Default", DefaultFragment.class.getName())); + adapter.add(new SampleInfo("Custom Last Item", CustomLastItemFragment.class.getName())); adapter.add( new SampleInfo("Custom Animation", CustomAnimationFragment.class.getName())); adapter.add(new SampleInfo("Change Color", ChangeColorFragment.class.getName())); diff --git a/sample/src/main/java/me/relex/circleindicator/sample/fragment/CustomLastItemFragment.java b/sample/src/main/java/me/relex/circleindicator/sample/fragment/CustomLastItemFragment.java new file mode 100644 index 0000000..1d22d02 --- /dev/null +++ b/sample/src/main/java/me/relex/circleindicator/sample/fragment/CustomLastItemFragment.java @@ -0,0 +1,33 @@ +package me.relex.circleindicator.sample.fragment; + +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.fragment.app.Fragment; +import androidx.viewpager.widget.ViewPager; + +import me.relex.circleindicator.CircleIndicator; +import me.relex.circleindicator.sample.R; +import me.relex.circleindicator.sample.SamplePagerAdapter; + +public class CustomLastItemFragment extends Fragment { + + @Nullable + @Override + public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, + @Nullable Bundle savedInstanceState) { + return inflater.inflate(R.layout.fragment_custom_last_item, container, false); + } + + @Override public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { + ViewPager viewpager = view.findViewById(R.id.viewpager); + CircleIndicator indicator = view.findViewById(R.id.indicator); + viewpager.setAdapter(new SamplePagerAdapter()); + indicator.setViewPager(viewpager); + viewpager.setCurrentItem(2); + } +} diff --git a/circleindicator/src/main/res/drawable/add.png b/sample/src/main/res/drawable/add.png similarity index 100% rename from circleindicator/src/main/res/drawable/add.png rename to sample/src/main/res/drawable/add.png diff --git a/sample/src/main/res/drawable/add_unselected.png b/sample/src/main/res/drawable/add_unselected.png new file mode 100644 index 0000000000000000000000000000000000000000..8e3d78b48a2f71e7ec5be8757a93ffb2fde8dc1b GIT binary patch literal 4297 zcmV;)5H|0LP)=M$ZnHCHQDQ%MpA!*0q(L$Vb+76wj(AsH?Z4w|& zFar{Hk^Io^y}ObuIkFzs?)mi(X%$)4V;}e4bNA|e{@T5J@9%tl{nfeWp2zPH7Aee3 zwr#fpp;bA^R$^`is0D-w0}%ou07pPXU{nF9pS<(}2p7T30QE7@M?fDKeE^?gqHY7C zn|b_w(=<;J5v%)Gs)JMu@B(Hg%j(}CDYu!Jt_AT20sJa}D_t)7Jb>e1I?lvzkQ7Jb z@kqyFFk4`abtau&Ye;;Iftv}u1)#8MO_THya8v@XNP+)ojz&+a7UTwjF%~mZGM(N+ zOt%5J6~G5nYbpc+PBQQk6CX%KqsM|$n^nBAEX&#?LB9{sCjm68)>9sQ8jJ&ic)w|y zZ>v^Q4i#xE%d+Zo5Wfdt2LT^Zt;Y=rI3^k2BF?^;NF;_;>nWCsGL~go(HzrGBKiz~ zh-y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XGL rLLVfb5}+<-bV+Hv@5GAYO6C6nw`g1R2aBhb00000NkvXXu0mjf5&-9O literal 0 HcmV?d00001 diff --git a/sample/src/main/res/layout/fragment_custom_last_item.xml b/sample/src/main/res/layout/fragment_custom_last_item.xml new file mode 100644 index 0000000..2dee688 --- /dev/null +++ b/sample/src/main/res/layout/fragment_custom_last_item.xml @@ -0,0 +1,23 @@ + + + + + + + + \ No newline at end of file From fc87d3a1802e47062ccf8ee37ae5d8281489a166 Mon Sep 17 00:00:00 2001 From: ThiagoFontes Date: Tue, 29 Oct 2019 17:01:37 -0300 Subject: [PATCH 3/3] Unselected item colors where not taken in consideration at last item --- .../me/relex/circleindicator/BaseCircleIndicator.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/circleindicator/src/main/java/me/relex/circleindicator/BaseCircleIndicator.java b/circleindicator/src/main/java/me/relex/circleindicator/BaseCircleIndicator.java index 7afcea2..ea5c0f6 100644 --- a/circleindicator/src/main/java/me/relex/circleindicator/BaseCircleIndicator.java +++ b/circleindicator/src/main/java/me/relex/circleindicator/BaseCircleIndicator.java @@ -120,9 +120,13 @@ public void initialize(Config config) { mIndicatorUnselectedBackgroundResId = (config.unselectedBackgroundId == 0) ? config.backgroundResId : config.unselectedBackgroundId; - mLastIndicatorBackgroundResId = (config.backgroundLastResID == 0) ? config.backgroundResId : config.backgroundLastResID; - mLastIndicatorUnselectedBackgroundResId = (config.unselectedBackgroundLastId == 0) ? config.backgroundResId: config.unselectedBackgroundLastId; + mLastIndicatorUnselectedBackgroundResId = + (config.unselectedBackgroundLastId == 0) ? + (config.unselectedBackgroundId == 0) ? + config.backgroundResId : config.unselectedBackgroundId : + config.unselectedBackgroundLastId; + setOrientation(config.orientation == VERTICAL ? VERTICAL : HORIZONTAL); setGravity(config.gravity >= 0 ? config.gravity : Gravity.CENTER); }