OSDN Git Service

Refactoring Geometry handling.
[android-x86/packages-apps-Gallery2.git] / src / com / android / gallery3d / filtershow / editors / EditorStraighten.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.editors;
18
19 import android.content.Context;
20 import android.util.Log;
21 import android.widget.FrameLayout;
22
23 import com.android.gallery3d.R;
24 import com.android.gallery3d.filtershow.filters.FilterRepresentation;
25 import com.android.gallery3d.filtershow.filters.FilterStraightenRepresentation;
26 import com.android.gallery3d.filtershow.imageshow.ImageStraighten;
27 import com.android.gallery3d.filtershow.imageshow.MasterImage;
28
29 public class EditorStraighten extends Editor implements EditorInfo {
30     public static final String TAG = EditorStraighten.class.getSimpleName();
31     public static final int ID = R.id.editorStraighten;
32     ImageStraighten mImageStraighten;
33
34     public EditorStraighten() {
35         super(ID);
36         mShowParameter = SHOW_VALUE_INT;
37         mChangesGeometry = true;
38     }
39
40     @Override
41     public String calculateUserMessage(Context context, String effectName, Object parameterValue) {
42         String apply = context.getString(R.string.apply_effect);
43         apply += " " + effectName;
44         return apply.toUpperCase();
45     }
46
47     @Override
48     public void createEditor(Context context, FrameLayout frameLayout) {
49         super.createEditor(context, frameLayout);
50         if (mImageStraighten == null) {
51             mImageStraighten = new ImageStraighten(context);
52         }
53         mView = mImageShow = mImageStraighten;
54         mImageStraighten.setEditor(this);
55     }
56
57     @Override
58     public void reflectCurrentFilter() {
59         MasterImage master = MasterImage.getImage();
60         master.setCurrentFilterRepresentation(master.getPreset().getFilterWithSerializationName(
61                 FilterStraightenRepresentation.SERIALIZATION_NAME));
62         super.reflectCurrentFilter();
63         FilterRepresentation rep = getLocalRepresentation();
64         if (rep == null || rep instanceof FilterStraightenRepresentation) {
65             mImageStraighten
66                     .setFilterStraightenRepresentation((FilterStraightenRepresentation) rep);
67         } else {
68             Log.w(TAG, "Could not reflect current filter, not of type: "
69                     + FilterStraightenRepresentation.class.getSimpleName());
70         }
71         mImageStraighten.invalidate();
72     }
73
74     @Override
75     public void finalApplyCalled() {
76         commitLocalRepresentation(mImageStraighten.getFinalRepresentation());
77     }
78
79     @Override
80     public int getTextId() {
81         return R.string.straighten;
82     }
83
84     @Override
85     public int getOverlayId() {
86         return R.drawable.filtershow_button_geometry_straighten;
87     }
88
89     @Override
90     public boolean getOverlayOnly() {
91         return true;
92     }
93
94     @Override
95     public boolean showsSeekBar() {
96         return false;
97     }
98
99     @Override
100     public boolean showsPopupIndicator() {
101         return false;
102     }
103 }