Revision 9881dc03
Added by Leszek Koltunski about 1 month ago
src/main/java/org/distorted/main/MainSettingsPopup.java | ||
---|---|---|
42 | 42 |
private static final float MENU_TEXT_SIZE = 0.060f; |
43 | 43 |
private static final int[] mLocation = new int[2]; |
44 | 44 |
|
45 |
private final PopupWindow mPopup;
|
|
46 |
private final WeakReference<MainActivity> mAct;
|
|
45 |
private PopupWindow mPopup; |
|
46 |
private WeakReference<MainActivity> mAct; |
|
47 | 47 |
private int mCurrMethod; |
48 | 48 |
private String[] mSortNames; |
49 |
private int mCurrTheme; |
|
50 |
private String[] mThemeNames; |
|
49 | 51 |
|
50 | 52 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
51 | 53 |
// this is supposed to prevent showing the navigational bar when we show the drop down list, |
... | ... | |
83 | 85 |
|
84 | 86 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
85 | 87 |
|
86 |
MainSettingsPopup(MainActivity act, int sortMethod, int width, int height) |
|
88 |
MainSettingsPopup(MainActivity act, int sortMethod, int themeValue, int width, int height)
|
|
87 | 89 |
{ |
88 | 90 |
mAct = new WeakReference<>(act); |
89 | 91 |
|
... | ... | |
101 | 103 |
int titleSize = (int)(MENU_TITLE_SIZE*width); |
102 | 104 |
int textSize = (int)(MENU_TEXT_SIZE*width); |
103 | 105 |
|
104 |
TextView title = layout.findViewById(R.id.sortTitle);
|
|
106 |
TextView title = layout.findViewById(R.id.settingsTitle);
|
|
105 | 107 |
title.setTextSize(TypedValue.COMPLEX_UNIT_PX, titleSize); |
106 |
TextView text = layout.findViewById(R.id.sortText); |
|
107 |
text.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize); |
|
108 |
TextView sortText = layout.findViewById(R.id.sortText); |
|
109 |
sortText.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize); |
|
110 |
TextView themeTitle = layout.findViewById(R.id.themeText); |
|
111 |
themeTitle.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize); |
|
108 | 112 |
|
109 |
Spinner actSpinner = layout.findViewById(R.id.sortMethod);
|
|
110 |
actSpinner.setOnItemSelectedListener(this);
|
|
113 |
Spinner sortSpinner = layout.findViewById(R.id.sortMethod);
|
|
114 |
sortSpinner.setOnItemSelectedListener(this);
|
|
111 | 115 |
|
112 | 116 |
mCurrMethod = sortMethod; |
113 | 117 |
buildSortOptions(act); |
114 | 118 |
|
115 |
ArrayAdapter<String> actAdapter = new ArrayAdapter<>(act, android.R.layout.simple_spinner_item, mSortNames);
|
|
116 |
actAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
|
117 |
actSpinner.setAdapter(actAdapter);
|
|
119 |
ArrayAdapter<String> sortAdapter = new ArrayAdapter<>(act, android.R.layout.simple_spinner_item, mSortNames);
|
|
120 |
sortAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
|
121 |
sortSpinner.setAdapter(sortAdapter);
|
|
118 | 122 |
|
119 |
if( sortMethod>=0 && sortMethod<mSortNames.length ) actSpinner.setSelection(sortMethod); |
|
123 |
if( sortMethod>=0 && sortMethod<mSortNames.length ) sortSpinner.setSelection(sortMethod); |
|
124 |
|
|
125 |
Spinner themeSpinner = layout.findViewById(R.id.themeValue); |
|
126 |
themeSpinner.setOnItemSelectedListener(this); |
|
127 |
|
|
128 |
mCurrTheme = themeValue; |
|
129 |
buildThemeOptions(act); |
|
130 |
|
|
131 |
ArrayAdapter<String> themeAdapter = new ArrayAdapter<>(act, android.R.layout.simple_spinner_item, mThemeNames); |
|
132 |
themeAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); |
|
133 |
themeSpinner.setAdapter(themeAdapter); |
|
134 |
|
|
135 |
if( themeValue>=0 && themeValue<mThemeNames.length ) themeSpinner.setSelection(themeValue); |
|
120 | 136 |
} |
121 | 137 |
|
122 | 138 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
133 | 149 |
mSortNames[4] = res.getString(R.string.sort_year); |
134 | 150 |
} |
135 | 151 |
|
152 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
153 |
|
|
154 |
private void buildThemeOptions(MainActivity act) |
|
155 |
{ |
|
156 |
Resources res = act.getResources(); |
|
157 |
mThemeNames = new String[3]; |
|
158 |
|
|
159 |
mThemeNames[0] = res.getString(R.string.theme_grey); |
|
160 |
mThemeNames[1] = res.getString(R.string.theme_white); |
|
161 |
mThemeNames[2] = res.getString(R.string.theme_green); |
|
162 |
} |
|
163 |
|
|
136 | 164 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
137 | 165 |
// work around lame bugs in Android's version <= 10 pop-up and split-screen modes |
138 | 166 |
|
... | ... | |
187 | 215 |
{ |
188 | 216 |
if( parent.getId()==R.id.sortMethod && mCurrMethod!=pos ) |
189 | 217 |
{ |
218 |
mPopup.dismiss(); |
|
190 | 219 |
mCurrMethod = pos; |
191 | 220 |
MainActivity act = mAct.get(); |
192 | 221 |
act.sortObjectsBy(pos); |
222 |
} |
|
223 |
if( parent.getId()==R.id.themeValue && mCurrTheme!=pos ) |
|
224 |
{ |
|
193 | 225 |
mPopup.dismiss(); |
226 |
mPopup = null; |
|
227 |
mCurrTheme = pos; |
|
228 |
MainActivity act = mAct.get(); |
|
229 |
mAct = null; |
|
230 |
act.changeThemeTo(pos); |
|
194 | 231 |
} |
195 | 232 |
} |
196 | 233 |
|
Also available in: Unified diff
common code from all activities to one BaseActivity