Added Notification Channels for Android O

This commit is contained in:
Christopher Beckmann 2018-06-13 11:23:51 +02:00
commit 7eff60f078
6 changed files with 54 additions and 5 deletions

View file

@ -8,8 +8,8 @@ android {
applicationId "org.secuso.privacyfriendlybreakreminder"
minSdkVersion 21
targetSdkVersion 27
versionCode 3
versionName "2.1"
versionCode 4
versionName "2.2"
vectorDrawables.useSupportLibrary = true
}
lintOptions {

View file

@ -7,6 +7,7 @@ import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.Bundle;
import android.os.CountDownTimer;
@ -164,6 +165,12 @@ public class ExerciseActivity extends AppCompatActivity implements android.suppo
nextButton = (ImageButton) findViewById(R.id.button_next);
exerciseInfoButton = (ImageButton) findViewById(R.id.exercise_info_button);
Drawable icon = getDrawable(R.drawable.ic_about);
if (icon != null) {
icon.setTint(ActivityCompat.getColor(this, R.color.black));
exerciseInfoButton.setImageDrawable(icon);
}
toast = Toast.makeText(this, "", Toast.LENGTH_SHORT);
toast.setGravity(toast.getGravity(), 0, 250);

View file

@ -1,10 +1,13 @@
package org.secuso.privacyfriendlybreakreminder.activities.adapter;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.preference.PreferenceManager;
import android.support.annotation.NonNull;
import android.support.constraint.ConstraintLayout;
import android.support.v4.app.ActivityCompat;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.util.SortedList;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
@ -154,6 +157,11 @@ public class ExerciseAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
}
});
Drawable icon = mContext.getDrawable(R.drawable.ic_about);
if (icon != null) {
icon.setTint(ActivityCompat.getColor(mContext, R.color.black));
vh.infoButton.setImageDrawable(icon);
}
vh.infoButton.setOnClickListener(infoClick);
}

View file

@ -1,9 +1,17 @@
package org.secuso.privacyfriendlybreakreminder.activities.tutorial;
import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationChannelGroup;
import android.app.NotificationManager;
import android.content.Context;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.graphics.Color;
import android.os.Build;
import android.preference.PreferenceManager;
import android.support.annotation.RequiresApi;
import android.support.v4.app.NotificationCompat;
import org.secuso.privacyfriendlybreakreminder.R;
import org.secuso.privacyfriendlybreakreminder.database.SQLiteHelper;
@ -84,9 +92,35 @@ public class FirstLaunchManager {
.apply();
loadInitialExerciseSets();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
createNotificationChannels();
}
}
}
@RequiresApi(api = Build.VERSION_CODES.O)
private void createNotificationChannels() {
String groupId = "timer_group";
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
// group
notificationManager.createNotificationChannelGroup(new NotificationChannelGroup(groupId, "Timer Notifications"));
// channels
NotificationChannel timerRunningChannel = new NotificationChannel("timer_running", "Timer Running Notification", NotificationManager.IMPORTANCE_DEFAULT);
timerRunningChannel.setVibrationPattern(new long[] { 0 });
timerRunningChannel.setGroup(groupId);
NotificationChannel timerDoneChannel = new NotificationChannel("timer_done", "Timer Done Notification", NotificationManager.IMPORTANCE_HIGH);
timerDoneChannel.setVibrationPattern(new long[] { 0, 1000, 1000, 1000, 1000, 1000, 1000 });
timerDoneChannel.setGroup(groupId);
notificationManager.createNotificationChannel(timerRunningChannel);
notificationManager.createNotificationChannel(timerDoneChannel);
}
private void loadInitialExerciseSets() {
Cursor setCursor = dbHandler.getExerciseSetsCursor();

View file

@ -104,7 +104,7 @@ public class TimerService extends Service {
PendingIntent startExercises = PendingIntent.getActivity(this, 0, new Intent(this, ExerciseActivity.class), FLAG_CANCEL_CURRENT);
PendingIntent snoozeExercise = PendingIntent.getService(this, 0, snoozeIntent, FLAG_UPDATE_CURRENT);
NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
NotificationCompat.Builder builder = new NotificationCompat.Builder(this, "timer_done");
builder.setContentTitle(getString(R.string.app_name))
.setContentText(getString(R.string.take_a_break_now))
.setContentIntent(startExercises)
@ -293,7 +293,7 @@ public class TimerService extends Service {
private Notification buildNotification() {
NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
NotificationCompat.Builder builder = new NotificationCompat.Builder(this, "timer_running");
builder.setContentTitle(getString(R.string.app_name));
int secondsUntilFinished = (int) Math.ceil(remainingDuration / 1000.0);

View file

@ -70,7 +70,7 @@
<!-- Preference Text -->
<string name="pref_exercise_time">Übungszeit (in Sekunden)</string>
<string name="pref_keep_screen_on_during_exercise">Bildschirm bleibt an während der Übungen</string>
<string name="pref_keep_screen_on_during_exercise">Bildschirm bleibt an während Übungen</string>
<string name="pref_category_exercise">Übungseinstellungen</string>
<string name="pref_category_schedule">Zeitplan für Arbeits- und Übungstimer</string>
<string name="pref_schedule_exercise_switch">Zeitpläne aktivieren</string>