diff options
Diffstat (limited to 'src/com/android/gallery3d/filtershow/category/MainPanel.java')
-rw-r--r-- | src/com/android/gallery3d/filtershow/category/MainPanel.java | 238 |
1 files changed, 238 insertions, 0 deletions
diff --git a/src/com/android/gallery3d/filtershow/category/MainPanel.java b/src/com/android/gallery3d/filtershow/category/MainPanel.java new file mode 100644 index 000000000..7cadbc323 --- /dev/null +++ b/src/com/android/gallery3d/filtershow/category/MainPanel.java @@ -0,0 +1,238 @@ +/* + * Copyright (C) 2013 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.gallery3d.filtershow.category; + +import android.os.Bundle; +import android.support.v4.app.Fragment; +import android.support.v4.app.FragmentTransaction; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ImageButton; +import android.widget.LinearLayout; +import com.android.gallery3d.R; +import com.android.gallery3d.filtershow.FilterShowActivity; +import com.android.gallery3d.filtershow.state.StatePanel; + +public class MainPanel extends Fragment { + + private static final String LOGTAG = "MainPanel"; + + private LinearLayout mMainView; + private ImageButton looksButton; + private ImageButton bordersButton; + private ImageButton geometryButton; + private ImageButton filtersButton; + + public static final String FRAGMENT_TAG = "MainPanel"; + public static final int LOOKS = 0; + public static final int BORDERS = 1; + public static final int GEOMETRY = 2; + public static final int FILTERS = 3; + + private int mCurrentSelected = -1; + + private void selection(int position, boolean value) { + if (value) { + FilterShowActivity activity = (FilterShowActivity) getActivity(); + activity.setCurrentPanel(position); + } + switch (position) { + case LOOKS: { + looksButton.setSelected(value); + break; + } + case BORDERS: { + bordersButton.setSelected(value); + break; + } + case GEOMETRY: { + geometryButton.setSelected(value); + break; + } + case FILTERS: { + filtersButton.setSelected(value); + break; + } + } + } + + @Override + public void onDestroyView() { + super.onDestroyView(); + if (mMainView != null) { + if (mMainView.getParent() != null) { + ViewGroup parent = (ViewGroup) mMainView.getParent(); + parent.removeView(mMainView); + } + } + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + + mMainView = (LinearLayout) inflater.inflate( + R.layout.filtershow_main_panel, null, false); + + looksButton = (ImageButton) mMainView.findViewById(R.id.fxButton); + bordersButton = (ImageButton) mMainView.findViewById(R.id.borderButton); + geometryButton = (ImageButton) mMainView.findViewById(R.id.geometryButton); + filtersButton = (ImageButton) mMainView.findViewById(R.id.colorsButton); + + looksButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + showPanel(LOOKS); + } + }); + bordersButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + showPanel(BORDERS); + } + }); + geometryButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + showPanel(GEOMETRY); + } + }); + filtersButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + showPanel(FILTERS); + } + }); + + FilterShowActivity activity = (FilterShowActivity) getActivity(); + showImageStatePanel(activity.isShowingImageStatePanel()); + showPanel(activity.getCurrentPanel()); + return mMainView; + } + + private boolean isRightAnimation(int newPos) { + if (newPos < mCurrentSelected) { + return false; + } + return true; + } + + private void setCategoryFragment(CategoryPanel category, boolean fromRight) { + FragmentTransaction transaction = getChildFragmentManager().beginTransaction(); + if (fromRight) { + transaction.setCustomAnimations(R.anim.slide_in_right, R.anim.slide_out_right); + } else { + transaction.setCustomAnimations(R.anim.slide_in_left, R.anim.slide_out_left); + } + transaction.replace(R.id.category_panel_container, category, CategoryPanel.FRAGMENT_TAG); + transaction.commit(); + } + + public void loadCategoryLookPanel() { + if (mCurrentSelected == LOOKS) { + return; + } + boolean fromRight = isRightAnimation(LOOKS); + selection(mCurrentSelected, false); + CategoryPanel categoryPanel = new CategoryPanel(); + categoryPanel.setAdapter(LOOKS); + setCategoryFragment(categoryPanel, fromRight); + mCurrentSelected = LOOKS; + selection(mCurrentSelected, true); + } + + public void loadCategoryBorderPanel() { + if (mCurrentSelected == BORDERS) { + return; + } + boolean fromRight = isRightAnimation(BORDERS); + selection(mCurrentSelected, false); + CategoryPanel categoryPanel = new CategoryPanel(); + categoryPanel.setAdapter(BORDERS); + setCategoryFragment(categoryPanel, fromRight); + mCurrentSelected = BORDERS; + selection(mCurrentSelected, true); + } + + public void loadCategoryGeometryPanel() { + if (mCurrentSelected == GEOMETRY) { + return; + } + boolean fromRight = isRightAnimation(GEOMETRY); + selection(mCurrentSelected, false); + CategoryPanel categoryPanel = new CategoryPanel(); + categoryPanel.setAdapter(GEOMETRY); + setCategoryFragment(categoryPanel, fromRight); + mCurrentSelected = GEOMETRY; + selection(mCurrentSelected, true); + } + + public void loadCategoryFiltersPanel() { + if (mCurrentSelected == FILTERS) { + return; + } + boolean fromRight = isRightAnimation(FILTERS); + selection(mCurrentSelected, false); + CategoryPanel categoryPanel = new CategoryPanel(); + categoryPanel.setAdapter(FILTERS); + setCategoryFragment(categoryPanel, fromRight); + mCurrentSelected = FILTERS; + selection(mCurrentSelected, true); + } + + public void showPanel(int currentPanel) { + switch (currentPanel) { + case LOOKS: { + loadCategoryLookPanel(); + break; + } + case BORDERS: { + loadCategoryBorderPanel(); + break; + } + case GEOMETRY: { + loadCategoryGeometryPanel(); + break; + } + case FILTERS: { + loadCategoryFiltersPanel(); + break; + } + } + } + + public void showImageStatePanel(boolean show) { + if (mMainView.findViewById(R.id.state_panel_container) == null) { + return; + } + FragmentTransaction transaction = getChildFragmentManager().beginTransaction(); + final View container = mMainView.findViewById(R.id.state_panel_container); + if (show) { + container.setVisibility(View.VISIBLE); + StatePanel statePanel = new StatePanel(); + transaction.replace(R.id.state_panel_container, statePanel, StatePanel.FRAGMENT_TAG); + } else { + container.setVisibility(View.GONE); + Fragment statePanel = getChildFragmentManager().findFragmentByTag(StatePanel.FRAGMENT_TAG); + if (statePanel != null) { + transaction.remove(statePanel); + } + } + transaction.commit(); + } +} |