• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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 
17 package com.android.camera;
18 
19 import java.util.ArrayList;
20 
21 import android.content.Context;
22 import 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  */
28 public class PreferenceGroup extends CameraPreference {
29     private ArrayList<CameraPreference> list =
30             new ArrayList<CameraPreference>();
31 
PreferenceGroup(Context context, AttributeSet attrs)32     public PreferenceGroup(Context context, AttributeSet attrs) {
33         super(context, attrs);
34     }
35 
addChild(CameraPreference child)36     public void addChild(CameraPreference child) {
37         list.add(child);
38     }
39 
removePreference(int index)40     public void removePreference(int index) {
41         list.remove(index);
42     }
43 
get(int index)44     public CameraPreference get(int index) {
45         return list.get(index);
46     }
47 
size()48     public int size() {
49         return list.size();
50     }
51 
52     @Override
reloadValue()53     public void reloadValue() {
54         for (CameraPreference pref : list) {
55             pref.reloadValue();
56         }
57     }
58 
59     /**
60      * Finds the preference with the given key recursively. Returns
61      * <code>null</code> if cannot find.
62      */
findPreference(String key)63     public ListPreference findPreference(String key) {
64         // Find a leaf preference with the given key. Currently, the base
65         // type of all "leaf" preference is "ListPreference". If we add some
66         // other types later, we need to change the code.
67         for (CameraPreference pref : list) {
68             if (pref instanceof ListPreference) {
69                 ListPreference listPref = (ListPreference) pref;
70                 if(listPref.getKey().equals(key)) return listPref;
71             } else if(pref instanceof PreferenceGroup) {
72                 ListPreference listPref =
73                         ((PreferenceGroup) pref).findPreference(key);
74                 if (listPref != null) return listPref;
75             }
76         }
77         return null;
78     }
79 }
80