1d61a2f9fcaad0309132b6b9b666c3dc6df62fed7John Hoford/* 2d61a2f9fcaad0309132b6b9b666c3dc6df62fed7John Hoford * Copyright (C) 2013 The Android Open Source Project 3d61a2f9fcaad0309132b6b9b666c3dc6df62fed7John Hoford * 4d61a2f9fcaad0309132b6b9b666c3dc6df62fed7John Hoford * Licensed under the Apache License, Version 2.0 (the "License"); 5d61a2f9fcaad0309132b6b9b666c3dc6df62fed7John Hoford * you may not use this file except in compliance with the License. 6d61a2f9fcaad0309132b6b9b666c3dc6df62fed7John Hoford * You may obtain a copy of the License at 7d61a2f9fcaad0309132b6b9b666c3dc6df62fed7John Hoford * 8d61a2f9fcaad0309132b6b9b666c3dc6df62fed7John Hoford * http://www.apache.org/licenses/LICENSE-2.0 9d61a2f9fcaad0309132b6b9b666c3dc6df62fed7John Hoford * 10d61a2f9fcaad0309132b6b9b666c3dc6df62fed7John Hoford * Unless required by applicable law or agreed to in writing, software 11d61a2f9fcaad0309132b6b9b666c3dc6df62fed7John Hoford * distributed under the License is distributed on an "AS IS" BASIS, 12d61a2f9fcaad0309132b6b9b666c3dc6df62fed7John Hoford * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13d61a2f9fcaad0309132b6b9b666c3dc6df62fed7John Hoford * See the License for the specific language governing permissions and 14d61a2f9fcaad0309132b6b9b666c3dc6df62fed7John Hoford * limitations under the License. 15d61a2f9fcaad0309132b6b9b666c3dc6df62fed7John Hoford */ 16d61a2f9fcaad0309132b6b9b666c3dc6df62fed7John Hoford 17d61a2f9fcaad0309132b6b9b666c3dc6df62fed7John Hofordpackage com.android.gallery3d.filtershow.editors; 18d61a2f9fcaad0309132b6b9b666c3dc6df62fed7John Hoford 19d61a2f9fcaad0309132b6b9b666c3dc6df62fed7John Hofordimport android.content.Context; 20b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunkimport android.util.Log; 21d61a2f9fcaad0309132b6b9b666c3dc6df62fed7John Hofordimport android.widget.FrameLayout; 22d61a2f9fcaad0309132b6b9b666c3dc6df62fed7John Hoford 23d61a2f9fcaad0309132b6b9b666c3dc6df62fed7John Hofordimport com.android.gallery3d.R; 24b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunkimport com.android.gallery3d.filtershow.filters.FilterRepresentation; 25b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunkimport com.android.gallery3d.filtershow.filters.FilterStraightenRepresentation; 26d61a2f9fcaad0309132b6b9b666c3dc6df62fed7John Hofordimport com.android.gallery3d.filtershow.imageshow.ImageStraighten; 27b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunkimport com.android.gallery3d.filtershow.imageshow.MasterImage; 28d61a2f9fcaad0309132b6b9b666c3dc6df62fed7John Hoford 29d61a2f9fcaad0309132b6b9b666c3dc6df62fed7John Hofordpublic class EditorStraighten extends Editor implements EditorInfo { 30b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk public static final String TAG = EditorStraighten.class.getSimpleName(); 31d61a2f9fcaad0309132b6b9b666c3dc6df62fed7John Hoford public static final int ID = R.id.editorStraighten; 32d61a2f9fcaad0309132b6b9b666c3dc6df62fed7John Hoford ImageStraighten mImageStraighten; 33d61a2f9fcaad0309132b6b9b666c3dc6df62fed7John Hoford 34d61a2f9fcaad0309132b6b9b666c3dc6df62fed7John Hoford public EditorStraighten() { 35d61a2f9fcaad0309132b6b9b666c3dc6df62fed7John Hoford super(ID); 366a07dfbe03c8396cc43840a1630ea480a2cff663John Hoford mShowParameter = SHOW_VALUE_INT; 37b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk mChangesGeometry = true; 386a07dfbe03c8396cc43840a1630ea480a2cff663John Hoford } 396a07dfbe03c8396cc43840a1630ea480a2cff663John Hoford 406a07dfbe03c8396cc43840a1630ea480a2cff663John Hoford @Override 416a07dfbe03c8396cc43840a1630ea480a2cff663John Hoford public String calculateUserMessage(Context context, String effectName, Object parameterValue) { 426a07dfbe03c8396cc43840a1630ea480a2cff663John Hoford String apply = context.getString(R.string.apply_effect); 439e5656be77bc3d06e414915a99c5346873ddab80Ruben Brunk apply += " " + effectName; 4433de212ec780eaf2bc8d86908f07da33ea8dd7f2John Hoford return apply.toUpperCase(); 45d61a2f9fcaad0309132b6b9b666c3dc6df62fed7John Hoford } 46d61a2f9fcaad0309132b6b9b666c3dc6df62fed7John Hoford 47d61a2f9fcaad0309132b6b9b666c3dc6df62fed7John Hoford @Override 48d61a2f9fcaad0309132b6b9b666c3dc6df62fed7John Hoford public void createEditor(Context context, FrameLayout frameLayout) { 49d61a2f9fcaad0309132b6b9b666c3dc6df62fed7John Hoford super.createEditor(context, frameLayout); 50839d529f800adcd1ef5fcd262322bc939c2c2089nicolasroard if (mImageStraighten == null) { 51839d529f800adcd1ef5fcd262322bc939c2c2089nicolasroard mImageStraighten = new ImageStraighten(context); 52839d529f800adcd1ef5fcd262322bc939c2c2089nicolasroard } 53839d529f800adcd1ef5fcd262322bc939c2c2089nicolasroard mView = mImageShow = mImageStraighten; 54d61a2f9fcaad0309132b6b9b666c3dc6df62fed7John Hoford mImageStraighten.setEditor(this); 55b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk } 56b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk 57b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk @Override 58b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk public void reflectCurrentFilter() { 59b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk MasterImage master = MasterImage.getImage(); 60b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk master.setCurrentFilterRepresentation(master.getPreset().getFilterWithSerializationName( 61b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk FilterStraightenRepresentation.SERIALIZATION_NAME)); 62b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk super.reflectCurrentFilter(); 63b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk FilterRepresentation rep = getLocalRepresentation(); 64b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk if (rep == null || rep instanceof FilterStraightenRepresentation) { 65b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk mImageStraighten 66b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk .setFilterStraightenRepresentation((FilterStraightenRepresentation) rep); 67b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk } else { 68b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk Log.w(TAG, "Could not reflect current filter, not of type: " 69b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk + FilterStraightenRepresentation.class.getSimpleName()); 70b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk } 71b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk mImageStraighten.invalidate(); 72b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk } 73b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk 74b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk @Override 75b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk public void finalApplyCalled() { 76b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk commitLocalRepresentation(mImageStraighten.getFinalRepresentation()); 77d61a2f9fcaad0309132b6b9b666c3dc6df62fed7John Hoford } 78d61a2f9fcaad0309132b6b9b666c3dc6df62fed7John Hoford 79d61a2f9fcaad0309132b6b9b666c3dc6df62fed7John Hoford @Override 80d61a2f9fcaad0309132b6b9b666c3dc6df62fed7John Hoford public int getTextId() { 81d61a2f9fcaad0309132b6b9b666c3dc6df62fed7John Hoford return R.string.straighten; 82d61a2f9fcaad0309132b6b9b666c3dc6df62fed7John Hoford } 83d61a2f9fcaad0309132b6b9b666c3dc6df62fed7John Hoford 84d61a2f9fcaad0309132b6b9b666c3dc6df62fed7John Hoford @Override 85d61a2f9fcaad0309132b6b9b666c3dc6df62fed7John Hoford public int getOverlayId() { 86d61a2f9fcaad0309132b6b9b666c3dc6df62fed7John Hoford return R.drawable.filtershow_button_geometry_straighten; 87d61a2f9fcaad0309132b6b9b666c3dc6df62fed7John Hoford } 88d61a2f9fcaad0309132b6b9b666c3dc6df62fed7John Hoford 89d61a2f9fcaad0309132b6b9b666c3dc6df62fed7John Hoford @Override 90d61a2f9fcaad0309132b6b9b666c3dc6df62fed7John Hoford public boolean getOverlayOnly() { 91d61a2f9fcaad0309132b6b9b666c3dc6df62fed7John Hoford return true; 92d61a2f9fcaad0309132b6b9b666c3dc6df62fed7John Hoford } 9391be98c35f6c5f19d7629bb29e7261970b2f4c67nicolasroard 9491be98c35f6c5f19d7629bb29e7261970b2f4c67nicolasroard @Override 9591be98c35f6c5f19d7629bb29e7261970b2f4c67nicolasroard public boolean showsSeekBar() { 9691be98c35f6c5f19d7629bb29e7261970b2f4c67nicolasroard return false; 9791be98c35f6c5f19d7629bb29e7261970b2f4c67nicolasroard } 98be31e587c1485fb8e3d7c8b079250ffbdc26e1b9nicolasroard 99be31e587c1485fb8e3d7c8b079250ffbdc26e1b9nicolasroard @Override 100be31e587c1485fb8e3d7c8b079250ffbdc26e1b9nicolasroard public boolean showsPopupIndicator() { 101be31e587c1485fb8e3d7c8b079250ffbdc26e1b9nicolasroard return false; 102be31e587c1485fb8e3d7c8b079250ffbdc26e1b9nicolasroard } 103d61a2f9fcaad0309132b6b9b666c3dc6df62fed7John Hoford} 104