com.hyphenate.util.EMLog Java Examples

The following examples show how to use com.hyphenate.util.EMLog. 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: EaseChatRowVideo.java    From Study_Android_Demo with Apache License 2.0 6 votes vote down vote up
@Override
protected void onBubbleClick() {
    EMVideoMessageBody videoBody = (EMVideoMessageBody) 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.Chat) {
           try {
               EMClient.getInstance().chatManager().ackMessageRead(message.getFrom(), message.getMsgId());
           } catch (Exception e) {
               e.printStackTrace();
           }
       }
       activity.startActivity(intent);
}
 
Example #2
Source File: CallReceiver.java    From Social with Apache License 2.0 6 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
    if ( !EMClient.getInstance().isLoggedInBefore()) return;
    //拨打方username
    String from = intent.getStringExtra("from");
    //call type
    String type = intent.getStringExtra("type");
    if("video".equals(type)){ //视频通话
        Toast.makeText(context,"收到视频聊天请求",Toast.LENGTH_LONG).show();
        Log.d("CallReceiver","收到视频聊天请求");
        context.startActivity(new Intent(context, VideoCallActivity.class).
                putExtra("username", from).putExtra("isComingCall", true).
                addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
    }else if ("voice".equals(type)){ //音频通话
        context.startActivity(new Intent(context, VoiceeCallActivity.class).
                putExtra("username", from).putExtra("isComingCall", true).
                addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
    }
    EMLog.d("CallReceiver", "app received a incoming call");
}
 
Example #3
Source File: EaseChatFragment.java    From Study_Android_Demo with Apache License 2.0 6 votes vote down vote up
/**
 * send @ message, only support group chat message
 * @param content
 */
@SuppressWarnings("ConstantConditions")
private void sendAtMessage(String content){
    if(chatType != EaseConstant.CHATTYPE_GROUP){
        EMLog.e(TAG, "only support group chat message");
        return;
    }
    EMMessage message = EMMessage.createTxtSendMessage(content, toChatUsername);
    EMGroup group = EMClient.getInstance().groupManager().getGroup(toChatUsername);
    if(EMClient.getInstance().getCurrentUser().equals(group.getOwner()) && EaseAtMessageHelper.get().containsAtAll(content)){
        message.setAttribute(EaseConstant.MESSAGE_ATTR_AT_MSG, EaseConstant.MESSAGE_ATTR_VALUE_AT_MSG_ALL);
    }else {
        message.setAttribute(EaseConstant.MESSAGE_ATTR_AT_MSG,
                EaseAtMessageHelper.get().atListToJsonArray(EaseAtMessageHelper.get().getAtMessageUsernames(content)));
    }
    sendMessage(message);
    
}
 
Example #4
Source File: EaseVoiceRecorder.java    From nono-android with GNU General Public License v3.0 6 votes vote down vote up
public int stopRecoding() {
    if(recorder != null){
        isRecording = false;
        recorder.stop();
        recorder.release();
        recorder = null;
        
        if(file == null || !file.exists() || !file.isFile()){
            return EMError.FILE_INVALID;
        }
        if (file.length() == 0) {
            file.delete();
            return EMError.FILE_INVALID;
        }
        int seconds = (int) (new Date().getTime() - startTime) / 1000;
        EMLog.d("voice", "voice recording finished. seconds:" + seconds + " file length:" + file.length());
        return seconds;
    }
    return 0;
}
 
Example #5
Source File: EaseNotifier.java    From Social with Apache License 2.0 6 votes vote down vote up
/**
 * 处理新收到的消息,然后发送通知
 * 
 * 开发者可以重载此函数
 * this function can be override
 * 
 * @param message
 */
public synchronized void onNewMsg(EMMessage message) {
    if(EMClient.getInstance().chatManager().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 #6
Source File: EaseNotifier.java    From Social with Apache License 2.0 6 votes vote down vote up
public synchronized void onNewMesg(List<EMMessage> messages) {
    if(EMClient.getInstance().chatManager().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 #7
Source File: EaseVoiceRecorder.java    From Social with Apache License 2.0 6 votes vote down vote up
public int stopRecoding() {
    if(recorder != null){
        isRecording = false;
        recorder.stop();
        recorder.release();
        recorder = null;
        
        if(file == null || !file.exists() || !file.isFile()){
            return EMError.FILE_INVALID;
        }
        if (file.length() == 0) {
            file.delete();
            return EMError.FILE_INVALID;
        }
        int seconds = (int) (new Date().getTime() - startTime) / 1000;
        EMLog.d("voice", "voice recording finished. seconds:" + seconds + " file length:" + file.length());
        return seconds;
    }
    return 0;
}
 
Example #8
Source File: EaseNotifier.java    From Study_Android_Demo with Apache License 2.0 6 votes vote down vote up
/**
 * handle the new message
 * this function can be override
 * 
 * @param message
 */
public synchronized void onNewMsg(EMMessage message) {
    if(EMClient.getInstance().chatManager().isSilentMessage(message)){
        return;
    }
    EaseSettingsProvider settingsProvider = EaseUI.getInstance().getSettingsProvider();
    if(!settingsProvider.isMsgNotifyAllowed(message)){
        return;
    }
    
    // check if app running background
    if (!EasyUtils.isAppRunningForeground(appContext)) {
        EMLog.d(TAG, "app is running in backgroud");
        sendNotification(message, false);
    } else {
        sendNotification(message, true);

    }
    
    vibrateAndPlayTone(message);
}
 
Example #9
Source File: EaseChatRowVideo.java    From Social with Apache License 2.0 6 votes vote down vote up
@Override
protected void onBubbleClick() {
    EMVideoMessageBody videoBody = (EMVideoMessageBody) 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.Chat) {
           try {
               EMClient.getInstance().chatManager().ackMessageRead(message.getFrom(), message.getMsgId());
           } catch (Exception e) {
               e.printStackTrace();
           }
       }
       activity.startActivity(intent);
}
 
Example #10
Source File: EaseNotifier.java    From nono-android with GNU General Public License v3.0 6 votes vote down vote up
public synchronized void onNewMesg(List<EMMessage> messages) {
    if(EMClient.getInstance().chatManager().isSlientMessage(messages.get(messages.size()-1))){
        return;
    }
    EaseUI.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 #11
Source File: EaseNotifier.java    From nono-android with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 处理新收到的消息,然后发送通知
 * 
 * 开发者可以重载此函数
 * this function can be override
 * 
 * @param message
 */
public synchronized void onNewMsg(EMMessage message) {
    if(EMClient.getInstance().chatManager().isSlientMessage(message)){
        return;
    }
    EaseUI.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 #12
Source File: EaseVoiceRecorder.java    From Study_Android_Demo with Apache License 2.0 6 votes vote down vote up
public int stopRecoding() {
    if(recorder != null){
        isRecording = false;
        recorder.stop();
        recorder.release();
        recorder = null;
        
        if(file == null || !file.exists() || !file.isFile()){
            return EMError.FILE_INVALID;
        }
        if (file.length() == 0) {
            file.delete();
            return EMError.FILE_INVALID;
        }
        int seconds = (int) (new Date().getTime() - startTime) / 1000;
        EMLog.d("voice", "voice recording finished. seconds:" + seconds + " file length:" + file.length());
        return seconds;
    }
    return 0;
}
 
Example #13
Source File: EaseNotifier.java    From Study_Android_Demo with Apache License 2.0 6 votes vote down vote up
public synchronized void onNewMesg(List<EMMessage> messages) {
    if(EMClient.getInstance().chatManager().isSilentMessage(messages.get(messages.size()-1))){
        return;
    }
    EaseSettingsProvider settingsProvider = EaseUI.getInstance().getSettingsProvider();
    if(!settingsProvider.isMsgNotifyAllowed(null)){
        return;
    }
    // check if app running background
    if (!EasyUtils.isAppRunningForeground(appContext)) {
        EMLog.d(TAG, "app is running in backgroud");
        sendNotification(messages, false);
    } else {
        sendNotification(messages, true);
    }
    vibrateAndPlayTone(messages.get(messages.size()-1));
}
 
Example #14
Source File: EaseChatFragment.java    From Study_Android_Demo with Apache License 2.0 5 votes vote down vote up
protected void onChatRoomViewCreation() {
    final ProgressDialog pd = ProgressDialog.show(getActivity(), "", "Joining......");
    EMClient.getInstance().chatroomManager().joinChatRoom(toChatUsername, new EMValueCallBack<EMChatRoom>() {

        @Override
        public void onSuccess(final EMChatRoom value) {
            getActivity().runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    if(getActivity().isFinishing() || !toChatUsername.equals(value.getId()))
                        return;
                    pd.dismiss();
                    EMChatRoom room = EMClient.getInstance().chatroomManager().getChatRoom(toChatUsername);
                    if (room != null) {
                        titleBar.setTitle(room.getName());
                        EMLog.d(TAG, "join room success : " + room.getName());
                    } else {
                        titleBar.setTitle(toChatUsername);
                    }
                    addChatRoomChangeListenr();
                    onConversationInit();
                    onMessageListInit();
                }
            });
        }

        @Override
        public void onError(final int error, String errorMsg) {
            // TODO Auto-generated method stub
            EMLog.d(TAG, "join room failure : " + error);
            getActivity().runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    pd.dismiss();
                }
            });
            getActivity().finish();
        }
    });
}
 
Example #15
Source File: EaseContactAdapter.java    From Study_Android_Demo with Apache License 2.0 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 #16
Source File: MyEaseChatFragment.java    From Social with Apache License 2.0 5 votes vote down vote up
protected void onChatRoomViewCreation() {
    final ProgressDialog pd = ProgressDialog.show(getActivity(), "", "Joining......");
    EMClient.getInstance().chatroomManager().joinChatRoom(toChatUsername, new EMValueCallBack<EMChatRoom>() {

        @Override
        public void onSuccess(final EMChatRoom value) {
            getActivity().runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    if(getActivity().isFinishing() || !toChatUsername.equals(value.getId()))
                        return;
                    pd.dismiss();
                    EMChatRoom room = EMClient.getInstance().chatroomManager().getChatRoom(toChatUsername);
                    if (room != null) {
                        titleBar.setTitle(room.getName());
                    } else {
                        titleBar.setTitle(toChatUsername);
                    }
                    EMLog.d(TAG, "join room success : " + room.getName());
                    addChatRoomChangeListenr();
                    onConversationInit();
                    onMessageListInit();
                }
            });
        }

        @Override
        public void onError(final int error, String errorMsg) {
            // TODO Auto-generated method stub
            EMLog.d(TAG, "join room failure : " + error);
            getActivity().runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    pd.dismiss();
                }
            });
            getActivity().finish();
        }
    });
}
 
Example #17
Source File: EaseShowVideoActivity.java    From Study_Android_Demo with Apache License 2.0 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 #18
Source File: EaseImageUtils.java    From Study_Android_Demo with Apache License 2.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 #19
Source File: EaseChatFragment.java    From nono-android with GNU General Public License v3.0 5 votes vote down vote up
protected void onChatRoomViewCreation() {
    final ProgressDialog pd = ProgressDialog.show(getActivity(), "", "Joining......");
    EMClient.getInstance().chatroomManager().joinChatRoom(toChatUsername, new EMValueCallBack<EMChatRoom>() {

        @Override
        public void onSuccess(final EMChatRoom value) {
            getActivity().runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    if(getActivity().isFinishing() || !toChatUsername.equals(value.getId()))
                        return;
                    pd.dismiss();
                    EMChatRoom room = EMClient.getInstance().chatroomManager().getChatRoom(toChatUsername);
                    if (room != null) {
                        titleBar.setTitle(room.getName());
                    } else {
                        titleBar.setTitle(toChatUsername);
                    }
                    EMLog.d(TAG, "join room success : " + room.getName());
                    addChatRoomChangeListenr();
                    onConversationInit();
                    onMessageListInit();
                }
            });
        }

        @Override
        public void onError(final int error, String errorMsg) {
            // TODO Auto-generated method stub
            EMLog.d(TAG, "join room failure : " + error);
            getActivity().runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    pd.dismiss();
                }
            });
            getActivity().finish();
        }
    });
}
 
Example #20
Source File: EaseShowVideoActivity.java    From Social with Apache License 2.0 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 #21
Source File: EaseChatFragment.java    From Social with Apache License 2.0 5 votes vote down vote up
protected void onChatRoomViewCreation() {
    final ProgressDialog pd = ProgressDialog.show(getActivity(), "", "Joining......");
    EMClient.getInstance().chatroomManager().joinChatRoom(toChatUsername, new EMValueCallBack<EMChatRoom>() {

        @Override
        public void onSuccess(final EMChatRoom value) {
            getActivity().runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    if(getActivity().isFinishing() || !toChatUsername.equals(value.getId()))
                        return;
                    pd.dismiss();
                    EMChatRoom room = EMClient.getInstance().chatroomManager().getChatRoom(toChatUsername);
                    if (room != null) {
                        titleBar.setTitle(room.getName());
                    } else {
                        titleBar.setTitle(toChatUsername);
                    }
                    EMLog.d(TAG, "join room success : " + room.getName());
                    addChatRoomChangeListenr();
                    onConversationInit();
                    onMessageListInit();
                }
            });
        }

        @Override
        public void onError(final int error, String errorMsg) {
            // TODO Auto-generated method stub
            EMLog.d(TAG, "join room failure : " + error);
            getActivity().runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    pd.dismiss();
                }
            });
            getActivity().finish();
        }
    });
}
 
Example #22
Source File: EaseContactAdapter.java    From Social with Apache License 2.0 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 #23
Source File: EaseImageUtils.java    From Social with Apache License 2.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 #24
Source File: EaseCommonUtils.java    From nono-android with GNU General Public License v3.0 4 votes vote down vote up
/**
     * 根据消息内容和消息类型获取消息内容提示
     * 
     * @param message
     * @param context
     * @return
     */
    public static String getMessageDigest(EMMessage message, Context context) {
        String digest = "";
        switch (message.getType()) {
        case LOCATION: // 位置消息
            if (message.direct() == EMMessage.Direct.RECEIVE) {
                //从sdk中提到了ui中,使用更简单不犯错的获取string方法
//              digest = EasyUtils.getAppResourceString(context, "location_recv");
                digest = getString(context, R.string.location_recv);
                digest = String.format(digest, message.getFrom());
                return digest;
            } else {
//              digest = EasyUtils.getAppResourceString(context, "location_prefix");
                digest = getString(context, R.string.location_prefix);
            }
            break;
        case IMAGE: // 图片消息
            digest = getString(context, R.string.picture);
            break;
        case VOICE:// 语音消息
            digest = getString(context, R.string.voice_prefix);
            break;
        case VIDEO: // 视频消息
            digest = getString(context, R.string.video);
            break;
        case TXT: // 文本消息
            EMTextMessageBody txtBody = (EMTextMessageBody) message.getBody();
            /*if(((DemoHXSDKHelper)HXSDKHelper.getInstance()).isRobotMenuMessage(message)){
                digest = ((DemoHXSDKHelper)HXSDKHelper.getInstance()).getRobotMenuMessageDigest(message);
            }else */if(message.getBooleanAttribute(EaseConstant.MESSAGE_ATTR_IS_VOICE_CALL, false)){
                digest = getString(context, R.string.voice_call) + txtBody.getMessage();
            }else if(message.getBooleanAttribute(EaseConstant.MESSAGE_ATTR_IS_BIG_EXPRESSION, false)){
                if(!TextUtils.isEmpty(txtBody.getMessage())){
                    digest = txtBody.getMessage();
                }else{
                    digest = getString(context, R.string.dynamic_expression);
                }
            }else{
                digest = txtBody.getMessage();
            }
            break;
        case FILE: //普通文件消息
            digest = getString(context, R.string.file);
            break;
        default:
            EMLog.e(TAG, "error, unknow type");
            return "";
        }

        return digest;
    }
 
Example #25
Source File: EaseChatRowVoicePlayClickListener.java    From Study_Android_Demo with Apache License 2.0 4 votes vote down vote up
@Override
public void onClick(View v) {
	String st = activity.getResources().getString(R.string.Is_download_voice_click_later);
	if (isPlaying) {
		if (playMsgId != null && playMsgId.equals(message.getMsgId())) {
			currentPlayListener.stopPlayVoice();
			return;
		}
		currentPlayListener.stopPlayVoice();
	}

	if (message.direct() == EMMessage.Direct.SEND) {
		// for sent msg, we will try to play the voice file directly
		playVoice(voiceBody.getLocalUrl());
	} else {
		if (message.status() == EMMessage.Status.SUCCESS) {
			File file = new File(voiceBody.getLocalUrl());
			if (file.exists() && file.isFile())
				playVoice(voiceBody.getLocalUrl());
			else
				EMLog.e(TAG, "file not exist");

		} else if (message.status() == EMMessage.Status.INPROGRESS) {
			Toast.makeText(activity, st, Toast.LENGTH_SHORT).show();
		} else if (message.status() == EMMessage.Status.FAIL) {
			Toast.makeText(activity, st, Toast.LENGTH_SHORT).show();
			new AsyncTask<Void, Void, Void>() {

				@Override
				protected Void doInBackground(Void... params) {
					EMClient.getInstance().chatManager().downloadAttachment(message);
					return null;
				}

				@Override
				protected void onPostExecute(Void result) {
					super.onPostExecute(result);
					adapter.notifyDataSetChanged();
				}

			}.execute();

		}

	}
}
 
Example #26
Source File: EaseChatRowVoicePlayClickListener.java    From nono-android with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onClick(View v) {
	String st = activity.getResources().getString(R.string.Is_download_voice_click_later);
	if (isPlaying) {
		if (playMsgId != null && playMsgId.equals(message.getMsgId())) {
			currentPlayListener.stopPlayVoice();
			return;
		}
		currentPlayListener.stopPlayVoice();
	}

	if (message.direct() == EMMessage.Direct.SEND) {
		// for sent msg, we will try to play the voice file directly
		playVoice(voiceBody.getLocalUrl());
	} else {
		if (message.status() == EMMessage.Status.SUCCESS) {
			File file = new File(voiceBody.getLocalUrl());
			if (file.exists() && file.isFile())
				playVoice(voiceBody.getLocalUrl());
			else
				EMLog.e(TAG, "file not exist");

		} else if (message.status() == EMMessage.Status.INPROGRESS) {
			Toast.makeText(activity, st, Toast.LENGTH_SHORT).show();
		} else if (message.status() == EMMessage.Status.FAIL) {
			Toast.makeText(activity, st, Toast.LENGTH_SHORT).show();
			new AsyncTask<Void, Void, Void>() {

				@Override
				protected Void doInBackground(Void... params) {
					EMClient.getInstance().chatManager().downloadAttachment(message);
					return null;
				}

				@Override
				protected void onPostExecute(Void result) {
					super.onPostExecute(result);
					adapter.notifyDataSetChanged();
				}

			}.execute();

		}

	}
}
 
Example #27
Source File: EaseShowBigImageActivity.java    From Study_Android_Demo with Apache License 2.0 4 votes vote down vote up
@SuppressLint("NewApi")
@Override
protected void onCreate(Bundle savedInstanceState) {
	setContentView(R.layout.ease_activity_show_big_image);
	super.onCreate(savedInstanceState);

	image = (EasePhotoView) findViewById(R.id.image);
	ProgressBar loadLocalPb = (ProgressBar) findViewById(R.id.pb_load_local);
	default_res = getIntent().getIntExtra("default_image", R.drawable.ease_default_avatar);
	Uri uri = getIntent().getParcelableExtra("uri");
	localFilePath = getIntent().getExtras().getString("localUrl");
	String msgId = getIntent().getExtras().getString("messageId");
	EMLog.d(TAG, "show big msgId:" + msgId );

	//show the image if it exist in local path
	if (uri != null && new File(uri.getPath()).exists()) {
		EMLog.d(TAG, "showbigimage file exists. directly show it");
		DisplayMetrics metrics = new DisplayMetrics();
		getWindowManager().getDefaultDisplay().getMetrics(metrics);
		// int screenWidth = metrics.widthPixels;
		// int screenHeight =metrics.heightPixels;
		bitmap = EaseImageCache.getInstance().get(uri.getPath());
		if (bitmap == null) {
			EaseLoadLocalBigImgTask task = new EaseLoadLocalBigImgTask(this, uri.getPath(), image, loadLocalPb, ImageUtils.SCALE_IMAGE_WIDTH,
					ImageUtils.SCALE_IMAGE_HEIGHT);
			if (android.os.Build.VERSION.SDK_INT > 10) {
				task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
			} else {
				task.execute();
			}
		} else {
			image.setImageBitmap(bitmap);
		}
	} else if(msgId != null) {
	    downloadImage(msgId);
	}else {
		image.setImageResource(default_res);
	}

	image.setOnClickListener(new OnClickListener() {
		@Override
		public void onClick(View v) {
			finish();
		}
	});
}
 
Example #28
Source File: EaseImageUtils.java    From Study_Android_Demo with Apache License 2.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 #29
Source File: EaseCommonUtils.java    From Study_Android_Demo with Apache License 2.0 4 votes vote down vote up
/**
 * Get digest according message type and content
 * 
 * @param message
 * @param context
 * @return
 */
public static String getMessageDigest(EMMessage message, Context context) {
    String digest = "";
    switch (message.getType()) {
    case LOCATION:
        if (message.direct() == EMMessage.Direct.RECEIVE) {
            digest = getString(context, R.string.location_recv);
            digest = String.format(digest, message.getFrom());
            return digest;
        } else {
            digest = getString(context, R.string.location_prefix);
        }
        break;
    case IMAGE:
        digest = getString(context, R.string.picture);
        break;
    case VOICE:
        digest = getString(context, R.string.voice_prefix);
        break;
    case VIDEO:
        digest = getString(context, R.string.video);
        break;
    case TXT:
        EMTextMessageBody txtBody = (EMTextMessageBody) message.getBody();
        if(message.getBooleanAttribute(EaseConstant.MESSAGE_ATTR_IS_VOICE_CALL, false)){
            digest = getString(context, R.string.voice_call) + txtBody.getMessage();
        }else if(message.getBooleanAttribute(EaseConstant.MESSAGE_ATTR_IS_VIDEO_CALL, false)){
            digest = getString(context, R.string.video_call) + txtBody.getMessage();
        }else if(message.getBooleanAttribute(EaseConstant.MESSAGE_ATTR_IS_BIG_EXPRESSION, false)){
            if(!TextUtils.isEmpty(txtBody.getMessage())){
                digest = txtBody.getMessage();
            }else{
                digest = getString(context, R.string.dynamic_expression);
            }
        }else{
            digest = txtBody.getMessage();
        }
        break;
    case FILE:
        digest = getString(context, R.string.file);
        break;
    default:
        EMLog.e(TAG, "error, unknow type");
        return "";
    }

    return digest;
}
 
Example #30
Source File: EaseChatRowVoicePlayClickListener.java    From Social with Apache License 2.0 4 votes vote down vote up
@Override
public void onClick(View v) {
	String st = activity.getResources().getString(R.string.Is_download_voice_click_later);
	if (isPlaying) {
		if (playMsgId != null && playMsgId.equals(message.getMsgId())) {
			currentPlayListener.stopPlayVoice();
			return;
		}
		currentPlayListener.stopPlayVoice();
	}

	if (message.direct() == EMMessage.Direct.SEND) {
		// for sent msg, we will try to play the voice file directly
		playVoice(voiceBody.getLocalUrl());
	} else {
		if (message.status() == EMMessage.Status.SUCCESS) {
			File file = new File(voiceBody.getLocalUrl());
			if (file.exists() && file.isFile())
				playVoice(voiceBody.getLocalUrl());
			else
				EMLog.e(TAG, "file not exist");

		} else if (message.status() == EMMessage.Status.INPROGRESS) {
			Toast.makeText(activity, st, Toast.LENGTH_SHORT).show();
		} else if (message.status() == EMMessage.Status.FAIL) {
			Toast.makeText(activity, st, Toast.LENGTH_SHORT).show();
			new AsyncTask<Void, Void, Void>() {

				@Override
				protected Void doInBackground(Void... params) {
					EMClient.getInstance().chatManager().downloadAttachment(message);
					return null;
				}

				@Override
				protected void onPostExecute(Void result) {
					super.onPostExecute(result);
					adapter.notifyDataSetChanged();
				}

			}.execute();

		}

	}
}