Commit 1953fa47 authored by Robert Hitt's avatar Robert Hitt

Vibrations can now be turned off/on

parent 4c5d51d5
......@@ -5,6 +5,7 @@
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.VIBRATE"/>
<application
android:name=".MyApplication"
android:allowBackup="true"
......
......@@ -4,6 +4,9 @@ import android.app.IntentService;
import android.app.NotificationManager;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Vibrator;
import android.preference.PreferenceManager;
import android.support.v4.app.NotificationCompat;
import android.support.v4.content.WakefulBroadcastReceiver;
......@@ -22,16 +25,33 @@ public class NotificationService extends IntentService {
String text = intent.getStringExtra("text");
int id = intent.getIntExtra("id", 0);
displayNotification(title, text, id);
setVibration();
WakefulBroadcastReceiver.completeWakefulIntent(intent);
}
private void displayNotification(String title, String text, int id) {
NotificationCompat.Builder builder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_access_time_black_24dp)
.setContentTitle(title)
.setContentText(text);
.setSmallIcon(R.drawable.ic_access_time_black_24dp)
.setContentTitle(title)
.setContentText(text);
NotificationManager notificationManager = (NotificationManager)
getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(id, builder.build());
WakefulBroadcastReceiver.completeWakefulIntent(intent);
}
private void setVibration() {
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
boolean vibrationsOff = preferences.getBoolean("turn_off_vibrations_preference", false);
if(!vibrationsOff) {
Vibrator v = (Vibrator) this.getApplicationContext()
.getSystemService(Context.VIBRATOR_SERVICE);
v.vibrate(400);
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment