package hong.specialEffects.ui;
import hong.specialEffects.R;
import hong.specialEffects.wight.BookPageFactory;
import hong.specialEffects.wight.BookPageWidget;
import hong.specialEffects.wight.FileUtils;
import java.io.IOException;
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Toast;
public class BookpageActivity extends Activity {
/** Called when the activity is first created. */
private BookPageWidget mPageWidget;
//��ǰҳ����һҳͼ��
Bitmap mCurPageBitmap, mNextPageBitmap;
Canvas mCurPageCanvas, mNextPageCanvas;
BookPageFactory pagefactory;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
FileUtils fileUtils=new FileUtils();
String text=getResources().getString(R.string.text);
fileUtils.write2SDFromInput("", "test.txt", text);
//ȥ������
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
mPageWidget = new BookPageWidget(this);
setContentView(mPageWidget);
mCurPageBitmap = Bitmap.createBitmap(480, 800, Bitmap.Config.ARGB_8888);
mNextPageBitmap = Bitmap.createBitmap(480, 800, Bitmap.Config.ARGB_8888);
mCurPageCanvas = new Canvas(mCurPageBitmap);
mNextPageCanvas = new Canvas(mNextPageBitmap);
pagefactory = new BookPageFactory(480, 800);
pagefactory.setBgBitmap(BitmapFactory.decodeResource(this.getResources(), R.drawable.bg));
try {
pagefactory.openbook("/sdcard/test.txt");
pagefactory.onDraw(mCurPageCanvas);
} catch (IOException e1) {
e1.printStackTrace();
Toast.makeText(this, "�����鲻����,�뽫��test.txt������SD����Ŀ¼��",
Toast.LENGTH_SHORT).show();
}
mPageWidget.setBitmaps(mCurPageBitmap, mCurPageBitmap);
mPageWidget.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent e) {
boolean ret=false;
if (v == mPageWidget) {
if (e.getAction() == MotionEvent.ACTION_DOWN) {
mPageWidget.abortAnimation();
mPageWidget.calcCornerXY(e.getX(), e.getY());
pagefactory.onDraw(mCurPageCanvas);
if (mPageWidget.DragToRight()) {
try {
pagefactory.prePage();
} catch (IOException e1) {
e1.printStackTrace();
}
if(pagefactory.isfirstPage()) return false;
pagefactory.onDraw(mNextPageCanvas);
} else {
try {
pagefactory.nextPage();
} catch (IOException e1) {
e1.printStackTrace();
}
if(pagefactory.islastPage()) return false;
pagefactory.onDraw(mNextPageCanvas);
}
mPageWidget.setBitmaps(mCurPageBitmap, mNextPageBitmap);
}
ret = mPageWidget.doTouchEvent(e);
return ret;
}
return false;
}
});
}
}