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) { for(TransportRouteSegment s : endStops) {
endSegments.put(s.getId(), s); 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){ for(TransportRouteSegment r : startStops){
r.walkDist = (float) MapUtils.getDistance(r.getLocation(), start); r.walkDist = (float) MapUtils.getDistance(r.getLocation(), start);
r.distFromStart = r.walkDist / ctx.cfg.walkSpeed; 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,19 +1,14 @@
<?xml version="1.0" encoding="utf-8"?> <?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:osmand="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/route_option_button" android:id="@+id/route_option_button"
android:layout_width="100dp" android:layout_width="100dp"
android:layout_height="32dp" android:layout_height="32dp"
android:orientation="horizontal" android:orientation="horizontal"
android:visibility="visible"
tools:background="@drawable/btn_border_dark"> tools:background="@drawable/btn_border_dark">
<FrameLayout
android:id="@+id/removable_option"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="visible">
<LinearLayout <LinearLayout
android:id="@+id/route_removable_option_container" android:id="@+id/route_removable_option_container"
android:layout_width="match_parent" android:layout_width="match_parent"
@ -31,8 +26,8 @@
android:gravity="center" android:gravity="center"
android:letterSpacing="@dimen/text_button_letter_spacing" android:letterSpacing="@dimen/text_button_letter_spacing"
android:maxLines="1" android:maxLines="1"
android:paddingBottom="3dp"
android:paddingTop="3dp" android:paddingTop="3dp"
android:paddingBottom="3dp"
android:text="@string/routing_attr_avoid_motorway_name" android:text="@string/routing_attr_avoid_motorway_name"
android:textSize="@dimen/default_sub_text_size" android:textSize="@dimen/default_sub_text_size"
osmand:typeface="@string/font_roboto_medium" osmand:typeface="@string/font_roboto_medium"
@ -57,10 +52,11 @@
android:layout_gravity="end|center_vertical" android:layout_gravity="end|center_vertical"
android:layout_marginLeft="1dp" android:layout_marginLeft="1dp"
android:layout_marginRight="1dp" android:layout_marginRight="1dp"
android:paddingBottom="3dp"
android:paddingLeft="@dimen/route_info_icon_vertical_padding" android:paddingLeft="@dimen/route_info_icon_vertical_padding"
android:paddingRight="@dimen/route_info_icon_vertical_padding"
android:paddingTop="3dp" 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" /> tools:src="@drawable/ic_action_remove_dark" />
<View <View
@ -69,6 +65,4 @@
android:layout_height="16dp" android:layout_height="16dp"
android:layout_gravity="end|center_vertical" /> android:layout_gravity="end|center_vertical" />
</FrameLayout> </FrameLayout>
</LinearLayout>

View file

@ -157,9 +157,10 @@ public class AppModeDialog {
} }
iv.setImageDrawable(drawable); iv.setImageDrawable(drawable);
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP) { 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); AndroidUtils.setBackground(ctx, selection, nightMode, R.drawable.ripple_light, R.drawable.ripple_dark);
} else { } 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 { } else {
iv.setImageDrawable(ctx.getUIUtilities().getThemedIcon(mode.getSmallIconDark())); 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) { if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP) {
AndroidUtils.setForeground(app, container, nightMode, R.drawable.ripple_light, R.drawable.ripple_dark); AndroidUtils.setForeground(app, container, nightMode, R.drawable.ripple_light, R.drawable.ripple_dark);
} else { } 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, 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); 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 @Override
public long getItemId(int position) { public long getItemId(int position) {
RouteSpinnerRow row = getItem(position); RouteSpinnerRow row = getItem(position);
return row.id; return row != null ? row.id : -1;
} }
@Override @Override
@ -1462,7 +1462,7 @@ public class MapRouteInfoMenu implements IRouteInformationListener {
View getRowItemView(int position, View convertView, ViewGroup parent) { View getRowItemView(int position, View convertView, ViewGroup parent) {
TextView label = (TextView) super.getView(position, convertView, parent); TextView label = (TextView) super.getView(position, convertView, parent);
RouteSpinnerRow row = getItem(position); RouteSpinnerRow row = getItem(position);
label.setText(row.text); label.setText(row != null ? row.text : "");
label.setTextColor(!isLight() ? label.setTextColor(!isLight() ?
ContextCompat.getColorStateList(mapActivity, android.R.color.primary_text_dark) : ContextCompat.getColorStateList(mapActivity, android.R.color.primary_text_light)); ContextCompat.getColorStateList(mapActivity, android.R.color.primary_text_dark) : ContextCompat.getColorStateList(mapActivity, android.R.color.primary_text_light));
return label; return label;
@ -1473,8 +1473,8 @@ public class MapRouteInfoMenu implements IRouteInformationListener {
TextView label = (TextView) super.getDropDownView(position, convertView, parent); TextView label = (TextView) super.getDropDownView(position, convertView, parent);
RouteSpinnerRow row = getItem(position); RouteSpinnerRow row = getItem(position);
label.setText(row.text); label.setText(row != null ? row.text : "");
if (id != SPINNER_HINT_ID) { if (row != null && id != SPINNER_HINT_ID) {
Drawable icon = null; Drawable icon = null;
if (row.icon != null) { if (row.icon != null) {
icon = row.icon; icon = row.icon;

View file

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

View file

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

View file

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