Java Code Examples for android.app.NotificationChannel#getSound()

The following examples show how to use android.app.NotificationChannel#getSound() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EditNotificationSettingsActivity.java    From revolution-irc with GNU General Public License v3.0 6 votes vote down vote up
private void loadNotificationRuleSettings() {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O ||
            mEditingRule == null || mEditingRule.settings == null ||
            mEditingRule.settings.notificationChannelId == null)
        return;
    android.app.NotificationManager mgr = (android.app.NotificationManager)
            getSystemService(NOTIFICATION_SERVICE);
    NotificationChannel channel =
            mgr.getNotificationChannel(mEditingRule.settings.notificationChannelId);

    mEditingRule.settings.soundEnabled = channel.getSound() != null;
    mEditingRule.settings.soundUri = null;
    if (channel.getSound() != null && !channel.getSound().equals(
            RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)))
        mEditingRule.settings.soundUri = channel.getSound().toString();

    mEditingRule.settings.vibrationEnabled = channel.shouldVibrate();
    if (channel.shouldVibrate())
        mEditingRule.settings.vibrationDuration = channel.getVibrationPattern() == null ||
                channel.getVibrationPattern().length != 2
                ? 0 : (int) channel.getVibrationPattern()[1];

    mEditingRule.settings.lightEnabled = channel.shouldShowLights();
    if (channel.shouldShowLights())
        mEditingRule.settings.light = channel.getLightColor();
}
 
Example 2
Source File: NotificationChannels.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
@TargetApi(26)
private static int myhashcode(NotificationChannel x) {

    int result = x.getId() != null ? x.getId().hashCode() : 0;
    //result = 31 * result + (getName() != null ? getName().hashCode() : 0);
    //result = 31 * result + (getDescription() != null ? getDescription().hashCode() : 0);
    //result = 31 * result + getImportance();
    //result = 31 * result + (mBypassDnd ? 1 : 0);
    //result = 31 * result + getLockscreenVisibility();
    result = 31 * result + (x.getSound() != null ? x.getSound().hashCode() : 0);
    //result = 31 * result + (x.mLights ? 1 : 0);
    result = 31 * result + x.getLightColor();
    result = 31 * result + Arrays.hashCode(x.getVibrationPattern());
    //result = 31 * result + getUserLockedFields();
    //result = 31 * result + (mVibrationEnabled ? 1 : 0);
    //result = 31 * result + (mShowBadge ? 1 : 0);
    //result = 31 * result + (isDeleted() ? 1 : 0);
    //result = 31 * result + (getGroup() != null ? getGroup().hashCode() : 0);
    //result = 31 * result + (getAudioAttributes() != null ? getAudioAttributes().hashCode() : 0);
    //result = 31 * result + (isBlockableSystem() ? 1 : 0);
    return result;

}
 
Example 3
Source File: NotificationChannels.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
@TargetApi(26)
public static boolean isSoundDifferent(String id, NotificationChannel x) {
    if (x.getSound() == null) return false; // this does not have a sound
    final NotificationChannel c = getNotifManager().getNotificationChannel(id);
    if (c == null) return false; // no channel with this id
    if (c.getSound() == null)
        return false; // this maybe will only happen if user disables sound so lets not create a new one in that case

    final String original_sound = PersistentStore.getString("original-channel-sound-" + id);
    if (original_sound.equals("")) {
        PersistentStore.setString("original-channel-sound-" + id, x.getSound().toString());
        return false; // no existing record so save the original and do nothing else
    }
    if (original_sound.equals(x.getSound().toString()))
        return false; // its the same sound still
    return true; // the sound has changed vs the original
}
 
Example 4
Source File: NotificationChannels.java    From xDrip-plus with GNU General Public License v3.0 6 votes vote down vote up
@TargetApi(26)
private static int myhashcode(NotificationChannel x) {

    int result = x.getId() != null ? x.getId().hashCode() : 0;
    //result = 31 * result + (getName() != null ? getName().hashCode() : 0);
    //result = 31 * result + (getDescription() != null ? getDescription().hashCode() : 0);
    //result = 31 * result + getImportance();
    //result = 31 * result + (mBypassDnd ? 1 : 0);
    //result = 31 * result + getLockscreenVisibility();
    result = 31 * result + (x.getSound() != null ? x.getSound().hashCode() : 0);
    //result = 31 * result + (x.mLights ? 1 : 0);
    result = 31 * result + x.getLightColor();
    result = 31 * result + Arrays.hashCode(x.getVibrationPattern());
    //result = 31 * result + getUserLockedFields();
    //result = 31 * result + (mVibrationEnabled ? 1 : 0);
    //result = 31 * result + (mShowBadge ? 1 : 0);
    //result = 31 * result + (isDeleted() ? 1 : 0);
    //result = 31 * result + (getGroup() != null ? getGroup().hashCode() : 0);
    //result = 31 * result + (getAudioAttributes() != null ? getAudioAttributes().hashCode() : 0);
    //result = 31 * result + (isBlockableSystem() ? 1 : 0);
    return result;

}
 
Example 5
Source File: NotificationChannels.java    From xDrip-plus with GNU General Public License v3.0 6 votes vote down vote up
@TargetApi(26)
public static boolean isSoundDifferent(String id, NotificationChannel x) {
    if (x.getSound() == null) return false; // this does not have a sound
    final NotificationChannel c = getNotifManager().getNotificationChannel(id);
    if (c == null) return false; // no channel with this id
    if (c.getSound() == null)
        return false; // this maybe will only happen if user disables sound so lets not create a new one in that case

    final String original_sound = PersistentStore.getString("original-channel-sound-" + id);
    if (original_sound.equals("")) {
        PersistentStore.setString("original-channel-sound-" + id, x.getSound().toString());
        return false; // no existing record so save the original and do nothing else
    }
    if (original_sound.equals(x.getSound().toString()))
        return false; // its the same sound still
    return true; // the sound has changed vs the original
}
 
Example 6
Source File: NotificationChannels.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
public static synchronized @Nullable Uri getMessageRingtone(@NonNull Context context, @NonNull Recipient recipient) {
  if (!supported() || recipient.resolve().getNotificationChannel() == null) {
    return null;
  }

  NotificationManager notificationManager = ServiceUtil.getNotificationManager(context);
  NotificationChannel channel             = notificationManager.getNotificationChannel(recipient.getNotificationChannel());

  if (!channelExists(channel)) {
    Log.w(TAG, "Recipient had no channel. Returning null.");
    return null;
  }

  return channel.getSound();
}
 
Example 7
Source File: ActivitySetup.java    From FairEmail with GNU General Public License v3.0 5 votes vote down vote up
@RequiresApi(api = Build.VERSION_CODES.O)
private JSONObject channelToJSON(NotificationChannel channel) throws JSONException {
    JSONObject jchannel = new JSONObject();

    jchannel.put("id", channel.getId());
    jchannel.put("group", channel.getGroup());
    jchannel.put("name", channel.getName());
    jchannel.put("description", channel.getDescription());

    jchannel.put("importance", channel.getImportance());
    jchannel.put("dnd", channel.canBypassDnd());
    jchannel.put("visibility", channel.getLockscreenVisibility());
    jchannel.put("badge", channel.canShowBadge());

    Uri sound = channel.getSound();
    if (sound != null)
        jchannel.put("sound", sound.toString());
    // audio attributes

    jchannel.put("light", channel.shouldShowLights());
    // color

    jchannel.put("vibrate", channel.shouldVibrate());
    // pattern

    return jchannel;
}
 
Example 8
Source File: EditNotificationSettingsActivity.java    From revolution-irc with GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("DoubleNegation")
private boolean hasNotificationRuleChanges() {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O ||
            mEditingRule == null || mEditingRule.settings.notificationChannelId == null)
        return false;
    android.app.NotificationManager mgr = (android.app.NotificationManager)
            getSystemService(NOTIFICATION_SERVICE);
    NotificationChannel channel =
            mgr.getNotificationChannel(mEditingRule.settings.notificationChannelId);

    Uri soundUri = mSoundEntry.getValue();
    if (channel.getSound() != soundUri &&
            (channel.getSound() == null || !channel.getSound().equals(soundUri)))
        return true;

    int vibrationDuration = mVibrationOptions[mVibrationEntry.getSelectedOption()];
    if (channel.shouldVibrate() != (vibrationDuration != 0))
        return true;
    if (channel.shouldVibrate()) {
        int channelVibrationDuration = channel.getVibrationPattern() == null ||
                channel.getVibrationPattern().length != 2
                ? -1 : (int) channel.getVibrationPattern()[1];
        if (channelVibrationDuration != vibrationDuration)
            return true;
    }

    if (channel.shouldShowLights() != (mColorEntry.getSelectedColorIndex() != 0))
        return true;
    //noinspection RedundantIfStatement
    if (channel.shouldShowLights() && channel.getLightColor() !=
            (mColorEntry.getSelectedColorIndex() == -1 ? 0 : mColorEntry.getSelectedColor()))
        return true;

    return false;
}