Skip to content

Commit 7dabc57

Browse files
committed
top-down info snackbar
1 parent 8bcdf11 commit 7dabc57

File tree

4 files changed

+34
-17
lines changed

4 files changed

+34
-17
lines changed

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

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
import android.content.Context;
1010
import android.content.DialogInterface;
1111
import android.content.pm.PackageManager;
12+
import android.os.Handler;
13+
import android.os.Looper;
1214
import android.os.SystemClock;
1315
import android.os.Vibrator;
1416
import android.support.annotation.StringRes;
@@ -55,6 +57,8 @@ public class SelfScanningView extends CoordinatorLayout implements Checkout.OnCh
5557
private boolean ignoreNextDialog;
5658
private ShoppingCart shoppingCart;
5759
private boolean allowShowingHints;
60+
private TextView info;
61+
private Handler infoHandler = new Handler(Looper.getMainLooper());
5862

5963
public SelfScanningView(Context context) {
6064
super(context);
@@ -80,6 +84,16 @@ private void inflateView() {
8084

8185
barcodeScanner = findViewById(R.id.barcode_scanner_view);
8286
noPermission = findViewById(R.id.no_permission);
87+
info = findViewById(R.id.info);
88+
info.setVisibility(View.GONE);
89+
info.addOnLayoutChangeListener(new OnLayoutChangeListener() {
90+
@Override
91+
public void onLayoutChange(View view, int left, int top, int right, int bottom,
92+
int oldLeft, int oldTop, int oldRight, int oldBottom) {
93+
info.setTranslationY(-info.getHeight());
94+
info.setVisibility(View.VISIBLE);
95+
}
96+
});
8397

8498
enterBarcode = findViewById(R.id.enter_barcode);
8599
TextView light = findViewById(R.id.light);
@@ -269,12 +283,17 @@ private void handleProductError() {
269283
}
270284

271285
private void showInfo(@StringRes int resId) {
272-
UIUtils.info(getContext(), resId, new DialogInterface.OnDismissListener() {
286+
info.setVisibility(View.VISIBLE);
287+
info.setText(resId);
288+
info.animate().translationY(0).start();
289+
290+
infoHandler.removeCallbacksAndMessages(null);
291+
infoHandler.postDelayed(new Runnable() {
273292
@Override
274-
public void onDismiss(DialogInterface dialog) {
275-
resumeBarcodeScanner();
293+
public void run() {
294+
info.animate().translationY(-info.getHeight()).start();
276295
}
277-
});
296+
}, UIUtils.SNACKBAR_LENGTH_VERY_LONG);
278297
}
279298

280299
private void onClickEnterBarcode() {

ui/src/main/java/io/snabble/sdk/ui/utils/UIUtils.java

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,19 @@
33
import android.app.Activity;
44
import android.content.Context;
55
import android.content.ContextWrapper;
6-
import android.content.DialogInterface;
76
import android.graphics.Color;
87
import android.os.Build;
98
import android.support.annotation.StringRes;
109
import android.support.design.widget.Snackbar;
11-
import android.support.v7.app.AlertDialog;
1210
import android.text.Spannable;
1311
import android.text.SpannableString;
1412
import android.text.style.ForegroundColorSpan;
1513
import android.view.View;
1614
import android.widget.TextView;
1715

18-
import io.snabble.sdk.ui.R;
19-
2016
public class UIUtils {
2117
public static final int SNACKBAR_LENGTH_VERY_LONG = 5000;
2218

23-
public static void info(Context context, @StringRes int stringResId, DialogInterface.OnDismissListener onDismissListener) {
24-
new AlertDialog.Builder(context)
25-
.setMessage(stringResId)
26-
.setPositiveButton(R.string.Snabble_OK, null)
27-
.setOnDismissListener(onDismissListener)
28-
.create()
29-
.show();
30-
}
31-
3219
public static Snackbar snackbar(View view, @StringRes int stringResId, int duration) {
3320
Snackbar snackbar = Snackbar.make(view, stringResId, duration);
3421
fixTextColor(snackbar);

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,13 @@
8484
android:textColor="@color/snabble_textColorLight" />
8585
</FrameLayout>
8686
</LinearLayout>
87+
88+
<TextView android:id="@+id/info"
89+
android:layout_width="match_parent"
90+
android:layout_height="wrap_content"
91+
android:background="@color/snabble_infoColor"
92+
android:textColor="@color/snabble_infoTextColor"
93+
android:gravity="center"
94+
tools:text="Unfortunately we could not query the product, please check your internet connection."
95+
android:padding="16dp" />
8796
</merge>

ui/src/main/res/values/colors.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
<color name="snabble_primaryColorDark">#008DCC</color>
66
<color name="snabble_primaryColorLight">#33C0FF</color>
77
<color name="snabble_accentColor">@color/snabble_primaryColor</color>
8+
<color name="snabble_infoColor">#FFC400</color>
9+
<color name="snabble_infoTextColor">@color/snabble_textColorDark</color>
810
<color name="snabble_textColorLight">#FFFFFF</color>
911
<color name="snabble_textColorDark">#1D1F24</color>
1012
<color name="snabble_textColorAction">@color/snabble_primaryColor</color>

0 commit comments

Comments
 (0)