42
42
import com .pranavpandey .android .dynamic .util .DynamicSdkUtils ;
43
43
import com .pranavpandey .android .dynamic .util .DynamicUnitUtils ;
44
44
import com .pranavpandey .android .dynamic .util .DynamicViewUtils ;
45
+ import com .pranavpandey .android .dynamic .util .DynamicWindowUtils ;
45
46
46
47
import java .lang .annotation .Retention ;
47
48
import java .lang .annotation .RetentionPolicy ;
@@ -225,6 +226,16 @@ protected int getMaxWidth() {
225
226
.getDimension (R .dimen .ads_popup_max_width );
226
227
}
227
228
229
+ /**
230
+ * The offset to adjust the size of the window if enough space is not available.
231
+ *
232
+ * @return The offset to adjust the size of the window if enough space is not available.
233
+ */
234
+ protected int getSizeOffset () {
235
+ return (int ) getAnchor ().getContext ().getResources ()
236
+ .getDimension (R .dimen .ads_popup_offset );
237
+ }
238
+
228
239
/**
229
240
* This method will be called just before showing this popup.
230
241
*
@@ -318,7 +329,7 @@ public void run() {
318
329
Dynamic .setVisibility (content , View .GONE );
319
330
}
320
331
321
- mPopupWindow = new PopupWindow (view , getMaxWidth () ,
332
+ mPopupWindow = new PopupWindow (view , LinearLayout . LayoutParams . WRAP_CONTENT ,
322
333
LinearLayout .LayoutParams .WRAP_CONTENT , true );
323
334
PopupWindowCompat .setWindowLayoutType (mPopupWindow ,
324
335
WindowManager .LayoutParams .TYPE_APPLICATION_SUB_PANEL );
@@ -327,6 +338,11 @@ public void run() {
327
338
mPopupWindow .setBackgroundDrawable (new ColorDrawable (Color .TRANSPARENT ));
328
339
mPopupWindow .setAnimationStyle (R .style .Animation_AppCompat_DropDownUp );
329
340
341
+ if (getMaxWidth () + getSizeOffset ()
342
+ < DynamicWindowUtils .getAppUsableScreenSize (getAnchor ().getContext ()).x ) {
343
+ mPopupWindow .setWidth (getMaxWidth ());
344
+ }
345
+
330
346
if (getAnchor ().getRootView () != null ) {
331
347
try {
332
348
TransitionManager .endTransitions ((ViewGroup ) getAnchor ().getRootView ());
@@ -343,7 +359,7 @@ public void run() {
343
359
344
360
// Check for RTL language.
345
361
if (DynamicViewUtils .isLayoutRtl (getAnchor ())) {
346
- viewCenterX = viewCenterX + getAnchor ().getWidth () - getMaxWidth ();
362
+ viewCenterX = viewCenterX + getAnchor ().getWidth () - mPopupWindow . getWidth ();
347
363
OFFSET_X = -OFFSET_X ;
348
364
}
349
365
0 commit comments