FileDocCategorySizeDatePackage
FingerPaint.javaAPI DocAndroid 1.5 API7110Wed May 06 22:41:08 BST 2009com.example.android.apis.graphics

FingerPaint

public class FingerPaint extends GraphicsActivity implements ColorPickerDialog.OnColorChangedListener

Fields Summary
private Paint
mPaint
private MaskFilter
mEmboss
private MaskFilter
mBlur
private static final int
COLOR_MENU_ID
private static final int
EMBOSS_MENU_ID
private static final int
BLUR_MENU_ID
private static final int
ERASE_MENU_ID
private static final int
SRCATOP_MENU_ID
Constructors Summary
Methods Summary
public voidcolorChanged(int color)

        mPaint.setColor(color);
    
protected voidonCreate(android.os.Bundle savedInstanceState)

        super.onCreate(savedInstanceState);
        setContentView(new MyView(this));

        mPaint = new Paint();
        mPaint.setAntiAlias(true);
        mPaint.setDither(true);
        mPaint.setColor(0xFFFF0000);
        mPaint.setStyle(Paint.Style.STROKE);
        mPaint.setStrokeJoin(Paint.Join.ROUND);
        mPaint.setStrokeCap(Paint.Cap.ROUND);
        mPaint.setStrokeWidth(12);
        
        mEmboss = new EmbossMaskFilter(new float[] { 1, 1, 1 },
                                       0.4f, 6, 3.5f);

        mBlur = new BlurMaskFilter(8, BlurMaskFilter.Blur.NORMAL);
    
public booleanonCreateOptionsMenu(android.view.Menu menu)


    
        
        super.onCreateOptionsMenu(menu);
        
        menu.add(0, COLOR_MENU_ID, 0, "Color").setShortcut('3", 'c");
        menu.add(0, EMBOSS_MENU_ID, 0, "Emboss").setShortcut('4", 's");
        menu.add(0, BLUR_MENU_ID, 0, "Blur").setShortcut('5", 'z");
        menu.add(0, ERASE_MENU_ID, 0, "Erase").setShortcut('5", 'z");
        menu.add(0, SRCATOP_MENU_ID, 0, "SrcATop").setShortcut('5", 'z");

        /****   Is this the mechanism to extend with filter effects?
        Intent intent = new Intent(null, getIntent().getData());
        intent.addCategory(Intent.CATEGORY_ALTERNATIVE);
        menu.addIntentOptions(
                              Menu.ALTERNATIVE, 0,
                              new ComponentName(this, NotesList.class),
                              null, intent, 0, null);
        *****/
        return true;
    
public booleanonOptionsItemSelected(android.view.MenuItem item)

        mPaint.setXfermode(null);
        mPaint.setAlpha(0xFF);

        switch (item.getItemId()) {
            case COLOR_MENU_ID:
                new ColorPickerDialog(this, this, mPaint.getColor()).show();
                return true;
            case EMBOSS_MENU_ID:
                if (mPaint.getMaskFilter() != mEmboss) {
                    mPaint.setMaskFilter(mEmboss);
                } else {
                    mPaint.setMaskFilter(null);
                }
                return true;
            case BLUR_MENU_ID:
                if (mPaint.getMaskFilter() != mBlur) {
                    mPaint.setMaskFilter(mBlur);
                } else {
                    mPaint.setMaskFilter(null);
                }
                return true;
            case ERASE_MENU_ID:
                mPaint.setXfermode(new PorterDuffXfermode(
                                                        PorterDuff.Mode.CLEAR));
                return true;
            case SRCATOP_MENU_ID:
                mPaint.setXfermode(new PorterDuffXfermode(
                                                    PorterDuff.Mode.SRC_ATOP));
                mPaint.setAlpha(0x80);
                return true;
        }
        return super.onOptionsItemSelected(item);
    
public booleanonPrepareOptionsMenu(android.view.Menu menu)

        super.onPrepareOptionsMenu(menu);
        return true;