Move java_core_sleep (now jave_wait_for_interrupt) to the Timer,
[kugel-rb.git] / android / src / org / rockbox / RockboxActivity.java
blob791cad90ff4a3a8ec2021437d1c3f9d27d7386ac
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2010 Thomas Martitz
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
22 package org.rockbox;
24 import java.io.BufferedInputStream;
25 import java.io.BufferedOutputStream;
26 import java.io.File;
27 import java.io.FileOutputStream;
28 import java.util.Enumeration;
29 import java.util.zip.ZipEntry;
30 import java.util.zip.ZipFile;
32 import android.app.Activity;
33 import android.graphics.Rect;
34 import android.os.Bundle;
35 import android.util.Log;
36 import android.view.Window;
37 import android.view.WindowManager;
39 public class RockboxActivity extends Activity {
40 /** Called when the activity is first created. */
41 public RockboxFramebuffer fb;
42 private Thread rb;
43 static final int BUFFER = 2048;
44 /** Called when the activity is first created. */
45 @Override
46 public void onCreate(Bundle savedInstanceState) {
47 super.onCreate(savedInstanceState);
48 LOG("start rb");
49 requestWindowFeature(Window.FEATURE_NO_TITLE);
50 getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN
51 ,WindowManager.LayoutParams.FLAG_FULLSCREEN);
52 fb = new RockboxFramebuffer(this);
53 if (true) {
54 try
56 BufferedOutputStream dest = null;
57 BufferedInputStream is = null;
58 ZipEntry entry;
59 File file = new File("/data/data/org.rockbox/lib/libmisc.so");
60 /* use arbitary file to determine whether extracting is needed */
61 File file2 = new File("/data/data/org.rockbox/app_rockbox/rockbox/codecs/mpa.codec");
62 if (!file2.exists() || (file.lastModified() > file2.lastModified()))
64 ZipFile zipfile = new ZipFile(file);
65 Enumeration<? extends ZipEntry> e = zipfile.entries();
66 File folder;
67 while(e.hasMoreElements()) {
68 entry = (ZipEntry) e.nextElement();
69 LOG("Extracting: " +entry);
70 if (entry.isDirectory())
72 folder = new File(entry.getName());
73 LOG("mkdir "+ entry);
74 try {
75 folder.mkdirs();
76 } catch (SecurityException ex){
77 LOG(ex.getMessage());
79 continue;
81 is = new BufferedInputStream(zipfile.getInputStream(entry));
82 int count;
83 byte data[] = new byte[BUFFER];
84 folder = new File(new File(entry.getName()).getParent());
85 LOG("" + folder.getAbsolutePath());
86 if (!folder.exists())
87 folder.mkdirs();
88 FileOutputStream fos = new FileOutputStream(entry.getName());
89 dest = new BufferedOutputStream(fos, BUFFER);
90 while ((count = is.read(data, 0, BUFFER)) != -1) {
91 dest.write(data, 0, count);
93 dest.flush();
94 dest.close();
95 is.close();
98 } catch(Exception e) {
99 e.printStackTrace();
101 Rect r = new Rect();
102 fb.getDrawingRect(r);
103 LOG(r.left + " " + r.top + " " + r.right + " " + r.bottom);
104 rb = new Thread(new Runnable()
106 public void run()
108 main();
110 },"Rockbox thread");
111 System.loadLibrary("rockbox");
112 rb.setDaemon(false);
113 setContentView(fb);
116 private void LOG(CharSequence text)
118 Log.d("RockboxBootloader", (String) text);
121 public synchronized void onStart()
123 super.onStart();
124 if (!rb.isAlive())
125 rb.start();
128 public void onPause()
130 super.onPause();
133 public void onResume()
135 super.onResume();
136 switch (rb.getState()) {
137 case BLOCKED: LOG("BLOCKED"); break;
138 case RUNNABLE: LOG("RUNNABLE"); break;
139 case NEW: LOG("NEW"); break;
140 case TERMINATED: LOG("TERMINATED"); break;
141 case TIMED_WAITING: LOG("TIMED_WAITING"); break;
142 case WAITING: LOG("WAITING"); break;
147 private native void main();