├── app ├── .gitignore ├── src │ └── main │ │ ├── res │ │ ├── values │ │ │ ├── strings.xml │ │ │ ├── colors.xml │ │ │ └── styles.xml │ │ ├── mipmap-hdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ ├── mipmap-mdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ ├── mipmap-xhdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxhdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxxhdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ ├── mipmap-anydpi-v26 │ │ │ ├── ic_launcher.xml │ │ │ └── ic_launcher_round.xml │ │ ├── drawable │ │ │ ├── input.xml │ │ │ └── ic_launcher_background.xml │ │ ├── layout │ │ │ ├── activity_login.xml │ │ │ └── activity_main.xml │ │ └── drawable-v24 │ │ │ └── ic_launcher_foreground.xml │ │ ├── java │ │ └── me │ │ │ └── wcy │ │ │ └── cchat │ │ │ ├── model │ │ │ ├── Callback.java │ │ │ ├── MsgType.java │ │ │ ├── LoginStatus.java │ │ │ ├── CMessage.java │ │ │ └── LoginInfo.java │ │ │ ├── ChatApplication.java │ │ │ ├── AppCache.java │ │ │ ├── ui │ │ │ ├── LoginActivity.java │ │ │ └── MainActivity.java │ │ │ └── PushService.java │ │ └── AndroidManifest.xml ├── proguard-rules.pro └── build.gradle ├── server ├── .gitignore ├── src │ └── main │ │ ├── res │ │ └── values │ │ │ └── strings.xml │ │ ├── AndroidManifest.xml │ │ └── java │ │ └── me │ │ └── wcy │ │ └── cchat │ │ └── server │ │ ├── model │ │ ├── MsgType.java │ │ ├── CMessage.java │ │ └── LoginInfo.java │ │ ├── PushServer.java │ │ ├── NettyChannelMap.java │ │ ├── UserManager.java │ │ ├── NettyServerBootstrap.java │ │ └── NettyServerHandler.java ├── proguard-rules.pro └── build.gradle ├── settings.gradle ├── art ├── netty.png ├── network.png ├── screenshot01.gif └── screenshot02.gif ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── .gitignore ├── gradle.properties ├── gradlew.bat ├── gradlew └── README.md /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /server/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app', ':server' 2 | -------------------------------------------------------------------------------- /art/netty.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangchenyan/cchat/HEAD/art/netty.png -------------------------------------------------------------------------------- /art/network.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangchenyan/cchat/HEAD/art/network.png -------------------------------------------------------------------------------- /art/screenshot01.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangchenyan/cchat/HEAD/art/screenshot01.gif -------------------------------------------------------------------------------- /art/screenshot02.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangchenyan/cchat/HEAD/art/screenshot02.gif -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | CChat 3 | 4 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangchenyan/cchat/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /server/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | server 3 | 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea 5 | .DS_Store 6 | /build 7 | /captures 8 | .externalNativeBuild 9 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangchenyan/cchat/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangchenyan/cchat/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangchenyan/cchat/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangchenyan/cchat/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangchenyan/cchat/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangchenyan/cchat/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/wangchenyan/cchat/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /server/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangchenyan/cchat/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/wangchenyan/cchat/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/wangchenyan/cchat/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/java/me/wcy/cchat/model/Callback.java: -------------------------------------------------------------------------------- 1 | package me.wcy.cchat.model; 2 | 3 | public interface Callback { 4 | void onEvent(int code, String msg, T t); 5 | } 6 | -------------------------------------------------------------------------------- /app/src/main/java/me/wcy/cchat/model/MsgType.java: -------------------------------------------------------------------------------- 1 | package me.wcy.cchat.model; 2 | 3 | public interface MsgType { 4 | int LOGIN = 1; 5 | int PING = 2; 6 | int TEXT = 3; 7 | int TIPS = 4; 8 | } 9 | -------------------------------------------------------------------------------- /server/src/main/java/me/wcy/cchat/server/model/MsgType.java: -------------------------------------------------------------------------------- 1 | package me.wcy.cchat.server.model; 2 | 3 | public interface MsgType { 4 | int LOGIN = 1; 5 | int PING = 2; 6 | int TEXT = 3; 7 | int TIPS = 4; 8 | } 9 | -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/java/me/wcy/cchat/model/LoginStatus.java: -------------------------------------------------------------------------------- 1 | package me.wcy.cchat.model; 2 | 3 | /** 4 | * Created by hzwangchenyan on 2017/12/26. 5 | */ 6 | public enum LoginStatus { 7 | UNLOGIN, 8 | CONNECTING, 9 | LOGINING, 10 | LOGINED, 11 | } 12 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Tue Dec 26 11:31:24 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-4.1-all.zip 7 | -------------------------------------------------------------------------------- /server/src/main/java/me/wcy/cchat/server/PushServer.java: -------------------------------------------------------------------------------- 1 | package me.wcy.cchat.server; 2 | 3 | public class PushServer { 4 | 5 | public static void main(String[] args) { 6 | NettyServerBootstrap serverBootstrap = new NettyServerBootstrap(8300); 7 | serverBootstrap.bind(); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/input.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 7 | 10 | -------------------------------------------------------------------------------- /app/src/main/java/me/wcy/cchat/ChatApplication.java: -------------------------------------------------------------------------------- 1 | package me.wcy.cchat; 2 | 3 | import android.app.Application; 4 | import android.content.Intent; 5 | 6 | /** 7 | * Created by hzwangchenyan on 2017/12/26. 8 | */ 9 | public class ChatApplication extends Application { 10 | 11 | @Override 12 | public void onCreate() { 13 | super.onCreate(); 14 | 15 | startService(new Intent(this, PushService.class)); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /app/src/main/java/me/wcy/cchat/AppCache.java: -------------------------------------------------------------------------------- 1 | package me.wcy.cchat; 2 | 3 | import me.wcy.cchat.model.LoginInfo; 4 | 5 | /** 6 | * Created by hzwangchenyan on 2017/12/26. 7 | */ 8 | public class AppCache { 9 | private static PushService service; 10 | private static LoginInfo myInfo; 11 | 12 | public static PushService getService() { 13 | return service; 14 | } 15 | 16 | public static void setService(PushService service) { 17 | AppCache.service = service; 18 | } 19 | 20 | public static LoginInfo getMyInfo() { 21 | return myInfo; 22 | } 23 | 24 | public static void setMyInfo(LoginInfo myInfo) { 25 | AppCache.myInfo = myInfo; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /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/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /server/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /server/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | 3 | android { 4 | compileSdkVersion 26 5 | buildToolsVersion "26.0.3" 6 | 7 | defaultConfig { 8 | minSdkVersion 14 9 | targetSdkVersion 26 10 | versionCode 1 11 | versionName "1.0" 12 | } 13 | 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | 21 | compileOptions { 22 | sourceCompatibility JavaVersion.VERSION_1_8 23 | targetCompatibility JavaVersion.VERSION_1_8 24 | } 25 | } 26 | 27 | dependencies { 28 | implementation fileTree(include: ['*.jar'], dir: 'libs') 29 | implementation 'io.netty:netty-all:4.1.9.Final' 30 | implementation 'com.google.code.gson:gson:2.8.2' 31 | } 32 | -------------------------------------------------------------------------------- /server/src/main/java/me/wcy/cchat/server/NettyChannelMap.java: -------------------------------------------------------------------------------- 1 | package me.wcy.cchat.server; 2 | 3 | import java.util.Map; 4 | import java.util.concurrent.ConcurrentHashMap; 5 | 6 | import io.netty.channel.Channel; 7 | 8 | public class NettyChannelMap { 9 | private static Map map = new ConcurrentHashMap<>(); 10 | 11 | public static void add(String account, Channel channel) { 12 | map.put(account, channel); 13 | } 14 | 15 | public static Channel get(String clientId) { 16 | return map.get(clientId); 17 | } 18 | 19 | public static void remove(Channel channel) { 20 | for (Map.Entry entry : map.entrySet()) { 21 | if (entry.getValue() == channel) { 22 | String account = (String) entry.getKey(); 23 | map.remove(account); 24 | System.out.println(account + " leave"); 25 | break; 26 | } 27 | } 28 | } 29 | } -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 26 5 | buildToolsVersion "26.0.3" 6 | 7 | defaultConfig { 8 | applicationId "me.wcy.cchat" 9 | minSdkVersion 14 10 | targetSdkVersion 26 11 | versionCode 1 12 | versionName "1.0" 13 | } 14 | 15 | buildTypes { 16 | release { 17 | minifyEnabled false 18 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 19 | } 20 | } 21 | 22 | compileOptions { 23 | sourceCompatibility JavaVersion.VERSION_1_8 24 | targetCompatibility JavaVersion.VERSION_1_8 25 | } 26 | } 27 | 28 | dependencies { 29 | implementation fileTree(include: ['*.jar'], dir: 'libs') 30 | implementation 'com.android.support:appcompat-v7:26.1.0' 31 | implementation 'com.android.support.constraint:constraint-layout:1.0.2' 32 | compile 'io.netty:netty-all:4.1.9.Final' 33 | compile 'com.google.code.gson:gson:2.8.2' 34 | } 35 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /server/src/main/java/me/wcy/cchat/server/UserManager.java: -------------------------------------------------------------------------------- 1 | package me.wcy.cchat.server; 2 | 3 | import java.util.HashSet; 4 | import java.util.Set; 5 | 6 | import me.wcy.cchat.server.model.LoginInfo; 7 | 8 | /** 9 | * Created by hzwangchenyan on 2017/12/27. 10 | */ 11 | public class UserManager { 12 | // 已注册的账号 13 | private Set loginInfos = new HashSet<>(); 14 | 15 | private static class SingletonHolder { 16 | private static UserManager instance = new UserManager(); 17 | } 18 | 19 | private UserManager() { 20 | LoginInfo wcy = new LoginInfo(); 21 | wcy.setAccount("test1"); 22 | wcy.setToken("123456"); 23 | LoginInfo wcy2 = new LoginInfo(); 24 | wcy2.setAccount("test2"); 25 | wcy2.setToken("123456"); 26 | loginInfos.add(wcy); 27 | loginInfos.add(wcy2); 28 | } 29 | 30 | public static UserManager get() { 31 | return SingletonHolder.instance; 32 | } 33 | 34 | public boolean verify(LoginInfo loginInfo) { 35 | for (LoginInfo info : loginInfos) { 36 | if (info.equals(loginInfo)) { 37 | return true; 38 | } 39 | } 40 | return false; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /app/src/main/java/me/wcy/cchat/model/CMessage.java: -------------------------------------------------------------------------------- 1 | package me.wcy.cchat.model; 2 | 3 | import com.google.gson.Gson; 4 | import com.google.gson.annotations.SerializedName; 5 | 6 | import java.io.Serializable; 7 | 8 | /** 9 | * Created by hzwangchenyan on 2017/12/26. 10 | */ 11 | public class CMessage implements Serializable { 12 | @SerializedName("from") 13 | private String from; 14 | @SerializedName("to") 15 | private String to; 16 | @SerializedName("type") 17 | private int type; 18 | @SerializedName("content") 19 | private String content; 20 | 21 | public String toJson() { 22 | Gson gson = new Gson(); 23 | return gson.toJson(this); 24 | } 25 | 26 | public String getFrom() { 27 | return from; 28 | } 29 | 30 | public void setFrom(String from) { 31 | this.from = from; 32 | } 33 | 34 | public String getTo() { 35 | return to; 36 | } 37 | 38 | public void setTo(String to) { 39 | this.to = to; 40 | } 41 | 42 | public int getType() { 43 | return type; 44 | } 45 | 46 | public void setType(int type) { 47 | this.type = type; 48 | } 49 | 50 | public String getContent() { 51 | return content; 52 | } 53 | 54 | public void setContent(String content) { 55 | this.content = content; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /app/src/main/java/me/wcy/cchat/model/LoginInfo.java: -------------------------------------------------------------------------------- 1 | package me.wcy.cchat.model; 2 | 3 | import com.google.gson.Gson; 4 | import com.google.gson.annotations.SerializedName; 5 | 6 | import java.io.Serializable; 7 | 8 | /** 9 | * Created by hzwangchenyan on 2017/12/26. 10 | */ 11 | public class LoginInfo implements Serializable { 12 | @SerializedName("account") 13 | private String account; 14 | @SerializedName("token") 15 | private String token; 16 | @SerializedName("code") 17 | private int code; 18 | @SerializedName("msg") 19 | private String msg; 20 | 21 | public String toJson() { 22 | Gson gson = new Gson(); 23 | return gson.toJson(this); 24 | } 25 | 26 | public String getAccount() { 27 | return account; 28 | } 29 | 30 | public void setAccount(String account) { 31 | this.account = account; 32 | } 33 | 34 | public String getToken() { 35 | return token; 36 | } 37 | 38 | public void setToken(String token) { 39 | this.token = token; 40 | } 41 | 42 | public int getCode() { 43 | return code; 44 | } 45 | 46 | public void setCode(int code) { 47 | this.code = code; 48 | } 49 | 50 | public String getMsg() { 51 | return msg; 52 | } 53 | 54 | public void setMsg(String msg) { 55 | this.msg = msg; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /server/src/main/java/me/wcy/cchat/server/model/CMessage.java: -------------------------------------------------------------------------------- 1 | package me.wcy.cchat.server.model; 2 | 3 | import com.google.gson.Gson; 4 | import com.google.gson.annotations.SerializedName; 5 | 6 | import java.io.Serializable; 7 | 8 | /** 9 | * Created by hzwangchenyan on 2017/12/26. 10 | */ 11 | public class CMessage implements Serializable { 12 | @SerializedName("from") 13 | private String from; 14 | @SerializedName("to") 15 | private String to; 16 | @SerializedName("type") 17 | private int type; 18 | @SerializedName("content") 19 | private String content; 20 | 21 | public String toJson() { 22 | Gson gson = new Gson(); 23 | return gson.toJson(this); 24 | } 25 | 26 | public String getFrom() { 27 | return from; 28 | } 29 | 30 | public void setFrom(String from) { 31 | this.from = from; 32 | } 33 | 34 | public String getTo() { 35 | return to; 36 | } 37 | 38 | public void setTo(String to) { 39 | this.to = to; 40 | } 41 | 42 | public int getType() { 43 | return type; 44 | } 45 | 46 | public void setType(int type) { 47 | this.type = type; 48 | } 49 | 50 | public String getContent() { 51 | return content; 52 | } 53 | 54 | public void setContent(String content) { 55 | this.content = content; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_login.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 19 | 20 | 30 | 31 |