Color.java
Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2011 Google Inc.
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
00005  * use this file except in compliance with the License. You may obtain a copy of
00006  * the License at
00007  *
00008  * http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
00012  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
00013  * License for the specific language governing permissions and limitations under
00014  * the License.
00015  */
00016 
00017 package org.ros.android.view.visualization;
00018 
00019 import com.google.common.base.Preconditions;
00020 
00021 import javax.microedition.khronos.opengles.GL10;
00022 
00028 public class Color {
00029 
00030   private float red;
00031   private float green;
00032   private float blue;
00033   private float alpha;
00034 
00035   public static Color copyOf(Color color) {
00036     return new Color(color.red, color.green, color.blue, color.alpha);
00037   }
00038 
00039   public static Color fromHexAndAlpha(String hex, float alpha) {
00040     Preconditions.checkArgument(hex.length() == 6);
00041     float red = Integer.parseInt(hex.substring(0, 2), 16) / 255.0f;
00042     float green = Integer.parseInt(hex.substring(2, 4), 16) / 255.0f;
00043     float blue = Integer.parseInt(hex.substring(4), 16) / 255.0f;
00044     return new Color(red, green, blue, alpha);
00045   }
00046 
00047   public Color(float red, float green, float blue, float alpha) {
00048     Preconditions.checkArgument(0.0f <= red && red <= 1.0f);
00049     Preconditions.checkArgument(0.0f <= green && green <= 1.0f);
00050     Preconditions.checkArgument(0.0f <= blue && blue <= 1.0f);
00051     Preconditions.checkArgument(0.0f <= alpha && alpha <= 1.0f);
00052     this.red = red;
00053     this.green = green;
00054     this.blue = blue;
00055     this.alpha = alpha;
00056   }
00057 
00058   public void apply(GL10 gl) {
00059     gl.glColor4f(red, green, blue, alpha);
00060   }
00061 
00062   public float getRed() {
00063     return red;
00064   }
00065 
00066   public void setRed(float red) {
00067     this.red = red;
00068   }
00069 
00070   public float getGreen() {
00071     return green;
00072   }
00073 
00074   public void setGreen(float green) {
00075     this.green = green;
00076   }
00077 
00078   public float getBlue() {
00079     return blue;
00080   }
00081 
00082   public void setBlue(float blue) {
00083     this.blue = blue;
00084   }
00085 
00086   public float getAlpha() {
00087     return alpha;
00088   }
00089 
00090   public void setAlpha(float alpha) {
00091     this.alpha = alpha;
00092   }
00093 }


android_core
Author(s): Damon Kohler
autogenerated on Thu Aug 27 2015 12:11:33