• 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 LinearGradient extends Shader {
20 	/**	Create a shader that draws a linear gradient along a line.
21         @param x0           The x-coordinate for the start of the gradient line
22         @param y0           The y-coordinate for the start of the gradient line
23         @param x1           The x-coordinate for the end of the gradient line
24         @param y1           The y-coordinate for the end of the gradient line
25         @param  colors      The colors to be distributed along the gradient line
26         @param  positions   May be null. The relative positions [0..1] of
27                             each corresponding color in the colors array. If this is null,
28                             the the colors are distributed evenly along the gradient line.
29         @param  tile        The Shader tiling mode
30 	*/
LinearGradient(float x0, float y0, float x1, float y1, int colors[], float positions[], TileMode tile)31 	public LinearGradient(float x0, float y0, float x1, float y1, int colors[], float positions[],
32             TileMode tile) {
33         if (colors.length < 2) {
34             throw new IllegalArgumentException("needs >= 2 number of colors");
35         }
36         if (positions != null && colors.length != positions.length) {
37             throw new IllegalArgumentException("color and position arrays must be of equal length");
38         }
39         native_instance = nativeCreate1(x0, y0, x1, y1, colors, positions, tile.nativeInt);
40         native_shader = nativePostCreate1(native_instance, x0, y0, x1, y1, colors, positions,
41                 tile.nativeInt);
42     }
43 
44 	/**	Create a shader that draws a linear gradient along a line.
45         @param x0       The x-coordinate for the start of the gradient line
46         @param y0       The y-coordinate for the start of the gradient line
47         @param x1       The x-coordinate for the end of the gradient line
48         @param y1       The y-coordinate for the end of the gradient line
49         @param  color0  The color at the start of the gradient line.
50         @param  color1  The color at the end of the gradient line.
51         @param  tile    The Shader tiling mode
52 	*/
LinearGradient(float x0, float y0, float x1, float y1, int color0, int color1, TileMode tile)53 	public LinearGradient(float x0, float y0, float x1, float y1, int color0, int color1,
54             TileMode tile) {
55         native_instance = nativeCreate2(x0, y0, x1, y1, color0, color1, tile.nativeInt);
56         native_shader = nativePostCreate2(native_instance, x0, y0, x1, y1, color0, color1,
57                 tile.nativeInt);
58     }
59 
nativeCreate1(float x0, float y0, float x1, float y1, int colors[], float positions[], int tileMode)60 	private native int nativeCreate1(float x0, float y0, float x1, float y1,
61             int colors[], float positions[], int tileMode);
nativeCreate2(float x0, float y0, float x1, float y1, int color0, int color1, int tileMode)62 	private native int nativeCreate2(float x0, float y0, float x1, float y1,
63             int color0, int color1, int tileMode);
nativePostCreate1(int native_shader, float x0, float y0, float x1, float y1, int colors[], float positions[], int tileMode)64     private native int nativePostCreate1(int native_shader, float x0, float y0, float x1, float y1,
65             int colors[], float positions[], int tileMode);
nativePostCreate2(int native_shader, float x0, float y0, float x1, float y1, int color0, int color1, int tileMode)66     private native int nativePostCreate2(int native_shader, float x0, float y0, float x1, float y1,
67             int color0, int color1, int tileMode);
68 }
69