Android: Slightly rework logging to logcat by offloading duplicated code to a new...
[kugel-rb.git] / android / src / org / rockbox / RockboxActivity.java
blob355c57daa83f86894ba387c32956100595aff46f
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.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. */
38 @Override
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);
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;
83 case RockboxService.RESULT_ROCKBOX_EXIT:
84 finish();
85 break;
88 });
89 setContentView(new RockboxFramebuffer(this));
90 startService(intent);
93 private void setServiceActivity(boolean set)
95 RockboxService s = RockboxService.get_instance();
96 if (s != null)
97 s.set_activity(set ? this : null);
100 public void onResume()
102 super.onResume();
103 setVisible(true);
106 /* this is also called when the backlight goes off,
107 * which is nice
109 @Override
110 protected void onPause()
112 super.onPause();
113 /* this will cause the framebuffer's Surface to be destroyed, enabling
114 * us to disable drawing */
115 setVisible(false);
118 @Override
119 protected void onStop()
121 super.onStop();
122 setServiceActivity(false);
125 @Override
126 protected void onDestroy()
128 super.onDestroy();
129 setServiceActivity(false);