public bool OnScale(ScaleGestureDetector detector) { int textSizeInt = (int)Math.Max(10, Math.Round(initTextSize * detector.ScaleFactor)); sharedPrefs.Edit().PutInt("pref_textSizeInt", textSizeInt).Commit(); mMainActivity.parentSettingsChanged = true; mMainActivity.Redraw(); mMainActivity.wPopup.dismiss(); return(false); }
public void OnCompleted(int task, int splitLineIndex, string pastedText, List <List <object> > tempLines, int curPos, long tempStartPos, long tempEndPos, bool isRemaining, List <Bookmark> foundBookmarks) { System.Console.WriteLine("UpdateLinesAnnTask => OnCompleted()"); if (Activity.curSaveName.Equals("") && Activity.curPos == 0) { //System.Console.WriteLine("UpdateLinesAnnTask => Step 1"); StringBuilder fName = new StringBuilder(); int p = 0, r = 0; while (fName.Length < 16 && r < tempLines.Count && (p < tempLines[r].Count || r < tempLines.Count - 1)) { var word = tempLines.ElementAt(r).ElementAt(p); if (word is int) { System.Console.WriteLine("UpdateLinesAnnTask => IS INT"); if (fName.Length > 0) { fName.Append("-"); } fName.Append(Regex.Replace(Dict.GetPinyin((int)word), @"[^a-zA-Z]+", "")); } else { System.Console.WriteLine("UpdateLinesAnnTask => IS STRING"); System.Console.WriteLine("word => " + (string)word); string s = Regex.Replace((string)word, @"[^a-zA-Z0-9]+", ""); fName.Append(s.Substring(0, Math.Min(s.Length, 16))); } if (++p == tempLines[r].Count) { p = 0; r++; } } Activity.curSaveName = fName.ToString(); } Activity.curPos = curPos; Activity.linesRecyclerView.SetItemAnimator(Activity.defaultItemAnimator); switch (task) { case AnnTask.TASK_ANNOTATE: case AnnTask.TASK_SPLIT: if (isRemaining) { Activity.linesAdapter.ShowFooter = true; } else { Activity.linesAdapter.ShowFooter = false; } int firstVisiblePosition = Activity.linesLayoutManager.FindFirstVisibleItemPosition(); View firstVisible = Activity.linesLayoutManager.FindViewByPosition(firstVisiblePosition); int top = firstVisible != null ? firstVisible.Top : 0; if (task == AnnTask.TASK_SPLIT) { Activity.linesRecyclerView.SetItemAnimator(null); int toRemove = Activity.lines.Count - splitLineIndex; while (toRemove-- > 0) { Activity.lines.RemoveAt(splitLineIndex); Activity.linesAdapter.NotifyItemRemoved(splitLineIndex + 1); } if (Activity.annoMode == ANNOTATE_FILE && Activity.mBookmarks.Count > 0) { int bookmarksRemoveFrom = Bookmark.SearchClosest(Activity.endPos, Activity.mFoundBookmarks); while (Activity.mFoundBookmarks.Count > bookmarksRemoveFrom) { Activity.mFoundBookmarks.RemoveAt(bookmarksRemoveFrom); } } } int rmCount = -1; if (Activity.annoMode == ANNOTATE_FILE && !Activity.isFirstFileAnnotation && firstVisiblePosition > AnnTask.visibleLines) { rmCount = firstVisiblePosition - AnnTask.visibleLines; tempStartPos = Activity.GetPosition(Activity.lines, rmCount + 1, 0, true); for (int i = 0; i < rmCount; i++) { Activity.lines.RemoveAt(0); Activity.linesAdapter.NotifyItemRemoved(1); } int bookmarksRemoveUntil = Bookmark.SearchClosest(tempStartPos, Activity.mFoundBookmarks); for (int i = 0; i < bookmarksRemoveUntil; i++) { Activity.mFoundBookmarks.RemoveAt(0); } for (int i = 0; i < Activity.mFoundBookmarks.Count; i++) { Activity.mFoundBookmarks[i].mLine -= rmCount; } } for (int i = 0; i < foundBookmarks.Count; i++) { foundBookmarks[i].mLine += Activity.lines.Count; } Activity.mFoundBookmarks.AddRange(foundBookmarks); Activity.lines.AddRange(tempLines); Activity.linesAdapter.NotifyItemRangeInserted(Activity.lines.Count - tempLines.Count + 1, tempLines.Count); if (tempStartPos > 0) { Activity.linesAdapter.ShowHeader = true; if (Activity.isFirstFileAnnotation) { Activity.linesLayoutManager.ScrollToPositionWithOffset(1, 0); } } else { Activity.linesAdapter.ShowHeader = false; } if (rmCount > -1) { Activity.linesLayoutManager.ScrollToPositionWithOffset(AnnTask.visibleLines, top); } tempLines.Clear(); break; case AnnTask.TASK_ANNOTATE_BACK: int remainCount = Activity.linesLayoutManager.FindFirstVisibleItemPosition() + AnnTask.visibleLines * 2; if (Activity.lines.Count > remainCount) { rmCount = Activity.lines.Count - remainCount; for (int i = 0; i < rmCount; i++) { List <object> rmLine = Activity.lines[remainCount]; Activity.lines.RemoveAt(remainCount); Activity.linesAdapter.NotifyItemRemoved(remainCount + 1); tempEndPos -= LineView.GetLineSize(rmLine, Activity.annoMode == ANNOTATE_FILE); } if (Activity.annoMode == ANNOTATE_FILE && Activity.mFoundBookmarks.Count > 0) { int bookmarksRemoveFrom = Bookmark.SearchClosest(tempEndPos, Activity.mFoundBookmarks); while (Activity.mFoundBookmarks.Count > bookmarksRemoveFrom) { Activity.mFoundBookmarks.RemoveAt(bookmarksRemoveFrom); } } } firstVisiblePosition = Activity.linesLayoutManager.FindFirstVisibleItemPosition(); int newFirstVisiblePosition = firstVisiblePosition + tempLines.Count; top = Activity.linesLayoutManager.FindViewByPosition(firstVisiblePosition).Top + Activity.linesLayoutManager.FindViewByPosition(firstVisiblePosition).Height - Activity.linesLayoutManager.FindViewByPosition(firstVisiblePosition + 1).Height; if (tempStartPos == 0) { Activity.linesAdapter.ShowHeader = false; } for (int i = 0; i < Activity.mFoundBookmarks.Count; i++) { Activity.mFoundBookmarks[i].mLine += tempLines.Count; } Activity.mFoundBookmarks.InsertRange(0, foundBookmarks); Activity.lines.InsertRange(0, tempLines); Activity.linesAdapter.NotifyItemRangeInserted(1, tempLines.Count); Activity.linesLayoutManager.ScrollToPositionWithOffset(newFirstVisiblePosition, top); tempLines.Clear(); break; } Activity.isFirstAnnotation = false; Activity.isFirstFileAnnotation = false; Activity.startPos = tempStartPos; Activity.endPos = tempEndPos; if (Activity.settingsChanged) { Activity.Redraw(); } //update header and footer Activity.linesAdapter.NotifyItemChanged(0); Activity.linesAdapter.NotifyItemChanged(Activity.linesAdapter.ItemCount - 1); }