fix: chat enter view icons

This commit is contained in:
Next Alone 2022-08-20 00:43:46 +08:00 committed by xtaodada
parent 066bc64497
commit af5b218234
Signed by: xtaodada
GPG Key ID: 4CBB3F4FA8C85659
4 changed files with 104 additions and 175 deletions

View File

@ -1862,7 +1862,7 @@ public class ChatActivityEnterView extends BlurredFrameLayout implements Notific
frameLayout.setClipChildren(false);
textFieldContainer.addView(frameLayout, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.BOTTOM, 0, 0, 48, 0));
emojiButton = new ChatActivityEnterViewAnimatedIconView(context, this) {
emojiButton = new ChatActivityEnterViewAnimatedIconView(context) {
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
@ -3166,7 +3166,7 @@ public class ChatActivityEnterView extends BlurredFrameLayout implements Notific
if (recordCircle.isSendButtonVisible()) {
if (!hasRecordVideo || calledRecordRunnable) {
startedDraggingX = -1;
if (hasRecordVideo && isInVideoMode) {
if (hasRecordVideo && audioVideoButtonContainer.getTag() != null) {
delegate.needStartRecordVideo(1, true, 0);
} else {
if (recordingAudioVideo && isInScheduleMode()) {
@ -3177,6 +3177,7 @@ public class ChatActivityEnterView extends BlurredFrameLayout implements Notific
}
recordingAudioVideo = false;
updateRecordInterface(RECORD_STATE_SENDING);
}
return;
}
@ -3350,7 +3351,7 @@ public class ChatActivityEnterView extends BlurredFrameLayout implements Notific
});
}
audioVideoSendButton = new ChatActivityEnterViewAnimatedIconView(context, this);
audioVideoSendButton = new ChatActivityEnterViewAnimatedIconView(context);
audioVideoSendButton.setContentDescription(LocaleController.getString("AccDescrVoiceMessage", R.string.AccDescrVoiceMessage));
audioVideoSendButton.setFocusable(true);
audioVideoSendButton.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_YES);
@ -3855,10 +3856,10 @@ public class ChatActivityEnterView extends BlurredFrameLayout implements Notific
}
}
isInVideoMode = false;
audioVideoSendButton.setTag(null);
recordAudioVideoRunnable.run();
delegate.onSwitchRecordMode(isInVideoMode);
setRecordVideoButtonVisible(isInVideoMode, true);
delegate.onSwitchRecordMode(audioVideoSendButton.getTag() == null);
setRecordVideoButtonVisible(audioVideoSendButton.getTag() == null, true);
if (!NekoConfig.disableVibration.Bool()) {
performHapticFeedback(HapticFeedbackConstants.KEYBOARD_TAP);
}
@ -3887,10 +3888,10 @@ public class ChatActivityEnterView extends BlurredFrameLayout implements Notific
}
}
isInVideoMode = true;
audioVideoSendButton.setTag(1);
recordAudioVideoRunnable.run();
delegate.onSwitchRecordMode(isInVideoMode);
setRecordVideoButtonVisible(isInVideoMode, true);
delegate.onSwitchRecordMode(audioVideoSendButton.getTag() == null);
setRecordVideoButtonVisible(audioVideoSendButton.getTag() == null, true);
if (!NekoConfig.disableVibration.Bool()) {
performHapticFeedback(HapticFeedbackConstants.KEYBOARD_TAP);
}
@ -4404,6 +4405,8 @@ public class ChatActivityEnterView extends BlurredFrameLayout implements Notific
if (audioVideoSendButton == null) {
return;
}
// if (NekoConfig.useChatAttachMediaMenu.Bool()) visible = animated = false;
audioVideoSendButton.setTag(visible ? 1 : null);
isInVideoMode = visible;
@ -4416,10 +4419,7 @@ public class ChatActivityEnterView extends BlurredFrameLayout implements Notific
}
preferences.edit().putBoolean(isChannel ? "currentModeVideoChannel" : "currentModeVideo", visible).apply();
}
if (!NekoConfig.useChatAttachMediaMenu.Bool())
audioVideoSendButton.setState(isInVideoMode() ? ChatActivityEnterViewAnimatedIconView.State.VIDEO : ChatActivityEnterViewAnimatedIconView.State.VOICE, animated);
else
audioVideoSendButton.setState(ChatActivityEnterViewAnimatedIconView.State.MENU, animated);
audioVideoSendButton.setState(isInVideoMode() ? ChatActivityEnterViewAnimatedIconView.State.VIDEO : ChatActivityEnterViewAnimatedIconView.State.VOICE, animated);
audioVideoSendButton.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED);
}
@ -6649,8 +6649,7 @@ public class ChatActivityEnterView extends BlurredFrameLayout implements Notific
audioVideoSendButton.setScaleX(1f);
audioVideoSendButton.setScaleY(1f);
runningAnimationAudio.playTogether(ObjectAnimator.ofFloat(audioVideoSendButton, View.ALPHA, 1));
if (!NekoConfig.useChatAttachMediaMenu.Bool())
audioVideoSendButton.setState(isInVideoMode() ? ChatActivityEnterViewAnimatedIconView.State.VIDEO : ChatActivityEnterViewAnimatedIconView.State.VOICE, true);
audioVideoSendButton.setState(isInVideoMode() ? ChatActivityEnterViewAnimatedIconView.State.VIDEO : ChatActivityEnterViewAnimatedIconView.State.VOICE, true);
}
if (scheduledButton != null) {
runningAnimationAudio.playTogether(
@ -6757,8 +6756,7 @@ public class ChatActivityEnterView extends BlurredFrameLayout implements Notific
ObjectAnimator.ofFloat(audioVideoSendButton, View.SCALE_X, 1),
ObjectAnimator.ofFloat(audioVideoSendButton, View.SCALE_Y, 1)
);
if (!NekoConfig.useChatAttachMediaMenu.Bool())
audioVideoSendButton.setState(isInVideoMode() ? ChatActivityEnterViewAnimatedIconView.State.VIDEO : ChatActivityEnterViewAnimatedIconView.State.VOICE, true);
audioVideoSendButton.setState(isInVideoMode() ? ChatActivityEnterViewAnimatedIconView.State.VIDEO : ChatActivityEnterViewAnimatedIconView.State.VOICE, true);
}
if (botCommandsMenuButton != null) {
@ -6902,8 +6900,7 @@ public class ChatActivityEnterView extends BlurredFrameLayout implements Notific
iconsAnimator.playTogether(ObjectAnimator.ofFloat(audioVideoSendButton, View.ALPHA, 1));
iconsAnimator.playTogether(ObjectAnimator.ofFloat(audioVideoSendButton, View.SCALE_X, 1));
iconsAnimator.playTogether(ObjectAnimator.ofFloat(audioVideoSendButton, View.SCALE_Y, 1));
if (!NekoConfig.useChatAttachMediaMenu.Bool())
audioVideoSendButton.setState(isInVideoMode() ? ChatActivityEnterViewAnimatedIconView.State.VIDEO : ChatActivityEnterViewAnimatedIconView.State.VOICE, true);
audioVideoSendButton.setState(isInVideoMode() ? ChatActivityEnterViewAnimatedIconView.State.VIDEO : ChatActivityEnterViewAnimatedIconView.State.VOICE, true);
}
if (scheduledButton != null) {
iconsAnimator.playTogether(
@ -7001,8 +6998,7 @@ public class ChatActivityEnterView extends BlurredFrameLayout implements Notific
audioVideoSendButton.setScaleX(1f);
audioVideoSendButton.setScaleY(1f);
iconsAnimator.playTogether(ObjectAnimator.ofFloat(audioVideoSendButton, View.ALPHA, 1));
if (!NekoConfig.useChatAttachMediaMenu.Bool())
audioVideoSendButton.setState(isInVideoMode() ? ChatActivityEnterViewAnimatedIconView.State.VIDEO : ChatActivityEnterViewAnimatedIconView.State.VOICE, true);
audioVideoSendButton.setState(isInVideoMode() ? ChatActivityEnterViewAnimatedIconView.State.VIDEO : ChatActivityEnterViewAnimatedIconView.State.VOICE, true);
}
if (attachLayout != null) {
attachLayout.setTranslationX(0);
@ -9164,8 +9160,7 @@ public class ChatActivityEnterView extends BlurredFrameLayout implements Notific
}
boolean audio = (Boolean) args[1];
isInVideoMode = !audio;
if (!NekoConfig.useChatAttachMediaMenu.Bool())
audioVideoSendButton.setState(audio ? ChatActivityEnterViewAnimatedIconView.State.VOICE : ChatActivityEnterViewAnimatedIconView.State.VIDEO, true);
audioVideoSendButton.setState(audio ? ChatActivityEnterViewAnimatedIconView.State.VOICE : ChatActivityEnterViewAnimatedIconView.State.VIDEO, true);
if (!recordingAudioVideo) {
recordingAudioVideo = true;
updateRecordInterface(RECORD_STATE_ENTER);
@ -10269,7 +10264,7 @@ public class ChatActivityEnterView extends BlurredFrameLayout implements Notific
}
}
int getThemedColor(String key) {
private int getThemedColor(String key) {
Integer color = resourcesProvider != null ? resourcesProvider.getColor(key) : null;
return color != null ? color : Theme.getColor(key);
}

View File

@ -1,82 +1,36 @@
package org.telegram.ui.Components;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.ColorFilter;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffColorFilter;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.LayerDrawable;
import android.graphics.drawable.ScaleDrawable;
import android.media.Image;
import android.os.Build;
import android.util.Property;
import android.view.Gravity;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import androidx.annotation.Nullable;
import com.fasterxml.jackson.databind.annotation.JsonAppend;
import org.telegram.messenger.AndroidUtilities;
import org.telegram.messenger.R;
import org.telegram.ui.ActionBar.Theme;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
public class ChatActivityEnterViewAnimatedIconView extends FrameLayout {
public class ChatActivityEnterViewAnimatedIconView extends RLottieImageView {
private State currentState;
private AnimatorSet buttonsAnimation;
private final ImageView[] buttonViews = new ImageView[2];
private TransitState animatingState;
public ChatActivityEnterViewAnimatedIconView(Context context, ChatActivityEnterView parentActivity) {
super(context);
for (int a = 0; a < 2; a++) {
buttonViews[a] = new ImageView(context);
buttonViews[a].setColorFilter(new PorterDuffColorFilter(parentActivity.getThemedColor(Theme.key_chat_messagePanelIcons), PorterDuff.Mode.MULTIPLY));
buttonViews[a].setScaleType(ImageView.ScaleType.CENTER_INSIDE);
if (Build.VERSION.SDK_INT >= 21) {
buttonViews[a].setBackground(Theme.createSelectorDrawable(parentActivity.getThemedColor(Theme.key_listSelector)));
private Map<TransitState, RLottieDrawable> stateMap = new HashMap<TransitState, RLottieDrawable>() {
@Nullable
@Override
public RLottieDrawable get(@Nullable Object key) {
RLottieDrawable obj = super.get(key);
if (obj == null) {
TransitState state = (TransitState) key;
int res = state.resource;
return new RLottieDrawable(res, String.valueOf(res), AndroidUtilities.dp(32), AndroidUtilities.dp(32));
}
addView(buttonViews[a], LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.BOTTOM | Gravity.LEFT, 0, 0, 0, 0));
return obj;
}
buttonViews[0].setVisibility(VISIBLE);
buttonViews[1].setVisibility(GONE);
}
};
public void setColorFilter(ColorFilter cf) {
buttonViews[0].setColorFilter(cf);
buttonViews[1].setColorFilter(cf);
}
private static class PropertyAlpha extends Property<LayerDrawable, Integer> {
private final int index;
public PropertyAlpha(int index) {
super(Integer.class, "alpha");
this.index = index;
}
@Override
public void set(LayerDrawable object, Integer value) {
object.getDrawable(index).setAlpha(value);
}
@Override
public Integer get(LayerDrawable object) {
return object.getDrawable(index).getAlpha();
}
public ChatActivityEnterViewAnimatedIconView(Context context) {
super(context);
}
public void setState(State state, boolean animate) {
@ -85,98 +39,77 @@ public class ChatActivityEnterViewAnimatedIconView extends FrameLayout {
}
State fromState = currentState;
currentState = state;
if (!animate || fromState == null) {
buttonViews[0].setImageResource(currentState.resource);
if (!animate || fromState == null || getState(fromState, currentState) == null) {
RLottieDrawable drawable = stateMap.get(getAnyState(currentState));
drawable.stop();
drawable.setProgress(0, false);
setAnimation(drawable);
} else {
if (buttonsAnimation != null)
buttonsAnimation.cancel();
buttonViews[1].setVisibility(VISIBLE);
buttonViews[1].setImageResource(currentState.resource);
buttonViews[0].setAlpha(1.0f);
buttonViews[1].setAlpha(0.0f);
buttonsAnimation = new AnimatorSet();
buttonsAnimation.playTogether(
ObjectAnimator.ofFloat(buttonViews[0], View.SCALE_X, 0.1f),
ObjectAnimator.ofFloat(buttonViews[0], View.SCALE_Y, 0.1f),
ObjectAnimator.ofFloat(buttonViews[0], View.ALPHA, 0.0f),
ObjectAnimator.ofFloat(buttonViews[1], View.SCALE_X, 1.0f),
ObjectAnimator.ofFloat(buttonViews[1], View.SCALE_Y, 1.0f),
ObjectAnimator.ofFloat(buttonViews[1], View.ALPHA, 1.0f));
buttonsAnimation.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
if (animation.equals(buttonsAnimation)) {
buttonsAnimation = null;
ImageView temp = buttonViews[1];
buttonViews[1] = buttonViews[0];
buttonViews[0] = temp;
buttonViews[1].setVisibility(INVISIBLE);
buttonViews[1].setAlpha(0.0f);
buttonViews[1].setScaleX(0.1f);
buttonViews[1].setScaleY(0.1f);
}
}
});
buttonsAnimation.setDuration(200);
buttonsAnimation.start();
TransitState transitState = getState(fromState, currentState);
if (transitState == animatingState) {
return;
}
animatingState = transitState;
RLottieDrawable drawable = stateMap.get(transitState);
drawable.stop();
drawable.setProgress(0, false);
drawable.setAutoRepeat(0);
drawable.setOnAnimationEndListener(() -> animatingState = null);
setAnimation(drawable);
AndroidUtilities.runOnUIThread(drawable::start);
}
}
// private TransitState getAnyState(State from) {
// for (TransitState transitState : TransitState.values()) {
// if (transitState.firstState == from) {
// return transitState;
// }
// }
// return null;
// }
//
// private TransitState getState(State from, State to) {
// for (TransitState transitState : TransitState.values()) {
// if (transitState.firstState == from && transitState.secondState == to) {
// return transitState;
// }
// }
// return null;
// }
//
// private enum TransitState {
// VOICE_TO_VIDEO(State.VOICE, State.VIDEO, R.raw.voice_to_video),
// STICKER_TO_KEYBOARD(State.STICKER, State.KEYBOARD, R.raw.sticker_to_keyboard),
// SMILE_TO_KEYBOARD(State.SMILE, State.KEYBOARD, R.raw.smile_to_keyboard),
// VIDEO_TO_VOICE(State.VIDEO, State.VOICE, R.raw.video_to_voice),
// KEYBOARD_TO_STICKER(State.KEYBOARD, State.STICKER, R.raw.keyboard_to_sticker),
// KEYBOARD_TO_GIF(State.KEYBOARD, State.GIF, R.raw.keyboard_to_gif),
// KEYBOARD_TO_SMILE(State.KEYBOARD, State.SMILE, R.raw.keyboard_to_smile),
// GIF_TO_KEYBOARD(State.GIF, State.KEYBOARD, R.raw.gif_to_keyboard),
// GIF_TO_SMILE(State.GIF, State.SMILE, R.raw.gif_to_smile),
// SMILE_TO_GIF(State.SMILE, State.GIF, R.raw.smile_to_gif),
// SMILE_TO_STICKER(State.SMILE, State.STICKER, R.raw.smile_to_sticker),
// STICKER_TO_SMILE(State.STICKER, State.SMILE, R.raw.sticker_to_smile);
//
// final State firstState, secondState;
// final int resource;
//
// TransitState(State firstState, State secondState, int resource) {
// this.firstState = firstState;
// this.secondState = secondState;
// this.resource = resource;
// }
// }
private TransitState getAnyState(State from) {
for (TransitState transitState : TransitState.values()) {
if (transitState.firstState == from) {
return transitState;
}
}
return null;
}
public enum State {
VOICE(R.drawable.baseline_mic_24),
VIDEO(R.drawable.baseline_camera_alt_24),
STICKER(R.drawable.deproko_baseline_stickers_24),
KEYBOARD(R.drawable.baseline_keyboard_24),
SMILE(R.drawable.baseline_emoticon_outline_24),
GIF(R.drawable.deproko_baseline_gif_24),
MENU(R.drawable.ic_ab_other);
private TransitState getState(State from, State to) {
for (TransitState transitState : TransitState.values()) {
if (transitState.firstState == from && transitState.secondState == to) {
return transitState;
}
}
return null;
}
private enum TransitState {
VOICE_TO_VIDEO(State.VOICE, State.VIDEO, R.raw.voice_to_video),
STICKER_TO_KEYBOARD(State.STICKER, State.KEYBOARD, R.raw.sticker_to_keyboard),
SMILE_TO_KEYBOARD(State.SMILE, State.KEYBOARD, R.raw.smile_to_keyboard),
VIDEO_TO_VOICE(State.VIDEO, State.VOICE, R.raw.video_to_voice),
KEYBOARD_TO_STICKER(State.KEYBOARD, State.STICKER, R.raw.keyboard_to_sticker),
KEYBOARD_TO_GIF(State.KEYBOARD, State.GIF, R.raw.keyboard_to_gif),
KEYBOARD_TO_SMILE(State.KEYBOARD, State.SMILE, R.raw.keyboard_to_smile),
GIF_TO_KEYBOARD(State.GIF, State.KEYBOARD, R.raw.gif_to_keyboard),
GIF_TO_SMILE(State.GIF, State.SMILE, R.raw.gif_to_smile),
SMILE_TO_GIF(State.SMILE, State.GIF, R.raw.smile_to_gif),
SMILE_TO_STICKER(State.SMILE, State.STICKER, R.raw.smile_to_sticker),
STICKER_TO_SMILE(State.STICKER, State.SMILE, R.raw.sticker_to_smile);
final State firstState, secondState;
final int resource;
State(int resource) {
TransitState(State firstState, State secondState, int resource) {
this.firstState = firstState;
this.secondState = secondState;
this.resource = resource;
}
}
public enum State {
VOICE,
VIDEO,
STICKER,
KEYBOARD,
SMILE,
GIF
}
}

View File

@ -1366,7 +1366,7 @@ public class EmojiView extends FrameLayout implements NotificationCenter.Notific
// Theme.createEmojiIconSelectorDrawable(context, R.drawable.stickers_gifs_trending, getThemedColor(Theme.key_chat_messagePanelIcons), getThemedColor(Theme.key_chat_emojiPanelIconSelected)),
// };
stickerIcons = new Drawable[]{
stickerIcons = new Drawable[]{
Theme.createEmojiIconSelectorDrawable(context, R.drawable.msg_emoji_recent, getThemedColor(Theme.key_chat_emojiPanelIcon), getThemedColor(Theme.key_chat_emojiPanelIconSelected)),
Theme.createEmojiIconSelectorDrawable(context, R.drawable.emoji_tabs_faves, getThemedColor(Theme.key_chat_emojiPanelIcon), getThemedColor(Theme.key_chat_emojiPanelIconSelected)),
Theme.createEmojiIconSelectorDrawable(context, R.drawable.emoji_tabs_new3, getThemedColor(Theme.key_chat_emojiPanelIcon), getThemedColor(Theme.key_chat_emojiPanelIconSelected)),
@ -1983,7 +1983,7 @@ public class EmojiView extends FrameLayout implements NotificationCenter.Notific
}
}
});
stickersGridView.setPadding(0, AndroidUtilities.dp(4 + 36), 0, AndroidUtilities.dp(44));
stickersGridView.setPadding(0, AndroidUtilities.dp(4 + 48), 0, AndroidUtilities.dp(44));
stickersGridView.setClipToPadding(false);
Tab stickersTabHolder = new Tab();
@ -2112,7 +2112,7 @@ public class EmojiView extends FrameLayout implements NotificationCenter.Notific
canvas.clipRect(0, searchProgressOffset, getMeasuredWidth(), getMeasuredHeight());
}
paint.setColor(getThemedColor(Theme.key_actionBarDefaultSubmenuBackground));
canvas.drawRect(0, 0, getMeasuredWidth(), AndroidUtilities.dp(36) + stickersTab.getExpandedOffset(), paint);
canvas.drawRect(0, 0, getMeasuredWidth(), AndroidUtilities.dp(48) + stickersTab.getExpandedOffset(), paint);
super.dispatchDraw(canvas);
stickersTab.drawOverlays(canvas);
canvas.restore();
@ -2124,10 +2124,10 @@ public class EmojiView extends FrameLayout implements NotificationCenter.Notific
updateStickerTabsPosition();
}
};
stickersTabContainer.addView(stickersTab, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 36, Gravity.LEFT | Gravity.TOP));
stickersTabContainer.addView(stickersTab, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 48, Gravity.LEFT | Gravity.TOP));
parentView.addView(stickersTabContainer, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
} else {
stickersContainer.addView(stickersTab, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 36, Gravity.LEFT | Gravity.TOP));
stickersContainer.addView(stickersTab, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 48, Gravity.LEFT | Gravity.TOP));
}
updateStickerTabs();
stickersTab.setDelegate(page -> {

View File

@ -28,7 +28,8 @@ public class StickerTabView extends FrameLayout {
// public final static int SMALL_WIDTH = 52;
// public final static int SMALL_HEIGHT = 48;
public final static int IMAGE_SMALL_SIZE = 26;
public final static int IMAGE_SMALL_SIZE = 36;
private final static int EMOJI_SMALL_SIZE = 30;
public final static int IMAGE_ICON_SMALL_SIZE = 24;
public int type;
@ -60,7 +61,7 @@ public class StickerTabView extends FrameLayout {
imageView.setLayerNum(1);
imageView.setAspectFit(false);
imageView.setRoundRadius(AndroidUtilities.dp(6));
addView(imageView, LayoutHelper.createFrame(IMAGE_SMALL_SIZE, IMAGE_SMALL_SIZE, Gravity.CENTER));
addView(imageView, LayoutHelper.createFrame(EMOJI_SMALL_SIZE, EMOJI_SMALL_SIZE, Gravity.CENTER));
visibleView = imageView;
} else if (type == ICON_TYPE) {
iconView = new ImageView(context);