From 29a52ea89dc7259c7bed4b4cc1dd6297f18604eb Mon Sep 17 00:00:00 2001 From: Loic Blot Date: Tue, 24 Mar 2015 19:42:31 +0100 Subject: [PATCH] First commit: import sources for our lib --- src/fr/nrz/androidlib/common/SharedPrefs.java | 23 ++++++++ .../notifications/NrzNotification.java | 57 +++++++++++++++++++ 2 files changed, 80 insertions(+) create mode 100644 src/fr/nrz/androidlib/common/SharedPrefs.java create mode 100644 src/fr/nrz/androidlib/notifications/NrzNotification.java diff --git a/src/fr/nrz/androidlib/common/SharedPrefs.java b/src/fr/nrz/androidlib/common/SharedPrefs.java new file mode 100644 index 0000000..638fc60 --- /dev/null +++ b/src/fr/nrz/androidlib/common/SharedPrefs.java @@ -0,0 +1,23 @@ +package fr.nrz.androidlib.common; + +import android.content.Context; +import android.content.SharedPreferences; +import android.content.SharedPreferences.Editor; + +public class SharedPrefs { + + protected final SharedPreferences _sPrefs; + protected final Context _context; + + public SharedPrefs(final Context context, final int prefFile) { + _context = context; + + _sPrefs = _context.getSharedPreferences(_context.getString(prefFile), Context.MODE_PRIVATE); + } + + public void putBoolean(final String prefKey, final Boolean boolValue) { + final Editor edit = _sPrefs.edit(); + edit.putBoolean(prefKey, boolValue); + edit.commit(); + } +} diff --git a/src/fr/nrz/androidlib/notifications/NrzNotification.java b/src/fr/nrz/androidlib/notifications/NrzNotification.java new file mode 100644 index 0000000..3a1231a --- /dev/null +++ b/src/fr/nrz/androidlib/notifications/NrzNotification.java @@ -0,0 +1,57 @@ +package fr.nrz.androidlib.notifications; + +/* + * Copyright (c) 2014-2015, Loic Blot + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +import android.annotation.TargetApi; +import android.app.Notification; +import android.app.Notification.Builder; +import android.app.NotificationManager; +import android.content.Context; +import android.os.Build; + +public class NrzNotification { + public NrzNotification(final Context ct, final int iconId) { + _iconId = iconId; + _ct = ct; + } + + @TargetApi(Build.VERSION_CODES.JELLY_BEAN) + public boolean createNotify(final int nType, final String nTitle, final String nText) { + if (_ct == null) { + return false; + } + final NotificationManager notificationManager = (NotificationManager)_ct.getSystemService(Context.NOTIFICATION_SERVICE); + + final Builder mBuilder = new Notification.Builder(_ct) + .setContentText(nText) + .setContentTitle(nTitle) + .setSmallIcon(_iconId); + + notificationManager.notify(nType, mBuilder.build()); + return true; + } + + @TargetApi(Build.VERSION_CODES.JELLY_BEAN) + public void cancelNotify(final int nType) { + final NotificationManager notificationManager = (NotificationManager)_ct.getSystemService(Context.NOTIFICATION_SERVICE); + notificationManager.cancel(nType); + } + + private final Context _ct; + private final int _iconId; +}