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

Commit 6c272949 authored by Adam He's avatar Adam He Committed by Android (Google) Code Review
Browse files

Merge "Add tmp renderer for Inline Presentation UI until extServices implemented."

parents e4e8b75e 4454e3ad
Loading
Loading
Loading
Loading
+67 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2020 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.
-->

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="wrap_content"
    android:layout_height="56dp"
    android:background="@color/white"
    android:orientation="horizontal"
    android:paddingStart="12dp"
    android:paddingEnd="12dp">

    <ImageView
        android:id="@+id/autofill_inline_suggestion_start_icon"
        android:layout_width="24dp"
        android:layout_height="24dp"
        android:layout_gravity="center"
        android:contentDescription="autofill_inline_suggestion_start_icon" />

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_gravity="center"
        android:layout_weight="1"
        android:layout_marginStart="12dp"
        android:layout_marginEnd="12dp"
        android:orientation="vertical"
        android:gravity="center_vertical">

        <TextView
            android:id="@+id/autofill_inline_suggestion_title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:ellipsize="end"
            android:maxLines="1"
            tools:text="username1"/>

        <TextView
            android:id="@+id/autofill_inline_suggestion_subtitle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:ellipsize="end"
            android:maxLines="1"
            tools:text="inline fill service"/>
    </LinearLayout>

    <ImageView
        android:id="@+id/autofill_inline_suggestion_end_icon"
        android:layout_width="24dp"
        android:layout_height="24dp"
        android:layout_gravity="center"
        android:contentDescription="autofill_inline_suggestion_end_icon" />
</LinearLayout>
+5 −0
Original line number Diff line number Diff line
@@ -3235,6 +3235,7 @@
  <java-symbol type="layout" name="autofill_dataset_picker"/>
  <java-symbol type="layout" name="autofill_dataset_picker_fullscreen"/>
  <java-symbol type="layout" name="autofill_dataset_picker_header_footer"/>
  <java-symbol type="layout" name="autofill_inline_suggestion" />
  <java-symbol type="id" name="autofill" />
  <java-symbol type="id" name="autofill_dataset_footer"/>
  <java-symbol type="id" name="autofill_dataset_header"/>
@@ -3242,6 +3243,10 @@
  <java-symbol type="id" name="autofill_dataset_list"/>
  <java-symbol type="id" name="autofill_dataset_picker"/>
  <java-symbol type="id" name="autofill_dataset_title" />
  <java-symbol type="id" name="autofill_inline_suggestion_end_icon" />
  <java-symbol type="id" name="autofill_inline_suggestion_start_icon" />
  <java-symbol type="id" name="autofill_inline_suggestion_subtitle" />
  <java-symbol type="id" name="autofill_inline_suggestion_title" />
  <java-symbol type="id" name="autofill_save_custom_subtitle" />
  <java-symbol type="id" name="autofill_save_icon" />
  <java-symbol type="id" name="autofill_save_no" />
+69 −9
Original line number Diff line number Diff line
@@ -16,24 +16,36 @@

package com.android.server.autofill.ui;

import static android.app.slice.SliceItem.FORMAT_IMAGE;
import static android.app.slice.SliceItem.FORMAT_TEXT;

import android.annotation.MainThread;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.app.slice.Slice;
import android.app.slice.SliceItem;
import android.content.Context;
import android.graphics.Color;
import android.graphics.PixelFormat;
import android.graphics.drawable.Icon;
import android.os.IBinder;
import android.service.autofill.Dataset;
import android.util.Log;
import android.util.Slog;
import android.view.LayoutInflater;
import android.view.SurfaceControl;
import android.view.SurfaceControlViewHost;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.view.autofill.AutofillId;
import android.view.autofill.AutofillValue;
import android.widget.ImageView;
import android.widget.TextView;

import com.android.internal.R;

import java.util.List;

/**
 * This is a temporary inline suggestion UI inflater which will be replaced by the ExtServices
 * implementation.
@@ -72,18 +84,66 @@ public class InlineSuggestionUi {
                mContext.getDisplay(), (IBinder) null);
        final SurfaceControl sc = wvr.getSurfacePackage().getSurfaceControl();

        TextView textView = new TextView(mContext);
        textView.setText(datasetValue.getTextValue());
        textView.setBackgroundColor(Color.WHITE);
        textView.setTextColor(Color.BLACK);
        if (onClickListener != null) {
            textView.setOnClickListener(onClickListener);
        }
        final ViewGroup suggestionView =
                (ViewGroup) renderSlice(dataset.getFieldInlinePresentation(index).getSlice());

        WindowManager.LayoutParams lp =
                new WindowManager.LayoutParams(width, height,
                        WindowManager.LayoutParams.TYPE_APPLICATION, 0, PixelFormat.TRANSPARENT);
        wvr.addView(textView, lp);
        wvr.addView(suggestionView, lp);
        return sc;
    }

    private View renderSlice(Slice slice) {
        final LayoutInflater inflater = LayoutInflater.from(mContext);
        final ViewGroup suggestionView =
                (ViewGroup) inflater.inflate(R.layout.autofill_inline_suggestion, null);

        final ImageView startIconView =
                suggestionView.findViewById(R.id.autofill_inline_suggestion_start_icon);
        final TextView titleView =
                suggestionView.findViewById(R.id.autofill_inline_suggestion_title);
        final TextView subtitleView =
                suggestionView.findViewById(R.id.autofill_inline_suggestion_subtitle);
        final ImageView endIconView =
                suggestionView.findViewById(R.id.autofill_inline_suggestion_end_icon);

        boolean hasStartIcon = false;
        boolean hasEndIcon = false;
        boolean hasSubtitle = false;
        final List<SliceItem> sliceItems = slice.getItems();
        for (int i = 0; i < sliceItems.size(); i++) {
            final SliceItem sliceItem = sliceItems.get(i);
            if (sliceItem.getFormat().equals(FORMAT_IMAGE)) {
                final Icon sliceIcon = sliceItem.getIcon();
                if (i == 0) { // start icon
                    startIconView.setImageIcon(sliceIcon);
                    hasStartIcon = true;
                } else { // end icon
                    endIconView.setImageIcon(sliceIcon);
                    hasEndIcon = true;
                }
            } else if (sliceItem.getFormat().equals(FORMAT_TEXT)) {
                final List<String> sliceHints = sliceItem.getHints();
                final String sliceText = sliceItem.getText().toString();
                if (sliceHints.contains("inline_title")) { // title
                    titleView.setText(sliceText);
                } else { // subtitle
                    subtitleView.setText(sliceText);
                    hasSubtitle = true;
                }
            }
        }
        if (!hasStartIcon) {
            startIconView.setVisibility(View.GONE);
        }
        if (!hasEndIcon) {
            endIconView.setVisibility(View.GONE);
        }
        if (!hasSubtitle) {
            subtitleView.setVisibility(View.GONE);
        }

        return suggestionView;
    }
}