49
49
50
50
import com .google .android .material .appbar .AppBarLayout ;
51
51
import com .google .android .material .appbar .CollapsingToolbarLayout ;
52
+ import com .google .android .material .floatingactionbutton .ExtendedFloatingActionButton ;
52
53
import com .google .android .material .floatingactionbutton .FloatingActionButton ;
53
54
import com .google .android .material .snackbar .Snackbar ;
54
55
import com .pranavpandey .android .dynamic .support .R ;
58
59
import com .pranavpandey .android .dynamic .support .utils .DynamicHintUtils ;
59
60
import com .pranavpandey .android .dynamic .support .utils .DynamicInputUtils ;
60
61
import com .pranavpandey .android .dynamic .support .utils .DynamicResourceUtils ;
62
+ import com .pranavpandey .android .dynamic .support .widget .DynamicExtendedFloatingActionButton ;
61
63
import com .pranavpandey .android .dynamic .utils .DynamicColorUtils ;
62
64
import com .pranavpandey .android .dynamic .utils .DynamicDrawableUtils ;
63
65
@@ -108,6 +110,13 @@ public abstract class DynamicActivity extends DynamicStateActivity {
108
110
*/
109
111
protected FloatingActionButton mFAB ;
110
112
113
+ /**
114
+ * Extended floating action button used by this activity.
115
+ * <p>Use the methods {@link #setExtendedFAB(Drawable, String, int, View.OnClickListener)} or
116
+ * {@link #setExtendedFAB(int, int, int, View.OnClickListener)} to enable it.
117
+ */
118
+ protected ExtendedFloatingActionButton mExtendedFAB ;
119
+
111
120
/**
112
121
* Coordinator layout used by this activity.
113
122
*/
@@ -176,6 +185,7 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
176
185
mSearchViewRoot = findViewById (R .id .ads_search_view_root );
177
186
mSearchViewClear = findViewById (R .id .ads_search_view_clear );
178
187
mFAB = findViewById (R .id .ads_fab );
188
+ mExtendedFAB = findViewById (R .id .ads_fab_extended );
179
189
180
190
mCoordinatorLayout = findViewById (R .id .ads_coordinator_layout );
181
191
mAppBarLayout = findViewById (R .id .ads_app_bar_layout );
@@ -198,13 +208,16 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
198
208
setSearchView ();
199
209
200
210
if (savedInstanceState != null ) {
201
- mAppBarLayout .setExpanded (
202
- savedInstanceState .getBoolean (ADS_STATE_APP_BAR_COLLAPSED ));
211
+ mAppBarLayout .setExpanded (savedInstanceState .getBoolean (ADS_STATE_APP_BAR_COLLAPSED ));
203
212
204
213
if (savedInstanceState .getInt (ADS_STATE_FAB_VISIBLE ) != View .INVISIBLE ) {
205
214
DynamicFABUtils .show (mFAB );
206
215
}
207
216
217
+ if (savedInstanceState .getInt (ADS_STATE_EXTENDED_FAB_VISIBLE ) != View .INVISIBLE ) {
218
+ DynamicFABUtils .show (mExtendedFAB , false );
219
+ }
220
+
208
221
if (savedInstanceState .getBoolean (ADS_STATE_SEARCH_VIEW_VISIBLE )) {
209
222
restoreSearchViewState ();
210
223
}
@@ -245,6 +258,12 @@ public void onSaveInstanceState(@NonNull Bundle outState) {
245
258
246
259
outState .putBoolean (ADS_STATE_APP_BAR_COLLAPSED , isAppBarCollapsed ());
247
260
outState .putInt (ADS_STATE_FAB_VISIBLE , mFAB .getVisibility ());
261
+ outState .putInt (ADS_STATE_EXTENDED_FAB_VISIBLE , mExtendedFAB .getVisibility ());
262
+
263
+ if (mExtendedFAB instanceof DynamicExtendedFloatingActionButton ) {
264
+ outState .putBoolean (ADS_STATE_EXTENDED_FAB_STATE ,
265
+ ((DynamicExtendedFloatingActionButton ) mExtendedFAB ).isFABExtended ());
266
+ }
248
267
249
268
if (mSearchViewRoot != null ) {
250
269
outState .putBoolean (ADS_STATE_SEARCH_VIEW_VISIBLE ,
@@ -773,6 +792,8 @@ public void onBackPressed() {
773
792
}
774
793
775
794
/**
795
+ * Get the floating action button used by this activity.
796
+ *
776
797
* @return The floating action button used by this activity.
777
798
*/
778
799
public @ Nullable FloatingActionButton getFAB () {
@@ -781,18 +802,20 @@ public void onBackPressed() {
781
802
782
803
/**
783
804
* Set a floating action button (FAB) used by this activity by supplying an image drawable,
784
- * current visibility and a click listener. FAB will be tinted automatically according to the
785
- * accent color used by this activity.
805
+ * current visibility and a click listener.
806
+ * <p>The FAB will be tinted automatically according to the accent color used by this activity.
786
807
*
787
808
* <p><p>Please use {@link #getFAB()} method to perform more operations dynamically.
788
809
*
789
810
* @param drawable The image drawable to be set.
790
811
* @param visibility The visibility to be set.
791
- * <p>C {@link View#VISIBLE}, {@link View#INVISIBLE} or {@link View#GONE}.
812
+ * <p>{@link View#VISIBLE}, {@link View#INVISIBLE} or {@link View#GONE}.
792
813
* @param onClickListener Callback that will run when this view is clicked.
793
814
*/
794
815
public void setFAB (@ Nullable Drawable drawable , int visibility ,
795
816
@ Nullable View .OnClickListener onClickListener ) {
817
+ removeExtendedFAB ();
818
+
796
819
if (mFAB != null ) {
797
820
setFABImageDrawable (drawable );
798
821
mFAB .setOnClickListener (onClickListener );
@@ -802,8 +825,8 @@ public void setFAB(@Nullable Drawable drawable, int visibility,
802
825
803
826
/**
804
827
* Set a floating action button (FAB) used by this activity by supplying an image drawable,
805
- * current visibility and a click listener. FAB will be tinted automatically according to the
806
- * accent color used by this activity.
828
+ * current visibility and a click listener.
829
+ * <p>The FAB will be tinted automatically according to the accent color used by this activity.
807
830
*
808
831
* <p><p>Please use {@link #getFAB()} method to perform more operations dynamically.
809
832
*
@@ -890,6 +913,180 @@ public void removeFAB() {
890
913
}
891
914
}
892
915
916
+ /**
917
+ * Get the extended floating action button used by this activity.
918
+ *
919
+ * @return The extended floating action button used by this activity.
920
+ */
921
+ public @ Nullable ExtendedFloatingActionButton getExtendedFAB () {
922
+ return mExtendedFAB ;
923
+ }
924
+
925
+ /**
926
+ * Set an extended floating action button (FAB) used by this activity by supplying an icon,
927
+ * a text, current visibility and a click listener.
928
+ * <p>The FAB will be tinted automatically according to the accent color used by this activity.
929
+ *
930
+ * <p><p>Please use {@link #getExtendedFAB()} method to perform more operations dynamically.
931
+ *
932
+ * @param icon The icon drawable to be set.
933
+ * @param text The text to be set.
934
+ * @param visibility The visibility to be set.
935
+ * <p>{@link View#VISIBLE}, {@link View#INVISIBLE} or {@link View#GONE}.
936
+ * @param onClickListener Callback that will run when this view is clicked.
937
+ */
938
+ public void setExtendedFAB (@ Nullable Drawable icon , @ Nullable String text ,
939
+ int visibility , @ Nullable View .OnClickListener onClickListener ) {
940
+ removeFAB ();
941
+
942
+ if (mExtendedFAB != null ) {
943
+ updateExtendedFAB (icon , text );
944
+ mExtendedFAB .setOnClickListener (onClickListener );
945
+ setExtendedFABVisibility (visibility );
946
+ }
947
+ }
948
+
949
+ /**
950
+ * Set an extended floating action button (FAB) used by this activity by supplying an icon,
951
+ * a text, current visibility and a click listener.
952
+ * <p>The FAB will be tinted automatically according to the accent color used by this activity.
953
+ *
954
+ * <p><p>Please use {@link #getExtendedFAB()} method to perform more operations dynamically.
955
+ *
956
+ * @param drawableRes The icon drawable resource to be set.
957
+ * @param resId The string resource id to be set.
958
+ * @param visibility The visibility to be set.
959
+ * <p>{@link View#VISIBLE}, {@link View#INVISIBLE} or {@link View#GONE}.
960
+ * @param onClickListener Callback that will run when this view is clicked.
961
+ */
962
+ public void setExtendedFAB (@ DrawableRes int drawableRes , @ StringRes int resId ,
963
+ int visibility , @ Nullable View .OnClickListener onClickListener ) {
964
+ setExtendedFAB (DynamicResourceUtils .getDrawable (this , drawableRes ),
965
+ getString (resId ), visibility , onClickListener );
966
+ }
967
+
968
+ /**
969
+ * Set the extended FAB icon and text.
970
+ * <p>Icon and text will be tinted automatically according to its background color to provide
971
+ * best visibility.
972
+ *
973
+ * @param icon The icon drawable to be set.
974
+ * @param text The text to be set.
975
+ */
976
+ public void updateExtendedFAB (@ Nullable Drawable icon , @ Nullable String text ) {
977
+ if (mExtendedFAB != null ) {
978
+ mExtendedFAB .setText (text );
979
+ mExtendedFAB .setIcon (icon );
980
+ }
981
+ }
982
+
983
+ /**
984
+ * Set the extended FAB icon and text.
985
+ * <p>Icon and text will be tinted automatically according to its background color to provide
986
+ * best visibility.
987
+ *
988
+ * @param drawableRes The icon drawable resource to be set.
989
+ * @param resId The string resource id to be set.
990
+ */
991
+ public void updateExtendedFAB (@ DrawableRes int drawableRes , @ StringRes int resId ) {
992
+ updateExtendedFAB (DynamicResourceUtils .getDrawable (this , drawableRes ), getString (resId ));
993
+ }
994
+
995
+ /**
996
+ * Set the extended FAB visibility to {@link View#VISIBLE}, {@link View#INVISIBLE}
997
+ * or {@link View#GONE}.
998
+ */
999
+ public void setExtendedFABVisibility (int visibility ) {
1000
+ if (mExtendedFAB != null && visibility != ADS_VISIBILITY_EXTENDED_FAB_NO_CHANGE ) {
1001
+ switch (visibility ) {
1002
+ case View .VISIBLE :
1003
+ DynamicFABUtils .show (mExtendedFAB , false );
1004
+ break ;
1005
+ case View .INVISIBLE :
1006
+ case View .GONE :
1007
+ DynamicFABUtils .hide (mExtendedFAB , false );
1008
+ break ;
1009
+ }
1010
+ }
1011
+ }
1012
+
1013
+ /**
1014
+ * Shrink the extended FAB.
1015
+ */
1016
+ public void shrinkFAB () {
1017
+ if (mExtendedFAB != null ) {
1018
+ mExtendedFAB .shrink ();
1019
+ }
1020
+ }
1021
+
1022
+ /**
1023
+ * Shrink the extended FAB.
1024
+ *
1025
+ * @param allowExtended {@code true} if the FAB can be extended.
1026
+ */
1027
+ public void shrinkFAB (boolean allowExtended ) {
1028
+ if (mExtendedFAB != null ) {
1029
+ shrinkFAB ();
1030
+
1031
+ if (mExtendedFAB instanceof DynamicExtendedFloatingActionButton ) {
1032
+ ((DynamicExtendedFloatingActionButton ) mExtendedFAB )
1033
+ .setAllowExtended (allowExtended );
1034
+ }
1035
+ }
1036
+ }
1037
+
1038
+ /**
1039
+ * Extend the extended FAB.
1040
+ */
1041
+ public void extendFAB () {
1042
+ if (mExtendedFAB != null ) {
1043
+ mExtendedFAB .extend ();
1044
+ }
1045
+ }
1046
+
1047
+ /**
1048
+ * Shrink the extended FAB.
1049
+ *
1050
+ * @param allowExtended {@code true} if the FAB can be extended.
1051
+ */
1052
+ public void extendFAB (boolean allowExtended ) {
1053
+ if (mExtendedFAB != null ) {
1054
+ extendFAB ();
1055
+
1056
+ if (mExtendedFAB instanceof DynamicExtendedFloatingActionButton ) {
1057
+ ((DynamicExtendedFloatingActionButton ) mExtendedFAB )
1058
+ .setAllowExtended (allowExtended );
1059
+ }
1060
+ }
1061
+ }
1062
+
1063
+ /**
1064
+ * Show the extended FAB by setting its visibility to {@link View#VISIBLE}.
1065
+ */
1066
+ public void showExtendedFAB () {
1067
+ setExtendedFABVisibility (View .VISIBLE );
1068
+ }
1069
+
1070
+ /**
1071
+ * Hide the extended FAB by setting its visibility to {@link View#GONE}.
1072
+ */
1073
+ public void hideExtendedFAB () {
1074
+ setExtendedFABVisibility (View .GONE );
1075
+ }
1076
+
1077
+ /**
1078
+ * Remove the extended FAB associated with this activity.
1079
+ * <p>Please call the methods {@link #setExtendedFAB(int, int, int, View.OnClickListener)}
1080
+ * or {@link #setExtendedFAB(Drawable, String, int, View.OnClickListener)} to set it again.
1081
+ */
1082
+ public void removeExtendedFAB () {
1083
+ if (mExtendedFAB != null ) {
1084
+ updateExtendedFAB (null , null );
1085
+ mExtendedFAB .setOnClickListener (null );
1086
+ hideExtendedFAB ();
1087
+ }
1088
+ }
1089
+
893
1090
/**
894
1091
* Make a themed snack bar with text and action. Background will be the tint background color
895
1092
* to blend it smoothly and it will automatically use its tint color for the text and action
0 commit comments