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;
218ab1d6661201d30063067f3b6c2fbd87e1ef9f67Ruben Brunkimport android.view.View;
228ab1d6661201d30063067f3b6c2fbd87e1ef9f67Ruben Brunkimport android.view.View.OnClickListener;
238ab1d6661201d30063067f3b6c2fbd87e1ef9f67Ruben Brunkimport android.widget.Button;
24d61a2f9fcaad0309132b6b9b666c3dc6df62fed7John Hofordimport android.widget.FrameLayout;
258ab1d6661201d30063067f3b6c2fbd87e1ef9f67Ruben Brunkimport android.widget.LinearLayout;
26d61a2f9fcaad0309132b6b9b666c3dc6df62fed7John Hoford
27d61a2f9fcaad0309132b6b9b666c3dc6df62fed7John Hofordimport com.android.gallery3d.R;
28b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunkimport com.android.gallery3d.filtershow.filters.FilterRepresentation;
29b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunkimport com.android.gallery3d.filtershow.filters.FilterRotateRepresentation;
30d61a2f9fcaad0309132b6b9b666c3dc6df62fed7John Hofordimport com.android.gallery3d.filtershow.imageshow.ImageRotate;
31b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunkimport com.android.gallery3d.filtershow.imageshow.MasterImage;
32d61a2f9fcaad0309132b6b9b666c3dc6df62fed7John Hoford
33d61a2f9fcaad0309132b6b9b666c3dc6df62fed7John Hofordpublic class EditorRotate extends Editor implements EditorInfo {
34b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk    public static final String TAG = EditorRotate.class.getSimpleName();
35d61a2f9fcaad0309132b6b9b666c3dc6df62fed7John Hoford    public static final int ID = R.id.editorRotate;
36d61a2f9fcaad0309132b6b9b666c3dc6df62fed7John Hoford    ImageRotate mImageRotate;
37d61a2f9fcaad0309132b6b9b666c3dc6df62fed7John Hoford
38d61a2f9fcaad0309132b6b9b666c3dc6df62fed7John Hoford    public EditorRotate() {
39d61a2f9fcaad0309132b6b9b666c3dc6df62fed7John Hoford        super(ID);
40b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk        mChangesGeometry = true;
41d61a2f9fcaad0309132b6b9b666c3dc6df62fed7John Hoford    }
42d61a2f9fcaad0309132b6b9b666c3dc6df62fed7John Hoford
43d61a2f9fcaad0309132b6b9b666c3dc6df62fed7John Hoford    @Override
44d61a2f9fcaad0309132b6b9b666c3dc6df62fed7John Hoford    public void createEditor(Context context, FrameLayout frameLayout) {
45d61a2f9fcaad0309132b6b9b666c3dc6df62fed7John Hoford        super.createEditor(context, frameLayout);
46839d529f800adcd1ef5fcd262322bc939c2c2089nicolasroard        if (mImageRotate == null) {
47839d529f800adcd1ef5fcd262322bc939c2c2089nicolasroard            mImageRotate = new ImageRotate(context);
48839d529f800adcd1ef5fcd262322bc939c2c2089nicolasroard        }
49839d529f800adcd1ef5fcd262322bc939c2c2089nicolasroard        mView = mImageShow = mImageRotate;
50d61a2f9fcaad0309132b6b9b666c3dc6df62fed7John Hoford        mImageRotate.setEditor(this);
51b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk    }
52b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk
53b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk    @Override
54b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk    public void reflectCurrentFilter() {
55b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk        MasterImage master = MasterImage.getImage();
56b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk        master.setCurrentFilterRepresentation(master.getPreset()
57b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk                .getFilterWithSerializationName(FilterRotateRepresentation.SERIALIZATION_NAME));
58b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk        super.reflectCurrentFilter();
59b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk        FilterRepresentation rep = getLocalRepresentation();
60b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk        if (rep == null || rep instanceof FilterRotateRepresentation) {
61b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk            mImageRotate.setFilterRotateRepresentation((FilterRotateRepresentation) rep);
62b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk        } else {
63b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk            Log.w(TAG, "Could not reflect current filter, not of type: "
64b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk                    + FilterRotateRepresentation.class.getSimpleName());
65b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk        }
66b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk        mImageRotate.invalidate();
67d61a2f9fcaad0309132b6b9b666c3dc6df62fed7John Hoford    }
68d61a2f9fcaad0309132b6b9b666c3dc6df62fed7John Hoford
69d61a2f9fcaad0309132b6b9b666c3dc6df62fed7John Hoford    @Override
708ab1d6661201d30063067f3b6c2fbd87e1ef9f67Ruben Brunk    public void openUtilityPanel(final LinearLayout accessoryViewList) {
718ab1d6661201d30063067f3b6c2fbd87e1ef9f67Ruben Brunk        final Button button = (Button) accessoryViewList.findViewById(R.id.applyEffect);
728ab1d6661201d30063067f3b6c2fbd87e1ef9f67Ruben Brunk        button.setOnClickListener(new OnClickListener() {
738ab1d6661201d30063067f3b6c2fbd87e1ef9f67Ruben Brunk            @Override
748ab1d6661201d30063067f3b6c2fbd87e1ef9f67Ruben Brunk            public void onClick(View arg0) {
758ab1d6661201d30063067f3b6c2fbd87e1ef9f67Ruben Brunk                mImageRotate.rotate();
76b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk                String displayVal = mContext.getString(getTextId()) + " "
77b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk                        + mImageRotate.getLocalValue();
78b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk                button.setText(displayVal);
798ab1d6661201d30063067f3b6c2fbd87e1ef9f67Ruben Brunk            }
808ab1d6661201d30063067f3b6c2fbd87e1ef9f67Ruben Brunk        });
818ab1d6661201d30063067f3b6c2fbd87e1ef9f67Ruben Brunk    }
828ab1d6661201d30063067f3b6c2fbd87e1ef9f67Ruben Brunk
838ab1d6661201d30063067f3b6c2fbd87e1ef9f67Ruben Brunk    @Override
84b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk    public void finalApplyCalled() {
85b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk        commitLocalRepresentation(mImageRotate.getFinalRepresentation());
86b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk    }
87b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk
88b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk    @Override
89d61a2f9fcaad0309132b6b9b666c3dc6df62fed7John Hoford    public int getTextId() {
90d61a2f9fcaad0309132b6b9b666c3dc6df62fed7John Hoford        return R.string.rotate;
91d61a2f9fcaad0309132b6b9b666c3dc6df62fed7John Hoford    }
92d61a2f9fcaad0309132b6b9b666c3dc6df62fed7John Hoford
93d61a2f9fcaad0309132b6b9b666c3dc6df62fed7John Hoford    @Override
94d61a2f9fcaad0309132b6b9b666c3dc6df62fed7John Hoford    public int getOverlayId() {
95d61a2f9fcaad0309132b6b9b666c3dc6df62fed7John Hoford        return R.drawable.filtershow_button_geometry_rotate;
96d61a2f9fcaad0309132b6b9b666c3dc6df62fed7John Hoford    }
97d61a2f9fcaad0309132b6b9b666c3dc6df62fed7John Hoford
98d61a2f9fcaad0309132b6b9b666c3dc6df62fed7John Hoford    @Override
99d61a2f9fcaad0309132b6b9b666c3dc6df62fed7John Hoford    public boolean getOverlayOnly() {
100d61a2f9fcaad0309132b6b9b666c3dc6df62fed7John Hoford        return true;
101d61a2f9fcaad0309132b6b9b666c3dc6df62fed7John Hoford    }
10291be98c35f6c5f19d7629bb29e7261970b2f4c67nicolasroard
10391be98c35f6c5f19d7629bb29e7261970b2f4c67nicolasroard    @Override
10491be98c35f6c5f19d7629bb29e7261970b2f4c67nicolasroard    public boolean showsSeekBar() {
10591be98c35f6c5f19d7629bb29e7261970b2f4c67nicolasroard        return false;
10691be98c35f6c5f19d7629bb29e7261970b2f4c67nicolasroard    }
107be31e587c1485fb8e3d7c8b079250ffbdc26e1b9nicolasroard
108be31e587c1485fb8e3d7c8b079250ffbdc26e1b9nicolasroard    @Override
109be31e587c1485fb8e3d7c8b079250ffbdc26e1b9nicolasroard    public boolean showsPopupIndicator() {
110be31e587c1485fb8e3d7c8b079250ffbdc26e1b9nicolasroard        return false;
111be31e587c1485fb8e3d7c8b079250ffbdc26e1b9nicolasroard    }
112d61a2f9fcaad0309132b6b9b666c3dc6df62fed7John Hoford}
113