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;
48 private int mCurrentSelected = -1;
50 private void selection(int position, boolean value) {
52 FilterShowActivity activity = (FilterShowActivity) getActivity();
53 activity.setCurrentPanel(position);
57 looksButton.setSelected(value);
61 bordersButton.setSelected(value);
65 geometryButton.setSelected(value);
69 filtersButton.setSelected(value);
76 public void onDestroyView() {
77 super.onDestroyView();
78 if (mMainView != null) {
79 if (mMainView.getParent() != null) {
80 ViewGroup parent = (ViewGroup) mMainView.getParent();
81 parent.removeView(mMainView);
87 public View onCreateView(LayoutInflater inflater, ViewGroup container,
88 Bundle savedInstanceState) {
90 mMainView = (LinearLayout) inflater.inflate(
91 R.layout.filtershow_main_panel, null, false);
93 looksButton = (ImageButton) mMainView.findViewById(R.id.fxButton);
94 bordersButton = (ImageButton) mMainView.findViewById(R.id.borderButton);
95 geometryButton = (ImageButton) mMainView.findViewById(R.id.geometryButton);
96 filtersButton = (ImageButton) mMainView.findViewById(R.id.colorsButton);
98 looksButton.setOnClickListener(new View.OnClickListener() {
100 public void onClick(View v) {
104 bordersButton.setOnClickListener(new View.OnClickListener() {
106 public void onClick(View v) {
110 geometryButton.setOnClickListener(new View.OnClickListener() {
112 public void onClick(View v) {
116 filtersButton.setOnClickListener(new View.OnClickListener() {
118 public void onClick(View v) {
123 FilterShowActivity activity = (FilterShowActivity) getActivity();
124 showImageStatePanel(activity.isShowingImageStatePanel());
125 showPanel(activity.getCurrentPanel());
129 private boolean isRightAnimation(int newPos) {
130 if (newPos < mCurrentSelected) {
136 private void setCategoryFragment(CategoryPanel category, boolean fromRight) {
137 FragmentTransaction transaction = getChildFragmentManager().beginTransaction();
139 transaction.setCustomAnimations(R.anim.slide_in_right, R.anim.slide_out_right);
141 transaction.setCustomAnimations(R.anim.slide_in_left, R.anim.slide_out_left);
143 transaction.replace(R.id.category_panel_container, category, CategoryPanel.FRAGMENT_TAG);
144 transaction.commit();
147 public void loadCategoryLookPanel() {
148 if (mCurrentSelected == LOOKS) {
151 boolean fromRight = isRightAnimation(LOOKS);
152 selection(mCurrentSelected, false);
153 CategoryPanel categoryPanel = new CategoryPanel();
154 categoryPanel.setAdapter(LOOKS);
155 setCategoryFragment(categoryPanel, fromRight);
156 mCurrentSelected = LOOKS;
157 selection(mCurrentSelected, true);
160 public void loadCategoryBorderPanel() {
161 if (mCurrentSelected == BORDERS) {
164 boolean fromRight = isRightAnimation(BORDERS);
165 selection(mCurrentSelected, false);
166 CategoryPanel categoryPanel = new CategoryPanel();
167 categoryPanel.setAdapter(BORDERS);
168 setCategoryFragment(categoryPanel, fromRight);
169 mCurrentSelected = BORDERS;
170 selection(mCurrentSelected, true);
173 public void loadCategoryGeometryPanel() {
174 if (mCurrentSelected == GEOMETRY) {
177 boolean fromRight = isRightAnimation(GEOMETRY);
178 selection(mCurrentSelected, false);
179 CategoryPanel categoryPanel = new CategoryPanel();
180 categoryPanel.setAdapter(GEOMETRY);
181 setCategoryFragment(categoryPanel, fromRight);
182 mCurrentSelected = GEOMETRY;
183 selection(mCurrentSelected, true);
186 public void loadCategoryFiltersPanel() {
187 if (mCurrentSelected == FILTERS) {
190 boolean fromRight = isRightAnimation(FILTERS);
191 selection(mCurrentSelected, false);
192 CategoryPanel categoryPanel = new CategoryPanel();
193 categoryPanel.setAdapter(FILTERS);
194 setCategoryFragment(categoryPanel, fromRight);
195 mCurrentSelected = FILTERS;
196 selection(mCurrentSelected, true);
199 public void showPanel(int currentPanel) {
200 switch (currentPanel) {
202 loadCategoryLookPanel();
206 loadCategoryBorderPanel();
210 loadCategoryGeometryPanel();
214 loadCategoryFiltersPanel();
220 public void showImageStatePanel(boolean show) {
221 if (mMainView.findViewById(R.id.state_panel_container) == null) {
224 FragmentTransaction transaction = getChildFragmentManager().beginTransaction();
225 final View container = mMainView.findViewById(R.id.state_panel_container);
227 container.setVisibility(View.VISIBLE);
228 StatePanel statePanel = new StatePanel();
229 transaction.replace(R.id.state_panel_container, statePanel, StatePanel.FRAGMENT_TAG);
231 container.setVisibility(View.GONE);
232 Fragment statePanel = getChildFragmentManager().findFragmentByTag(StatePanel.FRAGMENT_TAG);
233 if (statePanel != null) {
234 transaction.remove(statePanel);
237 transaction.commit();