diff --git a/app/release/SmsForwarder_release_20210304_1.4.0.apk b/app/release/SmsForwarder_release_20210304_1.4.0.apk index 18726731e5..d058e1f4b8 100644 Binary files a/app/release/SmsForwarder_release_20210304_1.4.0.apk and b/app/release/SmsForwarder_release_20210304_1.4.0.apk differ diff --git a/app/src/main/java/com/idormy/sms/forwarder/MainActivity.java b/app/src/main/java/com/idormy/sms/forwarder/MainActivity.java index 4d71fd90b1..6ee33cc82d 100644 --- a/app/src/main/java/com/idormy/sms/forwarder/MainActivity.java +++ b/app/src/main/java/com/idormy/sms/forwarder/MainActivity.java @@ -18,6 +18,7 @@ import android.view.MenuItem; import android.view.View; import android.widget.AdapterView; +import android.widget.Toast; import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AppCompatActivity; @@ -44,13 +45,25 @@ public class MainActivity extends AppCompatActivity implements ReFlashListView.I private List logVos = new ArrayList<>(); private LogAdapter adapter; private ReFlashListView listView; - //SIM卡信息 - //private Map SimInfo = new HashMap(); @Override protected void onCreate(Bundle savedInstanceState) { Log.d(TAG, "oncreate"); super.onCreate(savedInstanceState); + + //检查权限是否获取 + checkPermission(); + + //获取本机号码(注意:这里获取的不一定是卡槽1的) + TelephonyManager mTelephonyMgr = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); + String Line1Number = mTelephonyMgr.getLine1Number(); + Log.d(TAG, "Line1Number: " + Line1Number); + + //获取SIM卡信息 + getSimInfo(Line1Number); + //MyApplication appContext = ((MyApplication) getApplicationContext()); + //appContext.setSimInfo(SimInfo); + setContentView(R.layout.activity_main); LogUtil.init(this); // 先拿到数据并放在适配器上 @@ -67,18 +80,40 @@ public void onItemClick(AdapterView parent, View view, int position, long id) } }); - //检查权限是否获取 - checkPermission(); + listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { + @Override + public boolean onItemLongClick(AdapterView parent, View view, final int position, long id) { + //定义AlertDialog.Builder对象,当长按列表项的时候弹出确认删除对话框 + AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this); + builder.setMessage("确定删除?"); + builder.setTitle("提示"); + + //添加AlertDialog.Builder对象的setPositiveButton()方法 + builder.setPositiveButton("确定", new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + Long id = logVos.get(position - 1).getId(); + Log.d(TAG, "id = " + id); + LogUtil.delLog(id, null); + initTLogs(); //初始化数据 + showList(logVos); + Toast.makeText(getBaseContext(), "删除列表项", Toast.LENGTH_SHORT).show(); + } + }); - //获取本机号码(注意:这里获取的不一定是卡槽1的) - TelephonyManager mTelephonyMgr = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); - String Line1Number = mTelephonyMgr.getLine1Number(); - Log.d(TAG, "Line1Number: " + Line1Number); + //添加AlertDialog.Builder对象的setNegativeButton()方法 + builder.setNegativeButton("取消", new DialogInterface.OnClickListener() { - //获取SIM卡信息 - getSimInfo(Line1Number); - //MyApplication appContext = ((MyApplication) getApplicationContext()); - //appContext.setSimInfo(SimInfo); + @Override + public void onClick(DialogInterface dialog, int which) { + + } + }); + + builder.create().show(); + return true; + } + }); } // 初始化数据 diff --git a/app/src/main/java/com/idormy/sms/forwarder/MyApplication.java b/app/src/main/java/com/idormy/sms/forwarder/MyApplication.java index 5befe9744d..06a0906d5d 100644 --- a/app/src/main/java/com/idormy/sms/forwarder/MyApplication.java +++ b/app/src/main/java/com/idormy/sms/forwarder/MyApplication.java @@ -59,14 +59,6 @@ public static String getChannelName(Context ctx) { return channelName; } - public Map getSimInfo() { - return SimInfo; - } - - public void setSimInfo(Map info) { - SimInfo = info; - } - @Override protected void attachBaseContext(Context base) { super.attachBaseContext(base); diff --git a/app/src/main/java/com/idormy/sms/forwarder/model/RuleModel.java b/app/src/main/java/com/idormy/sms/forwarder/model/RuleModel.java index 3311fbd2f4..7edd2f41d0 100644 --- a/app/src/main/java/com/idormy/sms/forwarder/model/RuleModel.java +++ b/app/src/main/java/com/idormy/sms/forwarder/model/RuleModel.java @@ -10,21 +10,11 @@ import java.util.Map; public class RuleModel { - private String TAG = "RuleModel"; - private Long id; public static final String FILED_TRANSPOND_ALL = "transpond_all"; public static final String FILED_PHONE_NUM = "phone_num"; public static final String FILED_MSG_CONTENT = "msg_content"; - public static final String FILED_MULTI_MATCH="multi_match"; + public static final String FILED_MULTI_MATCH = "multi_match"; public static final Map FILED_MAP = new HashMap(); - static{ - FILED_MAP.put("transpond_all", "转发全部"); - FILED_MAP.put("phone_num", "手机号"); - FILED_MAP.put("msg_content", "内容"); - FILED_MAP.put("multi_match", "多重匹配"); - } - private String filed; - public static final String CHECK_IS = "is"; public static final String CHECK_CONTAIN = "contain"; public static final String CHECK_START_WITH = "startwith"; @@ -32,6 +22,13 @@ public class RuleModel { public static final String CHECK_NOT_IS = "notis"; public static final Map CHECK_MAP = new HashMap(); + static { + FILED_MAP.put("transpond_all", "转发全部"); + FILED_MAP.put("phone_num", "手机号"); + FILED_MAP.put("msg_content", "内容"); + FILED_MAP.put("multi_match", "多重匹配"); + } + static { CHECK_MAP.put("is", "是"); CHECK_MAP.put("contain", "包含"); @@ -39,6 +36,10 @@ public class RuleModel { CHECK_MAP.put("endwith", "结尾是"); CHECK_MAP.put("notis", "不是"); } + + private String TAG = "RuleModel"; + private Long id; + private String filed; private String check; private String value; @@ -46,25 +47,64 @@ public class RuleModel { private Long senderId; private Long time; + public static String getRuleMatch(String filed, String check, String value) { + switch (filed) { + case FILED_TRANSPOND_ALL: + return "全部转发到 "; + default: + return "当 " + FILED_MAP.get(filed) + " " + CHECK_MAP.get(check) + " " + value + " 转发到 "; + + } + + } + + public static String getRuleFiledFromCheckId(int id) { + switch (id) { + case R.id.btnContent: + return FILED_MSG_CONTENT; + case R.id.btnPhone: + return FILED_PHONE_NUM; + case R.id.btnMultiMatch: + return FILED_MULTI_MATCH; + default: + return FILED_TRANSPOND_ALL; + } + } + + public static String getRuleCheckFromCheckId(int id) { + switch (id) { + case R.id.btnContain: + return CHECK_CONTAIN; + case R.id.btnStartWith: + return CHECK_START_WITH; + case R.id.btnEndWith: + return CHECK_END_WITH; + case R.id.btnNotIs: + return CHECK_NOT_IS; + default: + return CHECK_IS; + } + } + //字段分支 public boolean checkMsg(SmsVo msg) throws Exception { //检查这一行和上一行合并的结果是否命中 - boolean mixChecked=false; - if(msg!=null){ + boolean mixChecked = false; + if (msg != null) { //先检查规则是否命中 - switch (this.filed){ + switch (this.filed) { case FILED_TRANSPOND_ALL: - mixChecked= true; + mixChecked = true; break; case FILED_PHONE_NUM: - mixChecked= checkValue(msg.getMobile()); + mixChecked = checkValue(msg.getMobile()); break; case FILED_MSG_CONTENT: - mixChecked= checkValue(msg.getContent()); + mixChecked = checkValue(msg.getContent()); break; case FILED_MULTI_MATCH: - mixChecked= RuleLineUtils.checkRuleLines(msg,this.value); + mixChecked = RuleLineUtils.checkRuleLines(msg, this.value); break; default: break; @@ -73,33 +113,33 @@ public boolean checkMsg(SmsVo msg) throws Exception { } - Log.i(TAG, "rule:"+this+" checkMsg:"+msg+" checked:"+mixChecked); + Log.i(TAG, "rule:" + this + " checkMsg:" + msg + " checked:" + mixChecked); return mixChecked; } //内容分支 - public boolean checkValue(String msgValue){ - boolean checked=false; + public boolean checkValue(String msgValue) { + boolean checked = false; - if(this.value!=null){ - switch (this.check){ + if (this.value != null) { + switch (this.check) { case CHECK_IS: - checked=this.value.equals(msgValue); + checked = this.value.equals(msgValue); break; case CHECK_CONTAIN: - if(msgValue!=null){ - checked=msgValue.contains(this.value); + if (msgValue != null) { + checked = msgValue.contains(this.value); } break; case CHECK_START_WITH: - if(msgValue!=null){ - checked=msgValue.startsWith(this.value); + if (msgValue != null) { + checked = msgValue.startsWith(this.value); } break; case CHECK_END_WITH: - if(msgValue!=null){ - checked=msgValue.endsWith(this.value); + if (msgValue != null) { + checked = msgValue.endsWith(this.value); } break; default: @@ -107,29 +147,18 @@ public boolean checkValue(String msgValue){ } } - Log.i(TAG, "checkValue "+msgValue+" "+this.check+" "+this.value+" checked:"+checked); + Log.i(TAG, "checkValue " + msgValue + " " + this.check + " " + this.value + " checked:" + checked); return checked; } - public String getRuleMatch() { - switch (filed){ - case FILED_TRANSPOND_ALL: - return "全部转发到 "; - default: - return "当 "+FILED_MAP.get(filed)+" "+CHECK_MAP.get(check)+" "+value+" 转发到 "; - } - - } - public static String getRuleMatch(String filed, String check, String value) { switch (filed) { case FILED_TRANSPOND_ALL: return "全部转发到 "; default: return "当 " + FILED_MAP.get(filed) + " " + CHECK_MAP.get(check) + " " + value + " 转发到 "; - } } @@ -138,8 +167,8 @@ public Long getRuleSenderId() { return senderId; } - public int getRuleFiledCheckId(){ - switch (filed){ + public int getRuleFiledCheckId() { + switch (filed) { case FILED_MSG_CONTENT: return R.id.btnContent; case FILED_PHONE_NUM: @@ -151,21 +180,8 @@ public int getRuleFiledCheckId(){ } } - public static String getRuleFiledFromCheckId(int id){ - switch (id){ - case R.id.btnContent: - return FILED_MSG_CONTENT; - case R.id.btnPhone: - return FILED_PHONE_NUM; - case R.id.btnMultiMatch: - return FILED_MULTI_MATCH; - default: - return FILED_TRANSPOND_ALL; - } - } - - public int getRuleCheckCheckId(){ - switch (check){ + public int getRuleCheckCheckId() { + switch (check) { case CHECK_CONTAIN: return R.id.btnContain; case CHECK_START_WITH: @@ -179,21 +195,6 @@ public int getRuleCheckCheckId(){ } } - public static String getRuleCheckFromCheckId(int id){ - switch (id){ - case R.id.btnContain: - return CHECK_CONTAIN; - case R.id.btnStartWith: - return CHECK_START_WITH; - case R.id.btnEndWith: - return CHECK_END_WITH; - case R.id.btnNotIs: - return CHECK_NOT_IS; - default: - return CHECK_IS; - } - } - public Long getId() { return id; } diff --git a/app/src/main/java/com/idormy/sms/forwarder/model/vo/LogVo.java b/app/src/main/java/com/idormy/sms/forwarder/model/vo/LogVo.java index 8212e3b045..56cb3b19aa 100644 --- a/app/src/main/java/com/idormy/sms/forwarder/model/vo/LogVo.java +++ b/app/src/main/java/com/idormy/sms/forwarder/model/vo/LogVo.java @@ -3,6 +3,7 @@ import com.idormy.sms.forwarder.R; public class LogVo { + private Long id; private String from; private String content; private String simInfo; @@ -10,7 +11,8 @@ public class LogVo { private int senderImageId; private String time; - public LogVo(String from, String content, String simInfo, String time, String rule, int senderImageId) { + public LogVo(Long id, String from, String content, String simInfo, String time, String rule, int senderImageId) { + this.id = id; this.from = from; this.content = content; this.simInfo = simInfo; @@ -23,6 +25,10 @@ public LogVo() { } + public Long getId() { + return id; + } + public String getFrom() { return from; } diff --git a/app/src/main/java/com/idormy/sms/forwarder/utils/LogUtil.java b/app/src/main/java/com/idormy/sms/forwarder/utils/LogUtil.java index 514d8c7548..7e10f9912e 100644 --- a/app/src/main/java/com/idormy/sms/forwarder/utils/LogUtil.java +++ b/app/src/main/java/com/idormy/sms/forwarder/utils/LogUtil.java @@ -141,6 +141,8 @@ public static List getLog(Long id, String key) { Log.d(TAG, "getLog: itemId cursor" + Arrays.toString(cursor.getColumnNames())); while (cursor.moveToNext()) { try { + Long itemid = cursor.getLong( + cursor.getColumnIndexOrThrow(BaseColumns._ID)); String itemfrom = cursor.getString( cursor.getColumnIndexOrThrow(LogTable.LogEntry.COLUMN_NAME_FROM)); String content = cursor.getString( @@ -163,7 +165,7 @@ public static List getLog(Long id, String key) { String rule = RuleModel.getRuleMatch(ruleFiled, ruleCheck, ruleValue) + senderName; int senderImageId = SenderModel.getImageId(senderType); - LogVo logVo = new LogVo(itemfrom, content, simInfo, time, rule, senderImageId); + LogVo logVo = new LogVo(itemid, itemfrom, content, simInfo, time, rule, senderImageId); LogVos.add(logVo); } catch (Exception e) { Log.i(TAG, "getLog e:" + e.getMessage()); diff --git a/app/src/main/java/com/idormy/sms/forwarder/utils/RuleLine.java b/app/src/main/java/com/idormy/sms/forwarder/utils/RuleLine.java index 69dc10516f..15c1d07c80 100644 --- a/app/src/main/java/com/idormy/sms/forwarder/utils/RuleLine.java +++ b/app/src/main/java/com/idormy/sms/forwarder/utils/RuleLine.java @@ -9,20 +9,22 @@ import java.util.List; class RuleLine { - static String TAG = "RuleLine"; - static Boolean STARTLOG = true; - - //开头有几个空格 - int headSpaceNum = 0; - RuleLine beforeRuleLine; - RuleLine nextRuleLine; - RuleLine parentRuleLine; - RuleLine childRuleLine; - //and or - String conjunction; - public static List CONJUNCTION_LIST = new ArrayList(); public static final String CONJUNCTION_AND = "并且"; public static final String CONJUNCTION_OR = "或者"; + public static final String FILED_PHONE_NUM = "手机号"; + public static final String FILED_MSG_CONTENT = "短信内容"; + public static final String SURE_YES = "是"; + public static final String SURE_NOT = "不是"; + public static final String CHECK_EQUALS = "相等"; + public static final String CHECK_CONTAIN = "包含"; + public static final String CHECK_START_WITH = "开头"; + public static final String CHECK_END_WITH = "结尾"; + public static List CONJUNCTION_LIST = new ArrayList(); + public static List FILED_LIST = new ArrayList(); + public static List SURE_LIST = new ArrayList(); + public static List CHECK_LIST = new ArrayList(); + static String TAG = "RuleLine"; + static Boolean STARTLOG = true; static { CONJUNCTION_LIST.add("and"); @@ -31,35 +33,16 @@ class RuleLine { CONJUNCTION_LIST.add("或者"); } - //手机号 短信内容 - String field; - public static List FILED_LIST = new ArrayList(); - public static final String FILED_PHONE_NUM = "手机号"; - public static final String FILED_MSG_CONTENT = "短信内容"; - static { FILED_LIST.add("手机号"); FILED_LIST.add("短信内容"); } - // 是否 - String sure; - public static List SURE_LIST = new ArrayList(); - public static final String SURE_YES = "是"; - public static final String SURE_NOT = "不是"; - static { SURE_LIST.add("是"); SURE_LIST.add("不是"); } - String check; - public static List CHECK_LIST = new ArrayList(); - public static final String CHECK_EQUALS = "相等"; - public static final String CHECK_CONTAIN = "包含"; - public static final String CHECK_START_WITH = "开头"; - public static final String CHECK_END_WITH = "结尾"; - static { CHECK_LIST.add("相等"); CHECK_LIST.add("包含"); @@ -67,78 +50,21 @@ class RuleLine { CHECK_LIST.add("结尾"); } + //开头有几个空格 + int headSpaceNum = 0; + RuleLine beforeRuleLine; + RuleLine nextRuleLine; + RuleLine parentRuleLine; + RuleLine childRuleLine; + //and or + String conjunction; + //手机号 短信内容 + String field; + // 是否 + String sure; + String check; String value; - //字段分支 - public boolean checkMsg(SmsVo msg) { - - //检查这一行和上一行合并的结果是否命中 - boolean mixChecked = false; - - //先检查规则是否命中 - switch (this.field) { - case FILED_PHONE_NUM: - mixChecked = checkValue(msg.getMobile()); - break; - case FILED_MSG_CONTENT: - mixChecked = checkValue(msg.getContent()); - break; - default: - break; - - } - - //整合肯定词 - switch (this.sure) { - case SURE_YES: - mixChecked = mixChecked; - break; - case SURE_NOT: - mixChecked = !mixChecked; - break; - default: - mixChecked = false; - break; - - } - - logg("rule:" + this + " checkMsg:" + msg + " checked:" + mixChecked); - return mixChecked; - - } - - //内容分支 - public boolean checkValue(String msgValue) { - boolean checked = false; - - switch (this.check) { - case CHECK_EQUALS: - checked = this.value.equals(msgValue); - break; - case CHECK_CONTAIN: - if (msgValue != null) { - checked = msgValue.contains(this.value); - } - break; - case CHECK_START_WITH: - if (msgValue != null) { - checked = msgValue.startsWith(this.value); - } - break; - case CHECK_END_WITH: - if (msgValue != null) { - checked = msgValue.endsWith(this.value); - } - break; - default: - break; - } - logg("checkValue " + msgValue + " " + this.check + " " + this.value + " checked:" + checked); - - return checked; - - } - public RuleLine(String line, int linenum, RuleLine beforeRuleLine) throws Exception { logg("----------" + linenum + "-----------------"); logg(line); @@ -328,6 +254,76 @@ public static void logg(String msg) { } + //字段分支 + public boolean checkMsg(SmsVo msg) { + + //检查这一行和上一行合并的结果是否命中 + boolean mixChecked = false; + + //先检查规则是否命中 + switch (this.field) { + case FILED_PHONE_NUM: + mixChecked = checkValue(msg.getMobile()); + break; + case FILED_MSG_CONTENT: + mixChecked = checkValue(msg.getContent()); + break; + default: + break; + + } + + //整合肯定词 + switch (this.sure) { + case SURE_YES: + mixChecked = mixChecked; + break; + case SURE_NOT: + mixChecked = !mixChecked; + break; + default: + mixChecked = false; + break; + + } + + logg("rule:" + this + " checkMsg:" + msg + " checked:" + mixChecked); + return mixChecked; + + } + + //内容分支 + public boolean checkValue(String msgValue) { + boolean checked = false; + + switch (this.check) { + case CHECK_EQUALS: + checked = this.value.equals(msgValue); + break; + case CHECK_CONTAIN: + if (msgValue != null) { + checked = msgValue.contains(this.value); + } + break; + case CHECK_START_WITH: + if (msgValue != null) { + checked = msgValue.startsWith(this.value); + } + break; + case CHECK_END_WITH: + if (msgValue != null) { + checked = msgValue.endsWith(this.value); + } + break; + default: + break; + } + logg("checkValue " + msgValue + " " + this.check + " " + this.value + " checked:" + checked); + + return checked; + + } + @Override public String toString() { return "RuleLine{" + diff --git a/app/src/main/java/com/idormy/sms/forwarder/utils/SettingUtil.java b/app/src/main/java/com/idormy/sms/forwarder/utils/SettingUtil.java index 5c7aaa1411..f854eea1c2 100644 --- a/app/src/main/java/com/idormy/sms/forwarder/utils/SettingUtil.java +++ b/app/src/main/java/com/idormy/sms/forwarder/utils/SettingUtil.java @@ -6,9 +6,8 @@ import android.util.Log; public class SettingUtil { - private static String TAG = "SettingUtil"; - static Boolean hasInit = false; + private static String TAG = "SettingUtil"; private static SharedPreferences sp_setting = null; private static Context context = null; diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 1c7dfc3cfe..156d5fb9c2 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -15,47 +15,59 @@ + android:orientation="vertical"> -