Fix NoSuchMethodError, possible npe and improve ui

This commit is contained in:
Chumva 2019-02-13 12:42:26 +02:00
parent 16fde2606e
commit 79f23d96ca
11 changed files with 110 additions and 74 deletions

View file

@ -37,7 +37,7 @@ public class TransportRoutePlanner {
for(TransportRouteSegment s : endStops) {
endSegments.put(s.getId(), s);
}
PriorityQueue<TransportRouteSegment> queue = new PriorityQueue<TransportRouteSegment>(new SegmentsComparator(ctx));
PriorityQueue<TransportRouteSegment> queue = new PriorityQueue<TransportRouteSegment>(startStops.size(), new SegmentsComparator(ctx));
for(TransportRouteSegment r : startStops){
r.walkDist = (float) MapUtils.getDistance(r.getLocation(), start);
r.distFromStart = r.walkDist / ctx.cfg.walkSpeed;

View file

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true">
<shape android:shape="rectangle">
<corners android:radius="4dp" />
<solid android:color="@color/active_buttons_and_links_trans_dark" />
<stroke android:width="1dp" android:color="@color/active_buttons_and_links_dark" />
</shape>
</item>
</selector>

View file

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true">
<shape android:shape="rectangle">
<corners android:radius="4dp" />
<solid android:color="@color/active_buttons_and_links_trans_light" />
<stroke android:width="1dp" android:color="@color/active_buttons_and_links_light" />
</shape>
</item>
</selector>

View file

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true">
<shape android:shape="rectangle">
<corners android:radius="4dp" />
<solid android:color="@color/active_buttons_and_links_trans_dark" />
</shape>
</item>
</selector>

View file

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true">
<shape android:shape="rectangle">
<corners android:radius="4dp" />
<solid android:color="@color/active_buttons_and_links_trans_light" />
<stroke android:width="1dp" android:color="@color/active_buttons_and_links_light" />
</shape>
</item>
</selector>

View file

@ -1,74 +1,68 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:osmand="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/route_option_button"
android:layout_width="100dp"
android:layout_height="32dp"
android:orientation="horizontal"
android:visibility="visible"
tools:background="@drawable/btn_border_dark">
<FrameLayout
android:id="@+id/removable_option"
<LinearLayout
android:id="@+id/route_removable_option_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="visible">
android:gravity="start|center_vertical"
android:paddingLeft="8dp"
android:paddingRight="8dp">
<LinearLayout
android:id="@+id/route_removable_option_container"
android:layout_width="match_parent"
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/route_removable_option_title"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="start|center_vertical"
android:paddingLeft="8dp"
android:paddingRight="8dp">
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/route_removable_option_title"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center"
android:ellipsize="end"
android:gravity="center"
android:letterSpacing="@dimen/text_button_letter_spacing"
android:maxLines="1"
android:paddingBottom="3dp"
android:paddingTop="3dp"
android:text="@string/routing_attr_avoid_motorway_name"
android:textSize="@dimen/default_sub_text_size"
osmand:typeface="@string/font_roboto_medium"
tools:ignore="UnusedAttribute"
tools:textColor="?attr/wikivoyage_active_color" />
</LinearLayout>
<View
android:id="@+id/title_divider"
android:layout_width="wrap_content"
android:layout_height="1dp"
android:layout_gravity="center_vertical"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:background="@color/description_font_and_bottom_sheet_icons" />
<ImageView
android:id="@+id/removable_option_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|center_vertical"
android:layout_marginLeft="1dp"
android:layout_marginRight="1dp"
android:paddingBottom="3dp"
android:paddingLeft="@dimen/route_info_icon_vertical_padding"
android:paddingRight="@dimen/route_info_icon_vertical_padding"
android:layout_gravity="center"
android:ellipsize="end"
android:gravity="center"
android:letterSpacing="@dimen/text_button_letter_spacing"
android:maxLines="1"
android:paddingTop="3dp"
tools:src="@drawable/ic_action_remove_dark" />
android:paddingBottom="3dp"
android:text="@string/routing_attr_avoid_motorway_name"
android:textSize="@dimen/default_sub_text_size"
osmand:typeface="@string/font_roboto_medium"
tools:ignore="UnusedAttribute"
tools:textColor="?attr/wikivoyage_active_color" />
<View
android:id="@+id/options_divider_end"
android:layout_width="1dp"
android:layout_height="16dp"
android:layout_gravity="end|center_vertical" />
</LinearLayout>
</FrameLayout>
<View
android:id="@+id/title_divider"
android:layout_width="wrap_content"
android:layout_height="1dp"
android:layout_gravity="center_vertical"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:background="@color/description_font_and_bottom_sheet_icons" />
</LinearLayout>
<ImageView
android:id="@+id/removable_option_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|center_vertical"
android:layout_marginLeft="1dp"
android:layout_marginRight="1dp"
android:paddingLeft="@dimen/route_info_icon_vertical_padding"
android:paddingTop="3dp"
android:paddingRight="@dimen/route_info_icon_vertical_padding"
android:paddingBottom="3dp"
android:contentDescription="@string/shared_string_remove"
tools:src="@drawable/ic_action_remove_dark" />
<View
android:id="@+id/options_divider_end"
android:layout_width="1dp"
android:layout_height="16dp"
android:layout_gravity="end|center_vertical" />
</FrameLayout>

View file

@ -157,9 +157,10 @@ public class AppModeDialog {
}
iv.setImageDrawable(drawable);
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP) {
AndroidUtils.setBackground(ctx, iv, nightMode, R.drawable.btn_border_pressed_light, R.drawable.btn_border_pressed_dark);
AndroidUtils.setBackground(ctx, selection, nightMode, R.drawable.ripple_light, R.drawable.ripple_dark);
} else {
AndroidUtils.setBackground(ctx, selection, nightMode, R.drawable.btn_border_pressed_light, R.drawable.btn_border_pressed_dark);
AndroidUtils.setBackground(ctx, selection, nightMode, R.drawable.btn_border_pressed_trans_light, R.drawable.btn_border_pressed_trans_dark);
}
} else {
iv.setImageDrawable(ctx.getUIUtilities().getThemedIcon(mode.getSmallIconDark()));

View file

@ -874,7 +874,7 @@ public class MapRouteInfoMenu implements IRouteInformationListener {
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP) {
AndroidUtils.setForeground(app, container, nightMode, R.drawable.ripple_light, R.drawable.ripple_dark);
} else {
AndroidUtils.setForeground(app, container, nightMode, R.drawable.ripple_light, R.drawable.ripple_dark);
AndroidUtils.setForeground(app, container, nightMode, R.drawable.btn_pressed_trans_light, R.drawable.btn_pressed_trans_dark);
}
AndroidUtils.setBackground(app, container.findViewById(R.id.options_divider_end), nightMode, R.color.divider_light, R.color.divider_dark);
AndroidUtils.setBackground(app, routeOptionImageView, nightMode, R.drawable.route_info_trans_gradient_light, R.drawable.route_info_trans_gradient_dark);
@ -1450,7 +1450,7 @@ public class MapRouteInfoMenu implements IRouteInformationListener {
@Override
public long getItemId(int position) {
RouteSpinnerRow row = getItem(position);
return row.id;
return row != null ? row.id : -1;
}
@Override
@ -1462,7 +1462,7 @@ public class MapRouteInfoMenu implements IRouteInformationListener {
View getRowItemView(int position, View convertView, ViewGroup parent) {
TextView label = (TextView) super.getView(position, convertView, parent);
RouteSpinnerRow row = getItem(position);
label.setText(row.text);
label.setText(row != null ? row.text : "");
label.setTextColor(!isLight() ?
ContextCompat.getColorStateList(mapActivity, android.R.color.primary_text_dark) : ContextCompat.getColorStateList(mapActivity, android.R.color.primary_text_light));
return label;
@ -1473,8 +1473,8 @@ public class MapRouteInfoMenu implements IRouteInformationListener {
TextView label = (TextView) super.getDropDownView(position, convertView, parent);
RouteSpinnerRow row = getItem(position);
label.setText(row.text);
if (id != SPINNER_HINT_ID) {
label.setText(row != null ? row.text : "");
if (row != null && id != SPINNER_HINT_ID) {
Drawable icon = null;
if (row.icon != null) {
icon = row.icon;

View file

@ -227,7 +227,7 @@ public class WaypointsFragment extends BaseOsmAndFragment implements ObservableS
@Override
public String getTitle() {
List<Object> activeObjects;
if ((getMyApplication().getRoutingHelper().isRoutePlanningMode() || getMyApplication().getRoutingHelper().isFollowingMode())
if ((mapActivity.getRoutingHelper().isRoutePlanningMode() || mapActivity.getRoutingHelper().isFollowingMode())
&& item != null
&& ((activeObjects = stableAdapter.getActiveObjects()).isEmpty() || isContainsOnlyStart(activeObjects))) {
return mapActivity.getResources().getString(R.string.cancel_navigation);
@ -247,7 +247,7 @@ public class WaypointsFragment extends BaseOsmAndFragment implements ObservableS
List<Object> activeObjects = stableAdapter.getActiveObjects();
if (activeObjects.isEmpty() || isContainsOnlyStart(activeObjects)) {
mapActivity.getMapActions().stopNavigationWithoutConfirm();
getMyApplication().getTargetPointsHelper().removeAllWayPoints(false, true);
mapActivity.getMyApplication().getTargetPointsHelper().removeAllWayPoints(false, true);
mapActivity.getMapLayers().getMapControlsLayer().getMapRouteInfoMenu().hide();
}
}
@ -410,7 +410,7 @@ public class WaypointsFragment extends BaseOsmAndFragment implements ObservableS
}
addButtonDescr.setText(R.string.shared_string_add);
addButtonDescr.setCompoundDrawablesWithIntrinsicBounds(getIcon(R.drawable.ic_action_plus, R.color.active_buttons_and_links_light), null, null, null);
addButtonDescr.setCompoundDrawablesWithIntrinsicBounds(getIcon(R.drawable.ic_action_plus, nightMode ? R.color.active_buttons_and_links_dark : R.color.active_buttons_and_links_light), null, null, null);
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP) {
AndroidUtils.setBackground(app, addButton, nightMode, R.drawable.btn_border_light, R.drawable.btn_border_dark);
AndroidUtils.setBackground(app, addButtonDescr, nightMode, R.drawable.ripple_light, R.drawable.ripple_dark);
@ -425,13 +425,13 @@ public class WaypointsFragment extends BaseOsmAndFragment implements ObservableS
FrameLayout clearButton = view.findViewById(R.id.clear_all_button);
TextView clearButtonDescr = (TextView) view.findViewById(R.id.clear_all_button_descr);
clearButtonDescr.setText(R.string.shared_string_clear_all);
clearButtonDescr.setCompoundDrawablesWithIntrinsicBounds(getIcon(R.drawable.ic_action_clear_all, R.color.active_buttons_and_links_light), null, null, null);
AndroidUtils.setBackground(app, clearButton, nightMode, R.drawable.btn_border_light, R.drawable.btn_border_dark);
clearButtonDescr.setCompoundDrawablesWithIntrinsicBounds(getIcon(R.drawable.ic_action_clear_all, nightMode ? R.color.active_buttons_and_links_dark : R.color.active_buttons_and_links_light), null, null, null);
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP) {
AndroidUtils.setBackground(app, clearButton, nightMode, R.drawable.btn_border_light, R.drawable.btn_border_dark);
AndroidUtils.setBackground(app, clearButtonDescr, nightMode, R.drawable.ripple_light, R.drawable.ripple_dark);
} else {
AndroidUtils.setBackground(app, clearButtonDescr, nightMode, R.drawable.ripple_light, R.drawable.ripple_dark);
AndroidUtils.setBackground(app, clearButtonDescr, nightMode, R.drawable.btn_border_trans_light, R.drawable.btn_border_trans_dark);
}
AndroidUtils.setBackground(app, view.findViewById(R.id.dividerControlButtons), nightMode,
@ -468,7 +468,9 @@ public class WaypointsFragment extends BaseOsmAndFragment implements ObservableS
public void onItemClick(AdapterView<?> adapterView, View view, int item, long l) {
if (listAdapter.getItem(item) instanceof WaypointHelper.LocationPointWrapper) {
WaypointHelper.LocationPointWrapper ps = (WaypointHelper.LocationPointWrapper) listAdapter.getItem(item);
showOnMap(app, ctx, ps.getPoint(), false);
if (ps != null) {
showOnMap(app, ctx, ps.getPoint(), false);
}
dismiss();
}
}
@ -552,7 +554,7 @@ public class WaypointsFragment extends BaseOsmAndFragment implements ObservableS
public void setupRouteCalculationButtonProgressBar(@NonNull ProgressBar pb) {
int bgColor = ContextCompat.getColor(app, nightMode ? R.color.route_info_cancel_button_color_dark : R.color.activity_background_light);
int progressColor = ContextCompat.getColor(getMyApplication(), nightMode ? R.color.active_buttons_and_links_dark : R.color.active_buttons_and_links_light);
int progressColor = ContextCompat.getColor(app, nightMode ? R.color.active_buttons_and_links_dark : R.color.active_buttons_and_links_light);
pb.setProgressDrawable(AndroidUtils.createProgressDrawable(bgColor, progressColor));
}
@ -565,7 +567,7 @@ public class WaypointsFragment extends BaseOsmAndFragment implements ObservableS
private void updateListAdapter() {
List<WaypointHelper.LocationPointWrapper> deletedPoints = new ArrayList<>();
listView.setEmptyView(null);
StableArrayAdapter listAdapter = getWaypointsDrawerAdapter(true, deletedPoints, mapActivity, running, false, false);
StableArrayAdapter listAdapter = getWaypointsDrawerAdapter(true, deletedPoints, mapActivity, running, false, nightMode);
AdapterView.OnItemClickListener listener = getDrawerItemClickListener(mapActivity, running, listAdapter);
setDynamicListItems(listView, listAdapter);
updateListAdapter(listAdapter, listener);

View file

@ -27,6 +27,7 @@ public abstract class BaseRouteCard {
public BaseRouteCard(MapActivity mapActivity) {
this.mapActivity = mapActivity;
this.app = mapActivity.getMyApplication();
nightMode = mapActivity.getMyApplication().getDaynightHelper().isNightModeForMapControls();
}
public abstract int getCardLayoutId();

View file

@ -2,7 +2,6 @@ package net.osmand.plus.routepreparationmenu.routeCards;
import android.graphics.Typeface;
import android.graphics.drawable.GradientDrawable;
import android.graphics.drawable.RippleDrawable;
import android.os.Build;
import android.support.v4.content.ContextCompat;
import android.text.SpannableString;