Skip to content
This repository has been archived by the owner on Oct 3, 2024. It is now read-only.

Commit

Permalink
fix crash when displaying toasts
Browse files Browse the repository at this point in the history
  • Loading branch information
lfuelling committed Apr 24, 2020
1 parent e83cf64 commit fa5c333
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions app/src/main/java/io/lerk/lrkFM/VibratingToast.java
Original file line number Diff line number Diff line change
@@ -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;

/**
Expand All @@ -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.
*
Expand All @@ -32,8 +32,12 @@ public VibratingToast(Context context, CharSequence text, int toastDuration) {
if (new Pref<Boolean>(PreferenceEntity.VIBRATING_TOASTS).getValue()) {
Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
if (vibrator != null) {
int duration = Integer.parseInt(new Pref<String>(PreferenceEntity.VIBRATION_LENGTH).getValue());
vibrator.vibrate(duration);
try {
int duration = Integer.parseInt(new Pref<String>(PreferenceEntity.VIBRATION_LENGTH).getValue());
vibrator.vibrate(duration);
} catch (NumberFormatException e) {
Log.w(TAG, "Unable to parse vibration length.");
}
}
}
makeText(context, text, toastDuration).show();
Expand Down

0 comments on commit fa5c333

Please sign in to comment.