com.easemob.EMCallBack Java Examples

The following examples show how to use com.easemob.EMCallBack. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EaseMobService.java    From monolog-android with MIT License 6 votes vote down vote up
/**
 * 用户登录
 *
 * @param handler
 */
public void easeMobLogin(final Handler handler) {
    UserBean user = AppContext.getInstance().getUser();
    String name = user.getId();
    String pwd = "pwd" + user.getId();
    EMChatManager.getInstance().login(name, pwd, new EMCallBack() {

        @Override
        public void onSuccess() {
            handler.sendEmptyMessage(0);
        }

        @Override
        public void onProgress(int progress, String status) {
        }

        @Override
        public void onError(final int code, final String error) {
            handler.sendEmptyMessage(1);
        }
    });
}
 
Example #2
Source File: DemoHXSDKHelper.java    From school_shop with MIT License 5 votes vote down vote up
@Override
    public void logout(final EMCallBack callback){
//        endCall();
        super.logout(new EMCallBack(){

            @Override
            public void onSuccess() {
                setContactList(null);
                getModel().closeDB();
                if(callback != null){
                    callback.onSuccess();
                }
            }

            @Override
            public void onError(int code, String message) {
                // TODO Auto-generated method stub
                
            }

            @Override
            public void onProgress(int progress, String status) {
                // TODO Auto-generated method stub
                if(callback != null){
                    callback.onProgress(progress, status);
                }
            }
            
        });
    }
 
Example #3
Source File: HXSDKHelper.java    From FanXin-based-HuanXin with GNU General Public License v2.0 5 votes vote down vote up
/**
 * logout HuanXin SDK
 */
public void logout(final EMCallBack callback){
    EMChatManager.getInstance().logout(new EMCallBack(){

        @Override
        public void onSuccess() {
            // TODO Auto-generated method stub
            setPassword(null);
            if(callback != null){
                callback.onSuccess();
            }
        }

        @Override
        public void onError(int code, String message) {
            // TODO Auto-generated method stub
            
        }

        @Override
        public void onProgress(int progress, String status) {
            // TODO Auto-generated method stub
            if(callback != null){
                callback.onProgress(progress, status);
            }
        }
        
    });
}
 
Example #4
Source File: MYApplication.java    From FanXin-based-HuanXin with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 退出登录,清空数据
 */
public void logout(final EMCallBack emCallBack) {
    // 先调用sdk logout,在清理app中自己的数据
    hxSDKHelper.logout(emCallBack);
    finishActivitys();
    
}
 
Example #5
Source File: SettingActivity.java    From FanXin-based-HuanXin with GNU General Public License v2.0 5 votes vote down vote up
void logout() {
    final ProgressDialog pd = new ProgressDialog(SettingActivity.this);
    pd.setMessage("正在退出登陆..");
    pd.setCanceledOnTouchOutside(false);
    pd.show();
    MYApplication.getInstance().logout(new EMCallBack() {
        
        @Override
        public void onSuccess() {
            SettingActivity.this.runOnUiThread(new Runnable() {
                public void run() {
                    pd.dismiss();
                    // 重新显示登陆页面
                    finish();
                    startActivity(new Intent(SettingActivity.this, LoginActivity.class));
                    
                }
            });
        }
        
        @Override
        public void onProgress(int progress, String status) {
            
        }
        
        @Override
        public void onError(int code, String message) {
            
        }
    });
}
 
Example #6
Source File: MessageAdapter.java    From FanXin-based-HuanXin with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 发送消息
 * 
 * @param message
 * @param holder
 * @param position
 */
public void sendMsgInBackground(final EMMessage message,
        final ViewHolder holder) {
    holder.staus_iv.setVisibility(View.GONE);
    holder.pb.setVisibility(View.VISIBLE);

    final long start = System.currentTimeMillis();
    // 调用sdk发送异步发送方法
    EMChatManager.getInstance().sendMessage(message, new EMCallBack() {

        @Override
        public void onSuccess() {
            // umeng自定义事件,

            updateSendedView(message, holder);
        }

        @Override
        public void onError(int code, String error) {

            updateSendedView(message, holder);
        }

        @Override
        public void onProgress(int progress, String status) {
        }

    });

}
 
Example #7
Source File: DemoHXSDKHelper.java    From FanXin-based-HuanXin with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void logout(final EMCallBack callback) {
    super.logout(new EMCallBack() {

        @Override
        public void onSuccess() {
            // TODO Auto-generated method stub
            setContactList(null);
            getModel().closeDB();
            if (callback != null) {
                callback.onSuccess();
            }
        }

        @Override
        public void onError(int code, String message) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onProgress(int progress, String status) {
            // TODO Auto-generated method stub
            if (callback != null) {
                callback.onProgress(progress, status);
            }
        }

    });
}
 
Example #8
Source File: MessageAdapter.java    From school_shop with MIT License 5 votes vote down vote up
/**
 * 发送消息
 * 
 * @param message
 * @param holder
 * @param position
 */
public void sendMsgInBackground(final EMMessage message, final ViewHolder holder) {
	holder.staus_iv.setVisibility(View.GONE);
	holder.pb.setVisibility(View.VISIBLE);

	final long start = System.currentTimeMillis();
	// 调用sdk发送异步发送方法
	EMChatManager.getInstance().sendMessage(message, new EMCallBack() {

		@Override
		public void onSuccess() {
			
			updateSendedView(message, holder);
		}

		@Override
		public void onError(int code, String error) {
			
			updateSendedView(message, holder);
		}

		@Override
		public void onProgress(int progress, String status) {
		}

	});

}
 
Example #9
Source File: HXSDKHelper.java    From school_shop with MIT License 5 votes vote down vote up
/**
 * logout HuanXin SDK
 */
public void logout(final EMCallBack callback){
    setPassword(null);
    EMChatManager.getInstance().logout(new EMCallBack(){

        @Override
        public void onSuccess() {
            // TODO Auto-generated method stub
            if(callback != null){
                callback.onSuccess();
            }
        }

        @Override
        public void onError(int code, String message) {
            // TODO Auto-generated method stub
            
        }

        @Override
        public void onProgress(int progress, String status) {
            // TODO Auto-generated method stub
            if(callback != null){
                callback.onProgress(progress, status);
            }
        }
        
    });
}
 
Example #10
Source File: LoginActivity.java    From school_shop with MIT License 4 votes vote down vote up
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
	super.onActivityResult(requestCode, resultCode, data);
	if (resultCode == RESULT_OK) {
		if (requestCode == REQUEST_CODE_SETNICK) {
			MyApplication.currentUserNick = data.getStringExtra("edittext");

			progressShow = true;
			final ProgressDialog pd = new ProgressDialog(LoginActivity.this);
			pd.setCanceledOnTouchOutside(false);
			pd.setOnCancelListener(new OnCancelListener() {

				@Override
				public void onCancel(DialogInterface dialog) {
					progressShow = false;
				}
			});
			pd.setMessage(getString(R.string.Is_landing));
			pd.show();

			// 调用sdk登陆方法登陆聊天服务器
			EMChatManager.getInstance().login(currentUsername, currentPassword, new EMCallBack() {

				@Override
				public void onSuccess() {
					
					if (!progressShow) {
						return;
					}
					// 登陆成功,保存用户名密码
					MyApplication.getInstance().setUserName(currentUsername);
					MyApplication.getInstance().setPassword(currentPassword);
					
					runOnUiThread(new Runnable() {
						public void run() {
							pd.setMessage(getString(R.string.list_is_for));
						}
					});
					try {
						// ** 第一次登录或者之前logout后再登录,加载所有本地群和回话
						// ** manually load all local groups and
						// conversations in case we are auto login
						EMGroupManager.getInstance().loadAllGroups();
						EMChatManager.getInstance().loadAllConversations();
						//处理好友和群组
						processContactsAndGroups();
					} catch (Exception e) {
						e.printStackTrace();
						//取好友或者群聊失败,不让进入主页面
						runOnUiThread(new Runnable() {
                               public void run() {
                                   pd.dismiss();
                                   MyApplication.getInstance().logout(null);
                                   Toast.makeText(getApplicationContext(), R.string.login_failure_failed, 1).show();
                               }
                           });
						return;
					}
					//更新当前用户的nickname 此方法的作用是在ios离线推送时能够显示用户nick
					boolean updatenick = EMChatManager.getInstance().updateCurrentUserNick(MyApplication.currentUserNick.trim());
					if (!updatenick) {
						Log.e("LoginActivity", "update current user nick fail");
					}
					if (!LoginActivity.this.isFinishing())
						pd.dismiss();
					// 进入主页面
					autoLogin = true;
					Intent intent = new Intent(LoginActivity.this, ChatActivity.class);
					intent.putExtra("chatType", ChatActivity.CHATTYPE_SINGLE);
					intent.putExtra("userId", "test1");
					startActivity(intent);
					finish();
				}

                  

				@Override
				public void onProgress(int progress, String status) {
				}

				@Override
				public void onError(final int code, final String message) {
					if (!progressShow) {
						return;
					}
					runOnUiThread(new Runnable() {
						public void run() {
							pd.dismiss();
							Toast.makeText(getApplicationContext(), getString(R.string.Login_failed) + message, Toast.LENGTH_SHORT).show();
						}
					});
				}
			});

		}
	}
}
 
Example #11
Source File: EaseShowBigImageActivity.java    From monolog-android with MIT License 4 votes vote down vote up
/**
 * 下载图片
 * 
 * @param remoteFilePath
 */
private void downloadImage(final String remoteFilePath, final Map<String, String> headers) {
	String str1 = getResources().getString(R.string.Download_the_pictures);
	pd = new ProgressDialog(this);
	pd.setProgressStyle(ProgressDialog.STYLE_SPINNER);
	pd.setCanceledOnTouchOutside(false);
	pd.setMessage(str1);
	pd.show();
	localFilePath = getLocalFilePath(remoteFilePath);
	final EMCallBack callback = new EMCallBack() {
		public void onSuccess() {

			runOnUiThread(new Runnable() {
				@Override
				public void run() {
					DisplayMetrics metrics = new DisplayMetrics();
					getWindowManager().getDefaultDisplay().getMetrics(metrics);
					int screenWidth = metrics.widthPixels;
					int screenHeight = metrics.heightPixels;

					bitmap = ImageUtils.decodeScaleImage(localFilePath, screenWidth, screenHeight);
					if (bitmap == null) {
						image.setImageResource(default_res);
					} else {
						image.setImageBitmap(bitmap);
						EaseImageCache.getInstance().put(localFilePath, bitmap);
						isDownloaded = true;
					}
					if (pd != null) {
						pd.dismiss();
					}
				}
			});
		}

		public void onError(int error, String msg) {
			EMLog.e(TAG, "offline file transfer error:" + msg);
			File file = new File(localFilePath);
			if (file.exists()&&file.isFile()) {
				file.delete();
			}
			runOnUiThread(new Runnable() {
				@Override
				public void run() {
					pd.dismiss();
					image.setImageResource(default_res);
				}
			});
		}

		public void onProgress(final int progress, String status) {
			EMLog.d(TAG, "Progress: " + progress);
			final String str2 = getResources().getString(R.string.Download_the_pictures_new);
			runOnUiThread(new Runnable() {
				@Override
				public void run() {
					
					pd.setMessage(str2 + progress + "%");
				}
			});
		}
	};

    EMChatManager.getInstance().downloadFile(remoteFilePath, localFilePath, headers, callback);

}
 
Example #12
Source File: MessageAdapter.java    From school_shop with MIT License 4 votes vote down vote up
private void sendPictureMessage(final EMMessage message, final ViewHolder holder) {
	try {
		String to = message.getTo();

		// before send, update ui
		holder.staus_iv.setVisibility(View.GONE);
		holder.pb.setVisibility(View.VISIBLE);
		holder.tv.setVisibility(View.VISIBLE);
		holder.tv.setText("0%");
		
		final long start = System.currentTimeMillis();
		// if (chatType == ChatActivity.CHATTYPE_SINGLE) {
		EMChatManager.getInstance().sendMessage(message, new EMCallBack() {

			@Override
			public void onSuccess() {
				Log.d(TAG, "send image message successfully");
				activity.runOnUiThread(new Runnable() {
					public void run() {
						// send success
						holder.pb.setVisibility(View.GONE);
						holder.tv.setVisibility(View.GONE);
					}
				});
			}

			@Override
			public void onError(int code, String error) {
				
				activity.runOnUiThread(new Runnable() {
					public void run() {
						holder.pb.setVisibility(View.GONE);
						holder.tv.setVisibility(View.GONE);
						// message.setSendingStatus(Message.SENDING_STATUS_FAIL);
						holder.staus_iv.setVisibility(View.VISIBLE);
						Toast.makeText(activity,
								activity.getString(R.string.send_fail) + activity.getString(R.string.connect_failuer_toast), 0).show();
					}
				});
			}

			@Override
			public void onProgress(final int progress, String status) {
				activity.runOnUiThread(new Runnable() {
					public void run() {
						holder.tv.setText(progress + "%");
					}
				});
			}

		});
	} catch (Exception e) {
		e.printStackTrace();
	}
}
 
Example #13
Source File: SettingFragment.java    From school_shop with MIT License 4 votes vote down vote up
@Override
public void onClick(View v) {
	int id = v.getId();
	switch (id) {
	case R.id.setting_account:
		if (Constants.ISLOGIN) startActivity(new Intent(getActivity(),AccountSetting.class));
		else showButtomToast("亲,你还没登录~");
		break;
	case R.id.loginOut:
		loadingProgressDialog.show();
		MyApplication.getInstance().logout(new EMCallBack() {
			
			@Override
			public void onSuccess() {
				getActivity().runOnUiThread(new Runnable() {
					public void run() {
						loadingProgressDialog.dismiss();
						AccountInfoUtils.loginOut(getActivity());
						showButtomToast(getStringByRId(R.string.loginout_success));
						Intent intent = new Intent(getActivity(),ChooseSchoolActivity.class);
						intent.putExtra("isFirst", true);
						startActivity(intent);
						getActivity().finish();
					}
				});
			}
			
			@Override
			public void onProgress(int progress, String status) {
				loadingProgressDialog.setMessage(getString(R.string.loginouting));
			}
			
			@Override
			public void onError(int code, String message) {
				
			}
		});
		break;
	case R.id.feedback:
		startActivity(new Intent(getActivity(),FeedbackActivity.class));
		break;
	case R.id.aboutus:
		startActivity(new Intent(getActivity(),AboutActivity.class));
		break;
	default:
		break;
	}
}
 
Example #14
Source File: LoginActivity.java    From school_shop with MIT License 4 votes vote down vote up
private void loginHx(){
		currentUsername = userEntity.getHxId();
		currentPassword = pwdEditText.getText().toString();
		// 调用sdk登陆方法登陆聊天服务器
		EMChatManager.getInstance().login(currentUsername, currentPassword, new EMCallBack() {

			@Override
			public void onSuccess() {
				loginSuccess();
//				if (!progressShow) {
//					return;
//				}
				// 登陆成功,保存用户名密码
//				MyApplication.getInstance().setUserName(currentUsername);
//				MyApplication.getInstance().setPassword(currentPassword);
				//更新当前用户的nickname 此方法的作用是在ios离线推送时能够显示用户nick
//				boolean updatenick = EMChatManager.getInstance().updateCurrentUserNick(MyApplication.currentUserNick.trim());
//				if (!updatenick) {
//					Log.e("LoginActivity", "update current user nick fail");
//				}
//				if (!LoginActivity.this.isFinishing())
//					pd.dismiss();
			}

			@Override
			public void onProgress(int progress, String status) {
				loadingProgressDialog.setMessage(getStringByRId(R.string.logining));
			}

			@Override
			public void onError(final int code, final String message) {
				loadingProgressDialog.dismiss();
				runOnUiThread(new Runnable() {
					@Override
					public void run() {
						showButtomToast(getStringByRId(R.string.login_fail));
					}
				});
			}
		});
	}
 
Example #15
Source File: MyApplication.java    From school_shop with MIT License 4 votes vote down vote up
/**
 * 退出登录,清空数据
 */
public void logout(final EMCallBack emCallBack) {
	// 先调用sdk logout,在清理app中自己的数据
    hxSDKHelper.logout(emCallBack);
}
 
Example #16
Source File: MessageAdapter.java    From FanXin-based-HuanXin with GNU General Public License v2.0 4 votes vote down vote up
private void sendPictureMessage(final EMMessage message,
        final ViewHolder holder) {
    try {
        String to = message.getTo();

        // before send, update ui
        holder.staus_iv.setVisibility(View.GONE);
        holder.pb.setVisibility(View.VISIBLE);
        holder.tv.setVisibility(View.VISIBLE);
        holder.tv.setText("0%");

        final long start = System.currentTimeMillis();
        // if (chatType == ChatActivity.CHATTYPE_SINGLE) {
        EMChatManager.getInstance().sendMessage(message, new EMCallBack() {

            @Override
            public void onSuccess() {
                Log.d(TAG, "send image message successfully");

                activity.runOnUiThread(new Runnable() {
                    public void run() {
                        // send success
                        holder.pb.setVisibility(View.GONE);
                        holder.tv.setVisibility(View.GONE);
                    }
                });
            }

            @Override
            public void onError(int code, String error) {

                activity.runOnUiThread(new Runnable() {
                    public void run() {
                        holder.pb.setVisibility(View.GONE);
                        holder.tv.setVisibility(View.GONE);
                        // message.setSendingStatus(Message.SENDING_STATUS_FAIL);
                        holder.staus_iv.setVisibility(View.VISIBLE);
                        Toast.makeText(
                                activity,
                                activity.getString(R.string.send_fail)
                                        + activity
                                                .getString(R.string.connect_failuer_toast),
                                0).show();
                    }
                });
            }

            @Override
            public void onProgress(final int progress, String status) {
                activity.runOnUiThread(new Runnable() {
                    public void run() {
                        holder.tv.setText(progress + "%");
                    }
                });
            }

        });
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example #17
Source File: EaseShowVideoActivity.java    From monolog-android with MIT License 4 votes vote down vote up
/**
 * 下载视频文件
 */
private void downloadVideo(final String remoteUrl,
		final Map<String, String> header) {

	if (TextUtils.isEmpty(localFilePath)) {
		localFilePath = getLocalFilePath(remoteUrl);
	}
	if (new File(localFilePath).exists()) {
		showLocalVideo(localFilePath);
		return;
	}
	loadingLayout.setVisibility(View.VISIBLE);
	
	EMCallBack callback = new EMCallBack() {

		@Override
		public void onSuccess() {
			runOnUiThread(new Runnable() {

				@Override
				public void run() {
					loadingLayout.setVisibility(View.GONE);
					progressBar.setProgress(0);
					showLocalVideo(localFilePath);
				}
			});
		}

		@Override
		public void onProgress(final int progress,String status) {
			Log.d("ease", "video progress:" + progress);
			runOnUiThread(new Runnable() {

				@Override
				public void run() {
					progressBar.setProgress(progress);
				}
			});

		}

		@Override
		public void onError(int error, String msg) {
			Log.e("###", "offline file transfer error:" + msg);
			File file = new File(localFilePath);
			if (file.exists()) {
				file.delete();
			}
		}
	};

	EMChatManager.getInstance().downloadFile(remoteUrl, localFilePath, header, callback);
}
 
Example #18
Source File: EaseShowNormalFileActivity.java    From monolog-android with MIT License 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.ease_activity_show_file);
	progressBar = (ProgressBar) findViewById(R.id.progressBar);

	final FileMessageBody messageBody = getIntent().getParcelableExtra("msgbody");
	file = new File(messageBody.getLocalUrl());
	//set head map
	final Map<String, String> maps = new HashMap<String, String>();
	if (!TextUtils.isEmpty(messageBody.getSecret())) {
		maps.put("share-secret", messageBody.getSecret());
	}
	
	//下载文件
	EMChatManager.getInstance().downloadFile(messageBody.getRemoteUrl(), messageBody.getLocalUrl(), maps,
               new EMCallBack() {
                   
                   @Override
                   public void onSuccess() {
                       runOnUiThread(new Runnable() {
                           public void run() {
                               FileUtils.openFile(file, EaseShowNormalFileActivity.this);
                               finish();
                           }
                       });
                   }
                   
                   @Override
                   public void onProgress(final int progress,String status) {
                       runOnUiThread(new Runnable() {
                           public void run() {
                               progressBar.setProgress(progress);
                           }
                       });
                   }
                   
                   @Override
                   public void onError(int error, final String msg) {
                       runOnUiThread(new Runnable() {
                           public void run() {
                               if(file != null && file.exists()&&file.isFile())
                                   file.delete();
                               String str4 = getResources().getString(R.string.Failed_to_download_file);
                               Toast.makeText(EaseShowNormalFileActivity.this, str4+msg, Toast.LENGTH_SHORT).show();
                               finish();
                           }
                       });
                   }
               });
	
}