OSDN Git Service

Add background processing service
[android-x86/packages-apps-Gallery2.git] / src_pd / com / android / gallery3d / filtershow / filters / FiltersManager.java
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 public class FiltersManager extends BaseFiltersManager {
26     private static FiltersManager sInstance = null;
27     private static FiltersManager sPreviewInstance = null;
28     private static FiltersManager sHighresInstance = null;
29     private static int mImageBorderSize = 4; // in percent
30     public FiltersManager() {
31         init();
32     }
33
34     public static FiltersManager getPreviewManager() {
35         if (sPreviewInstance == null) {
36             sPreviewInstance = new FiltersManager();
37         }
38         return sPreviewInstance;
39     }
40
41     public static FiltersManager getManager() {
42         if (sInstance == null) {
43             sInstance = new FiltersManager();
44         }
45         return sInstance;
46     }
47
48     @Override
49     public void addBorders(Context context) {
50
51         // Do not localize
52         String[] serializationNames = {
53                 "FRAME_4X5",
54                 "FRAME_BRUSH",
55                 "FRAME_GRUNGE",
56                 "FRAME_SUMI_E",
57                 "FRAME_TAPE",
58                 "FRAME_BLACK",
59                 "FRAME_BLACK_ROUNDED",
60                 "FRAME_WHITE",
61                 "FRAME_WHITE_ROUNDED",
62                 "FRAME_CREAM",
63                 "FRAME_CREAM_ROUNDED"
64         };
65
66         // The "no border" implementation
67         int i = 0;
68         FilterRepresentation rep = new FilterImageBorderRepresentation(0);
69         mBorders.add(rep);
70
71         // Regular borders
72         rep = new FilterImageBorderRepresentation(R.drawable.filtershow_border_4x5);
73         rep.setSerializationName(serializationNames[i++]);
74         mBorders.add(rep);
75
76         rep = new FilterImageBorderRepresentation(R.drawable.filtershow_border_brush);
77         rep.setSerializationName(serializationNames[i++]);
78         mBorders.add(rep);
79
80         rep = new FilterImageBorderRepresentation(R.drawable.filtershow_border_grunge);
81         rep.setSerializationName(serializationNames[i++]);
82         mBorders.add(rep);
83
84         rep = new FilterImageBorderRepresentation(R.drawable.filtershow_border_sumi_e);
85         rep.setSerializationName(serializationNames[i++]);
86         mBorders.add(rep);
87
88         rep = new FilterImageBorderRepresentation(R.drawable.filtershow_border_tape);
89         rep.setSerializationName(serializationNames[i++]);
90         mBorders.add(rep);
91
92         rep = new FilterColorBorderRepresentation(Color.BLACK, mImageBorderSize, 0);
93         rep.setSerializationName(serializationNames[i++]);
94         mBorders.add(rep);
95
96         rep = new FilterColorBorderRepresentation(Color.BLACK, mImageBorderSize,
97                 mImageBorderSize);
98         rep.setSerializationName(serializationNames[i++]);
99         mBorders.add(rep);
100
101         rep = new FilterColorBorderRepresentation(Color.WHITE, mImageBorderSize, 0);
102         rep.setSerializationName(serializationNames[i++]);
103         mBorders.add(rep);
104
105         rep = new FilterColorBorderRepresentation(Color.WHITE, mImageBorderSize,
106                 mImageBorderSize);
107         rep.setSerializationName(serializationNames[i++]);
108         mBorders.add(rep);
109
110         int creamColor = Color.argb(255, 237, 237, 227);
111         rep = new FilterColorBorderRepresentation(creamColor, mImageBorderSize, 0);
112         rep.setSerializationName(serializationNames[i++]);
113         mBorders.add(rep);
114
115         rep = new FilterColorBorderRepresentation(creamColor, mImageBorderSize,
116                 mImageBorderSize);
117         rep.setSerializationName(serializationNames[i++]);
118         mBorders.add(rep);
119     }
120
121     public static FiltersManager getHighresManager() {
122         if (sHighresInstance == null) {
123             sHighresInstance = new FiltersManager();
124         }
125         return sHighresInstance;
126     }
127
128     public static void reset() {
129         sInstance = null;
130         sPreviewInstance = null;
131         sHighresInstance = null;
132     }
133
134     public static void setResources(Resources resources) {
135         FiltersManager.getManager().setFilterResources(resources);
136         FiltersManager.getPreviewManager().setFilterResources(resources);
137         FiltersManager.getHighresManager().setFilterResources(resources);
138     }
139 }