Clover Coverage Report - Subsonic-Android Coverage Report
Coverage timestamp: ven dic 19 2014 17:57:13 EST
../../../../../img/srcFileCovDistChart6.png 65% of files have more coverage
34   138   24   3,09
14   90   0,71   5,5
11     2,18  
2    
This report was generated with an evaluation server license. Purchase Clover or configure your license.
 
  EqualizerController       Line # 35 22 17 66,7% 0.6666667
  EqualizerController.EqualizerSettings       Line # 108 12 7 45% 0.45
 
No Tests
 
1    /*
2    This file is part of Subsonic.
3   
4    Subsonic is free software: you can redistribute it and/or modify
5    it under the terms of the GNU General Public License as published by
6    the Free Software Foundation, either version 3 of the License, or
7    (at your option) any later version.
8   
9    Subsonic is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12    GNU General Public License for more details.
13   
14    You should have received a copy of the GNU General Public License
15    along with Subsonic. If not, see <http://www.gnu.org/licenses/>.
16   
17    Copyright 2011 (C) Sindre Mehus
18    */
19    package net.sourceforge.subsonic.androidapp.audiofx;
20   
21    import java.io.Serializable;
22   
23    import android.content.Context;
24    import android.media.MediaPlayer;
25    import android.media.audiofx.Equalizer;
26    import android.util.Log;
27    import net.sourceforge.subsonic.androidapp.util.FileUtil;
28   
29    /**
30    * Backward-compatible wrapper for {@link Equalizer}, which is API Level 9.
31    *
32    * @author Sindre Mehus
33    * @version $Id$
34    */
 
35    public class EqualizerController {
36   
37    private static final String TAG = EqualizerController.class.getSimpleName();
38   
39    private final Context context;
40    private Equalizer equalizer;
41   
42    // Class initialization fails when this throws an exception.
 
43  1 toggle static {
44  1 try {
45  1 Class.forName("android.media.audiofx.Equalizer");
46    } catch (Exception ex) {
47  0 throw new RuntimeException(ex);
48    }
49    }
50   
51    /**
52    * Throws an exception if the {@link Equalizer} class is not available.
53    */
 
54  1 toggle public static void checkAvailable() throws Throwable {
55    // Calling here forces class initialization.
56    }
57   
 
58  1 toggle public EqualizerController(Context context, MediaPlayer mediaPlayer) {
59  1 this.context = context;
60  1 try {
61  1 equalizer = new Equalizer(0, mediaPlayer.getAudioSessionId());
62    } catch (Throwable x) {
63  0 Log.w(TAG, "Failed to create equalizer.", x);
64    }
65    }
66   
 
67  2 toggle public void saveSettings() {
68  2 try {
69  2 if (isAvailable()) {
70  2 FileUtil.serialize(context, new EqualizerSettings(equalizer), "equalizer.dat");
71    }
72    } catch (Throwable x) {
73  0 Log.w(TAG, "Failed to save equalizer settings.", x);
74    }
75    }
76   
 
77  1 toggle public void loadSettings() {
78  1 try {
79  1 if (isAvailable()) {
80  1 EqualizerSettings settings = FileUtil.deserialize(context, "equalizer.dat");
81  1 if (settings != null) {
82  0 settings.apply(equalizer);
83    }
84    }
85    } catch (Throwable x) {
86  0 Log.w(TAG, "Failed to load equalizer settings.", x);
87    }
88    }
89   
 
90  23 toggle public boolean isAvailable() {
91  23 return equalizer != null;
92    }
93   
 
94  19 toggle public boolean isEnabled() {
95  19 return isAvailable() && equalizer.getEnabled();
96    }
97   
 
98  0 toggle public void release() {
99  0 if (isAvailable()) {
100  0 equalizer.release();
101    }
102    }
103   
 
104  2 toggle public Equalizer getEqualizer() {
105  2 return equalizer;
106    }
107   
 
108    private static class EqualizerSettings implements Serializable {
109   
110    private final short[] bandLevels;
111    private short preset;
112    private final boolean enabled;
113   
 
114  2 toggle public EqualizerSettings(Equalizer equalizer) {
115  2 enabled = equalizer.getEnabled();
116  2 bandLevels = new short[equalizer.getNumberOfBands()];
117  12 for (short i = 0; i < equalizer.getNumberOfBands(); i++) {
118  10 bandLevels[i] = equalizer.getBandLevel(i);
119    }
120  2 try {
121  2 preset = equalizer.getCurrentPreset();
122    } catch (Exception x) {
123  0 preset = -1;
124    }
125    }
126   
 
127  0 toggle public void apply(Equalizer equalizer) {
128  0 for (short i = 0; i < bandLevels.length; i++) {
129  0 equalizer.setBandLevel(i, bandLevels[i]);
130    }
131  0 if (preset >= 0 && preset < equalizer.getNumberOfPresets()) {
132  0 equalizer.usePreset(preset);
133    }
134  0 equalizer.setEnabled(enabled);
135    }
136    }
137    }
138