隐藏“查看地图”; 自定义ArrowView的Text属性
| | |
| | | import android.os.Bundle; |
| | | import android.support.annotation.NonNull; |
| | | import android.support.annotation.Nullable; |
| | | import android.util.Log; |
| | | import android.widget.Toast; |
| | | |
| | | |
| | |
| | | |
| | | |
| | | |
| | | |
| | | 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()); |
| | | |
| | | } |
| | | }); |
| | | |
| | |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | protected void onDestroy() { |
| | | super.onDestroy(); |
| | | Log.i(TAG, "onDestroy: "); |
| | | } |
| | | |
| | | @Override |
| | | protected void onResume() { |
| | |
| | | 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; |
| | |
| | | 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; |
| | | |
| | | /** |
| | |
| | | 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 |
| | |
| | | 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字符串写入数据 |
| | |
| | | } catch (InterruptedException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | json.postValue("我爱你JetPack!!"); |
| | | |
| | | Log.i(TAG, "run: "+ atomicInteger.incrementAndGet()); |
| | | json.postValue("我爱你JetPack!!"+atomicInteger.get()); |
| | | } |
| | | }).start(); |
| | | } |
| | |
| | | <?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" |
| | |
| | | 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" |
| | |
| | | android:layout_width="80dp" |
| | | android:layout_height="80dp" |
| | | android:id="@+id/av3" |
| | | app:text="侧方停车" |
| | | android:layout_marginLeft="-15dp" |
| | | android:layout_toRightOf="@id/av2" |
| | | /> |
| | |
| | | android:layout_marginLeft="-15dp" |
| | | android:layout_toRightOf="@+id/av3" |
| | | android:id="@+id/av4" |
| | | app:text="坡道定点" |
| | | |
| | | /> |
| | | </RelativeLayout> |
| | |
| | | android:layout_height="wrap_content" |
| | | android:layout_weight="1" |
| | | android:text="查看地图" |
| | | android:visibility="gone" |
| | | android:textColor="@android:color/white"/> |
| | | </LinearLayout> |
| | | |
| | |
| | | <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> |