Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgraded to Api25 and got it to work with https://socketio-chat.now.sh/ #59

Merged
merged 5 commits into from
Feb 22, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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
Expand Down
31 changes: 13 additions & 18 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -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"
}
Expand All @@ -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'
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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 <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@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());
}
}
Original file line number Diff line number Diff line change
@@ -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/";
}
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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();
Expand All @@ -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();
}
Expand All @@ -324,6 +340,7 @@ public void run() {
username = data.getString("username");
message = data.getString("message");
} catch (JSONException e) {
Log.e(TAG, e.getMessage());
return;
}

Expand All @@ -347,6 +364,7 @@ public void run() {
username = data.getString("username");
numUsers = data.getInt("numUsers");
} catch (JSONException e) {
Log.e(TAG, e.getMessage());
return;
}

Expand All @@ -370,6 +388,7 @@ public void run() {
username = data.getString("username");
numUsers = data.getInt("numUsers");
} catch (JSONException e) {
Log.e(TAG, e.getMessage());
return;
}

Expand All @@ -392,6 +411,7 @@ public void run() {
try {
username = data.getString("username");
} catch (JSONException e) {
Log.e(TAG, e.getMessage());
return;
}
addTyping(username);
Expand All @@ -411,6 +431,7 @@ public void run() {
try {
username = data.getString("username");
} catch (JSONException e) {
Log.e(TAG, e.getMessage());
return;
}
removeTyping(username);
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -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