/* * Copyright 2014 A.C.R. Development */ package acr.browser.lightning; import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.util.Iterator; import java.util.List; import android.content.Context; public class HistoryPage { private static final String FILENAME = "history.html"; private static final String HEADING = "" + BrowserApp.getAppContext().getString(R.string.action_history) + "
"; private static final String PART1 = "

"; private static final String PART3 = "

"; private static final String PART4 = "

"; private static final String END = ""; public static String getHistoryPage(Context context) { String historyHtml = HistoryPage.HEADING; List historyList = getWebHistory(context); Iterator it = historyList.iterator(); HistoryItem helper; while (it.hasNext()) { helper = it.next(); historyHtml += HistoryPage.PART1 + helper.getUrl() + HistoryPage.PART2 + helper.getTitle() + HistoryPage.PART3 + helper.getUrl() + HistoryPage.PART4; } historyHtml += HistoryPage.END; File historyWebPage = new File(context.getFilesDir(), FILENAME); try { FileWriter historyWriter = new FileWriter(historyWebPage, false); historyWriter.write(historyHtml); historyWriter.close(); } catch (IOException e) { e.printStackTrace(); } return Constants.FILE + historyWebPage; } private static List getWebHistory(Context context) { HistoryDatabaseHandler databaseHandler = new HistoryDatabaseHandler(context); return databaseHandler.getLastHundredItems(); } }