Exemplo n.º 1
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.PaintActivity);

            string thisJsonData = Intent.GetStringExtra("JSON") ?? "";

            LearningTask = JsonConvert.DeserializeObject <LearningTask>(thisJsonData, new JsonSerializerSettings {
                TypeNameHandling = TypeNameHandling.Auto
            });

            // Used if the task requires drawing on top of
            // a photo taken in another task
            PreviousImage = Intent.GetStringExtra("PREVIOUS_PHOTO");

            SupportActionBar.Title = LearningTask.Description;

            mPaint = new Paint {
                AntiAlias = true, Color = Color.Black
            };
            mPaint.SetStyle(Paint.Style.Stroke);
            mPaint.StrokeJoin  = (Paint.Join.Round);
            mPaint.StrokeCap   = (Paint.Cap.Round);
            mPaint.StrokeWidth = 20;

            mv        = FindViewById <PaintView>(Resource.Id.paintview);
            mv.MPaint = mPaint;
            mv.DrawingCacheEnabled = true;

            bgImage = FindViewById <ImageViewAsync>(Resource.Id.paintBackground);

            if (LearningTask.TaskType.IdName == "DRAW_PHOTO")
            {
                //used for accessing cache folder
                int activityId = Intent.GetIntExtra("ACTIVITY_ID", -1);

                if (string.IsNullOrWhiteSpace(PreviousImage))
                {
                    AndroidUtils.LoadActivityImageIntoView(bgImage, LearningTask.JsonData, activityId, 500);
                }
                else
                {
                    ImageService.Instance.LoadFile(PreviousImage)
                    .DownSample(500)
                    .Into(bgImage);
                }
            }
            else
            {
                bgImage.SetBackgroundColor(Color.White);
            }

            colorPickerView = FindViewById <ColorPickerView>(Resource.Id.color_picker_view);
            colorPickerView.setOnColorChangedListener(this);

            ImageButton saveBtn = FindViewById <ImageButton>(Resource.Id.saveBtn);

            saveBtn.Click += SaveBtn_Click;
        }
Exemplo n.º 2
0
        public void LoadIfPhotoMatch(View view)
        {
            if (learningTask.TaskType.IdName != "MATCH_PHOTO")
            {
                return;
            }

            ImageViewAsync targetImageView = view.FindViewById <ImageViewAsync>(Resource.Id.targetPhoto);
            string         imageUrl        = learningTask.JsonData;

            AndroidUtils.LoadActivityImageIntoView(targetImageView, imageUrl, activityId, 500);
        }
Exemplo n.º 3
0
        public override void OnBindViewHolder(RecyclerView.ViewHolder holder, int position)
        {
            TaskViewHolder vh;

            Type thisType = holder.GetType();

            OnBind = true;

            if (Curator)
            {
                if (position == 0)
                {
                    return;
                }
            }

            if (position == 0 || (Curator && position == 1))
            {
                // Activity description + entered names (if required)
                vh = holder as TaskViewHolderName;
                if (vh == null)
                {
                    return;
                }

                vh.Title.Text       = description;
                vh.Description.Text = context.Resources.GetString(Resource.String.TasksTitle);

                ((TaskViewHolderName)vh).NameSection.Visibility =
                    (reqName) ? ViewStates.Visible : ViewStates.Gone;
                ((TaskViewHolderName)vh).EnteredNames.Text = names;

                return;
            }

            if (position == Items.Count - 1)
            {
                // Finish button
                if (holder is ButtonViewHolder bvh)
                {
                    bvh.Button.Enabled = true;
                }

                return;
            }

            string taskType = Items[position].TaskType.IdName;

            if (thisType == typeof(TaskViewHolderInfo))
            {
                AdditionalInfoData taskInfo = JsonConvert.DeserializeObject <AdditionalInfoData>(Items[position].JsonData);
                vh = holder as TaskViewHolderInfo;
                Items[position].IsCompleted = true;

                if (!string.IsNullOrWhiteSpace(taskInfo.ImageUrl))
                {
                    Items[position].ImageUrl = taskInfo.ImageUrl;
                }

                TaskViewHolderInfo taskViewHolderInfo = (TaskViewHolderInfo)vh;
                if (taskViewHolderInfo != null)
                {
                    taskViewHolderInfo.Button.Visibility =
                        (string.IsNullOrWhiteSpace(taskInfo.ExternalUrl)) ? ViewStates.Gone : ViewStates.Visible;
                }
            }
            else if (thisType == typeof(TaskViewHolderRecordAudio))
            {
                vh = holder as TaskViewHolderRecordAudio;
                if (vh != null)
                {
                    ((TaskViewHolderRecordAudio)vh).StartTaskButton.Text =
                        context.Resources.GetString(Resource.String.StartBtn);

                    if (!string.IsNullOrWhiteSpace(Items[position].CompletionData.JsonData))
                    {
                        List <string> audioPaths =
                            JsonConvert.DeserializeObject <List <string> >(Items[position].CompletionData.JsonData);

                        ((TaskViewHolderRecordAudio)vh).ShowResults(audioPaths, context);
                        Items[position].IsCompleted = true;
                    }
                    else
                    {
                        Items[position].IsCompleted = false;
                        ((TaskViewHolderRecordAudio)vh).ClearResults();
                    }
                }
            }
            else if (thisType == typeof(TaskViewHolderRecordVideo))
            {
                vh = holder as TaskViewHolderRecordVideo;
                if (vh != null)
                {
                    ((TaskViewHolderRecordVideo)vh).StartTaskButton.Text =
                        context.Resources.GetString(Resource.String.RecBtn);

                    if (!string.IsNullOrWhiteSpace(Items[position].CompletionData.JsonData))
                    {
                        List <string> videoPaths =
                            JsonConvert.DeserializeObject <List <string> >(Items[position].CompletionData.JsonData);

                        ((TaskViewHolderRecordVideo)vh).ShowResults(videoPaths, context);
                        Items[position].IsCompleted = true;
                    }
                    else
                    {
                        Items[position].IsCompleted = false;
                        ((TaskViewHolderRecordVideo)vh).ClearResults();
                    }
                }
            }
            else if (thisType == typeof(TaskViewHolderResultList))
            {
                vh = holder as TaskViewHolderResultList;

                bool   btnEnabled = true;
                string btnText;

                if (taskType == "DRAW" || taskType == "DRAW_PHOTO")
                {
                    btnText = context.Resources.GetString(Resource.String.StartDrawBtn);

                    if (taskType == "DRAW_PHOTO")
                    {
                        btnEnabled = !int.TryParse(Items[position].JsonData, out var idResult) || GetTaskWithId(idResult).IsCompleted;

                        if (!btnEnabled)
                        {
                            btnText = context.Resources.GetString(Resource.String.TaskBtnNotReady);
                        }
                    }
                }
                else
                {
                    btnText = context.Resources.GetString(Resource.String.TakePhotoBtn);
                }

                if (vh != null)
                {
                    ((TaskViewHolderResultList)vh).StartTaskButton.Text    = btnText;
                    ((TaskViewHolderResultList)vh).StartTaskButton.Enabled = btnEnabled;

                    if (!string.IsNullOrWhiteSpace(Items[position].CompletionData.JsonData))
                    {
                        List <string> photoPaths =
                            JsonConvert.DeserializeObject <List <string> >(Items[position].CompletionData.JsonData);

                        ((TaskViewHolderResultList)vh).ShowResults(photoPaths, context);
                        Items[position].IsCompleted = true;
                    }
                    else
                    {
                        Items[position].IsCompleted = false;
                        ((TaskViewHolderResultList)vh).ClearResults();
                    }
                }
            }
            else if (thisType == typeof(TaskViewHolderBtn))
            {
                vh = holder as TaskViewHolderBtn;
                string btnText = context.Resources.GetString(Resource.String.TaskBtn);

                if (taskType == "LISTEN_AUDIO")
                {
                    btnText = context.Resources.GetString(Resource.String.ListenBtn);
                }

                TaskViewHolderBtn viewHolderBtn = (TaskViewHolderBtn)vh;
                if (viewHolderBtn != null)
                {
                    viewHolderBtn.Button.Text = btnText;
                }
            }
            else if (thisType == typeof(TaskViewHolderTextEntry))
            {
                vh = holder as TaskViewHolderTextEntry;
                if (vh != null)
                {
                    ((TaskViewHolderTextEntry)vh).TextField.Text = Items[position].CompletionData.JsonData;
                    Items[position].IsCompleted =
                        !string.IsNullOrWhiteSpace(((TaskViewHolderTextEntry)vh).TextField.Text);
                }
            }
            else
            {
                if (thisType == typeof(TaskViewHolderMultipleChoice))
                {
                    vh = holder as TaskViewHolderMultipleChoice;
                    RadioGroup radios = ((TaskViewHolderMultipleChoice)vh)?.RadioGroup;

                    string[] choices = JsonConvert.DeserializeObject <string[]>(Items[position].JsonData);
                    int.TryParse(Items[position].CompletionData.JsonData, out var answeredInd);

                    if (radios != null && radios.ChildCount == 0)
                    {
                        int index = 0;
                        foreach (string option in choices)
                        {
                            RadioButton rad = new RadioButton(context)
                            {
                                Text = option
                            };
                            rad.SetPadding(0, 0, 0, 5);
                            rad.TextSize = 16;
                            radios.AddView(rad);

                            if (Items[position].IsCompleted && answeredInd == index)
                            {
                                ((RadioButton)radios.GetChildAt(answeredInd)).Checked = true;
                            }
                            index++;
                        }
                    }

                    if (answeredInd == -1)
                    {
                        Items[position].IsCompleted = false;
                    }

                    if (radios != null)
                    {
                        radios.CheckedChange += (sender, e) =>
                        {
                            Items[position].IsCompleted = true;
                            int  radioButtonId = radios.CheckedRadioButtonId;
                            View radioButton   = radios.FindViewById(radioButtonId);
                            int  idx           = radios.IndexOfChild(radioButton);
                            Items[position].CompletionData.JsonData = idx.ToString();
                            NotifyItemChanged(Items.Count - 1);
                        };
                    }
                }
                else if (thisType == typeof(TaskViewHolderMap))
                {
                    vh = holder as TaskViewHolderMap;
                    TaskViewHolderMap mapHolder = ((TaskViewHolderMap)vh);

                    if (taskType == "MAP_MARK")
                    {
                        List <Map_Location> points = JsonConvert.DeserializeObject <List <Map_Location> >(Items[position].CompletionData.JsonData);

                        if (points != null && points.Count > 0)
                        {
                            if (mapHolder != null)
                            {
                                mapHolder.EnteredLocationsView.Visibility = ViewStates.Visible;
                                mapHolder.EnteredLocationsView.Text       = string.Format(
                                    context.Resources.GetString(Resource.String.ChosenLocations),
                                    points.Count,
                                    (points.Count > 1) ? "s" : "");
                            }

                            Items[position].IsCompleted = true;
                        }
                        else
                        {
                            if (mapHolder != null)
                            {
                                mapHolder.EnteredLocationsView.Visibility = ViewStates.Gone;
                            }

                            Items[position].IsCompleted = false;
                        }
                    }
                }
                else
                {
                    vh = holder as TaskViewHolder;
                }
            }

            // These apply to all task types:
            AndroidUtils.LoadTaskTypeIcon(Items[position].TaskType, ((TaskViewHolder)holder).TaskTypeIcon);

            if (!string.IsNullOrWhiteSpace(Items[position].ImageUrl))
            {
                AndroidUtils.LoadActivityImageIntoView(vh.TaskImage, Items[position].ImageUrl, activityId, 350);
            }
            else
            {
                if (vh != null)
                {
                    vh.TaskImage.Visibility = ViewStates.Gone;
                }
            }

            vh.Description.Text = Items[position].Description;
            vh.Title.Text       = Items[position].TaskType.DisplayName;

            bool hasChildren = Items[position].ChildTasks != null && Items[position].ChildTasks.Any();

            if (Items[position].TaskType.IdName == "ENTER_TEXT")
            {
                vh.LockedChildrenTease.Visibility = ViewStates.Gone;
            }
            else if (hasChildren && !Items[position].IsCompleted)
            {
                vh.LockedChildrenTease.Visibility = ViewStates.Visible;
                int childCount = Items[position].ChildTasks.Count();
                vh.LockedChildrenTease.Text = string.Format(
                    context.GetString(Resource.String.taskLockedParent),
                    childCount,
                    (childCount > 1) ? "s" : "");
            }
            else if (hasChildren && Items[position].IsCompleted)
            {
                vh.LockedChildrenTease.Visibility = ViewStates.Visible;
                vh.LockedChildrenTease.Text       = context.GetString(Resource.String.taskUnlockedParent);
            }
            else
            {
                vh.LockedChildrenTease.Visibility = ViewStates.Gone;
            }

            OnBind = false;
        }