ADD: Dark mode for Android price widget

This commit is contained in:
Marcos Rodriguez Velez 2024-06-09 10:27:53 -04:00 committed by Overtorment
parent e3d46c496c
commit 56cc14e4a7
6 changed files with 29 additions and 25 deletions

View file

@ -14,8 +14,6 @@ import android.view.View;
import android.widget.RemoteViews;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatDelegate;
import java.text.NumberFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
@ -153,20 +151,6 @@ public class BitcoinPriceWidget extends AppWidgetProvider {
String currentTime = new SimpleDateFormat("hh:mm a", Locale.getDefault()).format(new Date());
views.setTextViewText(R.id.last_updated, "Last Updated");
views.setTextViewText(R.id.last_updated_time, currentTime);
if (AppCompatDelegate.getDefaultNightMode() == AppCompatDelegate.MODE_NIGHT_YES) {
views.setTextColor(R.id.last_updated, context.getResources().getColor(android.R.color.white));
views.setTextColor(R.id.last_updated_time, context.getResources().getColor(android.R.color.white));
views.setTextColor(R.id.price_value, context.getResources().getColor(android.R.color.white));
views.setTextColor(R.id.previous_price, context.getResources().getColor(android.R.color.white));
views.setInt(R.id.widget_layout, "setBackgroundColor", context.getResources().getColor(android.R.color.black));
} else {
views.setTextColor(R.id.last_updated, context.getResources().getColor(android.R.color.black));
views.setTextColor(R.id.last_updated_time, context.getResources().getColor(android.R.color.black));
views.setTextColor(R.id.price_value, context.getResources().getColor(android.R.color.black));
views.setTextColor(R.id.previous_price, context.getResources().getColor(android.R.color.black));
views.setInt(R.id.widget_layout, "setBackgroundColor", context.getResources().getColor(android.R.color.white));
}
} else {
String errorMessage = "Network Error";
Log.e(TAG, errorMessage);

View file

@ -5,7 +5,7 @@
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="8dp"
android:background="@android:color/white">
android:background="@color/widget_background">
<LinearLayout
android:layout_width="match_parent"
@ -15,21 +15,21 @@
<TextView
android:id="@+id/last_updated"
style="@style/WidgetTextSecondary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textSize="12sp"
android:textStyle="bold"
android:textColor="@android:color/black"
android:layout_marginEnd="8dp"/>
<TextView
android:id="@+id/last_updated_time"
style="@style/WidgetTextPrimary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textSize="12sp"
android:textColor="@android:color/black"
android:layout_marginEnd="8dp"
android:layout_marginTop="2dp"/>
</LinearLayout>
@ -42,12 +42,12 @@
<TextView
android:id="@+id/price_value"
style="@style/WidgetTextPrimary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textSize="24sp"
android:textStyle="bold"
android:textColor="@android:color/black"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"/>
@ -67,11 +67,11 @@
<TextView
android:id="@+id/previous_price"
style="@style/WidgetTextPrimary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textSize="12sp"
android:textColor="@android:color/black"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"/>
</LinearLayout>

View file

@ -1,4 +1,7 @@
<resources>
<color name="background_color">#000000</color> <!-- Dark background -->
<color name="background_color">#000000</color>
<color name="widget_background">#1B1B1F</color>
<color name="text_primary">#FFFFFF</color>
<color name="text_secondary">#D3D3D3</color>
</resources>

View file

@ -0,0 +1,9 @@
<resources>
<style name="WidgetTextPrimary">
<item name="android:textColor">@color/text_primary</item>
</style>
<style name="WidgetTextSecondary">
<item name="android:textColor">@color/text_secondary</item>
</style>
</resources>

View file

@ -1,4 +1,7 @@
<resources>
<color name="white">#FFF</color>
<color name="background_color">#FFFFFF</color> <!-- Light background -->
<color name="background_color">#FFFFFF</color>
<color name="widget_background">#FFFFFF</color>
<color name="text_primary">#0C234F</color>
<color name="text_secondary">#D3D3D3</color>
</resources>

View file

@ -1,9 +1,14 @@
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.DayNight.NoActionBar">
<!-- Customize your theme here. -->
<item name="android:editTextBackground">@drawable/rn_edit_text_material</item>
</style>
<style name="WidgetTextPrimary">
<item name="android:textColor">@color/text_primary</item>
</style>
</resources>
<style name="WidgetTextSecondary">
<item name="android:textColor">@color/text_secondary</item>
</style>
</resources>