is there a system based method to call one of those color pickers, like in the Google Calendar app? Or do I have it to build it on my own?
You need to use Color Picker Collection.
Implementation:
ColorPickerDialog colorcalendar = ColorPickerDialog.newInstance(
R.string.color_picker_default_title,
mColor,
mSelectedColorCal0,
5,
Utils.isTablet(this)? ColorPickerDialog.SIZE_LARGE : ColorPickerDialog.SIZE_SMALL);
//Implement listener to get selected color value
colorcalendar.setOnColorSelectedListener(new ColorPickerSwatch.OnColorSelectedListener(){
@Override
public void onColorSelected(int color)
{
// ADD MARKER
Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.ic_mobileedge_navpoint);
bmp = changeBitmapColor(bmp, color);
googleMap.addMarker(new MarkerOptions()
.position(latLng)
.title("My Spot")
.snippet("This is my spot!")
.icon(BitmapDescriptorFactory.fromBitmap(bmp)));
}
});
colorcalendar.show(getFragmentManager(),"cal");
Function to change bitmap color:
private Bitmap changeBitmapColor(Bitmap sourceBitmap, int color) {
Bitmap resultBitmap = Bitmap.createBitmap(sourceBitmap, 0, 0,
sourceBitmap.getWidth() - 1, sourceBitmap.getHeight() - 1);
Paint p = new Paint();
ColorFilter filter = new LightingColorFilter(color, 1);
p.setColorFilter(filter);
Canvas canvas = new Canvas(resultBitmap);
canvas.drawBitmap(resultBitmap, 0, 0, p);
return resultBitmap;
}
I tested and it worked fine! The marker has to be all white with alpha, only then is that the colors will be perfect!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With