/* * Copyright (C) 2017 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.service.autofill; import static android.view.autofill.Helper.sDebug; import android.annotation.DrawableRes; import android.annotation.NonNull; import android.annotation.Nullable; import android.annotation.TestApi; import android.os.Parcel; import android.os.Parcelable; import android.text.TextUtils; import android.util.Log; import android.view.autofill.AutofillId; import android.widget.ImageView; import android.widget.RemoteViews; import com.android.internal.util.Preconditions; import java.util.ArrayList; import java.util.Objects; import java.util.regex.Pattern; /** * Replaces the content of a child {@link ImageView} of a * {@link RemoteViews presentation template} with the first image that matches a regular expression * (regex). * *

Typically used to display credit card logos. Example: * *

 *   new ImageTransformation.Builder(ccNumberId, Pattern.compile("^4815.*$"),
 *                                   R.drawable.ic_credit_card_logo1, "Brand 1")
 *     .addOption(Pattern.compile("^1623.*$"), R.drawable.ic_credit_card_logo2, "Brand 2")
 *     .addOption(Pattern.compile("^42.*$"), R.drawable.ic_credit_card_logo3, "Brand 3")
 *     .build();
 * 
* *

There is no imposed limit in the number of options, but keep in mind that regexs are * expensive to evaluate, so use the minimum number of regexs and add the most common first * (for example, if this is a tranformation for a credit card logo and the most common credit card * issuers are banks X and Y, add the regexes that resolves these 2 banks first). */ public final class ImageTransformation extends InternalTransformation implements Transformation, Parcelable { private static final String TAG = "ImageTransformation"; private final AutofillId mId; private final ArrayList