Loading java/res/values/keypress-volumes.xml 0 → 100644 +27 −0 Original line number Diff line number Diff line <?xml version="1.0" encoding="utf-8"?> <!-- /* ** ** Copyright 2011, The Android Open Source Project ** ** Licensed under the Apache License, Version 2.0 (the "License"); ** you may not use this file except in compliance with the License. ** You may obtain a copy of the License at ** ** http://www.apache.org/licenses/LICENSE-2.0 ** ** Unless required by applicable law or agreed to in writing, software ** distributed under the License is distributed on an "AS IS" BASIS, ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ** See the License for the specific language governing permissions and ** limitations under the License. */ --> <resources> <string-array name="keypress_volumes" translatable="false"> <!-- Build.HARDWARE,volume --> <item>herring,0.05</item> <item>tuna,0.05</item> <item>stingray,0.04</item> </string-array> </resources> java/src/com/android/inputmethod/latin/LatinIME.java +21 −17 Original line number Diff line number Diff line Loading @@ -209,7 +209,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar private long mLastKeyTime; private AudioManager mAudioManager; private static float mFxVolume = -1.0f; // just a default value to be updated runtime private float mFxVolume = -1.0f; // default volume private boolean mSilentModeOn; // System-wide current configuration private VibratorCompatWrapper mVibrator; Loading Loading @@ -2050,13 +2050,14 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar // update sound effect volume private void updateSoundEffectVolume() { if (mAudioManager == null) { mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); if (mAudioManager == null) return; final String[] volumePerHardwareList = mResources.getStringArray(R.array.keypress_volumes); final String hardwarePrefix = Build.HARDWARE + ","; for (final String element : volumePerHardwareList) { if (element.startsWith(hardwarePrefix)) { mFxVolume = Float.parseFloat(element.substring(element.lastIndexOf(',') + 1)); break; } } // This aligns with the current media volume minus 6dB mFxVolume = (float) mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC) / (float) mAudioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC) / 4.0f; } // update flags for silent mode Loading Loading @@ -2090,7 +2091,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar } } if (isSoundOn()) { int sound = AudioManager.FX_KEYPRESS_STANDARD; final int sound; switch (primaryCode) { case Keyboard.CODE_DELETE: sound = AudioManager.FX_KEYPRESS_DELETE; Loading @@ -2101,6 +2102,9 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar case Keyboard.CODE_SPACE: sound = AudioManager.FX_KEYPRESS_SPACEBAR; break; default: sound = AudioManager.FX_KEYPRESS_STANDARD; break; } mAudioManager.playSoundEffect(sound, mFxVolume); } Loading Loading
java/res/values/keypress-volumes.xml 0 → 100644 +27 −0 Original line number Diff line number Diff line <?xml version="1.0" encoding="utf-8"?> <!-- /* ** ** Copyright 2011, The Android Open Source Project ** ** Licensed under the Apache License, Version 2.0 (the "License"); ** you may not use this file except in compliance with the License. ** You may obtain a copy of the License at ** ** http://www.apache.org/licenses/LICENSE-2.0 ** ** Unless required by applicable law or agreed to in writing, software ** distributed under the License is distributed on an "AS IS" BASIS, ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ** See the License for the specific language governing permissions and ** limitations under the License. */ --> <resources> <string-array name="keypress_volumes" translatable="false"> <!-- Build.HARDWARE,volume --> <item>herring,0.05</item> <item>tuna,0.05</item> <item>stingray,0.04</item> </string-array> </resources>
java/src/com/android/inputmethod/latin/LatinIME.java +21 −17 Original line number Diff line number Diff line Loading @@ -209,7 +209,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar private long mLastKeyTime; private AudioManager mAudioManager; private static float mFxVolume = -1.0f; // just a default value to be updated runtime private float mFxVolume = -1.0f; // default volume private boolean mSilentModeOn; // System-wide current configuration private VibratorCompatWrapper mVibrator; Loading Loading @@ -2050,13 +2050,14 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar // update sound effect volume private void updateSoundEffectVolume() { if (mAudioManager == null) { mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); if (mAudioManager == null) return; final String[] volumePerHardwareList = mResources.getStringArray(R.array.keypress_volumes); final String hardwarePrefix = Build.HARDWARE + ","; for (final String element : volumePerHardwareList) { if (element.startsWith(hardwarePrefix)) { mFxVolume = Float.parseFloat(element.substring(element.lastIndexOf(',') + 1)); break; } } // This aligns with the current media volume minus 6dB mFxVolume = (float) mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC) / (float) mAudioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC) / 4.0f; } // update flags for silent mode Loading Loading @@ -2090,7 +2091,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar } } if (isSoundOn()) { int sound = AudioManager.FX_KEYPRESS_STANDARD; final int sound; switch (primaryCode) { case Keyboard.CODE_DELETE: sound = AudioManager.FX_KEYPRESS_DELETE; Loading @@ -2101,6 +2102,9 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar case Keyboard.CODE_SPACE: sound = AudioManager.FX_KEYPRESS_SPACEBAR; break; default: sound = AudioManager.FX_KEYPRESS_STANDARD; break; } mAudioManager.playSoundEffect(sound, mFxVolume); } Loading