A modern Music Player Daemon based on Rockbox open source high quality audio player
libadwaita
audio
rust
zig
deno
mpris
rockbox
mpd
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2010 Thomas Martitz
11 *
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.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22package org.rockbox;
23
24
25import android.app.Activity;
26import android.app.ProgressDialog;
27import android.content.Intent;
28import android.os.Bundle;
29import android.os.Handler;
30import android.os.ResultReceiver;
31import android.view.Window;
32import android.view.WindowManager;
33import android.widget.Toast;
34
35public class RockboxActivity extends Activity
36{
37 /** Called when the activity is first created. */
38 @Override
39 public void onCreate(Bundle savedInstanceState)
40 {
41 super.onCreate(savedInstanceState);
42 requestWindowFeature(Window.FEATURE_NO_TITLE);
43 getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
44 WindowManager.LayoutParams.FLAG_FULLSCREEN);
45 Intent intent = new Intent(this, RockboxService.class);
46 intent.setAction(Intent.ACTION_MAIN);
47 intent.putExtra("callback", new ResultReceiver(new Handler(getMainLooper())) {
48 private boolean unzip = false;
49 private ProgressDialog loadingdialog;
50 private void createProgressDialog()
51 {
52 loadingdialog = new ProgressDialog(RockboxActivity.this);
53 loadingdialog.setMessage(getString(R.string.rockbox_extracting));
54 loadingdialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
55 loadingdialog.setIndeterminate(true);
56 loadingdialog.setCancelable(false);
57 loadingdialog.show();
58 }
59
60 @Override
61 protected void onReceiveResult(final int resultCode, final Bundle resultData)
62 {
63 RockboxFramebuffer fb;
64 switch (resultCode) {
65 case RockboxService.RESULT_INVOKING_MAIN:
66 if (loadingdialog != null)
67 loadingdialog.dismiss();
68 fb = new RockboxFramebuffer(RockboxActivity.this);
69 setContentView(fb);
70 fb.requestFocus();
71 break;
72 case RockboxService.RESULT_LIB_LOAD_PROGRESS:
73 if (loadingdialog == null)
74 createProgressDialog();
75 loadingdialog.setIndeterminate(false);
76 loadingdialog.setMax(resultData.getInt("max", 100));
77 loadingdialog.setProgress(resultData.getInt("value", 0));
78 break;
79 case RockboxService.RESULT_LIB_LOADED:
80 unzip = resultData.getBoolean("unzip");
81 break;
82 case RockboxService.RESULT_SERVICE_RUNNING:
83 if (!unzip) /* defer to RESULT_INVOKING_MAIN */
84 {
85 fb = new RockboxFramebuffer(RockboxActivity.this);
86 setContentView(fb);
87 fb.requestFocus();
88 }
89 setServiceActivity(true);
90 break;
91 case RockboxService.RESULT_ERROR_OCCURED:
92 Toast.makeText(RockboxActivity.this, resultData.getString("error"), Toast.LENGTH_LONG);
93 break;
94 case RockboxService.RESULT_ROCKBOX_EXIT:
95 finish();
96 break;
97 }
98 }
99 });
100 startService(intent);
101 }
102
103 private void setServiceActivity(boolean set)
104 {
105 RockboxService s = RockboxService.getInstance();
106 if (s != null)
107 s.setActivity(set ? this : null);
108 }
109
110 public void onResume()
111 {
112 super.onResume();
113 setVisible(true);
114 setServiceActivity(true);
115 }
116
117 /* this is also called when the backlight goes off,
118 * which is nice
119 */
120 @Override
121 protected void onPause()
122 {
123 super.onPause();
124 /* this will cause the framebuffer's Surface to be destroyed, enabling
125 * us to disable drawing */
126 setVisible(false);
127 }
128
129 @Override
130 protected void onStop()
131 {
132 super.onStop();
133 setServiceActivity(false);
134 }
135
136 @Override
137 protected void onDestroy()
138 {
139 super.onDestroy();
140 setServiceActivity(false);
141 }
142}