Shreyash Mahajan
Shreyash Mahajan

Reputation: 23596

Android: not able to get the color with using the ColourPicker but can get color after get the focus on that view

In My Paint application i am going to pick the colour from the colourpicker.

MyApp is like that: This link

Now i am using this class to pick the colour.

the code i use to pick the colour is:

public void pickColour(){
    takePhotoFromCamera = false;
    takePhotoFromGallery = false;
    new UberColorPickerDialog(TWSBIDrawMainActivity.this, this, canvasColor, true).show(); // generats error here
    myView.getVisibility();
}

the Override method fot that picker is:

@Override
public void colorChanged(int color) {
    // TODO Auto-generated method stub
    TWSBIDrawMainActivity.canvasColor = color;
    float hsv[] = new float[3];
    Color.colorToHSV(TWSBIDrawMainActivity.canvasColor, hsv);
}

And i am drawing that colour in MyView class with code:

@Override
    protected void onDraw(Canvas canvas) {

        //canvas.drawColor(0, PorterDuff.Mode.CLEAR);
        // set the Canvas Color
        canvas.drawColor(canvasColor);
 }

Now while i select colourfrom picker then it is selected but when i press on accept it is not going to effect on that view but while i touch on that view then it takes effect.

Instead of that i want is that the colour should be get effect when i press accept from the picker.

Please help me in this. Thanks.

Edited:

Please see this Screen Shot: enter image description here

Here after opening the dialog if i press the accept button then the colour should be take effect on the white background. but instead of that right now if i press accept button and then if i touch on the white background then only the color take effect. So what should i have to do ?

Hope you got my point. I realy need help of this issue. please help me. . Thanks.

Upvotes: 0

Views: 384

Answers (2)

Android Help
Android Help

Reputation: 271

You change in the MyView class in the OnDraw function like this.

@Override protected void onDraw(Canvas canvas) {

    canvas.drawBitmap(mBitmap, 0, 0, mBitmapPaint);
    int colorPicked = MainActivity.selectedColor;

    paint1 = createPen(colorPicked);
     for (Path p : paths){       
         canvas.drawPath(p, paint1);
         paint1.setColor(colorPicked);
         }

    }

private Paint createPen(int color) {
    // TODO Auto-generated method stub

    paint1 = new Paint();
    paint1.setAntiAlias(true);
    paint1.setDither(true);
    paint1.setStyle(Paint.Style.STROKE);
    paint1.setStrokeJoin(Paint.Join.ROUND);
    paint1.setStrokeCap(Paint.Cap.ROUND);
    paint1.setStrokeWidth(3);
    return paint1;
}

Upvotes: 0

havexz
havexz

Reputation: 9590

The soln looks like you have to call the invalidate on the view after color is selected.

try myView.invalidate() in colorChanged like

@Override
public void colorChanged(int color) {
    // TODO Auto-generated method stub
    TWSBIDrawMainActivity.canvasColor = color;
    float hsv[] = new float[3];
    Color.colorToHSV(TWSBIDrawMainActivity.canvasColor, hsv);
    myView.invalidate();
}

Here is more help on view

Upvotes: 1

Related Questions