blob: d4972f8220bc2ddbefd78cef6c7b5cfc70f3a700 [file] [log] [blame]
Owen Lin73e782d2010-01-20 06:37:36 +08001/*
2 * Copyright (C) 2009 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.camera;
18
19import java.util.ArrayList;
20
21import android.content.Context;
22import android.util.AttributeSet;
23
24/**
25 * A collection of <code>CameraPreference</code>s. It may contain other
26 * <code>PreferenceGroup</code> and form a tree structure.
27 */
28public class PreferenceGroup extends CameraPreference {
29 private ArrayList<CameraPreference> list =
30 new ArrayList<CameraPreference>();
31
32 public PreferenceGroup(Context context, AttributeSet attrs) {
33 super(context, attrs);
34 }
35
36 public void addChild(CameraPreference child) {
37 list.add(child);
38 }
39
40 public void removePreference(int index) {
41 list.remove(index);
42 }
43
44 public CameraPreference get(int index) {
45 return list.get(index);
46 }
47
48 public int size() {
49 return list.size();
50 }
51
52 /**
53 * Finds the preference with the given key recursively. Returns
54 * <code>null</code> if cannot find.
55 */
56 public ListPreference findPreference(String key) {
57 // Find a leaf preference with the given key. Currently, the base
58 // type of all "leaf" preference is "ListPreference". If we add some
59 // other types later, we need to change the code.
60 for (CameraPreference pref : list) {
61 if (pref instanceof ListPreference) {
62 ListPreference listPref = (ListPreference) pref;
63 if(listPref.getKey().equals(key)) return listPref;
64 } else if(pref instanceof PreferenceGroup) {
65 ListPreference listPref =
66 ((PreferenceGroup) pref).findPreference(key);
67 if (listPref != null) return listPref;
68 }
69 }
70 return null;
71 }
72}