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(boolean force) {
150 if (!force && mCurrentSelected == LOOKS) {
153 boolean fromRight = isRightAnimation(LOOKS);
154 selection(mCurrentSelected, false);
155 CategoryPanel categoryPanel = new CategoryPanel();
156 categoryPanel.setAdapter(LOOKS);
157 setCategoryFragment(categoryPanel, fromRight);
158 mCurrentSelected = LOOKS;
159 selection(mCurrentSelected, true);
162 public void loadCategoryBorderPanel() {
163 if (mCurrentSelected == BORDERS) {
166 boolean fromRight = isRightAnimation(BORDERS);
167 selection(mCurrentSelected, false);
168 CategoryPanel categoryPanel = new CategoryPanel();
169 categoryPanel.setAdapter(BORDERS);
170 setCategoryFragment(categoryPanel, fromRight);
171 mCurrentSelected = BORDERS;
172 selection(mCurrentSelected, true);
175 public void loadCategoryGeometryPanel() {
176 if (mCurrentSelected == GEOMETRY) {
179 boolean fromRight = isRightAnimation(GEOMETRY);
180 selection(mCurrentSelected, false);
181 CategoryPanel categoryPanel = new CategoryPanel();
182 categoryPanel.setAdapter(GEOMETRY);
183 setCategoryFragment(categoryPanel, fromRight);
184 mCurrentSelected = GEOMETRY;
185 selection(mCurrentSelected, true);
188 public void loadCategoryFiltersPanel() {
189 if (mCurrentSelected == FILTERS) {
192 boolean fromRight = isRightAnimation(FILTERS);
193 selection(mCurrentSelected, false);
194 CategoryPanel categoryPanel = new CategoryPanel();
195 categoryPanel.setAdapter(FILTERS);
196 setCategoryFragment(categoryPanel, fromRight);
197 mCurrentSelected = FILTERS;
198 selection(mCurrentSelected, true);
201 public void loadCategoryVersionsPanel() {
202 if (mCurrentSelected == VERSIONS) {
205 FilterShowActivity activity = (FilterShowActivity) getActivity();
206 activity.updateVersions();
207 boolean fromRight = isRightAnimation(VERSIONS);
208 selection(mCurrentSelected, false);
209 CategoryPanel categoryPanel = new CategoryPanel();
210 categoryPanel.setAdapter(VERSIONS);
211 setCategoryFragment(categoryPanel, fromRight);
212 mCurrentSelected = VERSIONS;
213 selection(mCurrentSelected, true);
216 public void showPanel(int currentPanel) {
217 switch (currentPanel) {
219 loadCategoryLookPanel(false);
223 loadCategoryBorderPanel();
227 loadCategoryGeometryPanel();
231 loadCategoryFiltersPanel();
235 loadCategoryVersionsPanel();
241 public void setToggleVersionsPanelButton(ImageButton button) {
242 if (button == null) {
245 button.setOnClickListener(new View.OnClickListener() {
247 public void onClick(View v) {
248 if (mCurrentSelected == VERSIONS) {
249 showPanel(mPreviousToggleVersions);
251 mPreviousToggleVersions = mCurrentSelected;
258 public void showImageStatePanel(boolean show) {
259 View container = mMainView.findViewById(R.id.state_panel_container);
260 FragmentTransaction transaction = null;
261 if (container == null) {
262 FilterShowActivity activity = (FilterShowActivity) getActivity();
263 container = activity.getMainStatePanelContainer(R.id.state_panel_container);
265 transaction = getChildFragmentManager().beginTransaction();
267 if (container == null) {
270 transaction = getFragmentManager().beginTransaction();
272 int currentPanel = mCurrentSelected;
274 container.setVisibility(View.VISIBLE);
275 StatePanel statePanel = new StatePanel();
276 statePanel.setMainPanel(this);
277 FilterShowActivity activity = (FilterShowActivity) getActivity();
278 activity.updateVersions();
279 transaction.replace(R.id.state_panel_container, statePanel, StatePanel.FRAGMENT_TAG);
281 container.setVisibility(View.GONE);
282 Fragment statePanel = getChildFragmentManager().findFragmentByTag(StatePanel.FRAGMENT_TAG);
283 if (statePanel != null) {
284 transaction.remove(statePanel);
286 if (currentPanel == VERSIONS) {
287 currentPanel = LOOKS;
290 mCurrentSelected = -1;
291 showPanel(currentPanel);
292 transaction.commit();