/// <summary> /// FIx uripath for 5.0.2 new Gallery Picker Error /// see https://forums.xamarin.com/discussion/43908/issue-with-xlabs-mediapicker-selectpicture-and-selectvideo /// </summary> /// <param name="uriPath"></param> /// <returns>if result != null uri is fixed</returns> private static Uri FixUri(string uriPath) { //remove /ACTUAL if (uriPath.Contains("/ACTUAL")) { uriPath = uriPath.Substring(0, uriPath.IndexOf("/ACTUAL", StringComparison.Ordinal)); } Java.Util.Regex.Pattern pattern = Java.Util.Regex.Pattern.Compile("(content://media/.*\\d)"); if (uriPath.Contains("content")) { Matcher matcher = pattern.Matcher(uriPath); if (matcher.Find()) { return(Uri.Parse(matcher.Group(1))); } else { throw new IllegalArgumentException("Cannot handle this URI"); } } else { return(null); } }
public System.String DecodeFromNonLossyAscii(System.String original) { Java.Util.Regex.Pattern UNICODE_HEX_PATTERN = Java.Util.Regex.Pattern.Compile("\\\\u([0-9A-Fa-f]{4})"); Java.Util.Regex.Pattern UNICODE_OCT_PATTERN = Java.Util.Regex.Pattern.Compile("\\\\([0 - 7]{3})"); Matcher matcher = UNICODE_HEX_PATTERN.Matcher(original); StringBuffer charBuffer = new StringBuffer(original.Length); while (matcher.Find()) { System.String match = matcher.Group(1); char unicodeChar = (char)Integer.ParseInt(match, 16); matcher.AppendReplacement(charBuffer, Character.ToString(unicodeChar)); } matcher.AppendTail(charBuffer); System.String parsedUnicode = charBuffer.ToString(); matcher = UNICODE_OCT_PATTERN.Matcher(parsedUnicode); charBuffer = new StringBuffer(parsedUnicode.Length); while (matcher.Find()) { System.String match = matcher.Group(1); char unicodeChar = (char)Integer.ParseInt(match, 8); matcher.AppendReplacement(charBuffer, Character.ToString(unicodeChar)); } matcher.AppendTail(charBuffer); return(charBuffer.ToString()); }
private string Validate(MyValidationType validationType, string data, ref bool didError) { if (validationType == MyValidationType.Username) { Java.Util.Regex.Pattern p = Pattern.Compile(UsernameRegex); Matcher m = p.Matcher(data); if (!(m.Matches())) { didError = true; return(UsernameRegexError); } else { return(UsernameRegexSuccess); } } else if (validationType == MyValidationType.Password) { Java.Util.Regex.Pattern p = Pattern.Compile(PasswordRegex); Matcher m = p.Matcher(data); if (!(m.Matches() && ContainsLetter(data) && ContainsNumber(data) && NoRepeatingSequence(data))) { didError = true; return(PasswordRegexError); } else { return(PasswordRegexSuccess); } } else { throw new System.Exception(string.Format("Invalid ValidationType in CreateUserActivity.Validate: {0}", validationType)); } }
private List <StTools.XAutoLinkItem> MatchedRanges(ICharSequence text) { try { List <StTools.XAutoLinkItem> autoLinkItems = new List <StTools.XAutoLinkItem>(); if (AutoLinkModes == null) { Init(Context); //throw new NullPointerException("Please add at least one mode"); } foreach (StTools.XAutoLinkMode anAutoLinkMode in AutoLinkModes) { Console.WriteLine("Run foreach MatchedRanges => 175"); string regex = StTools.XUtils.GetRegexByAutoLinkMode(anAutoLinkMode, CustomRegex); if (regex.Length <= 0) { continue; } Pattern pattern = Pattern.Compile(regex); Matcher matcher = pattern.Matcher(text); if (anAutoLinkMode == StTools.XAutoLinkMode.ModePhone) { while (matcher.Find()) { Console.WriteLine("Run while MatchedRanges => 186"); StTools.XAutoLinkItem ss = new StTools.XAutoLinkItem(matcher.Start(), matcher.End(), matcher.Group(), anAutoLinkMode, UserId); if (matcher.Group().Length > MinPhoneNumberLength) { autoLinkItems.Add(ss); } } } else { while (matcher.Find()) { Console.WriteLine("Run while MatchedRanges => 199"); autoLinkItems.Add(new StTools.XAutoLinkItem(matcher.Start(), matcher.End(), matcher.Group(), anAutoLinkMode, UserId)); } } } return(autoLinkItems); } catch (Exception e) { Methods.DisplayReportResultTrack(e); return(new List <StTools.XAutoLinkItem>()); } }
public static bool IsIpTefValid(string ipserver) { Console.WriteLine(ipserver); Java.Util.Regex.Pattern p = Java.Util.Regex.Pattern.Compile(@"\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b"); Matcher m = p.Matcher(ipserver); bool b = m.Matches(); return(b); }
private bool isValidEmail(String email) { String EMAIL_PATTERN = "^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@" + "[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$"; Java.Util.Regex.Pattern pattern = Java.Util.Regex.Pattern.Compile(EMAIL_PATTERN); Matcher matcher = pattern.Matcher(email); return(matcher.Matches()); }
private bool ContainsNumber(string data) { Java.Util.Regex.Pattern p = Pattern.Compile(ContainsNumberRegex); Matcher m = p.Matcher(data); if (m.Matches()) { return(true); } return(false); }
public bool validaIp(string ipserver) { Java.Util.Regex.Pattern p = Java.Util.Regex.Pattern.Compile("^([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\." + "([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\." + "([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\." + "([01]?\\d\\d?|2[0-4]\\d|25[0-5])$"); Matcher m = p.Matcher(ipserver); bool b = m.Matches(); Console.WriteLine(b); return(b); }
/// <summary> /// Filter strings based on regular expressions. /// </summary> /// <param name="origin"></param> /// <param name="filterStr"></param> /// <returns></returns> public static string FilterString(string origin, string filterStr) { if (string.IsNullOrEmpty(origin)) { return(""); } if (string.IsNullOrEmpty(filterStr)) { return(origin); } Java.Util.Regex.Pattern pattern = Java.Util.Regex.Pattern.Compile(filterStr); Matcher matcher = pattern.Matcher(origin); return(matcher.ReplaceAll("").Trim()); }
/** * \brief load a media file, either from file or from web * @param url file path or url (String) * @param playFullscreen whatever should play in fullscreen or in AR * @param autoStart auto-start when ready * @param seekPosition start position (in milliseconds) * @return true on success */ public bool load(string url, bool playFullscreen, bool autoStart, int seekPosition) { mMediaPlayerLock.Lock(); mSurfaceTextureLock.Lock(); //if it's in a different state than NOT_READY don't load it. unload() must be called first! if ((mVideoState != VIDEO_STATE.NOT_READY) || (mMediaPlayer != null)) { Log.Warn("Pikkart AR Video", "Already loaded"); mSurfaceTextureLock.Unlock(); mMediaPlayerLock.Unlock(); return(false); } //if AR video (not fullscreen) was requested create and set the media player //we can play video in AR only if a SurfaceTexture has been created if (!playFullscreen && (Build.VERSION.SdkInt >= BuildVersionCodes.IceCreamSandwich) && mSurfaceTexture != null) { mMediaPlayer = new MediaPlayer(); //first search for the video locally, then check online AssetFileDescriptor afd = null; bool fileExist = true; try { afd = mParentActivity.Assets.OpenFd(url); } catch (IOException e) { fileExist = false; } if (afd == null) { fileExist = false; } try { if (fileExist) { mMovieUrl = url; mMediaPlayer.SetDataSource(afd.FileDescriptor, afd.StartOffset, afd.Length); afd.Close(); } else { string URL_REGEX = "^((https?|ftp)://|(www|ftp)\\.)[a-z0-9-]+(\\.[a-z0-9-]+)+((:[0-9]+)|)+([/?].*)?$"; //should be ok Java.Util.Regex.Pattern p = Java.Util.Regex.Pattern.Compile(URL_REGEX); Matcher m = p.Matcher(url); //replace with string to compare if (m.Find()) { mMovieUrl = url; mMediaPlayer.SetDataSource(mMovieUrl); } } try { mMediaPlayer.SetOnPreparedListener(this); } catch (Exception e) { System.Diagnostics.Debug.WriteLine(e.StackTrace); } mMediaPlayer.SetOnBufferingUpdateListener(this); mMediaPlayer.SetOnCompletionListener(this); mMediaPlayer.SetOnErrorListener(this); mMediaPlayer.SetAudioStreamType(Stream.Music); mMediaPlayer.SetSurface(new Surface(mSurfaceTexture)); mFullscreen = false; mAutoStart = autoStart; mMediaPlayer.PrepareAsync(); mSeekPosition = seekPosition; } catch (IOException e) { Log.Error("Pikkart AR Video", "Error while creating the MediaPlayer: " + e.ToString()); mMovieUrl = ""; mVideoState = VIDEO_STATE.ERROR; mMediaPlayerLock.Unlock(); mSurfaceTextureLock.Unlock(); return(false); } } else { //play full screen if requested or old android mPlayFullScreenIntent = new Intent(mParentActivity, typeof(FullscreenVideoPlayer)); mPlayFullScreenIntent.SetAction(Android.Content.Intent.ActionView); mFullscreen = true; mMovieUrl = url; mSeekPosition = seekPosition; mVideoState = VIDEO_STATE.READY; } mSurfaceTextureLock.Unlock(); mMediaPlayerLock.Unlock(); return(true); }
public static bool IsSecureLivechatIncDomain(string host) { return(host != null && Pattern.Compile("(secure-?(lc|dal|fra|)\\.(livechat|livechatinc)\\.com)").Matcher(host).Find()); }
private static bool AddImages(Context context, SpannableString spannable) { string pattern = "\\Q[img src=\\E([a-zA-Z0-9_]+?)\\Q/]\\E"; //MatchCollection m = Regex.Matches(spannable, pattern, System.Text.RegularExpressions.RegexOptions.IgnoreCase); //foreach (Match match in m) // Console.WriteLine("{0} (duplicates '{1}') at position {2}", match.Value, match.Groups[1].Value, match.Index); Java.Util.Regex.Pattern refImg = Java.Util.Regex.Pattern.Compile(pattern); bool hasChanges = false; Matcher matcher = refImg.Matcher(spannable); while (matcher.Find()) { bool set = true; foreach (ImageSpan span in spannable.GetSpans(matcher.Start(), matcher.End(), Java.Lang.Class.FromType(typeof(ImageSpan)))) { if (spannable.GetSpanStart(span) >= matcher.Start() && spannable.GetSpanEnd(span) <= matcher.End()) { spannable.RemoveSpan(span); } else { set = false; break; } } string resname = spannable.SubSequence(matcher.Start(1), matcher.End(1)).ToString().Trim(); //int id = context.Resources.GetIdentifier(resname, "drawable", context.PackageName); if (set) { hasChanges = true; int identifier = context.Resources.GetIdentifier("modezoneedit", "drawable", context.PackageName); bool isSvg = true; Bitmap bitmap2 = null; if (isSvg) { SvgBitmapDrawable oo = SvgFactory.GetDrawable(context.Resources, identifier); //oo.Mutate().SetColorFilter(0xffff0000, Android.Graphics.PorterDuff.Mode.Multiply); Bitmap bitmap = Bitmap.CreateBitmap(oo.Picture.Width, oo.Picture.Height, Bitmap.Config.Argb8888); Canvas canvas = new Canvas(bitmap); canvas.DrawPicture(oo.Picture); bitmap2 = Bitmap.CreateScaledBitmap(bitmap, (int)(bitmap.Width * 0.3), (int)(bitmap.Height * 0.3), false); } else { bitmap2 = BitmapFactory.DecodeResource(context.Resources, identifier); bitmap2 = Bitmap.CreateScaledBitmap(bitmap2, (int)(bitmap2.Width * 0.3), (int)(bitmap2.Height * 0.3), false); } ImageSpan span = new ImageSpan(context, bitmap2); spannable.SetSpan(span, matcher.Start(), matcher.End(), SpanTypes.ExclusiveExclusive); /*spannable.SetSpan(new ImageSpan(context, id), * matcher.Start(), * matcher.End(), * SpanTypes.ExclusiveExclusive * );*/ } //if (isLastPoint) canvas.DrawColor(Color.Green, PorterDuff.Mode.SrcAtop); //Bitmap b = BitmapFactory.DecodeResource(context.Resources, Resource.Drawable.ModeZoneEdit); } return(hasChanges); }
public void SetEndPunctuationPattern(Pattern pattern) { _endPunctuationPattern = pattern; }
private void register(string filePath) { string username = usernameEt.Text.ToString().Trim(); if (TextUtils.IsEmpty(username)) { Toast.MakeText(this, "userid不能为空", ToastLength.Short).Show(); return; } Java.Util.Regex.Pattern pattern = Java.Util.Regex.Pattern.Compile("^[0-9a-zA-Z_-]{1,}$"); Matcher matcher = pattern.Matcher(username); if (!matcher.Matches()) { Toast.MakeText(this, "userid由数字、字母、下划线中的一个或者多个组合", ToastLength.Short).Show(); return; } // final String groupId = groupIdEt.getText().toString().trim(); if (TextUtils.IsEmpty(groupId)) { Toast.MakeText(this, "分组groupId为空", ToastLength.Short).Show(); return; } matcher = pattern.Matcher(username); if (!matcher.Matches()) { Toast.MakeText(this, "groupId由数字、字母、下划线中的一个或者多个组合", ToastLength.Short).Show(); return; } /* * 用户id(由数字、字母、下划线组成),长度限制128B * uid为用户的id,百度对uid不做限制和处理,应该与您的帐号系统中的用户id对应。 * */ string uid = Guid.NewGuid().ToString(); // String uid = 修改为自己用户系统中用户的id; if (TextUtils.IsEmpty(faceImagePath)) { Toast.MakeText(this, "人脸文件不存在", ToastLength.Long).Show(); return; } File file = new File(filePath); if (!file.Exists()) { Toast.MakeText(this, "人脸文件不存在", ToastLength.Long).Show(); return; } User user = new User(); user.setUserId(uid); user.setUserInfo(username); user.setGroupId(groupId); // Executors.newSingleThreadExecutor().submit(new Runnable() // { // public void run() // { // ARGBImg argbImg = FeatureUtils.getARGBImgFromPath(filePath); // byte[] bytes = new byte[2048]; // int ret = 0; // int type = PreferencesUtil.getInt(GlobalFaceTypeModel.TYPE_MODEL, GlobalFaceTypeModel.RECOGNIZE_LIVE); // if (type == GlobalFaceTypeModel.RECOGNIZE_LIVE) // { // ret = FaceSDKManager.getInstance().getFaceFeature().faceFeature(argbImg, bytes, 50); // } // else if (type == GlobalFaceTypeModel.RECOGNIZE_ID_PHOTO) // { // ret = FaceSDKManager.getInstance().getFaceFeature().faceFeatureForIDPhoto(argbImg, bytes, 50); // } // if (ret == FaceDetector.NO_FACE_DETECTED) // { // toast("人脸太小(必须打于最小检测人脸minFaceSize),或者人脸角度太大,人脸不是朝上"); // } // else if (ret != -1) // { // Feature feature = new Feature(); // feature.setGroupId(groupId); // feature.setUserId(uid); // feature.setFeature(bytes); // feature.setImageName(file.getName()); // user.getFeatureList().add(feature); // // target = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/chaixiaogangFeature2"); // // Utils.saveToFile(target,"feature2.txt",bytes); // if (FaceApi.getInstance().userAdd(user)) // { // toast("注册成功"); // finish(); // } // else // { // toast("注册失败"); // } // } // else // { // toast("抽取特征失败"); // } // } //}); }