Пример #1
0
 public DropDownList(string[] entries, string pickerName, float width, BaseActivity context)
 {
     this.entries    = entries;
     this.pickerName = pickerName;
     this.width      = width;
     this.context    = context;
 }
Пример #2
0
        public override void AnimateTransition(IUIViewControllerContextTransitioning transitionContext)
        {
            var          inView   = transitionContext.ContainerView;
            var          fromVC   = transitionContext.GetViewControllerForKey(UITransitionContext.FromViewControllerKey);
            BaseActivity toVC     = (BaseActivity)transitionContext.GetViewControllerForKey(UITransitionContext.ToViewControllerKey);
            var          fromView = fromVC.View;
            var          toView   = toVC.View;

            inView.AddSubview(toView);

            var frame = toView.Frame;

            toView.Frame = new CGRect(frame.Width, 0, frame.Width, frame.Height);

            UIView.Animate(TransitionDuration(transitionContext), () => {
                fromView.Frame = new CGRect(-frame.Width, 0, frame.Width, frame.Height);
                toView.Frame   = new CGRect(0, 0, frame.Width, frame.Height);
            }, () => {
                transitionContext.CompleteTransition(true);

                CommonMethods.transitionRunning = false;
                if (CommonMethods.transitionTarget != "empty")
                {
                    CommonMethods.OpenPage(CommonMethods.transitionTarget, CommonMethods.transitionAnim);
                    CommonMethods.transitionTarget = "empty";
                }
            });
        }
Пример #3
0
        [Export("userNotificationCenter:didReceiveNotificationResponse:withCompletionHandler:")]                            //does it come after autologin?
        public void DidReceiveNotificationResponse(UNUserNotificationCenter center, UNNotificationResponse response, Action //called when app is in background, and user taps on notification
                                                   completionHandler)
        {
            completionHandler();
            NSDictionary userInfo = response.Notification.Request.Content.UserInfo;

            CommonMethods c       = new CommonMethods(null);
            BaseActivity  context = CommonMethods.GetCurrentViewController();

            CommonMethods.LogStatic("DidReceiveNotificationResponse " + userInfo.ToString().Replace(Environment.NewLine, " ") + " logged in " + c.IsLoggedIn() + " context " + context);

            if (userInfo != null && userInfo.ContainsKey(new NSString("aps")))
            {
                int senderID = ((NSNumber)userInfo.ObjectForKey(new NSString("fromuser"))).Int32Value;
                int targetID = ((NSNumber)userInfo.ObjectForKey(new NSString("touser"))).Int32Value;

                if (targetID != Session.ID)
                {
                    return;
                }

                IntentData.senderID = senderID;
                if (!(context is ChatOneActivity))
                {
                    CommonMethods.OpenPage("ChatOneActivity", 1);
                }
                //otherwise foreground notification will refresh the page
            }
        }
        protected override void OnPause()
        {
            base.OnPause();
            visibleContext = null;
            UnregisterReceiver(chatReceiver);

            isAppVisible = false;

            c.Log(LocalClassName.Split(".")[1] + " OnPause");
        }
Пример #5
0
 public void SetContext(BaseActivity context)
 {
     this.context = context;
     if (context is RegisterActivity)
     {
         rc = ((RegisterActivity)context).rc;
     }
     else
     {
         rc = ((ProfileEditActivity)context).rc;
     }
 }
        protected override void OnResume()
        {
            base.OnResume();
            visibleContext = this;
            RegisterReceiver(chatReceiver, new IntentFilter("balintfodor.locationconnection.ChatReceiver"));

            isAppVisible = true;
            if (!(this is ListActivity))             //we need to exclude ListActivity, because we need to show the GettingLocation label
            {
                if (!locationUpdating && c.IsLocationEnabled() && (c.IsLoggedIn() && Session.UseLocation == true || !c.IsLoggedIn()))
                {
                    StartLocationUpdates();
                }
            }

            c.Log(LocalClassName.Split(".")[1] + " OnResume");

            if (!ListActivity.initialized)             //When opening app, Android sometimes resumes an Activity while the static variables are cleared out, resulting in error
            {
                c.Log(LocalClassName.Split(".")[1] + " Not initialized");

                c.ReportErrorSilent("Initialization error");

                Intent i = new Intent(this, typeof(ListActivity));                 //current activity has to go through OnResume, therefore we cannot handle initialization errors in OnCreate
                StartActivity(i);
            }

            if (!(snack is null) && snack.IsShown)
            {
                snack.Dismiss();
            }

            if (!(Session.SnackMessage is null))             //ChatList: for the situation when the user is deleted, while the other is on their page, and now want to load the chat.
            {
                if (this is ChatOneActivity)
                {
                    RunOnUiThread(() =>
                    {
                        c.SnackStr(Session.SnackMessage.Replace("[name]", Session.CurrentMatch.TargetName));
                    });
                    Session.SnackMessage = null;
                }
                else
                {
                    RunOnUiThread(() =>
                    {
                        c.SnackStr(Session.SnackMessage);
                    });
                    Session.SnackMessage = null;
                }
            }
        }
        public void SetImage(BaseActivity context, string userID, string picture, bool temp = false)
        {
            NSBundle.MainBundle.LoadNib("UploadedItem", this, null);

            Frame          = Bounds;
            MainView.Frame = Bounds;

            AddSubview(MainView);

            ImageCache im = new ImageCache(context);

            im.LoadImage(UploadedImage, userID, picture, false, temp);
        }
        public void Stopped()
        {
            CommonMethods.LogStatic("Entered background");

            if (!string.IsNullOrEmpty(BaseActivity.locationUpdatesTo))
            {
                BaseActivity.EndLocationShare();
                BaseActivity.locationUpdatesTo = null;                 //stop real-time location updates when app goes to background
            }
            BaseActivity.locationUpdatesFrom     = null;
            BaseActivity.locationUpdatesFromData = null;

            BaseActivity.StopLocationUpdates();
        }
 public void SetContext(BaseActivity context)
 {
     this.context = context;
 }
Пример #10
0
        private void HandleNotification(int senderID, int targetID, string type, string meta, bool inApp, string title, string body)
        {
            int    sep1Pos;
            int    sep2Pos;
            int    sep3Pos;
            int    sep4Pos;
            int    matchID;
            string senderName;
            string text;

            BaseActivity context = CommonMethods.GetCurrentViewController();

            if (targetID != Session.ID)
            {
                return;
            }

            try
            {
                switch (type)
                {
                case "sendMessage":


                    if (context is ChatOneActivity)
                    {
                        long unixTimestamp = (long)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;

                        //we need to update the Read time locally for display purposes before
                        sep1Pos = meta.IndexOf('|');
                        sep2Pos = meta.IndexOf('|', sep1Pos + 1);
                        sep3Pos = meta.IndexOf('|', sep2Pos + 1);

                        int  messageID = int.Parse(meta.Substring(0, sep1Pos));
                        long sentTime  = long.Parse(meta.Substring(sep2Pos + 1, sep3Pos - sep2Pos - 1));
                        long seenTime  = unixTimestamp;
                        long readTime  = unixTimestamp;

                        meta = messageID + "|" + senderID + "|" + sentTime + "|" + seenTime + "|" + readTime + "|";

                        if (senderID != Session.ID && senderID == ((ChatOneActivity)context).currentMatch.TargetID)                                 //for tests, you can use 2 accounts from the same device, and a sent message would appear duplicate.
                        {
                            ((ChatOneActivity)context).AddMessageItemOne(meta + body);
                            ((ChatOneActivity)context).c.MakeRequest("action=messagedelivered&ID=" + Session.ID + "&SessionID=" + Session.SessionID + "&MatchID=" + ((ChatOneActivity)context).currentMatch.MatchID + "&MessageID=" + messageID + "&Status=Read");
                        }
                        else if (inApp && senderID != Session.ID)
                        {
                            context.c.SnackAction(title, LangEnglish.ShowReceived, new Action(delegate() { GoToChatNoOpen(senderID); }));
                        }
                    }
                    else
                    {
                        if (inApp)
                        {
                            context.c.SnackAction(title, LangEnglish.ShowReceived, new Action(delegate() { GoToChat(senderID); }));
                        }

                        //update message list
                        if (context is ChatListActivity)
                        {
                            ((ChatListActivity)context).InsertMessage(meta, body);
                        }
                    }
                    break;

                case "messageDelivered":
                case "loadMessages":
                case "loadMessageList":
                    if (context is ChatOneActivity && senderID == ((ChatOneActivity)context).currentMatch.TargetID)
                    {
                        string[] updateItems = meta.Substring(1, meta.Length - 2).Split("}{");
                        foreach (string item in updateItems)
                        {
                            ((ChatOneActivity)context).UpdateMessageItem(item);
                        }
                    }
                    break;

                case "matchProfile":
                    if (inApp)                             ////it is impossible to stand in that chat if wasn't previously a match
                    {
                        if (context is ChatOneActivity)
                        {
                            context.c.SnackAction(title, LangEnglish.ShowReceived, new Action(delegate() { GoToChatNoOpen(senderID); }));
                        }
                        else
                        {
                            context.c.SnackAction(title, LangEnglish.ShowReceived, new Action(delegate() { GoToChat(senderID); }));
                        }
                    }

                    if (context is ChatListActivity)
                    {
                        string matchItem = meta;
                        ServerParser <MatchItem> parser = new ServerParser <MatchItem>(matchItem);
                        ((ChatListActivity)context).AddMatchItem(parser.returnCollection[0]);
                    }

                    AddUpdateMatch(senderID, true);
                    if (context is ProfileViewActivity)
                    {
                        ((ProfileViewActivity)context).UpdateStatus(senderID, true);
                    }
                    break;

                case "rematchProfile":
                    sep1Pos = meta.IndexOf('|');

                    matchID = int.Parse(meta.Substring(0, sep1Pos));
                    bool active = bool.Parse(meta.Substring(sep1Pos + 1));

                    if (inApp)
                    {
                        if (context is ChatOneActivity && ((ChatOneActivity)context).currentMatch.TargetID == senderID)
                        {
                            context.c.Snack(title);
                        }
                        else if (context is ChatOneActivity)
                        {
                            context.c.SnackAction(title, LangEnglish.ShowReceived, new Action(delegate() { GoToChatNoOpen(senderID); }));
                        }
                        else
                        {
                            context.c.SnackAction(title, LangEnglish.ShowReceived, new Action(delegate() { GoToChat(senderID); }));
                        }
                    }

                    AddUpdateMatch(senderID, true);
                    if (context is ChatListActivity)
                    {
                        ((ChatListActivity)context).UpdateMatchItem(matchID, active, null);
                    }
                    else if (context is ChatOneActivity)
                    {
                        ((ChatOneActivity)context).UpdateStatus(senderID, active, null);
                    }
                    else if (context is ProfileViewActivity)
                    {
                        ((ProfileViewActivity)context).UpdateStatus(senderID, true);
                    }

                    break;

                case "unmatchProfile":
                    sep1Pos = meta.IndexOf('|');

                    matchID = int.Parse(meta.Substring(0, sep1Pos));
                    long unmatchDate = long.Parse(meta.Substring(sep1Pos + 1));

                    if (context.IsUpdatingFrom(senderID))
                    {
                        context.RemoveUpdatesFrom(senderID);
                    }
                    if (context.IsUpdatingTo(senderID))
                    {
                        context.RemoveUpdatesTo(senderID);
                    }

                    if (inApp)
                    {
                        if (context is ChatOneActivity && ((ChatOneActivity)context).currentMatch.TargetID == senderID)
                        {
                            context.c.Snack(title);
                        }
                        else if (context is ChatOneActivity)
                        {
                            context.c.SnackAction(title, LangEnglish.ShowReceived, new Action(delegate() { GoToChatNoOpen(senderID); }));
                        }
                        else
                        {
                            context.c.SnackAction(title, LangEnglish.ShowReceived, new Action(delegate() { GoToChat(senderID); }));
                        }
                    }

                    AddUpdateMatch(senderID, false);
                    if (context is ChatListActivity)
                    {
                        ((ChatListActivity)context).UpdateMatchItem(matchID, false, unmatchDate);
                    }
                    else if (context is ChatOneActivity)
                    {
                        ((ChatOneActivity)context).UpdateStatus(senderID, false, unmatchDate);
                    }
                    else if (context is ProfileViewActivity)
                    {
                        ((ProfileViewActivity)context).UpdateStatus(senderID, false);
                    }

                    break;

                case "locationUpdate":
                    sep1Pos = meta.IndexOf('|');
                    sep2Pos = meta.IndexOf('|', sep1Pos + 1);

                    senderName = meta.Substring(0, sep1Pos);
                    int frequency = int.Parse(meta.Substring(sep1Pos + 1, sep2Pos - sep1Pos - 1));

                    if (!context.IsUpdatingFrom(senderID))
                    {
                        context.AddUpdatesFrom(senderID);

                        text = senderName + " " + LangEnglish.LocationUpdatesFromStart + " " + frequency + " s.";
                        if (context is ProfileViewActivity)
                        {
                            ((ProfileViewActivity)context).UpdateLocationStart(senderID, text);
                        }
                        else
                        {
                            context.c.SnackAction(text, LangEnglish.ShowReceived, new Action(delegate() { GoToProfile(senderID); }));
                        }
                    }

                    sep3Pos = meta.IndexOf('|', sep2Pos + 1);
                    sep4Pos = meta.IndexOf('|', sep3Pos + 1);

                    long   time      = long.Parse(meta.Substring(sep2Pos + 1, sep3Pos - sep2Pos - 1));
                    double latitude  = double.Parse(meta.Substring(sep3Pos + 1, sep4Pos - sep3Pos - 1), CultureInfo.InvariantCulture);
                    double longitude = double.Parse(meta.Substring(sep4Pos + 1), CultureInfo.InvariantCulture);

                    context.AddLocationData(senderID, latitude, longitude, time);

                    if (!(ListActivity.listProfiles is null))
                    {
                        foreach (Profile user in ListActivity.listProfiles)
                        {
                            if (user.ID == senderID)
                            {
                                user.LastActiveDate = time;
                                user.Latitude       = latitude;
                                user.Longitude      = longitude;
                                user.LocationTime   = time;
                            }
                        }
                    }

                    if (context is ListActivity && (bool)Settings.IsMapView)
                    {
                        foreach (ProfileAnnotation annotation in ListActivity.profileAnnotations)
                        {
                            if (annotation.Title == senderID.ToString())
                            {
                                annotation.SetCoordinate(new CLLocationCoordinate2D(latitude, longitude));
                            }
                        }
                    }
                    else if (context is ProfileViewActivity)
                    {
                        ((ProfileViewActivity)context).UpdateLocation(senderID, time, latitude, longitude);
                    }
                    break;

                case "locationUpdateEnd":
                    senderName = meta;

                    if (context.IsUpdatingFrom(senderID))                             //user could have gone to the background, clearing out the list of people to receive updates from.
                    {
                        context.RemoveUpdatesFrom(senderID);

                        text = senderName + " " + LangEnglish.LocationUpdatesFromEnd;
                        context.c.Snack(text);
                    }
                    break;
                }
            }
            catch (Exception ex)
            {
                CommonMethods c = new CommonMethods(null);
                c.ReportErrorSilent(ex.Message + System.Environment.NewLine + ex.StackTrace + System.Environment.NewLine + " Error in DidReceiveMessage");
            }
        }
 public CustomAnnotationView(BaseActivity context)
 {
     this.context = context;
 }
        public override void ViewDidLoad()
        {
            try
            {
                base.ViewDidLoad();

                if (!foregroundNotificationSet)
                {
                    UIApplication.Notifications.ObserveDidEnterBackground((sender, args) => {
                        c.Log("Entered background LocationActivity");
                    });

                    UIApplication.Notifications.ObserveDidBecomeActive((sender, args) => { //once set, will be called when other activities go to background and foreground
                        c.Log("Entered foreground LocationActivity");

                        BaseActivity currentController = CommonMethods.GetCurrentViewController();
                        if (currentController is LocationActivity)
                        {
                            ((LocationActivity)currentController).LoadList();
                            ((LocationActivity)currentController).AddLinesToMap();
                        }
                    });

                    foregroundNotificationSet = true;
                }

                RoundBottom_Base           = RoundBottom;
                Snackbar_Base              = Snackbar;
                BottomConstraint_Base      = BottomConstraint;
                SnackTopConstraint_Base    = SnackTopConstraint;
                SnackBottomConstraint_Base = SnackBottomConstraint;

                LocationHistoryList.SeparatorStyle = UITableViewCellSeparatorStyle.None;

                c.AddViews(Snackbar, Snackbar.SnackText, Snackbar.SnackButton);

                mapSet = false;

                MapStreet.SetTitle(LangEnglish.MapStreet, UIControlState.Normal);
                MapSatellite.SetTitle(LangEnglish.MapSatellite, UIControlState.Normal);
                LocationHistoryMap.MapType = (MKMapType)Settings.LocationMapType;
                if (Settings.LocationMapType == (int)MKMapType.Standard)
                {
                    MapStreet.BackgroundColor    = UIColor.FromName("MapButtonActive");
                    MapSatellite.BackgroundColor = UIColor.FromName("MapButtonPassive");
                }
                else
                {
                    MapStreet.BackgroundColor    = UIColor.FromName("MapButtonPassive");
                    MapSatellite.BackgroundColor = UIColor.FromName("MapButtonActive");
                }
                LocationHistoryMap.Delegate      = new CustomAnnotationView(this);
                LocationHistoryMap.LayoutMargins = new UIEdgeInsets(43, 0, 0, 7); //to move the compass

                LocationBack.TouchUpInside += LocationBack_Click;
                LocationBack.TouchDown     += LocationBack_TouchDown;
                MapStreet.TouchUpInside    += MapStreet_Click;
                MapSatellite.TouchUpInside += MapSatellite_Click;

                LoadList();
            }
            catch (Exception ex)
            {
                c.ReportErrorSilent(ex.Message + Environment.NewLine + ex.StackTrace);
            }
        }
 public FusedLocationProviderCallback(BaseActivity context)
 {
     this.context = context;
 }
        public override void ViewDidLoad()
        {
            try
            {
                base.ViewDidLoad();

                if (!foregroundNotificationSet)
                {
                    UIApplication.Notifications.ObserveDidBecomeActive((sender, args) => {
                        c.Log("Entered foreground, registering for notifications");

                        c.RequestNotification();

                        BaseActivity currentController = CommonMethods.GetCurrentViewController();
                        if (currentController is ChatOneActivity)
                        {
                            ((ChatOneActivity)currentController).SetMenu();                             //needed in case location updates were running before backgrounding
                            ((ChatOneActivity)currentController).RefreshPage();
                        }
                    });

                    foregroundNotificationSet = true;
                }

                NoMessages.Text   = LangEnglish.NoMessages;
                NoMessages.Hidden = true;

                c.DrawBorder(ChatEditMessage);

                c.AddViews(Snackbar, Snackbar.SnackText, Snackbar.SnackButton);

                MenuUnmatch.SetTitle(LangEnglish.MenuUnmatch, UIControlState.Normal);
                MenuBlock.SetTitle(LangEnglish.MenuBlock, UIControlState.Normal);
                MenuReport.SetTitle(LangEnglish.MenuReport, UIControlState.Normal);

                c.HideMenu(MenuLayer, MenuContainer, false);

                ChatMessageWindow.RowHeight          = UITableView.AutomaticDimension;
                ChatMessageWindow.EstimatedRowHeight = 100;

                ChatOneBack.TouchUpInside     += ChatOneBack_Click;
                ChatSendMessage.TouchUpInside += ChatSendMessage_Click;

                MenuIcon.TouchUpInside += MenuIcon_Click;
                MenuLayer.TouchDown    += MenuLayer_TouchDown;

                MenuLocationUpdates.TouchUpInside += MenuLocationUpdates_Click;
                MenuFriend.TouchUpInside          += MenuFriend_Click;
                MenuUnmatch.TouchUpInside         += MenuUnmatch_Click;
                MenuReport.TouchUpInside          += MenuReport_Click;
                MenuBlock.TouchUpInside           += MenuBlock_Click;

                RoundBottom_Base = RoundBottom;
                Snackbar_Base    = Snackbar;

                BottomConstraint_Base       = BottomConstraint;
                SnackTopConstraint_Base     = SnackTopConstraint;
                SnackBottomConstraint_Base  = SnackBottomConstraint;
                ChatOneLeftConstraint_Base  = ChatOneLeftConstraint;
                ChatOneRightConstraint_Base = ChatOneRightConstraint;
                ChatMessageWindow_Base      = ChatMessageWindow;
            }
            catch (Exception ex)
            {
                c.ReportErrorSilent(ex.Message + Environment.NewLine + ex.StackTrace);
            }
        }
        public RegisterCommonMethods(BaseActivity context, CommonMethods c, ImageFrameLayout ImagesUploaded, UITextField Email, UITextField Username, UITextField Name, UITextView DescriptionText, UIButton CheckUsername, UIButton Images,
                                     UILabel ImagesProgressText, UIImageView LoaderCircle, UIProgressView ImagesProgress, UISwitch UseLocationSwitch, UISwitch LocationShareAll, UISwitch LocationShareLike, UISwitch LocationShareMatch, UISwitch LocationShareFriend, UISwitch LocationShareNone,
                                     UISwitch DistanceShareAll, UISwitch DistanceShareLike, UISwitch DistanceShareMatch, UISwitch DistanceShareFriend, UISwitch DistanceShareNone, UIView ImageEditorControls, UIImageView TopSeparator, UIImageView RippleImageEditor, UIView ImageEditorStatus, UIButton ImageEditorCancel, UIButton ImageEditorOK, UIImageView ImageEditor, UIView ImageEditorFrame, UIView ImageEditorFrameBorder)
        {
            this.context = context;
            this.c       = c;

            this.ImagesUploaded         = ImagesUploaded;
            this.Email                  = Email;
            this.Username               = Username;
            this.Name                   = Name;
            this.DescriptionText        = DescriptionText;
            this.CheckUsername          = CheckUsername;
            this.Images                 = Images;
            this.ImagesProgressText     = ImagesProgressText;
            this.LoaderCircle           = LoaderCircle;
            this.ImagesProgress         = ImagesProgress;
            this.UseLocationSwitch      = UseLocationSwitch;
            this.LocationShareAll       = LocationShareAll;
            this.LocationShareLike      = LocationShareLike;
            this.LocationShareMatch     = LocationShareMatch;
            this.LocationShareFriend    = LocationShareFriend;
            this.LocationShareNone      = LocationShareNone;
            this.DistanceShareAll       = DistanceShareAll;
            this.DistanceShareLike      = DistanceShareLike;
            this.DistanceShareMatch     = DistanceShareMatch;
            this.DistanceShareFriend    = DistanceShareFriend;
            this.DistanceShareNone      = DistanceShareNone;
            this.ImageEditorControls    = ImageEditorControls;
            this.TopSeparator           = TopSeparator;
            this.RippleImageEditor      = RippleImageEditor;
            this.ImageEditorStatus      = ImageEditorStatus;
            this.ImageEditorCancel      = ImageEditorCancel;
            this.ImageEditorOK          = ImageEditorOK;
            this.ImageEditor            = ImageEditor;
            this.ImageEditorFrame       = ImageEditorFrame;
            this.ImageEditorFrameBorder = ImageEditorFrameBorder;

            CheckUsername.TouchUpInside += CheckUsername_Click;
            Images.TouchUpInside        += Images_Click;

            UseLocationSwitch.TouchUpInside   += UseLocationSwitch_Click;
            LocationShareAll.TouchUpInside    += LocationShareAll_Click;
            LocationShareLike.TouchUpInside   += LocationShareLike_Click;
            LocationShareMatch.TouchUpInside  += LocationShareMatch_Click;
            LocationShareFriend.TouchUpInside += LocationShareFriend_Click;
            LocationShareNone.TouchUpInside   += LocationShareNone_Click;

            DistanceShareAll.TouchUpInside    += DistanceShareAll_Click;
            DistanceShareLike.TouchUpInside   += DistanceShareLike_Click;
            DistanceShareMatch.TouchUpInside  += DistanceShareMatch_Click;
            DistanceShareFriend.TouchUpInside += DistanceShareFriend_Click;
            DistanceShareNone.TouchUpInside   += DistanceShareNone_Click;

            ImageEditorCancel.TouchDown += ImageEditorButton_TouchDown;
            ImageEditorOK.TouchDown     += ImageEditorButton_TouchDown;

            UIPanGestureRecognizer move = new UIPanGestureRecognizer();

            move.AddTarget(() => MoveImage(move));
            ImageEditor.AddGestureRecognizer(move);

            UIPinchGestureRecognizer zoom = new UIPinchGestureRecognizer();

            zoom.AddTarget(() => ZoomImage(zoom));
            ImageEditor.AddGestureRecognizer(zoom);

            client = new WebClient();
            client.UploadProgressChanged += Client_UploadProgressChanged;
            client.UploadFileCompleted   += Client_UploadFileCompleted;
            client.Headers.Add("Content-Type", "image/jpeg");
        }
Пример #16
0
 public ImageCache(BaseActivity context)
 {
     this.context = context;
 }
 public LocationManager(BaseActivity context)
 {
     this.context = context;
     locMgr       = new CLLocationManager();
 }
        public async static Task <Bitmap> GetBitmap(BaseActivity context)
        {
            CommonMethods   c               = context.c;
            Resources       res             = context.Resources;
            ContentResolver contentResolver = context.ContentResolver;

            ExifInterface exif;

            try
            {
                exif = new ExifInterface(contentResolver.OpenInputStream(selectedFile));
            }
            catch (Exception ex)
            {
                await c.ErrorAlert(res.GetString(Resource.String.ImageLoadingError) + " " + ex.Message);

                c.ReportErrorSilent(res.GetString(Resource.String.ImageLoadingError) + " " + ex.Message);
                selectedFile = null;
                return(null);
            }

            c.Log("GetBitmap exif " + exif);

            int orientation = 0;

            if (!(exif is null))
            {
                orientation = exif.GetAttributeInt(ExifInterface.TagOrientation, (int)Android.Media.Orientation.Undefined);
            }

            try             //Original issue: On Android 7.1.1 (Asus ZenFone Zoom S), image loading fails for the 4th time
            {
                bm = BitmapFactory.DecodeStream(contentResolver.OpenInputStream(selectedFile));
            }
            catch (Exception ex)
            {
                if (ex is OutOfMemoryException)                 //does not seem to be an happen now that bm is recycled after closing the editor
                {
                    await c.ErrorAlert(res.GetString(Resource.String.OutOfMemoryError));

                    c.ReportErrorSilent(res.GetString(Resource.String.OutOfMemoryError) + " " + ex.Message);
                    throw ex;                     //OnResume is now finished, exception will not be caught
                }
                else
                {
                    await c.ErrorAlert(res.GetString(Resource.String.ImageLoadingError) + " " + ex.Message);

                    c.ReportErrorSilent(res.GetString(Resource.String.ImageLoadingError) + " " + ex.Message);
                }
                selectedFile = null;
                return(null);
            }

            c.Log("bm " + bm);

            c.Log("Image width " + bm.Width + " height " + bm.Height + " orientation " + orientation);

            switch (orientation)
            {
            case (int)Android.Media.Orientation.Rotate90:
                bm = RotateImage(bm, 90);
                break;

            case (int)Android.Media.Orientation.Rotate180:
                bm = RotateImage(bm, 180);
                break;

            case (int)Android.Media.Orientation.Rotate270:
                bm = RotateImage(bm, 270);
                break;
            }

            return(bm);
        }