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.imageshow.MasterImage;
31 import com.android.gallery3d.filtershow.state.StatePanel;
33 public class MainPanel extends Fragment {
35 private static final String LOGTAG = "MainPanel";
37 private LinearLayout mMainView;
38 private ImageButton looksButton;
39 private ImageButton bordersButton;
40 private ImageButton geometryButton;
41 private ImageButton filtersButton;
43 public static final String FRAGMENT_TAG = "MainPanel";
44 public static final int LOOKS = 0;
45 public static final int BORDERS = 1;
46 public static final int GEOMETRY = 2;
47 public static final int FILTERS = 3;
48 public static final int VERSIONS = 4;
50 private int mCurrentSelected = -1;
51 private int mPreviousToggleVersions = -1;
53 private void selection(int position, boolean value) {
55 FilterShowActivity activity = (FilterShowActivity) getActivity();
56 activity.setCurrentPanel(position);
60 looksButton.setSelected(value);
64 bordersButton.setSelected(value);
68 geometryButton.setSelected(value);
72 filtersButton.setSelected(value);
79 public void onDestroyView() {
80 super.onDestroyView();
81 if (mMainView != null) {
82 if (mMainView.getParent() != null) {
83 ViewGroup parent = (ViewGroup) mMainView.getParent();
84 parent.removeView(mMainView);
90 public View onCreateView(LayoutInflater inflater, ViewGroup container,
91 Bundle savedInstanceState) {
93 mMainView = (LinearLayout) inflater.inflate(
94 R.layout.filtershow_main_panel, null, false);
96 looksButton = (ImageButton) mMainView.findViewById(R.id.fxButton);
97 bordersButton = (ImageButton) mMainView.findViewById(R.id.borderButton);
98 geometryButton = (ImageButton) mMainView.findViewById(R.id.geometryButton);
99 filtersButton = (ImageButton) mMainView.findViewById(R.id.colorsButton);
101 looksButton.setOnClickListener(new View.OnClickListener() {
103 public void onClick(View v) {
107 bordersButton.setOnClickListener(new View.OnClickListener() {
109 public void onClick(View v) {
113 geometryButton.setOnClickListener(new View.OnClickListener() {
115 public void onClick(View v) {
119 filtersButton.setOnClickListener(new View.OnClickListener() {
121 public void onClick(View v) {
126 FilterShowActivity activity = (FilterShowActivity) getActivity();
127 showImageStatePanel(activity.isShowingImageStatePanel());
128 showPanel(activity.getCurrentPanel());
132 private boolean isRightAnimation(int newPos) {
133 if (newPos < mCurrentSelected) {
139 private void setCategoryFragment(CategoryPanel category, boolean fromRight) {
140 FragmentTransaction transaction = getChildFragmentManager().beginTransaction();
142 transaction.setCustomAnimations(R.anim.slide_in_right, R.anim.slide_out_right);
144 transaction.setCustomAnimations(R.anim.slide_in_left, R.anim.slide_out_left);
146 transaction.replace(R.id.category_panel_container, category, CategoryPanel.FRAGMENT_TAG);
147 transaction.commitAllowingStateLoss();
150 public void loadCategoryLookPanel(boolean force) {
151 if (!force && 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 if (MasterImage.getImage().hasTinyPlanet()) {
183 boolean fromRight = isRightAnimation(GEOMETRY);
184 selection(mCurrentSelected, false);
185 CategoryPanel categoryPanel = new CategoryPanel();
186 categoryPanel.setAdapter(GEOMETRY);
187 setCategoryFragment(categoryPanel, fromRight);
188 mCurrentSelected = GEOMETRY;
189 selection(mCurrentSelected, true);
192 public void loadCategoryFiltersPanel() {
193 if (mCurrentSelected == FILTERS) {
196 boolean fromRight = isRightAnimation(FILTERS);
197 selection(mCurrentSelected, false);
198 CategoryPanel categoryPanel = new CategoryPanel();
199 categoryPanel.setAdapter(FILTERS);
200 setCategoryFragment(categoryPanel, fromRight);
201 mCurrentSelected = FILTERS;
202 selection(mCurrentSelected, true);
205 public void loadCategoryVersionsPanel() {
206 if (mCurrentSelected == VERSIONS) {
209 FilterShowActivity activity = (FilterShowActivity) getActivity();
210 activity.updateVersions();
211 boolean fromRight = isRightAnimation(VERSIONS);
212 selection(mCurrentSelected, false);
213 CategoryPanel categoryPanel = new CategoryPanel();
214 categoryPanel.setAdapter(VERSIONS);
215 setCategoryFragment(categoryPanel, fromRight);
216 mCurrentSelected = VERSIONS;
217 selection(mCurrentSelected, true);
220 public void showPanel(int currentPanel) {
221 switch (currentPanel) {
223 loadCategoryLookPanel(false);
227 loadCategoryBorderPanel();
231 loadCategoryGeometryPanel();
235 loadCategoryFiltersPanel();
239 loadCategoryVersionsPanel();
245 public void setToggleVersionsPanelButton(ImageButton button) {
246 if (button == null) {
249 button.setOnClickListener(new View.OnClickListener() {
251 public void onClick(View v) {
252 if (mCurrentSelected == VERSIONS) {
253 showPanel(mPreviousToggleVersions);
255 mPreviousToggleVersions = mCurrentSelected;
262 public void showImageStatePanel(boolean show) {
263 View container = mMainView.findViewById(R.id.state_panel_container);
264 FragmentTransaction transaction = null;
265 if (container == null) {
266 FilterShowActivity activity = (FilterShowActivity) getActivity();
267 container = activity.getMainStatePanelContainer(R.id.state_panel_container);
269 transaction = getChildFragmentManager().beginTransaction();
271 if (container == null) {
274 transaction = getFragmentManager().beginTransaction();
276 int currentPanel = mCurrentSelected;
278 container.setVisibility(View.VISIBLE);
279 StatePanel statePanel = new StatePanel();
280 statePanel.setMainPanel(this);
281 FilterShowActivity activity = (FilterShowActivity) getActivity();
282 activity.updateVersions();
283 transaction.replace(R.id.state_panel_container, statePanel, StatePanel.FRAGMENT_TAG);
285 container.setVisibility(View.GONE);
286 Fragment statePanel = getChildFragmentManager().findFragmentByTag(StatePanel.FRAGMENT_TAG);
287 if (statePanel != null) {
288 transaction.remove(statePanel);
290 if (currentPanel == VERSIONS) {
291 currentPanel = LOOKS;
294 mCurrentSelected = -1;
295 showPanel(currentPanel);
296 transaction.commit();