Skip to content

Commit

Permalink
[Transitions] Fixed catalog errors for some demos.
Browse files Browse the repository at this point in the history
* Music player controls expands to take the place of the title area by updating constraints to tie both view groups to the bottom of the album art.
* Fixed container transform activity scrolling bug caused by window.setSharedElementsUseOverlay. Removed this as it has no effect on the demo.
* Fixed shared axis fragment end layout not animating by setting the end fragments transition name on the root scroll view instead of the scroll view's inner layout
* Added insets to shared axis controls to be visible above the navigation bar when in edge-to-edge mode

Resolves #3247

PiperOrigin-RevId: 511764274
  • Loading branch information
hunterstich committed Feb 23, 2023
1 parent 3fb6bb2 commit 4c3e1d5
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 49 deletions.
Expand Up @@ -58,6 +58,52 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<!-- Album Info Container. Use a Card to give its background an -->
<!-- elevation overlay in dark theme. -->
<com.google.android.material.card.MaterialCardView
android:id="@+id/album_info_container"
android:layout_width="match_parent"
android:layout_height="196dp"
app:cardBackgroundColor="?attr/colorPrimarySurface"
app:strokeWidth="0dp"
app:cardCornerRadius="0dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/album_image">

<LinearLayout
android:id="@+id/album_details"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingStart="56dp"
android:paddingEnd="16dp"
android:paddingLeft="56dp"
android:paddingRight="16dp"
android:gravity="center_vertical"
android:orientation="vertical">

<TextView
android:id="@+id/album_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="1"
android:textAppearance="?attr/textAppearanceHeadline3"
android:textColor="?attr/colorOnPrimarySurface"
tools:text="Metamorphosis" />
<TextView
android:id="@+id/album_artist"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="1"
android:textAppearance="?attr/textAppearanceSubtitle1"
android:textColor="?attr/colorOnPrimarySurface"
tools:text="Sandra Adams" />

</LinearLayout>

</com.google.android.material.card.MaterialCardView>
<!-- Music Player -->
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/music_player_container"
Expand Down Expand Up @@ -168,51 +214,6 @@

</androidx.constraintlayout.widget.ConstraintLayout>

<!-- Album Info Container. Use a Card to give its background an -->
<!-- elevation overlay in dark theme. -->
<com.google.android.material.card.MaterialCardView
android:id="@+id/album_info_container"
android:layout_width="match_parent"
android:layout_height="196dp"
app:cardBackgroundColor="?attr/colorPrimarySurface"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/music_player_container">

<LinearLayout
android:id="@+id/album_details"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingStart="56dp"
android:paddingEnd="16dp"
android:paddingLeft="56dp"
android:paddingRight="16dp"
android:gravity="center_vertical"
android:orientation="vertical">

<TextView
android:id="@+id/album_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="1"
android:textAppearance="?attr/textAppearanceHeadline3"
android:textColor="?attr/colorOnPrimarySurface"
tools:text="Metamorphosis" />
<TextView
android:id="@+id/album_artist"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="1"
android:textAppearance="?attr/textAppearanceSubtitle1"
android:textColor="?attr/colorOnPrimarySurface"
tools:text="Sandra Adams" />

</LinearLayout>

</com.google.android.material.card.MaterialCardView>

<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
Expand Down
19 changes: 19 additions & 0 deletions catalog/java/io/material/catalog/transition/SharedAxisHelper.java
Expand Up @@ -19,12 +19,16 @@
import io.material.catalog.R;

import android.util.SparseIntArray;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.RadioGroup;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.view.OnApplyWindowInsetsListener;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
import com.google.android.material.transition.MaterialSharedAxis;

/** A helper class that sets up and manages shared axis demo controls. */
Expand All @@ -46,6 +50,21 @@ public class SharedAxisHelper {
backButton = controlsLayout.findViewById(R.id.back_button);
nextButton = controlsLayout.findViewById(R.id.next_button);
directionRadioGroup = controlsLayout.findViewById(R.id.radio_button_group_direction);
ViewCompat.setOnApplyWindowInsetsListener(
controlsLayout,
new OnApplyWindowInsetsListener() {
@NonNull
@Override
public WindowInsetsCompat onApplyWindowInsets(
@NonNull View v, @NonNull WindowInsetsCompat insets) {
v.setPadding(
v.getPaddingLeft(),
v.getPaddingTop(),
v.getPaddingRight(),
insets.getInsets(WindowInsetsCompat.Type.navigationBars()).bottom);
return insets;
}
});
}

public void setNextButtonOnClickListener(@Nullable OnClickListener onClickListener) {
Expand Down
Expand Up @@ -46,9 +46,8 @@ public class TransitionContainerTransformStartDemoActivity extends DemoActivity
protected void onCreate(@Nullable Bundle bundle) {
getWindow().requestFeature(Window.FEATURE_ACTIVITY_TRANSITIONS);

// Set up shared element transition and disable overlay so views don't show above system bars
// Set up shared element transition
setExitSharedElementCallback(new MaterialContainerTransformSharedElementCallback());
getWindow().setSharedElementsUseOverlay(false);

super.onCreate(bundle);

Expand Down
Expand Up @@ -17,11 +17,11 @@
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/end_root"
android:layout_width="match_parent"
android:layout_height="match_parent">

<LinearLayout
android:id="@+id/end_root"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp"
Expand Down
Expand Up @@ -22,7 +22,7 @@
android:orientation="vertical"
tools:targetApi="lollipop">

<FrameLayout
<androidx.fragment.app.FragmentContainerView
android:id="@+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="0dp"
Expand Down

0 comments on commit 4c3e1d5

Please sign in to comment.