├── app ├── .gitignore ├── app-release.apk ├── src │ ├── main │ │ ├── res │ │ │ ├── values │ │ │ │ ├── attr.xml │ │ │ │ ├── strings.xml │ │ │ │ ├── colors.xml │ │ │ │ └── styles.xml │ │ │ ├── drawable │ │ │ │ ├── info_icon_100px.png │ │ │ │ ├── room_default_image.png │ │ │ │ └── scrollbar.xml │ │ │ ├── mipmap-xxxhdpi │ │ │ │ ├── chat_icon.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-hdpi │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-mdpi │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xhdpi │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xxhdpi │ │ │ │ └── ic_launcher_round.png │ │ │ ├── menu │ │ │ │ ├── chat_menu.xml │ │ │ │ └── info_menu.xml │ │ │ └── layout │ │ │ │ ├── layout_list_item.xml │ │ │ │ ├── layout_rooms.xml │ │ │ │ ├── activity_chat.xml │ │ │ │ └── activity_perpare.xml │ │ ├── java │ │ │ └── com │ │ │ │ └── linzg │ │ │ │ └── www │ │ │ │ └── androidinternet │ │ │ │ ├── ThreadCallback.java │ │ │ │ ├── Port.java │ │ │ │ ├── ServerConnect.java │ │ │ │ ├── SquareImageView.java │ │ │ │ ├── ServerService.java │ │ │ │ ├── SearchResponseThread.java │ │ │ │ ├── Server.java │ │ │ │ ├── util │ │ │ │ └── CostomUtil.java │ │ │ │ ├── SearchServerThread.java │ │ │ │ ├── activity │ │ │ │ ├── RoomsActivity.java │ │ │ │ ├── PrepareActivity.java │ │ │ │ └── ChatActivity.java │ │ │ │ ├── ServerThread.java │ │ │ │ └── Client.java │ │ └── AndroidManifest.xml │ ├── test │ │ └── java │ │ │ └── com │ │ │ └── linzg │ │ │ └── www │ │ │ └── androidinternet │ │ │ └── ExampleUnitTest.java │ └── androidTest │ │ └── java │ │ └── com │ │ └── linzg │ │ └── www │ │ └── androidinternet │ │ └── ExampleInstrumentedTest.java ├── proguard-rules.pro └── build.gradle ├── settings.gradle ├── .idea ├── copyright │ └── profiles_settings.xml ├── inspectionProfiles │ ├── profiles_settings.xml │ └── Project_Default.xml ├── modules.xml ├── runConfigurations.xml ├── gradle.xml ├── compiler.xml └── misc.xml ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── .gitignore ├── gradle.properties ├── README.md ├── gradlew.bat └── gradlew /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | -------------------------------------------------------------------------------- /app/app-release.apk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/evanforest/EasyChat/HEAD/app/app-release.apk -------------------------------------------------------------------------------- /app/src/main/res/values/attr.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 简易聊天室 3 | 4 | -------------------------------------------------------------------------------- /.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/evanforest/EasyChat/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /app/src/main/res/drawable/info_icon_100px.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/evanforest/EasyChat/HEAD/app/src/main/res/drawable/info_icon_100px.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/chat_icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/evanforest/EasyChat/HEAD/app/src/main/res/mipmap-xxxhdpi/chat_icon.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/room_default_image.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/evanforest/EasyChat/HEAD/app/src/main/res/drawable/room_default_image.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/evanforest/EasyChat/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/evanforest/EasyChat/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/evanforest/EasyChat/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/evanforest/EasyChat/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/evanforest/EasyChat/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | .externalNativeBuild 10 | -------------------------------------------------------------------------------- /app/src/main/java/com/linzg/www/androidinternet/ThreadCallback.java: -------------------------------------------------------------------------------- 1 | package com.linzg.www.androidinternet; 2 | 3 | /** 4 | * Created by asus on 2017/9/14. 5 | */ 6 | 7 | public interface ThreadCallback { 8 | void onThreadEnd(); 9 | } 10 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Wed Sep 13 14:48:58 CST 2017 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip 7 | -------------------------------------------------------------------------------- /.idea/inspectionProfiles/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/menu/chat_menu.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 8 | 9 | -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #000fb4 6 | #759cd4 7 | #e4e2e2 8 | 9 | -------------------------------------------------------------------------------- /app/src/main/java/com/linzg/www/androidinternet/Port.java: -------------------------------------------------------------------------------- 1 | package com.linzg.www.androidinternet; 2 | 3 | /** 4 | * Created by asus on 2017/9/14. 5 | */ 6 | 7 | public class Port { 8 | public static final int PORT_SERVER_RESPOND = 8890; 9 | public static final int PORT_SERVER_SOCKET = 8891; 10 | public static final int PORT_MULTICAST_SOCKET = 8892; 11 | 12 | } 13 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/scrollbar.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 10 | 11 | -------------------------------------------------------------------------------- /.idea/inspectionProfiles/Project_Default.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/menu/info_menu.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 10 | 11 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /app/src/main/java/com/linzg/www/androidinternet/ServerConnect.java: -------------------------------------------------------------------------------- 1 | package com.linzg.www.androidinternet; 2 | 3 | import java.net.DatagramSocket; 4 | import java.net.MulticastSocket; 5 | 6 | /** 7 | * Created by asus on 2017/9/15. 8 | */ 9 | 10 | public class ServerConnect extends Thread { 11 | private DatagramSocket sendSoket = null; //向发出组播的客户端发送UDP数据 12 | private MulticastSocket mMs = null; //接受客户端的组播 13 | public ServerConnect(){ 14 | 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /app/src/test/java/com/linzg/www/androidinternet/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.linzg.www.androidinternet; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * @see Testing documentation 11 | */ 12 | public class ExampleUnitTest { 13 | @Test 14 | public void addition_isCorrect() throws Exception { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 17 | 18 | -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | org.gradle.jvmargs=-Xmx1536m 13 | 14 | # When configured, Gradle will run in incubating parallel mode. 15 | # This option should only be used with decoupled projects. More details, visit 16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 17 | # org.gradle.parallel=true 18 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/linzg/www/androidinternet/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.linzg.www.androidinternet; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumentation test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() throws Exception { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("com.linzg.www.androidinternet", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in D:\Android\sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | 19 | # Uncomment this to preserve the line number information for 20 | # debugging stack traces. 21 | #-keepattributes SourceFile,LineNumberTable 22 | 23 | # If you keep the line number information, uncomment this to 24 | # hide the original source file name. 25 | #-renamesourcefileattribute SourceFile 26 | -------------------------------------------------------------------------------- /app/src/main/java/com/linzg/www/androidinternet/SquareImageView.java: -------------------------------------------------------------------------------- 1 | package com.linzg.www.androidinternet; 2 | 3 | import android.content.Context; 4 | import android.util.AttributeSet; 5 | import android.util.Log; 6 | import android.widget.ImageView; 7 | 8 | 9 | /** 10 | * 正方形ImageView,边长为宽 11 | * Created by asus on 2017/9/15. 12 | */ 13 | 14 | public class SquareImageView extends android.support.v7.widget.AppCompatImageView { 15 | private static final String TAG = "SquareImageView"; 16 | public SquareImageView(Context context) { 17 | super(context); 18 | } 19 | 20 | public SquareImageView(Context context, AttributeSet attrs) { 21 | super(context, attrs); 22 | } 23 | 24 | public SquareImageView(Context context, AttributeSet attrs, int defStyleAttr) { 25 | super(context, attrs, defStyleAttr); 26 | } 27 | 28 | @Override 29 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 30 | super.onMeasure(widthMeasureSpec, widthMeasureSpec); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 25 5 | buildToolsVersion "25.0.2" 6 | defaultConfig { 7 | applicationId "com.linzg.www.androidinternet" 8 | minSdkVersion 15 9 | targetSdkVersion 25 10 | versionCode 1 11 | versionName "1.0" 12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | sourceSets { main { res.srcDirs = ['src/main/res', 'src/main/res/menu'] } } 21 | } 22 | 23 | dependencies { 24 | compile fileTree(dir: 'libs', include: ['*.jar']) 25 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { 26 | exclude group: 'com.android.support', module: 'support-annotations' 27 | }) 28 | compile 'com.android.support:appcompat-v7:25.3.1' 29 | compile 'com.android.support.constraint:constraint-layout:1.0.2' 30 | testCompile 'junit:junit:4.12' 31 | } 32 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | 10 | 17 | 20 | 21 | 22 | 23 | 24 | 25 | 28 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # EasyChat-简易聊天室 2 | 3 | 作者:lzg
4 | qq:535903063
5 | 上传时间:2017.9.19
6 | 制作时间:9.10 - 9.19
7 |
8 |

简介:

9 | 本项目是一个简单的局域网多人聊天室安卓软件。实现局域网内的聊天室创建、搜索和加入。
10 |
11 |

功能:

12 | 必须在局域网的条件下使用(暂不完全支持热点,打开热点的用户将无法使用)。
13 | 使用时要在设置中打开软件的通知权限,本软件的提示是用Toast实现,不打开将无法看到提示。
14 | 取完昵称后可选择创建聊天室或加入局域网中他人的聊天室。
15 | 创建聊天室:创建服务器并加入到自己的聊天室中,同时向局域网可见。
16 | 加入聊天室:进入搜索界面,可搜索局域网的所有开启的聊天室,点击即可进入开始聊天。
17 | 对于客户端的加入与退出,聊天室内都有提示 “ 某某某 加入(离开)了聊天室 ”。
18 | 心跳检测:客户端连接服务器后会定时向服务器发送心跳包,服务器收到后向客户端返回心跳包。
19 |          如果当客户端因网络问题而连接不上的话,就可以检测已到离开聊天室。
20 |          服务器掉线的话就会结束聊天室。
21 | 处理了大部分异常,暂未发现大bug。
22 |
23 |

运用到的知识点:

24 | 封装、低耦合高内聚思想
25 | 安卓基础知识(Activity,Service,各种界面布局和View,自定义View)
26 | Socket(Socket、ServerSocket、MulticastSocket、DatagramSocket等)
27 | 多线程
28 | 异常处理
29 | 心跳检测机制
30 | IO流
31 | 集合
32 | Handler
33 | Dialog和Toast
34 | 安卓本地存储(SharedPreferences)
35 | 获取WIFI状态
36 |
37 |

项目结构:

38 | PrepareActivity :准备界面,
39 | RoomsActivity :搜索局域网内的聊天室界面
40 | ChatActivity  :聊天主界面
41 | SquareImageView :自定义正方形ImageView
42 | ServerService :服务器类
43 | ServerThread  :服务器聊天线程
44 | ServerThread.ClientChannel :客户端在服务器的映射线程
45 | ServerResponseThread  :服务器响应搜索请求线程
46 | SearchServerThread  :客户端搜索服务器线程
47 | Client  :客户端类
48 | Client.Connect  :客户端连接线程
49 | Client.SendMsg  :客户端发送消息线程
50 | Client.ReceviceMsg :客户端接收消息线程
51 | Port  :端口号类
52 | CostomUtil  :自定义工具类
53 |
54 | 55 |

欢迎下载学习交流

56 | 57 | 58 | 59 | 60 | -------------------------------------------------------------------------------- /app/src/main/res/layout/layout_list_item.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 13 | 19 | 32 | 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /app/src/main/res/layout/layout_rooms.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 13 | 22 | 23 | 28 | 38 | 39 | 40 | 45 | 46 | 47 | 48 |