Closed LossyDragon closed 6 years ago
I'm getting the exact same issue when using the builder for the ColorPicerDialog. If it helps at all, below is code snippet on how it is being launched.
ColorPickerDialog.Builder builder = new ColorPickerDialog.Builder(QueryValueMetricConfiguration.this,
AlertDialog.THEME_DEVICE_DEFAULT_LIGHT);
builder.setTitle("Set Background Colour");
builder.setPreferenceName("Background Colour");
builder.setPositiveButton("Confirm", new ColorListener() {
@Override
public void onColorSelected(ColorEnvelope colorEnvelope) {
view.setBackgroundColor(colorEnvelope.getColor());
view.setTag(colorEnvelope);
processRules();
}
});
builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
dialogInterface.dismiss();
}
});
builder.show();
@skydoves I found the issue:
private int getColorFromBitmap(float x, float y) {
if (paletteDrawable == null) return 0;
Matrix invertMatrix = new Matrix();
palette.getImageMatrix().invert(invertMatrix);
float[] mappedPoints = new float[]{x, y};
invertMatrix.mapPoints(mappedPoints);
if (palette.getDrawable() != null && palette.getDrawable() instanceof BitmapDrawable &&
mappedPoints[0] > 0 && mappedPoints[1] > 0 &&
mappedPoints[0] < palette.getDrawable().getIntrinsicWidth() && mappedPoints[1] < palette.getDrawable().getIntrinsicHeight()) {
invalidate();
return ((BitmapDrawable) palette.getDrawable()).getBitmap().getPixel((int) mappedPoints[0], (int) mappedPoints[1]);
}
return 0;
}
In the non-zero return statement, palette.getDrawable()
will return a drawable with the dimensions relative to whatever the display size is.
In Android P, the call to .getBitmap()
will return the size of the original bitmap, which is 730×730.
You'll have to interpolate the mapped points, or multiply the points with a scaling factor in the .getPixel()
call.
I have a fix I will trying to create a branch later today
It's fixed at version 1.0.5. @acorbin3 Thank you for your contribution!
t's fixed at version 1.0.5. Need to update the version of lbr
Hello,
I recently bumped my application to API 28, when launching the application, the following below crashes within the ColorPickerView.
Using these dependencies crash the app implementation 'com.android.support:design:28.0.0-rc01' implementation 'com.android.support:appcompat-v7:28.0.0-rc01'
Going down to API 27 works fine, not sure if the new dependencies once they get out of RC will still cause issues.
Thanks,