11package com .nitramite .apcupsdmonitor ;
22
3- import android .app .ActivityManager ;
43import android .app .PendingIntent ;
54import android .appwidget .AppWidgetManager ;
65import android .appwidget .AppWidgetProvider ;
76import android .content .ComponentName ;
87import android .content .Context ;
98import android .content .Intent ;
9+ import android .content .SharedPreferences ;
1010import android .graphics .Bitmap ;
1111import android .graphics .Canvas ;
1212import android .graphics .Matrix ;
13+ import android .preference .PreferenceManager ;
1314import android .util .Log ;
1415import android .view .LayoutInflater ;
1516import android .view .View ;
@@ -80,6 +81,9 @@ private ArrayList<UPS> getUpsData(DatabaseHelper databaseHelper) {
8081
8182
8283 private Bitmap createUpsViewBitmap (Context context , ArrayList <UPS > upsArrayList ) {
84+ SharedPreferences sharedPreferences = PreferenceManager .getDefaultSharedPreferences (context );
85+ boolean useDarkTheme = sharedPreferences .getBoolean (Constants .SP_USE_DARK_THEME , false );
86+
8387 LayoutInflater inflater = LayoutInflater .from (context );
8488
8589 LinearLayout mainLinearLayout = new LinearLayout (context );
@@ -89,7 +93,6 @@ private Bitmap createUpsViewBitmap(Context context, ArrayList<UPS> upsArrayList)
8993 );
9094 mainLinearLayout .setLayoutParams (layoutParams );
9195
92-
9396 for (int i = 0 ; i < upsArrayList .size (); i ++) {
9497 View inflatedLayout = inflater .inflate (R .layout .ups_item_widget , null , true );
9598 TextView upsName = inflatedLayout .findViewById (R .id .upsName );
@@ -108,6 +111,13 @@ private Bitmap createUpsViewBitmap(Context context, ArrayList<UPS> upsArrayList)
108111 CustomGauge chargePB = inflatedLayout .findViewById (R .id .chargePB );
109112 chargePB .setValue (upsArrayList .get (i ).getBatteryChargeLevelInteger ());
110113
114+ if (useDarkTheme ) {
115+ chargePB .setBackgroundColor (ContextCompat .getColor (context , R .color .widget_background ));
116+ percentageTv .setTextColor (ContextCompat .getColor (context , R .color .whiteColor ));
117+ } else {
118+ chargePB .setBackgroundColor (ContextCompat .getColor (context , R .color .whiteColor ));
119+ }
120+
111121 percentageTv .setText (upsArrayList .get (i ).getBatteryChargeLevelInteger () + "%" );
112122
113123 mainLinearLayout .addView (inflatedLayout );
@@ -140,19 +150,4 @@ private void setBitmap(RemoteViews views, int resId, Bitmap bitmap) {
140150 views .setImageViewBitmap (resId , proxy );
141151 }
142152
143-
144- // Check if service is running
145- private boolean isMyServiceRunning (Class <?> serviceClass , Context context ) {
146- ActivityManager manager = (ActivityManager ) context .getSystemService (Context .ACTIVITY_SERVICE );
147- if (manager != null ) {
148- for (ActivityManager .RunningServiceInfo service : manager .getRunningServices (Integer .MAX_VALUE )) {
149- if (serviceClass .getName ().equals (service .service .getClassName ())) {
150- return true ;
151- }
152- }
153- }
154- return false ;
155- }
156-
157-
158153} // End of class
0 commit comments