use drawable instead of bitmap, delete unnecessary code

This commit is contained in:
Nazar-Kutz 2020-05-14 12:23:20 +03:00
parent c9193e2c8c
commit c5547827f4
6 changed files with 55 additions and 116 deletions

View file

@ -711,11 +711,6 @@ public class AndroidUtils {
return new BitmapDrawable(ctx.getResources(), flipBitmapHorizontally(bitmap)); return new BitmapDrawable(ctx.getResources(), flipBitmapHorizontally(bitmap));
} }
public static Bitmap bitmapFromDrawableRes(@NonNull Context ctx, @DrawableRes int drawableResId) {
Drawable drawable = ContextCompat.getDrawable(ctx, drawableResId);
return drawableToBitmap(drawable);
}
public static Bitmap drawableToBitmap(Drawable drawable) { public static Bitmap drawableToBitmap(Drawable drawable) {
if (drawable instanceof BitmapDrawable) { if (drawable instanceof BitmapDrawable) {
BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable; BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;

View file

@ -1,11 +1,9 @@
package net.osmand.plus.mapmarkers; package net.osmand.plus.mapmarkers;
import android.graphics.Bitmap;
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;
@ -23,7 +21,6 @@ import androidx.recyclerview.widget.RecyclerView;
import com.google.android.material.snackbar.Snackbar; import com.google.android.material.snackbar.Snackbar;
import net.osmand.AndroidUtils;
import net.osmand.GPXUtilities.WptPt; import net.osmand.GPXUtilities.WptPt;
import net.osmand.Location; import net.osmand.Location;
import net.osmand.data.Amenity; import net.osmand.data.Amenity;
@ -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 = AndroidUtils.bitmapFromDrawableRes(mapActivity, R.drawable.ic_action_delete_dark);
private Bitmap historyBitmap = AndroidUtils.bitmapFromDrawableRes(mapActivity, 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();
} }

View file

@ -1,11 +1,9 @@
package net.osmand.plus.mapmarkers; package net.osmand.plus.mapmarkers;
import android.graphics.Bitmap;
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;
@ -22,7 +20,6 @@ import androidx.recyclerview.widget.RecyclerView;
import com.google.android.material.snackbar.Snackbar; import com.google.android.material.snackbar.Snackbar;
import net.osmand.AndroidUtils;
import net.osmand.plus.MapMarkersHelper; import net.osmand.plus.MapMarkersHelper;
import net.osmand.plus.MapMarkersHelper.MapMarker; import net.osmand.plus.MapMarkersHelper.MapMarker;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
@ -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 = AndroidUtils.bitmapFromDrawableRes(app, R.drawable.ic_action_delete_dark);
private Bitmap resetBitmap = AndroidUtils.bitmapFromDrawableRes(app, 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);
} }

View file

@ -1,18 +1,16 @@
package net.osmand.plus.mapmarkers.adapters; package net.osmand.plus.mapmarkers.adapters;
import android.graphics.Bitmap;
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.AndroidUtils; 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 = AndroidUtils.bitmapFromDrawableRes(mapActivity, R.drawable.ic_action_delete_dark);
historyBitmap = AndroidUtils.bitmapFromDrawableRes(mapActivity, 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);
} }

View file

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

View file

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