Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 23e6f6cc authored by Adam He's avatar Adam He
Browse files

Clean up some translation todos.

* Move high level constants to a Helper.java class.

* Added dump logs for dictionary results.

Bug: 176464808
Test: atest CtsTranslationServiceTestCases
Change-Id: I4f871189e011ba24bebc8f7a7849e141edece689
parent abbe3e85
Loading
Loading
Loading
Loading
+32 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2021 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.view.translation;

/** @hide */
public class Helper {

    // Debug-level flags are defined when service is bound.
    public static boolean sDebug = false;
    public static boolean sVerbose = false;

    // TODO: Use a device config value.
    public static final int ANIMATION_DURATION_MILLIS = 250;

    private Helper() {
        throw new UnsupportedOperationException("contains static members only");
    }
}
+0 −3
Original line number Diff line number Diff line
@@ -53,9 +53,6 @@ public class Translator {

    private static final String TAG = "Translator";

    // TODO: make this configurable and cross the Translation component
    private static boolean sDEBUG = false;

    private final Object mLock = new Object();

    private int mId;
+17 −4
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package android.view.translation;

import static android.view.translation.Helper.ANIMATION_DURATION_MILLIS;
import static android.view.translation.UiTranslationManager.STATE_UI_TRANSLATION_FINISHED;
import static android.view.translation.UiTranslationManager.STATE_UI_TRANSLATION_PAUSED;
import static android.view.translation.UiTranslationManager.STATE_UI_TRANSLATION_RESUMED;
@@ -26,6 +27,7 @@ import android.annotation.WorkerThread;
import android.app.Activity;
import android.app.assist.ActivityId;
import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.Process;
@@ -457,9 +459,6 @@ public class UiTranslationController {
        }
    }

    // TODO: Use a device config value.
    private static final int ANIMATION_DURATION_MILLIS = 250;

    /**
     * Creates a Translator for the given source and target translation specs and start the ui
     * translation when the Translator is created successfully.
@@ -716,7 +715,21 @@ public class UiTranslationController {
            msg.append("text=").append(value.getText() == null
                    ? "null"
                    : "string[" + value.getText().length() + "], ");
            //TODO: append dictionary results.
            final Bundle definitions =
                    (Bundle) value.getExtras().get(TranslationResponseValue.EXTRA_DEFINITIONS);
            if (definitions != null) {
                msg.append("definitions={");
                for (String partOfSpeech : definitions.keySet()) {
                    msg.append(partOfSpeech).append(":[");
                    for (CharSequence definition : definitions.getCharSequenceArray(partOfSpeech)) {
                        msg.append(definition == null
                                ? "null, "
                                : "string[" + definition.length() + "], ");
                    }
                    msg.append("], ");
                }
                msg.append("}");
            }
            msg.append("transliteration=").append(value.getTransliteration() == null
                    ? "null"
                    : "string[" + value.getTransliteration().length() + "]}, ");