mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-09 05:24:44 +01:00
new file (forgotten earlier)
This commit is contained in:
parent
67fa27069a
commit
2d91c133a8
1 changed files with 72 additions and 0 deletions
|
@ -0,0 +1,72 @@
|
||||||
|
/* -*- compile-command: "find-and-gradle.sh insXw4Deb"; -*- */
|
||||||
|
/*
|
||||||
|
* Copyright 2010 - 2014 by Eric House (xwords@eehouse.org). All
|
||||||
|
* rights reserved.
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU General Public License as
|
||||||
|
* published by the Free Software Foundation; either version 2 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
|
||||||
|
* General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.eehouse.android.xw4;
|
||||||
|
|
||||||
|
import android.os.Build;
|
||||||
|
import android.content.Context;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
import android.app.NotificationChannel;
|
||||||
|
import android.app.NotificationManager;
|
||||||
|
|
||||||
|
public class Channels {
|
||||||
|
|
||||||
|
enum ID {
|
||||||
|
FOREGROUND(R.string.foreground_channel_expl,
|
||||||
|
NotificationManager.IMPORTANCE_LOW),
|
||||||
|
GAME_EVENT(R.string.gameevent_channel_expl,
|
||||||
|
NotificationManager.IMPORTANCE_LOW);
|
||||||
|
|
||||||
|
private int mExpl;
|
||||||
|
private int mImportance;
|
||||||
|
private ID( int expl, int imp )
|
||||||
|
{
|
||||||
|
mExpl = expl;
|
||||||
|
mImportance = imp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getDesc() { return mExpl; }
|
||||||
|
private int getImportance() { return mImportance; }
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Set<ID> sChannelsMade = new HashSet<>();
|
||||||
|
public static String getChannelID( Context context, ID id )
|
||||||
|
{
|
||||||
|
final String name = id.toString();
|
||||||
|
if ( ! sChannelsMade.contains( id ) ) {
|
||||||
|
sChannelsMade.add( id );
|
||||||
|
if ( Build.VERSION.SDK_INT >= Build.VERSION_CODES.O ) {
|
||||||
|
NotificationManager notMgr = (NotificationManager)
|
||||||
|
context.getSystemService( Context.NOTIFICATION_SERVICE );
|
||||||
|
|
||||||
|
NotificationChannel channel = notMgr.getNotificationChannel( name );
|
||||||
|
if ( channel == null ) {
|
||||||
|
String channelDescription = context.getString( id.getDesc() );
|
||||||
|
channel = new NotificationChannel( name, channelDescription,
|
||||||
|
id.getImportance() );
|
||||||
|
channel.enableVibration( true );
|
||||||
|
notMgr.createNotificationChannel( channel );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue