Java Code Examples for com.easemob.util.EMLog#d()

The following examples show how to use com.easemob.util.EMLog#d() . 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: EaseNotifier.java    From monolog-android with MIT License 6 votes vote down vote up
/**
 * 处理新收到的消息,然后发送通知
 * 
 * 开发者可以重载此函数
 * this function can be override
 * 
 * @param message
 */
public synchronized void onNewMsg(EMMessage message) {
    if(EMChatManager.getInstance().isSlientMessage(message)){
        return;
    }
    EaseSettingsProvider settingsProvider = EaseUI.getInstance().getSettingsProvider();
    if(!settingsProvider.isMsgNotifyAllowed(message)){
        return;
    }
    
    // 判断app是否在后台
    if (!EasyUtils.isAppRunningForeground(appContext)) {
        EMLog.d(TAG, "app is running in backgroud");
        sendNotification(message, false);
    } else {
        sendNotification(message, true);

    }
    
    viberateAndPlayTone(message);
}
 
Example 2
Source File: EaseNotifier.java    From monolog-android with MIT License 6 votes vote down vote up
public synchronized void onNewMesg(List<EMMessage> messages) {
    if(EMChatManager.getInstance().isSlientMessage(messages.get(messages.size()-1))){
        return;
    }
    EaseSettingsProvider settingsProvider = EaseUI.getInstance().getSettingsProvider();
    if(!settingsProvider.isMsgNotifyAllowed(null)){
        return;
    }
    // 判断app是否在后台
    if (!EasyUtils.isAppRunningForeground(appContext)) {
        EMLog.d(TAG, "app is running in backgroud");
        sendNotification(messages, false);
    } else {
        sendNotification(messages, true);
    }
    viberateAndPlayTone(messages.get(messages.size()-1));
}
 
Example 3
Source File: EaseContactAdapter.java    From monolog-android with MIT License 6 votes vote down vote up
@Override
public Object[] getSections() {
    positionOfSection = new SparseIntArray();
    sectionOfPosition = new SparseIntArray();
    int count = getCount();
    list = new ArrayList<String>();
    list.add(getContext().getString(R.string.search_header));
    positionOfSection.put(0, 0);
    sectionOfPosition.put(0, 0);
    for (int i = 1; i < count; i++) {

        String letter = getItem(i).getInitialLetter();
        EMLog.d(TAG, "contactadapter getsection getHeader:" + letter + " name:" + getItem(i).getUsername());
        int section = list.size() - 1;
        if (list.get(section) != null && !list.get(section).equals(letter)) {
            list.add(letter);
            section++;
            positionOfSection.put(section, i);
        }
        sectionOfPosition.put(i, section);
    }
    return list.toArray(new String[list.size()]);
}
 
Example 4
Source File: EaseChatRowVideo.java    From monolog-android with MIT License 6 votes vote down vote up
@Override
protected void onBubbleClick() {
    VideoMessageBody videoBody = (VideoMessageBody) message.getBody();
       EMLog.d(TAG, "video view is on click");
       Intent intent = new Intent(context, EaseShowVideoActivity.class);
       intent.putExtra("localpath", videoBody.getLocalUrl());
       intent.putExtra("secret", videoBody.getSecret());
       intent.putExtra("remotepath", videoBody.getRemoteUrl());
       if (message != null && message.direct == EMMessage.Direct.RECEIVE && !message.isAcked
               && message.getChatType() != ChatType.GroupChat) {
           message.isAcked = true;
           try {
               EMChatManager.getInstance().ackMessageRead(message.getFrom(), message.getMsgId());
           } catch (Exception e) {
               e.printStackTrace();
           }
       }
       activity.startActivity(intent);
}
 
Example 5
Source File: HXNotifier.java    From school_shop with MIT License 6 votes vote down vote up
/**
 * 处理新收到的消息,然后发送通知
 * 
 * 开发者可以重载此函数
 * this function can be override
 * 
 * @param message
 */
public synchronized void onNewMsg(final EMMessage message) {
    if(EMChatManager.getInstance().isSlientMessage(message)){
        return;
    }
    
    // 判断app是否在后台
    if (!EasyUtils.isAppRunningForeground(appContext)) {
        EMLog.d(TAG, "app is running in backgroud");
        sendNotification(message, false);
    } else {
        sendNotification(message, true);

    }
    
    viberateAndPlayTone(message);
}
 
Example 6
Source File: CallReceiver.java    From school_shop with MIT License 6 votes vote down vote up
@Override
	public void onReceive(Context context, Intent intent) {
		if(!DemoHXSDKHelper.getInstance().isLogined())
		    return;
		//拨打方username
		String from = intent.getStringExtra("from");
		//call type
//		String type = intent.getStringExtra("type");
//		if("video".equals(type)){ //视频通话
//		    context.startActivity(new Intent(context, VideoCallActivity.class).
//                    putExtra("username", from).putExtra("isComingCall", true).
//                    addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
//		}else{ //音频通话
//		    context.startActivity(new Intent(context, VoiceCallActivity.class).
//		            putExtra("username", from).putExtra("isComingCall", true).
//		            addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
//		}
		EMLog.d("CallReceiver", "app received a incoming call");
	}
 
Example 7
Source File: EaseImageUtils.java    From monolog-android with MIT License 5 votes vote down vote up
public static String getImagePath(String remoteUrl)
{
	String imageName= remoteUrl.substring(remoteUrl.lastIndexOf("/") + 1, remoteUrl.length());
	String path =PathUtil.getInstance().getImagePath()+"/"+ imageName;
       EMLog.d("msg", "image path:" + path);
       return path;
	
}
 
Example 8
Source File: DownloadImageTask.java    From school_shop with MIT License 5 votes vote down vote up
public static String getThumbnailImagePath(String imagePath) {
    String path = imagePath.substring(0, imagePath.lastIndexOf("/") + 1);
    path += "th" + imagePath.substring(imagePath.lastIndexOf("/")+1, imagePath.length());
    EMLog.d("msg", "original image path:" + imagePath);
    EMLog.d("msg", "thum image path:" + path);
    return path;
}
 
Example 9
Source File: EaseContactAdapter.java    From monolog-android with MIT License 5 votes vote down vote up
@Override
protected synchronized void publishResults(CharSequence constraint,
        FilterResults results) {
    userList.clear();
    userList.addAll((List<EaseUser>)results.values);
    EMLog.d(TAG, "publish contacts filter results size: " + results.count);
    if (results.count > 0) {
        notiyfyByFilter = true;
        notifyDataSetChanged();
        notiyfyByFilter = false;
    } else {
        notifyDataSetInvalidated();
    }
}
 
Example 10
Source File: DemoHXSDKHelper.java    From school_shop with MIT License 5 votes vote down vote up
@Override
public HXNotifier createNotifier(){
    return new HXNotifier(){
        public synchronized void onNewMsg(final EMMessage message) {
            if(EMChatManager.getInstance().isSlientMessage(message)){
                return;
            }
            
            String chatUsename = null;
            List<String> notNotifyIds = null;
            // 获取设置的不提示新消息的用户或者群组ids
            if (message.getChatType() == ChatType.Chat) {
                chatUsename = message.getFrom();
                notNotifyIds = ((DemoHXSDKModel) hxModel).getDisabledGroups();
            } else {
                chatUsename = message.getTo();
                notNotifyIds = ((DemoHXSDKModel) hxModel).getDisabledIds();
            }

            if (notNotifyIds == null || !notNotifyIds.contains(chatUsename)) {
                // 判断app是否在后台
                if (!EasyUtils.isAppRunningForeground(appContext)) {
                    EMLog.d(TAG, "app is running in backgroud");
                    sendNotification(message, false);
                } else {
                    sendNotification(message, true);

                }
                
                viberateAndPlayTone(message);
            }
        }
    };
}
 
Example 11
Source File: EaseShowVideoActivity.java    From monolog-android with MIT License 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	requestWindowFeature(Window.FEATURE_NO_TITLE);
	getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
			WindowManager.LayoutParams.FLAG_FULLSCREEN);
	setContentView(R.layout.ease_showvideo_activity);
	loadingLayout = (RelativeLayout) findViewById(R.id.loading_layout);
	progressBar = (ProgressBar) findViewById(R.id.progressBar);
	localFilePath = getIntent().getStringExtra("localpath");
	String remotepath = getIntent().getStringExtra("remotepath");
	String secret = getIntent().getStringExtra("secret");
	EMLog.d(TAG, "show video view file:" + localFilePath
			+ " remotepath:" + remotepath + " secret:" + secret);
	if (localFilePath != null && new File(localFilePath).exists()) {
		Intent intent = new Intent(Intent.ACTION_VIEW);
		intent.setDataAndType(Uri.fromFile(new File(localFilePath)),
				"video/mp4");
		startActivity(intent);
		finish();
	} else if (!TextUtils.isEmpty(remotepath) && !remotepath.equals("null")) {
		EMLog.d(TAG, "download remote video file");
		Map<String, String> maps = new HashMap<String, String>();
		if (!TextUtils.isEmpty(secret)) {
			maps.put("share-secret", secret);
		}
		downloadVideo(remotepath, maps);
	} else {

	}
}
 
Example 12
Source File: ImageUtils.java    From FanXin-based-HuanXin with GNU General Public License v2.0 5 votes vote down vote up
public static String getImagePath(String remoteUrl)
{
	String imageName= remoteUrl.substring(remoteUrl.lastIndexOf("/") + 1, remoteUrl.length());
	String path =PathUtil.getInstance().getImagePath()+"/"+ imageName;
       EMLog.d("msg", "image path:" + path);
       return path;
	
}
 
Example 13
Source File: MessageAdapter.java    From school_shop with MIT License 4 votes vote down vote up
/**
 * load image into image view
 * 
 * @param thumbernailPath
 * @param iv
 * @param position
 * @return the image exists or not
 */
private boolean showImageView(final String thumbernailPath, final ImageView iv, final String localFullSizePath, String remoteDir,
		final EMMessage message) {
	// String imagename =
	// localFullSizePath.substring(localFullSizePath.lastIndexOf("/") + 1,
	// localFullSizePath.length());
	// final String remote = remoteDir != null ? remoteDir+imagename :
	// imagename;
	final String remote = remoteDir;
	EMLog.d("###", "local = " + localFullSizePath + " remote: " + remote);
	// first check if the thumbnail image already loaded into cache
	Bitmap bitmap = ImageCache.getInstance().get(thumbernailPath);
	if (bitmap != null) {
		// thumbnail image is already loaded, reuse the drawable
		iv.setImageBitmap(bitmap);
		iv.setClickable(true); 
		iv.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				System.err.println("image view on click");
				Intent intent = new Intent(activity, ShowBigImage.class);
				File file = new File(localFullSizePath);
				if (file.exists()) {
					Uri uri = Uri.fromFile(file);
					intent.putExtra("uri", uri);
					System.err.println("here need to check why download everytime");
				} else {
					// The local full size pic does not exist yet.
					// ShowBigImage needs to download it from the server
					// first
					// intent.putExtra("", message.get);
					ImageMessageBody body = (ImageMessageBody) message.getBody();
					intent.putExtra("secret", body.getSecret());
					intent.putExtra("remotepath", remote);
				}
				if (message != null && message.direct == EMMessage.Direct.RECEIVE && !message.isAcked
						&& message.getChatType() != ChatType.GroupChat) {
					try {
						EMChatManager.getInstance().ackMessageRead(message.getFrom(), message.getMsgId());
						message.isAcked = true;
					} catch (Exception e) {
						e.printStackTrace();
					}
				}
				activity.startActivity(intent);
			}
		});
		return true;
	} else {

		new LoadImageTask().execute(thumbernailPath, localFullSizePath, remote, message.getChatType(), iv, activity, message);
		return true;
	}

}
 
Example 14
Source File: ImageUtils.java    From school_shop with MIT License 4 votes vote down vote up
public static String getThumbnailImagePath(String thumbRemoteUrl) {
String thumbImageName= thumbRemoteUrl.substring(thumbRemoteUrl.lastIndexOf("/") + 1, thumbRemoteUrl.length());
String path =PathUtil.getInstance().getImagePath()+"/"+ "th"+thumbImageName;
      EMLog.d("msg", "thum image path:" + path);
      return path;
  }
 
Example 15
Source File: LoginActivity.java    From school_shop with MIT License 4 votes vote down vote up
private void processContactsAndGroups() throws EaseMobException {
    // demo中简单的处理成每次登陆都去获取好友username,开发者自己根据情况而定
    List<String> usernames = EMContactManager.getInstance().getContactUserNames();
    EMLog.d("roster", "contacts size: " + usernames.size());
    Map<String, User> userlist = new HashMap<String, User>();
    for (String username : usernames) {
        User user = new User();
        user.setUsername(username);
        setUserHearder(username, user);
        userlist.put(username, user);
    }
    // 添加user"申请与通知"
    User newFriends = new User();
    newFriends.setUsername(Constants.NEW_FRIENDS_USERNAME);
    String strChat = getResources().getString(R.string.Application_and_notify);
    newFriends.setNick(strChat);
    
    userlist.put(Constants.NEW_FRIENDS_USERNAME, newFriends);
    // 添加"群聊"
    User groupUser = new User();
    String strGroup = getResources().getString(R.string.group_chat);
    groupUser.setUsername(Constants.GROUP_USERNAME);
    groupUser.setNick(strGroup);
    groupUser.setHeader("");
    userlist.put(Constants.GROUP_USERNAME, groupUser);

    // 存入内存
    MyApplication.getInstance().setContactList(userlist);
    System.out.println("----------------"+userlist.values().toString());
    // 存入db
    UserDao dao = new UserDao(LoginActivity.this);
    List<User> users = new ArrayList<User>(userlist.values());
    dao.saveContactList(users);
    
    //获取黑名单列表
    List<String> blackList = EMContactManager.getInstance().getBlackListUsernamesFromServer();
    //保存黑名单
    EMContactManager.getInstance().saveBlackList(blackList);

    // 获取群聊列表(群聊里只有groupid和groupname等简单信息,不包含members),sdk会把群组存入到内存和db中
    EMGroupManager.getInstance().getGroupsFromServer();
}
 
Example 16
Source File: MessageAdapter.java    From FanXin-based-HuanXin with GNU General Public License v2.0 4 votes vote down vote up
/**
 * load image into image view
 * 
 * @param thumbernailPath
 * @param iv
 * @param position
 * @return the image exists or not
 */
private boolean showImageView(final String thumbernailPath,
        final ImageView iv, final String localFullSizePath,
        String remoteDir, final EMMessage message) {
    // String imagename =
    // localFullSizePath.substring(localFullSizePath.lastIndexOf("/") + 1,
    // localFullSizePath.length());
    // final String remote = remoteDir != null ? remoteDir+imagename :
    // imagename;
    final String remote = remoteDir;
    EMLog.d("###", "local = " + localFullSizePath + " remote: " + remote);
    // first check if the thumbnail image already loaded into cache
    Bitmap bitmap = ImageCache.getInstance().get(thumbernailPath);
    if (bitmap != null) {
        // thumbnail image is already loaded, reuse the drawable
        iv.setImageBitmap(bitmap);
        iv.setClickable(true);
        iv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                System.err.println("image view on click");
                Intent intent = new Intent(activity, ShowBigImage.class);
                File file = new File(localFullSizePath);
                if (file.exists()) {
                    Uri uri = Uri.fromFile(file);
                    intent.putExtra("uri", uri);
                    System.err
                            .println("here need to check why download everytime");
                } else {
                    // The local full size pic does not exist yet.
                    // ShowBigImage needs to download it from the server
                    // first
                    // intent.putExtra("", message.get);
                    ImageMessageBody body = (ImageMessageBody) message
                            .getBody();
                    intent.putExtra("secret", body.getSecret());
                    intent.putExtra("remotepath", remote);
                }
                if (message != null
                        && message.direct == EMMessage.Direct.RECEIVE
                        && !message.isAcked
                        && message.getChatType() != ChatType.GroupChat) {
                    try {
                        EMChatManager.getInstance().ackMessageRead(
                                message.getFrom(), message.getMsgId());
                        message.isAcked = true;
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
                activity.startActivity(intent);
            }
        });
        return true;
    } else {

        new LoadImageTask().execute(thumbernailPath, localFullSizePath,
                remote, message.getChatType(), iv, activity, message);
        return true;
    }

}
 
Example 17
Source File: ImageUtils.java    From FanXin-based-HuanXin with GNU General Public License v2.0 4 votes vote down vote up
public static String getThumbnailImagePath(String thumbRemoteUrl) {
String thumbImageName= thumbRemoteUrl.substring(thumbRemoteUrl.lastIndexOf("/") + 1, thumbRemoteUrl.length());
String path =PathUtil.getInstance().getImagePath()+"/"+ "th"+thumbImageName;
      EMLog.d("msg", "thum image path:" + path);
      return path;
  }
 
Example 18
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 19
Source File: DemoHXSDKHelper.java    From school_shop with MIT License 4 votes vote down vote up
/**
 * 全局事件监听
 * 因为可能会有UI页面先处理到这个消息,所以一般如果UI页面已经处理,这里就不需要再次处理
 * activityList.size() <= 0 意味着所有页面都已经在后台运行,或者已经离开Activity Stack
 */
protected void initEventListener() {
    eventListener = new EMEventListener() {
        
        @Override
        public void onEvent(EMNotifierEvent event) {
            
            switch (event.getEvent()) {
            case EventNewMessage:
            {
                EMMessage message = (EMMessage)event.getData();
                EMLog.d(TAG, "receive the event : " + event.getEvent() + ",id : " + message.getMsgId());
                
                //应用在后台,不需要刷新UI,通知栏提示新消息
                if(activityList.size() <= 0){
                    HXSDKHelper.getInstance().getNotifier().onNewMsg(message);
                }

                break;
            }
            // below is just giving a example to show a cmd toast, the app should not follow this
            // so be careful of this
            case EventNewCMDMessage:
            {
                EMMessage message = (EMMessage)event.getData();
                EMLog.d(TAG, "receive the event : " + event.getEvent() + ",id : " + message.getMsgId());
                
                EMLog.d(TAG, "收到透传消息");
                //获取消息body
                CmdMessageBody cmdMsgBody = (CmdMessageBody) message.getBody();
                final String action = cmdMsgBody.action;//获取自定义action
                
                //获取扩展属性 此处省略
                //message.getStringAttribute("");
                EMLog.d(TAG, String.format("透传消息:action:%s,message:%s", action,message.toString()));
                final String str = appContext.getString(R.string.receive_the_passthrough);
                
                final String CMD_TOAST_BROADCAST = "easemob.demo.cmd.toast";
                IntentFilter cmdFilter = new IntentFilter(CMD_TOAST_BROADCAST);
                
                //注册通话广播接收者
                appContext.registerReceiver(new BroadcastReceiver(){

                    @Override
                    public void onReceive(Context context, Intent intent) {
                        // TODO Auto-generated method stub
                        Toast.makeText(appContext, intent.getStringExtra("cmd_value"), Toast.LENGTH_SHORT).show();
                    }
                    
                }, cmdFilter); 
                

                Intent broadcastIntent = new Intent(CMD_TOAST_BROADCAST);
                broadcastIntent.putExtra("cmd_value", str+action);
                appContext.sendBroadcast(broadcastIntent, null);
                
                break;
            }
            // add other events in case you are interested in
            default:
                break;
            }
            
        }
    };
    
    EMChatManager.getInstance().registerEventListener(eventListener);
}
 
Example 20
Source File: EaseImageUtils.java    From monolog-android with MIT License 4 votes vote down vote up
public static String getThumbnailImagePath(String thumbRemoteUrl) {
String thumbImageName= thumbRemoteUrl.substring(thumbRemoteUrl.lastIndexOf("/") + 1, thumbRemoteUrl.length());
String path =PathUtil.getInstance().getImagePath()+"/"+ "th"+thumbImageName;
      EMLog.d("msg", "thum image path:" + path);
      return path;
  }