Skip to content

Commit 0091aa4

Browse files
committed
MDC-Android 1.1.0-alpha04
Add extened FAB and implement in sample. Update text input layout and edit text to support new styles.
1 parent 2f05d46 commit 0091aa4

19 files changed

+754
-51
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ buildscript {
2424
'fragment' : '1.1.0-alpha04',
2525
'gson' : '2.8.5',
2626
'kotlin' : '1.3.21',
27-
'material' : '1.1.0-alpha03'
27+
'material' : '1.1.0-alpha04'
2828
]
2929

3030
repositories {

dynamic-support/src/main/java/com/pranavpandey/android/dynamic/support/activity/DynamicActivity.java

Lines changed: 204 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949

5050
import com.google.android.material.appbar.AppBarLayout;
5151
import com.google.android.material.appbar.CollapsingToolbarLayout;
52+
import com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton;
5253
import com.google.android.material.floatingactionbutton.FloatingActionButton;
5354
import com.google.android.material.snackbar.Snackbar;
5455
import com.pranavpandey.android.dynamic.support.R;
@@ -58,6 +59,7 @@
5859
import com.pranavpandey.android.dynamic.support.utils.DynamicHintUtils;
5960
import com.pranavpandey.android.dynamic.support.utils.DynamicInputUtils;
6061
import com.pranavpandey.android.dynamic.support.utils.DynamicResourceUtils;
62+
import com.pranavpandey.android.dynamic.support.widget.DynamicExtendedFloatingActionButton;
6163
import com.pranavpandey.android.dynamic.utils.DynamicColorUtils;
6264
import com.pranavpandey.android.dynamic.utils.DynamicDrawableUtils;
6365

@@ -108,6 +110,13 @@ public abstract class DynamicActivity extends DynamicStateActivity {
108110
*/
109111
protected FloatingActionButton mFAB;
110112

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+
111120
/**
112121
* Coordinator layout used by this activity.
113122
*/
@@ -176,6 +185,7 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
176185
mSearchViewRoot = findViewById(R.id.ads_search_view_root);
177186
mSearchViewClear = findViewById(R.id.ads_search_view_clear);
178187
mFAB = findViewById(R.id.ads_fab);
188+
mExtendedFAB = findViewById(R.id.ads_fab_extended);
179189

180190
mCoordinatorLayout = findViewById(R.id.ads_coordinator_layout);
181191
mAppBarLayout = findViewById(R.id.ads_app_bar_layout);
@@ -198,13 +208,16 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
198208
setSearchView();
199209

200210
if (savedInstanceState != null) {
201-
mAppBarLayout.setExpanded(
202-
savedInstanceState.getBoolean(ADS_STATE_APP_BAR_COLLAPSED));
211+
mAppBarLayout.setExpanded(savedInstanceState.getBoolean(ADS_STATE_APP_BAR_COLLAPSED));
203212

204213
if (savedInstanceState.getInt(ADS_STATE_FAB_VISIBLE) != View.INVISIBLE) {
205214
DynamicFABUtils.show(mFAB);
206215
}
207216

217+
if (savedInstanceState.getInt(ADS_STATE_EXTENDED_FAB_VISIBLE) != View.INVISIBLE) {
218+
DynamicFABUtils.show(mExtendedFAB, false);
219+
}
220+
208221
if (savedInstanceState.getBoolean(ADS_STATE_SEARCH_VIEW_VISIBLE)) {
209222
restoreSearchViewState();
210223
}
@@ -245,6 +258,12 @@ public void onSaveInstanceState(@NonNull Bundle outState) {
245258

246259
outState.putBoolean(ADS_STATE_APP_BAR_COLLAPSED, isAppBarCollapsed());
247260
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+
}
248267

249268
if (mSearchViewRoot != null) {
250269
outState.putBoolean(ADS_STATE_SEARCH_VIEW_VISIBLE,
@@ -773,6 +792,8 @@ public void onBackPressed() {
773792
}
774793

775794
/**
795+
* Get the floating action button used by this activity.
796+
*
776797
* @return The floating action button used by this activity.
777798
*/
778799
public @Nullable FloatingActionButton getFAB() {
@@ -781,18 +802,20 @@ public void onBackPressed() {
781802

782803
/**
783804
* 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.
786807
*
787808
* <p><p>Please use {@link #getFAB()} method to perform more operations dynamically.
788809
*
789810
* @param drawable The image drawable to be set.
790811
* @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}.
792813
* @param onClickListener Callback that will run when this view is clicked.
793814
*/
794815
public void setFAB(@Nullable Drawable drawable, int visibility,
795816
@Nullable View.OnClickListener onClickListener) {
817+
removeExtendedFAB();
818+
796819
if (mFAB != null) {
797820
setFABImageDrawable(drawable);
798821
mFAB.setOnClickListener(onClickListener);
@@ -802,8 +825,8 @@ public void setFAB(@Nullable Drawable drawable, int visibility,
802825

803826
/**
804827
* 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.
807830
*
808831
* <p><p>Please use {@link #getFAB()} method to perform more operations dynamically.
809832
*
@@ -890,6 +913,180 @@ public void removeFAB() {
890913
}
891914
}
892915

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+
8931090
/**
8941091
* Make a themed snack bar with text and action. Background will be the tint background color
8951092
* to blend it smoothly and it will automatically use its tint color for the text and action

0 commit comments

Comments
 (0)