Search in sources :

Example 1 with Entry

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);
        }
    }
}
Also used : Context(android.content.Context) ActionMode(android.view.ActionMode) Bundle(android.os.Bundle) FloatingActionButton(android.support.design.widget.FloatingActionButton) LayoutInflater(android.view.LayoutInflater) IntentFilter(android.content.IntentFilter) Uri(android.net.Uri) Intent(android.content.Intent) SystemClock(android.os.SystemClock) LocalBroadcastManager(android.support.v4.content.LocalBroadcastManager) BroadcastReceiver(android.content.BroadcastReceiver) ViewGroup(android.view.ViewGroup) MenuItem(android.view.MenuItem) ClipData(android.content.ClipData) KeePassStorage(org.sorz.lab.tinykeepass.keepass.KeePassStorage) MenuInflater(android.view.MenuInflater) Toast(android.widget.Toast) Menu(android.view.Menu) ClipboardManager(android.content.ClipboardManager) View(android.view.View) Snackbar(android.support.design.widget.Snackbar) Entry(de.slackspace.openkeepass.domain.Entry) KeePassHelper.notEmpty(org.sorz.lab.tinykeepass.keepass.KeePassHelper.notEmpty) Intent(android.content.Intent) Snackbar(android.support.design.widget.Snackbar)

Example 2 with 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();
}
Also used : RemoteViews(android.widget.RemoteViews) Context(android.content.Context) Dataset(android.service.autofill.Dataset) KeyException(java.security.KeyException) KeePassFile(de.slackspace.openkeepass.domain.KeePassFile) R(org.sorz.lab.tinykeepass.R) SearchIndex(org.sorz.lab.tinykeepass.search.SearchIndex) Intent(android.content.Intent) RequiresApi(android.support.annotation.RequiresApi) PendingIntent(android.app.PendingIntent) Objects(java.util.Objects) IntentSender(android.content.IntentSender) Stream(java.util.stream.Stream) FillResponse(android.service.autofill.FillResponse) KeePassStorage(org.sorz.lab.tinykeepass.keepass.KeePassStorage) Build(android.os.Build) Entry(de.slackspace.openkeepass.domain.Entry) SearchIndex(org.sorz.lab.tinykeepass.search.SearchIndex) Dataset(android.service.autofill.Dataset) FillResponse(android.service.autofill.FillResponse) Entry(de.slackspace.openkeepass.domain.Entry) RemoteViews(android.widget.RemoteViews) Objects(java.util.Objects) KeePassFile(de.slackspace.openkeepass.domain.KeePassFile)

Example 3 with Entry

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);
        });
}
Also used : Context(android.content.Context) LayoutInflater(android.view.LayoutInflater) EntryQueryRelevance(org.sorz.lab.tinykeepass.search.EntryQueryRelevance) KeePassFile(de.slackspace.openkeepass.domain.KeePassFile) Spannable(android.text.Spannable) ImageView(android.widget.ImageView) BackgroundColorSpan(android.text.style.BackgroundColorSpan) Collectors(java.util.stream.Collectors) ViewGroup(android.view.ViewGroup) ArrayList(java.util.ArrayList) RecyclerView(android.support.v7.widget.RecyclerView) BiPredicate(java.util.function.BiPredicate) SpannableStringBuilder(android.text.SpannableStringBuilder) List(java.util.List) TextView(android.widget.TextView) KeePassStorage(org.sorz.lab.tinykeepass.keepass.KeePassStorage) BiConsumer(java.util.function.BiConsumer) KeePassHelper.getIcon(org.sorz.lab.tinykeepass.keepass.KeePassHelper.getIcon) View(android.view.View) KeePassHelper(org.sorz.lab.tinykeepass.keepass.KeePassHelper) Nullable(android.support.annotation.Nullable) ForegroundColorSpan(android.text.style.ForegroundColorSpan) Log(android.util.Log) Entry(de.slackspace.openkeepass.domain.Entry) Entry(de.slackspace.openkeepass.domain.Entry) ForegroundColorSpan(android.text.style.ForegroundColorSpan) SpannableStringBuilder(android.text.SpannableStringBuilder) BackgroundColorSpan(android.text.style.BackgroundColorSpan)

Aggregations

Context (android.content.Context)3 Entry (de.slackspace.openkeepass.domain.Entry)3 KeePassStorage (org.sorz.lab.tinykeepass.keepass.KeePassStorage)3 Intent (android.content.Intent)2 LayoutInflater (android.view.LayoutInflater)2 View (android.view.View)2 ViewGroup (android.view.ViewGroup)2 KeePassFile (de.slackspace.openkeepass.domain.KeePassFile)2 PendingIntent (android.app.PendingIntent)1 BroadcastReceiver (android.content.BroadcastReceiver)1 ClipData (android.content.ClipData)1 ClipboardManager (android.content.ClipboardManager)1 IntentFilter (android.content.IntentFilter)1 IntentSender (android.content.IntentSender)1 Uri (android.net.Uri)1 Build (android.os.Build)1 Bundle (android.os.Bundle)1 SystemClock (android.os.SystemClock)1 Dataset (android.service.autofill.Dataset)1 FillResponse (android.service.autofill.FillResponse)1