mirror of
https://github.com/nerzhul/nrz-androidlib.git
synced 2025-06-07 16:06:21 +00:00
First commit: import sources for our lib
This commit is contained in:
commit
29a52ea89d
23
src/fr/nrz/androidlib/common/SharedPrefs.java
Normal file
23
src/fr/nrz/androidlib/common/SharedPrefs.java
Normal file
@ -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();
|
||||
}
|
||||
}
|
57
src/fr/nrz/androidlib/notifications/NrzNotification.java
Normal file
57
src/fr/nrz/androidlib/notifications/NrzNotification.java
Normal file
@ -0,0 +1,57 @@
|
||||
package fr.nrz.androidlib.notifications;
|
||||
|
||||
/*
|
||||
* Copyright (c) 2014-2015, Loic Blot <loic.blot@unix-experience.fr>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user