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
This commit is contained in:
Adam He
2021-08-19 14:42:37 -07:00
parent abbe3e853b
commit 23e6f6cc0e
3 changed files with 49 additions and 7 deletions

View File

@@ -0,0 +1,32 @@
/*
* 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");
}
}

View File

@@ -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;

View File

@@ -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() + "]}, ");