package me.teafry.voipmessages; import android.app.AlertDialog; import android.content.Context; import android.content.pm.PackageInfo; import android.os.Bundle; import android.view.Gravity; import android.view.View; import android.view.ViewGroup; import android.widget.LinearLayout; import android.widget.ScrollView; import android.widget.Switch; import android.widget.TextView; /** Background checks, notifications, and what's connected. */ public final class SettingsActivity extends BaseActivity { private static final int[] INTERVALS = {0, 5, 10, 15, 30, 60, 120}; private static final int ROLE = 1; private LinearLayout box; @Override protected void onCreate(Bundle b) { super.onCreate(b); ScrollView scroll = new ScrollView(this); box = new LinearLayout(this); box.setOrientation(LinearLayout.VERTICAL); box.setPadding(Ui.dp(this, 28), Ui.dp(this, 12), Ui.dp(this, 28), Ui.dp(this, 28)); scroll.addView(box); setContentView(scroll); } @Override protected void onActivityResult(int req, int res, android.content.Intent data) { super.onActivityResult(req, res, data); if (req != ROLE) return; Sim.recheck(); // Bring over the texts already on the phone. Sim.syncSoon(this); changed(); } private static String intervalLabel(int m) { if (m == 0) return "Never (pull to refresh)"; if (m < 60) return "Every " + m + " minutes"; return m == 60 ? "Every hour" : "Every " + (m / 60) + " hours"; } @Override public void changed() { if (box == null) return; Context c = this; box.removeAllViews(); box.addView(Ui.bold(Ui.text(c, "Settings", Ui.T_TITLE, Ui.TEXT))); section("Checking for messages"); int current = Config.pollMinutes(c); row("In the background", intervalLabel(current), v -> { String[] labels = new String[INTERVALS.length]; int sel = 0; for (int i = 0; i < INTERVALS.length; i++) { labels[i] = intervalLabel(INTERVALS[i]); if (INTERVALS[i] == current) sel = i; } new AlertDialog.Builder(c).setTitle("Check in the background").setSingleChoiceItems(labels, sel, (d, i) -> { Config.prefs(c).edit().putInt("pollMinutes", INTERVALS[i]).apply(); Alarms.schedule(c); d.dismiss(); changed(); }).show(); }); String last = Store.get(c).get("last_poll"); note(last == null ? "Not checked yet. Pull down on the chat list to check now." : "Last checked " + Ui.shortTime(c, Long.parseLong(last)).toLowerCase() + ". Pull down on the chat list to check now."); Switch notify = new Switch(c); notify.setText("Notifications for new messages"); notify.setTextColor(Ui.TEXT); notify.setTextSize(Ui.T_SMALL + 2); notify.setChecked(Config.notifications(c)); notify.setPadding(0, Ui.dp(c, 16), 0, Ui.dp(c, 16)); notify.setOnCheckedChangeListener((v, on) -> Config.prefs(c).edit().putBoolean("notifications", on).apply()); box.addView(notify); section("Icon"); boolean inv = Icons.isInverted(c); row("Launcher icon", inv ? "Inverted (lighter)" : "Dark", v -> { new AlertDialog.Builder(c).setTitle("Launcher icon") .setSingleChoiceItems(new String[] {"Dark", "Inverted (lighter)"}, inv ? 1 : 0, (d, i) -> { if ((i == 1) != inv) Icons.setInverted(c, i == 1); d.dismiss(); changed(); }).show(); }); note("The home screen can take a few seconds to show the new one."); section("Accounts"); Config cfg = Config.get(c); kv("voip.ms", cfg.voipUser == null ? "Not set up" : Sync.voipError != null ? "⚠ " + Sync.voipError : cfg.voipUser); for (Config.Did d : cfg.dids) if (!d.gv) kv(" Number", Phone.format(d.did) + (d.description.isEmpty() ? "" : " · " + d.description)); kv("Google Voice", cfg.gvNumber == null ? "Not set up" : Sync.gvSignedOut ? "⚠ Signed out" : Sync.gvError != null ? "⚠ " + Sync.gvError : Phone.format(cfg.gvNumber)); note("Accounts come from the desktop app: Settings → Rabbit → Sync to Rabbit copies them here again (e.g. after reconnecting Google Voice there)."); section("SIM card"); Sim.recheck(); if (Sim.isDefault(c)) { String carrier = Sim.carrier(c); kv("Texting from the SIM", carrier.isEmpty() ? "On" : carrier); note(cfg.sandbox ? "Not in the dev app's made-up data: the sandbox never texts for real." : "bubble is the Rabbit's texting app: texts and MMS to the SIM come here, and chats can be sent \"via SIM\"." + " To stop, choose another app under Android Settings → Apps → Default apps → SMS app."); } else { row("Text from the SIM card", "Make bubble the texting app", v -> { try { startActivityForResult(Sim.roleRequest(c), ROLE); } catch (Exception e) { note("This Android won't let bubble become its texting app."); } }); note("Sends and receives texts and MMS over the Rabbit's own SIM, as a third number next to voip.ms and Google Voice." + " Android lets only its default texting app do that, so it takes over from the one you use now;" + " the texts already on the phone come over too."); } if (Relay.configured(cfg)) { section("Relay (jai)"); kv("Desktop link", Relay.status(c)); note("Texts typed on the desktop for \"via SIM\" go out at this Rabbit's background check, and chat names and read status" + " go both ways. Sealed with a key only the desktop and this Rabbit have."); } section("About"); String version = "?"; try { PackageInfo p = getPackageManager().getPackageInfo(getPackageName(), 0); version = p.versionName; } catch (Exception ignored) { } kv("Version", version); } private void section(String title) { TextView t = Ui.bold(Ui.text(this, title.toUpperCase(), Ui.T_TINY, Ui.MUTED)); t.setPadding(0, Ui.dp(this, 28), 0, Ui.dp(this, 6)); box.addView(t); } private void note(String s) { TextView t = Ui.text(this, s, Ui.T_TINY, Ui.FAINT); t.setPadding(0, Ui.dp(this, 4), 0, Ui.dp(this, 8)); box.addView(t); } private void kv(String k, String v) { LinearLayout r = new LinearLayout(this); r.setPadding(0, Ui.dp(this, 8), 0, Ui.dp(this, 8)); r.addView(Ui.text(this, k, Ui.T_SMALL, Ui.TEXT), new LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.WRAP_CONTENT, 1)); TextView val = Ui.text(this, v, Ui.T_SMALL, Ui.MUTED); val.setGravity(Gravity.END); r.addView(val, new LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.WRAP_CONTENT, 1.4f)); box.addView(r); } private void row(String label, String value, View.OnClickListener onClick) { 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.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); box.addView(r); } }