Android:
[kugel-rb.git] / android / src / org / rockbox / RockboxActivity.java
blob65c7f92bbe9f6a074d36f74e578d6a3b89c9fb49
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;
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. */
39 @Override
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.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);
58 loadingdialog.show();
61 @Override
62 protected void onReceiveResult(final int resultCode, final Bundle resultData)
64 switch (resultCode) {
65 case RockboxService.RESULT_INVOKING_MAIN:
66 if (loadingdialog != null)
67 loadingdialog.dismiss();
68 break;
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));
76 break;
77 case RockboxService.RESULT_SERVICE_RUNNING:
78 setServiceActivity(true);
79 break;
80 case RockboxService.RESULT_ERROR_OCCURED:
81 Toast.makeText(RockboxActivity.this, resultData.getString("error"), Toast.LENGTH_LONG);
82 break;
85 });
86 setContentView(new RockboxFramebuffer(this));
87 startService(intent);
90 private void setServiceActivity(boolean set)
92 RockboxService s = RockboxService.get_instance();
93 if (s != null)
94 s.set_activity(set ? this : null);
97 public void onResume()
99 super.onResume();
100 setVisible(true);
103 /* this is also called when the backlight goes off,
104 * which is nice
106 @Override
107 protected void onPause()
109 super.onPause();
110 /* this will cause the framebuffer's Surface to be destroyed, enabling
111 * us to disable drawing */
112 setVisible(false);
115 @Override
116 protected void onStop()
118 super.onStop();
119 setServiceActivity(false);
122 @Override
123 protected void onDestroy()
125 super.onDestroy();
126 setServiceActivity(false);
129 private void LOG(CharSequence text)
131 Log.d("Rockbox", (String) text);