commit
818517fda8
10 changed files with 123 additions and 129 deletions
|
@ -38,6 +38,20 @@
|
||||||
android:textColor="?android:textColorPrimary"
|
android:textColor="?android:textColorPrimary"
|
||||||
tools:text="Today"/>
|
tools:text="Today"/>
|
||||||
|
|
||||||
|
<net.osmand.plus.widgets.TextViewEx
|
||||||
|
android:id="@+id/clear_button"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:textSize="@dimen/default_desc_text_size"
|
||||||
|
android:text="@string/shared_string_clear"
|
||||||
|
osmand:typeface="@string/font_roboto_medium"
|
||||||
|
android:paddingLeft="@dimen/bottom_sheet_content_margin"
|
||||||
|
android:paddingRight="@dimen/bottom_sheet_content_margin"
|
||||||
|
android:gravity="center"
|
||||||
|
android:visibility="gone"
|
||||||
|
android:background="?android:selectableItemBackground"
|
||||||
|
android:textColor="?attr/active_color_basic" />
|
||||||
|
|
||||||
<androidx.appcompat.widget.SwitchCompat
|
<androidx.appcompat.widget.SwitchCompat
|
||||||
android:id="@+id/disable_group_switch"
|
android:id="@+id/disable_group_switch"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
|
|
|
@ -51,6 +51,7 @@ import android.widget.TextView;
|
||||||
import androidx.annotation.AttrRes;
|
import androidx.annotation.AttrRes;
|
||||||
import androidx.annotation.ColorInt;
|
import androidx.annotation.ColorInt;
|
||||||
import androidx.annotation.ColorRes;
|
import androidx.annotation.ColorRes;
|
||||||
|
import androidx.annotation.DrawableRes;
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.appcompat.content.res.AppCompatResources;
|
import androidx.appcompat.content.res.AppCompatResources;
|
||||||
import androidx.core.content.ContextCompat;
|
import androidx.core.content.ContextCompat;
|
||||||
|
@ -696,6 +697,10 @@ public class AndroidUtils {
|
||||||
|
|
||||||
public static Drawable getMirroredDrawable(@NonNull Context ctx,
|
public static Drawable getMirroredDrawable(@NonNull Context ctx,
|
||||||
@NonNull Drawable drawable) {
|
@NonNull Drawable drawable) {
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
||||||
|
drawable.setAutoMirrored(true);
|
||||||
|
return drawable;
|
||||||
|
}
|
||||||
Bitmap bitmap = drawableToBitmap(drawable);
|
Bitmap bitmap = drawableToBitmap(drawable);
|
||||||
return new BitmapDrawable(ctx.getResources(), flipBitmapHorizontally(bitmap));
|
return new BitmapDrawable(ctx.getResources(), flipBitmapHorizontally(bitmap));
|
||||||
}
|
}
|
||||||
|
|
|
@ -284,7 +284,7 @@ public class MapMarkersDbHelper {
|
||||||
if (db != null) {
|
if (db != null) {
|
||||||
try {
|
try {
|
||||||
for (MapMarker marker : markers) {
|
for (MapMarker marker : markers) {
|
||||||
insertLast(db, marker, false);
|
insertLast(db, marker);
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
db.close();
|
db.close();
|
||||||
|
@ -293,36 +293,24 @@ public class MapMarkersDbHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addMarker(MapMarker marker) {
|
public void addMarker(MapMarker marker) {
|
||||||
addMarker(marker, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void addMarker(MapMarker marker, boolean saveExisting) {
|
|
||||||
SQLiteConnection db = openConnection(false);
|
SQLiteConnection db = openConnection(false);
|
||||||
if (db != null) {
|
if (db != null) {
|
||||||
try {
|
try {
|
||||||
insertLast(db, marker, saveExisting);
|
insertLast(db, marker);
|
||||||
} finally {
|
} finally {
|
||||||
db.close();
|
db.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void insertLast(SQLiteConnection db, MapMarker marker, boolean saveExisting) {
|
private void insertLast(SQLiteConnection db, MapMarker marker) {
|
||||||
long currentTime;
|
long currentTime = System.currentTimeMillis();
|
||||||
if (saveExisting) {
|
|
||||||
Calendar cal = Calendar.getInstance();
|
|
||||||
cal.add(Calendar.MONTH, -1);
|
|
||||||
currentTime = cal.getTimeInMillis();
|
|
||||||
} else {
|
|
||||||
currentTime = System.currentTimeMillis();
|
|
||||||
}
|
|
||||||
if (marker.id == null) {
|
if (marker.id == null) {
|
||||||
marker.id = String.valueOf(currentTime) + String.valueOf(new Random().nextInt(900) + 100);
|
marker.id = String.valueOf(currentTime) + String.valueOf(new Random().nextInt(900) + 100);
|
||||||
}
|
}
|
||||||
marker.creationDate = currentTime;
|
marker.creationDate = currentTime;
|
||||||
String descr = PointDescription.serializeToString(marker.getOriginalPointDescription());
|
String descr = PointDescription.serializeToString(marker.getOriginalPointDescription());
|
||||||
int active = marker.history ? 0 : 1;
|
int active = marker.history ? 0 : 1;
|
||||||
long visited = saveExisting ? currentTime : 0;
|
|
||||||
|
|
||||||
PointDescription pointDescription = marker.getOriginalPointDescription();
|
PointDescription pointDescription = marker.getOriginalPointDescription();
|
||||||
if (pointDescription != null && !pointDescription.isSearchingAddress(context)) {
|
if (pointDescription != null && !pointDescription.isSearchingAddress(context)) {
|
||||||
|
@ -352,7 +340,7 @@ public class MapMarkersDbHelper {
|
||||||
MARKERS_COL_MAP_OBJECT_NAME + ") " +
|
MARKERS_COL_MAP_OBJECT_NAME + ") " +
|
||||||
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
||||||
new Object[]{marker.id, marker.getLatitude(), marker.getLongitude(), descr, active,
|
new Object[]{marker.id, marker.getLatitude(), marker.getLongitude(), descr, active,
|
||||||
currentTime, visited, marker.groupName, marker.groupKey, marker.colorIndex,
|
currentTime, marker.visitedDate, marker.groupName, marker.groupKey, marker.colorIndex,
|
||||||
marker.history ? HISTORY_NEXT_VALUE : TAIL_NEXT_VALUE, 0, 0, marker.mapObjectName});
|
marker.history ? HISTORY_NEXT_VALUE : TAIL_NEXT_VALUE, 0, 0, marker.mapObjectName});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,9 @@
|
||||||
package net.osmand.plus.mapmarkers;
|
package net.osmand.plus.mapmarkers;
|
||||||
|
|
||||||
import android.graphics.Bitmap;
|
|
||||||
import android.graphics.BitmapFactory;
|
|
||||||
import android.graphics.Canvas;
|
import android.graphics.Canvas;
|
||||||
import android.graphics.Paint;
|
import android.graphics.Paint;
|
||||||
import android.graphics.PorterDuff;
|
|
||||||
import android.graphics.PorterDuffColorFilter;
|
|
||||||
import android.graphics.Rect;
|
import android.graphics.Rect;
|
||||||
|
import android.graphics.drawable.Drawable;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
|
@ -48,9 +45,9 @@ public class MapMarkersGroupsFragment extends Fragment implements OsmAndCompassL
|
||||||
|
|
||||||
public static final String TAG = "MapMarkersGroupsFragment";
|
public static final String TAG = "MapMarkersGroupsFragment";
|
||||||
|
|
||||||
|
private OsmandApplication app;
|
||||||
private MapMarkersGroupsAdapter adapter;
|
private MapMarkersGroupsAdapter adapter;
|
||||||
private Paint backgroundPaint = new Paint();
|
private Paint backgroundPaint = new Paint();
|
||||||
private Paint iconPaint = new Paint();
|
|
||||||
private Paint textPaint = new Paint();
|
private Paint textPaint = new Paint();
|
||||||
private Snackbar snackbar;
|
private Snackbar snackbar;
|
||||||
private View mainView;
|
private View mainView;
|
||||||
|
@ -60,6 +57,12 @@ public class MapMarkersGroupsFragment extends Fragment implements OsmAndCompassL
|
||||||
private boolean locationUpdateStarted;
|
private boolean locationUpdateStarted;
|
||||||
private boolean compassUpdateAllowed = true;
|
private boolean compassUpdateAllowed = true;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
app = getMyApplication();
|
||||||
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||||
|
@ -89,9 +92,6 @@ public class MapMarkersGroupsFragment extends Fragment implements OsmAndCompassL
|
||||||
backgroundPaint.setColor(ContextCompat.getColor(getActivity(), night ? R.color.divider_color_dark : R.color.divider_color_light));
|
backgroundPaint.setColor(ContextCompat.getColor(getActivity(), night ? R.color.divider_color_dark : R.color.divider_color_light));
|
||||||
backgroundPaint.setStyle(Paint.Style.FILL_AND_STROKE);
|
backgroundPaint.setStyle(Paint.Style.FILL_AND_STROKE);
|
||||||
backgroundPaint.setAntiAlias(true);
|
backgroundPaint.setAntiAlias(true);
|
||||||
iconPaint.setAntiAlias(true);
|
|
||||||
iconPaint.setFilterBitmap(true);
|
|
||||||
iconPaint.setDither(true);
|
|
||||||
textPaint.setTextSize(getResources().getDimension(R.dimen.default_desc_text_size));
|
textPaint.setTextSize(getResources().getDimension(R.dimen.default_desc_text_size));
|
||||||
textPaint.setFakeBoldText(true);
|
textPaint.setFakeBoldText(true);
|
||||||
textPaint.setAntiAlias(true);
|
textPaint.setAntiAlias(true);
|
||||||
|
@ -106,8 +106,6 @@ public class MapMarkersGroupsFragment extends Fragment implements OsmAndCompassL
|
||||||
|
|
||||||
ItemTouchHelper.SimpleCallback simpleItemTouchCallback = new ItemTouchHelper.SimpleCallback(0, ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT) {
|
ItemTouchHelper.SimpleCallback simpleItemTouchCallback = new ItemTouchHelper.SimpleCallback(0, ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT) {
|
||||||
private float marginSides = getResources().getDimension(R.dimen.list_content_padding);
|
private float marginSides = getResources().getDimension(R.dimen.list_content_padding);
|
||||||
private Bitmap deleteBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.ic_action_delete_dark);
|
|
||||||
private Bitmap historyBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.ic_action_history);
|
|
||||||
private boolean iconHidden;
|
private boolean iconHidden;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -149,24 +147,27 @@ public class MapMarkersGroupsFragment extends Fragment implements OsmAndCompassL
|
||||||
colorIcon = night ? R.color.icon_color_default_dark : R.color.icon_color_default_light;
|
colorIcon = night ? R.color.icon_color_default_dark : R.color.icon_color_default_light;
|
||||||
colorText = night ? R.color.text_color_secondary_dark : R.color.text_color_secondary_light;
|
colorText = night ? R.color.text_color_secondary_dark : R.color.text_color_secondary_light;
|
||||||
}
|
}
|
||||||
if (colorIcon != 0) {
|
textPaint.setColor(ContextCompat.getColor(app, colorText));
|
||||||
iconPaint.setColorFilter(new PorterDuffColorFilter(ContextCompat.getColor(getActivity(), colorIcon), PorterDuff.Mode.SRC_IN));
|
Drawable icon = app.getUIUtilities().getIcon(
|
||||||
}
|
dX > 0 ? R.drawable.ic_action_history : R.drawable.ic_action_delete_dark,
|
||||||
textPaint.setColor(ContextCompat.getColor(getActivity(), colorText));
|
colorIcon);
|
||||||
|
int iconWidth = icon.getIntrinsicWidth();
|
||||||
|
int iconHeight = icon.getIntrinsicHeight();
|
||||||
float textMarginTop = ((float) itemView.getHeight() - (float) textHeight) / 2;
|
float textMarginTop = ((float) itemView.getHeight() - (float) textHeight) / 2;
|
||||||
|
float iconMarginTop = ((float) itemView.getHeight() - (float) iconHeight) / 2;
|
||||||
|
int iconTopY = itemView.getTop() + (int) iconMarginTop;
|
||||||
|
int iconLeftX;
|
||||||
if (dX > 0) {
|
if (dX > 0) {
|
||||||
|
iconLeftX = itemView.getLeft() + (int) marginSides;
|
||||||
c.drawRect(itemView.getLeft(), itemView.getTop(), dX, itemView.getBottom(), backgroundPaint);
|
c.drawRect(itemView.getLeft(), itemView.getTop(), dX, itemView.getBottom(), backgroundPaint);
|
||||||
float iconMarginTop = ((float) itemView.getHeight() - (float) historyBitmap.getHeight()) / 2;
|
c.drawText(moveToHistoryStr, itemView.getLeft() + 2 * marginSides + iconWidth, itemView.getTop() + textMarginTop + textHeight, textPaint);
|
||||||
c.drawBitmap(historyBitmap, itemView.getLeft() + marginSides, itemView.getTop() + iconMarginTop, iconPaint);
|
|
||||||
c.drawText(moveToHistoryStr, itemView.getLeft() + 2 * marginSides + historyBitmap.getWidth(),
|
|
||||||
itemView.getTop() + textMarginTop + textHeight, textPaint);
|
|
||||||
} else {
|
} else {
|
||||||
|
iconLeftX = itemView.getRight() - iconWidth - (int) marginSides;
|
||||||
c.drawRect(itemView.getRight() + dX, itemView.getTop(), itemView.getRight(), itemView.getBottom(), backgroundPaint);
|
c.drawRect(itemView.getRight() + dX, itemView.getTop(), itemView.getRight(), itemView.getBottom(), backgroundPaint);
|
||||||
float iconMarginTop = ((float) itemView.getHeight() - (float) deleteBitmap.getHeight()) / 2;
|
c.drawText(delStr, itemView.getRight() - iconWidth - 2 * marginSides - delStrWidth, itemView.getTop() + textMarginTop + textHeight, textPaint);
|
||||||
c.drawBitmap(deleteBitmap, itemView.getRight() - deleteBitmap.getWidth() - marginSides, itemView.getTop() + iconMarginTop, iconPaint);
|
|
||||||
c.drawText(delStr, itemView.getRight() - deleteBitmap.getWidth() - 2 * marginSides - delStrWidth,
|
|
||||||
itemView.getTop() + textMarginTop + textHeight, textPaint);
|
|
||||||
}
|
}
|
||||||
|
icon.setBounds(iconLeftX, iconTopY, iconLeftX + iconWidth, iconTopY + iconHeight);
|
||||||
|
icon.draw(c);
|
||||||
}
|
}
|
||||||
super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive);
|
super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive);
|
||||||
}
|
}
|
||||||
|
@ -189,10 +190,10 @@ public class MapMarkersGroupsFragment extends Fragment implements OsmAndCompassL
|
||||||
final MapMarker marker = (MapMarker) item;
|
final MapMarker marker = (MapMarker) item;
|
||||||
int snackbarStringRes;
|
int snackbarStringRes;
|
||||||
if (direction == ItemTouchHelper.RIGHT) {
|
if (direction == ItemTouchHelper.RIGHT) {
|
||||||
mapActivity.getMyApplication().getMapMarkersHelper().moveMapMarkerToHistory((MapMarker) item);
|
app.getMapMarkersHelper().moveMapMarkerToHistory((MapMarker) item);
|
||||||
snackbarStringRes = R.string.marker_moved_to_history;
|
snackbarStringRes = R.string.marker_moved_to_history;
|
||||||
} else {
|
} else {
|
||||||
mapActivity.getMyApplication().getMapMarkersHelper().removeMarker((MapMarker) item);
|
app.getMapMarkersHelper().removeMarker((MapMarker) item);
|
||||||
snackbarStringRes = R.string.item_removed;
|
snackbarStringRes = R.string.item_removed;
|
||||||
}
|
}
|
||||||
updateAdapter();
|
updateAdapter();
|
||||||
|
@ -201,9 +202,9 @@ public class MapMarkersGroupsFragment extends Fragment implements OsmAndCompassL
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
if (direction == ItemTouchHelper.RIGHT) {
|
if (direction == ItemTouchHelper.RIGHT) {
|
||||||
mapActivity.getMyApplication().getMapMarkersHelper().restoreMarkerFromHistory(marker, 0);
|
app.getMapMarkersHelper().restoreMarkerFromHistory(marker, 0);
|
||||||
} else {
|
} else {
|
||||||
mapActivity.getMyApplication().getMapMarkersHelper().addMarker(marker);
|
app.getMapMarkersHelper().addMarker(marker);
|
||||||
}
|
}
|
||||||
updateAdapter();
|
updateAdapter();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,9 @@
|
||||||
package net.osmand.plus.mapmarkers;
|
package net.osmand.plus.mapmarkers;
|
||||||
|
|
||||||
import android.graphics.Bitmap;
|
|
||||||
import android.graphics.BitmapFactory;
|
|
||||||
import android.graphics.Canvas;
|
import android.graphics.Canvas;
|
||||||
import android.graphics.Paint;
|
import android.graphics.Paint;
|
||||||
import android.graphics.PorterDuff;
|
|
||||||
import android.graphics.PorterDuffColorFilter;
|
|
||||||
import android.graphics.Rect;
|
import android.graphics.Rect;
|
||||||
|
import android.graphics.drawable.Drawable;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
|
@ -39,7 +36,6 @@ public class MapMarkersHistoryFragment extends Fragment implements MapMarkersHel
|
||||||
private MapMarkersHistoryAdapter adapter;
|
private MapMarkersHistoryAdapter adapter;
|
||||||
private OsmandApplication app;
|
private OsmandApplication app;
|
||||||
private Paint backgroundPaint = new Paint();
|
private Paint backgroundPaint = new Paint();
|
||||||
private Paint iconPaint = new Paint();
|
|
||||||
private Paint textPaint = new Paint();
|
private Paint textPaint = new Paint();
|
||||||
private Snackbar snackbar;
|
private Snackbar snackbar;
|
||||||
|
|
||||||
|
@ -58,9 +54,6 @@ public class MapMarkersHistoryFragment extends Fragment implements MapMarkersHel
|
||||||
backgroundPaint.setColor(ContextCompat.getColor(getActivity(), night ? R.color.divider_color_dark : R.color.divider_color_light));
|
backgroundPaint.setColor(ContextCompat.getColor(getActivity(), night ? R.color.divider_color_dark : R.color.divider_color_light));
|
||||||
backgroundPaint.setStyle(Paint.Style.FILL_AND_STROKE);
|
backgroundPaint.setStyle(Paint.Style.FILL_AND_STROKE);
|
||||||
backgroundPaint.setAntiAlias(true);
|
backgroundPaint.setAntiAlias(true);
|
||||||
iconPaint.setAntiAlias(true);
|
|
||||||
iconPaint.setFilterBitmap(true);
|
|
||||||
iconPaint.setDither(true);
|
|
||||||
textPaint.setTextSize(getResources().getDimension(R.dimen.default_desc_text_size));
|
textPaint.setTextSize(getResources().getDimension(R.dimen.default_desc_text_size));
|
||||||
textPaint.setFakeBoldText(true);
|
textPaint.setFakeBoldText(true);
|
||||||
textPaint.setAntiAlias(true);
|
textPaint.setAntiAlias(true);
|
||||||
|
@ -84,8 +77,6 @@ public class MapMarkersHistoryFragment extends Fragment implements MapMarkersHel
|
||||||
|
|
||||||
ItemTouchHelper.SimpleCallback simpleItemTouchCallback = new ItemTouchHelper.SimpleCallback(0, ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT) {
|
ItemTouchHelper.SimpleCallback simpleItemTouchCallback = new ItemTouchHelper.SimpleCallback(0, ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT) {
|
||||||
private float marginSides = getResources().getDimension(R.dimen.list_content_padding);
|
private float marginSides = getResources().getDimension(R.dimen.list_content_padding);
|
||||||
private Bitmap deleteBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.ic_action_delete_dark);
|
|
||||||
private Bitmap resetBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.ic_action_reset_to_default_dark);
|
|
||||||
private boolean iconHidden;
|
private boolean iconHidden;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -118,22 +109,27 @@ public class MapMarkersHistoryFragment extends Fragment implements MapMarkersHel
|
||||||
colorIcon = night ? R.color.icon_color_default_dark : R.color.icon_color_default_light;
|
colorIcon = night ? R.color.icon_color_default_dark : R.color.icon_color_default_light;
|
||||||
colorText = night ? R.color.text_color_secondary_dark : R.color.text_color_secondary_light;
|
colorText = night ? R.color.text_color_secondary_dark : R.color.text_color_secondary_light;
|
||||||
}
|
}
|
||||||
if (colorIcon != 0) {
|
textPaint.setColor(ContextCompat.getColor(app, colorText));
|
||||||
iconPaint.setColorFilter(new PorterDuffColorFilter(ContextCompat.getColor(getActivity(), colorIcon), PorterDuff.Mode.SRC_IN));
|
Drawable icon = app.getUIUtilities().getIcon(
|
||||||
}
|
dX > 0 ? R.drawable.ic_action_delete_dark : R.drawable.ic_action_reset_to_default_dark,
|
||||||
textPaint.setColor(ContextCompat.getColor(getActivity(), colorText));
|
colorIcon);
|
||||||
|
int iconWidth = icon.getIntrinsicWidth();
|
||||||
|
int iconHeight = icon.getIntrinsicHeight();
|
||||||
float textMarginTop = ((float) itemView.getHeight() - (float) textHeight) / 2;
|
float textMarginTop = ((float) itemView.getHeight() - (float) textHeight) / 2;
|
||||||
|
float iconMarginTop = ((float) itemView.getHeight() - (float) iconHeight) / 2;
|
||||||
|
int iconTopY = itemView.getTop() + (int) iconMarginTop;
|
||||||
|
int iconLeftX;
|
||||||
if (dX > 0) {
|
if (dX > 0) {
|
||||||
|
iconLeftX = itemView.getLeft() + (int) marginSides;
|
||||||
c.drawRect(itemView.getLeft(), itemView.getTop(), dX, itemView.getBottom(), backgroundPaint);
|
c.drawRect(itemView.getLeft(), itemView.getTop(), dX, itemView.getBottom(), backgroundPaint);
|
||||||
float iconMarginTop = ((float) itemView.getHeight() - (float) deleteBitmap.getHeight()) / 2;
|
c.drawText(delStr, itemView.getLeft() + 2 * marginSides + iconWidth, itemView.getTop() + textMarginTop + textHeight, textPaint);
|
||||||
c.drawBitmap(deleteBitmap, itemView.getLeft() + marginSides, itemView.getTop() + iconMarginTop, iconPaint);
|
|
||||||
c.drawText(delStr, itemView.getLeft() + 2 * marginSides + deleteBitmap.getWidth(), itemView.getTop() + textMarginTop + textHeight, textPaint);
|
|
||||||
} else {
|
} else {
|
||||||
|
iconLeftX = itemView.getRight() - iconWidth - (int) marginSides;
|
||||||
c.drawRect(itemView.getRight() + dX, itemView.getTop(), itemView.getRight(), itemView.getBottom(), backgroundPaint);
|
c.drawRect(itemView.getRight() + dX, itemView.getTop(), itemView.getRight(), itemView.getBottom(), backgroundPaint);
|
||||||
float iconMarginTop = ((float) itemView.getHeight() - (float) resetBitmap.getHeight()) / 2;
|
c.drawText(activateStr, itemView.getRight() - iconWidth - 2 * marginSides - activateStrWidth, itemView.getTop() + textMarginTop + textHeight, textPaint);
|
||||||
c.drawBitmap(resetBitmap, itemView.getRight() - resetBitmap.getWidth() - marginSides, itemView.getTop() + iconMarginTop, iconPaint);
|
|
||||||
c.drawText(activateStr, itemView.getRight() - resetBitmap.getWidth() - 2 * marginSides - activateStrWidth, itemView.getTop() + textMarginTop + textHeight, textPaint);
|
|
||||||
}
|
}
|
||||||
|
icon.setBounds(iconLeftX, iconTopY, iconLeftX + iconWidth, iconTopY + iconHeight);
|
||||||
|
icon.draw(c);
|
||||||
}
|
}
|
||||||
super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive);
|
super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive);
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,7 @@ public class MapMarkerHeaderViewHolder extends RecyclerView.ViewHolder {
|
||||||
final View iconSpace;
|
final View iconSpace;
|
||||||
final TextView title;
|
final TextView title;
|
||||||
final TextView content;
|
final TextView content;
|
||||||
|
final TextView clearButton;
|
||||||
final TextView button;
|
final TextView button;
|
||||||
final SwitchCompat disableGroupSwitch;
|
final SwitchCompat disableGroupSwitch;
|
||||||
final View bottomShadow;
|
final View bottomShadow;
|
||||||
|
@ -28,6 +29,7 @@ public class MapMarkerHeaderViewHolder extends RecyclerView.ViewHolder {
|
||||||
disableGroupSwitch = (SwitchCompat) itemView.findViewById(R.id.disable_group_switch);
|
disableGroupSwitch = (SwitchCompat) itemView.findViewById(R.id.disable_group_switch);
|
||||||
bottomShadow = itemView.findViewById(R.id.bottom_shadow);
|
bottomShadow = itemView.findViewById(R.id.bottom_shadow);
|
||||||
content = itemView.findViewById(R.id.content);
|
content = itemView.findViewById(R.id.content);
|
||||||
|
clearButton = itemView.findViewById(R.id.clear_button);
|
||||||
button = itemView.findViewById(R.id.text_button);
|
button = itemView.findViewById(R.id.text_button);
|
||||||
articleDescription = itemView.findViewById(R.id.article_description);
|
articleDescription = itemView.findViewById(R.id.article_description);
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,8 +20,10 @@ import java.text.SimpleDateFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
public class MapMarkersHistoryAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
public class MapMarkersHistoryAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
||||||
|
|
||||||
|
@ -35,6 +37,7 @@ public class MapMarkersHistoryAdapter extends RecyclerView.Adapter<RecyclerView.
|
||||||
|
|
||||||
private OsmandApplication app;
|
private OsmandApplication app;
|
||||||
private List<Object> items = new ArrayList<>();
|
private List<Object> items = new ArrayList<>();
|
||||||
|
private Map<Integer, List<MapMarker>> markerGroups = new HashMap<>();
|
||||||
private MapMarkersHistoryAdapterListener listener;
|
private MapMarkersHistoryAdapterListener listener;
|
||||||
private Snackbar snackbar;
|
private Snackbar snackbar;
|
||||||
private boolean night;
|
private boolean night;
|
||||||
|
@ -47,6 +50,7 @@ public class MapMarkersHistoryAdapter extends RecyclerView.Adapter<RecyclerView.
|
||||||
|
|
||||||
public void createHeaders() {
|
public void createHeaders() {
|
||||||
items = new ArrayList<>();
|
items = new ArrayList<>();
|
||||||
|
markerGroups = new HashMap<>();
|
||||||
List<MapMarker> markersHistory = app.getMapMarkersHelper().getMapMarkersHistory();
|
List<MapMarker> markersHistory = app.getMapMarkersHelper().getMapMarkersHistory();
|
||||||
int previousHeader = -1;
|
int previousHeader = -1;
|
||||||
int monthsDisplayed = 0;
|
int monthsDisplayed = 0;
|
||||||
|
@ -85,10 +89,22 @@ public class MapMarkersHistoryAdapter extends RecyclerView.Adapter<RecyclerView.
|
||||||
items.add(markerYear);
|
items.add(markerYear);
|
||||||
previousHeader = markerYear;
|
previousHeader = markerYear;
|
||||||
}
|
}
|
||||||
|
addMarkerToGroup(previousHeader, marker);
|
||||||
items.add(marker);
|
items.add(marker);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void addMarkerToGroup(Integer groupHeader, MapMarker marker) {
|
||||||
|
List<MapMarker> group = markerGroups.get(groupHeader);
|
||||||
|
if (group != null) {
|
||||||
|
group.add(marker);
|
||||||
|
} else {
|
||||||
|
group = new ArrayList<>();
|
||||||
|
group.add(marker);
|
||||||
|
markerGroups.put(groupHeader, group);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void setAdapterListener(MapMarkersHistoryAdapterListener listener) {
|
public void setAdapterListener(MapMarkersHistoryAdapterListener listener) {
|
||||||
this.listener = listener;
|
this.listener = listener;
|
||||||
}
|
}
|
||||||
|
@ -113,7 +129,7 @@ public class MapMarkersHistoryAdapter extends RecyclerView.Adapter<RecyclerView.
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
|
public void onBindViewHolder(final RecyclerView.ViewHolder holder, int position) {
|
||||||
UiUtilities iconsCache = app.getUIUtilities();
|
UiUtilities iconsCache = app.getUIUtilities();
|
||||||
if (holder instanceof MapMarkerItemViewHolder) {
|
if (holder instanceof MapMarkerItemViewHolder) {
|
||||||
final MapMarkerItemViewHolder itemViewHolder = (MapMarkerItemViewHolder) holder;
|
final MapMarkerItemViewHolder itemViewHolder = (MapMarkerItemViewHolder) holder;
|
||||||
|
@ -189,7 +205,32 @@ public class MapMarkersHistoryAdapter extends RecyclerView.Adapter<RecyclerView.
|
||||||
}
|
}
|
||||||
dateViewHolder.disableGroupSwitch.setVisibility(View.GONE);
|
dateViewHolder.disableGroupSwitch.setVisibility(View.GONE);
|
||||||
dateViewHolder.title.setText(dateString);
|
dateViewHolder.title.setText(dateString);
|
||||||
|
dateViewHolder.clearButton.setVisibility(View.VISIBLE);
|
||||||
dateViewHolder.articleDescription.setVisibility(View.GONE);
|
dateViewHolder.articleDescription.setVisibility(View.GONE);
|
||||||
|
|
||||||
|
dateViewHolder.clearButton.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
final List<MapMarker> group = markerGroups.get(dateHeader);
|
||||||
|
if (group == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (MapMarker marker : group) {
|
||||||
|
app.getMapMarkersHelper().removeMarker((MapMarker) marker);
|
||||||
|
}
|
||||||
|
snackbar = Snackbar.make(holder.itemView, app.getString(R.string.n_items_removed), Snackbar.LENGTH_LONG)
|
||||||
|
.setAction(R.string.shared_string_undo, new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View view) {
|
||||||
|
for (MapMarker marker : group) {
|
||||||
|
app.getMapMarkersHelper().addMarker(marker);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
UiUtilities.setupSnackbar(snackbar, night);
|
||||||
|
snackbar.show();
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,18 +1,16 @@
|
||||||
package net.osmand.plus.mapmarkers.adapters;
|
package net.osmand.plus.mapmarkers.adapters;
|
||||||
|
|
||||||
import android.graphics.Bitmap;
|
|
||||||
import android.graphics.BitmapFactory;
|
|
||||||
import android.graphics.Canvas;
|
import android.graphics.Canvas;
|
||||||
import android.graphics.Paint;
|
import android.graphics.Paint;
|
||||||
import android.graphics.PorterDuff;
|
|
||||||
import android.graphics.PorterDuffColorFilter;
|
|
||||||
import android.graphics.Rect;
|
import android.graphics.Rect;
|
||||||
|
import android.graphics.drawable.Drawable;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
|
||||||
import androidx.core.content.ContextCompat;
|
import androidx.core.content.ContextCompat;
|
||||||
import androidx.recyclerview.widget.ItemTouchHelper;
|
import androidx.recyclerview.widget.ItemTouchHelper;
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
|
||||||
|
import net.osmand.plus.OsmandApplication;
|
||||||
import net.osmand.plus.R;
|
import net.osmand.plus.R;
|
||||||
import net.osmand.plus.activities.MapActivity;
|
import net.osmand.plus.activities.MapActivity;
|
||||||
|
|
||||||
|
@ -23,12 +21,9 @@ public class MapMarkersItemTouchHelperCallback extends ItemTouchHelper.Callback
|
||||||
private boolean swipeEnabled = true;
|
private boolean swipeEnabled = true;
|
||||||
|
|
||||||
private Paint backgroundPaint = new Paint();
|
private Paint backgroundPaint = new Paint();
|
||||||
private Paint iconPaint = new Paint();
|
|
||||||
private Paint textPaint = new Paint();
|
private Paint textPaint = new Paint();
|
||||||
|
|
||||||
private float marginSides;
|
private float marginSides;
|
||||||
private Bitmap deleteBitmap;
|
|
||||||
private Bitmap historyBitmap;
|
|
||||||
private boolean iconHidden;
|
private boolean iconHidden;
|
||||||
private boolean night;
|
private boolean night;
|
||||||
|
|
||||||
|
@ -47,16 +42,11 @@ public class MapMarkersItemTouchHelperCallback extends ItemTouchHelper.Callback
|
||||||
this.mapActivity = mapActivity;
|
this.mapActivity = mapActivity;
|
||||||
this.adapter = adapter;
|
this.adapter = adapter;
|
||||||
marginSides = mapActivity.getResources().getDimension(R.dimen.list_content_padding);
|
marginSides = mapActivity.getResources().getDimension(R.dimen.list_content_padding);
|
||||||
deleteBitmap = BitmapFactory.decodeResource(mapActivity.getResources(), R.drawable.ic_action_delete_dark);
|
|
||||||
historyBitmap = BitmapFactory.decodeResource(mapActivity.getResources(), R.drawable.ic_action_history);
|
|
||||||
night = !mapActivity.getMyApplication().getSettings().isLightContent();
|
night = !mapActivity.getMyApplication().getSettings().isLightContent();
|
||||||
|
|
||||||
backgroundPaint.setColor(ContextCompat.getColor(mapActivity, night ? R.color.divider_color_dark : R.color.divider_color_light));
|
backgroundPaint.setColor(ContextCompat.getColor(mapActivity, night ? R.color.divider_color_dark : R.color.divider_color_light));
|
||||||
backgroundPaint.setStyle(Paint.Style.FILL_AND_STROKE);
|
backgroundPaint.setStyle(Paint.Style.FILL_AND_STROKE);
|
||||||
backgroundPaint.setAntiAlias(true);
|
backgroundPaint.setAntiAlias(true);
|
||||||
iconPaint.setAntiAlias(true);
|
|
||||||
iconPaint.setFilterBitmap(true);
|
|
||||||
iconPaint.setDither(true);
|
|
||||||
textPaint.setTextSize(mapActivity.getResources().getDimension(R.dimen.default_desc_text_size));
|
textPaint.setTextSize(mapActivity.getResources().getDimension(R.dimen.default_desc_text_size));
|
||||||
textPaint.setFakeBoldText(true);
|
textPaint.setFakeBoldText(true);
|
||||||
textPaint.setAntiAlias(true);
|
textPaint.setAntiAlias(true);
|
||||||
|
@ -100,6 +90,7 @@ public class MapMarkersItemTouchHelperCallback extends ItemTouchHelper.Callback
|
||||||
@Override
|
@Override
|
||||||
public void onChildDraw(Canvas c, RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, float dX, float dY, int actionState, boolean isCurrentlyActive) {
|
public void onChildDraw(Canvas c, RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, float dX, float dY, int actionState, boolean isCurrentlyActive) {
|
||||||
if (actionState == ItemTouchHelper.ACTION_STATE_SWIPE && viewHolder instanceof MapMarkerItemViewHolder) {
|
if (actionState == ItemTouchHelper.ACTION_STATE_SWIPE && viewHolder instanceof MapMarkerItemViewHolder) {
|
||||||
|
OsmandApplication app = mapActivity.getMyApplication();
|
||||||
if (!iconHidden && isCurrentlyActive) {
|
if (!iconHidden && isCurrentlyActive) {
|
||||||
((MapMarkerItemViewHolder) viewHolder).optionsBtn.setVisibility(View.GONE);
|
((MapMarkerItemViewHolder) viewHolder).optionsBtn.setVisibility(View.GONE);
|
||||||
iconHidden = true;
|
iconHidden = true;
|
||||||
|
@ -115,17 +106,19 @@ public class MapMarkersItemTouchHelperCallback extends ItemTouchHelper.Callback
|
||||||
colorIcon = night ? R.color.icon_color_default_dark : R.color.icon_color_default_light;
|
colorIcon = night ? R.color.icon_color_default_dark : R.color.icon_color_default_light;
|
||||||
colorText = night ? R.color.text_color_secondary_dark : R.color.text_color_secondary_light;
|
colorText = night ? R.color.text_color_secondary_dark : R.color.text_color_secondary_light;
|
||||||
}
|
}
|
||||||
if (colorIcon != 0) {
|
|
||||||
iconPaint.setColorFilter(new PorterDuffColorFilter(ContextCompat.getColor(mapActivity, colorIcon), PorterDuff.Mode.SRC_IN));
|
|
||||||
}
|
|
||||||
textPaint.setColor(ContextCompat.getColor(mapActivity, colorText));
|
textPaint.setColor(ContextCompat.getColor(mapActivity, colorText));
|
||||||
|
Drawable icon = app.getUIUtilities().getIcon(R.drawable.ic_action_history, colorIcon);
|
||||||
|
int iconWidth = icon.getIntrinsicWidth();
|
||||||
|
int iconHeight = icon.getIntrinsicHeight();
|
||||||
float textMarginTop = ((float) itemView.getHeight() - (float) textHeight) / 2;
|
float textMarginTop = ((float) itemView.getHeight() - (float) textHeight) / 2;
|
||||||
|
float iconMarginTop = ((float) itemView.getHeight() - (float) iconHeight) / 2;
|
||||||
|
int iconTopY = itemView.getTop() + (int) iconMarginTop;
|
||||||
|
int iconLeftX = itemView.getLeft() + (int) marginSides;
|
||||||
c.drawRect(itemView.getLeft(), itemView.getTop(), dX, itemView.getBottom(), backgroundPaint);
|
c.drawRect(itemView.getLeft(), itemView.getTop(), dX, itemView.getBottom(), backgroundPaint);
|
||||||
float iconMarginTop = ((float) itemView.getHeight() - (float) historyBitmap.getHeight()) / 2;
|
c.drawText(moveToHistoryStr, itemView.getLeft() + 2 * marginSides + iconWidth,
|
||||||
c.drawBitmap(historyBitmap, itemView.getLeft() + marginSides, itemView.getTop() + iconMarginTop, iconPaint);
|
|
||||||
c.drawText(moveToHistoryStr, itemView.getLeft() + 2 * marginSides + historyBitmap.getWidth(),
|
|
||||||
itemView.getTop() + textMarginTop + textHeight, textPaint);
|
itemView.getTop() + textMarginTop + textHeight, textPaint);
|
||||||
|
icon.setBounds(iconLeftX, iconTopY, iconLeftX + iconWidth, iconTopY + iconHeight);
|
||||||
|
icon.draw(c);
|
||||||
}
|
}
|
||||||
super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive);
|
super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,45 +0,0 @@
|
||||||
package net.osmand.plus.render;
|
|
||||||
import android.content.res.Resources;
|
|
||||||
import android.graphics.Bitmap;
|
|
||||||
import android.graphics.BitmapFactory;
|
|
||||||
import android.graphics.BitmapFactory.Options;
|
|
||||||
import android.os.Build;
|
|
||||||
import android.util.DisplayMetrics;
|
|
||||||
|
|
||||||
public abstract class UnscaledBitmapLoader {
|
|
||||||
|
|
||||||
public static final UnscaledBitmapLoader instance;
|
|
||||||
|
|
||||||
static {
|
|
||||||
instance = Integer.parseInt(Build.VERSION.SDK) < 4 ? new Old() : new New();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Bitmap loadFromResource(Resources resources, int resId, BitmapFactory.Options options, DisplayMetrics densityDpi) {
|
|
||||||
return instance.load(resources, resId, options, densityDpi);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class Old extends UnscaledBitmapLoader {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
Bitmap load(Resources resources, int resId, Options options, DisplayMetrics densityDpi) {
|
|
||||||
return BitmapFactory.decodeResource(resources, resId, options);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class New extends UnscaledBitmapLoader {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
Bitmap load(Resources resources, int resId, Options options, DisplayMetrics dm) {
|
|
||||||
options = new BitmapFactory.Options();
|
|
||||||
options.inScaled = false;
|
|
||||||
options.inTargetDensity = dm.densityDpi;
|
|
||||||
options.inDensity = dm.densityDpi;
|
|
||||||
return BitmapFactory.decodeResource(resources, resId, options);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
abstract Bitmap load(Resources resources, int resId, BitmapFactory.Options options, DisplayMetrics densityDpi);
|
|
||||||
|
|
||||||
}
|
|
|
@ -3,7 +3,6 @@ package net.osmand.plus.views;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.BitmapFactory;
|
import android.graphics.BitmapFactory;
|
||||||
import android.graphics.Canvas;
|
import android.graphics.Canvas;
|
||||||
import android.graphics.Color;
|
|
||||||
import android.graphics.Paint;
|
import android.graphics.Paint;
|
||||||
import android.graphics.PointF;
|
import android.graphics.PointF;
|
||||||
import android.graphics.PorterDuff;
|
import android.graphics.PorterDuff;
|
||||||
|
|
Loading…
Reference in a new issue