CategoryAdapter.java revision f5eedf1635eba7edfa7d41fd4e991cced978c4b2
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 17package com.android.gallery3d.filtershow.category; 18 19import android.content.Context; 20import android.util.Log; 21import android.view.LayoutInflater; 22import android.view.View; 23import android.view.ViewGroup; 24import android.widget.AbsListView; 25import android.widget.ArrayAdapter; 26import android.widget.LinearLayout; 27import android.widget.ListView; 28import com.android.gallery3d.R; 29import com.android.gallery3d.filtershow.filters.FilterRepresentation; 30import com.android.gallery3d.filtershow.filters.FilterTinyPlanetRepresentation; 31import com.android.gallery3d.filtershow.filters.ImageFilter; 32import com.android.gallery3d.filtershow.filters.ImageFilterTinyPlanet; 33import com.android.gallery3d.filtershow.ui.FilterIconButton; 34 35public class CategoryAdapter extends ArrayAdapter<Action> { 36 37 private static final String LOGTAG = "CategoryAdapter"; 38 private int mItemHeight = 200; 39 private ListView mContainer; 40 private int mItemWidth = ListView.LayoutParams.MATCH_PARENT; 41 private boolean mUseFilterIconButton = false; 42 43 public CategoryAdapter(Context context, int textViewResourceId) { 44 super(context, textViewResourceId); 45 } 46 47 public CategoryAdapter(Context context) { 48 this(context, 0); 49 } 50 51 public void setItemHeight(int height) { 52 mItemHeight = height; 53 } 54 55 public void setItemWidth(int width) { 56 mItemWidth = width; 57 } 58 59 @Override 60 public void add(Action action) { 61 super.add(action); 62 action.setAdapter(this); 63 } 64 65 @Override 66 public View getView(int position, View convertView, ViewGroup parent) { 67 if (mUseFilterIconButton) { 68 if (convertView == null) { 69 LayoutInflater inflater = 70 (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); 71 convertView = inflater.inflate(R.layout.filtericonbutton, parent, false); 72 } 73 FilterIconButton view = (FilterIconButton) convertView; 74 Action action = getItem(position); 75 view.setAction(action); 76 view.setup(action.getName(), null); 77 view.setLayoutParams( 78 new ListView.LayoutParams(mItemWidth, mItemHeight)); 79 return view; 80 } 81 if (convertView == null) { 82 convertView = new CategoryView(getContext()); 83 } 84 CategoryView view = (CategoryView) convertView; 85 view.setAction(getItem(position)); 86 view.setLayoutParams( 87 new ListView.LayoutParams(mItemWidth, mItemHeight)); 88 return view; 89 } 90 91 public void setContainer(ListView container) { 92 mContainer = container; 93 } 94 95 public ListView getContainer() { 96 return mContainer; 97 } 98 99 public void imageLoaded() { 100 notifyDataSetChanged(); 101 } 102 103 public void setUseFilterIconButton(boolean useFilterIconButton) { 104 mUseFilterIconButton = useFilterIconButton; 105 } 106 107 public boolean isUseFilterIconButton() { 108 return mUseFilterIconButton; 109 } 110 111 public FilterRepresentation getTinyPlanet() { 112 for (int i = 0; i < getCount(); i++) { 113 Action action = getItem(i); 114 if (action.getRepresentation() != null 115 && action.getRepresentation().getFilterClass() 116 == ImageFilterTinyPlanet.class) { 117 return action.getRepresentation(); 118 } 119 } 120 return null; 121 } 122 123 public void removeTinyPlanet() { 124 for (int i = 0; i < getCount(); i++) { 125 Action action = getItem(i); 126 if (action.getRepresentation() != null 127 && action.getRepresentation().getFilterClass() 128 == ImageFilterTinyPlanet.class) { 129 remove(action); 130 return; 131 } 132 } 133 } 134} 135