Ejemplo n.º 1
0
        //JAVA TO C# CONVERTER WARNING: 'final' parameters are not available in .NET:
        //ORIGINAL LINE: public static CharSequence parse(android.content.Context context, java.util.List<IconFontDescriptorWrapper> iconFontDescriptors, CharSequence text, final android.widget.TextView target)
        public static CharSequence parse(Context context, IList<IconFontDescriptorWrapper> iconFontDescriptors, CharSequence text, TextView target)
        {
            context = context.ApplicationContext;

            // Analyse the text and replace {} blocks with the appropriate character
            // Retain all transformations in the accumulator
            //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
            //ORIGINAL LINE: final android.text.SpannableStringBuilder spannableBuilder = new android.text.SpannableStringBuilder(text);
            SpannableStringBuilder spannableBuilder = new SpannableStringBuilder(text);
            recursivePrepareSpannableIndexes(context, text.ToString(), spannableBuilder, iconFontDescriptors, 0);
            bool isAnimated = hasAnimatedSpans(spannableBuilder);

            // If animated, periodically invalidate the TextView so that the
            // CustomTypefaceSpan can redraw itself
            if (isAnimated)
            {
                if (target == null)
                {
                    throw new System.ArgumentException("You can't use \"spin\" without providing the target TextView.");
                }
                if (!(target is HasOnViewAttachListener))
                {
                    throw new System.ArgumentException(target.GetType().Name + " does not implement " + "HasOnViewAttachListener. Please use IconTextView, IconButton or IconToggleButton.");
                }

                ((HasOnViewAttachListener) target).OnViewAttachListener = new HasOnViewAttachListener_OnViewAttachListenerAnonymousInnerClassHelper(target);

            }
            else if (target is HasOnViewAttachListener)
            {
                ((HasOnViewAttachListener) target).OnViewAttachListener = null;
            }

            return spannableBuilder;
        }
Ejemplo n.º 2
0
        private static void recursivePrepareSpannableIndexes(Context context, string fullText, SpannableStringBuilder text, IList<IconFontDescriptorWrapper> iconFontDescriptors, int start)
        {
            // Try to find a {...} in the string and extract expression from it
            string stringText = text.ToString();
            int startIndex = stringText.IndexOf("{", start, StringComparison.Ordinal);
            if (startIndex == -1)
            {
                return;
            }
            int endIndex = stringText.IndexOf("}", startIndex, StringComparison.Ordinal) + 1;
            string expression = stringText.Substring(startIndex + 1, endIndex - 1 - (startIndex + 1));

            // Split the expression and retrieve the icon key
            string[] strokes = expression.Split(" ", true);
            string key = strokes[0];

            // Loop through the descriptors to find a key match
            IconFontDescriptorWrapper iconFontDescriptor = null;
            Icon icon = null;
            for (int i = 0; i < iconFontDescriptors.Count; i++)
            {
                iconFontDescriptor = iconFontDescriptors[i];
                icon = iconFontDescriptor.getIcon(key);
                if (icon != null)
                {
                    break;
                }
            }

            // If no match, ignore and continue
            if (icon == null)
            {
                recursivePrepareSpannableIndexes(context, fullText, text, iconFontDescriptors, endIndex);
                return;
            }

            // See if any more stroke within {} should be applied
            float iconSizePx = -1;
            int iconColor = int.MaxValue;
            float iconSizeRatio = -1;
            bool spin = false;
            for (int i = 1; i < strokes.Length; i++)
            {
                string stroke = strokes[i];

                // Look for "spin"
                if (stroke.Equals("spin", StringComparison.CurrentCultureIgnoreCase))
                {
                    spin = true;
                }

                // Look for an icon size
                else if (stroke.matches("([0-9]*(\\.[0-9]*)?)dp"))
                {
                    iconSizePx = dpToPx(context, Convert.ToSingle(stroke.Substring(0, stroke.Length - 2)));
                }
                else if (stroke.matches("([0-9]*(\\.[0-9]*)?)sp"))
                {
                    iconSizePx = spToPx(context, Convert.ToSingle(stroke.Substring(0, stroke.Length - 2)));
                }
                else if (stroke.matches("([0-9]*)px"))
                {
                    iconSizePx = Convert.ToInt32(stroke.Substring(0, stroke.Length - 2));
                }
                else if (stroke.matches("@dimen/(.*)"))
                {
                    iconSizePx = getPxFromDimen(context, stroke.Substring(7));
                    if (iconSizePx < 0)
                    {
                        throw new System.ArgumentException("Unknown resource " + stroke + " in \"" + fullText + "\"");
                    }
                }
                else if (stroke.matches("([0-9]*(\\.[0-9]*)?)%"))
                {
                    iconSizeRatio = Convert.ToSingle(stroke.Substring(0, stroke.Length - 1)) / 100f;
                }

                // Look for an icon color
                else if (stroke.matches("#([0-9A-Fa-f]{6}|[0-9A-Fa-f]{8})"))
                {
                    iconColor = Color.parseColor(stroke);
                }
                else if (stroke.matches("@color/(.*)"))
                {
                    iconColor = getColorFromResource(context, stroke.Substring(7));
                    if (iconColor == int.MaxValue)
                    {
                        throw new System.ArgumentException("Unknown resource " + stroke + " in \"" + fullText + "\"");
                    }
                }
                else
                {
                    throw new System.ArgumentException("Unknown expression " + stroke + " in \"" + fullText + "\"");
                }

            }

            // Replace the character and apply the typeface
            text = text.replace(startIndex, endIndex, "" + icon.character());
            text.setSpan(new CustomTypefaceSpan(icon, iconFontDescriptor.getTypeface(context), iconSizePx, iconSizeRatio, iconColor, spin), startIndex, startIndex + 1, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
            recursivePrepareSpannableIndexes(context, fullText, text, iconFontDescriptors, startIndex);
        }
Ejemplo n.º 3
0
		private java.lang.CharSequence getDecoratedHint(java.lang.CharSequence hintText)
		{
			// If the field is always expanded, then don't add the search icon to the hint
			if (!mIconifiedByDefault)
			{
				return hintText;
			}
			android.text.SpannableStringBuilder ssb = new android.text.SpannableStringBuilder
				(java.lang.CharSequenceProxy.Wrap("   "));
			// for the icon
			ssb.append(hintText);
			android.graphics.drawable.Drawable searchIcon = getContext().getResources().getDrawable
				(getSearchIconId());
			int textSize = (int)(mQueryTextView.getTextSize() * 1.25);
			searchIcon.setBounds(0, 0, textSize, textSize);
			ssb.setSpan(new android.text.style.ImageSpan(searchIcon), 1, 2, android.text.SpannedClass.SPAN_EXCLUSIVE_EXCLUSIVE
				);
			return ssb;
		}
Ejemplo n.º 4
0
 private static bool hasAnimatedSpans(SpannableStringBuilder spannableBuilder)
 {
     CustomTypefaceSpan[] spans = spannableBuilder.getSpans(0, spannableBuilder.length(), typeof(CustomTypefaceSpan));
     foreach (CustomTypefaceSpan span in spans)
     {
         if (span.Animated)
         {
             return true;
         }
     }
     return false;
 }
Ejemplo n.º 5
0
		public virtual java.lang.CharSequence filter(java.lang.CharSequence source, int start
			, int end, android.text.Spanned dest, int dstart, int dend)
		{
			onStart();
			{
				// Scan through beginning characters in dest, calling onInvalidCharacter() 
				// for each invalid character.
				for (int i = 0; i < dstart; i++)
				{
					char c = dest[i];
					if (!isAllowed(c))
					{
						onInvalidCharacter(c);
					}
				}
			}
			// Scan through changed characters rejecting disallowed chars
			android.text.SpannableStringBuilder modification = null;
			int modoff = 0;
			{
				for (int i_1 = start; i_1 < end; i_1++)
				{
					char c = source[i_1];
					if (isAllowed(c))
					{
						// Character allowed.
						modoff++;
					}
					else
					{
						if (mAppendInvalid)
						{
							modoff++;
						}
						else
						{
							if (modification == null)
							{
								modification = new android.text.SpannableStringBuilder(source, start, end);
								modoff = i_1 - start;
							}
							modification.delete(modoff, modoff + 1);
						}
						onInvalidCharacter(c);
					}
				}
			}
			{
				// Scan through remaining characters in dest, calling onInvalidCharacter() 
				// for each invalid character.
				for (int i_2 = dend; i_2 < dest.Length; i_2++)
				{
					char c = dest[i_2];
					if (!isAllowed(c))
					{
						onInvalidCharacter(c);
					}
				}
			}
			onStop();
			// Either returns null if we made no changes,
			// or what we wanted to change it to if there were changes.
			return modification;
		}
Ejemplo n.º 6
0
 private static int appendQuotedText(android.text.SpannableStringBuilder s, int i,
                                     int len)
 {
     throw new System.NotImplementedException();
 }
Ejemplo n.º 7
0
		public void setDefaultKeyMode(int mode)
		{
			mDefaultKeyMode = mode;
			switch (mode)
			{
				case DEFAULT_KEYS_DISABLE:
				case DEFAULT_KEYS_SHORTCUT:
				{
					mDefaultKeySsb = null;
					break;
				}

				case DEFAULT_KEYS_DIALER:
				case DEFAULT_KEYS_SEARCH_LOCAL:
				case DEFAULT_KEYS_SEARCH_GLOBAL:
				{
					mDefaultKeySsb = new android.text.SpannableStringBuilder();
					android.text.Selection.setSelection(mDefaultKeySsb, 0);
					break;
				}

				default:
				{
					throw new System.ArgumentException();
				}
			}
		}
Ejemplo n.º 8
0
        public virtual java.lang.CharSequence filter(java.lang.CharSequence source, int start
                                                     , int end, android.text.Spanned dest, int dstart, int dend)
        {
            onStart();
            {
                // Scan through beginning characters in dest, calling onInvalidCharacter()
                // for each invalid character.
                for (int i = 0; i < dstart; i++)
                {
                    char c = dest[i];
                    if (!isAllowed(c))
                    {
                        onInvalidCharacter(c);
                    }
                }
            }
            // Scan through changed characters rejecting disallowed chars
            android.text.SpannableStringBuilder modification = null;
            int modoff = 0;

            {
                for (int i_1 = start; i_1 < end; i_1++)
                {
                    char c = source[i_1];
                    if (isAllowed(c))
                    {
                        // Character allowed.
                        modoff++;
                    }
                    else
                    {
                        if (mAppendInvalid)
                        {
                            modoff++;
                        }
                        else
                        {
                            if (modification == null)
                            {
                                modification = new android.text.SpannableStringBuilder(source, start, end);
                                modoff       = i_1 - start;
                            }
                            modification.delete(modoff, modoff + 1);
                        }
                        onInvalidCharacter(c);
                    }
                }
            }
            {
                // Scan through remaining characters in dest, calling onInvalidCharacter()
                // for each invalid character.
                for (int i_2 = dend; i_2 < dest.Length; i_2++)
                {
                    char c = dest[i_2];
                    if (!isAllowed(c))
                    {
                        onInvalidCharacter(c);
                    }
                }
            }
            onStop();
            // Either returns null if we made no changes,
            // or what we wanted to change it to if there were changes.
            return(modification);
        }
Ejemplo n.º 9
0
 private static void endHeader(android.text.SpannableStringBuilder text)
 {
     throw new System.NotImplementedException();
 }
Ejemplo n.º 10
0
 private static void startA(android.text.SpannableStringBuilder text, org.xml.sax.Attributes
                            attributes)
 {
     throw new System.NotImplementedException();
 }
Ejemplo n.º 11
0
 private static void startImg(android.text.SpannableStringBuilder text, org.xml.sax.Attributes
                              attributes, android.text.Html.ImageGetter img)
 {
     throw new System.NotImplementedException();
 }
Ejemplo n.º 12
0
 private static void end(android.text.SpannableStringBuilder text, System.Type kind
                         , object repl)
 {
     throw new System.NotImplementedException();
 }
Ejemplo n.º 13
0
 private static void start(android.text.SpannableStringBuilder text, object mark)
 {
     throw new System.NotImplementedException();
 }