RadialGradient.java revision 9066cfe9886ac131c34d59ed0e2d287b0e3c0087
1/*
2 * Copyright (C) 2007 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.graphics;
18
19public class RadialGradient extends Shader {
20
21	/**	Create a shader that draws a radial gradient given the center and radius.
22        @param x        The x-coordinate of the center of the radius
23        @param y        The y-coordinate of the center of the radius
24		@param radius   Must be positive. The radius of the circle for this gradient
25        @param colors   The colors to be distributed between the center and edge of the circle
26        @param positions May be NULL. The relative position of
27                        each corresponding color in the colors array. If this is NULL,
28                        the the colors are distributed evenly between the center and edge of the circle.
29        @param  tile    The Shader tiling mode
30	*/
31	public RadialGradient(float x, float y, float radius,
32                          int colors[], float positions[], TileMode tile) {
33        if (radius <= 0) {
34            throw new IllegalArgumentException("radius must be > 0");
35        }
36        if (colors.length < 2) {
37            throw new IllegalArgumentException("needs >= 2 number of colors");
38        }
39        if (positions != null && colors.length != positions.length) {
40            throw new IllegalArgumentException("color and position arrays must be of equal length");
41        }
42        native_instance = nativeCreate1(x, y, radius, colors, positions, tile.nativeInt);
43    }
44
45	/**	Create a shader that draws a radial gradient given the center and radius.
46        @param x        The x-coordinate of the center of the radius
47        @param y        The y-coordinate of the center of the radius
48		@param radius   Must be positive. The radius of the circle for this gradient
49        @param color0   The color at the center of the circle.
50        @param color1   The color at the edge of the circle.
51        @param tile     The Shader tiling mode
52	*/
53	public RadialGradient(float x, float y, float radius,
54                          int color0, int color1, TileMode tile) {
55        if (radius <= 0) {
56            throw new IllegalArgumentException("radius must be > 0");
57        }
58        native_instance = nativeCreate2(x, y, radius, color0, color1, tile.nativeInt);
59    }
60
61	private static native int nativeCreate1(float x, float y, float radius,
62                                            int colors[], float positions[], int tileMode);
63	private static native int nativeCreate2(float x, float y, float radius,
64                                            int color0, int color1, int tileMode);
65}
66
67