Revision 2eb70e4a
Added by Leszek Koltunski 23 days 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 int mWidth, mHeight; |
|
45 | 46 |
private PopupWindow mPopup; |
46 | 47 |
private WeakReference<MainActivity> mAct; |
47 | 48 |
private int mCurrMethod; |
... | ... | |
85 | 86 |
|
86 | 87 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
87 | 88 |
|
88 |
MainSettingsPopup(MainActivity act, int sortMethod, int themeValue, int width, int height) |
|
89 |
MainSettingsPopup(MainActivity act, int sortMethod, int themeValue, |
|
90 |
int scrWidth, int popupWidth, int popupHeight) |
|
89 | 91 |
{ |
90 | 92 |
mAct = new WeakReference<>(act); |
91 | 93 |
|
94 |
mWidth = popupWidth; |
|
95 |
mHeight= popupHeight; |
|
96 |
|
|
92 | 97 |
// due to bugs in Android API <=25, a Spinner inside a PopupWindow will crash once you click on it. |
93 | 98 |
// solution: on those APIs, use a special Spinner in dialog mode (this does not crash) |
94 | 99 |
int id = android.os.Build.VERSION.SDK_INT <= 25 ? R.layout.settings_popup_android25 : R.layout.settings_popup; |
... | ... | |
100 | 105 |
mPopup.setContentView(layout); |
101 | 106 |
mPopup.setFocusable(true); |
102 | 107 |
|
103 |
int titleSize = (int)(MENU_TITLE_SIZE*width);
|
|
104 |
int textSize = (int)(MENU_TEXT_SIZE*width);
|
|
108 |
int titleSize = (int)(0.26f*popupHeight);
|
|
109 |
int textSize = (int)(0.19f*popupHeight);
|
|
105 | 110 |
|
106 | 111 |
TextView title = layout.findViewById(R.id.settingsTitle); |
107 |
title.setTextSize(TypedValue.COMPLEX_UNIT_PX, titleSize); |
|
112 |
//title.setTextSize(TypedValue.COMPLEX_UNIT_PX, titleSize);
|
|
108 | 113 |
TextView sortText = layout.findViewById(R.id.sortText); |
109 |
sortText.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize); |
|
114 |
//sortText.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
|
|
110 | 115 |
TextView themeTitle = layout.findViewById(R.id.themeText); |
111 |
themeTitle.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize); |
|
116 |
// themeTitle.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
|
|
112 | 117 |
|
113 | 118 |
Spinner sortSpinner = layout.findViewById(R.id.sortMethod); |
114 | 119 |
sortSpinner.setOnItemSelectedListener(this); |
... | ... | |
116 | 121 |
mCurrMethod = sortMethod; |
117 | 122 |
buildSortOptions(act); |
118 | 123 |
|
119 |
ArrayAdapter<String> sortAdapter = new ArrayAdapter<>(act, android.R.layout.simple_spinner_item, mSortNames);
|
|
124 |
ArrayAdapter<String> sortAdapter = new ArrayAdapter<>(act, R.layout.settings_spinner_item, mSortNames);
|
|
120 | 125 |
sortAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); |
121 | 126 |
sortSpinner.setAdapter(sortAdapter); |
122 | 127 |
|
... | ... | |
128 | 133 |
mCurrTheme = themeValue; |
129 | 134 |
buildThemeOptions(act); |
130 | 135 |
|
131 |
ArrayAdapter<String> themeAdapter = new ArrayAdapter<>(act, android.R.layout.simple_spinner_item, mThemeNames);
|
|
136 |
ArrayAdapter<String> themeAdapter = new ArrayAdapter<>(act, R.layout.settings_spinner_item, mThemeNames);
|
|
132 | 137 |
themeAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); |
133 | 138 |
themeSpinner.setAdapter(themeAdapter); |
134 | 139 |
|
... | ... | |
164 | 169 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
165 | 170 |
// work around lame bugs in Android's version <= 10 pop-up and split-screen modes |
166 | 171 |
|
167 |
public void displayPopup(MainActivity act, View view, int w, int h, int xoff, int yoff)
|
|
172 |
public void displayPopup(MainActivity act, View view, int xoff, int yoff) |
|
168 | 173 |
{ |
169 | 174 |
View v = mPopup.getContentView(); |
170 | 175 |
v.setSystemUiVisibility(MainActivity.FLAGS); |
... | ... | |
189 | 194 |
if (Build.VERSION_CODES.R<=Build.VERSION.SDK_INT || isFullScreen ) |
190 | 195 |
{ |
191 | 196 |
mPopup.showAsDropDown(view, xoff, yoff, Gravity.CENTER); |
192 |
mPopup.update(view, w, h);
|
|
197 |
mPopup.update(view, mWidth, mHeight);
|
|
193 | 198 |
} |
194 | 199 |
else // Android 10 or below in pop-up mode or split-screen mode |
195 | 200 |
{ |
196 | 201 |
view.getLocationOnScreen(mLocation); |
197 | 202 |
int width = view.getWidth(); |
198 | 203 |
int height = view.getHeight(); |
199 |
int x = mLocation[0]+(width-w)/2;
|
|
204 |
int x = mLocation[0]+(width-mWidth)/2;
|
|
200 | 205 |
int y = mLocation[1]+height+yoff; |
201 | 206 |
mPopup.showAsDropDown(view); |
202 |
mPopup.update(x,y,w,h);
|
|
207 |
mPopup.update(x,y,mWidth,mHeight);
|
|
203 | 208 |
} |
204 | 209 |
} |
205 | 210 |
catch( IllegalArgumentException iae ) |
Also available in: Unified diff
some progress with the main settings popup