forked from len0rd/rockbox
Run Rockbox as a service, which allows for music decoding&playback in the background,
the activity only attaches to the framebuffer for displaying it. An icon in the notification area is displayed (it could be prettier I guess). Note: Some HTC phones won't, includng mine, get enough CPU time to do background decoding fluently, see: http://code.google.com/p/android/issues/detail?id=9663 git-svn-id: svn://svn.rockbox.org/rockbox/trunk@27686 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
83c60a1012
commit
9dd0158ffb
10 changed files with 74 additions and 136 deletions
|
@ -21,128 +21,81 @@
|
|||
|
||||
package org.rockbox;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.util.Enumeration;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipFile;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.graphics.Rect;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.Window;
|
||||
import android.view.WindowManager;
|
||||
|
||||
public class RockboxActivity extends Activity {
|
||||
/** Called when the activity is first created. */
|
||||
public RockboxFramebuffer fb;
|
||||
private Thread rb;
|
||||
static final int BUFFER = 2048;
|
||||
/** Called when the activity is first created. */
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
public void onCreate(Bundle savedInstanceState)
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
LOG("start rb");
|
||||
requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN
|
||||
,WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
||||
fb = new RockboxFramebuffer(this);
|
||||
if (true) {
|
||||
try
|
||||
,WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
||||
final Intent intent = new Intent(this,
|
||||
RockboxService.class);
|
||||
startService(intent);
|
||||
/* Now it gets a bit tricky:
|
||||
* The service is started in the same thread as we are now,
|
||||
* but the service also initializes the framebuffer
|
||||
* Unforunately, this happens *after* any of the default
|
||||
* startup methods of an activity, so we need to poll for it
|
||||
*
|
||||
* In order to get the fb, we need to let the Service start up
|
||||
* run, we can wait in a separate thread for fb to get ready
|
||||
* This thread waits for the fb to become ready */
|
||||
new Thread(new Runnable()
|
||||
{
|
||||
BufferedOutputStream dest = null;
|
||||
BufferedInputStream is = null;
|
||||
ZipEntry entry;
|
||||
File file = new File("/data/data/org.rockbox/lib/libmisc.so");
|
||||
/* use arbitary file to determine whether extracting is needed */
|
||||
File file2 = new File("/data/data/org.rockbox/app_rockbox/rockbox/codecs/mpa.codec");
|
||||
if (!file2.exists() || (file.lastModified() > file2.lastModified()))
|
||||
{
|
||||
ZipFile zipfile = new ZipFile(file);
|
||||
Enumeration<? extends ZipEntry> e = zipfile.entries();
|
||||
File folder;
|
||||
while(e.hasMoreElements()) {
|
||||
entry = (ZipEntry) e.nextElement();
|
||||
LOG("Extracting: " +entry);
|
||||
if (entry.isDirectory())
|
||||
{
|
||||
folder = new File(entry.getName());
|
||||
LOG("mkdir "+ entry);
|
||||
try {
|
||||
folder.mkdirs();
|
||||
} catch (SecurityException ex){
|
||||
LOG(ex.getMessage());
|
||||
}
|
||||
continue;
|
||||
}
|
||||
is = new BufferedInputStream(zipfile.getInputStream(entry));
|
||||
int count;
|
||||
byte data[] = new byte[BUFFER];
|
||||
folder = new File(new File(entry.getName()).getParent());
|
||||
LOG("" + folder.getAbsolutePath());
|
||||
if (!folder.exists())
|
||||
folder.mkdirs();
|
||||
FileOutputStream fos = new FileOutputStream(entry.getName());
|
||||
dest = new BufferedOutputStream(fos, BUFFER);
|
||||
while ((count = is.read(data, 0, BUFFER)) != -1) {
|
||||
dest.write(data, 0, count);
|
||||
}
|
||||
dest.flush();
|
||||
dest.close();
|
||||
is.close();
|
||||
}
|
||||
}
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}}
|
||||
Rect r = new Rect();
|
||||
fb.getDrawingRect(r);
|
||||
LOG(r.left + " " + r.top + " " + r.right + " " + r.bottom);
|
||||
rb = new Thread(new Runnable()
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
main();
|
||||
}
|
||||
},"Rockbox thread");
|
||||
System.loadLibrary("rockbox");
|
||||
rb.setDaemon(false);
|
||||
setContentView(fb);
|
||||
}
|
||||
|
||||
private void LOG(CharSequence text)
|
||||
{
|
||||
Log.d("RockboxBootloader", (String) text);
|
||||
}
|
||||
|
||||
public synchronized void onStart()
|
||||
{
|
||||
super.onStart();
|
||||
if (!rb.isAlive())
|
||||
rb.start();
|
||||
}
|
||||
|
||||
public void onPause()
|
||||
{
|
||||
super.onPause();
|
||||
public void run() {
|
||||
while (RockboxService.fb == null)
|
||||
{
|
||||
try {
|
||||
Thread.sleep(250);
|
||||
} catch (InterruptedException e) {
|
||||
} catch (Exception e) {
|
||||
LOG(e.toString());
|
||||
}
|
||||
/* drawing needs to happen in ui thread */
|
||||
runOnUiThread(new Runnable()
|
||||
{ @Override
|
||||
public void run() {
|
||||
setContentView(RockboxService.fb);
|
||||
RockboxService.fb.invalidate();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
public void onResume()
|
||||
{
|
||||
super.onResume();
|
||||
switch (rb.getState()) {
|
||||
case BLOCKED: LOG("BLOCKED"); break;
|
||||
case RUNNABLE: LOG("RUNNABLE"); break;
|
||||
case NEW: LOG("NEW"); break;
|
||||
case TERMINATED: LOG("TERMINATED"); break;
|
||||
case TIMED_WAITING: LOG("TIMED_WAITING"); break;
|
||||
case WAITING: LOG("WAITING"); break;
|
||||
if (RockboxService.fb != null)
|
||||
{
|
||||
try {
|
||||
setContentView(RockboxService.fb);
|
||||
} catch (IllegalStateException e) {
|
||||
/* we are already using the View,
|
||||
* need to remove it and re-attach it */
|
||||
ViewGroup g = (ViewGroup)RockboxService.fb.getParent();
|
||||
g.removeView(RockboxService.fb);
|
||||
setContentView(RockboxService.fb);
|
||||
} catch (Exception e) {
|
||||
LOG(e.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private native void main();
|
||||
private void LOG(CharSequence text)
|
||||
{
|
||||
Log.d("Rockbox", (String) text);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue