2 * Copyright (C) 2013 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package com.android.gallery3d.filtershow.editors;
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;
28 import com.android.gallery3d.R;
29 import com.android.gallery3d.filtershow.crop.CropExtras;
30 import com.android.gallery3d.filtershow.imageshow.ImageCrop;
32 public class EditorCrop extends Editor implements EditorInfo {
33 public static final int ID = R.id.editorCrop;
34 private static final String LOGTAG = "EditorCrop";
37 private String mAspectString = "";
38 private boolean mCropActionFlag = false;
39 private CropExtras mCropExtras = null;
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);
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);
64 mImageCrop.setExtras(null);
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() {
75 public void onClick(View arg0) {
76 showPopupMenu(accessoryViewList);
81 private void showPopupMenu(LinearLayout accessoryViewList) {
82 final Button button = (Button) accessoryViewList.findViewById(
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() {
92 public boolean onMenuItemClick(MenuItem item) {
93 mImageCrop.setAspectButton(item.getItemId());
101 public boolean showsSeekBar() {
106 public int getTextId() {
107 return R.string.crop;
111 public int getOverlayId() {
112 return R.drawable.filtershow_button_geometry_crop;
116 public boolean getOverlayOnly() {
120 public void setExtras(CropExtras cropExtras) {
121 mCropExtras = cropExtras;
124 public void setAspectString(String s) {
128 public void setCropActionFlag(boolean b) {