v0.6.0: bubble for Android 0.6.0 — the house look on the Rabbit, and a stretchy pull-to-refresh that pops

Desktop: Signal vibes or travewave, chosen in Preferences → Appearance.
Rabbit: white on pure black, 22/28/32 sp text, outlined buttons and dim-edged
text boxes, and drawn icons instead of emoji (rabbit.html). Pulling the chat
list further once the search box shows stretches a bubble that pops at the
mark and starts the check, then a spinner until it's done.
This commit is contained in:
2026-11-08 19:39:58 -08:00
parent 357a2312ce
commit 4d0c15757d
13 changed files with 504 additions and 79 deletions
@@ -37,7 +37,7 @@ final class AttachBubble extends View {
}
static final int CAMERA = 0, PHOTO = 1, VOICE = 2;
private static final String[] GLYPHS = {"📷", "🎨", "🎤"};
private static final Glyph.Kind[] GLYPHS = {Glyph.Kind.CAMERA, Glyph.Kind.PHOTO, Glyph.Kind.MIC};
private static final String[] LABELS = {"Camera", "Photo", "Voice note"};
// Physics, in dp and seconds (tuned offline: fanned out by ~180 ms, at rest by ~500 ms).
@@ -101,7 +101,7 @@ final class AttachBubble extends View {
panel.setColor(Ui.PANEL);
scrim.setColor(0x33000000);
disk.setColor(Ui.INPUT);
glyph.setTextSize(34 * dp);
glyph.setColor(Ui.TEXT);
glyph.setTextAlign(Paint.Align.CENTER);
label.setTextSize(20 * dp);
label.setTextAlign(Paint.Align.CENTER);
@@ -334,7 +334,6 @@ final class AttachBubble extends View {
}
// The icons, then the clip drawn again on top so they come out from under it.
Paint.FontMetrics fm = glyph.getFontMetrics();
if (selected >= 0) ringT = Math.min(1, ringT + dt / 0.16f);
float pop = 1 - (1 - ringT) * (1 - ringT);
for (int i = 0; i < n; i++) {
@@ -355,7 +354,7 @@ final class AttachBubble extends View {
glyph.setAlpha((int) (255 * s));
c.save();
c.scale(s, s, x, y);
c.drawText(GLYPHS[i], x, y - (fm.ascent + fm.descent) / 2, glyph);
Glyph.draw(c, GLYPHS[i], x, y, 44 * dp, glyph);
c.restore();
}
int[] at = new int[2], me = new int[2];
@@ -182,18 +182,17 @@ public final class ChatActivity extends BaseActivity {
LinearLayout row = new LinearLayout(this);
row.setGravity(Gravity.BOTTOM);
attach = Ui.headerButton(this, "📎");
attach = Ui.headerButton(this, Glyph.Kind.ATTACH);
attach.setOnTouchListener((v, e) -> attachTouch(e));
input = new EditText(this);
input.setHint("Message");
input.setHintTextColor(Ui.FAINT);
input.setHintTextColor(Ui.MUTED);
input.setTextColor(Ui.TEXT);
input.setTextSize(TypedValue.COMPLEX_UNIT_SP, Ui.T_BODY);
input.setMaxLines(4);
input.setBackground(Ui.round(Ui.INPUT, Ui.dp(this, 36)));
input.setBackground(Ui.input(this, 36));
input.setPadding(Ui.dp(this, 24), Ui.dp(this, 14), Ui.dp(this, 24), Ui.dp(this, 14));
send = Ui.headerButton(this, "➤");
send.setTextColor(Ui.ACCENT);
send = Ui.headerButton(this, Glyph.Kind.SEND, Ui.ACCENT);
send.setOnClickListener(v -> submit());
row.addView(attach);
row.addView(input, new LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.WRAP_CONTENT, 1));
@@ -701,9 +700,9 @@ public final class ChatActivity extends BaseActivity {
if (showSender) sender.setText(Contacts.name(c, msg.sender));
body.setText(msg.body);
body.setVisibility(msg.body.isEmpty() ? GONE : VISIBLE);
String status = "pending".equals(msg.status) ? " 🕓" : "";
meta.setText(Ui.timeOfDay(c, msg.ts) + status);
meta.setText(Ui.timeOfDay(c, msg.ts));
meta.setTextColor(out ? 0xB3FFFFFF : Ui.MUTED);
Ui.glyph(meta, "pending".equals(msg.status) ? Glyph.Kind.CLOCK : null, true);
failed.setVisibility("failed".equals(msg.status) ? VISIBLE : GONE);
failed.setText("⚠ Not sent" + (msg.error != null ? ": " + msg.error : "") + " · tap to retry");
List<Reactions.Reaction> rs = reactions.get(msg.id);
@@ -727,14 +726,15 @@ public final class ChatActivity extends BaseActivity {
int bw = w > 0 ? Math.round(w * scale) : Ui.dp(c, 200), bh = h > 0 ? Math.round(h * scale) : Ui.dp(c, 200);
String mime = ref.optString("mime", "");
if (mime.startsWith("audio/")) {
TextView t = Ui.bold(Ui.text(c, ((id + "/" + index).equals(playing) ? "⏸" : "▶") + " Voice note",
Ui.T_SMALL, Ui.TEXT));
TextView t = Ui.bold(Ui.text(c, "Voice note", Ui.T_SMALL, Ui.TEXT));
Ui.glyph(t, (id + "/" + index).equals(playing) ? Glyph.Kind.PAUSE : Glyph.Kind.PLAY, false);
t.setPadding(0, Ui.dp(c, 10), Ui.dp(c, 20), Ui.dp(c, 10));
t.setOnClickListener(v -> toggleAudio(id, index));
return t;
}
if (!mime.isEmpty() && !mime.startsWith("image/")) {
TextView t = Ui.text(c, mime.startsWith("video/") ? "🎥 Video" : "📎 Attachment", Ui.T_SMALL, Ui.TEXT);
TextView t = Ui.text(c, mime.startsWith("video/") ? "Video" : "Attachment", Ui.T_SMALL, Ui.TEXT);
Ui.glyph(t, mime.startsWith("video/") ? Glyph.Kind.VIDEO : Glyph.Kind.FILE, false);
t.setPadding(0, Ui.dp(c, 6), 0, Ui.dp(c, 6));
return t;
}
@@ -0,0 +1,253 @@
package me.teafry.voipmessages;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.ColorFilter;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.PixelFormat;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.drawable.Drawable;
/**
* The app's icons, drawn with Canvas paths rather than emoji or a glyph
* font (rabbit.html#looks), on a 24-unit grid like the desktop's Icons.tsx,
* in a line about as heavy as the bars' text.
*/
final class Glyph extends Drawable {
enum Kind { COMPOSE, ARCHIVE, UNARCHIVE, GEAR, SEARCH, ATTACH, SEND, PERSON, GROUP, CAMERA, PHOTO, MIC, PLAY, PAUSE, CLOCK, CLOSE, CHECK, MAIL, VIDEO, FILE }
private final Kind kind;
private final Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
private final int size;
/** A glyph of {@code sizePx}, centred in whatever bounds it's given. */
Glyph(Kind kind, int color, int sizePx) {
this.kind = kind;
this.size = sizePx;
paint.setColor(color);
setBounds(0, 0, sizePx, sizePx);
}
static Glyph of(Context c, Kind kind, int color, float sizeDp) {
return new Glyph(kind, color, Ui.dp(c, sizeDp));
}
void setColor(int color) {
paint.setColor(color);
invalidateSelf();
}
@Override
public int getIntrinsicWidth() {
return size;
}
@Override
public int getIntrinsicHeight() {
return size;
}
@Override
public void draw(Canvas canvas) {
Rect b = getBounds();
draw(canvas, kind, b.exactCenterX(), b.exactCenterY(), Math.min(size, Math.min(b.width(), b.height())), paint);
}
@Override
public void setAlpha(int alpha) {
paint.setAlpha(alpha);
}
@Override
public void setColorFilter(ColorFilter cf) {
paint.setColorFilter(cf);
}
@Override
public int getOpacity() {
return PixelFormat.TRANSLUCENT;
}
/** Draws {@code kind} centred on (cx, cy), {@code size} px square, in the paint's colour. */
static void draw(Canvas c, Kind kind, float cx, float cy, float size, Paint p) {
float s = size / 24f;
c.save();
c.translate(cx - size / 2, cy - size / 2);
c.scale(s, s);
Paint line = new Paint(p);
line.setStyle(Paint.Style.STROKE);
line.setStrokeWidth(2.1f);
line.setStrokeCap(Paint.Cap.ROUND);
line.setStrokeJoin(Paint.Join.ROUND);
Paint fill = new Paint(p);
fill.setStyle(Paint.Style.FILL);
Path path = new Path();
switch (kind) {
case COMPOSE:
path.moveTo(12, 20);
path.lineTo(21, 20);
path.moveTo(16.5f, 3.5f);
path.lineTo(20.5f, 7.5f);
path.lineTo(7, 19);
path.lineTo(3, 20);
path.lineTo(4, 16);
path.close();
c.drawPath(path, line);
break;
case ARCHIVE:
case UNARCHIVE:
c.drawRect(3, 4, 21, 8, line);
path.moveTo(5, 8);
path.lineTo(5, 20);
path.lineTo(19, 20);
path.lineTo(19, 8);
if (kind == Kind.ARCHIVE) {
path.moveTo(10, 12);
path.lineTo(14, 12);
} else {
path.moveTo(12, 17);
path.lineTo(12, 11);
path.moveTo(9.5f, 13.5f);
path.lineTo(12, 11);
path.lineTo(14.5f, 13.5f);
}
c.drawPath(path, line);
break;
case GEAR:
c.drawCircle(12, 12, 3, line);
c.drawCircle(12, 12, 6.8f, line);
for (int i = 0; i < 8; i++) {
double a = Math.PI * i / 4;
c.drawLine(12 + (float) Math.cos(a) * 6.8f, 12 + (float) Math.sin(a) * 6.8f,
12 + (float) Math.cos(a) * 9.6f, 12 + (float) Math.sin(a) * 9.6f, line);
}
break;
case SEARCH:
c.drawCircle(11, 11, 7, line);
c.drawLine(16.5f, 16.5f, 20.5f, 20.5f, line);
break;
case ATTACH:
path.moveTo(16.5f, 7);
path.lineTo(16.5f, 15.5f);
path.arcTo(new RectF(7.5f, 11, 16.5f, 20), 0, 180);
path.lineTo(7.5f, 6);
path.arcTo(new RectF(7.5f, 3, 13.5f, 9), 180, 180);
path.lineTo(13.5f, 15.5f);
path.arcTo(new RectF(10.5f, 14, 13.5f, 17), 0, 180);
path.lineTo(10.5f, 7.5f);
c.drawPath(path, line);
break;
case SEND:
path.moveTo(4, 4);
path.lineTo(21, 12);
path.lineTo(4, 20);
path.lineTo(6.5f, 12);
path.close();
c.drawPath(path, fill);
break;
case PERSON:
c.drawCircle(12, 8, 4.2f, fill);
path.addArc(new RectF(4, 13.5f, 20, 29.5f), 180, 180);
path.close();
c.drawPath(path, fill);
break;
case GROUP:
c.drawCircle(9, 8.5f, 3.6f, fill);
c.drawCircle(16.5f, 9.5f, 3, fill);
path.addArc(new RectF(2, 14, 16, 28), 180, 180);
path.close();
path.addArc(new RectF(12, 14.5f, 23, 25.5f), 200, 160);
path.close();
c.drawPath(path, fill);
break;
case CAMERA:
path.moveTo(3, 8);
path.lineTo(7, 8);
path.lineTo(9, 5);
path.lineTo(15, 5);
path.lineTo(17, 8);
path.lineTo(21, 8);
path.lineTo(21, 19);
path.lineTo(3, 19);
path.close();
c.drawPath(path, line);
c.drawCircle(12, 13, 3.5f, line);
break;
case PHOTO:
c.drawRoundRect(3, 4, 21, 20, 2, 2, line);
c.drawCircle(8.5f, 9, 1.6f, fill);
path.moveTo(21, 15.5f);
path.lineTo(16, 11);
path.lineTo(6, 20);
c.drawPath(path, line);
break;
case MIC:
c.drawRoundRect(9, 3, 15, 14, 3, 3, line);
path.addArc(new RectF(5.5f, 5, 18.5f, 17.5f), 0, 180);
path.moveTo(12, 17.5f);
path.lineTo(12, 21);
c.drawPath(path, line);
break;
case PLAY:
path.moveTo(7, 4.5f);
path.lineTo(19, 12);
path.lineTo(7, 19.5f);
path.close();
c.drawPath(path, fill);
break;
case PAUSE:
c.drawRoundRect(6, 4.5f, 10, 19.5f, 1, 1, fill);
c.drawRoundRect(14, 4.5f, 18, 19.5f, 1, 1, fill);
break;
case CLOCK:
c.drawCircle(12, 12, 8.5f, line);
path.moveTo(12, 7);
path.lineTo(12, 12);
path.lineTo(15.5f, 14);
c.drawPath(path, line);
break;
case CLOSE:
c.drawLine(6, 6, 18, 18, line);
c.drawLine(18, 6, 6, 18, line);
break;
case CHECK:
path.moveTo(4.5f, 12.5f);
path.lineTo(9.5f, 17.5f);
path.lineTo(19.5f, 6.5f);
c.drawPath(path, line);
break;
case MAIL:
c.drawRoundRect(3, 5, 21, 19, 2, 2, line);
path.moveTo(3.5f, 6);
path.lineTo(12, 13);
path.lineTo(20.5f, 6);
c.drawPath(path, line);
break;
case VIDEO:
c.drawRoundRect(2.5f, 6, 16, 18, 2, 2, line);
path.moveTo(16, 10.5f);
path.lineTo(21.5f, 7.5f);
path.lineTo(21.5f, 16.5f);
path.lineTo(16, 13.5f);
c.drawPath(path, line);
break;
case FILE:
path.moveTo(14, 3);
path.lineTo(6, 3);
path.lineTo(6, 21);
path.lineTo(18, 21);
path.lineTo(18, 7);
path.close();
path.moveTo(14, 3);
path.lineTo(14, 7);
path.lineTo(18, 7);
c.drawPath(path, line);
break;
default:
break;
}
c.restore();
}
}
@@ -40,11 +40,11 @@ public final class InfoActivity extends BaseActivity {
name = new EditText(this);
name.setText(Store.get(this).getName(did, contact));
name.setHint(Contacts.title(this, contact, null));
name.setHintTextColor(Ui.FAINT);
name.setHintTextColor(Ui.MUTED);
name.setTextColor(Ui.TEXT);
name.setTextSize(TypedValue.COMPLEX_UNIT_SP, Ui.T_BODY);
name.setSingleLine();
name.setBackground(Ui.round(Ui.INPUT, Ui.dp(this, 16)));
name.setBackground(Ui.input(this, 16));
name.setPadding(Ui.dp(this, 20), Ui.dp(this, 14), Ui.dp(this, 20), Ui.dp(this, 14));
box.addView(name);
TextView note = Ui.text(this, "Only you see this name. It syncs with the desktop app.", Ui.T_TINY, Ui.FAINT);
@@ -56,15 +56,15 @@ public final class MainActivity extends BaseActivity {
header.setPadding(Ui.dp(this, 24), Ui.dp(this, 8), Ui.dp(this, 8), Ui.dp(this, 8));
title = Ui.bold(Ui.text(this, "Messages", Ui.T_TITLE, Ui.TEXT));
header.addView(title, new LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.WRAP_CONTENT, 1));
TextView compose = Ui.headerButton(this, "✎");
TextView compose = Ui.headerButton(this, Glyph.Kind.COMPOSE);
compose.setOnClickListener(v -> startActivity(new Intent(this, NewChatActivity.class)));
TextView archive = Ui.headerButton(this, "🗄");
TextView archive = Ui.headerButton(this, Glyph.Kind.ARCHIVE);
archive.setOnClickListener(v -> {
archived = !archived;
hideSearch = true;
changed();
});
TextView settings = Ui.headerButton(this, "⚙");
TextView settings = Ui.headerButton(this, Glyph.Kind.GEAR);
settings.setOnClickListener(v -> startActivity(new Intent(this, SettingsActivity.class)));
header.addView(compose);
header.addView(archive);
@@ -172,13 +172,13 @@ public final class MainActivity extends BaseActivity {
LinearLayout box = new LinearLayout(this);
box.setPadding(Ui.dp(this, 20), Ui.dp(this, 6), Ui.dp(this, 20), Ui.dp(this, 10));
search = new EditText(this);
search.setHint("🔍 Search");
search.setHintTextColor(Ui.FAINT);
search.setHint("Search");
search.setHintTextColor(Ui.MUTED);
search.setTextColor(Ui.TEXT);
search.setTextSize(TypedValue.COMPLEX_UNIT_SP, Ui.T_SMALL);
search.setSingleLine();
search.setImeOptions(EditorInfo.IME_ACTION_SEARCH | EditorInfo.IME_FLAG_NO_EXTRACT_UI);
search.setBackground(Ui.round(Ui.INPUT, Ui.dp(this, 30)));
search.setBackground(Ui.input(this, 30));
search.setPadding(Ui.dp(this, 24), Ui.dp(this, 12), Ui.dp(this, 24), Ui.dp(this, 12));
search.setOnEditorActionListener((v, action, e) -> {
hideKeyboard();
@@ -411,7 +411,8 @@ public final class MainActivity extends BaseActivity {
@Override
public void reveal(boolean rightward) {
boolean unread = conv.unread > 0 || conv.markedUnread;
under.setText(rightward ? (conv.archived ? "↩ Unarchive" : "🗄 Archive") : unread ? "✓ Read" : "✉ Unread");
under.setText(rightward ? (conv.archived ? "Unarchive" : "Archive") : unread ? "Read" : "Unread");
Ui.glyph(under, rightward ? (conv.archived ? Glyph.Kind.UNARCHIVE : Glyph.Kind.ARCHIVE) : unread ? Glyph.Kind.CHECK : Glyph.Kind.MAIL, false);
under.setGravity(Gravity.CENTER_VERTICAL | (rightward ? Gravity.START : Gravity.END));
}
@@ -426,7 +427,7 @@ public final class MainActivity extends BaseActivity {
time.setText(Ui.shortTime(ctx, c.lastTs));
String reaction = Reactions.preview(c.lastBody);
String body = reaction != null ? reaction : c.lastBody == null ? "" : c.lastBody.replaceAll("\\s+", " ").trim();
if (body.isEmpty() && c.lastMediaJson != null) body = "📷 Photo";
if (body.isEmpty() && c.lastMediaJson != null) body = "Photo";
String who = "out".equals(c.lastDirection) ? "You: " : group && c.lastSender != null ? Contacts.firstName(ctx, c.lastSender) + ": " : "";
preview.setText(who + body);
boolean unread = c.unread > 0 || c.markedUnread;
@@ -92,12 +92,12 @@ public final class NewChatActivity extends BaseActivity {
LinearLayout toRow = new LinearLayout(this);
toRow.setGravity(Gravity.CENTER_VERTICAL);
toRow.setBackground(Ui.round(Ui.INPUT, Ui.dp(this, 20)));
toRow.setBackground(Ui.input(this, 20));
toRow.setPadding(Ui.dp(this, 20), 0, Ui.dp(this, 12), 0);
toLabel = Ui.text(this, "To:", Ui.T_SMALL, Ui.MUTED);
to = new EditText(this);
to.setHint("Name or number");
to.setHintTextColor(Ui.FAINT);
to.setHintTextColor(Ui.MUTED);
to.setTextColor(Ui.TEXT);
to.setTextSize(TypedValue.COMPLEX_UNIT_SP, Ui.T_BODY);
to.setBackground(null);
@@ -170,8 +170,9 @@ public final class NewChatActivity extends BaseActivity {
private void renderChips() {
chips.removeAllViews();
for (String n : members) {
TextView chip = Ui.text(this, Contacts.name(this, n) + " ✕", Ui.T_SMALL, Ui.TEXT);
chip.setBackground(Ui.round(Ui.INPUT, Ui.dp(this, 24)));
TextView chip = Ui.text(this, Contacts.name(this, n), Ui.T_SMALL, Ui.TEXT);
Ui.glyph(chip, Glyph.Kind.CLOSE, true);
chip.setBackground(Ui.input(this, 24));
chip.setPadding(Ui.dp(this, 18), Ui.dp(this, 8), Ui.dp(this, 18), Ui.dp(this, 8));
chip.setOnClickListener(v -> {
members.remove(n);
@@ -238,8 +239,8 @@ public final class NewChatActivity extends BaseActivity {
main.addView(Ui.text(c, o[1] != null ? Phone.format(o[0]) + (o[2] != null ? " · " + o[2] : "") : "Send to this number", Ui.T_SMALL, Ui.MUTED));
row.addView(main, new LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.WRAP_CONTENT, 1));
if (Config.get(c).canGroup(from) && members.isEmpty()) {
TextView plus = Ui.text(c, "+ Group", Ui.T_TINY, Ui.MUTED);
plus.setBackground(Ui.round(Ui.INPUT, Ui.dp(c, 24)));
TextView plus = Ui.text(c, "+ Group", Ui.T_SMALL, Ui.TEXT);
plus.setBackground(Ui.outline(c));
plus.setPadding(Ui.dp(c, 16), Ui.dp(c, 10), Ui.dp(c, 16), Ui.dp(c, 10));
plus.setOnClickListener(v -> addMember(o[0]));
row.addView(plus);
@@ -1,15 +1,25 @@
package me.teafry.voipmessages;
import android.animation.ValueAnimator;
import android.content.Context;
import android.view.Gravity;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.RectF;
import android.view.HapticFeedbackConstants;
import android.view.MotionEvent;
import android.view.View;
import android.view.animation.DecelerateInterpolator;
import android.view.animation.OvershootInterpolator;
import android.widget.AbsListView;
import android.widget.FrameLayout;
import android.widget.TextView;
/**
* Pull down on a list that's already at the top to check for new messages.
* (The framework has no SwipeRefreshLayout without androidx.)
* Pull down on a list that's already at its top (the search box showing)
* to check for new messages. The pull is a rubber band: the further you go
* the harder it gets. A bubble grows in the gap and stretches, then pops at
* the mark, and the check starts right then; let go and the list springs
* back to a spinner until the check is done. (The framework has no
* SwipeRefreshLayout without androidx.)
*/
final class PullRefresh extends FrameLayout {
interface OnRefresh {
@@ -17,29 +27,48 @@ final class PullRefresh extends FrameLayout {
}
private final AbsListView list;
private final TextView hint;
private final int threshold;
private final Bubble bubble;
private final int threshold, slop, reach, hold;
private float startY = -1;
private boolean pulling, refreshing;
private boolean pulling, refreshing, popped;
private ValueAnimator settle;
OnRefresh onRefresh;
PullRefresh(Context c, AbsListView list) {
super(c);
this.list = list;
threshold = Ui.dp(c, 140);
hint = Ui.text(c, "", Ui.T_SMALL, Ui.MUTED);
hint.setGravity(Gravity.CENTER);
hint.setPadding(0, Ui.dp(c, 16), 0, Ui.dp(c, 16));
hint.setVisibility(GONE);
threshold = Ui.dp(c, 150);
slop = Ui.dp(c, 24);
reach = Ui.dp(c, 230); // the most the list ever moves
hold = Ui.dp(c, 84); // the gap the spinner sits in
bubble = new Bubble(c, this);
addView(bubble, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
addView(list, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
addView(hint, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT, Gravity.TOP));
hint.setBackgroundColor(Ui.PANEL);
}
private boolean atTop() {
return list.getChildCount() == 0 || (list.getFirstVisiblePosition() == 0 && list.getChildAt(0).getTop() >= list.getPaddingTop());
}
/** How far the list sits below its place: the gap the bubble draws in. */
float gap() {
return list.getTranslationY();
}
private void moveTo(float y) {
list.setTranslationY(y);
bubble.invalidate();
}
private void animateTo(float y, boolean springy) {
if (settle != null) settle.cancel();
settle = ValueAnimator.ofFloat(gap(), y);
settle.setDuration(springy ? 420 : 260);
settle.setInterpolator(springy ? new OvershootInterpolator(1.6f) : new DecelerateInterpolator());
settle.addUpdateListener(a -> moveTo((float) a.getAnimatedValue()));
settle.start();
}
@Override
public boolean onInterceptTouchEvent(MotionEvent e) {
if (refreshing) return false;
@@ -49,8 +78,10 @@ final class PullRefresh extends FrameLayout {
pulling = false;
break;
case MotionEvent.ACTION_MOVE:
if (startY >= 0 && e.getY() - startY > Ui.dp(getContext(), 24) && atTop()) {
if (startY >= 0 && e.getY() - startY > slop && atTop()) {
pulling = true;
popped = false;
if (settle != null) settle.cancel();
return true;
}
break;
@@ -63,22 +94,28 @@ final class PullRefresh extends FrameLayout {
@Override
public boolean onTouchEvent(MotionEvent e) {
if (!pulling) return false;
float d = e.getY() - startY;
float d = Math.max(0, e.getY() - startY - slop);
switch (e.getActionMasked()) {
case MotionEvent.ACTION_MOVE:
hint.setVisibility(VISIBLE);
hint.setText(d > threshold ? "Release to check for messages" : "Pull to check for messages");
list.setTranslationY(Math.min(d, threshold * 1.4f) / 2);
// Rubber band: easy at first, ever stiffer towards reach.
moveTo(reach * (1 - (float) Math.exp(-d / reach)));
bubble.progress = Math.min(1f, d / threshold);
if (!popped && d >= threshold && onRefresh != null) {
popped = true;
refreshing = true;
bubble.pop();
performHapticFeedback(HapticFeedbackConstants.CONFIRM);
announceForAccessibility("Checking for messages");
onRefresh.refresh();
}
return true;
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_CANCEL:
pulling = false;
list.animate().translationY(0).setDuration(150).start();
if (d > threshold && e.getActionMasked() == MotionEvent.ACTION_UP && onRefresh != null) {
setRefreshing(true);
onRefresh.refresh();
} else {
hint.setVisibility(GONE);
if (refreshing) animateTo(hold, false);
else {
bubble.progress = 0;
animateTo(0, true);
}
return true;
default:
@@ -87,8 +124,91 @@ final class PullRefresh extends FrameLayout {
}
void setRefreshing(boolean on) {
refreshing = on;
hint.setText("Checking for messages…");
hint.setVisibility(on ? VISIBLE : GONE);
if (on || !refreshing) return; // only a pull starts one
refreshing = false;
if (pulling) return; // still held: it springs back on release
bubble.progress = 0;
animateTo(0, true);
}
boolean isRefreshing() {
return refreshing;
}
/** The bubble in the gap above the list: grows, stretches, pops, then spins. */
private static final class Bubble extends View {
private final PullRefresh owner;
private final Paint fill = new Paint(Paint.ANTI_ALIAS_FLAG), shine = new Paint(Paint.ANTI_ALIAS_FLAG);
private final Paint ring = new Paint(Paint.ANTI_ALIAS_FLAG);
private final float r, dp;
private final RectF oval = new RectF();
float progress;
private long poppedAt = -1;
Bubble(Context c, PullRefresh owner) {
super(c);
this.owner = owner;
dp = Ui.dp(c, 1);
r = 20 * dp;
fill.setColor(Ui.ACCENT);
shine.setColor(0xCCFFFFFF);
ring.setColor(Ui.TEXT);
ring.setStyle(Paint.Style.STROKE);
ring.setStrokeWidth(3 * dp);
ring.setStrokeCap(Paint.Cap.ROUND);
}
void pop() {
poppedAt = System.currentTimeMillis();
invalidate();
}
@Override
protected void onDraw(Canvas c) {
float gap = owner.gap();
if (gap < 2 * dp) {
if (!owner.isRefreshing()) poppedAt = -1;
return;
}
float cx = getWidth() / 2f, cy = gap / 2f;
long since = poppedAt < 0 ? -1 : System.currentTimeMillis() - poppedAt;
if (since < 0) {
// Growing for the first half of the pull, then stretching
// tall and thin as it nears the mark.
float grow = Math.min(1f, progress * 2), stretch = Math.max(0f, progress * 2 - 1);
float w = r * grow * (1 - 0.22f * stretch), h = r * grow * (1 + 0.55f * stretch);
h = Math.min(h, gap / 2 - 4 * dp);
if (w <= 0 || h <= 0) return;
oval.set(cx - w, cy - h, cx + w, cy + h);
c.drawOval(oval, fill);
c.drawCircle(cx - w * 0.38f, cy - h * 0.42f, w * 0.2f, shine);
return;
}
if (since < 320) {
// Pop: a ring bursting outwards, and droplets flying off.
float t = since / 320f, ease = 1 - (1 - t) * (1 - t);
int alpha = (int) (255 * (1 - t));
ring.setAlpha(alpha);
fill.setAlpha(alpha);
c.drawCircle(cx, cy, r * (1 + 0.9f * ease), ring);
for (int i = 0; i < 8; i++) {
double a = Math.PI * i / 4 + Math.PI / 8;
float d = r * (1.2f + 1.6f * ease);
c.drawCircle(cx + (float) Math.cos(a) * d, cy + (float) Math.sin(a) * d, 4 * dp * (1 - 0.6f * t), fill);
}
ring.setAlpha(255);
fill.setAlpha(255);
postInvalidateOnAnimation();
return;
}
if (owner.isRefreshing()) {
// Checking: a turning arc.
float spin = ((since - 320) % 900) / 900f * 360;
float sr = 16 * dp;
oval.set(cx - sr, cy - sr, cx + sr, cy + sr);
c.drawArc(oval, spin, 270, false, ring);
postInvalidateOnAnimation();
}
}
}
}
@@ -165,7 +165,7 @@ public final class SettingsActivity extends BaseActivity {
LinearLayout r = new LinearLayout(this);
r.setOrientation(LinearLayout.VERTICAL);
r.setPadding(Ui.dp(this, 20), Ui.dp(this, 14), Ui.dp(this, 20), Ui.dp(this, 14));
r.setBackground(Ui.round(Ui.INPUT, Ui.dp(this, 16)));
r.setBackground(Ui.outline(this));
r.addView(Ui.text(this, label, Ui.T_SMALL, Ui.TEXT));
r.addView(Ui.text(this, value, Ui.T_SMALL, Ui.ACCENT));
r.setOnClickListener(onClick);
@@ -9,6 +9,7 @@ import android.graphics.Rect;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.GradientDrawable;
import android.graphics.drawable.StateListDrawable;
import android.text.format.DateFormat;
import android.util.TypedValue;
import android.view.Gravity;
@@ -27,13 +28,14 @@ import java.util.Date;
final class Ui {
private Ui() {}
// Desktop's dark palette.
static final int BG = 0xFF121212, PANEL = 0xFF1B1B1D, ROW_ACTIVE = 0xFF333336, BORDER = 0xFF2E2E30;
static final int TEXT = 0xFFE9E9E9, MUTED = 0xFFA3A3A3, FAINT = 0xFF7C7C7C;
static final int ACCENT = 0xFF2C6BED, BUBBLE_IN = 0xFF3B3B3B, DANGER = 0xFFE05252, INPUT = 0xFF2E2E30;
// White on black (rabbit.html#dp, #looks: the dark look): bars #111,
// secondary text #8A8A8A, dim #3A3A3A, inputs #161616 with a dim edge.
static final int BG = 0xFF000000, PANEL = 0xFF111111, ROW_ACTIVE = 0xFF222222, BORDER = 0xFF3A3A3A, DIM = 0xFF3A3A3A;
static final int TEXT = 0xFFFFFFFF, MUTED = 0xFF8A8A8A, FAINT = 0xFF8A8A8A;
static final int ACCENT = 0xFF2C6BED, BUBBLE_IN = 0xFF2E2E2E, DANGER = 0xFFE05252, INPUT = 0xFF161616;
// Text sizes (sp).
static final float T_TITLE = 30, T_NAME = 27, T_BODY = 26, T_SMALL = 21, T_TINY = 18;
// Text sizes (sp): 22 / 28 / 32, small / body / big (rabbit.html#dp).
static final float T_TITLE = 32, T_NAME = 28, T_BODY = 28, T_SMALL = 22, T_TINY = 22;
static int dp(Context c, float v) {
return Math.round(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, v, c.getResources().getDisplayMetrics()));
@@ -59,29 +61,71 @@ final class Ui {
return g;
}
/** A text box: #161616 with a dim edge. */
static GradientDrawable input(Context c, float radiusDp) {
GradientDrawable g = round(INPUT, dp(c, radiusDp));
g.setStroke(dp(c, 2), DIM);
return g;
}
/** A button: a white 3 dp outline with 12 dp corners, filled white while held. */
static StateListDrawable outline(Context c) {
GradientDrawable rest = round(0x00000000, dp(c, 12));
rest.setStroke(dp(c, 3), TEXT);
GradientDrawable held = round(0x40FFFFFF, dp(c, 12));
held.setStroke(dp(c, 3), TEXT);
StateListDrawable d = new StateListDrawable();
d.addState(new int[] {android.R.attr.state_pressed}, held);
d.addState(new int[0], rest);
return d;
}
static Button button(Context c, String label, boolean primary) {
Button b = new Button(c);
b.setText(label);
b.setAllCaps(false);
b.setTextSize(TypedValue.COMPLEX_UNIT_SP, T_SMALL + 2);
b.setTextColor(primary ? 0xFFFFFFFF : TEXT);
b.setBackground(round(primary ? ACCENT : INPUT, dp(c, 16)));
b.setTextColor(TEXT);
if (primary) b.setTypeface(Typeface.DEFAULT_BOLD);
b.setStateListAnimator(null);
b.setBackground(outline(c));
b.setPadding(dp(c, 24), 0, dp(c, 24), 0);
b.setMinHeight(dp(c, 72));
b.setGravity(Gravity.CENTER);
return b;
}
/** A flat icon-ish text button for headers. */
static TextView headerButton(Context c, String glyph) {
TextView t = text(c, glyph, 34, TEXT);
t.setGravity(Gravity.CENTER);
/** A drawn icon as a flat button for the bars (80 dp, a 44 dp glyph). */
static TextView headerButton(Context c, Glyph.Kind kind) {
return headerButton(c, kind, TEXT);
}
static TextView headerButton(Context c, Glyph.Kind kind, int color) {
TextView t = new TextView(c);
t.setMinWidth(dp(c, 80));
t.setMinHeight(dp(c, 80));
t.setBackground(round(0x00000000, dp(c, 40)));
t.setForegroundGravity(Gravity.CENTER);
t.setForeground(Glyph.of(c, kind, color, 44));
GradientDrawable held = round(0x33FFFFFF, dp(c, 40));
StateListDrawable bg = new StateListDrawable();
bg.addState(new int[] {android.R.attr.state_pressed}, held);
bg.addState(new int[0], round(0x00000000, dp(c, 40)));
t.setBackground(bg);
return t;
}
/** Puts a drawn glyph before (or after) a TextView's text, sized to it. */
static void glyph(TextView t, Glyph.Kind kind, boolean after) {
if (kind == null) {
t.setCompoundDrawablesRelative(null, null, null, null);
return;
}
Glyph g = new Glyph(kind, t.getCurrentTextColor(), Math.round(t.getTextSize() * 1.05f));
t.setCompoundDrawablePadding(Math.round(t.getTextSize() * 0.4f));
if (after) t.setCompoundDrawablesRelative(null, null, g, null);
else t.setCompoundDrawablesRelative(g, null, null, null);
}
// ---- avatars (desktop's format.ts palette) ----
private static final int[] AV_BG = {0xFFE3B5A4, 0xFFA4C9E3, 0xFFB5E3A4, 0xFFE3A4D6, 0xFFE3D6A4, 0xFFA4E3D4, 0xFFC2A4E3, 0xFFE3A4A4, 0xFFA4B0E3, 0xFFD4E3A4};
private static final int[] AV_FG = {0xFF5C2A17, 0xFF16405C, 0xFF2A5C17, 0xFF5C1750, 0xFF5C4A17, 0xFF175C4C, 0xFF3C175C, 0xFF5C1717, 0xFF17245C, 0xFF4A5C17};
@@ -99,16 +143,19 @@ final class Ui {
int h = 0;
for (int i = 0; i < key.length(); i++) h = h * 31 + key.charAt(i);
int i = Math.abs(h) % AV_BG.length;
String label = group ? "👥" : (name == null ? "" : initials(name));
return new Avatar(AV_BG[i], AV_FG[i], label.isEmpty() ? "👤" : label);
String label = group ? "" : (name == null ? "" : initials(name));
return new Avatar(AV_BG[i], AV_FG[i], label, group ? Glyph.Kind.GROUP : Glyph.Kind.PERSON);
}
private static final class Avatar extends Drawable {
private final Paint bg = new Paint(Paint.ANTI_ALIAS_FLAG), fg = new Paint(Paint.ANTI_ALIAS_FLAG);
private final String label;
private final Glyph.Kind kind;
Avatar(int bgColor, int fgColor, String label) {
/** Initials, or (with none) the person / group glyph. */
Avatar(int bgColor, int fgColor, String label, Glyph.Kind kind) {
this.label = label;
this.kind = kind;
bg.setColor(bgColor);
fg.setColor(fgColor);
fg.setTypeface(Typeface.DEFAULT_BOLD);
@@ -120,6 +167,10 @@ final class Ui {
Rect b = getBounds();
float r = Math.min(b.width(), b.height()) / 2f;
canvas.drawCircle(b.exactCenterX(), b.exactCenterY(), r, bg);
if (label.isEmpty()) {
Glyph.draw(canvas, kind, b.exactCenterX(), b.exactCenterY(), r * 1.15f, fg);
return;
}
fg.setTextSize(r * (label.length() > 2 ? 0.8f : 0.85f));
Paint.FontMetrics fm = fg.getFontMetrics();
canvas.drawText(label, b.exactCenterX(), b.exactCenterY() - (fm.ascent + fm.descent) / 2, fg);
+2 -2
View File
@@ -26,8 +26,8 @@ import sys
import zipfile
from pathlib import Path
VERSION_NAME = "0.5.1"
VERSION_CODE = 6
VERSION_NAME = "0.6.0"
VERSION_CODE = 7
PACKAGE = "me.teafry.voipmessages"
DEV_PACKAGE = PACKAGE + ".dev"
+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "voipms-desktop",
"productName": "bubble",
"version": "0.5.1",
"version": "0.6.0",
"description": "Signal-style desktop SMS client for voip.ms",
"author": "trav <trav@teafry.me>",
"private": true,
Binary file not shown.
+1 -1
View File
@@ -1 +1 @@
{"version_name": "0.5.1", "version_code": 6, "package": "me.teafry.voipmessages"}
{"version_name": "0.6.0", "version_code": 7, "package": "me.teafry.voipmessages"}