Location:

HUD Navigation Mode

HUD navigation is used for projection display during driving. This mode visually displays navigation information and is a safe and simple navigation mode. HUD navigation is mainly to navigate a simple interface application.

HUD导航

The following is an example of driving navigation, how to achieve HUD navigation.

1. HUD layout code example

XML
                <?xml version="1.0" encoding="utf-8"?>
                <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:orientation="vertical">
                    
                    <include
                        android:id="@+id/hud_title"
                        layout="@layout/lay_title"/>
                        
                    <LinearLayout
                        android:id="@+id/hud_anim_parent"
                        android:layout_width="match_parent"
                        android:layout_height="0dp"
                        android:layout_weight="1"
                        android:background="#f000"
                        android:orientation="vertical">
                        
                        <ImageView
                            android:id="@+id/hud_turn_icon"
                            android:layout_width="160dp"
                            android:layout_height="160dp"
                            android:layout_gravity="center"
                            android:layout_marginTop="15dp"/>
                            
                        <TextView
                            android:id="@+id/tv_no_nivadata"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_gravity="center"
                            android:ellipsize="end"
                            android:gravity="center"
                            android:maxLines="1"
                            android:singleLine="true"
                            android:text="@string/hud_location"
                            android:textColor="@color/hud_color"
                            android:textSize="40sp"/>
                            
                        <TextView
                            android:id="@+id/hud_distance"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_gravity="center"
                            android:layout_marginTop="NavInfop"
                            android:ellipsize="end"
                            android:gravity="center"
                            android:maxLines="1"
                            android:maxEms="6"
                            android:textColor="@color/hud_color"
                            android:textSize="80sp"/>
                            
                        <TextView
                            android:id="@+id/hud_roadname"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_gravity="center"
                            android:ellipsize="end"
                            android:gravity="center"
                            android:maxLines="1"
                            android:maxEms="6"
                            android:singleLine="true"
                            android:textColor="@color/hud_color"
                            android:textSize="@dimen/F24"/>
                            
                        <LinearLayout
                            android:id="@+id/hud_bottom"
                            android:layout_width="match_parent"
                            android:layout_height="@dimen/space_60"
                            android:layout_marginTop="60dp"
                            android:gravity="center"
                            android:orientation="horizontal">
                            
                            <TextView
                                android:id="@+id/hud_speed"
                                android:layout_width="160dp"
                                android:layout_height="60dp"
                                android:layout_gravity="center"
                                android:background="@drawable/hud_circle_rect"
                                android:gravity="center"
                                android:singleLine="true"
                                android:text="0km/h"
                                android:textColor="@color/hud_color"
                                android:textSize="@dimen/F25"
                                android:textStyle="bold"/>
                                
                            <TextView
                                android:id="@+id/hud_direction"
                                android:layout_width="160dp"
                                android:layout_height="60dp"
                                android:layout_gravity="center"
                                android:layout_marginLeft="15dp"
                                android:layout_marginStart="15dp"
                                android:background="@drawable/hud_circle_rect"
                                android:gravity="center"
                                android:singleLine="true"
                                android:text="@string/north"
                                android:textColor="@color/hud_color"
                                android:textSize="@dimen/F25"
                                android:textStyle="bold"/>
                                
                        </LinearLayout>
                        <TextView
                            android:id="@+id/tv_remaining_time"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_gravity="center"
                            android:layout_marginTop="36dp"
                            android:singleLine="true"
                            android:textColor="@color/hud_color"
                            android:textSize="@dimen/F26"/>
                    </LinearLayout>
                </LinearLayout>
            

2. HUD layout initialization

Layout initialization uses a mapping framework that can be integrated on its own.

                @ViewerInject(R.id.hud_title)
                TitleViewer titleViewer;
                /**
                * Flip the parent control
                */
                @ViewInject(R.id.hud_anim_parent)
                View vAnimParent;
                /**
                * Steering mark
                */
                @ViewInject(R.id.hud_turn_icon)
                ImageView ivTurnIcon;
                /**
                * Next intersection
                */
                @ViewInject(R.id.hud_roadname)
                TextView tvRoadName;
                /**
                * Remaining distance
                */
                @ViewInject(R.id.hud_distance)
                TextView tvDistance;
                /**
                * Current speed
                */
                @ViewInject(R.id.hud_speed)
                TextView tvSpeed;
                /**
                * Compass
                */
                @ViewInject(R.id.hud_direction)
                TextView vDirection;
                /**
                * Remaining distance and time s
                */
                @ViewInject(R.id.tv_remaining_time)
                TextView tvRemainingTime;

                @ViewInject(R.id.tv_no_nivadata)
                TextView tv_no_nivadata;
            

3. Update the HUD interface according to the navigation information

                // Drive along XXX
                distance = mNavigateData.getCurrentToNextTurnDistance();
                // 200 meters
                distanceText = GISUtils.formatDistance(distance, GISUtils.DistanceUnit.CN);
                matcher = NUMBER_PATTERN.matcher(distanceText);
                start = 0;
                end = 0;
                if (matcher.find()) {
                    start = matcher.start();
                    end = matcher.end();
                }
                numberDistance = distanceText.substring(start, end);
                
                unite = distanceText.substring(end, distanceText.length());
                distanceSize = R.dimen.F22;
                driveNumSize = R.dimen.F24;
                suffixSize = R.dimen.F14;
                String yan = YAN + mRoadName;
                SpannableStringBuilder yanStyle = new SpannableStringBuilder(yan);
                
                yanStyle.setSpan(new AbsoluteSizeSpan(LayoutUtils.getPxByDimens(suffixSize)), 0, 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
                yanStyle.setSpan(new AbsoluteSizeSpan(LayoutUtils.getPxByDimens(distanceSize)), 1, yan.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
                
                String driveNum = typeKey + numberDistance + unite;
                SpannableStringBuilder driveNumStyle = new SpannableStringBuilder(driveNum);
                
                driveNumStyle.setSpan(new AbsoluteSizeSpan(LayoutUtils.getPxByDimens(suffixSize)), 0, typeKey.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
                driveNumStyle.setSpan(new AbsoluteSizeSpan(LayoutUtils.getPxByDimens(driveNumSize)), typeKey.length(), typeKey.length() + numberDistance.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
                driveNumStyle.setSpan(new AbsoluteSizeSpan(LayoutUtils.getPxByDimens(suffixSize)), typeKey.length() + numberDistance.length(), driveNum.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
                
                tvDistance.setText(yanStyle);
                tvRoadName.setText(driveNumStyle);
            
TOP