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

Commit eb95dd8f authored by Joy Babafemi's avatar Joy Babafemi
Browse files

Apply Credman Spec styles to Inline Presentation

Mainly addresses color (b/310038196), font, width (b/318548599) and background. More specific finetuning in follow-up CL.

Bug: 319126175
Change-Id: Iae5de114a56f22445fdccb7330fc9c0fb06a10ac
parent 7386ea76
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -22,4 +22,7 @@
    <color name="dropdown_container">#F3F3FA</color>
    <color name="sign_in_options_container">#DADADA</color>
    <color name="sign_in_options_icon_color">#1B1B1B</color>

    <!-- These colors are used for Inline Suggestions. -->
    <color name="inline_background">#FFFFFF</color>
</resources>
 No newline at end of file
+2 −0
Original line number Diff line number Diff line
@@ -28,4 +28,6 @@
    <dimen name="dropdown_layout_horizontal_margin">24dp</dimen>
    <integer name="autofill_max_visible_datasets">5</integer>
    <dimen name="dropdown_touch_target_min_height">48dp</dimen>
    <dimen name="horizontal_chip_padding">8dp</dimen>
    <dimen name="vertical_chip_padding">6dp</dimen>
</resources>
 No newline at end of file
+7 −2
Original line number Diff line number Diff line
@@ -56,6 +56,7 @@ import androidx.credentials.provider.CustomCredentialEntry
import androidx.credentials.provider.PasswordCredentialEntry
import androidx.credentials.provider.PublicKeyCredentialEntry
import com.android.credentialmanager.GetFlowUtils
import com.android.credentialmanager.common.ui.InlinePresentationsFactory
import com.android.credentialmanager.common.ui.RemoteViewsFactory
import com.android.credentialmanager.getflow.ProviderDisplayInfo
import com.android.credentialmanager.getflow.toProviderDisplayInfo
@@ -293,8 +294,12 @@ class CredentialAutofillService : AutofillService() {
                } else {
                    inlinePresentationSpecs[inlinePresentationSpecsCount - 1]
                }
                if (spec != null) {
                    inlinePresentation = createInlinePresentation(primaryEntry, pendingIntent, icon,
                        spec!!, duplicateDisplayNamesForPasskeys)
                            InlinePresentationsFactory.modifyInlinePresentationSpec
                            (this@CredentialAutofillService, spec),
                            duplicateDisplayNamesForPasskeys)
                }
            }
            var dropdownPresentation: RemoteViews? = null
            if (i < lastDropdownDatasetIndex) {
+84 −0
Original line number Diff line number Diff line
/*
* Copyright (C) 2024 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 com.android.credentialmanager.common.ui


import android.content.Context
import android.util.Size
import android.widget.inline.InlinePresentationSpec
import androidx.autofill.inline.common.TextViewStyle
import androidx.autofill.inline.common.ViewStyle
import androidx.autofill.inline.UiVersions
import androidx.autofill.inline.UiVersions.Style
import androidx.autofill.inline.v1.InlineSuggestionUi
import androidx.core.content.ContextCompat
import android.util.TypedValue
import android.graphics.Typeface


class InlinePresentationsFactory {
    companion object {
        private const val googleSansMediumFontFamily = "google-sans-medium"
        private const val googleSansTextFontFamily = "google-sans-text"
        // There is no min width required for now but this is needed for the spec builder
        private const val minInlineWidth = 5000


        fun modifyInlinePresentationSpec(context: Context,
                                         originalSpec: InlinePresentationSpec): InlinePresentationSpec {
            return InlinePresentationSpec.Builder(Size(originalSpec.minSize.width, originalSpec
                    .minSize.height),
                    Size(minInlineWidth, originalSpec
                            .maxSize.height))
                    .setStyle(UiVersions.newStylesBuilder().addStyle(getStyle(context)).build())
                    .build()
        }


        fun getStyle(context: Context): Style {
            val textColorPrimary = ContextCompat.getColor(context,
                    com.android.credentialmanager.R.color.text_primary)
            val textColorSecondary = ContextCompat.getColor(context,
                    com.android.credentialmanager.R.color.text_secondary)
            val textColorBackground = ContextCompat.getColor(context,
                    com.android.credentialmanager.R.color.inline_background)
            val chipHorizontalPadding = context.resources.getDimensionPixelSize(com.android
                    .credentialmanager.R.dimen.horizontal_chip_padding)
            val chipVerticalPadding = context.resources.getDimensionPixelSize(com.android
                    .credentialmanager.R.dimen.vertical_chip_padding)
            return InlineSuggestionUi.newStyleBuilder()
                    .setChipStyle(
                            ViewStyle.Builder().setPadding(chipHorizontalPadding,
                                    chipVerticalPadding,
                                    chipHorizontalPadding, chipVerticalPadding).build()
                    )
                    .setTitleStyle(
                            TextViewStyle.Builder().setTextColor(textColorPrimary).setTextSize
                            (TypedValue.COMPLEX_UNIT_DIP, 14F)
                                    .setTypeface(googleSansMediumFontFamily,
                                            Typeface.NORMAL).setBackgroundColor(textColorBackground)
                                    .build()
                    )
                    .setSubtitleStyle(TextViewStyle.Builder().setTextColor(textColorSecondary)
                            .setTextSize(TypedValue.COMPLEX_UNIT_DIP, 12F).setTypeface
                            (googleSansTextFontFamily, Typeface.NORMAL).setBackgroundColor
                            (textColorBackground).build())
                    .build()
        }
    }
}
 No newline at end of file
+9 −3
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package com.android.server.autofill.ui;

import static android.service.autofill.FillResponse.FLAG_CREDENTIAL_MANAGER_RESPONSE;

import static com.android.server.autofill.Helper.sVerbose;

import android.annotation.NonNull;
@@ -24,6 +26,7 @@ import android.annotation.UserIdInt;
import android.content.IntentSender;
import android.service.autofill.Dataset;
import android.service.autofill.FillResponse;
import android.service.autofill.Flags;
import android.service.autofill.InlinePresentation;
import android.text.TextUtils;
import android.util.Pair;
@@ -141,10 +144,12 @@ public final class InlineFillUi {
            return new InlineFillUi(inlineFillUiInfo, inlineAuthentication,
                    maxInputLengthForAutofill);
        } else if (response.getDatasets() != null) {
            boolean ignoreHostSpec = Flags.autofillCredmanIntegration() && (
                    (response.getFlags() & FLAG_CREDENTIAL_MANAGER_RESPONSE) != 0);
            SparseArray<Pair<Dataset, InlineSuggestion>> inlineSuggestions =
                    InlineSuggestionFactory.createInlineSuggestions(inlineFillUiInfo,
                            InlineSuggestionInfo.SOURCE_AUTOFILL, response.getDatasets(),
                            uiCallback);
                            uiCallback, ignoreHostSpec);
            return new InlineFillUi(inlineFillUiInfo, inlineSuggestions,
                    maxInputLengthForAutofill);
        }
@@ -160,7 +165,8 @@ public final class InlineFillUi {
            @NonNull InlineSuggestionUiCallback uiCallback) {
        SparseArray<Pair<Dataset, InlineSuggestion>> inlineSuggestions =
                InlineSuggestionFactory.createInlineSuggestions(inlineFillUiInfo,
                        InlineSuggestionInfo.SOURCE_PLATFORM, datasets, uiCallback);
                        InlineSuggestionInfo.SOURCE_PLATFORM, datasets,
                        uiCallback, /* ignoreHostSpec= */ false);
        return new InlineFillUi(inlineFillUiInfo, inlineSuggestions);
    }

Loading