use of de.slackspace.openkeepass.domain.Entry in project TinyKeePass by sorz.
the class EntryFragment method copyEntry.
private void copyEntry(Entry entry, boolean copyUsername, boolean copyPassword) {
if (copyUsername && notEmpty(entry.getUsername())) {
clipboardManager.setPrimaryClip(ClipData.newPlainText(getString(R.string.username), entry.getUsername()));
String message = getString(R.string.username_copied, entry.getUsername());
if (getView() == null) {
Toast.makeText(getContext(), message, Toast.LENGTH_SHORT).show();
} else {
Snackbar snackbar = Snackbar.make(getView(), message, Snackbar.LENGTH_LONG);
if (copyPassword)
snackbar.setAction(R.string.copy_password, v -> copyPassword(entry));
snackbar.show();
}
}
if (copyPassword && notEmpty(entry.getPassword())) {
if (copyUsername && notEmpty(entry.getUsername())) {
// username already copied, waiting for user's action before copy password.
Intent intent = new Intent(getContext(), PasswordCopingService.class);
intent.setAction(PasswordCopingService.ACTION_NEW_NOTIFICATION);
intent.putExtra(PasswordCopingService.EXTRA_PASSWORD, entry.getPassword());
if (entry.getUsername() != null)
intent.putExtra(PasswordCopingService.EXTRA_USERNAME, entry.getUsername());
if (entry.getTitle() != null)
intent.putExtra(PasswordCopingService.EXTRA_ENTRY_TITLE, entry.getTitle());
getContext().startService(intent);
} else {
// username not copied, copy password immediately.
copyPassword(entry);
}
}
}
use of de.slackspace.openkeepass.domain.Entry in project TinyKeePass by sorz.
the class AuthActivity method onDatabaseOpened.
@Override
protected void onDatabaseOpened() {
StructureParser.Result result = parseStructure();
KeePassFile keePass = KeePassStorage.get(this);
SearchIndex index = new SearchIndex(keePass);
StringBuilder queryBuilder = new StringBuilder();
result.title.forEach(title -> queryBuilder.append(title).append(' '));
Stream<Entry> entryStream = index.search(queryBuilder.toString()).map(keePass::getEntryByUUID);
FillResponse.Builder responseBuilder = new FillResponse.Builder();
// add matched entities
entryStream.map(entry -> AutofillUtils.buildDataset(this, entry, result)).filter(Objects::nonNull).limit(MAX_NUM_CANDIDATE_ENTRIES).forEach(responseBuilder::addDataset);
// add "show all" item
RemoteViews presentation = AutofillUtils.getRemoteViews(this, getString(R.string.autofill_item_show_all), R.drawable.ic_more_horiz_gray_24dp);
presentation.setTextColor(R.id.textView, getColor(R.color.hint));
Dataset.Builder datasetBuilder = new Dataset.Builder(presentation).setAuthentication(EntrySelectActivity.getAuthIntentSenderForResponse(this));
result.allAutofillIds().forEach(id -> datasetBuilder.setValue(id, null));
responseBuilder.addDataset(datasetBuilder.build());
setFillResponse(responseBuilder.build());
finish();
}
use of de.slackspace.openkeepass.domain.Entry in project TinyKeePass by sorz.
the class EntryRecyclerViewAdapter method onBindViewHolder.
@Override
public void onBindViewHolder(final ViewHolder holder, int position) {
Entry entry = entries.get(position);
holder.view.setSelected(selectedItem == position);
holder.imageIcon.setImageBitmap(getIcon(entry));
holder.textTitle.setText(parse(entry.getTitle()));
holder.textUsername.setText(parse(entry.getUsername()));
String url = parse(entry.getUrl()).replaceFirst("https?://(www\\.)?", "");
String[] hostnamePath = url.split("/", 2);
holder.textUrlHostname.setText(hostnamePath[0]);
holder.textUrlPath.setText(hostnamePath.length > 1 && !hostnamePath[1].isEmpty() ? "/" + hostnamePath[1] : "");
holder.textPassword.setText("");
if (position == passwordShownItem && entry.getPassword() != null && !entry.getPassword().isEmpty()) {
SpannableStringBuilder builder = new SpannableStringBuilder();
int[] textColors = { context.getColor(R.color.password1), context.getColor(R.color.password2) };
int[] backgroundColors = { context.getColor(R.color.passwordBackground1), context.getColor(R.color.passwordBackground2) };
int colorIndex = 0;
for (char c : entry.getPassword().toCharArray()) {
builder.append(c);
if (builder.length() >= PASSWORD_NUM_OF_CHARS_IN_GROUP || holder.textPassword.length() + builder.length() >= entry.getPassword().length()) {
builder.setSpan(new BackgroundColorSpan(backgroundColors[colorIndex]), 0, builder.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
builder.setSpan(new ForegroundColorSpan(textColors[colorIndex]), 0, builder.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
holder.textPassword.append(builder);
builder.clear();
colorIndex = (colorIndex + 1) % textColors.length;
}
}
}
showTextViewOnlyIfNotEmpty(holder.textUsername);
showTextViewOnlyIfNotEmpty(holder.textUrlHostname);
showTextViewOnlyIfNotEmpty(holder.textUrlPath);
showTextViewOnlyIfNotEmpty(holder.textPassword);
if (onClickHandler != null)
holder.view.setOnClickListener(v -> onClickHandler.accept(v, entry));
if (onLongClickHandler != null)
holder.view.setOnLongClickListener(v -> {
setSelectedItem(position);
return onLongClickHandler.test(v, entry);
});
}
Aggregations