Skip to content

Debloat any Android or Google TV over Wi-Fi and get an Apple TV-style home.

addons: add offline World Clock

SaviorOneZero09aa2dafba75
diff --git a/addons/README.md b/addons/README.md
index c3f00031d..c5f393b66 100644
--- a/addons/README.md
+++ b/addons/README.md
@@ -20,6 +20,7 @@ the core bigger or change how it behaves. You install an add-on only if you want
| [TV Static](tv-static/) | An off-the-air moment each time the screen turns on: the picture opens from a bright line, snow and hiss, colour bars or an old "no signal" screen for 3 to 10 s, then fades into what was on screen; the card sets style, sound and length | [@luyzfernando08](https://github.com/luyzfernando08) | Xiaomi Mi Box S (Android TV 9), Philco by Skyworth (Android TV 14) | foreground service (screen-on watcher), start at boot, display over other apps | <img src="tv-static/screenshot.jpg" width="240" alt="TV Static on a TV"> |
| [Brightness](brightness/) | Dims the picture below the TV's own minimum over every app (and the picture settings on Realtek TVs), with a warm night mode on a schedule and a one-press normal screen | [@maxhayim](https://github.com/maxhayim) | MOKA R8G (Android 14) | overlay, foreground service, start at boot | <img src="brightness/screenshot.jpg" width="240" alt="Brightness on a TV"> |
| [Sleep Timer](sleep-timer/) | A sleep timer: 15 to 120 minutes, a one-minute countdown over what is playing with "15 more minutes", then standby; over HDMI-CEC the TV turns off with the box | [@luyzfernando08](https://github.com/luyzfernando08) | Xiaomi Mi Box S (Android TV 9) | accessibility (lock-screen action only), display over other apps, exact alarms | <img src="sleep-timer/screenshot.jpg" width="240" alt="Sleep Timer on a TV"> |
+| [World Clock](world-clock/) | One to six offline clocks with dates, UTC offsets and day differences; city search and D-pad controls | [@SaviorOneZero](https://github.com/SaviorOneZero) | Samsung C71KW-200 / AT&T Osprey (Android TV 11) | None | <img src="world-clock/screenshot.jpg" width="240" alt="World Clock on a TV"> |
A widget, an info tile, a storage or smart-home card: if it can live as its own small app, it can live
here. See the rules below.
diff --git a/addons/world-clock/.gitignore b/addons/world-clock/.gitignore
new file mode 100644
index 000000000..1773035ff
--- /dev/null
+++ b/addons/world-clock/.gitignore
@@ -0,0 +1,6 @@
+.gradle/
+build/
+app/build/
+local.properties
+*.apk
+*.aab
diff --git a/addons/world-clock/README.md b/addons/world-clock/README.md
new file mode 100644
index 000000000..e9420b9dc
--- /dev/null
+++ b/addons/world-clock/README.md
@@ -0,0 +1,69 @@
+# World Clock
+
+Optional offline CleanYourTV add-on. It opens from a normal Android TV tile or a
+spec-1 module card. The first view contains **Local, London and Sydney**. It is an independent
+Android app; no launcher source, configuration, signing identity or Home behavior changes.
+
+Choose up to six clocks. Each shows the time, local date, UTC offset and calendar-day difference
+from the TV's local date. Local follows the TV's configured time zone. Named zones use the platform's
+rules, including daylight-saving transitions and fractional-hour offsets. Accuracy depends on the
+TV's clock and installed time-zone data; this app does not download updates or determine location.
+
+## Remote controls
+
+- Arrows move between the clocks, Add city and Clock format. Horizontal movement is mirrored in RTL.
+- OK on a clock opens Change city, Move earlier, Move later and Remove city where applicable.
+- Add city opens a searchable list. Press OK in the text field to use the TV keyboard, Down to choose
+ a result, or the keyboard's Done action to return to the list. Back cancels without editing clocks.
+- Clock format offers the TV setting, 12-hour or 24-hour time.
+- At least one clock remains. Back leaves the app. Clock updates change text without rebuilding focus.
+
+City names come from the TV's IANA time-zone catalogue, rather than a complete geographical city
+database. Search also accepts region/zone names. The legacy Katmandu spelling is displayed and
+searchable as Kathmandu. There is no GPS or network lookup.
+
+![World Clock on an Android TV](screenshot.jpg)
+
+## Permissions
+
+None. No network permission, telemetry, advertisements, subscription, account, native library,
+overlay, accessibility service, background service, boot receiver or alarm. Local SharedPreferences
+store only the selected zone IDs and clock format. Automatic backup/device transfer is disabled.
+Refresh runs at minute boundaries only while this Activity is resumed, and reacts to system time
+and time-zone changes. Leaving the screen stops callbacks; it does not keep the TV awake.
+
+## Build
+
+JDK 17, Gradle 8.9, Android SDK platform/build-tools 34; Android Gradle plugin 8.5.2.
+
+```sh
+./gradlew --no-daemon testReleaseUnitTest lintRelease assembleRelease
+```
+
+Use `--offline` when the build dependencies are already cached. The release build uses the standard
+local Android debug signing configuration. Retain the same private signing
+key for later in-place updates; no key or prebuilt APK belongs in a contribution.
+
+The app targets Android 8.0/API 26 and later and has no native ABI restriction. JUnit is test-only;
+there are no runtime dependencies. A module card has a static caption and opens this screen; it
+cannot display live clocks inside the launcher's Home grid. No screensaver mode is included.
+
+## Validation
+
+Tested on a Samsung C71KW-200 / AT&T Osprey, Android TV 11, ARMv7, at 1920×1080.
+The screenshot above is from the physical TV, resized to 1280×720. Navigation was exercised with
+ADB-injected D-pad/OK/Back events through Android's actual focus dispatcher, not a physical handset.
+
+Real-TV checks covered all 32 arrow transitions with six clocks, city entry using only D-pad/OK on
+the TV keyboard, change/move/remove, empty-search cancellation, the six-clock limit, 24-hour format
+and saved cities/format after a cold app restart. With module cards temporarily enabled, Keep hidden,
+Shown, card launch and Hidden were exercised; the original launcher configuration was then restored.
+
+The 28 JVM tests cover DST gaps/overlaps, different transition dates, local-zone changes,
+date-line differences, fractional-hour offsets, formatting, settings/list edits, search and every
+D-pad target/reachability for one to six clocks in LTR and RTL. Build and release lint pass with
+zero errors or warnings. There are no runtime dependencies; the locally built release is about 22 KB.
+
+The TV's installed time-zone database supplies the rules. There is no network time sync, screensaver,
+working-hours overlay or live clock inside the launcher's grid. Other Android versions, right-to-left
+locale rendering and different screen/font scales need broader device testing.
diff --git a/addons/world-clock/app/build.gradle b/addons/world-clock/app/build.gradle
new file mode 100644
index 000000000..10b7a4b4f
--- /dev/null
+++ b/addons/world-clock/app/build.gradle
@@ -0,0 +1,20 @@
+plugins { id 'com.android.application' }
+android {
+ namespace 'io.github.savioronezero.worldclock'
+ compileSdk 34
+ defaultConfig {
+ applicationId 'io.github.savioronezero.worldclock'
+ minSdk 26
+ targetSdk 34
+ versionCode 1
+ versionName '0.1'
+ }
+ buildTypes { release {
+ minifyEnabled true
+ shrinkResources true
+ proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
+ signingConfig signingConfigs.debug
+ } }
+ compileOptions { sourceCompatibility JavaVersion.VERSION_17; targetCompatibility JavaVersion.VERSION_17 }
+}
+dependencies { testImplementation 'junit:junit:4.13.2' }
diff --git a/addons/world-clock/app/proguard-rules.pro b/addons/world-clock/app/proguard-rules.pro
new file mode 100644
index 000000000..224282dcc
--- /dev/null
+++ b/addons/world-clock/app/proguard-rules.pro
@@ -0,0 +1 @@
+# No reflection or runtime libraries. Android entry points are retained by AGP.
diff --git a/addons/world-clock/app/src/main/AndroidManifest.xml b/addons/world-clock/app/src/main/AndroidManifest.xml
new file mode 100644
index 000000000..c7f207f61
--- /dev/null
+++ b/addons/world-clock/app/src/main/AndroidManifest.xml
@@ -0,0 +1,20 @@
+<manifest xmlns:android="http://schemas.android.com/apk/res/android">
+ <uses-feature android:name="android.software.leanback" android:required="true" />
+ <uses-feature android:name="android.hardware.touchscreen" android:required="false" />
+ <application android:allowBackup="false" android:fullBackupContent="false"
+ android:dataExtractionRules="@xml/data_extraction_rules" android:supportsRtl="true"
+ android:theme="@android:style/Theme.Material.NoActionBar.Fullscreen"
+ android:label="@string/app_name" android:icon="@drawable/icon" android:banner="@drawable/banner">
+ <activity android:name=".ClockActivity" android:exported="true">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ <category android:name="android.intent.category.LEANBACK_LAUNCHER" />
+ </intent-filter>
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ <category android:name="com.gathin.tvhome.category.DOCK_CARD" />
+ </intent-filter>
+ <meta-data android:name="com.gathin.tvhome.card" android:resource="@xml/module_card" />
+ </activity>
+ </application>
+</manifest>
diff --git a/addons/world-clock/app/src/main/java/io/github/savioronezero/worldclock/ClockActivity.java b/addons/world-clock/app/src/main/java/io/github/savioronezero/worldclock/ClockActivity.java
new file mode 100644
index 000000000..793ac87ca
--- /dev/null
+++ b/addons/world-clock/app/src/main/java/io/github/savioronezero/worldclock/ClockActivity.java
@@ -0,0 +1,382 @@
+package io.github.savioronezero.worldclock;
+
+import android.app.Activity;
+import android.app.AlertDialog;
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.content.SharedPreferences;
+import android.graphics.Color;
+import android.graphics.Typeface;
+import android.graphics.drawable.GradientDrawable;
+import android.graphics.drawable.StateListDrawable;
+import android.os.Build;
+import android.os.Bundle;
+import android.os.Handler;
+import android.os.Looper;
+import android.text.Editable;
+import android.text.SpannableString;
+import android.text.Spanned;
+import android.text.style.RelativeSizeSpan;
+import android.text.TextWatcher;
+import android.util.TypedValue;
+import android.view.Gravity;
+import android.view.KeyEvent;
+import android.view.View;
+import android.view.ViewGroup;
+import android.view.WindowManager;
+import android.view.inputmethod.EditorInfo;
+import android.view.inputmethod.InputMethodManager;
+import android.widget.ArrayAdapter;
+import android.widget.Button;
+import android.widget.EditText;
+import android.widget.LinearLayout;
+import android.widget.ListView;
+import android.widget.TextView;
+import android.widget.Toast;
+import org.json.JSONArray;
+import org.json.JSONException;
+import java.time.Instant;
+import java.time.ZoneId;
+import java.time.format.TextStyle;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Locale;
+
+/** Offline foreground screen. The system supplies the clock, time zones and keyboard. */
+public final class ClockActivity extends Activity {
+ private static final int INK = Color.rgb(237, 245, 252), MUTED = Color.rgb(169, 190, 210);
+ private static final int ACCENT = Color.rgb(131, 214, 222);
+ private final Handler handler = new Handler(Looper.getMainLooper());
+ private final List<ClockViews> clocks = new ArrayList<>();
+ private final List<View> focusNodes = new ArrayList<>();
+ private List<String> ids, catalogue;
+ private SharedPreferences preferences;
+ private TextView reference;
+ private AlertDialog dialog;
+ private int selected, format;
+ private boolean resumed;
+ private final Runnable tick = new Runnable() {
+ @Override public void run() {
+ if (!resumed) return;
+ refresh();
+ handler.postDelayed(this, ClockModel.nextMinute(System.currentTimeMillis()));
+ }
+ };
+ private final BroadcastReceiver changedTime = new BroadcastReceiver() {
+ @Override public void onReceive(Context context, Intent intent) {
+ if (resumed) {
+ handler.removeCallbacks(tick);
+ tick.run();
+ }
+ }
+ };
+
+ @Override public void onCreate(Bundle state) {
+ super.onCreate(state);
+ preferences = getSharedPreferences("world_clock", MODE_PRIVATE);
+ List<String> saved = new ArrayList<>();
+ try {
+ String raw = preferences.getString("zones_v1", "[]");
+ if (raw != null && raw.length() < 8192) {
+ JSONArray values = new JSONArray(raw);
+ for (int i = 0; i < Math.min(values.length(), 100); i++) {
+ Object id = values.get(i);
+ if (id instanceof String) saved.add((String) id);
+ }
+ }
+ format = preferences.getInt("format_v1", 0);
+ } catch (JSONException | ClassCastException ignored) {
+ // Damaged local preferences fall back to the documented defaults; no external data is used.
+ }
+ if (format < 0 || format > 2) format = 0;
+ ids = ClockModel.restore(saved);
+ catalogue = ClockModel.catalogue();
+ selected = state == null ? 0 : Math.max(0, Math.min(ids.size() - 1, state.getInt("selected", 0)));
+ render();
+ }
+
+ @Override protected void onStart() {
+ super.onStart();
+ IntentFilter filter = new IntentFilter();
+ filter.addAction(Intent.ACTION_TIME_CHANGED);
+ filter.addAction(Intent.ACTION_TIMEZONE_CHANGED);
+ filter.addAction(Intent.ACTION_DATE_CHANGED);
+ if (Build.VERSION.SDK_INT >= 33) registerReceiver(changedTime, filter, Context.RECEIVER_NOT_EXPORTED);
+ else registerReceiver(changedTime, filter);
+ }
+
+ @Override protected void onResume() {
+ super.onResume();
+ resumed = true;
+ handler.removeCallbacks(tick);
+ tick.run();
+ }
+
+ @Override protected void onPause() {
+ resumed = false;
+ handler.removeCallbacks(tick);
+ if (dialog != null) dialog.dismiss();
+ super.onPause();
+ }
+
+ @Override protected void onStop() {
+ unregisterReceiver(changedTime);
+ super.onStop();
+ }
+
+ @Override protected void onDestroy() {
+ handler.removeCallbacks(tick);
+ super.onDestroy();
+ }
+
+ @Override protected void onSaveInstanceState(Bundle state) {
+ state.putInt("selected", selected);
+ super.onSaveInstanceState(state);
+ }
+
+ private void save() {
+ preferences.edit().putString("zones_v1", new JSONArray(ids).toString())
+ .putInt("format_v1", format).apply();
+ }
+
+ private void render() {
+ clocks.clear(); focusNodes.clear();
+ LinearLayout root = column();
+ root.setPadding(dp(36), dp(22), dp(36), dp(20));
+ root.setBackground(new GradientDrawable(GradientDrawable.Orientation.TL_BR,
+ new int[]{Color.rgb(8, 19, 34), Color.rgb(18, 37, 55)}));
+ LinearLayout toolbar = new LinearLayout(this);
+ toolbar.setGravity(Gravity.CENTER_VERTICAL);
+ TextView title = text(getString(R.string.app_name), 28, INK);
+ toolbar.addView(title, new LinearLayout.LayoutParams(0, dp(54), 1));
+ Button add = button(getString(R.string.add_city));
+ add.setOnClickListener(v -> {
+ if (ids.size() == ClockModel.LIMIT) Toast.makeText(this, R.string.city_limit, Toast.LENGTH_SHORT).show();
+ else chooseCity(-1);
+ });
+ toolbar.addView(add, buttonParams()); focusNodes.add(add);
+ Button clockFormat = button(getString(R.string.clock_format));
+ clockFormat.setOnClickListener(v -> chooseFormat());
+ toolbar.addView(clockFormat, buttonParams()); focusNodes.add(clockFormat);
+ root.addView(toolbar);
+ reference = text("", 15, MUTED);
+ root.addView(reference, new LinearLayout.LayoutParams(-1, dp(38)));
+ LinearLayout grid = column();
+ root.addView(grid, new LinearLayout.LayoutParams(-1, 0, 1));
+ int columns = Math.min(3, ids.size());
+ for (int start = 0; start < ids.size(); start += columns) {
+ LinearLayout row = new LinearLayout(this);
+ LinearLayout.LayoutParams rowParams = new LinearLayout.LayoutParams(-1, 0, 1);
+ if (start > 0) rowParams.topMargin = dp(14);
+ grid.addView(row, rowParams);
+ for (int col = 0; col < columns; col++) {
+ final int index = start + col;
+ LinearLayout.LayoutParams cardParams = new LinearLayout.LayoutParams(0, -1, 1);
+ if (col > 0) cardParams.leftMargin = dp(14);
+ if (index >= ids.size()) { row.addView(new View(this), cardParams); continue; }
+ ClockViews card = new ClockViews(ids.get(index));
+ clocks.add(card);
+ row.addView(card.root, cardParams);
+ focusNodes.add(card.root);
+ card.root.setOnFocusChangeListener((v, focused) -> { if (focused) selected = index; });
+ card.root.setOnClickListener(v -> cityOptions(index));
+ }
+ }
+ TextView help = text(getString(R.string.controls), 14, MUTED);
+ help.setGravity(Gravity.CENTER);
+ LinearLayout.LayoutParams helpParams = new LinearLayout.LayoutParams(-1, dp(42));
+ helpParams.topMargin = dp(10);
+ root.addView(help, helpParams);
+ setContentView(root);
+ for (View node : focusNodes) node.setId(View.generateViewId());
+ for (int i = 0; i < focusNodes.size(); i++) {
+ View node = focusNodes.get(i);
+ node.setNextFocusLeftId(target(i, ClockNavigation.LEFT));
+ node.setNextFocusRightId(target(i, ClockNavigation.RIGHT));
+ node.setNextFocusUpId(target(i, ClockNavigation.UP));
+ node.setNextFocusDownId(target(i, ClockNavigation.DOWN));
+ }
+ refresh();
+ focusNodes.get(2 + Math.max(0, Math.min(selected, ids.size() - 1))).requestFocus();
+ }
+
+ private int target(int node, int direction) {
+ boolean rtl = getResources().getConfiguration().getLayoutDirection() == View.LAYOUT_DIRECTION_RTL;
+ return focusNodes.get(ClockNavigation.next(node, ids.size(), direction, rtl)).getId();
+ }
+
+ private void refresh() {
+ // One instant for every city: clocks cannot disagree when the minute/date rolls over mid-refresh.
+ Instant instant = Instant.now();
+ ZoneId local = ZoneId.systemDefault();
+ Locale locale = Locale.getDefault();
+ boolean twentyFour = format == 2 || (format == 0 && android.text.format.DateFormat.is24HourFormat(this));
+ reference.setText(getString(R.string.local_reference, local.getDisplayName(TextStyle.FULL, locale)));
+ for (ClockViews views : clocks) {
+ ClockModel.Reading reading = ClockModel.at(views.id, instant, local, twentyFour, locale);
+ if (reading.period.isEmpty()) views.time.setText(reading.time);
+ else {
+ SpannableString display = new SpannableString(reading.time + " " + reading.period);
+ display.setSpan(new RelativeSizeSpan(0.4f), reading.time.length() + 1, display.length(),
+ Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
+ views.time.setText(display);
+ }
+ views.date.setText(reading.date);
+ views.offset.setText(reading.offset);
+ views.day.setText(reading.dayDifference == 0 ? getString(R.string.same_day)
+ : reading.dayDifference == 1 ? getString(R.string.tomorrow)
+ : reading.dayDifference == -1 ? getString(R.string.yesterday)
+ : getResources().getQuantityString(R.plurals.day_difference,
+ Math.abs(reading.dayDifference), reading.dayDifference));
+ views.day.setTextColor(reading.dayDifference == 0 ? MUTED : ACCENT);
+ }
+ }
+
+ private void cityOptions(int index) {
+ List<String> labels = new ArrayList<>();
+ List<Runnable> actions = new ArrayList<>();
+ labels.add(getString(R.string.change_city)); actions.add(() -> chooseCity(index));
+ if (index > 0) {
+ labels.add(getString(R.string.move_earlier));
+ actions.add(() -> { ids = ClockModel.move(ids, index, index - 1); selected = index - 1; save(); render(); });
+ }
+ if (index + 1 < ids.size()) {
+ labels.add(getString(R.string.move_later));
+ actions.add(() -> { ids = ClockModel.move(ids, index, index + 1); selected = index + 1; save(); render(); });
+ }
+ if (ids.size() > 1) {
+ labels.add(getString(R.string.remove_city));
+ actions.add(() -> { ids = ClockModel.remove(ids, index); selected = Math.min(index, ids.size() - 1); save(); render(); });
+ }
+ show(new AlertDialog.Builder(this).setTitle(cityLabel(ids.get(index)))
+ .setItems(labels.toArray(new String[0]), (d, which) -> actions.get(which).run()).create());
+ }
+
+ private String cityLabel(String id) { return ClockModel.LOCAL.equals(id) ? getString(R.string.local) : ClockModel.city(id); }
+
+ private void chooseFormat() {
+ show(new AlertDialog.Builder(this).setTitle(R.string.clock_format)
+ .setSingleChoiceItems(new String[]{getString(R.string.format_system), getString(R.string.format_12),
+ getString(R.string.format_24)}, format, (d, which) -> {
+ format = which; save(); refresh(); d.dismiss();
+ }).setNegativeButton(R.string.close, null).create());
+ }
+
+ private void chooseCity(int replacing) {
+ LinearLayout panel = column(); panel.setPadding(dp(24), dp(8), dp(24), 0);
+ EditText search = new EditText(this);
+ search.setSingleLine(true); search.setHint(R.string.search_city);
+ search.setImeOptions(EditorInfo.IME_ACTION_DONE);
+ panel.addView(search, new LinearLayout.LayoutParams(-1, dp(52)));
+ panel.addView(text(getString(R.string.search_hint), 13, MUTED));
+ TextView empty = text(getString(R.string.no_cities), 18, INK);
+ empty.setPadding(0, dp(24), 0, dp(24));
+ panel.addView(empty);
+ ListView list = new ListView(this); list.setId(View.generateViewId());
+ list.setItemsCanFocus(false);
+ panel.addView(list, new LinearLayout.LayoutParams(-1, dp(230)));
+ list.setEmptyView(empty);
+ final List<String> matches = new ArrayList<>();
+ ArrayAdapter<String> adapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1);
+ list.setAdapter(adapter);
+ Runnable filter = () -> {
+ matches.clear(); matches.addAll(ClockModel.search(catalogue, search.getText().toString(), ids, replacing));
+ adapter.setNotifyOnChange(false);
+ adapter.clear();
+ for (String id : matches) adapter.add(cityLabel(id) + " · " + ClockModel.area(id));
+ adapter.notifyDataSetChanged();
+ if (!matches.isEmpty()) list.setSelection(0);
+ };
+ search.addTextChangedListener(new TextWatcher() {
+ @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
+ @Override public void onTextChanged(CharSequence s, int start, int before, int count) { filter.run(); }
+ @Override public void afterTextChanged(Editable text) {}
+ });
+ search.setOnKeyListener((v, key, event) -> {
+ if (key == KeyEvent.KEYCODE_DPAD_DOWN && event.getAction() == KeyEvent.ACTION_DOWN && !matches.isEmpty()) {
+ list.requestFocus(); list.setSelection(0); return true;
+ }
+ return false;
+ });
+ search.setOnEditorActionListener((v, action, event) -> {
+ if (action != EditorInfo.IME_ACTION_DONE) return false;
+ InputMethodManager ime = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
+ if (ime != null) ime.hideSoftInputFromWindow(search.getWindowToken(), 0);
+ if (!matches.isEmpty()) { list.requestFocus(); list.setSelection(0); }
+ return true;
+ });
+ AlertDialog picker = new AlertDialog.Builder(this).setTitle(replacing < 0 ? R.string.add_city : R.string.change_city)
+ .setView(panel).setNegativeButton(R.string.close, null).create();
+ list.setOnItemClickListener((parent, view, position, itemId) -> {
+ String id = matches.get(position);
+ List<String> updated = replacing < 0 ? ClockModel.add(ids, id) : ClockModel.replace(ids, replacing, id);
+ if (updated.equals(ids)) {
+ if (replacing >= 0 && id.equals(ids.get(replacing))) { picker.dismiss(); return; }
+ Toast.makeText(this, R.string.already_shown, Toast.LENGTH_SHORT).show(); return;
+ }
+ ids = updated;
+ selected = replacing < 0 ? ids.size() - 1 : replacing;
+ save(); picker.dismiss(); render();
+ });
+ filter.run();
+ show(picker);
+ if (picker.getWindow() != null) picker.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
+ search.requestFocus();
+ }
+
+ private void show(AlertDialog next) {
+ if (dialog != null) dialog.dismiss();
+ dialog = next;
+ next.setOnDismissListener(d -> { if (dialog == next) dialog = null; });
+ next.show();
+ }
+
+ private final class ClockViews {
+ final String id;
+ final LinearLayout root;
+ final TextView time, date, offset, day;
+ ClockViews(String id) {
+ this.id = id;
+ root = column(); root.setGravity(Gravity.CENTER);
+ root.setPadding(dp(12), dp(12), dp(12), dp(12));
+ root.setFocusable(true); root.setClickable(true); root.setBackground(focusBackground());
+ TextView city = text(cityLabel(id), 23, INK);
+ city.setMaxLines(1); city.setGravity(Gravity.CENTER);
+ city.setAutoSizeTextTypeUniformWithConfiguration(16, 23, 1, TypedValue.COMPLEX_UNIT_SP);
+ root.addView(city, new LinearLayout.LayoutParams(-1, dp(34)));
+ time = text("", 64, INK); time.setTypeface(Typeface.create("sans-serif-light", Typeface.NORMAL));
+ time.setGravity(Gravity.CENTER); time.setMaxLines(1); time.setTextDirection(View.TEXT_DIRECTION_LTR);
+ time.setAutoSizeTextTypeUniformWithConfiguration(18, 64, 2, TypedValue.COMPLEX_UNIT_SP);
+ root.addView(time, new LinearLayout.LayoutParams(-1, 0, 1));
+ date = text("", 17, INK); date.setGravity(Gravity.CENTER); root.addView(date);
+ day = text("", 13, MUTED); day.setGravity(Gravity.CENTER); root.addView(day);
+ offset = text("", 13, MUTED); offset.setGravity(Gravity.CENTER); root.addView(offset);
+ }
+ }
+
+ private int dp(int value) { return Math.round(value * getResources().getDisplayMetrics().density); }
+ private LinearLayout column() { LinearLayout v = new LinearLayout(this); v.setOrientation(LinearLayout.VERTICAL); return v; }
+ private TextView text(String value, int size, int color) {
+ TextView v = new TextView(this); v.setText(value); v.setTextSize(size); v.setTextColor(color);
+ v.setGravity(Gravity.CENTER_VERTICAL); return v;
+ }
+ private Button button(String label) {
+ Button v = new Button(this); v.setText(label); v.setTextSize(14); v.setAllCaps(false); v.setTextColor(INK);
+ v.setPadding(dp(16), 0, dp(16), 0); v.setBackground(focusBackground()); return v;
+ }
+ private LinearLayout.LayoutParams buttonParams() {
+ LinearLayout.LayoutParams p = new LinearLayout.LayoutParams(-2, dp(48)); p.leftMargin = dp(10); return p;
+ }
+ private StateListDrawable focusBackground() {
+ StateListDrawable state = new StateListDrawable();
+ state.addState(new int[]{android.R.attr.state_focused}, shape(Color.rgb(28, 62, 80), ACCENT));
+ state.addState(new int[]{}, shape(Color.rgb(19, 39, 57), Color.rgb(44, 64, 83)));
+ return state;
+ }
+ private GradientDrawable shape(int fill, int border) {
+ GradientDrawable shape = new GradientDrawable(); shape.setColor(fill); shape.setCornerRadius(dp(14));
+ shape.setStroke(dp(2), border); return shape;
+ }
+}
diff --git a/addons/world-clock/app/src/main/java/io/github/savioronezero/worldclock/ClockModel.java b/addons/world-clock/app/src/main/java/io/github/savioronezero/worldclock/ClockModel.java
new file mode 100644
index 000000000..1db6b0200
--- /dev/null
+++ b/addons/world-clock/app/src/main/java/io/github/savioronezero/worldclock/ClockModel.java
@@ -0,0 +1,140 @@
+package io.github.savioronezero.worldclock;
+
+import java.text.Normalizer;
+import java.time.Instant;
+import java.time.ZoneId;
+import java.time.ZonedDateTime;
+import java.time.format.DateTimeFormatter;
+import java.time.temporal.ChronoUnit;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Locale;
+import java.util.Set;
+
+/** Clock calculations and small list edits: no Android objects, fixed offsets or background work. */
+final class ClockModel {
+ static final String LOCAL = "@local";
+ static final int LIMIT = 6;
+ static final List<String> DEFAULTS = Collections.unmodifiableList(
+ Arrays.asList(LOCAL, "Europe/London", "Australia/Sydney"));
+
+ static boolean valid(String id) {
+ if (LOCAL.equals(id)) return true;
+ if (id == null || id.length() > 100) return false;
+ // Only platform-named zones: malformed IDs cannot silently become GMT as with TimeZone.getTimeZone.
+ return "UTC".equals(id) || ZoneId.getAvailableZoneIds().contains(id);
+ }
+
+ static List<String> restore(List<String> saved) {
+ List<String> result = new ArrayList<>();
+ if (saved != null) for (String id : saved) {
+ if (valid(id) && !result.contains(id)) result.add(id);
+ if (result.size() == LIMIT) break;
+ }
+ return result.isEmpty() ? new ArrayList<>(DEFAULTS) : result;
+ }
+
+ static List<String> add(List<String> ids, String id) {
+ List<String> result = new ArrayList<>(ids);
+ if (valid(id) && !result.contains(id) && result.size() < LIMIT) result.add(id);
+ return result;
+ }
+
+ static List<String> replace(List<String> ids, int index, String id) {
+ List<String> result = new ArrayList<>(ids);
+ if (index >= 0 && index < result.size() && valid(id)
+ && (id.equals(result.get(index)) || !result.contains(id))) result.set(index, id);
+ return result;
+ }
+
+ static List<String> remove(List<String> ids, int index) {
+ List<String> result = new ArrayList<>(ids);
+ if (result.size() > 1 && index >= 0 && index < result.size()) result.remove(index);
+ return result;
+ }
+
+ static List<String> move(List<String> ids, int from, int to) {
+ List<String> result = new ArrayList<>(ids);
+ if (from >= 0 && from < result.size() && to >= 0 && to < result.size()) {
+ String id = result.remove(from);
+ result.add(to, id);
+ }
+ return result;
+ }
+
+ static String city(String id) {
+ if (LOCAL.equals(id)) return "Local";
+ String name = id.substring(id.lastIndexOf('/') + 1).replace('_', ' ');
+ // Older Android/ICU catalogues use the legacy spelling; keep the familiar city searchable.
+ return "Katmandu".equals(name) ? "Kathmandu" : name;
+ }
+
+ static String area(String id) {
+ int slash = id.lastIndexOf('/');
+ return slash < 0 ? id : id.substring(0, slash).replace('_', ' ').replace('/', ' ');
+ }
+
+ private static String normalized(String value) {
+ return Normalizer.normalize(value, Normalizer.Form.NFD).replaceAll("\\p{M}", "")
+ .toLowerCase(Locale.ROOT).replace('_', ' ').trim();
+ }
+
+ static List<String> search(List<String> catalogue, String query, List<String> existing, int replacing) {
+ String q = normalized(query);
+ String[] terms = q.isEmpty() ? new String[0] : q.split("\\s+");
+ List<String> matches = new ArrayList<>();
+ for (String id : catalogue) {
+ if (existing.contains(id) && (replacing < 0 || !id.equals(existing.get(replacing)))) continue;
+ String text = normalized(city(id) + " " + id.replace('/', ' '));
+ boolean match = true;
+ for (String term : terms) if (!text.contains(term)
+ && !text.replace(" ", "").contains(term)) { match = false; break; }
+ if (match) matches.add(id);
+ }
+ return matches;
+ }
+
+ static List<String> catalogue() {
+ Set<String> found = new HashSet<>();
+ found.add(LOCAL); found.add("UTC");
+ Set<String> available = ZoneId.getAvailableZoneIds();
+ for (String id : available) {
+ if (id.equals("Asia/Katmandu") && available.contains("Asia/Kathmandu")) continue;
+ if (id.contains("/") && !id.startsWith("Etc/") && !id.startsWith("SystemV/")
+ && !id.startsWith("US/") && !id.startsWith("Canada/")
+ && !id.startsWith("Brazil/") && !id.startsWith("Mexico/")) found.add(id);
+ }
+ List<String> result = new ArrayList<>(found);
+ result.sort((a, b) -> {
+ if (a.equals(LOCAL)) return b.equals(LOCAL) ? 0 : -1;
+ if (b.equals(LOCAL)) return 1;
+ int name = city(a).compareToIgnoreCase(city(b));
+ return name == 0 ? a.compareTo(b) : name;
+ });
+ return result;
+ }
+
+ static final class Reading {
+ final String time, period, date, offset;
+ final int dayDifference;
+ Reading(String time, String period, String date, String offset, int dayDifference) {
+ this.time = time; this.period = period; this.date = date;
+ this.offset = offset; this.dayDifference = dayDifference;
+ }
+ }
+
+ static Reading at(String id, Instant instant, ZoneId local, boolean twentyFour, Locale locale) {
+ ZonedDateTime time = instant.atZone(LOCAL.equals(id) ? local : ZoneId.of(id));
+ String offset = time.getOffset().getId();
+ return new Reading(time.format(DateTimeFormatter.ofPattern(twentyFour ? "HH:mm" : "h:mm", locale)),
+ twentyFour ? "" : time.format(DateTimeFormatter.ofPattern("a", locale)),
+ time.format(DateTimeFormatter.ofPattern("EEE, d MMM", locale)),
+ "Z".equals(offset) ? "UTC" : "UTC" + offset,
+ (int) ChronoUnit.DAYS.between(instant.atZone(local).toLocalDate(), time.toLocalDate()));
+ }
+
+ static long nextMinute(long epochMillis) { return 60_000L - Math.floorMod(epochMillis, 60_000L); }
+}
diff --git a/addons/world-clock/app/src/main/java/io/github/savioronezero/worldclock/ClockNavigation.java b/addons/world-clock/app/src/main/java/io/github/savioronezero/worldclock/ClockNavigation.java
new file mode 100644
index 000000000..15b176465
--- /dev/null
+++ b/addons/world-clock/app/src/main/java/io/github/savioronezero/worldclock/ClockNavigation.java
@@ -0,0 +1,27 @@
+package io.github.savioronezero.worldclock;
+
+/** Two toolbar buttons (0/1) and up to six clocks (2..). Every D-pad edge has an explicit target. */
+final class ClockNavigation {
+ static final int LEFT = 0, RIGHT = 1, UP = 2, DOWN = 3;
+ static int next(int node, int count, int direction) { return next(node, count, direction, false); }
+ static int next(int node, int count, int direction, boolean rtl) {
+ if (rtl && direction == LEFT) direction = RIGHT;
+ else if (rtl && direction == RIGHT) direction = LEFT;
+ if (count < 1 || count > ClockModel.LIMIT || node < 0 || node >= count + 2)
+ throw new IllegalArgumentException("invalid clock focus state");
+ int columns = Math.min(3, count);
+ if (node < 2) {
+ if (direction == LEFT) return 0;
+ if (direction == RIGHT) return 1;
+ if (direction == DOWN) return 2 + (node == 0 ? 0 : columns - 1);
+ return node;
+ }
+ int index = node - 2, column = index % columns;
+ if (direction == LEFT) return column == 0 ? node : node - 1;
+ if (direction == RIGHT) return column == columns - 1 || index == count - 1 ? node : node + 1;
+ if (direction == UP) return index < columns ? (column == 0 ? 0 : 1) : node - columns;
+ if (direction == DOWN && index + columns < count) return node + columns;
+ if (direction == DOWN && index / columns == 0 && count > columns) return count + 1;
+ return node;
+ }
+}
diff --git a/addons/world-clock/app/src/main/res/drawable/banner.xml b/addons/world-clock/app/src/main/res/drawable/banner.xml
new file mode 100644
index 000000000..5d744ed60
--- /dev/null
+++ b/addons/world-clock/app/src/main/res/drawable/banner.xml
@@ -0,0 +1,6 @@
+<vector xmlns:android="http://schemas.android.com/apk/res/android" android:width="160dp" android:height="90dp" android:viewportWidth="320" android:viewportHeight="180">
+ <path android:fillColor="#0B1727" android:pathData="M0,0h320v180h-320z" />
+ <path android:fillColor="#203B50" android:pathData="M160,90m-61,0a61,61 0,1 1,122 0a61,61 0,1 1,-122 0" />
+ <path android:fillColor="@android:color/transparent" android:strokeColor="#83D6DE" android:strokeWidth="4" android:pathData="M160,90m-52,0a52,52 0,1 1,104 0a52,52 0,1 1,-104 0M160,56v34l28,17" />
+ <path android:fillColor="#83D6DE" android:pathData="M52,83h22v14h-22zM246,83h22v14h-22z" />
+</vector>
diff --git a/addons/world-clock/app/src/main/res/drawable/icon.xml b/addons/world-clock/app/src/main/res/drawable/icon.xml
new file mode 100644
index 000000000..312df51a8
--- /dev/null
+++ b/addons/world-clock/app/src/main/res/drawable/icon.xml
@@ -0,0 +1,4 @@
+<vector xmlns:android="http://schemas.android.com/apk/res/android" android:width="48dp" android:height="48dp" android:viewportWidth="48" android:viewportHeight="48">
+ <path android:fillColor="#0B1727" android:pathData="M0,0h48v48h-48z" />
+ <path android:fillColor="@android:color/transparent" android:strokeColor="#83D6DE" android:strokeWidth="2" android:pathData="M24,24m-18,0a18,18 0,1 1,36 0a18,18 0,1 1,-36 0M24,12v12l10,6" />
+</vector>
diff --git a/addons/world-clock/app/src/main/res/values/strings.xml b/addons/world-clock/app/src/main/res/values/strings.xml
new file mode 100644
index 000000000..8e2a716ec
--- /dev/null
+++ b/addons/world-clock/app/src/main/res/values/strings.xml
@@ -0,0 +1,28 @@
+<resources>
+ <string name="app_name">World Clock</string>
+ <string name="add_city">Add city</string>
+ <string name="clock_format">Clock format</string>
+ <string name="local">Local</string>
+ <string name="search_city">City or time zone</string>
+ <string name="search_hint">Press OK to type; Down to choose a city</string>
+ <string name="no_cities">No matching cities</string>
+ <string name="change_city">Change city</string>
+ <string name="move_earlier">Move earlier</string>
+ <string name="move_later">Move later</string>
+ <string name="remove_city">Remove city</string>
+ <string name="city_limit">Choose up to six clocks</string>
+ <string name="already_shown">That clock is already shown</string>
+ <string name="same_day">Same day as local</string>
+ <string name="tomorrow">Tomorrow in this city</string>
+ <string name="yesterday">Yesterday in this city</string>
+ <plurals name="day_difference">
+ <item quantity="one">%1$+d day from local</item>
+ <item quantity="other">%1$+d days from local</item>
+ </plurals>
+ <string name="local_reference">Dates compared with %1$s</string>
+ <string name="controls">Arrows to move · OK for city options · Back to return</string>
+ <string name="format_system">Use TV setting</string>
+ <string name="format_12">12-hour time</string>
+ <string name="format_24">24-hour time</string>
+ <string name="close">Close</string>
+</resources>
diff --git a/addons/world-clock/app/src/main/res/xml/data_extraction_rules.xml b/addons/world-clock/app/src/main/res/xml/data_extraction_rules.xml
new file mode 100644
index 000000000..9ddbf2143
--- /dev/null
+++ b/addons/world-clock/app/src/main/res/xml/data_extraction_rules.xml
@@ -0,0 +1,24 @@
+<data-extraction-rules>
+ <cloud-backup>
+ <exclude domain="root" path="." />
+ <exclude domain="file" path="." />
+ <exclude domain="database" path="." />
+ <exclude domain="sharedpref" path="." />
+ <exclude domain="external" path="." />
+ <exclude domain="device_root" path="." />
+ <exclude domain="device_file" path="." />
+ <exclude domain="device_database" path="." />
+ <exclude domain="device_sharedpref" path="." />
+ </cloud-backup>
+ <device-transfer>
+ <exclude domain="root" path="." />
+ <exclude domain="file" path="." />
+ <exclude domain="database" path="." />
+ <exclude domain="sharedpref" path="." />
+ <exclude domain="external" path="." />
+ <exclude domain="device_root" path="." />
+ <exclude domain="device_file" path="." />
+ <exclude domain="device_database" path="." />
+ <exclude domain="device_sharedpref" path="." />
+ </device-transfer>
+</data-extraction-rules>
diff --git a/addons/world-clock/app/src/main/res/xml/module_card.xml b/addons/world-clock/app/src/main/res/xml/module_card.xml
new file mode 100644
index 000000000..2cbb48a41
--- /dev/null
+++ b/addons/world-clock/app/src/main/res/xml/module_card.xml
@@ -0,0 +1 @@
+<card spec="1" label="World Clock" caption="Local and away" accent="#83D6DE" />
diff --git a/addons/world-clock/app/src/test/java/io/github/savioronezero/worldclock/ClockModelTest.java b/addons/world-clock/app/src/test/java/io/github/savioronezero/worldclock/ClockModelTest.java
new file mode 100644
index 000000000..e41fc4579
--- /dev/null
+++ b/addons/world-clock/app/src/test/java/io/github/savioronezero/worldclock/ClockModelTest.java
@@ -0,0 +1,123 @@
+package io.github.savioronezero.worldclock;
+
+import org.junit.Test;
+import static org.junit.Assert.*;
+import java.time.Instant;
+import java.time.ZoneId;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.Locale;
+
+public class ClockModelTest {
+ private ClockModel.Reading read(String id, String instant, String local) {
+ return ClockModel.at(id, Instant.parse(instant), ZoneId.of(local), true, Locale.US);
+ }
+ @Test public void firstRunUsesChosenCities() {
+ assertEquals(Arrays.asList("@local", "Europe/London", "Australia/Sydney"), ClockModel.restore(null));
+ }
+ @Test public void winterUsesSouthernSummerOffset() {
+ assertEquals("12:00", read("Europe/London", "2026-01-15T12:00:00Z", "America/New_York").time);
+ ClockModel.Reading s=read("Australia/Sydney", "2026-01-15T12:00:00Z", "America/New_York");
+ assertEquals("23:00", s.time); assertEquals("UTC+11:00", s.offset);
+ }
+ @Test public void summerUsesNorthernSummerOffset() {
+ assertEquals("13:00", read("Europe/London", "2026-07-15T12:00:00Z", "America/New_York").time);
+ ClockModel.Reading s=read("Australia/Sydney", "2026-07-15T12:00:00Z", "America/New_York");
+ assertEquals("22:00", s.time); assertEquals("UTC+10:00", s.offset);
+ }
+ @Test public void usSpringSkipsTheMissingHour() {
+ assertEquals("01:59", read("@local", "2026-03-08T06:59:00Z", "America/New_York").time);
+ assertEquals("03:00", read("@local", "2026-03-08T07:00:00Z", "America/New_York").time);
+ }
+ @Test public void usFallRepeatsHourWithDifferentOffset() {
+ ClockModel.Reading before=read("@local", "2026-11-01T05:59:00Z", "America/New_York");
+ ClockModel.Reading after=read("@local", "2026-11-01T06:00:00Z", "America/New_York");
+ assertEquals("01:59",before.time); assertEquals("UTC-04:00",before.offset);
+ assertEquals("01:00",after.time); assertEquals("UTC-05:00",after.offset);
+ }
+ @Test public void differentDstTransitionDatesAreNotAFixedTimeDifference() {
+ assertEquals("08:00",read("@local", "2026-03-15T12:00:00Z", "America/New_York").time);
+ assertEquals("12:00",read("Europe/London", "2026-03-15T12:00:00Z", "America/New_York").time);
+ }
+ @Test public void sydneySpringSkipsItsMissingHour() {
+ assertEquals("01:59", read("Australia/Sydney", "2026-10-03T15:59:00Z", "UTC").time);
+ assertEquals("03:00", read("Australia/Sydney", "2026-10-03T16:00:00Z", "UTC").time);
+ }
+ @Test public void nextDayIsRelativeToLocalDate() {
+ ClockModel.Reading s=read("Australia/Sydney", "2026-10-23T20:00:00Z", "America/New_York");
+ assertEquals(1,s.dayDifference); assertEquals("Sat, 24 Oct",s.date);
+ }
+ @Test public void previousDayCanBeShown() {
+ assertEquals(-1,read("Pacific/Honolulu", "2026-10-23T15:30:00Z", "Asia/Tokyo").dayDifference);
+ }
+ @Test public void internationalDateLineCanBeTwoCalendarDaysApart() {
+ assertEquals(2,read("Pacific/Kiritimati", "2026-10-23T10:30:00Z", "Pacific/Pago_Pago").dayDifference);
+ }
+ @Test public void fractionalHourOffsetIsPreserved() {
+ ClockModel.Reading n=read("Asia/Kathmandu", "2026-10-23T00:00:00Z", "UTC");
+ assertEquals("05:45",n.time); assertEquals("UTC+05:45",n.offset);
+ }
+ @Test public void localFollowsChangedTvZoneWithoutChangingSavedId() {
+ assertEquals("00:00",read("@local", "2026-10-23T00:00:00Z", "UTC").time);
+ assertEquals("09:00",read("@local", "2026-10-23T00:00:00Z", "Asia/Tokyo").time);
+ assertEquals("01:00",read("Europe/London", "2026-10-23T00:00:00Z", "Asia/Tokyo").time);
+ }
+ @Test public void twelveHourMidnightHasPeriod() {
+ ClockModel.Reading m=ClockModel.at("UTC", Instant.parse("2026-10-23T00:00:00Z"), ZoneId.of("UTC"), false, Locale.US);
+ assertEquals("12:00",m.time); assertEquals("AM",m.period);
+ }
+ @Test public void twentyFourHourTimeHasNoPeriod() {
+ ClockModel.Reading m=read("UTC", "2026-10-23T00:00:00Z", "UTC");
+ assertEquals("00:00",m.time); assertEquals("",m.period); assertEquals("UTC",m.offset);
+ }
+ @Test public void corruptAndDuplicateSavedIdsAreNotShownAsGmt() {
+ assertFalse(ClockModel.valid("Not/A_Zone"));
+ assertEquals(Arrays.asList("UTC","Europe/London"), ClockModel.restore(Arrays.asList("Not/A_Zone", null,"UTC","UTC","Europe/London")));
+ assertEquals(ClockModel.DEFAULTS,ClockModel.restore(Collections.singletonList("broken")));
+ }
+ @Test public void restoredOrderSurvivesAndIsBounded() {
+ List<String> ids=Arrays.asList("Asia/Tokyo","UTC","Europe/London","Australia/Sydney","America/New_York","Asia/Kathmandu","Europe/Paris");
+ assertEquals(ids.subList(0,6),ClockModel.restore(ids));
+ }
+ @Test public void addingBeyondLimitOrAddingDuplicateDoesNotDiscardAnything() {
+ List<String> ids=ClockModel.restore(Arrays.asList("Asia/Tokyo","UTC","Europe/London","Australia/Sydney","America/New_York","Asia/Kathmandu"));
+ assertEquals(ids,ClockModel.add(ids,"Europe/Paris"));
+ assertEquals(ids,ClockModel.add(ids,"UTC"));
+ }
+ @Test public void replacementCannotCreateDuplicate() {
+ assertEquals(ClockModel.DEFAULTS,ClockModel.replace(ClockModel.DEFAULTS,1,"Australia/Sydney"));
+ assertEquals(Arrays.asList("@local","UTC","Australia/Sydney"),ClockModel.replace(ClockModel.DEFAULTS,1,"UTC"));
+ }
+ @Test public void lastClockCannotBeRemoved() {
+ assertEquals(Collections.singletonList("UTC"),ClockModel.remove(Collections.singletonList("UTC"),0));
+ assertEquals(Arrays.asList("@local","Australia/Sydney"),ClockModel.remove(ClockModel.DEFAULTS,1));
+ }
+ @Test public void movingAcrossRowsKeepsEveryClockAndOrder() {
+ List<String> ids=Arrays.asList("UTC","Asia/Tokyo","Europe/London","Australia/Sydney");
+ assertEquals(Arrays.asList("UTC","Asia/Tokyo","Australia/Sydney","Europe/London"),ClockModel.move(ids,3,2));
+ assertEquals(ids,ClockModel.move(ids,0,-1));
+ }
+ @Test public void searchHandlesSpacesAccentsAndRegion() {
+ List<String> all=Arrays.asList("America/New_York","America/Sao_Paulo","Asia/Tokyo");
+ assertEquals(Collections.singletonList("America/New_York"),ClockModel.search(all,"newyork",Collections.emptyList(),-1));
+ assertEquals(Collections.singletonList("America/Sao_Paulo"),ClockModel.search(all,"São Paulo",Collections.emptyList(),-1));
+ assertEquals(Collections.singletonList("Asia/Tokyo"),ClockModel.search(all,"Asia",Collections.emptyList(),-1));
+ }
+ @Test public void legacyPlatformZoneSpellingStillMatchesTheCityName() {
+ assertEquals("Kathmandu", ClockModel.city("Asia/Katmandu"));
+ assertEquals(Collections.singletonList("Asia/Katmandu"), ClockModel.search(
+ Collections.singletonList("Asia/Katmandu"), "Kathmandu", Collections.emptyList(), -1));
+ }
+ @Test public void pickerExcludesExistingExceptTheCityBeingReplaced() {
+ List<String> all=Arrays.asList("Europe/London","Australia/Sydney","UTC");
+ assertEquals(Collections.singletonList("UTC"),ClockModel.search(all,"",ClockModel.DEFAULTS,-1));
+ assertEquals(Arrays.asList("Europe/London","UTC"),ClockModel.search(all,"",ClockModel.DEFAULTS,1));
+ }
+ @Test public void refreshDelayCannotSpinAtMinuteBoundaryOrAfterClockAdjustment() {
+ assertEquals(60_000,ClockModel.nextMinute(120_000));
+ assertEquals(1,ClockModel.nextMinute(119_999));
+ assertEquals(59_000,ClockModel.nextMinute(121_000));
+ assertEquals(1,ClockModel.nextMinute(-1));
+ }
+}
diff --git a/addons/world-clock/app/src/test/java/io/github/savioronezero/worldclock/ClockNavigationTest.java b/addons/world-clock/app/src/test/java/io/github/savioronezero/worldclock/ClockNavigationTest.java
new file mode 100644
index 000000000..2b4266063
--- /dev/null
+++ b/addons/world-clock/app/src/test/java/io/github/savioronezero/worldclock/ClockNavigationTest.java
@@ -0,0 +1,38 @@
+package io.github.savioronezero.worldclock;
+
+import org.junit.Test;
+import static org.junit.Assert.*;
+import java.util.HashSet;
+import java.util.Set;
+
+public class ClockNavigationTest {
+ @Test public void everyClockCountAndDirectionStaysOnAnExistingNode() {
+ for(boolean rtl:new boolean[]{false,true}) for(int count=1;count<=6;count++)
+ for(int node=0;node<count+2;node++) for(int d=0;d<4;d++) {
+ int next=ClockNavigation.next(node,count,d,rtl);
+ assertTrue(next>=0 && next<count+2);
+ }
+ }
+ @Test public void everyControlCanBeReachedWithOnlyTheDpad() {
+ for(boolean rtl:new boolean[]{false,true}) for(int count=1;count<=6;count++) {
+ Set<Integer> seen=new HashSet<>();seen.add(2);
+ boolean changed;
+ do {
+ changed=false;
+ for(int node:new HashSet<>(seen)) for(int d=0;d<4;d++)
+ changed|=seen.add(ClockNavigation.next(node,count,d,rtl));
+ } while(changed);
+ assertEquals(count+2,seen.size());
+ }
+ }
+ @Test public void partialLastRowClampsDownAndCanReturnUp() {
+ assertEquals(5,ClockNavigation.next(4,4,ClockNavigation.DOWN));
+ assertEquals(2,ClockNavigation.next(5,4,ClockNavigation.UP));
+ assertEquals(5,ClockNavigation.next(5,4,ClockNavigation.RIGHT));
+ }
+ @Test public void rtlMirrorsHorizontalMovementWithoutChangingVerticalTargets() {
+ assertEquals(3,ClockNavigation.next(2,3,ClockNavigation.LEFT,true));
+ assertEquals(2,ClockNavigation.next(2,3,ClockNavigation.RIGHT,true));
+ assertEquals(ClockNavigation.next(4,6,ClockNavigation.DOWN,false),ClockNavigation.next(4,6,ClockNavigation.DOWN,true));
+ }
+}
diff --git a/addons/world-clock/build.gradle b/addons/world-clock/build.gradle
new file mode 100644
index 000000000..48978475f
--- /dev/null
+++ b/addons/world-clock/build.gradle
@@ -0,0 +1,3 @@
+plugins {
+ id 'com.android.application' version '8.5.2' apply false
+}
diff --git a/addons/world-clock/gradle.properties b/addons/world-clock/gradle.properties
new file mode 100644
index 000000000..18825f968
--- /dev/null
+++ b/addons/world-clock/gradle.properties
@@ -0,0 +1,3 @@
+org.gradle.jvmargs=-Xmx2g -Dfile.encoding=UTF-8
+android.useAndroidX=true
+android.nonTransitiveRClass=true
diff --git a/addons/world-clock/gradle/wrapper/gradle-wrapper.jar b/addons/world-clock/gradle/wrapper/gradle-wrapper.jar
new file mode 100644
index 000000000..2c3521197
Binary files /dev/null and b/addons/world-clock/gradle/wrapper/gradle-wrapper.jar differ
diff --git a/addons/world-clock/gradle/wrapper/gradle-wrapper.properties b/addons/world-clock/gradle/wrapper/gradle-wrapper.properties
new file mode 100644
index 000000000..77f5d0ba6
--- /dev/null
+++ b/addons/world-clock/gradle/wrapper/gradle-wrapper.properties
@@ -0,0 +1,8 @@
+distributionBase=GRADLE_USER_HOME
+distributionPath=wrapper/dists
+distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip
+distributionSha256Sum=d725d707bfabd4dfdc958c624003b3c80accc03f7037b5122c4b1d0ef15cecab
+networkTimeout=10000
+validateDistributionUrl=true
+zipStoreBase=GRADLE_USER_HOME
+zipStorePath=wrapper/dists
diff --git a/addons/world-clock/gradlew b/addons/world-clock/gradlew
new file mode 100755
index 000000000..f5feea6d6
--- /dev/null
+++ b/addons/world-clock/gradlew
@@ -0,0 +1,252 @@
+#!/bin/sh
+
+#
+# Copyright © 2015-2021 the original authors.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+# SPDX-License-Identifier: Apache-2.0
+#
+
+##############################################################################
+#
+# Gradle start up script for POSIX generated by Gradle.
+#
+# Important for running:
+#
+# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
+# noncompliant, but you have some other compliant shell such as ksh or
+# bash, then to run this script, type that shell name before the whole
+# command line, like:
+#
+# ksh Gradle
+#
+# Busybox and similar reduced shells will NOT work, because this script
+# requires all of these POSIX shell features:
+# * functions;
+# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
+# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
+# * compound commands having a testable exit status, especially «case»;
+# * various built-in commands including «command», «set», and «ulimit».
+#
+# Important for patching:
+#
+# (2) This script targets any POSIX shell, so it avoids extensions provided
+# by Bash, Ksh, etc; in particular arrays are avoided.
+#
+# The "traditional" practice of packing multiple parameters into a
+# space-separated string is a well documented source of bugs and security
+# problems, so this is (mostly) avoided, by progressively accumulating
+# options in "$@", and eventually passing that to Java.
+#
+# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
+# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
+# see the in-line comments for details.
+#
+# There are tweaks for specific operating systems such as AIX, CygWin,
+# Darwin, MinGW, and NonStop.
+#
+# (3) This script is generated from the Groovy template
+# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
+# within the Gradle project.
+#
+# You can find Gradle at https://github.com/gradle/gradle/.
+#
+##############################################################################
+
+# Attempt to set APP_HOME
+
+# Resolve links: $0 may be a link
+app_path=$0
+
+# Need this for daisy-chained symlinks.
+while
+ APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
+ [ -h "$app_path" ]
+do
+ ls=$( ls -ld "$app_path" )
+ link=${ls#*' -> '}
+ case $link in #(
+ /*) app_path=$link ;; #(
+ *) app_path=$APP_HOME$link ;;
+ esac
+done
+
+# This is normally unused
+# shellcheck disable=SC2034
+APP_BASE_NAME=${0##*/}
+# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
+APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s
+' "$PWD" ) || exit
+
+# Use the maximum available, or set MAX_FD != -1 to use that value.
+MAX_FD=maximum
+
+warn () {
+ echo "$*"
+} >&2
+
+die () {
+ echo
+ echo "$*"
+ echo
+ exit 1
+} >&2
+
+# OS specific support (must be 'true' or 'false').
+cygwin=false
+msys=false
+darwin=false
+nonstop=false
+case "$( uname )" in #(
+ CYGWIN* ) cygwin=true ;; #(
+ Darwin* ) darwin=true ;; #(
+ MSYS* | MINGW* ) msys=true ;; #(
+ NONSTOP* ) nonstop=true ;;
+esac
+
+CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
+
+
+# Determine the Java command to use to start the JVM.
+if [ -n "$JAVA_HOME" ] ; then
+ if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
+ # IBM's JDK on AIX uses strange locations for the executables
+ JAVACMD=$JAVA_HOME/jre/sh/java
+ else
+ JAVACMD=$JAVA_HOME/bin/java
+ fi
+ if [ ! -x "$JAVACMD" ] ; then
+ die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+ fi
+else
+ JAVACMD=java
+ if ! command -v java >/dev/null 2>&1
+ then
+ die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+ fi
+fi
+
+# Increase the maximum file descriptors if we can.
+if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
+ case $MAX_FD in #(
+ max*)
+ # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
+ # shellcheck disable=SC2039,SC3045
+ MAX_FD=$( ulimit -H -n ) ||
+ warn "Could not query maximum file descriptor limit"
+ esac
+ case $MAX_FD in #(
+ '' | soft) :;; #(
+ *)
+ # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
+ # shellcheck disable=SC2039,SC3045
+ ulimit -n "$MAX_FD" ||
+ warn "Could not set maximum file descriptor limit to $MAX_FD"
+ esac
+fi
+
+# Collect all arguments for the java command, stacking in reverse order:
+# * args from the command line
+# * the main class name
+# * -classpath
+# * -D...appname settings
+# * --module-path (only if needed)
+# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
+
+# For Cygwin or MSYS, switch paths to Windows format before running java
+if "$cygwin" || "$msys" ; then
+ APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
+ CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
+
+ JAVACMD=$( cygpath --unix "$JAVACMD" )
+
+ # Now convert the arguments - kludge to limit ourselves to /bin/sh
+ for arg do
+ if
+ case $arg in #(
+ -*) false ;; # don't mess with options #(
+ /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
+ [ -e "$t" ] ;; #(
+ *) false ;;
+ esac
+ then
+ arg=$( cygpath --path --ignore --mixed "$arg" )
+ fi
+ # Roll the args list around exactly as many times as the number of
+ # args, so each arg winds up back in the position where it started, but
+ # possibly modified.
+ #
+ # NB: a `for` loop captures its iteration list before it begins, so
+ # changing the positional parameters here affects neither the number of
+ # iterations, nor the values presented in `arg`.
+ shift # remove old arg
+ set -- "$@" "$arg" # push replacement arg
+ done
+fi
+
+
+# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
+
+# Collect all arguments for the java command:
+# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
+# and any embedded shellness will be escaped.
+# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
+# treated as '${Hostname}' itself on the command line.
+
+set -- \
+ "-Dorg.gradle.appname=$APP_BASE_NAME" \
+ -classpath "$CLASSPATH" \
+ org.gradle.wrapper.GradleWrapperMain \
+ "$@"
+
+# Stop when "xargs" is not available.
+if ! command -v xargs >/dev/null 2>&1
+then
+ die "xargs is not available"
+fi
+
+# Use "xargs" to parse quoted args.
+#
+# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
+#
+# In Bash we could simply go:
+#
+# readarray ARGS < <( xargs -n1 <<<"$var" ) &&
+# set -- "${ARGS[@]}" "$@"
+#
+# but POSIX shell has neither arrays nor command substitution, so instead we
+# post-process each arg (as a line of input to sed) to backslash-escape any
+# character that might be a shell metacharacter, then use eval to reverse
+# that process (while maintaining the separation between arguments), and wrap
+# the whole thing up as a single "set" statement.
+#
+# This will of course break if any of these variables contains a newline or
+# an unmatched quote.
+#
+
+eval "set -- $(
+ printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
+ xargs -n1 |
+ sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
+ tr '\n' ' '
+ )" '"$@"'
+
+exec "$JAVACMD" "$@"
diff --git a/addons/world-clock/gradlew.bat b/addons/world-clock/gradlew.bat
new file mode 100644
index 000000000..9b42019c7
--- /dev/null
+++ b/addons/world-clock/gradlew.bat
@@ -0,0 +1,94 @@
+@rem
+@rem Copyright 2015 the original author or authors.
+@rem
+@rem Licensed under the Apache License, Version 2.0 (the "License");
+@rem you may not use this file except in compliance with the License.
+@rem You may obtain a copy of the License at
+@rem
+@rem https://www.apache.org/licenses/LICENSE-2.0
+@rem
+@rem Unless required by applicable law or agreed to in writing, software
+@rem distributed under the License is distributed on an "AS IS" BASIS,
+@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+@rem See the License for the specific language governing permissions and
+@rem limitations under the License.
+@rem
+@rem SPDX-License-Identifier: Apache-2.0
+@rem
+
+@if "%DEBUG%"=="" @echo off
+@rem ##########################################################################
+@rem
+@rem Gradle startup script for Windows
+@rem
+@rem ##########################################################################
+
+@rem Set local scope for the variables with windows NT shell
+if "%OS%"=="Windows_NT" setlocal
+
+set DIRNAME=%~dp0
+if "%DIRNAME%"=="" set DIRNAME=.
+@rem This is normally unused
+set APP_BASE_NAME=%~n0
+set APP_HOME=%DIRNAME%
+
+@rem Resolve any "." and ".." in APP_HOME to make it shorter.
+for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
+
+@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
+
+@rem Find java.exe
+if defined JAVA_HOME goto findJavaFromJavaHome
+
+set JAVA_EXE=java.exe
+%JAVA_EXE% -version >NUL 2>&1
+if %ERRORLEVEL% equ 0 goto execute
+
+echo. 1>&2
+echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
+echo. 1>&2
+echo Please set the JAVA_HOME variable in your environment to match the 1>&2
+echo location of your Java installation. 1>&2
+
+goto fail
+
+:findJavaFromJavaHome
+set JAVA_HOME=%JAVA_HOME:"=%
+set JAVA_EXE=%JAVA_HOME%/bin/java.exe
+
+if exist "%JAVA_EXE%" goto execute
+
+echo. 1>&2
+echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
+echo. 1>&2
+echo Please set the JAVA_HOME variable in your environment to match the 1>&2
+echo location of your Java installation. 1>&2
+
+goto fail
+
+:execute
+@rem Setup the command line
+
+set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
+
+
+@rem Execute Gradle
+"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
+
+:end
+@rem End local scope for the variables with windows NT shell
+if %ERRORLEVEL% equ 0 goto mainEnd
+
+:fail
+rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
+rem the _cmd.exe /c_ return code!
+set EXIT_CODE=%ERRORLEVEL%
+if %EXIT_CODE% equ 0 set EXIT_CODE=1
+if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
+exit /b %EXIT_CODE%
+
+:mainEnd
+if "%OS%"=="Windows_NT" endlocal
+
+:omega
diff --git a/addons/world-clock/screenshot.jpg b/addons/world-clock/screenshot.jpg
new file mode 100644
index 000000000..aa1eda0b2
Binary files /dev/null and b/addons/world-clock/screenshot.jpg differ
diff --git a/addons/world-clock/settings.gradle b/addons/world-clock/settings.gradle
new file mode 100644
index 000000000..00c8cc7dd
--- /dev/null
+++ b/addons/world-clock/settings.gradle
@@ -0,0 +1,16 @@
+pluginManagement {
+ repositories {
+ google()
+ mavenCentral()
+ gradlePluginPortal()
+ }
+}
+dependencyResolutionManagement {
+ repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
+ repositories {
+ google()
+ mavenCentral()
+ }
+}
+rootProject.name = "world-clock"
+include ':app'