Home | History | Annotate | Download | only in editors
      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.FilterMirrorRepresentation;
     29 import com.android.gallery3d.filtershow.filters.FilterRepresentation;
     30 import com.android.gallery3d.filtershow.imageshow.ImageMirror;
     31 import com.android.gallery3d.filtershow.imageshow.MasterImage;
     32 
     33 public class EditorMirror extends Editor implements EditorInfo {
     34     public static final String TAG = EditorMirror.class.getSimpleName();
     35     public static final int ID = R.id.editorFlip;
     36     ImageMirror mImageMirror;
     37 
     38     public EditorMirror() {
     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 (mImageMirror == null) {
     47             mImageMirror = new ImageMirror(context);
     48         }
     49         mView = mImageShow = mImageMirror;
     50         mImageMirror.setEditor(this);
     51     }
     52 
     53     @Override
     54     public void reflectCurrentFilter() {
     55         MasterImage master = MasterImage.getImage();
     56         master.setCurrentFilterRepresentation(master.getPreset()
     57                 .getFilterWithSerializationName(FilterMirrorRepresentation.SERIALIZATION_NAME));
     58         super.reflectCurrentFilter();
     59         FilterRepresentation rep = getLocalRepresentation();
     60         if (rep == null || rep instanceof FilterMirrorRepresentation) {
     61             mImageMirror.setFilterMirrorRepresentation((FilterMirrorRepresentation) rep);
     62         } else {
     63             Log.w(TAG, "Could not reflect current filter, not of type: "
     64                     + FilterMirrorRepresentation.class.getSimpleName());
     65         }
     66         mImageMirror.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                 mImageMirror.flip();
     76             }
     77         });
     78     }
     79 
     80     @Override
     81     public void finalApplyCalled() {
     82         commitLocalRepresentation(mImageMirror.getFinalRepresentation());
     83     }
     84 
     85     @Override
     86     public int getTextId() {
     87         return R.string.mirror;
     88     }
     89 
     90     @Override
     91     public int getOverlayId() {
     92         return R.drawable.filtershow_button_geometry_flip;
     93     }
     94 
     95     @Override
     96     public boolean getOverlayOnly() {
     97         return true;
     98     }
     99 
    100     @Override
    101     public boolean showsSeekBar() {
    102         return false;
    103     }
    104 
    105     @Override
    106     public boolean showsPopupIndicator() {
    107         return false;
    108     }
    109 }
    110