歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux編程 >> Linux編程

Android 翻頁卷曲 電子書源代碼

我的真機測試結果:

測試卷曲DEMO環境:三星T959 手機一部 系統 Android 2.3

測試txt文件位置:請自行將z8806c.txt放置SDcard 根目錄,進行測試

測試txt文件大小:98.5 MB(103,387,040 字節)電子書文件一個(為了復制出這麼大的文本文件,電腦足足卡了20多分鐘,實際中應該沒有這麼大的電子書,我想說明什麼,你懂的.....不解釋)

讀取此文本時間:低於0.5毫秒(貌似誇張了一點)

Android 翻頁卷曲 電子書源代碼下載:

免費下載地址在 http://linux.linuxidc.com/

用戶名與密碼都是www.linuxidc.com

具體下載目錄在 /pub/Android源碼集錦/2011年/11月/Android 翻頁卷曲 電子書源代碼/

 

package sf.hmg.turntest;

import java.io.IOException;

import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.PointF;
import android.os.Bundle;
import android.util.FloatMath;
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 turntest extends Activity {
 /** Called when the activity is first created. */
 private PageWidget mPageWidget;
 Bitmap mCurPageBitmap, mNextPageBitmap;
 Canvas mCurPageCanvas, mNextPageCanvas;
 BookPageFactory pagefactory;

 @Override
 public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  requestWindowFeature(Window.FEATURE_NO_TITLE);
  getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
    WindowManager.LayoutParams.FLAG_FULLSCREEN);
  mPageWidget = new PageWidget(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.shelf_bkg));

  try {
   pagefactory.openbook("/sdcard/z8806c.txt");
   pagefactory.onDraw(mCurPageCanvas);
  } catch (IOException e1) {
   Toast.makeText(this, "電子書不存在,請將《z8806c.txt》放在SD卡根目錄下,可以超過100M容量",
     Toast.LENGTH_LONG).show();
  }

  mPageWidget.setBitmaps(mCurPageBitmap, mCurPageBitmap);

  mPageWidget.setOnTouchListener(new OnTouchListener() {
   @Override
   public boolean onTouch(View v, MotionEvent e) {
    // TODO Auto-generated method stub

    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) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
       }
       if (pagefactory.isfirstPage())
        return false;
       pagefactory.onDraw(mNextPageCanvas);
      } else {
       try {
        pagefactory.nextPage();
       } catch (IOException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
       }
       if (pagefactory.islastPage()) {
        return false;
       }
       pagefactory.onDraw(mNextPageCanvas);
      }
      mPageWidget.setBitmaps(mCurPageBitmap, mNextPageBitmap);
     }

     ret = mPageWidget.doTouchEvent(e);
     return ret;
    }

    return false;
   }

  });

 }
}

Copyright © Linux教程網 All Rights Reserved