浏览代码

Works and looks good

Thomas Chef 2 年之前
父节点
当前提交
11ce9db44b

+ 1 - 1
.idea/misc.xml

@@ -12,7 +12,7 @@
         <entry key="app/src/main/res/layout/fragment_home.xml" value="0.3098958333333333" />
         <entry key="app/src/main/res/layout/fragment_map.xml" value="0.3098958333333333" />
         <entry key="app/src/main/res/layout/fragment_settings.xml" value="0.29583333333333334" />
-        <entry key="app/src/main/res/layout/home_temp_app_widget.xml" value="0.71875" />
+        <entry key="app/src/main/res/layout/home_temp_app_widget.xml" value="0.5" />
         <entry key="app/src/main/res/layout/widget_layout.xml" value="0.1890625" />
         <entry key="app/src/main/res/menu/bottom_nav_menu.xml" value="0.25" />
       </map>

+ 16 - 8
app/src/main/java/com/flacksta/chef/journeygpstracker/UpdateWidgetService.kt

@@ -5,11 +5,11 @@ import android.app.PendingIntent
 import android.app.Service
 import android.appwidget.AppWidgetManager
 import android.content.Intent
+import android.graphics.Color
 import android.os.IBinder
 import android.util.Log
 import android.widget.RemoteViews
 import com.android.volley.Request
-import com.android.volley.Response
 import com.android.volley.toolbox.StringRequest
 import com.android.volley.toolbox.Volley
 
@@ -22,23 +22,31 @@ class UpdateWidgetService : Service() {
 
         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)
+        }
+
+
         val queue = Volley.newRequestQueue(this)
-        val url = "http://chef.maya.se/info/curr_temp.php"
+        val url = "http://www.flacksta.com/info/curr_temp.php"
 
         // Request a string response from the provided URL.
         val stringRequest = StringRequest(
             Request.Method.GET, url,
-            Response.Listener<String> { response ->
+            { response ->
                 Log.i("SERVICE", "Response is: $response")
-                for (widgetId in allWidgetIds!!) {
+                for (widgetId in allWidgetIds) {
                     remoteViews.setTextViewText(R.id.appwidget_text,"$response \u2103")
+                    remoteViews.setTextColor(R.id.appwidget_text, Color.BLACK)
                     appWidgetManager.updateAppWidget(widgetId, remoteViews)
                 }
             },
-            Response.ErrorListener {
+            {
                 Log.i("SERVICE", "That didn't work!" )
-                for (widgetId in allWidgetIds!!) {
-                    remoteViews.setTextViewText(R.id.appwidget_text,"ERR")
+                for (widgetId in allWidgetIds) {
+                    remoteViews.setTextViewText(R.id.appwidget_text,"Error")
                     appWidgetManager.updateAppWidget(widgetId, remoteViews)
                 }
             }
@@ -46,7 +54,7 @@ class UpdateWidgetService : Service() {
 
         queue.add(stringRequest)
 
-        for (widgetId in allWidgetIds!!) {
+        for (widgetId in allWidgetIds) {
 
             val clickIntent = Intent(this.applicationContext,HomeTempAppWidget::class.java )
             clickIntent.action = AppWidgetManager.ACTION_APPWIDGET_UPDATE

+ 7 - 8
app/src/main/res/drawable/my_backgrnd_shape.xml

@@ -4,17 +4,16 @@
 
     <solid
         android:color="#FFDDDDDD"
-        android:height="30dp"
         />
 
-    <stroke
-        android:width="30dp"
-        android:color="#00CCAACC" />
+    <!--<stroke
+        android:width="10dp"
+        android:color="#FF0000FF" /> -->
 
     <corners
-        android:bottomLeftRadius="10dp"
-        android:bottomRightRadius="10dp"
-        android:topLeftRadius="10dp"
-        android:topRightRadius="10dp" />
+        android:bottomLeftRadius="14dp"
+        android:bottomRightRadius="14dp"
+        android:topLeftRadius="14dp"
+        android:topRightRadius="14dp" />
 
 </shape>

+ 25 - 13
app/src/main/res/layout/home_temp_app_widget.xml

@@ -2,20 +2,32 @@
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:id="@+id/layout"
     android:layout_width="match_parent"
-    android:layout_height="90dp"
-    android:layout_margin="20dip"
-    android:background="@drawable/my_backgrnd_shape">
+    android:layout_height="match_parent"
+    android:orientation="vertical"
+    android:layout_margin="0dp">
 
-    <TextView
-        android:id="@+id/appwidget_text"
-        style="@android:style/TextAppearance.Medium"
+    <LinearLayout
+        android:orientation="vertical"
         android:layout_width="match_parent"
-        android:layout_height="match_parent"
-        android:layout_gravity="center"
-        android:layout_margin="4dip"
-        android:gravity="center_horizontal|center_vertical"
-        android:text="Text"
-        android:textSize="28dp"
-        android:textStyle="bold"></TextView>
+        android:layout_height="69dp"
+        android:background="@drawable/my_backgrnd_shape">
+
+        <TextView
+            android:id="@+id/appwidget_text"
+            style="@android:style/TextAppearance.Medium"
+            android:layout_width="match_parent"
+            android:layout_height="match_parent"
+            android:layout_gravity="center"
+            android:layout_margin="0dip"
+            android:gravity="center_horizontal|center_vertical"
+            android:text="Text"
+            android:textSize="28dp"
+            android:textColor="@color/black"
+            android:textStyle="bold">
+        </TextView>
+    </LinearLayout>
+
+
+
 
 </LinearLayout>

+ 4 - 4
app/src/main/res/xml/home_temp_app_widget_info.xml

@@ -1,10 +1,10 @@
 <?xml version="1.0" encoding="utf-8"?>
 <appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
     android:initialLayout="@layout/home_temp_app_widget"
-    android:minWidth="130dp"
-    android:minHeight="62dp"
+    android:minWidth="100dp"
+    android:minHeight="50dp"
+    android:targetCellWidth="2"
+    android:targetCellHeight="1"
     android:updatePeriodMillis="1800000"
-
-
     android:widgetCategory="home_screen"
 />