Esempio n. 1
0
 @Override
 protected void onPause() {
   // TODO Auto-generated method stub
   super.onPause();
   position = pagefactory.getPosition();
   Editor editor = sp.edit();
   editor.putInt(id + "begin", position[0]);
   editor.putInt(id + "end", position[1]);
   editor.commit();
   int fontSize = pagefactory.getTextFont();
   Editor editor2 = sp.edit();
   editor2.putInt("fontsize", fontSize);
   editor2.commit();
 }
Esempio n. 2
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    sp = getSharedPreferences("config", MODE_PRIVATE);
    mInflater = LayoutInflater.from(this);
    mPageWidget = new MyPageWidget(this);
    setContentView(mPageWidget);
    dm = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(dm);
    mCurrentPageBitmap =
        Bitmap.createBitmap(dm.widthPixels, dm.heightPixels, Bitmap.Config.ARGB_8888);
    //		mNextPageBitmap = Bitmap.createBitmap(dm.widthPixels, dm.heightPixels,
    // Bitmap.Config.ARGB_8888);
    mCurrentPageCanvas = new Canvas(mCurrentPageBitmap);
    //		mNextPageCanvas = new Canvas(mNextPageBitmap);
    fontsize = sp.getInt("fontsize", 50);
    pagefactory = new MyBookPageFactory(dm.widthPixels, dm.heightPixels, fontsize);
    try {
      getWindow()
          .addFlags(WindowManager.LayoutParams.class.getField("FLAG_NEEDS_MENU_KEY").getInt(null));
    } catch (NoSuchFieldException e) {
      // Ignore since this field won't exist in most versions of Android
    } catch (IllegalAccessException e) {
      Log.w("feelyou.info", "Could not access FLAG_NEEDS_MENU_KEY in addLegacyOverflowButton()", e);
    }

    try {
      Bundle bundle = this.getIntent().getExtras();
      id = bundle.getInt("bookid");
      position[0] = sp.getInt(id + "begin", 0);
      position[1] = sp.getInt(id + "end", 0);
      //			Toast.makeText(getApplicationContext(),"fanyehhaha",Toast.LENGTH_LONG).show();
      copy(id);
      pagefactory.setBgBitmap(BitmapFactory.decodeResource(this.getResources(), R.drawable.ff));
      pagefactory.openBook(this.getFilesDir().getPath() + "/" + id + ".txt", position);
      pagefactory.onDrow(mCurrentPageCanvas);

    } catch (Exception e) {
      // TODO: handle exception
    }
    mPageWidget.setDrawBitMap(mCurrentPageBitmap);
    mPageWidget.setOnTouchListener(
        new OnTouchListener() {

          @Override
          public boolean onTouch(View v, MotionEvent event) {
            // TODO Auto-generated method stub
            if (v == mPageWidget) {
              if (event.getAction() == MotionEvent.ACTION_DOWN
                  && event.getY() > dm.heightPixels * 2 / 3) {
                if (event.getX() > dm.widthPixels / 2) {
                  pagefactory.nextPage();
                  pagefactory.onDrow(mCurrentPageCanvas);
                  mPageWidget.setDrawBitMap(mCurrentPageBitmap);
                } else {
                  pagefactory.prePage();
                  pagefactory.onDrow(mCurrentPageCanvas);
                  mPageWidget.setDrawBitMap(mCurrentPageBitmap);
                }
                mPageWidget.invalidate();
                return true;
              }
            }
            return false;
          }
        });

    mPageWidget.setOnLongClickListener(
        new OnLongClickListener() {

          @Override
          public boolean onLongClick(View v) {
            // TODO Auto-generated method stub
            openOptionsMenu();
            return true;
          }
        });
  }