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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
|
/*
* Copyright (C) 2010 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.camera.ui;
import android.content.Context;
import com.android.camera.IconListPreference;
import com.android.camera.ListPreference;
import com.android.camera.R;
import com.android.camera.Util;
import com.android.camera.ui.GLListView.OnItemSelectedListener;
class BasicIndicator extends AbstractIndicator {
private static final float FONT_SIZE = 18;
private static final int FONT_COLOR = 0xA8FFFFFF;
private static final int COLOR_OPTION_ITEM_HIGHLIGHT = 0xFF181818;
private final ResourceTexture mIcon[];
private final ListPreference mPreference;
protected int mIndex;
private GLListView mPopupContent;
private PreferenceAdapter mModel;
private String mOverride;
private int mTitleIndex;
private StringTexture mTitle;
private final float mFontSize;
private boolean mIsIconListMode;
public BasicIndicator(Context context, ListPreference preference) {
super(context);
mPreference = preference;
mIndex = preference.findIndexOfValue(preference.getValue());
if (preference instanceof IconListPreference) {
mIsIconListMode = true;
mIcon = new ResourceTexture[((IconListPreference) preference).getLargeIconIds().length];
mFontSize = 0;
} else {
mIsIconListMode = false;
mIcon = null;
mFontSize = GLRootView.dpToPixel(context, FONT_SIZE);
mTitleIndex = -1;
}
}
// Set the override and/or reload the value from preferences.
private void updateContent(String override, boolean reloadValue) {
if (!reloadValue && Util.equals(mOverride, override)) return;
ListPreference pref = mPreference;
mOverride = override;
int index = pref.findIndexOfValue(
override == null ? pref.getValue() : override);
if (mIndex != index) {
mIndex = index;
invalidate();
}
}
@Override
public void overrideSettings(String key, String settings) {
ListPreference pref = mPreference;
if (!pref.getKey().equals(key)) return;
updateContent(settings, false);
}
@Override
public void reloadPreferences() {
if (mModel != null) mModel.reload();
updateContent(null, true);
}
@Override
public GLView getPopupContent() {
if (mPopupContent == null) {
Context context = getGLRootView().getContext();
mPopupContent = new GLListView(context);
mPopupContent.setHighLight(
new ColorTexture(COLOR_OPTION_ITEM_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 BitmapTexture getIcon() {
if (mIsIconListMode) {
int index = mIndex;
if (mIcon[index] == null) {
Context context = getGLRootView().getContext();
mIcon[index] = new ResourceTexture(
context, ((IconListPreference) mPreference).getLargeIconIds()[index]);
}
return mIcon[index];
} else {
if (mTitleIndex != mIndex) {
mTitleIndex = mIndex;
if (mTitle != null) mTitle.deleteFromGL();
String value = mPreference.getEntry();
mTitle = StringTexture.newInstance(value, mFontSize, FONT_COLOR);
}
return mTitle;
}
}
}
|