diff --git a/README.md b/README.md index a3169fa..0d07c53 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # socket.io-android-chat -This is a simple chat demo for socket.io and Android. You can connect to [chat.socket.io](http://socket.io/demos/chat/) using this app. +This is a simple chat demo for socket.io and Android. You can connect to [https://socketio-chat.now.sh/](https://socketio-chat.now.sh/) using this app. ## Installation @@ -12,6 +12,9 @@ This is a simple chat demo for socket.io and Android. You can connect to [chat.s http://socket.io/blog/native-socket-io-and-android/ +## Misc +https://github.com/socketio/socket.io/issues/2823 + ## License MIT diff --git a/app/build.gradle b/app/build.gradle index b920e3e..c6c1e10 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,24 +1,14 @@ -buildscript { - repositories { - jcenter() - } - dependencies { - classpath 'com.android.tools.build:gradle:1.2.3' - } -} apply plugin: 'com.android.application' -repositories { - jcenter() -} + android { - compileSdkVersion 21 - buildToolsVersion "21.1.2" + compileSdkVersion 25 + buildToolsVersion "25.0.2" defaultConfig { applicationId 'com.github.nkzawa.socketio.androidchat' - minSdkVersion 15 - targetSdkVersion 21 + minSdkVersion 17 + targetSdkVersion 25 versionCode 1 versionName "1.0" } @@ -34,9 +24,14 @@ android { dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) - compile 'com.android.support:appcompat-v7:21.0.+' - compile 'com.android.support:recyclerview-v7:21.0.+' - compile ('io.socket:socket.io-client:0.8.1') { + compile 'com.android.support:appcompat-v7:25.0.+' + compile 'com.android.support:recyclerview-v7:25.0.+' + compile ('io.socket:socket.io-client:0.8.3') { exclude group: 'org.json', module: 'json' } + + androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { + exclude group: 'com.android.support', module: 'support-annotations' + }) + testCompile 'junit:junit:4.12' } diff --git a/app/src/androidTest/java/com/github/nkzawa/socketio/androidchat/ApplicationTest.java b/app/src/androidTest/java/com/github/nkzawa/socketio/androidchat/ApplicationTest.java deleted file mode 100644 index c22c369..0000000 --- a/app/src/androidTest/java/com/github/nkzawa/socketio/androidchat/ApplicationTest.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.github.nkzawa.socketio.androidchat; - -import android.app.Application; -import android.test.ApplicationTestCase; - -/** - * Testing Fundamentals - */ -public class ApplicationTest extends ApplicationTestCase { - public ApplicationTest() { - super(Application.class); - } -} \ No newline at end of file diff --git a/app/src/androidTest/java/com/github/nkzawa/socketio/androidchat/ExampleInstrumentedTest.java b/app/src/androidTest/java/com/github/nkzawa/socketio/androidchat/ExampleInstrumentedTest.java new file mode 100644 index 0000000..b9fd700 --- /dev/null +++ b/app/src/androidTest/java/com/github/nkzawa/socketio/androidchat/ExampleInstrumentedTest.java @@ -0,0 +1,27 @@ +package com.github.nkzawa.socketio.androidchat; + +import android.content.Context; +import android.support.test.InstrumentationRegistry; +import android.support.test.runner.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import static junit.framework.Assert.assertEquals; + + +/** + * Instrumentation test, which will execute on an Android device. + * + * @see Testing documentation + */ +@RunWith(AndroidJUnit4.class) +public class ExampleInstrumentedTest { + @Test + public void useAppContext() throws Exception { + // Context of the app under test. + Context appContext = InstrumentationRegistry.getTargetContext(); + + assertEquals("com.github.nkzawa.socketio.androidchat", appContext.getPackageName()); + } +} diff --git a/app/src/main/java/com/github/nkzawa/socketio/androidchat/Constants.java b/app/src/main/java/com/github/nkzawa/socketio/androidchat/Constants.java index 24627b2..84b0ba0 100644 --- a/app/src/main/java/com/github/nkzawa/socketio/androidchat/Constants.java +++ b/app/src/main/java/com/github/nkzawa/socketio/androidchat/Constants.java @@ -1,5 +1,5 @@ package com.github.nkzawa.socketio.androidchat; public class Constants { - public static final String CHAT_SERVER_URL = "http://chat.socket.io"; + public static final String CHAT_SERVER_URL = "https://socketio-chat.now.sh/"; } diff --git a/app/src/main/java/com/github/nkzawa/socketio/androidchat/MainActivity.java b/app/src/main/java/com/github/nkzawa/socketio/androidchat/MainActivity.java index 1da8b27..a5e010c 100644 --- a/app/src/main/java/com/github/nkzawa/socketio/androidchat/MainActivity.java +++ b/app/src/main/java/com/github/nkzawa/socketio/androidchat/MainActivity.java @@ -1,10 +1,10 @@ package com.github.nkzawa.socketio.androidchat; import android.os.Bundle; -import android.support.v7.app.ActionBarActivity; +import android.support.v7.app.AppCompatActivity; -public class MainActivity extends ActionBarActivity { +public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { diff --git a/app/src/main/java/com/github/nkzawa/socketio/androidchat/MainFragment.java b/app/src/main/java/com/github/nkzawa/socketio/androidchat/MainFragment.java index abf5349..4060468 100644 --- a/app/src/main/java/com/github/nkzawa/socketio/androidchat/MainFragment.java +++ b/app/src/main/java/com/github/nkzawa/socketio/androidchat/MainFragment.java @@ -1,6 +1,7 @@ package com.github.nkzawa.socketio.androidchat; import android.app.Activity; +import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.os.Handler; @@ -10,6 +11,7 @@ import android.text.Editable; import android.text.TextUtils; import android.text.TextWatcher; +import android.util.Log; import android.view.KeyEvent; import android.view.LayoutInflater; import android.view.Menu; @@ -22,20 +24,24 @@ import android.widget.ImageButton; import android.widget.TextView; import android.widget.Toast; -import io.socket.client.Socket; -import io.socket.emitter.Emitter; + import org.json.JSONException; import org.json.JSONObject; import java.util.ArrayList; import java.util.List; +import io.socket.client.Socket; +import io.socket.emitter.Emitter; + /** * A chat fragment containing messages view and input form. */ public class MainFragment extends Fragment { + private static final String TAG = "MainFragment"; + private static final int REQUEST_LOGIN = 0; private static final int TYPING_TIMER_LENGTH = 600; @@ -55,12 +61,20 @@ public MainFragment() { super(); } + + // This event fires 1st, before creation of fragment or any views + // The onAttach method is called when the Fragment instance is associated with an Activity. + // This does not mean the Activity is fully initialized. @Override - public void onAttach(Activity activity) { - super.onAttach(activity); - mAdapter = new MessageAdapter(activity, mMessages); + public void onAttach(Context context) { + super.onAttach(context); + mAdapter = new MessageAdapter(context, mMessages); + if (context instanceof Activity){ + //this.listener = (MainActivity) context; + } } + @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -290,6 +304,7 @@ public void call(Object... args) { getActivity().runOnUiThread(new Runnable() { @Override public void run() { + Log.i(TAG, "diconnected"); isConnected = false; Toast.makeText(getActivity().getApplicationContext(), R.string.disconnect, Toast.LENGTH_LONG).show(); @@ -304,6 +319,7 @@ public void call(Object... args) { getActivity().runOnUiThread(new Runnable() { @Override public void run() { + Log.e(TAG, "Error connecting"); Toast.makeText(getActivity().getApplicationContext(), R.string.error_connect, Toast.LENGTH_LONG).show(); } @@ -324,6 +340,7 @@ public void run() { username = data.getString("username"); message = data.getString("message"); } catch (JSONException e) { + Log.e(TAG, e.getMessage()); return; } @@ -347,6 +364,7 @@ public void run() { username = data.getString("username"); numUsers = data.getInt("numUsers"); } catch (JSONException e) { + Log.e(TAG, e.getMessage()); return; } @@ -370,6 +388,7 @@ public void run() { username = data.getString("username"); numUsers = data.getInt("numUsers"); } catch (JSONException e) { + Log.e(TAG, e.getMessage()); return; } @@ -392,6 +411,7 @@ public void run() { try { username = data.getString("username"); } catch (JSONException e) { + Log.e(TAG, e.getMessage()); return; } addTyping(username); @@ -411,6 +431,7 @@ public void run() { try { username = data.getString("username"); } catch (JSONException e) { + Log.e(TAG, e.getMessage()); return; } removeTyping(username); diff --git a/build.gradle b/build.gradle index 9405f3f..16f9930 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:1.2.3' + classpath 'com.android.tools.build:gradle:2.3.0-beta4' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files diff --git a/gradle.properties b/gradle.properties index 1d3591c..4e7c65d 100644 --- a/gradle.properties +++ b/gradle.properties @@ -11,6 +11,7 @@ # The setting is particularly useful for tweaking memory settings. # Default value: -Xmx10248m -XX:MaxPermSize=256m # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 +org.gradle.jvmargs=-Xmx1536m # When configured, Gradle will run in incubating parallel mode. # This option should only be used with decoupled projects. More details, visit diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index af155f8..2a61779 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Wed Dec 23 22:20:48 JST 2015 +#Mon Feb 20 09:34:25 PST 2017 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-2.4-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-3.4-all.zip