From e19beb75fb12a45a64028162df90566ff073268b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20=C3=96nnerby?= Date: Tue, 8 Sep 2009 05:06:38 +0000 Subject: [PATCH] Bugfixing --- src/android/AndroidManifest.xml | 2 +- src/android/src/org/musikcube/Service.java | 2 + .../src/org/musikcube/core/Library.java | 42 ++++++++++++------- 3 files changed, 30 insertions(+), 16 deletions(-) diff --git a/src/android/AndroidManifest.xml b/src/android/AndroidManifest.xml index 6a8c1f944..565654745 100644 --- a/src/android/AndroidManifest.xml +++ b/src/android/AndroidManifest.xml @@ -2,7 +2,7 @@ - + diff --git a/src/android/src/org/musikcube/Service.java b/src/android/src/org/musikcube/Service.java index 30690b2b5..56ad1beed 100644 --- a/src/android/src/org/musikcube/Service.java +++ b/src/android/src/org/musikcube/Service.java @@ -78,10 +78,12 @@ public class Service extends android.app.Service { // TODO Auto-generated method stub super.onStart(intent, startId); + boolean stopWorkout = false; String action = intent.getStringExtra("org.musikcube.Service.action"); if(action==null){ + this.library.Startup(this); return; } if(action.equals("playlist")){ diff --git a/src/android/src/org/musikcube/core/Library.java b/src/android/src/org/musikcube/core/Library.java index 797c89fd2..9c5950037 100644 --- a/src/android/src/org/musikcube/core/Library.java +++ b/src/android/src/org/musikcube/core/Library.java @@ -10,6 +10,7 @@ import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; import android.preference.PreferenceManager; +import android.util.Log; import doep.xml.*; import org.musikcube.core.IQuery; @@ -30,7 +31,7 @@ public final class Library implements Runnable{ private Thread thread; private boolean running = false; private boolean restart = false; - private boolean exit = false; + private boolean exit = true; private Socket socket; private Context context; @@ -78,7 +79,7 @@ public final class Library implements Runnable{ private final void SetStatus(int status){ synchronized(this.status){ - //Log.v("mC2::Lib","STATUS "+this.status); + Log.v("mC2::Lib","STATUS "+this.status); this.status = status; if(this.statusListener!=null){ this.statusListener.OnLibraryStatusChange(status); @@ -128,18 +129,23 @@ public final class Library implements Runnable{ public final void Startup(Context context){ - this.context = context; - - // Startup thread when the application sends the context for the first time - this.thread = new Thread(this); - this.running = true; - this.thread.start(); + synchronized(this.notifier){ + if(this.exit){ + this.exit = false; + this.context = context; + // Startup thread when the application sends the context for the first time + this.thread = new Thread(this); + this.running = true; + this.thread.start(); + } + } } public final void Restart(){ synchronized(this.notifier){ this.running = false; this.restart = true; + if(this.socket!=null){ try { this.socket.shutdownInput(); @@ -200,7 +206,7 @@ public final class Library implements Runnable{ this.SetStatus(STATUS_SHUTDOWN); while(true){ - //Log.v("mC2::Lib","1"); + Log.v("mC2::Lib","1"); this.running = true; // First try to connect @@ -310,7 +316,7 @@ public final class Library implements Runnable{ } - //Log.v("mC2::Lib","4"); + Log.v("mC2::Lib","4"); synchronized (notifier) { if(!this.restart){ @@ -323,10 +329,10 @@ public final class Library implements Runnable{ } this.restart = false; - //Log.v("mC2::Lib","5"); + Log.v("mC2::Lib","5"); if(this.exit){ - //Log.v("mC2::Lib","EXIT"); + Log.v("mC2::Lib","EXIT"); Intent intent = new Intent(this.context, org.musikcube.Service.class); intent.putExtra("org.musikcube.Service.action", "shutdown"); this.context.startService(intent); @@ -334,7 +340,7 @@ public final class Library implements Runnable{ } this.restart = false; // this.running = true; - //Log.v("mC2::Lib","6"); + Log.v("mC2::Lib","6"); } } @@ -378,7 +384,7 @@ public final class Library implements Runnable{ } } - //Log.v("Library::WriteThread","wait over"); + Log.v("Library::WriteThread","wait over"); }else{ // Get the first query query = this.sendQueryQueue.removeFirst(); @@ -423,7 +429,7 @@ public final class Library implements Runnable{ //Log.e("Library::WriteThread","E "+x.getMessage()); } - //Log.v("Library::WriteThread","Ended"); + Log.v("Library::WriteThread","Ended"); } public final void Exit(){ @@ -451,6 +457,12 @@ public final class Library implements Runnable{ } } + public final boolean Exited(){ + synchronized(this.notifier){ + return this.exit; + } + } + public final void AddQuery(IQuery query){ synchronized(this.sendQueryQueue){ this.sendQueryQueue.addLast(query);