public void cleanView(bool emptyAll) { WritePadAPI.recoResetInk(); mCurrStroke = -1; mPathList.Clear(); mPath.Reset(); Invalidate(); }
private void touch_up(float x, float y) { var gesture = WritePadAPI.detectGesture(WritePadAPI.GEST_RETURN | WritePadAPI.GEST_CUT | WritePadAPI.GEST_BACK, currentStroke); AddPixelsXY(x, y, true); AddCurrentPoint(mX, mY); mCurrStroke = -1; mMoved = false; if (!mMoved) { mX++; } mPath.LineTo(mX, mY); mPathList.AddLast(mPath); mPath = new Path(); Invalidate(); switch (gesture) { case WritePadAPI.GEST_RETURN: if (OnReturnGesture != null) { mPathList.RemoveLast(); WritePadAPI.recoDeleteLastStroke(); Invalidate(); OnReturnGesture(); return; } break; case WritePadAPI.GEST_CUT: if (OnCutGesture != null) { mPathList.RemoveLast(); WritePadAPI.recoDeleteLastStroke(); Invalidate(); OnCutGesture(); return; } break; case WritePadAPI.GEST_BACK_LONG: mPathList.RemoveLast(); WritePadAPI.recoDeleteLastStroke(); if (WritePadAPI.recoStrokeCount() > 0) { mPathList.RemoveLast(); WritePadAPI.recoDeleteLastStroke(); } Invalidate(); return; } }
private void touch_start(float x, float y) { mPath.Reset(); currentStroke = new List <WritePadAPI.CGTracePoint>(); mPath.MoveTo(x, y); mX = x; mY = y; AddCurrentPoint(mX, mY); mMoved = false; mCurrStroke = WritePadAPI.recoNewStroke(3, 0xFFFF0000); strokeLen = 0; AddPixelsXY(mX, mY, false); }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); SetContentView(Resource.Layout.Options); var seplet = FindViewById <CheckBox>(Resource.Id.separate_letters); var singleword = FindViewById <CheckBox>(Resource.Id.single_word); var corrector = FindViewById <CheckBox>(Resource.Id.autocorrector); var learner = FindViewById <CheckBox>(Resource.Id.autolearner); var userdict = FindViewById <CheckBox>(Resource.Id.user_dictionary); var dictwords = FindViewById <CheckBox>(Resource.Id.dict_words); var recoFlags = WritePadAPI.recoGetFlags(); seplet.Checked = WritePadAPI.isRecoFlagSet(recoFlags, WritePadAPI.FLAG_SEPLET); singleword.Checked = WritePadAPI.isRecoFlagSet(recoFlags, WritePadAPI.FLAG_SINGLEWORDONLY); learner.Checked = WritePadAPI.isRecoFlagSet(recoFlags, WritePadAPI.FLAG_ANALYZER); userdict.Checked = WritePadAPI.isRecoFlagSet(recoFlags, WritePadAPI.FLAG_USERDICT); dictwords.Checked = WritePadAPI.isRecoFlagSet(recoFlags, WritePadAPI.FLAG_ONLYDICT); corrector.Checked = WritePadAPI.isRecoFlagSet(recoFlags, WritePadAPI.FLAG_CORRECTOR); seplet.Click += (o, e) => { recoFlags = WritePadAPI.setRecoFlag(recoFlags, seplet.Checked, WritePadAPI.FLAG_SEPLET); WritePadAPI.recoSetFlags(recoFlags); }; singleword.Click += (o, e) => { recoFlags = WritePadAPI.setRecoFlag(recoFlags, singleword.Checked, WritePadAPI.FLAG_SINGLEWORDONLY); WritePadAPI.recoSetFlags(recoFlags); }; learner.Click += (o, e) => { recoFlags = WritePadAPI.setRecoFlag(recoFlags, learner.Checked, WritePadAPI.FLAG_ANALYZER); WritePadAPI.recoSetFlags(recoFlags); }; userdict.Click += (o, e) => { recoFlags = WritePadAPI.setRecoFlag(recoFlags, userdict.Checked, WritePadAPI.FLAG_USERDICT); WritePadAPI.recoSetFlags(recoFlags); }; dictwords.Click += (o, e) => { recoFlags = WritePadAPI.setRecoFlag(recoFlags, dictwords.Checked, WritePadAPI.FLAG_ONLYDICT); WritePadAPI.recoSetFlags(recoFlags); }; corrector.Click += (o, e) => { recoFlags = WritePadAPI.setRecoFlag(recoFlags, corrector.Checked, WritePadAPI.FLAG_CORRECTOR); WritePadAPI.recoSetFlags(recoFlags); }; }
private int AddPixelsXY(float X, float Y, bool bLastPoint) // this method called from inkCollectorThread { float xNew, yNew, x1, y1; int nSeg = SEGMENT3; if (mCurrStroke < 0) { return(0); } if (strokeLen < 1) { _lastPoint.X = _previousLocation.X = X; _lastPoint.Y = _previousLocation.Y = Y; WritePadAPI.recoAddPixel(mCurrStroke, X, Y); AddCurrentPoint(X, Y); strokeLen = 1; return(1); } float dx = Math.Abs(X - _lastPoint.X); float dy = Math.Abs(Y - _lastPoint.Y); if ((dx + dy) < SEGMENT_DIST_1) { _lastPoint.X = _previousLocation.X = X; _lastPoint.Y = _previousLocation.Y = Y; WritePadAPI.recoAddPixel(mCurrStroke, X, Y); AddCurrentPoint(X, Y); strokeLen++; return(1); } if ((dx + dy) < SEGMENT_DIST_2) { nSeg = SEGMENT2; } else if ((dx + dy) < SEGMENT_DIST_3) { nSeg = SEGMENT3; } else { nSeg = SEGMENT4; } int nPoints = 0; for (int i = 1; i < nSeg; i++) { x1 = _previousLocation.X + ((X - _previousLocation.X) * i) / nSeg; //the point "to look at" y1 = _previousLocation.Y + ((Y - _previousLocation.Y) * i) / nSeg; //the point "to look at" xNew = _lastPoint.X + (x1 - _lastPoint.X) / nSeg; yNew = _lastPoint.Y + (y1 - _lastPoint.Y) / nSeg; if (xNew != _lastPoint.X || yNew != _lastPoint.Y) { _lastPoint.X = xNew; _lastPoint.Y = yNew; WritePadAPI.recoAddPixel(mCurrStroke, xNew, yNew); AddCurrentPoint(X, Y); strokeLen++; nPoints++; } } if (bLastPoint) { // add last point if (X != _lastPoint.X || Y != _lastPoint.Y) { _lastPoint.X = X; _lastPoint.Y = Y; WritePadAPI.recoAddPixel(mCurrStroke, X, Y); AddCurrentPoint(X, Y); strokeLen++; nPoints++; } } _previousLocation.X = X; _previousLocation.Y = Y; return(nPoints); }
public string Recognize(bool bLearn) { var res = ""; var resultStringList = new List <string>(); var wordList = new List <List <WordAlternative> >(); var count = WritePadAPI.recoStrokeCount(); string defaultResult = WritePadAPI.recoInkData(count, false, false, false, false); // can also use the default result resultStringList.Add(defaultResult); var wordCount = WritePadAPI.recoResultColumnCount(); for (var i = 0; i < wordCount; i++) { var wordAlternativesList = new List <WordAlternative>(); var altCount = WritePadAPI.recoResultRowCount(i); for (var j = 0; j < altCount; j++) { var word = WritePadAPI.recoResultWord(i, j); if (word == "<--->") { word = "*Error*"; } if (string.IsNullOrEmpty(word)) { continue; } var weight = WritePadAPI.recoResultWeight(i, j); var flags = WritePadAPI.recoGetFlags(); if (j == 0 && bLearn && weight > 75 && 0 != (flags & WritePadAPI.FLAG_ANALYZER)) { WritePadAPI.recoLearnWord(word, weight); } if (wordAlternativesList.All(x => x.Word != word)) { wordAlternativesList.Add(new WordAlternative { Word = word, Weight = weight }); } while (resultStringList.Count < j + 2) { resultStringList.Add(""); } if (resultStringList[j + 1].Length > 0) { resultStringList[j + 1] += "\t\t"; } resultStringList[j + 1] += word + "\t[" + weight + "%]"; } wordList.Add(wordAlternativesList); } foreach (var line in resultStringList) { if (string.IsNullOrEmpty(line)) { continue; } if (res.Length > 0) { res += Environment.NewLine; } res += line; } return(res); }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); SetContentView(Resource.Layout.Main); WritePadAPI.recoInit(BaseContext); WritePadAPI.initializeFlags(BaseContext); var button = FindViewById <Button>(Resource.Id.RecognizeButton); var inkView = FindViewById <InkView>(Resource.Id.ink_view); var readyText = FindViewById <TextView>(Resource.Id.ready_text); var readyTextTitle = FindViewById <TextView>(Resource.Id.ready_text_title); var languageBtn = FindViewById <Button>(Resource.Id.LanguageButton); var optionsBtn = FindViewById <Button>(Resource.Id.OptionsButton); readyText.MovementMethod = new ScrollingMovementMethod(); readyTextTitle.Text = Resources.GetString(Resource.String.Title) + " (" + WritePadAPI.getLanguageName() + ")"; button.Click += delegate { readyText.Text = inkView.Recognize(false); }; optionsBtn.Click += delegate { // show options dialog StartActivity(typeof(WritePadOptions)); }; languageBtn.Click += delegate { var builder = new AlertDialog.Builder(this); builder.SetTitle("Select language"); var languages = new[] { "English", "English (UK)", "German", "French", "Spanish", "Portuguese", "Portuguese (Brazilian)", "Dutch", "Italian", "Finnish", "Sweddish", "Norwegian", "Danish", "Indonesian" }; var selection = 0; switch (WritePadAPI.language) { case WritePadAPI.LanguageType.en: selection = 0; break; case WritePadAPI.LanguageType.en_uk: selection = 1; break; case WritePadAPI.LanguageType.de: selection = 2; break; case WritePadAPI.LanguageType.fr: selection = 3; break; case WritePadAPI.LanguageType.es: selection = 4; break; case WritePadAPI.LanguageType.pt_PT: selection = 5; break; case WritePadAPI.LanguageType.pt_BR: selection = 6; break; case WritePadAPI.LanguageType.nl: selection = 7; break; case WritePadAPI.LanguageType.it: selection = 8; break; case WritePadAPI.LanguageType.fi: selection = 9; break; case WritePadAPI.LanguageType.sv: selection = 10; break; case WritePadAPI.LanguageType.nb: selection = 11; break; case WritePadAPI.LanguageType.da: selection = 12; break; case WritePadAPI.LanguageType.id: selection = 13; break; } builder.SetSingleChoiceItems(languages, selection, (sender, args) => { WritePadAPI.recoFree(); switch (args.Which) { case 0: WritePadAPI.language = WritePadAPI.LanguageType.en; break; case 1: WritePadAPI.language = WritePadAPI.LanguageType.en_uk; break; case 2: WritePadAPI.language = WritePadAPI.LanguageType.de; break; case 3: WritePadAPI.language = WritePadAPI.LanguageType.fr; break; case 4: WritePadAPI.language = WritePadAPI.LanguageType.es; break; case 5: WritePadAPI.language = WritePadAPI.LanguageType.pt_PT; break; case 6: WritePadAPI.language = WritePadAPI.LanguageType.pt_BR; break; case 7: WritePadAPI.language = WritePadAPI.LanguageType.nl; break; case 8: WritePadAPI.language = WritePadAPI.LanguageType.it; break; case 9: WritePadAPI.language = WritePadAPI.LanguageType.fi; break; case 10: WritePadAPI.language = WritePadAPI.LanguageType.sv; break; case 11: WritePadAPI.language = WritePadAPI.LanguageType.nb; break; case 12: WritePadAPI.language = WritePadAPI.LanguageType.da; break; case 13: WritePadAPI.language = WritePadAPI.LanguageType.id; break; } WritePadAPI.recoInit(BaseContext); WritePadAPI.initializeFlags(BaseContext); inkView.cleanView(true); readyTextTitle.Text = Resources.GetString(Resource.String.Title) + " (" + WritePadAPI.getLanguageName() + ")"; }); var alert = builder.Create(); alert.Show(); }; inkView.OnReturnGesture += () => readyText.Text = inkView.Recognize(true); inkView.OnReturnGesture += () => inkView.cleanView(true); inkView.OnCutGesture += () => inkView.cleanView(true); var clearbtn = FindViewById <Button>(Resource.Id.ClearButton); clearbtn.Click += delegate { readyText.Text = ""; inkView.cleanView(true); }; }
protected override void OnDestroy() { base.OnDestroy(); WritePadAPI.recoFree(); }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); SetContentView(Resource.Layout.MadMinute); //Get the username username = Intent.GetStringExtra("UserName"); WritePadAPI.recoInit(BaseContext); WritePadAPI.initializeFlags(BaseContext); button = FindViewById <Button> (Resource.Id.RecognizeButton); inkView = FindViewById <InkView> (Resource.Id.ink_view); readyText = FindViewById <TextView> (Resource.Id.ready_text); topLayerCount = FindViewById <LinearLayout> (Resource.Id.topLayerCount); containerLayer = FindViewById <FrameLayout> (Resource.Id.containerLayer); countdownView = FindViewById <TextView> (Resource.Id.countdownStart); ReadyGoStop = FindViewById <TextView> (Resource.Id.ReadyGoStop); questions_math = FindViewById <TextView> (Resource.Id.questions_math); submitAnswer = FindViewById <Button> (Resource.Id.submitAnswer); finalTotalScore = FindViewById <TextView> (Resource.Id.finalTotalScore); replayGame = FindViewById <Button> (Resource.Id.replayGame); countDownView = FindViewById <TextView> (Resource.Id.time_countdown); goBack = FindViewById <Button> (Resource.Id.goBack); countVariable = 3; //calculateTime (countVariable); topLayerCount.Visibility = Android.Views.ViewStates.Invisible; if (endTime) { return; } ReadyGoStop.Text = "GO!"; int minuteTime = 60; StartCountdownTimer(minuteTime); bool rightAnswer = false; ShowQuestions(rightAnswer); readyText.MovementMethod = new ScrollingMovementMethod(); //readyTextTitle.Text = Resources.GetString (Resource.String.Title) + " (" + WritePadAPI.getLanguageName () + ")"; button.Click += delegate { readyText.Text = inkView.Recognize(false); }; goBack.Click += delegate { var activity2 = new Intent(this, typeof(Activity2)); activity2.PutExtra("UserName", username); //activity2.PutExtra ("UserEmail", e.mProfile.Email); StartActivity(activity2); }; replayGame.Click += delegate { replayGame.Enabled = false; restartSettings(); }; /* WritePad SDK recognizing what the user wrote.*/ inkView.OnReturnGesture += () => readyText.Text = inkView.Recognize(true); inkView.OnReturnGesture += () => inkView.cleanView(true); inkView.OnCutGesture += () => inkView.cleanView(true); var clearbtn = FindViewById <Button> (Resource.Id.ClearButton); clearbtn.Click += delegate { readyText.Text = ""; inkView.cleanView(true); }; }