public static ISpannable ToProjectTaskClient(bool hasProject, string project, string projectColor, string task, string client)
        {
            if (!hasProject)
            {
                return(new SpannableString(string.Empty));
            }

            var spannableString = new SpannableStringBuilder();

            spannableString.Append(
                project,
                new ForegroundColorSpan(Color.ParseColor(projectColor)),
                SpanTypes.ExclusiveInclusive);

            if (!string.IsNullOrEmpty(task))
            {
                spannableString.Append($": {task}");
            }

            if (!string.IsNullOrEmpty(client))
            {
                spannableString.Append(
                    $" {client}",
                    new ForegroundColorSpan(Color.ParseColor(ClientNameColor)),
                    SpanTypes.ExclusiveExclusive);
            }

            return(spannableString);
        }
Example #2
0
        private static void AppendProjectText(this SpannableStringBuilder spannable, ProjectSpan projectSpan)
        {
            /* HACK: This unbreakable space is needed because of a bug in
             * the way android handles ReplacementSpans. It makes sure that
             * all token boundaries can't be changed by the soft input once
             * they are set. */
            var start = spannable.Length();

            spannable.Append(unbreakableSpace);
            spannable.Append(projectSpan.ProjectName);
            if (!string.IsNullOrEmpty(projectSpan.TaskName))
            {
                spannable.Append($": {projectSpan.TaskName}");
            }
            spannable.Append(unbreakableSpace);
            var end = spannable.Length();

            var projectTokenSpan = new ProjectTokenSpan(
                projectSpan.ProjectId,
                projectSpan.ProjectName,
                projectSpan.ProjectColor,
                projectSpan.TaskId,
                projectSpan.TaskName
                );


            spannable.SetSpan(projectTokenSpan, start, end, SpanTypes.ExclusiveExclusive);
            spannable.SetSpan(new RelativeSizeSpan(spanSizeProportion), start, end, SpanTypes.ExclusiveExclusive);
        }
        public override void OnBindViewHolder(RecyclerView.ViewHolder holder, int position)
        {
            MovieSummaryViewHolder vh = holder as MovieSummaryViewHolder;
            //var data = string.Join('\n', content);
            SpannableStringBuilder str = new SpannableStringBuilder();

            //int prev = 0;
            foreach (var item in content)
            {
                if (item.Key.EndsWith("Rating"))
                {
                    continue;
                }
                var ss = new SpannableString(item.Key);
                ss.SetSpan(new StyleSpan(TypefaceStyle.Bold), 0, item.Key.Length, SpanTypes.ExclusiveExclusive);
                str.Append(ss);
                str.Append(new SpannableString("\n"));
                str.Append(item.Value);
                str.Append(new SpannableString("\n\n"));
            }
            if (_showRatingBar)
            {
                vh.RatingBar.Visibility      = ViewStates.Visible;
                vh.TmdbRating.Text           = content.TryGetValue("TmdbRating", out string rating) ? rating : "--";
                vh.ImdbRating.Text           = content.TryGetValue("ImdbRating", out rating) ? rating : "--";
                vh.RottenTomatoesRating.Text = content.TryGetValue("RottenTomatoesRating", out rating) ? rating : "--";
                //imdbImage = vh.ImdbImage;
            }
            vh.MovieSummary.TextFormatted = str;
        }
Example #4
0
        public NotificationResult Notify(Activity activity, INotificationOptions options)
        {
            var view = activity.FindViewById(Android.Resource.Id.Content);

            SpannableStringBuilder builder = new SpannableStringBuilder();

            builder.Append(options.Title);

            if (!string.IsNullOrEmpty(options.Title) && !string.IsNullOrEmpty(options.Description))
            {
                builder.Append("\n"); // Max of 2 lines for snackbar
            }
            builder.Append(options.Description);

            var id = _count.ToString();

            _count++;

            var snackbar = Snackbar.Make(view, builder, Snackbar.LengthLong);

            if (options.IsClickable)
            {
                snackbar.SetAction(options.AndroidOptions.ViewText, new EmptyOnClickListener(id, (toastId, result) => { ToastClosed(toastId, result); }, new NotificationResult()
                {
                    Action = NotificationAction.Clicked
                }));
            }
            else
            {
                snackbar.SetAction(options.AndroidOptions.DismissText, new EmptyOnClickListener(id, (toastId, result) => { ToastClosed(toastId, result); }, new NotificationResult()
                {
                    Action = NotificationAction.Dismissed
                }));
            }

            // Monitor callbacks
            snackbar.SetCallback(new ToastCallback(id, (toastId, result) => { ToastClosed(toastId, result); }));

            // Setup reset events
            var resetEvent = new ManualResetEvent(false);

            _resetEvents.Add(id, resetEvent);
            _snackBars.Add(snackbar);
            snackbar.Show();

            resetEvent.WaitOne(); // Wait for a result

            var notificationResult = _eventResult[id];

            _eventResult.Remove(id);
            _resetEvents.Remove(id);

            if (_snackBars.Contains(snackbar))
            {
                _snackBars.Remove(snackbar);
            }

            return(notificationResult);
        }
Example #5
0
 void SetAuditoriums(RemoteViews rv, Lesson lesson, bool enabled = true)
 {
     using var auditoriums = new SpannableStringBuilder();
     //viewHolder.LessonAuditoriums.Enabled = enabled;
     if (lesson.Auditoriums == null)
     {
         rv.SetTextViewText(Resource.Id.text_schedule_auditoriums, string.Empty);
         return;
     }
     if (enabled)
     {
         for (int i = 0; i < lesson.Auditoriums.Length - 1; i++)
         {
             var audTitle = Html.FromHtml(lesson.Auditoriums[i].Name.ToLower(), FromHtmlOptions.ModeLegacy);
             if (!string.IsNullOrEmpty(lesson.Auditoriums[i].Color))
             {
                 string colorString = lesson.Auditoriums[i].Color;
                 if (colorString.Length == 4)
                 {
                     colorString = "#" +
                                   colorString[1] + colorString[1] +
                                   colorString[2] + colorString[2] +
                                   colorString[3] + colorString[3];
                 }
                 var color = Color.ParseColor(colorString);
                 if (this.nightMode)
                 {
                     float hue = color.GetHue();
                     if (hue > 214f && hue < 286f)
                     {
                         if (hue >= 250f)
                         {
                             hue = 214f;
                         }
                         else
                         {
                             hue = 286f;
                         }
                     }
                     color = Color.HSVToColor(
                         new float[] { hue, color.GetSaturation(), color.GetBrightness() * 3 });
                 }
                 auditoriums.Append(audTitle + ", ",
                                    new ForegroundColorSpan(color),
                                    SpanTypes.ExclusiveExclusive);
             }
             else
             {
                 auditoriums.Append(audTitle + ", ");
             }
         }
         if (lesson.Auditoriums.Length != 0)
         {
             var audTitle = Html.FromHtml(lesson.Auditoriums[^ 1].Name.ToLower(), FromHtmlOptions.ModeLegacy);
Example #6
0
 private static void appendProjectTextAndSpans(Context context, string projectName, string projectColor, bool projectIsPlaceholder, bool displayPlaceholders, SpannableStringBuilder spannableString)
 {
     if (displayPlaceholders && projectIsPlaceholder)
     {
         spannableString.Append(projectName, new VerticallyCenteredImageSpan(context, Resource.Drawable.text_placeholder), SpanTypes.ExclusiveExclusive);
         spannableString.Append(placeholderSeparator);
     }
     else
     {
         spannableString.Append(projectName, new ForegroundColorSpan(Color.ParseColor(projectColor)), SpanTypes.ExclusiveInclusive);
     }
 }
Example #7
0
        void SetAuditoriums(TextView textView, Lesson lesson)
        {
            using var auditoriums = new SpannableStringBuilder();
            if (lesson.Auditoriums == null)
            {
                textView.SetText("", TextView.BufferType.Normal);
                return;
            }
            var nightMode = (textView.Context.Resources.Configuration.UiMode & UiMode.NightMask) == UiMode.NightYes;

            for (int i = 0; i < lesson.Auditoriums.Length - 1; i++)
            {
                var audTitle = Html.FromHtml(lesson.Auditoriums[i].Name.ToLower(), FromHtmlOptions.ModeLegacy);
                if (!string.IsNullOrEmpty(lesson.Auditoriums[i].Color))
                {
                    var colorString = lesson.Auditoriums[i].Color;
                    if (colorString.Length == 4)
                    {
                        colorString = "#" +
                                      colorString[1] + colorString[1] +
                                      colorString[2] + colorString[2] +
                                      colorString[3] + colorString[3];
                    }
                    var color = Color.ParseColor(colorString);
                    if (nightMode)
                    {
                        var hue = color.GetHue();
                        if (hue > 214f && hue < 286f)
                        {
                            if (hue >= 250f)
                            {
                                hue = 214f;
                            }
                            else
                            {
                                hue = 286f;
                            }
                        }
                        color = Color.HSVToColor(
                            new float[] { hue, color.GetSaturation(), color.GetBrightness() * 3 });
                    }
                    auditoriums.Append(audTitle + ", ",
                                       new ForegroundColorSpan(color),
                                       SpanTypes.ExclusiveExclusive);
                }
                else
                {
                    auditoriums.Append(audTitle + ", ");
                }
            }
            if (lesson.Auditoriums.Length != 0)
            {
                var audTitle = Html.FromHtml(lesson.Auditoriums[^ 1].Name.ToLower(), FromHtmlOptions.ModeLegacy);
Example #8
0
        private void UpdateTabIcons()
        {
            var tabLayout = this.tabLayout;

            if (tabLayout.TabCount != this.Element.Children.Count)
            {
                return;
            }

            for (int i = 0; i < this.Element.Children.Count; ++i)
            {
                var page = this.Element.Children[i];
                if (string.IsNullOrEmpty(page.Icon))
                {
                    var glyph = (string)page.GetValue(AttachedFontIcon.GlyphProperty);
                    if (!string.IsNullOrWhiteSpace(glyph))
                    {
                        SpannableStringBuilder sb = new SpannableStringBuilder();
                        sb.Append(glyph);

                        var font = (string)page.GetValue(AttachedFontIcon.FontFamilyProperty);
                        if (!string.IsNullOrWhiteSpace(font))
                        {
                            var span = new CustomTypefaceSpan(font);
                            sb.SetSpan(span, 0, glyph.Length, SpanTypes.ExclusiveExclusive);
                        }

                        //var size = (int)(double)page.GetValue(AttachedFontIcon.FontSizeProperty);
                        sb.SetSpan(new AbsoluteSizeSpan(40), 0, glyph.Length, SpanTypes.ExclusiveExclusive);

                        sb.Append("\n");
                        sb.Append(page.Title);

                        //sb.SetSpan(new ForegroundColorSpan(Android.Graphics.Color.Red), 3, 4, SpanTypes.ExclusiveExclusive);

                        //Must set app:tabTextAppearance textAllCaps to false.
                        // See : tabs.xml,
                        //if not do this, span will not work not work
                        tabLayout.GetTabAt(i).SetText(sb);

                        ////without specify color
                        //var v = new TextView(this.Context) {
                        //    TextAlignment = Android.Views.TextAlignment.Center
                        //};
                        //v.SetText(sb, TextView.BufferType.Spannable);

                        //tabLayout.GetTabAt(i).SetCustomView(v);
                    }
                }
            }
        }
        public static SpannableStringBuilder BuildComments(List <FeedEngagementModel> commentList)
        {
            Mvx.RegisterType <IEncodingService, EncodingService>();
            var encodingService       = Mvx.Resolve <IEncodingService>();
            SpannableStringBuilder sb = new SpannableStringBuilder();

            for (int i = 0; i < commentList.Count; i++)
            {
                string commentText          = string.Empty;
                FeedEngagementModel comment = commentList[i];

                if (!string.IsNullOrEmpty(comment.UserName))
                {
                    try
                    {
                        var decodingNameUser = encodingService.DecodeFromNonLossyAscii(comment.UserName);
                        comment.UserName = decodingNameUser;
                    }
                    catch (FormatException)
                    {
                    }
                }

                if (!string.IsNullOrEmpty(comment.Notes))
                {
                    try
                    {
                        var decodingNameUser = encodingService.DecodeFromNonLossyAscii(comment.UserName);
                        comment.UserName = decodingNameUser;
                    }
                    catch (FormatException)
                    {
                    }
                }

                var start = sb.Length();
                var end   = start + comment.UserName.Length;
                sb.Append(comment.UserName);
                sb.SetSpan(new StyleSpan(Android.Graphics.TypefaceStyle.Bold), start, end, SpanTypes.ExclusiveExclusive);
                sb.SetSpan(new ForegroundColorSpan(Color.Black), start, end, SpanTypes.ExclusiveExclusive);
                commentText += " " + comment.Notes;
                sb.Append(commentText);
                if (i + 1 < commentList.Count)
                {
                    sb.Append("\n");
                }
            }
            return(sb);
        }
        private static void AppendTagText(this SpannableStringBuilder spannable, TagSpan tagSpan)
        {
            /* HACK: This unbreakable space is needed because of a bug in
             * the way android handles ReplacementSpans. It makes sure that
             * all token boundaries can't be changed by the soft input once
             * they are set. */
            var start = spannable.Length();

            spannable.Append(tagSpan.TagName);
            spannable.Append(unbreakableSpace);
            var end = spannable.Length();

            spannable.SetSpan(new RelativeSizeSpan(spanSizeProportion), start, end, SpanTypes.ExclusiveExclusive);
            spannable.SetSpan(new TagsTokenSpan(tagSpan.TagId, tagSpan.TagName), start, end, SpanTypes.ExclusiveExclusive);
        }
        private ISpannable GetFormattedResult(string result)
        {
            SpannableStringBuilder sb = new SpannableStringBuilder();

            for (int i = 0, n = result.Length; i < n; i++)
            {
                sb.Append(" ");
                sb.Append(result[i]);
                sb.Append(" ");
                sb.SetSpan(new BackgroundColorSpan(Color.Black), i * 4, i * 4 + 3, SpanTypes.ExclusiveExclusive);
                sb.SetSpan(new ForegroundColorSpan(Color.White), i * 4, i * 4 + 3, SpanTypes.ExclusiveExclusive);
                sb.Append(" ");
            }
            return(sb);
        }
            public void Run()
            {
                try
                {
                    int textLengthNew = Option.TextLength;

                    if (Option.TextLengthType == TypeLine)
                    {
                        if (TextView.Layout.LineCount <= Option.TextLength)
                        {
                            TextView.SetText(Text, TextView.BufferType.Spannable);
                            return;
                        }

                        ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams)TextView.LayoutParameters;

                        string subString = Text.ToString().Substring(TextView.Layout.GetLineStart(0), TextView.Layout.GetLineEnd(Option.TextLength - 1));
                        textLengthNew = subString.Length - (Option.MoreLabel.Length + 4 + lp.RightMargin / 6);
                    }

                    SpannableStringBuilder spendableStringBuilder = new SpannableStringBuilder(Text.SubSequence(0, textLengthNew));
                    spendableStringBuilder.Append(" ...");
                    spendableStringBuilder.Append(Option.MoreLabel);

                    SpannableString ss             = SpannableString.ValueOf(spendableStringBuilder);
                    ClickableSpan   rclickableSpan = new StRclickableSpan(Option, TextView, Text, StTools.StTypeText.ReadMore);

                    ss.SetSpan(rclickableSpan, ss.Length() - Option.MoreLabel.Length, ss.Length(), SpanTypes.ExclusiveExclusive);

                    switch (Build.VERSION.SdkInt)
                    {
                    case >= BuildVersionCodes.JellyBean when Option.ExpandAnimation:
                    {
                        LayoutTransition layoutTransition = new LayoutTransition();
                        layoutTransition.EnableTransitionType(LayoutTransitionType.Changing);
                        ((ViewGroup)TextView?.Parent).LayoutTransition = layoutTransition;
                        break;
                    }
                    }
                    //TextView.SetTextFuture(PrecomputedTextCompat.GetTextFuture(ss, TextViewCompat.GetTextMetricsParams(TextView), null));
                    TextView.SetText(ss, TextView.BufferType.Spannable);
                    TextView.MovementMethod = LinkMovementMethod.Instance;
                }
                catch (Exception e)
                {
                    Methods.DisplayReportResultTrack(e);
                }
            }
Example #13
0
        private void SetStyle()
        {
            var styledLabel = (ExtendedLabel)this.Element;

            if (styledLabel.Children != null && styledLabel.Children.Count > 0)
            {
                SpannableStringBuilder builder = new SpannableStringBuilder();
                styledLabel.Children.ToList().ForEach(child =>
                {
                    var spannableText = new SpannableString(child.Text);
                    spannableText.SetSpan(new ForegroundColorSpan(child.CustomFont.Color.ToAndroid()), 0, child.Text.Length, SpanTypes.Composing);
                    spannableText.SetSpan(new CustomTypefaceSpan(child.CustomFont), 0, child.Text.Length, SpanTypes.Composing);
                    if (child.Command != null)
                    {
                        var clickableSpan    = new CustomClickableSpan();
                        clickableSpan.Click += (Android.Views.View obj) =>
                        {
                            child.Command?.Execute(child.CommandParameter);
                        };
                        spannableText.SetSpan(clickableSpan, 0, child.Text.Length, SpanTypes.Composing);
                    }
                    builder.Append(spannableText);
                });

                Control.TextFormatted  = builder;
                Control.MovementMethod = new LinkMovementMethod();
                return;
            }

            if (styledLabel.Text != null && styledLabel.CustomFont != null)
            {
                styledLabel.CustomFont.ApplyTo(Control);
            }
        }
Example #14
0
 public ICharSequence FilterFormatted(ICharSequence source, int start, int end, ISpanned dest, int dstart, int dend)
 {
     if (source is SpannableStringBuilder)
     {
         var sourceAsSpannableBuilder = (SpannableStringBuilder)source;
         for (var i = end - 1; i >= start; i--)
         {
             if (!isCharacterOk(source.CharAt(i)))
             {
                 sourceAsSpannableBuilder.Delete(i, i + 1);
             }
         }
         return(sourceAsSpannableBuilder);
     }
     else
     {
         var filteredStringBuilder = new SpannableStringBuilder();
         for (int i = start; i < end; i++)
         {
             var currentChar = source.CharAt(i);
             if (isCharacterOk(currentChar))
             {
                 filteredStringBuilder.Append(currentChar);
             }
         }
         return(filteredStringBuilder);
     }
 }
Example #15
0
        protected virtual ISpanned GetSnackbarText(ToastConfig cfg)
        {
            var sb = new SpannableStringBuilder();

            string message = cfg.Message;
            var    hasIcon = (cfg.Icon != null);

            if (hasIcon)
            {
                message = "\u2002\u2002" + message; // add 2 spaces, 1 for the image the next for spacing between text and image
            }
            sb.Append(message);

            if (hasIcon)
            {
                var drawable = cfg.Icon.ToNative();
                drawable.SetBounds(0, 0, drawable.IntrinsicWidth, drawable.IntrinsicHeight);

                sb.SetSpan(new ImageSpan(drawable, SpanAlign.Bottom), 0, 1, SpanTypes.ExclusiveExclusive);
            }

            if (cfg.MessageTextColor != null)
            {
                sb.SetSpan(
                    new ForegroundColorSpan(cfg.MessageTextColor.Value.ToNative()),
                    0,
                    sb.Length(),
                    SpanTypes.ExclusiveExclusive
                    );
            }
            return(sb);
        }
Example #16
0
        public static ISpannable ToProjectTaskClient(Context context,
                                                     bool hasProject,
                                                     string project,
                                                     string projectColor,
                                                     string task,
                                                     string client,
                                                     bool projectIsPlaceholder,
                                                     bool taskIsPlaceholder,
                                                     bool displayPlaceholders = false)
        {
            if (!hasProject)
            {
                return(new SpannableString(string.Empty));
            }

            var spannableString = new SpannableStringBuilder();

            appendProjectTextAndSpans(context, project, projectColor, projectIsPlaceholder, displayPlaceholders, spannableString);
            appendTaskTextAndSpans(context, task, projectIsPlaceholder, taskIsPlaceholder, displayPlaceholders, spannableString);

            if (!string.IsNullOrEmpty(client))
            {
                spannableString.Append($" {client}", new ForegroundColorSpan(Color.ParseColor(ClientNameColor)), SpanTypes.ExclusiveExclusive);
            }

            return(spannableString);
        }
        protected override void SetValue(IEnumerable <string> value)
        {
            var tags = value?.ToList();

            if (tags == null || !tags.Any())
            {
                return;
            }

            var builder = new SpannableStringBuilder();

            for (var i = 0; i < tags.Count; i++)
            {
                var tag = tags[i];

                var start = builder.Length();
                builder.Append(tag);
                var end = builder.Length();

                builder.SetSpan(new RelativeSizeSpan(spanSizeProportion), start, end, SpanTypes.ExclusiveExclusive);
                builder.SetSpan(new TagsTokenSpan(i), start, end, SpanTypes.ExclusiveExclusive);
            }

            Target.TextFormatted = builder;
            Target.Invalidate();
        }
Example #18
0
        public static void Appand(SpannableStringBuilder ssb, string text, Java.Lang.Object what, SpanTypes flags)
        {
            var start = ssb.Length();

            ssb.Append(text);
            ssb.SetSpan(what, start, ssb.Length(), flags);
        }
Example #19
0
        public override View GetView(int position, View convertView, ViewGroup parent)
        {
            View row = convertView;

            if (row == null)
            {
                LayoutInflater inflater = ((Activity)Context).LayoutInflater;
                row = inflater.Inflate(viewResourceId, parent, false);
            }

            row.FindViewById <TextView>(Resource.Id.BroName).Text = bros.First(b => b.Id == items[position].Bro).Name;

            var amountsBuilder = new SpannableStringBuilder();
            var amount         = items[position].Amount.WithAccuracy(baseCurrency.Accuracy);
            var amountString   = new SpannableString(String.Format(culture, "{0:0.#} {1}", amount, baseCurrency.Name));

            ForegroundColorSpan foregroundColor;

            foregroundColor = amount > 0 ? new ForegroundColorSpan(Color.Green) : (amount < 0 ? new ForegroundColorSpan(Color.Red) : new ForegroundColorSpan(Color.Gray));
            amountString.SetSpan(foregroundColor, 0, amountString.Length(), SpanTypes.Composing);
            amountsBuilder.Append(amountString);

            row.FindViewById <TextView>(Resource.Id.BroAmounts).SetText(amountsBuilder, TextView.BufferType.Spannable);
            return(row);
        }
Example #20
0
        /// <summary>
        /// Handles IMG tags
        /// </summary>
        /// <returns>The image.</returns>
        /// <param name="text">Text.</param>
        /// <param name="attributes">Attributes.</param>
        /// <param name="img">Image.</param>
        static void startImg(SpannableStringBuilder text, IAttributes attributes, Html.IImageGetter img)
        {
            var      src = attributes.GetValue("src");
            Drawable d   = null;

            if (img != null)
            {
                d = img.GetDrawable(src);
            }

            if (d == null)
            {
                throw new NotImplementedException("Missing Inline image implementation");
                //				d = Resources.System.GetDrawable ();
                //					getDrawable(com.android.internal.R.drawable.unknown_image);

                //				d.SetBounds (0, 0, d.IntrinsicWidth, d.IntrinsicHeight);
            }

            int len = text.Length();

            text.Append("\uFFFC");

            text.SetSpan(new ImageSpan(d, src), len, text.Length(),
                         SpanTypes.ExclusiveExclusive);
        }
Example #21
0
 private static void appendTaskTextAndSpans(Context context, string taskName, bool projectIsPlaceholder, bool taskIsPlaceholder, bool displayPlaceholders, SpannableStringBuilder spannableString)
 {
     if (string.IsNullOrEmpty(taskName))
     {
         return;
     }
     if (displayPlaceholders && taskIsPlaceholder)
     {
         spannableString.Append(placeholderSeparator);
         spannableString.Append(taskName, new VerticallyCenteredImageSpan(context, Resource.Drawable.text_placeholder), SpanTypes.ExclusiveExclusive);
     }
     else
     {
         var projectTaskSeparator = projectIsPlaceholder ? placeholderSeparator : taskSeparator;
         spannableString.Append($"{projectTaskSeparator}{taskName}");
     }
 }
Example #22
0
        private void HeaderLabel()
        {
            //simpleInterestCalculatorLabel
            TextView simpleInterestCalculatorLabel = new TextView(con);

            simpleInterestCalculatorLabel.Text     = "Simple Interest Calculator";
            simpleInterestCalculatorLabel.Gravity  = GravityFlags.Center;
            simpleInterestCalculatorLabel.TextSize = 24;
            mainLayout.AddView(simpleInterestCalculatorLabel);
            TextView sILabelSpacing = new TextView(con);

            mainLayout.AddView(sILabelSpacing);

            //findingSILabel
            TextView findingSILabel = new TextView(con);

            findingSILabel.Text     = "The formula for finding simple interest is:";
            findingSILabel.TextSize = 16;

            //mainLayout.AddView(findingSILabel);
            mainLayout.FocusableInTouchMode = true;
            SpannableStringBuilder formulaBuilder = new SpannableStringBuilder();

            //formulaLabel
            TextView        formulaLabel      = new TextView(con);
            String          interest          = "";
            SpannableString interestSpannable = new SpannableString(interest);

            interestSpannable.SetSpan(new ForegroundColorSpan(Color.ParseColor("#66BB6A")), 0, interest.Length, 0);
            formulaBuilder.Append(interestSpannable);
            formulaBuilder.Append("  Principal * Rate * Time");
            formulaLabel.SetText(formulaBuilder, TextView.BufferType.Spannable);
            formulaLabel.TextSize = 16;

            //formulaLayout
            LinearLayout formulaLayout = new LinearLayout(con);

            formulaLayout.Orientation = Android.Widget.Orientation.Horizontal;
            formulaLayout.AddView(findingSILabel);
            formulaLayout.AddView(formulaLabel);
            mainLayout.AddView(formulaLayout);
            TextView formulaLabelSpacing = new TextView(con);

            mainLayout.AddView(formulaLabelSpacing);
        }
        private static void AppendNormalText(this SpannableStringBuilder mutableString, TextSpan textSpan)
        {
            var start = mutableString.Length();

            mutableString.Append(textSpan.Text);
            var end = mutableString.Length();

            mutableString.SetSpan(new RelativeSizeSpan(1), start, end, SpanTypes.ExclusiveExclusive);
        }
        private static void AppendTagText(this SpannableStringBuilder spannable, TagSpan tagSpan)
        {
            var start = spannable.Length();

            spannable.Append(tagSpan.TagName);
            var end = spannable.Length();

            spannable.SetSpan(new RelativeSizeSpan(spanSizeProportion), start, end, SpanTypes.ExclusiveExclusive);
            spannable.SetSpan(new TagsTokenSpan(tagSpan.TagId, tagSpan.TagName), start, end, SpanTypes.ExclusiveExclusive);
        }
Example #25
0
        public override void OnViewCreated(View view, Bundle savedInstanceState)
        {
            if (_didTwoFactorAuthentication)
            {
                ((IFragmentContainer)Activity).PopFragment();
            }

            ((IActionBarContainer)Activity).SetTitle(Resource.String.title_addaccount);
            ((IActionBarContainer)Activity).Hide();

            _userNameEditText      = view.FindViewById <TextInputEditText>(Resource.Id.fragment_login_username_input);
            _passwordEditText      = view.FindViewById <TextInputEditText>(Resource.Id.fragment_login_password_input);
            _userNameInputLayout   = view.FindViewById <TextInputLayout>(Resource.Id.fragment_login_username_layout);
            _passwordInputLayout   = view.FindViewById <TextInputLayout>(Resource.Id.fragment_login_password_layout);
            _loginButton           = view.FindViewById <MaterialButton>(Resource.Id.fragment_login_login);
            _privacyPolicyTextView = view.FindViewById <MaterialTextView>(Resource.Id.fragment_login_terms);

            _loginButton.Click += LoginButton_Click;

            // Show a "Privacy Policy" link
            // create spanned string
            var termsText = new SpannableStringBuilder();

            // append text before link
            termsText.Append(GetString(Resource.String.msg_terms0));
            // append link
            var spanStart = termsText.Length();

            termsText.Append(GetString(Resource.String.msg_terms1));
            var spanEnd = termsText.Length();

            // append text after link
            termsText.Append(GetString(Resource.String.msg_terms2));
            // add link span
            termsText.SetSpan(
                new TermsSpan(Context),
                spanStart,
                spanEnd,
                SpanTypes.InclusiveExclusive);

            _privacyPolicyTextView.SetText(termsText, TextView.BufferType.Spannable);
            _privacyPolicyTextView.MovementMethod = LinkMovementMethod.Instance;
        }
Example #26
0
        public static ISpannable GetSpannableText(this TextFieldInfo self)
        {
            var builder = new SpannableStringBuilder();

            builder.Append(self.Text);
            builder.AppendProjectToken(self);
            builder.AppendTagTokens(self);

            return(builder);
        }
Example #27
0
        public TimeEntryViewData(TimeEntryViewModel timeEntryViewModel)
        {
            TimeEntryViewModel = timeEntryViewModel;

            var spannableString = new SpannableStringBuilder();

            if (TimeEntryViewModel.HasProject)
            {
                spannableString.Append(TimeEntryViewModel.ProjectName, new ForegroundColorSpan(Color.ParseColor(TimeEntryViewModel.ProjectColor)), SpanTypes.ExclusiveInclusive);

                if (!string.IsNullOrEmpty(TimeEntryViewModel.TaskName))
                {
                    spannableString.Append($": {TimeEntryViewModel.TaskName}");
                }

                if (!string.IsNullOrEmpty(TimeEntryViewModel.ClientName))
                {
                    spannableString.Append($" {TimeEntryViewModel.ClientName}", new ForegroundColorSpan(Color.ParseColor(ClientNameColor)), SpanTypes.ExclusiveExclusive);
                }

                ProjectTaskClientText       = spannableString;
                ProjectTaskClientVisibility = ViewStates.Visible;
            }
            else
            {
                ProjectTaskClientText       = new SpannableString(string.Empty);
                ProjectTaskClientVisibility = ViewStates.Gone;
            }

            DurationText = TimeEntryViewModel.Duration.HasValue
                ? DurationAndFormatToString.Convert(TimeEntryViewModel.Duration.Value, TimeEntryViewModel.DurationFormat)
                : "";

            DescriptionVisibility         = TimeEntryViewModel.HasDescription.ToVisibility();
            AddDescriptionLabelVisibility = (!TimeEntryViewModel.HasDescription).ToVisibility();
            ContinueImageVisibility       = TimeEntryViewModel.CanContinue.ToVisibility();
            ErrorImageViewVisibility      = (!TimeEntryViewModel.CanContinue).ToVisibility();
            ErrorNeedsSyncVisibility      = TimeEntryViewModel.NeedsSync.ToVisibility();
            ContinueButtonVisibility      = TimeEntryViewModel.CanContinue.ToVisibility();
            BillableIconVisibility        = TimeEntryViewModel.IsBillable.ToVisibility();
            HasTagsIconVisibility         = TimeEntryViewModel.HasTags.ToVisibility();
        }
Example #28
0
        /// <summary>
        /// Handles the P tag.
        /// </summary>
        /// <returns>void</returns>
        /// <param name="text">Text within the P Tag</param>
        static void handleP(SpannableStringBuilder text)
        {
            int len = text.Length();

            if (len >= 1 && text.CharAt(len - 1) == '\n')
            {
                if (len >= 2 && text.CharAt(len - 2) == '\n')
                {
                    return;
                }

                text.Append("\n");
                return;
            }

            if (len != 0)
            {
                text.Append("\n\n");
            }
        }
        private void appendInlineButtons(SpannableStringBuilder text, string target)
        {
            CopySpan copySpan = new CopySpan(this);

            copySpan.link = target;
            text.Append(" ");
            Drawable copyImage = ContextCompat.GetDrawable(mContext, Resource.Drawable.ic_menu_copy_holo_light);

            copyImage.SetBounds(0, 0, (int)(mContent.LineHeight * 1.2), (int)(mContent.LineHeight * 1.2));
            text.SetSpan(new ImageSpan(copyImage), text.Length() - 2, text.Length() - 1, 0);
            text.SetSpan(copySpan, text.Length() - 2, text.Length() - 1, SpanTypes.User);
        }
Example #30
0
        private SpannableStringBuilder FormatSnackbarText(string text)
        {
            SpannableStringBuilder ssb = new SpannableStringBuilder();

            ssb.Append(text);
            ssb.SetSpan(
                new ForegroundColorSpan(Color.White),
                0,
                text.Length,
                SpanTypes.ExclusiveExclusive);
            return(ssb);
        }
        private void UpdateTabIcons() {
            var tabLayout = this.tabLayout;
            if (tabLayout.TabCount != this.Element.Children.Count)
                return;

            for (int i = 0; i < this.Element.Children.Count; ++i) {
                var page = this.Element.Children[i];
                if (string.IsNullOrEmpty(page.Icon)) {
                    var glyph = (string)page.GetValue(AttachedFontIcon.GlyphProperty);
                    if (!string.IsNullOrWhiteSpace(glyph)) {

                        SpannableStringBuilder sb = new SpannableStringBuilder();
                        sb.Append(glyph);

                        var font = (string)page.GetValue(AttachedFontIcon.FontFamilyProperty);
                        if (!string.IsNullOrWhiteSpace(font)) {
                            var span = new CustomTypefaceSpan(font);
                            sb.SetSpan(span, 0, glyph.Length, SpanTypes.ExclusiveExclusive);
                        }

                        //var size = (int)(double)page.GetValue(AttachedFontIcon.FontSizeProperty);
                        sb.SetSpan(new AbsoluteSizeSpan(40), 0, glyph.Length, SpanTypes.ExclusiveExclusive);

                        sb.Append("\n");
                        sb.Append(page.Title);

                        //sb.SetSpan(new ForegroundColorSpan(Android.Graphics.Color.Red), 3, 4, SpanTypes.ExclusiveExclusive);

                        //Must set app:tabTextAppearance textAllCaps to false.
                        // See : tabs.xml,
                        //if not do this, span will not work not work
                        tabLayout.GetTabAt(i).SetText(sb);

                        ////without specify color
                        //var v = new TextView(this.Context) {
                        //    TextAlignment = Android.Views.TextAlignment.Center
                        //};
                        //v.SetText(sb, TextView.BufferType.Spannable);

                        //tabLayout.GetTabAt(i).SetCustomView(v);
                    }
                }
            }
        }
		private void AppendColored (SpannableStringBuilder builder, string text, int colorResId)
		{
			builder.Append (text);
			builder.SetSpan (new ForegroundColorSpan (Resources.GetColor (colorResId)),
				builder.Length () - text.Length, builder.Length (), 0);
		}
		public override void OnMessageReceived (IMessageEvent messageEvent)
		{
			string path = messageEvent.Path;
			if (path.Equals (Constants.QUIZ_EXITED_PATH)) {
				((NotificationManager)GetSystemService (NotificationService)).CancelAll ();
			}
			if (path.Equals (Constants.QUIZ_ENDED_PATH) || path.Equals (Constants.QUIZ_EXITED_PATH)) {
				var dataMap = DataMap.FromByteArray (messageEvent.GetData ());
				int numCorrect = dataMap.GetInt (Constants.NUM_CORRECT);
				int numIncorrect = dataMap.GetInt (Constants.NUM_INCORRECT);
				int numSkipped = dataMap.GetInt (Constants.NUM_SKIPPED);

				var builder = new Notification.Builder (this)
					.SetContentTitle (GetString (Resource.String.quiz_report))
					.SetSmallIcon (Resource.Drawable.ic_launcher)
					.SetLocalOnly (true);
				var quizReportText = new SpannableStringBuilder ();
				AppendColored (quizReportText, numCorrect.ToString (), Resource.Color.dark_green);
				quizReportText.Append (" " + GetString (Resource.String.correct) + "\n");
				AppendColored (quizReportText, numIncorrect.ToString (), Resource.Color.dark_red);
				quizReportText.Append (" " + GetString (Resource.String.incorrect) + "\n");
				AppendColored (quizReportText, numSkipped.ToString (), Resource.Color.dark_yellow);
				quizReportText.Append (" " + GetString (Resource.String.skipped) + "\n");

				builder.SetContentText (quizReportText);
				if (!path.Equals (Constants.QUIZ_EXITED_PATH)) {
					builder.AddAction (Resource.Drawable.ic_launcher,
						GetString (Resource.String.reset_quiz), GetResetQuizPendingIntent ());
				}
				((NotificationManager)GetSystemService (NotificationService))
					.Notify (QUIZ_REPORT_NOTIF_ID, builder.Build ());
			}
		}
		//Java.Lang.Object.Locale localinfo;
		public override View GetSampleContent (Context con)
		{
			Context localcontext = con;
			int width = con.Resources.DisplayMetrics.WidthPixels -40;
			FrameLayout frameLayout = new FrameLayout(con);
			FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.MatchParent, GravityFlags.FillVertical);
			frameLayout.LayoutParameters = layoutParams;
			LinearLayout layout=new LinearLayout(con);
			layout.LayoutParameters=new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WrapContent, ViewGroup.LayoutParams.WrapContent);
			layout.SetGravity(GravityFlags.FillVertical);
			layout.Orientation=Orientation.Vertical;
			TextView dummy0 = new TextView(con);
			dummy0.Text="Simple Interest Calculator";
			dummy0.Gravity=GravityFlags.Center;
			dummy0.TextSize=24;
			layout.AddView(dummy0);
			TextView dummy7 = new TextView(con);
			layout.AddView(dummy7);
			TextView dummy = new TextView(con);
			dummy.Text="The formula for finding simple interest is:";
			dummy.TextSize=18;
			layout.AddView(dummy);


			layout.FocusableInTouchMode=true;
			SpannableStringBuilder builder = new SpannableStringBuilder();
			TextView dummy1 = new TextView(con);
			String str= "Interest";
			SpannableString strSpannable= new SpannableString(str);
			strSpannable.SetSpan(new ForegroundColorSpan(Color.ParseColor("#66BB6A")), 0, str.Length, 0);
			builder.Append(strSpannable);
			builder.Append(" = Principal * Rate * Time");
			dummy1.SetText(builder, TextView.BufferType.Spannable);
			dummy1.TextSize=18;
			layout.AddView(dummy1);

			TextView dummy8 = new TextView(con);
			layout.AddView(dummy8);

			/*
        Principal amount Stack
       */

			LinearLayout principalStack = new LinearLayout(con);

			TextView txtPricipal = new TextView(con);
			txtPricipal.LayoutParameters=new ViewGroup.LayoutParams(width / 2, 100);
			txtPricipal.Text="Principal";

			principalamount =new SfNumericTextBox(con);
			principalamount.FormatString="C";
			principalamount.LayoutParameters=new ViewGroup.LayoutParams(width / 2, 100);
			principalamount.Value=1000;
			principalamount.AllowNull = true;
			principalamount.Watermark = "Principal Amount";
			principalamount.MaximumNumberDecimalDigits=2;
			var culture = new Java.Util.Locale("en","US");

			principalamount.CultureInfo = culture;
			principalamount.ValueChangeMode=ValueChangeMode.OnKeyFocus;
			principalStack.Orientation = Orientation.Horizontal;
			principalStack.AddView(txtPricipal);
			principalStack.AddView(principalamount);

			layout.AddView(principalStack);

			TextView dummy3 = new TextView(con);
			layout.AddView(dummy3);

			/*
        Interest Input Box
        */

			LinearLayout InterestcalStack = new LinearLayout(con);

			TextView txtInterest = new TextView(con);
			txtInterest.LayoutParameters=new ViewGroup.LayoutParams(width / 2, 100);
			txtInterest.Text="Interest Rate";
			Interestvalue =new SfNumericTextBox(con);
			Interestvalue.FormatString="P"; 
			Interestvalue.PercentDisplayMode=PercentDisplayMode.Compute;
			Interestvalue.MaximumNumberDecimalDigits=2;
			Interestvalue.ValueChangeMode=ValueChangeMode.OnKeyFocus;
			Interestvalue.LayoutParameters=new ViewGroup.LayoutParams(width / 2, 100);
			Interestvalue.Value=0.1f;
			Interestvalue.Watermark = "Rate of Interest";
			Interestvalue.AllowNull = true;
			Interestvalue.CultureInfo = culture;
			InterestcalStack.Orientation=Orientation.Horizontal;
			InterestcalStack.AddView(txtInterest);
			InterestcalStack.AddView(Interestvalue);


			layout.AddView(InterestcalStack);

			TextView dummy2 = new TextView(con);
			layout.AddView(dummy2);



			/*
          Period Input TextBox
         */
			LinearLayout periodStack = new LinearLayout(con);

			TextView period = new TextView(con);
			period.LayoutParameters=new ViewGroup.LayoutParams(width / 2, 100);
			period.Text="Term";

			periodValue =new SfNumericTextBox(con);
			periodValue.FormatString=" years";
			periodValue.MaximumNumberDecimalDigits=0;
			periodValue.LayoutParameters=new ViewGroup.LayoutParams(width / 2, 100);
			periodValue.Value=20;
			periodValue.Watermark = "Period (in years)";
			periodValue.ValueChangeMode=ValueChangeMode.OnKeyFocus;
			periodValue.CultureInfo = culture;
			periodValue.AllowNull = true;

			periodStack.Orientation=Orientation.Horizontal;

			periodStack.AddView(period);
			periodStack.AddView(periodValue);

			layout.AddView(periodStack);



			/*
        OutPut values
         */

			LinearLayout outputStack = new LinearLayout(con);

			TextView outputtxt = new TextView(con);
			outputtxt.LayoutParameters=new ViewGroup.LayoutParams(width / 2, 100);
			outputtxt.Text="Interest";
			outputtxt.SetTextColor(Color.ParseColor("#66BB6A"));

			OutputNumbertxtBox =new SfNumericTextBox(con);
			OutputNumbertxtBox.FormatString="c";
			OutputNumbertxtBox.MaximumNumberDecimalDigits=0;
			OutputNumbertxtBox.AllowNull=true;
			OutputNumbertxtBox.CultureInfo = culture;
			OutputNumbertxtBox.Watermark="Enter Values";
			OutputNumbertxtBox.Clickable=false;
			OutputNumbertxtBox.Value = (float)(1000 * 0.1 * 20);
			OutputNumbertxtBox.Enabled=false;
			OutputNumbertxtBox.LayoutParameters=new ViewGroup.LayoutParams(width / 2, 100);
			OutputNumbertxtBox.ValueChangeMode=ValueChangeMode.OnLostFocus;


			outputStack.Orientation=Orientation.Horizontal;

			outputStack.AddView(outputtxt);
			outputStack.AddView(OutputNumbertxtBox);
			layout.AddView(outputStack);

			TextView dummy4 = new TextView(con);
			layout.SetPadding(20, 20, 10, 20);
			layout.AddView(dummy4);

			principalamount.ValueChanged+= (object sender, SfNumericTextBox.ValueChangedEventArgs e) => {
				if(!e.P1.ToString().Equals("")&&!periodValue.Value.ToString().Equals("")&&!Interestvalue.Value.ToString().Equals(""))
					OutputNumbertxtBox.Value=e.P1 * periodValue.Value *  Interestvalue.Value;

			};

			periodValue.ValueChanged+= (object sender, SfNumericTextBox.ValueChangedEventArgs e) => {
				if(!e.P1.ToString().Equals("")&&!principalamount.Value.ToString().Equals("")&&!Interestvalue.Value.ToString().Equals(""))
					OutputNumbertxtBox.Value=e.P1* principalamount.Value*Interestvalue.Value;

			};

			Interestvalue.ValueChanged+= (object sender, SfNumericTextBox.ValueChangedEventArgs e) => {
				if(!e.P1.ToString().Equals("")&&!principalamount.Value.ToString().Equals("")&&!periodValue.Value.ToString().Equals(""))
					OutputNumbertxtBox.Value=e.P1 * principalamount.Value *  periodValue.Value;

			};

			layout.Touch+= (object sender, View.TouchEventArgs e) => {
				if(OutputNumbertxtBox.IsFocused || Interestvalue.IsFocused ||periodValue.IsFocused || principalamount.IsFocused){
					Rect outRect = new Rect();
					OutputNumbertxtBox.GetGlobalVisibleRect(outRect);
					Interestvalue.GetGlobalVisibleRect(outRect);
					periodValue.GetGlobalVisibleRect(outRect);
					principalamount.GetGlobalVisibleRect(outRect);

					if (!outRect.Contains((int)e.Event.RawX, (int)e.Event.RawY)) {
						if(!OutputNumbertxtBox.Value.ToString().Equals(""))
							OutputNumbertxtBox.ClearFocus();
						if(!Interestvalue.Value.ToString().Equals(""))
							Interestvalue.ClearFocus();
						if(!periodValue.Value.ToString().Equals(""))
							periodValue.ClearFocus();
						if(!principalamount.Value.ToString().Equals(""))
							principalamount.ClearFocus();

					}
					hideSoftKeyboard((Activity)localcontext);
				}
			};






			frameLayout.AddView(layout);

			ScrollView scrollView = new ScrollView(con);
			scrollView.AddView(frameLayout);

			return scrollView;
		}
		/**
	     * Handle {@link SessionsQuery} {@link Cursor}.
	     */
		private void OnSessionQueryComplete (ICursor cursor)
		{
			try {
				mSessionCursor = true;
				if (!cursor.MoveToFirst ()) {
					return;
				}
	
				// Format time block this session occupies
				long blockStart = cursor.GetLong (SessionsQuery.BLOCK_START);
				long blockEnd = cursor.GetLong (SessionsQuery.BLOCK_END);
				String roomName = cursor.GetString (SessionsQuery.ROOM_NAME);
				String subtitle = UIUtils.FormatSessionSubtitle (blockStart, blockEnd, roomName, Activity);
	
				mTitleString = cursor.GetString (SessionsQuery.TITLE);
				mTitle.Text = mTitleString;
				mSubtitle.Text = subtitle;
	
				mUrl = cursor.GetString (SessionsQuery.URL);
				if (TextUtils.IsEmpty (mUrl)) {
					mUrl = "";
				}
	
				mHashtag = cursor.GetString (SessionsQuery.HASHTAG);
				mTagDisplay = mRootView.FindViewById<TextView> (Resource.Id.session_tags_button);
				if (!TextUtils.IsEmpty (mHashtag)) {
					// Create the button text
					SpannableStringBuilder sb = new SpannableStringBuilder ();
					sb.Append (GetString (Resource.String.tag_stream) + " ");
					int boldStart = sb.Length ();
					sb.Append (GetHashtagsString ());
					sb.SetSpan (sBoldSpan, boldStart, sb.Length (), SpanTypes.ExclusiveExclusive);
	
					mTagDisplay.Text = (string)sb;
					mTagDisplay.Click += (sender, e) => {
						Intent intent = new Intent (Activity, typeof(TagStreamActivity));
						intent.PutExtra (TagStreamFragment.EXTRA_QUERY, GetHashtagsString ());
						StartActivity (intent);	
					};
					
				} else {
					mTagDisplay.Visibility = ViewStates.Gone;
				}
	
				mRoomId = cursor.GetString (SessionsQuery.ROOM_ID);
	
				// Unregister around setting checked state to avoid triggering
				// listener since change isn't user generated.
				mStarred.CheckedChange += null;
				mStarred.Checked = cursor.GetInt (SessionsQuery.STARRED) != 0;
				mStarred.CheckedChange += HandleCheckedChange;
	
				String sessionAbstract = cursor.GetString (SessionsQuery.ABSTRACT);
				if (!TextUtils.IsEmpty (sessionAbstract)) {
					UIUtils.SetTextMaybeHtml (mAbstract, sessionAbstract);
					mAbstract.Visibility = ViewStates.Visible;
					mHasSummaryContent = true;
				} else {
					mAbstract.Visibility = ViewStates.Gone;
				}
	
				View requirementsBlock = mRootView.FindViewById (Resource.Id.session_requirements_block);
				String sessionRequirements = cursor.GetString (SessionsQuery.REQUIREMENTS);
				if (!TextUtils.IsEmpty (sessionRequirements)) {
					UIUtils.SetTextMaybeHtml (mRequirements, sessionRequirements);
					requirementsBlock.Visibility = ViewStates.Visible;
					mHasSummaryContent = true;
				} else {
					requirementsBlock.Visibility = ViewStates.Gone;
				}
	
				// Show empty message when all data is loaded, and nothing to show
				if (mSpeakersCursor && !mHasSummaryContent) {
					mRootView.FindViewWithTag (Android.Resource.Id.Empty).Visibility = ViewStates.Visible;
				}
	
				//AnalyticsUtils.getInstance(getActivity()).trackPageView("/Sessions/" + mTitleString);
	
				UpdateLinksTab (cursor);
				UpdateNotesTab ();
	
			} finally {
				cursor.Close ();
			}
		}
Example #36
0
		public void FillMultiImagePost(PostMultiImageViewHolder vh, int position)
		{
			try
			{
				vh.AuthorName.Text = _Posts[position].AuthorName;
				var context = Android.App.Application.Context;
				vh.HeaderRating.Text = _Posts[position].Rating.ToString();
				vh.BottomRating.Text = _Posts[position].Rating.ToString();
				if (_Posts[position].Rating > 0)
				{
					vh.HeaderRating.SetTextColor(context.Resources.GetColor(Resource.Color.mainGreen));
					vh.BottomRating.SetTextColor(context.Resources.GetColor(Resource.Color.mainGreen));
					var text = " + " + _Posts[position].Rating;
					vh.HeaderRating.Text = text;
					vh.BottomRating.Text = text;
				}
				if (_Posts[position].Rating < 0)
				{
					vh.HeaderRating.SetTextColor(context.Resources.GetColor(Resource.Color.red));
					vh.BottomRating.SetTextColor(context.Resources.GetColor(Resource.Color.red));
					var text = "" + _Posts[position].Rating;
					vh.HeaderRating.Text = text;
					vh.BottomRating.Text = text;
				}
				vh.PostTime.Text = _Posts[position].PostTime;
				vh.Title.Text = _Posts[position].Title;
				if (_Posts[position].Description != null && !String.IsNullOrEmpty(_Posts[position].Description.ToString()))
				{
					vh.Description.Text = _Posts[position].Description.ToString();
					vh.Description.Visibility = ViewStates.Visible;
				}
				else {
					vh.Description.Text = String.Empty;
					vh.Description.Visibility = ViewStates.Gone;
				}

				SpannableStringBuilder stringBuilder = new SpannableStringBuilder();
				Color textColor = context.Resources.GetColor(Resource.Color.mainGreen);

				foreach (var tag in _Posts[position].Tags)
				{
					SpannableString tag1 = new SpannableString("#" + tag);

					tag1.SetSpan(new ForegroundColorSpan(textColor), 0, tag1.Length(), SpanTypes.ExclusiveExclusive);
					stringBuilder.Append(tag1);
					stringBuilder.Append("  ");
					//SpannableString tag2 = new SpannableString(" ");
					//stringBuilder.Append(tag2);
					//stringBuilder.SetSpan(new TagSpan(backgroundColor, backgroundColor), stringBuilder.Length() - tag2.Length(), stringBuilder.Length(), SpanTypes.ExclusiveExclusive);
				}
				vh.Tags.SetText(stringBuilder, TextView.BufferType.Spannable);
				vh.Comments.Text = _Posts[position].Comments.ToString();



				ImageAdapter adapter = new ImageAdapter(context, _Posts[position].Images);
				vh.Rotator.Adapter = adapter;

			}
			catch (Exception ex)
			{
				Insights.Initialize("0637c26a1b2e27693e05298f7c3c3a04c102a3c7", Application.Context);
				Insights.Report(ex, new Dictionary<string, string> { { "Message", ex.Message } }, Insights.Severity.Error);
				var text = ex.Message;
			}
		}
Example #37
0
		public void FillImagePost(PostImageViewHolder vh,int position){
			try{
				vh.AuthorName.Text = _Posts[position].AuthorName;
				var context = Android.App.Application.Context;
				vh.HeaderRating.Text = _Posts [position].Rating.ToString ();
				vh.BottomRating.Text = _Posts [position].Rating.ToString ();
				if (_Posts [position].Rating > 0) {
					vh.HeaderRating.SetTextColor (context.Resources.GetColor(Resource.Color.mainGreen));
					vh.BottomRating.SetTextColor (context.Resources.GetColor(Resource.Color.mainGreen));
					var text = " + "+_Posts[position].Rating;
					vh.HeaderRating.Text = text;
					vh.BottomRating.Text = text;
				}
				if (_Posts [position].Rating < 0) {
					vh.HeaderRating.SetTextColor (context.Resources.GetColor(Resource.Color.red));
					vh.BottomRating.SetTextColor (context.Resources.GetColor(Resource.Color.red));
					var text = ""+_Posts[position].Rating;
					vh.HeaderRating.Text = text;
					vh.BottomRating.Text = text;
				}
				vh.PostTime.Text = _Posts[position].PostTime;
				vh.Title.Text = _Posts[position].Title;
				if(_Posts[position].Description!=null && !String.IsNullOrEmpty(_Posts[position].Description.ToString())){
					vh.Description.Text = _Posts[position].Description.ToString();
					vh.Description.Visibility = ViewStates.Visible;
				}else{
					vh.Description.Text = String.Empty;
					vh.Description.Visibility = ViewStates.Gone;
				}
//				if(_Posts[position].FormattedDescription!=null && _Posts[position].FormattedDescription.Count>0){
//					SpannableStringBuilder descriptionBulder = new SpannableStringBuilder();
//					Color descTextColorDarkGray = context.Resources.GetColor(Resource.Color.darkGray);
//					Color descTextColorGray = context.Resources.GetColor(Resource.Color.gray);
//
//					foreach(var des in _Posts[position].FormattedDescription){
//						if(des.Item1 == "text"){
//							SpannableString tag1 = new SpannableString(des.Item2);
//
//							tag1.SetSpan(new ForegroundColorSpan(descTextColorGray), 0, tag1.Length(), SpanTypes.ExclusiveExclusive);
//							descriptionBulder.Append(tag1);
//						}
//						if(des.Item1 == "textLink"){
//							SpannableString tag2 = new SpannableString(des.Item2);
//
//							tag2.SetSpan(new ForegroundColorSpan(descTextColorDarkGray), 0, tag2.Length(), SpanTypes.ExclusiveExclusive);
//							descriptionBulder.Append(tag2);
//						}
//					}
//					if(descriptionBulder.Count()>0){
//						//vh.Description.TextFormatted = descriptionBulder;
//						vh.Description.SetText(descriptionBulder,TextView.BufferType.Spannable);
//					}
//				}else{
//					vh.Description.Visibility = ViewStates.Invisible;
//					vh.Description.Text = null;
//				}
				//vh._Description.Text = _Posts[position].Description;
				//vh._Description.Text = _Posts[position].Description;
				SpannableStringBuilder stringBuilder = new SpannableStringBuilder();
				Color textColor = context.Resources.GetColor(Resource.Color.mainGreen);
				var tagsBuilder = new StringBuilder();

				foreach (var tag in _Posts[position].Tags) {
					SpannableString tag1 = new SpannableString("#"+tag);

					tag1.SetSpan(new ForegroundColorSpan(textColor), 0, tag1.Length(), SpanTypes.ExclusiveInclusive);
					stringBuilder.Append(tag1);
					stringBuilder.Append("  ");
					//SpannableString tag2 = new SpannableString(" ");
					//stringBuilder.Append(tag2);
					//stringBuilder.SetSpan(new TagSpan(backgroundColor, backgroundColor), stringBuilder.Length() - tag2.Length(), stringBuilder.Length(), SpanTypes.ExclusiveExclusive);
					//tagsBuilder.Append("#"+tag+" ");
				}

				vh.Tags.SetText(stringBuilder,TextView.BufferType.Spannable);
				//vh.Tags.Text = tagsBuilder.ToString();
				//vh.Tags.TextFormatted = stringBuilder;
				vh.Comments.Text = _Posts[position].Comments.ToString();
				vh.Image.Click -= videoHandler;
				vh.Image.Click -= imageHandler;
				vh.Image.Click -= gifHandler;
				if(_Posts[position].PostType==PostType.Video){
					if (vh.Image != null) {
						vh.Image.SetTag (Resource.String.currentPosition, vh.AdapterPosition.ToString ());
						vh.Image.SetTag (Resource.String.imageUrl, _Posts [vh.AdapterPosition].VideoUrl);

						vh.Image.Click -= imageHandler;
						vh.Image.Click -= gifHandler;
						vh.Image.Click -= videoHandler;
						vh.Image.Click += videoHandler;
						Picasso.With(Android.App.Application.Context)
							.Load(_Posts[position].Url)
							.Transform(new CropSquareTransformation())
							.Into(vh.Image);
					}
				}
				if(_Posts[position].PostType==PostType.Image){
				if (vh.Image != null) {
					vh.Image.SetTag (Resource.String.currentPosition, vh.AdapterPosition.ToString ());
					vh.Image.SetTag (Resource.String.imageUrl, _Posts [vh.AdapterPosition].Url);
					vh.Image.SetTag (Resource.String.isbiggeravailable,_Posts [vh.AdapterPosition].IsBiggerAvailable);

						vh.Image.Click -= videoHandler;
						vh.Image.Click -= gifHandler;
						vh.Image.Click -= imageHandler;
						vh.Image.Click += imageHandler;
					Picasso.With(Android.App.Application.Context)
							.Load(_Posts[position].Url)
						.Transform(new CropSquareTransformation())
						.Into(vh.Image);
				}
				}
				if(_Posts[position].PostType==PostType.Gif){
					if (vh.Image != null) {
						vh.Image.SetTag (Resource.String.currentPosition, vh.AdapterPosition.ToString ());
						vh.Image.SetTag (Resource.String.imageUrl, _Posts [vh.AdapterPosition].GifUrl);

						vh.Image.Click -= videoHandler;
						vh.Image.Click -= imageHandler;
						vh.Image.Click -= gifHandler;
						vh.Image.Click += gifHandler;
						Picasso.With(Android.App.Application.Context)
							.Load(_Posts[position].Url)
							.Transform(new CropSquareTransformation())
							.Into(vh.Image);
					}
				}



			}catch(Exception ex){
				Insights.Initialize("0637c26a1b2e27693e05298f7c3c3a04c102a3c7", Application.Context);
				Insights.Report(ex,new Dictionary<string,string>{{"Message",ex.Message}},Insights.Severity.Error);
				var text = ex.Message;
			}
		}
Example #38
0
        public static void Linkify(Activity activity, TextView textView, string linkText, string url)
        {
            var text = textView.Text;

            var builder = new SpannableStringBuilder();
            builder.Append(text);

            builder.SetSpan(new MyClickableSpan(v =>
                ShowWebPage(activity, url)),
                text.IndexOf(linkText),
                text.IndexOf(linkText) + linkText.Length,
                SpanTypes.ExclusiveExclusive
            );
            textView.MovementMethod = LinkMovementMethod.Instance;
        }