Ejemplo n.º 1
0
        public static ICharSequence Parse(Context context, IList<IconFontDescriptorWrapper> iconFontDescriptors,
            ICharSequence text, TextView target)
        {
            context = context.ApplicationContext;

            // Analyse the text and replace {} blocks With the appropriate character
            // Retain all transformations in the accumulator
            var spannableBuilder = new SpannableStringBuilder(text);
            RecursivePrepareSpannableIndexes(context, text.ToString(), spannableBuilder, iconFontDescriptors, 0);
            var isAnimated = HasAnimatedSpans(spannableBuilder);

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

                ((IHasOnViewAttachListener) target).OnViewAttachListener =
                    new OnViewAttachListenerOnViewAttachListenerAnonymousInnerClassHelper(target);
            }
            else if (target is IHasOnViewAttachListener)
            {
                ((IHasOnViewAttachListener) target).OnViewAttachListener = null;
            }

            return spannableBuilder;
        }
 public override void AddView(View child, int index, ViewGroup.LayoutParams @params)
 {
     base.AddView(child, index, @params);
     if (child?.GetType() != typeof(EditText) || string.IsNullOrWhiteSpace(helperText?.ToString()))
     {
         return;
     }
     HelperText = helperText;
 }
 protected override FilterResults PerformFiltering(ICharSequence constraint)
 {
     var results = performFilteringHandler(constraint.ToString());
     return new FilterResults
     {
         Count = results.Size(),
         Values = results
     };
 }
            protected override FilterResults PerformFiltering(ICharSequence constraint)
            {
                var stringConstraint = constraint == null ? string.Empty : constraint.ToString();

                var count = _owner.SetConstraintAndWaitForDataChange(stringConstraint);

                return new FilterResults
                    {
                        Count = count
                    };
            }
        public override void OnAuthenticationError(FingerprintState errorCode, ICharSequence errString)
        {
            base.OnAuthenticationError(errorCode, errString);
            var message = errString != null ? errString.ToString() : string.Empty;
            var result = new FingerprintAuthenticationResult { Status = FingerprintAuthenticationResultStatus.Failed, ErrorMessage = message };

            if (errorCode == FingerprintState.ErrorLockout)
            {
                result.Status = FingerprintAuthenticationResultStatus.TooManyAttempts;
            }

            SetResultSafe(result);
        }
Ejemplo n.º 6
0
        public ICharSequence FilterFormatted(ICharSequence source, int start, int end, ISpanned dest, int dstart,
            int dend)
        {
            try
            {
                var val = dest.ToString().Insert(dstart, source.ToString());
                var input = int.Parse(val);
                if (IsInRange(_min, _max, input))
                    return null;
            }
            catch (Exception ex)
            {
            }

            return new String(string.Empty);
        }
        protected override FilterResults PerformFiltering(ICharSequence constraint)
        {
            string charString = constraint?.ToString()?.ToLower();

            if (string.IsNullOrWhiteSpace(charString))
            {
                _adapter.mDatasetFileted = _adapter.mDataset;
            }
            else
            {
                _adapter.mDatasetFileted = new List <SimpleSelectorItem>();
                _adapter.mDatasetFileted
                .AddRange(_adapter.mDataset
                          .Where(i => (i.Name != null && i.Name.ToLower().Contains(charString))));
            }

            FilterResults filterResults = new FilterResults();

            filterResults.Values = new JavaList <SimpleSelectorItem>(_adapter.mDatasetFileted);
            return(filterResults);
        }
Ejemplo n.º 8
0
 public override void OnAuthenticationHelp(FingerprintState helpCode, ICharSequence helpString)
 {
     _callback.OnFingerprintError(helpString.ToString());
 }
Ejemplo n.º 9
0
 public static ICharSequence ToLowerCase(ICharSequence text, CultureInfo locale)
 {
     if (text is UnescapedCharSequence)
     {
         char[] chars = text.ToString().ToLower(locale).ToCharArray();
         bool[] wasEscaped = ((UnescapedCharSequence)text).wasEscaped;
         return new UnescapedCharSequence(chars, wasEscaped, 0, chars.Length);
     }
     else
         return new UnescapedCharSequence(text.ToString().ToLower(locale));
 }
 public void OnTextChanged(ICharSequence cs, int arg1, int arg2,
         int arg3)
 {
     if (cs.Length() <= 0)
     {
         return;
     }
     string city = (poiSearchDemo.FindViewById<EditText>(Resource.Id.city)).Text;
     /**
      * 使用建议搜索服务获取建议列表,结果在OnSuggestionResult()中更新
      */
     poiSearchDemo.mSearch.SuggestionSearch(cs.ToString(), city);
 }
Ejemplo n.º 11
0
 protected override void OnTextChanged( ICharSequence text, int start, int lengthBefore, int lengthAfter )
 {
     base.OnTextChanged ( text, start, lengthBefore, lengthAfter );
     if ( !programmaticChange ) {
         fullText = text.ToString ( );
         isStale = true;
     }
 }
 public override void OnAuthenticationHelp(int helpMsgId, ICharSequence helpString)
 {
     Log.Debug(TAG, "OnAuthenticationHelp: {0}:`{1}`", helpString, helpMsgId);
     ReportScanFailure(helpMsgId, helpString.ToString());
 }
Ejemplo n.º 13
0
        /// <summary>
        /// replace with ignore case
        /// </summary>
        /// <param name="string">string to get replaced</param>
        /// <param name="sequence1">the old character sequence in lowercase</param>
        /// <param name="escapeChar">the new character to prefix sequence1 in return string.</param>
        /// <param name="locale"></param>
        /// <returns>the new <see cref="ICharSequence"/></returns>
        private static ICharSequence ReplaceIgnoreCase(ICharSequence @string,
            string sequence1, string escapeChar, CultureInfo locale)
        {
            if (escapeChar == null || sequence1 == null || @string == null)
                throw new NullReferenceException(); // LUCNENET TODO: ArgumentException...

            // empty string case
            int count = @string.Length;
            int sequence1Length = sequence1.Length;
            if (sequence1Length == 0)
            {
                StringBuilder result2 = new StringBuilder((count + 1)
                    * escapeChar.Length);
                result2.Append(escapeChar);
                for (int i = 0; i < count; i++)
                {
                    result2.Append(@string[i]);
                    result2.Append(escapeChar);
                }
                return result2.ToString().ToCharSequence();
            }

            // normal case
            StringBuilder result = new StringBuilder();
            char first = sequence1[0];
            int start = 0, copyStart = 0, firstIndex;
            while (start < count)
            {
                if ((firstIndex = @string.ToString().ToLower(locale).IndexOf(first,
                    start)) == -1)
                    break;
                bool found = true;
                if (sequence1.Length > 1)
                {
                    if (firstIndex + sequence1Length > count)
                        break;
                    for (int i = 1; i < sequence1Length; i++)
                    {
                        if (@string.ToString().ToLower(locale)[firstIndex + i] != sequence1[i])
                        {
                            found = false;
                            break;
                        }
                    }
                }
                if (found)
                {
                    result.Append(@string.ToString().Substring(copyStart, firstIndex - copyStart));
                    result.Append(escapeChar);
                    result.Append(@string.ToString().Substring(firstIndex,
                        (firstIndex + sequence1Length) - firstIndex));
                    copyStart = start = firstIndex + sequence1Length;
                }
                else
                {
                    start = firstIndex + 1;
                }
            }
            
            if (result.Length == 0 && copyStart == 0)
                return @string;
            result.Append(@string.ToString().Substring(copyStart));
            return result.ToString().ToCharSequence();
        }
Ejemplo n.º 14
0
 /// <summary>
 /// Add the given mapping. </summary>
 public virtual V Put(ICharSequence text, V value)
 {
     return(Put(text.ToString(), value)); // could be more efficient
 }
Ejemplo n.º 15
0
        public void OnInput(MaterialDialog p0, ICharSequence p1)
        {
            try
            {
                if (p1.Length() > 0)
                {
                    var strName = p1.ToString();

                    if (!Methods.CheckConnectivity())
                    {
                        Toast.MakeText(MainContext, MainContext.GetString(Resource.String.Lbl_CheckYourInternetConnection), ToastLength.Short)?.Show();
                    }
                    else
                    {
                        if (TypeClass == "Comment")
                        {
                            //TypeClass
                            var adapterGlobal = CommentActivity.GetInstance()?.MAdapter;
                            var dataGlobal    = adapterGlobal?.CommentList?.FirstOrDefault(a => a.Id == CommentObject?.Id);
                            if (dataGlobal != null)
                            {
                                dataGlobal.Text = strName;
                                var index = adapterGlobal.CommentList.IndexOf(dataGlobal);
                                if (index > -1)
                                {
                                    adapterGlobal.NotifyItemChanged(index);
                                }
                            }

                            var dataPost = WRecyclerView.GetInstance()?.NativeFeedAdapter?.ListDiffer?.Where(a => a.PostData?.Id == CommentObject.PostId).ToList();
                            if (dataPost?.Count > 0)
                            {
                                foreach (var post in dataPost)
                                {
                                    if (post.TypeView != PostModelType.CommentSection)
                                    {
                                        continue;
                                    }

                                    var dataComment = post.PostData.GetPostComments?.FirstOrDefault(a => a.Id == CommentObject?.Id);
                                    if (dataComment != null)
                                    {
                                        dataComment.Text = strName;
                                        var index = post.PostData.GetPostComments.IndexOf(dataComment);
                                        if (index > -1)
                                        {
                                            WRecyclerView.GetInstance()?.NativeFeedAdapter.NotifyItemChanged(index);
                                        }
                                    }
                                }
                            }

                            PollyController.RunRetryPolicyFunction(new List <Func <Task> > {
                                () => RequestsAsync.Comment.EditCommentAsync(CommentObject.Id, strName)
                            });
                        }
                        else if (TypeClass == "Reply")
                        {
                            //TypeClass
                            var adapterGlobal = ReplyCommentActivity.GetInstance()?.MAdapter;
                            var dataGlobal    = adapterGlobal?.ReplyCommentList?.FirstOrDefault(a => a.Id == CommentObject?.Id);
                            if (dataGlobal != null)
                            {
                                dataGlobal.Text = strName;
                                var index = adapterGlobal.ReplyCommentList.IndexOf(dataGlobal);
                                if (index > -1)
                                {
                                    adapterGlobal.NotifyItemChanged(index);
                                }
                            }

                            PollyController.RunRetryPolicyFunction(new List <Func <Task> > {
                                () => RequestsAsync.Comment.EditCommentAsync(CommentObject.Id, strName, "edit_reply")
                            });
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Methods.DisplayReportResultTrack(e);
            }
        }
Ejemplo n.º 16
0
 public override void SetText(ICharSequence text, BufferType type)
 {
     base.SetText(Iconify.Compute(Context, text.ToString(), this), BufferType.Normal);
 }
Ejemplo n.º 17
0
            protected override FilterResults PerformFiltering(ICharSequence constraint)
            {
                returnObj = new FilterResults();
                _results = new List<ListItem>();
                if (_adapter._originalData == null)
                    _adapter._originalData = _adapter.Items;

                if (constraint == null)
                    return returnObj;

                if (_adapter._originalData != null && _adapter._originalData.Any())
                {
                    var searchQuery = constraint.ToString ();

                    _results.AddRange(_adapter._originalData.Where(item => item.Name.ToLower().Contains(searchQuery.ToLower())));
                }

                // Nasty piece of .NET to Java wrapping, be careful with this!
                returnObj.Values = FromArray(_results.Select(item => item.ToJavaObject()).ToArray());
                returnObj.Count = _results.Count;

                constraint.Dispose();

                return returnObj;
            }
Ejemplo n.º 18
0
            protected override FilterResults PerformFiltering(ICharSequence constraint)
            {
                var returnObj = new FilterResults();
                var results = new List<CalendarItem>();
                _adapter._originalData = _adapter._originalData ?? _adapter._items;

                if (constraint == null) return returnObj;

                if (_adapter._originalData != null && _adapter._originalData.Any())
                {
                    // Compare constraint to all names lowercased.
                    // It they are contained they are added to results.
                    results.AddRange(
                        _adapter._originalData.Where(
                            item => item.Description.ToLower().Contains(constraint.ToString())));
                }

                // Nasty piece of .NET to Java wrapping, be careful with this!
                returnObj.Values = FromArray(results.Select(r => r.ToJavaObject()).ToArray());
                returnObj.Count = results.Count;

                constraint.Dispose();

                return returnObj;
            }
Ejemplo n.º 19
0
 public ICursor RunQuery(ICharSequence constraint)
 {
     Console.WriteLine(constraint);
     ICursor cursor = _db.FetchNote(constraint.ToString());
     return cursor;
 }
Ejemplo n.º 20
0
        public void OnSelection(MaterialDialog p0, View p1, int itemId, ICharSequence itemString)
        {
            try
            {
                if (itemString.ToString() == Context.GetText(Resource.String.Lbl_Voice_call))
                {
                    string timeNow       = DateTime.Now.ToString("hh:mm");
                    var    unixTimestamp = DateTimeOffset.UtcNow.ToUnixTimeSeconds();
                    string time          = Convert.ToString(unixTimestamp);

                    Intent intentVideoCall = new Intent(Context, typeof(TwilioVideoCallActivity));
                    if (AppSettings.UseAgoraLibrary && AppSettings.UseTwilioLibrary == false)
                    {
                        intentVideoCall = new Intent(Context, typeof(AgoraAudioCallActivity));
                        intentVideoCall.PutExtra("type", "Agora_audio_calling_start");
                    }
                    else if (AppSettings.UseAgoraLibrary == false && AppSettings.UseTwilioLibrary)
                    {
                        intentVideoCall = new Intent(Context, typeof(TwilioAudioCallActivity));
                        intentVideoCall.PutExtra("type", "Twilio_audio_calling_start");
                    }

                    intentVideoCall.PutExtra("UserID", DataUser.UserId);
                    intentVideoCall.PutExtra("avatar", DataUser.Avatar);
                    intentVideoCall.PutExtra("name", DataUser.Name);
                    intentVideoCall.PutExtra("time", timeNow);
                    intentVideoCall.PutExtra("CallID", time);
                    StartActivity(intentVideoCall);
                }
                else if (itemString.ToString() == Context.GetText(Resource.String.Lbl_Video_call))
                {
                    string timeNow       = DateTime.Now.ToString("hh:mm");
                    var    unixTimestamp = DateTimeOffset.UtcNow.ToUnixTimeSeconds();
                    string time          = Convert.ToString(unixTimestamp);

                    Intent intentVideoCall = new Intent(Context, typeof(TwilioVideoCallActivity));
                    if (AppSettings.UseAgoraLibrary && AppSettings.UseTwilioLibrary == false)
                    {
                        intentVideoCall = new Intent(Context, typeof(AgoraVideoCallActivity));
                        intentVideoCall.PutExtra("type", "Agora_video_calling_start");
                    }
                    else if (AppSettings.UseAgoraLibrary == false && AppSettings.UseTwilioLibrary)
                    {
                        intentVideoCall = new Intent(Context, typeof(TwilioVideoCallActivity));
                        intentVideoCall.PutExtra("type", "Twilio_video_calling_start");
                    }

                    intentVideoCall.PutExtra("UserID", DataUser.UserId);
                    intentVideoCall.PutExtra("avatar", DataUser.Avatar);
                    intentVideoCall.PutExtra("name", DataUser.Name);
                    intentVideoCall.PutExtra("time", timeNow);
                    intentVideoCall.PutExtra("CallID", time);
                    intentVideoCall.PutExtra("access_token", "YOUR_TOKEN");
                    intentVideoCall.PutExtra("access_token_2", "YOUR_TOKEN");
                    intentVideoCall.PutExtra("from_id", "0");
                    intentVideoCall.PutExtra("active", "0");
                    intentVideoCall.PutExtra("status", "0");
                    intentVideoCall.PutExtra("room_name", "TestRoom");
                    StartActivity(intentVideoCall);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
Ejemplo n.º 21
0
        public void OnSelection(MaterialDialog p0, View p1, int itemId, ICharSequence itemString)
        {
            try
            {
                string text = itemString.ToString();

                if (text == GetString(Resource.String.Lbl_Light))
                {
                    AppCompatDelegate.DefaultNightMode = AppCompatDelegate.ModeNightNo;
                    AppSettings.SetTabDarkTheme        = false;
                    MainSettings.SharedNightMode.Edit().PutString("Night_Mode_key", MainSettings.LightMode).Commit();

                    if (Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop)
                    {
                        Window.ClearFlags(WindowManagerFlags.TranslucentStatus);
                        Window.AddFlags(WindowManagerFlags.DrawsSystemBarBackgrounds);
                    }

                    Intent intent = new Intent(this, typeof(SplashScreenActivity));
                    intent.AddCategory(Intent.CategoryHome);
                    intent.SetAction(Intent.ActionMain);
                    intent.AddFlags(ActivityFlags.ClearTop | ActivityFlags.NewTask | ActivityFlags.ClearTask);
                    StartActivity(intent);
                    FinishAffinity();
                }
                else if (text == GetString(Resource.String.Lbl_Dark))
                {
                    AppCompatDelegate.DefaultNightMode = AppCompatDelegate.ModeNightYes;
                    AppSettings.SetTabDarkTheme        = true;
                    MainSettings.SharedNightMode.Edit().PutString("Night_Mode_key", MainSettings.DarkMode).Commit();

                    if (Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop)
                    {
                        Window.ClearFlags(WindowManagerFlags.TranslucentStatus);
                        Window.AddFlags(WindowManagerFlags.DrawsSystemBarBackgrounds);
                    }

                    Intent intent = new Intent(this, typeof(SplashScreenActivity));
                    intent.AddCategory(Intent.CategoryHome);
                    intent.SetAction(Intent.ActionMain);
                    intent.AddFlags(ActivityFlags.ClearTop | ActivityFlags.NewTask | ActivityFlags.ClearTask);
                    StartActivity(intent);
                    FinishAffinity();
                }
                else if (text == GetString(Resource.String.Lbl_SetByBattery))
                {
                    MainSettings.SharedNightMode.Edit().PutString("Night_Mode_key", MainSettings.DefaultMode).Commit();

                    if ((int)Build.VERSION.SdkInt >= 29)
                    {
                        AppCompatDelegate.DefaultNightMode = AppCompatDelegate.ModeNightFollowSystem;

                        var currentNightMode = Resources.Configuration.UiMode & UiMode.NightMask;
                        switch (currentNightMode)
                        {
                        case UiMode.NightNo:
                            // Night mode is not active, we're using the light theme
                            AppSettings.SetTabDarkTheme = false;
                            break;

                        case UiMode.NightYes:
                            // Night mode is active, we're using dark theme
                            AppSettings.SetTabDarkTheme = true;
                            break;
                        }
                    }
                    else
                    {
                        AppCompatDelegate.DefaultNightMode = AppCompatDelegate.ModeNightAuto;

                        var currentNightMode = Resources.Configuration.UiMode & UiMode.NightMask;
                        switch (currentNightMode)
                        {
                        case UiMode.NightNo:
                            // Night mode is not active, we're using the light theme
                            AppSettings.SetTabDarkTheme = false;
                            break;

                        case UiMode.NightYes:
                            // Night mode is active, we're using dark theme
                            AppSettings.SetTabDarkTheme = true;
                            break;
                        }

                        if (Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop)
                        {
                            Window.ClearFlags(WindowManagerFlags.TranslucentStatus);
                            Window.AddFlags(WindowManagerFlags.DrawsSystemBarBackgrounds);
                        }

                        Intent intent = new Intent(this, typeof(SplashScreenActivity));
                        intent.AddCategory(Intent.CategoryHome);
                        intent.SetAction(Intent.ActionMain);
                        intent.AddFlags(ActivityFlags.ClearTop | ActivityFlags.NewTask | ActivityFlags.ClearTask);
                        StartActivity(intent);
                        FinishAffinity();
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
Ejemplo n.º 22
0
 public Phoneme(ICharSequence phonemeText, LanguageSet languages)
 {
     this.phonemeText = new StringBuilder(phonemeText.ToString());
     this.languages   = languages;
 }
Ejemplo n.º 23
0
        private static ICharSequence EscapeTerm(ICharSequence term, CultureInfo locale)
        {
            if (term == null)
                return term;

            // Escape single Chars
            term = EscapeChar(term, locale);
            term = EscapeWhiteChar(term, locale);

            // Escape Parser Words
            for (int i = 0; i < escapableWordTokens.Length; i++)
            {
                if (escapableWordTokens[i].Equals(term.ToString(), StringComparison.OrdinalIgnoreCase))
                    return new StringCharSequenceWrapper("\\" + term);
            }
            return term;
        }
        protected override FilterResults PerformFiltering(ICharSequence constraint)
        {
            var results = new FilterResults();

            if (constraint == null || constraint.Length() == 0)
            {
                return(results);
            }

            var actualResults = new string[this.originalData.Count];
            var filteredTasks = this.originalData.Where(x => x.Name.ToUpper().Contains(constraint.ToString().ToUpper()));
            var names         = filteredTasks.Select(x => x.Name).ToArray();

            results.Values = names;
            results.Count  = names.Length;

            return(results);
        }
            public override void OnAuthenticationError(int errMsgId, ICharSequence errString)
            {
                // There are some situations where we don't care about the error. For example, 
                // if the user cancelled the scan, this will raise errorID #5. We don't want to
                // report that, we'll just ignore it as that event is a part of the workflow.
                bool reportError = (errMsgId == (int) FingerprintState.ErrorCanceled) &&
                                   !_fragment.ScanForFingerprintsInOnResume;

                string debugMsg = string.Format("OnAuthenticationError: {0}:`{1}`.", errMsgId, errString);

                if (_fragment.UserCancelledScan)
                {
                    string msg = _fragment.Resources.GetString(Resource.String.scan_cancelled_by_user);
                    ReportScanFailure(-1, msg);
                }
                else if (reportError)
                {
                    ReportScanFailure(errMsgId, errString.ToString());
                    debugMsg += " Reporting the error.";
                }
                else
                {
                    debugMsg += " Ignoring the error.";
                }
                Log.Debug(TAG, debugMsg);
            }
 protected override void PublishResults(ICharSequence constraint, FilterResults results)
 {
     publishResultsHandler(constraint.ToString(), results.Values as AbstractList);
 }
Ejemplo n.º 27
0
 public static String ToString(ICharSequence charSequence)
 {
     return charSequence.ToString();
 }
Ejemplo n.º 28
0
 public virtual BytesRef TextToBytesRef()
 {
     return(new BytesRef(text.ToString()));
 }
 protected override void OnTextChanged(ICharSequence text, int start, int before, int after)
 {
     base.OnTextChanged(text, start, before, after);
     if (_programmaticChange == false)
     {
         _fullText = text.ToString();
         _isStale = true;
     }
 }
Ejemplo n.º 30
0
        protected override FilterResults PerformFiltering(ICharSequence constraint)
        {
            var returnObj = new FilterResults();
            var results   = new List <Books>();

            if (_adapter.searchBooks == null)
            {
                _adapter.searchBooks = _adapter.originalBooks;
            }

            if (constraint == null)
            {
                return(returnObj);
            }

            if (_adapter.searchBooks != null && _adapter.searchBooks.Any())
            {
                // Compare constraint to all names lowercased.
                // It they are contained they are added to results.
                results.AddRange(
                    _adapter.searchBooks.Where(
                        book => ((book.Title != null) ? book.Title.ToLower().Contains(constraint.ToString()) : false) || ((book.Author != null) ? book.Author.ToLower().Contains(constraint.ToString()) : false)));
            }

            // Nasty piece of .NET to Java wrapping, be careful with this!
            returnObj.Values = FromArray(results.Select(r => r.ToJavaObject()).ToArray());
            returnObj.Count  = results.Count;

            constraint.Dispose();

            return(returnObj);
        }
Ejemplo n.º 31
0
        /// <summary>
        /// replace with ignore case
        /// </summary>
        /// <param name="string">string to get replaced</param>
        /// <param name="sequence1">the old character sequence in lowercase</param>
        /// <param name="escapeChar">the new character to prefix sequence1 in return string.</param>
        /// <param name="locale"></param>
        /// <returns>the new <see cref="ICharSequence"/></returns>
        /// <exception cref="ArgumentNullException"><paramref name="string"/>, <paramref name="sequence1"/>, or <paramref name="escapeChar"/> is <c>null</c>.</exception>
        private static ICharSequence ReplaceIgnoreCase(ICharSequence @string,
                                                       string sequence1, string escapeChar, CultureInfo locale)
        {
            // LUCENENET specific - changed from NullPointerException to ArgumentNullException (.NET convention)
            if (escapeChar is null)
            {
                throw new ArgumentNullException(nameof(escapeChar));
            }
            if (sequence1 is null)
            {
                throw new ArgumentNullException(nameof(sequence1));
            }
            if (@string is null)
            {
                throw new ArgumentNullException(nameof(@string));
            }
            if (locale is null)
            {
                throw new ArgumentNullException(nameof(locale));
            }

            // empty string case
            int count           = @string.Length;
            int sequence1Length = sequence1.Length;

            if (sequence1Length == 0)
            {
                StringBuilder result2 = new StringBuilder((count + 1)
                                                          * escapeChar.Length);
                result2.Append(escapeChar);
                for (int i = 0; i < count; i++)
                {
                    result2.Append(@string[i]);
                    result2.Append(escapeChar);
                }
                return(result2.ToString().AsCharSequence());
            }

            // normal case
            StringBuilder result = new StringBuilder();
            char          first = sequence1[0];
            int           start = 0, copyStart = 0, firstIndex;

            while (start < count)
            {
                if ((firstIndex = locale.TextInfo.ToLower(@string.ToString()).IndexOf(first,
                                                                                      start)) == -1)
                {
                    break;
                }
                bool found = true;
                if (sequence1.Length > 1)
                {
                    if (firstIndex + sequence1Length > count)
                    {
                        break;
                    }
                    for (int i = 1; i < sequence1Length; i++)
                    {
                        if (locale.TextInfo.ToLower(@string.ToString())[firstIndex + i] != sequence1[i])
                        {
                            found = false;
                            break;
                        }
                    }
                }
                if (found)
                {
                    result.Append(@string.ToString().Substring(copyStart, firstIndex - copyStart));
                    result.Append(escapeChar);
                    result.Append(@string.ToString().Substring(firstIndex,
                                                               (firstIndex + sequence1Length) - firstIndex));
                    copyStart = start = firstIndex + sequence1Length;
                }
                else
                {
                    start = firstIndex + 1;
                }
            }

            if (result.Length == 0 && copyStart == 0)
            {
                return(@string);
            }
            result.Append(@string.ToString().Substring(copyStart));
            return(result.ToString().AsCharSequence());
        }
Ejemplo n.º 32
0
        protected override void OnMeasure(int widthMeasureSpec, int heightMeasureSpec)
        {
            base.OnMeasure (widthMeasureSpec, heightMeasureSpec);
            return;

            _inMeasure = true;
            //base.OnMeasure (widthMeasureSpec, heightMeasureSpec);
            try {
                var availableWidth = MeasureSpec.GetSize (widthMeasureSpec) - CompoundPaddingLeft - CompoundPaddingRight;
                var availableHeight = MeasureSpec.GetSize (heightMeasureSpec) - CompoundPaddingTop - CompoundPaddingBottom;

                _originalText = GetOriginalText ();

                if (_originalText == null || _originalText.Length () == 0 || availableWidth <= 0) {
                    SetMeasuredDimension (widthMeasureSpec, heightMeasureSpec);
                    return;
                }

                var textPaint = Paint;
                var targetTextSize = _maxTextSize;
                var originalText = new Java.Lang.String (_originalText.ToString ());
                var finalText = originalText;

                var textSize = GetTextSize (originalText, textPaint, targetTextSize);
                var textExcedsBounds = textSize.Height () > availableHeight || textSize.Width () > availableWidth;

                if (_shrinkTextSize && textExcedsBounds) {
                    var heightMultiplier = availableHeight / (float)textSize.Height ();
                    var widthMultiplier = availableWidth / (float)textSize.Width ();
                    var multiplier = System.Math.Min (heightMultiplier, widthMultiplier);

                    targetTextSize = System.Math.Max (targetTextSize * multiplier, _minTextSize);

                    textSize = GetTextSize (finalText, textPaint, targetTextSize);
                }
                if (textSize.Width () > availableWidth) {
                    var modifiedText = new StringBuilder ();
                    var lines = originalText.Split (Java.Lang.JavaSystem.GetProperty ("line.separator"));
                    for (var i = 0; i < lines.Length; i++) {
                        modifiedText.Append (ResizeLine (textPaint, lines [i], availableWidth));
                        if (i != lines.Length - 1)
                            modifiedText.Append (Java.Lang.JavaSystem.GetProperty ("line.separator"));
                    }

                    finalText = new Java.Lang.String (modifiedText);
                    textSize = GetTextSize (finalText, textPaint, targetTextSize);
                }

                textPaint.TextSize = targetTextSize;

                var isMultiline = finalText.IndexOf ('\n') > -1;
                if (isMultiline) {
                    SetLineSpacing (LineSpacingExtra, LineSpacingMultiplierMultiline);
                    SetIncludeFontPadding (false);
                } else {
                    SetLineSpacing (LineSpacingExtra, LineSpacingMultiplierSingleline);
                    SetIncludeFontPadding (true);
                }

                Text = finalText + "\u200B";

                var measuredWidth = textSize.Width () + CompoundPaddingLeft + CompoundPaddingRight;
                var measureHeight = textSize.Height () + CompoundPaddingTop + CompoundPaddingBottom;

                measureHeight = System.Math.Max (measureHeight, MeasureSpec.GetSize (heightMeasureSpec));
                SetMeasuredDimension (measuredWidth, measureHeight);
            } finally {
                _inMeasure = false;

            }
        }