// Path: app/src/main/java/org/morsi/android/nethack/redux/util/EncyclopediaEntry.java
// public class EncyclopediaEntry {
//   // Title of the article
//   public String topic;
// 
//   // Asset file number which this article resides
//   public int    catalog_number;
// 
//   // Location in the catalog which the articles resides
//   public int start_index;
// 
//   // Location in the catalog which the article ends
//   public int end_index;
// 
//   // Actual content of the article
//   public NString content;
// 
//   // Encyclopedia entry which we are redirecting to (if applicable)
//   EncyclopediaEntry redirect_to;
// 
//   // Constructor for an encyclopedia entry we have in the catalog
//   public EncyclopediaEntry(String rtopic, int rcatalog_number, int rstart_index, int rend_index){
//     topic = rtopic; catalog_number = rcatalog_number;
//     start_index = rstart_index; end_index = rend_index;
//     content = null; redirect_to = null;
//   }
//   
//   // Constructor for an encyclopedia entry we redirect to
//   public EncyclopediaEntry(String rtopic, EncyclopediaEntry rRedirectTo){
// 	  topic = rtopic;
// 	  content = null;
// 	  redirect_to = rRedirectTo;
//   }
// 
//   // Retrieves the content of the entry, pulling it from the appropriate source if neccesary
//   public String get_content(Context context){
// 	  if(redirect_to != null){
// 		  return redirect_to.get_content(context);
// 	  }else if(content == null){
// 		NString catalog_page = NString.fromAsset(context.getAssets(), "encyclopedia/" + Integer.toString(catalog_number));
//     	content = catalog_page.substring(start_index, end_index);
//     	return content.toString();
//     }
// 	return content.toString();
//   }
// }


import java.util.Stack;
import java.util.Timer;
import java.util.TimerTask;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;
import android.widget.TextView;
import org.morsi.android.nethack.redux.R;
import org.morsi.android.nethack.redux.util.EncyclopediaEntry;

package org.morsi.android.nethack.redux;



// Show encyclopedia page screen when encyclopedia topic is clicked
public class EncyclopediaPage extends Activity
{
    // stack of pages which have been displayed (To restore in order via back button)
    private static Stack<String> page_stack = new Stack<String>();
    
    // corresponding stack of page anchors
    private static Stack<String> anchors_stack = new Stack<String>();

    // show a new topic via the encyclopedia page
    public static void showPage(Context context, String topic){
        if(page_stack.isEmpty() || !page_stack.peek().equals(topic)){
            page_stack.push(topic);
            anchors_stack.push("");
        }
        Intent EncPage = new Intent(context, EncyclopediaPage.class);
        EncPage.putExtra("page", topic);
        EncPage.putExtra("anchor", anchors_stack.peek());
        context.startActivity(EncPage);
    }

    // close current page
    public void closePage(){
        setResult(RESULT_OK);
        finish();
// Path: app/src/main/java/org/morsi/android/nethack/redux/util/EncyclopediaEntry.java
// public class EncyclopediaEntry {
//   // Title of the article
//   public String topic;
// 
//   // Asset file number which this article resides
//   public int    catalog_number;
// 
//   // Location in the catalog which the articles resides
//   public int start_index;
// 
//   // Location in the catalog which the article ends
//   public int end_index;
// 
//   // Actual content of the article
//   public NString content;
// 
//   // Encyclopedia entry which we are redirecting to (if applicable)
//   EncyclopediaEntry redirect_to;
// 
//   // Constructor for an encyclopedia entry we have in the catalog
//   public EncyclopediaEntry(String rtopic, int rcatalog_number, int rstart_index, int rend_index){
//     topic = rtopic; catalog_number = rcatalog_number;
//     start_index = rstart_index; end_index = rend_index;
//     content = null; redirect_to = null;
//   }
//   
//   // Constructor for an encyclopedia entry we redirect to
//   public EncyclopediaEntry(String rtopic, EncyclopediaEntry rRedirectTo){
// 	  topic = rtopic;
// 	  content = null;
// 	  redirect_to = rRedirectTo;
//   }
// 
//   // Retrieves the content of the entry, pulling it from the appropriate source if neccesary
//   public String get_content(Context context){
// 	  if(redirect_to != null){
// 		  return redirect_to.get_content(context);
// 	  }else if(content == null){
// 		NString catalog_page = NString.fromAsset(context.getAssets(), "encyclopedia/" + Integer.toString(catalog_number));
//     	content = catalog_page.substring(start_index, end_index);
//     	return content.toString();
//     }
// 	return content.toString();
//   }
// }


// Path: app/src/main/java/org/morsi/android/nethack/redux/EncyclopediaPage.java
import java.util.Stack;
import java.util.Timer;
import java.util.TimerTask;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;
import android.widget.TextView;
import org.morsi.android.nethack.redux.R;
import org.morsi.android.nethack.redux.util.EncyclopediaEntry;


package org.morsi.android.nethack.redux;



// Show encyclopedia page screen when encyclopedia topic is clicked
public class EncyclopediaPage extends Activity
{
    // stack of pages which have been displayed (To restore in order via back button)
    private static Stack<String> page_stack = new Stack<String>();
    
    // corresponding stack of page anchors
    private static Stack<String> anchors_stack = new Stack<String>();

    // show a new topic via the encyclopedia page
    public static void showPage(Context context, String topic){
        if(page_stack.isEmpty() || !page_stack.peek().equals(topic)){
            page_stack.push(topic);
            anchors_stack.push("");
        }
        Intent EncPage = new Intent(context, EncyclopediaPage.class);
        EncPage.putExtra("page", topic);
        EncPage.putExtra("anchor", anchors_stack.peek());
        context.startActivity(EncPage);
    }

    // close current page
    public void closePage(){
        setResult(RESULT_OK);
        finish();
        if(!page_stack.isEmpty())