package com.aragaer.jtt;

import com.aragaer.jtt.core.Clockwork;
import com.aragaer.jtt.resources.RuntimeResources;
import com.aragaer.jtt.resources.StringResources;
import com.aragaer.jtt.resources.StringResources.StringResourceChangeListener;

import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Binder;
import android.os.IBinder;
import android.preference.PreferenceManager;
import android.util.Log;

public class JttService extends Service implements SharedPreferences.OnSharedPreferenceChangeListener {
	private static final String TAG = "JTT_SERVICE";
	private JttStatus status_notify;

	public class JttServiceBinder extends Binder {
		public JttService getService() {
			return JttService.this;
		}
	}
	private final JttServiceBinder binder = new JttServiceBinder();

	@Override
	public IBinder onBind(Intent intent) {
		return binder;
	}

	@Override
	public int onStartCommand(Intent intent, int flags, int startid) {
		Log.i(TAG, "Service starting");
		Clockwork.schedule(this);

		SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(this);
		pref.registerOnSharedPreferenceChangeListener(this);

		toggle_notify(pref.getBoolean("jtt_notify", true));

		return START_STICKY;
	}

	@Override
	public void onDestroy() {
		super.onDestroy();
		Log.i(TAG, "Service destroying");

		if (status_notify != null) {
			status_notify.release();
			status_notify = null;
		}
	}

	private void toggle_notify(final boolean notify) {
		if (status_notify == null) {
			if (notify)
				status_notify = new JttStatus(this);
		} else {
			if (!notify) {
				status_notify.release();
				status_notify = null;
			}
		}
	}

	public void onSharedPreferenceChanged(SharedPreferences pref, String key) {
		if (key.equals(Settings.PREF_NOTIFY))
			toggle_notify(pref.getBoolean("jtt_notify", true));
		else if (key.equals(Settings.PREF_LOCATION))
			Clockwork.schedule(this);
	}
}

@@ -19,16 +19,56 @@
 r.jtt;%0A%0A
+import com.aragaer.jtt.core.Calculator;%0A
 import c
@@ -98,16 +98,16 @@
 ckwork;%0A
-
 import c
@@ -307,16 +307,54 @@
 ervice;%0A
+import android.content.ContentValues;%0A
 import a
@@ -1133,39 +1133,21 @@
 ng%22);%0A%09%09
-Clockwork.schedule(this
+move(
 );%0A%0A%09%09Sh
@@ -2003,17 +2003,289 @@
 ATION))%0A
-
 %09
+%09%09move();%0A%09%7D%0A%0A%09private void move() %7B%0A%09%09final float l%5B%5D = Settings.getLocation(this);%0A%09%09final ContentValues location = new ContentValues(2);%0A%09%09location.put(%22lat%22, l%5B0%5D);%0A%09%09location.put(%22lon%22, l%5B1%5D);%0A%09%09getContentResolver().update(Calculator.LOCATION, location, null, null);%0A
 %09%09Clockw

Set location in calculator