summaryrefslogtreecommitdiff
path: root/android
diff options
context:
space:
mode:
Diffstat (limited to 'android')
-rw-r--r--android/src/org/rockbox/RockboxActivity.java85
-rw-r--r--android/src/org/rockbox/RockboxService.java28
2 files changed, 58 insertions, 55 deletions
diff --git a/android/src/org/rockbox/RockboxActivity.java b/android/src/org/rockbox/RockboxActivity.java
index 2e13a034c7..15576f4adb 100644
--- a/android/src/org/rockbox/RockboxActivity.java
+++ b/android/src/org/rockbox/RockboxActivity.java
@@ -26,6 +26,7 @@ import android.app.Activity;
26import android.app.ProgressDialog; 26import android.app.ProgressDialog;
27import android.content.Intent; 27import android.content.Intent;
28import android.os.Bundle; 28import android.os.Bundle;
29import android.os.ResultReceiver;
29import android.util.Log; 30import android.util.Log;
30import android.view.View; 31import android.view.View;
31import android.view.ViewGroup; 32import android.view.ViewGroup;
@@ -36,79 +37,61 @@ public class RockboxActivity extends Activity
36{ 37{
37 private ProgressDialog loadingdialog; 38 private ProgressDialog loadingdialog;
38 private RockboxService rbservice; 39 private RockboxService rbservice;
40
39 /** Called when the activity is first created. */ 41 /** Called when the activity is first created. */
40 @Override 42 @Override
41 public void onCreate(Bundle savedInstanceState) 43 public void onCreate(Bundle savedInstanceState)
42 { 44 {
43 super.onCreate(savedInstanceState); 45 super.onCreate(savedInstanceState);
44 requestWindowFeature(Window.FEATURE_NO_TITLE); 46 requestWindowFeature(Window.FEATURE_NO_TITLE);
45 getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN 47 getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
46 ,WindowManager.LayoutParams.FLAG_FULLSCREEN); 48 WindowManager.LayoutParams.FLAG_FULLSCREEN);
47 final Activity thisActivity = this; 49
48 final Intent intent = new Intent(this, RockboxService.class);
49 /* prepare a please wait dialog in case we need 50 /* prepare a please wait dialog in case we need
50 * to wait for unzipping libmisc.so 51 * to wait for unzipping libmisc.so
51 */ 52 */
52 loadingdialog = new ProgressDialog(this); 53 loadingdialog = new ProgressDialog(this);
53 loadingdialog.setMessage("Rockbox is loading. Please wait..."); 54 loadingdialog.setMessage("Rockbox is loading. Please wait...");
54 loadingdialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); 55 loadingdialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
56 loadingdialog.setIndeterminate(true);
55 loadingdialog.setCancelable(false); 57 loadingdialog.setCancelable(false);
56 startService(intent); 58 loadingdialog.show();
57 rbservice = RockboxService.get_instance(); 59
58 /* Now it gets a bit tricky: 60 Intent intent = new Intent(this, RockboxService.class);
59 * The service is started in the same thread as we are now, 61 intent.putExtra("callback", new ResultReceiver(null) {
60 * but the service also initializes the framebuffer 62 @Override
61 * Unfortunately, this happens *after* any of the default 63 protected void onReceiveResult(final int resultCode, final Bundle resultData)
62 * startup methods of an activity, so we need to poll for it
63 *
64 * In order to get the fb, we need to let the Service start up
65 * run, we can wait in a separate thread for fb to get ready
66 * This thread waits for the fb to become ready */
67 new Thread(new Runnable()
68 {
69 public void run()
70 { 64 {
71 int i = 0; 65 runOnUiThread(new Runnable()
72 try {
73 while (true)
74 {
75 Thread.sleep(250);
76 if (isRockboxRunning())
77 break;
78 /* if it's still null show the please wait dialog
79 * but not before 0.5s are over */
80 if (!loadingdialog.isShowing() && i > 0)
81 {
82 runOnUiThread(new Runnable()
83 {
84 public void run()
85 {
86 loadingdialog.show();
87 }
88 });
89 }
90 else
91 i++ ;
92 }
93 } catch (InterruptedException e) {
94 }
95 /* drawing needs to happen in ui thread */
96 runOnUiThread(new Runnable()
97 { 66 {
98 public void run() { 67 public void run() {
99 loadingdialog.dismiss(); 68 switch (resultCode) {
100 if (rbservice.get_fb() == null) 69 case RockboxService.RESULT_LIB_LOADED:
101 throw new IllegalStateException("FB NULL"); 70 rbservice = RockboxService.get_instance();
102 attachFramebuffer(); 71 loadingdialog.setIndeterminate(true);
72 break;
73 case RockboxService.RESULT_LIB_LOAD_PROGRESS:
74 loadingdialog.setIndeterminate(false);
75 loadingdialog.setMax(resultData.getInt("max", 100));
76 loadingdialog.setProgress(resultData.getInt("value", 0));
77 break;
78 case RockboxService.RESULT_FB_INITIALIZED:
79 attachFramebuffer();
80 loadingdialog.dismiss();
81 break;
82 }
83
103 } 84 }
104 }); 85 });
105 } 86 }
106 }).start(); 87 });
88 startService(intent);
107 } 89 }
90
108 private boolean isRockboxRunning() 91 private boolean isRockboxRunning()
109 { 92 {
110 if (rbservice == null) 93 if (rbservice == null)
111 rbservice = RockboxService.get_instance(); 94 rbservice = RockboxService.get_instance();
112 return (rbservice!= null && rbservice.isRockboxRunning() == true); 95 return (rbservice!= null && rbservice.isRockboxRunning() == true);
113 } 96 }
114 97
diff --git a/android/src/org/rockbox/RockboxService.java b/android/src/org/rockbox/RockboxService.java
index 8989271b9f..a441a7dec4 100644
--- a/android/src/org/rockbox/RockboxService.java
+++ b/android/src/org/rockbox/RockboxService.java
@@ -21,8 +21,6 @@
21 21
22package org.rockbox; 22package org.rockbox;
23 23
24import org.rockbox.Helper.RunForegroundManager;
25
26import java.io.BufferedInputStream; 24import java.io.BufferedInputStream;
27import java.io.BufferedOutputStream; 25import java.io.BufferedOutputStream;
28import java.io.File; 26import java.io.File;
@@ -35,13 +33,17 @@ import java.util.TimerTask;
35import java.util.zip.ZipEntry; 33import java.util.zip.ZipEntry;
36import java.util.zip.ZipFile; 34import java.util.zip.ZipFile;
37 35
36import org.rockbox.Helper.RunForegroundManager;
37
38import android.app.Activity; 38import android.app.Activity;
39import android.app.Service; 39import android.app.Service;
40import android.content.BroadcastReceiver; 40import android.content.BroadcastReceiver;
41import android.content.Context; 41import android.content.Context;
42import android.content.Intent; 42import android.content.Intent;
43import android.content.IntentFilter; 43import android.content.IntentFilter;
44import android.os.Bundle;
44import android.os.IBinder; 45import android.os.IBinder;
46import android.os.ResultReceiver;
45import android.util.Log; 47import android.util.Log;
46 48
47/* This class is used as the main glue between java and c. 49/* This class is used as the main glue between java and c.
@@ -65,12 +67,16 @@ public class RockboxService extends Service
65 private RunForegroundManager fg_runner; 67 private RunForegroundManager fg_runner;
66 @SuppressWarnings("unused") 68 @SuppressWarnings("unused")
67 private int battery_level; 69 private int battery_level;
70 private ResultReceiver resultReceiver;
71
72 public static final int RESULT_LIB_LOADED = 0;
73 public static final int RESULT_LIB_LOAD_PROGRESS = 1;
74 public static final int RESULT_FB_INITIALIZED = 2;
68 75
69 @Override 76 @Override
70 public void onCreate() 77 public void onCreate()
71 { 78 {
72 instance = this; 79 instance = this;
73 startservice();
74 } 80 }
75 81
76 public static RockboxService get_instance() 82 public static RockboxService get_instance()
@@ -87,6 +93,8 @@ public class RockboxService extends Service
87 { 93 {
88 fb = newfb; 94 fb = newfb;
89 mRockboxRunning = true; 95 mRockboxRunning = true;
96 if (resultReceiver != null)
97 resultReceiver.send(RESULT_FB_INITIALIZED, null);
90 } 98 }
91 99
92 public Activity get_activity() 100 public Activity get_activity()
@@ -97,11 +105,14 @@ public class RockboxService extends Service
97 { 105 {
98 current_activity = a; 106 current_activity = a;
99 } 107 }
100
101 108
102 private void do_start(Intent intent) 109 private void do_start(Intent intent)
103 { 110 {
104 LOG("Start Service"); 111 LOG("Start Service");
112
113 if (intent.hasExtra("callback"))
114 resultReceiver = (ResultReceiver) intent.getParcelableExtra("callback");
115 startservice();
105 116
106 /* Display a notification about us starting. 117 /* Display a notification about us starting.
107 * We put an icon in the status bar. */ 118 * We put an icon in the status bar. */
@@ -140,6 +151,7 @@ public class RockboxService extends Service
140 public void run() 151 public void run()
141 { 152 {
142 LOG("main"); 153 LOG("main");
154 Bundle progressData = new Bundle();
143 /* the following block unzips libmisc.so, which contains the files 155 /* the following block unzips libmisc.so, which contains the files
144 * we ship, such as themes. It's needed to put it into a .so file 156 * we ship, such as themes. It's needed to put it into a .so file
145 * because there's no other way to ship files and have access 157 * because there's no other way to ship files and have access
@@ -160,6 +172,7 @@ public class RockboxService extends Service
160 ZipFile zipfile = new ZipFile(file); 172 ZipFile zipfile = new ZipFile(file);
161 Enumeration<? extends ZipEntry> e = zipfile.entries(); 173 Enumeration<? extends ZipEntry> e = zipfile.entries();
162 File folder; 174 File folder;
175 progressData.putInt("max", zipfile.size());
163 while(e.hasMoreElements()) 176 while(e.hasMoreElements())
164 { 177 {
165 entry = (ZipEntry) e.nextElement(); 178 entry = (ZipEntry) e.nextElement();
@@ -190,6 +203,10 @@ public class RockboxService extends Service
190 dest.flush(); 203 dest.flush();
191 dest.close(); 204 dest.close();
192 is.close(); 205 is.close();
206 if (resultReceiver != null) {
207 progressData.putInt("value", progressData.getInt("value", 0) + 1);
208 resultReceiver.send(RESULT_LIB_LOAD_PROGRESS, progressData);
209 }
193 } 210 }
194 } 211 }
195 } catch(FileNotFoundException e) { 212 } catch(FileNotFoundException e) {
@@ -201,7 +218,10 @@ public class RockboxService extends Service
201 } 218 }
202 219
203 System.loadLibrary("rockbox"); 220 System.loadLibrary("rockbox");
221 if (resultReceiver != null)
222 resultReceiver.send(RESULT_LIB_LOADED, null);
204 main(); 223 main();
224 throw new IllegalStateException("native main() returned!");
205 } 225 }
206 },"Rockbox thread"); 226 },"Rockbox thread");
207 rb.setDaemon(false); 227 rb.setDaemon(false);