use of android.transition.TransitionValues in project Telegram-FOSS by Telegram-FOSS-Team.
the class StickersAlert method loadStickerSet.
private void loadStickerSet() {
if (inputStickerSet != null) {
final MediaDataController mediaDataController = MediaDataController.getInstance(currentAccount);
if (stickerSet == null && inputStickerSet.short_name != null) {
stickerSet = mediaDataController.getStickerSetByName(inputStickerSet.short_name);
}
if (stickerSet == null) {
stickerSet = mediaDataController.getStickerSetById(inputStickerSet.id);
}
if (stickerSet == null) {
TLRPC.TL_messages_getStickerSet req = new TLRPC.TL_messages_getStickerSet();
req.stickerset = inputStickerSet;
ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> {
reqId = 0;
if (error == null) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
Transition addTarget = new Transition() {
@Override
public void captureStartValues(TransitionValues transitionValues) {
transitionValues.values.put("start", true);
transitionValues.values.put("offset", containerView.getTop() + scrollOffsetY);
}
@Override
public void captureEndValues(TransitionValues transitionValues) {
transitionValues.values.put("start", false);
transitionValues.values.put("offset", containerView.getTop() + scrollOffsetY);
}
@Override
public Animator createAnimator(ViewGroup sceneRoot, TransitionValues startValues, TransitionValues endValues) {
int scrollOffsetY = StickersAlert.this.scrollOffsetY;
int startValue = (int) startValues.values.get("offset") - (int) endValues.values.get("offset");
final ValueAnimator animator = ValueAnimator.ofFloat(0f, 1f);
animator.setDuration(250);
animator.addUpdateListener(a -> {
float fraction = a.getAnimatedFraction();
gridView.setAlpha(fraction);
titleTextView.setAlpha(fraction);
if (startValue != 0) {
int value = (int) (startValue * (1f - fraction));
setScrollOffsetY(scrollOffsetY + value);
gridView.setTranslationY(value);
}
});
return animator;
}
};
addTarget.addTarget(containerView);
TransitionManager.beginDelayedTransition(container, addTarget);
}
optionsButton.setVisibility(View.VISIBLE);
stickerSet = (TLRPC.TL_messages_stickerSet) response;
showEmoji = !stickerSet.set.masks;
mediaDataController.preloadStickerSetThumb(stickerSet);
updateSendButton();
updateFields();
adapter.notifyDataSetChanged();
} else {
Toast.makeText(getContext(), LocaleController.getString("AddStickersNotFound", R.string.AddStickersNotFound), Toast.LENGTH_SHORT).show();
dismiss();
}
}));
} else {
if (adapter != null) {
updateSendButton();
updateFields();
adapter.notifyDataSetChanged();
}
mediaDataController.preloadStickerSetThumb(stickerSet);
}
}
if (stickerSet != null) {
showEmoji = !stickerSet.set.masks;
}
}
use of android.transition.TransitionValues in project Telegram-FOSS by Telegram-FOSS-Team.
the class ActionBar method beginDelayedTransition.
public void beginDelayedTransition() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
TransitionSet transitionSet = new TransitionSet();
transitionSet.setOrdering(TransitionSet.ORDERING_TOGETHER);
transitionSet.addTransition(new Fade());
transitionSet.addTransition(new ChangeBounds() {
public void captureStartValues(TransitionValues transitionValues) {
super.captureStartValues(transitionValues);
if (transitionValues.view instanceof SimpleTextView) {
float textSize = ((SimpleTextView) transitionValues.view).getTextPaint().getTextSize();
transitionValues.values.put("text_size", textSize);
}
}
public void captureEndValues(TransitionValues transitionValues) {
super.captureEndValues(transitionValues);
if (transitionValues.view instanceof SimpleTextView) {
float textSize = ((SimpleTextView) transitionValues.view).getTextPaint().getTextSize();
transitionValues.values.put("text_size", textSize);
}
}
@Override
public Animator createAnimator(ViewGroup sceneRoot, TransitionValues startValues, TransitionValues endValues) {
if (startValues != null && startValues.view instanceof SimpleTextView) {
AnimatorSet animatorSet = new AnimatorSet();
if (startValues != null && endValues != null) {
Animator animator = super.createAnimator(sceneRoot, startValues, endValues);
float s = (float) startValues.values.get("text_size") / (float) endValues.values.get("text_size");
startValues.view.setScaleX(s);
startValues.view.setScaleY(s);
if (animator != null) {
animatorSet.playTogether(animator);
}
}
animatorSet.playTogether(ObjectAnimator.ofFloat(startValues.view, SCALE_X, 1f));
animatorSet.playTogether(ObjectAnimator.ofFloat(startValues.view, SCALE_Y, 1f));
animatorSet.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationStart(Animator animation) {
super.onAnimationStart(animation);
startValues.view.setLayerType(LAYER_TYPE_HARDWARE, null);
}
@Override
public void onAnimationEnd(Animator animation) {
super.onAnimationEnd(animation);
startValues.view.setLayerType(LAYER_TYPE_NONE, null);
}
});
return animatorSet;
} else {
return super.createAnimator(sceneRoot, startValues, endValues);
}
}
});
centerScale = false;
transitionSet.setDuration(220);
transitionSet.setInterpolator(CubicBezierInterpolator.DEFAULT);
TransitionManager.beginDelayedTransition(this, transitionSet);
}
}
use of android.transition.TransitionValues in project Telegram-FOSS by Telegram-FOSS-Team.
the class PhotoViewer method setCurrentCaption.
private void setCurrentCaption(MessageObject messageObject, final CharSequence caption, boolean animated) {
if (needCaptionLayout) {
if (captionTextViewSwitcher.getParent() != pickerView) {
if (captionContainer != null) {
captionContainer.removeView(captionTextViewSwitcher);
}
captionTextViewSwitcher.setMeasureAllChildren(false);
pickerView.addView(captionTextViewSwitcher, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.BOTTOM | Gravity.LEFT, 0, 0, 76, 48));
}
} else {
if (captionScrollView == null) {
captionScrollView = new CaptionScrollView(containerView.getContext());
captionContainer = new FrameLayout(containerView.getContext());
captionContainer.setClipChildren(false);
captionScrollView.addView(captionContainer, new ViewGroup.LayoutParams(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
containerView.addView(captionScrollView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.BOTTOM));
}
if (captionTextViewSwitcher.getParent() != captionContainer) {
pickerView.removeView(captionTextViewSwitcher);
captionTextViewSwitcher.setMeasureAllChildren(true);
captionContainer.addView(captionTextViewSwitcher, LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT);
videoPreviewFrame.bringToFront();
}
}
final boolean isCaptionEmpty = TextUtils.isEmpty(caption);
final boolean isCurrentCaptionEmpty = TextUtils.isEmpty(captionTextViewSwitcher.getCurrentView().getText());
TextView captionTextView = animated ? captionTextViewSwitcher.getNextView() : captionTextViewSwitcher.getCurrentView();
if (isCurrentVideo) {
if (captionTextView.getMaxLines() != 1) {
captionTextViewSwitcher.getCurrentView().setMaxLines(1);
captionTextViewSwitcher.getNextView().setMaxLines(1);
captionTextViewSwitcher.getCurrentView().setSingleLine(true);
captionTextViewSwitcher.getNextView().setSingleLine(true);
captionTextViewSwitcher.getCurrentView().setEllipsize(TextUtils.TruncateAt.END);
captionTextViewSwitcher.getNextView().setEllipsize(TextUtils.TruncateAt.END);
}
} else {
final int maxLines = captionTextView.getMaxLines();
if (maxLines == 1) {
captionTextViewSwitcher.getCurrentView().setSingleLine(false);
captionTextViewSwitcher.getNextView().setSingleLine(false);
}
final int newCount;
if (needCaptionLayout) {
newCount = AndroidUtilities.displaySize.x > AndroidUtilities.displaySize.y ? 5 : 10;
} else {
newCount = Integer.MAX_VALUE;
}
if (maxLines != newCount) {
captionTextViewSwitcher.getCurrentView().setMaxLines(newCount);
captionTextViewSwitcher.getNextView().setMaxLines(newCount);
captionTextViewSwitcher.getCurrentView().setEllipsize(null);
captionTextViewSwitcher.getNextView().setEllipsize(null);
}
}
captionTextView.setScrollX(0);
dontChangeCaptionPosition = !needCaptionLayout && animated && isCaptionEmpty;
boolean withTransition = false;
if (!needCaptionLayout) {
captionScrollView.dontChangeTopMargin = false;
}
if (animated && Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
withTransition = true;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
TransitionManager.endTransitions(needCaptionLayout ? pickerView : captionScrollView);
}
if (needCaptionLayout) {
final TransitionSet transitionSet = new TransitionSet();
transitionSet.setOrdering(TransitionSet.ORDERING_TOGETHER);
transitionSet.addTransition(new ChangeBounds());
transitionSet.addTransition(new Fade(Fade.OUT));
transitionSet.addTransition(new Fade(Fade.IN));
transitionSet.setDuration(200);
TransitionManager.beginDelayedTransition(pickerView, transitionSet);
} else {
final TransitionSet transition = new TransitionSet().addTransition(new Fade(Fade.OUT) {
@Override
public Animator onDisappear(ViewGroup sceneRoot, View view, TransitionValues startValues, TransitionValues endValues) {
final Animator animator = super.onDisappear(sceneRoot, view, startValues, endValues);
if (!isCurrentCaptionEmpty && isCaptionEmpty && view == captionTextViewSwitcher) {
animator.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
captionScrollView.setVisibility(View.INVISIBLE);
captionScrollView.backgroundAlpha = 1f;
}
});
((ObjectAnimator) animator).addUpdateListener(animation -> {
captionScrollView.backgroundAlpha = (float) animation.getAnimatedValue();
captionScrollView.invalidate();
});
}
return animator;
}
}).addTransition(new Fade(Fade.IN) {
@Override
public Animator onAppear(ViewGroup sceneRoot, View view, TransitionValues startValues, TransitionValues endValues) {
final Animator animator = super.onAppear(sceneRoot, view, startValues, endValues);
if (isCurrentCaptionEmpty && !isCaptionEmpty && view == captionTextViewSwitcher) {
animator.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
captionScrollView.backgroundAlpha = 1f;
}
});
((ObjectAnimator) animator).addUpdateListener(animation -> {
captionScrollView.backgroundAlpha = (float) animation.getAnimatedValue();
captionScrollView.invalidate();
});
}
return animator;
}
}).setDuration(200);
if (!isCurrentCaptionEmpty) {
captionScrollView.dontChangeTopMargin = true;
transition.addTransition(new Transition() {
@Override
public void captureStartValues(TransitionValues transitionValues) {
if (transitionValues.view == captionScrollView) {
transitionValues.values.put("scrollY", captionScrollView.getScrollY());
}
}
@Override
public void captureEndValues(TransitionValues transitionValues) {
if (transitionValues.view == captionTextViewSwitcher) {
transitionValues.values.put("translationY", captionScrollView.getPendingMarginTopDiff());
}
}
@Override
public Animator createAnimator(ViewGroup sceneRoot, TransitionValues startValues, TransitionValues endValues) {
if (startValues.view == captionScrollView) {
final ValueAnimator animator = ValueAnimator.ofInt((Integer) startValues.values.get("scrollY"), 0);
animator.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
captionTextViewSwitcher.getNextView().setText(null);
captionScrollView.applyPendingTopMargin();
}
@Override
public void onAnimationStart(Animator animation) {
captionScrollView.stopScrolling();
}
});
animator.addUpdateListener(a -> captionScrollView.scrollTo(0, (Integer) a.getAnimatedValue()));
return animator;
} else if (endValues.view == captionTextViewSwitcher) {
final int endValue = (int) endValues.values.get("translationY");
if (endValue != 0) {
final ObjectAnimator animator = ObjectAnimator.ofFloat(captionTextViewSwitcher, View.TRANSLATION_Y, 0, endValue);
animator.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
captionTextViewSwitcher.setTranslationY(0);
}
});
return animator;
}
}
return null;
}
});
}
if (isCurrentCaptionEmpty && !isCaptionEmpty) {
transition.addTarget(captionTextViewSwitcher);
}
TransitionManager.beginDelayedTransition(captionScrollView, transition);
}
} else {
captionTextViewSwitcher.getCurrentView().setText(null);
if (captionScrollView != null) {
captionScrollView.scrollTo(0, 0);
}
}
if (!isCaptionEmpty) {
Theme.createChatResources(null, true);
CharSequence str;
if (messageObject != null && !messageObject.messageOwner.entities.isEmpty()) {
Spannable spannableString = SpannableString.valueOf(caption);
messageObject.addEntitiesToText(spannableString, true, false);
if (messageObject.isVideo()) {
MessageObject.addUrlsByPattern(messageObject.isOutOwner(), spannableString, false, 3, messageObject.getDuration(), false);
}
str = Emoji.replaceEmoji(spannableString, captionTextView.getPaint().getFontMetricsInt(), AndroidUtilities.dp(20), false);
} else {
str = Emoji.replaceEmoji(new SpannableStringBuilder(caption), captionTextView.getPaint().getFontMetricsInt(), AndroidUtilities.dp(20), false);
}
captionTextViewSwitcher.setTag(str);
try {
captionTextViewSwitcher.setText(str, animated);
if (captionScrollView != null) {
captionScrollView.updateTopMargin();
}
} catch (Exception e) {
FileLog.e(e);
}
captionTextView.setScrollY(0);
captionTextView.setTextColor(0xffffffff);
boolean visible = isActionBarVisible && (bottomLayout.getVisibility() == View.VISIBLE || pickerView.getVisibility() == View.VISIBLE || pageBlocksAdapter != null);
captionTextViewSwitcher.setVisibility(visible ? View.VISIBLE : View.INVISIBLE);
} else {
if (needCaptionLayout) {
captionTextViewSwitcher.setText(LocaleController.getString("AddCaption", R.string.AddCaption), animated);
captionTextViewSwitcher.getCurrentView().setTextColor(0xb2ffffff);
captionTextViewSwitcher.setTag("empty");
captionTextViewSwitcher.setVisibility(View.VISIBLE);
} else {
captionTextViewSwitcher.setText(null, animated);
captionTextViewSwitcher.getCurrentView().setTextColor(0xffffffff);
captionTextViewSwitcher.setVisibility(View.INVISIBLE, !withTransition || isCurrentCaptionEmpty);
captionTextViewSwitcher.setTag(null);
}
}
}
Aggregations