1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
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 ****************************************************************************/
24 import android
.app
.Activity
;
25 import android
.app
.ProgressDialog
;
26 import android
.content
.Intent
;
27 import android
.os
.Bundle
;
28 import android
.view
.ViewGroup
;
29 import android
.view
.Window
;
30 import android
.view
.WindowManager
;
32 public class RockboxActivity
extends Activity
34 private ProgressDialog loadingdialog
;
35 /** Called when the activity is first created. */
37 public void onCreate(Bundle savedInstanceState
)
39 super.onCreate(savedInstanceState
);
40 requestWindowFeature(Window
.FEATURE_NO_TITLE
);
41 getWindow().setFlags(WindowManager
.LayoutParams
.FLAG_FULLSCREEN
42 ,WindowManager
.LayoutParams
.FLAG_FULLSCREEN
);
43 final Intent intent
= new Intent(this,
44 RockboxService
.class);
45 /* prepare a please wait dialog in case we need
46 * to wait for unzipping libmisc.so
48 loadingdialog
= new ProgressDialog(this);
49 loadingdialog
.setMessage("Rockbox is loading. Please wait...");
50 loadingdialog
.setProgressStyle(ProgressDialog
.STYLE_SPINNER
);
51 loadingdialog
.setCancelable(false);
53 /* Now it gets a bit tricky:
54 * The service is started in the same thread as we are now,
55 * but the service also initializes the framebuffer
56 * Unfortunately, this happens *after* any of the default
57 * startup methods of an activity, so we need to poll for it
59 * In order to get the fb, we need to let the Service start up
60 * run, we can wait in a separate thread for fb to get ready
61 * This thread waits for the fb to become ready */
62 new Thread(new Runnable()
71 if (RockboxService
.fb
!= null)
73 /* if it's still null show the please wait dialog
74 * but not before 0.5s are over */
75 if (!loadingdialog
.isShowing() && i
> 0)
77 runOnUiThread(new Runnable()
88 } catch (InterruptedException e
) {
90 /* drawing needs to happen in ui thread */
91 runOnUiThread(new Runnable()
94 loadingdialog
.dismiss();
95 if (RockboxService
.fb
== null)
96 throw new IllegalStateException("FB NULL");
97 setContentView(RockboxService
.fb
);
98 RockboxService
.fb
.invalidate();
105 public void onResume()
109 if (RockboxService
.fb
!= null)
112 setContentView(RockboxService
.fb
);
113 } catch (IllegalStateException e
) {
114 /* we are already using the View,
115 * need to remove it and re-attach it */
116 ViewGroup g
= (ViewGroup
)RockboxService
.fb
.getParent();
117 g
.removeView(RockboxService
.fb
);
118 setContentView(RockboxService
.fb
);
120 RockboxService
.fb
.resume();
125 /* this is also called when the backlight goes off,
129 protected void onPause()
132 RockboxService
.fb
.suspend();
136 protected void onStop()
139 RockboxService
.fb
.suspend();
143 protected void onDestroy()
146 RockboxService
.fb
.suspend();