├── .classpath
├── .gitignore
├── .project
├── .settings
├── org.eclipse.core.resources.prefs
└── org.eclipse.jdt.core.prefs
├── AndroidManifest.xml
├── LICENSE
├── README.md
├── ic_launcher-web.png
├── libs
├── android-support-v4.jar
└── eventbus.jar
├── proguard-project.txt
├── project.properties
├── res
├── drawable-hdpi
│ ├── acm_inputbox.9.png
│ ├── arrow_right.png
│ ├── h001.png
│ ├── ic_action_search.png
│ ├── ic_launcher.png
│ ├── msp_edit_warning.png
│ └── search.png
├── drawable-ldpi
│ └── ic_launcher.png
├── drawable-mdpi
│ ├── ic_action_search.png
│ └── ic_launcher.png
├── drawable-xhdpi
│ ├── ic_action_search.png
│ └── ic_launcher.png
├── drawable
│ ├── ll_top_bg.xml
│ ├── login_picture_bg.xml
│ ├── qq_constact_all.xml
│ ├── qq_constact_font.xml
│ └── qq_constact_group.xml
├── layout
│ ├── activity_main.xml
│ ├── layout_netbar.xml
│ └── news_item.xml
├── menu
│ └── activity_main.xml
├── values-v11
│ └── styles.xml
├── values-v14
│ └── styles.xml
└── values
│ ├── colors.xml
│ ├── ids.xml
│ ├── strings.xml
│ └── styles.xml
└── src
└── com
└── finddreams
├── bean
└── RecentChat.java
├── netstate
├── MainActivity.java
├── NetEvent.java
└── NewsAdapter.java
├── network
└── NetUtils.java
└── receiver
└── NetReceiver.java
/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Built application files
2 | *.apk
3 | *.ap_
4 |
5 | # Files for the Dalvik VM
6 | *.dex
7 |
8 | # Java class files
9 | *.class
10 |
11 | # Generated files
12 | bin/
13 | gen/
14 |
15 | # Gradle files
16 | .gradle/
17 | build/
18 |
19 | # Local configuration file (sdk path, etc)
20 | local.properties
21 |
22 | # Proguard folder generated by Eclipse
23 | proguard/
24 |
25 | # Log Files
26 | *.log
27 |
--------------------------------------------------------------------------------
/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | NetTest
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 | eclipse.preferences.version=1
2 | encoding/=UTF-8
3 |
--------------------------------------------------------------------------------
/.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 |
--------------------------------------------------------------------------------
/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
5 |
6 |
9 |
10 |
11 |
12 |
13 |
17 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/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 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "{}"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright {yyyy} {name of copyright owner}
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
203 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # NetStateBar
2 |
3 | 关注finddreams,一起分享,一起进步:
4 | http://blog.csdn.net/finddreams/article/details/44647843
5 |
6 | 我们都知道手机QQ上有这样一个功能,就是当我们断网,没有网络的时候,聊天列表的上方就会出现一个警告的横条,上面写着"世界上最遥远的距离就是没网,检查设置",然后点击这个横条就会跳转到设置网络的界面,等我们把网络设置好了之后,这个警告横条也就自动的消失了。
7 | 今天咱们就来模仿以下这样的功能是如何实现的,话不多少,有图有真相,请看:
8 | 
9 |
10 |
--------------------------------------------------------------------------------
/ic_launcher-web.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/finddreams/NetStateBar/a03e23d0e11ab4fae29ada807b1a7f9bf8133bc2/ic_launcher-web.png
--------------------------------------------------------------------------------
/libs/android-support-v4.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/finddreams/NetStateBar/a03e23d0e11ab4fae29ada807b1a7f9bf8133bc2/libs/android-support-v4.jar
--------------------------------------------------------------------------------
/libs/eventbus.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/finddreams/NetStateBar/a03e23d0e11ab4fae29ada807b1a7f9bf8133bc2/libs/eventbus.jar
--------------------------------------------------------------------------------
/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/acm_inputbox.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/finddreams/NetStateBar/a03e23d0e11ab4fae29ada807b1a7f9bf8133bc2/res/drawable-hdpi/acm_inputbox.9.png
--------------------------------------------------------------------------------
/res/drawable-hdpi/arrow_right.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/finddreams/NetStateBar/a03e23d0e11ab4fae29ada807b1a7f9bf8133bc2/res/drawable-hdpi/arrow_right.png
--------------------------------------------------------------------------------
/res/drawable-hdpi/h001.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/finddreams/NetStateBar/a03e23d0e11ab4fae29ada807b1a7f9bf8133bc2/res/drawable-hdpi/h001.png
--------------------------------------------------------------------------------
/res/drawable-hdpi/ic_action_search.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/finddreams/NetStateBar/a03e23d0e11ab4fae29ada807b1a7f9bf8133bc2/res/drawable-hdpi/ic_action_search.png
--------------------------------------------------------------------------------
/res/drawable-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/finddreams/NetStateBar/a03e23d0e11ab4fae29ada807b1a7f9bf8133bc2/res/drawable-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/res/drawable-hdpi/msp_edit_warning.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/finddreams/NetStateBar/a03e23d0e11ab4fae29ada807b1a7f9bf8133bc2/res/drawable-hdpi/msp_edit_warning.png
--------------------------------------------------------------------------------
/res/drawable-hdpi/search.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/finddreams/NetStateBar/a03e23d0e11ab4fae29ada807b1a7f9bf8133bc2/res/drawable-hdpi/search.png
--------------------------------------------------------------------------------
/res/drawable-ldpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/finddreams/NetStateBar/a03e23d0e11ab4fae29ada807b1a7f9bf8133bc2/res/drawable-ldpi/ic_launcher.png
--------------------------------------------------------------------------------
/res/drawable-mdpi/ic_action_search.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/finddreams/NetStateBar/a03e23d0e11ab4fae29ada807b1a7f9bf8133bc2/res/drawable-mdpi/ic_action_search.png
--------------------------------------------------------------------------------
/res/drawable-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/finddreams/NetStateBar/a03e23d0e11ab4fae29ada807b1a7f9bf8133bc2/res/drawable-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/res/drawable-xhdpi/ic_action_search.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/finddreams/NetStateBar/a03e23d0e11ab4fae29ada807b1a7f9bf8133bc2/res/drawable-xhdpi/ic_action_search.png
--------------------------------------------------------------------------------
/res/drawable-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/finddreams/NetStateBar/a03e23d0e11ab4fae29ada807b1a7f9bf8133bc2/res/drawable-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/res/drawable/ll_top_bg.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/res/drawable/login_picture_bg.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/res/drawable/qq_constact_all.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/res/drawable/qq_constact_font.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/res/drawable/qq_constact_group.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
6 |
7 |
11 |
12 |
21 |
22 |
30 |
31 |
39 |
40 |
47 |
48 |
52 |
53 |
57 |
58 |
59 |
60 |
63 |
64 |
73 |
74 |
80 |
81 |
86 |
87 |
88 |
89 |
95 |
96 |
--------------------------------------------------------------------------------
/res/layout/layout_netbar.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
17 |
18 |
28 |
29 |
35 |
36 |
--------------------------------------------------------------------------------
/res/layout/news_item.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
10 |
11 |
21 |
22 |
33 |
34 |
43 |
44 |
52 |
53 |
63 |
64 |
65 |
66 |
--------------------------------------------------------------------------------
/res/menu/activity_main.xml:
--------------------------------------------------------------------------------
1 |
7 |
--------------------------------------------------------------------------------
/res/values-v11/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/res/values-v14/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #F9F9F9
4 | #499BF7
5 | #ffffff
6 | #000000
7 | #FFFF99
8 |
9 |
--------------------------------------------------------------------------------
/res/values/ids.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | NetStateBar
4 | Hello world!
5 | Settings
6 | NetStateBar
7 | 分组
8 | 全部
9 | 开心一刻
10 | 好好学习,天天向上
11 | TODO
12 | 世界上最遥远的距离就是没网,检查设置
13 | 搜索
14 |
15 |
--------------------------------------------------------------------------------
/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
12 |
13 |
21 |
25 |
--------------------------------------------------------------------------------
/src/com/finddreams/bean/RecentChat.java:
--------------------------------------------------------------------------------
1 | package com.finddreams.bean;
2 | /**
3 | * @Description:消息bean
4 | * @author http://blog.csdn.net/finddreams
5 | */
6 | public class RecentChat {
7 | private String userName;
8 | private String userFeel;
9 | private String userTime;
10 | private String imgPath;
11 | public RecentChat(String userName, String userFeel, String userTime, String img) {
12 | super();
13 | this.userName = userName;
14 | this.userFeel = userFeel;
15 | this.userTime = userTime;
16 | this.imgPath = img;
17 | }
18 | public String getUserName() {
19 | return userName;
20 | }
21 | public void setUserName(String userName) {
22 | this.userName = userName;
23 | }
24 | public String getUserFeel() {
25 | return userFeel;
26 | }
27 | public void setUserFeel(String userFeel) {
28 | this.userFeel = userFeel;
29 | }
30 | public String getUserTime() {
31 | return userTime;
32 | }
33 | public void setUserTime(String userTime) {
34 | this.userTime = userTime;
35 | }
36 | public String getImgPath() {
37 | return imgPath;
38 | }
39 | public void setImgPath(String img) {
40 | this.imgPath = img;
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/src/com/finddreams/netstate/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.finddreams.netstate;
2 |
3 | import java.util.LinkedList;
4 |
5 | import android.app.Activity;
6 | import android.content.IntentFilter;
7 | import android.net.ConnectivityManager;
8 | import android.os.Bundle;
9 | import android.view.View;
10 | import android.view.View.OnClickListener;
11 | import android.widget.ListView;
12 | import android.widget.RelativeLayout;
13 |
14 | import com.example.nettest.R;
15 | import com.finddreams.bean.RecentChat;
16 | import com.finddreams.network.NetUtils;
17 | import com.finddreams.receiver.NetReceiver;
18 |
19 | import de.greenrobot.event.EventBus;
20 |
21 | /**
22 | * @Description:网络状态条的显示控制
23 | * @author http://blog.csdn.net/finddreams
24 | */
25 | public class MainActivity extends Activity {
26 |
27 | private NewsAdapter adapter;
28 | private LinkedList chats = new LinkedList();
29 | private NetReceiver mReceiver;
30 | private ListView listView;
31 | private RelativeLayout no_network_rl;
32 |
33 | @Override
34 | public void onCreate(Bundle savedInstanceState) {
35 | super.onCreate(savedInstanceState);
36 | setContentView(R.layout.activity_main);
37 | initReceive();
38 | initView();
39 | EventBus.getDefault().register(this);
40 |
41 | }
42 |
43 | private void initView() {
44 |
45 | chats.add(new RecentChat("章泽天", "好好学习天天向上", "16:30", ""));
46 | chats.add(new RecentChat("宋茜", "好好学习天天向上", "17:30", ""));
47 | chats.add(new RecentChat("韩孝珠", "好好学习天天向上", "昨天", ""));
48 | chats.add(new RecentChat("景甜", "好好学习天天向上", "星期一", ""));
49 | chats.add(new RecentChat("刘亦菲", "好好学习天天向上", "17:30", ""));
50 | chats.add(new RecentChat("邓紫棋", "好好学习天天向上", "星期一", ""));
51 | listView = (ListView) findViewById(R.id.lv_news);
52 | adapter = new NewsAdapter(this, chats, listView);
53 | listView.setAdapter(adapter);
54 | no_network_rl = (RelativeLayout) findViewById(R.id.net_view_rl);
55 | }
56 |
57 | private void initReceive() {
58 | mReceiver = new NetReceiver();
59 | IntentFilter mFilter = new IntentFilter();
60 | mFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
61 | registerReceiver(mReceiver, mFilter);
62 | }
63 |
64 | public void onEventMainThread(NetEvent event) {
65 |
66 | setNetState(event.isNet());
67 | }
68 |
69 | public void setNetState(boolean netState) {
70 |
71 | if (no_network_rl != null) {
72 | no_network_rl.setVisibility(netState ? View.GONE : View.VISIBLE);
73 | no_network_rl.setOnClickListener(new OnClickListener() {
74 | @Override
75 | public void onClick(View arg0) {
76 | NetUtils.startToSettings(MainActivity.this);
77 | }
78 | });
79 | }
80 | }
81 |
82 | @Override
83 | protected void onDestroy() {
84 | unregisterReceiver(mReceiver);
85 | EventBus.getDefault().unregister(this);
86 | super.onDestroy();
87 | }
88 | }
89 |
--------------------------------------------------------------------------------
/src/com/finddreams/netstate/NetEvent.java:
--------------------------------------------------------------------------------
1 | package com.finddreams.netstate;
2 |
3 |
4 | /**
5 | * @Description:用于网络的事件
6 | * @author http://blog.csdn.net/finddreams
7 | */
8 | public class NetEvent {
9 | public boolean isNet;
10 |
11 | public NetEvent(boolean isNet) {
12 |
13 | this.isNet = isNet;
14 | }
15 |
16 | public boolean isNet() {
17 | return isNet;
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/src/com/finddreams/netstate/NewsAdapter.java:
--------------------------------------------------------------------------------
1 | package com.finddreams.netstate;
2 |
3 | import java.lang.ref.SoftReference;
4 | import java.util.HashMap;
5 | import java.util.List;
6 |
7 | import android.content.Context;
8 | import android.graphics.Bitmap;
9 | import android.view.View;
10 | import android.view.ViewGroup;
11 | import android.widget.BaseAdapter;
12 | import android.widget.ImageView;
13 | import android.widget.ListView;
14 | import android.widget.TextView;
15 |
16 | import com.example.nettest.R;
17 | import com.finddreams.bean.RecentChat;
18 | /**
19 | * @Description:消息显示的adapter
20 | * @author http://blog.csdn.net/finddreams
21 | */
22 | public class NewsAdapter extends BaseAdapter {
23 | protected static final String TAG = "NewsAdapter";
24 | private Context mContext;
25 | private List lists;
26 | private ListView mListView;
27 | private HashMap> hashMaps = new HashMap>();
28 |
29 | public NewsAdapter(Context context, List lists,
30 | ListView mListView) {
31 | this.mContext = context;
32 | this.lists = lists;
33 | this.mListView = mListView;
34 | }
35 |
36 | @Override
37 | public int getCount() {
38 | if (lists != null) {
39 | return lists.size();
40 | }
41 | return 0;
42 | }
43 |
44 | @Override
45 | public Object getItem(int position) {
46 | return lists.get(position);
47 | }
48 |
49 | @Override
50 | public long getItemId(int position) {
51 | return position;
52 | }
53 |
54 | @Override
55 | public View getView(int position, View convertView, ViewGroup parent) {
56 | final Holder holder;
57 | RecentChat chat = lists.get(position);
58 | if (convertView == null) {
59 | convertView = View.inflate(mContext, R.layout.news_item,
60 | null);
61 | holder = new Holder();
62 | holder.iv = (ImageView) convertView.findViewById(R.id.user_picture);
63 | holder.tv_name = (TextView) convertView
64 | .findViewById(R.id.user_name);
65 | holder.tv_feel = (TextView) convertView
66 | .findViewById(R.id.user_feel);
67 | holder.tv_time = (TextView) convertView
68 | .findViewById(R.id.user_time);
69 | convertView.setTag(holder);
70 | } else {
71 | holder = (Holder) convertView.getTag();
72 | }
73 | String path = chat.getImgPath();
74 |
75 |
76 | holder.tv_name.setText(chat.getUserName());
77 | holder.tv_feel.setText(chat.getUserFeel());
78 | holder.tv_time.setText(chat.getUserTime());
79 | return convertView;
80 | }
81 |
82 | class Holder {
83 | ImageView iv;
84 | TextView tv_name;
85 | TextView tv_feel;
86 | TextView tv_time;
87 | }
88 |
89 | }
90 |
--------------------------------------------------------------------------------
/src/com/finddreams/network/NetUtils.java:
--------------------------------------------------------------------------------
1 | package com.finddreams.network;
2 |
3 | import android.content.Context;
4 | import android.content.Intent;
5 | import android.net.ConnectivityManager;
6 | import android.net.NetworkInfo;
7 | import android.os.Build;
8 |
9 | public class NetUtils {
10 |
11 | // 判断网络连接状态
12 | public static boolean isNetworkConnected(Context context) {
13 | if (context != null) {
14 | ConnectivityManager mConnectivityManager = (ConnectivityManager) context
15 | .getSystemService(Context.CONNECTIVITY_SERVICE);
16 | NetworkInfo mNetworkInfo = mConnectivityManager
17 | .getActiveNetworkInfo();
18 | if (mNetworkInfo != null) {
19 | return mNetworkInfo.isAvailable();
20 | }
21 | }
22 | return false;
23 | }
24 |
25 | // 判断wifi状态
26 | public static boolean isWifiConnected(Context context) {
27 | if (context != null) {
28 | ConnectivityManager mConnectivityManager = (ConnectivityManager) context
29 | .getSystemService(Context.CONNECTIVITY_SERVICE);
30 | NetworkInfo mWiFiNetworkInfo = mConnectivityManager
31 | .getNetworkInfo(ConnectivityManager.TYPE_WIFI);
32 | if (mWiFiNetworkInfo != null) {
33 | return mWiFiNetworkInfo.isAvailable();
34 | }
35 | }
36 | return false;
37 | }
38 |
39 | // 判断移动网络
40 | public static boolean isMobileConnected(Context context) {
41 | if (context != null) {
42 | ConnectivityManager mConnectivityManager = (ConnectivityManager) context
43 | .getSystemService(Context.CONNECTIVITY_SERVICE);
44 | NetworkInfo mMobileNetworkInfo = mConnectivityManager
45 | .getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
46 | if (mMobileNetworkInfo != null) {
47 | return mMobileNetworkInfo.isAvailable();
48 | }
49 | }
50 | return false;
51 | }
52 |
53 | // 获取连接类型
54 | public static int getConnectedType(Context context) {
55 | if (context != null) {
56 | ConnectivityManager mConnectivityManager = (ConnectivityManager) context
57 | .getSystemService(Context.CONNECTIVITY_SERVICE);
58 | NetworkInfo mNetworkInfo = mConnectivityManager
59 | .getActiveNetworkInfo();
60 | if (mNetworkInfo != null && mNetworkInfo.isAvailable()) {
61 | return mNetworkInfo.getType();
62 | }
63 | }
64 | return -1;
65 | }
66 | /**
67 | * 设置网络
68 | * @param paramContext
69 | */
70 | public static void startToSettings(Context paramContext) {
71 | if (paramContext == null)
72 | return;
73 | try {
74 | if (Build.VERSION.SDK_INT > 10) {
75 | paramContext.startActivity(new Intent(
76 | "android.settings.SETTINGS"));
77 | return;
78 | }
79 | } catch (Exception localException) {
80 | localException.printStackTrace();
81 | return;
82 | }
83 | paramContext.startActivity(new Intent(
84 | "android.settings.WIRELESS_SETTINGS"));
85 | }
86 | }
87 |
--------------------------------------------------------------------------------
/src/com/finddreams/receiver/NetReceiver.java:
--------------------------------------------------------------------------------
1 | package com.finddreams.receiver;
2 |
3 | import android.content.BroadcastReceiver;
4 | import android.content.Context;
5 | import android.content.Intent;
6 | import android.net.ConnectivityManager;
7 | import android.widget.Toast;
8 |
9 | import com.finddreams.netstate.NetEvent;
10 | import com.finddreams.network.NetUtils;
11 |
12 | import de.greenrobot.event.EventBus;
13 | /**
14 | * @Description:网络状态的Receive
15 | * @author http://blog.csdn.net/finddreams
16 | */
17 | public class NetReceiver extends BroadcastReceiver {
18 |
19 | @Override
20 | public void onReceive(Context context, Intent intent) {
21 | String action = intent.getAction();
22 | if (ConnectivityManager.CONNECTIVITY_ACTION.equals(action)) {
23 | boolean isConnected = NetUtils.isNetworkConnected(context);
24 | System.out.println("网络状态:" + isConnected);
25 | System.out.println("wifi状态:" + NetUtils.isWifiConnected(context));
26 | System.out.println("移动网络状态:" + NetUtils.isMobileConnected(context));
27 | System.out.println("网络连接类型:" + NetUtils.getConnectedType(context));
28 | if (isConnected) {
29 | Toast.makeText(context, "已经连接网络", Toast.LENGTH_LONG).show();
30 | EventBus.getDefault().post(new NetEvent(true));
31 | } else {
32 | EventBus.getDefault().post(new NetEvent(false));
33 | Toast.makeText(context, "已经断开网络", Toast.LENGTH_LONG).show();
34 | }
35 | }
36 | }
37 |
38 | }
39 |
--------------------------------------------------------------------------------