1 /* 2 * Copyright (C) 2021 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 17 package android.view.translation; 18 19 import android.annotation.NonNull; 20 import android.annotation.UiThread; 21 import android.view.View; 22 23 /** 24 * Callback for handling the translated information show or hide in the {@link View}. 25 */ 26 @UiThread 27 public interface ViewTranslationCallback { 28 /** 29 * Called when the translated text is ready to show or if the user has requested to reshow the 30 * translated content after hiding it. 31 * <p> 32 * The translated content can be obtained from {@link View#getViewTranslationResponse}. This 33 * method will not be called before {@link View#onViewTranslationResponse} or 34 * {@link View#onVirtualViewTranslationResponses}. 35 * 36 * See {@link View#onViewTranslationResponse} for how to get the translated information. 37 * 38 * @return {@code true} if the View handles showing the translation. 39 */ onShowTranslation(@onNull View view)40 boolean onShowTranslation(@NonNull View view); 41 /** 42 * Called when the user wants to show the original text instead of the translated text. This 43 * method will not be called before {@link View#onViewTranslationResponse} or 44 * {@link View#onViewTranslationResponse}. 45 * 46 * @return {@code true} if the View handles hiding the translation. 47 */ onHideTranslation(@onNull View view)48 boolean onHideTranslation(@NonNull View view); 49 /** 50 * Called when the user finish the Ui translation and no longer to show the translated text. 51 * 52 * @return {@code true} if the View handles clearing the translation. 53 */ onClearTranslation(@onNull View view)54 boolean onClearTranslation(@NonNull View view); 55 56 /** 57 * Enables padding on the view's original content. 58 * <p> 59 * This is useful when we do not modify the content directly, rather use a mechanism like 60 * {@link android.text.method.TransformationMethod}. If the app misbehaves when the displayed 61 * translation and the underlying content have different sizes, the platform intelligence can 62 * request that the original content be padded to make the sizes match. 63 * 64 * @hide 65 */ enableContentPadding()66 default void enableContentPadding() {} 67 68 /** 69 * Sets the duration for animations while transitioning the view between the original and 70 * translated contents. 71 * 72 * @hide 73 */ setAnimationDurationMillis(int durationMillis)74 default void setAnimationDurationMillis(int durationMillis) {} 75 } 76