Merge branch 'r3.4' into 360_deg_setting

This commit is contained in:
madwasp79 2019-07-09 15:07:34 +03:00
commit 49285e49a0
7 changed files with 73 additions and 143 deletions

View file

@ -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)) {

View file

@ -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<Integer> vs = new ValueHolder<Integer>();
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<MapActivity> mapActivityRef) {
saveCurrentTrack(null, mapActivityRef);
}
public void saveCurrentTrack(@Nullable final Runnable onComplete,
@Nullable final WeakReference<MapActivity> mapActivityRef) {
public void saveCurrentTrack(@Nullable final Runnable onComplete, @Nullable Activity activity) {
final WeakReference<Activity> activityRef = activity != null ? new WeakReference<>(activity) : null;
app.getTaskManager().runInBackground(new OsmAndTaskRunnable<Void, Void, SaveGpxResult>() {
@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));
}
}

View file

@ -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;

View file

@ -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);
}
}
}

View file

@ -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<Object> 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));
}
}

View file

@ -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();
}
}

View file

@ -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);
}
}