OSDN Git Service

Refactoring ImageLoader.
[android-x86/packages-apps-Gallery2.git] / src / com / android / gallery3d / filtershow / editors / EditorCrop.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.view.MenuItem;
21 import android.view.View;
22 import android.view.View.OnClickListener;
23 import android.widget.Button;
24 import android.widget.FrameLayout;
25 import android.widget.LinearLayout;
26 import android.widget.PopupMenu;
27
28 import com.android.gallery3d.R;
29 import com.android.gallery3d.filtershow.crop.CropExtras;
30 import com.android.gallery3d.filtershow.imageshow.ImageCrop;
31
32 public class EditorCrop extends Editor implements EditorInfo {
33     public static final int ID = R.id.editorCrop;
34     private static final String LOGTAG = "EditorCrop";
35
36     ImageCrop mImageCrop;
37     private String mAspectString = "";
38     private boolean mCropActionFlag = false;
39     private CropExtras mCropExtras = null;
40
41     public EditorCrop() {
42         super(ID);
43     }
44
45     @Override
46     public void createEditor(Context context, FrameLayout frameLayout) {
47         super.createEditor(context, frameLayout);
48         if (mImageCrop == null) {
49             // TODO: need this for now because there's extra state in ImageCrop.
50             // all the state instead should be in the representation.
51             // Same thing for the other geometry editors.
52             mImageCrop = new ImageCrop(context);
53         }
54         mView = mImageShow = mImageCrop;
55         mImageCrop.bindAsImageLoadListener();
56         mImageCrop.setEditor(this);
57         mImageCrop.syncLocalToMasterGeometry();
58         mImageCrop.setCropActionFlag(mCropActionFlag);
59         if (mCropActionFlag) {
60             mImageCrop.setExtras(mCropExtras);
61             mImageCrop.setAspectString(mAspectString);
62             mImageCrop.clear();
63         } else {
64             mImageCrop.setExtras(null);
65         }
66     }
67
68     @Override
69     public void openUtilityPanel(final LinearLayout accessoryViewList) {
70         Button view = (Button) accessoryViewList.findViewById(R.id.applyEffect);
71         view.setText(mContext.getString(R.string.crop));
72         view.setOnClickListener(new OnClickListener() {
73
74                 @Override
75             public void onClick(View arg0) {
76                 showPopupMenu(accessoryViewList);
77             }
78         });
79     }
80
81     private void showPopupMenu(LinearLayout accessoryViewList) {
82         final Button button = (Button) accessoryViewList.findViewById(
83                 R.id.applyEffect);
84         if (button == null) {
85             return;
86         }
87         final PopupMenu popupMenu = new PopupMenu(mImageShow.getActivity(), button);
88         popupMenu.getMenuInflater().inflate(R.menu.filtershow_menu_crop, popupMenu.getMenu());
89         popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
90
91             @Override
92             public boolean onMenuItemClick(MenuItem item) {
93                 mImageCrop.setAspectButton(item.getItemId());
94                 return true;
95             }
96         });
97         popupMenu.show();
98     }
99
100     @Override
101     public boolean showsSeekBar() {
102         return false;
103     }
104
105     @Override
106     public int getTextId() {
107         return R.string.crop;
108     }
109
110     @Override
111     public int getOverlayId() {
112         return R.drawable.filtershow_button_geometry_crop;
113     }
114
115     @Override
116     public boolean getOverlayOnly() {
117         return true;
118     }
119
120     public void setExtras(CropExtras cropExtras) {
121         mCropExtras = cropExtras;
122     }
123
124     public void setAspectString(String s) {
125         mAspectString = s;
126     }
127
128     public void setCropActionFlag(boolean b) {
129         mCropActionFlag = b;
130     }
131
132 }