Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Calendar color picker

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?

enter image description here

like image 685
tom_tom Avatar asked Jul 01 '14 13:07

tom_tom


1 Answers

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!

like image 70
extmkv Avatar answered Sep 25 '22 16:09

extmkv