Home | History | Annotate | Download | only in filters
      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.filters;
     18 
     19 import com.android.gallery3d.R;
     20 import com.android.gallery3d.filtershow.editors.ImageOnlyEditor;
     21 
     22 public class FilterImageBorderRepresentation extends FilterRepresentation {
     23     private int mDrawableResource = 0;
     24 
     25     public FilterImageBorderRepresentation(int drawableResource) {
     26         super("ImageBorder");
     27         setFilterClass(ImageFilterBorder.class);
     28         mDrawableResource = drawableResource;
     29         setFilterType(FilterRepresentation.TYPE_BORDER);
     30         setTextId(R.string.borders);
     31         setEditorId(ImageOnlyEditor.ID);
     32         setShowParameterValue(false);
     33     }
     34 
     35     public String toString() {
     36         return "FilterBorder: " + getName();
     37     }
     38 
     39     @Override
     40     public FilterRepresentation copy() {
     41         FilterImageBorderRepresentation representation =
     42                 new FilterImageBorderRepresentation(mDrawableResource);
     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     public void useParametersFrom(FilterRepresentation a) {
     54         if (a instanceof FilterImageBorderRepresentation) {
     55             FilterImageBorderRepresentation representation = (FilterImageBorderRepresentation) a;
     56             setName(representation.getName());
     57             setDrawableResource(representation.getDrawableResource());
     58         }
     59     }
     60 
     61     @Override
     62     public boolean equals(FilterRepresentation representation) {
     63         if (!super.equals(representation)) {
     64             return false;
     65         }
     66         if (representation instanceof FilterImageBorderRepresentation) {
     67             FilterImageBorderRepresentation border = (FilterImageBorderRepresentation) representation;
     68             if (border.mDrawableResource == mDrawableResource) {
     69                 return true;
     70             }
     71         }
     72         return false;
     73     }
     74 
     75     @Override
     76     public int getTextId() {
     77         return R.string.none;
     78     }
     79 
     80     public boolean allowsSingleInstanceOnly() {
     81         return true;
     82     }
     83 
     84     public int getDrawableResource() {
     85         return mDrawableResource;
     86     }
     87 
     88     public void setDrawableResource(int drawableResource) {
     89         mDrawableResource = drawableResource;
     90     }
     91 }
     92