From ae292cb4f4a67e16465b732e26b408955b4407f5 Mon Sep 17 00:00:00 2001 From: endian11 <Dana_Lee1016@126.com> Date: 星期三, 11 九月 2019 11:22:27 +0800 Subject: [PATCH] 隐藏“查看地图”; 自定义ArrowView的Text属性 --- app/src/main/res/layout/layout_net_train_item.xml | 8 +++++++- app/src/main/java/safeluck/drive/evaluation/MainActivity.java | 12 +++++++++--- app/src/main/res/values/attrs.xml | 4 ++++ app/src/main/java/safeluck/drive/evaluation/viewmodels/MainViewModel.java | 9 ++++++++- app/src/main/java/safeluck/drive/evaluation/customview/ArrowView.java | 10 ++++++++-- app/src/main/res/layout/profile_layout.xml | 1 + 6 files changed, 37 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/safeluck/drive/evaluation/MainActivity.java b/app/src/main/java/safeluck/drive/evaluation/MainActivity.java index a8d8d37..0685da3 100644 --- a/app/src/main/java/safeluck/drive/evaluation/MainActivity.java +++ b/app/src/main/java/safeluck/drive/evaluation/MainActivity.java @@ -9,6 +9,7 @@ import android.os.Bundle; import android.support.annotation.NonNull; import android.support.annotation.Nullable; +import android.util.Log; import android.widget.Toast; @@ -63,14 +64,14 @@ - + MyLog.i(TAG,"onCreate"); MainViewModel mainViewModel = ViewModelProviders.of(this).get(MainViewModel.class); mainViewModel.getJson().observe(this, new Observer<String>() { @Override public void onChanged(@Nullable String json) { Toast.makeText(MainActivity.this, json, Toast.LENGTH_SHORT).show(); - MyLog.i(TAG,"json=========="+json); - MyLog.i(TAG,"json=========="+Thread.currentThread().getName()); + MyLog.i(TAG,"json=========="+json+" ThreadName:"+Thread.currentThread().getName()); + } }); @@ -81,6 +82,11 @@ } } + @Override + protected void onDestroy() { + super.onDestroy(); + Log.i(TAG, "onDestroy: "); + } @Override protected void onResume() { diff --git a/app/src/main/java/safeluck/drive/evaluation/customview/ArrowView.java b/app/src/main/java/safeluck/drive/evaluation/customview/ArrowView.java index e9b155b..426d708 100644 --- a/app/src/main/java/safeluck/drive/evaluation/customview/ArrowView.java +++ b/app/src/main/java/safeluck/drive/evaluation/customview/ArrowView.java @@ -1,6 +1,7 @@ package safeluck.drive.evaluation.customview; import android.content.Context; +import android.content.res.TypedArray; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; @@ -10,8 +11,10 @@ import android.text.StaticLayout; import android.text.TextPaint; import android.util.AttributeSet; +import android.util.TypedValue; import android.view.View; +import safeluck.drive.evaluation.R; import safeluck.drive.evaluation.util.Utils; /** @@ -31,15 +34,18 @@ private Path textPath = new Path(); public ArrowView(Context context) { - super(context); + this(context,null); } public ArrowView(Context context, @Nullable AttributeSet attrs) { - super(context, attrs); + this(context, attrs,0); } public ArrowView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); + TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ArrowView,defStyleAttr,0); + text = a.getString(R.styleable.ArrowView_text); + a.recycle(); } @Override diff --git a/app/src/main/java/safeluck/drive/evaluation/viewmodels/MainViewModel.java b/app/src/main/java/safeluck/drive/evaluation/viewmodels/MainViewModel.java index 44a397b..6276cde 100644 --- a/app/src/main/java/safeluck/drive/evaluation/viewmodels/MainViewModel.java +++ b/app/src/main/java/safeluck/drive/evaluation/viewmodels/MainViewModel.java @@ -4,10 +4,15 @@ import android.arch.lifecycle.LiveData; import android.arch.lifecycle.MutableLiveData; import android.arch.lifecycle.ViewModel; +import android.util.Log; + +import java.util.concurrent.atomic.AtomicInteger; import safeluck.drive.evaluation.util.MyLog; public class MainViewModel extends ViewModel { + private static final String TAG = "MainViewModel"; + AtomicInteger atomicInteger = new AtomicInteger(0); private MutableLiveData<String> json = new MutableLiveData<>(); public LiveData<String> getJson(){ //寰�json瀛楃涓插啓鍏ユ暟鎹� @@ -25,7 +30,9 @@ } catch (InterruptedException e) { e.printStackTrace(); } - json.postValue("鎴戠埍浣燡etPack锛侊紒"); + + Log.i(TAG, "run: "+ atomicInteger.incrementAndGet()); + json.postValue("鎴戠埍浣燡etPack锛侊紒"+atomicInteger.get()); } }).start(); } diff --git a/app/src/main/res/layout/layout_net_train_item.xml b/app/src/main/res/layout/layout_net_train_item.xml index a0aad0f..6e65d42 100644 --- a/app/src/main/res/layout/layout_net_train_item.xml +++ b/app/src/main/res/layout/layout_net_train_item.xml @@ -1,6 +1,8 @@ <?xml version="1.0" encoding="utf-8"?> <RelativeLayout - xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" + xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:app="http://schemas.android.com/apk/res-auto" + android:layout_width="match_parent" android:layout_height="wrap_content" android:padding="5dp" android:background="@color/train_item_bg" @@ -17,11 +19,13 @@ android:layout_height="80dp" android:layout_toRightOf="@+id/hv" android:id="@+id/av1" + app:text="鐩磋杞集" android:layout_marginLeft="-15dp" /> <safeluck.drive.evaluation.customview.ArrowView android:layout_width="80dp" android:layout_height="80dp" + app:text="鏇茬嚎琛岄┒" android:layout_marginLeft="-15dp" android:layout_toRightOf="@+id/av1" android:id="@+id/av2" @@ -30,6 +34,7 @@ android:layout_width="80dp" android:layout_height="80dp" android:id="@+id/av3" + app:text="渚ф柟鍋滆溅" android:layout_marginLeft="-15dp" android:layout_toRightOf="@id/av2" /> @@ -39,6 +44,7 @@ android:layout_marginLeft="-15dp" android:layout_toRightOf="@+id/av3" android:id="@+id/av4" + app:text="鍧¢亾瀹氱偣" /> </RelativeLayout> \ No newline at end of file diff --git a/app/src/main/res/layout/profile_layout.xml b/app/src/main/res/layout/profile_layout.xml index 9bc183f..3a545da 100644 --- a/app/src/main/res/layout/profile_layout.xml +++ b/app/src/main/res/layout/profile_layout.xml @@ -116,6 +116,7 @@ android:layout_height="wrap_content" android:layout_weight="1" android:text="鏌ョ湅鍦板浘" + android:visibility="gone" android:textColor="@android:color/white"/> </LinearLayout> diff --git a/app/src/main/res/values/attrs.xml b/app/src/main/res/values/attrs.xml index 8f59610..71c1330 100644 --- a/app/src/main/res/values/attrs.xml +++ b/app/src/main/res/values/attrs.xml @@ -6,4 +6,8 @@ <attr name="civ_border_overlay" format="boolean" /> <attr name="civ_fill_color" format="color" /> </declare-styleable> + <declare-styleable name="ArrowView"> + <attr name="text" format="string" /> + + </declare-styleable> </resources> \ No newline at end of file -- Gitblit v1.8.0