通话记录号码添加复制功能
This commit is contained in:
		| @@ -1,8 +1,8 @@ | ||||
| #Created by .winboll/winboll_app_build.gradle | ||||
| #Sat Jul 05 12:43:15 HKT 2025 | ||||
| #Sun Jul 06 07:58:58 GMT 2025 | ||||
| stageCount=9 | ||||
| libraryProject= | ||||
| baseVersion=15.3 | ||||
| publishVersion=15.3.8 | ||||
| buildCount=0 | ||||
| buildCount=1 | ||||
| baseBetaVersion=15.3.9 | ||||
|   | ||||
| @@ -5,13 +5,18 @@ package cc.winboll.studio.contacts.adapters; | ||||
|  * @Date 2025/02/26 13:09:32 | ||||
|  * @Describe CallLogAdapter | ||||
|  */ | ||||
| import android.content.ClipData; | ||||
| import android.content.ClipboardManager; | ||||
| import android.content.Context; | ||||
| import android.content.Intent; | ||||
| import android.view.LayoutInflater; | ||||
| import android.view.MenuItem; | ||||
| import android.view.View; | ||||
| import android.view.ViewGroup; | ||||
| import android.widget.Button; | ||||
| import android.widget.PopupMenu; | ||||
| import android.widget.TextView; | ||||
| import android.widget.Toast; | ||||
| import androidx.annotation.NonNull; | ||||
| import androidx.recyclerview.widget.RecyclerView; | ||||
| import cc.winboll.studio.contacts.R; | ||||
| @@ -47,6 +52,38 @@ public class CallLogAdapter extends RecyclerView.Adapter<CallLogAdapter.CallLogV | ||||
|     public void onBindViewHolder(@NonNull CallLogViewHolder holder, int position) { | ||||
|         final CallLogModel callLog = callLogList.get(position); | ||||
|         holder.phoneNumber.setText(callLog.getPhoneNumber() + "☎" + mContactUtils.getContactsName(callLog.getPhoneNumber())); | ||||
| 		holder.phoneNumber.setOnLongClickListener(new View.OnLongClickListener() { | ||||
| 				@Override | ||||
| 				public boolean onLongClick(View p1) { | ||||
| 					// 弹出复制菜单 | ||||
| 					PopupMenu menu = new PopupMenu(mContext, holder.phoneNumber); | ||||
| 					//加载菜单资源 | ||||
| 					menu.getMenuInflater().inflate(R.menu.toolbar_phonenumber, menu.getMenu()); | ||||
| 					//设置点击事件的响应 | ||||
| 					menu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { | ||||
| 							@Override | ||||
| 							public boolean onMenuItemClick(MenuItem menuItem) { | ||||
| 								int nItemId = menuItem.getItemId(); | ||||
| 								if (nItemId == R.id.item_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", callLog.getPhoneNumber()); | ||||
| 									// 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.callStatus.setText(callLog.getCallStatus()); | ||||
|         SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault()); | ||||
|         holder.callDate.setText(dateFormat.format(callLog.getCallDate())); | ||||
|   | ||||
							
								
								
									
										9
									
								
								contacts/src/main/res/menu/toolbar_phonenumber.xml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								contacts/src/main/res/menu/toolbar_phonenumber.xml
									
									
									
									
									
										Normal file
									
								
							| @@ -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_phonenumber_copy" | ||||
|         android:title="Copy"/> | ||||
|      | ||||
| </menu> | ||||
		Reference in New Issue
	
	Block a user
	 ZhanGSKen
					ZhanGSKen