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
.util
.Log
;
32 import android
.view
.Window
;
33 import android
.view
.WindowManager
;
34 import android
.widget
.Toast
;
36 public class RockboxActivity
extends Activity
38 /** Called when the activity is first created. */
40 public void onCreate(Bundle savedInstanceState
)
42 super.onCreate(savedInstanceState
);
43 requestWindowFeature(Window
.FEATURE_NO_TITLE
);
44 getWindow().setFlags(WindowManager
.LayoutParams
.FLAG_FULLSCREEN
,
45 WindowManager
.LayoutParams
.FLAG_FULLSCREEN
);
47 Intent intent
= new Intent(this, RockboxService
.class);
48 intent
.setAction(Intent
.ACTION_MAIN
);
49 intent
.putExtra("callback", new ResultReceiver(new Handler(getMainLooper())) {
50 private ProgressDialog loadingdialog
;
52 private void createProgressDialog()
54 loadingdialog
= new ProgressDialog(RockboxActivity
.this);
55 loadingdialog
.setMessage(getString(R
.string
.rockbox_extracting
));
56 loadingdialog
.setProgressStyle(ProgressDialog
.STYLE_HORIZONTAL
);
57 loadingdialog
.setIndeterminate(true);
58 loadingdialog
.setCancelable(false);
63 protected void onReceiveResult(final int resultCode
, final Bundle resultData
)
66 case RockboxService
.RESULT_INVOKING_MAIN
:
67 if (loadingdialog
!= null)
68 loadingdialog
.dismiss();
70 case RockboxService
.RESULT_LIB_LOAD_PROGRESS
:
71 if (loadingdialog
== null)
72 createProgressDialog();
74 loadingdialog
.setIndeterminate(false);
75 loadingdialog
.setMax(resultData
.getInt("max", 100));
76 loadingdialog
.setProgress(resultData
.getInt("value", 0));
78 case RockboxService
.RESULT_SERVICE_RUNNING
:
79 setServiceActivity(true);
81 case RockboxService
.RESULT_ERROR_OCCURED
:
82 Toast
.makeText(RockboxActivity
.this, resultData
.getString("error"), Toast
.LENGTH_LONG
);
84 case RockboxService
.RESULT_ROCKBOX_EXIT
:
90 setContentView(new RockboxFramebuffer(this));
94 private void setServiceActivity(boolean set
)
96 RockboxService s
= RockboxService
.get_instance();
98 s
.set_activity(set ?
this : null);
101 public void onResume()
107 /* this is also called when the backlight goes off,
111 protected void onPause()
114 /* this will cause the framebuffer's Surface to be destroyed, enabling
115 * us to disable drawing */
120 protected void onStop()
123 setServiceActivity(false);
127 protected void onDestroy()
130 setServiceActivity(false);
133 private void LOG(CharSequence text
)
135 Log
.d("Rockbox", (String
) text
);