Make sample IME support styling

Test: manual
Bug: 146454892

Change-Id: Idf173ae7fc0c3fe83736d73e7a3ab6953ae868aa
This commit is contained in:
Feng Cao
2020-01-17 13:27:59 -08:00
parent 92439f8860
commit 5687a2b635
3 changed files with 40 additions and 9 deletions

View File

@@ -61,4 +61,27 @@
<item name="android:layout_weight">5</item>
<item name="android:textColor">#FF333333</item>
</style>
<style name="YellowText" parent="@android:style/TextAppearance">
<item name="android:textColor">#FFFF00</item>
<item name="android:background">#88FF00FF</item>
<!-- This theme will be invalid -->
<item name="android:fontFamily">@font/just_another_hand</item>
</style>
<style name="GreenText" parent="@android:style/TextAppearance">
<item name="android:textColor">#00FF00</item>
<item name="android:fontFamily">monospace</item>
</style>
<style name="PinkBackground">
<item name="android:background">#33FF00FF</item>
</style>
<style name="YellowTheme" parent="@android:style/Theme.AutofillInlineSuggestion">
<item name="android:autofillInlineSuggestionTitle">@style/YellowText</item>
<item name="android:autofillInlineSuggestionSubtitle">@style/YellowText</item>
</style>
<style name="GreenTheme" parent="@android:style/Theme.AutofillInlineSuggestion">
<item name="android:autofillInlineSuggestionChip">@style/PinkBackground</item>
<item name="android:autofillInlineSuggestionTitle">@style/GreenText</item>
<item name="android:autofillInlineSuggestionSubtitle">@style/GreenText</item>
</style>
</resources>

View File

@@ -16,6 +16,7 @@
package com.example.android.autofillkeyboard;
import android.content.res.Resources;
import android.inputmethodservice.InputMethodService;
import android.os.AsyncTask;
import android.os.Handler;
@@ -93,9 +94,11 @@ public class AutofillImeService extends InputMethodService {
Log.d(TAG, "onCreateInlineSuggestionsRequest() called");
final ArrayList<InlinePresentationSpec> presentationSpecs = new ArrayList<>();
presentationSpecs.add(new InlinePresentationSpec.Builder(new Size(100, 100),
new Size(400, 100)).build());
new Size(400, 100)).setStyle(
getResources().getResourceName(R.style.YellowTheme)).build());
presentationSpecs.add(new InlinePresentationSpec.Builder(new Size(100, 100),
new Size(400, 100)).build());
new Size(400, 100)).setStyle(
getResources().getResourceName(R.style.GreenTheme)).build());
return new InlineSuggestionsRequest.Builder(presentationSpecs)
.setMaxSuggestionCount(2)
@@ -122,6 +125,9 @@ public class AutofillImeService extends InputMethodService {
mSuggestionStrip.removeAllViews();
final int size = mSuggestionViews.size();
for (int i = 0; i < size; i++) {
if(mSuggestionViews.get(i) == null) {
continue;
}
ViewGroup.LayoutParams layoutParams = new ViewGroup.LayoutParams(
mSuggestionViewSizes.get(i).getWidth(),
mSuggestionViewSizes.get(i).getHeight());
@@ -160,13 +166,15 @@ public class AutofillImeService extends InputMethodService {
AsyncTask.THREAD_POOL_EXECUTOR,
suggestionView -> {
Log.d(TAG, "new inline suggestion view ready");
suggestionViews[index] = suggestionView;
sizes[index] = size;
suggestionView.setOnTouchListener((v, event) -> {
Toast.makeText(AutofillImeService.this, "hello",
Toast.LENGTH_LONG).show();
return false;
});
if(suggestionView != null) {
suggestionViews[index] = suggestionView;
sizes[index] = size;
suggestionView.setOnTouchListener((v, event) -> {
Toast.makeText(AutofillImeService.this, "hello",
Toast.LENGTH_LONG).show();
return false;
});
}
if (suggestionsCount.decrementAndGet() == 0) {
updateSuggestionViews(suggestionViews, sizes);
}