From 5173f16dede178d7bab544ec33a14b87bd00f9b9 Mon Sep 17 00:00:00 2001
From: zosc <29935021+byzosc@users.noreply.github.com>
Date: Tue, 3 Nov 2026 17:02:18 +0800
Subject: [PATCH 1/3] Added: Theme-aware widget style and per-widget background
opacity setting
- The list widget now follows the system light/dark theme instead of the
hardcoded black title bar and light list background.
- The background is drawn with the system widget corner radius on Android 12+
(`system_app_widget_background_radius`) and the title/refresh button are
inset so the launcher's corner clipping no longer cuts them off.
- Add a configuration activity to set the background opacity per widget
instance. It is reachable from the launcher's widget "Settings" entry
(`reconfigurable|configuration_optional`) and by tapping the widget title.
Closes #10
Assisted-by: Claude Opus 5.5 (Claude Code)
---
app/src/main/AndroidManifest.xml | 10 ++
.../termux/widget/TermuxWidgetProvider.java | 22 ++++-
.../com/termux/widget/WidgetSkinPrefs.java | 47 +++++++++
.../TermuxWidgetConfigureActivity.java | 97 +++++++++++++++++++
app/src/main/res/drawable-v31/widget_bg.xml | 10 ++
.../main/res/drawable/ic_widget_refresh.xml | 14 +++
app/src/main/res/drawable/ripple_circle.xml | 11 +++
app/src/main/res/drawable/ripple_mask.xml | 4 +-
app/src/main/res/drawable/widget_bg.xml | 10 ++
.../activity_termux_widget_configure.xml | 40 ++++++++
app/src/main/res/layout/widget_item.xml | 12 ++-
app/src/main/res/layout/widget_layout.xml | 81 ++++++++++------
app/src/main/res/values-night/colors.xml | 9 ++
app/src/main/res/values/colors.xml | 9 ++
app/src/main/res/values/strings.xml | 5 +
.../main/res/xml/termux_appwidget_info.xml | 4 +-
16 files changed, 348 insertions(+), 37 deletions(-)
create mode 100644 app/src/main/java/com/termux/widget/WidgetSkinPrefs.java
create mode 100644 app/src/main/java/com/termux/widget/activities/TermuxWidgetConfigureActivity.java
create mode 100644 app/src/main/res/drawable-v31/widget_bg.xml
create mode 100644 app/src/main/res/drawable/ic_widget_refresh.xml
create mode 100644 app/src/main/res/drawable/ripple_circle.xml
create mode 100644 app/src/main/res/drawable/widget_bg.xml
create mode 100644 app/src/main/res/layout/activity_termux_widget_configure.xml
create mode 100644 app/src/main/res/values-night/colors.xml
create mode 100644 app/src/main/res/values/colors.xml
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 0c74788..69cb267 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -45,6 +45,16 @@
+
+
+
+
+
+
+ * settings) or by clicking the widget title.
+ */
+public class TermuxWidgetConfigureActivity extends AppCompatActivity {
+
+ public static final String LOG_TAG = "TermuxWidgetConfigureActivity";
+
+ private int mAppWidgetId = AppWidgetManager.INVALID_APPWIDGET_ID;
+
+ private TextView mAlphaValueTextView;
+ private SeekBar mAlphaSeekBar;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ Logger.logDebug(LOG_TAG, "onCreate");
+
+ setContentView(R.layout.activity_termux_widget_configure);
+
+ AppCompatActivityUtils.setNightMode(this, NightMode.getAppNightMode().getName(), true);
+
+ // If user backs out of the activity, then the launcher should treat it as cancelled.
+ setResult(RESULT_CANCELED);
+
+ mAppWidgetId = getIntent().getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID);
+ if (mAppWidgetId == AppWidgetManager.INVALID_APPWIDGET_ID) {
+ Logger.logError(LOG_TAG, "Invalid widget id received, finishing");
+ finish();
+ return;
+ }
+
+ Logger.logDebug(LOG_TAG, "Configuring widget id: " + mAppWidgetId);
+
+ setAlphaViews();
+
+ Button saveButton = findViewById(R.id.button_save);
+ saveButton.setOnClickListener(v -> saveAndFinish());
+ }
+
+ private void setAlphaViews() {
+ mAlphaValueTextView = findViewById(R.id.text_alpha_value);
+ mAlphaSeekBar = findViewById(R.id.seekbar_alpha);
+
+ int percent = WidgetSkinPrefs.getAlphaPercent(this, mAppWidgetId);
+ mAlphaSeekBar.setProgress(percent);
+ setAlphaValueText(percent);
+
+ mAlphaSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
+ @Override
+ public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
+ setAlphaValueText(progress);
+ }
+
+ @Override
+ public void onStartTrackingTouch(SeekBar seekBar) {}
+
+ @Override
+ public void onStopTrackingTouch(SeekBar seekBar) {}
+ });
+ }
+
+ private void setAlphaValueText(int percent) {
+ mAlphaValueTextView.setText(getString(R.string.label_widget_background_opacity, percent));
+ }
+
+ private void saveAndFinish() {
+ int percent = mAlphaSeekBar.getProgress();
+ Logger.logDebug(LOG_TAG, "Saving background opacity " + percent + "% for widget id: " + mAppWidgetId);
+
+ WidgetSkinPrefs.setAlphaPercent(this, mAppWidgetId, percent);
+ TermuxWidgetProvider.updateAppWidgetRemoteViews(this, AppWidgetManager.getInstance(this), mAppWidgetId);
+
+ setResult(RESULT_OK, new Intent().putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, mAppWidgetId));
+ finish();
+ }
+
+}
diff --git a/app/src/main/res/drawable-v31/widget_bg.xml b/app/src/main/res/drawable-v31/widget_bg.xml
new file mode 100644
index 0000000..42b0b98
--- /dev/null
+++ b/app/src/main/res/drawable-v31/widget_bg.xml
@@ -0,0 +1,10 @@
+
+
+
+
+
+
+
+
+
diff --git a/app/src/main/res/drawable/ic_widget_refresh.xml b/app/src/main/res/drawable/ic_widget_refresh.xml
new file mode 100644
index 0000000..a89df06
--- /dev/null
+++ b/app/src/main/res/drawable/ic_widget_refresh.xml
@@ -0,0 +1,14 @@
+
+
+
+
+
+
+
diff --git a/app/src/main/res/drawable/ripple_circle.xml b/app/src/main/res/drawable/ripple_circle.xml
new file mode 100644
index 0000000..68cbc71
--- /dev/null
+++ b/app/src/main/res/drawable/ripple_circle.xml
@@ -0,0 +1,11 @@
+
+
+
+ -
+
+
+
+
+
+
diff --git a/app/src/main/res/drawable/ripple_mask.xml b/app/src/main/res/drawable/ripple_mask.xml
index fe34991..2082a7b 100644
--- a/app/src/main/res/drawable/ripple_mask.xml
+++ b/app/src/main/res/drawable/ripple_mask.xml
@@ -1,6 +1,6 @@
+ android:color="@color/widget_ripple" >
-
@@ -8,4 +8,4 @@
-
\ No newline at end of file
+
diff --git a/app/src/main/res/drawable/widget_bg.xml b/app/src/main/res/drawable/widget_bg.xml
new file mode 100644
index 0000000..706b948
--- /dev/null
+++ b/app/src/main/res/drawable/widget_bg.xml
@@ -0,0 +1,10 @@
+
+
+
+
+
+
+
+
+
diff --git a/app/src/main/res/layout/activity_termux_widget_configure.xml b/app/src/main/res/layout/activity_termux_widget_configure.xml
new file mode 100644
index 0000000..52686d3
--- /dev/null
+++ b/app/src/main/res/layout/activity_termux_widget_configure.xml
@@ -0,0 +1,40 @@
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/app/src/main/res/layout/widget_item.xml b/app/src/main/res/layout/widget_item.xml
index 0df4d30..286132b 100644
--- a/app/src/main/res/layout/widget_item.xml
+++ b/app/src/main/res/layout/widget_item.xml
@@ -4,7 +4,10 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/ripple_mask"
- android:padding="10dp" >
+ android:paddingStart="16dp"
+ android:paddingEnd="16dp"
+ android:paddingTop="12dp"
+ android:paddingBottom="12dp" >
+
+
+ android:importantForAccessibility="no"
+ android:scaleType="fitXY"
+ android:src="@drawable/widget_bg" />
+
+
+
+
+ android:paddingStart="16dp"
+ android:paddingEnd="8dp" >
+ android:textColor="@color/widget_text_primary"
+ android:textSize="16sp" />
+
+
+
+
+ android:background="@android:color/transparent"
+ android:clipToPadding="false"
+ android:divider="@color/widget_divider"
+ android:dividerHeight="1px"
+ android:paddingBottom="8dp" >
@@ -45,20 +75,11 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/top_row"
- android:background="@android:color/white"
- android:padding="6dp"
+ android:background="@android:color/transparent"
+ android:padding="16dp"
android:text="@string/msg_refresh_widget_from_app"
- android:textColor="@android:color/black" />
+ android:textColor="@color/widget_text_secondary"
+ android:textSize="14sp" />
-
-
-
\ No newline at end of file
+
diff --git a/app/src/main/res/values-night/colors.xml b/app/src/main/res/values-night/colors.xml
new file mode 100644
index 0000000..c74bac5
--- /dev/null
+++ b/app/src/main/res/values-night/colors.xml
@@ -0,0 +1,9 @@
+
+
+
+ #FF252525
+ #FFFAFAFA
+ #FFA6A6A6
+ #1FFFFFFF
+ #33FFFFFF
+
diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml
new file mode 100644
index 0000000..51ff1a2
--- /dev/null
+++ b/app/src/main/res/values/colors.xml
@@ -0,0 +1,9 @@
+
+
+
+ #FFFFFFFF
+ #FF1A1A1A
+ #FF7A7A7A
+ #1F000000
+ #33000000
+
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 3071bcf..0640d4f 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -58,6 +58,11 @@
Open &TERMUX_WIDGET_APP_NAME; app to refresh widget
Refresh Widgets
+
+ Widget settings
+ Background opacity: %1$d%%
+ Save
+
Using file at `%1$s` as shortcut icon file
diff --git a/app/src/main/res/xml/termux_appwidget_info.xml b/app/src/main/res/xml/termux_appwidget_info.xml
index 5eef15f..ebd339e 100644
--- a/app/src/main/res/xml/termux_appwidget_info.xml
+++ b/app/src/main/res/xml/termux_appwidget_info.xml
@@ -5,10 +5,12 @@
for how to determine size:
-->
+ android:widgetCategory="home_screen|keyguard"
+ android:widgetFeatures="reconfigurable|configuration_optional" />
From 7478733787b59e1bc90f845529154e6cb6b19180 Mon Sep 17 00:00:00 2001
From: zosc <29935021+byzosc@users.noreply.github.com>
Date: Fri, 6 Nov 2026 00:46:40 +0800
Subject: [PATCH 2/3] Added: Background color option and One UI Home wallpaper
blur
- Add a background color choice to the widget settings: follow dark mode
(default), white, black, or the wallpaper based system palette on
Android 12+. The title, refresh button and list items use a matching
light or dark text color. On Android 12+ the colors follow dark mode
changes without a widget update (`RemoteViews.setColorInt()`).
- The root view is now `@android:id/background` and its color is set with
`setBackgroundColor()`, with alpha kept between 1 and 254. Together with
the `app:widgetStyle` and `app:widgetSize` provider attributes this makes
Samsung One UI Home 7.0+ draw its wallpaper blur behind the widget, like
it does for its own widgets. Other launchers ignore these attributes and
draw the translucent color.
- The refresh button now uses the title color.
Assisted-by: Claude Opus 5.5 (Claude Code)
---
.../termux/widget/TermuxWidgetProvider.java | 11 +-
.../termux/widget/TermuxWidgetService.java | 5 +-
.../java/com/termux/widget/WidgetSkin.java | 100 ++++++++++++++++++
.../com/termux/widget/WidgetSkinPrefs.java | 22 ++++
.../TermuxWidgetConfigureActivity.java | 46 +++++++-
app/src/main/res/drawable-v31/widget_bg.xml | 10 --
.../main/res/drawable/ic_widget_refresh.xml | 2 +-
app/src/main/res/drawable/widget_bg.xml | 10 --
.../activity_termux_widget_configure.xml | 38 +++++++
app/src/main/res/layout/widget_layout.xml | 23 ++--
app/src/main/res/values-night/colors.xml | 8 +-
app/src/main/res/values/attrs.xml | 22 ++++
app/src/main/res/values/colors.xml | 20 +++-
app/src/main/res/values/strings.xml | 5 +
.../main/res/xml/termux_appwidget_info.xml | 5 +-
15 files changed, 273 insertions(+), 54 deletions(-)
create mode 100644 app/src/main/java/com/termux/widget/WidgetSkin.java
delete mode 100644 app/src/main/res/drawable-v31/widget_bg.xml
delete mode 100644 app/src/main/res/drawable/widget_bg.xml
create mode 100644 app/src/main/res/values/attrs.xml
diff --git a/app/src/main/java/com/termux/widget/TermuxWidgetProvider.java b/app/src/main/java/com/termux/widget/TermuxWidgetProvider.java
index c0a228b..b59830a 100644
--- a/app/src/main/java/com/termux/widget/TermuxWidgetProvider.java
+++ b/app/src/main/java/com/termux/widget/TermuxWidgetProvider.java
@@ -84,10 +84,13 @@ public static void updateAppWidgetRemoteViews(@NonNull Context context, @NonNull
RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget_layout);
- // Set background opacity. Only the background ImageView alpha is changed so that the
- // content layer stays opaque and the rounded corners of the background drawable are kept.
- int percent = WidgetSkinPrefs.getAlphaPercent(context, appWidgetId);
- remoteViews.setInt(android.R.id.background, "setImageAlpha", Math.round(percent * 255f / 100f));
+ // Set background color and opacity, and matching text colors. See WidgetSkin for the
+ // One UI Home blur.
+ WidgetSkin skin = WidgetSkin.get(context, appWidgetId);
+ WidgetSkin.setColor(context, remoteViews, android.R.id.background, "setBackgroundColor", skin.backgroundLight, skin.backgroundDark);
+ WidgetSkin.setColor(context, remoteViews, R.id.widget_title, "setTextColor", skin.textPrimaryLight, skin.textPrimaryDark);
+ WidgetSkin.setColor(context, remoteViews, R.id.empty_view, "setTextColor", skin.textSecondaryLight, skin.textSecondaryDark);
+ WidgetSkin.setColor(context, remoteViews, R.id.refresh_button, "setColorFilter", skin.textPrimaryLight, skin.textPrimaryDark);
// The empty view is displayed when the collection has no items. It should be a sibling
// of the collection view:
diff --git a/app/src/main/java/com/termux/widget/TermuxWidgetService.java b/app/src/main/java/com/termux/widget/TermuxWidgetService.java
index 06ab1d6..821e065 100644
--- a/app/src/main/java/com/termux/widget/TermuxWidgetService.java
+++ b/app/src/main/java/com/termux/widget/TermuxWidgetService.java
@@ -57,7 +57,10 @@ public int getCount() {
@Override
public RemoteViews getViewAt(int position) {
// Position will always range from 0 to getCount() - 1.
- return shortcutFiles.get(position).getListWidgetView(mContext);
+ RemoteViews remoteViews = shortcutFiles.get(position).getListWidgetView(mContext);
+ WidgetSkin skin = WidgetSkin.get(mContext, mAppWidgetId);
+ WidgetSkin.setColor(mContext, remoteViews, R.id.widget_item, "setTextColor", skin.textPrimaryLight, skin.textPrimaryDark);
+ return remoteViews;
}
@Override
diff --git a/app/src/main/java/com/termux/widget/WidgetSkin.java b/app/src/main/java/com/termux/widget/WidgetSkin.java
new file mode 100644
index 0000000..b40dd29
--- /dev/null
+++ b/app/src/main/java/com/termux/widget/WidgetSkin.java
@@ -0,0 +1,100 @@
+package com.termux.widget;
+
+import android.content.Context;
+import android.content.res.Configuration;
+import android.os.Build;
+import android.widget.RemoteViews;
+
+import androidx.annotation.ColorInt;
+import androidx.annotation.IdRes;
+import androidx.annotation.NonNull;
+
+/**
+ * Widget colors resolved from {@link WidgetSkinPrefs}, with separate colors for light and dark
+ * system mode.
+ *
+ * One UI Home 7.0+ blurs the wallpaper behind the {@link android.R.id#background} root view and
+ * tints it with the view background color if its alpha is between 1 and 254 and the provider info
+ * declares {@code app:widgetStyle} and {@code app:widgetSize}, so background alpha is kept in that
+ * range. Other launchers just draw the translucent color.
+ */
+public final class WidgetSkin {
+
+ /** Lowest and highest background alpha for which One UI Home still applies its blur. */
+ private static final int MIN_BACKGROUND_ALPHA = 1;
+ private static final int MAX_BACKGROUND_ALPHA = 254;
+
+ @ColorInt public final int backgroundLight;
+ @ColorInt public final int backgroundDark;
+ @ColorInt public final int textPrimaryLight;
+ @ColorInt public final int textPrimaryDark;
+ @ColorInt public final int textSecondaryLight;
+ @ColorInt public final int textSecondaryDark;
+
+ private WidgetSkin(int backgroundLight, int backgroundDark,
+ int textPrimaryLight, int textPrimaryDark,
+ int textSecondaryLight, int textSecondaryDark) {
+ this.backgroundLight = backgroundLight;
+ this.backgroundDark = backgroundDark;
+ this.textPrimaryLight = textPrimaryLight;
+ this.textPrimaryDark = textPrimaryDark;
+ this.textSecondaryLight = textSecondaryLight;
+ this.textSecondaryDark = textSecondaryDark;
+ }
+
+ @NonNull
+ public static WidgetSkin get(@NonNull Context context, int appWidgetId) {
+ int bgLight = context.getColor(R.color.widget_bg_light);
+ int bgDark = context.getColor(R.color.widget_bg_dark);
+ int onLight = context.getColor(R.color.widget_text_primary_light);
+ int onDark = context.getColor(R.color.widget_text_primary_dark);
+ int onLightSecondary = context.getColor(R.color.widget_text_secondary_light);
+ int onDarkSecondary = context.getColor(R.color.widget_text_secondary_dark);
+
+ int alpha = Math.round(WidgetSkinPrefs.getAlphaPercent(context, appWidgetId) * 255f / 100f);
+ alpha = Math.max(MIN_BACKGROUND_ALPHA, Math.min(MAX_BACKGROUND_ALPHA, alpha));
+
+ switch (WidgetSkinPrefs.getColorMode(context, appWidgetId)) {
+ case WidgetSkinPrefs.COLOR_WHITE:
+ return new WidgetSkin(withAlpha(bgLight, alpha), withAlpha(bgLight, alpha),
+ onLight, onLight, onLightSecondary, onLightSecondary);
+ case WidgetSkinPrefs.COLOR_BLACK:
+ int black = context.getColor(R.color.widget_bg_black);
+ return new WidgetSkin(withAlpha(black, alpha), withAlpha(black, alpha),
+ onDark, onDark, onDarkSecondary, onDarkSecondary);
+ case WidgetSkinPrefs.COLOR_WALLPAPER:
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
+ // Resolved now, so a new wallpaper is picked up on the next widget update.
+ bgLight = context.getColor(android.R.color.system_accent1_100);
+ bgDark = context.getColor(android.R.color.system_accent1_800);
+ }
+ break;
+ default:
+ break;
+ }
+
+ return new WidgetSkin(withAlpha(bgLight, alpha), withAlpha(bgDark, alpha),
+ onLight, onDark, onLightSecondary, onDarkSecondary);
+ }
+
+ /**
+ * Set a color with a {@link RemoteViews} int method. On Android 12+ the launcher picks the
+ * light or dark color when applying the views, so it follows dark mode changes without an
+ * update. On older versions the color for the current mode is used.
+ */
+ public static void setColor(@NonNull Context context, @NonNull RemoteViews remoteViews, @IdRes int viewId,
+ @NonNull String methodName, @ColorInt int lightColor, @ColorInt int darkColor) {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
+ remoteViews.setColorInt(viewId, methodName, lightColor, darkColor);
+ } else {
+ int nightMode = context.getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK;
+ remoteViews.setInt(viewId, methodName, nightMode == Configuration.UI_MODE_NIGHT_YES ? darkColor : lightColor);
+ }
+ }
+
+ @ColorInt
+ private static int withAlpha(@ColorInt int color, int alpha) {
+ return (alpha << 24) | (color & 0x00FFFFFF);
+ }
+
+}
diff --git a/app/src/main/java/com/termux/widget/WidgetSkinPrefs.java b/app/src/main/java/com/termux/widget/WidgetSkinPrefs.java
index e23c66c..eda7161 100644
--- a/app/src/main/java/com/termux/widget/WidgetSkinPrefs.java
+++ b/app/src/main/java/com/termux/widget/WidgetSkinPrefs.java
@@ -14,6 +14,14 @@ public final class WidgetSkinPrefs {
private static final String PREFERENCES_NAME = "widget_skin";
private static final String KEY_ALPHA_PREFIX = "alpha_";
+ private static final String KEY_COLOR_PREFIX = "color_";
+
+ /** Background color follows the system dark mode. */
+ public static final int COLOR_AUTO = 0;
+ public static final int COLOR_WHITE = 1;
+ public static final int COLOR_BLACK = 2;
+ /** Background color is taken from the wallpaper based system palette on Android 12+. */
+ public static final int COLOR_WALLPAPER = 3;
/** Default background opacity in percent. */
public static final int DEFAULT_ALPHA_PERCENT = 100;
@@ -37,10 +45,24 @@ public static void setAlphaPercent(@NonNull Context context, int appWidgetId, in
.apply();
}
+ /** Get background color mode, one of the {@code COLOR_*} constants, for the widget. */
+ public static int getColorMode(@NonNull Context context, int appWidgetId) {
+ int mode = getSharedPreferences(context).getInt(KEY_COLOR_PREFIX + appWidgetId, COLOR_AUTO);
+ return mode >= COLOR_AUTO && mode <= COLOR_WALLPAPER ? mode : COLOR_AUTO;
+ }
+
+ /** Set background color mode, one of the {@code COLOR_*} constants, for the widget. */
+ public static void setColorMode(@NonNull Context context, int appWidgetId, int mode) {
+ getSharedPreferences(context).edit()
+ .putInt(KEY_COLOR_PREFIX + appWidgetId, mode)
+ .apply();
+ }
+
/** Remove all skin settings of the widget. */
public static void remove(@NonNull Context context, int appWidgetId) {
getSharedPreferences(context).edit()
.remove(KEY_ALPHA_PREFIX + appWidgetId)
+ .remove(KEY_COLOR_PREFIX + appWidgetId)
.apply();
}
diff --git a/app/src/main/java/com/termux/widget/activities/TermuxWidgetConfigureActivity.java b/app/src/main/java/com/termux/widget/activities/TermuxWidgetConfigureActivity.java
index 4dd502a..9ee0eb9 100644
--- a/app/src/main/java/com/termux/widget/activities/TermuxWidgetConfigureActivity.java
+++ b/app/src/main/java/com/termux/widget/activities/TermuxWidgetConfigureActivity.java
@@ -2,8 +2,11 @@
import android.appwidget.AppWidgetManager;
import android.content.Intent;
+import android.os.Build;
import android.os.Bundle;
+import android.view.View;
import android.widget.Button;
+import android.widget.RadioGroup;
import android.widget.SeekBar;
import android.widget.TextView;
@@ -26,6 +29,7 @@ public class TermuxWidgetConfigureActivity extends AppCompatActivity {
private int mAppWidgetId = AppWidgetManager.INVALID_APPWIDGET_ID;
+ private RadioGroup mColorRadioGroup;
private TextView mAlphaValueTextView;
private SeekBar mAlphaSeekBar;
@@ -51,12 +55,45 @@ protected void onCreate(Bundle savedInstanceState) {
Logger.logDebug(LOG_TAG, "Configuring widget id: " + mAppWidgetId);
+ setColorViews();
setAlphaViews();
Button saveButton = findViewById(R.id.button_save);
saveButton.setOnClickListener(v -> saveAndFinish());
}
+ private void setColorViews() {
+ mColorRadioGroup = findViewById(R.id.radio_group_color);
+
+ // Wallpaper colors are only available on Android 12+.
+ if (Build.VERSION.SDK_INT < Build.VERSION_CODES.S)
+ findViewById(R.id.radio_color_wallpaper).setVisibility(View.GONE);
+
+ switch (WidgetSkinPrefs.getColorMode(this, mAppWidgetId)) {
+ case WidgetSkinPrefs.COLOR_WHITE:
+ mColorRadioGroup.check(R.id.radio_color_white);
+ break;
+ case WidgetSkinPrefs.COLOR_BLACK:
+ mColorRadioGroup.check(R.id.radio_color_black);
+ break;
+ case WidgetSkinPrefs.COLOR_WALLPAPER:
+ mColorRadioGroup.check(Build.VERSION.SDK_INT >= Build.VERSION_CODES.S ?
+ R.id.radio_color_wallpaper : R.id.radio_color_auto);
+ break;
+ default:
+ mColorRadioGroup.check(R.id.radio_color_auto);
+ break;
+ }
+ }
+
+ private int getCheckedColorMode() {
+ int checkedId = mColorRadioGroup.getCheckedRadioButtonId();
+ if (checkedId == R.id.radio_color_white) return WidgetSkinPrefs.COLOR_WHITE;
+ if (checkedId == R.id.radio_color_black) return WidgetSkinPrefs.COLOR_BLACK;
+ if (checkedId == R.id.radio_color_wallpaper) return WidgetSkinPrefs.COLOR_WALLPAPER;
+ return WidgetSkinPrefs.COLOR_AUTO;
+ }
+
private void setAlphaViews() {
mAlphaValueTextView = findViewById(R.id.text_alpha_value);
mAlphaSeekBar = findViewById(R.id.seekbar_alpha);
@@ -84,11 +121,16 @@ private void setAlphaValueText(int percent) {
}
private void saveAndFinish() {
+ int colorMode = getCheckedColorMode();
int percent = mAlphaSeekBar.getProgress();
- Logger.logDebug(LOG_TAG, "Saving background opacity " + percent + "% for widget id: " + mAppWidgetId);
+ Logger.logDebug(LOG_TAG, "Saving background color mode " + colorMode + " and opacity " + percent + "% for widget id: " + mAppWidgetId);
+ WidgetSkinPrefs.setColorMode(this, mAppWidgetId, colorMode);
WidgetSkinPrefs.setAlphaPercent(this, mAppWidgetId, percent);
- TermuxWidgetProvider.updateAppWidgetRemoteViews(this, AppWidgetManager.getInstance(this), mAppWidgetId);
+ AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(this);
+ TermuxWidgetProvider.updateAppWidgetRemoteViews(this, appWidgetManager, mAppWidgetId);
+ // List item text colors are set by TermuxWidgetService, so reload the items too.
+ appWidgetManager.notifyAppWidgetViewDataChanged(mAppWidgetId, R.id.widget_list);
setResult(RESULT_OK, new Intent().putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, mAppWidgetId));
finish();
diff --git a/app/src/main/res/drawable-v31/widget_bg.xml b/app/src/main/res/drawable-v31/widget_bg.xml
deleted file mode 100644
index 42b0b98..0000000
--- a/app/src/main/res/drawable-v31/widget_bg.xml
+++ /dev/null
@@ -1,10 +0,0 @@
-
-
-
-
-
-
-
-
-
diff --git a/app/src/main/res/drawable/ic_widget_refresh.xml b/app/src/main/res/drawable/ic_widget_refresh.xml
index a89df06..6dbaa5e 100644
--- a/app/src/main/res/drawable/ic_widget_refresh.xml
+++ b/app/src/main/res/drawable/ic_widget_refresh.xml
@@ -8,7 +8,7 @@
android:viewportHeight="24" >
diff --git a/app/src/main/res/drawable/widget_bg.xml b/app/src/main/res/drawable/widget_bg.xml
deleted file mode 100644
index 706b948..0000000
--- a/app/src/main/res/drawable/widget_bg.xml
+++ /dev/null
@@ -1,10 +0,0 @@
-
-
-
-
-
-
-
-
-
diff --git a/app/src/main/res/layout/activity_termux_widget_configure.xml b/app/src/main/res/layout/activity_termux_widget_configure.xml
index 52686d3..a206452 100644
--- a/app/src/main/res/layout/activity_termux_widget_configure.xml
+++ b/app/src/main/res/layout/activity_termux_widget_configure.xml
@@ -16,6 +16,44 @@
android:text="@string/title_widget_settings"
android:textSize="20sp" />
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
+ android:layout_height="match_parent"
+ android:background="@color/widget_bg" >
diff --git a/app/src/main/res/values-night/colors.xml b/app/src/main/res/values-night/colors.xml
index c74bac5..dbd1771 100644
--- a/app/src/main/res/values-night/colors.xml
+++ b/app/src/main/res/values-night/colors.xml
@@ -1,9 +1,7 @@
- #FF252525
- #FFFAFAFA
- #FFA6A6A6
- #1FFFFFFF
- #33FFFFFF
+ @color/widget_bg_dark
+ @color/widget_text_primary_dark
+ @color/widget_text_secondary_dark
diff --git a/app/src/main/res/values/attrs.xml b/app/src/main/res/values/attrs.xml
new file mode 100644
index 0000000..b4c9753
--- /dev/null
+++ b/app/src/main/res/values/attrs.xml
@@ -0,0 +1,22 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml
index 51ff1a2..ca5fac9 100644
--- a/app/src/main/res/values/colors.xml
+++ b/app/src/main/res/values/colors.xml
@@ -1,9 +1,19 @@
+
+ #FFFFFFFF
+ #FF252525
+ #FF000000
+ #FF1A1A1A
+ #FFFAFAFA
+ #FF7A7A7A
+ #FFA6A6A6
+
- #FFFFFFFF
- #FF1A1A1A
- #FF7A7A7A
- #1F000000
- #33000000
+ @color/widget_bg_light
+ @color/widget_text_primary_light
+ @color/widget_text_secondary_light
+
+ #29808080
+ #33808080
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 0640d4f..e000315 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -61,6 +61,11 @@
Widget settings
Background opacity: %1$d%%
+ Background color
+ Follow dark mode
+ White
+ Black
+ Wallpaper color
Save
diff --git a/app/src/main/res/xml/termux_appwidget_info.xml b/app/src/main/res/xml/termux_appwidget_info.xml
index ebd339e..85fe6b2 100644
--- a/app/src/main/res/xml/termux_appwidget_info.xml
+++ b/app/src/main/res/xml/termux_appwidget_info.xml
@@ -5,6 +5,7 @@
for how to determine size:
-->
+ android:widgetFeatures="reconfigurable|configuration_optional"
+ app:widgetStyle="colorful"
+ app:widgetSize="small|wideSmall|medium|large|extraLarge|extraLargeLong" />
From bf153caa7d0fe89266bc9620187f45e73c326140 Mon Sep 17 00:00:00 2001
From: zosc <29935021+byzosc@users.noreply.github.com>
Date: Fri, 6 Nov 2026 15:16:46 +0800
Subject: [PATCH 3/3] Added: Text color option
- Add a per-widget text color choice: follow background (default,
preserving the existing behavior), white, or black. Explicit choices
keep the same text color across backgrounds and system light/dark modes.
- Use the selected color for the title, list items and refresh button,
with a translucent version of the same color for the empty-list hint.
- Make the settings screen scrollable so the save button stays reachable
on smaller screens and with larger text.
Assisted-by: Claude Opus 5.5 (Claude Code), Codex
---
.../java/com/termux/widget/WidgetSkin.java | 27 +++-
.../com/termux/widget/WidgetSkinPrefs.java | 20 +++
.../TermuxWidgetConfigureActivity.java | 28 +++-
.../activity_termux_widget_configure.xml | 143 +++++++++++-------
app/src/main/res/values/colors.xml | 6 +
app/src/main/res/values/strings.xml | 4 +
6 files changed, 169 insertions(+), 59 deletions(-)
diff --git a/app/src/main/java/com/termux/widget/WidgetSkin.java b/app/src/main/java/com/termux/widget/WidgetSkin.java
index b40dd29..1a6292b 100644
--- a/app/src/main/java/com/termux/widget/WidgetSkin.java
+++ b/app/src/main/java/com/termux/widget/WidgetSkin.java
@@ -56,12 +56,15 @@ public static WidgetSkin get(@NonNull Context context, int appWidgetId) {
switch (WidgetSkinPrefs.getColorMode(context, appWidgetId)) {
case WidgetSkinPrefs.COLOR_WHITE:
- return new WidgetSkin(withAlpha(bgLight, alpha), withAlpha(bgLight, alpha),
- onLight, onLight, onLightSecondary, onLightSecondary);
+ bgDark = bgLight;
+ onDark = onLight;
+ onDarkSecondary = onLightSecondary;
+ break;
case WidgetSkinPrefs.COLOR_BLACK:
- int black = context.getColor(R.color.widget_bg_black);
- return new WidgetSkin(withAlpha(black, alpha), withAlpha(black, alpha),
- onDark, onDark, onDarkSecondary, onDarkSecondary);
+ bgLight = bgDark = context.getColor(R.color.widget_bg_black);
+ onLight = onDark;
+ onLightSecondary = onDarkSecondary;
+ break;
case WidgetSkinPrefs.COLOR_WALLPAPER:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
// Resolved now, so a new wallpaper is picked up on the next widget update.
@@ -73,6 +76,20 @@ public static WidgetSkin get(@NonNull Context context, int appWidgetId) {
break;
}
+ // Explicit text colors stay the same across all backgrounds and system modes.
+ switch (WidgetSkinPrefs.getTextMode(context, appWidgetId)) {
+ case WidgetSkinPrefs.TEXT_WHITE:
+ onLight = onDark = context.getColor(R.color.widget_text_white);
+ onLightSecondary = onDarkSecondary = context.getColor(R.color.widget_text_white_secondary);
+ break;
+ case WidgetSkinPrefs.TEXT_BLACK:
+ onLight = onDark = context.getColor(R.color.widget_text_black);
+ onLightSecondary = onDarkSecondary = context.getColor(R.color.widget_text_black_secondary);
+ break;
+ default:
+ break;
+ }
+
return new WidgetSkin(withAlpha(bgLight, alpha), withAlpha(bgDark, alpha),
onLight, onDark, onLightSecondary, onDarkSecondary);
}
diff --git a/app/src/main/java/com/termux/widget/WidgetSkinPrefs.java b/app/src/main/java/com/termux/widget/WidgetSkinPrefs.java
index eda7161..48e8f21 100644
--- a/app/src/main/java/com/termux/widget/WidgetSkinPrefs.java
+++ b/app/src/main/java/com/termux/widget/WidgetSkinPrefs.java
@@ -15,6 +15,7 @@ public final class WidgetSkinPrefs {
private static final String KEY_ALPHA_PREFIX = "alpha_";
private static final String KEY_COLOR_PREFIX = "color_";
+ private static final String KEY_TEXT_PREFIX = "text_";
/** Background color follows the system dark mode. */
public static final int COLOR_AUTO = 0;
@@ -23,6 +24,11 @@ public final class WidgetSkinPrefs {
/** Background color is taken from the wallpaper based system palette on Android 12+. */
public static final int COLOR_WALLPAPER = 3;
+ /** Text colors follow the selected background by default. */
+ public static final int TEXT_AUTO = 0;
+ public static final int TEXT_WHITE = 1;
+ public static final int TEXT_BLACK = 2;
+
/** Default background opacity in percent. */
public static final int DEFAULT_ALPHA_PERCENT = 100;
@@ -58,11 +64,25 @@ public static void setColorMode(@NonNull Context context, int appWidgetId, int m
.apply();
}
+ /** Get text color mode, one of the {@code TEXT_*} constants, for the widget. */
+ public static int getTextMode(@NonNull Context context, int appWidgetId) {
+ int mode = getSharedPreferences(context).getInt(KEY_TEXT_PREFIX + appWidgetId, TEXT_AUTO);
+ return mode >= TEXT_AUTO && mode <= TEXT_BLACK ? mode : TEXT_AUTO;
+ }
+
+ /** Set text color mode, one of the {@code TEXT_*} constants, for the widget. */
+ public static void setTextMode(@NonNull Context context, int appWidgetId, int mode) {
+ getSharedPreferences(context).edit()
+ .putInt(KEY_TEXT_PREFIX + appWidgetId, mode)
+ .apply();
+ }
+
/** Remove all skin settings of the widget. */
public static void remove(@NonNull Context context, int appWidgetId) {
getSharedPreferences(context).edit()
.remove(KEY_ALPHA_PREFIX + appWidgetId)
.remove(KEY_COLOR_PREFIX + appWidgetId)
+ .remove(KEY_TEXT_PREFIX + appWidgetId)
.apply();
}
diff --git a/app/src/main/java/com/termux/widget/activities/TermuxWidgetConfigureActivity.java b/app/src/main/java/com/termux/widget/activities/TermuxWidgetConfigureActivity.java
index 9ee0eb9..ca10bfe 100644
--- a/app/src/main/java/com/termux/widget/activities/TermuxWidgetConfigureActivity.java
+++ b/app/src/main/java/com/termux/widget/activities/TermuxWidgetConfigureActivity.java
@@ -30,6 +30,7 @@ public class TermuxWidgetConfigureActivity extends AppCompatActivity {
private int mAppWidgetId = AppWidgetManager.INVALID_APPWIDGET_ID;
private RadioGroup mColorRadioGroup;
+ private RadioGroup mTextRadioGroup;
private TextView mAlphaValueTextView;
private SeekBar mAlphaSeekBar;
@@ -56,6 +57,7 @@ protected void onCreate(Bundle savedInstanceState) {
Logger.logDebug(LOG_TAG, "Configuring widget id: " + mAppWidgetId);
setColorViews();
+ setTextViews();
setAlphaViews();
Button saveButton = findViewById(R.id.button_save);
@@ -94,6 +96,28 @@ private int getCheckedColorMode() {
return WidgetSkinPrefs.COLOR_AUTO;
}
+ private void setTextViews() {
+ mTextRadioGroup = findViewById(R.id.radio_group_text);
+ switch (WidgetSkinPrefs.getTextMode(this, mAppWidgetId)) {
+ case WidgetSkinPrefs.TEXT_WHITE:
+ mTextRadioGroup.check(R.id.radio_text_white);
+ break;
+ case WidgetSkinPrefs.TEXT_BLACK:
+ mTextRadioGroup.check(R.id.radio_text_black);
+ break;
+ default:
+ mTextRadioGroup.check(R.id.radio_text_auto);
+ break;
+ }
+ }
+
+ private int getCheckedTextMode() {
+ int checkedId = mTextRadioGroup.getCheckedRadioButtonId();
+ if (checkedId == R.id.radio_text_white) return WidgetSkinPrefs.TEXT_WHITE;
+ if (checkedId == R.id.radio_text_black) return WidgetSkinPrefs.TEXT_BLACK;
+ return WidgetSkinPrefs.TEXT_AUTO;
+ }
+
private void setAlphaViews() {
mAlphaValueTextView = findViewById(R.id.text_alpha_value);
mAlphaSeekBar = findViewById(R.id.seekbar_alpha);
@@ -122,10 +146,12 @@ private void setAlphaValueText(int percent) {
private void saveAndFinish() {
int colorMode = getCheckedColorMode();
+ int textMode = getCheckedTextMode();
int percent = mAlphaSeekBar.getProgress();
- Logger.logDebug(LOG_TAG, "Saving background color mode " + colorMode + " and opacity " + percent + "% for widget id: " + mAppWidgetId);
+ Logger.logDebug(LOG_TAG, "Saving background color mode " + colorMode + " and text color mode " + textMode + " and opacity " + percent + "% for widget id: " + mAppWidgetId);
WidgetSkinPrefs.setColorMode(this, mAppWidgetId, colorMode);
+ WidgetSkinPrefs.setTextMode(this, mAppWidgetId, textMode);
WidgetSkinPrefs.setAlphaPercent(this, mAppWidgetId, percent);
AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(this);
TermuxWidgetProvider.updateAppWidgetRemoteViews(this, appWidgetManager, mAppWidgetId);
diff --git a/app/src/main/res/layout/activity_termux_widget_configure.xml b/app/src/main/res/layout/activity_termux_widget_configure.xml
index a206452..41d9e22 100644
--- a/app/src/main/res/layout/activity_termux_widget_configure.xml
+++ b/app/src/main/res/layout/activity_termux_widget_configure.xml
@@ -1,78 +1,115 @@
-
-
-
-
-
-
+ android:orientation="vertical"
+ android:padding="24dp">
+
-
+ android:text="@string/label_widget_background_color"
+ android:textSize="14sp" />
-
+ android:layout_marginTop="8dp"
+ android:layout_marginBottom="16dp" >
+
+
+
+
-
+
+
+
+
+
+ android:text="@string/label_widget_text_color"
+ android:textSize="14sp" />
-
-
+ android:layout_marginTop="8dp"
+ android:layout_marginBottom="16dp" >
-
+
-
+
-
+
+
+
+
+
+
+
+
-
+
+
diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml
index ca5fac9..2cb5d4b 100644
--- a/app/src/main/res/values/colors.xml
+++ b/app/src/main/res/values/colors.xml
@@ -9,6 +9,12 @@
#FF7A7A7A
#FFA6A6A6
+
+ #FFFFFFFF
+ #B3FFFFFF
+ #FF000000
+ #99000000
+
@color/widget_bg_light
@color/widget_text_primary_light
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index e000315..2bd238e 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -66,6 +66,10 @@
White
Black
Wallpaper color
+ Text color
+ Follow background
+ White text
+ Black text
Save