Skip to content

Commit deaf487

Browse files
committed
improved display scaling of product dialog
1 parent e58bb60 commit deaf487

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

ui/src/main/java/io/snabble/sdk/ui/scanner/ProductConfirmationDialog.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import android.text.Editable;
1111
import android.text.InputFilter;
1212
import android.text.TextWatcher;
13+
import android.util.DisplayMetrics;
1314
import android.view.Gravity;
1415
import android.view.KeyEvent;
1516
import android.view.View;
@@ -257,8 +258,14 @@ public void run() {
257258
});
258259
}
259260

260-
float density = context.getResources().getDisplayMetrics().density;
261-
window.setLayout(Math.round(320 * density), ViewGroup.LayoutParams.WRAP_CONTENT);
261+
DisplayMetrics dm = context.getResources().getDisplayMetrics();
262+
int availableWidth = Math.round(dm.widthPixels / dm.density);
263+
int width = Math.round(320 * dm.density);
264+
if(availableWidth >= 336) {
265+
width = Math.round(336 * dm.density);
266+
}
267+
268+
window.setLayout(width, ViewGroup.LayoutParams.WRAP_CONTENT);
262269
}
263270

264271
private void updatePrice() {

ui/src/main/res/layout/dialog_product_confirmation.xml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
33
xmlns:app="http://schemas.android.com/apk/res-auto"
44
xmlns:tools="http://schemas.android.com/tools"
5-
android:layout_width="304dp"
5+
android:layout_width="288dp"
66
android:layout_height="wrap_content"
77
android:layout_gravity="center"
88
android:focusable="true"
@@ -118,8 +118,10 @@
118118
<android.support.v7.widget.AppCompatButton
119119
android:id="@+id/addToCart"
120120
style="@style/SnabbleButton"
121-
android:layout_width="272dp"
121+
android:layout_width="match_parent"
122122
android:layout_height="wrap_content"
123+
android:layout_marginLeft="16dp"
124+
android:layout_marginRight="16dp"
123125
android:layout_below="@+id/quantity"
124126
android:layout_centerHorizontal="true"
125127
android:text="@string/Snabble.Scanner.addToCart" />

0 commit comments

Comments
 (0)