Skip to content

Commit

Permalink
- android: scale support, update on color change
Browse files Browse the repository at this point in the history
  • Loading branch information
Max Vasin committed Oct 25, 2017
1 parent a4d4067 commit e627f46
Showing 1 changed file with 12 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,19 @@
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.ColorMatrix;
import android.graphics.ColorMatrixColorFilter;
import android.graphics.LightingColorFilter;
import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffColorFilter;
import android.graphics.PorterDuffXfermode;
import android.graphics.Rect;
import android.graphics.drawable.Animatable;
import android.icu.text.Normalizer2;
import android.net.Uri;
import android.support.annotation.NonNull;
import android.util.DisplayMetrics;

import com.facebook.common.references.CloseableReference;
import com.facebook.datasource.DataSource;
import com.facebook.drawee.backends.pipeline.Fresco;
import com.facebook.drawee.backends.pipeline.PipelineDraweeController;
import com.facebook.drawee.controller.BaseControllerListener;
import com.facebook.drawee.controller.ControllerListener;
import com.facebook.drawee.drawable.ScalingUtils;
import com.facebook.drawee.generic.GenericDraweeHierarchy;
import com.facebook.drawee.generic.GenericDraweeHierarchyBuilder;
Expand All @@ -42,10 +35,8 @@
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

import javax.annotation.Nullable;

Expand Down Expand Up @@ -95,7 +86,7 @@ public void onFinalImageSet(
CloseableReference.closeSafely(imageReference);
}
}
this.marker.imageLoaded();
this.marker.composeIcon();
}
}

Expand All @@ -117,9 +108,6 @@ public void onFinalImageSet(
private int zIndex = 0;
private int width = 64;
private int height = 64;
private String badgeImage;
private String badgeMask;
private String badgeOverlay;
private boolean fadeBadgeImage;
private float scale = 1.0f;

Expand Down Expand Up @@ -190,7 +178,7 @@ public void setZIndex(int zIndex) {

public void setPinColor(int pinColor) {
this.pinColor = pinColor;
update();
this.composeIcon();
}

public void setAnchor(double x, double y) {
Expand All @@ -204,7 +192,7 @@ public void setAnchor(double x, double y) {
public void setSize(double width, double height) {
this.width = (int)width;
this.height = (int)height;
update();
this.composeIcon();
}

private void loadBitmap(String uri, DraweeHolder<?> holder) {
Expand All @@ -225,27 +213,25 @@ private void loadBitmap(String uri, DraweeHolder<?> holder) {
}

public void setBadgeImage(String badgeImage) {
this.badgeImage = badgeImage;
this.loadBitmap(badgeImage, badgeImageHolder);
}

public void setBadgeMask(String badgeMask) {
this.badgeMask = badgeMask;
this.loadBitmap(badgeMask, badgeMaskHolder);
}

public void setBadgeOverlay(String badgeOverlay) {
this.badgeOverlay = badgeOverlay;
this.loadBitmap(badgeOverlay, badgeOverlayHolder);
}

public void setFadeBadgeImage(boolean fadeBadgeImage) {
this.fadeBadgeImage = fadeBadgeImage;
this.imageLoaded();
this.composeIcon();
}

public void setScale(float scale) {
this.scale = scale;
this.composeIcon();
}

private BitmapDescriptor getIcon() {
Expand All @@ -267,7 +253,7 @@ private MarkerOptions createMarkerOptions() {
return options;
}

public synchronized void imageLoaded() {
public synchronized void composeIcon() {
Bitmap image = null;
Bitmap mask = null;
Bitmap overlay = null;
Expand All @@ -285,12 +271,13 @@ public synchronized void imageLoaded() {
overlay = controllerListener.getBitmap();

if ((image != null) && (mask != null) && (overlay != null)) {
Bitmap result = Bitmap.createBitmap(dpToPx(this.width), dpToPx(this.height), Bitmap.Config.ARGB_8888);
Bitmap result = Bitmap.createBitmap(
(int)(dpToPx(this.width) * this.scale),
(int)(dpToPx(this.height) * this.scale),
Bitmap.Config.ARGB_8888
);
Canvas tempCanvas = new Canvas(result);

Bitmap overlayBitmap = Bitmap.createBitmap(dpToPx(this.width), dpToPx(this.height), Bitmap.Config.ARGB_8888);
Canvas overlayCanvas = new Canvas(overlayBitmap);

Rect dst = new Rect(0,0,result.getWidth()-1, result.getHeight()-1);
Rect src = new Rect(0,0,image.getWidth()-1, image.getHeight()-1);

Expand All @@ -310,11 +297,7 @@ public synchronized void imageLoaded() {
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_OVER));
paint.setColorFilter(new PorterDuffColorFilter(this.pinColor, PorterDuff.Mode.MULTIPLY));
src = new Rect(0,0,overlay.getWidth()-1, overlay.getHeight()-1);
overlayCanvas.drawBitmap(overlay, src, dst, paint);

paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_OVER));
paint.setColorFilter(null);
tempCanvas.drawBitmap(overlayBitmap, src, dst, paint);
tempCanvas.drawBitmap(overlay, src, dst, paint);

iconBitmapDescriptor = BitmapDescriptorFactory.fromBitmap(result);
} else {
Expand Down

0 comments on commit e627f46

Please sign in to comment.