Initialize (instantiate) RockboxFramebuffer from the C code like with the othe java...
[maemo-rb.git] / android / src / org / rockbox / RockboxActivity.java
blobb4ca9a6d2a88bab72c4f7a5f45e8755cf9e710c6
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 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. */
37 @Override
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);
50 loadingdialog.show();
51 startService(intent);
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()
63 public void run()
65 try {
66 while (RockboxService.fb == null)
67 Thread.sleep(250);
68 } catch (InterruptedException e) {
69 } catch (Exception e) {
70 LOG(e.toString());
72 /* drawing needs to happen in ui thread */
73 runOnUiThread(new Runnable()
75 public void run() {
76 loadingdialog.dismiss();
77 setContentView(RockboxService.fb);
78 RockboxService.fb.invalidate();
80 });
82 }).start();
85 public void onResume()
87 super.onResume();
89 if (RockboxService.fb != null)
91 try {
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,
105 * which is nice
107 @Override
108 protected void onPause()
110 super.onPause();
111 RockboxService.fb.suspend();
114 @Override
115 protected void onStop()
117 super.onStop();
118 RockboxService.fb.suspend();
121 @Override
122 protected void onDestroy()
124 super.onDestroy();
125 RockboxService.fb.suspend();
128 private void LOG(CharSequence text)
130 Log.d("Rockbox", (String) text);