Project

General

Profile

« Previous | Next » 

Revision 2eb70e4a

Added by Leszek Koltunski 8 months ago

some progress with the main settings popup

View differences:

src/main/java/org/distorted/main/MainActivity.java
412 412

  
413 413
    public void onSettings(View v)
414 414
      {
415
      int sw = (int)(mScreenWidth*0.7);
416
      int sh = (int)(mScreenHeight*0.2f);
415
      int sw = (int)(mScreenWidth*0.70);
416
      int sh = (int)(mScreenHeight*0.25f);
417 417

  
418 418
      int vw = v.getWidth();
419 419

  
420
      MainSettingsPopup popup = new MainSettingsPopup(this,mSortMode,mCurrentTheme,mScreenWidth,mScreenHeight);
421
      popup.displayPopup(this,v,sw,sh,((vw-sw)/2),0);
420
      MainSettingsPopup popup = new MainSettingsPopup(this,mSortMode,mCurrentTheme,mScreenWidth,sw,sh);
421
      popup.displayPopup(this,v,((vw-sw)/2),0);
422 422
      }
423 423

  
424 424
///////////////////////////////////////////////////////////////////////////////////////////////////
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 )
src/main/res/layout/settings_popup.xml
11 11
        android:layout_width="match_parent"
12 12
        android:layout_height="wrap_content"
13 13
        android:text="@string/settings_title"
14
        android:textSize="34sp"
14 15
        android:background="@color/light_grey"
15 16
        android:gravity="center"/>
16 17

  
......
27 28
            android:layout_width="wrap_content"
28 29
            android:layout_height="match_parent"
29 30
            android:text="@string/sort_by"
31
            android:textSize="24sp"
30 32
            android:gravity="start|center_vertical"/>
31 33

  
32 34
        <Spinner
33 35
            android:id="@+id/sortMethod"
34 36
            android:layout_width="wrap_content"
35 37
            android:layout_height="match_parent"
38
            android:layout_margin="10dip"
36 39
            android:gravity="center|center_vertical"/>
37 40

  
38 41
        <TextView
......
42 45
            android:layout_width="wrap_content"
43 46
            android:layout_height="match_parent"
44 47
            android:text="@string/theme"
48
            android:textSize="24sp"
45 49
            android:gravity="start|center_vertical"/>
46 50

  
47 51
        <Spinner
48 52
            android:id="@+id/themeValue"
49 53
            android:layout_width="wrap_content"
50 54
            android:layout_height="match_parent"
55
            android:layout_margin="10dip"
51 56
            android:gravity="center|center_vertical"/>
52 57

  
53 58
   </GridLayout>
src/main/res/layout/settings_spinner_item.xml
1
<?xml version="1.0" encoding="utf-8"?>
2

  
3
<TextView
4
    xmlns:android="http://schemas.android.com/apk/res/android"
5
    style="?android:attr/spinnerItemStyle"
6
    android:layout_width="80dp"
7
    android:layout_height="wrap_content"
8
    android:textSize="24sp"
9
    android:gravity="end"
10
    android:singleLine="true"
11
    android:textColor="#FFFFFF"
12
    />

Also available in: Unified diff