Merge "Keep local reference to KeyguardStatusViewManager so it doesn't get GC'd" into jb-mr1-dev

This commit is contained in:
Jim Miller
2012-09-05 18:25:43 -07:00
committed by Android (Google) Code Review
3 changed files with 34 additions and 26 deletions

View File

@@ -149,7 +149,6 @@ public class KeyguardSelectorView extends LinearLayout implements KeyguardSecuri
mGlowPadView = (GlowPadView) findViewById(R.id.glow_pad_view);
mGlowPadView.setOnTriggerListener(mOnTriggerListener);
mEmergencyCallButton = (Button) findViewById(R.id.emergency_call_button);
KeyguardUpdateMonitor.getInstance(getContext()).registerCallback(mInfoCallback);
updateTargets();
}

View File

@@ -21,6 +21,8 @@ import android.util.AttributeSet;
import android.widget.GridLayout;
public class KeyguardStatusView extends GridLayout {
private KeyguardStatusViewManager mStatusViewManager;
public KeyguardStatusView(Context context) {
this(context, null, 0);
}
@@ -38,7 +40,7 @@ public class KeyguardStatusView extends GridLayout {
super.onFinishInflate();
// StatusView manages all of the widgets in this view.
new KeyguardStatusViewManager(this);
mStatusViewManager = new KeyguardStatusViewManager(this);
}
}

View File

@@ -100,7 +100,7 @@ public class KeyguardUpdateMonitor {
private boolean mClockVisible;
private ArrayList<WeakReference<KeyguardUpdateMonitorCallback>>
private final ArrayList<WeakReference<KeyguardUpdateMonitorCallback>>
mCallbacks = Lists.newArrayList();
private ContentObserver mContentObserver;
@@ -586,39 +586,46 @@ public class KeyguardUpdateMonitor {
/**
* Remove the given observer's callback.
*
* @param observer The observer to remove
* @param callback The callback to remove
*/
public void removeCallback(Object observer) {
mCallbacks.remove(observer);
public void removeCallback(KeyguardUpdateMonitorCallback callback) {
if (DEBUG) Log.v(TAG, "*** unregister callback for " + callback);
for (int i = mCallbacks.size() - 1; i >= 0; i--) {
if (mCallbacks.get(i).get() == callback) {
mCallbacks.remove(i);
}
}
}
/**
* Register to receive notifications about general keyguard information
* (see {@link InfoCallback}.
* @param callback The callback.
* @param callback The callback to register
*/
public void registerCallback(KeyguardUpdateMonitorCallback callback) {
if (!mCallbacks.contains(callback)) {
mCallbacks.add(new WeakReference<KeyguardUpdateMonitorCallback>(callback));
// Notify listener of the current state
callback.onRefreshBatteryInfo(mBatteryStatus);
callback.onTimeChanged();
callback.onRingerModeChanged(mRingMode);
callback.onPhoneStateChanged(mPhoneState);
callback.onRefreshCarrierInfo(mTelephonyPlmn, mTelephonySpn);
callback.onClockVisibilityChanged();
callback.onSimStateChanged(mSimState);
} else {
if (DEBUG) Log.e(TAG, "Object tried to add another callback",
new Exception("Called by"));
}
// Clean up any unused references
for (int i = mCallbacks.size() - 1; i >= 0; i--) {
if (mCallbacks.get(i).get() == null) {
mCallbacks.remove(i);
if (DEBUG) Log.v(TAG, "*** register callback for " + callback);
// Prevent adding duplicate callbacks
for (int i = 0; i < mCallbacks.size(); i++) {
if (mCallbacks.get(i).get() == callback) {
if (DEBUG) Log.e(TAG, "Object tried to add another callback",
new Exception("Called by"));
return;
}
}
mCallbacks.add(new WeakReference<KeyguardUpdateMonitorCallback>(callback));
removeCallback(null); // remove unused references
sendUpdates(callback);
}
private void sendUpdates(KeyguardUpdateMonitorCallback callback) {
// Notify listener of the current state
callback.onRefreshBatteryInfo(mBatteryStatus);
callback.onTimeChanged();
callback.onRingerModeChanged(mRingMode);
callback.onPhoneStateChanged(mPhoneState);
callback.onRefreshCarrierInfo(mTelephonyPlmn, mTelephonySpn);
callback.onClockVisibilityChanged();
callback.onSimStateChanged(mSimState);
}
public void reportClockVisible(boolean visible) {