From fa5c333db4bd5b7c782efcd769dc63cfa5700cc6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20F=C3=BClling?= Date: Fri, 24 Apr 2020 19:50:51 +0200 Subject: [PATCH] fix crash when displaying toasts --- .../main/java/io/lerk/lrkFM/VibratingToast.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/io/lerk/lrkFM/VibratingToast.java b/app/src/main/java/io/lerk/lrkFM/VibratingToast.java index 0d9bf175..c7e75c3f 100644 --- a/app/src/main/java/io/lerk/lrkFM/VibratingToast.java +++ b/app/src/main/java/io/lerk/lrkFM/VibratingToast.java @@ -1,12 +1,10 @@ package io.lerk.lrkFM; import android.content.Context; -import android.content.res.Resources; import android.os.Vibrator; +import android.util.Log; import android.widget.Toast; -import androidx.preference.PreferenceManager; - import io.lerk.lrkFM.consts.PreferenceEntity; /** @@ -18,6 +16,8 @@ */ public class VibratingToast extends Toast { + private static final String TAG = VibratingToast.class.getCanonicalName(); + /** * Constructor. Calling this will also show the toast. * @@ -32,8 +32,12 @@ public VibratingToast(Context context, CharSequence text, int toastDuration) { if (new Pref(PreferenceEntity.VIBRATING_TOASTS).getValue()) { Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE); if (vibrator != null) { - int duration = Integer.parseInt(new Pref(PreferenceEntity.VIBRATION_LENGTH).getValue()); - vibrator.vibrate(duration); + try { + int duration = Integer.parseInt(new Pref(PreferenceEntity.VIBRATION_LENGTH).getValue()); + vibrator.vibrate(duration); + } catch (NumberFormatException e) { + Log.w(TAG, "Unable to parse vibration length."); + } } } makeText(context, text, toastDuration).show();