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.content.res.TypedArray; 21import android.util.AttributeSet; 22import android.view.View; 23import android.widget.LinearLayout; 24import com.android.gallery3d.R; 25 26public class CategoryTrack extends LinearLayout { 27 28 private CategoryAdapter mAdapter; 29 private int mElemSize; 30 31 public CategoryTrack(Context context, AttributeSet attrs) { 32 super(context, attrs); 33 TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.CategoryTrack); 34 mElemSize = a.getDimensionPixelSize(R.styleable.CategoryTrack_iconSize, 0); 35 } 36 37 public void setAdapter(CategoryAdapter adapter) { 38 mAdapter = adapter; 39 mAdapter.setItemWidth(mElemSize); 40 mAdapter.setItemHeight(LayoutParams.MATCH_PARENT); 41 fillContent(); 42 } 43 44 public void fillContent() { 45 removeAllViews(); 46 int n = mAdapter.getCount(); 47 for (int i = 0; i < n; i++) { 48 View view = mAdapter.getView(i, null, this); 49 addView(view, i); 50 } 51 requestLayout(); 52 } 53 54} 55