use of androidx.transition.Transition in project IITB-App by wncc.
the class Utils method updateSharedElementFragment.
public static void updateSharedElementFragment(final Fragment fragment, final Fragment currentFragment, Map<View, String> sharedElements) {
FragmentTransaction ft = currentFragment.getActivity().getSupportFragmentManager().beginTransaction();
Transition transition = new DetailsTransition();
/* Set up transitions */
fragment.setSharedElementEnterTransition(transition);
fragment.setEnterTransition(new Slide());
currentFragment.setExitTransition(new Fade());
fragment.setSharedElementReturnTransition(transition);
/* Set transition for parent in case it is a child */
if (currentFragment instanceof TransitionTargetChild) {
((TransitionTargetChild) currentFragment).getParent().setExitTransition(new Fade());
}
transition.addListener(new Transition.TransitionListener() {
@Override
public void onTransitionStart(Transition transition) {
}
@Override
public void onTransitionEnd(Transition transition) {
if (fragment instanceof TransitionTargetFragment) {
((TransitionTargetFragment) fragment).transitionEnd();
}
if (currentFragment instanceof TransitionTargetFragment) {
((TransitionTargetFragment) currentFragment).transitionEnd();
}
}
@Override
public void onTransitionCancel(Transition transition) {
}
@Override
public void onTransitionPause(Transition transition) {
}
@Override
public void onTransitionResume(Transition transition) {
}
});
/* Add all shared elements */
for (Map.Entry<View, String> entry : sharedElements.entrySet()) {
ft.addSharedElement(entry.getKey(), entry.getValue());
}
/* Update the fragment */
ft.replace(R.id.framelayout_for_fragment, fragment, getTag(fragment)).addToBackStack(getTag(fragment)).commit();
}
use of androidx.transition.Transition in project Signal-Android by signalapp.
the class WebRtcCallView method fadeInNewUiState.
private void fadeInNewUiState(boolean useSmallMargins, boolean showSmallHeader) {
Transition transition = new AutoTransition().setDuration(TRANSITION_DURATION_MILLIS);
TransitionManager.beginDelayedTransition(parent, transition);
ConstraintSet constraintSet = new ConstraintSet();
constraintSet.clone(parent);
for (View view : SetUtil.difference(allTimeVisibleViews, visibleViewSet)) {
constraintSet.setVisibility(view.getId(), ConstraintSet.GONE);
}
for (View view : visibleViewSet) {
constraintSet.setVisibility(view.getId(), ConstraintSet.VISIBLE);
if (adjustableMarginsSet.contains(view)) {
constraintSet.setMargin(view.getId(), ConstraintSet.END, ViewUtil.dpToPx(useSmallMargins ? SMALL_ONGOING_CALL_BUTTON_MARGIN_DP : LARGE_ONGOING_CALL_BUTTON_MARGIN_DP));
}
}
adjustParticipantsRecycler(constraintSet);
constraintSet.applyTo(parent);
if (showSmallHeader) {
smallHeaderConstraints.setVisibility(incomingRingStatus.getId(), visibleViewSet.contains(incomingRingStatus) ? View.VISIBLE : View.GONE);
smallHeaderConstraints.applyTo(toolbar);
} else {
largeHeaderConstraints.setVisibility(incomingRingStatus.getId(), visibleViewSet.contains(incomingRingStatus) ? View.VISIBLE : View.GONE);
largeHeaderConstraints.applyTo(toolbar);
}
}
use of androidx.transition.Transition in project Signal-Android by signalapp.
the class WebRtcCallView method fadeControls.
private void fadeControls(int visibility) {
controlsVisible = visibility == VISIBLE;
Transition transition = new AutoTransition().setOrdering(TransitionSet.ORDERING_TOGETHER).setDuration(TRANSITION_DURATION_MILLIS);
TransitionManager.endTransitions(parent);
if (controlsListener != null) {
if (controlsVisible) {
controlsListener.showSystemUI();
} else {
controlsListener.hideSystemUI();
}
}
TransitionManager.beginDelayedTransition(parent, transition);
ConstraintSet constraintSet = new ConstraintSet();
constraintSet.clone(parent);
for (View view : controlsToFade()) {
constraintSet.setVisibility(view.getId(), visibility);
}
adjustParticipantsRecycler(constraintSet);
constraintSet.applyTo(parent);
layoutParticipants();
}
use of androidx.transition.Transition in project Transitions-Everywhere by andkulikov.
the class ChangeText method createAnimator.
@Nullable
@Override
public Animator createAnimator(@NonNull ViewGroup sceneRoot, @Nullable TransitionValues startValues, @Nullable TransitionValues endValues) {
if (startValues == null || endValues == null || !(startValues.view instanceof TextView) || !(endValues.view instanceof TextView)) {
return null;
}
final TextView view = (TextView) endValues.view;
Map<String, Object> startVals = startValues.values;
Map<String, Object> endVals = endValues.values;
final CharSequence startText = startVals.get(PROPNAME_TEXT) != null ? (CharSequence) startVals.get(PROPNAME_TEXT) : "";
final CharSequence endText = endVals.get(PROPNAME_TEXT) != null ? (CharSequence) endVals.get(PROPNAME_TEXT) : "";
final int startSelectionStart, startSelectionEnd, endSelectionStart, endSelectionEnd;
if (view instanceof EditText) {
startSelectionStart = startVals.get(PROPNAME_TEXT_SELECTION_START) != null ? (Integer) startVals.get(PROPNAME_TEXT_SELECTION_START) : -1;
startSelectionEnd = startVals.get(PROPNAME_TEXT_SELECTION_END) != null ? (Integer) startVals.get(PROPNAME_TEXT_SELECTION_END) : startSelectionStart;
endSelectionStart = endVals.get(PROPNAME_TEXT_SELECTION_START) != null ? (Integer) endVals.get(PROPNAME_TEXT_SELECTION_START) : -1;
endSelectionEnd = endVals.get(PROPNAME_TEXT_SELECTION_END) != null ? (Integer) endVals.get(PROPNAME_TEXT_SELECTION_END) : endSelectionStart;
} else {
startSelectionStart = startSelectionEnd = endSelectionStart = endSelectionEnd = -1;
}
if (!startText.equals(endText)) {
final int startColor;
final int endColor;
if (mChangeBehavior != CHANGE_BEHAVIOR_IN) {
view.setText(startText);
if (view instanceof EditText) {
setSelection(((EditText) view), startSelectionStart, startSelectionEnd);
}
}
Animator anim;
if (mChangeBehavior == CHANGE_BEHAVIOR_KEEP) {
startColor = endColor = 0;
anim = ValueAnimator.ofFloat(0, 1);
anim.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
if (startText.equals(view.getText())) {
// Only set if it hasn't been changed since anim started
view.setText(endText);
if (view instanceof EditText) {
setSelection(((EditText) view), endSelectionStart, endSelectionEnd);
}
}
}
});
} else {
startColor = (Integer) startVals.get(PROPNAME_TEXT_COLOR);
endColor = (Integer) endVals.get(PROPNAME_TEXT_COLOR);
// Fade out start text
ValueAnimator outAnim = null, inAnim = null;
if (mChangeBehavior == CHANGE_BEHAVIOR_OUT_IN || mChangeBehavior == CHANGE_BEHAVIOR_OUT) {
outAnim = ValueAnimator.ofInt(Color.alpha(startColor), 0);
outAnim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(@NonNull ValueAnimator animation) {
int currAlpha = (Integer) animation.getAnimatedValue();
view.setTextColor(currAlpha << 24 | startColor & 0xff0000 | startColor & 0xff00 | startColor & 0xff);
}
});
outAnim.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
if (startText.equals(view.getText())) {
// Only set if it hasn't been changed since anim started
view.setText(endText);
if (view instanceof EditText) {
setSelection(((EditText) view), endSelectionStart, endSelectionEnd);
}
}
// restore opaque alpha and correct end color
view.setTextColor(endColor);
}
});
}
if (mChangeBehavior == CHANGE_BEHAVIOR_OUT_IN || mChangeBehavior == CHANGE_BEHAVIOR_IN) {
inAnim = ValueAnimator.ofInt(0, Color.alpha(endColor));
inAnim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(@NonNull ValueAnimator animation) {
int currAlpha = (Integer) animation.getAnimatedValue();
view.setTextColor(currAlpha << 24 | Color.red(endColor) << 16 | Color.green(endColor) << 8 | Color.blue(endColor));
}
});
inAnim.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationCancel(Animator animation) {
// restore opaque alpha and correct end color
view.setTextColor(endColor);
}
});
}
if (outAnim != null && inAnim != null) {
anim = new AnimatorSet();
((AnimatorSet) anim).playSequentially(outAnim, inAnim);
} else if (outAnim != null) {
anim = outAnim;
} else {
// Must be an in-only animation
anim = inAnim;
}
}
TransitionListener transitionListener = new TransitionListenerAdapter() {
int mPausedColor = 0;
@Override
public void onTransitionPause(@NonNull Transition transition) {
if (mChangeBehavior != CHANGE_BEHAVIOR_IN) {
view.setText(endText);
if (view instanceof EditText) {
setSelection(((EditText) view), endSelectionStart, endSelectionEnd);
}
}
if (mChangeBehavior > CHANGE_BEHAVIOR_KEEP) {
mPausedColor = view.getCurrentTextColor();
view.setTextColor(endColor);
}
}
@Override
public void onTransitionResume(@NonNull Transition transition) {
if (mChangeBehavior != CHANGE_BEHAVIOR_IN) {
view.setText(startText);
if (view instanceof EditText) {
setSelection(((EditText) view), startSelectionStart, startSelectionEnd);
}
}
if (mChangeBehavior > CHANGE_BEHAVIOR_KEEP) {
view.setTextColor(mPausedColor);
}
}
@Override
public void onTransitionEnd(@NonNull Transition transition) {
transition.removeListener(this);
}
};
addListener(transitionListener);
return anim;
}
return null;
}
use of androidx.transition.Transition in project Transitions-Everywhere by andkulikov.
the class InterpolatorDurationStartDelaySample method onCreateView.
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_interpolator, container, false);
final ViewGroup transitionsContainer = view.findViewById(R.id.transitions_container);
final View button = transitionsContainer.findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
boolean mToRightAnimation;
@Override
public void onClick(View v) {
mToRightAnimation = !mToRightAnimation;
Transition transition = new ChangeBounds();
transition.setDuration(mToRightAnimation ? 700 : 300);
transition.setInterpolator(mToRightAnimation ? new FastOutSlowInInterpolator() : new AccelerateInterpolator());
transition.setStartDelay(mToRightAnimation ? 0 : 500);
TransitionManager.beginDelayedTransition(transitionsContainer, transition);
FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) button.getLayoutParams();
params.gravity = mToRightAnimation ? (Gravity.RIGHT | Gravity.TOP) : (Gravity.LEFT | Gravity.TOP);
button.setLayoutParams(params);
}
});
return view;
}
Aggregations