diff options
author | Thomas Martitz <kugel@rockbox.org> | 2010-08-04 12:25:25 +0000 |
---|---|---|
committer | Thomas Martitz <kugel@rockbox.org> | 2010-08-04 12:25:25 +0000 |
commit | 04dc00b7caa9f505ed3dd55fe5922910d004fa80 (patch) | |
tree | 52798713d9afae61746d72ff79a1826f1781ab8d /android | |
parent | f0611f878101caa323b3b0693c0cf7170f59fe00 (diff) | |
download | rockbox-04dc00b7caa9f505ed3dd55fe5922910d004fa80.tar.gz rockbox-04dc00b7caa9f505ed3dd55fe5922910d004fa80.zip |
Add a few forgotten files, Fix potential startup problem. Fix absolute touchscreen mode.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@27693 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'android')
-rw-r--r-- | android/res/drawable-hdpi/rb.png | bin | 0 -> 468 bytes | |||
-rw-r--r-- | android/res/drawable-ldpi/rb.png | bin | 0 -> 468 bytes | |||
-rw-r--r-- | android/res/drawable-mdpi/rb.png | bin | 0 -> 468 bytes | |||
-rw-r--r-- | android/src/org/rockbox/RockboxActivity.java | 31 | ||||
-rw-r--r-- | android/src/org/rockbox/RockboxService.java | 173 |
5 files changed, 187 insertions, 17 deletions
diff --git a/android/res/drawable-hdpi/rb.png b/android/res/drawable-hdpi/rb.png new file mode 100644 index 0000000000..6d21c98bf1 --- /dev/null +++ b/android/res/drawable-hdpi/rb.png | |||
Binary files differ | |||
diff --git a/android/res/drawable-ldpi/rb.png b/android/res/drawable-ldpi/rb.png new file mode 100644 index 0000000000..6d21c98bf1 --- /dev/null +++ b/android/res/drawable-ldpi/rb.png | |||
Binary files differ | |||
diff --git a/android/res/drawable-mdpi/rb.png b/android/res/drawable-mdpi/rb.png new file mode 100644 index 0000000000..6d21c98bf1 --- /dev/null +++ b/android/res/drawable-mdpi/rb.png | |||
Binary files differ | |||
diff --git a/android/src/org/rockbox/RockboxActivity.java b/android/src/org/rockbox/RockboxActivity.java index 2bafb6688d..3be9e3ed47 100644 --- a/android/src/org/rockbox/RockboxActivity.java +++ b/android/src/org/rockbox/RockboxActivity.java | |||
@@ -53,24 +53,21 @@ public class RockboxActivity extends Activity { | |||
53 | new Thread(new Runnable() | 53 | new Thread(new Runnable() |
54 | { | 54 | { |
55 | public void run() { | 55 | public void run() { |
56 | while (RockboxService.fb == null) | 56 | try { |
57 | { | 57 | while (RockboxService.fb == null) |
58 | try { | 58 | Thread.sleep(250); |
59 | Thread.sleep(250); | 59 | } catch (InterruptedException e) { |
60 | } catch (InterruptedException e) { | 60 | } catch (Exception e) { |
61 | } catch (Exception e) { | 61 | LOG(e.toString()); |
62 | LOG(e.toString()); | 62 | } |
63 | /* drawing needs to happen in ui thread */ | ||
64 | runOnUiThread(new Runnable() | ||
65 | { @Override | ||
66 | public void run() { | ||
67 | setContentView(RockboxService.fb); | ||
68 | RockboxService.fb.invalidate(); | ||
63 | } | 69 | } |
64 | /* drawing needs to happen in ui thread */ | 70 | }); |
65 | runOnUiThread(new Runnable() | ||
66 | { @Override | ||
67 | public void run() { | ||
68 | setContentView(RockboxService.fb); | ||
69 | RockboxService.fb.invalidate(); | ||
70 | } | ||
71 | }); | ||
72 | } | ||
73 | |||
74 | } | 71 | } |
75 | }).start(); | 72 | }).start(); |
76 | } | 73 | } |
diff --git a/android/src/org/rockbox/RockboxService.java b/android/src/org/rockbox/RockboxService.java new file mode 100644 index 0000000000..5c74d19ebf --- /dev/null +++ b/android/src/org/rockbox/RockboxService.java | |||
@@ -0,0 +1,173 @@ | |||
1 | package org.rockbox; | ||
2 | |||
3 | import java.io.BufferedInputStream; | ||
4 | import java.io.BufferedOutputStream; | ||
5 | import java.io.File; | ||
6 | import java.io.FileOutputStream; | ||
7 | import java.util.Enumeration; | ||
8 | import java.util.zip.ZipEntry; | ||
9 | import java.util.zip.ZipFile; | ||
10 | |||
11 | import android.app.Notification; | ||
12 | import android.app.NotificationManager; | ||
13 | import android.app.PendingIntent; | ||
14 | import android.app.Service; | ||
15 | import android.content.Intent; | ||
16 | import android.os.Binder; | ||
17 | import android.os.IBinder; | ||
18 | import android.util.Log; | ||
19 | |||
20 | public class RockboxService extends Service | ||
21 | { | ||
22 | public static RockboxFramebuffer fb = null; | ||
23 | @Override | ||
24 | public void onCreate() | ||
25 | { | ||
26 | mNM = (NotificationManager)getSystemService(NOTIFICATION_SERVICE); | ||
27 | startservice(); | ||
28 | } | ||
29 | |||
30 | private void do_start(Intent intent) | ||
31 | { | ||
32 | LOG("Start Service"); | ||
33 | } | ||
34 | |||
35 | private void LOG(CharSequence text) | ||
36 | { | ||
37 | Log.d("Rockbox", (String) text); | ||
38 | } | ||
39 | |||
40 | @Override | ||
41 | public void onStart(Intent intent, int startId) { | ||
42 | do_start(intent); | ||
43 | } | ||
44 | |||
45 | @Override | ||
46 | public int onStartCommand(Intent intent, int flags, int startId) | ||
47 | { | ||
48 | do_start(intent); | ||
49 | /* Display a notification about us starting. We put an icon in the status bar. */ | ||
50 | showNotification(); | ||
51 | return START_STICKY; | ||
52 | } | ||
53 | |||
54 | private void startservice() | ||
55 | { | ||
56 | fb = new RockboxFramebuffer(this); | ||
57 | final int BUFFER = 2048; | ||
58 | /* the following block unzips libmisc.so, which contains the files | ||
59 | * we ship, such as themes. It's needed to put it into a .so file | ||
60 | * because there's no other way to ship files and have access | ||
61 | * to them from native code | ||
62 | */ | ||
63 | try | ||
64 | { | ||
65 | BufferedOutputStream dest = null; | ||
66 | BufferedInputStream is = null; | ||
67 | ZipEntry entry; | ||
68 | File file = new File("/data/data/org.rockbox/lib/libmisc.so"); | ||
69 | /* use arbitary file to determine whether extracting is needed */ | ||
70 | File file2 = new File("/data/data/org.rockbox/app_rockbox/rockbox/codecs/mpa.codec"); | ||
71 | if (!file2.exists() || (file.lastModified() > file2.lastModified())) | ||
72 | { | ||
73 | ZipFile zipfile = new ZipFile(file); | ||
74 | Enumeration<? extends ZipEntry> e = zipfile.entries(); | ||
75 | File folder; | ||
76 | while(e.hasMoreElements()) { | ||
77 | entry = (ZipEntry) e.nextElement(); | ||
78 | LOG("Extracting: " +entry); | ||
79 | if (entry.isDirectory()) | ||
80 | { | ||
81 | folder = new File(entry.getName()); | ||
82 | LOG("mkdir "+ entry); | ||
83 | try { | ||
84 | folder.mkdirs(); | ||
85 | } catch (SecurityException ex){ | ||
86 | LOG(ex.getMessage()); | ||
87 | } | ||
88 | continue; | ||
89 | } | ||
90 | is = new BufferedInputStream(zipfile.getInputStream(entry)); | ||
91 | int count; | ||
92 | byte data[] = new byte[BUFFER]; | ||
93 | folder = new File(new File(entry.getName()).getParent()); | ||
94 | LOG("" + folder.getAbsolutePath()); | ||
95 | if (!folder.exists()) | ||
96 | folder.mkdirs(); | ||
97 | FileOutputStream fos = new FileOutputStream(entry.getName()); | ||
98 | dest = new BufferedOutputStream(fos, BUFFER); | ||
99 | while ((count = is.read(data, 0, BUFFER)) != -1) { | ||
100 | dest.write(data, 0, count); | ||
101 | } | ||
102 | dest.flush(); | ||
103 | dest.close(); | ||
104 | is.close(); | ||
105 | } | ||
106 | } | ||
107 | } catch(Exception e) { | ||
108 | e.printStackTrace(); | ||
109 | } | ||
110 | |||
111 | System.loadLibrary("rockbox"); | ||
112 | |||
113 | Thread rb = new Thread(new Runnable() | ||
114 | { | ||
115 | public void run() | ||
116 | { | ||
117 | main(); | ||
118 | } | ||
119 | },"Rockbox thread"); | ||
120 | rb.setDaemon(false); | ||
121 | rb.start(); | ||
122 | } | ||
123 | |||
124 | private native void main(); | ||
125 | @Override | ||
126 | public IBinder onBind(Intent intent) { | ||
127 | // TODO Auto-generated method stub | ||
128 | return null; | ||
129 | } | ||
130 | private NotificationManager mNM; | ||
131 | |||
132 | /** | ||
133 | * Class for clients to access. Because we know this service always | ||
134 | * runs in the same process as its clients, we don't need to deal with | ||
135 | * IPC. | ||
136 | */ | ||
137 | public class LocalBinder extends Binder { | ||
138 | RockboxService getService() { | ||
139 | return RockboxService.this; | ||
140 | } | ||
141 | } | ||
142 | |||
143 | /* heavily based on the example found on | ||
144 | * http://developer.android.com/reference/android/app/Service.html | ||
145 | */ | ||
146 | public void showNotification() { | ||
147 | // In this sample, we'll use the same text for the ticker and the expanded notification | ||
148 | CharSequence text = getText(R.string.notification); | ||
149 | |||
150 | // Set the icon, scrolling text and timestamp | ||
151 | Notification notification = new Notification(R.drawable.rb, text, | ||
152 | System.currentTimeMillis()); | ||
153 | |||
154 | // The PendingIntent to launch our activity if the user selects this notification | ||
155 | Intent intent = new Intent(this, RockboxActivity.class); | ||
156 | PendingIntent contentIntent = PendingIntent.getActivity(this, 0, intent, 0); | ||
157 | |||
158 | |||
159 | // Set the info for the views that show in the notification panel. | ||
160 | notification.setLatestEventInfo(this, getText(R.string.notification), text, contentIntent); | ||
161 | |||
162 | // Send the notification. | ||
163 | // We use a layout id because it is a unique number. We use it later to cancel. | ||
164 | mNM.notify(R.string.notification, notification); | ||
165 | |||
166 | /* | ||
167 | * this call makes the service run as foreground, which | ||
168 | * provides enough cpu time to do music decoding in the | ||
169 | * background | ||
170 | */ | ||
171 | startForeground(R.string.notification, notification); | ||
172 | } | ||
173 | } | ||