Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void loginPressed(View v){
- usernameStr = usernameField.getText().toString();
- passwordStr = passwordField.getText().toString();
- if (!bound) return;
- Bundle b = new Bundle();
- Message msg = Message.obtain(null, ChatService.LOGIN);
- try {
- b.putString("username", usernameStr);
- b.putString("password", passwordStr);
- msg.setData(b);
- messenger.send(msg);
- }
- catch (RemoteException e) {
- }
- private class IncomingHandler extends Handler {
- @Override
- public void handleMessage(Message msg) {
- switch(msg.what) {
- case LOGIN:
- Bundle b = msg.getData();
- String username = b.getString("username");
- String password = b.getString("password");
- String loginMessage = TCPCall.login(username, password);
- connection.sendMessage(loginMessage);
- String loginReturn = connection.retrieveMessage();
- Message m;
- Scanner s = new Scanner(loginReturn);
- s.useDelimiter(",");
- String c = s.next();
- String status = s.next();
- String message = s.next();
- if (status.equals("OK")) {
- m = Message.obtain(null, LoginActivity.OK);
- try {
- msg.replyTo.send(m);
- } catch (RemoteException e) {}
- }
- else {
- m = Message.obtain(null, LoginActivity.ERR);
- try {
- msg.replyTo.send(m);
- } catch (RemoteException e) {}
- }
- break;
- msg.replyTo.send(m);
- static final int LOGIN_STATUS = 1;
- private class IncomingHandler extends Handler {
- @Override
- public void handleMessage(Message msg) {
- switch(msg.what) {
- case LOGIN:
- Bundle b = msg.getData();
- String username = b.getString("username");
- String password = b.getString("password");
- String loginMessage = TCPCall.login(username, password);
- connection.sendMessage(loginMessage);
- String loginReturn = connection.retrieveMessage();
- Message m = Message.obtain(null, LOGIN_STATUS);
- Scanner s = new Scanner(loginReturn);
- s.useDelimiter(",");
- String c = s.next();
- String status = s.next();
- String message = s.next();
- if (status.equals("OK")) {
- b.putString("responseC",c);
- b.putString("responseStatus",status);
- b.putString("responseMessage",message)
- m.setData(b);
- try {
- msg.replyTo.send(m);
- } catch (RemoteException e) {}
- }
- else {
- /*if something is wrong with username and password you can put
- a toast*/
- }
- break;
- class IncomingHandler extends Handler{
- @Override
- public void handleMessage(Message msg) {
- switch (msg.what){
- case ChatService.LOGIN_STATUS:
- String C = msg.getData().getString("responseC");
- String Status = msg.getData().getString("responseStatus");
- String Message = msg.getData().getString("responseMessage");
- //Here is your response in LoginActivity, enjoy!!!
- break;
- default:
- super.handleMessage(msg);
- }
- }
- }
- final Messenger mMessenger = new Messenger(new IncomingHandler());
- public void loginPressed(View v){
- usernameStr = usernameField.getText().toString();
- passwordStr = passwordField.getText().toString();
- if (!bound) return;
- Bundle b = new Bundle();
- Message msg = Message.obtain(null, ChatService.LOGIN_SATUS,0,0);
- try {
- b.putString("username", usernameStr);
- b.putString("password", passwordStr);
- msg.setData(b);
- msg.replyTo = mMessenger;
- messenger.send(msg);
- }
- catch (RemoteException e) {
- // In this case the service has crashed before we could even
- // do anything with it; we can count on soon being
- // disconnected (and then reconnected if it can be restarted)
- // so there is no need to do anything here.
- }
Add Comment
Please, Sign In to add comment