Пример #1
0
        public virtual void StarredExportPleco()
        {
            string stars = sharedPrefs.GetString("stars", "");

            if (stars.Length < 2)
            {
                Toast.MakeText(this, "Starred list is empty. Nothing to export.", ToastLength.Long).Show();
                return;
            }

            try
            {
                File dir = new File(global::Android.OS.Environment.ExternalStorageDirectory.AbsolutePath, "/ChineseReader");

                dir.Mkdirs();
                System.IO.FileStream os  = new System.IO.FileStream(dir.AbsolutePath + "/chinesereader_starred.txt", System.IO.FileMode.Create, System.IO.FileAccess.Write);
                BufferedOutputStream bos = new BufferedOutputStream(os);

                StringBuilder english = new StringBuilder();

                int oldIndex = 0, nIndex;
                while ((nIndex = stars.IndexOf("\n", oldIndex)) > -1)
                {
                    english.Length = 0;

                    int entry = Dict.BinarySearch(stars.SubstringSpecial(oldIndex, nIndex), false);
                    oldIndex = nIndex + 1;

                    if (entry == -1)
                    {
                        continue;
                    }

                    english.Append(Dict.GetCh(entry)).Append("\t").Append(Regex.Replace(Dict.GetPinyin(entry), @"(\\d)", "$1 ")).Append("\t");

                    string[] parts = Regex.Split(Regex.Replace(Dict.GetEnglish(entry), @"/", "; "), @"\\$");
                    int      j     = 0;
                    foreach (string str in parts)
                    {
                        if (j++ % 2 == 1)
                        {
                            english.Append(" [ ").Append(Regex.Replace(str, @"(\\d)", "$1 ")).Append("] ");
                        }
                        else
                        {
                            english.Append(str);
                        }
                    }
                    english.Append("\n");

                    bos.Write(Encoding.UTF8.GetBytes(english.ToString()));
                }
                os.Flush();
                bos.Flush();
                bos.Close();
                os.Close();

                Toast.MakeText(this, "Successfully exported to " + dir.AbsolutePath + "/chinesereader_starred.txt", ToastLength.Long).Show();
            }
            catch (Exception e)
            {
                Toast.MakeText(this, "Could not export: " + e.Message, ToastLength.Long).Show();
            }
        }
Пример #2
0
            public void OnCompleted(int task, int splitLineIndex, string pastedText, List <List <object> > tempLines, int curPos, long tempStartPos, long tempEndPos, bool isRemaining, List <Bookmark> foundBookmarks)
            {
                try
                {
                    StringBuilder textLine = new StringBuilder();

                    foreach (List <object> line in tempLines)
                    {
                        object lastWord = null;

                        textLine.Length = 0;
                        foreach (object word in line)
                        {
                            if (lastWord != null && word is int)
                            {
                                dumpFileWriter.BaseStream.WriteByte(Convert.ToByte(@"\t"));
                                textLine.Append(@"\t");
                            }

                            if (word is string)
                            {
                                if (((string)word).Length != 0)
                                {
                                    textLine.Append(Regex.Replace((string)word, @"\t", ""));
                                }
                            }
                            else
                            {
                                dumpFileWriter.BaseStream.WriteByte(Convert.ToByte(Dict.PinyinToTones(Dict.GetPinyin((int)word))));
                                textLine.Append(Dict.GetCh((int)word));
                            }

                            if (lastWord != null || !(word is string))
                            {
                                lastWord = word;
                            }
                        }

                        dumpFileWriter.BaseStream.WriteByte(Convert.ToByte(@"\n\r"));
                        dumpFileWriter.BaseStream.WriteByte(Convert.ToByte(textLine.ToString()));
                        dumpFileWriter.BaseStream.WriteByte(Convert.ToByte(@"\n\r"));
                    }

                    if (isRemaining && !dumpCancelled)
                    {
                        int progress = (int)Math.Round((double)tempEndPos * 100 / Activity.textLen);
                        dumpProgress.Progress = progress;
                        dumpProgressText.Text = Convert.ToString(progress) + "%";
                        Activity.DumpBoth(tempStartPos, tempEndPos);
                    }
                    else
                    {
                        dumpFileWriter.Flush();
                        dumpFileWriter.Close();

                        dumpStartButton.Enabled     = true;
                        dumpProgress.Visibility     = ViewStates.Gone;
                        dumpProgressText.Visibility = ViewStates.Gone;
                        Toast.MakeText(Activity.Application, "Saved to " + dumpFilePath, ToastLength.Long).Show();
                    }
                }
                catch (Exception e)
                {
                    Toast.MakeText(Activity.Application, e.Message, ToastLength.Long).Show();
                }
            }
Пример #3
0
        public void StarredExport(int exportId)
        {
            string stars = sharedPrefs.GetString("stars", "");

            if (stars == null || stars.Length < 2)
            {
                Toast.MakeText(this, "Starred list is empty. Nothing to export.", ToastLength.Long).Show();
                return;
            }

            System.Random  random = new System.Random();
            SQLiteDatabase db     = OpenOrCreateDatabase("anki.db", FileCreationMode.Private, null);

            string[] commands = Regex.Split(GetString(Resource.String.anki_scheme), ";;");
            foreach (string command in commands)
            {
                db.ExecSQL(command);
            }

            int oldIndex = 0;
            int nIndex;

            while ((nIndex = stars.IndexOf("\n", oldIndex)) > -1)
            {
                int entry = Dict.BinarySearch(stars.SubstringSpecial(oldIndex, nIndex), false);
                oldIndex = nIndex + 1;

                if (entry == -1)
                {
                    continue;
                }

                string        id = Convert.ToString(Math.Abs(random.Next())), uuid = UUID.RandomUUID().ToString().SubstringSpecial(0, 10);
                StringBuilder english = new StringBuilder();

                if (exportId == Resource.Id.menu_starred_export_pinyin)
                {
                    english.Append(Dict.PinyinToTones(Dict.GetPinyin(entry))).Append("<br/>");
                }

                english.Append(Dict.GetCh(entry)).Append("\u001F");

                if (exportId == Resource.Id.menu_starred_export)
                {
                    english.Append("[ ").Append(Dict.PinyinToTones(Dict.GetPinyin(entry))).Append(" ]<br/>");
                }

                string[] parts = Regex.Split(Regex.Replace(Dict.GetEnglish(entry), @"/", "<br/>• "), @"\\$");
                int      j     = 0;
                foreach (string str in parts)
                {
                    if (j++ % 2 == 1)
                    {
                        english.Append("<br/><br/>[ ").Append(Dict.PinyinToTones(str)).Append(" ]<br/>");
                    }
                    else
                    {
                        english.Append("• ");

                        int bracketIndex, bracketEnd = 0;
                        while ((bracketIndex = str.IndexOf("[", bracketEnd)) > -1)
                        {
                            english.Append(str, bracketEnd, bracketIndex);
                            bracketEnd = str.IndexOf("]", bracketIndex);
                            english.Append(Dict.PinyinToTones(str.SubstringSpecial(bracketIndex, bracketEnd)));
                        }
                        english.Append(str, bracketEnd, str.Length);
                    }
                }

                db.ExecSQL("insert into notes values(?, ?, 1399962367564, 1400901624, -1, '', ?, 0, 147133787, 0, '')", new Java.Lang.Object[] { id, uuid, english.ToString() });

                db.ExecSQL("insert into cards values(?, ?, 1400901287521, 0, 1400901624, -1, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, '')", new Java.Lang.Object[] { Convert.ToString(random.Next()), id });
            }
            db.Close();

            try
            {
                File dir = new File(global::Android.OS.Environment.ExternalStorageDirectory.AbsolutePath, "/AnkiDroid");
                if (!dir.Exists())
                {
                    dir = new File(global::Android.OS.Environment.ExternalStorageDirectory.AbsolutePath, "/ChineseReader");
                }

                dir.Mkdirs();
                System.IO.Stream fos = new System.IO.FileStream(dir.AbsolutePath + "/chinesereader_starred.apkg", System.IO.FileMode.Create, System.IO.FileAccess.Write);
                System.IO.Stream fiz = new System.IO.FileStream(GetDatabasePath("anki.db").Path, System.IO.FileMode.Open, System.IO.FileAccess.Read);
                ZipOutputStream  zos = new ZipOutputStream(fos);

                zos.PutNextEntry(new ZipEntry("collection.anki2"));
                byte[] buffer  = new byte[1024];
                int    readLen = 0;
                while ((readLen = fiz.Read(buffer, 0, buffer.Length)) > 0)
                {
                    zos.Write(buffer, 0, readLen);
                }
                zos.CloseEntry();

                zos.PutNextEntry(new ZipEntry("media"));
                buffer[0] = 0x7b;
                buffer[1] = 0x7d;
                zos.Write(buffer, 0, 2);
                zos.CloseEntry();
                zos.Flush();
                zos.Close();
                fiz.Close();
                fos.Flush();
                fos.Close();

                Toast.MakeText(this, "Successfully exported to " + dir.AbsolutePath + "/chinesereader_starred.apkg", ToastLength.Long).Show();
            }
            catch (Exception e)
            {
                Toast.MakeText(this, "Could not export: " + e.Message, ToastLength.Long).Show();
            }
        }