Android: Delay the progress dialog so it's not shown until after 0.5s are over. This...
[maemo-rb.git] / android / src / org / rockbox / RockboxActivity.java
blob6226455deb3056f466d1cdc56e830b653f529aba
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.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. */
36 @Override
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);
52 startService(intent);
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()
64 public void run()
66 int i = 0;
67 try {
68 while (true)
70 Thread.sleep(250);
71 if (RockboxService.fb != null)
72 break;
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()
79 public void run()
81 loadingdialog.show();
83 });
85 else
86 i++ ;
88 } catch (InterruptedException e) {
90 /* drawing needs to happen in ui thread */
91 runOnUiThread(new Runnable()
93 public void run() {
94 loadingdialog.dismiss();
95 if (RockboxService.fb == null)
96 throw new IllegalStateException("FB NULL");
97 setContentView(RockboxService.fb);
98 RockboxService.fb.invalidate();
102 }).start();
105 public void onResume()
107 super.onResume();
109 if (RockboxService.fb != null)
111 try {
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);
119 } finally {
120 RockboxService.fb.resume();
125 /* this is also called when the backlight goes off,
126 * which is nice
128 @Override
129 protected void onPause()
131 super.onPause();
132 RockboxService.fb.suspend();
135 @Override
136 protected void onStop()
138 super.onStop();
139 RockboxService.fb.suspend();
142 @Override
143 protected void onDestroy()
145 super.onDestroy();
146 RockboxService.fb.suspend();