Skip to content

Commit 5964053

Browse files
committed
Replace native menu list with classic Opera Mini inspired canvas menu
1 parent f53438d commit 5964053

1 file changed

Lines changed: 130 additions & 21 deletions

File tree

‎src/com/netormium/client/ui/BrowserCanvas.java‎

Lines changed: 130 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ public final class BrowserCanvas extends Canvas implements CommandListener {
4040
private String[] speedDialUrls = new String[0];
4141
private int selectedSpeedDial = -1;
4242
private int startPageSelection = 0;
43+
private boolean mainMenuOpen = false;
44+
private int mainMenuSelection = 0;
45+
private int mainMenuScroll = 0;
4346
private final Command renameSpeedDialCommand = new Command("Rename", Command.SCREEN, 1);
4447
private final Command deleteSpeedDialCommand = new Command("Delete", Command.SCREEN, 2);
4548
private final Command moveSpeedDialUpCommand = new Command("Move Up", Command.SCREEN, 3);
@@ -310,28 +313,92 @@ else if (command == stopCommand && loading) {
310313
}
311314
}
312315

316+
private String[] mainMenuItems() {
317+
String[] items = new String[17];
318+
items[0] = "Open address";
319+
items[1] = "Start page";
320+
items[2] = "Tabs";
321+
items[3] = "New tab";
322+
items[4] = "Speed Dial";
323+
items[5] = "Add to Speed Dial";
324+
items[6] = "Bookmarks";
325+
items[7] = "Add bookmark";
326+
items[8] = "History";
327+
items[9] = "Reload page";
328+
items[10] = "Forward";
329+
items[11] = dataSaverEnabled ? "Data Saver: On" : "Data Saver: Off";
330+
items[12] = "Settings";
331+
items[13] = "Page information";
332+
items[14] = "Diagnostics";
333+
items[15] = "About Netormium";
334+
items[16] = "Exit";
335+
return items;
336+
}
337+
313338
private void showMainMenu() {
314-
chooser = new List("Netormium Menu", List.IMPLICIT);
315-
chooser.append("Open address", null);
316-
chooser.append("Start page", null);
317-
chooser.append("Tabs", null);
318-
chooser.append("New tab", null);
319-
chooser.append("Speed Dial", null);
320-
chooser.append("Add to Speed Dial", null);
321-
chooser.append("Bookmarks", null);
322-
chooser.append("Add bookmark", null);
323-
chooser.append("History", null);
324-
chooser.append("Reload page", null);
325-
chooser.append("Forward", null);
326-
chooser.append(dataSaverEnabled ? "Data Saver: On" : "Data Saver: Off", null);
327-
chooser.append("Settings", null);
328-
chooser.append("Page information", null);
329-
chooser.append("Diagnostics", null);
330-
chooser.append("About Netormium", null);
331-
chooser.append("Exit", null);
332-
chooser.addCommand(new Command("Back", Command.BACK, 1));
333-
chooser.setCommandListener(this);
334-
Display.getDisplay(midlet).setCurrent(chooser);
339+
mainMenuOpen = true;
340+
mainMenuSelection = 0;
341+
mainMenuScroll = 0;
342+
Display.getDisplay(midlet).setCurrent(this);
343+
repaint();
344+
}
345+
346+
private void closeMainMenu() {
347+
mainMenuOpen = false;
348+
repaint();
349+
}
350+
351+
private void paintMainMenu(Graphics g, int width, int height, Font body) {
352+
int headerHeight = Math.max(22, body.getHeight() + 10);
353+
int footerHeight = Math.max(18, body.getHeight() + 7);
354+
int x = 3;
355+
int panelWidth = width - 6;
356+
int top = 2;
357+
int bottom = height - footerHeight - 2;
358+
g.setColor(0xFFFFFF);
359+
g.fillRect(x, top, panelWidth, bottom - top);
360+
g.setColor(0x526F89);
361+
g.drawRect(x, top, panelWidth - 1, bottom - top - 1);
362+
g.setColor(0x244D70);
363+
g.fillRect(x + 1, top + 1, panelWidth - 2, headerHeight);
364+
g.setFont(body);
365+
g.setColor(0xFFFFFF);
366+
g.drawString("Netormium", x + 6, top + headerHeight / 2,
367+
Graphics.LEFT | Graphics.VCENTER);
368+
String[] items = mainMenuItems();
369+
int rowHeight = Math.max(19, body.getHeight() + 5);
370+
int listTop = top + headerHeight + 2;
371+
int listBottom = bottom - 2;
372+
int visibleRows = Math.max(1, (listBottom - listTop) / rowHeight);
373+
if (mainMenuSelection < mainMenuScroll) mainMenuScroll = mainMenuSelection;
374+
if (mainMenuSelection >= mainMenuScroll + visibleRows) {
375+
mainMenuScroll = mainMenuSelection - visibleRows + 1;
376+
}
377+
for (int row = 0; row < visibleRows; row++) {
378+
int index = mainMenuScroll + row;
379+
if (index >= items.length) break;
380+
int y = listTop + row * rowHeight;
381+
if (index == mainMenuSelection) {
382+
g.setColor(0x2879B9);
383+
g.fillRect(x + 2, y, panelWidth - 4, rowHeight);
384+
g.setColor(0xFFFFFF);
385+
} else {
386+
g.setColor(0x263B4D);
387+
}
388+
g.drawString(items[index], x + 8, y + rowHeight / 2,
389+
Graphics.LEFT | Graphics.VCENTER);
390+
if (index == 11) {
391+
g.drawString(dataSaverEnabled ? "ON" : "OFF",
392+
width - 10, y + rowHeight / 2, Graphics.RIGHT | Graphics.VCENTER);
393+
}
394+
}
395+
g.setColor(0x244D70);
396+
g.fillRect(0, height - footerHeight, width, footerHeight);
397+
g.setColor(0xFFFFFF);
398+
g.drawString("Select", 5, height - footerHeight / 2,
399+
Graphics.LEFT | Graphics.VCENTER);
400+
g.drawString("Back", width - 5, height - footerHeight / 2,
401+
Graphics.RIGHT | Graphics.VCENTER);
335402
}
336403

337404
private void handleMainMenuSelection(int selected) {
@@ -1070,6 +1137,11 @@ protected void paint(Graphics g) {
10701137
}
10711138
g.setClip(0, 0, w, h);
10721139

1140+
if (mainMenuOpen) {
1141+
paintMainMenu(g, w, h, body);
1142+
return;
1143+
}
1144+
10731145
g.setColor(0x244D70);
10741146
g.fillRect(0, footerY, w, footerH);
10751147
g.setColor(0x102F4B);
@@ -1201,6 +1273,26 @@ private int speedDialIndexAt(int x, int y, int top, int bottom) {
12011273
}
12021274

12031275
protected void pointerPressed(int x, int y) {
1276+
if (mainMenuOpen) {
1277+
int footerHeight = Math.max(18, ThemeManager.getBodyFont(
1278+
new ScreenMetrics(getWidth(), getHeight())).getHeight() + 7);
1279+
if (y >= getHeight() - footerHeight && x >= getWidth() / 2) {
1280+
closeMainMenu();
1281+
return;
1282+
}
1283+
Font body = ThemeManager.getBodyFont(new ScreenMetrics(getWidth(), getHeight()));
1284+
int headerHeight = Math.max(22, body.getHeight() + 10);
1285+
int rowHeight = Math.max(19, body.getHeight() + 5);
1286+
int listTop = 2 + headerHeight + 2;
1287+
int index = mainMenuScroll + ((y - listTop) / rowHeight);
1288+
String[] items = mainMenuItems();
1289+
if (y >= listTop && index >= 0 && index < items.length) {
1290+
mainMenuSelection = index;
1291+
mainMenuOpen = false;
1292+
handleMainMenuSelection(index);
1293+
}
1294+
return;
1295+
}
12041296
ScreenMetrics metrics = new ScreenMetrics(getWidth(), getHeight());
12051297
AdaptiveLayout layout = new AdaptiveLayout(metrics);
12061298
int top = layout.getAddressBarHeight() + 3;
@@ -1225,6 +1317,23 @@ protected void pointerPressed(int x, int y) {
12251317

12261318
protected void keyPressed(int keyCode) {
12271319
int action = getGameAction(keyCode);
1320+
if (mainMenuOpen) {
1321+
String[] items = mainMenuItems();
1322+
if (action == UP) {
1323+
if (mainMenuSelection > 0) mainMenuSelection--;
1324+
repaint();
1325+
} else if (action == DOWN) {
1326+
if (mainMenuSelection + 1 < items.length) mainMenuSelection++;
1327+
repaint();
1328+
} else if (action == FIRE || keyCode == KEY_NUM5) {
1329+
int selected = mainMenuSelection;
1330+
mainMenuOpen = false;
1331+
handleMainMenuSelection(selected);
1332+
} else if (keyCode == KEY_NUM0 || keyCode == KEY_NUM_STAR) {
1333+
closeMainMenu();
1334+
}
1335+
return;
1336+
}
12281337
if (currentUrl.length() == 0 && pageImage == null) {
12291338
SpeedDialStore.Entry[] homeItems = speedDial.all();
12301339
int columns = getWidth() >= 220 ? 3 : 2;

0 commit comments

Comments
 (0)