This commit is contained in:
Mike Schwörer 2018-11-12 17:23:19 +01:00
parent 96a236803e
commit 6cb2aa00fb
Signed by: Mikescher
GPG Key ID: D3C7172E0A70F8CF
4 changed files with 83 additions and 22 deletions

View File

@ -6,6 +6,7 @@
<uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="com.android.vending.BILLING" /> <uses-permission android:name="com.android.vending.BILLING" />
<application <application

View File

@ -6,9 +6,14 @@ import android.app.NotificationManager;
import android.app.PendingIntent; import android.app.PendingIntent;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.media.AudioAttributes;
import android.media.AudioManager; import android.media.AudioManager;
import android.media.Ringtone;
import android.media.RingtoneManager;
import android.net.Uri; import android.net.Uri;
import android.os.Build; import android.os.Build;
import android.os.VibrationEffect;
import android.os.Vibrator;
import android.widget.Toast; import android.widget.Toast;
import com.blackforestbytes.simplecloudnotifier.R; import com.blackforestbytes.simplecloudnotifier.R;
@ -52,36 +57,86 @@ public class NotificationService
if (notifman == null) return; if (notifman == null) return;
NotificationChannel channelLow = notifman.getNotificationChannel(CHANNEL_ID_LOW); NotificationChannel channelLow = notifman.getNotificationChannel(CHANNEL_ID_LOW);
if (channelLow == null) notifman.createNotificationChannel(channelLow = new NotificationChannel(CHANNEL_ID_LOW, "Push notifications (low priority)", NotificationManager.IMPORTANCE_LOW)); if (channelLow == null) notifman.createNotificationChannel(channelLow = new NotificationChannel(CHANNEL_ID_LOW, "Push notifications (0 - low)", NotificationManager.IMPORTANCE_LOW));
NotificationChannel channelNorm = notifman.getNotificationChannel(CHANNEL_ID_NORM); NotificationChannel channelNorm = notifman.getNotificationChannel(CHANNEL_ID_NORM);
if (channelNorm == null) notifman.createNotificationChannel(channelNorm = new NotificationChannel(CHANNEL_ID_NORM, "Push notifications (normal priority)", NotificationManager.IMPORTANCE_DEFAULT)); if (channelNorm == null) notifman.createNotificationChannel(channelNorm = new NotificationChannel(CHANNEL_ID_NORM, "Push notifications (1 - normal)", NotificationManager.IMPORTANCE_DEFAULT));
NotificationChannel channelHigh = notifman.getNotificationChannel(CHANNEL_ID_HIGH); NotificationChannel channelHigh = notifman.getNotificationChannel(CHANNEL_ID_HIGH);
if (channelHigh == null) notifman.createNotificationChannel(channelHigh = new NotificationChannel(CHANNEL_ID_HIGH, "Push notifications (high priority)", NotificationManager.IMPORTANCE_HIGH)); if (channelHigh == null) notifman.createNotificationChannel(channelHigh = new NotificationChannel(CHANNEL_ID_HIGH, "Push notifications (2 - high)", NotificationManager.IMPORTANCE_HIGH));
channelLow.setDescription("Messages from the API with priority set to low"); channelLow.setDescription("Messages from the API with priority set to low");
channelLow.enableLights(SCNSettings.inst().PriorityLow.EnableLED); updateSingleChannel(channelLow, SCNSettings.inst().PriorityLow, PriorityEnum.LOW);
channelLow.setLightColor(SCNSettings.inst().PriorityLow.LEDColor);
channelLow.enableVibration(SCNSettings.inst().PriorityLow.EnableVibration);
channelLow.setVibrationPattern(new long[]{200});
channelNorm.setDescription("Messages from the API with priority set to normal"); channelNorm.setDescription("Messages from the API with priority set to normal");
channelNorm.enableLights(SCNSettings.inst().PriorityNorm.EnableLED); updateSingleChannel(channelNorm, SCNSettings.inst().PriorityNorm, PriorityEnum.NORMAL);
channelNorm.setLightColor(SCNSettings.inst().PriorityNorm.LEDColor);
channelNorm.enableVibration(SCNSettings.inst().PriorityNorm.EnableVibration);
channelNorm.setVibrationPattern(new long[]{200});
channelHigh.setDescription("Messages from the API with priority set to high"); channelHigh.setDescription("Messages from the API with priority set to high");
channelHigh.enableLights(SCNSettings.inst().PriorityHigh.EnableLED); updateSingleChannel(channelHigh, SCNSettings.inst().PriorityHigh, PriorityEnum.HIGH);
channelHigh.setLightColor(SCNSettings.inst().PriorityHigh.LEDColor); }
channelHigh.enableVibration(SCNSettings.inst().PriorityHigh.EnableVibration);
channelHigh.setVibrationPattern(new long[]{200}); private void updateSingleChannel(NotificationChannel c, NotificationSettings s, PriorityEnum p)
channelLow.setBypassDnd(true); {
channelLow.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) return;
c.enableLights(s.EnableLED);
c.setLightColor(s.LEDColor);
c.enableVibration(s.EnableVibration);
c.setVibrationPattern(new long[]{500});
if (s.EnableSound)
{
AudioAttributes attr = new AudioAttributes.Builder()
.setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
.setLegacyStreamType(AudioManager.STREAM_NOTIFICATION)
.setUsage(AudioAttributes.USAGE_NOTIFICATION_EVENT)
.build();
c.setSound(Uri.parse(s.SoundSource), attr);
}
else
{
c.setSound(null, null);
}
if (p == PriorityEnum.HIGH) c.setBypassDnd(true);
if (p == PriorityEnum.HIGH) c.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC);
} }
public void showForeground(CMessage msg) public void showForeground(CMessage msg)
{ {
SCNApp.showToast("Message recieved: " + msg.Title, Toast.LENGTH_LONG); SCNApp.showToast("Message recieved: " + msg.Title, Toast.LENGTH_LONG);
try
{
NotificationSettings ns = SCNSettings.inst().PriorityNorm;
switch (msg.Priority)
{
case LOW: ns = SCNSettings.inst().PriorityLow; break;
case NORMAL: ns = SCNSettings.inst().PriorityNorm; break;
case HIGH: ns = SCNSettings.inst().PriorityHigh; break;
}
if (ns.EnableSound && !ns.SoundSource.isEmpty())
{
Ringtone rt = RingtoneManager.getRingtone(SCNApp.getContext(), Uri.parse(ns.SoundSource));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) rt.setLooping(false);
rt.play();
new Thread(() -> { try { Thread.sleep(2*1000); } catch (InterruptedException e) { /* */ } rt.stop(); }).start();
}
if (ns.EnableVibration)
{
Vibrator v = (Vibrator) SCNApp.getContext().getSystemService(Context.VIBRATOR_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
v.vibrate(VibrationEffect.createOneShot(500, VibrationEffect.DEFAULT_AMPLITUDE));
} else {
v.vibrate(500);
}
}
}
catch (Exception e)
{
e.printStackTrace();
}
} }
public void showBackground(CMessage msg) public void showBackground(CMessage msg)
@ -109,13 +164,13 @@ public class NotificationService
if (msg.Priority == PriorityEnum.LOW) mBuilder.setPriority(NotificationCompat.PRIORITY_LOW); if (msg.Priority == PriorityEnum.LOW) mBuilder.setPriority(NotificationCompat.PRIORITY_LOW);
if (msg.Priority == PriorityEnum.NORMAL) mBuilder.setPriority(NotificationCompat.PRIORITY_DEFAULT); if (msg.Priority == PriorityEnum.NORMAL) mBuilder.setPriority(NotificationCompat.PRIORITY_DEFAULT);
if (msg.Priority == PriorityEnum.HIGH) mBuilder.setPriority(NotificationCompat.PRIORITY_HIGH); if (msg.Priority == PriorityEnum.HIGH) mBuilder.setPriority(NotificationCompat.PRIORITY_HIGH);
if (ns.EnableVibration) mBuilder.setVibrate(new long[]{200}); if (ns.EnableVibration) mBuilder.setVibrate(new long[]{500});
if (ns.EnableLED) mBuilder.setLights(ns.LEDColor, 500, 500); if (ns.EnableLED) mBuilder.setLights(ns.LEDColor, 500, 500);
} }
if (ns.EnableSound && !ns.SoundSource.isEmpty()) if (ns.EnableSound && !ns.SoundSource.isEmpty())
{ {
mBuilder.setSound(Uri.parse(ns.SoundSource), AudioManager.STREAM_ALARM); mBuilder.setSound(Uri.parse(ns.SoundSource), AudioManager.STREAM_NOTIFICATION);
} }
Intent intent = new Intent(ctxt, MainActivity.class); Intent intent = new Intent(ctxt, MainActivity.class);

View File

@ -18,9 +18,9 @@
<string name="str_common_settings">Common Settings</string> <string name="str_common_settings">Common Settings</string>
<string name="str_enabled">Enabled</string> <string name="str_enabled">Enabled</string>
<string name="str_localcachesize">Remember the last x notifications locally</string> <string name="str_localcachesize">Remember the last x notifications locally</string>
<string name="str_header_prio0">Notifications (priority 0)</string> <string name="str_header_prio0">Notifications (priority 0 - Low)</string>
<string name="str_header_prio1">Notifications (priority 1)</string> <string name="str_header_prio1">Notifications (priority 1 - Normal)</string>
<string name="str_header_prio2">Notifications (priority 2)</string> <string name="str_header_prio2">Notifications (priority 2 - High)</string>
<string name="str_msg_enablesound">Enable notification sound</string> <string name="str_msg_enablesound">Enable notification sound</string>
<string name="str_notificationsound">Notification sound</string> <string name="str_notificationsound">Notification sound</string>
<string name="str_repeatnotificationsound">Repeat notification sound</string> <string name="str_repeatnotificationsound">Repeat notification sound</string>

View File

@ -193,6 +193,11 @@ input::-webkit-inner-spin-button {
pointer-events: none; pointer-events: none;
} }
.fullcenterflex .card
{
pointer-events: auto;
}
a.card, a.card,
a.card:active, a.card:active,
a.card:visited, a.card:visited,