<commit_before>/**
 *  LocalNotificationReceiver.java
 *  Cordova LocalNotification Plugin
 *
 *  Created by <NAME> (github.com/katzer) on 31/08/2013.
 *  Copyright 2013 <NAME>. All rights reserved.
 *  GPL v2 licensed
 */

package de.appplant.cordova.plugin.localnotification;

import java.util.Calendar;

import org.json.JSONException;
import org.json.JSONObject;

import android.annotation.SuppressLint;
import android.app.ActivityManager;
import android.app.Notification;
import android.app.Notification.Builder;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;

/**
 * The alarm receiver is triggered when a scheduled alarm is fired. This class
 * reads the information in the intent and displays this information in the
 * Android notification bar. The notification uses the default notification
 * sound and it vibrates the phone.
 */
public class LocalNotificationReceiver extends BroadcastReceiver {

	public static final String OPTIONS = "LOCAL_NOTIFICATION_OPTIONS";

	private Context context;
	private LocalNotificationOptions options;

	@Override
	public void onReceive (Context context, Intent intent) {
		LocalNotificationOptions options = null;
		Bundle bundle                    = intent.getExtras();
		JSONObject args;

		try {
			args    = new JSONObject(bundle.getString(OPTIONS));
			options = new LocalNotificationOptions(args);
		} catch (JSONException e) {}

		this.context = context;
		this.options = options;

		if (options.getInterval() == 0) {
			LocalNotification.unpersist(options.getId());
		} else if (isFirstAlarmInFuture()) {
			return;
		}

		Builder notification = buildNotification();

		if (!isInBackground(context)) {
			// exec foreground callback
			invokeForegroundCallback(options);
		}

		showNotification(notification);
	}

	/*
	 * If you set a repeating alarm at 11:00 in the morning and it
	 * should trigger every morning at 08:00 o'clock, it will
	 * immediately fire. E.g. Android tries to make up for the
	 * 'forgotten' reminder for that day. Therefore we ignore the event
	 * if Android tries to 'catch up'.
	 */
	private Boolean isFirstAlarmInFuture () {
		if (options.getInterval() > 0) {
			Calendar now    = Calendar.getInstance();
			Calendar alarm  = options.getCalendar();

			int alarmHour   = alarm.get(Calendar.HOUR_OF_DAY);
			int alarmMin    = alarm.get(Calendar.MINUTE);
			int currentHour = now.get(Calendar.HOUR_OF_DAY);
			int currentMin  = now.get(Calendar.MINUTE);

			if (currentHour != alarmHour && currentMin != alarmMin) {
				return true;
			}
		}

		return false;
	}

	/**
	 * Erstellt die Notification.
	 */
	private Builder buildNotification () {
		Builder notification = new Notification.Builder(context)
		.setContentTitle(options.getTitle())
		.setContentText(options.getSubTitle())
		.setNumber(options.getBadge())
		.setTicker(options.getTitle())
		.setSmallIcon(options.getIcon());

		try {
			if (isInBackground(context)) {
				// app is in background
				notification.setDefaults(Notification.DEFAULT_SOUND);
			}<commit_msg>Statt der Nachricht wurde der Subtitle angezeigt<commit_after>/**
 *  LocalNotificationReceiver.java
 *  Cordova LocalNotification Plugin
 *
 *  Created by <NAME> (github.com/katzer) on 31/08/2013.
 *  Copyright 2013 <NAME>. All rights reserved.
 *  GPL v2 licensed
 */

package de.appplant.cordova.plugin.localnotification;

import java.util.Calendar;

import org.json.JSONException;
import org.json.JSONObject;

import android.annotation.SuppressLint;
import android.app.ActivityManager;
import android.app.Notification;
import android.app.Notification.Builder;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;

/**
 * The alarm receiver is triggered when a scheduled alarm is fired. This class
 * reads the information in the intent and displays this information in the
 * Android notification bar. The notification uses the default notification
 * sound and it vibrates the phone.
 */
public class LocalNotificationReceiver extends BroadcastReceiver {

	public static final String OPTIONS = "LOCAL_NOTIFICATION_OPTIONS";

	private Context context;
	private LocalNotificationOptions options;

	@Override
	public void onReceive (Context context, Intent intent) {
		LocalNotificationOptions options = null;
		Bundle bundle                    = intent.getExtras();
		JSONObject args;

		try {
			args    = new JSONObject(bundle.getString(OPTIONS));
			options = new LocalNotificationOptions(args);
		} catch (JSONException e) {}

		this.context = context;
		this.options = options;

		if (options.getInterval() == 0) {
			LocalNotification.unpersist(options.getId());
		} else if (isFirstAlarmInFuture()) {
			return;
		}

		Builder notification = buildNotification();

		if (!isInBackground(context)) {
			// exec foreground callback
			invokeForegroundCallback(options);
		}

		showNotification(notification);
	}

	/*
	 * If you set a repeating alarm at 11:00 in the morning and it
	 * should trigger every morning at 08:00 o'clock, it will
	 * immediately fire. E.g. Android tries to make up for the
	 * 'forgotten' reminder for that day. Therefore we ignore the event
	 * if Android tries to 'catch up'.
	 */
	private Boolean isFirstAlarmInFuture () {
		if (options.getInterval() > 0) {
			Calendar now    = Calendar.getInstance();
			Calendar alarm  = options.getCalendar();

			int alarmHour   = alarm.get(Calendar.HOUR_OF_DAY);
			int alarmMin    = alarm.get(Calendar.MINUTE);
			int currentHour = now.get(Calendar.HOUR_OF_DAY);
			int currentMin  = now.get(Calendar.MINUTE);

			if (currentHour != alarmHour && currentMin != alarmMin) {
				return true;
			}
		}

		return false;
	}

	/**
	 * Erstellt die Notification.
	 */
	private Builder buildNotification () {
		Builder notification = new Notification.Builder(context)
		.setContentTitle(options.getTitle())
		.setContentText(options.getMessage())
		.setNumber(options.getBadge())
		.setTicker(options.getTitle())
		.setSmallIcon(options.getIcon());

		try {
			if (isInBackground(context)) {
				// app is in background
				notification.setDefaults(Notification.DEFAULT_SOUND);
			}
{'fraction_non_alphanumeric': 0.09750778816199376, 'fraction_numerical': 0.0071651090342679125, 'mean_word_length': 4.116334661354582, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6877148', 'n_tokens_mistral': 2006, 'n_tokens_neox': 1780, 'n_words': 524}