From f12beb03029e5beafdd32039ca43a6f5caa4d1b0 Mon Sep 17 00:00:00 2001 From: Nishith Khanna Date: Thu, 5 May 2022 13:13:04 +0530 Subject: [PATCH] Add support for auto adapt text color in light mode for widget --- .../e/drive/widgets/EDriveWidget.java | 32 +++- .../res/drawable/button_background_light.xml | 7 + .../main/res/layout/e_drive_widget_light.xml | 166 ++++++++++++++++++ .../res/layout/e_drive_widget_login_light.xml | 62 +++++++ app/src/main/res/values/colors.xml | 3 + 5 files changed, 265 insertions(+), 5 deletions(-) create mode 100644 app/src/main/res/drawable/button_background_light.xml create mode 100644 app/src/main/res/layout/e_drive_widget_light.xml create mode 100644 app/src/main/res/layout/e_drive_widget_login_light.xml diff --git a/app/src/main/java/foundation/e/drive/widgets/EDriveWidget.java b/app/src/main/java/foundation/e/drive/widgets/EDriveWidget.java index a9e5f292..34b8f719 100644 --- a/app/src/main/java/foundation/e/drive/widgets/EDriveWidget.java +++ b/app/src/main/java/foundation/e/drive/widgets/EDriveWidget.java @@ -26,6 +26,7 @@ import android.content.Intent; import android.net.ConnectivityManager; import android.net.Network; import android.net.Uri; +import android.os.Bundle; import android.provider.Settings; import android.view.View; import android.widget.RemoteViews; @@ -61,6 +62,9 @@ public class EDriveWidget extends AppWidgetProvider { private final SimpleDateFormat sdf = new SimpleDateFormat("HH:mm", Locale.getDefault()); private RemoteViews views; private Account account = null; + private static final String DARK_TEXT_KEY = "foundation.e.blisslauncher.WIDGET_OPTION_DARK_TEXT"; + private static boolean isDarkText = false; + public static String dataForWeb(Long bytes) { final String space = CommonUtils.humanReadableByteCountBin(bytes); @@ -148,7 +152,12 @@ public class EDriveWidget extends AppWidgetProvider { return; } - views = new RemoteViews(context.getPackageName(), R.layout.e_drive_widget_login); + if (isDarkText) { + views = new RemoteViews(context.getPackageName(), R.layout.e_drive_widget_login_light); + } else { + views = new RemoteViews(context.getPackageName(), R.layout.e_drive_widget_login); + } + Intent accountIntent = buildIntent("", "") .setComponent(new ComponentName(ACCOUNT_MANAGER_PACKAGE_NAME, GET_ACCOUNT_MANAGER_COMPONENT_NAME)) @@ -165,7 +174,11 @@ public class EDriveWidget extends AppWidgetProvider { private void noInternetView(Context context) { if (!isNetworkAvailable) { - views = new RemoteViews(context.getPackageName(), R.layout.e_drive_widget_login); + if (isDarkText) { + views = new RemoteViews(context.getPackageName(), R.layout.e_drive_widget_login_light); + } else { + views = new RemoteViews(context.getPackageName(), R.layout.e_drive_widget_login); + } views.setViewVisibility(R.id.button_container, View.GONE); views.setTextViewText(R.id.summary, context.getString(R.string.no_internet_widget)); } @@ -180,9 +193,11 @@ public class EDriveWidget extends AppWidgetProvider { noAccountView(context); return; } - - views = new RemoteViews(context.getPackageName(), R.layout.e_drive_widget); - + if (isDarkText) { + views = new RemoteViews(context.getPackageName(), R.layout.e_drive_widget_light); + } else { + views = new RemoteViews(context.getPackageName(), R.layout.e_drive_widget); + } views.setTextViewText(R.id.email, email); views.setTextViewText(R.id.name, accountManager.getUserData(account, ACCOUNT_DATA_NAME)); @@ -278,4 +293,11 @@ public class EDriveWidget extends AppWidgetProvider { } }); } + + @Override + public void onAppWidgetOptionsChanged(Context context, AppWidgetManager appWidgetManager, int appWidgetId, Bundle newOptions) { + super.onAppWidgetOptionsChanged(context, appWidgetManager, appWidgetId, newOptions); + isDarkText = newOptions.getBoolean(DARK_TEXT_KEY); + updateAppWidget(context); + } } \ No newline at end of file diff --git a/app/src/main/res/drawable/button_background_light.xml b/app/src/main/res/drawable/button_background_light.xml new file mode 100644 index 00000000..6a146ee3 --- /dev/null +++ b/app/src/main/res/drawable/button_background_light.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/e_drive_widget_light.xml b/app/src/main/res/layout/e_drive_widget_light.xml new file mode 100644 index 00000000..50e854bd --- /dev/null +++ b/app/src/main/res/layout/e_drive_widget_light.xml @@ -0,0 +1,166 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +