Create transport item dynamically
This commit is contained in:
parent
57174d7f25
commit
95499c39eb
4 changed files with 122 additions and 125 deletions
|
@ -1,66 +0,0 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
xmlns:osmand="http://schemas.android.com/apk/res-auto"
|
|
||||||
android:background="?attr/selectableItemBackground"
|
|
||||||
android:orientation="horizontal"
|
|
||||||
android:paddingBottom="12dp"
|
|
||||||
android:paddingLeft="16dp"
|
|
||||||
android:paddingRight="16dp">
|
|
||||||
|
|
||||||
<net.osmand.plus.widgets.TextViewEx
|
|
||||||
android:layout_marginTop="16dp"
|
|
||||||
android:textAllCaps="true"
|
|
||||||
osmand:typeface="@string/font_roboto_medium"
|
|
||||||
android:id="@+id/route_ref"
|
|
||||||
android:layout_width="32dp"
|
|
||||||
android:layout_height="18dp"
|
|
||||||
android:background="@drawable/transport_stop_route_bg"
|
|
||||||
android:gravity="center"
|
|
||||||
android:textColor="@color/color_white"
|
|
||||||
android:textSize="@dimen/default_sub_text_size_small"
|
|
||||||
tools:text="3"/>
|
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:layout_marginTop="12dp"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginLeft="16dp"
|
|
||||||
android:layout_marginStart="16dp"
|
|
||||||
android:orientation="vertical">
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:textSize="16sp"
|
|
||||||
android:id="@+id/route_desc"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
tools:text="№5: Льва Толстого площа - Белицкая улица (25м)"/>
|
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:gravity="center"
|
|
||||||
android:paddingTop="8dp">
|
|
||||||
|
|
||||||
<ImageView
|
|
||||||
android:id="@+id/route_type_icon"
|
|
||||||
android:layout_marginRight="@dimen/context_menu_transport_grid_spacing"
|
|
||||||
android:layout_marginEnd="@dimen/context_menu_transport_grid_spacing"
|
|
||||||
android:layout_width="@dimen/context_menu_transport_icon_size"
|
|
||||||
android:layout_height="@dimen/context_menu_transport_icon_size"
|
|
||||||
tools:src="@drawable/ic_action_polygom_dark"/>
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/route_type_text"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
tools:text="Метро "/>
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
|
@ -5,6 +5,7 @@ import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.res.ColorStateList;
|
import android.content.res.ColorStateList;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
|
import android.graphics.Color;
|
||||||
import android.graphics.PorterDuff;
|
import android.graphics.PorterDuff;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.graphics.drawable.GradientDrawable;
|
import android.graphics.drawable.GradientDrawable;
|
||||||
|
@ -716,60 +717,79 @@ public class MenuBuilder {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void buildTransportRouteRow(ViewGroup parent, TransportStopRoute r, OnClickListener listener, boolean showDivider) {
|
private View buildTransportRowItem(View view, TransportStopRoute route, OnClickListener listener) {
|
||||||
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.ctx_menu_transport_route_layout, parent, false);
|
LinearLayout baseView = new LinearLayout(view.getContext());
|
||||||
TextView routeDesc = (TextView) view.findViewById(R.id.route_desc);
|
baseView.setOrientation(LinearLayout.HORIZONTAL);
|
||||||
routeDesc.setText(r.getDescription(getMapActivity().getMyApplication(), true));
|
LinearLayout.LayoutParams llBaseViewParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
|
||||||
routeDesc.setTextColor(app.getResources().getColor(light ? R.color.ctx_menu_bottom_view_text_color_light : R.color.ctx_menu_bottom_view_text_color_dark));
|
baseView.setLayoutParams(llBaseViewParams);
|
||||||
int drawableResId = r.type == null ? R.drawable.ic_action_polygom_dark : r.type.getResourceId();
|
baseView.setPadding(dpToPx(16), 0, dpToPx(16), dpToPx(12));
|
||||||
((ImageView) view.findViewById(R.id.route_type_icon)).setImageDrawable(getRowIcon(drawableResId));
|
baseView.setBackgroundResource(resolveAttribute(view.getContext(), android.R.attr.selectableItemBackground));
|
||||||
TextView refTextView = (TextView) view.findViewById(R.id.route_ref);
|
|
||||||
refTextView.setText(r.route.getRef());
|
|
||||||
GradientDrawable refBg = (GradientDrawable) refTextView.getBackground();
|
|
||||||
refBg.setColor(r.getColor(mapActivity.getMyApplication(), !light));
|
|
||||||
view.setOnClickListener(listener);
|
|
||||||
int typeResId;
|
|
||||||
switch (r.type) {
|
|
||||||
case BUS:
|
|
||||||
typeResId = R.string.poi_route_bus_ref;
|
|
||||||
break;
|
|
||||||
case TRAM:
|
|
||||||
typeResId = R.string.poi_route_tram_ref;
|
|
||||||
break;
|
|
||||||
case FERRY:
|
|
||||||
typeResId = R.string.poi_route_ferry_ref;
|
|
||||||
break;
|
|
||||||
case TRAIN:
|
|
||||||
typeResId = R.string.poi_route_train_ref;
|
|
||||||
break;
|
|
||||||
case SHARE_TAXI:
|
|
||||||
typeResId = R.string.poi_route_share_taxi_ref;
|
|
||||||
break;
|
|
||||||
case FUNICULAR:
|
|
||||||
typeResId = R.string.poi_route_funicular_ref;
|
|
||||||
break;
|
|
||||||
case LIGHT_RAIL:
|
|
||||||
typeResId = R.string.poi_route_light_rail_ref;
|
|
||||||
break;
|
|
||||||
case MONORAIL:
|
|
||||||
typeResId = R.string.poi_route_monorail_ref;
|
|
||||||
break;
|
|
||||||
case TROLLEYBUS:
|
|
||||||
typeResId = R.string.poi_route_trolleybus_ref;
|
|
||||||
break;
|
|
||||||
case RAILWAY:
|
|
||||||
typeResId = R.string.poi_route_railway_ref;
|
|
||||||
break;
|
|
||||||
case SUBWAY:
|
|
||||||
typeResId = R.string.poi_route_subway_ref;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
typeResId = R.string.poi_filter_public_transport;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
((TextView) view.findViewById(R.id.route_type_text)).setText(typeResId);
|
|
||||||
|
|
||||||
parent.addView(view);
|
TextViewEx transportRect = new TextViewEx(view.getContext());
|
||||||
|
LinearLayout.LayoutParams trParams = new LinearLayout.LayoutParams(dpToPx(32), dpToPx(18));
|
||||||
|
trParams.setMargins(0, dpToPx(16), 0, 0);
|
||||||
|
transportRect.setLayoutParams(trParams);
|
||||||
|
transportRect.setGravity(Gravity.CENTER);
|
||||||
|
transportRect.setAllCaps(true);
|
||||||
|
transportRect.setTypeface(FontCache.getRobotoMedium(view.getContext()));
|
||||||
|
transportRect.setTextColor(Color.WHITE);
|
||||||
|
transportRect.setTextSize(10);
|
||||||
|
|
||||||
|
GradientDrawable shape = new GradientDrawable();
|
||||||
|
shape.setShape(GradientDrawable.RECTANGLE);
|
||||||
|
shape.setCornerRadius(dpToPx(3));
|
||||||
|
shape.setColor(route.getColor(mapActivity.getMyApplication(), !light));
|
||||||
|
|
||||||
|
transportRect.setBackgroundDrawable(shape);
|
||||||
|
transportRect.setText(route.route.getRef());
|
||||||
|
baseView.addView(transportRect);
|
||||||
|
|
||||||
|
LinearLayout infoView = new LinearLayout(view.getContext());
|
||||||
|
infoView.setOrientation(LinearLayout.VERTICAL);
|
||||||
|
LinearLayout.LayoutParams infoViewLayoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
||||||
|
infoViewLayoutParams.setMargins(dpToPx(16), dpToPx(12), dpToPx(16), 0);
|
||||||
|
infoView.setLayoutParams(infoViewLayoutParams);
|
||||||
|
baseView.addView(infoView);
|
||||||
|
|
||||||
|
TextView titleView = new TextView(view.getContext());
|
||||||
|
LinearLayout.LayoutParams titleParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
||||||
|
titleView.setLayoutParams(titleParams);
|
||||||
|
titleView.setTextSize(16);
|
||||||
|
titleView.setTextColor(app.getResources().getColor(light ? R.color.ctx_menu_bottom_view_text_color_light : R.color.ctx_menu_bottom_view_text_color_dark));
|
||||||
|
titleView.setText(route.getDescription(getMapActivity().getMyApplication(), true));
|
||||||
|
infoView.addView(titleView);
|
||||||
|
|
||||||
|
LinearLayout typeView = new LinearLayout(view.getContext());
|
||||||
|
typeView.setOrientation(LinearLayout.HORIZONTAL);
|
||||||
|
LinearLayout.LayoutParams typeViewParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
||||||
|
typeViewParams.setMargins(0, dpToPx(8), 0, 0);
|
||||||
|
typeView.setGravity(Gravity.CENTER);
|
||||||
|
typeView.setLayoutParams(typeViewParams);
|
||||||
|
infoView.addView(typeView);
|
||||||
|
|
||||||
|
ImageView typeImageView = new ImageView(view.getContext());
|
||||||
|
LinearLayout.LayoutParams typeImageParams = new LinearLayout.LayoutParams(dpToPx(16), dpToPx(16));
|
||||||
|
typeImageParams.setMargins(dpToPx(4), 0, dpToPx(4), 0);
|
||||||
|
typeImageView.setLayoutParams(typeImageParams);
|
||||||
|
int drawableResId = route.type == null ? R.drawable.ic_action_polygom_dark : route.type.getResourceId();
|
||||||
|
typeImageView.setImageDrawable(getRowIcon(drawableResId));
|
||||||
|
typeView.addView(typeImageView);
|
||||||
|
|
||||||
|
TextView typeTextView = new TextView(view.getContext());
|
||||||
|
LinearLayout.LayoutParams typeTextParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
||||||
|
typeTextView.setLayoutParams(typeTextParams);
|
||||||
|
typeTextView.setText(route.type.getTypeStrRes());
|
||||||
|
typeView.addView(typeTextView);
|
||||||
|
|
||||||
|
baseView.setOnClickListener(listener);
|
||||||
|
|
||||||
|
((ViewGroup) view).addView(baseView);
|
||||||
|
|
||||||
|
return baseView;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void buildTransportRouteRow(ViewGroup parent, TransportStopRoute r, OnClickListener listener, boolean showDivider) {
|
||||||
|
buildTransportRowItem(parent, r, listener);
|
||||||
|
|
||||||
if (showDivider) {
|
if (showDivider) {
|
||||||
buildRowDivider(parent, false);
|
buildRowDivider(parent, false);
|
||||||
|
|
|
@ -58,7 +58,7 @@ public class TransportStopRoute {
|
||||||
RenderingRulesStorage rrs = ctx.getRendererRegistry().getCurrentSelectedRenderer();
|
RenderingRulesStorage rrs = ctx.getRendererRegistry().getCurrentSelectedRenderer();
|
||||||
RenderingRuleSearchRequest req = new RenderingRuleSearchRequest(rrs);
|
RenderingRuleSearchRequest req = new RenderingRuleSearchRequest(rrs);
|
||||||
req.setBooleanFilter(rrs.PROPS.R_NIGHT_MODE, nightMode);
|
req.setBooleanFilter(rrs.PROPS.R_NIGHT_MODE, nightMode);
|
||||||
String typeStr = type.getTypeStr();
|
String typeStr = type.getRendeAttr();
|
||||||
if (req.searchRenderingAttribute(typeStr)) {
|
if (req.searchRenderingAttribute(typeStr)) {
|
||||||
cachedColor = req.getIntPropertyValue(rrs.PROPS.R_ATTR_COLOR_VALUE);
|
cachedColor = req.getIntPropertyValue(rrs.PROPS.R_ATTR_COLOR_VALUE);
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,12 +17,12 @@ public enum TransportStopType {
|
||||||
|
|
||||||
final int resId;
|
final int resId;
|
||||||
final int topResId;
|
final int topResId;
|
||||||
final String typeStr;
|
final String renderAttr;
|
||||||
|
|
||||||
TransportStopType(int resId, int topResId, String typeStr) {
|
TransportStopType(int resId, int topResId, String renderAttr) {
|
||||||
this.resId = resId;
|
this.resId = resId;
|
||||||
this.topResId = topResId;
|
this.topResId = topResId;
|
||||||
this.typeStr = typeStr;
|
this.renderAttr = renderAttr;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getResourceId() {
|
public int getResourceId() {
|
||||||
|
@ -33,8 +33,8 @@ public enum TransportStopType {
|
||||||
return topResId;
|
return topResId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getTypeStr() {
|
public String getRendeAttr() {
|
||||||
return typeStr;
|
return renderAttr;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isTopType() {
|
public boolean isTopType() {
|
||||||
|
@ -51,4 +51,47 @@ public enum TransportStopType {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getTypeStrRes() {
|
||||||
|
int typeResId;
|
||||||
|
switch (this) {
|
||||||
|
case BUS:
|
||||||
|
typeResId = R.string.poi_route_bus_ref;
|
||||||
|
break;
|
||||||
|
case TRAM:
|
||||||
|
typeResId = R.string.poi_route_tram_ref;
|
||||||
|
break;
|
||||||
|
case FERRY:
|
||||||
|
typeResId = R.string.poi_route_ferry_ref;
|
||||||
|
break;
|
||||||
|
case TRAIN:
|
||||||
|
typeResId = R.string.poi_route_train_ref;
|
||||||
|
break;
|
||||||
|
case SHARE_TAXI:
|
||||||
|
typeResId = R.string.poi_route_share_taxi_ref;
|
||||||
|
break;
|
||||||
|
case FUNICULAR:
|
||||||
|
typeResId = R.string.poi_route_funicular_ref;
|
||||||
|
break;
|
||||||
|
case LIGHT_RAIL:
|
||||||
|
typeResId = R.string.poi_route_light_rail_ref;
|
||||||
|
break;
|
||||||
|
case MONORAIL:
|
||||||
|
typeResId = R.string.poi_route_monorail_ref;
|
||||||
|
break;
|
||||||
|
case TROLLEYBUS:
|
||||||
|
typeResId = R.string.poi_route_trolleybus_ref;
|
||||||
|
break;
|
||||||
|
case RAILWAY:
|
||||||
|
typeResId = R.string.poi_route_railway_ref;
|
||||||
|
break;
|
||||||
|
case SUBWAY:
|
||||||
|
typeResId = R.string.poi_route_subway_ref;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
typeResId = R.string.poi_filter_public_transport;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return typeResId;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue