From 66c223e3528c1586cceafae7dddda1538132a9c0 Mon Sep 17 00:00:00 2001 From: wangmingjun Date: Thu, 26 May 2022 16:27:10 +0800 Subject: [PATCH] =?UTF-8?q?[taxi/bus-d=20270]=20bus/taxi=20=E4=B9=98?= =?UTF-8?q?=E5=AE=A2=E5=B1=8F=E7=BA=A2=E8=B7=AF=E7=81=AF=E6=97=A0=E5=80=92?= =?UTF-8?q?=E8=AE=A1=E6=97=B6UI=E6=A0=B7=E5=BC=8F=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ui/BusPassengerTrafficLightView.java | 36 ++++++++++++++++++ .../res/layout/bus_p_traffic_light_view.xml | 1 + .../ui/TaxiPassengerTrafficLightView.java | 38 +++++++++++++++++-- .../res/layout/taxi_p_traffic_light_view.xml | 1 + 4 files changed, 73 insertions(+), 3 deletions(-) diff --git a/OCH/mogo-och-bus-passenger/src/main/java/com/mogo/och/bus/passenger/ui/BusPassengerTrafficLightView.java b/OCH/mogo-och-bus-passenger/src/main/java/com/mogo/och/bus/passenger/ui/BusPassengerTrafficLightView.java index 16cda08315..4c75d3d6b3 100644 --- a/OCH/mogo-och-bus-passenger/src/main/java/com/mogo/och/bus/passenger/ui/BusPassengerTrafficLightView.java +++ b/OCH/mogo-och-bus-passenger/src/main/java/com/mogo/och/bus/passenger/ui/BusPassengerTrafficLightView.java @@ -3,6 +3,7 @@ package com.mogo.och.bus.passenger.ui; import android.content.Context; import android.util.AttributeSet; import android.view.LayoutInflater; +import android.view.ViewGroup; import android.widget.ImageView; import android.widget.TextView; @@ -22,6 +23,7 @@ public class BusPassengerTrafficLightView extends IViewTrafficLight { private ImageView mLightIconIV; private TextView mLightTimeTV; private int mCurrentLightId; + private ImageView mLightIconBG; public BusPassengerTrafficLightView(@Nullable Context context) { this(context, null, 0); @@ -40,6 +42,7 @@ public class BusPassengerTrafficLightView extends IViewTrafficLight { LayoutInflater.from(context).inflate(R.layout.bus_p_traffic_light_view, this, true); mLightIconIV = findViewById(R.id.bus_p_traffic_light_iv); mLightTimeTV = findViewById(R.id.bus_p_traffic_light_time_tv); + mLightIconBG = findViewById(R.id.bus_p_traffic_light_bg); } /** @@ -74,6 +77,7 @@ public class BusPassengerTrafficLightView extends IViewTrafficLight { @Override public void changeCountdownTrafficLightNum(int redNum, int yellowNum, int greenNum) { super.changeCountdownTrafficLightNum(redNum, yellowNum, greenNum); + resetView(); switch (mCurrentLightId) { case 1: changeCountdownRed(redNum); @@ -97,8 +101,10 @@ public class BusPassengerTrafficLightView extends IViewTrafficLight { super.changeCountdownRed(redNum); UiThreadHandler.post(() -> { if (redNum > 0) { + resetView(); mLightTimeTV.setText(String.valueOf(redNum)); } else { + disableCountdown(); mLightTimeTV.setText(""); } }); @@ -109,8 +115,10 @@ public class BusPassengerTrafficLightView extends IViewTrafficLight { super.changeCountdownGreen(greenNum); UiThreadHandler.post(() -> { if (greenNum > 0) { + resetView(); mLightTimeTV.setText(String.valueOf(greenNum)); } else { + disableCountdown(); mLightTimeTV.setText(""); } }); @@ -121,8 +129,10 @@ public class BusPassengerTrafficLightView extends IViewTrafficLight { super.changeCountdownYellow(yellowNum); UiThreadHandler.post(() -> { if (yellowNum > 0) { + resetView(); mLightTimeTV.setText(String.valueOf(yellowNum)); } else { + disableCountdown(); mLightTimeTV.setText(""); } }); @@ -154,4 +164,30 @@ public class BusPassengerTrafficLightView extends IViewTrafficLight { } }); } + + @Override + public void disableCountdown() { + super.disableCountdown(); + UiThreadHandler.post(() ->{ + ViewGroup.LayoutParams layoutParams = getLayoutParams(); + if (layoutParams instanceof MarginLayoutParams){ + MarginLayoutParams lp = (MarginLayoutParams) layoutParams; + lp.width = (int) getResources().getDimension(R.dimen.bus_p_traffic_light_icon_size); + setLayoutParams(lp); + mLightTimeTV.setVisibility(GONE); + mLightIconBG.getLayoutParams().width = (int)getResources().getDimension(R.dimen.dp_90); + } + }); + } + + private void resetView(){ + ViewGroup.LayoutParams layoutParams = getLayoutParams(); + if (layoutParams instanceof MarginLayoutParams) { + MarginLayoutParams lp = (MarginLayoutParams) layoutParams; + lp.width = (int) getResources().getDimension(R.dimen.bus_p_route_traffic_light_view_width); + setLayoutParams(lp); + mLightTimeTV.setVisibility(VISIBLE); + mLightIconBG.getLayoutParams().width = (int) getResources().getDimension(R.dimen.bus_p_traffic_light_bg_width); + } + } } diff --git a/OCH/mogo-och-bus-passenger/src/main/res/layout/bus_p_traffic_light_view.xml b/OCH/mogo-och-bus-passenger/src/main/res/layout/bus_p_traffic_light_view.xml index e62c37454f..5a0db32bc0 100644 --- a/OCH/mogo-och-bus-passenger/src/main/res/layout/bus_p_traffic_light_view.xml +++ b/OCH/mogo-och-bus-passenger/src/main/res/layout/bus_p_traffic_light_view.xml @@ -7,6 +7,7 @@ android:visibility="visible"> { if (redNum > 0) { + resetView(); mLightTimeTV.setVertrial(true); mLightTimeTV.setmColorList(new int[]{getResources().getColor(R.color.taxi_p_traffic_light_red_color_up), getResources().getColor(R.color.taxi_p_traffic_light_red_color_down)}); mLightTimeTV.setText(String.valueOf(redNum)); } else { + disableCountdown(); mLightTimeTV.setText(""); } }); @@ -115,11 +118,13 @@ public class TaxiPassengerTrafficLightView extends IViewTrafficLight { super.changeCountdownGreen(greenNum); UiThreadHandler.post(() -> { if (greenNum > 0) { + resetView(); mLightTimeTV.setVertrial(true); mLightTimeTV.setmColorList(new int[]{getResources().getColor(R.color.taxi_p_traffic_light_green_color_up), getResources().getColor(R.color.taxi_p_traffic_light_green_color_down)}); mLightTimeTV.setText(String.valueOf(greenNum)); } else { + disableCountdown(); mLightTimeTV.setText(""); } }); @@ -130,11 +135,13 @@ public class TaxiPassengerTrafficLightView extends IViewTrafficLight { super.changeCountdownYellow(yellowNum); UiThreadHandler.post(() -> { if (yellowNum > 0) { + resetView(); mLightTimeTV.setVertrial(true); mLightTimeTV.setmColorList(new int[]{getResources().getColor(R.color.taxi_p_traffic_light_yellow_color_up), getResources().getColor(R.color.taxi_p_traffic_light_yellow_color_down)}); mLightTimeTV.setText(String.valueOf(yellowNum)); } else { + disableCountdown(); mLightTimeTV.setText(""); } }); @@ -166,4 +173,29 @@ public class TaxiPassengerTrafficLightView extends IViewTrafficLight { } }); } + @Override + public void disableCountdown() { + super.disableCountdown(); + UiThreadHandler.post(() ->{ + ViewGroup.LayoutParams layoutParams = getLayoutParams(); + if (layoutParams instanceof MarginLayoutParams){ + MarginLayoutParams lp = (MarginLayoutParams) layoutParams; + lp.width = (int) getResources().getDimension(R.dimen.taxi_p_traffic_light_icon_size); + setLayoutParams(lp); + mLightTimeTV.setVisibility(GONE); + mLightIconBG.getLayoutParams().width = (int)getResources().getDimension(R.dimen.dp_124); + } + }); + } + + private void resetView(){ + ViewGroup.LayoutParams layoutParams = getLayoutParams(); + if (layoutParams instanceof MarginLayoutParams) { + MarginLayoutParams lp = (MarginLayoutParams) layoutParams; + lp.width = (int) getResources().getDimension(R.dimen.taxi_p_traffic_light_layout_width); + setLayoutParams(lp); + mLightTimeTV.setVisibility(VISIBLE); + mLightIconBG.getLayoutParams().width = (int) getResources().getDimension(R.dimen.taxi_p_traffic_light_bg_width); + } + } } diff --git a/OCH/mogo-och-taxi-passenger/src/main/res/layout/taxi_p_traffic_light_view.xml b/OCH/mogo-och-taxi-passenger/src/main/res/layout/taxi_p_traffic_light_view.xml index 7bd77d1200..150f0b1eb8 100644 --- a/OCH/mogo-och-taxi-passenger/src/main/res/layout/taxi_p_traffic_light_view.xml +++ b/OCH/mogo-och-taxi-passenger/src/main/res/layout/taxi_p_traffic_light_view.xml @@ -7,6 +7,7 @@ android:visibility="visible">