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 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 */ RadialGradient(float x, float y, float radius, int colors[], float positions[], TileMode tile)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 native_shader = nativePostCreate1(native_instance, x, y, radius, colors, positions, 44 tile.nativeInt); 45 } 46 47 /** Create a shader that draws a radial gradient given the center and radius. 48 @param x The x-coordinate of the center of the radius 49 @param y The y-coordinate of the center of the radius 50 @param radius Must be positive. The radius of the circle for this gradient 51 @param color0 The color at the center of the circle. 52 @param color1 The color at the edge of the circle. 53 @param tile The Shader tiling mode 54 */ RadialGradient(float x, float y, float radius, int color0, int color1, TileMode tile)55 public RadialGradient(float x, float y, float radius, 56 int color0, int color1, TileMode tile) { 57 if (radius <= 0) { 58 throw new IllegalArgumentException("radius must be > 0"); 59 } 60 native_instance = nativeCreate2(x, y, radius, color0, color1, tile.nativeInt); 61 native_shader = nativePostCreate2(native_instance, x, y, radius, color0, color1, 62 tile.nativeInt); 63 } 64 nativeCreate1(float x, float y, float radius, int colors[], float positions[], int tileMode)65 private static native int nativeCreate1(float x, float y, float radius, 66 int colors[], float positions[], int tileMode); nativeCreate2(float x, float y, float radius, int color0, int color1, int tileMode)67 private static native int nativeCreate2(float x, float y, float radius, 68 int color0, int color1, int tileMode); 69 nativePostCreate1(int native_shader, float x, float y, float radius, int colors[], float positions[], int tileMode)70 private static native int nativePostCreate1(int native_shader, float x, float y, float radius, 71 int colors[], float positions[], int tileMode); nativePostCreate2(int native_shader, float x, float y, float radius, int color0, int color1, int tileMode)72 private static native int nativePostCreate2(int native_shader, float x, float y, float radius, 73 int color0, int color1, int tileMode); 74 } 75 76