Quellcode durchsuchen

Added a ProgressBar

Thomas Chef vor 2 Jahren
Ursprung
Commit
ce37ea5979

+ 3 - 1
.idea/misc.xml

@@ -12,7 +12,9 @@
         <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.5" />
+        <entry key="app/src/main/res/layout/home_temp_app_widget.xml" value="1.0" />
+        <entry key="app/src/main/res/layout/home_temp_app_widget_old.xml" value="0.86875" />
+        <entry key="app/src/main/res/layout/home_temp_app_widget_v2.xml" value="1.121875" />
         <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>

+ 2 - 0
app/build.gradle

@@ -52,6 +52,8 @@ dependencies {
     implementation "androidx.appcompat:appcompat:$rootProject.appCompatVersion"
     implementation "androidx.activity:activity-ktx:$rootProject.activityVersion"
 
+    //implementation 'com.google.android.material:material:1.3.0-alpha02'
+
     // Room components
     implementation "androidx.room:room-ktx:$rootProject.roomVersion"
     kapt "androidx.room:room-compiler:$rootProject.roomVersion"

+ 2 - 0
app/src/main/java/com/flacksta/chef/journeygpstracker/HomeTempAppWidget.kt

@@ -9,6 +9,7 @@ import android.content.Context
 import android.content.Intent
 import android.graphics.Color
 import android.util.Log
+import android.view.View
 import android.widget.RemoteViews
 import androidx.core.content.ContextCompat.getSystemService
 
@@ -31,6 +32,7 @@ class HomeTempAppWidget : AppWidgetProvider() {
         for (widgetId in allWidgetIds!!) {
             Log.i("SERVICE", "Set gray")
             remoteViews.setTextColor(R.id.appwidget_text, Color.LTGRAY)
+            remoteViews.setViewVisibility(R.id.progressBar, View.VISIBLE)
             appWidgetManager.updateAppWidget(widgetId, remoteViews)
         }
 

+ 5 - 0
app/src/main/java/com/flacksta/chef/journeygpstracker/UpdateWidgetService.kt

@@ -8,10 +8,12 @@ import android.content.Intent
 import android.graphics.Color
 import android.os.IBinder
 import android.util.Log
+import android.view.View
 import android.widget.RemoteViews
 import com.android.volley.Request
 import com.android.volley.toolbox.StringRequest
 import com.android.volley.toolbox.Volley
+import kotlin.concurrent.thread
 
 
 class UpdateWidgetService : Service() {
@@ -30,6 +32,8 @@ class UpdateWidgetService : Service() {
         val queue = Volley.newRequestQueue(this)
         val url = "http://www.flacksta.com/info/curr_temp.php"
 
+        Thread.sleep(1000)
+
         // Request a string response from the provided URL.
         val stringRequest = StringRequest(
             Request.Method.GET, url,
@@ -38,6 +42,7 @@ class UpdateWidgetService : Service() {
                 for (widgetId in allWidgetIds) {
                     remoteViews.setTextViewText(R.id.appwidget_text,"$response \u2103")
                     remoteViews.setTextColor(R.id.appwidget_text, Color.BLACK)
+                    remoteViews.setViewVisibility(R.id.progressBar, View.INVISIBLE)
                     appWidgetManager.updateAppWidget(widgetId, remoteViews)
                 }
             },

+ 0 - 4
app/src/main/res/drawable/my_backgrnd_shape.xml

@@ -6,10 +6,6 @@
         android:color="#FFDDDDDD"
         />
 
-    <!--<stroke
-        android:width="10dp"
-        android:color="#FF0000FF" /> -->
-
     <corners
         android:bottomLeftRadius="14dp"
         android:bottomRightRadius="14dp"

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

@@ -1,16 +1,30 @@
 <?xml version="1.0" encoding="utf-8"?>
-<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:id="@+id/layout"
     android:layout_width="match_parent"
-    android:layout_height="match_parent"
-    android:orientation="vertical"
-    android:layout_margin="0dp">
+    android:layout_height="match_parent">
+
+    <ProgressBar
+        android:id="@+id/progressBar"
+        android:indeterminate="false"
+        android:max="0"
+        android:layout_width="25dp"
+        android:layout_height="25dp"
+        android:layout_alignBottom="@+id/text_layout"
+        android:layout_marginBottom="5dp"
+        android:layout_marginEnd="5dp"
+        android:layout_alignParentEnd="true"
+        android:elevation="1dp"
+ />
 
     <LinearLayout
-        android:orientation="vertical"
+        android:id="@+id/text_layout"
         android:layout_width="match_parent"
         android:layout_height="69dp"
-        android:background="@drawable/my_backgrnd_shape">
+        android:layout_alignParentTop="true"
+        android:layout_marginTop="0dp"
+        android:background="@drawable/my_background_shape"
+        android:orientation="horizontal">
 
         <TextView
             android:id="@+id/appwidget_text"
@@ -18,16 +32,17 @@
             android:layout_width="match_parent"
             android:layout_height="match_parent"
             android:layout_gravity="center"
-            android:layout_margin="0dip"
+            android:layout_marginStart="0dip"
+            android:layout_marginTop="0dip"
+            android:layout_marginEnd="0dip"
+            android:layout_marginBottom="0dip"
             android:gravity="center_horizontal|center_vertical"
-            android:text="Text"
-            android:textSize="28dp"
+            android:text="@string/widget_default_text"
             android:textColor="@color/black"
-            android:textStyle="bold">
-        </TextView>
+            android:textSize="28sp"
+            android:textStyle="bold" />
     </LinearLayout>
 
 
 
-
-</LinearLayout>
+    </RelativeLayout>

+ 1 - 0
app/src/main/res/values/strings.xml

@@ -9,4 +9,5 @@
     <string name="appwidget_text">GHI</string>
     <string name="add_widget">Add widget</string>
     <string name="app_widget_description">Widget that shows outside temp at your home</string>
+    <string name="widget_default_text">Text</string>
 </resources>