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 void Show() { NSMutableString message = new NSMutableString(); NSIndexPath[] selected = appearAnimationsList.IndexPathsForSelectedItems(); if (selected.Length > 0) { NSIndexPath indexPath = selected [0]; message.Append(new NSString("Alert did ")); message.Append(new NSString(showAnimations.GetItem <NSString> ((uint)indexPath.Row))); message.Append(new NSString("\n")); } selected = hideAnimationsList.IndexPathsForSelectedItems(); if (selected.Length > 0) { NSIndexPath indexPath = selected [0]; message.Append(new NSString("It will ")); message.Append(new NSString(dismissAnimations.GetItem <NSString> ((uint)indexPath.Row))); message.Append(new NSString(" when close")); } alert.Message = message; alert.Show(true); }
public void setSecureTextViewEntry(bool _secureTextViewEntry) { secureTextViewEntry = _secureTextViewEntry; if (secureText.Length == 0) { return; } else { if (secureTextViewEntry) { //secret NSMutableString aaa = new NSMutableString(); for (int i = 0; i < secureText.Length; i++) { aaa.Append(new NSString("•")); } myTextView.Text = aaa; } else { //real word myTextView.Text = secureText; if (null != timer) { timer.Invalidate(); } } } Changed(myTextView); }
private void handleAuthorizationError(NSError authorizationError) { NSDictionary unauthorizedAPIInfo = (NSDictionary)authorizationError.UserInfo.ObjectForKey(WTAuthorizationRequestManager.WTUnauthorizedAppleiOSSDKAPIsKey); NSMutableString detailedAuthorizationErrorLogMessage = (NSMutableString) new NSString("The following authorization states do not meet the requirements:").MutableCopy(); NSMutableString missingAuthorizations = (NSMutableString) new NSString("In order to use the Wikitude SDK, please grant access to the following:").MutableCopy(); foreach (NSString unauthorizedAPIKey in unauthorizedAPIInfo.Keys) { NSNumber unauthorizedAPIValue = (NSNumber)unauthorizedAPIInfo.ObjectForKey(unauthorizedAPIKey); detailedAuthorizationErrorLogMessage.Append(new NSString("\n")); detailedAuthorizationErrorLogMessage.Append(unauthorizedAPIKey); detailedAuthorizationErrorLogMessage.Append(new NSString(" = ")); detailedAuthorizationErrorLogMessage.Append(WTAuthorizationRequestManager.StringFromAuthorizationStatusForUnauthorizedAppleiOSSDKAPI(unauthorizedAPIValue.Int32Value, unauthorizedAPIKey)); missingAuthorizations.Append(new NSString("\n *")); missingAuthorizations.Append(WTAuthorizationRequestManager.HumanReadableDescriptionForUnauthorizedAppleiOSSDKAPI(unauthorizedAPIKey)); } Console.WriteLine(detailedAuthorizationErrorLogMessage); UIAlertController settingsAlertController = UIAlertController.Create("Required API authorizations missing", missingAuthorizations, UIAlertControllerStyle.Alert); settingsAlertController.AddAction(UIAlertAction.Create("Open Settings", UIAlertActionStyle.Default, (UIAlertAction obj) => { UIApplication.SharedApplication.OpenUrl(new NSUrl(UIApplication.OpenSettingsUrlString)); })); settingsAlertController.AddAction(UIAlertAction.Create("NO", UIAlertActionStyle.Destructive, (UIAlertAction obj) => { })); this.PresentViewController(settingsAlertController, true, null); }
public static int ConnectDevice(this IEpos2BluetoothConnection This, NSMutableString target) { if (target == null) { throw new ArgumentNullException("target"); } return(global::ApiDefinition.Messaging.int_objc_msgSend_IntPtr(This.Handle, Selector.GetHandle("connectDevice:"), target.Handle)); }
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()); }
private void ChangeToHidden(object sender) { // Change all the text entered to '●' UITextView customEditor = this.UiTextViewForControl; this.timer.Invalidate(); NSMutableString temp = MakeHiddenText(); customEditor.Text = temp; }
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); } }
private NSMutableString MakeHiddenText() //Make string of '●''s for the text and return { NSMutableString temp = new NSMutableString(); for (int i = 0; i < this.SecureText.Length; i++) { temp.Append(new NSString("●")); } return(temp); }
private void onlyPassword() { //throw new NotImplementedException(); timer.Invalidate(); NSMutableString temp = new NSMutableString(); for (int i = 0; i < secureText.Length; i++) { temp.Append(new NSString("•")); } myTextView.Text = temp; }
private const string randomAlphabet = ""; // TODO: Add random alphabet chars #endregion Fields #region Methods public static NSString GetRandomNSString() { string alphabet = randomAlphabet; var alphabetLength = alphabet.Length; nint stringLength = 20; NSMutableString mstring = new NSMutableString(stringLength); for (var index = 0; index < stringLength; index++) { int randomIndex = new Random().Next(1, alphabetLength); mstring.Append(new NSString(alphabet[randomIndex].ToString())); } return mstring; }
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"); } }
private const string randomAlphabet = ""; // TODO: Add random alphabet chars public static NSString GetRandomNSString() { string alphabet = randomAlphabet; var alphabetLength = alphabet.Length; nint stringLength = 20; NSMutableString mstring = new NSMutableString(stringLength); for (var index = 0; index < stringLength; index++) { int randomIndex = new Random().Next(1, alphabetLength); mstring.Append(new NSString(alphabet[randomIndex].ToString())); } return(mstring); }
public virtual int ConnectDevice(NSMutableString target) { if (target == null) { throw new ArgumentNullException("target"); } if (IsDirectBinding) { return(global::ApiDefinition.Messaging.int_objc_msgSend_IntPtr(this.Handle, Selector.GetHandle("connectDevice:"), target.Handle)); } else { return(global::ApiDefinition.Messaging.int_objc_msgSendSuper_IntPtr(this.SuperHandle, Selector.GetHandle("connectDevice:"), target.Handle)); } }
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"); } }
public SbtResult SbtExecuteCommand(int opCode, string inXML, ref NSMutableString outXML, int scannerID) { if (inXML == null) { throw new ArgumentNullException("inXML"); } IntPtr outXMLValue = outXML.Handle; var nsinXML = NSString.CreateNative(inXML); SbtResult ret; ret = (SbtResult)global::ApiDefinition.ZebraMessaging.UInt32_objc_msgSend_int_IntPtr_ref_IntPtr_int(this.Handle, Selector.GetHandle("sbtExecuteCommand:aInXML:aOutXML:forScanner:"), opCode, nsinXML, ref outXMLValue, scannerID); NSString.ReleaseNative(nsinXML); outXML = Runtime.GetNSObject <NSMutableString> (outXMLValue); return(ret); }
private static NSString OK_QueryStringWithSignature(this NSDictionary self, NSString secretKey, NSString sigName) { var sigSource = new NSMutableString(); var queryString = new NSMutableString(); var sortedKeys = self.Keys.OrderBy((NSObject arg) => arg); foreach (var key in sortedKeys) { var @value = self[key] as NSString; sigSource.Append(NSString.LocalizedFormat(@"%@=%@\", key, value)); queryString.Append(NSString.LocalizedFormat(@"%@=%@&", key, value.OK_Encode())); } sigSource.Append(secretKey); queryString.Append(NSString.LocalizedFormat(@"%@=%@&", sigName, sigSource.OK_MD5())); return(queryString); }
private void HandleSecureEntryChange(object sender) { if (this.SecureText.Length > 0) { // If SecureTextEntry is true, hide text, else make plain text and clean the timer. UITextView customEditor = (UITextView)sender; if (customEditor.SecureTextEntry) { NSMutableString temp = MakeHiddenText(); customEditor.Text = temp; } else { customEditor.Text = this.SecureText; if (null != timer) { this.timer.Invalidate(); } } } }
public void Copy() { IntPtr nscopying = Runtime.GetProtocol("NSCopying"); Assert.That(nscopying, Is.Not.EqualTo(IntPtr.Zero), "NSCopying"); IntPtr nsmutablecopying = Runtime.GetProtocol("NSMutableCopying"); Assert.That(nsmutablecopying, Is.Not.EqualTo(IntPtr.Zero), "NSMutableCopying"); // NSObject does not conform to NSCopying using (var o = new NSObject()) { Assert.False(o.ConformsToProtocol(nscopying), "NSObject/NSCopying"); Assert.False(o.ConformsToProtocol(nsmutablecopying), "NSObject/NSMutableCopying"); } // NSNumber conforms to NSCopying - but not NSMutableCopying using (var n = new NSNumber(-1)) { Assert.True(n.ConformsToProtocol(nscopying), "NSNumber/NSCopying"); using (var xn = n.Copy()) { Assert.NotNull(xn, "NSNumber/Copy/NotNull"); Assert.AreSame(n, xn, "NSNumber/Copy/NotSame"); } Assert.False(n.ConformsToProtocol(nsmutablecopying), "NSNumber/NSMutableCopying"); } // NSMutableString conforms to NSCopying - but not NSMutableCopying using (var s = new NSMutableString(1)) { Assert.True(s.ConformsToProtocol(nscopying), "NSMutableString/NSCopying"); using (var xs = s.Copy()) { Assert.NotNull(xs, "NSMutableString/Copy/NotNull"); Assert.AreNotSame(s, xs, "NSMutableString/Copy/NotSame"); } Assert.True(s.ConformsToProtocol(nsmutablecopying), "NSMutableString/NSMutableCopying"); using (var xs = s.MutableCopy()) { Assert.NotNull(xs, "NSMutableString/MutableCopy/NotNull"); Assert.AreNotSame(s, xs, "NSMutableString/MutableCopy/NotSame"); } } }
public string ReplaceCharacters(string text, NSRange range, string newText) { if (text != null) { var strg = new NSString(text); var result = new NSMutableString(); result.Append(strg); var newContent = new NSString(newText); if (range.Length > 0) { result.Replace(range, newContent); return(text.Replace(text, newText)); } else { result.Insert(newContent, range.Location); return(result); } } return(string.Empty); }
public void Show(Object sender, EventArgs e) { NSMutableString message = new NSMutableString (); NSIndexPath[] selected = appearAnimationsList.IndexPathsForSelectedItems(); if (selected.Length > 0) { NSIndexPath indexPath = selected [0]; message.Append (new NSString("Alert did ")); message.Append(new NSString(showAnimations.GetItem<NSString> ((uint)indexPath.Row))); message.Append (new NSString("\n")); } selected = hideAnimationsList.IndexPathsForSelectedItems(); if (selected.Length > 0) { NSIndexPath indexPath = selected [0]; message.Append (new NSString ("It will ")); message.Append (new NSString(dismissAnimations.GetItem<NSString> ((uint)indexPath.Row))); message.Append (new NSString(" when close")); } alert.Message = message; alert.Show (true); }
private void DoRestoreEndian(NSMutableString str ) { NSRange range = new NSRange(0, (int) str.length()); NSString target = NSString.Create("\n"); if (m_endian == LineEndian.Windows) { NSString replacement = NSString.Create("\r\n"); str.replaceOccurrencesOfString_withString_options_range(target, replacement, Enums.NSLiteralSearch, range); } else if (m_endian == LineEndian.Mac) { NSString replacement = NSString.Create("\r"); str.replaceOccurrencesOfString_withString_options_range(target, replacement, Enums.NSLiteralSearch, range); } }
public TextViewDelegate(UITextView myTextView) { this.myTextView = myTextView; secureTextViewEntry = false; secureText = new NSMutableString(); }
public abstract SbtResult SbtExecuteCommand(int opCode, string inXML, ref NSMutableString outXML, int scannerID);
protected override void OnAttached() { SecureText = new NSMutableString(); ConfigureControl(); }
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(); } } }