2014-01-14 2 views
-1

siegmann epub 라이브러리를 사용하여 책 리더를 만들고 있습니다. 나는 화면에 아무것도 표시 할 수 없지만 logcat에. 디스플레이에 사용할 레이아웃 유형은 무엇입니까?화면에 목차 또는 전체 책을 표시 할 수 없습니다.

가 여기 내 main.java main.xml에에서

public class MainActivity extends Activity { 

    private WebView webview; 
    private String line, line1="", finalstr=""; 
    int i = 0; 
    private String fullBook; 
    private Book book; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 
     webview = (WebView) findViewById(R.id.webview); 
     AssetManager assetManager = getAssets(); 

     try{ 
      //find input Stream for book 
      InputStream epubInputStream = assetManager.open("oliver_twist.epub"); 

      //Load book from input stream 
      book = (new EpubReader()).readEpub(epubInputStream); 

      Log.i("epublib", "title: "+book.getTitle()); 

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

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

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

      fullBook = getEntireBook(); 


     } 
     catch(IOException e){ 
      Log.e("epublib", e.getMessage()); 
     } 
     String javascrips = ""; 
     try { 
      // InputStream input = getResources().openRawResource(R.raw.lights); 
      InputStream input = this.getAssets().open(
        "poe-fall-of-the-house-of-usher.epub"); 

      int size; 
      size = input.available(); 
      byte[] buffer = new byte[size]; 
      input.read(buffer); 
      input.close(); 
      // byte buffer into a string 
      javascrips = new String(buffer); 
     } catch (IOException e) { 
      e.printStackTrace(); 
     } 
     // String html = readFile(is); 

     webview.loadDataWithBaseURL("file:///android_asset/", javascrips, 
       "application/epub+zip", "UTF-8", null); 
     //webview.setwe 
    } 

    private void logTableOfContents(List<TOCReference> tocReferences, int depth){ 

     if(tocReferences == null){ 
      System.out.println("---->>>"+tocReferences); 
      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("epulib", tocString.toString()); 

      try { 
        InputStream is = tocReference.getResource().getInputStream(); 
        BufferedReader r = new BufferedReader(new InputStreamReader(is)); 

        while ((line = r.readLine()) != null) { 
         // line1 = Html.fromHtml(line).toString(); 
         Log.v("line" + i, Html.fromHtml(line).toString()); 
         // line1 = (tocString.append(Html.fromHtml(line).toString()+ 
         // "\n")).toString(); 
         line1 = line1.concat(Html.fromHtml(line).toString()); 
        } 
        finalstr = finalstr.concat("\n").concat(line1); 
        Log.i("Content " + i, finalstr); 
        i++; 
       } catch (IOException e) { 

       } 


      logTableOfContents(tocReference.getChildren(), depth+1); 
     } 
     webview.loadDataWithBaseURL("", finalstr, "text/html", "UTF-8", ""); 
    } 

    public String getEntireBook(){ 
     String line, linez = null; 
     Spine spine = book.getSpine(); 
     Resource res; 
     List<SpineReference> spineList = spine.getSpineReferences() ; 

     int count = spineList.size(); 
     int start = 0; 

     StringBuilder string = new StringBuilder(); 
     for (int i = start; count > i; i = i +1) { 
      res = spine.getResource(i); 

       try { 
        InputStream is = res.getInputStream(); 
        BufferedReader reader = new BufferedReader(new InputStreamReader(is)); 
        try { 
         while ((line = reader.readLine()) != null) { 
          linez = string.append(line + "\n").toString(); 
         } 

        } catch (IOException e) {e.printStackTrace();} 
       } catch (IOException e) { 
        e.printStackTrace(); 
       } 
     } 
     return linez; 


    } 

} 

, 난 그냥 웹보기를 만들었습니다. 내가 추가 할 수있는 또 다른 elemnets는 무엇인가? 책이 표시되는 텍스트보기입니까?

답변

0

다음 코드를 사용하여 해결했습니다.

public class MainActivity extends Activity { 

    private WebView webview; 
    private String line, line1="", finalstr=""; 
    int i = 0; 
    private String fullBook; 
    private Book book; 

    private TextView tv; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 
     webview = (WebView) findViewById(R.id.webview); 
     WebSettings webSettings = webview.getSettings(); 
     webSettings.setJavaScriptEnabled(true); 
     webSettings.setBuiltInZoomControls(true); 
     AssetManager assetManager = getAssets(); 
     //tv = (TextView) findViewById(R.id.tv); 

     try{ 
      //find input Stream for book 
      InputStream epubInputStream = assetManager.open("TheThreeBears.epub"); 

      //Load book from input stream 
      book = (new EpubReader()).readEpub(epubInputStream); 

      Log.i("epublib", "title: "+book.getTitle()); 

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

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

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

      getEntireBook(); 


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

    } 

    private void logTableOfContents(List<TOCReference> tocReferences, int depth){ 
     // Load entire text into particular no. of lines and display each 
     // then with next button navigate through pages 

     String lineXX = "p"; 
     if(tocReferences == null){ 
      System.out.println("---->>>"+tocReferences); 
      return ; 
     } 

     for(TOCReference tocReference:tocReferences){ 

      StringBuilder tocString = new StringBuilder(); 

      for(int i=0;i<depth;i++){ 
       tocString.append("\t"); 
      } 

      tocString.append(tocReference.getTitle()); 
      //tv.setText(tocString.toString()); 
      //Log.i("epulib", tocString.toString()); 

      try { 
       InputStream is = tocReference.getResource().getInputStream(); 
       BufferedReader r = new BufferedReader(new InputStreamReader(is)); 

       while ((line = r.readLine()) != null) { 

        //String lineX = Html.fromHtml(line).toString(); 
        //lineXX = lineX; 
        Log.v("line" + i, Html.fromHtml(line).toString()); 

        line1 = line1.concat(Html.fromHtml(line).toString()); 

       } 
       finalstr = finalstr.concat("\n").concat(line1); 
       //tv.setText(finalstr); 
       //Log.i("Content " + i, finalstr); 
       i++; 
      } catch (IOException e) { 

      } 


      logTableOfContents(tocReference.getChildren(), depth+1); 
     } 
     //return lineXX; 
     webview.loadDataWithBaseURL("", finalstr, "text/html", "UTF-8", ""); 
    } 

    public void getEntireBook(){ 
     String line, linez = null; 
     Spine spine = book.getSpine(); 
     Resource res; 
     List<SpineReference> spineList = spine.getSpineReferences() ; 

     int count = spineList.size(); 
     int start = 0; 

     StringBuilder string = new StringBuilder(); 
     for (int i = start; count > i; i = i +1) { 
      res = spine.getResource(i); 

      try { 
       InputStream is = res.getInputStream(); 
       BufferedReader reader = new BufferedReader(new InputStreamReader(is)); 
       try { 
        while ((line = reader.readLine()) != null) { 
         linez = string.append(line + "\n").toString(); 
        } 

       } catch (IOException e) {e.printStackTrace();} 
      } catch (IOException e) { 
       e.printStackTrace(); 
      } 
     } 
     webview.loadData(linez, "text/html", "utf-8"); 

    } 

} 
관련 문제