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.category;
19 import android.os.Bundle;
20 import android.support.v4.app.Fragment;
21 import android.support.v4.app.FragmentTransaction;
22 import android.view.LayoutInflater;
23 import android.view.View;
24 import android.view.ViewGroup;
25 import android.widget.ImageButton;
26 import android.widget.LinearLayout;
28 import com.android.gallery3d.R;
29 import com.android.gallery3d.filtershow.FilterShowActivity;
30 import com.android.gallery3d.filtershow.state.StatePanel;
32 public class MainPanel extends Fragment {
34 private static final String LOGTAG = "MainPanel";
36 private LinearLayout mMainView;
37 private ImageButton looksButton;
38 private ImageButton bordersButton;
39 private ImageButton geometryButton;
40 private ImageButton filtersButton;
42 public static final String FRAGMENT_TAG = "MainPanel";
43 public static final int LOOKS = 0;
44 public static final int BORDERS = 1;
45 public static final int GEOMETRY = 2;
46 public static final int FILTERS = 3;
47 public static final int VERSIONS = 4;
49 private int mCurrentSelected = -1;
50 private int mPreviousToggleVersions = -1;
52 private void selection(int position, boolean value) {
54 FilterShowActivity activity = (FilterShowActivity) getActivity();
55 activity.setCurrentPanel(position);
59 looksButton.setSelected(value);
63 bordersButton.setSelected(value);
67 geometryButton.setSelected(value);
71 filtersButton.setSelected(value);
78 public void onDestroyView() {
79 super.onDestroyView();
80 if (mMainView != null) {
81 if (mMainView.getParent() != null) {
82 ViewGroup parent = (ViewGroup) mMainView.getParent();
83 parent.removeView(mMainView);
89 public View onCreateView(LayoutInflater inflater, ViewGroup container,
90 Bundle savedInstanceState) {
92 mMainView = (LinearLayout) inflater.inflate(
93 R.layout.filtershow_main_panel, null, false);
95 looksButton = (ImageButton) mMainView.findViewById(R.id.fxButton);
96 bordersButton = (ImageButton) mMainView.findViewById(R.id.borderButton);
97 geometryButton = (ImageButton) mMainView.findViewById(R.id.geometryButton);
98 filtersButton = (ImageButton) mMainView.findViewById(R.id.colorsButton);
100 looksButton.setOnClickListener(new View.OnClickListener() {
102 public void onClick(View v) {
106 bordersButton.setOnClickListener(new View.OnClickListener() {
108 public void onClick(View v) {
112 geometryButton.setOnClickListener(new View.OnClickListener() {
114 public void onClick(View v) {
118 filtersButton.setOnClickListener(new View.OnClickListener() {
120 public void onClick(View v) {
125 FilterShowActivity activity = (FilterShowActivity) getActivity();
126 showImageStatePanel(activity.isShowingImageStatePanel());
127 showPanel(activity.getCurrentPanel());
131 private boolean isRightAnimation(int newPos) {
132 if (newPos < mCurrentSelected) {
138 private void setCategoryFragment(CategoryPanel category, boolean fromRight) {
139 FragmentTransaction transaction = getChildFragmentManager().beginTransaction();
141 transaction.setCustomAnimations(R.anim.slide_in_right, R.anim.slide_out_right);
143 transaction.setCustomAnimations(R.anim.slide_in_left, R.anim.slide_out_left);
145 transaction.replace(R.id.category_panel_container, category, CategoryPanel.FRAGMENT_TAG);
146 transaction.commit();
149 public void loadCategoryLookPanel() {
150 if (mCurrentSelected == LOOKS) {
154 boolean fromRight = isRightAnimation(LOOKS);
155 selection(mCurrentSelected, false);
156 CategoryPanel categoryPanel = new CategoryPanel();
157 categoryPanel.setAdapter(LOOKS);
158 setCategoryFragment(categoryPanel, fromRight);
159 mCurrentSelected = LOOKS;
160 selection(mCurrentSelected, true);
163 public void loadCategoryBorderPanel() {
164 if (mCurrentSelected == BORDERS) {
167 boolean fromRight = isRightAnimation(BORDERS);
168 selection(mCurrentSelected, false);
169 CategoryPanel categoryPanel = new CategoryPanel();
170 categoryPanel.setAdapter(BORDERS);
171 setCategoryFragment(categoryPanel, fromRight);
172 mCurrentSelected = BORDERS;
173 selection(mCurrentSelected, true);
176 public void loadCategoryGeometryPanel() {
177 if (mCurrentSelected == GEOMETRY) {
180 boolean fromRight = isRightAnimation(GEOMETRY);
181 selection(mCurrentSelected, false);
182 CategoryPanel categoryPanel = new CategoryPanel();
183 categoryPanel.setAdapter(GEOMETRY);
184 setCategoryFragment(categoryPanel, fromRight);
185 mCurrentSelected = GEOMETRY;
186 selection(mCurrentSelected, true);
189 public void loadCategoryFiltersPanel() {
190 if (mCurrentSelected == FILTERS) {
193 boolean fromRight = isRightAnimation(FILTERS);
194 selection(mCurrentSelected, false);
195 CategoryPanel categoryPanel = new CategoryPanel();
196 categoryPanel.setAdapter(FILTERS);
197 setCategoryFragment(categoryPanel, fromRight);
198 mCurrentSelected = FILTERS;
199 selection(mCurrentSelected, true);
202 public void loadCategoryVersionsPanel() {
203 if (mCurrentSelected == VERSIONS) {
206 FilterShowActivity activity = (FilterShowActivity) getActivity();
207 activity.updateVersions();
208 boolean fromRight = isRightAnimation(VERSIONS);
209 selection(mCurrentSelected, false);
210 CategoryPanel categoryPanel = new CategoryPanel();
211 categoryPanel.setAdapter(VERSIONS);
212 setCategoryFragment(categoryPanel, fromRight);
213 mCurrentSelected = VERSIONS;
214 selection(mCurrentSelected, true);
217 public void showPanel(int currentPanel) {
218 switch (currentPanel) {
220 loadCategoryLookPanel();
224 loadCategoryBorderPanel();
228 loadCategoryGeometryPanel();
232 loadCategoryFiltersPanel();
236 loadCategoryVersionsPanel();
242 public void setToggleVersionsPanelButton(ImageButton button) {
243 if (button == null) {
246 button.setOnClickListener(new View.OnClickListener() {
248 public void onClick(View v) {
249 if (mCurrentSelected == VERSIONS) {
250 showPanel(mPreviousToggleVersions);
252 mPreviousToggleVersions = mCurrentSelected;
259 public void showImageStatePanel(boolean show) {
260 View container = mMainView.findViewById(R.id.state_panel_container);
261 FragmentTransaction transaction = null;
262 if (container == null) {
263 FilterShowActivity activity = (FilterShowActivity) getActivity();
264 container = activity.getMainStatePanelContainer(R.id.state_panel_container);
266 transaction = getChildFragmentManager().beginTransaction();
268 if (container == null) {
271 transaction = getFragmentManager().beginTransaction();
273 int currentPanel = mCurrentSelected;
275 container.setVisibility(View.VISIBLE);
276 StatePanel statePanel = new StatePanel();
277 statePanel.setMainPanel(this);
278 FilterShowActivity activity = (FilterShowActivity) getActivity();
279 activity.updateVersions();
280 transaction.replace(R.id.state_panel_container, statePanel, StatePanel.FRAGMENT_TAG);
282 container.setVisibility(View.GONE);
283 Fragment statePanel = getChildFragmentManager().findFragmentByTag(StatePanel.FRAGMENT_TAG);
284 if (statePanel != null) {
285 transaction.remove(statePanel);
287 if (currentPanel == VERSIONS) {
288 currentPanel = LOOKS;
291 mCurrentSelected = -1;
292 showPanel(currentPanel);
293 transaction.commit();