am 3cd46244: Merge "Avoid memory leak by only registering callback while attached to window." into jb-dev
* commit '3cd4624448dcaddecc75461ef645da72e7e5c098': Avoid memory leak by only registering callback while attached to window.
This commit is contained in:
@@ -39,6 +39,8 @@ public class MediaRouteButton extends View {
|
|||||||
private final MediaRouteCallback mRouterCallback = new MediaRouteCallback();
|
private final MediaRouteCallback mRouterCallback = new MediaRouteCallback();
|
||||||
private int mRouteTypes;
|
private int mRouteTypes;
|
||||||
|
|
||||||
|
private boolean mAttachedToWindow;
|
||||||
|
|
||||||
private Drawable mRemoteIndicator;
|
private Drawable mRemoteIndicator;
|
||||||
private boolean mRemoteActive;
|
private boolean mRemoteActive;
|
||||||
private boolean mToggleMode;
|
private boolean mToggleMode;
|
||||||
@@ -132,13 +134,22 @@ public class MediaRouteButton extends View {
|
|||||||
// Already registered; nothing to do.
|
// Already registered; nothing to do.
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (mRouteTypes != 0) {
|
|
||||||
|
if (mAttachedToWindow && mRouteTypes != 0) {
|
||||||
mRouter.removeCallback(mRouterCallback);
|
mRouter.removeCallback(mRouterCallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
mRouteTypes = types;
|
mRouteTypes = types;
|
||||||
|
|
||||||
|
if (mAttachedToWindow) {
|
||||||
|
updateRouteInfo();
|
||||||
|
mRouter.addCallback(types, mRouterCallback);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateRouteInfo() {
|
||||||
updateRemoteIndicator();
|
updateRemoteIndicator();
|
||||||
updateRouteCount();
|
updateRouteCount();
|
||||||
mRouter.addCallback(types, mRouterCallback);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getRouteTypes() {
|
public int getRouteTypes() {
|
||||||
@@ -213,6 +224,25 @@ public class MediaRouteButton extends View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onAttachedToWindow() {
|
||||||
|
super.onAttachedToWindow();
|
||||||
|
mAttachedToWindow = true;
|
||||||
|
if (mRouteTypes != 0) {
|
||||||
|
mRouter.addCallback(mRouteTypes, mRouterCallback);
|
||||||
|
updateRouteInfo();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDetachedFromWindow() {
|
||||||
|
if (mRouteTypes != 0) {
|
||||||
|
mRouter.removeCallback(mRouterCallback);
|
||||||
|
}
|
||||||
|
mAttachedToWindow = false;
|
||||||
|
super.onDetachedFromWindow();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||||
final int widthSize = MeasureSpec.getSize(widthMeasureSpec);
|
final int widthSize = MeasureSpec.getSize(widthMeasureSpec);
|
||||||
|
|||||||
Reference in New Issue
Block a user