1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
package com.android.camera.ui;
import android.content.Context;
import com.android.camera.ListPreference;
import com.google.android.camera.R;
import java.util.HashMap;
public class OtherSettingsIndicator extends AbstractIndicator {
private final ListPreference mPreference[];
private final PreferenceAdapter mAdapters[];
private ResourceTexture mIcon;
private GLListView mPopupContent;
private final HashMap<String, String> mOverrides = new HashMap<String, String>();
public OtherSettingsIndicator(
Context context, ListPreference preference[]) {
super(context);
mPreference = preference;
mAdapters = new PreferenceAdapter[preference.length];
}
@Override
protected ResourceTexture getIcon() {
if (mIcon == null) {
Context context = getGLRootView().getContext();
mIcon = new ResourceTexture(
context, R.drawable.ic_viewfinder_settings);
}
return mIcon;
}
@Override
public void overrideSettings(String key, String value) {
if (value == null) {
mOverrides.remove(key);
} else {
mOverrides.put(key, value);
}
if (mPopupContent != null) {
ListPreference prefs[] = mPreference;
for (int i = 0, n = prefs.length; i < n; ++i) {
if (!prefs[i].getKey().equals(key)) continue;
mAdapters[i].overrideSettings(value);
break;
}
}
}
private UberAdapter buildUberAdapter() {
ListPreference prefs[] = mPreference;
PreferenceAdapter adapters[] = mAdapters;
Context context = getGLRootView().getContext();
for (int i = 0, n = prefs.length; i < n; ++i) {
adapters[i] = new PreferenceAdapter(context, prefs[i]);
String override = mOverrides.get(prefs[i].getKey());
if (override != null) adapters[i].overrideSettings(override);
}
return new UberAdapter();
}
@Override
public GLView getPopupContent() {
if (mPopupContent == null) {
Context context = getGLRootView().getContext();
mPopupContent = new GLListView();
mPopupContent.setHighLight(new NinePatchTexture(
context, R.drawable.optionitem_highlight));
mPopupContent.setScroller(new NinePatchTexture(
context, R.drawable.scrollbar_handle_vertical));
UberAdapter adapter = buildUberAdapter();
mPopupContent.setOnItemSelectedListener(adapter);
mPopupContent.setDataModel(adapter);
}
return mPopupContent;
}
private class UberAdapter implements
GLListView.Model, GLListView.OnItemSelectedListener {
public GLView getView(int index) {
for (PreferenceAdapter adapter : mAdapters) {
if (index < adapter.size()) {
return adapter.getView(index);
}
index -= adapter.size();
}
return null;
}
public boolean isSelectable(int index) {
for (PreferenceAdapter adapter : mAdapters) {
if (index < adapter.size()) {
return adapter.isSelectable(index);
}
index -= adapter.size();
}
return true;
}
public int size() {
int size = 0;
for (PreferenceAdapter adapter : mAdapters) {
size += adapter.size();
}
return size;
}
public void onItemSelected(GLView view, int position) {
for (PreferenceAdapter adapter : mAdapters) {
if (position < adapter.size()) {
adapter.onItemSelected(view, position);
return;
}
position -= adapter.size();
}
}
}
}
|