Removed duplicating method.

This commit is contained in:
GaidamakUA 2016-04-05 17:52:23 +03:00
parent a42d54d43e
commit af98243576
13 changed files with 33 additions and 69 deletions

View file

@ -1,9 +1,6 @@
package net.osmand.plus;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.PorterDuff;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.LayerDrawable;
import android.support.annotation.ColorInt;
@ -24,19 +21,6 @@ public class IconsCache {
this.app = app;
}
public Drawable scaleImage(Drawable image, float scaleFactor) {
if ((image == null) || !(image instanceof BitmapDrawable)) {
return image;
}
Bitmap b = ((BitmapDrawable)image).getBitmap();
int sizeX = Math.round(image.getIntrinsicWidth() * scaleFactor);
int sizeY = Math.round(image.getIntrinsicHeight() * scaleFactor);
Bitmap bitmapResized = Bitmap.createScaledBitmap(b, sizeX, sizeY, false);
return new BitmapDrawable(app.getResources(), bitmapResized);
}
private Drawable getDrawable(@DrawableRes int resId, @ColorRes int clrId) {
long hash = ((long)resId << 31l) + clrId;
Drawable d = drawable.get(hash);
@ -44,10 +28,8 @@ public class IconsCache {
d = ContextCompat.getDrawable(app, resId);
d = DrawableCompat.wrap(d);
d.mutate();
// d.clearColorFilter();
if (clrId != 0) {
DrawableCompat.setTint(d, ContextCompat.getColor(app, clrId));
// d.setColorFilter(ContextCompat.getColor(app, clrId), PorterDuff.Mode.SRC_IN);
}
drawable.put(hash, d);
}
@ -63,9 +45,6 @@ public class IconsCache {
d.mutate();
DrawableCompat.setTint(d, color);
// d = app.getResources().getDrawable(resId).mutate();
// d.clearColorFilter();
// d.setColorFilter(color, PorterDuff.Mode.SRC_IN);
drawable.put(hash, d);
}
return d;
@ -79,7 +58,6 @@ public class IconsCache {
return getDrawable(id, colorId);
}
public Drawable getIcon(@DrawableRes int backgroundId, @DrawableRes int id, @ColorRes int colorId) {
Drawable b = getDrawable(backgroundId, 0);
Drawable f = getDrawable(id, colorId);
@ -93,10 +71,6 @@ public class IconsCache {
return getDrawable(id, app.getSettings().isLightContent() ? R.color.icon_color : 0);
}
public Drawable getContentIcon(@DrawableRes int id, boolean isLightContent) {
return getDrawable(id, isLightContent ? R.color.icon_color : 0);
}
public Drawable getIcon(@DrawableRes int id) {
return getDrawable(id, 0);
}
@ -105,15 +79,6 @@ public class IconsCache {
return getDrawable(id, light ? R.color.icon_color : 0);
}
public Drawable getContentIconCompat(@DrawableRes int id) {
Drawable drawable = ContextCompat.getDrawable(app, id);
@ColorInt int color = ContextCompat.getColor(app, getDefaultColorRes(app));
drawable = DrawableCompat.wrap(drawable);
drawable.mutate();
DrawableCompat.setTint(drawable, color);
return drawable;
}
public void paintMenuItem(MenuItem menuItem) {
Drawable drawable = menuItem.getIcon();
drawable = DrawableCompat.wrap(drawable);

View file

@ -371,7 +371,7 @@ public class OsmandApplication extends MultiDexApplication {
View view = uiContext.getLayoutInflater().inflate(R.layout.select_voice_first, null);
((ImageView) view.findViewById(R.id.icon))
.setImageDrawable(getIconsCache().getContentIcon(R.drawable.ic_action_volume_up, getSettings().isLightContent()));
.setImageDrawable(getIconsCache().getIcon(R.drawable.ic_action_volume_up, getSettings().isLightContent()));
view.findViewById(R.id.spinner).setOnClickListener(new View.OnClickListener() {
@Override
@ -392,7 +392,7 @@ public class OsmandApplication extends MultiDexApplication {
});
((ImageView) view.findViewById(R.id.dropDownIcon))
.setImageDrawable(getIconsCache().getContentIcon(R.drawable.ic_action_arrow_drop_down, getSettings().isLightContent()));
.setImageDrawable(getIconsCache().getIcon(R.drawable.ic_action_arrow_drop_down, getSettings().isLightContent()));
builder.setCancelable(true);
builder.setNegativeButton(R.string.shared_string_cancel, null);

View file

@ -80,7 +80,7 @@ public class AppModeDialog {
} else {
if (useMapTheme) {
boolean nightMode = ctx.getDaynightHelper().isNightModeForMapControls();
iv.setImageDrawable(ctx.getIconsCache().getContentIcon(mode.getSmallIconDark(), !nightMode));
iv.setImageDrawable(ctx.getIconsCache().getIcon(mode.getSmallIconDark(), !nightMode));
AndroidUtils.setBackground(ctx, iv, nightMode, R.drawable.dashboard_button_light, R.drawable.dashboard_button_dark);
} else {
iv.setImageDrawable(ctx.getIconsCache().getContentIcon(mode.getSmallIconDark()));

View file

@ -368,7 +368,7 @@ public class NotesFragment extends OsmAndListFragment {
DashAudioVideoNotesFragment.getNoteView(recording, row, getMyApplication());
}
// ((ImageView) row.findViewById(R.id.play)).setImageDrawable(getMyApplication().getIconsCache()
// .getContentIcon(R.drawable.ic_play_dark));
// .getIcon(R.drawable.ic_play_dark));
row.findViewById(R.id.play).setVisibility(View.GONE);

View file

@ -161,7 +161,7 @@ public class DashWaypointsFragment extends DashLocationFragment {
final boolean optionsVisible = (SHOW_ALL && getMyApplication().getTargetPointsHelper().getIntermediatePoints().size() > 0);
options.setImageDrawable(getMyApplication().getIconsCache().
getContentIcon(optionsVisible? R.drawable.ic_overflow_menu_white :
getContentIcon(optionsVisible ? R.drawable.ic_overflow_menu_white :
R.drawable.ic_action_remove_dark));
options.setOnClickListener(new View.OnClickListener() {
@Override
@ -222,7 +222,7 @@ public class DashWaypointsFragment extends DashLocationFragment {
MenuItem item;
// item = optionsMenu.getMenu().add(
// R.string.shared_string_add_to_favorites).setIcon(getMyApplication().getIconsCache().
// getContentIcon(R.drawable.ic_action_fav_dark));
// getIcon(R.drawable.ic_action_fav_dark));
// item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
// @Override
// public boolean onMenuItemClick(MenuItem item) {

View file

@ -334,7 +334,7 @@ public class MapMarkerDialogHelper {
} else {
final ImageButton btn = (ImageButton) v.findViewById(R.id.image_button);
btn.setImageDrawable(app.getIconsCache().getContentIcon(R.drawable.ic_overflow_menu_white, !nightMode));
btn.setImageDrawable(app.getIconsCache().getIcon(R.drawable.ic_overflow_menu_white, !nightMode));
btn.setVisibility(View.VISIBLE);
btn.setOnClickListener(new View.OnClickListener() {
@Override
@ -423,7 +423,7 @@ public class MapMarkerDialogHelper {
more.setVisibility(View.GONE);
if (!marker.history && !sorted) {
move.setVisibility(View.VISIBLE);
((ImageView) move).setImageDrawable(app.getIconsCache().getContentIcon(
((ImageView) move).setImageDrawable(app.getIconsCache().getIcon(
R.drawable.ic_action_reorder, !nightMode));
move.setTag(new DynamicListView.DragIcon() {
@Override
@ -513,7 +513,7 @@ public class MapMarkerDialogHelper {
.getColor(useCenter ? R.color.color_distance : R.color.color_myloc_distance));
} else {
waypointIcon.setImageDrawable(app.getIconsCache()
.getContentIcon(R.drawable.ic_action_flag_dark, !nightMode));
.getIcon(R.drawable.ic_action_flag_dark, !nightMode));
AndroidUtils.setTextSecondaryColor(ctx, text, nightMode);
AndroidUtils.setTextSecondaryColor(ctx, textDist, nightMode);
}

View file

@ -418,7 +418,7 @@ public class WaypointDialogHelper {
remove.setVisibility(View.GONE);
move.setVisibility(View.GONE);
more.setVisibility(View.VISIBLE);
((ImageButton) more).setImageDrawable(app.getIconsCache().getContentIcon(
((ImageButton) more).setImageDrawable(app.getIconsCache().getIcon(
R.drawable.map_overflow_menu_white, !nightMode));
more.setOnClickListener(new View.OnClickListener() {
@Override
@ -481,7 +481,7 @@ public class WaypointDialogHelper {
remove.setVisibility(View.GONE);
move.setVisibility(View.VISIBLE);
more.setVisibility(View.GONE);
((ImageView) move).setImageDrawable(app.getIconsCache().getContentIcon(
((ImageView) move).setImageDrawable(app.getIconsCache().getIcon(
R.drawable.ic_action_reorder, !nightMode));
move.setTag(new DragIcon() {
@Override
@ -544,7 +544,7 @@ public class WaypointDialogHelper {
remove.setVisibility(View.VISIBLE);
move.setVisibility(View.GONE);
more.setVisibility(View.GONE);
((ImageButton) remove).setImageDrawable(app.getIconsCache().getContentIcon(
((ImageButton) remove).setImageDrawable(app.getIconsCache().getIcon(
R.drawable.ic_action_remove_dark, !nightMode));
remove.setOnClickListener(new View.OnClickListener() {
@Override

View file

@ -50,7 +50,7 @@ public class DestinationReachedMenuFragment extends Fragment {
IconsCache iconsCache = getMapActivity().getMyApplication().getIconsCache();
ImageButton closeImageButton = (ImageButton) view.findViewById(R.id.closeImageButton);
closeImageButton.setImageDrawable(iconsCache.getContentIcon(R.drawable.ic_action_remove_dark, menu.isLight()));
closeImageButton.setImageDrawable(iconsCache.getIcon(R.drawable.ic_action_remove_dark, menu.isLight()));
closeImageButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
@ -60,7 +60,7 @@ public class DestinationReachedMenuFragment extends Fragment {
Button removeDestButton = (Button) view.findViewById(R.id.removeDestButton);
removeDestButton.setCompoundDrawablesWithIntrinsicBounds(
iconsCache.getContentIcon(R.drawable.ic_action_done, menu.isLight()), null, null, null);
iconsCache.getIcon(R.drawable.ic_action_done, menu.isLight()), null, null, null);
AndroidUtils.setTextPrimaryColor(view.getContext(), removeDestButton, !menu.isLight());
removeDestButton.setOnClickListener(new View.OnClickListener() {
@Override
@ -80,7 +80,7 @@ public class DestinationReachedMenuFragment extends Fragment {
Button recalcDestButton = (Button) view.findViewById(R.id.recalcDestButton);
recalcDestButton.setCompoundDrawablesWithIntrinsicBounds(
iconsCache.getContentIcon(R.drawable.ic_action_gdirections_dark, menu.isLight()), null, null, null);
iconsCache.getIcon(R.drawable.ic_action_gdirections_dark, menu.isLight()), null, null, null);
AndroidUtils.setTextPrimaryColor(view.getContext(), recalcDestButton, !menu.isLight());
recalcDestButton.setOnClickListener(new View.OnClickListener() {
@Override
@ -102,7 +102,7 @@ public class DestinationReachedMenuFragment extends Fragment {
Button findParkingButton = (Button) view.findViewById(R.id.findParkingButton);
findParkingButton.setCompoundDrawablesWithIntrinsicBounds(
iconsCache.getContentIcon(R.drawable.ic_action_parking_dark, menu.isLight()), null, null, null);
iconsCache.getIcon(R.drawable.ic_action_parking_dark, menu.isLight()), null, null, null);
AndroidUtils.setTextPrimaryColor(view.getContext(), findParkingButton, !menu.isLight());
findParkingButton.setOnClickListener(new View.OnClickListener() {
@Override

View file

@ -33,7 +33,6 @@ import net.osmand.plus.MapMarkersHelper;
import net.osmand.plus.MapMarkersHelper.MapMarker;
import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.TargetPointsHelper;
import net.osmand.plus.TargetPointsHelper.TargetPoint;
@ -217,7 +216,7 @@ public class MapRouteInfoMenu implements IRouteInformationListener {
main.findViewById(R.id.InfoDuration).setVisibility(View.GONE);
textView.setText(R.string.route_is_too_long);
textView.setVisibility(View.VISIBLE);
iconView.setImageDrawable(mapActivity.getMyApplication().getIconsCache().getContentIcon(R.drawable.ic_warning, isLight()));
iconView.setImageDrawable(mapActivity.getMyApplication().getIconsCache().getIcon(R.drawable.ic_warning, isLight()));
} else {
main.findViewById(R.id.dividerToDropDown).setVisibility(View.GONE);
main.findViewById(R.id.RouteInfoControls).setVisibility(View.GONE);
@ -328,7 +327,7 @@ public class MapRouteInfoMenu implements IRouteInformationListener {
updateToIcon(parentView);
ImageView toDropDownIcon = (ImageView) parentView.findViewById(R.id.toDropDownIcon);
toDropDownIcon.setImageDrawable(mapActivity.getMyApplication().getIconsCache().getContentIcon(R.drawable.ic_action_arrow_drop_down, isLight()));
toDropDownIcon.setImageDrawable(mapActivity.getMyApplication().getIconsCache().getIcon(R.drawable.ic_action_arrow_drop_down, isLight()));
}
private void updateToIcon(View parentView) {
@ -400,7 +399,7 @@ public class MapRouteInfoMenu implements IRouteInformationListener {
updateFromIcon(parentView);
ImageView fromDropDownIcon = (ImageView) parentView.findViewById(R.id.fromDropDownIcon);
fromDropDownIcon.setImageDrawable(mapActivity.getMyApplication().getIconsCache().getContentIcon(R.drawable.ic_action_arrow_drop_down, isLight()));
fromDropDownIcon.setImageDrawable(mapActivity.getMyApplication().getIconsCache().getIcon(R.drawable.ic_action_arrow_drop_down, isLight()));
}
@SuppressWarnings("deprecation")
@ -525,7 +524,7 @@ public class MapRouteInfoMenu implements IRouteInformationListener {
mainView.findViewById(R.id.RouteInfoControls).setVisibility(View.VISIBLE);
final OsmandApplication ctx = mapActivity.getMyApplication();
ImageView prev = (ImageView) mainView.findViewById(R.id.Prev);
prev.setImageDrawable(ctx.getIconsCache().getContentIcon(R.drawable.ic_prev, isLight()));
prev.setImageDrawable(ctx.getIconsCache().getIcon(R.drawable.ic_prev, isLight()));
if (directionInfo >= 0) {
prev.setVisibility(View.VISIBLE);
prev.setOnClickListener(new View.OnClickListener() {
@ -554,7 +553,7 @@ public class MapRouteInfoMenu implements IRouteInformationListener {
}
ImageView next = (ImageView) mainView.findViewById(R.id.Next);
next.setVisibility(View.VISIBLE);
next.setImageDrawable(ctx.getIconsCache().getContentIcon(R.drawable.ic_next, isLight()));
next.setImageDrawable(ctx.getIconsCache().getIcon(R.drawable.ic_next, isLight()));
next.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
@ -592,9 +591,9 @@ public class MapRouteInfoMenu implements IRouteInformationListener {
infoDurationView.setVisibility(View.GONE);
textView.setVisibility(View.VISIBLE);
} else {
infoIcon.setImageDrawable(ctx.getIconsCache().getContentIcon(R.drawable.ic_action_polygom_dark, isLight()));
infoIcon.setImageDrawable(ctx.getIconsCache().getIcon(R.drawable.ic_action_polygom_dark, isLight()));
infoIcon.setVisibility(View.VISIBLE);
durationIcon.setImageDrawable(ctx.getIconsCache().getContentIcon(R.drawable.ic_action_time, isLight()));
durationIcon.setImageDrawable(ctx.getIconsCache().getIcon(R.drawable.ic_action_time, isLight()));
durationIcon.setVisibility(View.VISIBLE);
infoDistanceView.setVisibility(View.VISIBLE);
infoDurationView.setVisibility(View.VISIBLE);

View file

@ -331,7 +331,7 @@ public class RoutePreferencesMenu {
v.findViewById(R.id.description_text).setVisibility(View.GONE);
v.findViewById(R.id.select_button).setVisibility(View.GONE);
((ImageView) v.findViewById(R.id.icon))
.setImageDrawable(app.getIconsCache().getContentIcon(R.drawable.ic_action_volume_up, !nightMode));
.setImageDrawable(app.getIconsCache().getIcon(R.drawable.ic_action_volume_up, !nightMode));
final CompoundButton btn = (CompoundButton) v.findViewById(R.id.toggle_item);
btn.setVisibility(View.VISIBLE);
btn.setChecked(!routingHelper.getVoiceRouter().isMute());
@ -351,7 +351,7 @@ public class RoutePreferencesMenu {
View v = mapActivity.getLayoutInflater().inflate(R.layout.switch_select_list_item, null);
AndroidUtils.setListItemBackground(mapActivity, v, nightMode);
((ImageView) v.findViewById(R.id.icon))
.setImageDrawable(app.getIconsCache().getContentIcon(R.drawable.ic_action_road_works_dark, !nightMode));
.setImageDrawable(app.getIconsCache().getIcon(R.drawable.ic_action_road_works_dark, !nightMode));
v.findViewById(R.id.toggle_item).setVisibility(View.GONE);
final TextView btn = (TextView) v.findViewById(R.id.select_button);
btn.setTextColor(btn.getLinkTextColors());
@ -437,7 +437,7 @@ public class RoutePreferencesMenu {
final TextView gpxSpinner = (TextView) v.findViewById(R.id.GPXRouteSpinner);
AndroidUtils.setTextPrimaryColor(mapActivity, gpxSpinner, nightMode);
((ImageView) v.findViewById(R.id.dropDownIcon))
.setImageDrawable(app.getIconsCache().getContentIcon(R.drawable.ic_action_arrow_drop_down, !nightMode));
.setImageDrawable(app.getIconsCache().getIcon(R.drawable.ic_action_arrow_drop_down, !nightMode));
updateSpinnerItems(gpxSpinner);
return v;
}
@ -445,7 +445,7 @@ public class RoutePreferencesMenu {
View v = mapActivity.getLayoutInflater().inflate(R.layout.layers_list_activity_item, null);
AndroidUtils.setListItemBackground(mapActivity, v, nightMode);
final ImageView icon = (ImageView) v.findViewById(R.id.icon);
icon.setImageDrawable(app.getIconsCache().getContentIcon(R.drawable.map_action_settings, !nightMode));
icon.setImageDrawable(app.getIconsCache().getIcon(R.drawable.map_action_settings, !nightMode));
icon.setVisibility(View.VISIBLE);
TextView titleView = (TextView) v.findViewById(R.id.title);
titleView.setText(R.string.routing_settings_2);

View file

@ -105,7 +105,7 @@ public class ShareMenuFragment extends Fragment implements OnItemClickListener {
final ShareItem item = getItem(position);
ImageView icon = (ImageView) v.findViewById(R.id.icon);
icon.setImageDrawable(menu.getMapActivity().getMyApplication()
.getIconsCache().getContentIcon(item.getIconResourceId(), menu.isLight()));
.getIconsCache().getIcon(item.getIconResourceId(), menu.isLight()));
TextView name = (TextView) v.findViewById(R.id.name);
AndroidUtils.setTextPrimaryColor(v.getContext(), name, !menu.isLight());
name.setText(getContext().getText(item.getTitleResourceId()));

View file

@ -1210,7 +1210,7 @@ public class OsMoGroupsActivity extends OsmandExpandableListActivity implements
if (model.isMainGroup()) {
v.setVisibility(View.GONE);
} else {
// (ImageView) v.setImageDrawable(getMyApplication().getIconsCache().getContentIcon(R.drawable.ic_action_settings));
// (ImageView) v.setImageDrawable(getMyApplication().getIconsCache().getIcon(R.drawable.ic_action_settings));
if ((selectedObject == model) != ((CheckBox) v).isChecked()) {
((CheckBox) v).setChecked(selectedObject == model);

View file

@ -222,7 +222,7 @@ public class MapControlsLayer extends OsmandMapLayer {
public void updateRouteButtons(View main, boolean routeInfo) {
boolean nightMode = mapActivity.getMyApplication().getDaynightHelper().isNightModeForMapControls();
ImageView cancelRouteButton = (ImageView) main.findViewById(R.id.map_cancel_route_button);
cancelRouteButton.setImageDrawable(app.getIconsCache().getContentIcon(R.drawable.map_action_cancel, !nightMode));
cancelRouteButton.setImageDrawable(app.getIconsCache().getIcon(R.drawable.map_action_cancel, !nightMode));
AndroidUtils.setBackground(mapActivity, cancelRouteButton, nightMode, R.drawable.dashboard_button_light, R.drawable.dashboard_button_dark);
cancelRouteButton.setOnClickListener(new View.OnClickListener() {
@Override
@ -232,7 +232,7 @@ public class MapControlsLayer extends OsmandMapLayer {
});
ImageView waypointsButton = (ImageView) main.findViewById(R.id.map_waypoints_route_button);
waypointsButton.setImageDrawable(app.getIconsCache().getContentIcon(R.drawable.map_action_waypoint, !nightMode));
waypointsButton.setImageDrawable(app.getIconsCache().getIcon(R.drawable.map_action_waypoint, !nightMode));
AndroidUtils.setBackground(mapActivity, waypointsButton, nightMode, R.drawable.dashboard_button_light, R.drawable.dashboard_button_dark);
waypointsButton.setOnClickListener(new View.OnClickListener() {
@Override
@ -243,7 +243,7 @@ public class MapControlsLayer extends OsmandMapLayer {
ImageView options = (ImageView) main.findViewById(R.id.map_options_route_button);
options.setImageDrawable(!routeInfo ? app.getIconsCache().getIcon(R.drawable.map_action_settings,
R.color.osmand_orange) : app.getIconsCache().getContentIcon(R.drawable.map_action_settings, !nightMode));
R.color.osmand_orange) : app.getIconsCache().getIcon(R.drawable.map_action_settings, !nightMode));
AndroidUtils.setBackground(mapActivity, options, nightMode, R.drawable.dashboard_button_light, R.drawable.dashboard_button_dark);
options.setOnClickListener(new View.OnClickListener() {
@Override