From e20862daf1e6c1dc3c7c4f53665908f801ef32f4 Mon Sep 17 00:00:00 2001 From: limqhz Date: Tue, 28 Jul 2020 21:13:18 +0800 Subject: [PATCH] SDGustInfo fixbug --- .../ydd/sportfaceid/main/SDBaseActivity.java | 2 - .../ydd/sportfaceid/view/SDGustInfoView.java | 80 +++++++------------ 2 files changed, 30 insertions(+), 52 deletions(-) diff --git a/app/src/main/java/com/ydd/sportfaceid/main/SDBaseActivity.java b/app/src/main/java/com/ydd/sportfaceid/main/SDBaseActivity.java index 91fba50..465117b 100644 --- a/app/src/main/java/com/ydd/sportfaceid/main/SDBaseActivity.java +++ b/app/src/main/java/com/ydd/sportfaceid/main/SDBaseActivity.java @@ -40,8 +40,6 @@ public class SDBaseActivity extends Activity { public void setContentView(View view, ViewGroup.LayoutParams params) { super.setContentView(view, params); ButterKnife.bind(this); -// ScreenAdapterTools.getInstance().loadView(getWindow().getDecorView()); - } @Override diff --git a/app/src/main/java/com/ydd/sportfaceid/view/SDGustInfoView.java b/app/src/main/java/com/ydd/sportfaceid/view/SDGustInfoView.java index e8a7cd8..dba6f20 100644 --- a/app/src/main/java/com/ydd/sportfaceid/view/SDGustInfoView.java +++ b/app/src/main/java/com/ydd/sportfaceid/view/SDGustInfoView.java @@ -1,6 +1,8 @@ package com.ydd.sportfaceid.view; import android.content.Context; +import android.os.Handler; +import android.os.Message; import android.support.annotation.Nullable; import android.util.AttributeSet; import android.view.LayoutInflater; @@ -19,10 +21,6 @@ import java.util.TimerTask; import butterknife.BindView; import butterknife.ButterKnife; -import rx.Observable; -import rx.Subscriber; -import rx.android.schedulers.AndroidSchedulers; -import rx.schedulers.Schedulers; /** * Created by sandershan on 2018/12/4. @@ -31,66 +29,49 @@ import rx.schedulers.Schedulers; public class SDGustInfoView extends RelativeLayout { public Context mContext; - - public static String mMemberName =""; - - @BindView(R.id.app_logo_imageview) - ImageView app_logo_imageview; - @BindView(R.id.time_label) TextView time_label; @BindView(R.id.date_label) TextView date_label; - private Timer mTimerOutput; + private Timer timer = new Timer(); + + Handler handler = new Handler(){ + + public void handleMessage(Message msg) { + switch (msg.what) { + case 1: + Date now_date = new Date(); + SimpleDateFormat time_format =new SimpleDateFormat("HH:mm"); + String time_string = time_format.format(now_date); + time_label.setText(time_string); + SimpleDateFormat date_format =new SimpleDateFormat("yyyy/MM/dd"); + String date_string = date_format.format(now_date); + String weak_string = TimeUntil.getWeakDay(now_date); + date_label.setText(date_string + " " + weak_string); + break; + } + super.handleMessage(msg); + } + + }; public SDGustInfoView(Context context, @Nullable AttributeSet attrs) { super(context, attrs); this.mContext = context; LayoutInflater.from(context).inflate(R.layout.layout_guest_info_top, this); ButterKnife.bind(this); - sdConfigData(); startRunUpdateTime(); } - public void sdConfigData(){ - Date now_date = new Date(); - SimpleDateFormat time_format =new SimpleDateFormat("HH:mm"); - String time_string = time_format.format(now_date); - time_label.setText(time_string); - SimpleDateFormat date_format =new SimpleDateFormat("yyyy/MM/dd"); - String date_string = date_format.format(now_date); - String weak_string = TimeUntil.getWeakDay(now_date); - date_label.setText(date_string + " " + weak_string); - } - public void startRunUpdateTime(){ - mTimerOutput = new Timer(); - mTimerOutput.schedule(new TimerTask() { + timer.schedule(new TimerTask() { @Override public void run() { //定时器,更新日志 - Observable.create(subscriber -> { - subscriber.onNext(null); - subscriber.onCompleted(); - }).subscribeOn(Schedulers.io()) - .observeOn(AndroidSchedulers.mainThread()).subscribe(new Subscriber() { - - @Override - public void onCompleted() { - - } - - @Override - public void onError(Throwable e) { - - } - - @Override - public void onNext(Object o) { - sdConfigData(); - } - }); + Message message = new Message(); + message.what = 1; + handler.sendMessage(message); } }, 100, 1000); } @@ -99,11 +80,10 @@ public class SDGustInfoView extends RelativeLayout { @Override protected void onDetachedFromWindow() { super.onDetachedFromWindow(); - if (mTimerOutput != null){ - this.mTimerOutput.cancel(); - this.mTimerOutput = null; + if (timer != null){ + this.timer.cancel(); + this.timer = null; } - } }