Skip to content

Instantly share code, notes, and snippets.

View Kvest's full-sized avatar

Roman Bielokon Kvest

  • Prague, Czech Republic
View GitHub Profile
@TargetApi(Build.VERSION_CODES.KITKAT)
public class TextColorTransition extends Transition {
private static final String PROPNAME_TEXT_COLOR = "kvest:textColorTransition:textColor";
private static final String[] TRANSITION_PROPERTIES = {PROPNAME_TEXT_COLOR};
public TextColorTransition() {
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public TextColorTransition(Context context, AttributeSet attrs) {
Transition transition = new TextColorTransition();
TransitionManager.beginDelayedTransition(root, transition);
textView.setTextColor(newColor);
<?xml version="1.0" encoding="utf-8"?>
<transitionSet xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:interpolator/accelerate_cubic"
android:duration="@integer/anim_duration_default">
<transition class="com.kvest.material_design_playground.transitions.TextColorTransition" />
<transition class="com.kvest.material_design_playground.transitions.RingViewTransition" />
<!--Others-->
<autoTransition/>
</transitionSet>
Intent = new Intent(...);
...
//Shared transitions available only from Lollipop
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
//grab properties for custom transitions
Bundle nameExtra = new Bundle();
TextColorTransition.addExtraProperties(nameView, nameExtra);
intent.putExtra(transitionName, nameExtra);
Bundle frameExtra = new Bundle();
public class RingViewTransition extends Transition {
....
public static void addExtraProperties(RingView view, Bundle extra) {
extra.putInt(PROPNAME_COLOR, view.getColor());
extra.putFloat(PROPNAME_INNER_RADIUS, view.getInnerCircleRadius());
extra.putFloat(PROPNAME_OUTER_RADIUS, view.getOuterCircleRadius());
}
}
public class TextColorTransition extends Transition {
....
public static void addExtraProperties(TextView view, Bundle extra) {
extra.putInt(PROPNAME_TEXT_COLOR, view.getCurrentTextColor());
}
}
setEnterSharedElementCallback(new SharedElementCallback() {
@Override
public void onSharedElementStart(List<String> sharedElementNames, List<View> sharedElements, List<View> sharedElementSnapshots) {
Intent intent = getIntent();
for (int i = 0; i < sharedElementNames.size(); i++) {
String name = sharedElementNames.get(i);
if (intent.hasExtra(name)) {
sharedElements.get(i).setTag(R.id.tag_transition_extra_properties, intent.getBundleExtra(name));
}
}
public class TextColorTransition extends Transition {
...
private void captureValues(@NonNull TransitionValues transitionValues) {
if (transitionValues.view instanceof TextView) {
Bundle extraData = (Bundle)transitionValues.view.getTag(R.id.tag_transition_extra_properties);
int color;
if (extraData != null && extraData.containsKey(PROPNAME_TEXT_COLOR)) {
color = extraData.getInt(PROPNAME_TEXT_COLOR);
} else {
public class RingViewTransition extends Transition {
...
private void captureValues(RingView view, TransitionValues transitionValues) {
Bundle extraData = (Bundle)transitionValues.view.getTag(R.id.tag_transition_extra_properties);
if (extraData != null) {
transitionValues.values.put(PROPNAME_COLOR,
extraData.getInt(PROPNAME_COLOR, view.getColor()));
transitionValues.values.put(PROPNAME_INNER_RADIUS,
extraData.getFloat(PROPNAME_INNER_RADIUS, view.getInnerCircleRadius()));
transitionValues.values.put(PROPNAME_OUTER_RADIUS,
@Kvest
Kvest / avd_bundle.xml
Created October 27, 2016 06:19 — forked from nickbutcher/avd_bundle.xml
An example of the Android xml bundle format for creating an AnimatedVectorDrawable. See https://plus.google.com/+NickButcher/posts/A8KKxnJdg4r
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright 2016 Google Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0