|
18 | 18 | import java.net.URLDecoder; |
19 | 19 | import java.util.Date; |
20 | 20 | import java.util.HashMap; |
| 21 | +import java.util.Locale; |
21 | 22 | import java.util.Map; |
22 | 23 | import java.util.Properties; |
23 | 24 | import java.util.Queue; |
@@ -59,6 +60,7 @@ public class MainActivity extends NativeActivity { |
59 | 60 | private boolean _untrusted = false; |
60 | 61 | private ExecutorService _audioExecutor = Executors.newSingleThreadExecutor(); |
61 | 62 | private Queue<Sound> _sounds = new ConcurrentLinkedQueue<Sound>(); |
| 63 | + private float _ringVolume; |
62 | 64 |
|
63 | 65 | static { |
64 | 66 | System.loadLibrary("smallbasic"); |
@@ -128,10 +130,7 @@ public void onClick(DialogInterface dialog, int index) { |
128 | 130 | } |
129 | 131 |
|
130 | 132 | public void playTone(int frq, int dur, int vol) { |
131 | | - AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); |
132 | | - float ringVolume = audioManager.getStreamVolume(AudioManager.STREAM_RING); |
133 | | - float maxRingVolume = audioManager.getStreamMaxVolume(AudioManager.STREAM_RING); |
134 | | - float volume = (vol / 100f) * (ringVolume / maxRingVolume); |
| 133 | + float volume = (vol / 100f) * _ringVolume; |
135 | 134 | Log.i(TAG, "playTone: " + frq + " " + dur + " " + vol + " " + volume); |
136 | 135 |
|
137 | 136 | final Sound sound = new Sound(frq, dur, volume); |
@@ -203,6 +202,11 @@ protected void onCreate(Bundle savedInstanceState) { |
203 | 202 | } catch (Exception e) { |
204 | 203 | Log.i(TAG, "Failed to start web service: ", e); |
205 | 204 | } |
| 205 | + |
| 206 | + AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); |
| 207 | + float ringVolume = audioManager.getStreamVolume(AudioManager.STREAM_RING); |
| 208 | + float maxRingVolume = audioManager.getStreamMaxVolume(AudioManager.STREAM_RING); |
| 209 | + _ringVolume = ringVolume / maxRingVolume; |
206 | 210 | } |
207 | 211 |
|
208 | 212 | private String buildRunForm(String buffer, String token) { |
@@ -285,7 +289,7 @@ private Map<String, String> getPostData(DataInputStream inputStream, String line |
285 | 289 | int length = 0; |
286 | 290 | final String lengthHeader = "content-length: "; |
287 | 291 | while (line != null && line.length() > 0) { |
288 | | - if (line.toLowerCase().startsWith(lengthHeader)) { |
| 292 | + if (line.toLowerCase(Locale.ENGLISH).startsWith(lengthHeader)) { |
289 | 293 | length = Integer.valueOf(line.substring(lengthHeader.length())); |
290 | 294 | } |
291 | 295 | line = readLine(inputStream); |
|
0 commit comments