• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
17 package android.graphics;
18 
19 public class SweepGradient extends Shader {
20 
21     /**
22      * A subclass of Shader that draws a sweep gradient around a center point.
23      *
24      * @param cx       The x-coordinate of the center
25      * @param cy       The y-coordinate of the center
26      * @param colors   The colors to be distributed between around the center.
27      *                 There must be at least 2 colors in the array.
28      * @param positions May be NULL. The relative position of
29      *                 each corresponding color in the colors array, beginning
30      *                 with 0 and ending with 1.0. If the values are not
31      *                 monotonic, the drawing may produce unexpected results.
32      *                 If positions is NULL, then the colors are automatically
33      *                 spaced evenly.
34      */
SweepGradient(float cx, float cy, int colors[], float positions[])35     public SweepGradient(float cx, float cy,
36                          int colors[], float positions[]) {
37         if (colors.length < 2) {
38             throw new IllegalArgumentException("needs >= 2 number of colors");
39         }
40         if (positions != null && colors.length != positions.length) {
41             throw new IllegalArgumentException(
42                         "color and position arrays must be of equal length");
43         }
44         native_instance = nativeCreate1(cx, cy, colors, positions);
45         native_shader = nativePostCreate1(native_instance, cx, cy, colors, positions);
46     }
47 
48     /**
49      * A subclass of Shader that draws a sweep gradient around a center point.
50      *
51      * @param cx       The x-coordinate of the center
52      * @param cy       The y-coordinate of the center
53      * @param color0   The color to use at the start of the sweep
54      * @param color1   The color to use at the end of the sweep
55      */
SweepGradient(float cx, float cy, int color0, int color1)56     public SweepGradient(float cx, float cy, int color0, int color1) {
57         native_instance = nativeCreate2(cx, cy, color0, color1);
58         native_shader = nativePostCreate2(native_instance, cx, cy, color0, color1);
59     }
60 
nativeCreate1(float x, float y, int colors[], float positions[])61     private static native int nativeCreate1(float x, float y, int colors[], float positions[]);
nativeCreate2(float x, float y, int color0, int color1)62     private static native int nativeCreate2(float x, float y, int color0, int color1);
63 
nativePostCreate1(int native_shader, float cx, float cy, int[] colors, float[] positions)64     private static native int nativePostCreate1(int native_shader, float cx, float cy,
65             int[] colors, float[] positions);
nativePostCreate2(int native_shader, float cx, float cy, int color0, int color1)66     private static native int nativePostCreate2(int native_shader, float cx, float cy,
67             int color0, int color1);
68 }
69 
70