Exemple #1
0
        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            var view = inflater.Inflate(Resource.Layout.ParticipantSelectionLayout, container, false);

            view.FindViewById <LinearLayout> (Resource.Id.animatedLayout).LayoutTransition = new Android.Animation.LayoutTransition();

            selfFace              = view.FindViewById <ImageView> (Resource.Id.selfFace);
            otherFace             = view.FindViewById <ImageView> (Resource.Id.otherFace);
            faceLayout            = view.FindViewById <LinearLayout> (Resource.Id.userFacesLayout);
            selfFaceLayout        = view.FindViewById <FrameLayout> (Resource.Id.selfFaceLayout);
            otherFaceLayout       = view.FindViewById <FrameLayout> (Resource.Id.otherFaceLayout);
            selfFaceLayout.Drag  += HandleDrag;
            otherFaceLayout.Drag += HandleDrag;
            arrowWay              = view.FindViewById <Arrow> (Resource.Id.arrowWay);
            statsSpinner          = view.FindViewById <ProgressBar> (Resource.Id.StatsLoadSpinner);
            whatEntry             = view.FindViewById <LinearLayout> (Resource.Id.whatEntry);
            whatLayout            = view.FindViewById <LinearLayout> (Resource.Id.whatLayout);

            userDropZone = view.FindViewById <LinearLayout> (Resource.Id.whoLayout);

            var inset = view.FindViewById <InsetTextView> (Resource.Id.testInset);

            inset.Text   = "Drag Us";
            karmaBar     = view.FindViewById <KarmaMeter> (Resource.Id.karmaBar);
            flashBarCtrl = new FlashBarController(view.FindViewById(Resource.Id.flashbar));

            Task.Factory.StartNew(() => {
                var contactData = ContactsContract.Profile.ContentUri;
                var stream      = ContactsContract.Contacts.OpenContactPhotoInputStream(Activity.ContentResolver,
                                                                                        contactData,
                                                                                        false);
                if (stream != null)
                {
                    var options = new BitmapFactory.Options {
                        InPreferQualityOverSpeed = true,
                        InPreferredConfig        = Bitmap.Config.Argb8888,
                    };
                    var bmp = BitmapFactory.DecodeStream(stream, null, options);
                    Activity.RunOnUiThread(() => selfFace.SetImageBitmap(bmp));
                }
            });

            userBadge = (TapUserBadge)FragmentManager.FindFragmentById(Resource.Id.userBadge);
            CategoryBadge.StartDragValidate = () => userBadge.SelectedUser != null;
            userBadge.SelectedUserChanged  += HandleSelectedUserChanged;

            categoryPlaceholder = view.FindViewById <LinearLayout> (Resource.Id.categoryPlaceholder);
            TabTypes.GetTabTypes().ContinueWith(types => {
                var badges = types.Result
                             .Select(t => Tuple.Create(t, SvgUtils.GetBitmapFromSvgString(t.SvgImage,
                                                                                          40.ToPixels (),
                                                                                          40.ToPixels ())))
                             .ToArray();
                Activity.RunOnUiThread(() => AddTabTypeBadges(badges, inflater));
            });

            if (lastSelectedUser != null)
            {
                userBadge.RestoreSelectedUserInfo(lastSelectedUser);
            }

            return(view);
        }
Exemple #2
0
        void RegisterNewTab(SelectedUserInfo originator, SelectedUserInfo recipient, string tabTypeName, string locationDesc = null)
        {
            var selectedPerson = (originator ?? recipient).ToPerson();
            var tabType        = TabTypes.GetTabTypes()
                                 .ContinueWith(ts => ts.Result.FirstOrDefault(t => t.Name.Equals(tabTypeName, StringComparison.OrdinalIgnoreCase)));

            var dialog = new AskLocationDialog(locator);

            if (!string.IsNullOrEmpty(locationDesc))
            {
                dialog.FillInLocation(locationDesc);
            }

            Task.Factory.ContinueWhenAll(new Task[] { selectedPerson, tabType, dialog.LocationName }, _ => {
                if (dialog.LocationName.IsCanceled)
                {
                    return;
                }
                var dir      = originator == null ? TabDirection.Giving : TabDirection.Receiving;
                var location = locator.GetLocationAndStopActiveSearching();
                locationDesc = dialog.LocationName.Result;
                locator.RefreshNamedLocation(locationDesc);
                TabPlace.RegisterPlace(locationDesc,
                                       Tuple.Create(location.Latitude, location.Longitude));

                var tab = new TabObject {
                    Originator   = TabPerson.CurrentPerson,
                    Recipient    = selectedPerson.Result,
                    Type         = tabType.Result,
                    Direction    = dir,
                    LatLng       = Tuple.Create(location.Latitude, location.Longitude),
                    LocationDesc = locationDesc,
                    Time         = DateTime.Now
                };
                Action postSave = () => {
                    UpdateTabStatistics(selectedPerson.Result, originator ?? recipient, true);
                    Activity.RunOnUiThread(() => PostedNewTab(tab));
                };
                var po = tab.ToParse();
                try {
                    po.Save();
                } catch (Exception e) {
                    Log.Error("TabSaver", e.ToString());
                    Activity.RunOnUiThread(() => flashBarCtrl.ShowBarUntil(() => {
                        po.Save();
                        postSave();
                        return(true);
                    }, withMessageId: Resource.String.flashbar_tab_error));
                    return;
                }
                postSave();
            });

            if (locationDesc == null)
            {
                var lastLocation = locator.LastKnownLocation;
                if (lastLocation != null)
                {
                    dialog.FilterWithLocation(Tuple.Create(lastLocation.Latitude, lastLocation.Longitude));
                }
                dialog.Show(FragmentManager, "location-asker");
            }
        }