Fix crashing of font size settings screen due to the timing
of initialization of ExploreByTouchHelper Bug: 27674946 Change-Id: Ief92b5db975861aa31029712854e78edf4454eb5
This commit is contained in:
@@ -139,6 +139,9 @@ public class LabeledSeekBar extends SeekBar {
|
||||
|
||||
private ExploreByTouchHelper mAccessHelper;
|
||||
|
||||
private boolean mOnMeasureCalled;
|
||||
private boolean mOnAttachedWindowCalled;
|
||||
|
||||
public LabeledSeekBar(Context context, AttributeSet attrs) {
|
||||
this(context, attrs, com.android.internal.R.attr.seekBarStyle);
|
||||
}
|
||||
@@ -204,11 +207,18 @@ public class LabeledSeekBar extends SeekBar {
|
||||
super.setOnSeekBarChangeListener(l2);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
||||
mOnMeasureCalled = true;
|
||||
tryInitAccessHelper();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onAttachedToWindow() {
|
||||
super.onAttachedToWindow();
|
||||
mAccessHelper = new LabeledSeekBarExploreByTouchHelper(this);
|
||||
ViewCompat.setAccessibilityDelegate(this, mAccessHelper);
|
||||
mOnAttachedWindowCalled = true;
|
||||
tryInitAccessHelper();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -227,6 +237,18 @@ public class LabeledSeekBar extends SeekBar {
|
||||
return super.dispatchHoverEvent(event);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize accessibility delegation only when both onAttachedWindow and onMeasure
|
||||
* has been called.
|
||||
*/
|
||||
private void tryInitAccessHelper() {
|
||||
if (mOnAttachedWindowCalled && mOnMeasureCalled) {
|
||||
mAccessHelper = new LabeledSeekBarExploreByTouchHelper(this);
|
||||
ViewCompat.setAccessibilityDelegate(this, mAccessHelper);
|
||||
mOnAttachedWindowCalled = mOnMeasureCalled = false;
|
||||
}
|
||||
}
|
||||
|
||||
private void sendClickEventForAccessibility(int progress) {
|
||||
if (mAccessHelper != null) {
|
||||
mAccessHelper.invalidateRoot();
|
||||
|
Reference in New Issue
Block a user