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 ****************************************************************************/
25 import android
.app
.Activity
;
26 import android
.app
.ProgressDialog
;
27 import android
.content
.Intent
;
28 import android
.os
.Bundle
;
29 import android
.os
.Handler
;
30 import android
.os
.ResultReceiver
;
31 import android
.view
.Window
;
32 import android
.view
.WindowManager
;
33 import android
.widget
.Toast
;
35 public class RockboxActivity
extends Activity
37 /** Called when the activity is first created. */
39 public void onCreate(Bundle savedInstanceState
)
41 super.onCreate(savedInstanceState
);
42 requestWindowFeature(Window
.FEATURE_NO_TITLE
);
43 getWindow().setFlags(WindowManager
.LayoutParams
.FLAG_FULLSCREEN
,
44 WindowManager
.LayoutParams
.FLAG_FULLSCREEN
);
46 Intent intent
= new Intent(this, RockboxService
.class);
47 intent
.setAction(Intent
.ACTION_MAIN
);
48 intent
.putExtra("callback", new ResultReceiver(new Handler(getMainLooper())) {
49 private ProgressDialog loadingdialog
;
51 private void createProgressDialog()
53 loadingdialog
= new ProgressDialog(RockboxActivity
.this);
54 loadingdialog
.setMessage(getString(R
.string
.rockbox_extracting
));
55 loadingdialog
.setProgressStyle(ProgressDialog
.STYLE_HORIZONTAL
);
56 loadingdialog
.setIndeterminate(true);
57 loadingdialog
.setCancelable(false);
62 protected void onReceiveResult(final int resultCode
, final Bundle resultData
)
65 case RockboxService
.RESULT_INVOKING_MAIN
:
66 if (loadingdialog
!= null)
67 loadingdialog
.dismiss();
69 case RockboxService
.RESULT_LIB_LOAD_PROGRESS
:
70 if (loadingdialog
== null)
71 createProgressDialog();
73 loadingdialog
.setIndeterminate(false);
74 loadingdialog
.setMax(resultData
.getInt("max", 100));
75 loadingdialog
.setProgress(resultData
.getInt("value", 0));
77 case RockboxService
.RESULT_SERVICE_RUNNING
:
78 setServiceActivity(true);
80 case RockboxService
.RESULT_ERROR_OCCURED
:
81 Toast
.makeText(RockboxActivity
.this, resultData
.getString("error"), Toast
.LENGTH_LONG
);
83 case RockboxService
.RESULT_ROCKBOX_EXIT
:
89 setContentView(new RockboxFramebuffer(this));
93 private void setServiceActivity(boolean set
)
95 RockboxService s
= RockboxService
.get_instance();
97 s
.set_activity(set ?
this : null);
100 public void onResume()
106 /* this is also called when the backlight goes off,
110 protected void onPause()
113 /* this will cause the framebuffer's Surface to be destroyed, enabling
114 * us to disable drawing */
119 protected void onStop()
122 setServiceActivity(false);
126 protected void onDestroy()
129 setServiceActivity(false);