Home | History | Annotate | Download | only in controller
      1 /*
      2  * Copyright (C) 2013 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 com.android.gallery3d.filtershow.controller;
     18 
     19 import android.graphics.Color;
     20 
     21 import java.util.Arrays;
     22 
     23 public class ParameterColor implements Parameter {
     24     public static String sParameterType = "ParameterColor";
     25     protected Control mControl;
     26     protected FilterView mEditor;
     27     float[] mHSVO = new float[4];
     28     String mParameterName;
     29     int mValue;
     30     public final int ID;
     31     int[] mBasColors = {
     32             Color.RED & 0x80FFFFFF,
     33             Color.GREEN & 0x80FFFFFF,
     34             Color.BLUE & 0x80FFFFFF,
     35             Color.BLACK & 0x80FFFFFF,
     36             Color.WHITE & 0x80FFFFFF
     37     };
     38 
     39     public ParameterColor(int id, int defaultColor) {
     40         ID = id;
     41         Color.colorToHSV(defaultColor, mHSVO);
     42         mHSVO[3] = ((defaultColor >> 24) & 0xFF) / (float) 255;
     43     }
     44 
     45     @Override
     46     public String getParameterType() {
     47         return sParameterType;
     48     }
     49 
     50     public void setColor(float[] hsvo) {
     51         mHSVO = hsvo;
     52         mValue = Color.HSVToColor((int) (hsvo[3] * 255), mHSVO);
     53     }
     54 
     55     public float[] getColor() {
     56         return mHSVO;
     57     }
     58 
     59     public void copyFrom(Parameter src) {
     60         if (!(src instanceof ParameterColor)) {
     61             throw new IllegalArgumentException(src.getClass().getName());
     62         }
     63         ParameterColor p = (ParameterColor) src;
     64 
     65         mValue = p.mValue;
     66         System.arraycopy(p.mHSVO, 0, mHSVO, 0, 4);
     67     }
     68 
     69     @Override
     70     public String getParameterName() {
     71         return mParameterName;
     72     }
     73 
     74     @Override
     75     public String getValueString() {
     76         return "(" + Integer.toHexString(mValue) + ")";
     77     }
     78 
     79     @Override
     80     public void setController(Control control) {
     81         mControl = control;
     82     }
     83 
     84     public int getValue() {
     85         return mValue;
     86     }
     87 
     88     public void setValue(int value) {
     89         mValue = value;
     90         Color.colorToHSV(mValue, mHSVO);
     91         mHSVO[3] = ((mValue >> 24) & 0xFF) / (float) 255;
     92     }
     93 
     94     @Override
     95     public String toString() {
     96         return getValueString();
     97     }
     98 
     99     @Override
    100     public void setFilterView(FilterView editor) {
    101         mEditor = editor;
    102     }
    103 
    104     public void copyPalletFrom(ParameterColor parameterColor) {
    105         System.arraycopy(parameterColor.mBasColors,0,mBasColors,0,mBasColors.length);
    106     }
    107 
    108     public void setColorpalette(int[] palette) {
    109         mBasColors = Arrays.copyOf(palette, palette.length);
    110     }
    111 
    112     public int[] getColorPalette() {
    113         return mBasColors;
    114     }
    115 }
    116