Fix the size and position of the illumination dot

Bug: 162700441
Test: manual on device
Change-Id: I1238f160f190a3c5cac0335f13200c7dc3ff7ba7
This commit is contained in:
Ilya Matyukhin
2020-08-17 16:46:52 -07:00
parent 7d605ec38a
commit 5f7a2b6b72
3 changed files with 17 additions and 16 deletions

View File

@@ -5,6 +5,6 @@
android:id="@+id/udfps_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
systemui:sensorRadius="140px"
systemui:sensorMarginBottom="630px"
systemui:sensorRadius="130px"
systemui:sensorCenterY="1636px"
systemui:sensorTouchAreaCoefficient="0.5"/>

View File

@@ -159,7 +159,7 @@
<declare-styleable name="UdfpsView">
<attr name="sensorRadius" format="dimension"/>
<attr name="sensorMarginBottom" format="dimension"/>
<attr name="sensorCenterY" format="dimension"/>
<attr name="sensorPressureCoefficient" format="float"/>
<attr name="sensorTouchAreaCoefficient" format="float"/>
</declare-styleable>

View File

@@ -53,12 +53,10 @@ public class UdfpsView extends View implements DozeReceiver,
private final Paint mScrimPaint;
private final Paint mDebugTextPaint;
private float mSensorX;
private float mSensorY;
private final RectF mSensorRect;
private final Paint mSensorPaint;
private final float mSensorRadius;
private final float mSensorMarginBottom;
private final float mSensorCenterY;
private final float mSensorTouchAreaCoefficient;
private final int mMaxBurnInOffsetX;
private final int mMaxBurnInOffsetY;
@@ -66,6 +64,10 @@ public class UdfpsView extends View implements DozeReceiver,
private final Rect mTouchableRegion;
private final ViewTreeObserver.OnComputeInternalInsetsListener mInsetsListener;
// This is calculated from the screen's dimensions at runtime, as opposed to mSensorCenterY,
// which is defined in layout.xml
private float mSensorCenterX;
// AOD anti-burn-in offsets
private float mInterpolatedDarkAmount;
private float mBurnInOffsetX;
@@ -84,7 +86,7 @@ public class UdfpsView extends View implements DozeReceiver,
if (!a.hasValue(R.styleable.UdfpsView_sensorRadius)) {
throw new IllegalArgumentException("UdfpsView must contain sensorRadius");
}
if (!a.hasValue(R.styleable.UdfpsView_sensorMarginBottom)) {
if (!a.hasValue(R.styleable.UdfpsView_sensorCenterY)) {
throw new IllegalArgumentException("UdfpsView must contain sensorMarginBottom");
}
if (!a.hasValue(R.styleable.UdfpsView_sensorTouchAreaCoefficient)) {
@@ -92,7 +94,7 @@ public class UdfpsView extends View implements DozeReceiver,
"UdfpsView must contain sensorTouchAreaCoefficient");
}
mSensorRadius = a.getDimension(R.styleable.UdfpsView_sensorRadius, 0f);
mSensorMarginBottom = a.getDimension(R.styleable.UdfpsView_sensorMarginBottom, 0f);
mSensorCenterY = a.getDimension(R.styleable.UdfpsView_sensorCenterY, 0f);
mSensorTouchAreaCoefficient = a.getFloat(
R.styleable.UdfpsView_sensorTouchAreaCoefficient, 0f);
} finally {
@@ -163,10 +165,9 @@ public class UdfpsView extends View implements DozeReceiver,
final int h = getLayoutParams().height;
final int w = getLayoutParams().width;
mScrimRect.set(0 /* left */, 0 /* top */, w, h);
mSensorX = w / 2f;
mSensorY = h - mSensorMarginBottom - mSensorRadius;
mSensorRect.set(mSensorX - mSensorRadius, mSensorY - mSensorRadius,
mSensorX + mSensorRadius, mSensorY + mSensorRadius);
mSensorCenterX = w / 2f;
mSensorRect.set(mSensorCenterX - mSensorRadius, mSensorCenterY - mSensorRadius,
mSensorCenterX + mSensorRadius, mSensorCenterY + mSensorRadius);
// Sets mTouchableRegion with rounded up values from mSensorRect.
mSensorRect.roundOut(mTouchableRegion);
@@ -210,10 +211,10 @@ public class UdfpsView extends View implements DozeReceiver,
}
boolean isValidTouch(float x, float y, float pressure) {
return x > (mSensorX - mSensorRadius * mSensorTouchAreaCoefficient)
&& x < (mSensorX + mSensorRadius * mSensorTouchAreaCoefficient)
&& y > (mSensorY - mSensorRadius * mSensorTouchAreaCoefficient)
&& y < (mSensorY + mSensorRadius * mSensorTouchAreaCoefficient);
return x > (mSensorCenterX - mSensorRadius * mSensorTouchAreaCoefficient)
&& x < (mSensorCenterX + mSensorRadius * mSensorTouchAreaCoefficient)
&& y > (mSensorCenterY - mSensorRadius * mSensorTouchAreaCoefficient)
&& y < (mSensorCenterY + mSensorRadius * mSensorTouchAreaCoefficient);
}
void setScrimAlpha(int alpha) {