Merge "Replace the cached MotionEvent with getX() value to improve GC state" into sc-v2-dev
This commit is contained in:
@@ -108,7 +108,7 @@ public class BatteryChartView extends AppCompatImageView implements View.OnClick
|
|||||||
Paint mTrapezoidCurvePaint = null;
|
Paint mTrapezoidCurvePaint = null;
|
||||||
private TrapezoidSlot[] mTrapezoidSlots;
|
private TrapezoidSlot[] mTrapezoidSlots;
|
||||||
// Records the location to calculate selected index.
|
// Records the location to calculate selected index.
|
||||||
private MotionEvent mTouchUpEvent;
|
private float mTouchUpEventX = Float.MIN_VALUE;
|
||||||
private BatteryChartView.OnSelectListener mOnSelectListener;
|
private BatteryChartView.OnSelectListener mOnSelectListener;
|
||||||
|
|
||||||
public BatteryChartView(Context context) {
|
public BatteryChartView(Context context) {
|
||||||
@@ -255,20 +255,20 @@ public class BatteryChartView extends AppCompatImageView implements View.OnClick
|
|||||||
// Caches the location to calculate selected trapezoid index.
|
// Caches the location to calculate selected trapezoid index.
|
||||||
final int action = event.getAction();
|
final int action = event.getAction();
|
||||||
if (action == MotionEvent.ACTION_UP) {
|
if (action == MotionEvent.ACTION_UP) {
|
||||||
mTouchUpEvent = MotionEvent.obtain(event);
|
mTouchUpEventX = event.getX();
|
||||||
} else if (action == MotionEvent.ACTION_CANCEL) {
|
} else if (action == MotionEvent.ACTION_CANCEL) {
|
||||||
mTouchUpEvent = null; // reset
|
mTouchUpEventX = Float.MIN_VALUE; // reset
|
||||||
}
|
}
|
||||||
return super.onTouchEvent(event);
|
return super.onTouchEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
if (mTouchUpEvent == null) {
|
if (mTouchUpEventX == Float.MIN_VALUE) {
|
||||||
Log.w(TAG, "invalid motion event for onClick() callback");
|
Log.w(TAG, "invalid motion event for onClick() callback");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final int trapezoidIndex = getTrapezoidIndex(mTouchUpEvent.getX());
|
final int trapezoidIndex = getTrapezoidIndex(mTouchUpEventX);
|
||||||
// Ignores the click event if the level is zero.
|
// Ignores the click event if the level is zero.
|
||||||
if (trapezoidIndex == SELECTED_INDEX_INVALID
|
if (trapezoidIndex == SELECTED_INDEX_INVALID
|
||||||
|| !isValidToDraw(trapezoidIndex)) {
|
|| !isValidToDraw(trapezoidIndex)) {
|
||||||
|
Reference in New Issue
Block a user