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

The following examples show how to use android.app.NotificationChannel#shouldVibrate() . 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: NotificationChannels.java    From mollyim-android with GNU General Public License v3.0 6 votes vote down vote up
/**
 * @return The vibrate setting for a specific recipient. If that recipient has no channel, this
 *         will return the setting for the default message channel.
 */
public static synchronized boolean getMessageVibrate(@NonNull Context context, @NonNull Recipient recipient) {
  if (!supported()) {
    return getMessageVibrate(context);
  }

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

  if (!channelExists(channel)) {
    Log.w(TAG, "Recipient didn't have a channel. Returning message default.");
    return getMessageVibrate(context);
  }

  return channel.shouldVibrate();
}
 
Example 2
Source File: RankingHelper.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
@VisibleForTesting
void lockFieldsForUpdate(NotificationChannel original, NotificationChannel update) {
    if (original.canBypassDnd() != update.canBypassDnd()) {
        update.lockFields(NotificationChannel.USER_LOCKED_PRIORITY);
    }
    if (original.getLockscreenVisibility() != update.getLockscreenVisibility()) {
        update.lockFields(NotificationChannel.USER_LOCKED_VISIBILITY);
    }
    if (original.getImportance() != update.getImportance()) {
        update.lockFields(NotificationChannel.USER_LOCKED_IMPORTANCE);
    }
    if (original.shouldShowLights() != update.shouldShowLights()
            || original.getLightColor() != update.getLightColor()) {
        update.lockFields(NotificationChannel.USER_LOCKED_LIGHTS);
    }
    if (!Objects.equals(original.getSound(), update.getSound())) {
        update.lockFields(NotificationChannel.USER_LOCKED_SOUND);
    }
    if (!Arrays.equals(original.getVibrationPattern(), update.getVibrationPattern())
            || original.shouldVibrate() != update.shouldVibrate()) {
        update.lockFields(NotificationChannel.USER_LOCKED_VIBRATION);
    }
    if (original.canShowBadge() != update.canShowBadge()) {
        update.lockFields(NotificationChannel.USER_LOCKED_SHOW_BADGE);
    }
}
 
Example 3
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 4
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;
}