Android: Implement app shutdown and thus, sleep timer.
[kugel-rb.git] / android / src / org / rockbox / RockboxActivity.java
blobcae05102292f18f6078e5d525bbfaab5e3649ec8
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.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);
59 loadingdialog.show();
62 @Override
63 protected void onReceiveResult(final int resultCode, final Bundle resultData)
65 switch (resultCode) {
66 case RockboxService.RESULT_INVOKING_MAIN:
67 if (loadingdialog != null)
68 loadingdialog.dismiss();
69 break;
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));
77 break;
78 case RockboxService.RESULT_SERVICE_RUNNING:
79 setServiceActivity(true);
80 break;
81 case RockboxService.RESULT_ERROR_OCCURED:
82 Toast.makeText(RockboxActivity.this, resultData.getString("error"), Toast.LENGTH_LONG);
83 break;
84 case RockboxService.RESULT_ROCKBOX_EXIT:
85 finish();
86 break;
89 });
90 setContentView(new RockboxFramebuffer(this));
91 startService(intent);
94 private void setServiceActivity(boolean set)
96 RockboxService s = RockboxService.get_instance();
97 if (s != null)
98 s.set_activity(set ? this : null);
101 public void onResume()
103 super.onResume();
104 setVisible(true);
107 /* this is also called when the backlight goes off,
108 * which is nice
110 @Override
111 protected void onPause()
113 super.onPause();
114 /* this will cause the framebuffer's Surface to be destroyed, enabling
115 * us to disable drawing */
116 setVisible(false);
119 @Override
120 protected void onStop()
122 super.onStop();
123 setServiceActivity(false);
126 @Override
127 protected void onDestroy()
129 super.onDestroy();
130 setServiceActivity(false);
133 private void LOG(CharSequence text)
135 Log.d("Rockbox", (String) text);