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 android.content.Context;
     20 import android.content.res.Resources;
     21 import android.graphics.Color;
     22 
     23 import com.android.gallery3d.R;
     24 
     25 import java.util.HashMap;
     26 import java.util.Vector;
     27 
     28 public class FiltersManager extends BaseFiltersManager {
     29     private static FiltersManager sInstance = null;
     30     private static FiltersManager sPreviewInstance = null;
     31     private static FiltersManager sHighresInstance = null;
     32     private static int mImageBorderSize = 4; // in percent
     33     public FiltersManager() {
     34         init();
     35     }
     36 
     37     public static FiltersManager getPreviewManager() {
     38         if (sPreviewInstance == null) {
     39             sPreviewInstance = new FiltersManager();
     40         }
     41         return sPreviewInstance;
     42     }
     43 
     44     public static FiltersManager getManager() {
     45         if (sInstance == null) {
     46             sInstance = new FiltersManager();
     47         }
     48         return sInstance;
     49     }
     50 
     51     @Override
     52     public void addBorders(Context context, Vector<FilterRepresentation> representations) {
     53         // Regular borders
     54         representations.add(new FilterImageBorderRepresentation(R.drawable.filtershow_border_4x5));
     55         representations.add(
     56                 new FilterImageBorderRepresentation(R.drawable.filtershow_border_brush));
     57         representations.add(
     58                 new FilterImageBorderRepresentation(R.drawable.filtershow_border_grunge));
     59         representations.add(
     60                 new FilterImageBorderRepresentation(R.drawable.filtershow_border_sumi_e));
     61         representations.add(new FilterImageBorderRepresentation(R.drawable.filtershow_border_tape));
     62         representations.add(new FilterColorBorderRepresentation(Color.BLACK, mImageBorderSize, 0));
     63         representations.add(new FilterColorBorderRepresentation(Color.BLACK, mImageBorderSize,
     64                 mImageBorderSize));
     65         representations.add(new FilterColorBorderRepresentation(Color.WHITE, mImageBorderSize, 0));
     66         representations.add(new FilterColorBorderRepresentation(Color.WHITE, mImageBorderSize,
     67                 mImageBorderSize));
     68         int creamColor = Color.argb(255, 237, 237, 227);
     69         representations.add(new FilterColorBorderRepresentation(creamColor, mImageBorderSize, 0));
     70         representations.add(new FilterColorBorderRepresentation(creamColor, mImageBorderSize,
     71                 mImageBorderSize));
     72     }
     73 
     74     public static FiltersManager getHighresManager() {
     75         if (sHighresInstance == null) {
     76             sHighresInstance = new FiltersManager();
     77         }
     78         return sHighresInstance;
     79     }
     80 
     81     public static void reset() {
     82         sInstance = null;
     83         sPreviewInstance = null;
     84         sHighresInstance = null;
     85     }
     86 
     87     public static void setResources(Resources resources) {
     88         FiltersManager.getManager().setFilterResources(resources);
     89         FiltersManager.getPreviewManager().setFilterResources(resources);
     90         FiltersManager.getHighresManager().setFilterResources(resources);
     91     }
     92 }
     93