Project

General

Profile

« Previous | Next » 

Revision 255492a0

Added by Leszek Koltunski over 2 years ago

Improvements for the PopupWindows: now they work:

1) on Android 11, everywhere
2) on Android 10,9,8.1,8.0 - in case of fullscreen and split-screen modes; pop-up mode still does not work.
3) on Android <= 7.0 : there should be no pop-up mode, so they should be working in all cases

View differences:

src/main/java/org/distorted/screens/RubikScreenPlay.java
22 22
import android.content.Context;
23 23
import android.content.SharedPreferences;
24 24
import android.graphics.drawable.BitmapDrawable;
25
import android.os.Build;
25 26
import android.os.Bundle;
26 27
import android.util.TypedValue;
28
import android.view.Gravity;
27 29
import android.view.LayoutInflater;
28 30
import android.view.View;
29 31
import android.widget.Button;
......
74 76
  private float mButtonSize, mMenuItemSize, mMenuTextSize;
75 77
  private int mColCount, mRowCount, mMaxRowCount;
76 78
  private LinearLayout mPlayLayout;
79
  private int mUpperBarHeight;
80

  
81
  private boolean mIsFullScreen;
77 82

  
78 83
///////////////////////////////////////////////////////////////////////////////////////////////////
79 84

  
......
88 93
    {
89 94
    float width = act.getScreenWidthInPixels();
90 95
    float height= act.getScreenHeightInPixels();
96
    mUpperBarHeight = act.getHeightUpperBar();
91 97

  
92 98
    mMenuTextSize = width*RubikActivity.MENU_MED_TEXT_SIZE;
93 99
    mButtonSize   = width*RubikActivity.BUTTON_TEXT_SIZE;
......
121 127
  private void setupObjectButton(final RubikActivity act, final float width)
122 128
    {
123 129
    final int margin  = (int)(width*RubikActivity.MARGIN);
124
    final int upperBarHeight = act.getHeightUpperBar();
125 130
    final int icon = RubikActivity.getDrawable(R.drawable.ui_small_cube_menu,R.drawable.ui_medium_cube_menu, R.drawable.ui_big_cube_menu, R.drawable.ui_huge_cube_menu);
126 131

  
127 132
    mObjButton = new TransparentImageButton(act, icon, width,LinearLayout.LayoutParams.MATCH_PARENT);
......
136 141
          int rowCount = Math.min(mMaxRowCount,mRowCount);
137 142
          View popupView = mObjectPopup.getContentView();
138 143
          popupView.setSystemUiVisibility(RubikActivity.FLAGS);
139

  
140
          view.getLocationOnScreen(mLocation);
141
          final int x = mLocation[0];
142
          final int y = mLocation[1]+upperBarHeight+margin;
143

  
144
          mObjectPopup.showAsDropDown(view);
145
          mObjectPopup.update(x,y,mObjectSize*mColCount,mObjectSize*rowCount);
144
          displayPopup(act,view,mObjectPopup,mObjectSize*mColCount,mObjectSize*rowCount,margin,margin);
146 145
          }
147 146
        }
148 147
      });
......
153 152
  private void setupPlayButton(final RubikActivity act, final float width, final float height)
154 153
    {
155 154
    final int margin   = (int)(width*RubikActivity.MARGIN);
156
    final int upperBarHeight = act.getHeightUpperBar();
157
    final int maxHeight= (int)(0.9f*(height-upperBarHeight) );
155
    final int maxHeight= (int)(0.9f*(height-mUpperBarHeight) );
158 156

  
159 157
    mPlayButton = new TransparentButton(act, R.string.play, mButtonSize, width);
160 158

  
......
167 165
          {
168 166
          View popupView = mPlayPopup.getContentView();
169 167
          popupView.setSystemUiVisibility(RubikActivity.FLAGS);
170

  
171
          view.getLocationOnScreen(mLocation);
172
          int width = view.getWidth();
173

  
174 168
          final int sizeIndex = ObjectList.getSizeIndex(mObject,mSize);
175 169
          final int dbLevel = ObjectList.getDBLevel(mObject, sizeIndex);
176 170
          final int levelsShown = Math.min(dbLevel,LEVELS_SHOWN);
177 171
          final int popupHeight = (int)(levelsShown*(mMenuItemSize+margin)+3*margin+mMenuItemSize*(LAST_BUTTON-1.0f));
178
          final int realHeight  = Math.min(popupHeight,maxHeight);
179
          final int x = mLocation[0]+width-mPlayLayoutWidth;
180
          final int y = mLocation[1]+upperBarHeight+margin;
181

  
182
          mPlayPopup.showAsDropDown(view);
183
          mPlayPopup.update(x,y,mPlayLayoutWidth,realHeight);
172
          final int realHeight = Math.min(popupHeight,maxHeight);
173
          displayPopup(act,view,mPlayPopup,mPlayLayoutWidth,realHeight,margin,margin);
184 174
          }
185 175
        }
186 176
      });
......
192 182
    {
193 183
    final int margin  = (int)(width*RubikActivity.MARGIN);
194 184
    final int icon = RubikActivity.getDrawable(R.drawable.ui_small_menu,R.drawable.ui_medium_menu, R.drawable.ui_big_menu, R.drawable.ui_huge_menu);
195
    final int upperBarHeight = act.getHeightUpperBar();
196 185

  
197 186
    mMenuButton = new TransparentImageButton(act, icon, width,LinearLayout.LayoutParams.MATCH_PARENT);
198 187

  
......
205 194
          {
206 195
          View popupView = mMenuPopup.getContentView();
207 196
          popupView.setSystemUiVisibility(RubikActivity.FLAGS);
208

  
209
          view.getLocationOnScreen(mLocation);
210
          int width = view.getWidth();
211
          final int x = mLocation[0]+(width-mMenuLayoutWidth)/2;
212
          final int y = mLocation[1]+upperBarHeight+margin;
213

  
214
          mMenuPopup.showAsDropDown(view);
215
          mMenuPopup.update(x,y,mMenuLayoutWidth,mMenuLayoutHeight);
197
          displayPopup(act,view,mMenuPopup,mMenuLayoutWidth,mMenuLayoutHeight,(int)(-width/12),margin);
216 198
          }
217 199
        }
218 200
      });
......
228 210
    int cubeWidth = bd.getIntrinsicWidth();
229 211
    int margin = (int)(width*RubikActivity.LARGE_MARGIN);
230 212
    mObjectSize = (int)(cubeWidth + 2*margin + 0.5f);
231
    int upperBarHeight  = act.getHeightUpperBar();
232
    mMaxRowCount = (int)(0.9f*(height-upperBarHeight)/mObjectSize);
213
    mMaxRowCount = (int)(0.9f*(height-mUpperBarHeight)/mObjectSize);
233 214
    GridLayout objectGrid = new GridLayout(act);
234 215
    mObjectPopup = new PopupWindow(act);
235 216
    mObjectPopup.setFocusable(true);
......
508 489
    return true;
509 490
    }
510 491

  
492
///////////////////////////////////////////////////////////////////////////////////////////////////
493
// work around lame bugs in Android's version <= 10 pop-up and split-screen modes
494

  
495
  private void displayPopup(RubikActivity act, View view, PopupWindow window, int w, int h, int xoff, int yoff)
496
    {
497
    View topLayout = act.findViewById(R.id.relativeLayout);
498
    topLayout.getLocationOnScreen(mLocation);
499
    mIsFullScreen = (mLocation[1]==0);
500

  
501
    // if on Android 11 or we are fullscreen
502
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R || mIsFullScreen )
503
      {
504
      window.showAsDropDown(view, xoff, yoff, Gravity.CENTER);
505
      window.update(view, w, h);
506
      }
507
    else  // Android 10 or below in pop-up mode or split-screen mode
508
      {
509
      view.getLocationOnScreen(mLocation);
510
      int width  = view.getWidth();
511
      int height = view.getHeight();
512
      int x = mLocation[0]+(width-w)/2;
513
      int y = mLocation[1]+height+yoff;
514

  
515
      window.showAsDropDown(view);
516
      window.update(x,y,w,h);
517
      }
518
    }
519

  
511 520
///////////////////////////////////////////////////////////////////////////////////////////////////
512 521

  
513 522
  private void adjustLevels(final RubikActivity act)

Also available in: Unified diff