├── .classpath ├── .gitignore ├── .project ├── .settings ├── org.eclipse.core.resources.prefs └── org.eclipse.jdt.core.prefs ├── AlertSystem.iml ├── AndroidManifest.xml ├── README.md ├── assets └── alert-data-sample.txt ├── ic_launcher-web.png ├── libs ├── android-support-v4.jar └── umeng_sdk.jar ├── license ├── lint.xml ├── proguard-project.txt ├── project.properties ├── res ├── drawable-hdpi │ ├── back.png │ ├── button_above_more.png │ ├── button_above_showmenu.9.png │ ├── detail.png │ ├── done.png │ ├── ic_launcher_xsms.png │ ├── ic_list_remove.png │ ├── remove.png │ └── trash.png ├── drawable-xhdpi │ ├── all_bg.png │ ├── all_setting_list_bottom_bg.9.png │ ├── all_setting_list_bottom_bg_2.9.png │ ├── all_setting_list_center_bg.9.png │ ├── all_setting_list_center_bg_2.9.png │ ├── all_setting_list_only_bg.9.png │ ├── all_setting_list_only_bg_2.9.png │ ├── all_setting_list_top_bg.9.png │ ├── all_setting_list_top_bg_2.9.png │ ├── all_top_new_bg.9.png │ ├── all_top_transparent_bg.9.png │ ├── ic_launcher_xsms.png │ ├── ic_list_remove.png │ ├── namecard_info_not_verified.png │ ├── namecard_info_verified.png │ ├── smiley_tab_mao_pressed.png │ ├── tab_bottom_icon_address_book.png │ ├── tab_bottom_icon_address_book_2.png │ └── tab_bottom_new_bg.9.png ├── drawable │ ├── back_above_menushow_style.xml │ ├── background_tab.xml │ ├── border.xml │ ├── color_b_pressed_a.xml │ ├── color_d_pressed_a.xml │ ├── color_e_pressed_a.xml │ ├── ic_launcher_xsms.png │ ├── list_bottom_bg.xml │ ├── list_center_bg.xml │ ├── list_sole_bg.xml │ ├── list_top_bg.xml │ ├── tab_bg.xml │ └── tab_icon_friends.xml ├── layout │ ├── about.xml │ ├── add_phone_number.xml │ ├── add_rules_dialog.xml │ ├── common_listview.xml │ ├── content_activity.xml │ ├── level_activity_layout.xml │ ├── level_list_layout.xml │ ├── logo.xml │ ├── main.xml │ ├── main_activity_tab.xml │ ├── main_list_layout.xml │ ├── phone_list_item.xml │ ├── phone_number_layout.xml │ ├── setting_activity.xml │ ├── sms_notify_item.xml │ ├── sms_rules_layout.xml │ ├── tab_host.xml │ ├── thread_activity_layout.xml │ ├── title_bar.xml │ └── usage.xml ├── values-v11 │ └── styles.xml ├── values-v14 │ └── styles.xml ├── values │ ├── arrays.xml │ ├── attrs.xml │ ├── colors.xml │ ├── strings.xml │ └── styles.xml └── xml │ └── alert.xml └── src └── com ├── astuetz └── viewpager │ └── extensions │ └── PagerSlidingTabStrip.java └── xiaomi └── alertsystem ├── AlertSystemApplication.java ├── data ├── AlertItem.java ├── AlertManager.java ├── AlertMeta.java ├── Constants.java ├── NotifyMeta.java └── Sms.java ├── ui ├── AboutActivity.java ├── AlertContentActivity.java ├── AlertLevelAdapter.java ├── AlertLevelFragment.java ├── AlertMainlAdapter.java ├── AlertThreadActivity.java ├── AlertThreadAdapter.java ├── BaseActivity.java ├── LogoActivity.java ├── MainActivity.java ├── PhoneAdapter.java ├── PhoneNumberActivity.java ├── PrefActivity.java ├── SettingActivity.java ├── SmsNotifyAdapter.java ├── SmsRulesActivity.java └── UsageActivity.java └── utils ├── AlertSystemDBHelper.java ├── AsyncTaskUtils.java ├── BootReceiver.java ├── CommonUtils.java ├── HandleSmsIntentService.java ├── NotificationUtils.java ├── ReadFileContent.java ├── ReadLocalSmsHelper.java ├── SmsBroadcastReceiver.java ├── SmsManager.java └── ThreadUpdateApp.java /.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.swp 2 | out/ 3 | .idea/ 4 | app_key 5 | ./bin/ 6 | ./gen/ 7 | -------------------------------------------------------------------------------- /.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | AlertSystem 4 | 5 | 6 | 7 | 8 | 9 | com.android.ide.eclipse.adt.ResourceManagerBuilder 10 | 11 | 12 | 13 | 14 | com.android.ide.eclipse.adt.PreCompilerBuilder 15 | 16 | 17 | 18 | 19 | org.eclipse.jdt.core.javabuilder 20 | 21 | 22 | 23 | 24 | com.android.ide.eclipse.adt.ApkBuilder 25 | 26 | 27 | 28 | 29 | 30 | com.android.ide.eclipse.adt.AndroidNature 31 | org.eclipse.jdt.core.javanature 32 | 33 | 34 | -------------------------------------------------------------------------------- /.settings/org.eclipse.core.resources.prefs: -------------------------------------------------------------------------------- 1 | #Sun May 12 23:08:39 CST 2013 2 | eclipse.preferences.version=1 3 | encoding/=UTF-8 4 | -------------------------------------------------------------------------------- /.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 3 | org.eclipse.jdt.core.compiler.compliance=1.6 4 | org.eclipse.jdt.core.compiler.source=1.6 5 | -------------------------------------------------------------------------------- /AlertSystem.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | MANIFEST_FILE_PATH 8 | RESOURCES_DIR_PATH 9 | ASSETS_DIR_PATH 10 | NATIVE_LIBS_DIR_PATH 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 40 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 56 | 57 | 61 | 62 | 66 | 67 | 71 | 72 | 73 | 76 | 77 | 78 | 82 | 83 | 87 | 88 | 92 | 93 | 97 | 98 | 102 | 103 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 121 | 122 | 125 | 126 | 127 | 128 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | #报警助手 2 | ##介绍: 3 | 报警助手是小米运维不开发的针对运维人员的一款短信报警处理软件。运维人员每天会处理大量短信报警,经常会有漏报警,报警处理不及时,不重要短信频频打扰我们生活的问题。报警助手对报警进行拦截,实行分级别管理,对不同基本报警,采用不同的处理和提醒方式,让你能够高效准确的处理报警,节省更多的时间投入到工作、学习、及家庭中。 4 | ##短信格式: 5 | **[P0][PROBLEM][hostname][host_ip][host is down]** 6 | 7 | ######各个字段解释 8 | - 字段1:告警级别,可以是P0, P1, P2 ... ,其中P0级别最高 9 | - 字段2:告警标志,可以是PROBLEM 或者OK,前者标明故障发生,后者标明故障恢复 10 | - 字段3:机器名,标明是哪台机器发生了告警 11 | - 字段4:机器IP,同字段3 12 | - 字段5:告警的具体内容 13 | 14 | ##下载地址: 15 | 在小米应用商城里面,搜索"报警助手",下载即可。如果担心应用风险或者有定制化需求,可以到github上下载源代码进行二次开发,地址:https://github.com/xiaomi-sa/alertsystem。 16 | ##开发者: 17 | 本应用有小米运维部开发,博客:http://noops.me. 有问题可以联系: jingyuan@xiaomi.com、panxiaodong@xiaomi.com或者laiwei@xiaomi.com 18 | -------------------------------------------------------------------------------- /ic_launcher-web.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaomi-sa/alertsystem/f398b7f2cd307ffdd35df5db6412e76dd165b2ba/ic_launcher-web.png -------------------------------------------------------------------------------- /libs/android-support-v4.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaomi-sa/alertsystem/f398b7f2cd307ffdd35df5db6412e76dd165b2ba/libs/android-support-v4.jar -------------------------------------------------------------------------------- /libs/umeng_sdk.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaomi-sa/alertsystem/f398b7f2cd307ffdd35df5db6412e76dd165b2ba/libs/umeng_sdk.jar -------------------------------------------------------------------------------- /license: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | -------------------------------------------------------------------------------- /lint.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /proguard-project.txt: -------------------------------------------------------------------------------- 1 | # To enable ProGuard in your project, edit project.properties 2 | # to define the proguard.config property as described in that file. 3 | # 4 | # Add project specific ProGuard rules here. 5 | # By default, the flags in this file are appended to flags specified 6 | # in ${sdk.dir}/tools/proguard/proguard-android.txt 7 | # You can edit the include path and order by changing the ProGuard 8 | # include property in project.properties. 9 | # 10 | # For more details, see 11 | # http://developer.android.com/guide/developing/tools/proguard.html 12 | 13 | # Add any project specific keep options here: 14 | 15 | # If your project uses WebView with JS, uncomment the following 16 | # and specify the fully qualified class name to the JavaScript interface 17 | # class: 18 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 19 | # public *; 20 | #} 21 | -------------------------------------------------------------------------------- /project.properties: -------------------------------------------------------------------------------- 1 | # This file is automatically generated by Android Tools. 2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED! 3 | # 4 | # This file must be checked in Version Control Systems. 5 | # 6 | # To customize properties used by the Ant build system edit 7 | # "ant.properties", and override values to adapt the script to your 8 | # project structure. 9 | # 10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home): 11 | #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt 12 | 13 | # Project target. 14 | target=android-16 15 | -------------------------------------------------------------------------------- /res/drawable-hdpi/back.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaomi-sa/alertsystem/f398b7f2cd307ffdd35df5db6412e76dd165b2ba/res/drawable-hdpi/back.png -------------------------------------------------------------------------------- /res/drawable-hdpi/button_above_more.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaomi-sa/alertsystem/f398b7f2cd307ffdd35df5db6412e76dd165b2ba/res/drawable-hdpi/button_above_more.png -------------------------------------------------------------------------------- /res/drawable-hdpi/button_above_showmenu.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaomi-sa/alertsystem/f398b7f2cd307ffdd35df5db6412e76dd165b2ba/res/drawable-hdpi/button_above_showmenu.9.png -------------------------------------------------------------------------------- /res/drawable-hdpi/detail.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaomi-sa/alertsystem/f398b7f2cd307ffdd35df5db6412e76dd165b2ba/res/drawable-hdpi/detail.png -------------------------------------------------------------------------------- /res/drawable-hdpi/done.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaomi-sa/alertsystem/f398b7f2cd307ffdd35df5db6412e76dd165b2ba/res/drawable-hdpi/done.png -------------------------------------------------------------------------------- /res/drawable-hdpi/ic_launcher_xsms.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaomi-sa/alertsystem/f398b7f2cd307ffdd35df5db6412e76dd165b2ba/res/drawable-hdpi/ic_launcher_xsms.png -------------------------------------------------------------------------------- /res/drawable-hdpi/ic_list_remove.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaomi-sa/alertsystem/f398b7f2cd307ffdd35df5db6412e76dd165b2ba/res/drawable-hdpi/ic_list_remove.png -------------------------------------------------------------------------------- /res/drawable-hdpi/remove.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaomi-sa/alertsystem/f398b7f2cd307ffdd35df5db6412e76dd165b2ba/res/drawable-hdpi/remove.png -------------------------------------------------------------------------------- /res/drawable-hdpi/trash.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaomi-sa/alertsystem/f398b7f2cd307ffdd35df5db6412e76dd165b2ba/res/drawable-hdpi/trash.png -------------------------------------------------------------------------------- /res/drawable-xhdpi/all_bg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaomi-sa/alertsystem/f398b7f2cd307ffdd35df5db6412e76dd165b2ba/res/drawable-xhdpi/all_bg.png -------------------------------------------------------------------------------- /res/drawable-xhdpi/all_setting_list_bottom_bg.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaomi-sa/alertsystem/f398b7f2cd307ffdd35df5db6412e76dd165b2ba/res/drawable-xhdpi/all_setting_list_bottom_bg.9.png -------------------------------------------------------------------------------- /res/drawable-xhdpi/all_setting_list_bottom_bg_2.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaomi-sa/alertsystem/f398b7f2cd307ffdd35df5db6412e76dd165b2ba/res/drawable-xhdpi/all_setting_list_bottom_bg_2.9.png -------------------------------------------------------------------------------- /res/drawable-xhdpi/all_setting_list_center_bg.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaomi-sa/alertsystem/f398b7f2cd307ffdd35df5db6412e76dd165b2ba/res/drawable-xhdpi/all_setting_list_center_bg.9.png -------------------------------------------------------------------------------- /res/drawable-xhdpi/all_setting_list_center_bg_2.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaomi-sa/alertsystem/f398b7f2cd307ffdd35df5db6412e76dd165b2ba/res/drawable-xhdpi/all_setting_list_center_bg_2.9.png -------------------------------------------------------------------------------- /res/drawable-xhdpi/all_setting_list_only_bg.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaomi-sa/alertsystem/f398b7f2cd307ffdd35df5db6412e76dd165b2ba/res/drawable-xhdpi/all_setting_list_only_bg.9.png -------------------------------------------------------------------------------- /res/drawable-xhdpi/all_setting_list_only_bg_2.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaomi-sa/alertsystem/f398b7f2cd307ffdd35df5db6412e76dd165b2ba/res/drawable-xhdpi/all_setting_list_only_bg_2.9.png -------------------------------------------------------------------------------- /res/drawable-xhdpi/all_setting_list_top_bg.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaomi-sa/alertsystem/f398b7f2cd307ffdd35df5db6412e76dd165b2ba/res/drawable-xhdpi/all_setting_list_top_bg.9.png -------------------------------------------------------------------------------- /res/drawable-xhdpi/all_setting_list_top_bg_2.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaomi-sa/alertsystem/f398b7f2cd307ffdd35df5db6412e76dd165b2ba/res/drawable-xhdpi/all_setting_list_top_bg_2.9.png -------------------------------------------------------------------------------- /res/drawable-xhdpi/all_top_new_bg.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaomi-sa/alertsystem/f398b7f2cd307ffdd35df5db6412e76dd165b2ba/res/drawable-xhdpi/all_top_new_bg.9.png -------------------------------------------------------------------------------- /res/drawable-xhdpi/all_top_transparent_bg.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaomi-sa/alertsystem/f398b7f2cd307ffdd35df5db6412e76dd165b2ba/res/drawable-xhdpi/all_top_transparent_bg.9.png -------------------------------------------------------------------------------- /res/drawable-xhdpi/ic_launcher_xsms.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaomi-sa/alertsystem/f398b7f2cd307ffdd35df5db6412e76dd165b2ba/res/drawable-xhdpi/ic_launcher_xsms.png -------------------------------------------------------------------------------- /res/drawable-xhdpi/ic_list_remove.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaomi-sa/alertsystem/f398b7f2cd307ffdd35df5db6412e76dd165b2ba/res/drawable-xhdpi/ic_list_remove.png -------------------------------------------------------------------------------- /res/drawable-xhdpi/namecard_info_not_verified.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaomi-sa/alertsystem/f398b7f2cd307ffdd35df5db6412e76dd165b2ba/res/drawable-xhdpi/namecard_info_not_verified.png -------------------------------------------------------------------------------- /res/drawable-xhdpi/namecard_info_verified.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaomi-sa/alertsystem/f398b7f2cd307ffdd35df5db6412e76dd165b2ba/res/drawable-xhdpi/namecard_info_verified.png -------------------------------------------------------------------------------- /res/drawable-xhdpi/smiley_tab_mao_pressed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaomi-sa/alertsystem/f398b7f2cd307ffdd35df5db6412e76dd165b2ba/res/drawable-xhdpi/smiley_tab_mao_pressed.png -------------------------------------------------------------------------------- /res/drawable-xhdpi/tab_bottom_icon_address_book.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaomi-sa/alertsystem/f398b7f2cd307ffdd35df5db6412e76dd165b2ba/res/drawable-xhdpi/tab_bottom_icon_address_book.png -------------------------------------------------------------------------------- /res/drawable-xhdpi/tab_bottom_icon_address_book_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaomi-sa/alertsystem/f398b7f2cd307ffdd35df5db6412e76dd165b2ba/res/drawable-xhdpi/tab_bottom_icon_address_book_2.png -------------------------------------------------------------------------------- /res/drawable-xhdpi/tab_bottom_new_bg.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaomi-sa/alertsystem/f398b7f2cd307ffdd35df5db6412e76dd165b2ba/res/drawable-xhdpi/tab_bottom_new_bg.9.png -------------------------------------------------------------------------------- /res/drawable/back_above_menushow_style.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /res/drawable/background_tab.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /res/drawable/border.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /res/drawable/color_b_pressed_a.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /res/drawable/color_d_pressed_a.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /res/drawable/color_e_pressed_a.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /res/drawable/ic_launcher_xsms.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaomi-sa/alertsystem/f398b7f2cd307ffdd35df5db6412e76dd165b2ba/res/drawable/ic_launcher_xsms.png -------------------------------------------------------------------------------- /res/drawable/list_bottom_bg.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /res/drawable/list_center_bg.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /res/drawable/list_sole_bg.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /res/drawable/list_top_bg.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /res/drawable/tab_bg.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /res/drawable/tab_icon_friends.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /res/layout/about.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 14 | 15 | 27 | 28 | 35 | 36 | 48 | 49 | 50 | 53 | 54 | 59 | 60 | 61 | 62 | 68 | 69 | 75 | 76 | 79 | 80 | 83 | 84 | 90 | 91 | 98 | 99 | 102 | 103 | 104 | 105 | -------------------------------------------------------------------------------- /res/layout/add_phone_number.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 21 | 22 | -------------------------------------------------------------------------------- /res/layout/add_rules_dialog.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 12 | 13 | 20 | 21 | 26 | 27 | 28 | 32 | 33 | 40 | 41 | 46 | 47 | 48 | 52 | 53 | 60 | 61 | 67 | 68 | 69 | 73 | 74 | 81 | 82 | 88 | 89 | 90 | 94 | 95 | 102 | 103 | 109 | 110 | 111 | 115 | 116 | 123 | 124 | 130 | 131 | 132 | 136 | 137 | 144 | 145 | 151 | 152 | 153 | -------------------------------------------------------------------------------- /res/layout/common_listview.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /res/layout/content_activity.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 14 | 15 | 27 | 28 | 35 | 36 | 37 | 40 | 41 | 45 | 46 | 55 | 56 | 62 | 63 | 70 | 71 | 72 | 80 | 81 | 87 | 88 | 95 | 96 | 97 | 105 | 106 | 112 | 113 | 120 | 121 | 122 | 130 | 131 | 137 | 138 | 145 | 146 | 147 | 155 | 156 | 162 | 163 | 171 | 172 | 173 | 181 | 182 | 188 | 189 | 196 | 197 | 198 | 206 | 207 | 213 | 214 | 221 | 222 | 223 | 224 | 225 | -------------------------------------------------------------------------------- /res/layout/level_activity_layout.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /res/layout/level_list_layout.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 16 | 17 | 25 | 26 | -------------------------------------------------------------------------------- /res/layout/logo.xml: -------------------------------------------------------------------------------- 1 | 6 | 7 | 14 | 15 | 24 | 25 | 34 | 35 | 44 | 45 | 55 | 56 | -------------------------------------------------------------------------------- /res/layout/main.xml: -------------------------------------------------------------------------------- 1 | 7 | 8 | 9 | 13 | 14 | 25 | 26 | 36 | 37 | 49 | 50 | 51 | 56 | 57 | 63 | 64 | -------------------------------------------------------------------------------- /res/layout/main_activity_tab.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 17 | 18 | 25 | 26 | 34 | 35 | 40 | -------------------------------------------------------------------------------- /res/layout/main_list_layout.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 15 | 16 | 24 | 25 | 36 | 37 | 46 | 47 | 58 | 59 | 60 | 64 | 65 | 74 | 75 | 79 | 80 | 88 | 89 | 90 | 99 | 100 | 101 | 107 | 108 | 109 | -------------------------------------------------------------------------------- /res/layout/phone_list_item.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 18 | 19 | 25 | 26 | -------------------------------------------------------------------------------- /res/layout/phone_number_layout.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 14 | 15 | 27 | 28 | 35 | 36 | 37 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /res/layout/sms_notify_item.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 17 | 18 | 28 | 29 | 36 | 37 | -------------------------------------------------------------------------------- /res/layout/sms_rules_layout.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 14 | 15 | 27 | 28 | 35 | 36 | 48 | 49 | 50 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /res/layout/tab_host.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 11 | 12 | 16 | 17 | 22 | 23 | 30 | 31 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /res/layout/thread_activity_layout.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 13 | 14 | 26 | 27 | 34 | 35 | 47 | 48 | 49 | 61 | 62 | 63 | -------------------------------------------------------------------------------- /res/layout/title_bar.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 15 | 16 | 20 | 21 | 28 | 29 | 39 | 40 | 41 | 42 | 49 | 50 | 53 | 54 | 63 | 64 | 71 | 72 | 73 | 83 | 84 | 85 | 91 | 92 | 97 | 98 | 106 | 107 | 108 | 109 | -------------------------------------------------------------------------------- /res/layout/usage.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 14 | 15 | 27 | 28 | 35 | 36 | 48 | 49 | 50 | 53 | 54 | 59 | 60 | 61 | 62 | 68 | 69 | 75 | 76 | 79 | 80 | 83 | 84 | 87 | 88 | 91 | 92 | 95 | 96 | 102 | 103 | 106 | 107 | 110 | 111 | 114 | 115 | 121 | 122 | 129 | 130 | 133 | 134 | 135 | 136 | -------------------------------------------------------------------------------- /res/values-v11/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 10 | 11 | -------------------------------------------------------------------------------- /res/values-v14/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 11 | 12 | -------------------------------------------------------------------------------- /res/values/arrays.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | P 6 | P0 7 | P1 8 | P2 9 | P3 10 | P4 11 | P5 12 | P6 13 | 14 | 15 | 全部 16 | P0级 17 | P1级 18 | P2级 19 | P3级 20 | P4级 21 | P5级 22 | P6级 23 | 24 | 25 | 不提醒 26 | 声音提醒 27 | 震动提醒 28 | 声音加震动提醒 29 | 通知栏提醒 30 | 31 | 32 | NONE 33 | BUBBLE 34 | SOUND 35 | VIBRATE 36 | SOUND_VIBRATE 37 | 38 | 39 | 大家说 40 | 有人说 41 | 42 | 43 | 永远相信美好的事情即将发生 44 | 菊花也是一种美 45 | 初恋无限好,只是挂得早 46 | 暗恋是成功的哑剧 47 | 学会换位思考,世界才会简单 48 | 心若怡然,何处不桃源 49 | 有些话,说再多也没用 50 | 人生,快乐不快乐看心情 51 | 任何物体的表面,都不是绝对的平整 52 | 生活总不完美,总有辛酸的泪 53 | 没有报警,生活总是缺了点什么 54 | 报警是解决失恋痛苦的良药 55 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /res/values/attrs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 | 22 | 23 | #7f040000 24 | 25 | 26 | #ffecfbff 27 | #ffffffff 28 | 29 | 30 | #ff478534 31 | 32 | #666666 33 | 34 | #fff7f7f7 35 | #ff000000 36 | #ee747474 37 | #ffebf0f2 38 | #ffffffff 39 | #ff999999 40 | #00000000 41 | #ffffffff 42 | #ffeeeeee 43 | #5fb02e 44 | 45 | #bf000000 46 | 47 | #ffeeeeee 48 | #fff8f8f8 49 | #ffe4e4e4 50 | #000000 51 | #ff0000 52 | #ff85aeec 53 | #fff98a12 54 | #ff629c3d 55 | #cccccc 56 | #ff333333 57 | #FFFFFF 58 | #000000 59 | #333333 60 | #777777 61 | #FF0000 62 | #C0FFFFFF 63 | #80FFFFFF 64 | #60FFFFFF 65 | #40FFFFFF 66 | #C0000000 67 | #80000000 68 | #A0000000 69 | #60000000 70 | #30000000 71 | #90000000 72 | #00000000 73 | #FFFFFF 74 | #a5a7ab 75 | #888888 76 | #a1a1a1 77 | #444444 78 | #4f9630 79 | #cfcfcf 80 | #676a73 81 | #ffd2d2d2 82 | #ff888888 83 | #ff51982a 84 | #ffff8712 85 | 86 | #ff272727 87 | #ff333333 88 | 89 | #ff339900 90 | #ff999999 91 | #fff1ad 92 | #ffa800 93 | #ffaaaaaa 94 | #ff999999 95 | #d9d9d9 96 | #e1e4e9 97 | #707277 98 | #339933 99 | #45474c 100 | #555b68 101 | #8d9198 102 | #555555 103 | #78bb3c 104 | #3aa4e3 105 | #7d72ed 106 | #e96ba6 107 | #efa800 108 | #f7f7f7 109 | 110 | 111 | #5c5f65 112 | #416333 113 | #FFFFFF 114 | #f81e7f 115 | #fe0000 116 | #fe9903 117 | #fdfd04 118 | #22d422 119 | #12d1ce 120 | #65a2f4 121 | #6164cd 122 | #6600cb 123 | #8f8f8f 124 | #f29cc2 125 | #ee8989 126 | #f4c175 127 | #fef9a6 128 | #7ad27a 129 | #82eaea 130 | #a2c6f7 131 | #a4a6f9 132 | #ba7cf6 133 | #FFFFFF 134 | #85043d 135 | #831414 136 | #80420e 137 | #d9ae00 138 | #237b23 139 | #125f5f 140 | #09489d 141 | #0f129b 142 | #6d136d 143 | #000000 144 | #5dae0b 145 | 146 | 147 | #999999 148 | #aa000000 149 | #653005 150 | 151 | 152 | #00000000 153 | #b0000000 154 | #c0ffff00 155 | #ff000000 156 | #ffff0000 157 | #60000000 158 | #e1e4e9 159 | #ffffff 160 | #333333 161 | #666666 162 | #999999 163 | #aaaaaa 164 | #ff7700 165 | #3399ff 166 | #ffaa00 167 | #f6f6f6 168 | #ff0000 169 | #00ccff 170 | #36b336 171 | #899bdd 172 | #dbdbdb 173 | #000000 174 | #6ab6ec 175 | 176 | #C0ffffff 177 | #7fffffff 178 | #C0333333 179 | #C0000000 180 | #E6000000 181 | #7faaaaaa 182 | 183 | 184 | #ff7700 185 | #dedede 186 | 187 | #ff9900 188 | #cfcfcf 189 | #333333 190 | #ffc63d 191 | #999999 192 | #d1d1d1 193 | 194 | 195 | #139949 196 | #028035 197 | #dfe8e5 198 | #4a504e 199 | 200 | 201 | #6633B5E5 202 | #2000 203 | #F5801F 204 | #b3b3b3 205 | 206 | 207 | #F3B300 208 | #2673EC 209 | #78BA00 210 | #252525 211 | #AE113D 212 | 213 | 214 | 215 | 216 | 217 | -------------------------------------------------------------------------------- /res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 报警助手 5 | 1.0.4 6 | Alert 7 | %1$s 问题 8 | %1$s %2$s 问题 9 | 发件人: 10 | 告警级别: 11 | 主机名: 12 | 机器的IP: 13 | 告警具体内容: 14 | 告警发生时间: 15 | 内容 16 | 故障状态: 17 | 设置 18 | 声音设置 19 | 提醒设置 20 | 拦截规则 21 | 添加拦截规则 22 | 未读 23 | 已读 24 | 添加拦截号码 25 | 电话号码不能为空 26 | 电话号码不能过长 27 | 电话号码已经存在 28 | 拦截号码添加成功 29 | 电话列表 30 | 删除所有 31 | 删除已读 32 | P0提醒设置 33 | P1提醒设置 34 | P2提醒设置 35 | P3提醒设置 36 | P4提醒设置 37 | P5提醒设置 38 | P6提醒设置 39 | 短信详情 40 | 消息原文: 41 | 取消 42 | 确定 43 | 拦截列表 44 | 版本更新 45 | 使用说明 46 | 关于我们 47 | 48 | 49 | -------------------------------------------------------------------------------- /res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 14 | 15 | 16 | 19 | 20 | 24 | 25 | 28 | 29 | 32 | 33 | 37 | 38 | 42 | 43 | 47 | 48 | 53 | 54 | 58 | 59 | -------------------------------------------------------------------------------- /res/xml/alert.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 9 | 16 | 17 | 20 | 27 | 28 | 31 | 38 | 39 | 42 | 49 | 50 | 53 | 60 | 61 | 64 | 71 | 72 | 73 | -------------------------------------------------------------------------------- /src/com/xiaomi/alertsystem/AlertSystemApplication.java: -------------------------------------------------------------------------------- 1 | /** 2 | * All rights Reserved, Designed By NoOps.me 3 | * Company: XIAOMI.COM 4 | * @author: 5 | * Xiaodong Pan 6 | * Wei Lai parse(List lines) { 51 | List alertMetas = new ArrayList(); 52 | 53 | for (String str : lines) { 54 | List sms = AlertManager.getAlertManager().parse(str); 55 | AlertMeta meta = AlertManager.getAlertManager().format(sms); 56 | alertMetas.add(meta); 57 | } 58 | 59 | return alertMetas; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/com/xiaomi/alertsystem/data/AlertItem.java: -------------------------------------------------------------------------------- 1 | /** 2 | * All rights Reserved, Designed By NoOps.me 3 | * Company: XIAOMI.COM 4 | * @author: 5 | * Xiaodong Pan 6 | * Wei Lai 7 | * @version V1.0 8 | */ 9 | 10 | package com.xiaomi.alertsystem.data; 11 | 12 | import java.util.List; 13 | 14 | public class AlertItem { 15 | 16 | public int mNumbers; 17 | 18 | public int mNewNumber; 19 | 20 | public List mLAlertMetas; 21 | 22 | public AlertItem(List metas) { 23 | mLAlertMetas = metas; 24 | mNumbers = metas.size(); 25 | } 26 | 27 | public void setNews(List meta) { 28 | if (meta != null) { 29 | mLAlertMetas.addAll(meta); 30 | mNewNumber = meta.size(); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/com/xiaomi/alertsystem/data/AlertManager.java: -------------------------------------------------------------------------------- 1 | /** 2 | * All rights Reserved, Designed By NoOps.me 3 | * Company: XIAOMI.COM 4 | * @author: 5 | * Xiaodong Pan 6 | * Wei Lai 7 | * @version V1.0 8 | */ 9 | 10 | package com.xiaomi.alertsystem.data; 11 | 12 | import android.util.Log; 13 | 14 | import com.xiaomi.alertsystem.AlertSystemApplication; 15 | import com.xiaomi.alertsystem.data.Constants; 16 | 17 | import java.util.ArrayList; 18 | import java.util.List; 19 | import java.util.regex.Matcher; 20 | import java.util.regex.Pattern; 21 | 22 | public class AlertManager { 23 | public final static String TAG = "AlertManager"; 24 | public final static char sPatternStart = '['; 25 | public final static char sPatternEnd = ']'; 26 | public static AlertManager mAlertManager; 27 | 28 | private AlertManager() { 29 | 30 | } 31 | 32 | // 按照规则匹配 33 | public static boolean matchAlert(String sms) { 34 | if (sms.startsWith("[P") || sms.startsWith("【P")) 35 | return true; 36 | Pattern pattern = Pattern.compile(".*\\[P\\d\\].*||.*\\【P\\d\\】.*"); 37 | Matcher matcher = pattern.matcher(sms); 38 | if (matcher != null && matcher.matches()) 39 | return true; 40 | return false; 41 | } 42 | 43 | public static AlertManager getAlertManager() { 44 | if (mAlertManager == null) { 45 | mAlertManager = new AlertManager(); 46 | } 47 | return mAlertManager; 48 | } 49 | 50 | private boolean isLevelField(String s) { 51 | Pattern pattern = Pattern.compile("p\\d"); 52 | Matcher matcher = pattern.matcher(s); 53 | if (matcher != null && matcher.matches()) 54 | return true; 55 | return false; 56 | } 57 | 58 | public List parse(String msg) { 59 | List list = new ArrayList(); 60 | 61 | // 首先尝试【】 62 | Pattern pattern = Pattern.compile("\\【(.*?)\\】"); 63 | Matcher matcher = pattern.matcher(msg); 64 | while (matcher.find()) { 65 | list.add(matcher.group(1)); 66 | } 67 | // 然后尝试[] 68 | if (list.size() < 4) { 69 | list.clear(); 70 | pattern = Pattern.compile("\\[(.*?)\\]"); 71 | matcher = pattern.matcher(msg); 72 | while (matcher.find()) { 73 | list.add(matcher.group(1)); 74 | } 75 | } 76 | 77 | // 长度小于4,显示ParseError 78 | if (list.size() < 4) 79 | return null; 80 | else 81 | return list; 82 | } 83 | 84 | public AlertMeta format(List lst) { 85 | AlertMeta meta = null; 86 | if (lst == null || lst.size() == 0) { 87 | return meta; 88 | } 89 | 90 | try { 91 | meta = new AlertMeta(); 92 | int levelIndex = 0; 93 | for (int i = 0; i < lst.size(); i++) { 94 | if (Constants.NOTIFICATION_LEVEL.contains(lst.get(i) 95 | .toUpperCase())) { 96 | levelIndex = i; 97 | break; 98 | } 99 | } 100 | // 如果从报警级别开始,字段不足4个,则退出 101 | if (lst.size() - levelIndex < 4) { 102 | Log.d(TAG, "sms parse error!"); 103 | return null; 104 | } 105 | Log.d(TAG,"sms parse ok, level :" + lst.get(levelIndex)); 106 | 107 | //没有IP的情况,只有4个域 108 | if ((lst.size() - levelIndex) == 4) { 109 | meta.mAlertLevel = lst.get(levelIndex + 0).toUpperCase(); 110 | meta.mFlag = lst.get(levelIndex + 1); 111 | meta.mMachineName = lst.get(levelIndex + 2); 112 | meta.mBody = lst.get(levelIndex + 3); 113 | return meta; 114 | }else{ 115 | meta.mAlertLevel = lst.get(levelIndex + 0).toUpperCase(); 116 | meta.mFlag = lst.get(levelIndex + 1); 117 | meta.mMachineName = lst.get(levelIndex + 2); 118 | meta.mMachineIP = lst.get(levelIndex + 3); 119 | meta.mBody = lst.get(levelIndex + 4); 120 | return meta; 121 | } 122 | 123 | 124 | } catch (IndexOutOfBoundsException e) { 125 | // TODO:return raw string 126 | Log.d(TAG, "invalid sms"); 127 | return null; 128 | } 129 | } 130 | 131 | public boolean isIIegle(List list) { 132 | if (Constants.NOTIFICATION_LEVEL.contains(list.get(0))) { 133 | return true; 134 | } else { 135 | return false; 136 | } 137 | } 138 | } -------------------------------------------------------------------------------- /src/com/xiaomi/alertsystem/data/AlertMeta.java: -------------------------------------------------------------------------------- 1 | /** 2 | * All rights Reserved, Designed By NoOps.me 3 | * Company: XIAOMI.COM 4 | * @author: 5 | * Xiaodong Pan 6 | * Wei Lai 7 | * @version V1.0 8 | */ 9 | 10 | package com.xiaomi.alertsystem.data; 11 | 12 | import android.os.Parcel; 13 | import android.os.Parcelable; 14 | import android.text.TextUtils; 15 | 16 | import java.text.SimpleDateFormat; 17 | import java.util.Date; 18 | 19 | public class AlertMeta extends Sms implements Parcelable { 20 | public static final String ALERT_LEVEL_PALL = "P"; 21 | public static final String ALERT_LEVEL_P0 = "P0"; 22 | public static final String ALERT_LEVEL_P1 = "P1"; 23 | public static final String ALERT_LEVEL_P2 = "P2"; 24 | public static final String ALERT_LEVEL_P3 = "P3"; 25 | 26 | public static final String ALERT_FLAG_OK = "OK"; 27 | public static final String ALERT_FLAG_ERROR = "PROBLEM"; 28 | 29 | private SimpleDateFormat mSimpleDateFormat = new SimpleDateFormat( 30 | "yyyy-MM-dd HH:mm"); 31 | 32 | public String mAlertLevel; 33 | 34 | public String mFlag; // 报警标志 35 | 36 | public String mMachineName; 37 | 38 | public String mMachineIP; 39 | 40 | public String mMsg; 41 | 42 | public AlertMeta(final String level, final String flag, 43 | final String machineName, final String machineIP, final String msg) { 44 | 45 | mAlertLevel = level; 46 | mFlag = flag; 47 | mMachineName = machineName; 48 | mMachineIP = machineIP; 49 | mMsg = msg; 50 | } 51 | 52 | public String toString() { 53 | return "(" + mId + ")" + mMsg.toString(); 54 | } 55 | 56 | public AlertMeta(Parcel in) { 57 | super(in); 58 | mAlertLevel = in.readString(); 59 | mFlag = in.readString(); 60 | mMachineName = in.readString(); 61 | mMachineIP = in.readString(); 62 | mMsg = in.readString(); 63 | } 64 | 65 | public AlertMeta() { 66 | 67 | } 68 | 69 | public String getAlertLevel() { 70 | return mAlertLevel; 71 | } 72 | 73 | public String getMachineName() { 74 | return mMachineName; 75 | } 76 | 77 | public String getMachineIP() { 78 | return mMachineIP; 79 | } 80 | 81 | public long getTimeStamp() { 82 | return mTimeStamp; 83 | } 84 | 85 | public String getProblem() { 86 | return mBody; 87 | } 88 | 89 | public String getDateTime() { 90 | Date date = new Date(mTimeStamp); 91 | return mSimpleDateFormat.format(date); 92 | } 93 | 94 | public boolean isProblemMachine() { 95 | if (TextUtils.isEmpty(mFlag)) { 96 | return false; 97 | } 98 | return TextUtils.equals(mFlag, ALERT_FLAG_ERROR); 99 | } 100 | 101 | public boolean isHighProblem() { 102 | if (TextUtils.isEmpty(mAlertLevel)) { 103 | return false; 104 | } 105 | 106 | return TextUtils.equals(mAlertLevel, ALERT_LEVEL_P0); 107 | } 108 | 109 | @Override 110 | public boolean equals(Object o) { 111 | AlertMeta alertMeta = (AlertMeta) o; 112 | 113 | if (o == null) { 114 | return false; 115 | } 116 | 117 | return alertMeta.mId == mId; 118 | } 119 | 120 | public static final Parcelable.Creator CREATOR = new Creator() { 121 | 122 | @Override 123 | public AlertMeta[] newArray(int size) { 124 | return new AlertMeta[size]; 125 | } 126 | 127 | @Override 128 | public AlertMeta createFromParcel(Parcel source) { 129 | return new AlertMeta(source); 130 | } 131 | }; 132 | 133 | @Override 134 | public void writeToParcel(Parcel dest, int flags) { 135 | super.writeToParcel(dest, flags); 136 | dest.writeString(mAlertLevel); 137 | dest.writeString(mFlag); 138 | dest.writeString(mMachineName); 139 | dest.writeString(mMachineIP); 140 | dest.writeString(mMsg); 141 | } 142 | 143 | } 144 | -------------------------------------------------------------------------------- /src/com/xiaomi/alertsystem/data/Constants.java: -------------------------------------------------------------------------------- 1 | /** 2 | * All rights Reserved, Designed By NoOps.me 3 | * Company: XIAOMI.COM 4 | * @author: 5 | * Xiaodong Pan 6 | * Wei Lai 7 | * @version V1.0 8 | */ 9 | 10 | package com.xiaomi.alertsystem.data; 11 | 12 | import java.util.ArrayList; 13 | import java.util.Arrays; 14 | 15 | public class Constants { 16 | public static final String SMS_RECEIVED = "android.provider.Telephony.SMS_RECEIVED"; 17 | // broadcast: sms updated 18 | public static final String sActSmsInserted = "com.xiaomi.alertsystem.SMS_INSERTED"; 19 | 20 | // intent: start activity thread 21 | public static final String sActSmsThread = "com.xiaomi.alertsystem.SMS_THREAD"; 22 | public static final String TIELE_INTENT = "title_intent"; 23 | public static final String KEY = "key"; 24 | public static final String HOST = "host"; 25 | public static final String URL_UPDATE = "http://xbox.pt.xiaomi.com/monitor/apk/alertsystem/update?ver="; 26 | public static final String APP_DIR = "alertsystem/"; 27 | public static final String DEFAULT_DIR = "/sdcard/"; 28 | 29 | 30 | // 报警方式 31 | public static final int NOTIFICATION_NONE = 0; 32 | public static final int NOTIFICATION_SOUND = 1; 33 | public static final int NOTIFICATION_VIBRATE = 2; 34 | public static final int NOTIFICATION_SOUND_VIBRATE = 3; 35 | public static final int NOTIFICATION_BUBBLE = 4; 36 | 37 | // 版本消息提示 38 | public static final int MSG_VER_ERROR = 1000; 39 | public static final int MSG_VER_UPDATE = 1001; 40 | public static final int MSG_VER_NONEED = 1002; 41 | 42 | public static final String[] NOTIFICATION = { "不提醒", "声音", "振动", "声音振动", 43 | "通知栏" }; 44 | public static ArrayList NOTIFICATION_LEVEL = new ArrayList( 45 | Arrays.asList("P", "P0", "P1", "P2", "P3")); 46 | 47 | // *******************拦截号码********************* 48 | public static ArrayList DEFAULT_PHONE = new ArrayList( 49 | Arrays.asList("10657520300931689", "10690269222", "15011518472", 50 | "951312330315")); 51 | 52 | public static final String P0_SOUND_KEY = "pref_p0_notification"; 53 | public static final String P1_SOUND_KEY = "pref_p1_notification"; 54 | public static final String P2_SOUND_KEY = "pref_p2_notification"; 55 | public static final String P3_SOUND_KEY = "pref_p3_notification"; 56 | public static final String P4_SOUND_KEY = "pref_p4_notification"; 57 | public static final String P5_SOUND_KEY = "pref_p5_notification"; 58 | 59 | public static final String BROADCAST_TYPE = "com.xiaomi.alertsystem.broadcast_type"; 60 | public static final String BROADCAST_SMS = "com.xiaomi.alertsystem.broadcast_sms"; 61 | // 数据刷新方式 62 | public static final int DATA_REFREASH = 1; 63 | public static final int DATA_CHANGE = 2; 64 | public static final int DATA_REMOVE = 3; 65 | public static final int DATA_LIST_CHANGE = 4; 66 | 67 | } -------------------------------------------------------------------------------- /src/com/xiaomi/alertsystem/data/NotifyMeta.java: -------------------------------------------------------------------------------- 1 | /** 2 | * All rights Reserved, Designed By NoOps.me 3 | * Company: XIAOMI.COM 4 | * @author: 5 | * Xiaodong Pan 6 | * Wei Lai 7 | * @version V1.0 8 | */ 9 | 10 | package com.xiaomi.alertsystem.data; 11 | 12 | import com.xiaomi.alertsystem.utils.CommonUtils; 13 | 14 | import android.content.Context; 15 | 16 | public class NotifyMeta { 17 | 18 | private String key; 19 | private String mPerfKey; 20 | private Context mContext; 21 | 22 | 23 | public NotifyMeta(String key, Context context) { 24 | super(); 25 | this.key = key.toLowerCase(); 26 | this.mContext = context; 27 | // 为了兼容老版本 28 | this.mPerfKey = "pref_"+ key.toLowerCase() +"_notification "; 29 | } 30 | 31 | public String getKey() { 32 | return key; 33 | } 34 | 35 | public String getName_cn() { 36 | return key.toUpperCase() + "提醒设置"; 37 | } 38 | 39 | public String getName_en() { 40 | // 为了兼容老版本 41 | return mPerfKey; 42 | } 43 | 44 | public int getValue() { 45 | return CommonUtils.getSettingInt(mContext, mPerfKey, Constants.NOTIFICATION_VIBRATE); 46 | } 47 | 48 | public String getTextValue() { 49 | int index = getValue(); 50 | return Constants.NOTIFICATION[index]; 51 | } 52 | public void setValue(int value) { 53 | CommonUtils.setSettingInt(mContext, mPerfKey, value); 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /src/com/xiaomi/alertsystem/data/Sms.java: -------------------------------------------------------------------------------- 1 | /** 2 | * All rights Reserved, Designed By NoOps.me 3 | * Company: XIAOMI.COM 4 | * @author: 5 | * Xiaodong Pan 6 | * Wei Lai 7 | * @version V1.0 8 | */ 9 | 10 | package com.xiaomi.alertsystem.data; 11 | 12 | import android.os.Parcel; 13 | import android.os.Parcelable; 14 | 15 | public class Sms implements Parcelable { 16 | public long mId; 17 | 18 | public String mAddress; 19 | 20 | public String mPerson; 21 | 22 | public String mBody; 23 | 24 | public long mTimeStamp; 25 | 26 | public String mType; 27 | 28 | public int mStatus; // 0,未读,1,一读 29 | 30 | public Sms(final long id, final String address, final String person, 31 | final String body, final long date, final String type, 32 | final int status) { 33 | mId = id; 34 | mAddress = address; 35 | mPerson = person; 36 | mBody = body; 37 | mTimeStamp = date; 38 | mType = type; 39 | mStatus = status; 40 | } 41 | 42 | public Sms(Parcel in) { 43 | mId = in.readLong(); 44 | mAddress = in.readString(); 45 | mPerson = in.readString(); 46 | mBody = in.readString(); 47 | mTimeStamp = in.readLong(); 48 | mType = in.readString(); 49 | mStatus = in.readInt(); 50 | } 51 | 52 | public Sms() { 53 | 54 | } 55 | 56 | @Override 57 | public int describeContents() { 58 | return 0; 59 | } 60 | 61 | public final static Parcelable.Creator CREATOR = new Creator() { 62 | 63 | @Override 64 | public Sms[] newArray(int size) { 65 | return new Sms[size]; 66 | } 67 | 68 | @Override 69 | public Sms createFromParcel(Parcel source) { 70 | return new Sms(source); 71 | } 72 | }; 73 | 74 | @Override 75 | public void writeToParcel(Parcel dest, int flags) { 76 | dest.writeLong(mId); 77 | dest.writeString(mAddress); 78 | dest.writeString(mPerson); 79 | dest.writeString(mBody); 80 | dest.writeLong(mTimeStamp); 81 | dest.writeString(mType); 82 | dest.writeInt(mStatus); 83 | } 84 | 85 | } 86 | -------------------------------------------------------------------------------- /src/com/xiaomi/alertsystem/ui/AboutActivity.java: -------------------------------------------------------------------------------- 1 | /** 2 | * All rights Reserved, Designed By NoOps.me 3 | * Company: XIAOMI.COM 4 | * @author: 5 | * Xiaodong Pan 6 | * Wei Lai 7 | * @version V1.0 8 | */ 9 | 10 | package com.xiaomi.alertsystem.ui; 11 | 12 | import android.os.Bundle; 13 | import android.view.View; 14 | import android.view.View.OnClickListener; 15 | 16 | import com.xiaomi.alertsystem.R; 17 | 18 | public class AboutActivity extends BaseActivity { 19 | 20 | private View mBack; 21 | @Override 22 | protected void onCreate(Bundle savedInstanceState) { 23 | super.onCreate(savedInstanceState); 24 | setContentView(R.layout.about); 25 | findViews(); 26 | setListens(); 27 | 28 | } 29 | 30 | private void findViews() { 31 | mBack = findViewById(R.id.goback); 32 | } 33 | 34 | private void setListens() { 35 | mBack.setOnClickListener(gobackListener); 36 | } 37 | 38 | private OnClickListener gobackListener = new OnClickListener() { 39 | 40 | @Override 41 | public void onClick(View v) { 42 | AboutActivity.this.finish(); 43 | } 44 | }; 45 | } 46 | -------------------------------------------------------------------------------- /src/com/xiaomi/alertsystem/ui/AlertContentActivity.java: -------------------------------------------------------------------------------- 1 | /** 2 | * All rights Reserved, Designed By NoOps.me 3 | * Company: XIAOMI.COM 4 | * @author: 5 | * Xiaodong Pan 6 | * Wei Lai mMetaList; 33 | private AlertMeta mSms = null; 34 | private int mId = 0; 35 | private View mBack; 36 | 37 | 38 | @Override 39 | protected void onCreate(Bundle savedInstanceState) { 40 | super.onCreate(savedInstanceState); 41 | setContentView(R.layout.content_activity); 42 | mId = getIntent().getExtras().getInt("ID"); 43 | mBack = findViewById(R.id.goback); 44 | mBack.setOnClickListener(gobackListener); 45 | 46 | 47 | if(mMetaList != null){ 48 | mSms = mMetaList.get(mId); 49 | mSms.mStatus = 1; 50 | buildContentView(); 51 | updateStatusTask(); 52 | 53 | SmsManager.registerTableChangeListener(this); 54 | } 55 | } 56 | 57 | 58 | private OnClickListener gobackListener = new OnClickListener() { 59 | 60 | @Override 61 | public void onClick(View v) { 62 | AlertContentActivity.this.finish(); 63 | } 64 | }; 65 | 66 | private void updateStatusTask() { 67 | AsyncTask task = new AsyncTask() { 68 | 69 | @Override 70 | protected AlertMeta doInBackground(Void... params) { 71 | return SmsManager.updateStatus(mSms); 72 | } 73 | 74 | @Override 75 | protected void onPostExecute(AlertMeta result) { 76 | super.onPostExecute(result); 77 | notifyChanged("", result); 78 | } 79 | }; 80 | AsyncTaskUtils.exe(task); 81 | } 82 | 83 | private void buildContentView() { 84 | if (mSms == null) { 85 | return; 86 | } 87 | 88 | TextView flagView = (TextView) findViewById(R.id.flag); 89 | TextView safeView = (TextView) findViewById(R.id.safetype); 90 | TextView hostnameView = (TextView) findViewById(R.id.hostname); 91 | TextView machineIPView = (TextView) findViewById(R.id.ip); 92 | TextView contentView = (TextView) findViewById(R.id.content); 93 | TextView timeView = (TextView) findViewById(R.id.time); 94 | TextView originalView = (TextView) findViewById(R.id.msg); 95 | 96 | 97 | if (mSms.isProblemMachine()) { 98 | flagView.setTextColor(this.getResources().getColor(R.color.class_J)); 99 | } else { 100 | flagView.setTextColor(this.getResources().getColor(R.color.class_K)); 101 | } 102 | flagView.setText(mSms.mFlag); 103 | contentView.setText(mSms.mBody); 104 | safeView.setText(mSms.getAlertLevel()); 105 | hostnameView.setText(mSms.getMachineName()); 106 | machineIPView.setText(mSms.getMachineIP()); 107 | timeView.setText(mSms.getDateTime()); 108 | originalView.setText(mSms.mMsg); 109 | } 110 | 111 | @Override 112 | //发送广播,通知第一级Activity和第二级Activity 113 | public void notifyChanged(String tablename, AlertMeta meta) { 114 | Log.d(TAG, "changed:" + meta.mMsg); 115 | //改变第二级activity数据,第二级全部Reload 116 | mMetaList.get(mId).mStatus = 1; 117 | 118 | Intent intent=new Intent(Constants.sActSmsInserted); 119 | intent.putExtra(Constants.BROADCAST_TYPE, Constants.DATA_CHANGE); 120 | intent.putExtra(Constants.BROADCAST_SMS, meta); 121 | sendBroadcast(intent); 122 | } 123 | } 124 | -------------------------------------------------------------------------------- /src/com/xiaomi/alertsystem/ui/AlertLevelAdapter.java: -------------------------------------------------------------------------------- 1 | /** 2 | * All rights Reserved, Designed By NoOps.me 3 | * Company: XIAOMI.COM 4 | * @author: 5 | * Xiaodong Pan 6 | * Wei Lai 7 | * @version V1.0 8 | */ 9 | 10 | package com.xiaomi.alertsystem.ui; 11 | 12 | import android.app.Activity; 13 | import android.util.Log; 14 | import android.view.LayoutInflater; 15 | import android.view.View; 16 | import android.view.ViewGroup; 17 | import android.widget.BaseAdapter; 18 | import android.widget.TextView; 19 | 20 | import com.xiaomi.alertsystem.R; 21 | import com.xiaomi.alertsystem.data.AlertMeta; 22 | 23 | import java.util.List; 24 | 25 | //TODO:deprecated, will not be used 26 | public class AlertLevelAdapter extends BaseAdapter { 27 | 28 | private Activity mActivity; 29 | private List mList; 30 | 31 | public AlertLevelAdapter(Activity activity, List sms) { 32 | mActivity = activity; 33 | mList = sms; 34 | } 35 | 36 | @Override 37 | public int getCount() { 38 | if (mList != null) { 39 | return mList.size(); 40 | } 41 | return 0; 42 | } 43 | 44 | @Override 45 | public Object getItem(int position) { 46 | return null; 47 | } 48 | 49 | @Override 50 | public long getItemId(int position) { 51 | return 0; 52 | } 53 | 54 | @Override 55 | public View getView(int position, View convertView, ViewGroup parent) { 56 | if (convertView == null) { 57 | convertView = LayoutInflater.from(mActivity).inflate( 58 | R.layout.level_list_layout, null); 59 | } 60 | Log.d("AlertLevelAdapter", "getview:" + mList.get(position).toString()); 61 | TextView text = (TextView) convertView.findViewById(R.id.sub_title); 62 | TextView body = (TextView) convertView.findViewById(R.id.body); 63 | text.setText(mList.get(position).mAddress); 64 | body.setText(mList.get(position).mBody); 65 | return convertView; 66 | } 67 | 68 | } 69 | -------------------------------------------------------------------------------- /src/com/xiaomi/alertsystem/ui/AlertLevelFragment.java: -------------------------------------------------------------------------------- 1 | /** 2 | * All rights Reserved, Designed By NoOps.me 3 | * Company: XIAOMI.COM 4 | * @author: 5 | * Xiaodong Pan 6 | * Wei Lai mSms; 44 | private int mPageNum; 45 | private int mPageTotal; 46 | private String mLevel; 47 | private static Context mContext; 48 | public BroadcastReceiver receiver = null; 49 | 50 | 51 | public static AlertLevelFragment newInstance(String level, Context context) { 52 | AlertLevelFragment f = new AlertLevelFragment(); 53 | mContext = context; 54 | Bundle b = new Bundle(); 55 | b.putString(KEY, level); 56 | f.setArguments(b); 57 | return f; 58 | } 59 | 60 | @Override 61 | public void onCreate(Bundle savedInstanceState) { 62 | super.onCreate(savedInstanceState); 63 | mLevel = getArguments().getString(KEY); 64 | Log.d(TAG, "Level:" + mLevel); 65 | 66 | } 67 | 68 | @Override 69 | public void onDestroy() { 70 | if(receiver != null) 71 | mContext.unregisterReceiver(receiver); 72 | super.onDestroy(); 73 | } 74 | 75 | @Override 76 | public View onCreateView(LayoutInflater inflater, ViewGroup container, 77 | Bundle savedInstanceState) { 78 | View view = inflater.inflate(R.layout.level_activity_layout, null); 79 | 80 | mListView = (ListView) view.findViewById(R.id.list); 81 | 82 | // 初始化页面数目 83 | mPageTotal = SmsManager.getAlertPageNum(mLevel); 84 | mPageNum = 0; 85 | mSms = SmsManager.queryAlertSmsByPage(SmsManager.sProjection, mPageNum, 86 | mLevel); 87 | 88 | mAdapter = new AlertMainlAdapter(mContext, mSms, mLevel); 89 | mListView.setAdapter(mAdapter); 90 | 91 | // 注册receiver 92 | enableReceiver(); 93 | mListView.setOnItemClickListener(this); 94 | mListView.setOnScrollListener(pageScroll); 95 | return view; 96 | } 97 | 98 | public void onResume() { 99 | Log.d(TAG, "onResume"); 100 | super.onResume(); 101 | mAdapter.notifyDataSetChanged(); 102 | MobclickAgent.onPageStart("AlertLevelFragment"); 103 | 104 | } 105 | 106 | 107 | 108 | public void onPause() { 109 | super.onPause(); 110 | MobclickAgent.onPageEnd("AlertLevelFragment"); 111 | } 112 | 113 | @Override 114 | public void onItemClick(AdapterView parent, View view, int position, 115 | long id) { 116 | //Log.d(TAG, "click, put to intent:" + mSms.get(position)); 117 | final Intent intent = new Intent(mContext, AlertThreadActivity.class); 118 | intent.putExtra(Constants.sActSmsThread, mSms.get(position)); 119 | intent.putExtra(Constants.KEY, mLevel); 120 | intent.putExtra(Constants.HOST, mSms.get(position).mMachineName); 121 | startActivity(intent); 122 | } 123 | 124 | public AbsListView.OnScrollListener pageScroll = new OnScrollListener() { 125 | private int firstView = 0; 126 | private boolean finish = false; 127 | 128 | @Override 129 | public void onScrollStateChanged(AbsListView view, int scrollState) { 130 | if (scrollState == OnScrollListener.SCROLL_STATE_IDLE) { 131 | if (firstView > 0 && mPageNum < mPageTotal - 1) { 132 | mPageNum++; 133 | List list = SmsManager.queryAlertSmsByPage( 134 | SmsManager.sProjection, mPageNum, mLevel); 135 | mSms.addAll(list); 136 | mAdapter.notifyDataSetChanged(); 137 | } else { 138 | // if (!finish) 139 | // Toast.makeText(mContext, "还好,没有更多报警了", 140 | // Toast.LENGTH_SHORT).show(); 141 | // finish = true; 142 | } 143 | } 144 | } 145 | 146 | @Override 147 | public void onScroll(AbsListView view, int firstVisibleItem, 148 | int visibleItemCount, int totalItemCount) { 149 | firstView = firstVisibleItem; 150 | // System.out.println("firstVisibleItem: " + firstVisibleItem 151 | // + " , visibleItemCount:" + visibleItemCount 152 | // + " , totalItemCount:" + totalItemCount); 153 | 154 | } 155 | }; 156 | 157 | 158 | public void enableReceiver() { 159 | receiver = new BroadcastReceiver() { 160 | public void onReceive(Context context, Intent intent) { 161 | doReceive(intent); 162 | } 163 | }; 164 | mContext.registerReceiver(receiver, makeReceiverFilter()); 165 | } 166 | 167 | public IntentFilter makeReceiverFilter() { 168 | final IntentFilter filter = new IntentFilter(); 169 | filter.addAction(Constants.sActSmsInserted); 170 | return filter; 171 | } 172 | 173 | private void updateMetaList(AlertMeta meta) { 174 | // 遍历,并且修改 175 | for (AlertMeta elem : mSms) { 176 | if (elem.mId == meta.mId) { 177 | elem.mStatus = 1; 178 | break; 179 | } 180 | } 181 | //mAdapter.notifyDataSetChanged(); 182 | } 183 | 184 | private void updateHostList(String host) { 185 | // 更新主机数据 186 | for (AlertMeta elem : mSms) { 187 | if (elem.mMachineName != null && elem.mMachineName.equals(host)) { 188 | elem.mStatus = 1; 189 | } 190 | } 191 | //mAdapter.notifyDataSetChanged(); 192 | } 193 | 194 | private void removeMetaList(AlertMeta meta) { 195 | // 遍历,并且修改 196 | for (AlertMeta elem : mSms) { 197 | if (elem.mId == meta.mId) { 198 | //elem.mStatus = 1; 199 | mSms.remove(elem); 200 | break; 201 | } 202 | } 203 | //mAdapter.notifyDataSetChanged(); 204 | } 205 | 206 | public void doReceive(Intent intent) { 207 | mAdapter.notifyDataSetChanged(); 208 | final String action = intent.getAction(); 209 | 210 | Log.d(TAG, "receive broadcast:" + action); 211 | if (action.equals(Constants.sActSmsInserted)) { 212 | int type = intent.getIntExtra(Constants.BROADCAST_TYPE, -1); 213 | Log.d(TAG, "broadcast action is smsinserted, notify, type:" + type); 214 | 215 | // 完全重新加载 216 | if (type == Constants.DATA_REFREASH) { 217 | mPageTotal = SmsManager.getAlertPageNum(mLevel); 218 | mPageNum = 0; 219 | List list = SmsManager.queryAlertSmsByPage(SmsManager.sProjection, 220 | mPageNum, mLevel); 221 | mSms.clear(); 222 | mSms.addAll(list); 223 | mAdapter.notifyDataSetChanged(); 224 | } 225 | 226 | // 部分数据更新 227 | if (type == Constants.DATA_CHANGE) { 228 | AlertMeta meta = (AlertMeta) intent 229 | .getParcelableExtra(Constants.BROADCAST_SMS); 230 | 231 | if(meta == null) 232 | return ; 233 | // 获取更新数据,更新后清除 234 | if (mLevel.equals("P")) { 235 | updateMetaList(meta); 236 | } else { 237 | if (meta.mAlertLevel.equals(mLevel)) 238 | updateMetaList(meta); 239 | } 240 | } 241 | 242 | // 主机数据更新 243 | if (type == Constants.DATA_LIST_CHANGE) { 244 | String host = intent.getStringExtra(Constants.BROADCAST_SMS); 245 | if(host == null || host.equals("") == true) 246 | return ; 247 | 248 | updateHostList(host); 249 | 250 | } 251 | 252 | // 部分数据删除 253 | if (type == Constants.DATA_REMOVE) { 254 | AlertMeta meta = (AlertMeta) intent 255 | .getParcelableExtra(Constants.BROADCAST_SMS); 256 | 257 | if(meta == null) 258 | return ; 259 | // 获取更新数据,更新后清除 260 | if (mLevel.equals("P")) { 261 | removeMetaList(meta); 262 | } else { 263 | if (meta.mAlertLevel.equals(mLevel)) 264 | removeMetaList(meta); 265 | } 266 | } 267 | } 268 | } 269 | 270 | 271 | 272 | } 273 | -------------------------------------------------------------------------------- /src/com/xiaomi/alertsystem/ui/AlertMainlAdapter.java: -------------------------------------------------------------------------------- 1 | /** 2 | * All rights Reserved, Designed By NoOps.me 3 | * Company: XIAOMI.COM 4 | * @author: 5 | * Xiaodong Pan 6 | * Wei Lai mSms = null; 31 | private Context mContext = null; 32 | private String mKey = null; 33 | 34 | public AlertMainlAdapter(final Context context, 35 | final List sms, final String key) { 36 | mContext = context; 37 | mSms = sms; 38 | mKey = key; 39 | } 40 | 41 | @Override 42 | public int getCount() { 43 | return mSms != null ? mSms.size() : 0; 44 | } 45 | 46 | @Override 47 | public Object getItem(int position) { 48 | return null; 49 | } 50 | 51 | @Override 52 | public long getItemId(int position) { 53 | return 0; 54 | } 55 | 56 | @Override 57 | public View getView(int position, View convertView, ViewGroup parent) { 58 | ViewHolder holder = null; 59 | if (convertView == null) { 60 | convertView = LayoutInflater.from(mContext).inflate( 61 | R.layout.main_list_layout, null); 62 | holder = new ViewHolder(); 63 | holder.icon = (ImageView) convertView.findViewById(R.id.icon); 64 | holder.title = (TextView) convertView.findViewById(R.id.title); 65 | holder.subTitle = (TextView) convertView 66 | .findViewById(R.id.sub_title); 67 | holder.time = (TextView) convertView.findViewById(R.id.time); 68 | holder.problem = (TextView) convertView.findViewById(R.id.problem); 69 | holder.status = (TextView) convertView.findViewById(R.id.status); 70 | convertView.setTag(holder); 71 | } else { 72 | holder = (ViewHolder) convertView.getTag(); 73 | } 74 | 75 | AlertMeta meta = mSms.get(position); 76 | //Log.d(TAG, meta.toString()); 77 | if (meta.isProblemMachine()) { 78 | holder.icon.setImageDrawable(mContext.getResources().getDrawable( 79 | R.drawable.namecard_info_not_verified)); 80 | } else { 81 | holder.icon.setImageDrawable(mContext.getResources().getDrawable( 82 | R.drawable.namecard_info_verified)); 83 | } 84 | 85 | holder.title.setText(meta.getMachineName()); 86 | holder.subTitle.setText(meta.mBody); 87 | holder.time.setText(meta.getDateTime()); 88 | if (TextUtils.equals(mKey, "P")) { 89 | holder.problem.setVisibility(View.VISIBLE); 90 | holder.problem.setText(meta.mAlertLevel); 91 | } else { 92 | holder.problem.setVisibility(View.GONE); 93 | } 94 | 95 | if (meta.mStatus == 0) { 96 | holder.title.setTextColor(mContext.getResources().getColor(R.color.class_B)); 97 | holder.title.setTypeface(null, Typeface.BOLD); 98 | holder.status.setText(R.string.weidu); 99 | holder.status.setTextColor(mContext.getResources().getColor(R.color.red)); 100 | } else { 101 | holder.title.setTextColor(mContext.getResources().getColor(R.color.class_D)); 102 | holder.title.setTypeface(null, Typeface.NORMAL); 103 | holder.status.setText(R.string.yidu); 104 | holder.status.setTextColor(mContext.getResources().getColor(R.color.class_K)); 105 | } 106 | return convertView; 107 | } 108 | 109 | private static class ViewHolder { 110 | ImageView icon; 111 | TextView title; 112 | TextView subTitle; 113 | TextView time; 114 | TextView problem; 115 | TextView status; 116 | } 117 | 118 | } 119 | -------------------------------------------------------------------------------- /src/com/xiaomi/alertsystem/ui/AlertThreadActivity.java: -------------------------------------------------------------------------------- 1 | /** 2 | * All rights Reserved, Designed By NoOps.me 3 | * Company: XIAOMI.COM 4 | * @author: 5 | * Xiaodong Pan 6 | * Wei Lai mThreadSmsList = new ArrayList(); 48 | 49 | private BroadcastReceiver receiver = null; 50 | private View mBack; 51 | 52 | @Override 53 | protected void onCreate(Bundle savedInstanceState) { 54 | Log.d(TAG, "onCreate"); 55 | super.onCreate(savedInstanceState); 56 | setContentView(R.layout.thread_activity_layout); 57 | 58 | findViews(); 59 | setListen(); 60 | 61 | // 获取主机所有报警 62 | mLevel = "P";//getIntent().getStringExtra(Constants.KEY); 63 | mHost = getIntent().getStringExtra(Constants.HOST); 64 | mTitleView.setText(mHost + "问题"); 65 | mDeleteStatus = false; 66 | 67 | if (!TextUtils.isEmpty(mLevel) && !TextUtils.isEmpty(mHost)) { 68 | mThreadSmsList = SmsManager.queryAlertSmsByHost( 69 | SmsManager.sProjection, mHost, mLevel); 70 | mAdapter = new AlertThreadAdapter(this, mThreadSmsList, mLevel, mHost, 71 | deleteListener); 72 | mListView.setAdapter(mAdapter); 73 | } 74 | 75 | mListView.setOnItemClickListener(mItemListener); 76 | // 注册receiver 77 | //enableReceiver(); 78 | 79 | //后台更新数据 80 | new Thread(){ 81 | public void run(){ 82 | for(AlertMeta sms: mThreadSmsList){ 83 | if(sms.mStatus == 0){ 84 | sms.mStatus = 1; 85 | //更新数据库 86 | SmsManager.updateStatus(sms); 87 | } 88 | } 89 | } 90 | }.start(); 91 | 92 | //发送广播 93 | Intent intent=new Intent(Constants.sActSmsInserted); 94 | intent.putExtra(Constants.BROADCAST_TYPE, Constants.DATA_LIST_CHANGE); 95 | intent.putExtra(Constants.BROADCAST_SMS, mHost); 96 | sendBroadcast(intent); 97 | } 98 | 99 | 100 | private void setListen() { 101 | mDeleteView.setOnClickListener(trashListener); 102 | mBack.setOnClickListener(gobackListener); 103 | } 104 | 105 | 106 | private void findViews() { 107 | mListView = (ListView) findViewById(R.id.list); 108 | mTitleView = (TextView) findViewById(R.id.title); 109 | mDeleteView = (ImageView) findViewById(R.id.trash); 110 | mBack = findViewById(R.id.goback); 111 | } 112 | 113 | private OnClickListener gobackListener = new OnClickListener() { 114 | 115 | @Override 116 | public void onClick(View v) { 117 | AlertThreadActivity.this.finish(); 118 | } 119 | }; 120 | 121 | @Override 122 | public boolean onKeyDown(int keyCode, KeyEvent event) { 123 | if (keyCode == KeyEvent.KEYCODE_BACK){ 124 | if(mDeleteStatus){ 125 | mAdapter.setDelete(false); 126 | mAdapter.notifyDataSetChanged(); 127 | mListView.setOnItemClickListener(mItemListener); 128 | mDeleteView.setImageResource(R.drawable.trash); 129 | mDeleteStatus = false; 130 | return true; 131 | }else{ 132 | this.finish(); 133 | } 134 | 135 | } 136 | return false; 137 | } 138 | 139 | 140 | private OnClickListener trashListener = new OnClickListener() { 141 | 142 | @Override 143 | public void onClick(View v) { 144 | if (mDeleteStatus == false) { 145 | mAdapter.setDelete(true); 146 | mAdapter.notifyDataSetChanged(); 147 | mListView.setOnItemClickListener(null); 148 | mDeleteView.setImageResource(R.drawable.done); 149 | mDeleteStatus = true; 150 | } else { 151 | mAdapter.setDelete(false); 152 | mAdapter.notifyDataSetChanged(); 153 | mListView.setOnItemClickListener(mItemListener); 154 | mDeleteView.setImageResource(R.drawable.trash); 155 | mDeleteStatus = false; 156 | } 157 | } 158 | }; 159 | 160 | OnClickListener deleteListener = new OnClickListener() { 161 | 162 | @Override 163 | public void onClick(View v) { 164 | int pos = (Integer) v.getTag(); 165 | AlertMeta sms = mThreadSmsList.get(pos); 166 | // 删除数据库 167 | SmsManager.deleteOneSms(sms); 168 | // 删除列表 169 | mThreadSmsList.remove(pos); 170 | mAdapter.notifyDataSetChanged(); 171 | //通知上层界面 172 | Intent intent=new Intent(Constants.sActSmsInserted); 173 | intent.putExtra(Constants.BROADCAST_TYPE, Constants.DATA_REMOVE); 174 | intent.putExtra(Constants.BROADCAST_SMS, sms); 175 | sendBroadcast(intent); 176 | } 177 | }; 178 | 179 | public void onResume() { 180 | super.onResume(); 181 | } 182 | 183 | @Override 184 | protected void onDestroy() { 185 | super.onDestroy(); 186 | //unregisterReceiver(receiver); 187 | } 188 | 189 | OnItemClickListener mItemListener = new OnItemClickListener() { 190 | 191 | @Override 192 | public void onItemClick(AdapterView parent, View view, int position, 193 | long id) { 194 | final Intent intent = new Intent(); 195 | // 传递短信列表,子activity能够更新数据 196 | AlertContentActivity.mMetaList = mThreadSmsList; 197 | Bundle bundle = new Bundle(); 198 | bundle.putInt("ID", position); 199 | intent.putExtras(bundle); 200 | intent.setClass(AlertThreadActivity.this, 201 | AlertContentActivity.class); 202 | startActivity(intent); 203 | } 204 | }; 205 | 206 | public void enableReceiver() { 207 | receiver = new BroadcastReceiver() { 208 | public void onReceive(Context context, Intent intent) { 209 | doReceive(intent); 210 | } 211 | }; 212 | registerReceiver(receiver, makeReceiverFilter()); 213 | } 214 | 215 | public IntentFilter makeReceiverFilter() { 216 | final IntentFilter filter = new IntentFilter(); 217 | filter.addAction(Constants.sActSmsInserted); 218 | return filter; 219 | } 220 | 221 | public void doReceive(Intent intent) { 222 | mAdapter.notifyDataSetChanged(); 223 | final String action = intent.getAction(); 224 | Log.d(TAG, "receive broadcast:" + action); 225 | if (action.equals(Constants.sActSmsInserted)) { 226 | mAdapter.notifyDataSetChanged(); 227 | } 228 | } 229 | } 230 | -------------------------------------------------------------------------------- /src/com/xiaomi/alertsystem/ui/AlertThreadAdapter.java: -------------------------------------------------------------------------------- 1 | /** 2 | * All rights Reserved, Designed By NoOps.me 3 | * Company: XIAOMI.COM 4 | * @author: 5 | * Xiaodong Pan 6 | * Wei Lai mSms = null; 32 | private Context mContext = null; 33 | private Boolean mDelete; 34 | private OnClickListener mListener = null; 35 | 36 | public AlertThreadAdapter(final Context c, 37 | final List sms, final String key, final String host, OnClickListener l) { 38 | mContext = c; 39 | mSms = sms; 40 | mDelete = false; 41 | mListener = l; 42 | } 43 | 44 | @Override 45 | public int getCount() { 46 | return mSms != null ? mSms.size() : 0; 47 | } 48 | 49 | public void setDelete(Boolean flag){ 50 | mDelete = flag; 51 | } 52 | 53 | @Override 54 | public Object getItem(int position) { 55 | return null; 56 | } 57 | 58 | @Override 59 | public long getItemId(int position) { 60 | return 0; 61 | } 62 | 63 | @Override 64 | public View getView(int position, View convertView, ViewGroup parent) { 65 | ViewHolder holder = null; 66 | if (convertView == null) { 67 | convertView = LayoutInflater.from(mContext).inflate( 68 | R.layout.main_list_layout, null); 69 | holder = new ViewHolder(); 70 | holder.icon = (ImageView) convertView.findViewById(R.id.icon); 71 | holder.title = (TextView) convertView.findViewById(R.id.title); 72 | holder.subTitle = (TextView) convertView 73 | .findViewById(R.id.sub_title); 74 | holder.time = (TextView) convertView.findViewById(R.id.time); 75 | holder.problem = (TextView) convertView.findViewById(R.id.problem); 76 | holder.status = (TextView) convertView.findViewById(R.id.status); 77 | holder.delete = (ImageView) convertView.findViewById(R.id.delete_button); 78 | convertView.setTag(holder); 79 | } else { 80 | holder = (ViewHolder) convertView.getTag(); 81 | } 82 | 83 | if(mDelete) 84 | holder.delete.setVisibility(View.VISIBLE); 85 | else 86 | holder.delete.setVisibility(View.GONE); 87 | 88 | if(mListener != null) 89 | holder.delete.setOnClickListener(mListener); 90 | 91 | AlertMeta meta = mSms.get(position); 92 | //保存位置 93 | holder.delete.setTag(position); 94 | //Log.d(TAG, meta.toString()); 95 | if (meta.isProblemMachine()) { 96 | holder.icon.setImageDrawable(mContext.getResources().getDrawable( 97 | R.drawable.namecard_info_not_verified)); 98 | } else { 99 | holder.icon.setImageDrawable(mContext.getResources().getDrawable( 100 | R.drawable.namecard_info_verified)); 101 | } 102 | 103 | holder.title.setText(meta.getMachineName()); 104 | holder.subTitle.setText(meta.mBody); 105 | holder.time.setText(meta.getDateTime()); 106 | holder.problem.setVisibility(View.VISIBLE); 107 | holder.problem.setText(meta.mAlertLevel); 108 | 109 | // if (meta.mStatus == 0) { 110 | // holder.title.setTextColor(mContext.getResources().getColor(R.color.class_B)); 111 | // holder.title.setTypeface(null, Typeface.BOLD); 112 | // holder.status.setText(R.string.weidu); 113 | // } else { 114 | holder.title.setTextColor(mContext.getResources().getColor(R.color.class_D)); 115 | holder.title.setTypeface(null, Typeface.NORMAL); 116 | holder.status.setText(R.string.yidu); 117 | // } 118 | return convertView; 119 | } 120 | 121 | private static class ViewHolder { 122 | ImageView icon; 123 | TextView title; 124 | TextView subTitle; 125 | TextView time; 126 | TextView problem; 127 | TextView status; 128 | ImageView delete; 129 | } 130 | 131 | } 132 | -------------------------------------------------------------------------------- /src/com/xiaomi/alertsystem/ui/BaseActivity.java: -------------------------------------------------------------------------------- 1 | /** 2 | * All rights Reserved, Designed By NoOps.me 3 | * Company: XIAOMI.COM 4 | * @author: 5 | * Xiaodong Pan 6 | * Wei Lai 6 | * Wei Lai 7 | * @version V1.0 8 | */ 9 | 10 | package com.xiaomi.alertsystem.ui; 11 | 12 | 13 | import java.util.Random; 14 | 15 | import android.content.Intent; 16 | import android.os.Bundle; 17 | import android.os.Handler; 18 | import android.os.Message; 19 | import android.view.Window; 20 | import android.widget.ImageView; 21 | 22 | import com.xiaomi.alertsystem.R; 23 | 24 | public class LogoActivity extends BaseActivity { 25 | 26 | private Handler handler; 27 | private ImageView mBackColor; 28 | private int[] colors = {R.color.xiaomiYellow,R.color.metroGreen, R.color.metroRed}; 29 | 30 | @Override 31 | protected void onCreate(Bundle savedInstanceState) { 32 | this.requestWindowFeature(Window.FEATURE_NO_TITLE); 33 | super.onCreate(savedInstanceState); 34 | 35 | setContentView(R.layout.logo); 36 | findViews(); 37 | 38 | Random rnd = new Random(); 39 | int color = colors[rnd.nextInt(colors.length)]; 40 | 41 | /**************变换启动背景颜色****************/ 42 | //mBackColor.setImageResource(color); 43 | 44 | this.handler = new Handler() { 45 | public void handleMessage(Message msg) { 46 | if (!Thread.currentThread().isInterrupted()) { 47 | switch (msg.what) { 48 | case 0: 49 | Intent intent = new Intent(LogoActivity.this, MainActivity.class); 50 | startActivity(intent); 51 | finish(); 52 | break; 53 | } 54 | } 55 | super.handleMessage(msg); 56 | } 57 | }; 58 | 59 | handler.sendEmptyMessageDelayed(0, 1500); 60 | } 61 | 62 | 63 | private void findViews() { 64 | mBackColor = (ImageView) findViewById(R.id.backcolor); 65 | } 66 | 67 | 68 | 69 | } 70 | -------------------------------------------------------------------------------- /src/com/xiaomi/alertsystem/ui/MainActivity.java: -------------------------------------------------------------------------------- 1 | /** 2 | * All rights Reserved, Designed By NoOps.me 3 | * Company: XIAOMI.COM 4 | * @author: 5 | * Xiaodong Pan 6 | * Wei Lai 7 | * @version V1.0 8 | */ 9 | 10 | package com.xiaomi.alertsystem.ui; 11 | 12 | import java.util.ArrayList; 13 | import java.util.List; 14 | import java.util.Random; 15 | 16 | import android.content.Context; 17 | import android.content.Intent; 18 | import android.os.Bundle; 19 | import android.os.Handler; 20 | import android.os.Message; 21 | import android.support.v4.app.Fragment; 22 | import android.support.v4.app.FragmentActivity; 23 | import android.support.v4.app.FragmentManager; 24 | import android.support.v4.app.FragmentPagerAdapter; 25 | import android.support.v4.view.ViewPager; 26 | import android.util.Log; 27 | import android.view.View; 28 | import android.widget.Toast; 29 | 30 | import com.astuetz.viewpager.extensions.PagerSlidingTabStrip; 31 | import com.umeng.analytics.MobclickAgent; 32 | import com.xiaomi.alertsystem.R; 33 | import com.xiaomi.alertsystem.data.AlertManager; 34 | import com.xiaomi.alertsystem.data.Constants; 35 | import com.xiaomi.alertsystem.data.AlertMeta; 36 | import com.xiaomi.alertsystem.utils.CommonUtils; 37 | import com.xiaomi.alertsystem.utils.SmsManager; 38 | import com.xiaomi.alertsystem.utils.ThreadUpdateApp; 39 | import com.xiaomi.alertsystem.utils.SmsManager.DatabaseChangedListener; 40 | 41 | public class MainActivity extends FragmentActivity implements 42 | DatabaseChangedListener { 43 | private static final String TAG = "MainActivity"; 44 | private Context mContext = MainActivity.this; 45 | private PagerSlidingTabStrip mTabs; 46 | private ViewPager mPager; 47 | private MyPagerAdapter adapter; 48 | private View mSetting; 49 | private Handler handler; 50 | 51 | public static final String AB = "0123456789abcdefjghijklmnopqrstuvwxyz"; 52 | public static List level = Constants.NOTIFICATION_LEVEL; 53 | public static String flag = "OK"; 54 | public static Random rnd = new Random(); 55 | 56 | @Override 57 | protected void onCreate(Bundle savedInstanceState) { 58 | super.onCreate(savedInstanceState); 59 | MobclickAgent.setDebugMode(false); 60 | MobclickAgent.onError(this); 61 | MobclickAgent.updateOnlineConfig(this); 62 | setContentView(R.layout.main); 63 | 64 | findViews(); 65 | setListen(); 66 | //new MyTask().start(); 67 | Bundle bundle = this.getIntent().getExtras(); 68 | if (bundle != null) { 69 | int index = bundle.getInt("PageIndex"); 70 | mPager.setCurrentItem(index); 71 | } 72 | 73 | handler = new Handler() { 74 | public void handleMessage(Message msg) { 75 | if (!Thread.currentThread().isInterrupted()) { 76 | switch (msg.what) { 77 | case Constants.MSG_VER_UPDATE: 78 | Toast.makeText(mContext, "发现新版本,版本更新中...", Toast.LENGTH_SHORT) 79 | .show(); 80 | break; 81 | case Constants.MSG_VER_NONEED: 82 | break; 83 | case Constants.MSG_VER_ERROR: 84 | break; 85 | } 86 | } 87 | super.handleMessage(msg); 88 | } 89 | }; 90 | 91 | String setkey = "updatetime"; 92 | String today = CommonUtils.getNowDate(); 93 | String dateStr = CommonUtils.getSettingString(mContext, setkey, ""); 94 | if(dateStr != null && dateStr.equals(today)){ 95 | Log.i(TAG, "今天无需更新"); 96 | }else{ 97 | ThreadUpdateApp t = new ThreadUpdateApp(mContext, handler); 98 | t.start(); 99 | CommonUtils.setSettingString(mContext, setkey, today); 100 | } 101 | } 102 | 103 | public void onResume() { 104 | super.onResume(); 105 | MobclickAgent.onResume(this); 106 | } 107 | 108 | public void onPause() { 109 | super.onPause(); 110 | MobclickAgent.onPause(this); 111 | } 112 | 113 | public void findViews() { 114 | mSetting = (View) findViewById(R.id.setting); 115 | mTabs = (PagerSlidingTabStrip) findViewById(R.id.tabs); 116 | mPager = (ViewPager) findViewById(R.id.pager); 117 | } 118 | 119 | private void setListen() { 120 | adapter = new MyPagerAdapter(getSupportFragmentManager()); 121 | mPager.setAdapter(adapter); 122 | mTabs.setViewPager(mPager); 123 | mSetting.setOnClickListener(settingListener); 124 | } 125 | 126 | static String randomString(int len) { 127 | StringBuilder sb = new StringBuilder(len); 128 | for (int i = 0; i < len; i++) 129 | sb.append(AB.charAt(rnd.nextInt(AB.length()))); 130 | return sb.toString(); 131 | } 132 | 133 | static int mIndex = 0; 134 | static String mName = randomString(10);; 135 | 136 | static List randomMsg() { 137 | List list = new ArrayList(); 138 | list.add(level.get(rnd.nextInt(5))); 139 | list.add(flag); 140 | if (mIndex++ == 10) { 141 | mIndex = 0; 142 | mName = randomString(10); 143 | } 144 | String m = mName; 145 | String ip = "127.0.0.1"; 146 | String body = m + " ok"; 147 | list.add(m); 148 | list.add(ip); 149 | list.add(body); 150 | return list; 151 | } 152 | 153 | class MyTask extends Thread { 154 | 155 | public void run() { 156 | for (int i = 0; i < 1000; i++) { 157 | List list = randomMsg(); 158 | AlertMeta alertMeta = AlertManager.getAlertManager().format( 159 | list); 160 | alertMeta.mMsg = list.toString(); 161 | SmsManager.insertAlertSms(alertMeta); 162 | } 163 | } 164 | } 165 | 166 | android.view.View.OnClickListener settingListener = new android.view.View.OnClickListener() { 167 | 168 | @Override 169 | public void onClick(View v) { 170 | 171 | Intent intent = new Intent(); 172 | intent.setClass(mContext, SettingActivity.class); 173 | startActivity(intent); 174 | } 175 | }; 176 | 177 | public class MyPagerAdapter extends FragmentPagerAdapter { 178 | 179 | private ArrayList mPages = new ArrayList(); 180 | 181 | public MyPagerAdapter(FragmentManager fm) { 182 | super(fm); 183 | Init(); 184 | } 185 | 186 | private void Init() { 187 | 188 | for (int i = 0; i < level.size(); i++) { 189 | mPages.add(AlertLevelFragment.newInstance(level.get(i), mContext)); 190 | } 191 | } 192 | 193 | @Override 194 | public CharSequence getPageTitle(int position) { 195 | if( level.get(position).equals("P")) 196 | return "所有"; 197 | else 198 | return level.get(position) + "级"; 199 | } 200 | 201 | @Override 202 | public int getCount() { 203 | return level.size(); 204 | } 205 | 206 | @Override 207 | public Fragment getItem(int position) { 208 | return mPages.get(position); 209 | } 210 | 211 | } 212 | 213 | @Override 214 | protected void onDestroy() { 215 | int mSmsUnReadNum = SmsManager.getAlertUnReadNum(); 216 | CommonUtils.sendIconCountMessage(mContext, mSmsUnReadNum); 217 | super.onDestroy(); 218 | } 219 | 220 | @Override 221 | public void notifyChanged(String tablename, AlertMeta meta) { 222 | // TODO Auto-generated method stub 223 | 224 | } 225 | } 226 | -------------------------------------------------------------------------------- /src/com/xiaomi/alertsystem/ui/PhoneAdapter.java: -------------------------------------------------------------------------------- 1 | /** 2 | * All rights Reserved, Designed By NoOps.me 3 | * Company: XIAOMI.COM 4 | * @author: 5 | * Xiaodong Pan 6 | * Wei Lai mPhones; 22 | Activity mActivity; 23 | 24 | public PhoneAdapter(final Activity activity, final List strings) { 25 | mActivity = activity; 26 | mPhones = strings; 27 | } 28 | 29 | @Override 30 | public int getCount() { 31 | return mPhones == null || mPhones.size() == 0 ? 0 : mPhones.size(); 32 | } 33 | 34 | @Override 35 | public Object getItem(int position) { 36 | return null; 37 | } 38 | 39 | @Override 40 | public long getItemId(int position) { 41 | return 0; 42 | } 43 | 44 | @Override 45 | public View getView(int position, View convertView, ViewGroup parent) { 46 | return null; 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /src/com/xiaomi/alertsystem/ui/PhoneNumberActivity.java: -------------------------------------------------------------------------------- 1 | /** 2 | * All rights Reserved, Designed By NoOps.me 3 | * Company: XIAOMI.COM 4 | * @author: 5 | * Xiaodong Pan 6 | * Wei Lai mPhoneList; 31 | private PhoneNumberAdapter mAdapter; 32 | private View mBack; 33 | 34 | @Override 35 | protected void onCreate(Bundle savedInstanceState) { 36 | super.onCreate(savedInstanceState); 37 | setContentView(R.layout.phone_number_layout); 38 | mListView = (ListView) findViewById(R.id.phone_list); 39 | mBack = findViewById(R.id.goback); 40 | mPhoneList= SmsManager.getAllPhone(); 41 | mAdapter =new PhoneNumberAdapter(mPhoneList); 42 | mListView.setAdapter(mAdapter); 43 | mBack.setOnClickListener(gobackListener); 44 | } 45 | 46 | private OnClickListener gobackListener = new OnClickListener() { 47 | 48 | @Override 49 | public void onClick(View v) { 50 | PhoneNumberActivity.this.finish(); 51 | } 52 | }; 53 | 54 | public class PhoneNumberAdapter extends BaseAdapter { 55 | List mList; 56 | PhoneNumberAdapter mAdapter; 57 | 58 | public PhoneNumberAdapter(List list) { 59 | super(); 60 | mAdapter = this; 61 | mList = list; 62 | } 63 | 64 | @Override 65 | public int getCount() { 66 | // TODO Auto-generated method stub 67 | return mList.size(); 68 | } 69 | 70 | @Override 71 | public Object getItem(int arg0) { 72 | // TODO Auto-generated method stub 73 | return null; 74 | } 75 | 76 | @Override 77 | public long getItemId(int pos) { 78 | // TODO Auto-generated method stub 79 | return 0; 80 | } 81 | 82 | @Override 83 | public View getView(int position, View convertView, ViewGroup parent) { 84 | if (convertView == null) { 85 | convertView = LayoutInflater.from(parent.getContext()).inflate( 86 | R.layout.phone_list_item, null); 87 | } 88 | TextView nameTextView = (TextView) convertView.findViewById(R.id.phone); 89 | View button = (View) convertView.findViewById(R.id.delete_button); 90 | String phone = mList.get(position); 91 | nameTextView.setText(phone); 92 | button.setTag(position); 93 | if(Constants.DEFAULT_PHONE.contains(phone)) 94 | button.setVisibility(View.INVISIBLE); 95 | else 96 | button.setVisibility(View.VISIBLE); 97 | 98 | button.setOnClickListener(new View.OnClickListener() { 99 | @Override 100 | public void onClick(View view) { 101 | int pos = (Integer) view.getTag(); 102 | String phone = mPhoneList.get(pos); 103 | mPhoneList.remove(pos); 104 | SmsManager.deletePhoneNumber(phone); 105 | mAdapter.notifyDataSetChanged(); 106 | } 107 | }); 108 | 109 | return convertView; 110 | } 111 | 112 | } 113 | 114 | } 115 | -------------------------------------------------------------------------------- /src/com/xiaomi/alertsystem/ui/PrefActivity.java: -------------------------------------------------------------------------------- 1 | /** 2 | * All rights Reserved, Designed By NoOps.me 3 | * Company: XIAOMI.COM 4 | * @author: 5 | * Xiaodong Pan 6 | * Wei Lai 6 | * Wei Lai mList; 29 | 30 | public SmsNotifyAdapter(Context context, List notify) { 31 | mContext = context; 32 | mList = notify; 33 | } 34 | 35 | @Override 36 | public int getCount() { 37 | if (mList != null) { 38 | return mList.size(); 39 | } 40 | return 0; 41 | } 42 | 43 | @Override 44 | public Object getItem(int position) { 45 | return null; 46 | } 47 | 48 | @Override 49 | public long getItemId(int position) { 50 | return 0; 51 | } 52 | 53 | @Override 54 | public View getView(int position, View convertView, ViewGroup parent) { 55 | if (convertView == null) { 56 | convertView = LayoutInflater.from(mContext).inflate( 57 | R.layout.sms_notify_item, null); 58 | } 59 | TextView text = (TextView) convertView.findViewById(R.id.pn_notify_name); 60 | TextView body = (TextView) convertView.findViewById(R.id.pn_notify_text); 61 | text.setText(mList.get(position).getName_cn()); 62 | body.setText(mList.get(position).getTextValue()); 63 | return convertView; 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /src/com/xiaomi/alertsystem/ui/SmsRulesActivity.java: -------------------------------------------------------------------------------- 1 | /** 2 | * All rights Reserved, Designed By NoOps.me 3 | * Company: XIAOMI.COM 4 | * @author: 5 | * Xiaodong Pan 6 | * Wei Lai mPhoneList; 38 | private PhoneNumberAdapter mAdapter; 39 | private View mBack; 40 | private View mAddRules; 41 | 42 | @Override 43 | protected void onCreate(Bundle savedInstanceState) { 44 | super.onCreate(savedInstanceState); 45 | setContentView(R.layout.sms_rules_layout); 46 | findViews(); 47 | setListens(); 48 | 49 | } 50 | 51 | private void findViews() { 52 | mListView = (ListView) findViewById(R.id.phone_list); 53 | mBack = findViewById(R.id.goback); 54 | mAddRules = findViewById(R.id.addrules); 55 | mPhoneList = SmsManager.getAllPhone(); 56 | } 57 | 58 | private void setListens() { 59 | mAdapter = new PhoneNumberAdapter(mPhoneList); 60 | mListView.setAdapter(mAdapter); 61 | mBack.setOnClickListener(gobackListener); 62 | mAddRules.setOnClickListener(addRulesListener); 63 | } 64 | 65 | private OnClickListener gobackListener = new OnClickListener() { 66 | 67 | @Override 68 | public void onClick(View v) { 69 | SmsRulesActivity.this.finish(); 70 | } 71 | }; 72 | 73 | private OnClickListener addRulesListener = new OnClickListener() { 74 | 75 | @Override 76 | public void onClick(View v) { 77 | addRulesDialog(); 78 | } 79 | }; 80 | 81 | private void addRulesDialog() { 82 | AlertDialog.Builder builder = new AlertDialog.Builder(this); 83 | final View v = LayoutInflater.from(this).inflate( 84 | R.layout.add_rules_dialog, null); 85 | final EditText startWithEdit = (EditText) v 86 | .findViewById(R.id.start_with); 87 | final EditText endWithEdit = (EditText) v 88 | .findViewById(R.id.edit_content); 89 | final EditText alertLevelEdit = (EditText) v 90 | .findViewById(R.id.alert_level); 91 | final EditText alertFlagEdit = (EditText) v 92 | .findViewById(R.id.alert_status); 93 | final EditText alertHostEdit = (EditText) v 94 | .findViewById(R.id.alert_host); 95 | final EditText alertIpEdit = (EditText) v.findViewById(R.id.alert_ip); 96 | final EditText alertContentEdit = (EditText) v 97 | .findViewById(R.id.alert_content); 98 | 99 | builder.setView(v); 100 | 101 | builder.setTitle(R.string.addrules); 102 | builder.setPositiveButton(R.string.ok, 103 | new DialogInterface.OnClickListener() { 104 | 105 | @Override 106 | public void onClick(DialogInterface dialog, int which) { 107 | // String phone = editText.getText().toString(); 108 | String alertStart = startWithEdit.getText().toString(); 109 | String alertEnd = endWithEdit.getText().toString(); 110 | String alertLevel = alertLevelEdit.getText().toString(); 111 | String alertFlag = alertFlagEdit.getText().toString(); 112 | String alertHost = alertHostEdit.getText().toString(); 113 | String alertIp = alertIpEdit.getText().toString(); 114 | String alertContent = alertContentEdit.getText() 115 | .toString(); 116 | 117 | if (TextUtils.isEmpty(alertStart) 118 | || TextUtils.isEmpty(alertEnd) 119 | || TextUtils.isEmpty(alertLevel) 120 | || TextUtils.isEmpty(alertFlag) 121 | || TextUtils.isEmpty(alertHost) 122 | || TextUtils.isEmpty(alertIp) 123 | || TextUtils.isEmpty(alertContent)) { 124 | Toast.makeText(mContext, R.string.notnull, 125 | Toast.LENGTH_SHORT).show(); 126 | return ; 127 | } 128 | 129 | // if (TextUtils.isEmpty(phone)) { 130 | // Toast.makeText(mContext, R.string.notnull, 131 | // Toast.LENGTH_SHORT).show(); 132 | // return; 133 | // } 134 | // 135 | // if (phone.length() > 20) { 136 | // Toast.makeText(mContext, R.string.toolong, 137 | // Toast.LENGTH_SHORT).show(); 138 | // return; 139 | // } 140 | // 141 | // List phoneList = SmsManager.getAllPhone(); 142 | // if (phoneList.contains(phone)) { 143 | // Toast.makeText(mContext, R.string.allreadyexist, 144 | // Toast.LENGTH_SHORT).show(); 145 | // return; 146 | // } 147 | // 148 | // // 添加到数据库 149 | // SmsManager.insertPhone(phone); 150 | // Toast.makeText(mContext, R.string.phoneaddsuss, 151 | // Toast.LENGTH_SHORT).show(); 152 | 153 | } 154 | }); 155 | builder.setNegativeButton(R.string.cancel, null); 156 | builder.show(); 157 | } 158 | 159 | public class PhoneNumberAdapter extends BaseAdapter { 160 | List mList; 161 | PhoneNumberAdapter mAdapter; 162 | 163 | public PhoneNumberAdapter(List list) { 164 | super(); 165 | mAdapter = this; 166 | mList = list; 167 | } 168 | 169 | @Override 170 | public int getCount() { 171 | // TODO Auto-generated method stub 172 | return mList.size(); 173 | } 174 | 175 | @Override 176 | public Object getItem(int arg0) { 177 | // TODO Auto-generated method stub 178 | return null; 179 | } 180 | 181 | @Override 182 | public long getItemId(int pos) { 183 | // TODO Auto-generated method stub 184 | return 0; 185 | } 186 | 187 | @Override 188 | public View getView(int position, View convertView, ViewGroup parent) { 189 | if (convertView == null) { 190 | convertView = LayoutInflater.from(parent.getContext()).inflate( 191 | R.layout.phone_list_item, null); 192 | } 193 | TextView nameTextView = (TextView) convertView 194 | .findViewById(R.id.phone); 195 | View button = (View) convertView.findViewById(R.id.delete_button); 196 | String phone = mList.get(position); 197 | nameTextView.setText(phone); 198 | button.setTag(position); 199 | if (Constants.DEFAULT_PHONE.contains(phone)) 200 | button.setVisibility(View.INVISIBLE); 201 | else 202 | button.setVisibility(View.VISIBLE); 203 | 204 | button.setOnClickListener(new View.OnClickListener() { 205 | @Override 206 | public void onClick(View view) { 207 | int pos = (Integer) view.getTag(); 208 | String phone = mPhoneList.get(pos); 209 | mPhoneList.remove(pos); 210 | SmsManager.deletePhoneNumber(phone); 211 | mAdapter.notifyDataSetChanged(); 212 | } 213 | }); 214 | 215 | return convertView; 216 | } 217 | 218 | } 219 | 220 | } 221 | -------------------------------------------------------------------------------- /src/com/xiaomi/alertsystem/ui/UsageActivity.java: -------------------------------------------------------------------------------- 1 | /** 2 | * All rights Reserved, Designed By NoOps.me 3 | * Company: XIAOMI.COM 4 | * @author: 5 | * Xiaodong Pan 6 | * Wei Lai void exe(AsyncTask asyncTask, Params... params) { 11 | if (Build.VERSION.SDK_INT >= 11) { 12 | asyncTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, params); 13 | } else { 14 | asyncTask.execute(params); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/com/xiaomi/alertsystem/utils/BootReceiver.java: -------------------------------------------------------------------------------- 1 | package com.xiaomi.alertsystem.utils; 2 | 3 | import android.content.BroadcastReceiver; 4 | import android.content.Context; 5 | import android.content.Intent; 6 | import android.util.Log; 7 | 8 | import com.xiaomi.alertsystem.ui.MainActivity; 9 | 10 | public class BootReceiver extends BroadcastReceiver { 11 | 12 | static final String action_boot = "android.intent.action.BOOT_COMPLETED"; 13 | 14 | @Override 15 | public void onReceive(Context context, Intent intent) { 16 | if (intent.getAction().equals(action_boot)) { 17 | Intent ootStartIntent = new Intent(context, MainActivity.class); 18 | ootStartIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 19 | context.startActivity(ootStartIntent); 20 | } 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /src/com/xiaomi/alertsystem/utils/CommonUtils.java: -------------------------------------------------------------------------------- 1 | package com.xiaomi.alertsystem.utils; 2 | 3 | import java.io.ByteArrayOutputStream; 4 | import java.io.File; 5 | import java.io.InputStream; 6 | import java.io.RandomAccessFile; 7 | import java.net.HttpURLConnection; 8 | import java.net.URL; 9 | import java.sql.Date; 10 | import java.text.SimpleDateFormat; 11 | import java.util.List; 12 | 13 | import org.json.JSONException; 14 | import org.json.JSONObject; 15 | 16 | import com.xiaomi.alertsystem.data.Constants; 17 | 18 | import android.content.Context; 19 | import android.content.Intent; 20 | import android.content.SharedPreferences; 21 | import android.content.pm.PackageInfo; 22 | import android.content.pm.PackageManager.NameNotFoundException; 23 | import android.database.sqlite.SQLiteDatabase; 24 | import android.net.Uri; 25 | import android.os.Environment; 26 | import android.os.Handler; 27 | import android.preference.PreferenceManager; 28 | import android.provider.BaseColumns; 29 | 30 | public class CommonUtils { 31 | private static String AGENT = "Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:17.0) Gecko/17.0 Firefox/17."; 32 | private static String defaultHome; 33 | 34 | public static boolean mkdir(String path) { 35 | File file = new File(path); 36 | if (file.isDirectory()) 37 | return true; 38 | else { 39 | boolean creadok = file.mkdirs(); 40 | if (creadok) { 41 | return true; 42 | } else { 43 | return false; 44 | } 45 | } 46 | } 47 | 48 | public static String getSdcardPath() { 49 | String sdcardPath = Environment.getExternalStorageDirectory() 50 | .getAbsolutePath(); 51 | return sdcardPath; 52 | } 53 | 54 | public static void setDefaultHome() { 55 | String sdcard = getSdcardPath(); 56 | String path = sdcard + "/" + Constants.APP_DIR + "/"; 57 | if (mkdir(path)) 58 | defaultHome = path; 59 | else 60 | defaultHome = Constants.DEFAULT_DIR; 61 | } 62 | 63 | public static String getDefaultHome() { 64 | if (defaultHome == null) 65 | setDefaultHome(); 66 | return defaultHome; 67 | } 68 | 69 | public static String getNowDate() { 70 | SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd"); 71 | Date date = new Date(System.currentTimeMillis()); 72 | return sf.format(date); 73 | } 74 | 75 | public static String readStream(InputStream inStream) throws Exception { 76 | ByteArrayOutputStream outStream = new ByteArrayOutputStream(); 77 | byte[] buffer = new byte[1024]; 78 | int len = -1; 79 | while ((len = inStream.read(buffer)) != -1) { 80 | outStream.write(buffer, 0, len); 81 | } 82 | outStream.close(); 83 | inStream.close(); 84 | return outStream.toString(); 85 | } 86 | 87 | public static String execUrl(String uri) { 88 | String res = ""; 89 | try { 90 | URL url = new URL(uri); 91 | HttpURLConnection conn = (HttpURLConnection) url.openConnection(); 92 | conn.setRequestProperty("User-Agent", AGENT); 93 | 94 | res = readStream(conn.getInputStream()); 95 | } catch (Exception e) { 96 | e.printStackTrace(); 97 | res = ""; 98 | } 99 | return res; 100 | } 101 | 102 | public static boolean download(String uri, String filePath) { 103 | try { 104 | URL url = new URL(uri); 105 | HttpURLConnection conn = (HttpURLConnection) url.openConnection(); 106 | conn.setRequestProperty("User-Agent", AGENT); 107 | readStreamToFile(conn.getInputStream(), filePath); 108 | } catch (Exception e) { 109 | e.printStackTrace(); 110 | return false; 111 | } 112 | return true; 113 | } 114 | 115 | public static void readStreamToFile(InputStream inStream, String filePath) 116 | throws Exception { 117 | File file = new File(filePath + ".wei"); 118 | RandomAccessFile outStream = new RandomAccessFile(file, "rw"); 119 | outStream.seek(0); 120 | byte[] buffer = new byte[1024]; 121 | int len = -1; 122 | while ((len = inStream.read(buffer)) != -1) { 123 | outStream.write(buffer, 0, len); 124 | } 125 | outStream.close(); 126 | inStream.close(); 127 | file.renameTo(new File(filePath)); 128 | return; 129 | } 130 | 131 | public static void createTable(final SQLiteDatabase db, 132 | final String tableName, final String[] columnsDefinition) { 133 | String queryStr = "CREATE TABLE " + tableName + "(" + BaseColumns._ID 134 | + " INTEGER PRIMARY KEY ,"; 135 | // Add the columns now, Increase by 2 136 | for (int i = 0; i < (columnsDefinition.length - 1); i += 2) { 137 | if (i != 0) { 138 | queryStr += ","; 139 | } 140 | queryStr += columnsDefinition[i] + " " + columnsDefinition[i + 1]; 141 | } 142 | 143 | queryStr += ");"; 144 | 145 | db.execSQL(queryStr); 146 | } 147 | 148 | public static String getSettingString(final Context context, 149 | final String key, final String defaultValue) { 150 | final SharedPreferences settings = PreferenceManager 151 | .getDefaultSharedPreferences(context); 152 | return settings.getString(key, defaultValue); 153 | } 154 | 155 | public static void setSettingString(final Context context, 156 | final String key, final String value) { 157 | SharedPreferences setting = PreferenceManager 158 | .getDefaultSharedPreferences(context); 159 | SharedPreferences.Editor editor = setting.edit(); 160 | editor.putString(key, value); 161 | editor.commit(); 162 | } 163 | 164 | public static int getSettingInt(final Context context, final String key, 165 | final int defaultValue) { 166 | final SharedPreferences settings = PreferenceManager 167 | .getDefaultSharedPreferences(context); 168 | return settings.getInt(key, defaultValue); 169 | } 170 | 171 | public static void setSettingInt(final Context context, final String key, 172 | final int value) { 173 | SharedPreferences setting = PreferenceManager 174 | .getDefaultSharedPreferences(context); 175 | SharedPreferences.Editor editor = setting.edit(); 176 | editor.putInt(key, value); 177 | editor.commit(); 178 | } 179 | 180 | public static String join(List list, String conjunction) { 181 | StringBuilder sb = new StringBuilder(); 182 | boolean first = true; 183 | for (String item : list) { 184 | if (first) 185 | first = false; 186 | else 187 | sb.append(conjunction); 188 | sb.append(item); 189 | } 190 | return sb.toString(); 191 | } 192 | 193 | public static String join(String[] list, String conjunction) { 194 | StringBuilder sb = new StringBuilder(); 195 | boolean first = true; 196 | for (String item : list) { 197 | if (first) 198 | first = false; 199 | else 200 | sb.append(conjunction); 201 | sb.append(item); 202 | } 203 | return sb.toString(); 204 | } 205 | 206 | public static void sendIconCountMessage(Context mContext, int num) { 207 | Intent i = new Intent( 208 | "android.intent.action.APPLICATION_MESSAGE_UPDATE"); 209 | i.putExtra("android.intent.extra.update_application_component_name", 210 | "com.xiaomi.alertsystem/.ui.LogoActivity"); 211 | String s = ""; 212 | if (num > 0) { 213 | if (num > 99) 214 | s = "99+"; 215 | else 216 | s = "" + num; 217 | i.putExtra("android.intent.extra.update_application_message_text", 218 | s); 219 | } 220 | mContext.sendBroadcast(i); 221 | } 222 | } 223 | -------------------------------------------------------------------------------- /src/com/xiaomi/alertsystem/utils/HandleSmsIntentService.java: -------------------------------------------------------------------------------- 1 | package com.xiaomi.alertsystem.utils; 2 | 3 | import android.app.Service; 4 | import android.content.Intent; 5 | import android.content.IntentFilter; 6 | import android.os.IBinder; 7 | import android.util.Log; 8 | 9 | import com.xiaomi.alertsystem.data.Constants; 10 | 11 | 12 | public class HandleSmsIntentService extends Service { 13 | 14 | public static final String TAG = "HandleSmsIntentService"; 15 | public static final String StringKey = "sms"; 16 | private SmsBroadcastReceiver mSmsBroadcastReceiver; 17 | private IntentFilter mIntentFilter; 18 | 19 | @Override 20 | public void onCreate() { 21 | Log.d(TAG, "service created"); 22 | super.onCreate(); 23 | mSmsBroadcastReceiver = new SmsBroadcastReceiver(); 24 | mIntentFilter = new IntentFilter(); 25 | mIntentFilter.addAction(Constants.SMS_RECEIVED); 26 | //=================设置优先级别=================== 27 | mIntentFilter.setPriority(2147483647); 28 | registerReceiver(mSmsBroadcastReceiver, mIntentFilter); 29 | } 30 | 31 | @Override 32 | public int onStartCommand(Intent intent, int flags, int startId){ 33 | Log.d(TAG, "onStartCommand"); 34 | return START_STICKY; 35 | } 36 | 37 | @Override 38 | public void onDestroy() { 39 | Log.d(TAG, "service destroy"); 40 | super.onDestroy(); 41 | if(mSmsBroadcastReceiver != null){ 42 | unregisterReceiver(mSmsBroadcastReceiver); 43 | } 44 | } 45 | 46 | @Override 47 | public IBinder onBind(Intent intent) { 48 | return null; 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /src/com/xiaomi/alertsystem/utils/NotificationUtils.java: -------------------------------------------------------------------------------- 1 | 2 | package com.xiaomi.alertsystem.utils; 3 | 4 | import android.app.Notification; 5 | import android.app.NotificationManager; 6 | import android.app.PendingIntent; 7 | import android.content.Context; 8 | import android.content.Intent; 9 | import android.graphics.Color; 10 | import android.os.Vibrator; 11 | 12 | import com.xiaomi.alertsystem.R; 13 | 14 | public class NotificationUtils { 15 | private static final int NOTIFICATION_SOUND_INTERVAL_MSEC = 5 * 1000; // 5秒钟内不要再重响 16 | 17 | private static long mLastSoundTime = 0; 18 | 19 | public static void doNotify(Intent notificationIntent, Context context, 20 | CharSequence tickerText, CharSequence contentTitle, CharSequence contentText, 21 | boolean notificationSound, boolean vibrate, int buddyId, int id) { 22 | doNotify(notificationIntent, context, 23 | tickerText, contentTitle, contentText, 24 | notificationSound, vibrate, buddyId, id, id); 25 | } 26 | 27 | 28 | public static void doNotify(Intent notificationIntent, Context context, 29 | CharSequence tickerText, CharSequence contentTitle, CharSequence contentText, 30 | boolean notificationSound, boolean vibrate, int buddyId, int id, int requestCode) { 31 | PendingIntent contentIntent = PendingIntent.getActivity(context, requestCode, notificationIntent, 32 | PendingIntent.FLAG_UPDATE_CURRENT); 33 | 34 | Notification notification = new Notification(R.drawable.smiley_tab_mao_pressed, tickerText, 35 | System.currentTimeMillis()); 36 | 37 | notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent); 38 | notification.flags |= Notification.FLAG_AUTO_CANCEL; 39 | 40 | long now = System.currentTimeMillis(); 41 | if (now - mLastSoundTime > NOTIFICATION_SOUND_INTERVAL_MSEC) { 42 | 43 | if (notificationSound) { 44 | notification.defaults |= Notification.DEFAULT_SOUND; 45 | } 46 | 47 | if (vibrate) { 48 | Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE); 49 | if (vibrator != null) { 50 | vibrator.vibrate(500); 51 | } 52 | } 53 | notification.defaults |= Notification.DEFAULT_LIGHTS; 54 | notification.flags |= Notification.FLAG_SHOW_LIGHTS; 55 | notification.ledARGB = Color.GREEN; 56 | notification.ledOnMS = 7; 57 | notification.ledOffMS = 15 * 1000; 58 | 59 | mLastSoundTime = now; 60 | } 61 | 62 | NotificationManager notifManager = (NotificationManager) context 63 | .getSystemService(Context.NOTIFICATION_SERVICE); 64 | notifManager.notify(id, notification); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/com/xiaomi/alertsystem/utils/ReadFileContent.java: -------------------------------------------------------------------------------- 1 | package com.xiaomi.alertsystem.utils; 2 | 3 | import android.content.Context; 4 | 5 | import java.io.BufferedReader; 6 | import java.io.IOException; 7 | import java.io.InputStream; 8 | import java.io.InputStreamReader; 9 | import java.util.ArrayList; 10 | import java.util.List; 11 | 12 | public class ReadFileContent { 13 | 14 | public static InputStream getAssetsInputStream(final Context context, 15 | final String filename) { 16 | InputStream stream = null; 17 | try { 18 | stream = context.getAssets().open(filename); 19 | } catch (IOException e) { 20 | e.printStackTrace(); 21 | } 22 | return stream; 23 | } 24 | 25 | public static List getAssetsTxtLine(final InputStream inputStream) { 26 | List list = new ArrayList(); 27 | BufferedReader reader = new BufferedReader(new InputStreamReader( 28 | inputStream)); 29 | 30 | String line = null; 31 | try { 32 | while ((line = reader.readLine()) != null) { 33 | list.add(line.trim()); 34 | } 35 | } catch (IOException e) { 36 | e.printStackTrace(); 37 | } 38 | 39 | return list; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/com/xiaomi/alertsystem/utils/ReadLocalSmsHelper.java: -------------------------------------------------------------------------------- 1 | package com.xiaomi.alertsystem.utils; 2 | 3 | import android.content.ContentResolver; 4 | import android.content.Context; 5 | import android.database.Cursor; 6 | import android.net.Uri; 7 | 8 | import com.xiaomi.alertsystem.data.Sms; 9 | 10 | import java.util.ArrayList; 11 | import java.util.List; 12 | 13 | public class ReadLocalSmsHelper { 14 | public final static String SMS_URI_ALL = "content://sms/"; 15 | public final static String SMS_URI_INBOX = "content://sms/inbox"; 16 | public final static String SMS_URI_SEND = "content://sms/sent"; 17 | public final static String SMS_URI_DRAFT = "content://sms/draft"; 18 | public final static String SMS_URI_OUTBOX = "content://sms/outbox"; 19 | public final static String SMS_URI_FAILED = "content://sms/failed"; 20 | public final static String SMS_URI_QUEUED = "content://sms/queued"; 21 | 22 | public static class SmsColoumn { 23 | public final static String id = "_id"; 24 | public final static String address = "address"; 25 | public final static String person = "person"; 26 | public final static String body = "body"; 27 | public final static String date = "date"; 28 | public final static String type = "type"; 29 | } 30 | 31 | public final static String[] sProjection = new String[]{SmsColoumn.id, 32 | SmsColoumn.address, SmsColoumn.person, SmsColoumn.body, 33 | SmsColoumn.date, SmsColoumn.type}; 34 | 35 | public static List querySms(final Context context, final Uri uri, 36 | final String[] projection) { 37 | List sms = null; 38 | if (uri == null) { 39 | return sms; 40 | } 41 | 42 | ContentResolver contentResolver = context.getContentResolver(); 43 | try { 44 | Cursor cursor = contentResolver.query(uri, projection, null, null, 45 | "date desc"); 46 | sms = parseResult(cursor); 47 | } catch (Exception e) { 48 | } 49 | return sms; 50 | } 51 | 52 | public static List parseResult(Cursor cur) { 53 | List sms = new ArrayList(); 54 | if (cur.moveToFirst()) { 55 | int personColumn = cur.getColumnIndex(SmsColoumn.person); 56 | int addressColumn = cur.getColumnIndex(SmsColoumn.address); 57 | int bodyColumn = cur.getColumnIndex(SmsColoumn.body); 58 | int typeColumn = cur.getColumnIndex(SmsColoumn.type); 59 | int dateColumn = cur.getColumnIndex(SmsColoumn.date); 60 | int idColumn = cur.getColumnIndex(SmsColoumn.id); 61 | 62 | do { 63 | Sms newSms = new Sms(); 64 | newSms.mId = cur.getLong(idColumn); 65 | newSms.mAddress = cur.getString(addressColumn); 66 | newSms.mBody = cur.getString(bodyColumn); 67 | newSms.mPerson = cur.getString(personColumn); 68 | newSms.mTimeStamp = cur.getLong(dateColumn); 69 | newSms.mType = cur.getString(typeColumn); 70 | sms.add(newSms); 71 | } while (cur.moveToNext()); 72 | } 73 | return sms; 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /src/com/xiaomi/alertsystem/utils/SmsBroadcastReceiver.java: -------------------------------------------------------------------------------- 1 | package com.xiaomi.alertsystem.utils; 2 | 3 | import java.util.List; 4 | 5 | import android.content.BroadcastReceiver; 6 | import android.content.Context; 7 | import android.content.Intent; 8 | import android.os.Bundle; 9 | import android.telephony.SmsMessage; 10 | import android.text.TextUtils; 11 | import android.util.Log; 12 | 13 | import com.xiaomi.alertsystem.data.AlertManager; 14 | import com.xiaomi.alertsystem.data.AlertMeta; 15 | import com.xiaomi.alertsystem.data.Constants; 16 | import com.xiaomi.alertsystem.data.NotifyMeta; 17 | import com.xiaomi.alertsystem.ui.MainActivity; 18 | 19 | public class SmsBroadcastReceiver extends BroadcastReceiver { 20 | private static final String TAG = "SmsBroadcastReceiver"; 21 | private static final String strACT = "android.provider.Telephony.SMS_RECEIVED"; 22 | 23 | @Override 24 | public void onReceive(Context context, Intent intent) { 25 | Log.d(TAG, "sms intent received:" + intent.getAction()); 26 | if (intent.getAction().equals(strACT)) { 27 | Bundle bundle = intent.getExtras(); 28 | if (bundle != null) { 29 | StringBuilder sb = new StringBuilder(); 30 | String address = null; 31 | Object[] pdus = (Object[]) bundle.get("pdus"); 32 | SmsMessage[] msg = new SmsMessage[pdus.length]; 33 | for (int i = 0; i < pdus.length; i++) { 34 | msg[i] = SmsMessage.createFromPdu((byte[]) pdus[i]); 35 | } 36 | for (SmsMessage currMsg : msg) { 37 | address = currMsg.getDisplayOriginatingAddress(); 38 | sb.append(currMsg.getDisplayMessageBody()); 39 | } 40 | Log.d(TAG, "================================="); 41 | Log.d(TAG, "====sms:"+sb.toString()); 42 | Log.d(TAG, address); 43 | Log.d(TAG, "================================="); 44 | 45 | List phoneList = SmsManager.getAllPhone(); 46 | 47 | 48 | if (phoneList.contains(address) || AlertManager.matchAlert(sb.toString())){ 49 | List list = AlertManager.getAlertManager().parse( 50 | sb.toString()); 51 | AlertMeta alertMeta = AlertManager.getAlertManager().format(list); 52 | if (alertMeta != null) { 53 | alertMeta.mMsg = sb.toString(); 54 | SmsManager.insertAlertSms(alertMeta); 55 | doNotifyMsg(context, alertMeta, sb.toString()); 56 | //只有在拦截列表中,并且分解成功了,才abort 57 | int mSmsUnReadNum = SmsManager.getAlertUnReadNum(); 58 | CommonUtils.sendIconCountMessage(context, mSmsUnReadNum); 59 | this.abortBroadcast(); 60 | } 61 | } 62 | 63 | } 64 | } 65 | } 66 | 67 | private void doNotifyMsg(Context c, AlertMeta meta, String sb) { 68 | if (TextUtils.equals(AlertMeta.ALERT_LEVEL_P0, meta.mAlertLevel)) { 69 | checkPrefence(c, AlertMeta.ALERT_LEVEL_P0, sb); 70 | } else if (TextUtils.equals(AlertMeta.ALERT_LEVEL_P1, meta.mAlertLevel)) { 71 | checkPrefence(c, AlertMeta.ALERT_LEVEL_P1, sb); 72 | } else if (TextUtils.equals(AlertMeta.ALERT_LEVEL_P2, meta.mAlertLevel)) { 73 | checkPrefence(c, AlertMeta.ALERT_LEVEL_P2, sb); 74 | } else if (TextUtils.equals(AlertMeta.ALERT_LEVEL_P3, meta.mAlertLevel)) { 75 | checkPrefence(c, AlertMeta.ALERT_LEVEL_P3, sb); 76 | } else { 77 | final Intent intent = new Intent(c, MainActivity.class); 78 | NotificationUtils.doNotify(intent, c, sb, null, sb, true, true, 0, 0, 0); 79 | } 80 | } 81 | 82 | private int getPageIndex(String key){ 83 | int index = 0; 84 | 85 | for(int i = 0; i< Constants.NOTIFICATION_LEVEL.size(); i++){ 86 | if(key!=null && key.equals(Constants.NOTIFICATION_LEVEL.get(i))) 87 | index = i; 88 | } 89 | return index; 90 | } 91 | 92 | private void checkPrefence(final Context c, final String key, 93 | final String sb) { 94 | NotifyMeta meta = new NotifyMeta(key, c); 95 | int type = meta.getValue(); 96 | 97 | boolean sound = false; 98 | boolean vibrate = false; 99 | boolean bubble = false; 100 | 101 | if (type == Constants.NOTIFICATION_SOUND_VIBRATE) { 102 | sound = true; 103 | vibrate = true; 104 | } else if (type == Constants.NOTIFICATION_SOUND) { 105 | sound = true; 106 | } else if (type == Constants.NOTIFICATION_VIBRATE) { 107 | vibrate = true; 108 | } else if (type == Constants.NOTIFICATION_BUBBLE) { 109 | bubble = true; 110 | } 111 | 112 | //设置跳转页 113 | Intent intent = new Intent(c, MainActivity.class); 114 | Bundle bundle = new Bundle(); 115 | int index = getPageIndex(key); 116 | bundle.putInt("PageIndex", index); 117 | intent.putExtras(bundle); 118 | 119 | if (!bubble) { 120 | NotificationUtils.doNotify(intent, c, 121 | sb, null, sb, sound, vibrate, 0, 0, 0); 122 | } else { 123 | NotificationUtils.doNotify(intent, c, sb, null, sb, false, false, 0, 124 | 0, 0); 125 | } 126 | } 127 | } 128 | -------------------------------------------------------------------------------- /src/com/xiaomi/alertsystem/utils/ThreadUpdateApp.java: -------------------------------------------------------------------------------- 1 | package com.xiaomi.alertsystem.utils; 2 | 3 | import java.io.File; 4 | 5 | import org.json.JSONException; 6 | import org.json.JSONObject; 7 | 8 | import android.content.Context; 9 | import android.content.Intent; 10 | import android.content.pm.PackageInfo; 11 | import android.content.pm.PackageManager.NameNotFoundException; 12 | import android.net.Uri; 13 | import android.os.Handler; 14 | 15 | import com.xiaomi.alertsystem.data.Constants; 16 | 17 | public class ThreadUpdateApp extends Thread { 18 | private String mUrl; 19 | private Context mContext; 20 | private Handler mHandler; 21 | 22 | public ThreadUpdateApp(Context context, Handler handler) { 23 | mContext = context; 24 | mHandler = handler; 25 | 26 | } 27 | 28 | public void run() { 29 | PackageInfo pInfo = null; 30 | try { 31 | pInfo = mContext.getPackageManager().getPackageInfo(mContext.getPackageName(), 0); 32 | } catch (NameNotFoundException e1) { 33 | // TODO Auto-generated catch block 34 | e1.printStackTrace(); 35 | } 36 | String version = pInfo.versionName; 37 | String ret = CommonUtils.execUrl(Constants.URL_UPDATE + version); 38 | int stat = 0; 39 | String url = ""; 40 | try { 41 | JSONObject json = new JSONObject(ret); 42 | url = json.getString("url"); 43 | stat = json.getInt("stat"); 44 | mUrl = url; 45 | } catch (JSONException e) { 46 | mHandler.sendEmptyMessage(Constants.MSG_VER_ERROR); 47 | e.printStackTrace(); 48 | return; 49 | } 50 | 51 | if (stat == 1) { 52 | mHandler.sendEmptyMessage(Constants.MSG_VER_UPDATE); 53 | String today = CommonUtils.getNowDate(); 54 | String filePath = CommonUtils.getDefaultHome() + today + ".apk"; 55 | CommonUtils.download(mUrl, filePath); 56 | Uri uri = Uri.fromFile(new File(filePath)); // 这里是APK路径 57 | Intent intent = new Intent(Intent.ACTION_VIEW); 58 | intent.setDataAndType(uri, 59 | "application/vnd.android.package-archive"); 60 | mContext.startActivity(intent); 61 | } else { 62 | mHandler.sendEmptyMessage(Constants.MSG_VER_NONEED); 63 | } 64 | } 65 | } --------------------------------------------------------------------------------