summaryrefslogtreecommitdiff
path: root/android/src/org
diff options
context:
space:
mode:
Diffstat (limited to 'android/src/org')
-rw-r--r--android/src/org/rockbox/RockboxActivity.java42
-rw-r--r--android/src/org/rockbox/RockboxPCM.java4
-rw-r--r--android/src/org/rockbox/RockboxService.java49
3 files changed, 68 insertions, 27 deletions
diff --git a/android/src/org/rockbox/RockboxActivity.java b/android/src/org/rockbox/RockboxActivity.java
index 6226455deb..f775597d30 100644
--- a/android/src/org/rockbox/RockboxActivity.java
+++ b/android/src/org/rockbox/RockboxActivity.java
@@ -32,6 +32,7 @@ import android.view.WindowManager;
32public class RockboxActivity extends Activity 32public class RockboxActivity extends Activity
33{ 33{
34 private ProgressDialog loadingdialog; 34 private ProgressDialog loadingdialog;
35 private RockboxService rbservice;
35 /** Called when the activity is first created. */ 36 /** Called when the activity is first created. */
36 @Override 37 @Override
37 public void onCreate(Bundle savedInstanceState) 38 public void onCreate(Bundle savedInstanceState)
@@ -40,8 +41,7 @@ public class RockboxActivity extends Activity
40 requestWindowFeature(Window.FEATURE_NO_TITLE); 41 requestWindowFeature(Window.FEATURE_NO_TITLE);
41 getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN 42 getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN
42 ,WindowManager.LayoutParams.FLAG_FULLSCREEN); 43 ,WindowManager.LayoutParams.FLAG_FULLSCREEN);
43 final Intent intent = new Intent(this, 44 final Intent intent = new Intent(this, RockboxService.class);
44 RockboxService.class);
45 /* prepare a please wait dialog in case we need 45 /* prepare a please wait dialog in case we need
46 * to wait for unzipping libmisc.so 46 * to wait for unzipping libmisc.so
47 */ 47 */
@@ -50,6 +50,7 @@ public class RockboxActivity extends Activity
50 loadingdialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); 50 loadingdialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
51 loadingdialog.setCancelable(false); 51 loadingdialog.setCancelable(false);
52 startService(intent); 52 startService(intent);
53 rbservice = RockboxService.get_instance();
53 /* Now it gets a bit tricky: 54 /* Now it gets a bit tricky:
54 * The service is started in the same thread as we are now, 55 * The service is started in the same thread as we are now,
55 * but the service also initializes the framebuffer 56 * but the service also initializes the framebuffer
@@ -68,8 +69,8 @@ public class RockboxActivity extends Activity
68 while (true) 69 while (true)
69 { 70 {
70 Thread.sleep(250); 71 Thread.sleep(250);
71 if (RockboxService.fb != null) 72 if (isRockboxRunning())
72 break; 73 break;
73 /* if it's still null show the please wait dialog 74 /* if it's still null show the please wait dialog
74 * but not before 0.5s are over */ 75 * but not before 0.5s are over */
75 if (!loadingdialog.isShowing() && i > 0) 76 if (!loadingdialog.isShowing() && i > 0)
@@ -92,32 +93,37 @@ public class RockboxActivity extends Activity
92 { 93 {
93 public void run() { 94 public void run() {
94 loadingdialog.dismiss(); 95 loadingdialog.dismiss();
95 if (RockboxService.fb == null) 96 if (rbservice.get_fb() == null)
96 throw new IllegalStateException("FB NULL"); 97 throw new IllegalStateException("FB NULL");
97 setContentView(RockboxService.fb); 98 setContentView(rbservice.get_fb());
98 RockboxService.fb.invalidate(); 99 rbservice.get_fb().invalidate();
99 } 100 }
100 }); 101 });
101 } 102 }
102 }).start(); 103 }).start();
103 } 104 }
105 private boolean isRockboxRunning()
106 {
107 if (rbservice == null)
108 rbservice = RockboxService.get_instance();
109 return (rbservice!= null && rbservice.isRockboxRunning() == true);
110 }
104 111
105 public void onResume() 112 public void onResume()
106 { 113 {
107 super.onResume(); 114 super.onResume();
108 115 if (isRockboxRunning())
109 if (RockboxService.fb != null)
110 { 116 {
111 try { 117 try {
112 setContentView(RockboxService.fb); 118 setContentView(rbservice.get_fb());
113 } catch (IllegalStateException e) { 119 } catch (IllegalStateException e) {
114 /* we are already using the View, 120 /* we are already using the View,
115 * need to remove it and re-attach it */ 121 * need to remove it and re-attach it */
116 ViewGroup g = (ViewGroup)RockboxService.fb.getParent(); 122 ViewGroup g = (ViewGroup)rbservice.get_fb().getParent();
117 g.removeView(RockboxService.fb); 123 g.removeView(rbservice.get_fb());
118 setContentView(RockboxService.fb); 124 setContentView(rbservice.get_fb());
119 } finally { 125 } finally {
120 RockboxService.fb.resume(); 126 rbservice.get_fb().resume();
121 } 127 }
122 } 128 }
123 } 129 }
@@ -129,20 +135,20 @@ public class RockboxActivity extends Activity
129 protected void onPause() 135 protected void onPause()
130 { 136 {
131 super.onPause(); 137 super.onPause();
132 RockboxService.fb.suspend(); 138 rbservice.get_fb().suspend();
133 } 139 }
134 140
135 @Override 141 @Override
136 protected void onStop() 142 protected void onStop()
137 { 143 {
138 super.onStop(); 144 super.onStop();
139 RockboxService.fb.suspend(); 145 rbservice.get_fb().suspend();
140 } 146 }
141 147
142 @Override 148 @Override
143 protected void onDestroy() 149 protected void onDestroy()
144 { 150 {
145 super.onDestroy(); 151 super.onDestroy();
146 RockboxService.fb.suspend(); 152 rbservice.get_fb().suspend();
147 } 153 }
148} \ No newline at end of file 154}
diff --git a/android/src/org/rockbox/RockboxPCM.java b/android/src/org/rockbox/RockboxPCM.java
index 46bdd121f0..146e639a08 100644
--- a/android/src/org/rockbox/RockboxPCM.java
+++ b/android/src/org/rockbox/RockboxPCM.java
@@ -86,7 +86,7 @@ public class RockboxPCM extends AudioTrack
86 { 86 {
87 if (getPlayState() == AudioTrack.PLAYSTATE_STOPPED) 87 if (getPlayState() == AudioTrack.PLAYSTATE_STOPPED)
88 { 88 {
89 RockboxService.startForeground(); 89 RockboxService.get_instance().startForeground();
90 if (getState() == AudioTrack.STATE_INITIALIZED) 90 if (getState() == AudioTrack.STATE_INITIALIZED)
91 { 91 {
92 if (h == null) 92 if (h == null)
@@ -113,7 +113,7 @@ public class RockboxPCM extends AudioTrack
113 } catch (IllegalStateException e) { 113 } catch (IllegalStateException e) {
114 throw new IllegalStateException(e); 114 throw new IllegalStateException(e);
115 } 115 }
116 RockboxService.stopForeground(); 116 RockboxService.get_instance().stopForeground();
117 } 117 }
118 118
119 @SuppressWarnings("unused") 119 @SuppressWarnings("unused")
diff --git a/android/src/org/rockbox/RockboxService.java b/android/src/org/rockbox/RockboxService.java
index be02342768..c403736c72 100644
--- a/android/src/org/rockbox/RockboxService.java
+++ b/android/src/org/rockbox/RockboxService.java
@@ -46,11 +46,22 @@ import android.content.IntentFilter;
46import android.os.IBinder; 46import android.os.IBinder;
47import android.util.Log; 47import android.util.Log;
48 48
49/* This class is used as the main glue between java and c.
50 * All access should be done through RockboxService.get_instance() for safety.
51 */
52
49public class RockboxService extends Service 53public class RockboxService extends Service
50{ 54{
51 /* this Service is really a singleton class */ 55 /* this Service is really a singleton class - well almost.
52 public static RockboxFramebuffer fb = null; 56 * To do it properly this line should be instance = new RockboxService()
53 private static RockboxService instance; 57 * but apparently that doesnt work with the way android Services are created.
58 */
59 private static RockboxService instance = null;
60
61 /* locals needed for the c code and rockbox state */
62 private RockboxFramebuffer fb = null;
63 private boolean mRockboxRunning = false;
64
54 private Notification notification; 65 private Notification notification;
55 private static final Class<?>[] mStartForegroundSignature = 66 private static final Class<?>[] mStartForegroundSignature =
56 new Class[] { int.class, Notification.class }; 67 new Class[] { int.class, Notification.class };
@@ -70,6 +81,7 @@ public class RockboxService extends Service
70 @Override 81 @Override
71 public void onCreate() 82 public void onCreate()
72 { 83 {
84 instance = this;
73 mNM = (NotificationManager)getSystemService(NOTIFICATION_SERVICE); 85 mNM = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
74 try 86 try
75 { 87 {
@@ -83,9 +95,24 @@ public class RockboxService extends Service
83 /* Running on an older platform: fall back to old API */ 95 /* Running on an older platform: fall back to old API */
84 mStartForeground = mStopForeground = null; 96 mStartForeground = mStopForeground = null;
85 } 97 }
86 instance = this;
87 startservice(); 98 startservice();
88 } 99 }
100
101 public static RockboxService get_instance()
102 {
103 return instance;
104 }
105
106 public RockboxFramebuffer get_fb()
107 {
108 return fb;
109 }
110 /* framebuffer is initialised by the native code(!) so this is needed */
111 public void set_fb(RockboxFramebuffer newfb)
112 {
113 fb = newfb;
114 mRockboxRunning = true;
115 }
89 116
90 private void do_start(Intent intent) 117 private void do_start(Intent intent)
91 { 118 {
@@ -190,8 +217,16 @@ public class RockboxService extends Service
190 rb.setDaemon(false); 217 rb.setDaemon(false);
191 rb.start(); 218 rb.start();
192 } 219 }
193
194 private native void main(); 220 private native void main();
221
222 /* returns true once rockbox is up and running.
223 * This is considered done once the framebuffer is initialised
224 */
225 public boolean isRockboxRunning()
226 {
227 return mRockboxRunning;
228 }
229
195 @Override 230 @Override
196 public IBinder onBind(Intent intent) 231 public IBinder onBind(Intent intent)
197 { 232 {
@@ -262,7 +297,7 @@ public class RockboxService extends Service
262 getText(R.string.notification), text, contentIntent); 297 getText(R.string.notification), text, contentIntent);
263 } 298 }
264 299
265 public static void startForeground() 300 public void startForeground()
266 { 301 {
267 if (instance != null) 302 if (instance != null)
268 { 303 {
@@ -282,7 +317,7 @@ public class RockboxService extends Service
282 } 317 }
283 } 318 }
284 319
285 public static void stopForeground() 320 public void stopForeground()
286 { 321 {
287 if (instance.notification != null) 322 if (instance.notification != null)
288 { 323 {