private void init(Context context, int color) {

      // To fight color branding.
      getWindow().setFormat(PixelFormat.RGBA_8888);

      final LinearLayout mContentView = new LinearLayout(context);
      mContentView.setGravity(Gravity.CENTER);

      mColorPicker = new ColorPickerView(context);

      mContentView.addView(mColorPicker, LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);

      mContentView.setPadding(
          Math.round(mColorPicker.getDrawingOffset()),
          0,
          Math.round(mColorPicker.getDrawingOffset()),
          0);

      mColorPicker.setOnColorChangedListener(this);
      mColorPicker.setColor(color, true);
      mColorPicker.setAlphaSliderVisible(true);

      setTitle(R.string.pick_color);
      setView(mContentView);

      setButton(BUTTON_POSITIVE, context.getString(android.R.string.ok), this);
      setButton(BUTTON_NEGATIVE, context.getString(android.R.string.cancel), this);
    }
 @Override
 public void onClick(DialogInterface dialog, int which) {
   switch (which) {
     case BUTTON_POSITIVE:
       if (mListener != null) {
         mListener.onColorSelected(mColorPicker.getColor());
       }
       break;
   }
   dismiss();
 }
    public int getColor() {

      return mColorPicker.getColor();
    }
    public void setAlphaSliderVisible(boolean visible) {

      mColorPicker.setAlphaSliderVisible(visible);
    }