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.view.View; 22 import android.view.View.OnClickListener; 23 import android.widget.Button; 24 import android.widget.FrameLayout; 25 import android.widget.LinearLayout; 26 27 import com.android.gallery3d.R; 28 import com.android.gallery3d.filtershow.filters.FilterRepresentation; 29 import com.android.gallery3d.filtershow.filters.FilterRotateRepresentation; 30 import com.android.gallery3d.filtershow.imageshow.ImageRotate; 31 import com.android.gallery3d.filtershow.imageshow.MasterImage; 32 33 public class EditorRotate extends Editor implements EditorInfo { 34 public static final String TAG = EditorRotate.class.getSimpleName(); 35 public static final int ID = R.id.editorRotate; 36 ImageRotate mImageRotate; 37 38 public EditorRotate() { 39 super(ID); 40 mChangesGeometry = true; 41 } 42 43 @Override 44 public void createEditor(Context context, FrameLayout frameLayout) { 45 super.createEditor(context, frameLayout); 46 if (mImageRotate == null) { 47 mImageRotate = new ImageRotate(context); 48 } 49 mView = mImageShow = mImageRotate; 50 mImageRotate.setEditor(this); 51 } 52 53 @Override 54 public void reflectCurrentFilter() { 55 MasterImage master = MasterImage.getImage(); 56 master.setCurrentFilterRepresentation(master.getPreset() 57 .getFilterWithSerializationName(FilterRotateRepresentation.SERIALIZATION_NAME)); 58 super.reflectCurrentFilter(); 59 FilterRepresentation rep = getLocalRepresentation(); 60 if (rep == null || rep instanceof FilterRotateRepresentation) { 61 mImageRotate.setFilterRotateRepresentation((FilterRotateRepresentation) rep); 62 } else { 63 Log.w(TAG, "Could not reflect current filter, not of type: " 64 + FilterRotateRepresentation.class.getSimpleName()); 65 } 66 mImageRotate.invalidate(); 67 } 68 69 @Override 70 public void openUtilityPanel(final LinearLayout accessoryViewList) { 71 final Button button = (Button) accessoryViewList.findViewById(R.id.applyEffect); 72 button.setOnClickListener(new OnClickListener() { 73 @Override 74 public void onClick(View arg0) { 75 mImageRotate.rotate(); 76 String displayVal = mContext.getString(getTextId()) + " " 77 + mImageRotate.getLocalValue(); 78 button.setText(displayVal); 79 } 80 }); 81 } 82 83 @Override 84 public void finalApplyCalled() { 85 commitLocalRepresentation(mImageRotate.getFinalRepresentation()); 86 } 87 88 @Override 89 public int getTextId() { 90 return R.string.rotate; 91 } 92 93 @Override 94 public int getOverlayId() { 95 return R.drawable.filtershow_button_geometry_rotate; 96 } 97 98 @Override 99 public boolean getOverlayOnly() { 100 return true; 101 } 102 103 @Override 104 public boolean showsSeekBar() { 105 return false; 106 } 107 108 @Override 109 public boolean showsPopupIndicator() { 110 return false; 111 } 112 } 113