2 * Copyright 2008 ZXing authors
\r
4 * Licensed under the Apache License, Version 2.0 (the "License");
\r
5 * you may not use this file except in compliance with the License.
\r
6 * You may obtain a copy of the License at
\r
8 * http://www.apache.org/licenses/LICENSE-2.0
\r
10 * Unless required by applicable law or agreed to in writing, software
\r
11 * distributed under the License is distributed on an "AS IS" BASIS,
\r
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
13 * See the License for the specific language governing permissions and
\r
14 * limitations under the License.
\r
17 package com.google.zxing.client.rim;
\r
19 import com.google.zxing.client.rim.persistence.history.DecodeHistory;
\r
20 import com.google.zxing.client.rim.persistence.history.DecodeHistoryItem;
\r
21 import com.google.zxing.client.rim.util.Log;
\r
22 import net.rim.blackberry.api.browser.Browser;
\r
23 import net.rim.blackberry.api.browser.BrowserSession;
\r
24 import net.rim.device.api.ui.DrawStyle;
\r
25 import net.rim.device.api.ui.Field;
\r
26 import net.rim.device.api.ui.FieldChangeListener;
\r
27 import net.rim.device.api.ui.Manager;
\r
28 import net.rim.device.api.ui.component.ButtonField;
\r
29 import net.rim.device.api.ui.component.LabelField;
\r
30 import net.rim.device.api.ui.container.MainScreen;
\r
31 import net.rim.device.api.ui.container.VerticalFieldManager;
\r
34 * The screen used to display the qrcode decoding history.
\r
36 * This code was contributed by LifeMarks.
\r
38 * @author Matt York (matt@lifemarks.mobi)
\r
40 final class HistoryScreen extends MainScreen {
\r
43 setTitle(new LabelField("ZXing - History", DrawStyle.ELLIPSIS | USE_ALL_WIDTH));
\r
44 Manager vfm = new VerticalFieldManager(FIELD_HCENTER | VERTICAL_SCROLL);
\r
45 Log.debug("Num history items: " + DecodeHistory.getInstance().getNumItems());
\r
46 DecodeHistory history = DecodeHistory.getInstance();
\r
47 FieldChangeListener itemListener = new ButtonListener();
\r
48 for (int i = 0; i < history.getNumItems(); i++) {
\r
49 DecodeHistoryItem item = history.getItemAt(i);
\r
50 Field labelButton = new ButtonField(item.getURI(), FIELD_HCENTER | ButtonField.CONSUME_CLICK);
\r
51 labelButton.setChangeListener(itemListener);
\r
52 vfm.add(labelButton);
\r
55 Field okButton = new ButtonField("OK", FIELD_HCENTER | ButtonField.CONSUME_CLICK);
\r
56 okButton.setChangeListener(itemListener);
\r
61 * Closes the screen when the OK button is pressed.
\r
63 private static class ButtonListener implements FieldChangeListener {
\r
64 public void fieldChanged(Field field, int context) {
\r
65 if (field instanceof ButtonField) {
\r
66 BrowserSession browserSession = Browser.getDefaultSession();
\r
67 // This cannot be weakened to FieldLabelProvider -- not a public API
\r
68 browserSession.displayPage(((ButtonField) field).getLabel());
\r
74 * Overriding this method removes the save changes prompt
\r
76 public boolean onSavePrompt() {
\r