Android Open Source - RadaeePDF-B4A P D F Grid Item






From Project

Back to project page RadaeePDF-B4A.

License

The source code is released under:

Apache License

If you think the Android project RadaeePDF-B4A listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.radaee.util;
//from   w w  w  . j  av a 2s. c  om
import com.radaee.pdf.Document;
import com.radaee.pdf.Matrix;
import com.radaee.pdf.Page;
import com.radaee.reader.R;
import com.radaee.reader.R.drawable;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.Gravity;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

public class PDFGridItem extends LinearLayout
{
  private ImageView m_image;
  private TextView m_name;
  private String m_path;
  private Bitmap m_bmp;
  private Page m_page;
  private boolean m_cancel = false;
  static Bitmap m_def_pdf_icon = null;
  static Bitmap m_def_dir_icon = null;
  static Bitmap m_def_up_icon = null;
  static int TEXT_COLOR = 0xFFCCCCCC;
  public PDFGridItem(Context context, AttributeSet attrs)
  {
    super(context, attrs);
    if( m_def_pdf_icon == null )
      m_def_pdf_icon = BitmapFactory.decodeResource(context.getResources(), R.drawable.file03);
    if( m_def_dir_icon == null )
      m_def_dir_icon = BitmapFactory.decodeResource(context.getResources(), R.drawable.folder0);
    if( m_def_up_icon == null )
      m_def_up_icon = BitmapFactory.decodeResource(context.getResources(), R.drawable.folder1);
    this.setBackgroundColor(0);
    this.setOrientation(VERTICAL);
    unlock_file();
  }
  public int open_doc( Document doc, String password )
  {
    lock_file();
    int ret = doc.Open(m_path, password);
    unlock_file();
    return ret;
  }
  public boolean is_dir()
  {
    return (m_bmp == m_def_dir_icon || m_bmp == m_def_up_icon);
  }
  public String get_name()
  {
    return (String) m_name.getText();
  }
  protected synchronized void page_set()
  {
    this.removeAllViews();
    m_image = new ImageView(getContext());
    m_image.setImageBitmap(m_bmp);
    m_image.setPadding(2, 2, 2, 2);
    this.addView(m_image);
    this.addView(m_name);
  }
  protected synchronized void page_destroy()
  {
    m_cancel = true;
    if( m_page != null )
      m_page.RenderCancel();
    if( m_bmp != m_def_pdf_icon && m_bmp != m_def_dir_icon && m_bmp != m_def_up_icon && m_bmp != null )
    {
      m_bmp.recycle();
      m_bmp = null;
    }
  }
  protected void set_dir( String name, String path )
  {
    m_path = path;
    m_name = new TextView(getContext());
    m_name.setText(name);
    m_name.setSingleLine(true);
    m_name.setGravity(Gravity.CENTER_HORIZONTAL);
    m_name.setTextColor(TEXT_COLOR);
    m_image = new ImageView(getContext());
    if( name == ".." )
      m_bmp = m_def_up_icon;
    else
      m_bmp = m_def_dir_icon;
    m_image.setImageBitmap(m_bmp);
    m_image.setPadding(2, 2, 2, 2);
    this.addView(m_image);
    this.addView(m_name);
  }
  protected void set_file( PDFGridThread thread, String name, String path )
  {
    m_path = path;
    m_name = new TextView(getContext());
    m_name.setText(name);
    m_name.setSingleLine(true);
    m_name.setGravity(Gravity.CENTER_HORIZONTAL);
    m_name.setTextColor(TEXT_COLOR);
    m_image = new ImageView(getContext());
    m_bmp = m_def_pdf_icon;
    m_image.setImageBitmap(m_bmp);
    m_image.setPadding(2, 2, 2, 2);
    this.addView(m_image);
    this.addView(m_name);
    thread.start_render( this );
  }
  private synchronized void set_page(Page page, Bitmap bmp)
  {
    m_page = page;
    if( bmp != null ) m_bmp = bmp;
  }
  protected boolean render()
  {
    if( m_cancel ) return false;
    lock_file();
    Document doc = new Document();
    if( doc.Open(m_path, null) == 0 )
    {
      Page page = doc.GetPage(0);
      set_page( page, null );
      float w = doc.GetPageWidth(0);
      float h = doc.GetPageHeight(0);
      int iw = m_bmp.getWidth();
      int ih = m_bmp.getHeight();
      Bitmap bmp = null;
      try
      {
        bmp = Bitmap.createBitmap( iw, ih, Bitmap.Config.ARGB_8888 );
        bmp.eraseColor(0);
        float ratiox = iw/w;
        float ratioy = ih/h;
        if( ratiox > ratioy ) ratiox = ratioy;
        if( !page.RenderThumb(bmp) )
        {
          Canvas canvas = new Canvas(bmp);
          Paint paint = new Paint();
          paint.setARGB(255, 255, 255, 255);
          canvas.drawRect((iw - w * ratiox)/2, (ih - h * ratiox)/2,
              (iw + w * ratiox)/2, (ih + h * ratiox)/2, paint);
          Matrix mat = new Matrix( ratiox, -ratiox, (iw - w * ratiox)/2, (ih + h * ratiox)/2 );
          page.RenderToBmp(bmp, mat);
          mat.Destroy();
          if( !m_page.RenderIsFinished() )
          {
            bmp.recycle();
            bmp = null;
          }
        }
        set_page( null, bmp );
      }
      catch(Exception e)
      {
      }
      page.Close();
      doc.Close();
      unlock_file();
      return bmp != null;
    }
    else
    {
      unlock_file();
      return false;
    }
  }
  private boolean is_notified = false;
  private boolean is_waitting = false;
  private synchronized void lock_file()
  {
    try
    {
      if( is_notified )
        is_notified = false;
      else
      {
        is_waitting = true;
        wait();
        is_waitting = false;
      }
    }
    catch(Exception e)
    {
    }
  }
  private synchronized void unlock_file()
  {
    if( is_waitting )
      notify();
    else
      is_notified = true;
  }
}




Java Source Code List

com.example.pdfhttpdemo.MainActivity.java
com.example.pdfhttpdemo.ReaderController.java
com.radaee.pdf.BMDatabase.java
com.radaee.pdf.BMDatabase.java
com.radaee.pdf.BMDatabase.java
com.radaee.pdf.Document.java
com.radaee.pdf.Document.java
com.radaee.pdf.Document.java
com.radaee.pdf.Global.java
com.radaee.pdf.Global.java
com.radaee.pdf.Global.java
com.radaee.pdf.HWriting.java
com.radaee.pdf.HWriting.java
com.radaee.pdf.HWriting.java
com.radaee.pdf.Ink.java
com.radaee.pdf.Ink.java
com.radaee.pdf.Ink.java
com.radaee.pdf.Matrix.java
com.radaee.pdf.Matrix.java
com.radaee.pdf.Matrix.java
com.radaee.pdf.PDFHttpStream.java
com.radaee.pdf.PageContent.java
com.radaee.pdf.PageContent.java
com.radaee.pdf.PageContent.java
com.radaee.pdf.Page.java
com.radaee.pdf.Page.java
com.radaee.pdf.Page.java
com.radaee.pdf.Path.java
com.radaee.pdf.Path.java
com.radaee.pdf.Path.java
com.radaee.reader.PDFCropAct.java
com.radaee.reader.PDFCrop.java
com.radaee.reader.PDFEncAct.java
com.radaee.reader.PDFInkAct.java
com.radaee.reader.PDFInk.java
com.radaee.reader.PDFReaderAct.java
com.radaee.reader.PDFReaderOldAct.java
com.radaee.reader.PDFReaderOld.java
com.radaee.reader.PDFReader.java
com.radaee.reader.PDFSimpleAct.java
com.radaee.reader.PDFSimple.java
com.radaee.reader.PDFTestAct.java
com.radaee.reader.ReaderActivity.java
com.radaee.reader.ReaderController.java
com.radaee.reader.ReaderController.java
com.radaee.util.ComboListAdt.java
com.radaee.util.ComboList.java
com.radaee.util.PDFAESEnc.java
com.radaee.util.PDFAESEnc.java
com.radaee.util.PDFAESStream.java
com.radaee.util.PDFAESStream.java
com.radaee.util.PDFAssetStream.java
com.radaee.util.PDFAssetStream.java
com.radaee.util.PDFFileStream.java
com.radaee.util.PDFFileStream.java
com.radaee.util.PDFGridAdt.java
com.radaee.util.PDFGridItem.java
com.radaee.util.PDFGridThread.java
com.radaee.util.PDFGridView.java
com.radaee.util.PDFHttpStream.java
com.radaee.util.PDFHttpStream.java
com.radaee.util.PDFMemStream.java
com.radaee.util.PDFMemStream.java
com.radaee.util.PDFThumbView.java
com.radaee.util.SnatchAdt.java
com.radaee.util.SnatchView.java
com.rootsoft.pdfviewer.main.java
com.rootsoft.pdfviewer.readercontroller.java
com.rootsoft.rspdfviewer.pdf.RSPDFAnnotation.java
com.rootsoft.rspdfviewer.pdf.RSPDFBMDatabase.java
com.rootsoft.rspdfviewer.pdf.RSPDFDocument.java
com.rootsoft.rspdfviewer.pdf.RSPDFGlobal.java
com.rootsoft.rspdfviewer.pdf.RSPDFHWriting.java
com.rootsoft.rspdfviewer.pdf.RSPDFInk.java
com.rootsoft.rspdfviewer.pdf.RSPDFMatrix.java
com.rootsoft.rspdfviewer.pdf.RSPDFPageContent.java
com.rootsoft.rspdfviewer.pdf.RSPDFPage.java
com.rootsoft.rspdfviewer.pdf.RSPDFPath.java
com.rootsoft.rspdfviewer.pdf.RSPDFTemplate.java
com.rootsoft.rspdfviewer.pdf.RSPDFVPage.java
com.rootsoft.rspdfviewer.pdf.RSPDFViewCurl.java
com.rootsoft.rspdfviewer.pdf.RSPDFViewDual.java
com.rootsoft.rspdfviewer.pdf.RSPDFViewHorz.java
com.rootsoft.rspdfviewer.pdf.RSPDFViewThumb.java
com.rootsoft.rspdfviewer.pdf.RSPDFViewVert.java
com.rootsoft.rspdfviewer.pdf.RSPDFView.java
com.rootsoft.rspdfviewer.pdf.RSReaderView.java