Replace magic numbers with constants and move them to BlobDrawable.

This commit is contained in:
Makhorin 2023-03-13 00:36:02 +03:00
parent 3433c786e6
commit 97c4ac68d9
5 changed files with 21 additions and 14 deletions

View file

@ -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));
}
}

View file

@ -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;

View file

@ -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));

View file

@ -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();

View file

@ -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);