Search in sources :

Example 1 with Dataset

use of android.service.autofill.Dataset 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)

Example 2 with Dataset

use of android.service.autofill.Dataset in project KeePassDX by Kunzisoft.

the class AutofillHelper method buildResponseWhenEntrySelected.

/**
 * Method to hit when right key is selected
 */
public void buildResponseWhenEntrySelected(Activity activity, PwEntry entry) {
    Intent mReplyIntent;
    Intent intent = activity.getIntent();
    if (isIntentContainsExtraAssistStructureKey(intent)) {
        AssistStructure structure = intent.getParcelableExtra(android.view.autofill.AutofillManager.EXTRA_ASSIST_STRUCTURE);
        StructureParser.Result result = new StructureParser(structure).parse();
        // New Response
        FillResponse.Builder responseBuilder = new FillResponse.Builder();
        Dataset dataset = buildDataset(activity, entry, result);
        responseBuilder.addDataset(dataset);
        mReplyIntent = new Intent();
        Log.d(activity.getClass().getName(), "Successed Autofill auth.");
        mReplyIntent.putExtra(AutofillManager.EXTRA_AUTHENTICATION_RESULT, responseBuilder.build());
        activity.setResult(Activity.RESULT_OK, mReplyIntent);
    } else {
        Log.w(activity.getClass().getName(), "Failed Autofill auth.");
        activity.setResult(Activity.RESULT_CANCELED);
    }
}
Also used : Dataset(android.service.autofill.Dataset) FillResponse(android.service.autofill.FillResponse) AssistStructure(android.app.assist.AssistStructure) Intent(android.content.Intent)

Example 3 with Dataset

use of android.service.autofill.Dataset in project KeePassDX by Kunzisoft.

the class AutofillHelper method buildDataset.

@Nullable
private Dataset buildDataset(Context context, PwEntry entry, StructureParser.Result struct) {
    String title = makeEntryTitle(entry);
    RemoteViews views = newRemoteViews(context.getPackageName(), title);
    Dataset.Builder builder = new Dataset.Builder(views);
    builder.setId(entry.getUUID().toString());
    if (entry.getPassword() != null) {
        AutofillValue value = AutofillValue.forText(entry.getPassword());
        struct.password.forEach(id -> builder.setValue(id, value));
    }
    if (entry.getUsername() != null) {
        AutofillValue value = AutofillValue.forText(entry.getUsername());
        List<AutofillId> ids = new ArrayList<>(struct.username);
        if (entry.getUsername().contains("@") || struct.username.isEmpty())
            ids.addAll(struct.email);
        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) ArrayList(java.util.ArrayList) AutofillValue(android.view.autofill.AutofillValue) AutofillId(android.view.autofill.AutofillId) Nullable(android.support.annotation.Nullable)

Aggregations

Dataset (android.service.autofill.Dataset)3 Nullable (android.support.annotation.Nullable)2 AutofillId (android.view.autofill.AutofillId)2 AutofillValue (android.view.autofill.AutofillValue)2 RemoteViews (android.widget.RemoteViews)2 AssistStructure (android.app.assist.AssistStructure)1 Intent (android.content.Intent)1 FillResponse (android.service.autofill.FillResponse)1 ArrayList (java.util.ArrayList)1