Search in sources :

Example 1 with AutofillValue

use of android.view.autofill.AutofillValue in project TinyKeePass by sorz.

the class AutofillUtils method buildDataset.

@Nullable
static Dataset buildDataset(Context context, Entry entry, StructureParser.Result struct) {
    String title = makeEntryTitle(context, entry);
    RemoteViews views = getRemoteViews(context, title, R.drawable.ic_person_blue_24dp);
    views.setImageViewBitmap(R.id.imageIcon, getIcon(entry));
    Dataset.Builder builder = new Dataset.Builder(views);
    builder.setId(entry.getUuid().toString());
    if (notEmpty(entry.getPassword())) {
        AutofillValue value = AutofillValue.forText(entry.getPassword());
        struct.password.forEach(id -> builder.setValue(id, value));
    }
    if (notEmpty(entry.getUsername())) {
        AutofillValue value = AutofillValue.forText(entry.getUsername());
        Stream<AutofillId> ids = struct.username.stream();
        if (entry.getUsername().contains("@") || struct.username.isEmpty())
            ids = Stream.concat(ids, struct.email.stream());
        ids.forEach(id -> builder.setValue(id, value));
    }
    try {
        return builder.build();
    } catch (IllegalArgumentException e) {
        // if not value be set
        return null;
    }
}
Also used : RemoteViews(android.widget.RemoteViews) Dataset(android.service.autofill.Dataset) AutofillValue(android.view.autofill.AutofillValue) AutofillId(android.view.autofill.AutofillId) Nullable(android.support.annotation.Nullable)

Aggregations

Dataset (android.service.autofill.Dataset)1 Nullable (android.support.annotation.Nullable)1 AutofillId (android.view.autofill.AutofillId)1 AutofillValue (android.view.autofill.AutofillValue)1 RemoteViews (android.widget.RemoteViews)1