• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2008 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 import java.awt.GradientPaint;
20 import java.awt.Color;
21 import java.awt.Paint;
22 
23 public class LinearGradient extends Shader {
24 
25     private GradientPaint mGradientPaint;
26 
27     /** Create a shader that draws a linear gradient along a line.
28         @param x0           The x-coordinate for the start of the gradient line
29         @param y0           The y-coordinate for the start of the gradient line
30         @param x1           The x-coordinate for the end of the gradient line
31         @param y1           The y-coordinate for the end of the gradient line
32         @param  colors      The colors to be distributed along the gradient line
33         @param  positions   May be null. The relative positions [0..1] of
34                             each corresponding color in the colors array. If this is null,
35                             the the colors are distributed evenly along the gradient line.
36         @param  tile        The Shader tiling mode
37     */
LinearGradient(float x0, float y0, float x1, float y1, int colors[], float positions[], TileMode tile)38     public LinearGradient(float x0, float y0, float x1, float y1,
39                           int colors[], float positions[], TileMode tile) {
40         if (colors.length < 2) {
41             throw new IllegalArgumentException("needs >= 2 number of colors");
42         }
43         if (positions != null && colors.length != positions.length) {
44             throw new IllegalArgumentException("color and position arrays must be of equal length");
45         }
46 
47         // FIXME implement multi color linear gradient
48     }
49 
50     /** Create a shader that draws a linear gradient along a line.
51         @param x0       The x-coordinate for the start of the gradient line
52         @param y0       The y-coordinate for the start of the gradient line
53         @param x1       The x-coordinate for the end of the gradient line
54         @param y1       The y-coordinate for the end of the gradient line
55         @param  color0  The color at the start of the gradient line.
56         @param  color1  The color at the end of the gradient line.
57         @param  tile    The Shader tiling mode
58     */
LinearGradient(float x0, float y0, float x1, float y1, int color0, int color1, TileMode tile)59     public LinearGradient(float x0, float y0, float x1, float y1,
60                           int color0, int color1, TileMode tile) {
61         mGradientPaint = new GradientPaint(x0, y0, new Color(color0, true /* hasalpha */),
62                 x1,y1, new Color(color1, true /* hasalpha */), tile != TileMode.CLAMP);
63     }
64 
65     //---------- Custom Methods
66 
getPaint()67     public Paint getPaint() {
68         return mGradientPaint;
69     }
70 }
71 
72