1 /* 2 * Copyright (C) 2013 The Android Open Source Project 3 * 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 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 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. 15 */ 16 17 package com.android.gallery3d.filtershow.category; 18 19 import android.app.Activity; 20 import android.os.Bundle; 21 import android.support.v4.app.Fragment; 22 import android.view.LayoutInflater; 23 import android.view.View; 24 import android.view.ViewGroup; 25 import android.widget.LinearLayout; 26 import android.widget.ListView; 27 import com.android.gallery3d.R; 28 import com.android.gallery3d.filtershow.FilterShowActivity; 29 30 public class CategoryPanel extends Fragment { 31 32 public static final String FRAGMENT_TAG = "CategoryPanel"; 33 private static final String PARAMETER_TAG = "currentPanel"; 34 35 private int mCurrentAdapter = MainPanel.LOOKS; 36 private CategoryAdapter mAdapter; 37 38 public void setAdapter(int value) { 39 mCurrentAdapter = value; 40 } 41 42 @Override 43 public void onAttach(Activity activity) { 44 super.onAttach(activity); 45 loadAdapter(mCurrentAdapter); 46 } 47 48 private void loadAdapter(int adapter) { 49 FilterShowActivity activity = (FilterShowActivity) getActivity(); 50 switch (adapter) { 51 case MainPanel.LOOKS: { 52 mAdapter = activity.getCategoryLooksAdapter(); 53 mAdapter.initializeSelection(MainPanel.LOOKS); 54 break; 55 } 56 case MainPanel.BORDERS: { 57 mAdapter = activity.getCategoryBordersAdapter(); 58 mAdapter.initializeSelection(MainPanel.BORDERS); 59 break; 60 } 61 case MainPanel.GEOMETRY: { 62 mAdapter = activity.getCategoryGeometryAdapter(); 63 mAdapter.initializeSelection(MainPanel.GEOMETRY); 64 break; 65 } 66 case MainPanel.FILTERS: { 67 mAdapter = activity.getCategoryFiltersAdapter(); 68 mAdapter.initializeSelection(MainPanel.FILTERS); 69 break; 70 } 71 } 72 } 73 74 @Override 75 public void onSaveInstanceState(Bundle state) { 76 super.onSaveInstanceState(state); 77 state.putInt(PARAMETER_TAG, mCurrentAdapter); 78 } 79 80 @Override 81 public View onCreateView(LayoutInflater inflater, ViewGroup container, 82 Bundle savedInstanceState) { 83 LinearLayout main = (LinearLayout) inflater.inflate( 84 R.layout.filtershow_category_panel_new, container, 85 false); 86 87 if (savedInstanceState != null) { 88 int selectedPanel = savedInstanceState.getInt(PARAMETER_TAG); 89 loadAdapter(selectedPanel); 90 } 91 92 View panelView = main.findViewById(R.id.listItems); 93 if (panelView instanceof CategoryTrack) { 94 CategoryTrack panel = (CategoryTrack) panelView; 95 mAdapter.setUseFilterIconButton(true); 96 panel.setAdapter(mAdapter); 97 mAdapter.setContainer(panel); 98 } else { 99 ListView panel = (ListView) main.findViewById(R.id.listItems); 100 panel.setAdapter(mAdapter); 101 mAdapter.setContainer(panel); 102 } 103 return main; 104 } 105 106 } 107