/**
         * 移除多个收藏
         *
         * @param removeList
         */
        public void removeSome(List <Recommend.RecommendBooks> removeList, bool removeCache)
        {
            List <Recommend.RecommendBooks> list = getCollectionList();

            if (list == null)
            {
                return;
            }
            if (removeCache)
            {
                foreach (Recommend.RecommendBooks book in removeList)
                {
                    try
                    {
                        // 移除章节文件
                        FileUtils.deleteFileOrDirectory(FileUtils.getBookDir(book._id));
                        // 移除目录缓存
                        CacheManager.RemoveTocList(book._id);
                        // 移除阅读进度
                        Settings.RemoveReadProgress(book._id);
                    }
                    catch (IOException e)
                    {
                        LogUtils.e(e.ToString());
                    }
                }
            }
            foreach (var item in removeList)
            {
                list.Remove(item);
            }
            putCollectionList(list);
        }
示例#2
0
            public override void setData(Recommend.RecommendBooks item)
            {
                base.setData(item);
                String latelyUpdate = "";

                if (!TextUtils.IsEmpty(FormatUtils.getDescriptionTimeFromDateString(item.updated)))
                {
                    latelyUpdate = FormatUtils.getDescriptionTimeFromDateString(item.updated) + ":";
                }

                holder.setText(Resource.Id.tvRecommendTitle, item.title)
                .setText(Resource.Id.tvLatelyUpdate, latelyUpdate)
                .setText(Resource.Id.tvRecommendShort, item.lastChapter)
                .setVisible(Resource.Id.ivTopLabel, item.isTop)
                .setVisible(Resource.Id.ckBoxSelect, item.showCheckBox)
                .setVisible(Resource.Id.ivUnReadDot, FormatUtils.formatZhuiShuDateString(item.updated)
                            .CompareTo(item.recentReadingTime) > 0);

                if (item.path != null && item.path.EndsWith(Constant.SUFFIX_PDF))
                {
                    holder.setImageResource(Resource.Id.ivRecommendCover, Resource.Drawable.ic_shelf_pdf);
                }
                else if (item.path != null && item.path.EndsWith(Constant.SUFFIX_EPUB))
                {
                    holder.setImageResource(Resource.Id.ivRecommendCover, Resource.Drawable.ic_shelf_epub);
                }
                else if (item.path != null && item.path.EndsWith(Constant.SUFFIX_CHM))
                {
                    holder.setImageResource(Resource.Id.ivRecommendCover, Resource.Drawable.ic_shelf_chm);
                }
                else if (item.isFromSD)
                {
                    holder.setImageResource(Resource.Id.ivRecommendCover, Resource.Drawable.ic_shelf_txt);
                    long fileLen = FileUtils.getChapterFile(item._id, 1).Length();
                    if (fileLen > 10)
                    {
                        double       progress = ((double)Settings.GetReadProgress(item._id)[2]) / fileLen;
                        NumberFormat fmt      = NumberFormat.PercentInstance;
                        fmt.MaximumFractionDigits = 2;
                        holder.setText(Resource.Id.tvRecommendShort, "当前阅读进度:" + fmt.Format(progress));
                    }
                }
                else if (!Settings.IsNoneCover)
                {
                    holder.setRoundImageUrl(Resource.Id.ivRecommendCover, Constant.IMG_BASE_URL + item.cover,
                                            Resource.Drawable.cover_default);
                }
                else
                {
                    holder.setImageResource(Resource.Id.ivRecommendCover, Resource.Drawable.cover_default);
                }

                CheckBox ckBoxSelect = holder.getView <CheckBox>(Resource.Id.ckBoxSelect);

                ckBoxSelect.Checked        = (item.isSeleted);
                ckBoxSelect.CheckedChange += (sender, e) => {
                    item.isSeleted = e.IsChecked;
                };
            }
示例#3
0
        /**
         * 绘制阅读页面
         *
         * @param canvas
         */
        public /*synchronized*/ void onDraw(Canvas canvas)
        {
            if (mLines.Size() == 0)
            {
                curEndPos = curBeginPos;
                mLines    = pageDown();
            }
            if (mLines.Size() > 0)
            {
                int y = marginHeight + (mLineSpace << 1);
                // 绘制背景
                if (mBookPageBg != null)
                {
                    canvas.DrawBitmap(mBookPageBg, null, rectF, null);
                }
                else
                {
                    canvas.DrawColor(Color.White);
                }
                // 绘制标题
                canvas.DrawText(chaptersList[currentChapter - 1].title, marginWidth, y, mTitlePaint);
                y += mLineSpace + mNumFontSize;
                // 绘制阅读页面文字
                for (var i = 0; i < mLines.Size(); i++)
                {
                    var line = mLines.Get(i).ToString();
                    y += mLineSpace;
                    if (line.EndsWith("@"))
                    {
                        canvas.DrawText(line.Substring(0, line.Count() - 1), marginWidth, y, mPaint);
                        y += mLineSpace;
                    }
                    else
                    {
                        canvas.DrawText(line, marginWidth, y, mPaint);
                    }
                    y += mFontSize;
                }
                // 绘制提示内容
                if (batteryBitmap != null)
                {
                    canvas.DrawBitmap(batteryBitmap, marginWidth + 2,
                                      mHeight - marginHeight - ScreenUtils.dpToPxInt(12), mTitlePaint);
                }

                float percent = (float)currentChapter * 100 / chapterSize;
                canvas.DrawText(decimalFormat.Format(percent) + "%", (mWidth - percentLen) / 2,
                                mHeight - marginHeight, mTitlePaint);

                string mTime = dateFormat.Format(new Date());
                canvas.DrawText(mTime, mWidth - marginWidth - timeLen, mHeight - marginHeight, mTitlePaint);

                // 保存阅读进度
                Settings.SaveReadProgress(bookId, currentChapter, curBeginPos, curEndPos);
            }
        }
示例#4
0
 public /*synchronized*/ void init(int theme)
 {
     if (!isPrepared)
     {
         try {
             pagefactory.setBgBitmap(ThemeManager.getThemeDrawable(theme));
             // 自动跳转到上次阅读位置
             int[] pos = Settings.GetReadProgress(bookId);
             int   ret = pagefactory.openBook(pos[0], new int[] { pos[1], pos[2] });
             LogUtils.i("上次阅读位置:chapter=" + pos[0] + " startPos=" + pos[1] + " endPos=" + pos[2]);
             if (ret == 0)
             {
                 listener.onLoadChapterFailure(pos[0]);
                 return;
             }
             pagefactory.onDraw(mCurrentPageCanvas);
             PostInvalidate();
         } catch (Java.Lang.Exception e) {
         }
         isPrepared = true;
     }
 }
示例#5
0
        /**
         * 获取最后一页的内容。比较繁琐,待优化
         *
         * @return
         */
        public Vector pageLast()
        {
            Java.Lang.String strParagraph = new Java.Lang.String();
            Vector           lines        = new Vector();

            currentPage = 0;
            while (curEndPos < mbBufferLen)
            {
                int paraSpace = 0;
                mPageLineCount = mVisibleHeight / (mFontSize + mLineSpace);
                curBeginPos    = curEndPos;
                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);
                }
                if (curEndPos < mbBufferLen)
                {
                    lines.Clear();
                }
                currentPage++;
            }
            Settings.SaveReadProgress(bookId, currentChapter, curBeginPos, curEndPos);
            return(lines);
        }