Home | History | Annotate | Download | only in filters
      1 /*
      2  * Copyright (C) 2012 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.filters;
     18 
     19 import com.android.gallery3d.R;
     20 import com.android.gallery3d.filtershow.editors.EditorTinyPlanet;
     21 
     22 public class FilterTinyPlanetRepresentation extends FilterBasicRepresentation {
     23     private static final String SERIALIZATION_NAME = "TINYPLANET";
     24     private static final String LOGTAG = "FilterTinyPlanetRepresentation";
     25     private static final String SERIAL_ANGLE = "Angle";
     26     private float mAngle = 0;
     27 
     28     public FilterTinyPlanetRepresentation() {
     29         super("TinyPlanet", 0, 50, 100);
     30         setSerializationName(SERIALIZATION_NAME);
     31         setShowParameterValue(true);
     32         setFilterClass(ImageFilterTinyPlanet.class);
     33         setFilterType(FilterRepresentation.TYPE_TINYPLANET);
     34         setTextId(R.string.tinyplanet);
     35         setEditorId(EditorTinyPlanet.ID);
     36         setMinimum(1);
     37         setSupportsPartialRendering(false);
     38     }
     39 
     40     @Override
     41     public FilterRepresentation copy() {
     42         FilterTinyPlanetRepresentation representation = new FilterTinyPlanetRepresentation();
     43         copyAllParameters(representation);
     44         return representation;
     45     }
     46 
     47     @Override
     48     protected void copyAllParameters(FilterRepresentation representation) {
     49         super.copyAllParameters(representation);
     50         representation.useParametersFrom(this);
     51     }
     52 
     53     @Override
     54     public void useParametersFrom(FilterRepresentation a) {
     55         FilterTinyPlanetRepresentation representation = (FilterTinyPlanetRepresentation) a;
     56         super.useParametersFrom(a);
     57         mAngle = representation.mAngle;
     58         setZoom(representation.getZoom());
     59     }
     60 
     61     public void setAngle(float angle) {
     62         mAngle = angle;
     63     }
     64 
     65     public float getAngle() {
     66         return mAngle;
     67     }
     68 
     69     public int getZoom() {
     70         return getValue();
     71     }
     72 
     73     public void setZoom(int zoom) {
     74         setValue(zoom);
     75     }
     76 
     77     public boolean isNil() {
     78         // TinyPlanet always has an effect
     79         return false;
     80     }
     81 
     82     public boolean equals(FilterRepresentation representation) {
     83         if (!super.equals(representation)) {
     84             return false;
     85         }
     86         if (mAngle == ((FilterTinyPlanetRepresentation) representation).mAngle) {
     87             return true;
     88         }
     89         return false;
     90     }
     91 
     92     @Override
     93     public String[][] serializeRepresentation() {
     94         String[][] ret = {
     95                 {SERIAL_NAME  , getName() },
     96                 {SERIAL_VALUE , Integer.toString(getValue())},
     97                 {SERIAL_ANGLE , Float.toString(mAngle)}};
     98         return ret;
     99     }
    100 
    101     @Override
    102     public void deSerializeRepresentation(String[][] rep) {
    103         super.deSerializeRepresentation(rep);
    104         for (int i = 0; i < rep.length; i++) {
    105             if (SERIAL_VALUE.equals(rep[i][0])) {
    106                 setValue(Integer.parseInt(rep[i][1]));
    107             } else if (SERIAL_ANGLE.equals(rep[i][0])) {
    108                 setAngle(Float.parseFloat(rep[i][1]));
    109             }
    110         }
    111     }
    112 }
    113