Long press to copy quick search text

pull/209/head
M66B 2 years ago
parent 1c5622c54e
commit 57096d2b9f

@ -21,6 +21,8 @@ package eu.faircode.email;
import android.app.DatePickerDialog; import android.app.DatePickerDialog;
import android.app.Dialog; import android.app.Dialog;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.SharedPreferences; import android.content.SharedPreferences;
@ -29,6 +31,7 @@ import android.database.Cursor;
import android.database.MatrixCursor; import android.database.MatrixCursor;
import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteDatabase;
import android.graphics.Typeface; import android.graphics.Typeface;
import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.text.TextUtils; import android.text.TextUtils;
import android.view.KeyEvent; import android.view.KeyEvent;
@ -45,6 +48,7 @@ import android.widget.FilterQueryProvider;
import android.widget.ImageButton; import android.widget.ImageButton;
import android.widget.Spinner; import android.widget.Spinner;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
@ -198,6 +202,21 @@ public class FragmentDialogSearch extends FragmentDialogBase {
} }
}; };
View.OnLongClickListener onCopy = new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
String text = ((TextView) v).getText().toString();
ClipboardManager cbm = Helper.getSystemService(v.getContext(), ClipboardManager.class);
cbm.setPrimaryClip(ClipData.newPlainText(getString(R.string.app_name), text));
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU)
ToastEx.makeText(context, R.string.title_clipboard_copied, Toast.LENGTH_LONG).show();
return true;
}
};
Button[] btn = new Button[]{btnSearch1, btnSearch2, btnSearch3}; Button[] btn = new Button[]{btnSearch1, btnSearch2, btnSearch3};
int searches = 0; int searches = 0;
@ -210,6 +229,7 @@ public class FragmentDialogSearch extends FragmentDialogBase {
String search = prefs.getString("last_search" + (i + 1), null); String search = prefs.getString("last_search" + (i + 1), null);
btn[i].setText(search); btn[i].setText(search);
btn[i].setOnClickListener(onSearch); btn[i].setOnClickListener(onSearch);
btn[i].setOnLongClickListener(onCopy);
btn[i].setVisibility(View.VISIBLE); btn[i].setVisibility(View.VISIBLE);
} else } else
btn[i].setVisibility(searches > 0 ? View.INVISIBLE : View.GONE); btn[i].setVisibility(searches > 0 ? View.INVISIBLE : View.GONE);

Loading…
Cancel
Save