Debloat any Android or Google TV over Wi-Fi and get an Apple TV-style home.
Python adbadblockandroid-tvandroid-tv-launcherapple-tvbloatware-removalclaude-codedebloatfire-tvgoogle-tvlauncherprivacysmart-tvsony-braviatclvibe-codingxiaomi
Sleep Timer: a quick bar for a remote button, bedtime in one press, zh-TW strings
NewPlayer021323f9be731a60
diff --git a/addons/sleep-timer/.gitignore b/addons/sleep-timer/.gitignoreindex 875cd7fd6..b0bbcda92 100644--- a/addons/sleep-timer/.gitignore+++ b/addons/sleep-timer/.gitignore@@ -1,3 +1,4 @@app/build/.gradle/build/+local.propertiesdiff --git a/addons/sleep-timer/README.md b/addons/sleep-timer/README.mdindex 96aa102e1..fb387c563 100644--- a/addons/sleep-timer/README.md+++ b/addons/sleep-timer/README.md@@ -5,7 +5,11 @@ out. One minute before, a small countdown shows over whatever is playing with ****Turn off now**; if nobody answers, the TV goes to standby. Back leaves the warning but not the timer.Package `io.github.luyzfernando08.sleeptimer`. You see it as **Sleep Timer** (Portuguese: **Desligar**). On-cleanyourtv's Home it is also a module card, **Sleep Timer**, which opens the picker; the picker shows when the+cleanyourtv's Home it is also a module card, **Sleep Timer**, which opens the picker. A remote button mapped to+its quick bar (the launcher's `app_keys`: `hold:178:io.github.luyzfernando08.sleeptimer/.QuickActivity`) opens a+small bar at the bottom over whatever is playing: Left/Right pick the time, OK closes it. `.BedtimeActivity` in its+place is bedtime in one press: a 30-minute timer plus the Brightness add-on's night mode when it is installed, both+off again on the next press. The picker shows when theTV will turn off and can cancel the timer.## How it turns the TV off@@ -53,7 +57,7 @@ it without waiting, the first lines of `build-and-install.sh` have an adb comman- No network, no storage permission, no background service: between setting the timer and its end there aretwo alarms and nothing running.- **`AlarmReceiver`** is exported only to callers holding `WRITE_SECURE_SETTINGS`, which the adb shell has and- ordinary apps cannot get, for the test action above. **`TimerActivity`** (exported) is the tile and the card.+ ordinary apps cannot get, for the test action above. **`TimerActivity`** (exported) is the tile and the card; `QuickActivity` and `BedtimeActivity` (exported) answer a remote button.## Tested ondiff --git a/addons/sleep-timer/app/src/main/AndroidManifest.xml b/addons/sleep-timer/app/src/main/AndroidManifest.xmlindex a15fefd54..349a29440 100644--- a/addons/sleep-timer/app/src/main/AndroidManifest.xml+++ b/addons/sleep-timer/app/src/main/AndroidManifest.xml@@ -16,6 +16,26 @@android:icon="@drawable/banner"android:label="@string/app_name">+ <!-- The quick bar: the app's own tile, its module card and what a remote button mapped to this app (app_keys)+ opens; OK on the bar opens the picker. -->+ <!-- The quick bar, for a remote button: map it in the launcher's app_keys as+ hold:<keycode>:io.github.luyzfernando08.sleeptimer/.QuickActivity. The tile and the card open the picker. -->+ <activity+ android:name=".QuickActivity"+ android:taskAffinity=""+ android:launchMode="singleInstance"+ android:exported="true"+ android:excludeFromRecents="true"+ android:noHistory="true"+ android:theme="@android:style/Theme.Translucent.NoTitleBar" />+ <!-- Bedtime in one press: a 30-minute timer plus Brightness's night mode, off again on the next press. -->+ <activity+ android:name=".BedtimeActivity"+ android:taskAffinity=""+ android:exported="true"+ android:excludeFromRecents="true"+ android:noHistory="true"+ android:theme="@android:style/Theme.Translucent.NoTitleBar" /><!-- The timer picker: the app's own tile and, on the cleanyourtv launcher, its module card. --><activityandroid:name=".TimerActivity"diff --git a/addons/sleep-timer/app/src/main/java/io/github/luyzfernando08/sleeptimer/BedtimeActivity.java b/addons/sleep-timer/app/src/main/java/io/github/luyzfernando08/sleeptimer/BedtimeActivity.javanew file mode 100644index 000000000..69d360886--- /dev/null+++ b/addons/sleep-timer/app/src/main/java/io/github/luyzfernando08/sleeptimer/BedtimeActivity.java@@ -0,0 +1,37 @@+package io.github.luyzfernando08.sleeptimer;++import android.app.Activity;+import android.content.ActivityNotFoundException;+import android.content.ComponentName;+import android.content.Intent;+import android.os.Bundle;++/**+ * Bedtime in one press, for a remote button ("178:io.github.luyzfernando08.sleeptimer/.BedtimeActivity" in the+ * launcher's app_keys): starts a 30-minute timer and, when the Brightness add-on is installed, switches its night+ * mode on; pressed again while the timer runs, it cancels the timer and switches night mode off. The quick bar+ * then shows the timer, and Left/Right still change it. No window of its own.+ */+public class BedtimeActivity extends Activity {+ static final int DEFAULT_MINUTES = 30;+ private static final ComponentName NIGHT_MODE = new ComponentName("io.github.maxhayim.brightness",+ "io.github.maxhayim.brightness.NightToggleActivity");++ @Override+ protected void onCreate(Bundle savedInstanceState) {+ super.onCreate(savedInstanceState);+ boolean bedtime = Timer.end(this) == 0;+ if (bedtime) Timer.start(this, DEFAULT_MINUTES);+ else Timer.cancel(this);+ try {+ startActivity(new Intent().setComponent(NIGHT_MODE)+ .putExtra("night", bedtime ? "on" : "off")+ .putExtra("bar", false)+ .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));+ } catch (ActivityNotFoundException | SecurityException noBrightness) {+ // Then bedtime is the timer alone.+ }+ startActivity(new Intent(this, QuickActivity.class));+ finish();+ }+}diff --git a/addons/sleep-timer/app/src/main/java/io/github/luyzfernando08/sleeptimer/QuickActivity.java b/addons/sleep-timer/app/src/main/java/io/github/luyzfernando08/sleeptimer/QuickActivity.javanew file mode 100644index 000000000..171a408ec--- /dev/null+++ b/addons/sleep-timer/app/src/main/java/io/github/luyzfernando08/sleeptimer/QuickActivity.java@@ -0,0 +1,127 @@+package io.github.luyzfernando08.sleeptimer;++import android.app.Activity;+import android.content.Intent;+import android.graphics.Color;+import android.os.Bundle;+import android.os.Handler;+import android.os.Looper;+import android.text.format.DateFormat;+import android.view.Gravity;+import android.view.KeyEvent;+import android.view.ViewGroup;+import android.widget.FrameLayout;+import android.widget.LinearLayout;+import android.widget.TextView;++/**+ * A small bar at the bottom of the screen, for a remote button mapped to it (the launcher's app_keys,+ * "hold:<keycode>:io.github.luyzfernando08.sleeptimer/.QuickActivity"): Left/Right pick the timer (off, then each+ * length) and it applies at once, over whatever is playing; OK or Back, or a few seconds untouched, closes it. The+ * full picker stays on the app's tile and its module card. It is drawn like one of the+ * launcher's glass panels, so it reads as part of Home.+ */+public class QuickActivity extends Activity {+ private static final long CLOSE_AFTER_MS = 4000;++ private final Handler handler = new Handler(Looper.getMainLooper());+ private final Runnable close = this::finish;+ private TextView label;+ /** 0 is off; otherwise the index into Timer.MINUTES plus one. */+ private int choice;++ @Override+ protected void onCreate(Bundle savedInstanceState) {+ super.onCreate(savedInstanceState);+ LinearLayout panel = new LinearLayout(this);+ panel.setOrientation(LinearLayout.VERTICAL);+ int padX = Ui.dp(this, 28), padY = Ui.dp(this, 18);+ panel.setPadding(padX, padY, padX, padY);+ panel.setBackground(getDrawable(R.drawable.glass_panel));++ label = Ui.text(this, 20, Color.WHITE);+ panel.addView(label);+ TextView hint = Ui.text(this, 13, 0xB3FFFFFF);+ hint.setText(R.string.quick_hint);+ hint.setPadding(0, Ui.dp(this, 8), 0, 0);+ panel.addView(hint);++ FrameLayout root = new FrameLayout(this);+ FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,+ ViewGroup.LayoutParams.WRAP_CONTENT, Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL);+ lp.bottomMargin = Ui.dp(this, 56);+ root.addView(panel, lp);+ setContentView(root);+ }++ @Override+ protected void onResume() {+ super.onResume();+ choice = currentChoice();+ show();+ closeLater();+ }++ /** The button held again while the bar is up (singleInstance): keep it up a little longer. */+ @Override+ protected void onNewIntent(Intent intent) {+ super.onNewIntent(intent);+ closeLater();+ }++ @Override+ protected void onPause() {+ handler.removeCallbacks(close);+ super.onPause();+ }++ @Override+ public boolean onKeyDown(int keyCode, KeyEvent event) {+ switch (keyCode) {+ case KeyEvent.KEYCODE_DPAD_LEFT:+ step(-1);+ return true;+ case KeyEvent.KEYCODE_DPAD_RIGHT:+ step(1);+ return true;+ case KeyEvent.KEYCODE_DPAD_CENTER:+ case KeyEvent.KEYCODE_ENTER:+ finish();+ return true;+ default:+ return super.onKeyDown(keyCode, event);+ }+ }++ /** The choice that matches a running timer: the first length that still covers what is left, so Right extends. */+ private int currentChoice() {+ long end = Timer.end(this);+ if (end == 0) return 0;+ long leftMinutes = (end - System.currentTimeMillis() + 59_999) / 60_000;+ for (int i = 0; i < Timer.MINUTES.length; i++) {+ if (Timer.MINUTES[i] >= leftMinutes) return i + 1;+ }+ return Timer.MINUTES.length;+ }++ private void step(int direction) {+ choice = Math.max(0, Math.min(Timer.MINUTES.length, choice + direction));+ if (choice == 0) Timer.cancel(this);+ else Timer.start(this, Timer.MINUTES[choice - 1]);+ show();+ closeLater();+ }++ private void show() {+ long end = Timer.end(this);+ if (!Timer.canSleep()) label.setText(R.string.no_service);+ else if (end == 0) label.setText(R.string.state_off);+ else label.setText(getString(R.string.in_minutes, (end - System.currentTimeMillis() + 59_999) / 60_000) + " · "+ + getString(R.string.state_on, DateFormat.getTimeFormat(this).format(end)));+ }++ private void closeLater() {+ handler.removeCallbacks(close);+ handler.postDelayed(close, CLOSE_AFTER_MS);+ }+}diff --git a/addons/sleep-timer/app/src/main/res/drawable/glass_panel.xml b/addons/sleep-timer/app/src/main/res/drawable/glass_panel.xmlnew file mode 100644index 000000000..5bd38045c--- /dev/null+++ b/addons/sleep-timer/app/src/main/res/drawable/glass_panel.xml@@ -0,0 +1,11 @@+<?xml version="1.0" encoding="utf-8"?>+<!-- The launcher's glass_panel.xml, copied so the quick bar looks like a Home panel. Keep the two in step. -->+<layer-list xmlns:android="http://schemas.android.com/apk/res/android">+ <item>+ <shape android:shape="rectangle">+ <gradient android:angle="270" android:startColor="#F22A2A2E" android:endColor="#F5161618" />+ <stroke android:width="1dp" android:color="#33FFFFFF" />+ <corners android:radius="20dp" />+ </shape>+ </item>+</layer-list>diff --git a/addons/sleep-timer/app/src/main/res/values-pt/strings.xml b/addons/sleep-timer/app/src/main/res/values-pt/strings.xmlindex 52ea6106a..85367934b 100644--- a/addons/sleep-timer/app/src/main/res/values-pt/strings.xml+++ b/addons/sleep-timer/app/src/main/res/values-pt/strings.xml@@ -13,4 +13,5 @@<string name="now">Desligar agora</string><string name="service_label">Desligar</string><string name="service_description">Só põe a TV em espera quando o timer do Desligar acaba. Não lê a tela.</string>+ <string name="quick_hint">◀ ▶ escolher o tempo OK fechar</string></resources>diff --git a/addons/sleep-timer/app/src/main/res/values-zh-rTW/strings.xml b/addons/sleep-timer/app/src/main/res/values-zh-rTW/strings.xmlnew file mode 100644index 000000000..6c6f94acb--- /dev/null+++ b/addons/sleep-timer/app/src/main/res/values-zh-rTW/strings.xml@@ -0,0 +1,17 @@+<?xml version="1.0" encoding="utf-8"?>+<resources>+ <string name="app_name">睡眠定時</string>+ <string name="hint">選擇電視進入待機的時間,結束前一分鐘會提醒。</string>+ <string name="in_minutes">%1$d 分鐘</string>+ <string name="cancel">取消定時</string>+ <string name="state_off">未設定定時。</string>+ <string name="state_on">%1$s 待機。</string>+ <string name="no_service">睡眠定時的無障礙服務未開啟(請執行安裝腳本)。</string>+ <string name="warning_title">電視即將關閉</string>+ <string name="warning_seconds">%1$d 秒後</string>+ <string name="more">再 15 分鐘</string>+ <string name="now">立即關閉</string>+ <string name="service_label">睡眠定時</string>+ <string name="service_description">只在睡眠定時結束時讓電視待機,不讀取畫面。</string>+ <string name="quick_hint">◀ ▶ 選擇時間 OK 關閉</string>+</resources>diff --git a/addons/sleep-timer/app/src/main/res/values/values.xml b/addons/sleep-timer/app/src/main/res/values/values.xmlindex daf399516..a1c73883e 100644--- a/addons/sleep-timer/app/src/main/res/values/values.xml+++ b/addons/sleep-timer/app/src/main/res/values/values.xml@@ -12,6 +12,7 @@<string name="more">15 more minutes</string><string name="now">Turn off now</string><string name="service_label">Sleep Timer</string>+ <string name="quick_hint">◀ ▶ pick a time OK close</string><string name="service_description">Only puts the TV in standby when the Sleep Timer ends. It does not read the screen.</string><style name="Warning" parent="android:Theme.DeviceDefault.NoActionBar">