Merge broadcast receivers again

It's probably simpler not to have registers dance around,
and just message the feedback manager when the audio event
happens.

Change-Id: Id0710ed102d10d01f1af93ad8cb660653bb3a9f8
main
Jean Chalard 2012-03-09 11:00:23 +09:00
parent 7b77c683d7
commit 21af2f40c5
2 changed files with 7 additions and 21 deletions

View File

@ -16,9 +16,7 @@
package com.android.inputmethod.latin; package com.android.inputmethod.latin;
import android.content.BroadcastReceiver;
import android.content.Context; import android.content.Context;
import android.content.Intent;
import android.media.AudioManager; import android.media.AudioManager;
import android.view.HapticFeedbackConstants; import android.view.HapticFeedbackConstants;
import android.view.View; import android.view.View;
@ -32,7 +30,7 @@ import com.android.inputmethod.keyboard.Keyboard;
* It offers a consistent and simple interface that allows LatinIME to forget about the * It offers a consistent and simple interface that allows LatinIME to forget about the
* complexity of settings and the like. * complexity of settings and the like.
*/ */
public class AudioAndHapticFeedbackManager extends BroadcastReceiver { public class AudioAndHapticFeedbackManager {
final private SettingsValues mSettingsValues; final private SettingsValues mSettingsValues;
final private AudioManager mAudioManager; final private AudioManager mAudioManager;
final private VibratorCompatWrapper mVibrator; final private VibratorCompatWrapper mVibrator;
@ -100,13 +98,7 @@ public class AudioAndHapticFeedbackManager extends BroadcastReceiver {
} }
} }
@Override public void onRingerModeChanged() {
public void onReceive(Context context, Intent intent) { mSoundOn = reevaluateIfSoundIsOn();
final String action = intent.getAction();
// The following test is supposedly useless since we only listen for the ringer event.
// Still, it's a good safety measure.
if (action.equals(AudioManager.RINGER_MODE_CHANGED_ACTION)) {
mSoundOn = reevaluateIfSoundIsOn();
}
} }
} }

View File

@ -532,6 +532,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
// Also receive installation and removal of a dictionary pack. // Also receive installation and removal of a dictionary pack.
final IntentFilter filter = new IntentFilter(); final IntentFilter filter = new IntentFilter();
filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION); filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
filter.addAction(AudioManager.RINGER_MODE_CHANGED_ACTION);
registerReceiver(mReceiver, filter); registerReceiver(mReceiver, filter);
mVoiceProxy = VoiceProxy.init(this, prefs, mHandler); mVoiceProxy = VoiceProxy.init(this, prefs, mHandler);
@ -547,19 +548,11 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
registerReceiver(mDictionaryPackInstallReceiver, newDictFilter); registerReceiver(mDictionaryPackInstallReceiver, newDictFilter);
} }
private void renewFeedbackReceiver() {
if (null != mFeedbackManager) unregisterReceiver(mFeedbackManager);
mFeedbackManager = new AudioAndHapticFeedbackManager(this, mSettingsValues);
final IntentFilter ringerModeFilter = new IntentFilter();
ringerModeFilter.addAction(AudioManager.RINGER_MODE_CHANGED_ACTION);
registerReceiver(mFeedbackManager, ringerModeFilter);
}
// Has to be package-visible for unit tests // Has to be package-visible for unit tests
/* package */ void loadSettings() { /* package */ void loadSettings() {
if (null == mPrefs) mPrefs = PreferenceManager.getDefaultSharedPreferences(this); if (null == mPrefs) mPrefs = PreferenceManager.getDefaultSharedPreferences(this);
mSettingsValues = new SettingsValues(mPrefs, this, mSubtypeSwitcher.getInputLocaleStr()); mSettingsValues = new SettingsValues(mPrefs, this, mSubtypeSwitcher.getInputLocaleStr());
renewFeedbackReceiver(); mFeedbackManager = new AudioAndHapticFeedbackManager(this, mSettingsValues);
resetContactsDictionary(null == mSuggest ? null : mSuggest.getContactsDictionary()); resetContactsDictionary(null == mSuggest ? null : mSuggest.getContactsDictionary());
} }
@ -648,7 +641,6 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
mSuggest = null; mSuggest = null;
} }
unregisterReceiver(mReceiver); unregisterReceiver(mReceiver);
unregisterReceiver(mFeedbackManager);
unregisterReceiver(mDictionaryPackInstallReceiver); unregisterReceiver(mDictionaryPackInstallReceiver);
mVoiceProxy.destroy(); mVoiceProxy.destroy();
LatinImeLogger.commit(); LatinImeLogger.commit();
@ -2356,6 +2348,8 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
final String action = intent.getAction(); final String action = intent.getAction();
if (action.equals(ConnectivityManager.CONNECTIVITY_ACTION)) { if (action.equals(ConnectivityManager.CONNECTIVITY_ACTION)) {
mSubtypeSwitcher.onNetworkStateChanged(intent); mSubtypeSwitcher.onNetworkStateChanged(intent);
} else if (action.equals(AudioManager.RINGER_MODE_CHANGED_ACTION)) {
mFeedbackManager.onRingerModeChanged();
} }
} }
}; };