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

Commit

Permalink
add nullcheck for vibrator
Browse files Browse the repository at this point in the history
  • Loading branch information
lfuelling committed Sep 25, 2019
1 parent 4dde4a5 commit 822f5f2
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions app/src/main/java/io/lerk/lrkFM/VibratingToast.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
import android.content.Context;
import android.os.Vibrator;
import android.widget.Toast;

import io.lerk.lrkFM.consts.PreferenceEntity;

/**
* Vibrating Toast.
*
* <p>
* Based on: https://stackoverflow.com/a/6109644/1979736
*
* @author Lukas Fülling ([email protected])
Expand All @@ -16,8 +17,11 @@ public class VibratingToast extends Toast {

public VibratingToast(Context context, CharSequence text, int duration) {
super(context);
if(new Pref<Boolean>(PreferenceEntity.VIBRATING_TOASTS).getValue()) {
((Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE)).vibrate(120);
if (new Pref<Boolean>(PreferenceEntity.VIBRATING_TOASTS).getValue()) {
Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
if (vibrator != null) {
vibrator.vibrate(120);
}
}
makeText(context, text, duration).show();
}
Expand Down

0 comments on commit 822f5f2

Please sign in to comment.