Merge changes from topics "cc-composing-update", "cc-merge-equals" into sc-dev
* changes: ContentCapture: Don't ignore events with changed composing/selection span ContentCapture: Notify when Composing region changes.
This commit is contained in:
@@ -286,6 +286,15 @@ public final class ContentCaptureEvent implements Parcelable {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
boolean hasSameComposingSpan(@NonNull ContentCaptureEvent other) {
|
||||||
|
return mComposingStart == other.mComposingStart && mComposingEnd == other.mComposingEnd;
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean hasSameSelectionSpan(@NonNull ContentCaptureEvent other) {
|
||||||
|
return mSelectionStartIndex == other.mSelectionStartIndex
|
||||||
|
&& mSelectionEndIndex == other.mSelectionEndIndex;
|
||||||
|
}
|
||||||
|
|
||||||
private int getComposingStart() {
|
private int getComposingStart() {
|
||||||
return mComposingStart;
|
return mComposingStart;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -368,7 +368,10 @@ public final class MainContentCaptureSession extends ContentCaptureSession {
|
|||||||
final CharSequence lastText = lastEvent.getText();
|
final CharSequence lastText = lastEvent.getText();
|
||||||
final boolean bothNonEmpty = !TextUtils.isEmpty(lastText)
|
final boolean bothNonEmpty = !TextUtils.isEmpty(lastText)
|
||||||
&& !TextUtils.isEmpty(text);
|
&& !TextUtils.isEmpty(text);
|
||||||
boolean equalContent = TextUtils.equals(lastText, text);
|
boolean equalContent =
|
||||||
|
TextUtils.equals(lastText, text)
|
||||||
|
&& lastEvent.hasSameComposingSpan(event)
|
||||||
|
&& lastEvent.hasSameSelectionSpan(event);
|
||||||
if (equalContent) {
|
if (equalContent) {
|
||||||
addEvent = false;
|
addEvent = false;
|
||||||
} else if (bothNonEmpty) {
|
} else if (bothNonEmpty) {
|
||||||
|
|||||||
@@ -162,6 +162,17 @@ public class BaseInputConnection implements InputConnection {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called after only the composing region is modified (so it isn't called if the text also
|
||||||
|
* changes).
|
||||||
|
* <p>
|
||||||
|
* Default implementation does nothing.
|
||||||
|
*
|
||||||
|
* @hide
|
||||||
|
*/
|
||||||
|
public void endComposingRegionEditInternal() {
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default implementation calls {@link #finishComposingText()} and
|
* Default implementation calls {@link #finishComposingText()} and
|
||||||
* {@code setImeConsumesInput(false)}.
|
* {@code setImeConsumesInput(false)}.
|
||||||
@@ -468,6 +479,7 @@ public class BaseInputConnection implements InputConnection {
|
|||||||
// Note: sendCurrentText does nothing unless mFallbackMode is set
|
// Note: sendCurrentText does nothing unless mFallbackMode is set
|
||||||
sendCurrentText();
|
sendCurrentText();
|
||||||
endBatchEdit();
|
endBatchEdit();
|
||||||
|
endComposingRegionEditInternal();
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -734,6 +746,7 @@ public class BaseInputConnection implements InputConnection {
|
|||||||
// Note: sendCurrentText does nothing unless mFallbackMode is set
|
// Note: sendCurrentText does nothing unless mFallbackMode is set
|
||||||
sendCurrentText();
|
sendCurrentText();
|
||||||
endBatchEdit();
|
endBatchEdit();
|
||||||
|
endComposingRegionEditInternal();
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10832,11 +10832,19 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
notifyContentCaptureTextChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Notifies the ContentCapture service that the text of the view has changed (only if
|
||||||
|
* ContentCapture has been notified of this view's existence already).
|
||||||
|
*
|
||||||
|
* @hide
|
||||||
|
*/
|
||||||
|
public void notifyContentCaptureTextChanged() {
|
||||||
// TODO(b/121045053): should use a flag / boolean to keep status of SHOWN / HIDDEN instead
|
// TODO(b/121045053): should use a flag / boolean to keep status of SHOWN / HIDDEN instead
|
||||||
// of using isLaidout(), so it's not called in cases where it's laid out but a
|
// of using isLaidout(), so it's not called in cases where it's laid out but a
|
||||||
// notifyAppeared was not sent.
|
// notifyAppeared was not sent.
|
||||||
|
|
||||||
// ContentCapture
|
|
||||||
if (isLaidOut() && isImportantForContentCapture() && getNotifiedContentCaptureAppeared()) {
|
if (isLaidOut() && isImportantForContentCapture() && getNotifiedContentCaptureAppeared()) {
|
||||||
final ContentCaptureManager cm = mContext.getSystemService(ContentCaptureManager.class);
|
final ContentCaptureManager cm = mContext.getSystemService(ContentCaptureManager.class);
|
||||||
if (cm != null && cm.isContentCaptureEnabled()) {
|
if (cm != null && cm.isContentCaptureEnabled()) {
|
||||||
|
|||||||
@@ -98,6 +98,12 @@ public class EditableInputConnection extends BaseInputConnection
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void endComposingRegionEditInternal() {
|
||||||
|
// The ContentCapture service is interested in Composing-state changes.
|
||||||
|
mTextView.notifyContentCaptureTextChanged();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void closeConnection() {
|
public void closeConnection() {
|
||||||
super.closeConnection();
|
super.closeConnection();
|
||||||
|
|||||||
Reference in New Issue
Block a user