Пример #1
0
        public void OnPrimaryClipChanged()
        {
            string pastedText = MainActivity.GetBufText(context);

            if (!sharedPrefs.GetBoolean("pref_monitor", true) || MainActivity.isActive)
            {
                return;
            }

            int textLen = pastedText.Length;

            for (int i = 0; i < textLen; i++)
            {
                if (pastedText[i] >= '\u25CB' && pastedText[i] <= '\u9FA5')
                {
                    if (dict == null)
                    {
                        dict = new Dict();
                    }
                    if (Dict.entries == null)
                    {
                        Dict.LoadDict(context);
                    }
                    List <List <object> > lines = new List <List <object> >();
                    AnnTask annotateTask        = new AnnTask(context, AnnTask.TASK_ANNOTATE, MainActivity.ANNOTATE_BUFFER, 0, 0, 0, 5, 0, lines, new List <object>(), pastedText, pastedText.Length, null, new LineView(context), DisplayNotificationAnnInterface, true, null);
                    annotateTask.Execute();

                    break;
                }
            }
        }
Пример #2
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            System.Console.WriteLine("MainActivity >> OnCreate");

            try
            {
                PackageInfo pInfo  = PackageManager.GetPackageInfo(PackageName, 0);
                int         oldVer = sharedPrefs.GetInt("version", 0);
                if (oldVer != pInfo.VersionCode)
                {
                    string stars = sharedPrefs.GetString("stars", "");
                    stars = stars.Replace(" ", "");
                    if (stars.EndsWith(";"))
                    {
                        stars = stars.Substring(1).Replace(";", @"\n");
                    }

                    sharedPrefs.Edit().PutString("stars", stars).Commit();

                    (new File(FilesDir, "dict.db")).Delete();
                    (new File(FilesDir, "idx.db")).Delete();
                    (new File(FilesDir, "entries.bin")).Delete();
                    (new File(FilesDir, "parts.bin")).Delete();
                    new File(global::Android.OS.Environment.ExternalStorageDirectory + "/ChineseReader/").Mkdir();
                    sharedPrefs.Edit().PutInt("version", pInfo.VersionCode).Commit();
                }
                if (oldVer <= 110)
                {
                    ActivityCompat.RequestPermissions(this, new string[] { Manifest.Permission.WriteExternalStorage }, REQUEST_STORAGE_FOR_BOOK);
                }
                if (0 < oldVer && oldVer <= 370)
                {
                    string prefTextSize = sharedPrefs.GetString("pref_textSize", "medium");
                    int    textSizeInt  = 16;
                    if (prefTextSize.Equals("small"))
                    {
                        textSizeInt = 13;
                    }
                    if (prefTextSize.Equals("medium"))
                    {
                        textSizeInt = 16;
                    }
                    if (prefTextSize.Equals("large"))
                    {
                        textSizeInt = 19;
                    }
                    if (prefTextSize.Equals("extra"))
                    {
                        textSizeInt = 23;
                    }

                    string prefPinyinSize = sharedPrefs.GetString("pref_pinyinSize", "medium");
                    int    pinyinSizeInt  = 100;
                    if (prefPinyinSize.Equals("small"))
                    {
                        pinyinSizeInt = 13 * 100 / textSizeInt;
                    }
                    if (prefPinyinSize.Equals("medium"))
                    {
                        pinyinSizeInt = 16 * 100 / textSizeInt;
                    }
                    if (prefPinyinSize.Equals("large"))
                    {
                        pinyinSizeInt = 19 * 100 / textSizeInt;
                    }
                    if (prefPinyinSize.Equals("extra"))
                    {
                        pinyinSizeInt = 23 * 100 / textSizeInt;
                    }

                    sharedPrefs.Edit().PutInt("pref_textSizeInt", textSizeInt).PutInt("pref_pinyinSizeInt", pinyinSizeInt).Commit();
                }

                Dict.LoadDict(this.Application);

                pastedText = GetBufText(this);
                textLen    = pastedText.Length;
                if (isFirstAnnotation)
                {
                    string lastFile = sharedPrefs.GetString("lastFile", "");
                    if (lastFile.Length > 0 && sharedPrefs.GetString("lastText", "").Equals(pastedText))
                    {
                        Annotate(lastFile);
                        return;
                    }
                }

                Title = "Chinese Reader";

                if (!CheckIsShared())
                {
                    if (textLen == 0)
                    {
                        Toast.MakeText(this.Application, GetString(Resource.String.msg_empty), ToastLength.Long).Show();
                    }
                    else
                    {
                        annoMode = ANNOTATE_BUFFER;
                        Annotate(-1);
                    }
                }
            }
            catch (Exception e)
            {
                Toast.MakeText(this, "Error: " + e.Message, ToastLength.Long).Show();
            }
        }