浏览代码

Switch color on text quicker when updating by click.

Thomas Chef 2 年之前
父节点
当前提交
8f02ea8520

+ 10 - 1
app/src/main/java/com/flacksta/chef/journeygpstracker/HomeTempAppWidget.kt

@@ -7,7 +7,9 @@ import android.appwidget.AppWidgetProvider
 import android.content.ComponentName
 import android.content.Context
 import android.content.Intent
+import android.graphics.Color
 import android.util.Log
+import android.widget.RemoteViews
 import androidx.core.content.ContextCompat.getSystemService
 
 
@@ -24,6 +26,14 @@ class HomeTempAppWidget : AppWidgetProvider() {
 
         val thisWidget = ComponentName(context,HomeTempAppWidget::class.java)
         val allWidgetIds = appWidgetManager.getAppWidgetIds(thisWidget)
+        val remoteViews = RemoteViews(context.packageName,  R.layout.home_temp_app_widget )
+
+        for (widgetId in allWidgetIds!!) {
+            Log.i("SERVICE", "Set gray")
+            remoteViews.setTextColor(R.id.appwidget_text, Color.LTGRAY)
+            appWidgetManager.updateAppWidget(widgetId, remoteViews)
+        }
+
 
         // Build the intent to call the service
         val intent = Intent(context.applicationContext,UpdateWidgetService::class.java)
@@ -31,7 +41,6 @@ class HomeTempAppWidget : AppWidgetProvider() {
 
         // Update the widgets via the service
         context.startService(intent);
-
     }
 
 

+ 4 - 7
app/src/main/java/com/flacksta/chef/journeygpstracker/UpdateWidgetService.kt

@@ -20,14 +20,12 @@ class UpdateWidgetService : Service() {
         val appWidgetManager = AppWidgetManager.getInstance(this.applicationContext)
         val allWidgetIds = intent.getIntArrayExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS)
 
-        val remoteViews = RemoteViews(this.applicationContext.packageName,  R.layout.home_temp_app_widget )
-
-        for (widgetId in allWidgetIds!!) {
-            Log.i("SERVICE", "Set gray")
-            remoteViews.setTextColor(R.id.appwidget_text, Color.DKGRAY)
-            appWidgetManager.updateAppWidget(widgetId, remoteViews)
+        if( allWidgetIds == null ) {
+            stopSelf()
+            return
         }
 
+        val remoteViews = RemoteViews(this.applicationContext.packageName,  R.layout.home_temp_app_widget )
 
         val queue = Volley.newRequestQueue(this)
         val url = "http://www.flacksta.com/info/curr_temp.php"
@@ -67,7 +65,6 @@ class UpdateWidgetService : Service() {
         }
 
         stopSelf()
-        super.onStart(intent, startId)
     }
 
     override fun onBind(intent: Intent): IBinder? {