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.app.Activity;
20 import android.graphics.Rect;
21 import android.os.Bundle;
22 import androidx.fragment.app.Fragment;
23 import android.view.LayoutInflater;
24 import android.view.View;
25 import android.view.ViewGroup;
26 import android.widget.ImageButton;
27 import android.widget.LinearLayout;
28 import android.widget.ListView;
29 import android.widget.TextView;
30 import com.android.gallery3d.R;
31 import com.android.gallery3d.filtershow.FilterShowActivity;
33 public class CategoryPanel extends Fragment implements View.OnClickListener {
35 public static final String FRAGMENT_TAG = "CategoryPanel";
36 private static final String PARAMETER_TAG = "currentPanel";
38 private int mCurrentAdapter = MainPanel.LOOKS;
39 private CategoryAdapter mAdapter;
40 private IconView mAddButton;
42 public void setAdapter(int value) {
43 mCurrentAdapter = value;
47 public void onAttach(Activity activity) {
48 super.onAttach(activity);
49 loadAdapter(mCurrentAdapter);
52 public void loadAdapter(int adapter) {
53 FilterShowActivity activity = (FilterShowActivity) getActivity();
55 case MainPanel.LOOKS: {
56 mAdapter = activity.getCategoryLooksAdapter();
57 if (mAdapter != null) {
58 mAdapter.initializeSelection(MainPanel.LOOKS);
60 activity.updateCategories();
63 case MainPanel.BORDERS: {
64 mAdapter = activity.getCategoryBordersAdapter();
65 if (mAdapter != null) {
66 mAdapter.initializeSelection(MainPanel.BORDERS);
68 activity.updateCategories();
71 case MainPanel.GEOMETRY: {
72 mAdapter = activity.getCategoryGeometryAdapter();
73 if (mAdapter != null) {
74 mAdapter.initializeSelection(MainPanel.GEOMETRY);
78 case MainPanel.FILTERS: {
79 mAdapter = activity.getCategoryFiltersAdapter();
80 if (mAdapter != null) {
81 mAdapter.initializeSelection(MainPanel.FILTERS);
85 case MainPanel.VERSIONS: {
86 mAdapter = activity.getCategoryVersionsAdapter();
87 if (mAdapter != null) {
88 mAdapter.initializeSelection(MainPanel.VERSIONS);
93 updateAddButtonVisibility();
97 public void onSaveInstanceState(Bundle state) {
98 super.onSaveInstanceState(state);
99 state.putInt(PARAMETER_TAG, mCurrentAdapter);
103 public View onCreateView(LayoutInflater inflater, ViewGroup container,
104 Bundle savedInstanceState) {
105 LinearLayout main = (LinearLayout) inflater.inflate(
106 R.layout.filtershow_category_panel_new, container,
109 if (savedInstanceState != null) {
110 int selectedPanel = savedInstanceState.getInt(PARAMETER_TAG);
111 loadAdapter(selectedPanel);
114 View panelView = main.findViewById(R.id.listItems);
115 if (panelView instanceof CategoryTrack) {
116 CategoryTrack panel = (CategoryTrack) panelView;
117 if (mAdapter != null) {
118 mAdapter.setOrientation(CategoryView.HORIZONTAL);
119 panel.setAdapter(mAdapter);
120 mAdapter.setContainer(panel);
122 } else if (mAdapter != null) {
123 ListView panel = (ListView) main.findViewById(R.id.listItems);
124 panel.setAdapter(mAdapter);
125 mAdapter.setContainer(panel);
128 mAddButton = (IconView) main.findViewById(R.id.addButton);
129 if (mAddButton != null) {
130 mAddButton.setOnClickListener(this);
131 updateAddButtonVisibility();
137 public void onClick(View v) {
140 FilterShowActivity activity = (FilterShowActivity) getActivity();
141 activity.addCurrentVersion();
146 public void updateAddButtonVisibility() {
147 if (mAddButton == null) {
150 FilterShowActivity activity = (FilterShowActivity) getActivity();
151 if (activity.isShowingImageStatePanel() && mAdapter.showAddButton()) {
152 mAddButton.setVisibility(View.VISIBLE);
153 if (mAdapter != null) {
154 mAddButton.setText(mAdapter.getAddButtonText());
157 mAddButton.setVisibility(View.GONE);