blob: ed2d06af0198f1196a1312254aa692b195e495e4 (
plain)
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
|
package com.android.camera.ui;
import android.content.Context;
import com.android.camera.R;
import com.android.camera.IconListPreference;
import com.android.camera.Util;
import com.android.camera.ui.GLListView.OnItemSelectedListener;
public class BasicIndicator extends AbstractIndicator {
private final ResourceTexture mIcon[];
private final IconListPreference mPreference;
protected int mIndex;
private GLListView mPopupContent;
private PreferenceAdapter mModel;
private String mOverride;
public BasicIndicator(Context context, IconListPreference preference) {
super(context);
mPreference = preference;
mIcon = new ResourceTexture[preference.getIconIds().length];
mIndex = preference.findIndexOfValue(preference.getValue());
}
@Override
public void overrideSettings(String key, String settings) {
IconListPreference pref = mPreference;
if (!pref.getKey().equals(key)) return;
if (Util.equals(mOverride, settings)) return;
mOverride = settings;
int index = pref.findIndexOfValue(
settings == null ? pref.getValue() : settings);
if (mIndex != index) {
mIndex = index;
invalidate();
}
}
@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));
mModel = new PreferenceAdapter(context, mPreference);
mPopupContent.setOnItemSelectedListener(new MyListener(mModel));
mPopupContent.setDataModel(mModel);
}
mModel.overrideSettings(mOverride);
return mPopupContent;
}
protected void onPreferenceChanged(int newIndex) {
if (newIndex == mIndex) return;
mIndex = newIndex;
invalidate();
}
private class MyListener implements OnItemSelectedListener {
private final PreferenceAdapter mAdapter;
public MyListener(PreferenceAdapter adapter) {
mAdapter = adapter;
}
public void onItemSelected(GLView view, int position) {
mAdapter.onItemSelected(view, position);
onPreferenceChanged(position - 1);
}
}
@Override
protected ResourceTexture getIcon() {
int index = mIndex;
if (mIcon[index] == null) {
IconListPreference pref = mPreference;
Context context = getGLRootView().getContext();
mIcon[index] = new ResourceTexture(
context, mPreference.getLargeIconIds()[index]);
}
return mIcon[index];
}
}
|