Ejemplo n.º 1
0
        //해당 thread_id에 해당되는 모든 MMS를 불러옴, inboxType에 따라 송신/수신한 메시지만 불러올 수도 있다.
        private List <TextMessage> LoadMMS(long thread_id, int inboxType)
        {
            List <TextMessage> messages = null;
            ContentResolver    cr       = Application.Context.ContentResolver;
            Uri uri = Uri.Parse("content://mms/");

            string[] projection = new string[] { "_id", "ct_t", "read", "date", "thread_id", "m_type" };

            string selection = "thread_id = " + thread_id;

            switch (inboxType)
            {
            case (int)TextMessage.MESSAGE_TYPE.RECEIVED:
                selection = "thread_id = " + thread_id + " AND m_type = " + 132;
                break;

            case (int)TextMessage.MESSAGE_TYPE.SENT:
                selection = "thread_id = " + thread_id + " AND m_type = " + 128;
                break;
            }

            string  sortOrder = "date desc";
            ICursor cursor    = cr.Query(uri, projection, selection, null, sortOrder);

            if (cursor != null)
            {
                if (cursor.Count > 0)
                {
                    messages = new List <TextMessage>();
                    while (cursor.MoveToNext())
                    {
                        string id        = cursor.GetString(cursor.GetColumnIndex("_id"));
                        string mmsType   = cursor.GetString(cursor.GetColumnIndex("ct_t"));
                        int    readState = cursor.GetInt(cursor.GetColumnIndex("read"));
                        long   time      = cursor.GetLong(cursor.GetColumnIndex("date"));
                        int    type      = cursor.GetInt(cursor.GetColumnIndexOrThrow("m_type"));
                        if ("application/vnd.wap.multipart.related".Equals(mmsType) || "application/vnd.wap.multipart.mixed".Equals(mmsType))
                        {
                            //this is MMS
                            MultiMediaMessage objMMS = ReadMMS(id);
                            objMMS.Id        = id;
                            objMMS.ReadState = readState;
                            objMMS.Time      = time * 1000;
                            objMMS.Thread_id = thread_id;
                            objMMS.Type      = type == 132 ? (int)TextMessage.MESSAGE_TYPE.RECEIVED : (int)TextMessage.MESSAGE_TYPE.SENT;

                            //Add to List
                            messages.Add(objMMS);
                        }
                        else
                        {
                            //this is SMS
                            //throw new Exception("알 수 없는 MMS 유형");
                        }
                    }
                }
                cursor.Close();
            }
            return(messages);
        }
Ejemplo n.º 2
0
        public static void BindHolder(Dialogue dialogue, TextView address, TextView msgText, TextView timeText, RelativeLayout readStateRL, TextView readStateCnt)
        {
            TextMessage lastMessage = dialogue[0];                           //대화 중 가장 마지막 문자

            //이름 혹은 연락처 표시, 문자 내용 표시
            address.Text = dialogue.DisplayName;
            if (lastMessage.GetType() == typeof(MultiMediaMessage))
            {
                MultiMediaMessage objMMS = lastMessage as MultiMediaMessage;
                switch (objMMS.MediaType)
                {
                case (int)MultiMediaMessage.MEDIA_TYPE.TEXT:
                    msgText.Text = objMMS.Msg;
                    break;

                case (int)MultiMediaMessage.MEDIA_TYPE.IMAGE:
                    msgText.Text = objMMS.Msg != null ? objMMS.Msg : "이미지 MMS";
                    break;

                case (int)MultiMediaMessage.MEDIA_TYPE.VCF:
                    msgText.Text = objMMS.Msg != null ? objMMS.Msg : "VCF MMS";
                    break;
                }
            }
            else
            {
                msgText.Text = lastMessage.Msg;
            }

            //날짜 표시
            DateTimeUtillity dtu = new DateTimeUtillity();

            if (dtu.GetNow().Year <= dtu.GetYear(lastMessage.Time))                                  //올해 메시지이면
            {
                if (dtu.GetDatetime(lastMessage.Time) >= dtu.GetToday())
                {
                    timeText.Text = dtu.MilisecondToDateTimeStr(lastMessage.Time, "a hh:mm");          //오늘 메시지이면
                }
                else
                {
                    timeText.Text = dtu.MilisecondToDateTimeStr(lastMessage.Time, "MM월 dd일");        //올해인데 오늘 메시지가 아님
                }
            }
            else
            {
                timeText.Text = dtu.MilisecondToDateTimeStr(lastMessage.Time, "yyyy년 MM월 dd일");    //올해 메시지가 아님
            }

            //문자 읽음 여부에 따른 상태표시기 표시여부 및 카운트설정
            if (dialogue.UnreadCnt > 0)
            {
                readStateRL.Visibility = ViewStates.Visible;
                readStateCnt.Text      = dialogue.UnreadCnt.ToString();
            }
            else
            {
                readStateRL.Visibility = ViewStates.Invisible;
            }
        }
Ejemplo n.º 3
0
        public void Bind(List <RecyclerItem> list, int iPosition)
        {
            MessageItem obj     = list[iPosition] as MessageItem;
            TextMessage message = obj.TextMessage;

            mMsg.Text = message.Msg;

            if (message.Msg != string.Empty && message.Msg != null)
            {
                mMsg.Visibility = ViewStates.Visible;
            }
            else
            {
                mMsg.Visibility = ViewStates.Gone;
            }

            DateTimeUtillity dtu = new DateTimeUtillity();

            mTime.Text = dtu.MilisecondToDateTimeStr(message.Time, "a hh:mm");

            if (message.GetType() == typeof(MultiMediaMessage))
            {
                mMmsTag.Visibility = ViewStates.Visible;

                MultiMediaMessage mms = message as MultiMediaMessage;
                if (mms.MediaType == (int)MultiMediaMessage.MEDIA_TYPE.IMAGE)
                {
                    if (mms.Bitmap != null)
                    {
                        mMmsImage.SetImageBitmap(mms.Bitmap);
                        mMmsImage.Visibility = ViewStates.Visible;
                    }
                    else
                    {
                        mMmsImage.SetImageBitmap(null);
                        mMmsImage.Visibility = ViewStates.Gone;
                    }
                }
                else
                {
                    mMmsImage.SetImageBitmap(null);
                    mMmsImage.Visibility = ViewStates.Gone;
                }
            }
            else
            {
                mMmsImage.SetImageBitmap(null);
                mMmsTag.Visibility   = ViewStates.Gone;
                mMmsImage.Visibility = ViewStates.Gone;
            }
        }
Ejemplo n.º 4
0
        //메시지 DB를 탐색하여, 각 대화중 가장 최신 MMS를 찾아 메모리에 올림.
        public void UpdateLastMMS()
        {
            ContentResolver cr  = Application.Context.ContentResolver;
            Uri             uri = Uri.Parse("content://mms/");

            string[] projection = new string[] { "DISTINCT thread_id", "_id", "ct_t", "read", "date", "m_type" };
            string   selection  = "thread_id IS NOT NULL) GROUP BY (thread_id";
            string   sortOrder  = "date desc";
            ICursor  cursor     = cr.Query(uri, projection, selection, null, sortOrder);

            if (cursor != null)
            {
                if (cursor.Count > 0)
                {
                    while (cursor.MoveToNext())
                    {
                        string id        = cursor.GetString(cursor.GetColumnIndex("_id"));
                        string mmsType   = cursor.GetString(cursor.GetColumnIndex("ct_t"));
                        int    readState = cursor.GetInt(cursor.GetColumnIndex("read"));
                        long   time      = cursor.GetLong(cursor.GetColumnIndex("date"));
                        long   thread_id = cursor.GetLong(cursor.GetColumnIndexOrThrow("thread_id"));
                        int    type      = cursor.GetInt(cursor.GetColumnIndexOrThrow("m_type"));
                        if ("application/vnd.wap.multipart.related".Equals(mmsType) || "application/vnd.wap.multipart.mixed".Equals(mmsType))
                        {
                            //this is MMS
                            MultiMediaMessage objMMS = ReadMMS(id);
                            objMMS.Id        = id;
                            objMMS.ReadState = readState;
                            objMMS.Time      = time * 1000;     //1000을 곱하지 않으면 1970년으로 표기됨
                            objMMS.Thread_id = thread_id;
                            objMMS.Type      = type == 132 ? (int)TextMessage.MESSAGE_TYPE.RECEIVED : (int)TextMessage.MESSAGE_TYPE.SENT;

                            UpdateLastMessage(objMMS);
                        }
                        else
                        {
                            //this is SMS
                            //throw new Exception("알 수 없는 MMS 유형");
                        }
                    }
                }
                cursor.Close();
            }
        }
Ejemplo n.º 5
0
        public void Bind(List <RecyclerItem> list, int iPosition, ContactData iContact)
        {
            MessageItem obj     = list[iPosition] as MessageItem;
            TextMessage message = obj.TextMessage;

            //연락처에 있는 사람이면
            if (iContact != null)
            {
                ////연락처에 사진이 있다면 사진으로 대체
                if (iContact.PhotoThumnail_uri != null)
                {
                    mProfileImage.SetImageURI(Android.Net.Uri.Parse(iContact.PhotoThumnail_uri));
                }
                else
                {
                    mProfileImage.SetImageResource(Resource.Drawable.profile_icon_256_background);
                }
            }
            else
            {
                //연락처에 사진이 없으면 기본사진으로 설정
                mProfileImage.SetImageResource(Resource.Drawable.profile_icon_256_background);
            }

            mMsg.Text = message.Msg;

            if (message.Msg != string.Empty && message.Msg != null)
            {
                mMsg.Visibility = ViewStates.Visible;
            }
            else
            {
                mMsg.Visibility = ViewStates.Gone;
            }

            DateTimeUtillity dtu = new DateTimeUtillity();

            mTime.Text = dtu.MilisecondToDateTimeStr(message.Time, "a hh:mm");

            if (message.GetType() == typeof(MultiMediaMessage))
            {
                mMmsTag.Visibility = ViewStates.Visible;

                MultiMediaMessage mms = message as MultiMediaMessage;
                if (mms.MediaType == (int)MultiMediaMessage.MEDIA_TYPE.IMAGE)
                {
                    if (mms.Bitmap != null)
                    {
                        mMmsImage.SetImageBitmap(mms.Bitmap);
                        mMmsImage.Visibility = ViewStates.Visible;
                    }
                    else
                    {
                        mMmsImage.SetImageBitmap(null);
                        mMmsImage.Visibility = ViewStates.Gone;
                    }
                }
                else
                {
                    mMmsImage.SetImageBitmap(null);
                    mMmsImage.Visibility = ViewStates.Gone;
                }
            }
            else
            {
                mMmsImage.SetImageBitmap(null);
                mMmsTag.Visibility   = ViewStates.Gone;
                mMmsImage.Visibility = ViewStates.Gone;
            }
        }
Ejemplo n.º 6
0
        // ---------------------------------------------------------------------------------
        // MMS를 읽기 위한 메소드

        private MultiMediaMessage ReadMMS(string id)
        {
            ContentResolver cr        = Application.Context.ContentResolver;
            string          selection = "mid = " + id;

            string[] projection = new string[] { "_id", "ct", "_data", "text" };
            Uri      uri        = Uri.Parse("content://mms/part");
            ICursor  cursor     = cr.Query(uri, projection, selection, null, null);

            MultiMediaMessage objMMS = new MultiMediaMessage();;

            if (cursor != null)
            {
                if (cursor.Count > 0)
                {
                    while (cursor.MoveToNext())
                    {
                        string mediaType = cursor.GetString(cursor.GetColumnIndexOrThrow("ct"));
                        if ("application/smil".Equals(mediaType))
                        {
                            //smil은 무시한다?
                            continue;
                        }

                        objMMS.Address = GetAddress(id);

                        string partId = cursor.GetString(cursor.GetColumnIndexOrThrow("_id"));

                        if ("text/plain".Equals(mediaType))
                        {
                            string data = cursor.GetString(cursor.GetColumnIndexOrThrow("_data"));
                            string body;
                            if (data != null)
                            {
                                body = GetMMSText(partId);
                            }
                            else
                            {
                                body = cursor.GetString(cursor.GetColumnIndexOrThrow("text"));
                            }
                            objMMS.Msg       = body;
                            objMMS.MediaType = (int)MultiMediaMessage.MEDIA_TYPE.TEXT;
                        }
                        else if ("image/jpeg".Equals(mediaType) || "image/bmp".Equals(mediaType) || "image/gif".Equals(mediaType) ||
                                 "image/jpg".Equals(mediaType) || "image/png".Equals(mediaType))
                        {
                            objMMS.Bitmap    = GetMMSImage(partId);
                            objMMS.MediaType = (int)MultiMediaMessage.MEDIA_TYPE.IMAGE;
                        }
                        else if ("text/x-vCard".Equals(mediaType))
                        {
                            //.vcf는 처리 어케하지
                            objMMS.MediaType = (int)MultiMediaMessage.MEDIA_TYPE.VCF;
                        }
                        else
                        {
                            //throw new Exception("알 수 없는 MMS 타입");
                        }
                    }
                }
                cursor.Close();
            }
            return(objMMS);
        }