Search in sources :

Example 21 with ChatMsg

use of com.lingtuan.firefly.vo.ChatMsg in project SmartMesh_Android by SmartMeshFoundation.

the class ContactSelectedUI method forwardImgMethod.

/**
 * Sending pictures method
 * @param picturePath Image path
 */
private void forwardImgMethod(String uid, String picturePath, String userName, String avatarUrl, boolean isGroup, boolean isSend) {
    float density = getResources().getDisplayMetrics().density;
    // mContext.getResources().getDisplayMetrics().widthPixels;
    int screenWidth = Constants.MAX_IMAGE_WIDTH;
    // mContext.getResources().getDisplayMetrics().heightPixels;
    int screenHeight = Constants.MAX_IMAGE_HEIGHT;
    int width = (int) (120 * density);
    Bitmap bmp = BitmapUtils.getimage(picturePath, width, width, 10);
    Bitmap bmpUpload = BitmapUtils.getimage(picturePath, screenWidth, screenHeight, Constants.MAX_KB);
    BitmapUtils.saveBitmap2SD(bmp, 10, false);
    String uploadPath = BitmapUtils.saveBitmap2SD(bmpUpload, screenWidth, true).getPath();
    String url = uploadPath;
    boolean successed = true;
    if (uid.equals("everyone")) {
        XmppMessageUtil.getInstance().sendEnterLeaveEveryOne(0, false);
        try {
            Thread.sleep(500);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        ChatMsg msg = createImageChatMsg(uid, url, userName, avatarUrl, BitmapUtils.BitmapToBase64String(bmp), isGroup, isSend);
        try {
            Thread.sleep(500);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        XmppMessageUtil.getInstance().sendEnterLeaveEveryOne(0, true);
        if (appNetService != null) {
            successed = appNetService.handleSendPicutre(url, true, uid, msg.getMessageId());
        }
        if (msg.getSend() == 0 && !successed) {
            msg.setSend(0);
        }
    } else if (isGroup) {
        createImageChatMsg(uid, url, userName, avatarUrl, BitmapUtils.BitmapToBase64String(bmp), isGroup, isSend);
    } else {
        boolean foundPeople = false;
        if (appNetService != null && appNetService.getwifiPeopleList() != null) {
            for (// All users need to traverse, find out the corresponding touid users
            WifiPeopleVO vo : // All users need to traverse, find out the corresponding touid users
            appNetService.getwifiPeopleList()) {
                if (uid.equals(vo.getLocalId())) {
                    foundPeople = true;
                    break;
                }
            }
        }
        if (// With no net with no net send messages
        foundPeople) {
            ChatMsg msg = new ChatMsg();
            msg.setType(1);
            msg.setContent(url);
            msg.setLocalUrl(url);
            msg.setCover(BitmapUtils.BitmapToBase64String(bmp));
            msg.parseUserBaseVo(NextApplication.myInfo.getUserBaseVo());
            msg.setChatId(uid);
            msg.setOffLineMsg(true);
            msg.setSend(1);
            msg.setMessageId(UUID.randomUUID().toString());
            msg.setMsgTime(System.currentTimeMillis() / 1000);
            msg.setShowTime(FinalUserDataBase.getInstance().isOffLineShowTime(uid, msg.getMsgTime()));
            successed = appNetService.handleSendPicutre(url, false, uid, msg.getMessageId());
            if (!successed) {
                msg.setSend(0);
            }
            FinalUserDataBase.getInstance().saveChatMsg(msg, uid, userName, avatarUrl);
        } else {
            createImageChatMsg(uid, url, userName, avatarUrl, BitmapUtils.BitmapToBase64String(bmp), isGroup, isSend);
        }
    }
    if (bmp != null && !bmp.isRecycled()) {
        bmp.recycle();
    }
    if (bmpUpload != null && !bmpUpload.isRecycled()) {
        bmpUpload.recycle();
    }
}
Also used : Bitmap(android.graphics.Bitmap) WifiPeopleVO(com.lingtuan.firefly.offline.vo.WifiPeopleVO) ChatMsg(com.lingtuan.firefly.vo.ChatMsg)

Example 22 with ChatMsg

use of com.lingtuan.firefly.vo.ChatMsg in project SmartMesh_Android by SmartMeshFoundation.

the class ContactSelectedUI method initData.

@Override
protected void initData() {
    setTitle(getString(R.string.chatting_selected_title));
    // -1 default  0 close  1 open
    int openSmartMesh = MySharedPrefs.readInt1(NextApplication.mContext, MySharedPrefs.FILE_USER, MySharedPrefs.KEY_NO_NETWORK_COMMUNICATION + NextApplication.myInfo.getLocalId());
    if (openSmartMesh == -1) {
        bindService(new Intent(this, AppNetService.class), serviceConn, Activity.BIND_AUTO_CREATE);
    }
    if (getIntent() != null) {
        msgList = (ArrayList<ChatMsg>) getIntent().getSerializableExtra("msglist");
        if (msgList != null && msgList.size() >= 0) {
            if (!TextUtils.isEmpty(msgList.get(0).getForwardLeaveMsg())) {
                linkTitle = msgList.get(0).getForwardLeaveMsg();
            }
        }
    }
    mListView.addHeaderView(headerView);
    mAdapter = new MessageEventAdapter(null, this);
    mListView.setAdapter(mAdapter);
    new Thread(new UpdateMessage()).start();
}
Also used : MessageEventAdapter(com.lingtuan.firefly.adapter.MessageEventAdapter) AppNetService(com.lingtuan.firefly.offline.AppNetService) Intent(android.content.Intent) ChatMsg(com.lingtuan.firefly.vo.ChatMsg)

Example 23 with ChatMsg

use of com.lingtuan.firefly.vo.ChatMsg in project SmartMesh_Android by SmartMeshFoundation.

the class DiscussGroupMemberListUI method removeMemberChatMsg.

/**
 * Forge a delete members of the group chat message
 */
private void removeMemberChatMsg(final String name) {
    StringBuilder sb = new StringBuilder();
    int index = 1;
    for (UserBaseVo vo : data) {
        if (// Most need four pictures
        index > 4) {
            break;
        }
        sb.append(vo.getThumb()).append("___").append(vo.getGender()).append("#");
        index++;
    }
    sb.deleteCharAt(sb.lastIndexOf("#"));
    String url = sb.toString();
    ChatMsg chatmsg = new ChatMsg();
    chatmsg.setChatId("group-" + cid);
    chatmsg.setGroupName(name);
    chatmsg.setGroup(true);
    chatmsg.setType(14);
    chatmsg.setSend(1);
    chatmsg.setContent(getString(R.string.discuss_group_remove_other, name));
    chatmsg.setMsgTime(System.currentTimeMillis() / 1000);
    chatmsg.setMessageId(UUID.randomUUID().toString());
    chatmsg.parseUserBaseVo(NextApplication.myInfo.getUserBaseVo());
    Bundle bundle = new Bundle();
    bundle.putSerializable(XmppAction.ACTION_MESSAGE_LISTENER, chatmsg);
    Utils.intentAction(getApplicationContext(), XmppAction.ACTION_MESSAGE_LISTENER, bundle);
    FinalUserDataBase.getInstance().saveChatMsg(chatmsg, chatmsg.getChatId(), name, url, false);
}
Also used : Bundle(android.os.Bundle) UserBaseVo(com.lingtuan.firefly.vo.UserBaseVo) ChatMsg(com.lingtuan.firefly.vo.ChatMsg)

Example 24 with ChatMsg

use of com.lingtuan.firefly.vo.ChatMsg in project SmartMesh_Android by SmartMeshFoundation.

the class DiscussGroupSettingUI method inviteOthersChatMsg.

/**
 * Forge a invite others to join group chat message
 */
private void inviteOthersChatMsg(final String name) {
    StringBuilder sb = new StringBuilder();
    int index = 1;
    for (UserBaseVo vo : data) {
        if (// Most need four pictures
        index > 4) {
            break;
        }
        sb.append(vo.getThumb()).append("___").append(vo.getGender()).append("#");
        index++;
    }
    sb.deleteCharAt(sb.lastIndexOf("#"));
    String url = sb.toString();
    ChatMsg chatmsg = new ChatMsg();
    chatmsg.setChatId("group-" + cid);
    chatmsg.setGroupName(nameEdit.getText().toString());
    chatmsg.setGroup(true);
    chatmsg.setType(13);
    chatmsg.setSend(1);
    chatmsg.setContent(getString(R.string.discuss_group_invite_others, name));
    chatmsg.setMsgTime(System.currentTimeMillis() / 1000);
    chatmsg.setMessageId(UUID.randomUUID().toString());
    chatmsg.parseUserBaseVo(NextApplication.myInfo.getUserBaseVo());
    Bundle bundle = new Bundle();
    bundle.putSerializable(XmppAction.ACTION_MESSAGE_LISTENER, chatmsg);
    Utils.intentAction(getApplicationContext(), XmppAction.ACTION_MESSAGE_LISTENER, bundle);
    FinalUserDataBase.getInstance().saveChatMsg(chatmsg, chatmsg.getChatId(), nameEdit.getText().toString(), url, false);
}
Also used : Bundle(android.os.Bundle) UserBaseVo(com.lingtuan.firefly.vo.UserBaseVo) ChatMsg(com.lingtuan.firefly.vo.ChatMsg)

Example 25 with ChatMsg

use of com.lingtuan.firefly.vo.ChatMsg in project SmartMesh_Android by SmartMeshFoundation.

the class DiscussGroupSettingUI method reNameChatMsg.

/**
 * Forge a system modification group chat information
 */
private void reNameChatMsg(final String name) {
    StringBuilder sb = new StringBuilder();
    int index = 1;
    for (UserBaseVo vo : data) {
        if (// Most need four pictures
        index > 4) {
            break;
        }
        sb.append(vo.getThumb()).append("___").append(vo.getGender()).append("#");
        index++;
    }
    sb.deleteCharAt(sb.lastIndexOf("#"));
    String url = sb.toString();
    ChatMsg chatmsg = new ChatMsg();
    chatmsg.setChatId("group-" + cid);
    chatmsg.setGroupName(name);
    chatmsg.setGroup(true);
    chatmsg.setType(17);
    chatmsg.setSend(1);
    chatmsg.setContent(getString(R.string.discuss_group_rename, chatmsg.getGroupName()));
    chatmsg.setMsgTime(System.currentTimeMillis() / 1000);
    chatmsg.setMessageId(UUID.randomUUID().toString());
    chatmsg.parseUserBaseVo(NextApplication.myInfo.getUserBaseVo());
    Bundle bundle = new Bundle();
    bundle.putSerializable(XmppAction.ACTION_MESSAGE_LISTENER, chatmsg);
    Utils.intentAction(getApplicationContext(), XmppAction.ACTION_MESSAGE_LISTENER, bundle);
    FinalUserDataBase.getInstance().saveChatMsg(chatmsg, chatmsg.getChatId(), name, url, false);
}
Also used : Bundle(android.os.Bundle) UserBaseVo(com.lingtuan.firefly.vo.UserBaseVo) ChatMsg(com.lingtuan.firefly.vo.ChatMsg)

Aggregations

ChatMsg (com.lingtuan.firefly.vo.ChatMsg)61 Bundle (android.os.Bundle)17 Intent (android.content.Intent)12 ArrayList (java.util.ArrayList)11 UserBaseVo (com.lingtuan.firefly.vo.UserBaseVo)9 Cursor (android.database.Cursor)8 SuppressLint (android.annotation.SuppressLint)6 WifiPeopleVO (com.lingtuan.firefly.offline.vo.WifiPeopleVO)5 View (android.view.View)4 ImageView (android.widget.ImageView)4 GroupMemberAvatarVo (com.lingtuan.firefly.contact.vo.GroupMemberAvatarVo)4 PendingIntent (android.app.PendingIntent)3 TextView (android.widget.TextView)3 MyDialogFragment (com.lingtuan.firefly.util.MyDialogFragment)3 LoginThread (com.lingtuan.firefly.xmpp.LoginThread)3 File (java.io.File)3 JSONObject (org.json.JSONObject)3 Bitmap (android.graphics.Bitmap)2 Message (android.os.Message)2 Editable (android.text.Editable)2