14.01.2013 Views

Android™ Application Development - Bahar Ali Khan

Android™ Application Development - Bahar Ali Khan

Android™ Application Development - Bahar Ali Khan

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

gradientColors[1] = Color.YELLOW;<br />

gradientColors[2] = Color.RED;<br />

float[] gradientPositions = new float[3];<br />

gradientPositions[0] = 0.0f;<br />

gradientPositions[1] = 0.5f;<br />

gradientPositions[2] = 1.0f;<br />

Chapter 11: Advanced Android <strong>Development</strong><br />

RadialGradient radialGradientShader = new RadialGradient(centerX, centerY, radius,<br />

gradientColors,<br />

gradientPositions,<br />

TileMode.CLAMP);<br />

Each of the gradient Shaders (linear, radial, and sweep) lets you defi ne the gradient fi ll using either of<br />

these techniques.<br />

Using Shader Tile Modes<br />

The brush sizes of the gradient Shaders are defi ned using explicit bounding rectangles or center points<br />

and radius lengths; the Bitmap Shader implies a brush size through its bitmap size.<br />

If the area defi ned by your Shader brush is smaller than the area being fi lled, the TileMode determines<br />

how the remaining area will be covered.<br />

❑ CLAMP Uses the edge colors of the Shader to fi ll the extra space.<br />

❑ MIRROR Flips the Shader image horizontally and vertically so that each image seams with the<br />

last.<br />

❑ REPEAT Repeats the Shader image horizontally and vertically, but doesn’t fl ip it.<br />

Using MaskFilters<br />

The MaskFilter classes let you assign edge effects to your Paint.<br />

Extensions to MaskFilter apply transformations to the alpha-channel of a Paint along its outer edge.<br />

Android includes the following Mask Filters:<br />

❑ BlurMaskFilter Specifi es a blur style and radius to feather the edges of your Paint.<br />

❑ EmbossMaskFilter Specifi es the direction of the light source and ambient light level to add<br />

an embossing effect.<br />

To apply a Mask Filter, use the setMaskFilter method, passing in a MaskFilter object. The following<br />

code snippet applies an EmbossMaskFilter to an existing Paint:<br />

// Set the direction of the light source<br />

float[] direction = new float[]{ 1, 1, 1 };<br />

// Set the ambient light level<br />

float light = 0.4f;<br />

// Choose a level of specularity to apply<br />

float specular = 6;<br />

377

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!