Commit 757f0257 authored by Corentin Mors's avatar Corentin Mors
Browse files

Fix some functions and lint code

parent 82ecfb54
......@@ -25,7 +25,6 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".LoginActivity" />
<activity android:name=".SettingsActivity"></activity>
</application>
......
......@@ -97,8 +97,9 @@ public class ChatFragment extends Fragment {
mSocket.on("new message", onNewMessage);
mSocket.on("user joined", onUserJoined);
mSocket.on("user left", onUserLeft);
//mSocket.on("typing", onTyping);
//mSocket.on("stop typing", onStopTyping);
mSocket.on("typing", onTyping);
mSocket.on("stop typing", onStopTyping);
mSocket.on("login", onLogin);
mSocket.connect();
startSignIn();
......@@ -123,8 +124,9 @@ public class ChatFragment extends Fragment {
mSocket.off("new message", onNewMessage);
mSocket.off("user joined", onUserJoined);
mSocket.off("user left", onUserLeft);
//mSocket.off("typing", onTyping);
//mSocket.off("stop typing", onStopTyping);
mSocket.off("typing", onTyping);
mSocket.off("stop typing", onStopTyping);
mSocket.off("login", onLogin);
}
@Override
......@@ -179,22 +181,6 @@ public class ChatFragment extends Fragment {
});
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (Activity.RESULT_OK != resultCode) {
getActivity().finish();
return;
}
mUsername = data.getStringExtra("username");
int numUsers = data.getIntExtra("numUsers", 1);
addLog(getResources().getString(R.string.message_welcome));
//addParticipantsLog(numUsers);
}
private void addLog(String message) {
mMessages.add(new Message.Builder(Message.TYPE_LOG)
......@@ -261,8 +247,6 @@ public class ChatFragment extends Fragment {
mPassword = settings.getString("mPassword", "azerty");
mRoom = settings.getString("mRoom", "default");
mSocket.emit("add user", mUsername, mRoom);
//Intent intent = new Intent(getActivity(), LoginActivity.class);
//startActivityForResult(intent, REQUEST_LOGIN);
}
private void leave() {
......@@ -403,6 +387,29 @@ public class ChatFragment extends Fragment {
}
};
private Emitter.Listener onLogin = new Emitter.Listener() {
@Override
public void call(final Object... args) {
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
JSONObject data = (JSONObject) args[0];
addLog(getResources().getString(R.string.message_welcome));
int numUsers;
try {
numUsers = data.getInt("numUsers");
addParticipantsLog(numUsers);
} catch (JSONException e) {
Log.e("OM_LOG", "Fail num user");
return;
}
}
});
}
};
private Emitter.Listener onTyping = new Emitter.Listener() {
@Override
public void call(final Object... args) {
......
package fr.pixelswap.onmap.onmap;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.inputmethod.EditorInfo;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import org.json.JSONException;
import org.json.JSONObject;
import io.socket.client.Socket;
import io.socket.emitter.Emitter;
/**
* A login screen that offers login via username.
*/
public class LoginActivity extends Activity {
private EditText mUsernameView;
private String mUsername;
private Socket mSocket;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
ChatApplication app = (ChatApplication) getApplication();
mSocket = app.getSocket();
// Set up the login form.
mUsernameView = (EditText) findViewById(R.id.username_input);
/*mUsernameView.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView textView, int id, KeyEvent keyEvent) {
if (id == R.id.login || id == EditorInfo.IME_NULL) {
attemptLogin();
return true;
}
return false;
}
});*/
Button signInButton = (Button) findViewById(R.id.sign_in_button);
signInButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
attemptLogin();
}
});
mSocket.on("login", onLogin);
}
@Override
protected void onDestroy() {
super.onDestroy();
mSocket.off("login", onLogin);
}
/**
* Attempts to sign in the account specified by the login form.
* If there are form errors (invalid username, missing fields, etc.), the
* errors are presented and no actual login attempt is made.
*/
private void attemptLogin() {
// Reset errors.
mUsernameView.setError(null);
// Store values at the time of the login attempt.
String username = mUsernameView.getText().toString().trim();
// Check for a valid username.
if (TextUtils.isEmpty(username)) {
// There was an error; don't attempt login and focus the first
// form field with an error.
mUsernameView.setError("Required field");
mUsernameView.requestFocus();
return;
}
mUsername = username;
// perform the user login attempt.
mSocket.emit("add user", username, "one");
}
private Emitter.Listener onLogin = new Emitter.Listener() {
@Override
public void call(Object... args) {
JSONObject data = (JSONObject) args[0];
Log.e("OM_LOGIN", "User join");
int numUsers;
try {
numUsers = data.getInt("numUsers");
} catch (JSONException e) {
Log.e("OM_LOG", "Fail num user");
return;
}
Intent intent = new Intent();
intent.putExtra("username", mUsername);
intent.putExtra("numUsers", numUsers);
setResult(RESULT_OK, intent);
finish();
}
};
}
\ No newline at end of file
......@@ -31,7 +31,7 @@ public class MessageAdapter extends RecyclerView.Adapter<MessageAdapter.ViewHold
layout = R.layout.item_log;
break;
case Message.TYPE_ACTION:
//layout = R.layout.item_action;
layout = R.layout.item_action;
break;
}
View v = LayoutInflater
......
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="8dp"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:paddingTop="8dp"
tools:context="fr.pixelswap.onmap.onmap.LoginActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="vertical">
<EditText
android:id="@+id/username_input"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Username"
android:imeActionId="@+id/login"
android:imeActionLabel="Sign in"
android:imeOptions="actionUnspecified"
android:inputType="textPersonName"
android:maxLength="14"
android:maxLines="1"
android:singleLine="true"/>
<Button
android:id="@+id/sign_in_button"
style="?android:textAppearanceSmall"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="Sign in"
android:textStyle="bold"/>
</LinearLayout>
</ScrollView>
\ No newline at end of file
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center_vertical"
android:paddingTop="8dp">
<TextView
android:id="@+id/username"
style="?android:textAppearanceMedium"
android:textColor="?android:textColorPrimary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:textStyle="bold"/>
<TextView
android:id="@+id/action"
style="?android:textAppearanceMedium"
android:textColor="?android:textColorSecondary"
android:text="@string/user_action_typing"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:singleLine="true"/>
</LinearLayout>
......@@ -10,7 +10,7 @@
<string name="error_connect">Failed to connect</string>
<!-- messages -->
<string name="message_welcome">Welcome to Socket.IO Chat</string>
<string name="message_welcome">Welcome to onMap Chat</string>
<plurals name="message_participants">
<item quantity="one">there\'s %d participant</item>
<item quantity="other">there are %d participants</item>
......
......@@ -388,7 +388,7 @@ $(function() {
});
function moveParticipantPoint(data){
console.log("Got data " + data.coordinates + " from " + data.username);
// console.log("Got data " + data.coordinates + " from " + data.username);
if (userPositions[data.username] != null) {
// The point exist we pass
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment