layout traffic light in vr mode

This commit is contained in:
admin
2020-12-08 17:50:37 +08:00
parent 596accaf4c
commit fb0a377383
27 changed files with 402 additions and 1 deletions

2
.idea/misc.xml generated
View File

@@ -4,7 +4,7 @@
<asm skipDebug="false" skipFrames="false" skipCode="false" expandFrames="false" />
<groovy codeStyle="LEGACY" />
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="JDK" project-jdk-type="JavaSDK">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
</project>

View File

@@ -0,0 +1,138 @@
package com.mogo.module.extensions.view;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.IntDef;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.constraintlayout.widget.Group;
import com.mogo.module.extensions.R;
import com.mogo.utils.logger.Logger;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
/**
* vr模式下的纵向显示的红绿灯封装
*
* @author tongchenfei
*/
public class VerticalTrafficLightView extends ConstraintLayout {
private static final String TAG = "VerticalTrafficLightView";
public static final int TRAFFIC_LIGHT_COLOR_GRAY = 0;
public static final int TRAFFIC_LIGHT_COLOR_RED = 1;
public static final int TRAFFIC_LIGHT_COLOR_YELLOW = 2;
public static final int TRAFFIC_LIGHT_COLOR_GREEN = 3;
private ImageView ivTrafficLight, ivNoLeftTime;
private TextView tvLeftTime, tvLeftTimeUnit;
private Group groupLeftTime;
private static final int[] TURN_AROUND_ICON_RES = new int[]{R.drawable.module_ext_dw_traffic_turn_around_gray, R.drawable.module_ext_dw_traffic_turn_around_red, R.drawable.module_ext_dw_traffic_turn_around_yellow, R.drawable.module_ext_dw_traffic_turn_around_green};
private static final int[] TURN_LEFT_ICON_RES = new int[]{R.drawable.module_ext_dw_traffic_turn_left_gray, R.drawable.module_ext_dw_traffic_turn_left_red, R.drawable.module_ext_dw_traffic_turn_left_yellow, R.drawable.module_ext_dw_traffic_turn_left_green};
private static final int[] STRAIGHT_ICON_RES = new int[]{R.drawable.module_ext_dw_traffic_straight_gray, R.drawable.module_ext_dw_traffic_straight_red, R.drawable.module_ext_dw_traffic_straight_yellow, R.drawable.module_ext_dw_traffic_straight_green};
private static final int[] TURN_RIGHT_ICON_RES = new int[]{R.drawable.module_ext_dw_traffic_turn_right_gray, R.drawable.module_ext_dw_traffic_turn_right_red, R.drawable.module_ext_dw_traffic_turn_right_yellow, R.drawable.module_ext_dw_traffic_turn_right_green};
private final int[] iconRes;
private final int[] colorRes = new int[]{-1, Color.parseColor("#F63A35"), Color.parseColor("#F63A35"), Color.parseColor("#11FF89")};
public VerticalTrafficLightView(Context context) {
this(context, null);
}
public VerticalTrafficLightView(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
public VerticalTrafficLightView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
LayoutInflater.from(context).inflate(R.layout.merge_vertical_traffic_light_in_vr, this);
initView();
TypedArray typedArray = context.getTheme().obtainStyledAttributes(attrs, R.styleable.VerticalTrafficLightView, 0, 0);
int lightType = typedArray.getInt(R.styleable.VerticalTrafficLightView_iconRes, 0);
typedArray.recycle();
switch (lightType) {
case 1:
// turn left
iconRes = TURN_LEFT_ICON_RES;
break;
case 2:
// straight
iconRes = STRAIGHT_ICON_RES;
break;
case 3:
// turn right
iconRes = TURN_RIGHT_ICON_RES;
break;
default:
// turn around
iconRes = TURN_AROUND_ICON_RES;
break;
}
}
private void initView() {
ivTrafficLight = findViewById(R.id.module_ext_id_traffic_light_icon);
ivNoLeftTime = findViewById(R.id.module_ext_id_traffic_light_no_left_time);
tvLeftTime = findViewById(R.id.module_ext_id_traffic_light_left_time);
tvLeftTimeUnit = findViewById(R.id.module_ext_id_traffic_light_left_time_unit);
groupLeftTime = findViewById(R.id.module_ext_id_group_left_time);
}
/**
* 设置红绿灯的颜色,根据颜色来展示不同的效果
*
* @param color 红绿灯颜色{@link #TRAFFIC_LIGHT_COLOR_GRAY},{@link #TRAFFIC_LIGHT_COLOR_RED}等四个颜色
*/
private void setTrafficLightColor(@TrafficLightColor int color) {
if (iconRes == null) {
Logger.e(TAG, "红绿灯Icon数据为空无法进行设置");
return;
}
ivTrafficLight.setImageResource(iconRes[color]);
if (color != TRAFFIC_LIGHT_COLOR_GRAY) {
tvLeftTime.setTextColor(colorRes[color]);
tvLeftTimeUnit.setTextColor(colorRes[color]);
}
}
/**
* 设置红绿灯剩余时长
*
* @param leftTime 剩余时长null或者empty表示没有时长数据
*/
private void setTrafficLightLeftTime(String leftTime) {
if (leftTime == null || leftTime.isEmpty()) {
groupLeftTime.setVisibility(View.GONE);
ivNoLeftTime.setVisibility(View.VISIBLE);
} else {
groupLeftTime.setVisibility(View.VISIBLE);
ivNoLeftTime.setVisibility(View.GONE);
tvLeftTime.setText(leftTime);
}
}
/**
* 设置红绿灯状态,需设置颜色及时长
*
* @param color 红绿灯颜色,使用{@link #TRAFFIC_LIGHT_COLOR_RED}等四个值
* @param leftTime 剩余时长null或者empty表示没有时长数据
*/
public void setTrafficLightStatus(@TrafficLightColor int color, String leftTime) {
setTrafficLightColor(color);
setTrafficLightLeftTime(leftTime);
}
@IntDef({TRAFFIC_LIGHT_COLOR_GRAY, TRAFFIC_LIGHT_COLOR_GREEN, TRAFFIC_LIGHT_COLOR_RED, TRAFFIC_LIGHT_COLOR_YELLOW})
@Retention(RetentionPolicy.SOURCE)
public @interface TrafficLightColor {
}
}

View File

@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<size
android:width="@dimen/module_ext_navi_in_vr_speed_bg_width"
android:height="@dimen/module_ext_navi_in_vr_speed_bg_height" />
<gradient
android:startColor="#FF344687"
android:endColor="#FF141C35" />
<corners android:radius="@dimen/module_ext_navi_in_vr_bg_corner" />
</shape>

View File

@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<size
android:width="@dimen/module_ext_navi_in_vr_speed_bg_width"
android:height="@dimen/module_ext_navi_in_vr_traffic_bg_height" />
<gradient
android:startColor="#FF131D42"
android:centerColor="#FF080F25"
android:endColor="#FF121A35"
android:angle="0"/>
<corners android:bottomLeftRadius="@dimen/module_ext_navi_in_vr_bg_corner"
android:bottomRightRadius="@dimen/module_ext_navi_in_vr_bg_corner"/>
</shape>

Binary file not shown.

After

Width:  |  Height:  |  Size: 177 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.0 KiB

View File

@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<size
android:width="@dimen/module_ext_navi_in_vr_width"
android:height="@dimen/module_ext_navi_in_vr_height" />
<gradient
android:startColor="#9C4F77D1"
android:centerColor="#68203784"
android:endColor="#68203784" />
<corners android:radius="@dimen/module_ext_navi_in_vr_bg_corner" />
</shape>

View File

@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<size
android:height="@dimen/module_ext_navi_in_vr_limit_speed_size"
android:width="@dimen/module_ext_navi_in_vr_limit_speed_size" />
<gradient
android:startColor="#FF222F5B"
android:endColor="#FF1F2A54" />
</shape>

View File

@@ -0,0 +1,116 @@
<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:parentTag="androidx.constraintlayout.widget.ConstraintLayout">
<View
android:layout_width="@dimen/module_ext_navi_in_vr_width"
android:layout_height="@dimen/module_ext_navi_in_vr_height"
android:id="@+id/module_ext_id_navi_in_vr_bg"
android:background="@drawable/module_ext_navi_in_vr_bg"/>
<View
android:id="@+id/module_ext_id_navi_in_vr_speed_bg"
android:layout_width="@dimen/module_ext_navi_in_vr_speed_bg_width"
android:layout_height="@dimen/module_ext_navi_in_vr_speed_bg_height"
android:background="@drawable/module_ext_navi_in_vr_speed_bg"
app:layout_constraintLeft_toLeftOf="@id/module_ext_id_navi_in_vr_bg"
app:layout_constraintTop_toTopOf="@id/module_ext_id_navi_in_vr_bg"
app:layout_constraintBottom_toBottomOf="@id/module_ext_id_navi_in_vr_bg"
app:layout_constraintRight_toRightOf="@id/module_ext_id_navi_in_vr_bg"/>
<View
android:id="@+id/module_ext_id_navi_in_vr_traffic_bg"
android:layout_width="@dimen/module_ext_navi_in_vr_speed_bg_width"
android:layout_height="@dimen/module_ext_navi_in_vr_traffic_bg_height"
android:background="@drawable/module_ext_navi_in_vr_traffic_bg"
app:layout_constraintLeft_toLeftOf="@id/module_ext_id_navi_in_vr_bg"
app:layout_constraintRight_toRightOf="@id/module_ext_id_navi_in_vr_bg"
app:layout_constraintBottom_toBottomOf="@id/module_ext_id_navi_in_vr_bg"
android:layout_marginBottom="@dimen/module_ext_navi_in_vr_traffic_bg_margin_bottom" />
<androidx.constraintlayout.widget.Group
android:id="@+id/module_ext_id_group_navi_in_vr_speed"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:constraint_referenced_ids="module_ext_id_tv_speed,module_ext_id_tv_speed_unit"/>
<TextView
android:id="@+id/module_ext_id_tv_speed"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="78"
app:layout_constraintLeft_toLeftOf="@id/module_ext_id_navi_in_vr_bg"
app:layout_constraintTop_toTopOf="@id/module_ext_id_navi_in_vr_bg"
app:layout_constraintBottom_toTopOf="@id/module_ext_id_navi_in_vr_traffic_bg"
android:layout_marginStart="@dimen/module_ext_navi_in_vr_speed_margin_start"
android:textSize="@dimen/module_ext_navi_in_vr_speed_text_size"
android:textColor="#fff" />
<TextView
android:id="@+id/module_ext_id_tv_speed_unit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="km/h"
android:textSize="@dimen/module_ext_navi_in_vr_speed_unit_size"
android:textColor="#fff"
app:layout_constraintLeft_toRightOf="@id/module_ext_id_tv_speed"
app:layout_constraintBaseline_toBaselineOf="@id/module_ext_id_tv_speed"
android:layout_marginStart="@dimen/module_ext_navi_in_vr_speed_unit_margin_start" />
<TextView
android:id="@+id/module_ext_id_tv_limit_speed"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/module_ext_vr_mode_limit_speed_bg"
android:text="80"
android:textColor="#FF9CA8D8"
android:gravity="center"
android:textSize="@dimen/module_ext_navi_in_vr_limit_speed_text_size"
app:layout_constraintRight_toRightOf="@id/module_ext_id_navi_in_vr_bg"
app:layout_constraintTop_toTopOf="@id/module_ext_id_navi_in_vr_bg"
app:layout_constraintBottom_toTopOf="@id/module_ext_id_navi_in_vr_traffic_bg"
android:layout_marginEnd="@dimen/module_ext_navi_in_vr_limit_speed_margin_end" />
<com.mogo.module.extensions.view.VerticalTrafficLightView
android:id="@+id/module_ext_id_traffic_light_turn_around"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/module_ext_navi_in_vr_traffic_light_margin_top"
app:iconRes="turnAround"
app:layout_constraintLeft_toLeftOf="@id/module_ext_id_navi_in_vr_traffic_bg"
app:layout_constraintTop_toTopOf="@id/module_ext_id_navi_in_vr_traffic_bg"
app:layout_constraintRight_toLeftOf="@id/module_ext_id_traffic_light_turn_left"/>
<com.mogo.module.extensions.view.VerticalTrafficLightView
android:id="@+id/module_ext_id_traffic_light_turn_left"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:iconRes="turnLeft"
app:layout_constraintLeft_toRightOf="@id/module_ext_id_traffic_light_turn_around"
app:layout_constraintRight_toLeftOf="@id/module_ext_id_traffic_light_straight"
app:layout_constraintTop_toTopOf="@id/module_ext_id_traffic_light_turn_around" />
<com.mogo.module.extensions.view.VerticalTrafficLightView
android:id="@+id/module_ext_id_traffic_light_straight"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:iconRes="straight"
app:layout_constraintLeft_toRightOf="@id/module_ext_id_traffic_light_turn_left"
app:layout_constraintRight_toLeftOf="@id/module_ext_id_traffic_light_turn_right"
app:layout_constraintTop_toTopOf="@id/module_ext_id_traffic_light_turn_left" />
<com.mogo.module.extensions.view.VerticalTrafficLightView
android:id="@+id/module_ext_id_traffic_light_turn_right"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:iconRes="turnRight"
app:layout_constraintLeft_toRightOf="@id/module_ext_id_traffic_light_straight"
app:layout_constraintTop_toTopOf="@id/module_ext_id_traffic_light_straight"
app:layout_constraintRight_toRightOf="@id/module_ext_id_navi_in_vr_traffic_bg" />
</merge>

View File

@@ -0,0 +1,53 @@
<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:parentTag="androidx.constraintlayout.widget.ConstraintLayout">
<androidx.constraintlayout.widget.Group
android:id="@+id/module_ext_id_group_left_time"
app:constraint_referenced_ids="module_ext_id_traffic_light_left_time,module_ext_id_traffic_light_left_time_unit"
android:visibility="gone"
tools:visibility="visible"/>
<ImageView
android:id="@+id/module_ext_id_traffic_light_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/module_ext_dw_traffic_turn_right_red" />
<TextView
android:id="@+id/module_ext_id_traffic_light_left_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="12"
android:textColor="#fff"
app:layout_constraintHorizontal_chainStyle="packed"
android:textSize="@dimen/module_ext_navi_in_vr_traffic_light_left_time_txt_size"
app:layout_constraintLeft_toLeftOf="@id/module_ext_id_traffic_light_icon"
app:layout_constraintRight_toLeftOf="@id/module_ext_id_traffic_light_left_time_unit"
app:layout_constraintTop_toBottomOf="@id/module_ext_id_traffic_light_icon" />
<TextView
android:id="@+id/module_ext_id_traffic_light_left_time_unit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="s"
android:textColor="#fff"
android:textSize="@dimen/module_ext_navi_in_vr_traffic_light_left_time_unit_size"
app:layout_constraintBaseline_toBaselineOf="@id/module_ext_id_traffic_light_left_time"
app:layout_constraintLeft_toRightOf="@id/module_ext_id_traffic_light_left_time"
app:layout_constraintRight_toRightOf="@id/module_ext_id_traffic_light_icon" />
<ImageView
android:id="@+id/module_ext_id_traffic_light_no_left_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/module_ext_navi_in_vr_traffic_light_no_time_margin_top"
app:layout_constraintLeft_toLeftOf="@id/module_ext_id_traffic_light_icon"
app:layout_constraintRight_toRightOf="@id/module_ext_id_traffic_light_icon"
app:layout_constraintTop_toBottomOf="@id/module_ext_id_traffic_light_icon"
android:src="@drawable/module_ext_dw_traffic_no_time" />
</merge>

View File

@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="VerticalTrafficLightView" >
<attr name="iconRes" format="enum">
<enum name="turnAround" value="0" />
<enum name="turnLeft" value="1" />
<enum name="straight" value="2" />
<enum name="turnRight" value="3" />
</attr>
</declare-styleable>
</resources>

View File

@@ -188,4 +188,29 @@
<dimen name="module_common_btn_bottom">0px</dimen>
<dimen name="module_entrance_id_button_marginLeft">0px</dimen>
<!-- 仅在vr模式下有此内容仅增加了xhdpi对应的大小 -->
<dimen name="module_ext_navi_in_vr_width">464px</dimen>
<dimen name="module_ext_navi_in_vr_height">304px</dimen>
<dimen name="module_ext_navi_in_vr_speed_bg_width">458px</dimen>
<dimen name="module_ext_navi_in_vr_speed_bg_height">298px</dimen>
<dimen name="module_ext_navi_in_vr_traffic_bg_height">140px</dimen>
<dimen name="module_ext_navi_in_vr_traffic_bg_margin_bottom">3px</dimen>
<dimen name="module_ext_navi_in_vr_speed_text_size">100px</dimen>
<dimen name="module_ext_navi_in_vr_speed_unit_size">30px</dimen>
<dimen name="module_ext_navi_in_vr_speed_unit_margin_start">30px</dimen>
<dimen name="module_ext_navi_in_vr_speed_margin_start">36px</dimen>
<dimen name="module_ext_navi_in_vr_speed_margin_top">22px</dimen>
<dimen name="module_ext_navi_in_vr_limit_speed_size">78px</dimen>
<dimen name="module_ext_navi_in_vr_limit_speed_margin_end">26px</dimen>
<dimen name="module_ext_navi_in_vr_limit_speed_margin_top">43px</dimen>
<dimen name="module_ext_navi_in_vr_limit_speed_text_size">40px</dimen>
<dimen name="module_ext_navi_in_vr_bg_corner">20px</dimen>
<dimen name="module_ext_navi_in_vr_traffic_light_margin_top">17px</dimen>
<dimen name="module_ext_navi_in_vr_traffic_light_left_time_txt_size">36px</dimen>
<dimen name="module_ext_navi_in_vr_traffic_light_left_time_unit_size">21px</dimen>
<dimen name="module_ext_navi_in_vr_traffic_light_no_time_margin_top">21px</dimen>
</resources>