├── sample ├── .gitignore ├── src │ ├── main │ │ ├── res │ │ │ ├── values │ │ │ │ ├── strings.xml │ │ │ │ ├── styles.xml │ │ │ │ ├── colors.xml │ │ │ │ └── dimens.xml │ │ │ ├── mipmap-hdpi │ │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-mdpi │ │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-xhdpi │ │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-xxhdpi │ │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-xxxhdpi │ │ │ │ └── ic_launcher.png │ │ │ ├── layout │ │ │ │ ├── include_divider.xml │ │ │ │ ├── activity_multicast_server.xml │ │ │ │ ├── activity_mina_tcp_server.xml │ │ │ │ ├── activity_multicast_client.xml │ │ │ │ ├── activity_mina_tcp_client.xml │ │ │ │ ├── activity_main.xml │ │ │ │ └── activity_home.xml │ │ │ └── values-w820dp │ │ │ │ └── dimens.xml │ │ ├── java │ │ │ └── com │ │ │ │ └── ethanco │ │ │ │ └── sample │ │ │ │ ├── TestBean.java │ │ │ │ ├── ScrollBottomTextWatcher.java │ │ │ │ ├── HomeActivity.java │ │ │ │ ├── MinaTcpServerActivity.java │ │ │ │ ├── MulticastServerActivity.java │ │ │ │ ├── MinaUdpServerActivity.java │ │ │ │ ├── MulticastClientActivity.java │ │ │ │ ├── MinaTcpServerByteActivity.java │ │ │ │ ├── MinaTcpServerHeartBeatActivity.java │ │ │ │ ├── MinaTcpClientActivity.java │ │ │ │ ├── UdpClientActivity.java │ │ │ │ ├── MinaUdpClientActivity.java │ │ │ │ ├── MinaTcpClientByteActivity.java │ │ │ │ └── MinaTcpClientHeartBeatActivity.java │ │ └── AndroidManifest.xml │ ├── test │ │ └── java │ │ │ └── com │ │ │ └── ethanco │ │ │ └── sample │ │ │ └── ExampleUnitTest.java │ └── androidTest │ │ └── java │ │ └── com │ │ └── ethanco │ │ └── sample │ │ └── ApplicationTest.java ├── proguard-rules.pro └── build.gradle ├── halo-turbo ├── .gitignore ├── src │ ├── main │ │ ├── res │ │ │ └── values │ │ │ │ └── strings.xml │ │ ├── java │ │ │ └── com │ │ │ │ └── ethanco │ │ │ │ └── halo │ │ │ │ └── turbo │ │ │ │ ├── ads │ │ │ │ ├── AbstractHalo.java │ │ │ │ ├── ISession.java │ │ │ │ ├── AbstractSession.java │ │ │ │ ├── AbstractLog.java │ │ │ │ ├── ISocket.java │ │ │ │ ├── IConvertor.java │ │ │ │ ├── ILog.java │ │ │ │ ├── IHandler.java │ │ │ │ ├── IHandlerAdapter.java │ │ │ │ ├── IKeepAliveListener.java │ │ │ │ ├── BaseLogHandler.java │ │ │ │ └── AbstractSocket.java │ │ │ │ ├── type │ │ │ │ └── Mode.java │ │ │ │ ├── impl │ │ │ │ ├── handler │ │ │ │ │ ├── EmptyHandler.java │ │ │ │ │ ├── HexLogHandler.java │ │ │ │ │ └── StringLogHandler.java │ │ │ │ ├── convert │ │ │ │ │ ├── StringByteConvertor.java │ │ │ │ │ ├── ObjectByteConvertor.java │ │ │ │ │ └── ConvertManager.java │ │ │ │ └── socket │ │ │ │ │ ├── IHopeSocket.java │ │ │ │ │ ├── UdpClientSocket.java │ │ │ │ │ └── MulticastSocket.java │ │ │ │ ├── bean │ │ │ │ ├── Config.java │ │ │ │ └── KeepAlive.java │ │ │ │ ├── utils │ │ │ │ ├── Util.java │ │ │ │ └── HexUtil.java │ │ │ │ ├── SocketFactory.java │ │ │ │ └── Halo.java │ │ └── AndroidManifest.xml │ ├── test │ │ └── java │ │ │ └── com │ │ │ └── ethanco │ │ │ └── halo │ │ │ └── turbo │ │ │ ├── ExampleUnitTest.java │ │ │ └── HaloTest.java │ └── androidTest │ │ └── java │ │ └── com │ │ └── ethanco │ │ └── halo │ │ └── turbo │ │ └── ApplicationTest.java ├── proguard-rules.pro └── build.gradle ├── halo-turbo-mina ├── .gitignore ├── libs │ ├── mina-core-2.0.16.jar │ └── slf4j-android-1.6.1-RC1.jar ├── src │ ├── main │ │ ├── res │ │ │ └── values │ │ │ │ └── strings.xml │ │ ├── AndroidManifest.xml │ │ └── java │ │ │ └── com │ │ │ └── ethanco │ │ │ └── halo │ │ │ └── turbo │ │ │ └── mina │ │ │ ├── MinaTcpServerSocket.java │ │ │ ├── MinaUdpServerSocket.java │ │ │ ├── MinaUdpClientSocket.java │ │ │ └── MinaTcpClientSocket.java │ ├── test │ │ └── java │ │ │ └── com │ │ │ └── ethanco │ │ │ └── halo │ │ │ └── turbo │ │ │ └── mina │ │ │ └── ExampleUnitTest.java │ └── androidTest │ │ └── java │ │ └── com │ │ └── ethanco │ │ └── halo │ │ └── turbo │ │ └── mina │ │ └── ExampleInstrumentedTest.java ├── proguard-rules.pro └── build.gradle ├── json-convertor ├── .gitignore ├── src │ ├── main │ │ ├── res │ │ │ └── values │ │ │ │ └── strings.xml │ │ ├── AndroidManifest.xml │ │ └── java │ │ │ └── com │ │ │ └── ethanco │ │ │ └── json │ │ │ └── convertor │ │ │ └── convert │ │ │ ├── ObjectJsonByteConvertor.java │ │ │ └── ObjectJsonConvertor.java │ ├── test │ │ └── java │ │ │ └── com │ │ │ └── ethanco │ │ │ └── json │ │ │ └── convertor │ │ │ └── ExampleUnitTest.java │ └── androidTest │ │ └── java │ │ └── com │ │ └── ethanco │ │ └── json │ │ └── convertor │ │ └── ExampleInstrumentedTest.java ├── proguard-rules.pro └── build.gradle ├── settings.gradle ├── .idea ├── copyright │ └── profiles_settings.xml ├── encodings.xml ├── vcs.xml ├── kotlinc.xml ├── runConfigurations.xml ├── compiler.xml ├── modules.xml ├── gradle.xml └── misc.xml ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── .gitignore ├── gradle.properties ├── gradlew.bat ├── Mina Byte数组传输-ByteArrayCodecFactory ├── ReadMe.md └── gradlew /sample/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /halo-turbo/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /halo-turbo-mina/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /json-convertor/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':sample', ':halo-turbo', ':halo-turbo-mina', ':json-convertor' 2 | -------------------------------------------------------------------------------- /.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EthanCo/Halo-Turbo/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /halo-turbo/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Halo-Turbo 3 | 4 | -------------------------------------------------------------------------------- /sample/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Halo-Sample 3 | 4 | -------------------------------------------------------------------------------- /halo-turbo-mina/libs/mina-core-2.0.16.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EthanCo/Halo-Turbo/HEAD/halo-turbo-mina/libs/mina-core-2.0.16.jar -------------------------------------------------------------------------------- /halo-turbo-mina/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Halo-Turbo-Mina 3 | 4 | -------------------------------------------------------------------------------- /json-convertor/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Json-Convertor 3 | 4 | -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EthanCo/Halo-Turbo/HEAD/sample/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EthanCo/Halo-Turbo/HEAD/sample/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /halo-turbo-mina/libs/slf4j-android-1.6.1-RC1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EthanCo/Halo-Turbo/HEAD/halo-turbo-mina/libs/slf4j-android-1.6.1-RC1.jar -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EthanCo/Halo-Turbo/HEAD/sample/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EthanCo/Halo-Turbo/HEAD/sample/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EthanCo/Halo-Turbo/HEAD/sample/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /halo-turbo/src/main/java/com/ethanco/halo/turbo/ads/AbstractHalo.java: -------------------------------------------------------------------------------- 1 | package com.ethanco.halo.turbo.ads; 2 | 3 | /** 4 | * Created by EthanCo on 2016/9/14. 5 | */ 6 | public abstract class AbstractHalo implements ISocket { 7 | } 8 | -------------------------------------------------------------------------------- /.idea/kotlinc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | -------------------------------------------------------------------------------- /halo-turbo/src/main/java/com/ethanco/halo/turbo/ads/ISession.java: -------------------------------------------------------------------------------- 1 | package com.ethanco.halo.turbo.ads; 2 | 3 | /** 4 | * @author EthanCo 5 | * @since 2017/1/17 6 | */ 7 | public interface ISession { 8 | void write(Object message); 9 | 10 | void close(); 11 | } 12 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Thu Apr 06 15:41:38 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 | -------------------------------------------------------------------------------- /sample/src/main/res/layout/include_divider.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /json-convertor/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /halo-turbo/src/main/java/com/ethanco/halo/turbo/type/Mode.java: -------------------------------------------------------------------------------- 1 | package com.ethanco.halo.turbo.type; 2 | 3 | /** 4 | * Created by EthanCo on 2016/9/14. 5 | */ 6 | public enum Mode { 7 | MINA_NIO_TCP_CLIENT, 8 | MINA_NIO_TCP_SERVER, 9 | MINA_NIO_UDP_CLIENT, 10 | MINA_NIO_UDP_SERVER, 11 | MULTICAST, 12 | UDP_CLIENT, 13 | } 14 | -------------------------------------------------------------------------------- /halo-turbo/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /halo-turbo/src/main/java/com/ethanco/halo/turbo/impl/handler/EmptyHandler.java: -------------------------------------------------------------------------------- 1 | package com.ethanco.halo.turbo.impl.handler; 2 | 3 | import com.ethanco.halo.turbo.ads.IHandlerAdapter; 4 | 5 | /** 6 | * 空的Handler 7 | * 8 | * @author EthanCo 9 | * @since 2017/1/17 10 | */ 11 | 12 | public class EmptyHandler extends IHandlerAdapter { 13 | 14 | } 15 | -------------------------------------------------------------------------------- /halo-turbo/src/main/java/com/ethanco/halo/turbo/ads/AbstractSession.java: -------------------------------------------------------------------------------- 1 | package com.ethanco.halo.turbo.ads; 2 | 3 | /** 4 | * 回话 抽象类 5 | * 6 | * @author EthanCo 7 | * @since 2017/1/17 8 | */ 9 | 10 | public abstract class AbstractSession implements ISession { 11 | //private final IHandler handler; 12 | 13 | public AbstractSession() { 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /sample/src/main/res/values-w820dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 64dp 6 | 7 | -------------------------------------------------------------------------------- /sample/src/test/java/com/ethanco/sample/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.ethanco.sample; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * To work on unit tests, switch the Test Artifact in the Build Variants view. 9 | */ 10 | public class ExampleUnitTest { 11 | @Test 12 | public void addition_isCorrect() throws Exception { 13 | assertEquals(4, 2 + 2); 14 | } 15 | } -------------------------------------------------------------------------------- /halo-turbo/src/test/java/com/ethanco/halo/turbo/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.ethanco.halo.turbo; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * To work on unit tests, switch the Test Artifact in the Build Variants view. 9 | */ 10 | public class ExampleUnitTest { 11 | @Test 12 | public void addition_isCorrect() throws Exception { 13 | assertEquals(4, 2 + 2); 14 | } 15 | } -------------------------------------------------------------------------------- /sample/src/androidTest/java/com/ethanco/sample/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package com.ethanco.sample; 2 | 3 | import android.app.Application; 4 | import android.test.ApplicationTestCase; 5 | 6 | /** 7 | * Testing Fundamentals 8 | */ 9 | public class ApplicationTest extends ApplicationTestCase { 10 | public ApplicationTest() { 11 | super(Application.class); 12 | } 13 | } -------------------------------------------------------------------------------- /halo-turbo/src/main/java/com/ethanco/halo/turbo/ads/AbstractLog.java: -------------------------------------------------------------------------------- 1 | package com.ethanco.halo.turbo.ads; 2 | 3 | /** 4 | * @author EthanCo 5 | * @since 2017/1/18 6 | */ 7 | 8 | public abstract class AbstractLog implements ILog { 9 | protected String prefix = ""; 10 | 11 | protected String getPrefix() { 12 | return prefix; 13 | } 14 | 15 | protected void setPrefix(String prefix) { 16 | this.prefix = prefix; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /halo-turbo/src/main/java/com/ethanco/halo/turbo/ads/ISocket.java: -------------------------------------------------------------------------------- 1 | package com.ethanco.halo.turbo.ads; 2 | 3 | import java.util.List; 4 | 5 | /** 6 | * Created by EthanCo on 2016/9/14. 7 | */ 8 | public interface ISocket { 9 | boolean start(); 10 | 11 | void stop(); 12 | 13 | List getHandlers(); 14 | 15 | void addHandler(IHandler handler); 16 | 17 | boolean removeHandler(IHandler handler); 18 | 19 | boolean isRunning(); 20 | } 21 | -------------------------------------------------------------------------------- /halo-turbo/src/androidTest/java/com/ethanco/halo/turbo/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package com.ethanco.halo.turbo; 2 | 3 | import android.app.Application; 4 | import android.test.ApplicationTestCase; 5 | 6 | /** 7 | * Testing Fundamentals 8 | */ 9 | public class ApplicationTest extends ApplicationTestCase { 10 | public ApplicationTest() { 11 | super(Application.class); 12 | } 13 | } -------------------------------------------------------------------------------- /halo-turbo-mina/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /halo-turbo/src/main/java/com/ethanco/halo/turbo/ads/IConvertor.java: -------------------------------------------------------------------------------- 1 | package com.ethanco.halo.turbo.ads; 2 | 3 | /** 4 | * 转换器 5 | * 6 | * @author EthanCo 7 | * @since 2017/1/20 8 | */ 9 | 10 | public interface IConvertor { 11 | //发送时 是否处理 12 | boolean isSentHandler(Object message); 13 | 14 | //接收时 是否处理 15 | boolean isReceiveHandler(Object message); 16 | 17 | //发送时 转换 18 | Object sentConvert(Object message); 19 | 20 | //接收时 转换 21 | Object receiveConvert(Object message); 22 | } 23 | -------------------------------------------------------------------------------- /json-convertor/src/test/java/com/ethanco/json/convertor/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.ethanco.json.convertor; 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 | } -------------------------------------------------------------------------------- /halo-turbo-mina/src/test/java/com/ethanco/halo/turbo/mina/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.ethanco.halo.turbo.mina; 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 | } -------------------------------------------------------------------------------- /halo-turbo/src/main/java/com/ethanco/halo/turbo/ads/ILog.java: -------------------------------------------------------------------------------- 1 | package com.ethanco.halo.turbo.ads; 2 | 3 | /** 4 | * Log接口 5 | * 6 | * @author EthanCo 7 | * @since 2017/1/18 8 | */ 9 | 10 | public interface ILog extends IHandler { 11 | void onStarting(); 12 | 13 | void onStartSuccess(); 14 | 15 | void onStartFailed(Exception e); 16 | 17 | void onStopping(); 18 | 19 | void onStopped(); 20 | 21 | void onReceiveException(Exception e); 22 | 23 | void onReConnecting(); 24 | 25 | void onReConnected(); 26 | 27 | void onReConnectFailed(Exception e); 28 | } 29 | -------------------------------------------------------------------------------- /json-convertor/src/main/java/com/ethanco/json/convertor/convert/ObjectJsonByteConvertor.java: -------------------------------------------------------------------------------- 1 | package com.ethanco.json.convertor.convert; 2 | 3 | /** 4 | * 如果是Object对象,则先转换为json字符串后,再转换为byte[] 5 | * 6 | * @author EthanCo 7 | * @since 2017/1/20 8 | */ 9 | 10 | public class ObjectJsonByteConvertor extends ObjectJsonConvertor { 11 | @Override 12 | public Object sentConvert(Object message) { 13 | Object result = super.sentConvert(message); 14 | if (result instanceof String) { 15 | return ((String) result).getBytes(); 16 | } 17 | return result; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /halo-turbo/src/main/java/com/ethanco/halo/turbo/ads/IHandler.java: -------------------------------------------------------------------------------- 1 | package com.ethanco.halo.turbo.ads; 2 | 3 | /** 4 | * 回调处理类 5 | * 6 | * @author EthanCo 7 | * @since 2017/1/17 8 | */ 9 | 10 | public interface IHandler { 11 | //会话(session)创建之后,回调该方法 12 | void sessionCreated(ISession session); 13 | 14 | //会话(session)打开之后,回调该方法 15 | void sessionOpened(ISession session); 16 | 17 | //会话(session)关闭后,回调该方法 18 | void sessionClosed(ISession session); 19 | 20 | //接收到消息时回调这个方法 21 | void messageReceived(ISession session, Object message); 22 | 23 | //发送数据时回调这个方法 24 | void messageSent(ISession session, Object message); 25 | } 26 | -------------------------------------------------------------------------------- /sample/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:\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 | -------------------------------------------------------------------------------- /halo-turbo/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:\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 | -------------------------------------------------------------------------------- /halo-turbo-mina/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 C:\Java\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 | -------------------------------------------------------------------------------- /json-convertor/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 C:\Java\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 | -------------------------------------------------------------------------------- /.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 | -------------------------------------------------------------------------------- /halo-turbo/src/main/java/com/ethanco/halo/turbo/ads/IHandlerAdapter.java: -------------------------------------------------------------------------------- 1 | package com.ethanco.halo.turbo.ads; 2 | 3 | /** 4 | * Handler 默认实现 5 | * 6 | * @author EthanCo 7 | * @since 2017/1/18 8 | */ 9 | 10 | public abstract class IHandlerAdapter implements IHandler { 11 | 12 | @Override 13 | public void sessionCreated(ISession session) { 14 | 15 | } 16 | 17 | @Override 18 | public void sessionOpened(ISession session) { 19 | 20 | } 21 | 22 | @Override 23 | public void sessionClosed(ISession session) { 24 | 25 | } 26 | 27 | @Override 28 | public void messageReceived(ISession session, Object message) { 29 | 30 | } 31 | 32 | @Override 33 | public void messageSent(ISession session, Object message) { 34 | 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | <<<<<<< HEAD 2 | *.iml 3 | .gradle 4 | /local.properties 5 | /.idea/workspace.xml 6 | /.idea/libraries 7 | .DS_Store 8 | /build 9 | /captures 10 | ======= 11 | # Built application files 12 | *.apk 13 | *.ap_ 14 | 15 | # Files for the ART/Dalvik VM 16 | *.dex 17 | 18 | # Java class files 19 | *.class 20 | 21 | # Generated files 22 | bin/ 23 | gen/ 24 | out/ 25 | 26 | # Gradle files 27 | .gradle/ 28 | build/ 29 | 30 | # Local configuration file (sdk path, etc) 31 | local.properties 32 | 33 | # Proguard folder generated by Eclipse 34 | proguard/ 35 | 36 | # Log Files 37 | *.log 38 | 39 | # Android Studio Navigation editor temp files 40 | .navigation/ 41 | 42 | # Android Studio captures folder 43 | captures/ 44 | 45 | # Intellij 46 | *.iml 47 | .idea/workspace.xml 48 | 49 | # Keystore files 50 | *.jks 51 | >>>>>>> 270eb2d3bbc73ca31a11c299773d32e874b7153c 52 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 20 | 21 | -------------------------------------------------------------------------------- /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 | # Default value: -Xmx10248m -XX:MaxPermSize=256m 13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 14 | 15 | # When configured, Gradle will run in incubating parallel mode. 16 | # This option should only be used with decoupled projects. More details, visit 17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 18 | # org.gradle.parallel=true -------------------------------------------------------------------------------- /sample/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 24 5 | buildToolsVersion '25.0.0' 6 | 7 | defaultConfig { 8 | applicationId "com.ethanco.sample" 9 | minSdkVersion 15 10 | targetSdkVersion 24 11 | versionCode 1 12 | versionName "1.0" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | dataBinding { 21 | enabled true 22 | } 23 | } 24 | 25 | dependencies { 26 | compile fileTree(include: ['*.jar'], dir: 'libs') 27 | testCompile 'junit:junit:4.12' 28 | compile 'com.android.support:appcompat-v7:24.1.1' 29 | compile project(':halo-turbo') 30 | compile project(':halo-turbo-mina') 31 | compile project(':json-convertor') 32 | } 33 | -------------------------------------------------------------------------------- /halo-turbo/src/main/java/com/ethanco/halo/turbo/impl/convert/StringByteConvertor.java: -------------------------------------------------------------------------------- 1 | package com.ethanco.halo.turbo.impl.convert; 2 | 3 | import com.ethanco.halo.turbo.ads.IConvertor; 4 | 5 | /** 6 | * String转化为Byte[] 7 | * 8 | * @author EthanCo 9 | * @since 2017/1/20 10 | */ 11 | 12 | public class StringByteConvertor implements IConvertor { 13 | @Override 14 | public boolean isSentHandler(Object message) { 15 | return message instanceof String; 16 | } 17 | 18 | @Override 19 | public boolean isReceiveHandler(Object message) { 20 | return message instanceof byte[] || message instanceof Byte[]; 21 | } 22 | 23 | @Override 24 | public Object sentConvert(Object message) { 25 | return ((String) message).getBytes(); 26 | } 27 | 28 | @Override 29 | public Object receiveConvert(Object message) { 30 | return new String((byte[]) message).trim(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /sample/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /json-convertor/src/androidTest/java/com/ethanco/json/convertor/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.ethanco.json.convertor; 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.ethanco.json.convertor.test", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /sample/src/main/java/com/ethanco/sample/TestBean.java: -------------------------------------------------------------------------------- 1 | package com.ethanco.sample; 2 | 3 | /** 4 | * TODO 5 | * 6 | * @author EthanCo 7 | * @since 2017/1/22 8 | */ 9 | 10 | public class TestBean { 11 | private String arg1; 12 | private String arg2; 13 | 14 | public TestBean(String arg1, String arg2) { 15 | this.arg1 = arg1; 16 | this.arg2 = arg2; 17 | } 18 | 19 | public String getArg1() { 20 | return arg1; 21 | } 22 | 23 | public void setArg1(String arg1) { 24 | this.arg1 = arg1; 25 | } 26 | 27 | public String getArg2() { 28 | return arg2; 29 | } 30 | 31 | public void setArg2(String arg2) { 32 | this.arg2 = arg2; 33 | } 34 | 35 | @Override 36 | public String toString() { 37 | return "TestBean{" + 38 | "arg1='" + arg1 + '\'' + 39 | ", arg2='" + arg2 + '\'' + 40 | '}'; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /halo-turbo-mina/src/androidTest/java/com/ethanco/halo/turbo/mina/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.ethanco.halo.turbo.mina; 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.ethanco.halo.turbo.mina.test", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /halo-turbo/src/main/java/com/ethanco/halo/turbo/bean/Config.java: -------------------------------------------------------------------------------- 1 | package com.ethanco.halo.turbo.bean; 2 | 3 | import android.content.Context; 4 | 5 | import com.ethanco.halo.turbo.ads.IConvertor; 6 | import com.ethanco.halo.turbo.ads.IHandler; 7 | import com.ethanco.halo.turbo.type.Mode; 8 | 9 | import java.util.List; 10 | import java.util.concurrent.ExecutorService; 11 | 12 | /** 13 | * Created by EthanCo on 2016/9/16. 14 | */ 15 | public class Config { 16 | //模式 17 | public Mode mode; 18 | //目标IP 19 | public String targetIP; 20 | //目标端口 21 | public int targetPort; 22 | //源IP 23 | //public String sourceIP; 24 | //源端口 25 | public int sourcePort; 26 | //缓存大小 27 | public int bufferSize; 28 | //线程池 29 | public ExecutorService threadPool; 30 | 31 | public List handlers; 32 | 33 | public List convertors; 34 | 35 | public Object codec; 36 | 37 | public Context context; 38 | 39 | public KeepAlive keepAlive; 40 | } 41 | -------------------------------------------------------------------------------- /halo-turbo/src/main/java/com/ethanco/halo/turbo/impl/convert/ObjectByteConvertor.java: -------------------------------------------------------------------------------- 1 | package com.ethanco.halo.turbo.impl.convert; 2 | 3 | import com.ethanco.halo.turbo.ads.IConvertor; 4 | 5 | /** 6 | * Object转换为Byte[] 7 | * 8 | * @author EthanCo 9 | * @since 2017/1/20 10 | */ 11 | 12 | public class ObjectByteConvertor implements IConvertor { 13 | @Override 14 | public boolean isSentHandler(Object message) { 15 | return message instanceof Object; 16 | } 17 | 18 | @Override 19 | public boolean isReceiveHandler(Object message) { 20 | return message instanceof byte[] || message instanceof Byte[]; 21 | } 22 | 23 | @Override 24 | public Object sentConvert(Object message) { 25 | return message.toString().getBytes(); 26 | } 27 | 28 | @Override 29 | public Object receiveConvert(Object message) { 30 | if (message instanceof String) { 31 | ((String) message).trim(); 32 | } 33 | return message; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /halo-turbo/src/main/java/com/ethanco/halo/turbo/impl/handler/HexLogHandler.java: -------------------------------------------------------------------------------- 1 | package com.ethanco.halo.turbo.impl.handler; 2 | 3 | import com.ethanco.halo.turbo.ads.BaseLogHandler; 4 | import com.ethanco.halo.turbo.utils.HexUtil; 5 | 6 | /** 7 | * 16进制 日志处理 8 | * 9 | * @author EthanCo 10 | * @since 2017/1/18 11 | */ 12 | 13 | public class HexLogHandler extends BaseLogHandler { 14 | 15 | public HexLogHandler() { 16 | } 17 | 18 | public HexLogHandler(String tag) { 19 | super(tag); 20 | } 21 | 22 | @Override 23 | protected String convertToString(Object message) { 24 | if (message == null) { 25 | return "message is null"; 26 | } 27 | 28 | String receive; 29 | if (message instanceof byte[] || message instanceof Byte[]) { 30 | receive = HexUtil.bytesToHexString((byte[]) message); 31 | } else if (message instanceof String) { 32 | receive = (String) message; 33 | } else { 34 | receive = message.toString(); 35 | } 36 | return receive.trim(); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /halo-turbo-mina/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | apply plugin: 'com.github.dcendents.android-maven' 3 | 4 | group='com.github.EthanCo' 5 | 6 | android { 7 | compileSdkVersion 25 8 | buildToolsVersion "25.0.1" 9 | 10 | defaultConfig { 11 | minSdkVersion 15 12 | targetSdkVersion 25 13 | versionCode 1 14 | versionName "1.0" 15 | 16 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 17 | 18 | } 19 | buildTypes { 20 | release { 21 | minifyEnabled false 22 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 23 | } 24 | } 25 | } 26 | 27 | dependencies { 28 | compile fileTree(include: ['*.jar'], dir: 'libs') 29 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { 30 | exclude group: 'com.android.support', module: 'support-annotations' 31 | }) 32 | compile 'com.android.support:appcompat-v7:25.0.1' 33 | testCompile 'junit:junit:4.12' 34 | compile project(':halo-turbo') 35 | } 36 | -------------------------------------------------------------------------------- /halo-turbo/src/test/java/com/ethanco/halo/turbo/HaloTest.java: -------------------------------------------------------------------------------- 1 | package com.ethanco.halo.turbo; 2 | 3 | import com.ethanco.halo.turbo.type.Mode; 4 | 5 | import org.junit.Before; 6 | import org.junit.Test; 7 | import org.robolectric.annotation.Config; 8 | 9 | import java.io.IOException; 10 | 11 | /** 12 | * Created by EthanCo on 2016/9/14. 13 | */ 14 | @Config(constants = BuildConfig.class, sdk = 21) 15 | public class HaloTest { 16 | private Halo halo; 17 | 18 | @Before 19 | public void setUp() { 20 | 21 | Halo.Builder builder = new Halo.Builder() 22 | .setTargetIP("192.168.2.1") 23 | .setTargetPort(8890) 24 | .setMode(Mode.MINA_NIO_TCP_CLIENT) 25 | //.setType(Type.UDP) 26 | .setBufferSize(1024 * 2); 27 | 28 | halo = builder.build(); 29 | } 30 | 31 | @Test 32 | public void testLogic() { 33 | try { 34 | halo.start(); 35 | } catch (IOException e) { 36 | e.printStackTrace(); 37 | } 38 | //halo.send("hello"); 39 | halo.stop(); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /json-convertor/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | apply plugin: 'com.github.dcendents.android-maven' 3 | 4 | group='com.github.EthanCo' 5 | 6 | 7 | android { 8 | compileSdkVersion 25 9 | buildToolsVersion "25.0.1" 10 | 11 | defaultConfig { 12 | minSdkVersion 15 13 | targetSdkVersion 25 14 | versionCode 1 15 | versionName "1.0" 16 | 17 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 18 | 19 | } 20 | buildTypes { 21 | release { 22 | minifyEnabled false 23 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 24 | } 25 | } 26 | } 27 | 28 | dependencies { 29 | compile fileTree(dir: 'libs', include: ['*.jar']) 30 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { 31 | exclude group: 'com.android.support', module: 'support-annotations' 32 | }) 33 | compile 'com.android.support:appcompat-v7:25.0.1' 34 | testCompile 'junit:junit:4.12' 35 | compile project(':halo-turbo') 36 | compile 'com.google.code.gson:gson:2.8.0' 37 | } 38 | -------------------------------------------------------------------------------- /sample/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | #3F51B5 6 | 7 | #303F9F 8 | 9 | #1976D2 10 | 11 | #DD0050 12 | 13 | #C60037 14 | 15 | #212121 16 | 17 | #757575 18 | 19 | #d5d5d5 20 | 21 | #FFFFFF 22 | 23 | #BDBDBD 24 | 25 | 26 | #FFFFFF 27 | 28 | #000000 29 | 30 | #F5F5F5 31 | 32 | #00000000 33 | 34 | -------------------------------------------------------------------------------- /halo-turbo/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | apply plugin: 'com.github.dcendents.android-maven' 3 | 4 | group='com.github.EthanCo' 5 | 6 | android { 7 | compileSdkVersion 24 8 | buildToolsVersion '25.0.0' 9 | 10 | defaultConfig { 11 | minSdkVersion 15 12 | targetSdkVersion 24 13 | versionCode 1 14 | versionName "1.0" 15 | } 16 | buildTypes { 17 | release { 18 | minifyEnabled false 19 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 20 | } 21 | } 22 | configurations.all { 23 | resolutionStrategy { 24 | force 'com.android.support:support-annotations:23.2.1' 25 | } 26 | } 27 | } 28 | 29 | dependencies { 30 | compile fileTree(dir: 'libs', include: ['*.jar']) 31 | testCompile 'junit:junit:4.12' 32 | //Mockito 33 | testCompile 'org.mockito:mockito-all:2.0.2-beta' 34 | //Robolectric 35 | testCompile 'org.robolectric:robolectric:3.1.2' 36 | testCompile 'org.khronos:opengl-api:gl1.1-android-2.1_r1' 37 | testCompile 'org.hamcrest:hamcrest-all:1.3' 38 | 39 | compile 'com.android.support:appcompat-v7:24.1.1' 40 | } 41 | -------------------------------------------------------------------------------- /halo-turbo/src/main/java/com/ethanco/halo/turbo/ads/IKeepAliveListener.java: -------------------------------------------------------------------------------- 1 | package com.ethanco.halo.turbo.ads; 2 | 3 | import com.ethanco.halo.turbo.bean.KeepAlive; 4 | 5 | /** 6 | * 心跳 回调 7 | * 8 | * @author EthanCo 9 | * @since 2017/7/31 10 | * - ┌─┐ ┌─┐ 11 | * - ┌──┘ ┴───────┘ ┴──┐ 12 | * - │ │ 13 | * - │ ─── │ 14 | * - │ ─┬┘ └┬─ │ 15 | * - │ │ 16 | * - │ ─┴─ │ 17 | * - │ │ 18 | * - └───┐ ┌───┘ 19 | * - │ │ 20 | * - │ │ 21 | * - │ │ 22 | * - │ └──────────────┐ 23 | * - │ │ 24 | * - │ ├─┐ 25 | * - │ ┌─┘ 26 | * - │ │ 27 | * - └─┐ ┐ ┌───────┬──┐ ┌──┘ 28 | * - │ ─┤ ─┤ │ ─┤ ─┤ 29 | * - └──┴──┘ └──┴──┘ 30 | * --------------- 神兽保佑 --------------- 31 | * --------------- 永无BUG! --------------- 32 | */ 33 | 34 | public interface IKeepAliveListener { 35 | void onKeepAliveRequestTimedOut(KeepAlive keepAlive, ISession iSession); 36 | 37 | boolean isKeepAliveMessage(ISession ioSession, Object message); 38 | 39 | Object getKeepAliveMessage(ISession ioSession, Object o); 40 | } 41 | -------------------------------------------------------------------------------- /sample/src/main/java/com/ethanco/sample/ScrollBottomTextWatcher.java: -------------------------------------------------------------------------------- 1 | package com.ethanco.sample; 2 | 3 | import android.os.Handler; 4 | import android.os.Looper; 5 | import android.text.Editable; 6 | import android.text.TextWatcher; 7 | import android.widget.ScrollView; 8 | 9 | import java.lang.ref.WeakReference; 10 | 11 | /** 12 | * ScrollView 总是滑动到底部 13 | * 14 | * @author EthanCo 15 | * @since 2017/1/24 16 | */ 17 | 18 | public class ScrollBottomTextWatcher implements TextWatcher { 19 | 20 | private WeakReference scrollViewRef; 21 | 22 | public ScrollBottomTextWatcher(ScrollView scrollView) { 23 | this.scrollViewRef = new WeakReference(scrollView); 24 | } 25 | 26 | @Override 27 | public void beforeTextChanged(CharSequence s, int start, int count, int after) { 28 | 29 | } 30 | 31 | @Override 32 | public void onTextChanged(CharSequence s, int start, int before, int count) { 33 | 34 | } 35 | 36 | @Override 37 | public void afterTextChanged(Editable s) { 38 | final ScrollView scrollview = scrollViewRef.get(); 39 | if (scrollview == null) { 40 | return; 41 | } 42 | 43 | new Handler(Looper.getMainLooper()).post(new Runnable() { 44 | @Override 45 | public void run() { 46 | scrollview.fullScroll(ScrollView.FOCUS_DOWN); 47 | } 48 | }); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /json-convertor/src/main/java/com/ethanco/json/convertor/convert/ObjectJsonConvertor.java: -------------------------------------------------------------------------------- 1 | package com.ethanco.json.convertor.convert; 2 | 3 | import com.ethanco.halo.turbo.ads.IConvertor; 4 | import com.google.gson.Gson; 5 | 6 | /** 7 | * @author EthanCo 8 | * @since 2017/1/20 9 | */ 10 | 11 | public class ObjectJsonConvertor implements IConvertor { 12 | private Gson gson = new Gson(); 13 | 14 | @Override 15 | public boolean isSentHandler(Object message) { 16 | return message instanceof Object; 17 | } 18 | 19 | @Override 20 | public boolean isReceiveHandler(Object message) { 21 | return message instanceof Object; 22 | } 23 | 24 | @Override 25 | public Object sentConvert(Object message) { 26 | if (message instanceof String || message instanceof Byte[] || message instanceof byte[]) { 27 | return message; 28 | } 29 | 30 | String json = gson.toJson(message); 31 | //Log.i("Z-Test", "sentConvert:" + json); 32 | return json; 33 | } 34 | 35 | @Override 36 | public Object receiveConvert(Object message) { 37 | return message; 38 | /*if (message instanceof byte[] || message instanceof Byte[]) { 39 | return message;//new String((byte[]) message).trim(); 40 | } else if (message instanceof String) { 41 | return message;//((String) (message)).trim(); 42 | } 43 | return message;*/ 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /sample/src/main/res/layout/activity_multicast_server.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | 18 | 19 | 23 | 24 | 25 | 26 |