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">