Commit 0bb4549e authored by Marcin Wiącek's avatar Marcin Wiącek Committed by Commit Bot

Improve @IntDef inside Selection

This patch is aligning various @IntDef to some standard used with many other CLs:

1. @IntDef is first, @Retention second and related @interface third
2. there is used @Retention(RetentionPolicy.SOURCE)
3. @IntDef entries are inside @interface

BUG=919666

Change-Id: I2d9f057071bfa282809545a91d6917908e1594f5
Reviewed-on: https://chromium-review.googlesource.com/c/1480371Reviewed-by: default avatarPedro Amaral <amaralp@chromium.org>
Commit-Queue: Marcin Wiącek <marcin@mwiacek.com>
Cr-Commit-Position: refs/heads/master@{#636566}
parent 5a8399a7
......@@ -27,17 +27,17 @@ import java.lang.annotation.RetentionPolicy;
*/
@JNINamespace("content")
public class SmartSelectionClient implements SelectionClient {
@IntDef({CLASSIFY, SUGGEST_AND_CLASSIFY})
@IntDef({RequestType.CLASSIFY, RequestType.SUGGEST_AND_CLASSIFY})
@Retention(RetentionPolicy.SOURCE)
private @interface RequestType {}
// Request to obtain the type (e.g. phone number, e-mail address) and the most
// appropriate operation for the selected text.
private static final int CLASSIFY = 0;
// Request to obtain the type (e.g. phone number, e-mail address), the most
// appropriate operation for the selected text and a better selection boundaries.
private static final int SUGGEST_AND_CLASSIFY = 1;
private @interface RequestType {
// Request to obtain the type (e.g. phone number, e-mail address) and the most
// appropriate operation for the selected text.
int CLASSIFY = 0;
// Request to obtain the type (e.g. phone number, e-mail address), the most
// appropriate operation for the selected text and a better selection boundaries.
int SUGGEST_AND_CLASSIFY = 1;
}
// The maximal number of characters on the left and on the right from the current selection.
// Used for surrounding text request.
......@@ -88,7 +88,8 @@ public class SmartSelectionClient implements SelectionClient {
@Override
public boolean requestSelectionPopupUpdates(boolean shouldSuggest) {
requestSurroundingText(shouldSuggest ? SUGGEST_AND_CLASSIFY : CLASSIFY);
requestSurroundingText(
shouldSuggest ? RequestType.SUGGEST_AND_CLASSIFY : RequestType.CLASSIFY);
return true;
}
......@@ -139,11 +140,11 @@ public class SmartSelectionClient implements SelectionClient {
}
switch (callbackData) {
case SUGGEST_AND_CLASSIFY:
case RequestType.SUGGEST_AND_CLASSIFY:
mProvider.sendSuggestAndClassifyRequest(text, start, end, null);
break;
case CLASSIFY:
case RequestType.CLASSIFY:
mProvider.sendClassifyRequest(text, start, end, null);
break;
......
......@@ -50,10 +50,10 @@ public class SmartSelectionMetricsLogger implements SelectionMetricsLogger {
private SelectionIndicesConverter mConverter;
// ActionType, from SmartSelectionEventTracker.SelectionEvent class.
@Retention(RetentionPolicy.SOURCE)
@IntDef({ActionType.OVERTYPE, ActionType.COPY, ActionType.PASTE, ActionType.CUT,
ActionType.SHARE, ActionType.SMART_SHARE, ActionType.DRAG, ActionType.ABANDON,
ActionType.OTHER, ActionType.SELECT_ALL, ActionType.RESET})
@Retention(RetentionPolicy.SOURCE)
public @interface ActionType {
/** User typed over the selection. */
int OVERTYPE = 100;
......
......@@ -30,12 +30,12 @@ import java.util.Locale;
public class SmartSelectionProvider {
private static final String TAG = "SmartSelProvider";
@IntDef({CLASSIFY, SUGGEST_AND_CLASSIFY})
@IntDef({RequestType.CLASSIFY, RequestType.SUGGEST_AND_CLASSIFY})
@Retention(RetentionPolicy.SOURCE)
private @interface RequestType {}
private static final int CLASSIFY = 0;
private static final int SUGGEST_AND_CLASSIFY = 1;
private @interface RequestType {
int CLASSIFY = 0;
int SUGGEST_AND_CLASSIFY = 1;
}
private SelectionClient.ResultCallback mResultCallback;
private WindowAndroid mWindowAndroid;
......@@ -60,11 +60,11 @@ public class SmartSelectionProvider {
public void sendSuggestAndClassifyRequest(
CharSequence text, int start, int end, Locale[] locales) {
sendSmartSelectionRequest(SUGGEST_AND_CLASSIFY, text, start, end, locales);
sendSmartSelectionRequest(RequestType.SUGGEST_AND_CLASSIFY, text, start, end, locales);
}
public void sendClassifyRequest(CharSequence text, int start, int end, Locale[] locales) {
sendSmartSelectionRequest(CLASSIFY, text, start, end, locales);
sendSmartSelectionRequest(RequestType.CLASSIFY, text, start, end, locales);
}
public void cancelAllRequests() {
......@@ -118,7 +118,7 @@ public class SmartSelectionProvider {
@TargetApi(Build.VERSION_CODES.O)
private class ClassificationTask extends AsyncTask<SelectionClient.Result> {
private final TextClassifier mTextClassifier;
private final int mRequestType;
private final @RequestType int mRequestType;
private final CharSequence mText;
private final int mOriginalStart;
private final int mOriginalEnd;
......@@ -141,7 +141,7 @@ public class SmartSelectionProvider {
TextSelection textSelection = null;
if (mRequestType == SUGGEST_AND_CLASSIFY) {
if (mRequestType == RequestType.SUGGEST_AND_CLASSIFY) {
textSelection = mTextClassifier.suggestSelection(
mText, start, end, makeLocaleList(mLocales));
start = Math.max(0, textSelection.getSelectionStartIndex());
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment