Skip to content

Commit

Permalink
[TopAppBar] Added liftOnScroll and lifted toggles to the catalog.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 561137677
  • Loading branch information
pekingme authored and leticiarossi committed Aug 30, 2023
1 parent 480bbc6 commit 4e995d1
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
Expand Up @@ -28,6 +28,7 @@
import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.Nullable;
import com.google.android.material.appbar.AppBarLayout;
import com.google.android.material.badge.BadgeDrawable;
import com.google.android.material.badge.BadgeUtils;
import com.google.android.material.button.MaterialButton;
Expand All @@ -38,9 +39,12 @@
/** A fragment that displays the main Top App Bar demo for the Catalog app. */
public class TopAppBarMainDemoFragment extends DemoFragment {

private AppBarLayout appBarLayout;
private Toolbar toolbar;
private BadgeDrawable badgeDrawable;
private MaterialSwitch editMenuToggle;
private MaterialSwitch liftOnScrollToggle;
private MaterialSwitch liftToggle;
private MaterialButton incrementBadgeNumber;

@Override
Expand All @@ -54,6 +58,7 @@ public View onCreateDemoView(
LayoutInflater layoutInflater, @Nullable ViewGroup viewGroup, @Nullable Bundle bundle) {
View view = layoutInflater.inflate(R.layout.cat_topappbar_fragment, viewGroup, false);

appBarLayout = view.findViewById(R.id.appbarlayout);
toolbar = view.findViewById(R.id.toolbar);
AppCompatActivity activity = (AppCompatActivity) getActivity();
activity.setSupportActionBar(toolbar);
Expand All @@ -66,6 +71,20 @@ public View onCreateDemoView(
BadgeUtils.attachBadgeDrawable(badgeDrawable, toolbar, R.id.cat_topappbar_item_favorite);
});

liftOnScrollToggle = view.findViewById(R.id.cat_topappbar_switch_lift_on_scroll);
liftOnScrollToggle.setOnCheckedChangeListener(
(buttonView, isChecked) -> {
appBarLayout.setLiftOnScroll(isChecked);
liftToggle.setEnabled(!isChecked);
if (!isChecked) {
appBarLayout.setLifted(liftToggle.isChecked());
}
});

liftToggle = view.findViewById(R.id.cat_topappbar_switch_lifted);
liftToggle.setOnCheckedChangeListener(
(buttonView, isChecked) -> appBarLayout.setLifted(isChecked));

incrementBadgeNumber = view.findViewById(R.id.cat_topappbar_button_increment_badge);
incrementBadgeNumber.setOnClickListener(
v -> {
Expand Down
Expand Up @@ -52,6 +52,20 @@
android:layout_gravity="center_horizontal"
android:text="@string/cat_topappbar_edit_menu_toggle"
android:checked="true"/>
<com.google.android.material.materialswitch.MaterialSwitch
android:id="@+id/cat_topappbar_switch_lift_on_scroll"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="@string/cat_topappbar_lift_on_scroll_toggle"
android:checked="true"/>
<com.google.android.material.materialswitch.MaterialSwitch
android:id="@+id/cat_topappbar_switch_lifted"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="@string/cat_topappbar_lifted"
android:enabled="false"/>
<Button
android:id="@+id/cat_topappbar_button_increment_badge"
android:layout_width="wrap_content"
Expand Down
Expand Up @@ -97,6 +97,8 @@
<string name="cat_topappbar_increment_badge_number" description="The title of a button to increment the notification number. [CHAR_LIMIT=20]">+Badge number</string>
<!-- Badge increment button label -->
<string name="cat_topappbar_edit_menu_toggle" description="The title of a switch to toggle between showing and hiding an edit menu. [CHAR_LIMIT=NONE]">Show edit menu</string>
<string name="cat_topappbar_lift_on_scroll_toggle" description="The title of a switch to toggle between enabling and disabling lift on scroll. [CHAR_LIMIT=NONE]">Enable lift on scroll</string>
<string name="cat_topappbar_lifted" description="The title of a switch to toggle between lifting and not lifting the app bar. [CHAR_LIMIT=NONE]">Lift the app bar</string>

<string name="cat_topappbar_compress_effect_demo_title">Compress Effect Demo</string>
<string name="cat_topappbar_compress_toolbar_title">Compress Title</string>
Expand Down

0 comments on commit 4e995d1

Please sign in to comment.