+ OcAccountManager.OnPostListener onSignUp = new OcAccountManager.OnPostListener() {
+ @Override
+ public synchronized void onPostCompleted(List<OcHeaderOption> list,
+ OcRepresentation ocRepresentation) {
+ msg("signUp was successful");
+ try {
+ mUserUuid = ocRepresentation.getValue("uid");
+ mAccesstoken = ocRepresentation.getValue("accesstoken");
+ mRefreshtoken = ocRepresentation.getValue("refreshtoken");
+ String tokenType = ocRepresentation.getValue("tokentype");
+ msg("\tuserID: " + mUserUuid);
+ msg("\taccessToken: " + mAccesstoken);
+ msg("\trefreshToken: " + mRefreshtoken);
+ msg("\ttokenType: " + tokenType);
+
+ if (ocRepresentation.hasAttribute("expiresin"))
+ {
+ int expiresIn = ocRepresentation.getValue("expiresin");
+ msg("\texpiresIn: " + expiresIn);
+ }
+ } catch (OcException e) {
+ Log.e(TAG, e.toString());
+ }
+ }
+
+ @Override
+ public synchronized void onPostFailed(Throwable throwable) {
+ msg("Failed to signUp");
+ if (throwable instanceof OcException) {
+ OcException ocEx = (OcException) throwable;
+ Log.e(TAG, ocEx.toString());
+ ErrorCode errCode = ocEx.getErrorCode();
+ msg("Error code: " + errCode);
+ }
+ }
+ };
+
+ OcAccountManager.OnPostListener onSignIn = new OcAccountManager.OnPostListener() {
+ @Override
+ public synchronized void onPostCompleted(List<OcHeaderOption> list,
+ OcRepresentation ocRepresentation) {
+ msg("signIn was successful");
+ try {
+ msg("observeInvitation");
+ mAccountManager.observeInvitation(onObserveInvitation);
+ msg("getGroupList");
+ mAccountManager.getGroupList(onGetGrouptList);
+ } catch (OcException e) {
+ Log.e(TAG, e.toString());
+ }
+ }
+
+ @Override
+ public synchronized void onPostFailed(Throwable throwable) {
+ msg("Failed to signIn");
+ if (throwable instanceof OcException) {
+ OcException ocEx = (OcException) throwable;
+ Log.e(TAG, ocEx.toString());
+ ErrorCode errCode = ocEx.getErrorCode();
+ msg("Error code: " + errCode);
+ }
+ }
+ };
+
+ OcAccountManager.OnGetListener onGetGrouptList = new OcAccountManager.OnGetListener() {
+ @Override
+ public void onGetCompleted(List<OcHeaderOption> list, OcRepresentation ocRepresentation) {
+ msg("getGroupList was successful");
+ try {
+ String[] gidlist = ocRepresentation.getValue("gidlist");
+ if (gidlist == null) {
+ msg("\tgroup list is empty");
+ mGroupId = null;
+ }
+ else{
+ msg("\tgroup list");
+ for (String group : gidlist) {
+ msg("\t\t" + group);
+ mGroupId = group;
+ }
+ msg("\tcurrent group is " + mGroupId);
+ }
+ } catch (OcException e) {
+ e.printStackTrace();
+ }
+ }
+
+ @Override
+ public void onGetFailed(Throwable throwable) {
+ msg("Failed to getGroupList");
+ if (throwable instanceof OcException) {
+ OcException ocEx = (OcException) throwable;
+ Log.e(TAG, ocEx.toString());
+ ErrorCode errCode = ocEx.getErrorCode();
+ msg("Error code: " + errCode);
+ }
+ }
+ };
+
+ OcAccountManager.OnObserveListener onObserveInvitation = new OcAccountManager.OnObserveListener() {
+ @Override
+ public void onObserveCompleted(List<OcHeaderOption> list, OcRepresentation ocRepresentation, int i) {
+ msg("observeInvitation was successful");
+ try {
+ if (this.REGISTER == i) {
+ msg("REGISTER was successful");
+
+ OcRepresentation[] sendInvitationList = ocRepresentation.getValue("invite");
+ if (sendInvitationList != null) {
+ msg("\tList of invitation that I sent");
+ for (OcRepresentation invitation : sendInvitationList) {
+ String gid = invitation.getValue("gid");
+ String mid = invitation.getValue("mid");
+ msg("\t\t-GroupID : " + gid);
+ msg("\t\t InviteeID : " + mid);
+ }
+ }
+
+ OcRepresentation[] receivInvitationList = ocRepresentation.getValue("invited");
+ if (receivInvitationList != null) {
+ msg("\tList of invitation that I received");
+ for (OcRepresentation invitation : receivInvitationList) {
+ String gid = invitation.getValue("gid");
+ String mid = invitation.getValue("mid");
+ msg("\t\t-GroupID : " + gid);
+ msg("\t\t InviterID : " + mid);
+ }
+ }
+ } else if (this.DEREGISTER == i) {
+ msg("DEREGISTER was successful");
+ } else {
+ OcRepresentation[] sendInvitationList = ocRepresentation.getValue("invite");
+ if (sendInvitationList != null) {
+ msg("\tList of invitation that I sent");
+ for (OcRepresentation invitation : sendInvitationList) {
+ String gid = invitation.getValue("gid");
+ String mid = invitation.getValue("mid");
+ msg("\t\t-GroupID : " + gid);
+ msg("\t\t InviteeID : " + mid);
+ }
+ }
+
+ OcRepresentation[] receivInvitationList = ocRepresentation.getValue("invited");
+ if (receivInvitationList != null) {
+ msg("\tList of invitation that I received");
+ for (OcRepresentation invitation : receivInvitationList) {
+ mGroupId = invitation.getValue("gid");
+ mGroupMasterId = invitation.getValue("mid");
+ msg("\t\t-GroupID : " + mGroupId);
+ msg("\t\t InviterID : " + mGroupMasterId);
+ }
+ msg("searchUser");
+ mAccountManager.searchUser(mGroupMasterId, onSearchUserForInvitee);
+ }
+ }
+ } catch (OcException e) {
+ e.printStackTrace();
+ }
+ }
+
+ @Override
+ public void onObserveFailed(Throwable throwable) {
+ msg("Failed to observeInvitation");
+ if (throwable instanceof OcException) {
+ OcException ocEx = (OcException) throwable;
+ Log.e(TAG, ocEx.toString());
+ ErrorCode errCode = ocEx.getErrorCode();
+ msg("Error code: " + errCode);
+ }
+ }
+ };
+
+ OcAccountManager.OnGetListener onSearchUserForInvitee = new OcAccountManager.OnGetListener() {
+ @Override
+ public synchronized void onGetCompleted(List<OcHeaderOption> list,
+ OcRepresentation ocRepresentation) {
+ msg("searchUser was successful");
+ try {
+ OcRepresentation[] userList = ocRepresentation.getValue("ulist");
+ for (OcRepresentation user : userList) {
+ mInviterUuid = user.getValue("uid");
+ OcRepresentation userInfo = user.getValue("uinfo");
+ mInviterUserId = userInfo.getValue("userid");
+ }
+
+ mActivity.runOnUiThread(new Runnable() {
+ public void run() {
+ showInviteMsg(mInviterUserId);
+ }
+ });
+
+ } catch (OcException e) {
+ e.printStackTrace();
+ }
+ }
+
+ @Override
+ public synchronized void onGetFailed(Throwable throwable) {
+ msg("Failed to searchUser");
+ if (throwable instanceof OcException) {
+ OcException ocEx = (OcException) throwable;
+ Log.e(TAG, ocEx.toString());
+ ErrorCode errCode = ocEx.getErrorCode();
+ msg("Error code: " + errCode);
+ }
+ }
+ };
+
+ OcAccountManager.OnPostListener onJoinGroup = new OcAccountManager.OnPostListener() {
+ @Override
+ public synchronized void onPostCompleted(List<OcHeaderOption> list,
+ OcRepresentation ocRepresentation) {
+ msg("joinGroup was successful");
+ try {
+ msg("observeGroup");
+ mAccountManager.observeGroup(mGroupId, onObserveGroup);
+ } catch (OcException e) {
+ Log.e(TAG, e.toString());
+ }
+ }
+
+ @Override
+ public synchronized void onPostFailed(Throwable throwable) {
+ msg("Failed to joinGroup");
+ if (throwable instanceof OcException) {
+ OcException ocEx = (OcException) throwable;
+ Log.e(TAG, ocEx.toString());
+ ErrorCode errCode = ocEx.getErrorCode();
+ msg("Error code: " + errCode);
+ }
+ }
+ };
+
+ OcAccountManager.OnDeleteListener onDeleteInvitation = new OcAccountManager.OnDeleteListener() {
+ @Override
+ public void onDeleteCompleted(List<OcHeaderOption> list) {
+ msg("deleteInvitation was successful");
+ try {
+ mAccountManager.getGroupList(onGetGrouptList);
+ } catch (OcException e) {
+ e.printStackTrace();
+ }
+ }
+
+ @Override
+ public void onDeleteFailed(Throwable throwable) {
+ msg("Failed to deleteInvitation");
+ }
+ };
+
+ OcAccountManager.OnGetListener onSearchUserForInviter = new OcAccountManager.OnGetListener() {
+ @Override
+ public synchronized void onGetCompleted(List<OcHeaderOption> list,
+ OcRepresentation ocRepresentation) {
+ msg("searchUser was successful");
+ try {
+ OcRepresentation[] userList = ocRepresentation.getValue("ulist");
+ for (OcRepresentation user : userList) {
+ mInviteeUuid = user.getValue("uid");
+ OcRepresentation userInfo = user.getValue("uinfo");
+ mInviteeUserId = userInfo.getValue("userid");
+ }
+ msg("sendInvitation");
+ mAccountManager.sendInvitation(mGroupId, mInviteeUuid, onSendInvitation);
+ } catch (OcException e) {
+ e.printStackTrace();
+ }
+ }
+
+ @Override
+ public synchronized void onGetFailed(Throwable throwable) {
+ msg("Failed to searchUser");
+ if (throwable instanceof OcException) {
+ OcException ocEx = (OcException) throwable;
+ Log.e(TAG, ocEx.toString());
+ ErrorCode errCode = ocEx.getErrorCode();
+ msg("Error code: " + errCode);
+ }
+ }
+ };
+
+ OcAccountManager.OnPostListener onCreateGroup = new OcAccountManager.OnPostListener() {
+ @Override
+ public synchronized void onPostCompleted(List<OcHeaderOption> list,
+ OcRepresentation ocRepresentation) {
+ msg("createGroup was successful");
+ try {
+ mGroupId = ocRepresentation.getValue("gid");
+ msg("\tgroupId: " + mGroupId);
+
+ msg("observeGroup");
+ mAccountManager.observeGroup(mGroupId, onObserveGroup);
+ } catch (OcException e) {
+ Log.e(TAG, e.toString());
+ }
+ }
+
+ @Override
+ public synchronized void onPostFailed(Throwable throwable) {
+ msg("Failed to createGroup");
+ if (throwable instanceof OcException) {
+ OcException ocEx = (OcException) throwable;
+ Log.e(TAG, ocEx.toString());
+ ErrorCode errCode = ocEx.getErrorCode();
+ msg("Error code: " + errCode);
+ }
+ }
+ };
+
+ OcAccountManager.OnObserveListener onObserveGroup = new OcAccountManager.OnObserveListener() {
+ @Override
+ public void onObserveCompleted(List<OcHeaderOption> list, OcRepresentation ocRepresentation, int i) {
+ msg("observeGroup was successful");
+ try {
+ if (this.REGISTER == i) {
+ msg("REGISTER was successful");
+ } else if (this.DEREGISTER == i) {
+ msg("DEREGISTER was successful");
+ } else {
+ String gid = ocRepresentation.getValue("gid");
+ msg("\tGroupID: " + gid);
+
+ String gmid = ocRepresentation.getValue("gmid");
+ msg("\tGroupMasterID: " + gmid);
+
+ String[] midlist = ocRepresentation.getValue("midlist");
+ if (midlist == null){
+ msg("\tMember List is empty");
+ }
+ else {
+ msg("\tMember List(" + midlist.length + ")");
+ for (String mid : midlist) {
+ msg("\t : " + mid);
+ }
+ }
+
+ String[] dilist = ocRepresentation.getValue("dilist");
+ if (dilist == null){
+ msg("\tDevice List is empty");
+ }
+ else {
+ msg("\tDevice List(" + dilist.length + ")");
+ for (String di : dilist) {
+ msg("\t : " + di);
+ }
+ }
+ }
+ } catch (OcException e) {
+ e.printStackTrace();
+ }
+ }
+
+ @Override
+ public void onObserveFailed(Throwable throwable) {
+ msg("Failed to observeGroup");
+ if (throwable instanceof OcException) {
+ OcException ocEx = (OcException) throwable;
+ Log.e(TAG, ocEx.toString());
+ ErrorCode errCode = ocEx.getErrorCode();
+ msg("Error code: " + errCode);
+ }
+ }
+ };
+
+ OcAccountManager.OnPostListener onSendInvitation = new OcAccountManager.OnPostListener() {
+ @Override
+ public synchronized void onPostCompleted(List<OcHeaderOption> list,
+ OcRepresentation ocRepresentation) {
+ msg("sendInvitation was successful");
+ }
+
+ @Override
+ public synchronized void onPostFailed(Throwable throwable) {
+ msg("Failed to sendInvitation");
+ if (throwable instanceof OcException) {
+ OcException ocEx = (OcException) throwable;
+ Log.e(TAG, ocEx.toString());
+ ErrorCode errCode = ocEx.getErrorCode();
+ msg("Error code: " + errCode);
+ }
+ }
+ };
+
+ OcAccountManager.OnDeleteListener onLeaveGroup = new OcAccountManager.OnDeleteListener() {
+ @Override
+ public void onDeleteCompleted(List<OcHeaderOption> list) {
+ msg("leaveGroup was successful");
+ try {
+ msg("getGroupList");
+ mAccountManager.getGroupList(onGetGrouptList);
+ } catch (OcException e) {
+ e.printStackTrace();
+ }
+ }
+
+ @Override
+ public void onDeleteFailed(Throwable throwable) {
+ msg("Failed to leaveGroup");
+ }
+ };