Refactoring

This commit is contained in:
M66B
2024-01-22 08:13:27 +01:00
parent 7002cf44cf
commit 56a63dc66e
7 changed files with 84 additions and 30 deletions

View File

@@ -24,6 +24,8 @@ import android.util.AttributeSet;
import android.view.MotionEvent;
import android.widget.RelativeLayout;
import androidx.annotation.NonNull;
import java.util.Map;
import java.util.WeakHashMap;
@@ -54,7 +56,14 @@ public class FixedRelativeLayout extends RelativeLayout {
}
}
private final Map<Runnable, Runnable> mapRunnable = new WeakHashMap<>();
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) {
@@ -64,7 +73,7 @@ public class FixedRelativeLayout extends RelativeLayout {
action.run();
}
};
mapRunnable.put(action, wrapped);
getMapRunnable().put(action, wrapped);
return super.post(wrapped);
}
@@ -76,13 +85,13 @@ public class FixedRelativeLayout extends RelativeLayout {
action.run();
}
};
mapRunnable.put(action, wrapped);
getMapRunnable().put(action, wrapped);
return super.postDelayed(wrapped, delayMillis);
}
@Override
public boolean removeCallbacks(Runnable action) {
Runnable wrapped = mapRunnable.get(action);
Runnable wrapped = getMapRunnable().get(action);
if (wrapped == null)
return super.removeCallbacks(action);
else