Merge pull request #103 from Naccl/main

优化:自定义模板
This commit is contained in:
pppscn 2022-01-14 16:00:50 +08:00 committed by GitHub
commit a2999a2ade
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 12 deletions

View File

@ -374,49 +374,49 @@ public class RuleActivity extends AppCompatActivity {
buttonInsertSender.setOnClickListener(view -> {
textSmsTemplate.setFocusable(true);
textSmsTemplate.requestFocus();
textSmsTemplate.append("{{来源号码}}");
insertOrReplaceText2Cursor(textSmsTemplate, "{{来源号码}}");
});
Button buttonInsertContent = view1.findViewById(R.id.bt_insert_content);
buttonInsertContent.setOnClickListener(view -> {
textSmsTemplate.setFocusable(true);
textSmsTemplate.requestFocus();
textSmsTemplate.append("{{短信内容}}");
insertOrReplaceText2Cursor(textSmsTemplate, "{{短信内容}}");
});
Button buttonInsertSenderApp = view1.findViewById(R.id.bt_insert_sender_app);
buttonInsertSenderApp.setOnClickListener(view -> {
textSmsTemplate.setFocusable(true);
textSmsTemplate.requestFocus();
textSmsTemplate.append("{{APP包名}}");
insertOrReplaceText2Cursor(textSmsTemplate, "{{APP包名}}");
});
Button buttonInsertContentApp = view1.findViewById(R.id.bt_insert_content_app);
buttonInsertContentApp.setOnClickListener(view -> {
textSmsTemplate.setFocusable(true);
textSmsTemplate.requestFocus();
textSmsTemplate.append("{{通知内容}}");
insertOrReplaceText2Cursor(textSmsTemplate, "{{通知内容}}");
});
Button buttonInsertExtra = view1.findViewById(R.id.bt_insert_extra);
buttonInsertExtra.setOnClickListener(view -> {
textSmsTemplate.setFocusable(true);
textSmsTemplate.requestFocus();
textSmsTemplate.append("{{卡槽信息}}");
insertOrReplaceText2Cursor(textSmsTemplate, "{{卡槽信息}}");
});
Button buttonInsertTime = view1.findViewById(R.id.bt_insert_time);
buttonInsertTime.setOnClickListener(view -> {
textSmsTemplate.setFocusable(true);
textSmsTemplate.requestFocus();
textSmsTemplate.append("{{接收时间}}");
insertOrReplaceText2Cursor(textSmsTemplate, "{{接收时间}}");
});
Button buttonInsertDeviceName = view1.findViewById(R.id.bt_insert_device_name);
buttonInsertDeviceName.setOnClickListener(view -> {
textSmsTemplate.setFocusable(true);
textSmsTemplate.requestFocus();
textSmsTemplate.append("{{设备名称}}");
insertOrReplaceText2Cursor(textSmsTemplate, "{{设备名称}}");
});
//正则替换
@ -433,6 +433,12 @@ public class RuleActivity extends AppCompatActivity {
}
private void insertOrReplaceText2Cursor(EditText editText, String str) {
int start = Math.max(editText.getSelectionStart(), 0);
int end = Math.max(editText.getSelectionEnd(), 0);
editText.getText().replace(Math.min(start, end), Math.max(start, end), str, 0, str.length());
}
//当更新选择的字段的时候更新之下各个选项的状态
// 如果设置了转发全部禁用选择模式和匹配值输入
// 如果设置了多重规则选择模式置为是

View File

@ -356,24 +356,30 @@ public class SettingActivity extends AppCompatActivity {
textSmsTemplate.requestFocus();
switch (v.getId()) {
case R.id.bt_insert_sender:
textSmsTemplate.append("{{来源号码}}");
insertOrReplaceText2Cursor(textSmsTemplate, "{{来源号码}}");
return;
case R.id.bt_insert_content:
textSmsTemplate.append("{{短信内容}}");
insertOrReplaceText2Cursor(textSmsTemplate, "{{短信内容}}");
return;
case R.id.bt_insert_extra:
textSmsTemplate.append("{{卡槽信息}}");
insertOrReplaceText2Cursor(textSmsTemplate, "{{卡槽信息}}");
return;
case R.id.bt_insert_time:
textSmsTemplate.append("{{接收时间}}");
insertOrReplaceText2Cursor(textSmsTemplate, "{{接收时间}}");
return;
case R.id.bt_insert_device_name:
textSmsTemplate.append("{{设备名称}}");
insertOrReplaceText2Cursor(textSmsTemplate, "{{设备名称}}");
return;
default:
}
}
private void insertOrReplaceText2Cursor(EditText editText, String str) {
int start = Math.max(editText.getSelectionStart(), 0);
int end = Math.max(editText.getSelectionEnd(), 0);
editText.getText().replace(Math.min(start, end), Math.max(start, end), str, 0, str.length());
}
//恢复初始化配置
public void initSetting(View view) {