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;
27 import com.android.gallery3d.R;
28 import com.android.gallery3d.filtershow.FilterShowActivity;
29 import com.android.gallery3d.filtershow.state.StatePanel;
31 public class MainPanel extends Fragment {
33 private static final String LOGTAG = "MainPanel";
35 private LinearLayout mMainView;
36 private ImageButton looksButton;
37 private ImageButton bordersButton;
38 private ImageButton geometryButton;
39 private ImageButton filtersButton;
41 public static final String FRAGMENT_TAG = "MainPanel";
42 public static final int LOOKS = 0;
43 public static final int BORDERS = 1;
44 public static final int GEOMETRY = 2;
45 public static final int FILTERS = 3;
47 private int mCurrentSelected = -1;
49 private void selection(int position, boolean value) {
51 FilterShowActivity activity = (FilterShowActivity) getActivity();
52 activity.setCurrentPanel(position);
56 looksButton.setSelected(value);
60 bordersButton.setSelected(value);
64 geometryButton.setSelected(value);
68 filtersButton.setSelected(value);
75 public void onDestroyView() {
76 super.onDestroyView();
77 if (mMainView != null) {
78 if (mMainView.getParent() != null) {
79 ViewGroup parent = (ViewGroup) mMainView.getParent();
80 parent.removeView(mMainView);
86 public View onCreateView(LayoutInflater inflater, ViewGroup container,
87 Bundle savedInstanceState) {
89 mMainView = (LinearLayout) inflater.inflate(
90 R.layout.filtershow_main_panel, null, false);
92 looksButton = (ImageButton) mMainView.findViewById(R.id.fxButton);
93 bordersButton = (ImageButton) mMainView.findViewById(R.id.borderButton);
94 geometryButton = (ImageButton) mMainView.findViewById(R.id.geometryButton);
95 filtersButton = (ImageButton) mMainView.findViewById(R.id.colorsButton);
97 looksButton.setOnClickListener(new View.OnClickListener() {
99 public void onClick(View v) {
103 bordersButton.setOnClickListener(new View.OnClickListener() {
105 public void onClick(View v) {
109 geometryButton.setOnClickListener(new View.OnClickListener() {
111 public void onClick(View v) {
115 filtersButton.setOnClickListener(new View.OnClickListener() {
117 public void onClick(View v) {
122 FilterShowActivity activity = (FilterShowActivity) getActivity();
123 showImageStatePanel(activity.isShowingImageStatePanel());
124 showPanel(activity.getCurrentPanel());
128 private boolean isRightAnimation(int newPos) {
129 if (newPos < mCurrentSelected) {
135 private void setCategoryFragment(CategoryPanel category, boolean fromRight) {
136 FragmentTransaction transaction = getChildFragmentManager().beginTransaction();
138 transaction.setCustomAnimations(R.anim.slide_in_right, R.anim.slide_out_right);
140 transaction.setCustomAnimations(R.anim.slide_in_left, R.anim.slide_out_left);
142 transaction.replace(R.id.category_panel_container, category, CategoryPanel.FRAGMENT_TAG);
143 transaction.commit();
146 public void loadCategoryLookPanel() {
147 if (mCurrentSelected == LOOKS) {
150 boolean fromRight = isRightAnimation(LOOKS);
151 selection(mCurrentSelected, false);
152 CategoryPanel categoryPanel = new CategoryPanel();
153 categoryPanel.setAdapter(LOOKS);
154 setCategoryFragment(categoryPanel, fromRight);
155 mCurrentSelected = LOOKS;
156 selection(mCurrentSelected, true);
159 public void loadCategoryBorderPanel() {
160 if (mCurrentSelected == BORDERS) {
163 boolean fromRight = isRightAnimation(BORDERS);
164 selection(mCurrentSelected, false);
165 CategoryPanel categoryPanel = new CategoryPanel();
166 categoryPanel.setAdapter(BORDERS);
167 setCategoryFragment(categoryPanel, fromRight);
168 mCurrentSelected = BORDERS;
169 selection(mCurrentSelected, true);
172 public void loadCategoryGeometryPanel() {
173 if (mCurrentSelected == GEOMETRY) {
176 boolean fromRight = isRightAnimation(GEOMETRY);
177 selection(mCurrentSelected, false);
178 CategoryPanel categoryPanel = new CategoryPanel();
179 categoryPanel.setAdapter(GEOMETRY);
180 setCategoryFragment(categoryPanel, fromRight);
181 mCurrentSelected = GEOMETRY;
182 selection(mCurrentSelected, true);
185 public void loadCategoryFiltersPanel() {
186 if (mCurrentSelected == FILTERS) {
189 boolean fromRight = isRightAnimation(FILTERS);
190 selection(mCurrentSelected, false);
191 CategoryPanel categoryPanel = new CategoryPanel();
192 categoryPanel.setAdapter(FILTERS);
193 setCategoryFragment(categoryPanel, fromRight);
194 mCurrentSelected = FILTERS;
195 selection(mCurrentSelected, true);
198 public void showPanel(int currentPanel) {
199 switch (currentPanel) {
201 loadCategoryLookPanel();
205 loadCategoryBorderPanel();
209 loadCategoryGeometryPanel();
213 loadCategoryFiltersPanel();
219 public void showImageStatePanel(boolean show) {
220 if (mMainView.findViewById(R.id.state_panel_container) == null) {
223 FragmentTransaction transaction = getChildFragmentManager().beginTransaction();
224 final View container = mMainView.findViewById(R.id.state_panel_container);
226 container.setVisibility(View.VISIBLE);
227 StatePanel statePanel = new StatePanel();
228 transaction.replace(R.id.state_panel_container, statePanel, StatePanel.FRAGMENT_TAG);
230 container.setVisibility(View.GONE);
231 Fragment statePanel = getChildFragmentManager().findFragmentByTag(StatePanel.FRAGMENT_TAG);
232 if (statePanel != null) {
233 transaction.remove(statePanel);
236 transaction.commit();