From 97c4ac68d94835fe002e5e2428f471dae3038ca3 Mon Sep 17 00:00:00 2001 From: Makhorin Date: Mon, 13 Mar 2023 00:36:02 +0300 Subject: [PATCH] Replace magic numbers with constants and move them to BlobDrawable. --- .../org/telegram/ui/Cells/GroupCallUserCell.java | 6 +++--- .../org/telegram/ui/Components/BlobDrawable.java | 7 +++++++ .../ui/Components/ChatActivityEnterView.java | 12 ++++++------ .../ui/Components/GroupCallFullscreenAdapter.java | 6 +++--- .../main/java/org/telegram/ui/GroupCallActivity.java | 4 ++-- 5 files changed, 21 insertions(+), 14 deletions(-) diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Cells/GroupCallUserCell.java b/TMessagesProj/src/main/java/org/telegram/ui/Cells/GroupCallUserCell.java index c03306060..96d88b944 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/Cells/GroupCallUserCell.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/Cells/GroupCallUserCell.java @@ -952,8 +952,8 @@ public class GroupCallUserCell extends FrameLayout { blobDrawable2.maxRadius = maxRadius; blobDrawable.generateBlob(); blobDrawable2.generateBlob(); - blobDrawable.paint.setColor(ColorUtils.setAlphaComponent(Theme.getColor(Theme.key_voipgroup_speakingText), 76)); - blobDrawable2.paint.setColor(ColorUtils.setAlphaComponent(Theme.getColor(Theme.key_voipgroup_speakingText), 76)); + blobDrawable.paint.setColor(ColorUtils.setAlphaComponent(Theme.getColor(Theme.key_voipgroup_speakingText), BlobDrawable.ALPHA_2)); + blobDrawable2.paint.setColor(ColorUtils.setAlphaComponent(Theme.getColor(Theme.key_voipgroup_speakingText), BlobDrawable.ALPHA_2)); } public void update() { @@ -1011,7 +1011,7 @@ public class GroupCallUserCell extends FrameLayout { if (invalidateColor) { int color = ColorUtils.blendARGB(Theme.getColor(Theme.key_voipgroup_speakingText), isMuted == 2 ? Theme.getColor(Theme.key_voipgroup_mutedByAdminIcon) : Theme.getColor(Theme.key_voipgroup_listeningText), progressToMuted); - blobDrawable.paint.setColor(ColorUtils.setAlphaComponent(color, 76)); + blobDrawable.paint.setColor(ColorUtils.setAlphaComponent(color, BlobDrawable.ALPHA_2)); } } diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Components/BlobDrawable.java b/TMessagesProj/src/main/java/org/telegram/ui/Components/BlobDrawable.java index 789d0165e..e95a8a546 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/Components/BlobDrawable.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/Components/BlobDrawable.java @@ -34,6 +34,13 @@ public class BlobDrawable { public static float LIGHT_GRADIENT_SIZE = 0.5f; + public static int MAX_AMPLITUDE = 1800; + + public static float ANIMATION_SPEED = 0.55f; + + public static int ALPHA_1 = 76; + public static int ALPHA_2 = 38; + public float minRadius; public float maxRadius; diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Components/ChatActivityEnterView.java b/TMessagesProj/src/main/java/org/telegram/ui/Components/ChatActivityEnterView.java index 01e76a397..9ab1ad9af 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/Components/ChatActivityEnterView.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/Components/ChatActivityEnterView.java @@ -1002,11 +1002,11 @@ public class ChatActivityEnterView extends BlurredFrameLayout implements Notific } public void setAmplitude(double value) { - bigWaveDrawable.setValue((float) (Math.min(1800, value) / 1800), true); - tinyWaveDrawable.setValue((float) (Math.min(1800, value) / 1800), false); + bigWaveDrawable.setValue((float) (Math.min(BlobDrawable.MAX_AMPLITUDE, value) / BlobDrawable.MAX_AMPLITUDE), true); + tinyWaveDrawable.setValue((float) (Math.min(BlobDrawable.MAX_AMPLITUDE, value) / BlobDrawable.MAX_AMPLITUDE), false); - animateToAmplitude = (float) (Math.min(1800, value) / 1800); - animateAmplitudeDiff = (animateToAmplitude - amplitude) / (100f + 500.0f * 0.55f); + animateToAmplitude = (float) (Math.min(BlobDrawable.MAX_AMPLITUDE, value) / BlobDrawable.MAX_AMPLITUDE); + animateAmplitudeDiff = (animateToAmplitude - amplitude) / (100f + 500.0f * BlobDrawable.ANIMATION_SPEED); invalidate(); } @@ -1646,8 +1646,8 @@ public class ChatActivityEnterView extends BlurredFrameLayout implements Notific public void updateColors() { paint.setColor(getThemedColor(Theme.key_chat_messagePanelVoiceBackground)); - tinyWaveDrawable.paint.setColor(ColorUtils.setAlphaComponent(getThemedColor(Theme.key_chat_messagePanelVoiceBackground), 38)); - bigWaveDrawable.paint.setColor(ColorUtils.setAlphaComponent(getThemedColor(Theme.key_chat_messagePanelVoiceBackground), 76)); + tinyWaveDrawable.paint.setColor(ColorUtils.setAlphaComponent(getThemedColor(Theme.key_chat_messagePanelVoiceBackground), BlobDrawable.ALPHA_2)); + bigWaveDrawable.paint.setColor(ColorUtils.setAlphaComponent(getThemedColor(Theme.key_chat_messagePanelVoiceBackground), BlobDrawable.ALPHA_1)); tooltipPaint.setColor(getThemedColor(Theme.key_chat_gifSaveHintText)); tooltipBackground = Theme.createRoundRectDrawable(AndroidUtilities.dp(5), getThemedColor(Theme.key_chat_gifSaveHintBackground)); tooltipBackgroundArrow.setColorFilter(new PorterDuffColorFilter(getThemedColor(Theme.key_chat_gifSaveHintBackground), PorterDuff.Mode.MULTIPLY)); diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Components/GroupCallFullscreenAdapter.java b/TMessagesProj/src/main/java/org/telegram/ui/Components/GroupCallFullscreenAdapter.java index 682b59483..63ea2525c 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/Components/GroupCallFullscreenAdapter.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/Components/GroupCallFullscreenAdapter.java @@ -509,7 +509,7 @@ public class GroupCallFullscreenAdapter extends RecyclerListView.SelectionAdapte muteButton.setColorFilter(new PorterDuffColorFilter(newColor, PorterDuff.Mode.MULTIPLY)); textPaint.setColor(lastColor); selectionPaint.setColor(newWavesColor); - avatarWavesDrawable.setColor(ColorUtils.setAlphaComponent(newWavesColor, 76)); + avatarWavesDrawable.setColor(ColorUtils.setAlphaComponent(newWavesColor, BlobDrawable.ALPHA_2)); invalidate(); } else { int colorFrom = lastColor; @@ -521,7 +521,7 @@ public class GroupCallFullscreenAdapter extends RecyclerListView.SelectionAdapte muteButton.setColorFilter(new PorterDuffColorFilter(lastColor, PorterDuff.Mode.MULTIPLY)); textPaint.setColor(lastColor); selectionPaint.setColor(lastWavesColor); - avatarWavesDrawable.setColor(ColorUtils.setAlphaComponent(lastWavesColor, 76)); + avatarWavesDrawable.setColor(ColorUtils.setAlphaComponent(lastWavesColor, BlobDrawable.ALPHA_2)); invalidate(); }); colorAnimator.addListener(new AnimatorListenerAdapter() { @@ -532,7 +532,7 @@ public class GroupCallFullscreenAdapter extends RecyclerListView.SelectionAdapte muteButton.setColorFilter(new PorterDuffColorFilter(lastColor, PorterDuff.Mode.MULTIPLY)); textPaint.setColor(lastColor); selectionPaint.setColor(lastWavesColor); - avatarWavesDrawable.setColor(ColorUtils.setAlphaComponent(lastWavesColor, 76)); + avatarWavesDrawable.setColor(ColorUtils.setAlphaComponent(lastWavesColor, BlobDrawable.ALPHA_2)); } }); colorAnimator.start(); diff --git a/TMessagesProj/src/main/java/org/telegram/ui/GroupCallActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/GroupCallActivity.java index d944967d8..9627dc1f5 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/GroupCallActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/GroupCallActivity.java @@ -4065,8 +4065,8 @@ public class GroupCallActivity extends BottomSheet implements NotificationCenter bigWaveDrawable.maxRadius = AndroidUtilities.dp(75); bigWaveDrawable.generateBlob(); - tinyWaveDrawable.paint.setColor(ColorUtils.setAlphaComponent(Theme.getColor(Theme.key_voipgroup_unmuteButton), 38)); - bigWaveDrawable.paint.setColor(ColorUtils.setAlphaComponent(Theme.getColor(Theme.key_voipgroup_unmuteButton),76)); + tinyWaveDrawable.paint.setColor(ColorUtils.setAlphaComponent(Theme.getColor(Theme.key_voipgroup_unmuteButton), BlobDrawable.ALPHA_2)); + bigWaveDrawable.paint.setColor(ColorUtils.setAlphaComponent(Theme.getColor(Theme.key_voipgroup_unmuteButton),BlobDrawable.ALPHA_1)); soundButton = new VoIPToggleButton(context); soundButton.setCheckable(true);