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.icu.util.ULocale;
21 
22 import java.util.concurrent.Executor;
23 
24 /**
25  * Callback for listening to UI Translation state changes. See {@link
26  * UiTranslationManager#registerUiTranslationStateCallback(Executor, UiTranslationStateCallback)}.
27  */
28 public interface UiTranslationStateCallback {
29 
30     /**
31      * @removed use {@link #onStarted(ULocale, ULocale)} instead.
32      */
33     @Deprecated
onStarted(@onNull String sourceLocale, @NonNull String targetLocale)34     default void onStarted(@NonNull String sourceLocale, @NonNull String targetLocale) {
35         // no-op
36     }
37 
38     /**
39      * The system is requesting translation of the UI from {@code sourceLocale} to {@code
40      * targetLocale}.
41      * <p>
42      * This is also called if either the requested {@code sourceLocale} or {@code targetLocale} has
43      * changed.
44      */
onStarted(@onNull ULocale sourceLocale, @NonNull ULocale targetLocale)45     default void onStarted(@NonNull ULocale sourceLocale, @NonNull ULocale targetLocale) {
46         onStarted(sourceLocale.getLanguage(), targetLocale.getLanguage());
47     }
48 
49     /**
50      * The system is requesting that the application temporarily show the UI contents in their
51      * original language.
52      */
onPaused()53     void onPaused();
54 
55     /**
56      * The system is requesting that the application restore from the temporarily paused state and
57      * show the content in translated language.
58      */
59     // TODO: Remove the default implementation when clients have implemented this.
onResumed(@onNull ULocale sourceLocale, @NonNull ULocale targetLocale)60     default void onResumed(@NonNull ULocale sourceLocale, @NonNull ULocale targetLocale) {
61     }
62 
63     /**
64      * The UI Translation session has ended.
65      */
onFinished()66     void onFinished();
67 }
68