<commit_before>package com.kuxhausen.huemore;

import java.util.ArrayList;
import java.util.PriorityQueue;

import android.app.PendingIntent;
import android.app.Service;
import android.content.Intent;
import android.os.Binder;
import android.os.CountDownTimer;
import android.os.IBinder;
import android.support.v4.app.NotificationCompat;
import android.util.Log;
import android.util.Pair;

import com.android.volley.RequestQueue;
import com.android.volley.toolbox.Volley;
import com.kuxhausen.huemore.network.NetworkMethods;
import com.kuxhausen.huemore.persistence.DatabaseDefinitions.InternalArguments;
import com.kuxhausen.huemore.persistence.HueUrlEncoder;
import com.kuxhausen.huemore.state.Event;
import com.kuxhausen.huemore.state.Mood;
import com.kuxhausen.huemore.state.QueueEvent;
import com.kuxhausen.huemore.state.api.BulbState;

public class MoodExecuterService extends Service {

	/**
	 * Class used for the client Binder. Because we know this service always
	 * runs in the same process as its clients, we don't need to deal with IPC.
	 */
	public class LocalBinder extends Binder {
		MoodExecuterService getService() {
			// Return this instance of LocalService so clients can call public
			// methods
			return MoodExecuterService.this;
		}
	}
	MoodExecuterService me = this;
	private RequestQueue volleyRQ;

	int notificationId = 1337;

	// Binder given to clients
	private final IBinder mBinder = new LocalBinder();

	private BulbState[] transientStateChanges = new BulbState[50];

	{
		for (int i = 0; i < transientStateChanges.length; i++)
			transientStateChanges[i] = new BulbState();
	}

	private boolean[] flagTransientChanges = new boolean[50];

	private Pair<Integer[], Mood> moodPair;

	private CountDownTimer countDownTimer;

	int time;

	PriorityQueue<QueueEvent> queue = new PriorityQueue<QueueEvent>();

	PriorityQueue<QueueEvent> highPriorityQueue = new PriorityQueue<QueueEvent>();

	int transientIndex = 0;
	public MoodExecuterService() {
	}
	public void createNotification(String secondaryText) {
		// Creates an explicit intent for an Activity in your app
		Intent resultIntent = new Intent(this, MainActivity.class);
		PendingIntent resultPendingIntent = PendingIntent.getActivity(this, 0,
				resultIntent, PendingIntent.FLAG_UPDATE_CURRENT);

		NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
				this)
				.setSmallIcon(R.drawable.huemore)
				.setContentTitle(
						this.getResources().getString(R.string.app_name))
				.setContentText(secondaryText)
				.setContentIntent(resultPendingIntent);
		this.startForeground(notificationId, mBuilder.build());

	}

	public RequestQueue getRequestQueue() {
		return volleyRQ;
	}

	private boolean hasTransientChanges() {
		boolean result = false;
		for (boolean b : flagTransientChanges)
			result |= b;
		return result;
	}
	private void loadMoodIntoQueue() {
		Integer[] bulbS = moodPair.first;
		Mood m = moodPair.second;

		ArrayList<Integer>[] channels = new ArrayList[m.numChannels];
		for (int i = 0; i < channels.length; i++)
			channels[i] = new ArrayList<Integer>();

		for (int i = 0; i < bulbS.length; i++) {
			channels[i % m.numChannels].add(bulbS[i]);
		}

		for (Event e : m.events) {
			e.time += (int) System.nanoTime() / 1000000;// divide by 1 million
														// to convert to millis
			for (Integer bNum : channels[e.channel]) {
				QueueEvent qe = new QueueEvent(e);
				qe.bulb = bNum;
				queue.add(qe);
			}
		}
	}
	@Override
	public IBinder onBind(Intent intent) {
		return mBinder;
	}

	@Override
	public void onCreate() {
		super.onCreate();
		volleyRQ = Volley.newRequestQueue(this);
		restartCountDownTimer();
		createNotification("");
	}
	@Override
	public void onDestroy() {
		countDownTimer.cancel();
		volleyRQ.cancelAll(InternalArguments.TRANSIENT_NETWORK_REQUEST);
		volleyRQ.cancelAll(InternalArguments.PERMANENT_NETWORK_REQUEST);
		super.onDestroy();
	}
	@Override
	public int onStartCommand(Intent intent, int flags, int startId) {
		if (intent != null) {
			String encodedMood = intent
					.getStringExtra(InternalArguments.ENCODED_MOOD);
			String encodedTransientMood = intent
					.getStringExtra(InternalArguments.ENCODED_TRANSIENT_MOOD);

			if (encodedMood != null) {
				moodPair = HueUrlEncoder.decode(encodedMood);
				loadMoodIntoQueue();

				String moodName = intent
						.getStringExtra(InternalArguments.MOOD_NAME);
				moodName = (moodName == null) ? "" : moodName;
				createNotification(moodName);

			} else if (encodedTransientMood != null) {
				Pair<Integer[], Mood> decodedValues = HueUrlEncoder<commit_msg>set notification to always indicate a mood is in progress<commit_after>package com.kuxhausen.huemore;

import java.util.ArrayList;
import java.util.PriorityQueue;

import android.app.PendingIntent;
import android.app.Service;
import android.content.Intent;
import android.os.Binder;
import android.os.CountDownTimer;
import android.os.IBinder;
import android.support.v4.app.NotificationCompat;
import android.util.Log;
import android.util.Pair;

import com.android.volley.RequestQueue;
import com.android.volley.toolbox.Volley;
import com.kuxhausen.huemore.network.NetworkMethods;
import com.kuxhausen.huemore.persistence.DatabaseDefinitions.InternalArguments;
import com.kuxhausen.huemore.persistence.HueUrlEncoder;
import com.kuxhausen.huemore.state.Event;
import com.kuxhausen.huemore.state.Mood;
import com.kuxhausen.huemore.state.QueueEvent;
import com.kuxhausen.huemore.state.api.BulbState;

public class MoodExecuterService extends Service {

	/**
	 * Class used for the client Binder. Because we know this service always
	 * runs in the same process as its clients, we don't need to deal with IPC.
	 */
	public class LocalBinder extends Binder {
		MoodExecuterService getService() {
			// Return this instance of LocalService so clients can call public
			// methods
			return MoodExecuterService.this;
		}
	}
	MoodExecuterService me = this;
	private RequestQueue volleyRQ;

	int notificationId = 1337;

	// Binder given to clients
	private final IBinder mBinder = new LocalBinder();

	private BulbState[] transientStateChanges = new BulbState[50];

	{
		for (int i = 0; i < transientStateChanges.length; i++)
			transientStateChanges[i] = new BulbState();
	}

	private boolean[] flagTransientChanges = new boolean[50];

	private Pair<Integer[], Mood> moodPair;

	private CountDownTimer countDownTimer;

	int time;

	PriorityQueue<QueueEvent> queue = new PriorityQueue<QueueEvent>();

	PriorityQueue<QueueEvent> highPriorityQueue = new PriorityQueue<QueueEvent>();

	int transientIndex = 0;
	public MoodExecuterService() {
	}
	public void createNotification(String secondaryText) {
		// Creates an explicit intent for an Activity in your app
		Intent resultIntent = new Intent(this, MainActivity.class);
		PendingIntent resultPendingIntent = PendingIntent.getActivity(this, 0,
				resultIntent, PendingIntent.FLAG_UPDATE_CURRENT);

		NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
				this)
				.setSmallIcon(R.drawable.huemore)
				.setContentTitle(
						this.getResources().getString(R.string.app_name))
				.setContentText(secondaryText)
				.setContentIntent(resultPendingIntent);
		this.startForeground(notificationId, mBuilder.build());

	}

	public RequestQueue getRequestQueue() {
		return volleyRQ;
	}

	private boolean hasTransientChanges() {
		boolean result = false;
		for (boolean b : flagTransientChanges)
			result |= b;
		return result;
	}
	private void loadMoodIntoQueue() {
		Integer[] bulbS = moodPair.first;
		Mood m = moodPair.second;

		ArrayList<Integer>[] channels = new ArrayList[m.numChannels];
		for (int i = 0; i < channels.length; i++)
			channels[i] = new ArrayList<Integer>();

		for (int i = 0; i < bulbS.length; i++) {
			channels[i % m.numChannels].add(bulbS[i]);
		}

		for (Event e : m.events) {
			e.time += (int) System.nanoTime() / 1000000;// divide by 1 million
														// to convert to millis
			for (Integer bNum : channels[e.channel]) {
				QueueEvent qe = new QueueEvent(e);
				qe.bulb = bNum;
				queue.add(qe);
			}
		}
	}
	@Override
	public IBinder onBind(Intent intent) {
		return mBinder;
	}

	@Override
	public void onCreate() {
		super.onCreate();
		volleyRQ = Volley.newRequestQueue(this);
		restartCountDownTimer();
		createNotification("");
	}
	@Override
	public void onDestroy() {
		countDownTimer.cancel();
		volleyRQ.cancelAll(InternalArguments.TRANSIENT_NETWORK_REQUEST);
		volleyRQ.cancelAll(InternalArguments.PERMANENT_NETWORK_REQUEST);
		super.onDestroy();
	}
	@Override
	public int onStartCommand(Intent intent, int flags, int startId) {
		if (intent != null) {
			String encodedMood = intent
					.getStringExtra(InternalArguments.ENCODED_MOOD);
			String encodedTransientMood = intent
					.getStringExtra(InternalArguments.ENCODED_TRANSIENT_MOOD);

			
			
			if (encodedMood != null) {
				moodPair = HueUrlEncoder.decode(encodedMood);
				loadMoodIntoQueue();

				String moodName = intent
						.getStringExtra(InternalArguments.MOOD_NAME);
				moodName = (moodName == null) ? "Unknown Mood" : moodName;
				createNotification(moodName);

			} else if (encodedTransientMood != null) {
				Pair<Integer[], Mood> decodedValues = HueUrlEncoder
{'fraction_non_alphanumeric': 0.10227518959913326, 'fraction_numerical': 0.004767063921993499, 'mean_word_length': 4.550811785929044, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 19, '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': '975703', 'n_tokens_mistral': 3230, 'n_tokens_neox': 2846, 'n_words': 684}