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