package com.sunteam.ebook;

import com.sunteam.ebook.util.EbookConstants;
import com.sunteam.ebook.util.PublicUtils;
import com.sunteam.ebook.util.TextFileReaderUtils;
import com.sunteam.ebook.view.TextReaderView;
import com.sunteam.ebook.view.TextReaderView.OnPageFlingListener;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;
/**
 * TXT文件显示
 * @author sylar
 *
 */
public class ReadTxtActivity extends Activity implements OnPageFlingListener {
	private TextView mTvTitle = null;
	private TextView mTvPageCount = null;
	private TextView mTvCurPage = null;
	private View mLine = null;
	private TextReaderView mTextReaderView = null;
	private int mColorSchemeIndex = 0;	//系统配色索引
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_read_txt);
		
		String filename = getIntent().getStringExtra("name");
		int part = getIntent().getIntExtra("part", 0);
		
		//此处需要从系统配置文件中得到配色方案索引
    	PublicUtils.setColorSchemeIndex(mColorSchemeIndex);
    	this.getWindow().setBackgroundDrawableResource(EbookConstants.ViewBkDrawable[mColorSchemeIndex]);
    	mTvTitle = (TextView)this.findViewById(R.id.main_title);
    	mTvPageCount = (TextView)this.findViewById(R.id.pageCount);
    	mTvCurPage = (TextView)this.findViewById(R.id.curPage);
    	mLine = (View)this.findViewById(R.id.line);
    	
    	mTvTitle.setTextColor(this.getResources().getColor(EbookConstants.FontColorID[mColorSchemeIndex]));
    	mTvPageCount.setTextColor(this.getResources().getColor(EbookConstants.FontColorID[mColorSchemeIndex]));
    	mTvCurPage.setTextColor(this.getResources().getColor(EbookConstants.FontColorID[mColorSchemeIndex]));
    	mLine.setBackgroundResource(EbookConstants.FontColorID[mColorSchemeIndex]);
    	
    	mTvTitle.setText(filename);
				
    	mTextReaderView = (TextReaderView) findViewById(R.id.read_txt_view);
    	mTextReaderView.setOnPageFlingListener(this);
    	mTextReaderView.setTextColor(this.getResources().getColor(EbookConstants.FontColorID[mColorSchemeIndex]));
    	mTextReaderView.openBook(TextFileReaderUtils.getInstance().getParagraphBuffer(part), TextFileReaderUtils.getInstance().getCharsetName(), 0);
	}

	@Override
	public void onPageFlingToTop() {
		// TODO Auto-generated method stub
		Toast.makeText(this, "已经是第一页了！", Toast.LENGTH_LONG).show();
	}

	@Override
	public void onPageFlingToBottom() {
		// TODO Auto-generated method stub
		Toast.makeText(this, "已经是最后一页了！", Toast.LENGTH_LONG).show();
	}

	@Override
	public void onPageFlingCompleted(int curPage) {
		// TODO Auto-generated method stub
		mTvCurPage.setText(curPage+"");
	}

	@Override
	public void onLoadCompleted(int pageCount, int curPage) {
		// TODO Auto-generated method stub
		mTvPageCount.setText(pageCount+"");
		mTvCurPage.setText(curPage+"");
	}
}

@@ -67,16 +67,17 @@
 stants;%0A
+%0A
 import c
@@ -417,16 +417,17 @@
 .Toast;%0A
+%0A
 /**%0A * T
@@ -433,16 +433,20 @@
 TXT%E6%96%87%E4%BB%B6%E6%98%BE%E7%A4%BA%0A
+ * %0A
  * @auth
@@ -458,11 +458,8 @@
 lar%0A
- *%0A
  */%0A
@@ -535,16 +535,17 @@
 istener 
+%0A
 %7B%0A%09priva
@@ -1038,36 +1038,28 @@
 %09%0A%09%09
-//%E6%AD%A4%E5%A4%84%E9%9C%80%E8%A6%81%E4%BB%8E%E7%B3%BB%E7%BB%9F%E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6%E4%B8%AD%E5%BE%97%E5%88%B0%E9%85%8D%E8%89%B2%E6%96%B9%E6%A1%88%E7%B4%A2%E5%BC%95%0A    %09
+mColorSchemeIndex = 
 Publ
@@ -1066,17 +1066,17 @@
 icUtils.
-s
+g
 etColorS
@@ -1086,33 +1086,16 @@
 meIndex(
-mColorSchemeIndex
 );%0A    %09
@@ -2311,16 +2311,18 @@
 ToTop() 
+%0A%09
 %7B%0A%09%09// T
@@ -2464,16 +2464,18 @@
 ottom() 
+%0A%09
 %7B%0A%09%09// T
@@ -2622,32 +2622,34 @@
 ed(int curPage) 
+%0A%09
 %7B%0A%09%09// TODO Auto
@@ -2712,32 +2712,32 @@
 %0A%09%7D%0A%0A%09@Override%0A
-
 %09public void onL
@@ -2777,16 +2777,18 @@
 urPage) 
+%0A%09
 %7B%0A%09%09// T

优化代码。