Tony Mak | fc039c3 | 2019-01-17 19:32:08 +0000 | [diff] [blame] | 1 | /* |
| 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 Mak | 8ab9b18 | 2019-03-01 16:44:17 +0000 | [diff] [blame] | 16 | package android.view.textclassifier.intent; |
Tony Mak | fc039c3 | 2019-01-17 19:32:08 +0000 | [diff] [blame] | 17 | |
| 18 | import android.annotation.Nullable; |
| 19 | import android.content.Context; |
| 20 | import android.content.Intent; |
| 21 | |
| 22 | import com.google.android.textclassifier.AnnotatorModel; |
| 23 | |
| 24 | import java.time.Instant; |
| 25 | import java.util.List; |
| 26 | |
| 27 | /** |
| 28 | * @hide |
| 29 | */ |
Tony Mak | 8ab9b18 | 2019-03-01 16:44:17 +0000 | [diff] [blame] | 30 | public interface ClassificationIntentFactory { |
Tony Mak | fc039c3 | 2019-01-17 19:32:08 +0000 | [diff] [blame] | 31 | |
| 32 | /** |
| 33 | * Return a list of LabeledIntent from the classification result. |
| 34 | */ |
Tony Mak | ac9b4d8 | 2019-02-15 13:57:38 +0000 | [diff] [blame] | 35 | List<LabeledIntent> create( |
Tony Mak | fc039c3 | 2019-01-17 19:32:08 +0000 | [diff] [blame] | 36 | 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 Mak | ac9b4d8 | 2019-02-15 13:57:38 +0000 | [diff] [blame] | 46 | List<LabeledIntent> actions, Context context, String text) { |
| 47 | actions.add(new LabeledIntent( |
Tony Mak | fc039c3 | 2019-01-17 19:32:08 +0000 | [diff] [blame] | 48 | context.getString(com.android.internal.R.string.translate), |
Tony Mak | ac9b4d8 | 2019-02-15 13:57:38 +0000 | [diff] [blame] | 49 | /* titleWithEntity */ null, |
Tony Mak | fc039c3 | 2019-01-17 19:32:08 +0000 | [diff] [blame] | 50 | context.getString(com.android.internal.R.string.translate_desc), |
| 51 | new Intent(Intent.ACTION_TRANSLATE) |
| 52 | // TODO: Probably better to introduce a "translate" scheme instead of |
| 53 | // using EXTRA_TEXT. |
Tony Mak | 72e1797 | 2019-03-16 10:28:42 +0000 | [diff] [blame] | 54 | .putExtra(Intent.EXTRA_TEXT, text), |
Tony Mak | fc039c3 | 2019-01-17 19:32:08 +0000 | [diff] [blame] | 55 | text.hashCode())); |
| 56 | } |
| 57 | } |