--- /dev/null
+/*\r
+ * Copyright 2008 ZXing authors\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+\r
+package com.google.zxing.client.rim;\r
+\r
+import com.google.zxing.client.rim.persistence.history.DecodeHistory;\r
+import com.google.zxing.client.rim.persistence.history.DecodeHistoryItem;\r
+import com.google.zxing.client.rim.util.Log;\r
+import net.rim.blackberry.api.browser.Browser;\r
+import net.rim.blackberry.api.browser.BrowserSession;\r
+import net.rim.device.api.ui.DrawStyle;\r
+import net.rim.device.api.ui.Field;\r
+import net.rim.device.api.ui.FieldChangeListener;\r
+import net.rim.device.api.ui.Manager;\r
+import net.rim.device.api.ui.FieldLabelProvider;\r
+import net.rim.device.api.ui.component.ButtonField;\r
+import net.rim.device.api.ui.component.LabelField;\r
+import net.rim.device.api.ui.container.MainScreen;\r
+import net.rim.device.api.ui.container.VerticalFieldManager;\r
+\r
+/**\r
+ * The screen used to display the qrcode decoding history.\r
+ *\r
+ * This code was contributed by LifeMarks.\r
+ *\r
+ * @author Matt York (matt@lifemarks.mobi)\r
+ */\r
+final class HistoryScreen extends MainScreen {\r
+\r
+ HistoryScreen() {\r
+ setTitle(new LabelField("ZXing - History", DrawStyle.ELLIPSIS | USE_ALL_WIDTH));\r
+ Manager vfm = new VerticalFieldManager(FIELD_HCENTER | VERTICAL_SCROLL);\r
+ Log.debug("Num history items: " + DecodeHistory.getInstance().getNumItems());\r
+ DecodeHistory history = DecodeHistory.getInstance();\r
+ FieldChangeListener itemListener = new ButtonListener();\r
+ for (int i = 0; i < history.getNumItems(); i++) {\r
+ DecodeHistoryItem item = history.getItemAt(i);\r
+ Field labelButton = new ButtonField(item.getURI(), FIELD_HCENTER | ButtonField.CONSUME_CLICK);\r
+ labelButton.setChangeListener(itemListener);\r
+ vfm.add(labelButton);\r
+ }\r
+\r
+ Field okButton = new ButtonField("OK", FIELD_HCENTER | ButtonField.CONSUME_CLICK);\r
+ okButton.setChangeListener(itemListener);\r
+ add(vfm);\r
+ }\r
+\r
+ /**\r
+ * Closes the screen when the OK button is pressed.\r
+ */\r
+ private static class ButtonListener implements FieldChangeListener {\r
+ public void fieldChanged(Field field, int context) {\r
+ if (field instanceof ButtonField) {\r
+ BrowserSession browserSession = Browser.getDefaultSession();\r
+ browserSession.displayPage(((FieldLabelProvider) field).getLabel());\r
+ }\r
+ }\r
+ }\r
+\r
+ /**\r
+ * Overriding this method removes the save changes prompt\r
+ */\r
+ public boolean onSavePrompt() {\r
+ setDirty(false);\r
+ return true;\r
+ }\r
+\r
+}\r