summaryrefslogtreecommitdiffstats
path: root/src/com/android/gallery3d/filtershow/category
diff options
context:
space:
mode:
authornicolasroard <nicolasroard@google.com>2013-04-19 17:13:30 -0700
committernicolasroard <nicolasroard@google.com>2013-04-24 20:23:36 -0700
commit61ef319ade6d32f35e2f61a20c6208e6fbac8076 (patch)
tree3fd5d946392d65e9a8c8e69a8cd2d480202aec91 /src/com/android/gallery3d/filtershow/category
parentb341bb5ddda66c8df047cb5a7ad7a2f6bb9b2991 (diff)
downloadandroid_packages_apps_Snap-61ef319ade6d32f35e2f61a20c6208e6fbac8076.tar.gz
android_packages_apps_Snap-61ef319ade6d32f35e2f61a20c6208e6fbac8076.tar.bz2
android_packages_apps_Snap-61ef319ade6d32f35e2f61a20c6208e6fbac8076.zip
UI changes
bug:8664728 Change-Id: I133328543af534c745526d0d58aa7a61f5748a9d
Diffstat (limited to 'src/com/android/gallery3d/filtershow/category')
-rw-r--r--src/com/android/gallery3d/filtershow/category/Action.java174
-rw-r--r--src/com/android/gallery3d/filtershow/category/CategoryAdapter.java134
-rw-r--r--src/com/android/gallery3d/filtershow/category/CategoryPanel.java101
-rw-r--r--src/com/android/gallery3d/filtershow/category/CategoryTrack.java54
-rw-r--r--src/com/android/gallery3d/filtershow/category/CategoryView.java104
-rw-r--r--src/com/android/gallery3d/filtershow/category/MainPanel.java238
6 files changed, 805 insertions, 0 deletions
diff --git a/src/com/android/gallery3d/filtershow/category/Action.java b/src/com/android/gallery3d/filtershow/category/Action.java
new file mode 100644
index 000000000..667a897fe
--- /dev/null
+++ b/src/com/android/gallery3d/filtershow/category/Action.java
@@ -0,0 +1,174 @@
+/*
+ * 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.content.Context;
+import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
+import android.graphics.Canvas;
+import android.graphics.Matrix;
+import android.graphics.Paint;
+import android.graphics.Rect;
+import android.graphics.RectF;
+import com.android.gallery3d.filtershow.cache.RenderingRequest;
+import com.android.gallery3d.filtershow.cache.RenderingRequestCaller;
+import com.android.gallery3d.filtershow.filters.FilterRepresentation;
+import com.android.gallery3d.filtershow.imageshow.MasterImage;
+import com.android.gallery3d.filtershow.presets.ImagePreset;
+
+public class Action implements RenderingRequestCaller {
+
+ private static final String LOGTAG = "Action";
+ private FilterRepresentation mRepresentation;
+ private String mName;
+ private Rect mImageFrame;
+ private Bitmap mImage;
+ private CategoryAdapter mAdapter;
+ public static final int FULL_VIEW = 0;
+ public static final int CROP_VIEW = 1;
+ private int mType = CROP_VIEW;
+ private Bitmap mPortraitImage;
+ private Bitmap mOverlayBitmap;
+ private Context mContext;
+
+ public Action(Context context, FilterRepresentation representation, int type) {
+ mContext = context;
+ setRepresentation(representation);
+ setType(type);
+ }
+
+ public Action(Context context, FilterRepresentation representation) {
+ this(context, representation, CROP_VIEW);
+ }
+
+ public FilterRepresentation getRepresentation() {
+ return mRepresentation;
+ }
+
+ public void setRepresentation(FilterRepresentation representation) {
+ mRepresentation = representation;
+ mName = representation.getName();
+ }
+
+ public String getName() {
+ return mName;
+ }
+
+ public void setName(String name) {
+ mName = name;
+ }
+
+ public void setImageFrame(Rect imageFrame) {
+ if (mImageFrame != null && mImageFrame.equals(imageFrame)) {
+ return;
+ }
+ Bitmap bitmap = MasterImage.getImage().getLargeThumbnailBitmap();
+ if (bitmap != null) {
+ mImageFrame = imageFrame;
+ int w = mImageFrame.width();
+ int h = mImageFrame.height();
+ if (mType == CROP_VIEW) {
+ w /= 2;
+ }
+ Bitmap bitmapCrop = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
+ drawCenteredImage(bitmap, bitmapCrop, true);
+
+ postNewIconRenderRequest(bitmapCrop);
+ }
+ }
+
+ public Bitmap getImage() {
+ return mImage;
+ }
+
+ public void setImage(Bitmap image) {
+ mImage = image;
+ }
+
+ public void setAdapter(CategoryAdapter adapter) {
+ mAdapter = adapter;
+ }
+
+ public void setType(int type) {
+ mType = type;
+ }
+
+ private void postNewIconRenderRequest(Bitmap bitmap) {
+ if (bitmap != null && mRepresentation != null) {
+ ImagePreset preset = new ImagePreset();
+ preset.addFilter(mRepresentation);
+ RenderingRequest.post(bitmap,
+ preset, RenderingRequest.ICON_RENDERING, this);
+ }
+ }
+
+ private void drawCenteredImage(Bitmap source, Bitmap destination, boolean scale) {
+ RectF image = new RectF(0, 0, source.getWidth(), source.getHeight());
+ int border = 0;
+ if (!scale) {
+ border = destination.getWidth() - destination.getHeight();
+ if (border < 0) {
+ border = 0;
+ }
+ }
+ RectF frame = new RectF(border, 0,
+ destination.getWidth() - border,
+ destination.getHeight());
+ Matrix m = new Matrix();
+ m.setRectToRect(frame, image, Matrix.ScaleToFit.CENTER);
+ image.set(frame);
+ m.mapRect(image);
+ m.setRectToRect(image, frame, Matrix.ScaleToFit.FILL);
+ Canvas canvas = new Canvas(destination);
+ canvas.drawBitmap(source, m, new Paint());
+ }
+
+ @Override
+ public void available(RenderingRequest request) {
+ mImage = request.getBitmap();
+ if (mImage == null) {
+ return;
+ }
+ if (mRepresentation.getOverlayId() != 0 && mOverlayBitmap == null) {
+ mOverlayBitmap = BitmapFactory.decodeResource(
+ mContext.getResources(),
+ mRepresentation.getOverlayId());
+ }
+ if (mOverlayBitmap != null) {
+ drawCenteredImage(mOverlayBitmap, mImage, false);
+ }
+ if (mAdapter != null) {
+ mAdapter.notifyDataSetChanged();
+ }
+ }
+
+ public void setPortraitImage(Bitmap portraitImage) {
+ mPortraitImage = portraitImage;
+ }
+
+ public Bitmap getPortraitImage() {
+ return mPortraitImage;
+ }
+
+ public Bitmap getOverlayBitmap() {
+ return mOverlayBitmap;
+ }
+
+ public void setOverlayBitmap(Bitmap overlayBitmap) {
+ mOverlayBitmap = overlayBitmap;
+ }
+}
diff --git a/src/com/android/gallery3d/filtershow/category/CategoryAdapter.java b/src/com/android/gallery3d/filtershow/category/CategoryAdapter.java
new file mode 100644
index 000000000..e310b2f33
--- /dev/null
+++ b/src/com/android/gallery3d/filtershow/category/CategoryAdapter.java
@@ -0,0 +1,134 @@
+/*
+ * 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.content.Context;
+import android.util.Log;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.AbsListView;
+import android.widget.ArrayAdapter;
+import android.widget.LinearLayout;
+import android.widget.ListView;
+import com.android.gallery3d.R;
+import com.android.gallery3d.filtershow.filters.FilterRepresentation;
+import com.android.gallery3d.filtershow.filters.FilterTinyPlanetRepresentation;
+import com.android.gallery3d.filtershow.filters.ImageFilter;
+import com.android.gallery3d.filtershow.filters.ImageFilterTinyPlanet;
+import com.android.gallery3d.filtershow.ui.FilterIconButton;
+
+public class CategoryAdapter extends ArrayAdapter<Action> {
+
+ private static final String LOGTAG = "CategoryAdapter";
+ private int mItemHeight = 200;
+ private ListView mContainer;
+ private int mItemWidth = ListView.LayoutParams.MATCH_PARENT;
+ private boolean mUseFilterIconButton = false;
+
+ public CategoryAdapter(Context context, int textViewResourceId) {
+ super(context, textViewResourceId);
+ }
+
+ public CategoryAdapter(Context context) {
+ this(context, 0);
+ }
+
+ public void setItemHeight(int height) {
+ mItemHeight = height;
+ }
+
+ public void setItemWidth(int width) {
+ mItemWidth = width;
+ }
+
+ @Override
+ public void add(Action action) {
+ super.add(action);
+ action.setAdapter(this);
+ }
+
+ @Override
+ public View getView(int position, View convertView, ViewGroup parent) {
+ if (mUseFilterIconButton) {
+ if (convertView == null) {
+ LayoutInflater inflater =
+ (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
+ convertView = inflater.inflate(R.layout.filtericonbutton, parent, false);
+ }
+ FilterIconButton view = (FilterIconButton) convertView;
+ Action action = getItem(position);
+ view.setAction(action);
+ view.setup(action.getName(), null);
+ view.setLayoutParams(
+ new ListView.LayoutParams(mItemWidth, mItemHeight));
+ return view;
+ }
+ if (convertView == null) {
+ convertView = new CategoryView(getContext());
+ }
+ CategoryView view = (CategoryView) convertView;
+ view.setAction(getItem(position));
+ view.setLayoutParams(
+ new ListView.LayoutParams(mItemWidth, mItemHeight));
+ return view;
+ }
+
+ public void setContainer(ListView container) {
+ mContainer = container;
+ }
+
+ public ListView getContainer() {
+ return mContainer;
+ }
+
+ public void imageLoaded() {
+ notifyDataSetChanged();
+ }
+
+ public void setUseFilterIconButton(boolean useFilterIconButton) {
+ mUseFilterIconButton = useFilterIconButton;
+ }
+
+ public boolean isUseFilterIconButton() {
+ return mUseFilterIconButton;
+ }
+
+ public FilterRepresentation getTinyPlanet() {
+ for (int i = 0; i < getCount(); i++) {
+ Action action = getItem(i);
+ if (action.getRepresentation() != null
+ && action.getRepresentation().getFilterClass()
+ == ImageFilterTinyPlanet.class) {
+ return action.getRepresentation();
+ }
+ }
+ return null;
+ }
+
+ public void removeTinyPlanet() {
+ for (int i = 0; i < getCount(); i++) {
+ Action action = getItem(i);
+ if (action.getRepresentation() != null
+ && action.getRepresentation().getFilterClass()
+ == ImageFilterTinyPlanet.class) {
+ remove(action);
+ return;
+ }
+ }
+ }
+}
diff --git a/src/com/android/gallery3d/filtershow/category/CategoryPanel.java b/src/com/android/gallery3d/filtershow/category/CategoryPanel.java
new file mode 100644
index 000000000..9ddfcabe0
--- /dev/null
+++ b/src/com/android/gallery3d/filtershow/category/CategoryPanel.java
@@ -0,0 +1,101 @@
+/*
+ * 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.app.Activity;
+import android.os.Bundle;
+import android.support.v4.app.Fragment;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.LinearLayout;
+import android.widget.ListView;
+import com.android.gallery3d.R;
+import com.android.gallery3d.filtershow.FilterShowActivity;
+
+public class CategoryPanel extends Fragment {
+
+ public static final String FRAGMENT_TAG = "CategoryPanel";
+ private static final String PARAMETER_TAG = "currentPanel";
+
+ private int mCurrentAdapter = MainPanel.LOOKS;
+ private CategoryAdapter mAdapter;
+
+ public void setAdapter(int value) {
+ mCurrentAdapter = value;
+ }
+
+ @Override
+ public void onAttach(Activity activity) {
+ super.onAttach(activity);
+ loadAdapter(mCurrentAdapter);
+ }
+
+ private void loadAdapter(int adapter) {
+ FilterShowActivity activity = (FilterShowActivity) getActivity();
+ switch (adapter) {
+ case MainPanel.LOOKS: {
+ mAdapter = activity.getCategoryLooksAdapter();
+ break;
+ }
+ case MainPanel.BORDERS: {
+ mAdapter = activity.getCategoryBordersAdapter();
+ break;
+ }
+ case MainPanel.GEOMETRY: {
+ mAdapter = activity.getCategoryGeometryAdapter();
+ break;
+ }
+ case MainPanel.FILTERS: {
+ mAdapter = activity.getCategoryFiltersAdapter();
+ break;
+ }
+ }
+ }
+
+ @Override
+ public void onSaveInstanceState(Bundle state) {
+ super.onSaveInstanceState(state);
+ state.putInt(PARAMETER_TAG, mCurrentAdapter);
+ }
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container,
+ Bundle savedInstanceState) {
+ LinearLayout main = (LinearLayout) inflater.inflate(
+ R.layout.filtershow_category_panel_new, container,
+ false);
+
+ if (savedInstanceState != null) {
+ int selectedPanel = savedInstanceState.getInt(PARAMETER_TAG);
+ loadAdapter(selectedPanel);
+ }
+
+ View panelView = main.findViewById(R.id.listItems);
+ if (panelView instanceof CategoryTrack) {
+ CategoryTrack panel = (CategoryTrack) panelView;
+ mAdapter.setUseFilterIconButton(true);
+ panel.setAdapter(mAdapter);
+ } else {
+ ListView panel = (ListView) main.findViewById(R.id.listItems);
+ panel.setAdapter(mAdapter);
+ mAdapter.setContainer(panel);
+ }
+ return main;
+ }
+
+}
diff --git a/src/com/android/gallery3d/filtershow/category/CategoryTrack.java b/src/com/android/gallery3d/filtershow/category/CategoryTrack.java
new file mode 100644
index 000000000..e0a8a2fab
--- /dev/null
+++ b/src/com/android/gallery3d/filtershow/category/CategoryTrack.java
@@ -0,0 +1,54 @@
+/*
+ * 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.content.Context;
+import android.content.res.TypedArray;
+import android.util.AttributeSet;
+import android.view.View;
+import android.widget.LinearLayout;
+import com.android.gallery3d.R;
+
+public class CategoryTrack extends LinearLayout {
+
+ private CategoryAdapter mAdapter;
+ private int mElemSize;
+
+ public CategoryTrack(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.CategoryTrack);
+ mElemSize = a.getDimensionPixelSize(R.styleable.CategoryTrack_iconSize, 0);
+ }
+
+ public void setAdapter(CategoryAdapter adapter) {
+ mAdapter = adapter;
+ mAdapter.setItemWidth(mElemSize);
+ mAdapter.setItemHeight(LayoutParams.MATCH_PARENT);
+ fillContent();
+ }
+
+ public void fillContent() {
+ removeAllViews();
+ int n = mAdapter.getCount();
+ for (int i = 0; i < n; i++) {
+ View view = mAdapter.getView(i, null, this);
+ addView(view, i);
+ }
+ requestLayout();
+ }
+
+}
diff --git a/src/com/android/gallery3d/filtershow/category/CategoryView.java b/src/com/android/gallery3d/filtershow/category/CategoryView.java
new file mode 100644
index 000000000..5467841c4
--- /dev/null
+++ b/src/com/android/gallery3d/filtershow/category/CategoryView.java
@@ -0,0 +1,104 @@
+/*
+ * 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.content.Context;
+import android.content.res.Resources;
+import android.graphics.Bitmap;
+import android.graphics.Canvas;
+import android.graphics.Color;
+import android.graphics.Paint;
+import android.graphics.Rect;
+import android.graphics.Typeface;
+import android.util.Log;
+import android.view.View;
+import com.android.gallery3d.R;
+import com.android.gallery3d.filtershow.FilterShowActivity;
+import com.android.gallery3d.filtershow.filters.FilterRepresentation;
+
+public class CategoryView extends View implements View.OnClickListener {
+
+ private static final String LOGTAG = "CategoryView";
+ private Paint mPaint = new Paint();
+ private Action mAction;
+ private Rect mTextBounds = new Rect();
+ private static int sMargin = 16;
+ private static int sTextSize = 32;
+ private int mTextColor;
+ private int mBackgroundColor;
+
+ public static void setTextSize(int size) {
+ sTextSize = size;
+ }
+
+ public static void setMargin(int margin) {
+ sMargin = margin;
+ }
+
+ public CategoryView(Context context) {
+ super(context);
+ setOnClickListener(this);
+ Resources res = getResources();
+ mBackgroundColor = res.getColor(R.color.filtershow_categoryview_background);
+ mTextColor = res.getColor(R.color.filtershow_categoryview_text);
+ }
+
+ public void drawText(Canvas canvas, String text) {
+ if (text == null) {
+ return;
+ }
+ text = text.toUpperCase();
+ mPaint.reset();
+ mPaint.setColor(mTextColor);
+ mPaint.setTextSize(sTextSize);
+ mPaint.setTypeface(Typeface.DEFAULT_BOLD);
+ mPaint.setAntiAlias(true);
+ float textWidth = mPaint.measureText(text);
+ mPaint.getTextBounds(text, 0, text.length(), mTextBounds);
+ int x = (int) (canvas.getWidth() - textWidth - sMargin);
+ int y = canvas.getHeight() - sMargin;
+ canvas.drawText(text, x, y, mPaint);
+ }
+
+ public void onDraw(Canvas canvas) {
+ canvas.drawColor(mBackgroundColor);
+ if (mAction != null) {
+ drawText(canvas, mAction.getName());
+ if (mAction.getImage() == null) {
+ mAction.setImageFrame(new Rect(0, 0, canvas.getWidth(), canvas.getHeight()));
+ } else {
+ Bitmap bitmap = mAction.getImage();
+ canvas.drawBitmap(bitmap, 0, 0, mPaint);
+ }
+ }
+ }
+
+ public void setAction(Action action) {
+ mAction = action;
+ invalidate();
+ }
+
+ public FilterRepresentation getRepresentation() {
+ return mAction.getRepresentation();
+ }
+
+ @Override
+ public void onClick(View view) {
+ FilterShowActivity activity = (FilterShowActivity) getContext();
+ activity.showRepresentation(mAction.getRepresentation());
+ }
+}
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();
+ }
+}