Skip to content

Commit

Permalink
[Motion] Update transitions to be based on androidx and add transitio…
Browse files Browse the repository at this point in the history
…ns platform subpackage to support Activities, Windows, etc.

PiperOrigin-RevId: 308651633
  • Loading branch information
dsn5ft committed Apr 27, 2020
1 parent 4a8e005 commit cd36c2f
Show file tree
Hide file tree
Showing 58 changed files with 3,240 additions and 188 deletions.
4 changes: 2 additions & 2 deletions catalog/java/io/material/catalog/feature/DemoActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
import android.view.View;
import android.view.ViewGroup;
import com.google.android.material.color.MaterialColors;
import com.google.android.material.transition.MaterialContainerTransform;
import com.google.android.material.transition.MaterialContainerTransformSharedElementCallback;
import com.google.android.material.transition.platform.MaterialContainerTransform;
import com.google.android.material.transition.platform.MaterialContainerTransformSharedElementCallback;
import dagger.android.AndroidInjection;
import dagger.android.AndroidInjector;
import dagger.android.DispatchingAndroidInjector;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
import android.view.ViewGroup.MarginLayoutParams;
import android.widget.TextView;
import com.google.android.material.resources.MaterialResources;
import com.google.android.material.transition.MaterialContainerTransformSharedElementCallback;
import com.google.android.material.transition.platform.MaterialContainerTransformSharedElementCallback;
import dagger.android.support.DaggerFragment;
import java.util.Collections;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
* A helper class which manages all configuration UI presented in {@link
* TransitionContainerTransformDemoFragment}.
*/
@RequiresApi(VERSION_CODES.LOLLIPOP)
public class ContainerTransformConfigurationHelper {

private static final String CUBIC_CONTROL_FORMAT = "%.3f";
Expand Down Expand Up @@ -88,7 +87,7 @@ void showConfigurationChooser(Context context, @Nullable OnDismissListener onDis
bottomSheetDialog.show();
}

/** Set up the transition according to the config helper's parameters. */
/** Set up the androidx transition according to the config helper's parameters. */
void configure(MaterialContainerTransform transform, boolean entering) {
transform.setDuration(entering ? getEnterDuration() : getReturnDuration());
transform.setInterpolator(getInterpolator());
Expand All @@ -99,6 +98,21 @@ void configure(MaterialContainerTransform transform, boolean entering) {
transform.setDrawDebugEnabled(isDrawDebugEnabled());
}

/** Set up the platform transition according to the config helper's parameters. */
@RequiresApi(VERSION_CODES.LOLLIPOP)
void configure(
com.google.android.material.transition.platform.MaterialContainerTransform transform,
boolean entering) {
transform.setDuration(entering ? getEnterDuration() : getReturnDuration());
transform.setInterpolator(getInterpolator());
if (isArcMotionEnabled()) {
transform.setPathMotion(
new com.google.android.material.transition.platform.MaterialArcMotion());
}
transform.setFadeMode(getFadeMode());
transform.setDrawDebugEnabled(isDrawDebugEnabled());
}

/**
* Whether or not to a custom container transform should use {@link
* com.google.android.material.transition.MaterialArcMotion}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,14 @@

import io.material.catalog.R;

import android.annotation.TargetApi;
import android.os.Build.VERSION_CODES;
import android.os.Bundle;
import androidx.annotation.IdRes;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentManager.FragmentLifecycleCallbacks;
import androidx.core.view.ViewCompat;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
Expand All @@ -39,7 +38,6 @@
import io.material.catalog.feature.OnBackPressedHandler;

/** A fragment that displays the main Transition demo for the Catalog app. */
@TargetApi(VERSION_CODES.LOLLIPOP)
public class TransitionContainerTransformDemoFragment extends DemoFragment
implements OnBackPressedHandler {

Expand Down Expand Up @@ -106,14 +104,17 @@ public boolean onOptionsItemSelected(MenuItem menuItem) {
private void addTransitionableTarget(View view, @IdRes int id) {
View target = view.findViewById(id);
if (target != null) {
ViewCompat.setTransitionName(target, String.valueOf(id));
target.setOnClickListener(this::showEndFragment);
}
}

private void showStartFragment() {
TransitionSimpleLayoutFragment fragment =
TransitionSimpleLayoutFragment.newInstance(
R.layout.cat_transition_container_transform_start_fragment);
R.layout.cat_transition_container_transform_start_fragment,
"shared_element_fab",
R.id.start_fab);
fragment.setExitTransition(holdTransition);
getChildFragmentManager()
.beginTransaction()
Expand All @@ -123,14 +124,16 @@ private void showStartFragment() {
}

private void showEndFragment(View sharedElement) {
String transitionName = "shared_element_end_root";

Fragment fragment =
TransitionSimpleLayoutFragment.newInstance(
R.layout.cat_transition_container_transform_end_fragment);
R.layout.cat_transition_container_transform_end_fragment, transitionName);
configureTransitions(fragment);

getChildFragmentManager()
.beginTransaction()
.addSharedElement(sharedElement, "shared_element_end_root")
.addSharedElement(sharedElement, transitionName)
.replace(R.id.fragment_container, fragment, END_FRAGMENT_TAG)
.addToBackStack("ContainerTransformFragment::end")
.commit();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,22 @@

import static io.material.catalog.transition.TransitionContainerTransformStartDemoActivity.configurationHelper;

import android.annotation.TargetApi;
import android.os.Build.VERSION_CODES;
import android.os.Bundle;
import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import com.google.android.material.transition.MaterialContainerTransform;
import com.google.android.material.transition.MaterialContainerTransformSharedElementCallback;
import com.google.android.material.transition.platform.MaterialContainerTransform;
import com.google.android.material.transition.platform.MaterialContainerTransformSharedElementCallback;
import io.material.catalog.feature.DemoActivity;

/**
* An activity that displays the Container Transform activity transition demo for the Catalog app.
*/
@TargetApi(VERSION_CODES.LOLLIPOP)
@RequiresApi(VERSION_CODES.LOLLIPOP)
public class TransitionContainerTransformEndDemoActivity extends DemoActivity {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,26 @@

import io.material.catalog.R;

import android.annotation.TargetApi;
import android.app.ActivityOptions;
import android.content.Intent;
import android.os.Build.VERSION_CODES;
import android.os.Bundle;
import androidx.annotation.IdRes;
import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import com.google.android.material.transition.MaterialContainerTransformSharedElementCallback;
import com.google.android.material.transition.platform.MaterialContainerTransformSharedElementCallback;
import io.material.catalog.feature.DemoActivity;

/**
* An activity that displays the Container Transform activity transition demo for the Catalog app.
*/
@TargetApi(VERSION_CODES.LOLLIPOP)
@RequiresApi(VERSION_CODES.LOLLIPOP)
public class TransitionContainerTransformStartDemoActivity extends DemoActivity {

static ContainerTransformConfigurationHelper configurationHelper;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,25 @@

import io.material.catalog.R;

import android.annotation.TargetApi;
import android.graphics.Color;
import android.os.Build.VERSION_CODES;
import android.os.Bundle;
import androidx.annotation.IdRes;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import android.transition.TransitionManager;
import androidx.core.view.ViewCompat;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import androidx.transition.TransitionManager;
import com.google.android.material.transition.MaterialContainerTransform;
import io.material.catalog.feature.DemoFragment;
import io.material.catalog.feature.OnBackPressedHandler;

/** A fragment that displays the main Transition demo for the Catalog app. */
@TargetApi(VERSION_CODES.LOLLIPOP)
public class TransitionContainerTransformViewDemoFragment extends DemoFragment
implements OnBackPressedHandler {

Expand Down Expand Up @@ -75,6 +73,7 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle bundle) {
private void addTransitionableTarget(@NonNull View view, @IdRes int id) {
View target = view.findViewById(id);
if (target != null) {
ViewCompat.setTransitionName(target, String.valueOf(id));
if (id == R.id.end_card) {
target.setOnClickListener(v -> showStartView());
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,19 @@

import io.material.catalog.R;

import android.annotation.TargetApi;
import android.os.Build.VERSION_CODES;
import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import android.transition.TransitionManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import androidx.transition.TransitionManager;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.android.material.transition.MaterialFade;
import io.material.catalog.feature.DemoFragment;

/** A fragment that displays the Fade Transition demo for the Catalog app. */
@TargetApi(VERSION_CODES.LOLLIPOP)
public class TransitionFadeDemoFragment extends DemoFragment {

private Button fadeButton;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@

import io.material.catalog.R;

import android.annotation.TargetApi;
import android.os.Build.VERSION_CODES;
import android.os.Bundle;
import androidx.annotation.IdRes;
import androidx.annotation.LayoutRes;
Expand All @@ -35,7 +33,6 @@
import io.material.catalog.feature.DemoFragment;

/** A fragment that displays the Fade Through Transition demo for the Catalog app. */
@TargetApi(VERSION_CODES.LOLLIPOP)
public class TransitionFadeThroughDemoFragment extends DemoFragment {

private static final SparseIntArray LAYOUT_RES_MAP = new SparseIntArray();
Expand Down
93 changes: 46 additions & 47 deletions catalog/java/io/material/catalog/transition/TransitionFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import android.os.Build.VERSION;
import android.os.Build.VERSION_CODES;
import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi;
import androidx.fragment.app.Fragment;
import dagger.Provides;
import dagger.android.ContributesAndroidInjector;
Expand All @@ -32,22 +33,13 @@
import io.material.catalog.feature.DemoLandingFragment;
import io.material.catalog.feature.FeatureDemo;
import io.material.catalog.transition.hero.TransitionMusicDemoActivity;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/** A landing fragment that links to Transition demos for the Catalog app. */
public class TransitionFragment extends DemoLandingFragment {

@Override
public boolean isRestricted() {
return VERSION.SDK_INT < VERSION_CODES.LOLLIPOP;
}

@Override
public int getRestrictedMessageId() {
return R.string.cat_transition_restricted_message;
}

@Override
public int getTitleResId() {
return R.string.cat_transition_title;
Expand All @@ -70,45 +62,52 @@ public Intent createActivityIntent() {

@Override
public List<Demo> getAdditionalDemos() {
return Arrays.asList(
new Demo(R.string.cat_transition_container_transform_activity_title) {
@Override
public Intent createActivityIntent() {
return getTransitionContainerTransformStartDemoActivity();
}
},
new Demo(R.string.cat_transition_container_transform_fragment_title) {
@Override
public Fragment createFragment() {
return getTransitionContainerTransformDemoFragment();
}
},
new Demo(R.string.cat_transition_container_transform_view_title) {
@Override
public Fragment createFragment() {
return new TransitionContainerTransformViewDemoFragment();
}
},
new Demo(R.string.cat_transition_shared_axis_title) {
@Override
public Fragment createFragment() {
return new TransitionSharedAxisDemoFragment();
}
},
new Demo(R.string.cat_transition_fade_through_title) {
@Override
public Fragment createFragment() {
return new TransitionFadeThroughDemoFragment();
}
},
new Demo(R.string.cat_transition_fade_title) {
@Override
public Fragment createFragment() {
return new TransitionFadeDemoFragment();
}
});
List<Demo> demos = new ArrayList<>();
if (VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP) {
demos.add(
new Demo(R.string.cat_transition_container_transform_activity_title) {
@Override
public Intent createActivityIntent() {
return getTransitionContainerTransformStartDemoActivity();
}
});
}
demos.addAll(
Arrays.asList(
new Demo(R.string.cat_transition_container_transform_fragment_title) {
@Override
public Fragment createFragment() {
return getTransitionContainerTransformDemoFragment();
}
},
new Demo(R.string.cat_transition_container_transform_view_title) {
@Override
public Fragment createFragment() {
return new TransitionContainerTransformViewDemoFragment();
}
},
new Demo(R.string.cat_transition_shared_axis_title) {
@Override
public Fragment createFragment() {
return new TransitionSharedAxisDemoFragment();
}
},
new Demo(R.string.cat_transition_fade_through_title) {
@Override
public Fragment createFragment() {
return new TransitionFadeThroughDemoFragment();
}
},
new Demo(R.string.cat_transition_fade_title) {
@Override
public Fragment createFragment() {
return new TransitionFadeDemoFragment();
}
}));
return demos;
}

@RequiresApi(VERSION_CODES.LOLLIPOP)
@NonNull
protected Intent getTransitionContainerTransformStartDemoActivity() {
return new Intent(getContext(), TransitionContainerTransformStartDemoActivity.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@

import io.material.catalog.R;

import android.annotation.TargetApi;
import android.os.Build.VERSION_CODES;
import android.os.Bundle;
import androidx.annotation.LayoutRes;
import androidx.annotation.NonNull;
Expand All @@ -36,7 +34,6 @@
import io.material.catalog.feature.OnBackPressedHandler;

/** A fragment that displays the Shared Axis Transition demo for the Catalog app. */
@TargetApi(VERSION_CODES.LOLLIPOP)
public class TransitionSharedAxisDemoFragment extends DemoFragment implements OnBackPressedHandler {

private static final int LAYOUT_RES_ID_START = R.layout.cat_transition_shared_axis_start_fragment;
Expand Down
Loading

0 comments on commit cd36c2f

Please sign in to comment.