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
.util
.Log
;
29 import android
.view
.ViewGroup
;
30 import android
.view
.Window
;
31 import android
.view
.WindowManager
;
33 public class RockboxActivity
extends Activity
35 private ProgressDialog loadingdialog
;
36 /** Called when the activity is first created. */
38 public void onCreate(Bundle savedInstanceState
)
40 super.onCreate(savedInstanceState
);
41 requestWindowFeature(Window
.FEATURE_NO_TITLE
);
42 getWindow().setFlags(WindowManager
.LayoutParams
.FLAG_FULLSCREEN
43 ,WindowManager
.LayoutParams
.FLAG_FULLSCREEN
);
44 final Intent intent
= new Intent(this,
45 RockboxService
.class);
46 loadingdialog
= new ProgressDialog(this);
47 loadingdialog
.setMessage("Rockbox Loading. Please wait...");
48 loadingdialog
.setProgressStyle(ProgressDialog
.STYLE_SPINNER
);
49 loadingdialog
.setCancelable(false);
52 /* Now it gets a bit tricky:
53 * The service is started in the same thread as we are now,
54 * but the service also initializes the framebuffer
55 * Unfortunately, this happens *after* any of the default
56 * startup methods of an activity, so we need to poll for it
58 * In order to get the fb, we need to let the Service start up
59 * run, we can wait in a separate thread for fb to get ready
60 * This thread waits for the fb to become ready */
61 new Thread(new Runnable()
66 while (RockboxService
.fb
== null)
68 } catch (InterruptedException e
) {
69 } catch (Exception e
) {
72 /* drawing needs to happen in ui thread */
73 runOnUiThread(new Runnable()
76 loadingdialog
.dismiss();
77 setContentView(RockboxService
.fb
);
78 RockboxService
.fb
.invalidate();
85 public void onResume()
89 if (RockboxService
.fb
!= null)
92 setContentView(RockboxService
.fb
);
93 } catch (IllegalStateException e
) {
94 /* we are already using the View,
95 * need to remove it and re-attach it */
96 ViewGroup g
= (ViewGroup
)RockboxService
.fb
.getParent();
97 g
.removeView(RockboxService
.fb
);
98 setContentView(RockboxService
.fb
);
100 RockboxService
.fb
.resume();
104 /* this is also called when the backlight goes off,
108 protected void onPause()
111 RockboxService
.fb
.suspend();
115 protected void onStop()
118 RockboxService
.fb
.suspend();
122 protected void onDestroy()
125 RockboxService
.fb
.suspend();
128 private void LOG(CharSequence text
)
130 Log
.d("Rockbox", (String
) text
);