2016-06-27 8 views
1

私はアンドロイドのレイアウトで.epubファイルをレンダリングしてそのコンテンツを表示するアンドロイドアプリを作ろうとしています。ネイティブアンドロイドアプリでepubファイルをレンダリングするにはどうすればよいですか?

ビットマップを使ってpdfページを表示するpdfRendererを使用して、pdfを表示するための同様のアプリを作成しました。

アンドロイドのepubファイルを使用して同様のことを達成するにはどうすればよいですか? Epublibを使用していますが、良いチュートリアルが見つかりません。私もskyepubを試しましたが、それは時代遅れのようです。

誰もがepublibのための例で私を助けることができる、これはepublibのための私のコードです:

package org.inevitablesol.com.epubdemo; 

import android.content.res.AssetManager; 
import android.graphics.Bitmap; 
import android.graphics.BitmapFactory; 
import android.support.v7.app.AppCompatActivity; 
import android.os.Bundle; 
import android.util.Log; 
import android.view.View; 
import android.widget.Button; 
import java.io.IOException; 
import java.io.InputStream; 
import java.util.List; 
import nl.siegmann.epublib.domain.Book; 
import nl.siegmann.epublib.domain.TOCReference; 
import nl.siegmann.epublib.epub.EpubReader; 

public class MainActivity extends AppCompatActivity { 
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 

    Button btn_openepub = (Button) findViewById(R.id.btn_openepub); 
    btn_openepub.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 
     OpenEpubfile(); 
     } 
    }); 

    } 

    private void OpenEpubfile() { 
    AssetManager assetManager = getAssets(); 

    try { 
     // find InputStream for book 
     InputStream epubInputStream = assetManager.open("books/The-Problems-of-Philosophy-LewisTheme.epub"); 

     // Load Book from inputStream 
     Book book = (new EpubReader()).readEpub(epubInputStream); 

     // Log the book's authors 
     Log.i("epublib", "author(s): " + book.getMetadata().getAuthors()); 

     // Log the book's title 
     Log.i("epublib", "title: " + book.getTitle()); 

     // Log the book's coverimage property 
     Bitmap coverImage = BitmapFactory.decodeStream(book.getCoverImage().getInputStream()); 

     Log.i("epublib", "Coverimage is " + coverImage.getWidth() + " by " 
      + coverImage.getHeight() + " pixels"); 

     // Log the tale of contents 
     logTableOfContents(book.getTableOfContents().getTocReferences(), 0); 

    } catch (IOException e) { 
     Log.e("epublib", e.getMessage()); 
    } 
    } 

/** 
    * Recursively Log the Table of Contents 
    * 
    * @param tocReferences 
    * @param depth 
    */ 
    private void logTableOfContents(List<TOCReference> tocReferences, int depth) { 
    if (tocReferences == null) { 
     return; 
    } 

    for (TOCReference tocReference : tocReferences) { 
     StringBuilder tocString = new StringBuilder(); 
     for (int i = 0; i < depth; i++) { 
     tocString.append("\t"); 
     } 
     tocString.append(tocReference.getTitle()); 
     Log.i("epublib", tocString.toString()); 

     logTableOfContents(tocReference.getChildren(), depth + 1); 
    } 
    } 
} 

私は任意のヘルプやサポートが高く評価され、プログラミングに新しいです。

ありがとうございます。

+0

試してみてください... skyreader sdkが含まれています。 https://bitbucket.org/abhishek_patil/bookreaderbyskyepub/overview – Abhishek

答えて

1

あなたはnl.siegmann.epublib.browsersupportパッケージからNavigatorとNavigatorEventListenerでのWebViewを使用することができます簡単な方法についてPageTurner Readerepub3reader

から学ぶことができます。 WebViewは「ネイティブ」ではありません。

ここでの手順:

  1. あなたのクラスでNavigatorEventListenerを実装します。次のスニペットのよう
  2. 初期ナビゲーター:あなたの実装で

    private void init() { 
        mNavigator = new Navigator(); 
        mNavigator.addNavigationEventListener(this); 
        mNavigator.gotoBook(book, this); // book is from your loaded InputStream book 
        mNavigator.gotoFirstSpineSection(this); 
    } 
    
  3. NavigationPerformedは次のように追加します。

    private void displayPage(Resource resource, int sectionPos) { 
        if (resource == null) { 
        return; 
        } 
        try { 
        mWebView.loadDataWithBaseURL("file:///android_asset/data/", data, "text/html", "UTF-8", null); 
        } catch (Exception e) { 
        Log.d(TAG, "When reading resource " 
        + resource.getId() 
        + "(" 
        + resource.getHref() 
        + ") :" 
        + e.getMessage(), e); 
        } 
    } 
    
  4. @Override public void navigationPerformed(NavigationEvent navigationEvent) { 
        if (navigationEvent.isResourceChanged()) { 
        int currentSpinePos = navigationEvent.getCurrentSpinePos(); 
        displayPage(navigationEvent.getCurrentResource(), currentSpinePos);navigationEvent.getCurrentResource().toString()); 
        } 
    } 
    
  5. はEPUBを表示するdisplayPageメソッドを追加します。完了。

関連する問題