联系人号码添加复制功能
This commit is contained in:
@@ -1,8 +1,8 @@
|
|||||||
#Created by .winboll/winboll_app_build.gradle
|
#Created by .winboll/winboll_app_build.gradle
|
||||||
#Sun Jul 06 07:58:58 GMT 2025
|
#Sun Jul 06 08:12:37 GMT 2025
|
||||||
stageCount=9
|
stageCount=9
|
||||||
libraryProject=
|
libraryProject=
|
||||||
baseVersion=15.3
|
baseVersion=15.3
|
||||||
publishVersion=15.3.8
|
publishVersion=15.3.8
|
||||||
buildCount=1
|
buildCount=3
|
||||||
baseBetaVersion=15.3.9
|
baseBetaVersion=15.3.9
|
||||||
|
|||||||
@@ -5,19 +5,25 @@ package cc.winboll.studio.contacts.adapters;
|
|||||||
* @Date 2025/02/26 13:35:44
|
* @Date 2025/02/26 13:35:44
|
||||||
* @Describe ContactAdapter
|
* @Describe ContactAdapter
|
||||||
*/
|
*/
|
||||||
|
import android.content.ClipData;
|
||||||
|
import android.content.ClipboardManager;
|
||||||
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.Button;
|
import android.widget.LinearLayout;
|
||||||
|
import android.widget.PopupMenu;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
import android.widget.Toast;
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
import cc.winboll.studio.contacts.R;
|
import cc.winboll.studio.contacts.R;
|
||||||
import cc.winboll.studio.contacts.beans.ContactModel;
|
import cc.winboll.studio.contacts.beans.ContactModel;
|
||||||
|
import cc.winboll.studio.libaes.views.AOHPCTCSeekBar;
|
||||||
import com.hjq.toast.ToastUtils;
|
import com.hjq.toast.ToastUtils;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import cc.winboll.studio.libaes.views.AOHPCTCSeekBar;
|
|
||||||
|
|
||||||
public class ContactAdapter extends RecyclerView.Adapter<ContactAdapter.ContactViewHolder> {
|
public class ContactAdapter extends RecyclerView.Adapter<ContactAdapter.ContactViewHolder> {
|
||||||
|
|
||||||
@@ -26,8 +32,10 @@ public class ContactAdapter extends RecyclerView.Adapter<ContactAdapter.ContactV
|
|||||||
private static final int REQUEST_CALL_PHONE = 1;
|
private static final int REQUEST_CALL_PHONE = 1;
|
||||||
|
|
||||||
private List<ContactModel> contactList;
|
private List<ContactModel> contactList;
|
||||||
|
Context mContext;
|
||||||
|
|
||||||
public ContactAdapter(List<ContactModel> contactList) {
|
public ContactAdapter(Context context, List<ContactModel> contactList) {
|
||||||
|
mContext = context;
|
||||||
this.contactList = contactList;
|
this.contactList = contactList;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -41,6 +49,37 @@ public class ContactAdapter extends RecyclerView.Adapter<ContactAdapter.ContactV
|
|||||||
@Override
|
@Override
|
||||||
public void onBindViewHolder(@NonNull ContactViewHolder holder, int position) {
|
public void onBindViewHolder(@NonNull ContactViewHolder holder, int position) {
|
||||||
final ContactModel contact = contactList.get(position);
|
final ContactModel contact = contactList.get(position);
|
||||||
|
holder.llPhoneNumberMain.setOnLongClickListener(new View.OnLongClickListener() {
|
||||||
|
@Override
|
||||||
|
public boolean onLongClick(View p1) {
|
||||||
|
// 弹出复制菜单
|
||||||
|
PopupMenu menu = new PopupMenu(mContext, holder.llPhoneNumberMain);
|
||||||
|
//加载菜单资源
|
||||||
|
menu.getMenuInflater().inflate(R.menu.toolbar_contact_phonenumber, menu.getMenu());
|
||||||
|
//设置点击事件的响应
|
||||||
|
menu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
|
||||||
|
@Override
|
||||||
|
public boolean onMenuItemClick(MenuItem menuItem) {
|
||||||
|
int nItemId = menuItem.getItemId();
|
||||||
|
if (nItemId == R.id.item_contact_phonenumber_copy) {
|
||||||
|
// Gets a handle to the clipboard service.
|
||||||
|
ClipboardManager clipboard = (ClipboardManager) mContext.getSystemService(Context.CLIPBOARD_SERVICE);
|
||||||
|
// Creates a new text clip to put on the clipboard
|
||||||
|
ClipData clip = ClipData.newPlainText("simple text", contact.getNumber());
|
||||||
|
// Set the clipboard's primary clip.
|
||||||
|
clipboard.setPrimaryClip(clip);
|
||||||
|
Toast.makeText(mContext, "Copy to clipboard.", Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
//一定要调用show()来显示弹出式菜单
|
||||||
|
menu.show();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
holder.contactName.setText(contact.getName());
|
holder.contactName.setText(contact.getName());
|
||||||
holder.contactNumber.setText(contact.getNumber());
|
holder.contactNumber.setText(contact.getNumber());
|
||||||
|
|
||||||
@@ -69,12 +108,14 @@ public class ContactAdapter extends RecyclerView.Adapter<ContactAdapter.ContactV
|
|||||||
}
|
}
|
||||||
|
|
||||||
public class ContactViewHolder extends RecyclerView.ViewHolder {
|
public class ContactViewHolder extends RecyclerView.ViewHolder {
|
||||||
|
LinearLayout llPhoneNumberMain;
|
||||||
TextView contactName;
|
TextView contactName;
|
||||||
TextView contactNumber;
|
TextView contactNumber;
|
||||||
AOHPCTCSeekBar dialAOHPCTCSeekBar;
|
AOHPCTCSeekBar dialAOHPCTCSeekBar;
|
||||||
|
|
||||||
public ContactViewHolder(@NonNull View itemView) {
|
public ContactViewHolder(@NonNull View itemView) {
|
||||||
super(itemView);
|
super(itemView);
|
||||||
|
llPhoneNumberMain = itemView.findViewById(R.id.itemcontactLinearLayout1);
|
||||||
contactName = itemView.findViewById(R.id.contact_name);
|
contactName = itemView.findViewById(R.id.contact_name);
|
||||||
contactNumber = itemView.findViewById(R.id.contact_number);
|
contactNumber = itemView.findViewById(R.id.contact_number);
|
||||||
dialAOHPCTCSeekBar = itemView.findViewById(R.id.aohpctcseekbar_dial);
|
dialAOHPCTCSeekBar = itemView.findViewById(R.id.aohpctcseekbar_dial);
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ public class ContactsFragment extends Fragment {
|
|||||||
super.onViewCreated(view, savedInstanceState);
|
super.onViewCreated(view, savedInstanceState);
|
||||||
recyclerView = view.findViewById(R.id.contacts_recycler_view);
|
recyclerView = view.findViewById(R.id.contacts_recycler_view);
|
||||||
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
|
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
|
||||||
contactAdapter = new ContactAdapter(contactList);
|
contactAdapter = new ContactAdapter(getContext(), contactList);
|
||||||
recyclerView.setAdapter(contactAdapter);
|
recyclerView.setAdapter(contactAdapter);
|
||||||
|
|
||||||
searchEditText = view.findViewById(R.id.search_edit_text);
|
searchEditText = view.findViewById(R.id.search_edit_text);
|
||||||
|
|||||||
@@ -9,7 +9,8 @@
|
|||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:orientation="horizontal"
|
android:orientation="horizontal"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content">
|
android:layout_height="wrap_content"
|
||||||
|
android:id="@+id/itemcontactLinearLayout1">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/contact_number"
|
android:id="@+id/contact_number"
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||||
|
|
||||||
|
<item
|
||||||
|
android:id="@+id/item_contact_phonenumber_copy"
|
||||||
|
android:title="Copy"/>
|
||||||
|
|
||||||
|
</menu>
|
||||||
Reference in New Issue
Block a user