public override void Changed(UITextView textView) { Console.WriteLine("-----" + secureText); if (secureTextViewEntry) { string text = textView.Text; if (text.Length > 0) { if ("" == lastText) { secureText.DeleteCharacters(new NSRange(secureText.Length - 1, 1)); onlyPassword(); timer.Invalidate(); //base.Changed(textView); return; } else { NSString one = new NSString(text.Substring(text.Length - 1)); secureText.Append(one); NSMutableString temp = new NSMutableString(); for (int i = 0; i < secureText.Length - 1; i++) { temp.Append(new NSString("•")); } temp.Append(new NSString(secureText.ToString().Substring(secureText.ToString().Length - 1))); myTextView.Text = temp; //timer.Invalidate(); timer = NSTimer.CreateScheduledTimer(2, onlyPassword); } } else { secureText = new NSMutableString(); } //base.Changed(textView); } else { if (textView.Text.Length == 0) { secureText = new NSMutableString(); } else { secureText = new NSMutableString(); secureText.SetString(new NSString(textView.Text)); } timer.Invalidate(); //base.Changed(textView); } }
public void Replace() { using (var s = new NSMutableString(0)) { s.SetString((NSString)"Hello World"); var number = s.ReplaceOcurrences((NSString)"World", (NSString)"Xamarin", NSStringCompareOptions.CaseInsensitiveSearch, new NSRange(0, s.Length)); #if XAMCORE_2_0 Assert.That(number, Is.EqualTo((nuint)1), "Number of replacements"); #else Assert.That(number, Is.EqualTo(1), "Number of replacements"); #endif Assert.That(s.ToString(), Is.EqualTo("Hello Xamarin"), "replaced"); Assert.Throws <ArgumentOutOfRangeException> (delegate { s.ReplaceOcurrences((NSString)"Xamarin", (NSString)"World!", NSStringCompareOptions.CaseInsensitiveSearch, new NSRange(0, s.Length + 1)); }, "bad 1"); Assert.Throws <ArgumentOutOfRangeException> (delegate { s.ReplaceOcurrences((NSString)"Xamarin", (NSString)"World!", NSStringCompareOptions.CaseInsensitiveSearch, new NSRange(1, s.Length)); }, "bad 2"); } }
public static string GetPinyin(string input) { var output = new NSMutableString(); output.SetString(new NSString(input)); var dumy = new NSRange(); output.ApplyTransform(NSStringTransform.MandarinToLatin, false, new NSRange(0, output.Length), out dumy); return(output.ToString()); }
public void Insert() { using (var s = new NSMutableString(-1)) { s.SetString((NSString)"Hello World"); s.Insert((NSString)"!", s.Length); Assert.That(s.ToString(), Is.EqualTo("Hello World!"), "end"); Assert.Throws <ArgumentOutOfRangeException> (delegate { s.Insert((NSString)"@", -1); }, "negative"); Assert.Throws <ArgumentOutOfRangeException> (delegate { s.Insert((NSString)"oops", s.Length + 1); }, "out of range"); } }
public void Delete() { using (var s = new NSMutableString(0)) { s.SetString((NSString)"Hello World"); s.DeleteCharacters(new NSRange(5, 6)); Assert.That(s.ToString(), Is.EqualTo("Hello"), "deleetd"); Assert.Throws <ArgumentOutOfRangeException> (delegate { s.DeleteCharacters(new NSRange(0, s.Length + 1)); }, "bad 1"); Assert.Throws <ArgumentOutOfRangeException> (delegate { s.DeleteCharacters(new NSRange(1, s.Length)); }, "bad 2"); } }
private void HandleTextChange(object sender, EventArgs e) { UITextView customEditor = (UITextView)sender; if (customEditor.SecureTextEntry) { string text = customEditor.Text; if (text.Length > 0) { //If LastText is empty, that means deletion occured. if ("" == this.LastText) { //Delete the last character from the actual text this.SecureText.DeleteCharacters(new NSRange(this.SecureText.Length - 1, 1)); if (null != timer) { timer.Invalidate(); } return; } // If LastText is not empty, that means (a) new character(s) was/were entered. int lastTextLength = ((this.LastText.ToString()).Length); //Number of characters in LastText. if (lastTextLength > 1) { // If more than one character was entered (usually by pasting) int NewTextStartIndex = (text.Length - lastTextLength); string TempNewCharacters = text.Substring(NewTextStartIndex); // Get all the characters except the last character and add them to the secureText NSString NewCharacters = new NSString(TempNewCharacters.Substring(0, TempNewCharacters.Length - 1)); SecureText.Append(NewCharacters); } // Get and add the last character NSString LastCharacter = new NSString(text.Substring(text.Length - 1)); this.SecureText.Append(LastCharacter); // Change all characters to '●' except the last character NSMutableString temp = new NSMutableString(); for (int i = 0; i < this.SecureText.Length - 1; i++) { temp.Append(new NSString("●")); } // Add the last character as a plain text to the temp and set that into the editor. temp.Append(new NSString(this.SecureText.ToString().Substring(this.SecureText.ToString().Length - 1))); customEditor.Text = temp; if (null != this.timer) { this.timer.Invalidate(); } // Wait two seconds before changing the last character to '●'. this.timer = NSTimer.CreateScheduledTimer(2, ChangeToHidden); } else { this.SecureText = new NSMutableString(); } } else { // If the password is plain text, then initialize it to the secureText string. SecureText = new NSMutableString(); SecureText.SetString(new NSString(customEditor.Text)); if (null != timer) { this.timer.Invalidate(); } } CustomEditor ActualCustomEditor = (CustomEditor)Element; ActualCustomEditor.PlainText = SecureText.ToString(); }