Merge "TRON: Log "textAssist" actions." into oc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
fa9d889d3e
@@ -47,6 +47,7 @@ public final class TextClassificationResult {
|
||||
@Nullable private final OnClickListener mOnClickListener;
|
||||
@NonNull private final EntityConfidence<String> mEntityConfidence;
|
||||
@NonNull private final List<String> mEntities;
|
||||
private int mLogType;
|
||||
|
||||
private TextClassificationResult(
|
||||
@NonNull String text,
|
||||
@@ -54,7 +55,8 @@ public final class TextClassificationResult {
|
||||
String label,
|
||||
Intent intent,
|
||||
OnClickListener onClickListener,
|
||||
@NonNull EntityConfidence<String> entityConfidence) {
|
||||
@NonNull EntityConfidence<String> entityConfidence,
|
||||
int logType) {
|
||||
mText = text;
|
||||
mIcon = icon;
|
||||
mLabel = label;
|
||||
@@ -62,6 +64,7 @@ public final class TextClassificationResult {
|
||||
mOnClickListener = onClickListener;
|
||||
mEntityConfidence = new EntityConfidence<>(entityConfidence);
|
||||
mEntities = mEntityConfidence.getEntities();
|
||||
mLogType = logType;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -134,6 +137,14 @@ public final class TextClassificationResult {
|
||||
return mOnClickListener;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the MetricsLogger subtype for the action that is performed for this result.
|
||||
* @hide
|
||||
*/
|
||||
public int getLogType() {
|
||||
return mLogType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("TextClassificationResult {"
|
||||
@@ -167,6 +178,7 @@ public final class TextClassificationResult {
|
||||
@Nullable private OnClickListener mOnClickListener;
|
||||
@NonNull private final EntityConfidence<String> mEntityConfidence =
|
||||
new EntityConfidence<>();
|
||||
private int mLogType;
|
||||
|
||||
/**
|
||||
* Sets the classified text.
|
||||
@@ -214,6 +226,15 @@ public final class TextClassificationResult {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the MetricsLogger subtype for the action that is performed for this result.
|
||||
* @hide
|
||||
*/
|
||||
public Builder setLogType(int type) {
|
||||
mLogType = type;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets an OnClickListener that may be triggered to act on the classified text.
|
||||
*/
|
||||
@@ -227,7 +248,7 @@ public final class TextClassificationResult {
|
||||
*/
|
||||
public TextClassificationResult build() {
|
||||
return new TextClassificationResult(
|
||||
mText, mIcon, mLabel, mIntent, mOnClickListener, mEntityConfidence);
|
||||
mText, mIcon, mLabel, mIntent, mOnClickListener, mEntityConfidence, mLogType);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,6 +37,7 @@ import android.text.util.Linkify;
|
||||
import android.util.Log;
|
||||
import android.util.Patterns;
|
||||
import android.view.View;
|
||||
import android.widget.TextViewMetrics;
|
||||
|
||||
import com.android.internal.annotations.GuardedBy;
|
||||
import com.android.internal.util.Preconditions;
|
||||
@@ -243,6 +244,8 @@ final class TextClassifierImpl implements TextClassifier {
|
||||
}
|
||||
|
||||
final String type = getHighestScoringType(classifications);
|
||||
builder.setLogType(IntentFactory.getLogType(type));
|
||||
|
||||
final Intent intent = IntentFactory.create(mContext, type, text.toString());
|
||||
final PackageManager pm;
|
||||
final ResolveInfo resolveInfo;
|
||||
@@ -543,5 +546,22 @@ final class TextClassifierImpl implements TextClassifier {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static int getLogType(String type) {
|
||||
type = type.trim().toLowerCase(Locale.ENGLISH);
|
||||
switch (type) {
|
||||
case TextClassifier.TYPE_EMAIL:
|
||||
return TextViewMetrics.SUBTYPE_ASSIST_MENU_ITEM_EMAIL;
|
||||
case TextClassifier.TYPE_PHONE:
|
||||
return TextViewMetrics.SUBTYPE_ASSIST_MENU_ITEM_PHONE;
|
||||
case TextClassifier.TYPE_ADDRESS:
|
||||
return TextViewMetrics.SUBTYPE_ASSIST_MENU_ITEM_ADDRESS;
|
||||
case TextClassifier.TYPE_URL:
|
||||
return TextViewMetrics.SUBTYPE_ASSIST_MENU_ITEM_URL;
|
||||
default:
|
||||
return TextViewMetrics.SUBTYPE_ASSIST_MENU_ITEM_OTHER;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,6 +41,7 @@ import android.graphics.Rect;
|
||||
import android.graphics.RectF;
|
||||
import android.graphics.drawable.ColorDrawable;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.metrics.LogMaker;
|
||||
import android.os.Bundle;
|
||||
import android.os.LocaleList;
|
||||
import android.os.Parcel;
|
||||
@@ -165,6 +166,8 @@ public class Editor {
|
||||
final UndoInputFilter mUndoInputFilter = new UndoInputFilter(this);
|
||||
boolean mAllowUndo = true;
|
||||
|
||||
private final MetricsLogger mMetricsLogger = new MetricsLogger();
|
||||
|
||||
// Cursor Controllers.
|
||||
private InsertionPointCursorController mInsertionPointCursorController;
|
||||
SelectionModifierCursorController mSelectionModifierCursorController;
|
||||
@@ -3894,6 +3897,10 @@ public class Editor {
|
||||
menu.add(TextView.ID_ASSIST, TextView.ID_ASSIST, MENU_ITEM_ORDER_ASSIST, label)
|
||||
.setIcon(icon)
|
||||
.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
|
||||
mMetricsLogger.write(
|
||||
new LogMaker(MetricsEvent.TEXT_SELECTION_MENU_ITEM_ASSIST)
|
||||
.setType(MetricsEvent.TYPE_OPEN)
|
||||
.setSubtype(textClassificationResult.getLogType()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3922,6 +3929,9 @@ public class Editor {
|
||||
.onClick(mTextView);
|
||||
}
|
||||
}
|
||||
mMetricsLogger.action(
|
||||
MetricsEvent.ACTION_TEXT_SELECTION_MENU_ITEM_ASSIST,
|
||||
textClassificationResult.getLogType());
|
||||
stopTextActionMode();
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -21,20 +21,45 @@ package android.widget;
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
final class TextViewMetrics {
|
||||
public final class TextViewMetrics {
|
||||
|
||||
private TextViewMetrics() {}
|
||||
|
||||
/**
|
||||
* Long press on TextView - no special classification.
|
||||
*/
|
||||
static final int SUBTYPE_LONG_PRESS_OTHER = 0;
|
||||
public static final int SUBTYPE_LONG_PRESS_OTHER = 0;
|
||||
/**
|
||||
* Long press on TextView - selection started.
|
||||
*/
|
||||
static final int SUBTYPE_LONG_PRESS_SELECTION = 1;
|
||||
public static final int SUBTYPE_LONG_PRESS_SELECTION = 1;
|
||||
/**
|
||||
* Long press on TextView - drag and drop started.
|
||||
*/
|
||||
static final int SUBTYPE_LONG_PRESS_DRAG_AND_DROP = 2;
|
||||
public static final int SUBTYPE_LONG_PRESS_DRAG_AND_DROP = 2;
|
||||
|
||||
/**
|
||||
* Assist menu item (shown or clicked) - classification: other.
|
||||
*/
|
||||
public static final int SUBTYPE_ASSIST_MENU_ITEM_OTHER = 0;
|
||||
|
||||
/**
|
||||
* Assist menu item (shown or clicked) - classification: email.
|
||||
*/
|
||||
public static final int SUBTYPE_ASSIST_MENU_ITEM_EMAIL = 1;
|
||||
|
||||
/**
|
||||
* Assist menu item (shown or clicked) - classification: phone.
|
||||
*/
|
||||
public static final int SUBTYPE_ASSIST_MENU_ITEM_PHONE = 2;
|
||||
|
||||
/**
|
||||
* Assist menu item (shown or clicked) - classification: address.
|
||||
*/
|
||||
public static final int SUBTYPE_ASSIST_MENU_ITEM_ADDRESS = 3;
|
||||
|
||||
/**
|
||||
* Assist menu item (shown or clicked) - classification: url.
|
||||
*/
|
||||
public static final int SUBTYPE_ASSIST_MENU_ITEM_URL = 4;
|
||||
}
|
||||
|
||||
@@ -3911,6 +3911,18 @@ message MetricsEvent {
|
||||
// OS: O
|
||||
APPLICATIONS_STORAGE_MOVIES = 935;
|
||||
|
||||
// OPEN: Text selection "assist" menu item shown.
|
||||
// SUBTYPE: 1 is for EMAIL, 2 is for PHONE, 3 is for ADDRESS, 4 is for URL, 0 is for OTHER.
|
||||
// CATEGORY: TEXT_CONTROLS
|
||||
// OS: O
|
||||
TEXT_SELECTION_MENU_ITEM_ASSIST = 936;
|
||||
|
||||
// ACTION: Text selection "assist" menu item clicked.
|
||||
// SUBTYPE: 1 is for EMAIL, 2 is for PHONE, 3 is for ADDRESS, 4 is for URL, 0 is for OTHER.
|
||||
// CATEGORY: TEXT_CONTROLS
|
||||
// OS: O
|
||||
ACTION_TEXT_SELECTION_MENU_ITEM_ASSIST = 937;
|
||||
|
||||
// ---- End O Constants, all O constants go above this line ----
|
||||
|
||||
// Add new aosp constants above this line.
|
||||
|
||||
Reference in New Issue
Block a user