Ejemplo n.º 1
0
        private void generateMessageBarAndAnimate(string message, MessageDB msgList, UserDB contact, bool shutUp = false)
        {
            //RunOnUiThread (delegate {
            bool rpong = false;
            if (shutUp != true) {
                AudioPlayer ap = new AudioPlayer (context);
                Android.Content.Res.AssetManager am = this.Assets;
                ap.playFromAssets (am, "incoming.mp3");
            }
            Guid grabGuid = Guid.Empty;
            RunOnUiThread (() => messageBar.SetPadding ((int)ImageHelper.convertDpToPixel (5f, context), 0, (int)ImageHelper.convertDpToPixel (5f, context),
                                                        (int)ImageHelper.convertDpToPixel (10f, context)));

            int leftOver = Convert.ToInt32 (wowZapp.LaffOutOut.Singleton.ScreenXWidth - (picSize + 40));
            LinearLayout.LayoutParams layParams;
            if (contact == null)
                throw new Exception ("Contact is null in generateMessageBarAndAnimate");

            ImageView profilePic = new ImageView (context);
            using (layParams = new LinearLayout.LayoutParams (picSize, picSize)) {
                layParams.SetMargins ((int)ImageHelper.convertDpToPixel (15f, context), (int)ImageHelper.convertDpToPixel (20f, context), 0, 0);
                profilePic.LayoutParameters = layParams;
            }
            profilePic.SetBackgroundResource (Resource.Drawable.defaultuserimage);
            profilePic.Tag = new Java.Lang.String ("profilepic_" + contact.AccountID);

            RunOnUiThread (() => messageBar.AddView (profilePic));

            if (Contacts.ContactsUtil.contactFilenames.Contains (contact.AccountGuid)) {
                rpong = true;
                using (Bitmap bm = BitmapFactory.DecodeFile (System.IO.Path.Combine (wowZapp.LaffOutOut.Singleton.ImageDirectory, contact.AccountGuid))) {
                    using (MemoryStream ms = new MemoryStream ()) {
                        bm.Compress (Bitmap.CompressFormat.Jpeg, 80, ms);
                        byte[] image = ms.ToArray ();
                        displayImage (image, profilePic);
                    }
                }
            } else {
                if (contact.Picture.Length == 0)
                    grabGuid = contact.AccountID;
                else {
                    if (contact.Picture.Length > 0)
                        loadProfilePicture (contact, profilePic);
                }
            }

            LinearLayout fromTVH = new LinearLayout (context);
            fromTVH.Orientation = Orientation.Vertical;
            fromTVH.LayoutParameters = new ViewGroup.LayoutParams (LinearLayout.LayoutParams.FillParent, LinearLayout.LayoutParams.FillParent);

            float textNameSize = wowZapp.LaffOutOut.Singleton.resizeFonts == true ? (int)ImageHelper.convertPixelToDp (((25 * picSize) / 100), context) : 16f;
            TextView textFrom = new TextView (context);
            using (layParams = new LinearLayout.LayoutParams (leftOver, (int)textNameSize)) {
                layParams.SetMargins ((int)ImageHelper.convertDpToPixel (9.3f, context), (int)ImageHelper.convertPixelToDp (textNameSize - 1, context), 0, 0);
                textFrom.LayoutParameters = layParams;
            }
            float fontSize = wowZapp.LaffOutOut.Singleton.resizeFonts == true ? ImageHelper.convertPixelToDp (((12 * picSize) / 100), context) : ImageHelper.convertPixelToDp (14f, context);
            textFrom.SetTextSize (Android.Util.ComplexUnitType.Dip, fontSize);

            textFrom.SetTextColor (Color.Black);
            if (contact != null)
                textFrom.Text = contact.FirstName + " " + contact.LastName;
            else
                textFrom.Text = "Ann Onymouse";
            RunOnUiThread (() => fromTVH.AddView (textFrom));

            float textMessageSize = wowZapp.LaffOutOut.Singleton.resizeFonts == true ? ImageHelper.convertPixelToDp (((70 * picSize) / 100), context) : ImageHelper.convertDpToPixel (39f, context);
            TextView textMessage = new TextView (context);
            using (layParams = new LinearLayout.LayoutParams (leftOver, (int)textMessageSize)) {
                layParams.SetMargins ((int)ImageHelper.convertDpToPixel (10f, context), 0, (int)ImageHelper.convertDpToPixel (10, context), 0);
                textMessage.LayoutParameters = layParams;
            }
            float fontSize2 = wowZapp.LaffOutOut.Singleton.resizeFonts == true ? ImageHelper.convertPixelToDp (((12 * picSize) / 100), context) : ImageHelper.convertPixelToDp (16f, context);
            textMessage.SetTextSize (Android.Util.ComplexUnitType.Dip, fontSize2);
            textMessage.SetTextColor (Color.White);

            textMessage.SetPadding ((int)ImageHelper.convertDpToPixel (20f, context), 0, (int)ImageHelper.convertDpToPixel (10f, context), 0);
            if (!string.IsNullOrEmpty (message))
                textMessage.SetBackgroundResource (Resource.Drawable.bubblesolidleft);
            textMessage.Text = message != string.Empty ? message : "";
            textMessage.ContentDescription = msgList.MessageGuid;
            textMessage.Click += new EventHandler (textMessage_Click);
            RunOnUiThread (() => fromTVH.AddView (textMessage));
            //}

            if (msgList != null) {
                LinearLayout messageItems = new LinearLayout (context);
                messageItems.Orientation = Orientation.Horizontal;
                float messageBarSize = wowZapp.LaffOutOut.Singleton.resizeFonts == true ? ImageHelper.convertPixelToDp (((35 * picSize) / 100), context) : ImageHelper.convertDpToPixel (40f, context);
                using (layParams = new LinearLayout.LayoutParams (leftOver, (int)messageBarSize)) {
                    layParams.SetMargins ((int)ImageHelper.convertDpToPixel (14f, context), (int)ImageHelper.convertDpToPixel (3.3f, context), (int)ImageHelper.convertDpToPixel (12.7f, context), (int)ImageHelper.convertDpToPixel (4f, context));
                    messageItems.LayoutParameters = layParams;
                }
                messageItems.SetPadding ((int)ImageHelper.convertDpToPixel (10f, context), (int)ImageHelper.convertDpToPixel (3.3f, context), (int)ImageHelper.convertDpToPixel (10f, context), 0);
                messageItems.SetGravity (GravityFlags.Left);
                messageItems = createMessageBar (messageItems, msgList, leftOver);
                RunOnUiThread (() => fromTVH.AddView (messageItems));
            }

            RunOnUiThread (() => messageBar.AddView (fromTVH));

            RunOnUiThread (delegate {
                hsv.RemoveAllViews ();
                hsv.AddView (messageBar);
            });

            if (grabGuid != null) {
                LOLConnectClient service = new LOLConnectClient (LOLConstants.DefaultHttpBinding, LOLConstants.LOLConnectEndpoint);
                service.UserGetImageDataCompleted += Service_UserGetImageDataCompleted;
                service.UserGetImageDataAsync (AndroidData.CurrentUser.AccountID, grabGuid, new Guid (AndroidData.ServiceAuthToken));
            }
            //});
            RunOnUiThread (delegate {
                Handler handler = new Handler ();
                handler.PostDelayed (new Action (() =>
                {
                    hsv.SmoothScrollTo (newX, 0);
                }), 2000);
            });
        }