/// <summary>
        /// Build the spannable according to the computed text, meaning set the right font, color and size to the text and icon char index
        /// </summary>
        /// <param name="computedString"></param>
        /// <returns></returns>
        private SpannableString BuildSpannableString(string computedString)
        {
            SpannableString span = new SpannableString(computedString);

            //if there is an icon
            if (!string.IsNullOrEmpty(iconButton.Icon))
            {
                //set icon
                span.SetSpan(new CustomTypefaceSpan("fontawesome", iconFont, GetSpanColor(iconButton.IconColor)),
                             computedString.IndexOf(iconButton.Icon),
                             computedString.IndexOf(iconButton.Icon) + iconButton.Icon.Length,
                             SpanTypes.ExclusiveExclusive);
                //set icon size
                span.SetSpan(new AbsoluteSizeSpan((int)iconButton.IconSize, true),
                             computedString.IndexOf(iconButton.Icon),
                             computedString.IndexOf(iconButton.Icon) + iconButton.Icon.Length,
                             SpanTypes.ExclusiveExclusive);
            }
            //if there is text
            if (!string.IsNullOrEmpty(iconButton.Text))
            {
                span.SetSpan(new CustomTypefaceSpan("", textFont, GetSpanColor(iconButton.TextColor)),
                             textStartIndex,
                             textStopIndex,
                             SpanTypes.ExclusiveExclusive);
                span.SetSpan(new AbsoluteSizeSpan((int)iconButton.FontSize, true),
                             textStartIndex,
                             textStopIndex,
                             SpanTypes.ExclusiveExclusive);
            }

            return(span);
        }
        /// <summary>
        /// Build the spannable according to the computed text, meaning set the right font, color and size to the text and icon char index
        /// </summary>
        /// <param name="computedString"></param>
        private SpannableString BuildSpannableString(string computedString)
        {
            SpannableString span = new SpannableString(computedString);

            if (!string.IsNullOrEmpty(_iconLabel.Icon))
            {
                //set icon
                span.SetSpan(new CustomTypefaceSpan("fontawesome", _iconFont, _helper.GetSpanColor(_iconLabel.IconColor, Control.TextColors)),
                             computedString.IndexOf(_iconLabel.Icon),
                             computedString.IndexOf(_iconLabel.Icon) + _iconLabel.Icon.Length,
                             SpanTypes.ExclusiveExclusive);
                //set icon size
                span.SetSpan(new AbsoluteSizeSpan((int)_iconLabel.IconSize, true),
                             computedString.IndexOf(_iconLabel.Icon),
                             computedString.IndexOf(_iconLabel.Icon) + _iconLabel.Icon.Length,
                             SpanTypes.ExclusiveExclusive);
            }
            if (!string.IsNullOrEmpty(_iconLabel.Text))
            {
                span.SetSpan(new CustomTypefaceSpan("", _textFont, _helper.GetSpanColor(_iconLabel.TextColor, Control.TextColors)),
                             _textStartIndex,
                             _textStopIndex,
                             SpanTypes.ExclusiveExclusive);
                span.SetSpan(new AbsoluteSizeSpan((int)_iconLabel.FontSize, true),
                             _textStartIndex,
                             _textStopIndex,
                             SpanTypes.ExclusiveExclusive);
            }

            return(span);
        }
Beispiel #3
0
 private void init(View view)
 {
     if (!isOnline())
     {
         mErrorDialog.Show();
     }
     else
     {
         SpannableString s = new SpannableString("Payment Options");
         typeface = Typeface.CreateFromAsset(navigationActivity.Assets, "JosefinSans-SemiBold.ttf");
         s.SetSpan(new TypefaceSpan("Amaranth-Regular.ttf"), 0, s.Length(), SpanTypes.ExclusiveExclusive);
         s.SetSpan(new ForegroundColorSpan(navigationActivity.Resources.GetColor(Resource.Color.title)), 0, s.Length(), SpanTypes.ExclusiveExclusive);
         navigationActivity.TitleFormatted = s;
         mContosoText  = view.FindViewById <TextView>(Resource.Id.contosocabsmoney);
         mWalletAmount = view.FindViewById <TextView>(Resource.Id.price);
         mAddMoney     = view.FindViewById <TextView>(Resource.Id.addmoney);
         mSelectMode   = view.FindViewById <TextView>(Resource.Id.paymentopttext);
         mCash         = view.FindViewById <TextView>(Resource.Id.textcash);
         mCard         = view.FindViewById <TextView>(Resource.Id.textcard);
         mWallet       = view.FindViewById <TextView>(Resource.Id.textwallet);
         mContosoText.SetTypeface(typeface, TypefaceStyle.Normal);
         mWallet.SetTypeface(typeface, TypefaceStyle.Normal);
         mWalletAmount.SetTypeface(typeface, TypefaceStyle.Normal);
         mAddMoney.SetTypeface(typeface, TypefaceStyle.Normal);
         mCard.SetTypeface(typeface, TypefaceStyle.Normal);
         mCash.SetTypeface(typeface, TypefaceStyle.Normal);
         mSelectMode.SetTypeface(typeface, TypefaceStyle.Normal);
         mAddMoney.SetOnClickListener(this);
     }
 }
        protected void DecorateText(TextView tv, BaseText baseText, Android.Graphics.Color color, TextDecorationType tdType)
        {
            string text = GetTextCallback(baseText);

            if (baseText.Highlights != null && baseText.Highlights.Count > 0)
            {
                var span = new SpannableString(text);
                foreach (var highlight in baseText.Highlights)
                {
                    switch (tdType)
                    {
                    case TextDecorationType.Foreground:
                        span.SetSpan(new ForegroundColorSpan(color), highlight[0], highlight[1], SpanTypes.ExclusiveExclusive);
                        break;

                    case TextDecorationType.Background:
                        span.SetSpan(new BackgroundColorSpan(color), highlight[0], highlight[1], SpanTypes.ExclusiveExclusive);
                        break;
                    }
                }
                tv.Append(span);
            }
            else
            {
                tv.Text = text;
            }
        }
Beispiel #5
0
            public override View GetChildView(int groupPosition, int childPosition,
                                              bool isLastChild, View convertView,
                                              ViewGroup parent)
            {
                var item = _dictGroup[_lstGroupId[groupPosition]][childPosition];

                if (convertView == null)
                {
                    convertView = _activity.LayoutInflater.Inflate(Android.Resource.Layout.SimpleListItem1, null);
                }

                var tv        = convertView.FindViewById <TextView>(Android.Resource.Id.Text1);
                var text      = item.FullName;
                var spannable = new SpannableString(text);

                spannable.SetSpan(new LeadingMarginSpanStandard(0, 15), 0, text.Length, 0);

                if (item.CompletionDate.HasValue && !item.CompletionDate.Value.Equals(DateTime.MinValue))
                {
                    // Strike out the text
                    spannable.SetSpan(new StrikethroughSpan(), 0, text.Length, SpanTypes.InclusiveExclusive);
                }
                tv.TextFormatted = spannable;

                return(convertView);
            }
Beispiel #6
0
 public static void SetClickableSpan(this SpannableString spannableString, string allText, string clickableText, Action <CoreClickableSpan, View> onClick, string argument, Color?textColor = null, bool hideUnderline = false)
 {
     CoreUtility.ExecuteMethod("SetClickableSpan", delegate()
     {
         if (!textColor.HasValue)
         {
             textColor = Color.Black;
         }
         int ix = allText.IndexOf(clickableText);
         CoreClickableSpan clickableSpan = new CoreClickableSpan(onClick, argument, clickableText);
         clickableSpan.HideUnderline     = hideUnderline;
         while (ix >= 0)
         {
             spannableString.SetSpan(clickableSpan, ix, ix + clickableText.Length, SpanTypes.ExclusiveExclusive);
             spannableString.SetSpan(new StyleSpan(Android.Graphics.TypefaceStyle.Bold), ix, ix + clickableText.Length, SpanTypes.ExclusiveExclusive);
             spannableString.SetSpan(new ForegroundColorSpan(textColor.Value), ix, ix + clickableText.Length, SpanTypes.ExclusiveExclusive);
             int nextIndex = allText.Substring(ix + clickableText.Length).IndexOf(clickableText);
             if (nextIndex >= 0)
             {
                 ix = nextIndex + (ix + clickableText.Length);
             }
             else
             {
                 ix = -1; // break out
             }
         }
     });
 }
Beispiel #7
0
        private void SetFont(ref SpannableString converted, IBaseFont font, FontIndexPair pair, FontTag fontTag)
        {
            //set the text color
            if (font.Color != System.Drawing.Color.Empty)
            {
                converted.SetSpan(new ForegroundColorSpan(font.Color.ToNativeColor()), pair.StartIndex, pair.EndIndex, SpanTypes.ExclusiveInclusive);
            }

            if (fontTag != null && fontTag.FontAction == FontTagAction.Link)
            {
                CreateLink(ref converted, font, pair);
            }

            //set allignment
            if (font is Font)
            {
                Font taggedExtendedFont = font as Font;

                if (taggedExtendedFont.Alignment != TextAlignment.None)
                {
                    Layout.Alignment alignment = taggedExtendedFont.Alignment == TextAlignment.Center ? Layout.Alignment.AlignCenter : Layout.Alignment.AlignNormal;
                    converted.SetSpan(new AlignmentSpanStandard(alignment), pair.StartIndex, pair.EndIndex, SpanTypes.ExclusiveInclusive);
                }
            }

            if (_extendedFont != null)
            {
                //calculate the relative size to the regular font
                converted.SetSpan(new RelativeSizeSpan((float)font.Size / (float)_extendedFont.Size), pair.StartIndex, pair.EndIndex, SpanTypes.ExclusiveInclusive);
            }
            //set the custom typeface
            converted.SetSpan(new CustomTypefaceSpan("sans-serif", DroidAssetPlugin.GetCachedFont(font, _context)), pair.StartIndex, pair.EndIndex, SpanTypes.ExclusiveInclusive);
        }
Beispiel #8
0
 public static void SetStyleSpan(this SpannableString spannableString, string allText, string styleText, TypefaceStyle style, Color textColor, Typeface typeFace = null, float typeFaceSize = 0)
 {
     CoreUtility.ExecuteMethod("SetStyleSpan", delegate()
     {
         int ix = allText.IndexOf(styleText);
         while (ix >= 0)
         {
             spannableString.SetSpan(new StyleSpan(style), ix, ix + styleText.Length, SpanTypes.ExclusiveExclusive);
             if (textColor != Color.Transparent)
             {
                 spannableString.SetSpan(new ForegroundColorSpan(textColor), ix, ix + styleText.Length, SpanTypes.ExclusiveExclusive);
             }
             if (typeFace != null)
             {
                 spannableString.SetSpan(new CustomTypefaceSpan(typeFace, typeFaceSize), ix, ix + styleText.Length, SpanTypes.ExclusiveExclusive);
             }
             int nextIndex = allText.Substring(ix + styleText.Length).IndexOf(styleText);
             if (nextIndex >= 0)
             {
                 ix = nextIndex + (ix + styleText.Length);
             }
             else
             {
                 ix = -1; // break out
             }
         }
     });
 }
Beispiel #9
0
        void UpdateUITime(DateTime?date = null)
        {
            var dt = date.HasValue ? date.Value : DateTime.UtcNow.ToLocalTime();

            wheelSeconds.SetProgress(dt.Second);

            //var fmt = "h:mm tt";
            var fmt = "h:mm";

            if (WearListenerService.Settings.Use24Clock)
            {
                fmt = "H:mm";
            }

            var str = dt.ToString(fmt).ToUpperInvariant();

            var ss = new SpannableString(str);

            ss.SetSpan(new StyleSpan(Android.Graphics.TypefaceStyle.Bold), 0, str.IndexOf(':'), SpanTypes.ExclusiveExclusive);

            if (fmt.Contains(" "))
            {
                var ttIndex = str.LastIndexOf(' ') + 1;

                ss.SetSpan(new ForegroundColorSpan(Android.Graphics.Color.Gray), ttIndex, ttIndex + 2, SpanTypes.ExclusiveExclusive);
                ss.SetSpan(new RelativeSizeSpan(0.8f), ttIndex, ttIndex + 2, SpanTypes.ExclusiveExclusive);
            }

            time.TextFormatted = ss;
        }
Beispiel #10
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            this.RequestWindowFeature(WindowFeatures.NoTitle);

            SetContentView(Resource.Layout.MyScores);

            txtBestScore         = (TextView)FindViewById <TextView>(Resource.Id.txtBestScore);
            txtMediumScore       = FindViewById <TextView>(Resource.Id.txtMediumScore);
            txtMemoryDescription = FindViewById <TextView>(Resource.Id.txtMemoryDescription);

            //String bestScoreText = "<![CDATA[<p><font color='#CBCBCB'>BEST SCORE</font> <font color='#FFFFFF'>3211</font></p> ]]>";
            //txtBestScore.SetText((Html.FromHtml((bestScoreText))));

            var bestScoreString = "BEST SCORE " + 0;
            var spanBestScore   = new SpannableString(bestScoreString);

            spanBestScore.SetSpan(new ForegroundColorSpan(Color.Rgb(203, 203, 203)), 0, 10, 0);
            spanBestScore.SetSpan(new ForegroundColorSpan(Color.Rgb(255, 255, 255)), 11, bestScoreString.Length, 0);
            spanBestScore.SetSpan(new StyleSpan(TypefaceStyle.Normal), 0, 10, 0);
            spanBestScore.SetSpan(new StyleSpan(TypefaceStyle.Bold), 11, bestScoreString.Length, 0);
            txtBestScore.SetText(spanBestScore, TextView.BufferType.Spannable);

            var mediumScoreString = "MEDIUM SCORE " + 0;
            var spanMediumScore   = new SpannableString(mediumScoreString);

            spanMediumScore.SetSpan(new ForegroundColorSpan(Color.Rgb(203, 203, 203)), 0, 12, 0);
            spanMediumScore.SetSpan(new ForegroundColorSpan(Color.Rgb(255, 255, 255)), 13, mediumScoreString.Length, 0);
            spanMediumScore.SetSpan(new StyleSpan(TypefaceStyle.Normal), 0, 12, 0);
            spanMediumScore.SetSpan(new StyleSpan(TypefaceStyle.Bold), 13, mediumScoreString.Length, 0);
            txtMediumScore.SetText(spanMediumScore, TextView.BufferType.Spannable);

            txtMemoryDescription.Text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc sit amet purus pellentesque, vulputate tellus vitae, posuere nisl. Vivamus volutpat facilisis feugiat. Aliquam id dignissim purus. Cras ut iaculis tortor, ac dignissim diam. Aliquam varius, eros mattis placerat consequat, elit ligula lacinia mi, quis tincidunt orci enim quis risus. Cras pharetra diam felis, nec semper ipsum placerat nec. Phasellus feugiat at neque ac aliquet. Sed hendrerit, tellus a ultricies iaculis, orci odio ornare arcu, molestie lacinia risus orci non magna. Mauris auctor ut ante eu porttitor. Ut nunc elit, vehicula a tempus quis, commodo vel quam. Sed scelerisque, dolor ut tempus auctor, lorem massa suscipit dolor, accumsan tincidunt lectus metus nec massa.";
        }
Beispiel #11
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);
            }
        }
Beispiel #12
0
        public SpannableString ConvertToSpannable(StateNode state, DisplayMetrics displayMetrics)
        {
            var nodes = Flatten(state).TrimNewLines();

            var s = new SpannableString(string.Concat(nodes as IEnumerable<TextEx>));
            int start = 0;
            foreach (var n in nodes)
            {
                if (string.IsNullOrEmpty(n.Text))
                {
                    if (n is StringAnchor a)
                    {
                        //s.SetSpan(new ClickableSpan(a.Owner), start, start + a.Length, SpanTypes.InclusiveExclusive);
                        //s.SetSpan(new UnderlineSpan(), start, start + a.Length, SpanTypes.InclusiveExclusive);
                    }
                    continue;
                }

                if (n.Bold != null || n.Italic != null || n.FontSize != null || n.Foreground != null)
                {
                    TypefaceStyle style = 0;
                    if (n.Bold == true && n.Italic == true)
                        style = TypefaceStyle.BoldItalic;
                    else if (n.Bold == true)
                        style = TypefaceStyle.Bold;
                    else if (n.Italic == true)
                        style = TypefaceStyle.Italic;
                    else
                        style = TypefaceStyle.Normal;


                    ColorStateList color = null;
                    if (n.Foreground != null) color = ColorStateList.ValueOf(new AColor(
                            (byte)(n.Foreground.Value.R * 255),
                            (byte)(n.Foreground.Value.G * 255),
                            (byte)(n.Foreground.Value.B * 255),
                            (byte)(n.Foreground.Value.A * 255)
                        ));

                    int fontSize = -1;

                    if (n.FontSize != null)
                        fontSize = (int) Math.Round(TypedValue.ApplyDimension(ComplexUnitType.Sp, (float) n.FontSize.Value, displayMetrics), MidpointRounding.AwayFromZero);

                    s.SetSpan(new TextAppearanceSpan(null, style, fontSize, color, null), start, start + n.Text.Length, SpanTypes.InclusiveExclusive);
                }
                if (n.Sub == true)
                    s.SetSpan(new SubscriptSpan(), start, start + n.Text.Length, SpanTypes.InclusiveExclusive);
                if (n.Super == true)
                    s.SetSpan(new SuperscriptSpan(), start, start + n.Text.Length, SpanTypes.InclusiveExclusive);
                if (n.Strike == true)
                    s.SetSpan(new StrikethroughSpan(), start, start + n.Text.Length, SpanTypes.InclusiveExclusive);
                if (n.Underline == true)
                    s.SetSpan(new UnderlineSpan(), start, start + n.Text.Length, SpanTypes.InclusiveExclusive);

                start += n.Text.Length;
            }

            return s;
        }
Beispiel #13
0
        private SpannableString MakeSpannAbleString(ICharSequence text)
        {
            try
            {
                SpannableString spendableString = new SpannableString(text);

                List <StTools.XAutoLinkItem> autoLinkItems = MatchedRanges(text);

                foreach (StTools.XAutoLinkItem autoLinkItem in autoLinkItems)
                {
                    Color          currentColor  = GetColorByMode(autoLinkItem.GetAutoLinkMode());
                    XTouchableSpan clickAbleSpan = new XTouchableSpan(this, autoLinkItem, currentColor, DefaultSelectedColor, IsUnderLineEnabled);

                    spendableString.SetSpan(clickAbleSpan, autoLinkItem.GetStartPoint(), autoLinkItem.GetEndPoint(), SpanTypes.ExclusiveExclusive);

                    // check if we should make this auto link item bold
                    if (MBoldAutoLinkModes != null && MBoldAutoLinkModes.Contains(autoLinkItem.GetAutoLinkMode()))
                    {
                        // make the auto link item bold
                        spendableString.SetSpan(new StyleSpan(TypefaceStyle.Bold), autoLinkItem.GetStartPoint(), autoLinkItem.GetEndPoint(), SpanTypes.ExclusiveExclusive);
                    }
                }
                return(spendableString);
            }
            catch (Exception e)
            {
                Methods.DisplayReportResultTrack(e);
                SpannableString spendableString = new SpannableString(text);
                return(spendableString);
            }
        }
        private static SpannableString AddImages(PostDataObject item, Context context, SpannableString spendable)
        {
            try
            {   //Regex pattern that looks for embedded images of the format: [img src=imageName/]
                //exp. This [img src=imageName/] is an icon.

                Pattern refImg = Pattern.Compile("\\Q[img src=\\E([a-zA-Z0-9_]+?)\\Q/]\\E");

                //bool hasChanges = false;

                Matcher matcher = refImg.Matcher(spendable);

                while (matcher.Find())
                {
                    bool set = true;
                    foreach (var span in spendable.GetSpans(matcher.Start(), matcher.End(), Class.FromType(typeof(ImageSpan))))
                    {
                        if (spendable.GetSpanStart(span) >= matcher.Start() && spendable.GetSpanEnd(span) <= matcher.End())
                        {
                            spendable.RemoveSpan(span);
                        }
                        else
                        {
                            set = false;
                            break;
                        }
                    }

                    if (set)
                    {
                        string resName = spendable.SubSequence(matcher.Start(1), matcher.End(1))?.Trim();
                        int    id      = context.Resources.GetIdentifier(resName, "drawable", context.PackageName);

                        var d = ContextCompat.GetDrawable(context, id);
                        if (d != null)
                        {
                            d.SetBounds(0, 0, d.IntrinsicWidth, d.IntrinsicHeight);
                            spendable.SetSpan(new ImageSpan(d, SpanAlign.Baseline), matcher.Start(), matcher.End(), SpanTypes.ExclusiveExclusive);
                        }
                        else
                        {
                            spendable.SetSpan(new ImageSpan(context, id, SpanAlign.Baseline), matcher.Start(), matcher.End(), SpanTypes.ExclusiveExclusive);
                        }

                        //hasChanges = true;
                    }
                }

                var username = WoWonderTools.GetNameFinal(Publisher);
                SetTextStyle(spendable, username, TypefaceStyle.Bold);

                if (spendable.ToString() !.Contains(context.GetText(Resource.String.Lbl_ChangedProfileCover)))
                {
                    SetTextColor(spendable, context.GetText(Resource.String.Lbl_ChangedProfileCover), "#888888");
                }
                else if (spendable.ToString() !.Contains(context.GetText(Resource.String.Lbl_ChangedProfilePicture)))
                {
                    SetTextColor(spendable, context.GetText(Resource.String.Lbl_ChangedProfilePicture), "#888888");
                }
Beispiel #15
0
        public static SpannableString setColorBold(string input, Color color)
        {
            SpannableString result = new SpannableString(input);

            result.SetSpan(new ForegroundColorSpan(color), 0, input.Length, 0);
            result.SetSpan(new StyleSpan(TypefaceStyle.Bold), 0, input.Length, 0);
            return(result);
        }
        void SetTextStyle()
        {
            if (base.Control == null)
            {
                return;
            }

            SpannableString styledString = new SpannableString(base.Control.Text);

            int counter = 0;

            foreach (var span in Base.FormattedText.Spans)
            {
                var spanText   = Base.FormattedText.Spans[counter].Text;
                var startIndex = base.Control.Text.IndexOf(spanText);
                var endIndex   = startIndex + spanText.Length;

                if (Base.ClickableIndex == counter)
                {
                    var       clickableSpan = new MyClickableSpan();
                    TextPaint paint         = new TextPaint();

                    paint.LinkColor = Base.FormattedText.Spans[counter].ForegroundColor.ToAndroid();
                    paint.BgColor   = Base.FormattedText.Spans[counter].ForegroundColor.ToAndroid();
                    paint.Color     = Base.FormattedText.Spans[counter].ForegroundColor.ToAndroid();

                    clickableSpan.UpdateDrawState(paint);

                    clickableSpan.Click += v =>
                    {
                        if (Base.Command != null && Base.Command.CanExecute(null))
                        {
                            Base.Command.Execute(null);
                        }
                    };

                    styledString.SetSpan(clickableSpan, startIndex, endIndex, SpanTypes.ExclusiveExclusive);
                    styledString.SetSpan(new UnderlineSpan(), startIndex, endIndex, 0);
                }

                styledString.SetSpan(new ForegroundColorSpan(Base.FormattedText.Spans[counter].ForegroundColor.ToAndroid()), startIndex, endIndex, 0);
                counter += 1;
            }


            //paint.LinkColor = Base.FormattedText.Spans[2].ForegroundColor.ToAndroid();
            //paint.BgColor = Base.FormattedText.Spans[2].ForegroundColor.ToAndroid();
            //paint.Color = Base.FormattedText.Spans[2].ForegroundColor.ToAndroid();

            //styledString.SetSpan(clickableSpan, span3StartIndex, base.Control.Text.Length, SpanTypes.ExclusiveExclusive);
            //styledString.SetSpan(new UnderlineSpan(), span3StartIndex, base.Control.Text.Length, 0);
            //styledString.SetSpan(new ForegroundColorSpan(Base.FormattedText.Spans[2].ForegroundColor.ToAndroid()), span3StartIndex, base.Control.Text.Length, 0);
            //styledString.SetSpan(new ForegroundColorSpan(Base.FormattedText.Spans[0].ForegroundColor.ToAndroid()), 0, span3StartIndex, 0);

            this.Control.TextAlignment  = Android.Views.TextAlignment.Center;
            this.Control.TextFormatted  = styledString;
            this.Control.MovementMethod = new LinkMovementMethod();
        }
Beispiel #17
0
        private void DataTemplateBasic(View view, int i, AnimeVideoData animeVideoData)
        {
            var str = new SpannableString($"{animeVideoData.Name} - {animeVideoData.AnimeTitle}");

            str.SetSpan(PrefixStyle, 0, animeVideoData.Name.Length, SpanTypes.InclusiveInclusive);
            str.SetSpan(PrefixColorStyle, 0, animeVideoData.Name.Length, SpanTypes.InclusiveInclusive);
            view.FindViewById <TextView>(Resource.Id.PromoVideosPageItemSubtitle)
            .SetText(str.SubSequenceFormatted(0, str.Length()), TextView.BufferType.Spannable);
        }
        private SpannableString SpannableText(string text, string word, CustomClickableSpan clickableSpan)
        {
            var spannableText = new SpannableString(text);
            var index         = text.IndexOf(word, StringComparison.Ordinal);

            spannableText.SetSpan(new ForegroundColorSpan(Resources.GetColor(Resource.Color.rgb255_34_5)), index, index + word.Length, 0);
            spannableText.SetSpan(clickableSpan, index, index + word.Length, SpanTypes.ExclusiveExclusive);

            return(spannableText);
        }
        private void Rebind()
        {
            if (!enabled || DurationTextView == null)
            {
                return;
            }

            var durationShown     = digitsEntered > 0 ? newDuration : oldDuration;
            var durationText      = durationShown.ToString();
            var durationSpannable = new SpannableString(durationText);

            durationSpannable.SetSpan(
                new ForegroundColorSpan(Color.LightGray),
                0, durationSpannable.Length(),
                SpanTypes.InclusiveExclusive);
            if (digitsEntered > 0)
            {
                // Divider
                var sepIdx = durationText.IndexOf(":", StringComparison.Ordinal);
                if (sepIdx >= 0)
                {
                    durationSpannable.SetSpan(
                        new ForegroundColorSpan(Color.Black),
                        sepIdx, sepIdx + 1,
                        SpanTypes.InclusiveExclusive);
                }
                // Color entered minutes
                durationSpannable.SetSpan(
                    new ForegroundColorSpan(Color.Black),
                    durationText.Length - (Math.Min(digitsEntered, 2)), durationText.Length,
                    SpanTypes.InclusiveExclusive);
                // Color entered hours
                if (digitsEntered > 2)
                {
                    durationSpannable.SetSpan(
                        new ForegroundColorSpan(Color.Black),
                        2 - (digitsEntered - 2), 2,
                        SpanTypes.InclusiveExclusive);
                }
            }
            DurationTextView.SetText(durationSpannable, TextView.BufferType.Spannable);

            int num = 0;

            foreach (var numButton in numButtons)
            {
                numButton.Enabled = digitsEntered < 4;
                num += 1;
            }

            DeleteImageButton.Enabled = digitsEntered > 0;
            Add5Button.Enabled        = newDuration.IsValid && newDuration.AddMinutes(5).IsValid;
            Add30Button.Enabled       = newDuration.IsValid && newDuration.AddMinutes(30).IsValid;
            OkButton.Enabled          = digitsEntered > 0 && newDuration.IsValid;
        }
Beispiel #20
0
        private void setCurrentScore()
        {
            var currentString     = score + " POINTS";
            var spanCurrentString = new SpannableString(currentString);

            spanCurrentString.SetSpan(new ForegroundColorSpan(Color.Rgb(203, 203, 203)), currentString.Length - 6, currentString.Length, 0);
            spanCurrentString.SetSpan(new ForegroundColorSpan(Color.Rgb(255, 255, 255)), 0, currentString.Length - 7, 0);
            spanCurrentString.SetSpan(new StyleSpan(TypefaceStyle.Normal), currentString.Length - 6, currentString.Length, 0);
            spanCurrentString.SetSpan(new StyleSpan(TypefaceStyle.Bold), 0, currentString.Length - 7, 0);
            txtTestScore.SetText(spanCurrentString, TextView.BufferType.Spannable);
        }
Beispiel #21
0
        private void setCurrentLevel()
        {
            var currentString     = "LEVEL " + level;
            var spanCurrentString = new SpannableString(currentString);

            spanCurrentString.SetSpan(new ForegroundColorSpan(Color.Rgb(203, 203, 203)), 0, 5, 0);
            spanCurrentString.SetSpan(new ForegroundColorSpan(Color.Rgb(255, 255, 255)), 6, currentString.Length, 0);
            spanCurrentString.SetSpan(new StyleSpan(TypefaceStyle.Normal), 0, 5, 0);
            spanCurrentString.SetSpan(new StyleSpan(TypefaceStyle.Bold), 6, currentString.Length, 0);
            txtTestLevel.SetText(spanCurrentString, TextView.BufferType.Spannable);
        }
Beispiel #22
0
        private void setCurrentCombo()
        {
            var currentString     = "COMBO X" + combo;
            var spanCurrentString = new SpannableString(currentString);

            spanCurrentString.SetSpan(new ForegroundColorSpan(Color.Rgb(203, 203, 203)), 0, 5, 0);
            spanCurrentString.SetSpan(new ForegroundColorSpan(Color.Rgb(255, 255, 255)), 6, currentString.Length, 0);
            spanCurrentString.SetSpan(new StyleSpan(TypefaceStyle.Normal), 0, 5, 0);
            spanCurrentString.SetSpan(new StyleSpan(TypefaceStyle.Bold), 6, currentString.Length, 0);
            txtYourCombo.SetText(spanCurrentString, TextView.BufferType.Spannable);
        }
Beispiel #23
0
        ISpannable GetTextColorized(string text, Color color)
        {
            var span = new SpannableString(text);

            if (text.Length > 4)
            {
                span.SetSpan(new TextAppearanceSpan(Context, Android.Resource.Style.TextAppearanceDeviceDefaultMedium), 0, text.Length, SpanTypes.ExclusiveExclusive);
            }
            span.SetSpan(new ForegroundColorSpan(color), 0, text.Length, SpanTypes.ExclusiveExclusive);

            return(span);
        }
        private void SetItemBindingsFling(View view, AnimeVideoData animeVideoData)
        {
            view.FindViewById(Resource.Id.PromoVideosPageItemImgPlaceholder).Visibility = ViewStates.Visible;
            view.FindViewById(Resource.Id.PromoVideosPageItemImage).Visibility          = ViewStates.Invisible;

            var str = new SpannableString($"{animeVideoData.Name} - {animeVideoData.AnimeTitle}");

            str.SetSpan(PrefixStyle, 0, animeVideoData.Name.Length, SpanTypes.InclusiveInclusive);
            str.SetSpan(PrefixColorStyle, 0, animeVideoData.Name.Length, SpanTypes.InclusiveInclusive);
            view.FindViewById <TextView>(Resource.Id.PromoVideosPageItemSubtitle)
            .SetText(str.SubSequenceFormatted(0, str.Length()), TextView.BufferType.Spannable);
        }
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            if (!isOnline())
            {
                mErrorDialog.Show();
                return;
            }
            SetContentView(Resource.Layout.activity_get_started);
            mLocationManager = GetSystemService(LocationService) as LocationManager;
            mTts             = new TextToSpeech(this, this, "com.google.android.tts");
            speech           = SpeechRecognizer.CreateSpeechRecognizer(this);
            speech.SetRecognitionListener(this);
            Criteria mLocationServiceCriteria = new Criteria
            {
                Accuracy         = Accuracy.Coarse,
                PowerRequirement = Power.Medium
            };
            IList <string> acceptableLocationProviders = mLocationManager.GetProviders(mLocationServiceCriteria, true);

            if (acceptableLocationProviders.Any())
            {
                mLocationProvider = acceptableLocationProviders.First();
            }
            else
            {
                mLocationProvider = string.Empty;
            }
            mSharedPreference = GetSharedPreferences(Constants.MY_PREF, 0);
            token             = mSharedPreference.GetString("token", " ");
            mEditor           = mSharedPreference.Edit();
            mLoadingDialog    = new LoadingDialog(this, Resource.Drawable.main);
            mLoadingDialog.SetCancelable(false);
            Window window = mLoadingDialog.Window;

            window.SetLayout(WindowManagerLayoutParams.MatchParent, WindowManagerLayoutParams.MatchParent);
            window.SetBackgroundDrawable(new ColorDrawable(Resources.GetColor(Resource.Color.trans)));
            SpannableString s = new SpannableString("Contoso Cabs");

            typeface = Typeface.CreateFromAsset(this.Assets, "JosefinSans-SemiBold.ttf");
            s.SetSpan(new TypefaceSpan("Amaranth-Regular.ttf"), 0, s.Length(), SpanTypes.ExclusiveExclusive);
            s.SetSpan(new ForegroundColorSpan(this.Resources.GetColor(Resource.Color.title)), 0, s.Length(), SpanTypes.ExclusiveExclusive);
            this.TitleFormatted = s;
            mGetStarted         = FindViewById <Button>(Resource.Id.btnGetStarted);
            mUri      = FindViewById <Button>(Resource.Id.btnuri);
            mSpeak    = FindViewById <ImageView>(Resource.Id.imagespeech);
            mTextView = FindViewById <TextView>(Resource.Id.bookText);
            mTextView.SetTypeface(typeface, TypefaceStyle.Normal);
            mGetStarted.SetTypeface(typeface, TypefaceStyle.Normal);
            mGetStarted.SetOnClickListener(this);
            mUri.SetOnClickListener(this);
            mSpeak.SetOnClickListener(this);
        }
Beispiel #26
0
        private void UpdateTokenValues(string currTokenOne, string nextTokenOne, string currTokenTwo, string nextTokenTwo)
        {
            _tokenValueOne = new SpannableString($"{currTokenOne} > {nextTokenOne}");
            _tokenValueOne.SetSpan(new ForegroundColorSpan(Style.R151G155B158), 0, currTokenOne.Length + 2, SpanTypes.ExclusiveExclusive);
            _tokenValueOne.SetSpan(new ForegroundColorSpan(Style.R255G34B5), currTokenOne.Length + 2, _tokenValueOne.Length(), SpanTypes.ExclusiveExclusive);
            _tokenOneValue.SetText(_tokenValueOne, TextView.BufferType.Spannable);

            _tokenValueTwo = new SpannableString($"{currTokenTwo} > {nextTokenTwo}");
            _tokenValueTwo.SetSpan(new ForegroundColorSpan(Style.R151G155B158), 0, currTokenTwo.Length + 2, SpanTypes.ExclusiveExclusive);
            _tokenValueTwo.SetSpan(new ForegroundColorSpan(Style.R255G34B5), currTokenTwo.Length + 2, _tokenValueTwo.Length(), SpanTypes.ExclusiveExclusive);
            _tokenTwoValue.SetText(_tokenValueTwo, TextView.BufferType.Spannable);
        }
        public void UpdateInputType()
        {
            if (Base == null || Control == null)
            {
                return;
            }

            if (Base == null || Control == null)
            {
                return;
            }

            if (Base.InputType == TextInputType.Phone)
            {
                SpannableString ss = new SpannableString(Control.Text);
                ss.SetSpan(new URLSpan("tel:" + Control.Text), 0, Control.Text.Length, SpanTypes.ExclusiveExclusive);

                Control.TextFormatted  = ss;
                Control.MovementMethod = LinkMovementMethod.Instance;
            }
            else if (Base.InputType == TextInputType.EmailAddress)
            {
                SpannableString ss = new SpannableString(Control.Text);
                ss.SetSpan(new URLSpan("mailto:" + Control.Text), 0, Control.Text.Length, SpanTypes.ExclusiveExclusive);

                Control.TextFormatted  = ss;
                Control.MovementMethod = LinkMovementMethod.Instance;
            }
            else if (Base.InputType == TextInputType.Website)
            {
                SpannableString ss = new SpannableString(Control.Text);
                ss.SetSpan(new ForegroundColorSpan(Base.TextColor.ToAndroid()), 0, Control.Text.Length, SpanTypes.ExclusiveExclusive);
                ss.SetSpan(new UnderlineSpan(), 0, Control.Text.Length, SpanTypes.ExclusiveExclusive);
                //ss.SetSpan(new URLSpan(Control.Text), 0, Control.Text.Length, SpanTypes.ExclusiveExclusive);

                int clickCounter = 0;

                Control.TextFormatted = ss;
                Control.Click        += (s, e) =>
                {
                    if (clickCounter > 0)
                    {
                        return;
                    }

                    Xamarin.Forms.Device.OpenUri(new System.Uri(Base.Text));

                    clickCounter += 1;
                };

                //Control.MovementMethod = LinkMovementMethod.Instance;
            }
        }
Beispiel #28
0
        protected override ISpannable GetFormattedString(string timeString, int lengthOfHours, bool isDisabled)
        {
            var color = isDisabled ? disabledColor : normalColor;

            var spannable   = new SpannableString(timeString);
            var hourSpanEnd = lengthOfHours + 3;

            spannable.SetSpan(new TypefaceSpan("sans-serif"), 0, hourSpanEnd, SpanTypes.InclusiveInclusive);
            spannable.SetSpan(new TypefaceSpan("sans-serif-light"), hourSpanEnd, hourSpanEnd + 3, SpanTypes.InclusiveInclusive);
            spannable.SetSpan(new ForegroundColorSpan(color), 0, spannable.Length(), SpanTypes.InclusiveInclusive);

            return(spannable);
        }
 private static void SetTextColor(SpannableString spendable, string texts, string color, float proportion = 0.9f)
 {
     try
     {
         string content = spendable.ToString();
         spendable.SetSpan(new ForegroundColorSpan(Color.ParseColor(color)), content.IndexOf(texts, StringComparison.Ordinal), /* content.IndexOf(texts, StringComparison.Ordinal) +*/ content.Length, SpanTypes.ExclusiveExclusive);
         spendable.SetSpan(new RelativeSizeSpan(proportion), content.IndexOf(texts, StringComparison.Ordinal), /*content.IndexOf(texts, StringComparison.Ordinal) +*/ content.Length, SpanTypes.ExclusiveExclusive);
     }
     catch (Exception e)
     {
         Console.WriteLine(e);
     }
 }
Beispiel #30
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            SetContentView(Resource.Layout.link);

            // text1 shows the android:autoLink property, which
            // automatically linkifies things like URLs and phone numbers
            // found in the text.  No java code is needed to make this
            // work.

            // text2 has links specified by putting <a> tags in the string
            // resource.  By default these links will appear but not
            // respond to user input.  To make them active, you need to
            // call setMovementMethod() on the TextView object.

            TextView t2 = (TextView)FindViewById(Resource.Id.text2);

            t2.MovementMethod = LinkMovementMethod.Instance;

            // text3 shows creating text with links from HTML in the Java
            // code, rather than from a string resource.  Note that for a
            // fixed string, using a (localizable) resource as shown above
            // is usually a better way to go; this example is intended to
            // illustrate how you might display text that came from a
            // dynamic source (eg, the network).

            //TextView t3 = (TextView)FindViewById (Resource.Id.text3);
            //t3.Text = Html.FromHtml(
            //        "<b>text3:</b>  Text with a " +
            //        "<a href=\"http://www.google.com\">link</a> " +
            //        "created in the Java source code using HTML.");

            //t3.MovementMethod = LinkMovementMethod.Instance;

            // text4 illustrates constructing a styled string containing a
            // link without using HTML at all.  Again, for a fixed string
            // you should probably be using a string resource, not a
            // hardcoded value.

            SpannableString ss = new SpannableString("text4: Click here to dial the phone.");

            ss.SetSpan(new StyleSpan(TypefaceStyle.Bold), 0, 6, SpanTypes.ExclusiveExclusive);
            ss.SetSpan(new URLSpan("tel:4155551212"), 13, 17, SpanTypes.ExclusiveExclusive);

            TextView t4 = (TextView)FindViewById(Resource.Id.text4);

            t4.TextFormatted  = ss;
            t4.MovementMethod = LinkMovementMethod.Instance;
        }
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate (savedInstanceState);

            SetContentView (Resource.Layout.link);

            // text1 shows the android:autoLink property, which
            // automatically linkifies things like URLs and phone numbers
            // found in the text.  No java code is needed to make this
            // work.

            // text2 has links specified by putting <a> tags in the string
            // resource.  By default these links will appear but not
            // respond to user input.  To make them active, you need to
            // call setMovementMethod() on the TextView object.

            TextView t2 = (TextView)FindViewById (Resource.Id.text2);
            t2.MovementMethod = LinkMovementMethod.Instance;

            // text3 shows creating text with links from HTML in the Java
            // code, rather than from a string resource.  Note that for a
            // fixed string, using a (localizable) resource as shown above
            // is usually a better way to go; this example is intended to
            // illustrate how you might display text that came from a
            // dynamic source (eg, the network).

            //TextView t3 = (TextView)FindViewById (Resource.Id.text3);
            //t3.Text = Html.FromHtml(
            //        "<b>text3:</b>  Text with a " +
            //        "<a href=\"http://www.google.com\">link</a> " +
            //        "created in the Java source code using HTML.");

            //t3.MovementMethod = LinkMovementMethod.Instance;

            // text4 illustrates constructing a styled string containing a
            // link without using HTML at all.  Again, for a fixed string
            // you should probably be using a string resource, not a
            // hardcoded value.

            SpannableString ss = new SpannableString ("text4: Click here to dial the phone.");

            ss.SetSpan (new StyleSpan (TypefaceStyle.Bold), 0, 6, SpanTypes.ExclusiveExclusive);
            ss.SetSpan (new URLSpan ("tel:4155551212"), 13, 17, SpanTypes.ExclusiveExclusive);

            TextView t4 = (TextView)FindViewById (Resource.Id.text4);

            t4.TextFormatted = ss;
            t4.MovementMethod = LinkMovementMethod.Instance;
        }
		public static SpannableString ToAttributed(this FormattedString formattedString, Font defaultFont, Color defaultForegroundColor, TextView view)
		{
			if (formattedString == null)
				return null;

			var builder = new StringBuilder();
			foreach (Span span in formattedString.Spans)
			{
				if (span.Text == null)
					continue;

				builder.Append(span.Text);
			}

			var spannable = new SpannableString(builder.ToString());

			var c = 0;
			foreach (Span span in formattedString.Spans)
			{
				if (span.Text == null)
					continue;

				int start = c;
				int end = start + span.Text.Length;
				c = end;

				if (span.ForegroundColor != Color.Default)
				{
					spannable.SetSpan(new ForegroundColorSpan(span.ForegroundColor.ToAndroid()), start, end, SpanTypes.InclusiveExclusive);
				}
				else if (defaultForegroundColor != Color.Default)
				{
					spannable.SetSpan(new ForegroundColorSpan(defaultForegroundColor.ToAndroid()), start, end, SpanTypes.InclusiveExclusive);
				}

				if (span.BackgroundColor != Color.Default)
				{
					spannable.SetSpan(new BackgroundColorSpan(span.BackgroundColor.ToAndroid()), start, end, SpanTypes.InclusiveExclusive);
				}

				if (!span.IsDefault())
#pragma warning disable 618 // We will need to update this when .Font goes away
					spannable.SetSpan(new FontSpan(span.Font, view), start, end, SpanTypes.InclusiveInclusive);
#pragma warning restore 618
				else if (defaultFont != Font.Default)
					spannable.SetSpan(new FontSpan(defaultFont, view), start, end, SpanTypes.InclusiveInclusive);
			}
			return spannable;
		}
		protected override void OnCreate (Bundle bundle)
		{
			base.OnCreate (bundle);

			var toggle_alarm_operation = new Intent (this, typeof(FindPhoneService));

			toggle_alarm_operation.SetAction(FindPhoneService.ACTION_TOGGLE_ALARM);
			var toggle_alarm_intent = PendingIntent.GetService (this, 0, toggle_alarm_operation, PendingIntentFlags.CancelCurrent);
			Android.App.Notification.Action alarm_action = new Android.App.Notification.Action (Resource.Drawable.alarm_action_icon, "", toggle_alarm_intent);
			var cancel_alarm_operation = new Intent (this, typeof(FindPhoneService));
			cancel_alarm_operation.SetAction (FindPhoneService.ACTION_CANCEL_ALARM);
			var cancel_alarm_intent = PendingIntent.GetService (this, 0, cancel_alarm_operation, PendingIntentFlags.CancelCurrent);
			var title = new SpannableString ("Find My Phone");
			title.SetSpan (new RelativeSizeSpan (0.85f), 0, title.Length(), SpanTypes.PointMark);
			notification = new Notification.Builder (this)
				.SetContentTitle (title)
				.SetContentText ("Tap to sound an alarm on phone")
				.SetSmallIcon (Resource.Drawable.ic_launcher)
				.SetVibrate (new long[]{ 0, 50 })
				.SetDeleteIntent (cancel_alarm_intent)
				.Extend (new Notification.WearableExtender ()
					.AddAction (alarm_action)
					.SetContentAction (0)
					.SetHintHideIcon (true))
				.SetLocalOnly (true)
				.SetPriority ((int)NotificationPriority.Max);
			((NotificationManager)GetSystemService (NotificationService))
				.Notify (FIND_PHONE_NOTIFICATION_ID, notification.Build ());

			Finish ();
		}
 protected override void OnCreate(Bundle savedInstanceState)
 {
     base.OnCreate(savedInstanceState);
     var st = new SpannableString("Test");
     st.SetSpan(new TypefaceSpan("Arial"), 0, st.Length(), SpanTypes.ExclusiveExclusive);
     ActionBar.TitleFormatted = st;
 }
		public static SpannableString ParseStringForKeywords(FragmentManager fragmentManager, int containerId, string str)
		{

			if (String.IsNullOrEmpty(str))
			{
				return new SpannableString("");
			}

			SpannableString spannableString = new SpannableString(str);

			List<Range> handles = RangedOfStringInString("@", str, str);
			if (handles.Count > 0)
			{
				for (int i = 0; i < handles.Count; i++)
				{
					ClickableSpan clickableSpan = new MyClickableSpan(str.Substring(handles[i].Start, handles[i].End), (string obj) =>
					{
						if (obj.IndexOf('@') == 0)
						{
							TenServiceHelper.GoToGuestProfile(fragmentManager, containerId, obj);
						}
					});
					spannableString.SetSpan(clickableSpan, handles[i].Start, handles[i].Start + handles[i].End, SpanTypes.ExclusiveExclusive);
				}
			}

			List<Range> hashes = RangedOfStringInString("#", str, str);
			if (hashes.Count > 0)
			{
				for (int i = 0; i < hashes.Count; i++)
				{
					ClickableSpan clickableSpan = new MyClickableSpan(str.Substring(hashes[i].Start, hashes[i].End), (string obj) =>
					{
						if (obj.IndexOf('#') == 0)
						{
							TenServiceHelper.GoToSearchTags(fragmentManager, containerId, obj);
						}
					});
					spannableString.SetSpan(clickableSpan, hashes[i].Start, hashes[i].Start + hashes[i].End, SpanTypes.ExclusiveExclusive);
				}
			}


			return spannableString;
		}
Beispiel #36
0
        public static SpannableString GetLettersMarked(List<string> markedLetters, bool capitalize)
        {
            var alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
            if (capitalize == false)
                alphabet = alphabet.ToLower();

            if (markedLetters == null)
                return new SpannableString(alphabet);

            var spannable = new SpannableString(alphabet);
            foreach (var letter in markedLetters)
            {
                var index = Letters.IndexOf(letter.ToUpper());
                spannable.SetSpan(new ForegroundColorSpan(Android.Graphics.Color.Red), index, index + 1, SpanTypes.ExclusiveExclusive);
            }

            return spannable;
        }
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
              this.SetContentView(Resource.Layout.activity_playground);

              //Show how to style the text of an existing TextView
              TextView tv1 = this.FindViewById<TextView>(Resource.Id.test1);
              new Iconics.IconicsBuilder().Ctx(this)
            .Style(new ForegroundColorSpan(Color.White), new BackgroundColorSpan(Color.Black), new RelativeSizeSpan(2f))
            .StyleFor("faw-adjust", new BackgroundColorSpan(Color.Red), new ForegroundColorSpan(Color.ParseColor("#33000000")), new RelativeSizeSpan(2f))
            .On(tv1)
            .Build();

              //You can also do some advanced stuff like setting an image within a text
              TextView tv2 = this.FindViewById<TextView>(Resource.Id.test5);
              SpannableString sb = new SpannableString(tv2.Text);

              IconicsDrawable d = new IconicsDrawable(this, FontAwesome.Icon.FawAndroid).SizeDp(48).PaddingDp(4);
              sb.SetSpan(new ImageSpan(d, SpanAlign.Bottom), 1, 2, SpanTypes.ExclusiveExclusive);
              tv2.Text = sb.ToString();

              //Set the icon of an ImageView (or something else) as drawable
              ImageView iv2 = this.FindViewById<ImageView>(Resource.Id.test2);
              iv2.SetImageDrawable(new IconicsDrawable(this, FontAwesome.Icon.FawThumbsOUp).SizeDp(48).Color(Color.ParseColor("#aaFF0000")).ContourWidthDp(1));

              //Set the icon of an ImageView (or something else) as bitmap
              ImageView iv3 = this.FindViewById<ImageView>(Resource.Id.test3);
              iv3.SetImageBitmap(new IconicsDrawable(this, new FontAwesome(), FontAwesome.Icon.FawAndroid).Color(Color.ParseColor("#deFF0000")).ToBitmap());

              //Show how to style the text of an existing button (NOT WORKING AT THE MOMENT)
              Button b4 = this.FindViewById<Button>(Resource.Id.test4);
              new Iconics.IconicsBuilder().Ctx(this)
            .Style(new BackgroundColorSpan(Color.Black))
            .Style(new RelativeSizeSpan(2f))
            .Style(new ForegroundColorSpan(Color.White))
            .On(b4)
            .Build();
        }
Beispiel #38
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;
			}
		}
Beispiel #39
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;
			}
		}
Beispiel #40
0
		/*public override long GetItemId (int position)
		{
			return _Posts [position].Id;
		}*/
		public static SpannableString BuildBackgroundColorSpan(SpannableString spannableString,
			String text, String searchString, Color color) {

			int indexOf = text.ToUpperInvariant().IndexOf(searchString.ToUpperInvariant());

			try {
				spannableString.SetSpan(new BackgroundColorSpan(color), indexOf,
					(indexOf + searchString.Length),SpanTypes.ExclusiveExclusive);
			} catch (Exception e) {

			}


			return spannableString;
		}
 public void SetClickAbleText(TextView textview,string alltext,string clickabletext,Action action)
 {
     textview.Clickable = true;
     SpannableString spanablestring = new SpannableString (alltext);
     if (alltext.IndexOf (clickabletext) != -1) {
         int i = alltext.IndexOf (clickabletext);
         Clickable cliclablespan = new Clickable (action);
         spanablestring.SetSpan (cliclablespan, i, i + clickabletext.Length, SpanTypes.ExclusiveExclusive);
         spanablestring.SetSpan (new ForegroundColorSpan(Resources.GetColor(Resource.Color.iosblue)), i, i + clickabletext.Length, SpanTypes.ExclusiveExclusive);
         spanablestring.SetSpan (new StyleSpan(TypefaceStyle.Bold), i, i + clickabletext.Length, SpanTypes.ExclusiveExclusive);
         spanablestring.SetSpan (new RelativeSizeSpan(1.1f), i, i + clickabletext.Length, SpanTypes.ExclusiveExclusive);
     }
     textview.TextFormatted = spanablestring;
     textview.MovementMethod = new LinkMovementMethod ();
 }
		//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;
		}
        private void Rebind ()
        {
            if (!enabled || DurationTextView == null)
                return;

            var durationShown = digitsEntered > 0 ? newDuration : oldDuration;
            var durationText = durationShown.ToString ();
            var durationSpannable = new SpannableString (durationText);
            durationSpannable.SetSpan (
                new ForegroundColorSpan (Color.LightGray),
                0, durationSpannable.Length (),
                SpanTypes.InclusiveExclusive);
            if (digitsEntered > 0) {
                // Divider
                var sepIdx = durationText.IndexOf (":", StringComparison.Ordinal);
                if (sepIdx >= 0) {
                    durationSpannable.SetSpan (
                        new ForegroundColorSpan (Color.Black),
                        sepIdx, sepIdx + 1,
                        SpanTypes.InclusiveExclusive);
                }
                // Color entered minutes
                durationSpannable.SetSpan (
                    new ForegroundColorSpan (Color.Black),
                    durationText.Length - (Math.Min (digitsEntered, 2)), durationText.Length,
                    SpanTypes.InclusiveExclusive);
                // Color entered hours
                if (digitsEntered > 2) {
                    durationSpannable.SetSpan (
                        new ForegroundColorSpan (Color.Black),
                        2 - (digitsEntered - 2), 2,
                        SpanTypes.InclusiveExclusive);
                }
            }
            DurationTextView.SetText (durationSpannable, TextView.BufferType.Spannable);

            int num = 0;
            foreach (var numButton in numButtons) {
                numButton.Enabled = digitsEntered < 4;
                num += 1;
            }

            DeleteImageButton.Enabled = digitsEntered > 0;
            Add5Button.Enabled = newDuration.IsValid && newDuration.AddMinutes (5).IsValid;
            Add30Button.Enabled = newDuration.IsValid && newDuration.AddMinutes (30).IsValid;
            OkButton.Enabled = digitsEntered > 0 && newDuration.IsValid;
        }
        public static SpannableString GetLettersMarked(List<string> markedLetters, bool capitalize)
        {
            var alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
            if (capitalize == false)
                alphabet = alphabet.ToLower();

            if (markedLetters == null)
                return new SpannableString(alphabet);

            var levelColor = Color.ParseColor(DataHolder.Current.CurrentLevel.Color);
            var spannable = new SpannableString(alphabet);
            foreach (var letter in markedLetters)
            {
                var index = Alphabet.Letters.IndexOf(letter.ToUpper());
                if (index > -1)
                {
                    spannable.SetSpan(new ForegroundColorSpan(levelColor), index, index + 1, SpanTypes.ExclusiveExclusive);
                }
            }

            return spannable;
        }
 SpannableString generateCenterSpannableText()
 {
     SpannableString s = new SpannableString("MPAndroidChart developed by Philipp Jahoda");
     s.SetSpan(new RelativeSizeSpan(1.7f), 0, 14, 0);
     s.SetSpan(new StyleSpan(TypefaceStyle.Normal), 14, s.Length() - 15, 0);
     s.SetSpan(new ForegroundColorSpan(Color.Gray), 14, s.Length() - 15, 0);
     s.SetSpan(new RelativeSizeSpan(.8f), 14, s.Length() - 15, 0);
     s.SetSpan(new StyleSpan(TypefaceStyle.Italic), s.Length() - 14, s.Length(), 0);
     s.SetSpan(new ForegroundColorSpan(ColorTemplate.HoloBlue), s.Length() - 14, s.Length(), 0);
     return s;
 }
        /// <summary>
        /// Build the spannable according to the computed text, meaning set the right font, color and size to the text and icon char index
        /// </summary>
        /// <param name="computedString"></param>
        private SpannableString BuildSpannableString(string computedString)
        {
            SpannableString span = new SpannableString(computedString);
            if (!string.IsNullOrEmpty(iconLabel.Icon))
            {
                //set icon
                span.SetSpan(new CustomTypefaceSpan("fontawesome", iconFont, iconLabel.IconColor.ToAndroid()),
                    computedString.IndexOf(iconLabel.Icon),
                    computedString.IndexOf(iconLabel.Icon) + iconLabel.Icon.Length,
                    SpanTypes.ExclusiveExclusive);
                //set icon size
                span.SetSpan(new AbsoluteSizeSpan((int)iconLabel.IconSize,true),
                     computedString.IndexOf(iconLabel.Icon),
                     computedString.IndexOf(iconLabel.Icon) + iconLabel.Icon.Length,
                     SpanTypes.ExclusiveExclusive);
                                

            }
            if (!string.IsNullOrEmpty(iconLabel.Text))
            {
                span.SetSpan(new CustomTypefaceSpan("", textFont, iconLabel.TextColor.ToAndroid()),
                     textStartIndex,
                     textStopIndex,
                     SpanTypes.ExclusiveExclusive);
                span.SetSpan(new AbsoluteSizeSpan((int)iconLabel.FontSize, true),
                    textStartIndex,
                     textStopIndex,
                    SpanTypes.ExclusiveExclusive);


            }

            return span;

        }
Beispiel #47
0
 public static void SetTextWithRouble(this TextView label, string text, RoubleType roubleType)
 {
     var textFormatted = new SpannableString(text + Roubles.GetRoubleSymbFor(roubleType));
     textFormatted.SetSpan(RoubleSpan, textFormatted.Length() - 1, textFormatted.Length(), SpanTypes.ExclusiveExclusive);
     label.TextFormatted = textFormatted;
 }
Beispiel #48
0
 public void SetTitle(string title)
 {
     if (title != null) {
         SpannableString ssbTitle = new SpannableString(title);
         ssbTitle.SetSpan(mTitleSpan, 0, ssbTitle.Length(), 0);
         mTitle = ssbTitle;
     }
 }
		void UpdateUITime (DateTime? date = null)
		{


			var dt = date.HasValue ? date.Value : DateTime.UtcNow.ToLocalTime ();

			wheelSeconds.SetProgress (dt.Second);

			//var fmt = "h:mm tt";
			var fmt = "h:mm";
			if (WearListenerService.Settings.Use24Clock)
				fmt = "H:mm";

			var str = dt.ToString (fmt).ToUpperInvariant ();

			var ss = new SpannableString (str);
			ss.SetSpan (new StyleSpan (Android.Graphics.TypefaceStyle.Bold), 0, str.IndexOf (':'), SpanTypes.ExclusiveExclusive);

			if (fmt.Contains (" ")) {
				var ttIndex = str.LastIndexOf (' ') + 1;

				ss.SetSpan (new ForegroundColorSpan (Android.Graphics.Color.Gray), ttIndex, ttIndex + 2, SpanTypes.ExclusiveExclusive);
				ss.SetSpan (new RelativeSizeSpan (0.8f), ttIndex, ttIndex + 2, SpanTypes.ExclusiveExclusive);
			}

			time.TextFormatted = ss;
		}
Beispiel #50
0
        private void PopulateView(View ev, PwEntry pw, int pos)
        {
            _entry = pw;
            _pos = pos;

            ImageView iv = (ImageView)ev.FindViewById(Resource.Id.entry_icon);
            bool isExpired = pw.Expires && pw.ExpiryTime < DateTime.Now;
            if (isExpired)
            {
                App.Kp2a.GetDb().DrawableFactory.AssignDrawableTo(iv, Resources, App.Kp2a.GetDb().KpDatabase, PwIcon.Expired, PwUuid.Zero);
            } else
            {
                App.Kp2a.GetDb().DrawableFactory.AssignDrawableTo(iv, Resources, App.Kp2a.GetDb().KpDatabase, pw.IconId, pw.CustomIconUuid);
            }

            String title = pw.Strings.ReadSafe(PwDefs.TitleField);
            var str = new SpannableString(title);

            if (isExpired)
            {
                str.SetSpan(new StrikethroughSpan(), 0, title.Length, SpanTypes.ExclusiveExclusive);
            }
            _textView.TextFormatted = str;

            if (_defaultTextColor == null)
                _defaultTextColor = _textView.TextColors.DefaultColor;

            if (_groupActivity.IsBeingMoved(_entry.Uuid))
            {
                int elementBeingMoved = Context.Resources.GetColor(Resource.Color.element_being_moved);
                _textView.SetTextColor(new Color(elementBeingMoved));
            }
            else
                _textView.SetTextColor(new Color((int)_defaultTextColor));

            String detail = pw.Strings.ReadSafe(PwDefs.UserNameField);

            if ((_showDetail == false) || (String.IsNullOrEmpty(detail)))
            {
                _textviewDetails.Visibility = ViewStates.Gone;
            }
            else
            {
                var strDetail = new SpannableString(detail);

                if (isExpired)
                {
                    strDetail.SetSpan(new StrikethroughSpan(), 0, detail.Length, SpanTypes.ExclusiveExclusive);
                }
                _textviewDetails.TextFormatted = strDetail;

                _textviewDetails.Visibility = ViewStates.Visible;
            }

            if ( (!_showGroupFullPath) || (!_isSearchResult) ) {
                _textgroupFullPath.Visibility = ViewStates.Gone;
            }

            else {
                String groupDetail = pw.ParentGroup.GetFullPath();

                var strGroupDetail = new SpannableString (groupDetail);

                if (isExpired) {
                    strGroupDetail.SetSpan (new StrikethroughSpan (), 0, groupDetail.Length, SpanTypes.ExclusiveExclusive);
                }
                _textgroupFullPath.TextFormatted = strGroupDetail;

                _textgroupFullPath.Visibility = ViewStates.Visible;
            }
        }
        // for mutiple clickable text
        public void SetClickAbleText(TextView textview,string alltext,Dictionary<string,Action> clickabletextsdic)
        {
            textview.Clickable = true;
            SpannableString spanablestring = new SpannableString (alltext);

            foreach(KeyValuePair<string, Action> entry in clickabletextsdic){
                string  clickabletext = entry.Key;
                Action  action = entry.Value;

                if (alltext.IndexOf (clickabletext) != -1) {
                    int m = alltext.IndexOf (clickabletext);
                    MutipleClickable cliclablespan = new MutipleClickable (action);
                    spanablestring.SetSpan (cliclablespan, m, m + clickabletext.Length, SpanTypes.ExclusiveExclusive);
                    spanablestring.SetSpan (new ForegroundColorSpan(Resources.GetColor(Resource.Color.iosblue)), m,m + clickabletext.Length, SpanTypes.ExclusiveExclusive);
                    spanablestring.SetSpan (new StyleSpan(TypefaceStyle.Bold), m, m + clickabletext.Length, SpanTypes.ExclusiveExclusive);
                    spanablestring.SetSpan (new RelativeSizeSpan(1.1f), m, m + clickabletext.Length, SpanTypes.ExclusiveExclusive);
                }
            }
            textview.TextFormatted = spanablestring;
            textview.MovementMethod = new LinkMovementMethod ();
        }
        //displays totem info
        private void SetInfo()
        {
            body.Text = _appController.CurrentTotem.body;
            if (hidden) {
                title_synonyms.Text = "...";
                body.Text = _appController.CurrentTotem.body.Replace(_appController.CurrentTotem.title, "...");
            } else {
                number.Text = _appController.CurrentTotem.number + ". ";

                Typeface Verveine = Typeface.CreateFromAsset(Assets, "fonts/Verveine W01 Regular.ttf");

                //code to get formatting right
                //title and synonyms are in the same TextView
                //font, size,... are given using spans
                if (_appController.CurrentTotem.synonyms != null) {
                    string titlestring = _appController.CurrentTotem.title;
                    string synonymsstring = " - " + _appController.CurrentTotem.synonyms + " ";

                    Typeface Din = Typeface.CreateFromAsset(Assets, "fonts/DINPro-Light.ttf");

                    ISpannable sp = new SpannableString(titlestring + synonymsstring);
                    sp.SetSpan(new CustomTypefaceSpan("sans-serif", Verveine, 0), 0, titlestring.Length, SpanTypes.ExclusiveExclusive);
                    sp.SetSpan(new CustomTypefaceSpan("sans-serif", Din, TypefaceStyle.Italic, ConvertDPToPixels(17)), titlestring.Length, titlestring.Length + synonymsstring.Length, SpanTypes.ExclusiveExclusive);

                    title_synonyms.TextFormatted = sp;
                } else {
                    title_synonyms.Text = _appController.CurrentTotem.title;
                    title_synonyms.SetTypeface(Verveine, 0);
                }
            }
        }
		void UpdateAccountUI ()
		{
			var text = state.ActiveAccount != null ? state.ActiveAccount.Username : GetAddAccountTitle ();

			var content = new SpannableString (text);
			content.SetSpan (new UnderlineSpan (), 0, text.Length, (SpanTypes)0);
			acctPicker.SetText (content, TextView.BufferType.Spannable);
		}
            public override void Decorate(CalendarCellView cellView, DateTime date)
            {
                var dateString = date.Day.ToString();
                var span = new SpannableString(dateString + "\ntitle");
                span.SetSpan(new RelativeSizeSpan(0.5f), 0, dateString.Length, SpanTypes.InclusiveExclusive);
				cellView.DayOfMonthTextView.TextFormatted = span;
            }
Beispiel #55
0
 public void SetDetails(string details)
 {
     if (details != null)
     {
         SpannableString ssbDetail = new SpannableString(details);
         ssbDetail.SetSpan(mDetailSpan, 0, ssbDetail.Length(), 0);
         mDetails = ssbDetail;
     }
 }
            private void Render(Marker marker, View view)
            {
                int badge;
                // Use the equals() method on a Marker to check for equals.  Do not use ==.
                if (marker.Equals(parent.mBrisbane)) {
                    badge = Resource.Drawable.badge_qld;
                } else if (marker.Equals(parent.mAdelaide)) {
                    badge = Resource.Drawable.badge_sa;
                } else if (marker.Equals(parent.mSydney)) {
                    badge = Resource.Drawable.badge_nsw;
                } else if (marker.Equals(parent.mMelbourne)) {
                    badge = Resource.Drawable.badge_victoria;
                } else if (marker.Equals(parent.mPerth)) {
                    badge = Resource.Drawable.badge_wa;
                } else {
                    // Passing 0 to setImageResource will clear the image view.
                    badge = 0;
                }
                ((ImageView) view.FindViewById (Resource.Id.badge)).SetImageResource (badge);

                String title = marker.Title;
                TextView titleUi = ((TextView) view.FindViewById (Resource.Id.title));
                if (title != null) {
                    // Spannable string allows us to edit the formatting of the text.
                    SpannableString titleText = new SpannableString (title);
                    SpanTypes st = (SpanTypes) 0;
                    // FIXME: this somehow rejects to compile
                    //titleText.SetSpan (new ForegroundColorSpan(Color.Red), 0, titleText.Length, st);
                    titleUi.TextFormatted = (titleText);
                } else {
                    titleUi.Text = ("");
                }

                String snippet = marker.Snippet;
                TextView snippetUi = ((TextView) view.FindViewById(Resource.Id.snippet));
                if (snippet != null) {
                    SpannableString snippetText = new SpannableString(snippet);
                    snippetText.SetSpan(new ForegroundColorSpan(Color.Magenta), 0, 10, 0);
                    snippetText.SetSpan(new ForegroundColorSpan(Color.Blue), 12, 21, 0);
                    snippetUi.TextFormatted = (snippetText);
                } else {
                    snippetUi.Text = ("");
                }
            }
        /// <summary>
        /// Build the spannable according to the computed text, meaning set the right font, color and size to the text and icon char index
        /// </summary>
        /// <param name="computedString"></param>
        /// <returns></returns>
        private SpannableString BuildSpannableString(string computedString)
        {
            SpannableString span = new SpannableString(computedString);
            //if there is an icon
            if (!string.IsNullOrEmpty(_iconButton.Icon))
            {
                //set icon
                span.SetSpan(new CustomTypefaceSpan("fontawesome", _iconFont, _helper.GetSpanColor(_iconButton.IconColor, Control.TextColors)),
                    computedString.IndexOf(_iconButton.Icon),
                    computedString.IndexOf(_iconButton.Icon) + _iconButton.Icon.Length,
                    SpanTypes.ExclusiveExclusive);
                //set icon size
                span.SetSpan(new AbsoluteSizeSpan((int)_iconButton.IconSize, true),
                     computedString.IndexOf(_iconButton.Icon),
                     computedString.IndexOf(_iconButton.Icon) + _iconButton.Icon.Length,
                     SpanTypes.ExclusiveExclusive);


            }
            //if there is text
            if (!string.IsNullOrEmpty(_iconButton.Text))
            {
                span.SetSpan(new CustomTypefaceSpan("", _textFont, _helper.GetSpanColor(_iconButton.TextColor, Control.TextColors)),
                     _textStartIndex,
                     _textStopIndex,
                     SpanTypes.ExclusiveExclusive);
                span.SetSpan(new AbsoluteSizeSpan((int)_iconButton.FontSize, true),
                    _textStartIndex,
                     _textStopIndex,
                    SpanTypes.ExclusiveExclusive);


            }

            return span;

        }