Exemplo n.º 1
0
        /**
         * 根据起始位置指针,读取一页内容
         *
         * @return
         */
        private Vector pageDown()
        {
            Java.Lang.String strParagraph = new Java.Lang.String();
            Vector           lines        = new Vector();
            int paraSpace = 0;

            mPageLineCount = mVisibleHeight / (mFontSize + mLineSpace);
            while ((lines.Size() < mPageLineCount) && (curEndPos < mbBufferLen))
            {
                byte[] parabuffer = readParagraphForward(curEndPos);
                curEndPos += parabuffer.Length;
                try
                {
                    strParagraph = new Java.Lang.String(parabuffer, charset);
                }
                catch (UnsupportedEncodingException e)
                {
                    e.PrintStackTrace();
                }
                strParagraph = new Java.Lang.String(strParagraph.ReplaceAll("\r\n", "  "));
                strParagraph = new Java.Lang.String(strParagraph.ReplaceAll("\n", " ")); // 段落中的换行符去掉,绘制的时候再换行

                while (strParagraph.Length() > 0)
                {
                    int paintSize = mPaint.BreakText(strParagraph.ToString(), true, mVisibleWidth, null);
                    lines.Add(strParagraph.Substring(0, paintSize));
                    strParagraph = new Java.Lang.String(strParagraph.Substring(paintSize));
                    if (lines.Size() >= mPageLineCount)
                    {
                        break;
                    }
                }
                lines.Set(lines.Size() - 1, lines.Get(lines.Size() - 1) + "@");
                if (strParagraph.Length() != 0)
                {
                    try
                    {
                        curEndPos -= (strParagraph).GetBytes(charset).Length;
                    }
                    catch (UnsupportedEncodingException e)
                    {
                        e.PrintStackTrace();
                    }
                }
                paraSpace     += mLineSpace;
                mPageLineCount = (mVisibleHeight - paraSpace) / (mFontSize + mLineSpace);
            }
            return(lines);
        }
Exemplo n.º 2
0
        /**
         * 指针移到上一页页首
         */
        private void pageUp()
        {
            Java.Lang.String strParagraph = new Java.Lang.String();
            Vector           lines        = new Vector(); // 页面行
            int paraSpace = 0;

            mPageLineCount = mVisibleHeight / (mFontSize + mLineSpace);
            while ((lines.Size() < mPageLineCount) && (curBeginPos > 0))
            {
                Vector paraLines  = new Vector();                   // 段落行
                byte[] parabuffer = readParagraphBack(curBeginPos); // 1.读取上一个段落

                curBeginPos -= parabuffer.Length;                   // 2.变换起始位置指针
                try
                {
                    strParagraph = new Java.Lang.String(parabuffer, charset);
                }
                catch (UnsupportedEncodingException e)
                {
                    e.PrintStackTrace();
                }
                strParagraph = new Java.Lang.String(strParagraph.ReplaceAll("\r\n", "  "));
                strParagraph = new Java.Lang.String(strParagraph.ReplaceAll("\n", " "));

                while (strParagraph.Length() > 0)
                { // 3.逐行添加到lines
                    int paintSize = mPaint.BreakText(strParagraph.ToString(), true, mVisibleWidth, null);
                    paraLines.Add(strParagraph.Substring(0, paintSize));
                    strParagraph = new Java.Lang.String(strParagraph.Substring(paintSize));
                }
                lines.AddAll(0, paraLines.ToArray());

                while (lines.Size() > mPageLineCount)
                { // 4.如果段落添加完,但是超出一页,则超出部分需删减
                    try
                    {
                        curBeginPos += (new Java.Lang.String(lines.Get(0).ToString())).GetBytes(charset).Length; // 5.删减行数同时起始位置指针也要跟着偏移
                        lines.Remove(0);
                    }
                    catch (UnsupportedEncodingException e)
                    {
                        e.PrintStackTrace();
                    }
                }
                curEndPos      = curBeginPos;                                             // 6.最后结束指针指向下一段的开始处
                paraSpace     += mLineSpace;
                mPageLineCount = (mVisibleHeight - paraSpace) / (mFontSize + mLineSpace); // 添加段落间距,实时更新容纳行数
            }
        }
Exemplo n.º 3
0
        internal Uri WriteBinaryToFile(string key, bool writeToCacheDirectory)
        {
            ProtectedBinary pb = Entry.Binaries.Get(key);

            System.Diagnostics.Debug.Assert(pb != null);
            if (pb == null)
            {
                throw new ArgumentException();
            }


            ISharedPreferences prefs           = PreferenceManager.GetDefaultSharedPreferences(this);
            string             binaryDirectory = prefs.GetString(GetString(Resource.String.BinaryDirectory_key), GetString(Resource.String.BinaryDirectory_default));

            if (writeToCacheDirectory)
            {
                binaryDirectory = CacheDir.Path + File.Separator + AttachmentContentProvider.AttachmentCacheSubDir;
            }

            string filepart = key;

            if (writeToCacheDirectory)
            {
                Java.Lang.String javaFilename = new Java.Lang.String(filepart);
                filepart = javaFilename.ReplaceAll("[^a-zA-Z0-9.-]", "_");
            }
            var targetFile = new File(binaryDirectory, filepart);

            File parent = targetFile.ParentFile;

            if (parent == null || (parent.Exists() && !parent.IsDirectory))
            {
                Toast.MakeText(this,
                               Resource.String.error_invalid_path,
                               ToastLength.Long).Show();
                return(null);
            }

            if (!parent.Exists())
            {
                // Create parent directory
                if (!parent.Mkdirs())
                {
                    Toast.MakeText(this,
                                   Resource.String.error_could_not_create_parent,
                                   ToastLength.Long).Show();
                    return(null);
                }
            }
            string filename = targetFile.AbsolutePath;
            Uri    fileUri  = Uri.FromFile(targetFile);

            byte[] pbData = pb.ReadData();
            try
            {
                System.IO.File.WriteAllBytes(filename, pbData);
            }
            catch (Exception exWrite)
            {
                Toast.MakeText(this, GetString(Resource.String.SaveAttachment_Failed, new Java.Lang.Object[] { filename })
                               + exWrite.Message, ToastLength.Long).Show();
                return(null);
            }
            finally
            {
                MemUtil.ZeroByteArray(pbData);
            }
            Toast.MakeText(this, GetString(Resource.String.SaveAttachment_doneMessage, new Java.Lang.Object[] { filename }), ToastLength.Short).Show();
            if (writeToCacheDirectory)
            {
                return(Uri.Parse("content://" + AttachmentContentProvider.Authority + "/"
                                 + filename));
            }
            return(fileUri);
        }