105 lines
3.2 KiB
Java
105 lines
3.2 KiB
Java
package com.xxpatx.os.adapter;
|
|
|
|
import android.content.Context;
|
|
import android.content.Intent;
|
|
import android.net.Uri;
|
|
import android.view.LayoutInflater;
|
|
import android.view.View;
|
|
import android.view.ViewGroup;
|
|
import android.widget.ImageView;
|
|
import android.widget.TextView;
|
|
|
|
import androidx.annotation.NonNull;
|
|
import androidx.constraintlayout.widget.ConstraintLayout;
|
|
import androidx.recyclerview.widget.RecyclerView;
|
|
|
|
import com.xxpatx.os.R;
|
|
|
|
import java.util.List;
|
|
|
|
public class PhoneAdapter extends RecyclerView.Adapter<PhoneAdapter.Holder> {
|
|
|
|
//指定SIM卡拨打
|
|
public static final String[] DUAL_SIM_TYPES = {"subscription", "Subscription",
|
|
"com.android.phone.extra.slot",
|
|
"phone", "com.android.phone.DialingMode",
|
|
"simId", "simnum", "phone_type",
|
|
"simSlot"};
|
|
|
|
private Context mContext;
|
|
private List<String> mPhoneList;
|
|
private String mPhone;
|
|
|
|
public void setPhoneList(List<String> phoneList) {
|
|
mPhoneList = phoneList;
|
|
notifyDataSetChanged();
|
|
}
|
|
|
|
public void setPhone(String phone) {
|
|
mPhone = phone;
|
|
}
|
|
|
|
public interface OutCallback {
|
|
public void onCall();
|
|
}
|
|
|
|
private OutCallback mOutCallback;
|
|
|
|
public void setOutCallback(OutCallback outCallback) {
|
|
mOutCallback = outCallback;
|
|
}
|
|
|
|
@NonNull
|
|
@Override
|
|
public Holder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
|
mContext = parent.getContext();
|
|
return new Holder(LayoutInflater.from(mContext).inflate(R.layout.item_phone, parent, false));
|
|
}
|
|
|
|
@Override
|
|
public void onBindViewHolder(@NonNull Holder holder, int position) {
|
|
String phone = mPhoneList.get(position);
|
|
if (position == 0) {
|
|
holder.iv_card.setImageDrawable(mContext.getDrawable(R.drawable.sim_card_1));
|
|
} else if (position == 1) {
|
|
holder.iv_card.setImageDrawable(mContext.getDrawable(R.drawable.sim_card_2));
|
|
}
|
|
holder.tv_number.setText(phone);
|
|
holder.root.setOnClickListener(new View.OnClickListener() {
|
|
@Override
|
|
public void onClick(View v) {
|
|
Intent dialIntent = new Intent(Intent.ACTION_CALL);
|
|
Uri data = Uri.parse("tel:" + mPhone);
|
|
dialIntent.setData(data);
|
|
for (int i = 0; i < DUAL_SIM_TYPES.length; i++) {
|
|
//0代表卡1,1代表卡2
|
|
dialIntent.putExtra(DUAL_SIM_TYPES[i], position);
|
|
}
|
|
mContext.startActivity(dialIntent);
|
|
if (mOutCallback != null) {
|
|
mOutCallback.onCall();
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
@Override
|
|
public int getItemCount() {
|
|
return mPhoneList == null ? 0 : mPhoneList.size();
|
|
}
|
|
|
|
public class Holder extends RecyclerView.ViewHolder {
|
|
ConstraintLayout root;
|
|
TextView tv_sim, tv_number;
|
|
ImageView iv_card;
|
|
|
|
public Holder(@NonNull View itemView) {
|
|
super(itemView);
|
|
root = itemView.findViewById(R.id.root);
|
|
iv_card = itemView.findViewById(R.id.iv_card);
|
|
tv_sim = itemView.findViewById(R.id.tv_sim);
|
|
tv_number = itemView.findViewById(R.id.tv_number);
|
|
}
|
|
}
|
|
}
|