2 * Copyright (C) 2013 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package com.android.gallery3d.filtershow.editors;
19 import android.app.Activity;
20 import android.os.Bundle;
21 import android.support.v4.app.Fragment;
22 import android.support.v4.app.FragmentTransaction;
23 import android.view.LayoutInflater;
24 import android.view.View;
25 import android.view.ViewGroup;
26 import android.widget.Button;
27 import android.widget.ImageButton;
28 import android.widget.LinearLayout;
29 import com.android.gallery3d.R;
30 import com.android.gallery3d.filtershow.FilterShowActivity;
31 import com.android.gallery3d.filtershow.history.HistoryManager;
32 import com.android.gallery3d.filtershow.category.MainPanel;
33 import com.android.gallery3d.filtershow.imageshow.MasterImage;
34 import com.android.gallery3d.filtershow.state.StatePanel;
36 public class EditorPanel extends Fragment {
38 private static final String LOGTAG = "EditorPanel";
40 private LinearLayout mMainView;
41 private Editor mEditor;
42 private int mEditorID;
44 public void setEditor(int editor) {
49 public void onAttach(Activity activity) {
50 super.onAttach(activity);
51 FilterShowActivity filterShowActivity = (FilterShowActivity) activity;
52 mEditor = filterShowActivity.getEditor(mEditorID);
55 public void cancelCurrentFilter() {
56 MasterImage masterImage = MasterImage.getImage();
57 HistoryManager adapter = masterImage.getHistory();
59 int position = adapter.undo();
60 masterImage.onHistoryItemClick(position);
61 ((FilterShowActivity)getActivity()).invalidateViews();
65 public View onCreateView(LayoutInflater inflater, ViewGroup container,
66 Bundle savedInstanceState) {
67 FilterShowActivity activity = (FilterShowActivity) getActivity();
68 if (mMainView != null) {
69 if (mMainView.getParent() != null) {
70 ViewGroup parent = (ViewGroup) mMainView.getParent();
71 parent.removeView(mMainView);
73 showImageStatePanel(activity.isShowingImageStatePanel());
76 mMainView = (LinearLayout) inflater.inflate(R.layout.filtershow_editor_panel, null);
78 View actionControl = mMainView.findViewById(R.id.panelAccessoryViewList);
79 View editControl = mMainView.findViewById(R.id.controlArea);
80 ImageButton cancelButton = (ImageButton) mMainView.findViewById(R.id.cancelFilter);
81 ImageButton applyButton = (ImageButton) mMainView.findViewById(R.id.applyFilter);
82 Button editTitle = (Button) mMainView.findViewById(R.id.applyEffect);
83 cancelButton.setOnClickListener(new View.OnClickListener() {
85 public void onClick(View v) {
86 cancelCurrentFilter();
87 FilterShowActivity activity = (FilterShowActivity) getActivity();
88 activity.backToMain();
92 Button toggleState = (Button) mMainView.findViewById(R.id.toggle_state);
93 mEditor = activity.getEditor(mEditorID);
94 if (mEditor != null) {
95 mEditor.setUpEditorUI(actionControl, editControl, editTitle, toggleState);
96 mEditor.reflectCurrentFilter();
97 if (mEditor.useUtilityPanel()) {
98 mEditor.openUtilityPanel((LinearLayout) actionControl);
101 applyButton.setOnClickListener(new View.OnClickListener() {
103 public void onClick(View v) {
104 FilterShowActivity activity = (FilterShowActivity) getActivity();
105 mEditor.finalApplyCalled();
106 activity.backToMain();
110 showImageStatePanel(activity.isShowingImageStatePanel());
115 public void onDetach() {
116 if (mEditor != null) {
122 public void showImageStatePanel(boolean show) {
123 View container = mMainView.findViewById(R.id.state_panel_container);
124 FragmentTransaction transaction = null;
125 boolean child = false;
126 if (container == null) {
127 FilterShowActivity activity = (FilterShowActivity) getActivity();
128 container = activity.getMainStatePanelContainer(R.id.state_panel_container);
130 transaction = getChildFragmentManager().beginTransaction();
133 if (container == null) {
136 transaction = getFragmentManager().beginTransaction();
138 Fragment panel = getActivity().getSupportFragmentManager().findFragmentByTag(
139 MainPanel.FRAGMENT_TAG);
140 if (panel == null || panel instanceof MainPanel) {
141 transaction.setCustomAnimations(android.R.anim.fade_in, android.R.anim.fade_out);
144 container.setVisibility(View.VISIBLE);
145 StatePanel statePanel = new StatePanel();
146 transaction.replace(R.id.state_panel_container, statePanel, StatePanel.FRAGMENT_TAG);
148 Fragment statePanel = getChildFragmentManager().findFragmentByTag(StatePanel.FRAGMENT_TAG);
150 statePanel = getFragmentManager().findFragmentByTag(StatePanel.FRAGMENT_TAG);
152 if (statePanel != null) {
153 transaction.remove(statePanel);
156 transaction.commit();