FBReaderJ学习笔记(三):Footer底部状态栏更改

底部状态栏显示页码,电量和时间,原版还弄了个进度条,但是无论是它的OldStyle还是NewStyle都不好看,那个进度条完全是多余的。那就动手改吧,我们最终实现的效果是这样的。

关键在org.geometerplus.fbreader.fbreader.FBView这个类中。这里的结构是这样的。

因为比较简单,我直接贴代码了。

首先是Footer类。

        //右侧信息
        protected String buildInfoString(String separator) {
            final StringBuilder info = new StringBuilder();
            final FooterOptions footerOptions = myViewOptions.getFooterOptions();
//            if (footerOptions.ShowProgress.getValue()) {
//                info.append(pagePosition.Current);
//                info.append("/");
//                info.append(pagePosition.Total);
//            }
            if (footerOptions.ShowBattery.getValue()) {
                if (info.length() > 0) {
                    info.append(separator);
                }
                info.append(myReader.getBatteryLevel());
                info.append("%");
            }
            if (footerOptions.ShowClock.getValue()) {
                if (info.length() > 0) {
                    info.append(separator);
                }
                info.append(ZLibrary.Instance().getCurrentTimeString());
            }
            return info.toString();
        }
        //左侧进度页码
        protected String buildProgressString(PagePosition pagePosition){
            final StringBuilder info = new StringBuilder();
            final FooterOptions footerOptions = myViewOptions.getFooterOptions();
            if (footerOptions.ShowProgress.getValue()) {
                info.append(pagePosition.Current);
                info.append("/");
                info.append(pagePosition.Total);
            }
            return info.toString();
        }

然后在FooterOldStyle和FooterNewStyle中绘制出相应的信息,同时注释掉绘制进度条的部分。

            // draw info text
            final String infoString = buildInfoString(" | ");
            final String progressString=buildProgressString(pagePosition);
            final int infoWidth = context.getStringWidth(infoString);
            context.setTextColor(fgColor);
            context.drawString(right - infoWidth, height - delta, infoString);
            context.drawString(left, height - delta, progressString);

 

posted @ 2015-02-09 16:59  chace  阅读(771)  评论(0编辑  收藏  举报