A modern Music Player Daemon based on Rockbox open source high quality audio player
libadwaita audio rust zig deno mpris rockbox mpd
at master 131 lines 5.4 kB view raw
1/*************************************************************************** 2 * __________ __ ___. 3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___ 4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / 5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < 6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ 7 * \/ \/ \/ \/ \/ 8 * $Id$ 9 * 10 * Copyright (C) 2011 Antoine Cellerier <dionoea at videolan dot org> 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.widgets; 23 24import org.rockbox.R; 25import org.rockbox.RockboxService; 26 27import android.app.Activity; 28import android.appwidget.AppWidgetManager; 29import android.content.Context; 30import android.content.Intent; 31import android.content.SharedPreferences; 32import android.net.Uri; 33import android.os.Bundle; 34import android.view.View; 35import android.widget.CheckBox; 36 37public class RockboxWidgetConfigure extends Activity 38{ 39 int mAppWidgetId = AppWidgetManager.INVALID_APPWIDGET_ID; 40 41 public RockboxWidgetConfigure() 42 { 43 super(); 44 } 45 46 @Override 47 public void onCreate(Bundle savedInstanceState) 48 { 49 super.onCreate(savedInstanceState); 50 51 setResult(RESULT_CANCELED); 52 setContentView(R.layout.appwidget_configure); 53 54 ((CheckBox)findViewById(R.id.enable_aa)).setChecked(true); 55 ((CheckBox)findViewById(R.id.enable_prev)).setChecked(false); 56 ((CheckBox)findViewById(R.id.enable_stop)).setChecked(true); 57 ((CheckBox)findViewById(R.id.enable_playpause)).setChecked(true); 58 ((CheckBox)findViewById(R.id.enable_next)).setChecked(false); 59 60 findViewById(R.id.confirm).setOnClickListener(mCreateWidget); 61 62 Intent intent = getIntent(); 63 Bundle extras = intent.getExtras(); 64 if (extras != null) 65 mAppWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID); 66 67 if (mAppWidgetId == AppWidgetManager.INVALID_APPWIDGET_ID) 68 finish(); 69 } 70 71 View.OnClickListener mCreateWidget = new View.OnClickListener() 72 { 73 public void onClick(View v) 74 { 75 final Context context = RockboxWidgetConfigure.this; 76 77 WidgetPref state = new WidgetPref(); 78 state.enableAA = ((CheckBox)findViewById(R.id.enable_aa)).isChecked(); 79 state.enablePrev = ((CheckBox)findViewById(R.id.enable_prev)).isChecked(); 80 state.enableStop = ((CheckBox)findViewById(R.id.enable_stop)).isChecked(); 81 state.enablePlayPause = ((CheckBox)findViewById(R.id.enable_playpause)).isChecked(); 82 state.enableNext = ((CheckBox)findViewById(R.id.enable_next)).isChecked(); 83 saveWidgetPref(context, mAppWidgetId, state); 84 85 AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context); 86 RockboxWidgetProvider.getInstance().updateAppWidget(context, appWidgetManager, mAppWidgetId, null); 87 88 /* Ask for track information so that new widgets display properly 89 * if rockbox was already playing */ 90 context.startService(new Intent("org.rockbox.ResendTrackUpdateInfo", 91 Uri.EMPTY, context, RockboxService.class)); 92 93 Intent result = new Intent(); 94 result.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, mAppWidgetId); 95 setResult(RESULT_OK, result); 96 finish(); 97 } 98 }; 99 100 static public class WidgetPref 101 { 102 public boolean enableAA = true; 103 public boolean enablePrev = true; 104 public boolean enableStop = true; 105 public boolean enablePlayPause = true; 106 public boolean enableNext = true; 107 } 108 109 static void saveWidgetPref(Context context, int appWidgetId, WidgetPref state) 110 { 111 SharedPreferences.Editor prefs = context.getSharedPreferences("org.rockbox.RockboxWidgetConfigure", 0).edit(); 112 prefs.putBoolean("albumart"+appWidgetId, state.enableAA); 113 prefs.putBoolean("prev"+appWidgetId, state.enablePrev); 114 prefs.putBoolean("stop"+appWidgetId, state.enableStop); 115 prefs.putBoolean("playpause"+appWidgetId, state.enablePlayPause); 116 prefs.putBoolean("next"+appWidgetId, state.enableNext); 117 prefs.commit(); 118 } 119 120 static WidgetPref loadWidgetPref(Context context, int appWidgetId) 121 { 122 SharedPreferences prefs = context.getSharedPreferences("org.rockbox.RockboxWidgetConfigure", 0); 123 WidgetPref state = new WidgetPref(); 124 state.enableAA = prefs.getBoolean("albumart"+appWidgetId, true); 125 state.enablePrev = prefs.getBoolean("prev"+appWidgetId, true); 126 state.enableStop = prefs.getBoolean("stop"+appWidgetId, true); 127 state.enablePlayPause = prefs.getBoolean("playpause"+appWidgetId, true); 128 state.enableNext = prefs.getBoolean("next"+appWidgetId, true); 129 return state; 130 } 131}