<commit_before>/*
 * BRLTTY - A background process providing access to the console screen (when in
 *          text mode) for a blind person using a refreshable braille display.
 *
 * Copyright (C) 1995-2018 by The BRLTTY Developers.
 *
 * BRLTTY comes with ABSOLUTELY NO WARRANTY.
 *
 * This is free software, placed under the terms of the
 * GNU Lesser General Public License, as published by the Free Software
 * Foundation; either version 2.1 of the License, or (at your option) any
 * later version. Please see the file LICENSE-LGPL for details.
 *
 * Web Page: http://brltty.com/
 *
 * This software is maintained by <NAME> <<EMAIL>>.
 */

package org.a11y.brltty.android;

import android.content.Context;
import android.content.Intent;
import android.app.PendingIntent;
import android.app.Activity;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.NotificationChannel;

public abstract class BrailleNotification {
  private BrailleNotification () {
  }

  private final static Integer NOTIFICATION_IDENTIFIER = 1;
  private final static String NOTIFICATION_CHANNEL = "braille";

  private static Context applicationContext = null;
  private static NotificationManager notificationManager = null;
  private static Notification.Builder notificationBuilder = null;

  private static Context getContext () {
    if (applicationContext == null) {
      applicationContext = ApplicationContext.get();
    }

    return applicationContext;
  }

  private static String getString (int identifier) {
    return getContext().getString(identifier);
  }

  private static PendingIntent newPendingIntent (Class<? extends Activity> activityClass) {
    Context context = getContext();
    Intent intent = new Intent(context, activityClass);

    intent.addFlags(
      Intent.FLAG_ACTIVITY_CLEAR_TASK |
      Intent.FLAG_ACTIVITY_NEW_TASK
    );

    return PendingIntent.getActivity(context, 0, intent, 0);
  }

  private static NotificationManager getManager () {
    if (notificationManager == null) {
      notificationManager = (NotificationManager)
                            getContext().getSystemService(Context.NOTIFICATION_SERVICE);
    }

    return notificationManager;
  }

  private static boolean isActive () {
    return notificationBuilder != null;
  }

  private static void makeBuilder () {
    Context context = getContext();

    if (ApplicationUtilities.haveOreo) {
      NotificationManager nm = getManager();
      NotificationChannel channel = nm.getNotificationChannel(NOTIFICATION_CHANNEL);

      if (channel == null) {
        channel = new NotificationChannel(
          NOTIFICATION_CHANNEL,
          getString(R.string.braille_channel_name),
          NotificationManager.IMPORTANCE_LOW
        );

        nm.createNotificationChannel(channel);
      }

      notificationBuilder = new Notification.Builder(context, NOTIFICATION_CHANNEL);
    } else {
      notificationBuilder = new Notification.Builder(context);
    }

    notificationBuilder
      .setPriority(Notification.PRIORITY_LOW)
      .setOngoing(true)<commit_msg>A notification's priority shouldn't be explicitly set when a channel is being used. (dm)<commit_after>/*
 * BRLTTY - A background process providing access to the console screen (when in
 *          text mode) for a blind person using a refreshable braille display.
 *
 * Copyright (C) 1995-2018 by The BRLTTY Developers.
 *
 * BRLTTY comes with ABSOLUTELY NO WARRANTY.
 *
 * This is free software, placed under the terms of the
 * GNU Lesser General Public License, as published by the Free Software
 * Foundation; either version 2.1 of the License, or (at your option) any
 * later version. Please see the file LICENSE-LGPL for details.
 *
 * Web Page: http://brltty.com/
 *
 * This software is maintained by <NAME> <<EMAIL>>.
 */

package org.a11y.brltty.android;

import android.content.Context;
import android.content.Intent;
import android.app.PendingIntent;
import android.app.Activity;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.NotificationChannel;

public abstract class BrailleNotification {
  private BrailleNotification () {
  }

  private final static Integer NOTIFICATION_IDENTIFIER = 1;
  private final static String NOTIFICATION_CHANNEL = "braille";

  private static Context applicationContext = null;
  private static NotificationManager notificationManager = null;
  private static Notification.Builder notificationBuilder = null;

  private static Context getContext () {
    if (applicationContext == null) {
      applicationContext = ApplicationContext.get();
    }

    return applicationContext;
  }

  private static String getString (int identifier) {
    return getContext().getString(identifier);
  }

  private static PendingIntent newPendingIntent (Class<? extends Activity> activityClass) {
    Context context = getContext();
    Intent intent = new Intent(context, activityClass);

    intent.addFlags(
      Intent.FLAG_ACTIVITY_CLEAR_TASK |
      Intent.FLAG_ACTIVITY_NEW_TASK
    );

    return PendingIntent.getActivity(context, 0, intent, 0);
  }

  private static NotificationManager getManager () {
    if (notificationManager == null) {
      notificationManager = (NotificationManager)
                            getContext().getSystemService(Context.NOTIFICATION_SERVICE);
    }

    return notificationManager;
  }

  private static boolean isActive () {
    return notificationBuilder != null;
  }

  private static void makeBuilder () {
    Context context = getContext();

    if (ApplicationUtilities.haveOreo) {
      NotificationManager nm = getManager();
      NotificationChannel channel = nm.getNotificationChannel(NOTIFICATION_CHANNEL);

      if (channel == null) {
        channel = new NotificationChannel(
          NOTIFICATION_CHANNEL,
          getString(R.string.braille_channel_name),
          NotificationManager.IMPORTANCE_LOW
        );

        nm.createNotificationChannel(channel);
      }

      notificationBuilder = new Notification.Builder(context, NOTIFICATION_CHANNEL);
    } else {
      notificationBuilder = new Notification.Builder(context)
        .setPriority(Notification.PRIORITY_LOW)
        ;
    }

    notificationBuilder
      .setOngoing(true)
{'fraction_non_alphanumeric': 0.07813494589433481, 'fraction_numerical': 0.004774029280712922, 'mean_word_length': 3.6418020679468244, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5108587', 'n_tokens_mistral': 1670, 'n_tokens_neox': 1585, 'n_words': 484}