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;
}
}
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);
}
}
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;
}
}
Aggregations