blob: 22e374f2b38f2d4b8b64f7992b2e8ce7c1911ddf [file] [log] [blame]
Tony Makfc039c32019-01-17 19:32:08 +00001/*
2 * Copyright (C) 2019 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
Tony Mak8ab9b182019-03-01 16:44:17 +000016package android.view.textclassifier.intent;
Tony Makfc039c32019-01-17 19:32:08 +000017
18import android.annotation.Nullable;
19import android.content.Context;
20import android.content.Intent;
21
22import com.google.android.textclassifier.AnnotatorModel;
23
24import java.time.Instant;
25import java.util.List;
26
27/**
28 * @hide
29 */
Tony Mak8ab9b182019-03-01 16:44:17 +000030public interface ClassificationIntentFactory {
Tony Makfc039c32019-01-17 19:32:08 +000031
32 /**
33 * Return a list of LabeledIntent from the classification result.
34 */
Tony Makac9b4d82019-02-15 13:57:38 +000035 List<LabeledIntent> create(
Tony Makfc039c32019-01-17 19:32:08 +000036 Context context,
37 String text,
38 boolean foreignText,
39 @Nullable Instant referenceTime,
40 @Nullable AnnotatorModel.ClassificationResult classification);
41
42 /**
43 * Inserts translate action to the list if it is a foreign text.
44 */
45 static void insertTranslateAction(
Tony Makac9b4d82019-02-15 13:57:38 +000046 List<LabeledIntent> actions, Context context, String text) {
47 actions.add(new LabeledIntent(
Tony Makfc039c32019-01-17 19:32:08 +000048 context.getString(com.android.internal.R.string.translate),
Tony Makac9b4d82019-02-15 13:57:38 +000049 /* titleWithEntity */ null,
Tony Makfc039c32019-01-17 19:32:08 +000050 context.getString(com.android.internal.R.string.translate_desc),
Tony Mak15b64be2019-04-01 20:02:29 +010051 /* descriptionWithAppName */ null,
Tony Makfc039c32019-01-17 19:32:08 +000052 new Intent(Intent.ACTION_TRANSLATE)
53 // TODO: Probably better to introduce a "translate" scheme instead of
54 // using EXTRA_TEXT.
Tony Mak72e17972019-03-16 10:28:42 +000055 .putExtra(Intent.EXTRA_TEXT, text),
Tony Makfc039c32019-01-17 19:32:08 +000056 text.hashCode()));
57 }
58}