Compare commits

...

2 Commits

5 changed files with 169 additions and 101 deletions

View File

@@ -1,8 +1,8 @@
#Created by .winboll/winboll_app_build.gradle
#Mon Sep 01 08:07:48 HKT 2025
#Fri Sep 05 17:49:46 GMT 2025
stageCount=8
libraryProject=
baseVersion=15.3
publishVersion=15.3.7
buildCount=0
buildCount=16
baseBetaVersion=15.3.8

View File

@@ -57,6 +57,7 @@ public class ComposeSMSActivity extends BaseActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
LogUtils.d(TAG, "onCreate");
setContentView(R.layout.activity_composesms);
// 初始化Intent数据增加空判断避免NullPointerException
@@ -116,8 +117,9 @@ public class ComposeSMSActivity extends BaseActivity {
}
});
// 初始化联系人列表
// 初始化联系人列表(关键:设置单选模式,确保选中状态生效)
mlvContracts = (ListView) findViewById(R.id.activitycomposesmsListView1);
mlvContracts.setChoiceMode(ListView.CHOICE_MODE_SINGLE); // 开启单选,与布局中一致
// 初始化号码输入框(核心:优化文本变化监听逻辑)
metTO = (EditText) findViewById(R.id.activitycomposesmsEditText1);
@@ -171,7 +173,7 @@ public class ComposeSMSActivity extends BaseActivity {
}
}
// 核心优化:根据输入号码筛选列表(无结果则显示空列表)
// 核心优化:根据输入号码筛选列表(无结果则显示空列表,优化选中逻辑
private void filterListByPhone(String inputPhone) {
PhoneUtil phoneUtil = new PhoneUtil(this);
List<PhoneBean> allContacts = phoneUtil.getPhoneList();
@@ -179,7 +181,7 @@ public class ComposeSMSActivity extends BaseActivity {
// 遍历所有联系人,匹配包含输入号码的联系人
for (PhoneBean contact : allContacts) {
if (contact.getTelPhone().contains(inputPhone)
if (contact.getTelPhone().contains(inputPhone)
|| phoneUtil.isTheSamePhoneNumber(contact.getTelPhone(), inputPhone)) {
matchedContacts.add(contact);
}
@@ -190,10 +192,29 @@ public class ComposeSMSActivity extends BaseActivity {
// 用筛选结果更新列表(无结果则传入空列表)
initAdapter(matchedContacts.isEmpty() ? new ArrayList<PhoneBean>() : matchedContacts);
// 定位到第一个匹配项(如果有)
// 定位并选中匹配项(如果有)
if (!matchedContacts.isEmpty()) {
mlvContracts.setSelection(0);
mtvTOName.setText(matchedContacts.get(0).getName());
boolean isFound = false;
for (int i = 0; i < matchedContacts.size(); i++) {
PhoneBean item = matchedContacts.get(i);
// 精确匹配号码(兼容区域码格式)
if (phoneUtil.isTheSamePhoneNumber(item.getTelPhone(), inputPhone)) {
mtvTOName.setText(item.getName());
// 关键:先滚动到目标位置,再设置选中状态
mlvContracts.setSelection(i);
// 主动设置选中(确保样式生效,兼容部分系统)
mlvContracts.setItemChecked(i, true);
LogUtils.d(TAG, String.format("%s 匹配 %s选中位置%d", inputPhone, item.getTelPhone(), i));
isFound = true;
break;
}
}
// 若未精确匹配,选中第一个结果
/*if (!isFound) {
mlvContracts.setSelection(0);
mlvContracts.setItemChecked(0, true);
mtvTOName.setText(matchedContacts.get(0).getName());
}*/
} else {
mtvTOName.setText(""); // 无结果时清空姓名显示
}
@@ -206,7 +227,9 @@ public class ComposeSMSActivity extends BaseActivity {
List<PhoneBean> matchedContacts = phoneUtil.getPhonesByName(searchName);
initAdapter(matchedContacts);
if (!matchedContacts.isEmpty()) {
// 选中第一个结果并设置样式
mlvContracts.setSelection(0);
mlvContracts.setItemChecked(0, true);
}
}
@@ -246,7 +269,7 @@ public class ComposeSMSActivity extends BaseActivity {
return 0;
}
// 初始化或更新列表适配器
// 初始化或更新列表适配器
private void initAdapter(List<PhoneBean> initData) {
mAdapterData.clear(); // 清空旧数据
final PhoneUtil phoneUtil = new PhoneUtil(this);
@@ -280,19 +303,45 @@ public class ComposeSMSActivity extends BaseActivity {
mSimpleAdapter.setDropDownViewResource(R.layout.listview_contracts);
mlvContracts.setAdapter(mSimpleAdapter);
// 列表项点击事件
// 列表项点击事件:点击时主动设置选中状态,确保样式突显
mlvContracts.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
if (position < mAdapterData.size()) {
// 1. 主动设置当前项为选中状态
mlvContracts.setItemChecked(position, true);
// 2. 更新号码输入框和姓名显示
String phone = mAdapterData.get(position).get(MAP_PHONE).toString();
metTO.setText(phone);
mtvTOName.setText(phoneUtil.getNameByPhone(phone));
// 3. 滚动到点击位置(确保可见)
mlvContracts.setSelection(position);
}
}
});
// 列表项选中状态变化监听(可选,增强选中反馈)
mlvContracts.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
// 选中时可添加额外反馈(如改变文本颜色,可选)
if (view != null) {
TextView tvName = (TextView) view.findViewById(R.id.listviewcontractsTextView1);
TextView tvPhone = (TextView) view.findViewById(R.id.listviewcontractsTextView2);
if (tvName != null) tvName.setTextColor(getResources().getColor(R.color.white));
if (tvPhone != null) tvPhone.setTextColor(getResources().getColor(R.color.white));
}
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
// 未选中时无操作
}
});
} else {
mSimpleAdapter.notifyDataSetChanged(); // 数据更新时通知适配器
// 数据更新时,先取消所有旧选中状态,再通知适配器刷新
mlvContracts.clearChoices();
mSimpleAdapter.notifyDataSetChanged();
}
}

View File

@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- 选中状态:深灰色背景(可根据需求调整颜色) -->
<item android:state_selected="true" android:drawable="@color/list_item_selected"/>
<!-- 按压状态:浅灰色背景 -->
<item android:state_pressed="true" android:drawable="@color/list_item_pressed"/>
<!-- 默认状态:透明背景 -->
<item android:drawable="@android:color/transparent"/>
</selector>

View File

@@ -1,109 +1,112 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<cc.winboll.studio.libaes.views.AToolbar
android:layout_width="match_parent"
android:layout_height="@dimen/toolbar_height"
android:id="@+id/activitycomposesmsASupportToolbar1"/>
<cc.winboll.studio.libaes.views.AToolbar
android:layout_width="match_parent"
android:layout_height="@dimen/toolbar_height"
android:id="@+id/activitycomposesmsASupportToolbar1"/>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/bg_frame">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/bg_frame">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/activitycomposesmsRelativeLayout1">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/activitycomposesmsRelativeLayout1">
<LinearLayout
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/activitycomposesmsLinearLayout1"
android:gravity="center_vertical"
android:layout_alignParentRight="true"
android:layout_marginRight="10dp"
android:layout_marginLeft="10dp"
android:layout_alignParentLeft="true">
<LinearLayout
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/activitycomposesmsLinearLayout1"
android:gravity="center_vertical"
android:layout_alignParentRight="true"
android:layout_marginRight="10dp"
android:layout_marginLeft="10dp"
android:layout_alignParentLeft="true">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="(拼音搜索):"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="(拼音搜索):"/>
<EditText
android:layout_width="80dp"
android:ems="10"
android:layout_height="wrap_content"
android:id="@+id/activitycomposesmsEditText2"/>
<EditText
android:layout_width="80dp"
android:ems="10"
android:layout_height="wrap_content"
android:id="@+id/activitycomposesmsEditText2"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toRightOf="@id/activitycomposesmsEditText2"
android:id="@+id/activitycomposesmsTextView2"
android:layout_weight="1.0"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toRightOf="@id/activitycomposesmsEditText2"
android:id="@+id/activitycomposesmsTextView2"
android:layout_weight="1.0"/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_below="@id/activitycomposesmsLinearLayout1"
android:layout_alignParentRight="true"
android:layout_marginRight="10dp"
android:layout_marginLeft="10dp"
android:layout_alignParentLeft="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical">
<LinearLayout
android:orientation="horizontal"
android:layout_below="@id/activitycomposesmsLinearLayout1"
android:layout_alignParentRight="true"
android:layout_marginRight="10dp"
android:layout_marginLeft="10dp"
android:layout_alignParentLeft="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="(SMS TO) :"
android:id="@+id/activitycomposesmsTextView1"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="(SMS TO) :"
android:id="@+id/activitycomposesmsTextView1"/>
<EditText
android:layout_width="wrap_content"
android:inputType="phone"
android:layout_height="wrap_content"
android:ems="10"
android:id="@+id/activitycomposesmsEditText1"/>
<EditText
android:layout_width="wrap_content"
android:inputType="phone"
android:layout_height="wrap_content"
android:ems="10"
android:id="@+id/activitycomposesmsEditText1"/>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
</RelativeLayout>
</LinearLayout>
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:padding="10dp"
android:layout_weight="1.0">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:padding="10dp"
android:layout_weight="1.0">
<ListView
android:layout_alignParentTop="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/activitycomposesmsinclude1"
android:id="@+id/activitycomposesmsListView1"/>
<!-- 关键修改:添加 listSelector 属性,关联选中样式 -->
<ListView
android:layout_alignParentTop="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/activitycomposesmsinclude1"
android:id="@+id/activitycomposesmsListView1"
android:listSelector="@drawable/listview_item_selector"
android:choiceMode="singleChoice"/> <!-- 开启单选模式,确保选中状态唯一 -->
<include
layout="@layout/view_smssend"
android:layout_alignParentBottom="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/activitycomposesmsinclude1"/>
<include
layout="@layout/view_smssend"
android:layout_alignParentBottom="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/activitycomposesmsinclude1"/>
</RelativeLayout>
</RelativeLayout>
</LinearLayout>

View File

@@ -1,5 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="white">#FFFFFFFF</color>
<color name="colorSMSSendColor">#FFDCDA3D</color>
<color name="colorSMSInboxColor">#FF3DDC84</color>
<color name="colorTTSRuleViewBackgroundColor">#FFDCDA3D</color>
@@ -7,11 +10,11 @@
<color name="colorSMSSendColorDepth">#FFA28BFF</color>
<color name="colorSMSInboxColorDepth">#FF8BAEFF</color>
<color name="colorTTSRuleViewBackgroundColorDepth">#FFA28BFF</color>
<color name="colorSMSSendColorSky">#FFFFEB8C</color>
<color name="colorSMSInboxColorSky">#FF8CD9FF</color>
<color name="colorTTSRuleViewBackgroundColorSky">#FFFFEB8C</color>
<color name="colorSMSSendColorGolden">#FF78BDFF</color>
<color name="colorSMSInboxColorGolden">#FFFFED78</color>
<color name="colorTTSRuleViewBackgroundColorGolden">#FF78BDFF</color>
@@ -19,9 +22,13 @@
<color name="colorSMSSendColorMemor">#FF5AEB53</color>
<color name="colorSMSInboxColorMemor">#FFE653EB</color>
<color name="colorTTSRuleViewBackgroundColorMemor">#FF5AEB53</color>
<color name="colorSMSSendColorTao">#FFB4B4B4</color>
<color name="colorSMSInboxColorTao">#FFD9D9D9</color>
<color name="colorTTSRuleViewBackgroundColorTao">#FFB4B4B4</color>
<!-- 列表项选中颜色(深灰) -->
<color name="list_item_selected">#FF696969</color>
<!-- 列表项按压颜色(浅灰) -->
<color name="list_item_pressed">#FFE0E0E0</color>
</resources>