From ef37c28ebd861c7ec967a5c6db46380c02764938 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Tue, 9 Jul 2019 13:22:03 +0200 Subject: [PATCH 1/5] Fix compilation --- OsmAnd/src/net/osmand/aidl/IOsmAndAidlInterface.aidl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OsmAnd/src/net/osmand/aidl/IOsmAndAidlInterface.aidl b/OsmAnd/src/net/osmand/aidl/IOsmAndAidlInterface.aidl index b0cd6be027..c130c47290 100644 --- a/OsmAnd/src/net/osmand/aidl/IOsmAndAidlInterface.aidl +++ b/OsmAnd/src/net/osmand/aidl/IOsmAndAidlInterface.aidl @@ -829,5 +829,5 @@ interface IOsmAndAidlInterface { * Removes all active map markers (marks them as passed and moves to history) * Empty class of params */ - boolean removeAllActiveMapMarkers(in RemoveMapMarkersParams); + boolean removeAllActiveMapMarkers(in RemoveMapMarkersParams params); } From 72ae21288e1f02390d041698a3b0181d35d14c5a Mon Sep 17 00:00:00 2001 From: crimean Date: Tue, 9 Jul 2019 14:20:10 +0300 Subject: [PATCH 2/5] Fix aidl compilation --- OsmAnd/src/net/osmand/aidl/IOsmAndAidlInterface.aidl | 1 + OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java | 2 +- OsmAnd/src/net/osmand/aidl/OsmandAidlService.java | 8 ++++---- .../net/osmand/aidl/mapmarker/RemoveMapMarkersParams.aidl | 2 +- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/OsmAnd/src/net/osmand/aidl/IOsmAndAidlInterface.aidl b/OsmAnd/src/net/osmand/aidl/IOsmAndAidlInterface.aidl index c130c47290..2038a68fbd 100644 --- a/OsmAnd/src/net/osmand/aidl/IOsmAndAidlInterface.aidl +++ b/OsmAnd/src/net/osmand/aidl/IOsmAndAidlInterface.aidl @@ -90,6 +90,7 @@ import net.osmand.aidl.contextmenu.ContextMenuButtonsParams; import net.osmand.aidl.contextmenu.UpdateContextMenuButtonsParams; import net.osmand.aidl.contextmenu.RemoveContextMenuButtonsParams; +import net.osmand.aidl.mapmarker.RemoveMapMarkersParams; // NOTE: Add new methods at the end of file!!! diff --git a/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java b/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java index 331566f132..68e5a9959f 100644 --- a/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java +++ b/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java @@ -1057,7 +1057,7 @@ public class OsmandAidlApi { } } - boolean removeAllMapMarkers() { + boolean removeAllActiveMapMarkers() { boolean refreshNeeded = false; MapMarkersHelper markersHelper = app.getMapMarkersHelper(); List mapMarkers = markersHelper.getMapMarkers(); diff --git a/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java b/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java index 4cccbbbbca..bec6725bdc 100644 --- a/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java +++ b/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java @@ -49,6 +49,7 @@ import net.osmand.aidl.maplayer.point.ShowMapPointParams; import net.osmand.aidl.maplayer.point.UpdateMapPointParams; import net.osmand.aidl.mapmarker.AddMapMarkerParams; import net.osmand.aidl.mapmarker.RemoveMapMarkerParams; +import net.osmand.aidl.mapmarker.RemoveMapMarkersParams; import net.osmand.aidl.mapmarker.UpdateMapMarkerParams; import net.osmand.aidl.mapwidget.AddMapWidgetParams; import net.osmand.aidl.mapwidget.RemoveMapWidgetParams; @@ -75,7 +76,6 @@ import net.osmand.aidl.search.SearchParams; import net.osmand.aidl.search.SearchResult; import net.osmand.aidl.tiles.ASqliteDbFile; import net.osmand.plus.OsmandApplication; -import net.osmand.plus.routing.VoiceRouter; import net.osmand.util.Algorithms; import org.apache.commons.logging.Log; @@ -1165,10 +1165,10 @@ public class OsmandAidlService extends Service implements AidlCallbackListener { } @Override - public boolean removeAllMapMarkers() { + public boolean removeAllActiveMapMarkers(RemoveMapMarkersParams params) { try { - OsmandAidlApi api = getApi("removeAllMapMarkers"); - return api != null && api.removeAllMapMarkers(); + OsmandAidlApi api = getApi("removeAllActiveMapMarkers"); + return api != null && api.removeAllActiveMapMarkers(); } catch (Exception e) { handleException(e); return false; diff --git a/OsmAnd/src/net/osmand/aidl/mapmarker/RemoveMapMarkersParams.aidl b/OsmAnd/src/net/osmand/aidl/mapmarker/RemoveMapMarkersParams.aidl index e5b5b126ad..ee5f4936d7 100644 --- a/OsmAnd/src/net/osmand/aidl/mapmarker/RemoveMapMarkersParams.aidl +++ b/OsmAnd/src/net/osmand/aidl/mapmarker/RemoveMapMarkersParams.aidl @@ -1,3 +1,3 @@ package net.osmand.aidl.mapmarker; -parcelable RemoveMapMarkerParams; \ No newline at end of file +parcelable RemoveMapMarkersParams; \ No newline at end of file From 3e8799f63afd583ed3a0ee6401021f3b7c0692ec Mon Sep 17 00:00:00 2001 From: crimean Date: Tue, 9 Jul 2019 14:05:58 +0300 Subject: [PATCH 3/5] Fix monitoring plugin dialog code (cherry picked from commit 49d5016419feb63da0b84bccb80feafa500eaf3c) --- .../OnSaveCurrentTrackFragment.java | 2 +- .../monitoring/OsmandMonitoringPlugin.java | 39 ++++++++----------- 2 files changed, 18 insertions(+), 23 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/monitoring/OnSaveCurrentTrackFragment.java b/OsmAnd/src/net/osmand/plus/monitoring/OnSaveCurrentTrackFragment.java index 9cd177191c..e7957ddc02 100644 --- a/OsmAnd/src/net/osmand/plus/monitoring/OnSaveCurrentTrackFragment.java +++ b/OsmAnd/src/net/osmand/plus/monitoring/OnSaveCurrentTrackFragment.java @@ -33,7 +33,7 @@ public class OnSaveCurrentTrackFragment extends BottomSheetDialogFragment { @Nullable @Override public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - final OsmandApplication app = getMyApplication(); + final OsmandApplication app = requiredMyApplication(); Bundle args = getArguments(); String savedGpxName = ""; if (args != null && args.containsKey(SAVED_TRACK_KEY)) { diff --git a/OsmAnd/src/net/osmand/plus/monitoring/OsmandMonitoringPlugin.java b/OsmAnd/src/net/osmand/plus/monitoring/OsmandMonitoringPlugin.java index 73bf7137e1..f8b2866e16 100644 --- a/OsmAnd/src/net/osmand/plus/monitoring/OsmandMonitoringPlugin.java +++ b/OsmAnd/src/net/osmand/plus/monitoring/OsmandMonitoringPlugin.java @@ -5,6 +5,7 @@ import android.content.Context; import android.content.DialogInterface; import android.content.DialogInterface.OnClickListener; import android.support.annotation.Nullable; +import android.support.v4.app.FragmentActivity; import android.support.v7.app.AlertDialog; import android.util.DisplayMetrics; import android.view.View; @@ -18,7 +19,6 @@ import android.widget.SeekBar; import android.widget.SeekBar.OnSeekBarChangeListener; import android.widget.TextView; -import java.lang.ref.WeakReference; import net.osmand.AndroidUtils; import net.osmand.Location; import net.osmand.ValueHolder; @@ -38,11 +38,12 @@ import net.osmand.plus.views.MapInfoLayer; import net.osmand.plus.views.OsmandMapLayer.DrawSettings; import net.osmand.plus.views.OsmandMapTileView; import net.osmand.plus.views.mapwidgets.TextInfoWidget; +import net.osmand.util.Algorithms; +import java.lang.ref.WeakReference; import java.util.List; import gnu.trove.list.array.TIntArrayList; -import net.osmand.util.Algorithms; public class OsmandMonitoringPlugin extends OsmandPlugin { public static final String ID = "osmand.monitoring"; @@ -261,10 +262,10 @@ public class OsmandMonitoringPlugin extends OsmandPlugin { return monitoringControl; } - public void controlDialog(final Activity map, final boolean showTrackSelection) { + public void controlDialog(final Activity activity, final boolean showTrackSelection) { final boolean wasTrackMonitored = settings.SAVE_GLOBAL_TRACK_TO_GPX.get(); - AlertDialog.Builder bld = new AlertDialog.Builder(map); + AlertDialog.Builder bld = new AlertDialog.Builder(activity); final TIntArrayList items = new TIntArrayList(); if (wasTrackMonitored) { items.add(R.string.gpx_monitoring_stop); @@ -291,14 +292,10 @@ public class OsmandMonitoringPlugin extends OsmandPlugin { int which = holder[0]; int item = items.get(which); if(item == R.string.save_current_track){ - if (map instanceof MapActivity) { - saveCurrentTrack(new WeakReference<>((MapActivity) map)); - } else { - saveCurrentTrack(); - } + saveCurrentTrack(null, activity); } else if(item == R.string.gpx_monitoring_start) { - if (app.getLocationProvider().checkGPSEnabled(map)) { - startGPXMonitoring(map, showTrackSelection); + if (app.getLocationProvider().checkGPSEnabled(activity)) { + startGPXMonitoring(activity, showTrackSelection); } } else if(item == R.string.gpx_monitoring_stop) { stopRecording(); @@ -309,7 +306,7 @@ public class OsmandMonitoringPlugin extends OsmandPlugin { } else if(item == R.string.live_monitoring_start) { final ValueHolder vs = new ValueHolder(); vs.value = settings.LIVE_MONITORING_INTERVAL.get(); - showIntervalChooseDialog(map, app.getString(R.string.live_monitoring_interval) + " : %s", + showIntervalChooseDialog(activity, app.getString(R.string.live_monitoring_interval) + " : %s", app.getString(R.string.save_track_to_gpx_globally), SECONDS, MINUTES, null, vs, showTrackSelection, new OnClickListener() { @Override @@ -344,12 +341,10 @@ public class OsmandMonitoringPlugin extends OsmandPlugin { saveCurrentTrack(onComplete, null); } - public void saveCurrentTrack(@Nullable final WeakReference mapActivityRef) { - saveCurrentTrack(null, mapActivityRef); - } - - public void saveCurrentTrack(@Nullable final Runnable onComplete, - @Nullable final WeakReference mapActivityRef) { + public void saveCurrentTrack(@Nullable final Runnable onComplete, @Nullable Activity activity) { + + final WeakReference activityRef = activity != null ? new WeakReference<>(activity) : null; + app.getTaskManager().runInBackground(new OsmAndTaskRunnable() { @Override @@ -376,10 +371,10 @@ public class OsmandMonitoringPlugin extends OsmandPlugin { isSaving = false; app.getNotificationHelper().refreshNotifications(); updateControl(); - if (mapActivityRef != null && !Algorithms.isEmpty(result.getFilenames())) { - final MapActivity a = mapActivityRef.get(); - if (a != null && !a.isFinishing()) { - OnSaveCurrentTrackFragment.showInstance(a.getSupportFragmentManager(), result.getFilenames().get(0)); + if (activityRef != null && !Algorithms.isEmpty(result.getFilenames())) { + final Activity a = activityRef.get(); + if (a instanceof FragmentActivity && !a.isFinishing()) { + OnSaveCurrentTrackFragment.showInstance(((FragmentActivity) a).getSupportFragmentManager(), result.getFilenames().get(0)); } } From fca3c95c5deb61c130dc540b6efd3b49b124b8c4 Mon Sep 17 00:00:00 2001 From: Chumva Date: Tue, 9 Jul 2019 14:09:39 +0300 Subject: [PATCH 4/5] Fix progress button redrawing (cherry picked from commit e3d2681bf58933a9a38a2baea716ad3dbf7f2884) --- .../MapRouteInfoMenu.java | 21 +++++-- .../MapRouteInfoMenuFragment.java | 19 ++---- .../WaypointsFragment.java | 19 +++--- .../plus/widgets/ImageViewExProgress.java | 55 ----------------- .../plus/widgets/TextViewExProgress.java | 61 +++++++------------ 5 files changed, 55 insertions(+), 120 deletions(-) delete mode 100644 OsmAnd/src/net/osmand/plus/widgets/ImageViewExProgress.java diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenu.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenu.java index cd73b8e4be..2f131e441b 100644 --- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenu.java +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenu.java @@ -3,11 +3,11 @@ package net.osmand.plus.routepreparationmenu; import android.content.Context; import android.content.DialogInterface.OnDismissListener; -import android.content.res.Configuration; import android.graphics.PointF; import android.graphics.drawable.Drawable; import android.os.Build; import android.os.Handler; +import android.support.annotation.ColorRes; import android.support.annotation.DrawableRes; import android.support.annotation.NonNull; import android.support.annotation.Nullable; @@ -27,6 +27,7 @@ import android.widget.FrameLayout; import android.widget.HorizontalScrollView; import android.widget.ImageView; import android.widget.LinearLayout; +import android.widget.ProgressBar; import android.widget.TextView; import net.osmand.AndroidUtils; @@ -97,6 +98,8 @@ import net.osmand.search.SearchUICore.SearchResultCollection; import net.osmand.search.core.SearchResult; import net.osmand.util.MapUtils; +import org.apache.commons.logging.Log; + import java.io.IOException; import java.lang.ref.WeakReference; import java.util.ArrayList; @@ -106,7 +109,6 @@ import java.util.List; import java.util.Map; import java.util.Set; import java.util.TreeMap; -import org.apache.commons.logging.Log; public class MapRouteInfoMenu implements IRouteInformationListener, CardListener { @@ -917,6 +919,7 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener final RoutingHelper helper = app.getRoutingHelper(); View startButton = mainView.findViewById(R.id.start_button); TextViewExProgress startButtonText = (TextViewExProgress) mainView.findViewById(R.id.start_button_descr); + ProgressBar progressBar = (ProgressBar) mainView.findViewById(R.id.progress_bar_button); boolean publicTransportMode = helper.getAppMode() == ApplicationMode.PUBLIC_TRANSPORT; boolean routeCalculated = isRouteCalculated(); int iconId = publicTransportMode ? R.drawable.ic_map : R.drawable.ic_action_start_navigation; @@ -942,8 +945,8 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener color2 = R.color.description_font_and_bottom_sheet_icons; } } - startButtonText.color1 = ContextCompat.getColor(mapActivity, color1); - startButtonText.color2 = ContextCompat.getColor(mapActivity, color2); + setupRouteCalculationButtonProgressBar(progressBar, startButtonText, color1, color2); + startButtonText.setCompoundDrawablesWithIntrinsicBounds(app.getUIUtilities().getIcon(iconId, color2), null, null, null); if (publicTransportMode) { startButtonText.setText(R.string.shared_string_show_on_map); @@ -976,6 +979,16 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener }); } + private void setupRouteCalculationButtonProgressBar(@NonNull ProgressBar pb, @NonNull TextViewExProgress textProgress, @ColorRes int progressTextColor, @ColorRes int bgTextColor) { + MapActivity mapActivity = getMapActivity(); + if (mapActivity != null) { + int progressColor = ContextCompat.getColor(mapActivity, nightMode ? R.color.active_color_primary_dark : R.color.active_color_primary_light); + pb.setProgressDrawable(AndroidUtils.createProgressDrawable(ContextCompat.getColor(mapActivity, R.color.color_transparent), ContextCompat.getColor(mapActivity, progressTextColor))); + textProgress.paint.setColor(progressColor); + textProgress.setTextColor(ContextCompat.getColor(mapActivity, bgTextColor)); + } + } + private void createRoutingParametersButtons(MapActivity mapActivity, final RouteMenuAppModes mode, LinearLayout optionsContainer) { if (mapActivity == null || optionsContainer == null) { return; diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenuFragment.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenuFragment.java index 8b4327d00b..73586f0266 100644 --- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenuFragment.java +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenuFragment.java @@ -379,7 +379,7 @@ public class MapRouteInfoMenuFragment extends ContextMenuFragment { progressBarButton.setProgress(progress); } TextViewExProgress textViewExProgress = (TextViewExProgress) view.findViewById(R.id.start_button_descr); - textViewExProgress.percent = progress / 100f; + textViewExProgress.percent = publicTransportMode ? 0 : progress / 100f; textViewExProgress.invalidate(); } @@ -395,12 +395,12 @@ public class MapRouteInfoMenuFragment extends ContextMenuFragment { if (progressBar != null) { progressBar.setVisibility(View.GONE); } - View progressBarButton = view.findViewById(R.id.progress_bar_button); + ProgressBar progressBarButton = (ProgressBar) view.findViewById(R.id.progress_bar_button); if (progressBarButton != null) { - progressBarButton.setVisibility(View.GONE); + progressBarButton.setProgress(100); } TextViewExProgress textViewExProgress = (TextViewExProgress) view.findViewById(R.id.start_button_descr); - textViewExProgress.percent = 1; + textViewExProgress.percent = isPublicTransportMode() ? 0 : 1; } public void show(MapActivity mapActivity) { @@ -469,7 +469,6 @@ public class MapRouteInfoMenuFragment extends ContextMenuFragment { ((TextView) mainView.findViewById(R.id.toTitle)).setTextColor(descriptionColor); ctx.setupRouteCalculationProgressBar((ProgressBar) mainView.findViewById(R.id.progress_bar)); - setupRouteCalculationButtonProgressBar((ProgressBar) view.findViewById(R.id.progress_bar_button)); } public static boolean showInstance(final MapActivity mapActivity, int initialMenuState) { @@ -506,14 +505,4 @@ public class MapRouteInfoMenuFragment extends ContextMenuFragment { return false; } } - - public void setupRouteCalculationButtonProgressBar(@NonNull ProgressBar pb) { - MapActivity mapActivity = getMapActivity(); - if (mapActivity != null) { - int bgColor = ContextCompat.getColor(mapActivity, isNightMode() ? R.color.activity_background_dark : R.color.activity_background_light); - int progressColor = ContextCompat.getColor(mapActivity, isNightMode() ? R.color.active_color_primary_dark : R.color.active_color_primary_light); - pb.setProgressDrawable(AndroidUtils.createProgressDrawable(bgColor, progressColor)); - pb.getIndeterminateDrawable().setColorFilter(progressColor, android.graphics.PorterDuff.Mode.SRC_IN); - } - } } \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/WaypointsFragment.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/WaypointsFragment.java index b754e6c319..477152f06b 100644 --- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/WaypointsFragment.java +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/WaypointsFragment.java @@ -4,6 +4,7 @@ import android.content.Context; import android.os.Build; import android.os.Bundle; import android.os.CountDownTimer; +import android.support.annotation.ColorRes; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.v4.app.FragmentActivity; @@ -425,9 +426,13 @@ public class WaypointsFragment extends BaseOsmAndFragment implements ObservableS AndroidUtils.setBackground(mapActivity, view.findViewById(R.id.controls_divider), nightMode, R.color.divider_color_light, R.color.divider_color_dark); ((TextView) view.findViewById(R.id.cancel_button_descr)).setTextColor(colorActive); - ((TextView) view.findViewById(R.id.start_button_descr)).setText(getText(R.string.shared_string_apply)); - setupRouteCalculationButtonProgressBar((ProgressBar) view.findViewById(R.id.progress_bar_button)); + TextViewExProgress startButtonText = (TextViewExProgress) view.findViewById(R.id.start_button_descr); + ProgressBar progressBar = (ProgressBar) view.findViewById(R.id.progress_bar_button); + startButtonText.setText(getText(R.string.shared_string_apply)); + + int progressTextColor = nightMode ? R.color.active_buttons_and_links_text_disabled_dark : R.color.active_buttons_and_links_text_light; + setupRouteCalculationButtonProgressBar(progressBar, startButtonText, progressTextColor); } public void reloadListAdapter(ArrayAdapter listAdapter) { @@ -551,19 +556,17 @@ public class WaypointsFragment extends BaseOsmAndFragment implements ObservableS } TextViewExProgress textViewExProgress = (TextViewExProgress) view.findViewById(R.id.start_button_descr); textViewExProgress.percent = progress / 100f; - int color = nightMode ? R.color.active_buttons_and_links_text_disabled_dark : R.color.active_buttons_and_links_text_light; - textViewExProgress.color1 = ContextCompat.getColor(mapActivity, color); - textViewExProgress.color2 = ContextCompat.getColor(mapActivity, R.color.active_buttons_and_links_text_disabled_dark); textViewExProgress.invalidate(); } - public void setupRouteCalculationButtonProgressBar(@NonNull ProgressBar pb) { + private void setupRouteCalculationButtonProgressBar(@NonNull ProgressBar pb, @NonNull TextViewExProgress textProgress, @ColorRes int progressTextColor) { OsmandApplication app = getMyApplication(); if (app != null) { int bgColor = ContextCompat.getColor(app, nightMode ? R.color.activity_background_dark : R.color.activity_background_light); int progressColor = ContextCompat.getColor(app, nightMode ? R.color.active_color_primary_dark : R.color.active_color_primary_light); - - pb.setProgressDrawable(AndroidUtils.createProgressDrawable(bgColor, progressColor)); + pb.setProgressDrawable(AndroidUtils.createProgressDrawable(bgColor, ContextCompat.getColor(app, progressTextColor))); + textProgress.paint.setColor(progressColor); + textProgress.setTextColor(ContextCompat.getColor(app, R.color.active_buttons_and_links_text_disabled_dark)); } } diff --git a/OsmAnd/src/net/osmand/plus/widgets/ImageViewExProgress.java b/OsmAnd/src/net/osmand/plus/widgets/ImageViewExProgress.java deleted file mode 100644 index 43c7d66575..0000000000 --- a/OsmAnd/src/net/osmand/plus/widgets/ImageViewExProgress.java +++ /dev/null @@ -1,55 +0,0 @@ -package net.osmand.plus.widgets; - -import android.annotation.TargetApi; -import android.content.Context; -import android.graphics.Canvas; -import android.graphics.Rect; -import android.support.annotation.Nullable; -import android.util.AttributeSet; -import android.widget.ImageView; - -public class ImageViewExProgress extends ImageView { - - public float percent; - public int color1; - public int color2; - - public ImageViewExProgress(Context context) { - super(context); - } - - public ImageViewExProgress(Context context, @Nullable AttributeSet attrs) { - super(context, attrs); - } - - public ImageViewExProgress(Context context, @Nullable AttributeSet attrs, int defStyleAttr) { - super(context, attrs, defStyleAttr); - } - - @TargetApi(21) - public ImageViewExProgress(Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) { - super(context, attrs, defStyleAttr, defStyleRes); - } - - - @Override - public void draw(Canvas canvas) { - canvas.save(); - setColorFilter(color1); - int width = getWidth(); - int widthP = (int) (width * percent); - int height = getHeight(); - canvas.clipRect(new Rect(0, 0, widthP, height)); - super.draw(canvas); - canvas.restore(); - - canvas.save(); - setColorFilter(color2); - int width2 = getWidth(); - int widthP2 = (int) (width2 * percent); - int height2 = getHeight(); - canvas.clipRect(new Rect(widthP2, 0, width2, height2)); - super.draw(canvas); - canvas.restore(); - } -} \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/widgets/TextViewExProgress.java b/OsmAnd/src/net/osmand/plus/widgets/TextViewExProgress.java index d3dcd1089e..a7a79088ee 100644 --- a/OsmAnd/src/net/osmand/plus/widgets/TextViewExProgress.java +++ b/OsmAnd/src/net/osmand/plus/widgets/TextViewExProgress.java @@ -2,67 +2,52 @@ package net.osmand.plus.widgets; import android.content.Context; import android.graphics.Canvas; +import android.graphics.Paint; import android.graphics.PorterDuff; -import android.graphics.Rect; -import android.graphics.drawable.Drawable; +import android.graphics.PorterDuffXfermode; import android.util.AttributeSet; public class TextViewExProgress extends TextViewEx { + + public Paint paint; public float percent; - public int color1; - public int color2; public TextViewExProgress(Context context) { super(context); + initPaint(); } public TextViewExProgress(Context context, AttributeSet attrs) { super(context, attrs); + initPaint(); } public TextViewExProgress(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); + initPaint(); } public TextViewExProgress(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { super(context, attrs, defStyleAttr, defStyleRes); + initPaint(); } @Override - public void draw(Canvas canvas) { - canvas.save(); - setTextColor(color1); - Drawable[] icons = getCompoundDrawables(); - for (int i = 0; i < icons.length; i++) { - Drawable drawable = icons[i]; - if (drawable != null) { - drawable.setColorFilter(color1, PorterDuff.Mode.SRC_ATOP); - icons[i] = drawable; - } - } - setCompoundDrawables(icons[0], icons[1], icons[2], icons[3]); - int width = getWidth(); - int widthP = (int) (width * percent); - int height = getHeight(); - canvas.clipRect(new Rect(0, 0, widthP, height)); - super.draw(canvas); - canvas.restore(); + public void onDraw(Canvas canvas) { + super.onDraw(canvas); + drawProgress(canvas); + } - canvas.save(); - setTextColor(color2); - for (int i = 0; i < icons.length; i++) { - Drawable drawable = icons[i]; - if (drawable != null) { - drawable.setColorFilter(color2, PorterDuff.Mode.SRC_ATOP); - icons[i] = drawable; - } - } - setCompoundDrawables(icons[0], icons[1], icons[2], icons[3]); - int width2 = getWidth(); - int widthP2 = (int) (width2 * percent); - int height2 = getHeight(); - canvas.clipRect(new Rect(widthP2, 0, width2, height2)); - super.draw(canvas); - canvas.restore(); + private void drawProgress(Canvas canvas) { + int w = getWidth(); + int h = getHeight(); + float rectW = w * (percent); + canvas.drawRect(0, 0, rectW, h, paint); + } + + private void initPaint() { + paint = new Paint(); + paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.XOR)); + setLayerType(LAYER_TYPE_SOFTWARE, null); } } \ No newline at end of file From 60a68a416858bd34f2e867e581efcf6ccaa6e2a5 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Tue, 9 Jul 2019 14:27:34 +0200 Subject: [PATCH 5/5] Fix api --- .../net/osmand/aidl/IOsmAndAidlCallback.aidl | 3 +- OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java | 5 +- .../navigation/OnVoiceNavigationParams.aidl | 3 + .../navigation/OnVoiceNavigationParams.java | 55 +++++++++++++++++++ .../net/osmand/plus/routing/VoiceRouter.java | 18 +++--- .../net/osmand/plus/voice/CommandBuilder.java | 20 +++++-- .../net/osmand/plus/voice/CommandPlayer.java | 2 +- .../osmand/plus/voice/JSCommandBuilder.java | 11 +--- .../plus/voice/JSMediaCommandPlayerImpl.java | 9 ++- .../plus/voice/MediaCommandPlayerImpl.java | 9 ++- .../plus/voice/TTSCommandPlayerImpl.java | 3 +- 11 files changed, 105 insertions(+), 33 deletions(-) create mode 100644 OsmAnd/src/net/osmand/aidl/navigation/OnVoiceNavigationParams.aidl create mode 100644 OsmAnd/src/net/osmand/aidl/navigation/OnVoiceNavigationParams.java diff --git a/OsmAnd/src/net/osmand/aidl/IOsmAndAidlCallback.aidl b/OsmAnd/src/net/osmand/aidl/IOsmAndAidlCallback.aidl index 19d5b75416..2fcd46d2a7 100644 --- a/OsmAnd/src/net/osmand/aidl/IOsmAndAidlCallback.aidl +++ b/OsmAnd/src/net/osmand/aidl/IOsmAndAidlCallback.aidl @@ -3,6 +3,7 @@ package net.osmand.aidl; import net.osmand.aidl.search.SearchResult; import net.osmand.aidl.gpx.AGpxBitmap; import net.osmand.aidl.navigation.ADirectionInfo; +import net.osmand.aidl.navigation.OnVoiceNavigationParams; interface IOsmAndAidlCallback { @@ -49,5 +50,5 @@ interface IOsmAndAidlCallback { /** * Callback for {@link IOsmAndAidlInterface} registerForVoiceRouterMessages() method. */ - void onVoiceRouterNotify(); + void onVoiceRouterNotify(in OnVoiceNavigationParams params); } \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java b/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java index 68e5a9959f..07da3f1642 100644 --- a/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java +++ b/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java @@ -47,6 +47,7 @@ import net.osmand.aidl.mapmarker.AMapMarker; import net.osmand.aidl.mapwidget.AMapWidget; import net.osmand.aidl.navdrawer.NavDrawerFooterParams; import net.osmand.aidl.navigation.ADirectionInfo; +import net.osmand.aidl.navigation.OnVoiceNavigationParams; import net.osmand.aidl.plugins.PluginParams; import net.osmand.aidl.search.SearchResult; import net.osmand.aidl.tiles.ASqliteDbFile; @@ -1923,12 +1924,12 @@ public class OsmandAidlApi { public void registerForVoiceRouterMessages(long id) { VoiceRouter.VoiceMessageListener listener = new VoiceRouter.VoiceMessageListener() { @Override - public void onVoiceMessage() { + public void onVoiceMessage(List cmds, List played) { if (aidlCallbackListener != null) { for (OsmandAidlService.AidlCallbackParams cb : aidlCallbackListener.getAidlCallbacks().values()) { if (!aidlCallbackListener.getAidlCallbacks().isEmpty() && (cb.getKey() & KEY_ON_VOICE_MESSAGE) > 0) { try { - cb.getCallback().onVoiceRouterNotify(); + cb.getCallback().onVoiceRouterNotify(new OnVoiceNavigationParams(cmds, played)); } catch (Exception e) { LOG.error(e.getMessage(), e); } diff --git a/OsmAnd/src/net/osmand/aidl/navigation/OnVoiceNavigationParams.aidl b/OsmAnd/src/net/osmand/aidl/navigation/OnVoiceNavigationParams.aidl new file mode 100644 index 0000000000..53ab4f6a5c --- /dev/null +++ b/OsmAnd/src/net/osmand/aidl/navigation/OnVoiceNavigationParams.aidl @@ -0,0 +1,3 @@ +package net.osmand.aidl.navigation; + +parcelable OnVoiceNavigationParams; \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/aidl/navigation/OnVoiceNavigationParams.java b/OsmAnd/src/net/osmand/aidl/navigation/OnVoiceNavigationParams.java new file mode 100644 index 0000000000..cdffd45110 --- /dev/null +++ b/OsmAnd/src/net/osmand/aidl/navigation/OnVoiceNavigationParams.java @@ -0,0 +1,55 @@ +package net.osmand.aidl.navigation; + +import android.os.Parcel; +import android.os.Parcelable; + +import java.util.ArrayList; +import java.util.List; + +public class OnVoiceNavigationParams implements Parcelable { + + private List cmds; + private List played; + + public OnVoiceNavigationParams() { + cmds = new ArrayList<>(); + played = new ArrayList<>(); + } + + public OnVoiceNavigationParams(List cmds, List played) { + this.cmds = cmds; + this.played = played; + } + + public OnVoiceNavigationParams(Parcel in) { + readFromParcel(in); + } + + public static final Creator CREATOR = new Creator() { + @Override + public OnVoiceNavigationParams createFromParcel(Parcel in) { + return new OnVoiceNavigationParams(in); + } + + @Override + public OnVoiceNavigationParams[] newArray(int size) { + return new OnVoiceNavigationParams[size]; + } + }; + + @Override + public void writeToParcel(Parcel out, int flags) { + out.writeList(cmds); + out.writeList(played); + } + + private void readFromParcel(Parcel in) { + in.readList(cmds, getClass().getClassLoader()); + in.readList(played, getClass().getClassLoader()); + } + + @Override + public int describeContents() { + return 0; + } +} diff --git a/OsmAnd/src/net/osmand/plus/routing/VoiceRouter.java b/OsmAnd/src/net/osmand/plus/routing/VoiceRouter.java index 08f9876389..34adfa1afb 100644 --- a/OsmAnd/src/net/osmand/plus/routing/VoiceRouter.java +++ b/OsmAnd/src/net/osmand/plus/routing/VoiceRouter.java @@ -9,7 +9,6 @@ import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; import net.osmand.Location; import net.osmand.binary.RouteDataObject; @@ -80,7 +79,7 @@ public class VoiceRouter { private static RouteDirectionInfo nextRouteDirection; public interface VoiceMessageListener { - void onVoiceMessage(); + void onVoiceMessage(List listCommands, List played); } private List> voiceMessageListeners = new ArrayList<>(); @@ -241,8 +240,8 @@ public class VoiceRouter { } public void announceBackOnRoute() { - CommandBuilder p = getNewCommandPlayerToPlay(); if (announceBackOnRoute) { + CommandBuilder p = getNewCommandPlayerToPlay(); if (p != null) { p.backOnRoute(); } @@ -909,9 +908,12 @@ public class VoiceRouter { private void play(CommandBuilder p) { if (p != null) { - p.play(); + List played = p.play(); + notifyOnVoiceMessage(p.getListCommands(), played); + } else { + notifyOnVoiceMessage(Collections.emptyList(), Collections.emptyList()); } - notifyOnVoiceMessage(); + } private void makeSound() { @@ -941,12 +943,12 @@ public class VoiceRouter { voiceMessageListeners = updateVoiceMessageListeners(new ArrayList<>(voiceMessageListeners), voiceMessageListener, false); } - private void notifyOnVoiceMessage() { - List> voiceMessageListeners = new ArrayList<>(this.voiceMessageListeners); + private void notifyOnVoiceMessage(List listCommands, List played) { + List> voiceMessageListeners = this.voiceMessageListeners; for (WeakReference weakReference : voiceMessageListeners) { VoiceMessageListener lnt = weakReference.get(); if (lnt != null) { - lnt.onVoiceMessage(); + lnt.onVoiceMessage(listCommands, played); } } } diff --git a/OsmAnd/src/net/osmand/plus/voice/CommandBuilder.java b/OsmAnd/src/net/osmand/plus/voice/CommandBuilder.java index 779ec2ca62..7abe7d56ff 100644 --- a/OsmAnd/src/net/osmand/plus/voice/CommandBuilder.java +++ b/OsmAnd/src/net/osmand/plus/voice/CommandBuilder.java @@ -5,15 +5,12 @@ import java.util.Arrays; import java.util.List; import net.osmand.PlatformUtil; -import net.osmand.plus.R; import net.osmand.plus.routing.data.StreetName; import org.apache.commons.logging.Log; import alice.tuprolog.Struct; import alice.tuprolog.Term; -import android.support.v4.app.NotificationCompat; -import android.support.v4.app.NotificationManagerCompat; public class CommandBuilder { @@ -57,6 +54,7 @@ public class CommandBuilder { protected final CommandPlayer commandPlayer; protected boolean alreadyExecuted = false; private List listStruct = new ArrayList(); + private List listCommands = new ArrayList(); public CommandBuilder(CommandPlayer commandPlayer){ this.commandPlayer = commandPlayer; @@ -71,9 +69,21 @@ public class CommandBuilder { private CommandBuilder addCommand(String name, Object... args){ Struct struct = prepareStruct(name, args); listStruct.add(struct); + listCommands.add(name); + for(Object o : args) { + if(o == null) { + listCommands.add(o.toString()); + } else { + listCommands.add(""); + } + } return this; } + public List getListCommands() { + return listCommands; + } + private Struct prepareStruct(String name, Object... args) { checkState(); Term[] list = new Term[args.length]; @@ -254,8 +264,8 @@ public class CommandBuilder { return alt(prepareStruct(C_ROUTE_RECALC, dist, time), prepareStruct(C_ROUTE_RECALC, dist)); } - public void play(){ - this.commandPlayer.playCommands(this); + public List play(){ + return this.commandPlayer.playCommands(this); } diff --git a/OsmAnd/src/net/osmand/plus/voice/CommandPlayer.java b/OsmAnd/src/net/osmand/plus/voice/CommandPlayer.java index 814b317074..c09356bfac 100644 --- a/OsmAnd/src/net/osmand/plus/voice/CommandPlayer.java +++ b/OsmAnd/src/net/osmand/plus/voice/CommandPlayer.java @@ -10,7 +10,7 @@ public interface CommandPlayer { public CommandBuilder newCommandBuilder(); - public void playCommands(CommandBuilder builder); + public List playCommands(CommandBuilder builder); public void clear(); diff --git a/OsmAnd/src/net/osmand/plus/voice/JSCommandBuilder.java b/OsmAnd/src/net/osmand/plus/voice/JSCommandBuilder.java index 52a6d6ac6e..24d4865faa 100644 --- a/OsmAnd/src/net/osmand/plus/voice/JSCommandBuilder.java +++ b/OsmAnd/src/net/osmand/plus/voice/JSCommandBuilder.java @@ -12,15 +12,8 @@ import org.mozilla.javascript.NativeJSON; import org.mozilla.javascript.Scriptable; import org.mozilla.javascript.ScriptableObject; -import java.io.BufferedReader; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileReader; -import java.io.IOException; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; -import java.util.Map; public class JSCommandBuilder extends CommandBuilder { @@ -216,8 +209,8 @@ public class JSCommandBuilder extends CommandBuilder { } @Override - public void play(){ - this.commandPlayer.playCommands(this); + public List play(){ + return this.commandPlayer.playCommands(this); } @Override diff --git a/OsmAnd/src/net/osmand/plus/voice/JSMediaCommandPlayerImpl.java b/OsmAnd/src/net/osmand/plus/voice/JSMediaCommandPlayerImpl.java index 8da4098e3b..decb8e2c09 100644 --- a/OsmAnd/src/net/osmand/plus/voice/JSMediaCommandPlayerImpl.java +++ b/OsmAnd/src/net/osmand/plus/voice/JSMediaCommandPlayerImpl.java @@ -15,6 +15,7 @@ import java.io.FileReader; import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.List; public class JSMediaCommandPlayerImpl extends MediaCommandPlayerImpl { @@ -44,11 +45,12 @@ public class JSMediaCommandPlayerImpl extends MediaCommandPlayerImpl { } @Override - public synchronized void playCommands(CommandBuilder builder) { + public synchronized List playCommands(CommandBuilder builder) { if(vrt.isMute()) { - return; + return Collections.emptyList(); } - filesToPlay.addAll(splitAnnouncements(builder.execute())); + List lst = splitAnnouncements(builder.execute()); + filesToPlay.addAll(lst); // If we have not already started to play audio, start. if (mediaPlayer == null) { @@ -63,6 +65,7 @@ public class JSMediaCommandPlayerImpl extends MediaCommandPlayerImpl { } } playQueue(); + return lst; } private List splitAnnouncements(List execute) { diff --git a/OsmAnd/src/net/osmand/plus/voice/MediaCommandPlayerImpl.java b/OsmAnd/src/net/osmand/plus/voice/MediaCommandPlayerImpl.java index a3366dec37..d32fe76bcb 100644 --- a/OsmAnd/src/net/osmand/plus/voice/MediaCommandPlayerImpl.java +++ b/OsmAnd/src/net/osmand/plus/voice/MediaCommandPlayerImpl.java @@ -67,7 +67,7 @@ public class MediaCommandPlayerImpl extends AbstractPrologCommandPlayer implemen // Called from the calculating route thread. @Override - public synchronized void playCommands(CommandBuilder builder) { + public synchronized List playCommands(CommandBuilder builder) { if(vrt.isMute()) { StringBuilder bld = new StringBuilder(); for (String s : builder.execute()) { @@ -76,9 +76,11 @@ public class MediaCommandPlayerImpl extends AbstractPrologCommandPlayer implemen if (ctx != null) { // sendAlertToAndroidWear(ctx, bld.toString()); } - return; + return Collections.emptyList(); } - filesToPlay.addAll(builder.execute()); + List lst = builder.execute(); + + filesToPlay.addAll(lst); // If we have not already started to play audio, start. if (mediaPlayer == null) { @@ -93,6 +95,7 @@ public class MediaCommandPlayerImpl extends AbstractPrologCommandPlayer implemen } } playQueue(); + return lst; } synchronized void playQueue() { diff --git a/OsmAnd/src/net/osmand/plus/voice/TTSCommandPlayerImpl.java b/OsmAnd/src/net/osmand/plus/voice/TTSCommandPlayerImpl.java index 6eecf61c18..b6821062eb 100644 --- a/OsmAnd/src/net/osmand/plus/voice/TTSCommandPlayerImpl.java +++ b/OsmAnd/src/net/osmand/plus/voice/TTSCommandPlayerImpl.java @@ -104,7 +104,7 @@ public class TTSCommandPlayerImpl extends AbstractPrologCommandPlayer { // Called from the calculating route thread. @Override - public synchronized void playCommands(CommandBuilder builder) { + public synchronized List playCommands(CommandBuilder builder) { final List execute = builder.execute(); //list of strings, the speech text, play it StringBuilder bld = new StringBuilder(); for (String s : execute) { @@ -132,6 +132,7 @@ public class TTSCommandPlayerImpl extends AbstractPrologCommandPlayer { } else if (ctx != null && vrt.isMute()) { // sendAlertToAndroidWear(ctx, bld.toString()); } + return execute; } @Override