Fixed runnable memory leaks

pull/215/head
M66B 6 months ago
parent 9a7bb254cc
commit b3cc164eef

@ -27,9 +27,6 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.constraintlayout.widget.ConstraintLayout; import androidx.constraintlayout.widget.ConstraintLayout;
import java.util.Map;
import java.util.WeakHashMap;
public class FixedConstraintLayout extends ConstraintLayout { public class FixedConstraintLayout extends ConstraintLayout {
public FixedConstraintLayout(@NonNull Context context) { public FixedConstraintLayout(@NonNull Context context) {
super(context); super(context);
@ -122,46 +119,4 @@ public class FixedConstraintLayout extends ConstraintLayout {
return false; return false;
} }
} }
private Map<Runnable, Runnable> mapRunnable = null;
@NonNull
private Map<Runnable, Runnable> getMapRunnable() {
if (mapRunnable == null)
mapRunnable = new WeakHashMap<>();
return mapRunnable;
}
@Override
public boolean post(Runnable action) {
Runnable wrapped = new RunnableEx("post") {
@Override
protected void delegate() {
action.run();
}
};
getMapRunnable().put(action, wrapped);
return super.post(wrapped);
}
@Override
public boolean postDelayed(Runnable action, long delayMillis) {
Runnable wrapped = new RunnableEx("postDelayed") {
@Override
protected void delegate() {
action.run();
}
};
getMapRunnable().put(action, wrapped);
return super.postDelayed(wrapped, delayMillis);
}
@Override
public boolean removeCallbacks(Runnable action) {
Runnable wrapped = getMapRunnable().get(action);
if (wrapped == null)
return super.removeCallbacks(action);
else
return super.removeCallbacks(wrapped);
}
} }

@ -27,9 +27,6 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.coordinatorlayout.widget.CoordinatorLayout; import androidx.coordinatorlayout.widget.CoordinatorLayout;
import java.util.Map;
import java.util.WeakHashMap;
public class FixedCoordinatorLayout extends CoordinatorLayout { public class FixedCoordinatorLayout extends CoordinatorLayout {
public FixedCoordinatorLayout(@NonNull Context context) { public FixedCoordinatorLayout(@NonNull Context context) {
super(context); super(context);
@ -62,46 +59,4 @@ public class FixedCoordinatorLayout extends CoordinatorLayout {
return false; return false;
} }
} }
private Map<Runnable, Runnable> mapRunnable = null;
@NonNull
private Map<Runnable, Runnable> getMapRunnable() {
if (mapRunnable == null)
mapRunnable = new WeakHashMap<>();
return mapRunnable;
}
@Override
public boolean post(Runnable action) {
Runnable wrapped = new RunnableEx("post") {
@Override
protected void delegate() {
action.run();
}
};
getMapRunnable().put(action, wrapped);
return super.post(wrapped);
}
@Override
public boolean postDelayed(Runnable action, long delayMillis) {
Runnable wrapped = new RunnableEx("postDelayed") {
@Override
protected void delegate() {
action.run();
}
};
getMapRunnable().put(action, wrapped);
return super.postDelayed(wrapped, delayMillis);
}
@Override
public boolean removeCallbacks(Runnable action) {
Runnable wrapped = getMapRunnable().get(action);
if (wrapped == null)
return super.removeCallbacks(action);
else
return super.removeCallbacks(wrapped);
}
} }

@ -27,9 +27,6 @@ import android.widget.FrameLayout;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import java.util.Map;
import java.util.WeakHashMap;
public class FixedFrameLayout extends FrameLayout { public class FixedFrameLayout extends FrameLayout {
public FixedFrameLayout(@NonNull Context context) { public FixedFrameLayout(@NonNull Context context) {
super(context); super(context);
@ -75,46 +72,4 @@ public class FixedFrameLayout extends FrameLayout {
return false; return false;
} }
} }
private Map<Runnable, Runnable> mapRunnable = null;
@NonNull
private Map<Runnable, Runnable> getMapRunnable() {
if (mapRunnable == null)
mapRunnable = new WeakHashMap<>();
return mapRunnable;
}
@Override
public boolean post(Runnable action) {
Runnable wrapped = new RunnableEx("post") {
@Override
protected void delegate() {
action.run();
}
};
getMapRunnable().put(action, wrapped);
return super.post(wrapped);
}
@Override
public boolean postDelayed(Runnable action, long delayMillis) {
Runnable wrapped = new RunnableEx("postDelayed") {
@Override
protected void delegate() {
action.run();
}
};
getMapRunnable().put(action, wrapped);
return super.postDelayed(wrapped, delayMillis);
}
@Override
public boolean removeCallbacks(Runnable action) {
Runnable wrapped = getMapRunnable().get(action);
if (wrapped == null)
return super.removeCallbacks(action);
else
return super.removeCallbacks(wrapped);
}
} }

@ -24,12 +24,8 @@ import android.util.AttributeSet;
import android.view.MotionEvent; import android.view.MotionEvent;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import java.util.Map;
import java.util.WeakHashMap;
public class FixedLinearLayout extends LinearLayout { public class FixedLinearLayout extends LinearLayout {
public FixedLinearLayout(Context context) { public FixedLinearLayout(Context context) {
super(context); super(context);
@ -56,46 +52,4 @@ public class FixedLinearLayout extends LinearLayout {
return false; return false;
} }
} }
private Map<Runnable, Runnable> mapRunnable = null;
@NonNull
private Map<Runnable, Runnable> getMapRunnable() {
if (mapRunnable == null)
mapRunnable = new WeakHashMap<>();
return mapRunnable;
}
@Override
public boolean post(Runnable action) {
Runnable wrapped = new RunnableEx("post") {
@Override
protected void delegate() {
action.run();
}
};
getMapRunnable().put(action, wrapped);
return super.post(wrapped);
}
@Override
public boolean postDelayed(Runnable action, long delayMillis) {
Runnable wrapped = new RunnableEx("postDelayed") {
@Override
protected void delegate() {
action.run();
}
};
getMapRunnable().put(action, wrapped);
return super.postDelayed(wrapped, delayMillis);
}
@Override
public boolean removeCallbacks(Runnable action) {
Runnable wrapped = getMapRunnable().get(action);
if (wrapped == null)
return super.removeCallbacks(action);
else
return super.removeCallbacks(wrapped);
}
} }

@ -32,9 +32,6 @@ import androidx.annotation.Nullable;
import androidx.recyclerview.widget.FastScrollerEx; import androidx.recyclerview.widget.FastScrollerEx;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
import java.util.Map;
import java.util.WeakHashMap;
public class FixedRecyclerView extends RecyclerView { public class FixedRecyclerView extends RecyclerView {
public FixedRecyclerView(@NonNull Context context) { public FixedRecyclerView(@NonNull Context context) {
super(context); super(context);
@ -210,70 +207,4 @@ public class FixedRecyclerView extends RecyclerView {
*/ */
} }
} }
private Map<Runnable, Runnable> mapRunnable = null;
@NonNull
private Map<Runnable, Runnable> getMapRunnable() {
if (mapRunnable == null)
mapRunnable = new WeakHashMap<>();
return mapRunnable;
}
@Override
public boolean post(Runnable action) {
Runnable wrapped = new RunnableEx("post") {
@Override
protected void delegate() {
action.run();
}
};
getMapRunnable().put(action, wrapped);
return super.post(wrapped);
}
@Override
public boolean postDelayed(Runnable action, long delayMillis) {
Runnable wrapped = new RunnableEx("postDelayed") {
@Override
protected void delegate() {
action.run();
}
};
getMapRunnable().put(action, wrapped);
return super.postDelayed(wrapped, delayMillis);
}
@Override
public void postOnAnimation(Runnable action) {
Runnable wrapped = new RunnableEx("postOnAnimation") {
@Override
protected void delegate() {
action.run();
}
};
getMapRunnable().put(action, wrapped);
super.postOnAnimation(wrapped);
}
@Override
public void postOnAnimationDelayed(Runnable action, long delayMillis) {
Runnable wrapped = new RunnableEx("postOnAnimationDelayed") {
@Override
protected void delegate() {
action.run();
}
};
getMapRunnable().put(action, wrapped);
super.postOnAnimationDelayed(wrapped, delayMillis);
}
@Override
public boolean removeCallbacks(Runnable action) {
Runnable wrapped = getMapRunnable().get(action);
if (wrapped == null)
return super.removeCallbacks(action);
else
return super.removeCallbacks(wrapped);
}
} }

@ -24,11 +24,6 @@ import android.util.AttributeSet;
import android.view.MotionEvent; import android.view.MotionEvent;
import android.widget.RelativeLayout; import android.widget.RelativeLayout;
import androidx.annotation.NonNull;
import java.util.Map;
import java.util.WeakHashMap;
public class FixedRelativeLayout extends RelativeLayout { public class FixedRelativeLayout extends RelativeLayout {
public FixedRelativeLayout(Context context) { public FixedRelativeLayout(Context context) {
super(context); super(context);
@ -55,46 +50,4 @@ public class FixedRelativeLayout extends RelativeLayout {
return false; return false;
} }
} }
private Map<Runnable, Runnable> mapRunnable = null;
@NonNull
private Map<Runnable, Runnable> getMapRunnable() {
if (mapRunnable == null)
mapRunnable = new WeakHashMap<>();
return mapRunnable;
}
@Override
public boolean post(Runnable action) {
Runnable wrapped = new RunnableEx("post") {
@Override
protected void delegate() {
action.run();
}
};
getMapRunnable().put(action, wrapped);
return super.post(wrapped);
}
@Override
public boolean postDelayed(Runnable action, long delayMillis) {
Runnable wrapped = new RunnableEx("postDelayed") {
@Override
protected void delegate() {
action.run();
}
};
getMapRunnable().put(action, wrapped);
return super.postDelayed(wrapped, delayMillis);
}
@Override
public boolean removeCallbacks(Runnable action) {
Runnable wrapped = getMapRunnable().get(action);
if (wrapped == null)
return super.removeCallbacks(action);
else
return super.removeCallbacks(wrapped);
}
} }

@ -5,11 +5,6 @@ import android.util.AttributeSet;
import android.view.MotionEvent; import android.view.MotionEvent;
import android.widget.ScrollView; import android.widget.ScrollView;
import androidx.annotation.NonNull;
import java.util.Map;
import java.util.WeakHashMap;
/* /*
This file is part of FairEmail. This file is part of FairEmail.
@ -134,46 +129,4 @@ public class FixedScrollView extends ScrollView {
return false; return false;
} }
} }
private Map<Runnable, Runnable> mapRunnable = null;
@NonNull
private Map<Runnable, Runnable> getMapRunnable() {
if (mapRunnable == null)
mapRunnable = new WeakHashMap<>();
return mapRunnable;
}
@Override
public boolean post(Runnable action) {
Runnable wrapped = new RunnableEx("post") {
@Override
protected void delegate() {
action.run();
}
};
getMapRunnable().put(action, wrapped);
return super.post(wrapped);
}
@Override
public boolean postDelayed(Runnable action, long delayMillis) {
Runnable wrapped = new RunnableEx("postDelayed") {
@Override
protected void delegate() {
action.run();
}
};
getMapRunnable().put(action, wrapped);
return super.postDelayed(wrapped, delayMillis);
}
@Override
public boolean removeCallbacks(Runnable action) {
Runnable wrapped = getMapRunnable().get(action);
if (wrapped == null)
return super.removeCallbacks(action);
else
return super.removeCallbacks(wrapped);
}
} }

Loading…
Cancel
Save