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 */ 16 package android.view.textclassifier.intent; 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 */ 30 public interface ClassificationIntentFactory { 31 32 /** 33 * Return a list of LabeledIntent from the classification result. 34 */ create( Context context, String text, boolean foreignText, @Nullable Instant referenceTime, @Nullable AnnotatorModel.ClassificationResult classification)35 List<LabeledIntent> create( 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 */ insertTranslateAction( List<LabeledIntent> actions, Context context, String text)45 static void insertTranslateAction( 46 List<LabeledIntent> actions, Context context, String text) { 47 actions.add(new LabeledIntent( 48 context.getString(com.android.internal.R.string.translate), 49 /* titleWithEntity */ null, 50 context.getString(com.android.internal.R.string.translate_desc), 51 /* descriptionWithAppName */ null, 52 new Intent(Intent.ACTION_TRANSLATE) 53 // TODO: Probably better to introduce a "translate" scheme instead of 54 // using EXTRA_TEXT. 55 .putExtra(Intent.EXTRA_TEXT, text), 56 text.hashCode())); 57 } 58 } 59