Android Open Source - PDF2ImageForEP Load Library






From Project

Back to project page PDF2ImageForEP.

License

The source code is released under:

GNU General Public License

If you think the Android project PDF2ImageForEP 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

/* ????????????????????
 * ???????static { System.loadLibrary("????????"); }????????com.artifex.mupdf.MuPDFCore.java????????????
 * ??????????????????????????????????????????ClassLoader???????????????????????????????????????????????????????????
 *     ClassLoader?????????????????????????????????????????????????????????????????????????????
 *     ???????????????????????????????????????????????????????Manifest???android:sharedUserId??????????????????????????????????
 *///from   ww  w.j av a 2  s  . com

package jp.co.muratec.pdf2image;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Calendar;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;

import android.os.Build;

public class LoadLibrary {
  // ??????????
  private static LoadLibrary instance = new LoadLibrary();
  private LoadLibrary() {}
  
  // ??????????????
  public static LoadLibrary getInstance() {
    return instance;
  }
  
  
  /*
   * ???????????????
   */
  private boolean initFlag = false;
  private String sourceDir = null;
  private String outDir    = null;
  
  // ???????????????????????
  public void setAppPath(String _sourceDir,String _outDir) {
    sourceDir = _sourceDir;
    outDir    = _outDir;
  }
  public void init(){
    init(sourceDir,outDir);
  }
  /**
   * ?????????????ClassLoader??????????????????
   * @param appPath  <br>????????.apk?????<br>?Context.getPackageManager().getApplicationInfo("???????????????", 0).sourceDir<br>???????????????????????
   * @param outPath  <br>?.so???????????<br>????????????????????????????????????????????????????????????
   */
  public void init(String appPath,String outPath){
    if(initFlag == false){
      // ??????????????????????????????????????
      String soName = "libmupdf.so";
      if(Build.CPU_ABI.equals("armeabi-v7a")){
        soName = "libmupdf_neon.so";
      }
      Calendar calendar = Calendar.getInstance();
      int now   = calendar.get(Calendar.MILLISECOND);    // ???????????????????System.load??????????already loaded?????????????????????????????????????????????????
      File outDir = new File(outPath);
      File[] list = outDir.listFiles();
      for(File file : list){
        if(file.getName().endsWith(soName)){
          // ????so?????????????????
          file.renameTo(new File(outPath,Integer.toString(now)+soName));
          System.load(outPath+"/"+Integer.toString(now)+soName);
          initFlag = true;
          return;
        }
      }
      // ????????so??????????????????
      String copyFile = outPath+"/"+Integer.toString(now)+soName;
      ZipExtractFile(appPath,"assets/"+soName,copyFile);    // appPath???????.so???????outPath??????
      System.load(copyFile);                  // ?????????????????????
      initFlag = true;
    }
  }
    
    //extract file from apk file
    public static boolean ZipExtractFile(String ZipFile,String SrcFile,String DstFile) 
    {
      ZipFile zip;
      try {
        File DstFileObj=new File(DstFile);
        zip = new ZipFile(ZipFile);
        ZipEntry zipen = zip.getEntry(SrcFile);
        if ((!DstFileObj.exists()) || (zipen.getSize()!=DstFileObj.length())) {
          InputStream is = zip.getInputStream(zipen);
          OutputStream os = new FileOutputStream(DstFile);
          byte[] buf = new byte[8092];
          int n;
          while ((n = is.read(buf)) > 0) {
            os.write(buf, 0, n);
          }
          os.close();
          is.close();
        }
      } catch (IOException e) {
        e.printStackTrace();
        return false;
      }
      return true;
    }
}




Java Source Code List

com.artifex.mupdf.ChoosePDFActivity.java
com.artifex.mupdf.LinkInfo.java
com.artifex.mupdf.MuPDFActivity.java
com.artifex.mupdf.MuPDFCore.java
com.artifex.mupdf.MuPDFPageAdapter.java
com.artifex.mupdf.MuPDFPageView.java
com.artifex.mupdf.OutlineActivityData.java
com.artifex.mupdf.OutlineActivity.java
com.artifex.mupdf.OutlineAdapter.java
com.artifex.mupdf.OutlineItem.java
com.artifex.mupdf.PageView.java
com.artifex.mupdf.ReaderView.java
com.artifex.mupdf.SafeAsyncTask.java
com.artifex.mupdf.SearchTaskResult.java
jp.co.muratec.pdf2image.DeepRadioGroup.java
jp.co.muratec.pdf2image.FilerActivity.java
jp.co.muratec.pdf2image.LoadLibrary.java
jp.co.muratec.pdf2image.PDF2ImageActivity.java
jp.co.muratec.pdf2image.PDF2ImageService.java