Эх сурвалжийг харах

历史轨迹页添加地址显示

carlos 11 сар өмнө
parent
commit
a4b48de1f4

+ 69 - 1
app/src/main/java/com/sikey/veryfit/ui/avtivity/component/path/MDPathHistoryActivity.kt

@@ -5,6 +5,7 @@ import android.app.Activity
 import android.content.Intent
 import android.os.Bundle
 import android.os.Message
+import android.util.Log
 import android.view.Menu
 import android.view.MenuItem
 import android.view.View
@@ -17,6 +18,7 @@ import androidx.fragment.app.FragmentTransaction
 import androidx.lifecycle.lifecycleScope
 import androidx.recyclerview.widget.LinearLayoutManager
 import androidx.recyclerview.widget.RecyclerView
+import com.android.volley.toolbox.StringRequest
 import com.google.android.gms.maps.CameraUpdateFactory
 import com.google.android.gms.maps.GoogleMap
 import com.google.android.gms.maps.OnMapReadyCallback
@@ -37,24 +39,33 @@ import com.sikey.veryfit.app.DataManager.Companion.checkLoginResponseAndCurrentC
 import com.sikey.veryfit.component.VersionMatch.VersionMatch
 import com.sikey.veryfit.component.handler.WeakReferenceHandler
 import com.sikey.veryfit.component.log.Logger
+import com.sikey.veryfit.component.network.RequestManager
 import com.sikey.veryfit.component.network.http.HttpServiceExecutor
 import com.sikey.veryfit.component.network.http.LocationService
 import com.sikey.veryfit.component.network.http.RetrofitFactory
+import com.sikey.veryfit.component.network.http.model.ChildInfo
 import com.sikey.veryfit.component.network.http.model.HistoryLocationRepo
 import com.sikey.veryfit.component.network.http.model.Location
+import com.sikey.veryfit.constant.UrlConstants
 import com.sikey.veryfit.data.bean.PathTraceBean
 import com.sikey.veryfit.k2.entity.DateBean
 import com.sikey.veryfit.k2.ui.settings.LocationSettingActivity
 import com.sikey.veryfit.k2.utils.FormatUtils
+import com.sikey.veryfit.k2.utils.TextUtils
 import com.sikey.veryfit.ui.adapter.DateAdapter
 import com.sikey.veryfit.ui.avtivity.base.BaseNoActionBarActivity
 import com.sikey.veryfit.ui.avtivity.component.path.MDPathHistoryActivity
+import com.sikey.veryfit.ui.fragment.avatar.ChildInfoPageFragment
+import com.sikey.veryfit.ui.fragment.avatar.ChildInfoPageFragment.Companion
 import com.sikey.veryfit.ui.fragment.path.TrackSeekBarFragment
 import com.sikey.veryfit.utils.ResUtils
 import com.sikey.veryfit.utils.ToastUtils
 import kotlinx.coroutines.Dispatchers
 import kotlinx.coroutines.delay
 import kotlinx.coroutines.launch
+import org.json.JSONArray
+import org.json.JSONException
+import org.json.JSONObject
 import java.text.SimpleDateFormat
 import java.util.Calendar
 import java.util.Date
@@ -135,6 +146,7 @@ class MDPathHistoryActivity : BaseNoActionBarActivity(), View.OnClickListener,
         val today = Date(System.currentTimeMillis())
         //mChosenDate=today;
         startToSubmit(today)
+//        getGeoAdress()
     }
 
     private fun startToSubmit(startDay: Date) {
@@ -582,6 +594,59 @@ class MDPathHistoryActivity : BaseNoActionBarActivity(), View.OnClickListener,
         map!!.animateCamera(CameraUpdateFactory.newCameraPosition(position))
     }
 
+    private fun getGeoAdress() {
+        Logger.d(TAG, "getGeoAdress")
+        if (mCurrentBeanList == null || mCurrentBeanList!!.isEmpty() || mCurrentBeanList!!.size < mCurrentProgress || mCurrentProgress < 1) {
+            return
+        }
+        if (mCurrentMarker != null) {
+            mCurrentMarker!!.remove()
+        }
+        val bean = mCurrentBeanList!![mCurrentProgress - 1]
+        val latlng = bean.lat + "," + bean.lng
+        Log.d(
+            TAG,
+            "url = " + UrlConstants.GOOGLE_GEO_ADRESS + "?latlng=" + latlng + getString(R.string.param_google_maps_key)
+        )
+        val request = StringRequest(
+            UrlConstants.GOOGLE_GEO_ADRESS + "?latlng=" + latlng + getString(R.string.param_google_maps_key),
+            { response ->
+                try {
+//                    Log.d(TAG, "response=$response")
+                    val jsonObject = JSONObject(response)
+                    val status = jsonObject.getString("status")
+                    Log.d(TAG, "status=$status")
+                    if ("OK" == status) {
+                        val results = jsonObject.getString("results")
+                        val jsonArray = JSONArray(results)
+                        val length = jsonArray.length()
+                        Logger.d(TAG, "jsonArray.length(): " + jsonArray.length())
+                        for (i in 0 until length) {
+                            val jsonObject2 = jsonArray.getJSONObject(i)
+                            val formatted_address = jsonObject2.getString("formatted_address")
+                            Logger.i(TAG, "formatted_address: $formatted_address")
+                            if (i == 0) {
+
+                                var mAddressStr = formatted_address
+                                if (TextUtils.isEmpty(mAddressStr)) {
+                                    mAddressStr = resources.getString(R.string.locating_tip)
+                                }
+                                mTrackSeekBarFrag?.setAddress(mAddressStr)
+                                break
+                            }
+                        }
+                    }
+                } catch (e: JSONException) {
+                    e.printStackTrace()
+                }
+            }) { error ->
+            Logger.i(TAG, "add err==" + error.message)
+            /* ToastUtils.showLongToast(R.string.network_exception) */
+        }
+        RequestManager.getInstance(this).addToRequestQueue(request)
+    }
+
+    private var inited = false
     //another useful function is that inner class could implements all the interfaces that outter class do not want to implements
     //In this way, the code will be elegant and tidy
     private inner class TrackSeekBarManager : OnSeekBarChangeListener {
@@ -589,10 +654,13 @@ class MDPathHistoryActivity : BaseNoActionBarActivity(), View.OnClickListener,
             Logger.d(TAG, "progress:$progress")
             mCurrentProgress = progress + 1
             refreshChosenMarkerAndPositionDetail()
+            if(progress == 0 && !inited) getGeoAdress()
         }
 
         override fun onStartTrackingTouch(seekBar: SeekBar) {}
-        override fun onStopTrackingTouch(seekBar: SeekBar) {}
+        override fun onStopTrackingTouch(seekBar: SeekBar) {
+            getGeoAdress()
+        }
     }
 
     ///////////////////////////////////////////////////////////////

+ 4 - 0
app/src/main/java/com/sikey/veryfit/ui/fragment/path/TrackSeekBarFragment.kt

@@ -44,6 +44,10 @@ class TrackSeekBarFragment : Fragment() {
         mOnSeekBarChangeListener = listener
     }
 
+    fun setAddress(address:String) {
+        mPositon?.text = address
+    }
+
     override fun onCreate(savedInstanceState: Bundle?) {
         super.onCreate(savedInstanceState)
         if (this.arguments != null) {

+ 46 - 46
app/src/main/res/layout/track_seekbar_layout.xml

@@ -1,14 +1,10 @@
 <?xml version="1.0" encoding="utf-8"?>
 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
-    android:orientation="vertical"
-    android:padding="@dimen/left_menu_left_margin"
-    android:background="@color/white"
     android:layout_width="match_parent"
-    android:layout_height="120dp">
-
-
-
-
+    android:layout_height="120dp"
+    android:background="@color/white"
+    android:orientation="vertical"
+    android:padding="@dimen/left_menu_left_margin">
 
     <RelativeLayout
         android:id="@+id/lyt_detial"
@@ -24,49 +20,52 @@
                 android:id="@+id/lyt_time"
                 android:layout_width="match_parent"
                 android:layout_height="wrap_content">
+
                 <TextView
                     android:id="@+id/tv_time"
                     android:layout_width="wrap_content"
                     android:layout_height="wrap_content"
-                    android:textSize="22sp"
                     android:textColor="@color/dark"
-                    android:textStyle="bold"/>
+                    android:textSize="22sp"
+                    android:textStyle="bold" />
+
                 <TextView
                     android:id="@+id/tv_date"
                     android:layout_width="wrap_content"
                     android:layout_height="wrap_content"
-                    android:textColor="@color/gray_60"
-                    android:fontFamily="sans-serif-medium"
                     android:layout_marginLeft="@dimen/space_value_small"
-                    android:textSize="14sp"/>
+                    android:fontFamily="sans-serif-medium"
+                    android:textColor="@color/gray_60"
+                    android:textSize="14sp" />
 
                 <TextView
                     android:id="@+id/tv_accuracy"
                     android:layout_width="wrap_content"
                     android:layout_height="wrap_content"
+                    android:layout_gravity="center"
                     android:layout_marginLeft="@dimen/space_value_small"
-                    android:textSize="10sp"
-                    android:textColor="@color/gray_40"
+                    android:background="@drawable/bg_text_gray"
                     android:gravity="center"
-                    android:paddingTop="3dp"
-                    android:paddingBottom="3dp"
                     android:paddingLeft="10dp"
+                    android:paddingTop="3dp"
                     android:paddingRight="10dp"
-                    android:layout_gravity="center"
-                    android:background="@drawable/bg_text_gray"/>
+                    android:paddingBottom="3dp"
+                    android:textColor="@color/gray_40"
+                    android:textSize="10sp" />
+
                 <ImageView
                     android:id="@+id/tv_localType"
                     android:layout_width="wrap_content"
                     android:layout_height="wrap_content"
+                    android:layout_gravity="center"
                     android:layout_marginStart="@dimen/space_value_small"
+                    android:background="@drawable/bg_text_gray"
                     android:gravity="center"
-                    android:paddingTop="3dp"
-                    android:paddingBottom="3dp"
                     android:paddingLeft="10dp"
+                    android:paddingTop="3dp"
                     android:paddingRight="10dp"
-                    android:layout_gravity="center"
-                    android:src="@drawable/ic_location_gps"
-                    android:background="@drawable/bg_text_gray"/>
+                    android:paddingBottom="3dp"
+                    android:src="@drawable/ic_location_gps" />
             </LinearLayout>
 
 
@@ -74,7 +73,7 @@
                 android:id="@+id/tv_position"
                 android:layout_width="match_parent"
                 android:layout_height="wrap_content"
-                android:layout_below="@id/lyt_time"/>
+                android:layout_below="@id/lyt_time" />
 
         </RelativeLayout>
 
@@ -82,12 +81,12 @@
             android:id="@+id/tv_current"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
-            android:layout_centerVertical="true"
-            android:textSize="17sp"
             android:layout_alignBottom="@+id/tv_max"
+            android:layout_centerVertical="true"
             android:layout_toLeftOf="@+id/tv_max"
             android:fontFamily="sans-serif-medium"
-            android:textColor="@color/gray_60"/>
+            android:textColor="@color/gray_60"
+            android:textSize="17sp" />
 
         <TextView
             android:id="@+id/tv_max"
@@ -95,32 +94,33 @@
             android:layout_height="wrap_content"
             android:layout_alignParentRight="true"
             android:layout_centerVertical="true"
-            android:paddingBottom="2dp"
-            android:textSize="10sp"
             android:fontFamily="sans-serif-medium"
-            android:textColor="@color/gray_40"/>
+            android:paddingBottom="2dp"
+            android:textColor="@color/gray_40"
+            android:textSize="10sp" />
     </RelativeLayout>
 
     <RelativeLayout
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:layout_below="@+id/lyt_detial">
+
         <ImageView
             android:id="@+id/leftForwardsImageView"
-            android:src="@drawable/k2_app_homepage_left_normal"
-            android:layout_centerVertical="true"
-            android:visibility="gone"
             android:layout_width="30dp"
-            android:layout_height="30dp" />
+            android:layout_height="30dp"
+            android:layout_centerVertical="true"
+            android:src="@drawable/k2_app_homepage_left_normal"
+            android:visibility="gone" />
 
         <ImageView
             android:id="@+id/rightForwardsImageView"
+            android:layout_width="30dp"
+            android:layout_height="30dp"
             android:layout_alignParentRight="true"
             android:layout_centerVertical="true"
-            android:visibility="gone"
             android:src="@drawable/k2_app_homepage_right_normal"
-            android:layout_width="30dp"
-            android:layout_height="30dp" />
+            android:visibility="gone" />
 
 
         <SeekBar
@@ -128,25 +128,25 @@
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
             android:layout_alignTop="@+id/leftForwardsImageView"
-            android:layout_centerHorizontal="true"
-            />
+            android:layout_centerHorizontal="true" />
     </RelativeLayout>
 
 
     <RelativeLayout
         android:id="@+id/lyt_empty"
-        android:visibility="gone"
-        android:background="@color/white"
         android:layout_width="match_parent"
-        android:layout_height="match_parent">
+        android:layout_height="match_parent"
+        android:background="@color/white"
+        android:visibility="gone">
+
         <TextView
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:layout_centerInParent="true"
-            android:textColor="@color/gray_60"
             android:fontFamily="sans-serif-medium"
-            android:textSize="@dimen/text_size_mediumMore"
-            android:text="@string/no_track"/>
+            android:text="@string/no_track"
+            android:textColor="@color/gray_60"
+            android:textSize="@dimen/text_size_mediumMore" />
     </RelativeLayout>