Refactor
This commit is contained in:
parent
62a792952b
commit
7b3aea100d
9 changed files with 55 additions and 64 deletions
|
@ -45,7 +45,7 @@ public class GPXUtilities {
|
||||||
private static final String ICON_NAME_EXTENSION = "icon";
|
private static final String ICON_NAME_EXTENSION = "icon";
|
||||||
private static final String DEFAULT_ICON_NAME = "special_star";
|
private static final String DEFAULT_ICON_NAME = "special_star";
|
||||||
private static final String BACKGROUND_TYPE_EXTENSION = "background";
|
private static final String BACKGROUND_TYPE_EXTENSION = "background";
|
||||||
private static final String DEFAULT_BACKGROUND_TYPE = "CIRCLE";
|
private static final String DEFAULT_BACKGROUND_TYPE = "circle";
|
||||||
|
|
||||||
private final static String GPX_TIME_FORMAT = "yyyy-MM-dd'T'HH:mm:ss'Z'"; //$NON-NLS-1$
|
private final static String GPX_TIME_FORMAT = "yyyy-MM-dd'T'HH:mm:ss'Z'"; //$NON-NLS-1$
|
||||||
private final static String GPX_TIME_FORMAT_MILLIS = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"; //$NON-NLS-1$
|
private final static String GPX_TIME_FORMAT_MILLIS = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"; //$NON-NLS-1$
|
||||||
|
|
|
@ -93,10 +93,7 @@ public class FavouritePoint implements Serializable, LocationPoint {
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getIconId() {
|
public int getIconId() {
|
||||||
if (iconId == 0) {
|
return iconId == 0 ? R.drawable.mx_special_star : iconId;
|
||||||
return R.drawable.mx_special_star;
|
|
||||||
}
|
|
||||||
return iconId;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getIconEntryName(Context ctx) {
|
public String getIconEntryName(Context ctx) {
|
||||||
|
@ -201,10 +198,7 @@ public class FavouritePoint implements Serializable, LocationPoint {
|
||||||
}
|
}
|
||||||
|
|
||||||
public BackgroundType getBackgroundType() {
|
public BackgroundType getBackgroundType() {
|
||||||
if (backgroundType == null) {
|
return backgroundType == null ? BackgroundType.CIRCLE : backgroundType;
|
||||||
return BackgroundType.CIRCLE;
|
|
||||||
}
|
|
||||||
return backgroundType;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setBackgroundType(BackgroundType backgroundType) {
|
public void setBackgroundType(BackgroundType backgroundType) {
|
||||||
|
@ -323,6 +317,19 @@ public class FavouritePoint implements Serializable, LocationPoint {
|
||||||
public int getIconId() {
|
public int getIconId() {
|
||||||
return iconId;
|
return iconId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getTypeName() {
|
||||||
|
return typeName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static BackgroundType getByTypeName(String typeName, BackgroundType defaultValue) {
|
||||||
|
for (BackgroundType type : BackgroundType.values()) {
|
||||||
|
if (type.typeName.equals(typeName)) {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return defaultValue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static FavouritePoint fromWpt(@NonNull WptPt pt, @NonNull Context ctx) {
|
public static FavouritePoint fromWpt(@NonNull WptPt pt, @NonNull Context ctx) {
|
||||||
|
@ -344,7 +351,8 @@ public class FavouritePoint implements Serializable, LocationPoint {
|
||||||
if (iconName != null) {
|
if (iconName != null) {
|
||||||
fp.setIconIdFromName(ctx, iconName);
|
fp.setIconIdFromName(ctx, iconName);
|
||||||
}
|
}
|
||||||
fp.setBackgroundType(BackgroundType.valueOf((pt.getBackgroundType().toUpperCase())));
|
BackgroundType backgroundType = BackgroundType.getByTypeName(pt.getBackgroundType(), BackgroundType.CIRCLE);
|
||||||
|
fp.setBackgroundType(backgroundType);
|
||||||
return fp;
|
return fp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,7 @@ import androidx.annotation.NonNull;
|
||||||
|
|
||||||
import net.osmand.GPXUtilities;
|
import net.osmand.GPXUtilities;
|
||||||
import net.osmand.data.FavouritePoint;
|
import net.osmand.data.FavouritePoint;
|
||||||
|
import net.osmand.data.FavouritePoint.BackgroundType;
|
||||||
import net.osmand.plus.OsmandApplication;
|
import net.osmand.plus.OsmandApplication;
|
||||||
import net.osmand.plus.R;
|
import net.osmand.plus.R;
|
||||||
import net.osmand.plus.UiUtilities;
|
import net.osmand.plus.UiUtilities;
|
||||||
|
@ -136,9 +137,9 @@ public class FavoriteImageDrawable extends Drawable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void drawBitmap(@NonNull Canvas canvas, Rect bs, Bitmap syncedShadow, Paint paintBackground) {
|
public void drawBitmap(@NonNull Canvas canvas, Rect bs, Bitmap bitmap, Paint paintBackground) {
|
||||||
canvas.drawBitmap(syncedShadow, bs.exactCenterX() - syncedShadow.getWidth() / 2f,
|
canvas.drawBitmap(bitmap, bs.exactCenterX() - bitmap.getWidth() / 2f,
|
||||||
bs.exactCenterY() - syncedShadow.getHeight() / 2f, paintBackground);
|
bs.exactCenterY() - bitmap.getHeight() / 2f, paintBackground);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void drawBitmapInCenter(Canvas canvas, float x, float y, boolean history) {
|
public void drawBitmapInCenter(Canvas canvas, float x, float y, boolean history) {
|
||||||
|
@ -206,7 +207,7 @@ public class FavoriteImageDrawable extends Drawable {
|
||||||
if (pt != null) {
|
if (pt != null) {
|
||||||
point = new FavouritePoint(pt.getLatitude(), pt.getLongitude(), pt.name, pt.category);
|
point = new FavouritePoint(pt.getLatitude(), pt.getLongitude(), pt.name, pt.category);
|
||||||
point.setIconIdFromName(a, pt.getIconName());
|
point.setIconIdFromName(a, pt.getIconName());
|
||||||
point.setBackgroundType(FavouritePoint.BackgroundType.valueOf(pt.getBackgroundType()));
|
point.setBackgroundType(BackgroundType.getByTypeName(pt.getBackgroundType(), BackgroundType.CIRCLE));
|
||||||
}
|
}
|
||||||
return point;
|
return point;
|
||||||
}
|
}
|
||||||
|
|
|
@ -93,16 +93,7 @@ public class FavoritePointEditorFragment extends PointEditorFragment {
|
||||||
@Override
|
@Override
|
||||||
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
||||||
super.onViewCreated(view, savedInstanceState);
|
super.onViewCreated(view, savedInstanceState);
|
||||||
|
|
||||||
if (autoFill) {
|
if (autoFill) {
|
||||||
|
|
||||||
// String name = favorite.getName() != null && !favorite.getName().isEmpty() ?
|
|
||||||
// favorite.getName() : getString(R.string.favorite_empty_place_name);
|
|
||||||
//
|
|
||||||
// String tostText = name + getString(R.string.favorite_autofill_toast_text) + group.name;
|
|
||||||
//
|
|
||||||
// Toast.makeText(getContext(), tostText, Toast.LENGTH_SHORT).show();
|
|
||||||
|
|
||||||
save(true);
|
save(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,7 @@ import androidx.appcompat.app.AlertDialog;
|
||||||
import androidx.fragment.app.FragmentActivity;
|
import androidx.fragment.app.FragmentActivity;
|
||||||
|
|
||||||
import net.osmand.data.FavouritePoint;
|
import net.osmand.data.FavouritePoint;
|
||||||
|
import net.osmand.data.FavouritePoint.BackgroundType;
|
||||||
import net.osmand.data.LatLon;
|
import net.osmand.data.LatLon;
|
||||||
import net.osmand.plus.FavouritesDbHelper;
|
import net.osmand.plus.FavouritesDbHelper;
|
||||||
import net.osmand.plus.FavouritesDbHelper.FavoriteGroup;
|
import net.osmand.plus.FavouritesDbHelper.FavoriteGroup;
|
||||||
|
@ -43,7 +44,7 @@ public class FavoritePointEditorFragmentNew extends PointEditorFragmentNew {
|
||||||
private int color;
|
private int color;
|
||||||
private int iconId;
|
private int iconId;
|
||||||
@NonNull
|
@NonNull
|
||||||
private FavouritePoint.BackgroundType backgroundType = FavouritePoint.BackgroundType.CIRCLE;
|
private BackgroundType backgroundType = BackgroundType.CIRCLE;
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
FavouritesDbHelper helper;
|
FavouritesDbHelper helper;
|
||||||
|
@ -118,16 +119,7 @@ public class FavoritePointEditorFragmentNew extends PointEditorFragmentNew {
|
||||||
@Override
|
@Override
|
||||||
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
||||||
super.onViewCreated(view, savedInstanceState);
|
super.onViewCreated(view, savedInstanceState);
|
||||||
|
|
||||||
if (autoFill) {
|
if (autoFill) {
|
||||||
|
|
||||||
// String name = favorite.getName() != null && !favorite.getName().isEmpty() ?
|
|
||||||
// favorite.getName() : getString(R.string.favorite_empty_place_name);
|
|
||||||
//
|
|
||||||
// String tostText = name + getString(R.string.favorite_autofill_toast_text) + group.name;
|
|
||||||
//
|
|
||||||
// Toast.makeText(getContext(), tostText, Toast.LENGTH_SHORT).show();
|
|
||||||
|
|
||||||
save(true);
|
save(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -185,7 +177,7 @@ public class FavoritePointEditorFragmentNew extends PointEditorFragmentNew {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setBackgroundType(@NonNull FavouritePoint.BackgroundType backgroundType) {
|
public void setBackgroundType(@NonNull BackgroundType backgroundType) {
|
||||||
this.backgroundType = backgroundType;
|
this.backgroundType = backgroundType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -281,7 +273,7 @@ public class FavoritePointEditorFragmentNew extends PointEditorFragmentNew {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void doSave(FavouritePoint favorite, String name, String category, String description,
|
private void doSave(FavouritePoint favorite, String name, String category, String description,
|
||||||
@ColorInt int color, FavouritePoint.BackgroundType backgroundType, @DrawableRes int iconId, boolean needDismiss) {
|
@ColorInt int color, BackgroundType backgroundType, @DrawableRes int iconId, boolean needDismiss) {
|
||||||
FavouritesDbHelper helper = getHelper();
|
FavouritesDbHelper helper = getHelper();
|
||||||
FavoritePointEditor editor = getFavoritePointEditor();
|
FavoritePointEditor editor = getFavoritePointEditor();
|
||||||
if (editor != null && helper != null) {
|
if (editor != null && helper != null) {
|
||||||
|
@ -311,7 +303,7 @@ public class FavoritePointEditorFragmentNew extends PointEditorFragmentNew {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void doAddFavorite(String name, String category, String description, @ColorInt int color,
|
private void doAddFavorite(String name, String category, String description, @ColorInt int color,
|
||||||
FavouritePoint.BackgroundType backgroundType, @DrawableRes int iconId) {
|
BackgroundType backgroundType, @DrawableRes int iconId) {
|
||||||
OsmandApplication app = getMyApplication();
|
OsmandApplication app = getMyApplication();
|
||||||
FavouritesDbHelper helper = getHelper();
|
FavouritesDbHelper helper = getHelper();
|
||||||
FavouritePoint favorite = getFavorite();
|
FavouritePoint favorite = getFavorite();
|
||||||
|
@ -414,7 +406,7 @@ public class FavoritePointEditorFragmentNew extends PointEditorFragmentNew {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@NonNull
|
@NonNull
|
||||||
public FavouritePoint.BackgroundType getBackgroundType() {
|
public BackgroundType getBackgroundType() {
|
||||||
return backgroundType;
|
return backgroundType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -90,21 +90,14 @@ public abstract class PointEditor {
|
||||||
if (mapActivity != null) {
|
if (mapActivity != null) {
|
||||||
Fragment fragment = mapActivity.getSupportFragmentManager().findFragmentByTag(getFragmentTag());
|
Fragment fragment = mapActivity.getSupportFragmentManager().findFragmentByTag(getFragmentTag());
|
||||||
if (fragment != null) {
|
if (fragment != null) {
|
||||||
if (!checkNewUiFragment(fragment, name, color)) { //todo remove "if" after switch to new UI
|
if (fragment instanceof PointEditorFragment) {
|
||||||
PointEditorFragment editorFragment = (PointEditorFragment) fragment;
|
PointEditorFragment editorFragment = (PointEditorFragment) fragment;
|
||||||
editorFragment.setCategory(name, color);
|
editorFragment.setCategory(name, color);
|
||||||
|
} else if (fragment instanceof PointEditorFragmentNew) {
|
||||||
|
PointEditorFragmentNew editorFragment = (PointEditorFragmentNew) fragment;
|
||||||
|
editorFragment.setCategory(name, color);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//todo remove after switch to new UI
|
|
||||||
private boolean checkNewUiFragment(Fragment fragment, String name, int color) {
|
|
||||||
if (fragment instanceof PointEditorFragmentNew) {
|
|
||||||
PointEditorFragmentNew editorFragment = (PointEditorFragmentNew) fragment;
|
|
||||||
editorFragment.setCategory(name, color);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -82,7 +82,6 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment {
|
||||||
private LinkedHashMap<String, JSONArray> group;
|
private LinkedHashMap<String, JSONArray> group;
|
||||||
private OsmandApplication app;
|
private OsmandApplication app;
|
||||||
|
|
||||||
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
|
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
|
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
|
||||||
Bundle savedInstanceState) {
|
Bundle savedInstanceState) {
|
||||||
|
|
|
@ -15,7 +15,7 @@ import androidx.fragment.app.DialogFragment;
|
||||||
import net.osmand.GPXUtilities;
|
import net.osmand.GPXUtilities;
|
||||||
import net.osmand.GPXUtilities.GPXFile;
|
import net.osmand.GPXUtilities.GPXFile;
|
||||||
import net.osmand.GPXUtilities.WptPt;
|
import net.osmand.GPXUtilities.WptPt;
|
||||||
import net.osmand.data.FavouritePoint;
|
import net.osmand.data.FavouritePoint.BackgroundType;
|
||||||
import net.osmand.data.LatLon;
|
import net.osmand.data.LatLon;
|
||||||
import net.osmand.data.WptLocationPoint;
|
import net.osmand.data.WptLocationPoint;
|
||||||
import net.osmand.plus.GpxSelectionHelper;
|
import net.osmand.plus.GpxSelectionHelper;
|
||||||
|
@ -51,7 +51,7 @@ public class WptPtEditorFragmentNew extends PointEditorFragmentNew {
|
||||||
protected boolean skipDialog;
|
protected boolean skipDialog;
|
||||||
private String iconName;
|
private String iconName;
|
||||||
@NonNull
|
@NonNull
|
||||||
private String backgroundTypeName = FavouritePoint.BackgroundType.CIRCLE.name();
|
private String backgroundTypeName = BackgroundType.CIRCLE.getTypeName();
|
||||||
|
|
||||||
private Map<String, Integer> categoriesMap;
|
private Map<String, Integer> categoriesMap;
|
||||||
private OsmandApplication app;
|
private OsmandApplication app;
|
||||||
|
@ -357,7 +357,7 @@ public class WptPtEditorFragmentNew extends PointEditorFragmentNew {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setBackgroundType(FavouritePoint.BackgroundType backgroundType) {
|
public void setBackgroundType(BackgroundType backgroundType) {
|
||||||
this.backgroundTypeName = backgroundType.name();
|
this.backgroundTypeName = backgroundType.name();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -419,8 +419,8 @@ public class WptPtEditorFragmentNew extends PointEditorFragmentNew {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public FavouritePoint.BackgroundType getBackgroundType() {
|
public BackgroundType getBackgroundType() {
|
||||||
return FavouritePoint.BackgroundType.valueOf(backgroundTypeName);
|
return BackgroundType.getByTypeName(backgroundTypeName, BackgroundType.CIRCLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -439,7 +439,13 @@ public class WptPtEditorFragmentNew extends PointEditorFragmentNew {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getCategoryColor(String category) {
|
public int getCategoryColor(String category) {
|
||||||
return categoriesMap != null ? categoriesMap.get(category) : defaultColor;
|
if (categoriesMap != null) {
|
||||||
|
Integer color = categoriesMap.get(category);
|
||||||
|
if (color != null) {
|
||||||
|
return color;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return defaultColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -16,6 +16,7 @@ import androidx.annotation.Nullable;
|
||||||
import androidx.core.content.ContextCompat;
|
import androidx.core.content.ContextCompat;
|
||||||
|
|
||||||
import net.osmand.data.FavouritePoint;
|
import net.osmand.data.FavouritePoint;
|
||||||
|
import net.osmand.data.FavouritePoint.BackgroundType;
|
||||||
import net.osmand.data.LatLon;
|
import net.osmand.data.LatLon;
|
||||||
import net.osmand.data.PointDescription;
|
import net.osmand.data.PointDescription;
|
||||||
import net.osmand.data.QuadRect;
|
import net.osmand.data.QuadRect;
|
||||||
|
@ -66,10 +67,10 @@ public class FavouritesLayer extends OsmandMapLayer implements ContextMenuLayer.
|
||||||
mapMarkersHelper = view.getApplication().getMapMarkersHelper();
|
mapMarkersHelper = view.getApplication().getMapMarkersHelper();
|
||||||
textLayer = view.getLayerByClass(MapTextLayer.class);
|
textLayer = view.getLayerByClass(MapTextLayer.class);
|
||||||
paintIcon = new Paint();
|
paintIcon = new Paint();
|
||||||
for (FavouritePoint.BackgroundType backgroundType : FavouritePoint.BackgroundType.values()) {
|
for (BackgroundType backgroundType : BackgroundType.values()) {
|
||||||
putBitmap(backgroundType, "top");
|
putBitmapToIconCache(backgroundType, "top");
|
||||||
putBitmap(backgroundType, "center");
|
putBitmapToIconCache(backgroundType, "center");
|
||||||
putBitmap(backgroundType, "bottom");
|
putBitmapToIconCache(backgroundType, "bottom");
|
||||||
}
|
}
|
||||||
pointSmall = BitmapFactory.decodeResource(view.getResources(), R.drawable.map_white_shield_small);
|
pointSmall = BitmapFactory.decodeResource(view.getResources(), R.drawable.map_white_shield_small);
|
||||||
defaultColor = ContextCompat.getColor(view.getContext(), R.color.color_favorite);
|
defaultColor = ContextCompat.getColor(view.getContext(), R.color.color_favorite);
|
||||||
|
@ -77,9 +78,9 @@ public class FavouritesLayer extends OsmandMapLayer implements ContextMenuLayer.
|
||||||
contextMenuLayer = view.getLayerByClass(ContextMenuLayer.class);
|
contextMenuLayer = view.getLayerByClass(ContextMenuLayer.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void putBitmap(FavouritePoint.BackgroundType backgroundType, String bottom) {
|
private void putBitmapToIconCache(BackgroundType backgroundType, String layer) {
|
||||||
smallIconCache.put(backgroundType.name() + bottom, BitmapFactory.decodeResource(view.getResources(),
|
smallIconCache.put(backgroundType.getTypeName() + "_" + layer, BitmapFactory.decodeResource(view.getResources(),
|
||||||
getSmallIconID(bottom, backgroundType.getIconId())));
|
getSmallIconId(layer, backgroundType.getIconId())));
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean calculateBelongs(int ex, int ey, int objx, int objy, int radius) {
|
private boolean calculateBelongs(int ex, int ey, int objx, int objy, int radius) {
|
||||||
|
@ -182,7 +183,7 @@ public class FavouritesLayer extends OsmandMapLayer implements ContextMenuLayer.
|
||||||
}
|
}
|
||||||
|
|
||||||
private Bitmap getBitmap(FavouritePoint o, String layer) {
|
private Bitmap getBitmap(FavouritePoint o, String layer) {
|
||||||
Bitmap pointSmall = smallIconCache.get(o.getBackgroundType().name() + layer);
|
Bitmap pointSmall = smallIconCache.get(o.getBackgroundType().getTypeName() + "_" + layer);
|
||||||
if (pointSmall == null) {
|
if (pointSmall == null) {
|
||||||
pointSmall = this.pointSmall;
|
pointSmall = this.pointSmall;
|
||||||
}
|
}
|
||||||
|
@ -201,7 +202,7 @@ public class FavouritesLayer extends OsmandMapLayer implements ContextMenuLayer.
|
||||||
fid.drawBitmapInCenter(canvas, x, y, history);
|
fid.drawBitmapInCenter(canvas, x, y, history);
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getSmallIconID(String layer, int iconId) {
|
private int getSmallIconId(String layer, int iconId) {
|
||||||
String iconName = view.getResources().getResourceEntryName(iconId);
|
String iconName = view.getResources().getResourceEntryName(iconId);
|
||||||
return view.getResources().getIdentifier("map_" + iconName + "_" + layer + "_small"
|
return view.getResources().getIdentifier("map_" + iconName + "_" + layer + "_small"
|
||||||
, "drawable", view.getContext().getPackageName());
|
, "drawable", view.getContext().getPackageName());
|
||||||
|
|
Loading…
Reference in a new issue