Skip to content

Commit dba31ca

Browse files
authored
Merge pull request #36 from jpage4500/feature/02-05
More response click listener; ignore invalid phone numbers
2 parents c8c5ffe + bc0cd6a commit dba31ca

16 files changed

+301
-273
lines changed

src/main/java/com/jpage4500/devicemanager/manager/DeviceManager.java

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -266,12 +266,15 @@ private void fetchDeviceDetails(Device device, boolean fullRefresh, DeviceListen
266266
fetchNickname(device);
267267

268268
// -- phone number --
269+
// NOTE: there's no consistent way to get a phone number via adb
270+
// - the best I've found is a script from: https://github.com/micro5k/microg-unofficial-installer/blob/main/utils/device-info.sh
269271
String phone = runShellServiceCall(device, COMMAND_SERVICE_PHONE1);
270-
if (TextUtils.notEmpty(phone)) device.phone = phone;
271-
if (TextUtils.isEmpty(device.phone)) {
272+
if (TextUtils.length(phone) > 7) {
273+
device.phone = phone;
274+
} else {
272275
// alternative way of getting phone number
273276
phone = runShellServiceCall(device, COMMAND_SERVICE_PHONE2);
274-
if (TextUtils.notEmpty(phone)) device.phone = phone;
277+
if (TextUtils.length(phone) > 7) device.phone = phone;
275278
}
276279

277280
// -- IMEI --
@@ -579,9 +582,9 @@ public void mirrorDevice(Device device, TaskListener listener) {
579582
int port = Utils.getRandomNumber(2000, 65000);
580583
// NOTE: adb must be in PATH (or ADB env variable set)
581584
appResult = runApp(app, true, "-s", device.serial,
582-
"-p", String.valueOf(port),
583-
"--window-title", device.getDisplayName(),
584-
"--show-touches", "--stay-awake", "--no-audio");
585+
"-p", String.valueOf(port),
586+
"--window-title", device.getDisplayName(),
587+
"--show-touches", "--stay-awake", "--no-audio");
585588
}
586589

587590
// TODO: figure out how to determine if scrcpy was run successfully..
@@ -647,8 +650,8 @@ private String findApp(String app) {
647650
String[] arr = new String[]{};
648651
if (Utils.isMac()) {
649652
arr = new String[]{
650-
"/opt/homebrew/bin",
651-
"/usr/local/bin",
653+
"/opt/homebrew/bin",
654+
"/usr/local/bin",
652655
};
653656
}
654657
for (String s : arr) {

src/main/java/com/jpage4500/devicemanager/ui/DeviceScreen.java

Lines changed: 35 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -198,20 +198,20 @@ private void setupStatusBar(JPanel panel) {
198198
updateLabel = new HoverLabel(icon);
199199
updateLabel.setToolTipText("Check for updates");
200200
leftPanel.add(updateLabel);
201-
UiUtils.addClickListener(updateLabel, this::handleUpdateClicked);
201+
UiUtils.addLeftClickListener(updateLabel, this::handleUpdateClicked);
202202

203203
// version
204204
versionLabel = new HoverLabel();
205205
leftPanel.add(versionLabel);
206-
UiUtils.addClickListener(versionLabel, this::handleVersionClicked);
206+
UiUtils.addLeftClickListener(versionLabel, this::handleVersionClicked);
207207
versionLabel.setText("v" + MainApplication.version);
208208

209209
// memory
210210
icon = UiUtils.getImageIcon("memory.png", UiUtils.IMG_SIZE_SMALL);
211211
memoryLabel = new HoverLabel(icon);
212212
memoryLabel.setBorder(0, 0);
213213
leftPanel.add(memoryLabel);
214-
UiUtils.addClickListener(memoryLabel, this::showSystemEnvironmentDialog);
214+
UiUtils.addLeftClickListener(memoryLabel, this::showSystemEnvironmentDialog);
215215

216216
statusBar.add(leftPanel, BorderLayout.WEST);
217217

@@ -935,12 +935,12 @@ private void handleDeviceDetails(Device device) {
935935
ImageIcon icon = UiUtils.getImageIcon("arrow_right.png", UiUtils.IMG_SIZE_SMALL);
936936
if (device.propMap != null) {
937937
HoverLabel devicePropLabel = new HoverLabel("Device Properties", icon);
938-
UiUtils.addClickListener(devicePropLabel, mouseEvent -> showDeviceProperties(device));
938+
UiUtils.addLeftClickListener(devicePropLabel, mouseEvent -> showDeviceProperties(device));
939939
panel.add(devicePropLabel, "wrap");
940940
}
941941

942942
HoverLabel appsLabel = new HoverLabel("Installed Apps / Versions", icon);
943-
UiUtils.addClickListener(appsLabel, mouseEvent -> showInstalledApps(device));
943+
UiUtils.addLeftClickListener(appsLabel, mouseEvent -> showInstalledApps(device));
944944
panel.add(appsLabel, "wrap");
945945

946946
DialogHelper.showCustomDialog(this, panel, "Device Info", null);
@@ -1191,22 +1191,17 @@ public void setupToolbar() {
11911191
filterTextField.setPreferredSize(new Dimension(150, 40));
11921192
filterTextField.setMinimumSize(new Dimension(10, 40));
11931193
filterTextField.setMaximumSize(new Dimension(200, 40));
1194-
filterTextField.addMouseListener(new MouseAdapter() {
1195-
@Override
1196-
public void mouseClicked(MouseEvent e) {
1197-
if (SwingUtilities.isRightMouseButton(e)) {
1198-
JPopupMenu popupMenu = new JPopupMenu();
1199-
JMenuItem hideItem = new JMenuItem("Hide " + ToolbarButton.FILTER.label);
1200-
hideItem.addActionListener(actionEvent -> {
1201-
popupMenu.setVisible(false);
1202-
SettingsDialog.addHiddenToolbarItem(ToolbarButton.FILTER.label);
1203-
setupToolbar();
1204-
});
1205-
popupMenu.add(hideItem);
1206-
UiUtils.addPopupMenuItem(popupMenu, "Manage Toolbar", actionEvent -> SettingsDialog.showManageToolbar(DeviceScreen.this));
1207-
popupMenu.show(e.getComponent(), e.getX(), e.getY());
1208-
}
1209-
}
1194+
UiUtils.addRightClickListener(filterTextField, e -> {
1195+
JPopupMenu popupMenu = new JPopupMenu();
1196+
JMenuItem hideItem = new JMenuItem("Hide " + ToolbarButton.FILTER.label);
1197+
hideItem.addActionListener(actionEvent -> {
1198+
popupMenu.setVisible(false);
1199+
SettingsDialog.addHiddenToolbarItem(ToolbarButton.FILTER.label);
1200+
setupToolbar();
1201+
});
1202+
popupMenu.add(hideItem);
1203+
UiUtils.addPopupMenuItem(popupMenu, "Manage Toolbar", actionEvent -> SettingsDialog.showManageToolbar(DeviceScreen.this));
1204+
popupMenu.show(e.getComponent(), e.getX(), e.getY());
12101205
});
12111206
toolbar.add(filterTextField);
12121207
}
@@ -1224,20 +1219,17 @@ protected JButton createToolbarButton(JToolBar toolbar, ToolbarButton toolbarBut
12241219
String tooltip = toolbarButton.tooltip;
12251220

12261221
JButton button = createToolbarButton(toolbar, imageName, label, tooltip, 40, listener);
1227-
button.addMouseListener(new MouseAdapter() {
1228-
@Override
1229-
public void mouseClicked(MouseEvent e) {
1230-
if (SwingUtilities.isRightMouseButton(e) && toolbarButton != ToolbarButton.SETTINGS) {
1231-
JPopupMenu popupMenu = new JPopupMenu();
1232-
UiUtils.addPopupMenuItem(popupMenu, "Hide " + label, actionEvent -> {
1233-
SettingsDialog.addHiddenToolbarItem(toolbarButton.label);
1234-
setupToolbar();
1235-
});
1236-
UiUtils.addPopupMenuItem(popupMenu, "Manage Toolbar", actionEvent -> SettingsDialog.showManageToolbar(DeviceScreen.this));
1237-
popupMenu.show(e.getComponent(), e.getX(), e.getY());
1238-
}
1239-
}
1222+
UiUtils.addRightClickListener(button, e -> {
1223+
if (toolbarButton == ToolbarButton.SETTINGS) return;
1224+
JPopupMenu popupMenu = new JPopupMenu();
1225+
UiUtils.addPopupMenuItem(popupMenu, "Hide " + label, actionEvent -> {
1226+
SettingsDialog.addHiddenToolbarItem(toolbarButton.label);
1227+
setupToolbar();
1228+
});
1229+
UiUtils.addPopupMenuItem(popupMenu, "Manage Toolbar", actionEvent -> SettingsDialog.showManageToolbar(DeviceScreen.this));
1230+
popupMenu.show(e.getComponent(), e.getX(), e.getY());
12401231
});
1232+
12411233
return button;
12421234
}
12431235

@@ -1265,19 +1257,16 @@ private void loadCustomScripts(JToolBar toolbar) {
12651257
if (scriptList == null || scriptList.isEmpty()) return;
12661258
JButton scriptButton = createToolbarButton(toolbar, ToolbarButton.SCRIPTS, null);
12671259
if (scriptButton == null) return;
1268-
scriptButton.addMouseListener(new MouseAdapter() {
1269-
@Override
1270-
public void mousePressed(MouseEvent e) {
1271-
JPopupMenu popupMenu = new JPopupMenu();
1272-
List<File> scriptList = getCustomScripts();
1273-
for (File script : scriptList) {
1274-
String name = FileUtils.getNameNoExt(script).replaceAll("_", " ");
1275-
JMenuItem item = new JMenuItem(name, UiUtils.getImageIcon("icon_custom.png", UiUtils.IMG_SIZE_SMALL));
1276-
item.addActionListener(e2 -> handleCustomScriptClicked(script, name));
1277-
popupMenu.add(item);
1278-
}
1279-
popupMenu.show(e.getComponent(), e.getX(), e.getY());
1260+
UiUtils.addLeftClickListener(scriptButton, e -> {
1261+
JPopupMenu popupMenu = new JPopupMenu();
1262+
List<File> list = getCustomScripts();
1263+
for (File script : list) {
1264+
String name = FileUtils.getNameNoExt(script).replaceAll("_", " ");
1265+
JMenuItem item = new JMenuItem(name, UiUtils.getImageIcon("icon_custom.png", UiUtils.IMG_SIZE_SMALL));
1266+
item.addActionListener(e2 -> handleCustomScriptClicked(script, name));
1267+
popupMenu.add(item);
12801268
}
1269+
popupMenu.show(e.getComponent(), e.getX(), e.getY());
12811270
});
12821271
}
12831272

src/main/java/com/jpage4500/devicemanager/ui/ExploreScreen.java

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ private void setupStatusBar(JPanel mainPanel) {
117117
// bookmark
118118
ImageIcon icon = UiUtils.getImageIcon("icon_bookmark.png", UiUtils.IMG_SIZE_SMALL);
119119
pathLabel = new HoverLabel(selectedPath, icon);
120-
UiUtils.addClickListener(pathLabel, this::showFavoritePopup);
120+
UiUtils.addLeftClickListener(pathLabel, this::showFavoritePopup);
121121
statusBar.add(pathLabel, BorderLayout.WEST);
122122

123123
// empty space
@@ -145,16 +145,17 @@ private void showFavoritePopup(MouseEvent e) {
145145
UiUtils.setEmptyBorder(item);
146146
popupMenu.add(item);
147147
}
148-
popupMenu.addMouseListener(new MouseAdapter() {
149-
@Override
150-
public void mouseClicked(MouseEvent mouseEvent) {
151-
if (SwingUtilities.isRightMouseButton(mouseEvent)) {
152-
log.debug("mouseClicked: LEFT");
153-
} else {
154-
log.debug("mouseClicked: RIGHT-CLICK");
155-
}
156-
}
157-
});
148+
// TODO:
149+
// popupMenu.addMouseListener(new MouseAdapter() {
150+
// @Override
151+
// public void mouseClicked(MouseEvent mouseEvent) {
152+
// if (SwingUtilities.isRightMouseButton(mouseEvent)) {
153+
// log.debug("mouseClicked: LEFT");
154+
// } else {
155+
// log.debug("mouseClicked: RIGHT-CLICK");
156+
// }
157+
// }
158+
// });
158159
popupMenu.addSeparator();
159160
if (!pathList.contains(selectedPath)) {
160161
// add current item

src/main/java/com/jpage4500/devicemanager/ui/SaveLogsScreen.java

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -315,33 +315,30 @@ private void setupToolbar() {
315315

316316
// filter
317317
filterButton = createToolbarButton(toolbar, "clear_filter.png", "Filter", "Set Filter", null);
318-
filterButton.addMouseListener(new MouseAdapter() {
319-
@Override
320-
public void mousePressed(MouseEvent e) {
321-
JPopupMenu popupMenu = new JPopupMenu();
322-
323-
if (SaveLogsScreen.this.logFilter != null) {
324-
JMenuItem item = new JMenuItem("Clear Filter", UiUtils.getImageIcon("clear_filter.png", UiUtils.IMG_SIZE_SMALL));
325-
item.addActionListener(e2 -> handleFilterClicked(null));
326-
popupMenu.add(item);
327-
}
328-
329-
List<LogFilter> systemList = ViewLogsScreen.getSystemFilters();
330-
List<LogFilter> filterList = ViewLogsScreen.getUserFilters();
331-
systemList.addAll(filterList);
332-
for (LogFilter filter : systemList) {
333-
if (filter.filterList == null || filter.filterList.isEmpty()) continue;
334-
JMenuItem item = new JMenuItem(filter.name, UiUtils.getImageIcon("icon_filter.png", UiUtils.IMG_SIZE_SMALL));
335-
item.addActionListener(e2 -> handleFilterClicked(filter));
336-
popupMenu.add(item);
337-
}
318+
UiUtils.addRightClickListener(filterButton, e -> {
319+
JPopupMenu popupMenu = new JPopupMenu();
338320

339-
JMenuItem item = new JMenuItem("Add Filter", UiUtils.getImageIcon("icon_add.png", UiUtils.IMG_SIZE_SMALL));
340-
item.addActionListener(e2 -> handleAddFilterClicked());
321+
if (SaveLogsScreen.this.logFilter != null) {
322+
JMenuItem item = new JMenuItem("Clear Filter", UiUtils.getImageIcon("clear_filter.png", UiUtils.IMG_SIZE_SMALL));
323+
item.addActionListener(e2 -> handleFilterClicked(null));
341324
popupMenu.add(item);
325+
}
342326

343-
popupMenu.show(e.getComponent(), e.getX(), e.getY());
327+
List<LogFilter> systemList = ViewLogsScreen.getSystemFilters();
328+
List<LogFilter> filterList = ViewLogsScreen.getUserFilters();
329+
systemList.addAll(filterList);
330+
for (LogFilter filter : systemList) {
331+
if (filter.filterList == null || filter.filterList.isEmpty()) continue;
332+
JMenuItem item = new JMenuItem(filter.name, UiUtils.getImageIcon("icon_filter.png", UiUtils.IMG_SIZE_SMALL));
333+
item.addActionListener(e2 -> handleFilterClicked(filter));
334+
popupMenu.add(item);
344335
}
336+
337+
JMenuItem item = new JMenuItem("Add Filter", UiUtils.getImageIcon("icon_add.png", UiUtils.IMG_SIZE_SMALL));
338+
item.addActionListener(e2 -> handleAddFilterClicked());
339+
popupMenu.add(item);
340+
341+
popupMenu.show(e.getComponent(), e.getX(), e.getY());
345342
});
346343
}
347344

src/main/java/com/jpage4500/devicemanager/ui/ViewLogsScreen.java

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@
2323
import java.awt.*;
2424
import java.awt.datatransfer.Clipboard;
2525
import java.awt.datatransfer.StringSelection;
26-
import java.awt.event.*;
26+
import java.awt.event.ActionEvent;
27+
import java.awt.event.InputEvent;
28+
import java.awt.event.KeyEvent;
2729
import java.util.List;
2830
import java.util.*;
2931
import java.util.concurrent.TimeUnit;
@@ -682,30 +684,26 @@ private void setupFilterList() {
682684
filterList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
683685
filterList.setCellRenderer(new LogFilterRenderer());
684686
filterList.addListSelectionListener(e -> handleFilterSelected());
685-
filterList.addMouseListener(new MouseAdapter() {
686-
@Override
687-
public void mouseClicked(MouseEvent e) {
688-
// single click
689-
if (SwingUtilities.isRightMouseButton(e)) {
690-
// select item
691-
Point point = e.getPoint();
692-
int i = filterList.locationToIndex(point);
693-
if (i < 0) return;
694-
filterList.setSelectedIndex(i);
695-
696-
LogFilter selectedFilter = filterList.getSelectedValue();
697-
if (selectedFilter == null || selectedFilter.isSystemFilter) return;
698-
699-
JPopupMenu popupMenu = new JPopupMenu();
700-
UiUtils.addPopupMenuItem(popupMenu, "Edit Filter", actionEvent -> handleEditFilterClicked(selectedFilter));
701-
UiUtils.addPopupMenuItem(popupMenu, "Duplicate Filter", actionEvent -> handleCopyFilterClicked(selectedFilter));
702-
UiUtils.addPopupMenuItem(popupMenu, "Delete Filter", actionEvent -> handleDeleteFilterClicked(selectedFilter));
703-
popupMenu.show(e.getComponent(), e.getX(), e.getY());
704-
} else if (e.getClickCount() >= 2) {
705-
LogFilter selectedFilter = filterList.getSelectedValue();
706-
if (selectedFilter == null || selectedFilter.isSystemFilter) return;
707-
handleEditFilterClicked(selectedFilter);
708-
}
687+
UiUtils.addClickListener(filterList, e -> {
688+
if (SwingUtilities.isRightMouseButton(e)) {
689+
// select item
690+
Point point = e.getPoint();
691+
int i = filterList.locationToIndex(point);
692+
if (i < 0) return;
693+
filterList.setSelectedIndex(i);
694+
695+
LogFilter selectedFilter = filterList.getSelectedValue();
696+
if (selectedFilter == null || selectedFilter.isSystemFilter) return;
697+
698+
JPopupMenu popupMenu = new JPopupMenu();
699+
UiUtils.addPopupMenuItem(popupMenu, "Edit Filter", actionEvent -> handleEditFilterClicked(selectedFilter));
700+
UiUtils.addPopupMenuItem(popupMenu, "Duplicate Filter", actionEvent -> handleCopyFilterClicked(selectedFilter));
701+
UiUtils.addPopupMenuItem(popupMenu, "Delete Filter", actionEvent -> handleDeleteFilterClicked(selectedFilter));
702+
popupMenu.show(e.getComponent(), e.getX(), e.getY());
703+
} else if (e.getClickCount() >= 2) {
704+
LogFilter selectedFilter = filterList.getSelectedValue();
705+
if (selectedFilter == null || selectedFilter.isSystemFilter) return;
706+
handleEditFilterClicked(selectedFilter);
709707
}
710708
});
711709
}

src/main/java/com/jpage4500/devicemanager/ui/dialog/CommandDialog.java

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212

1313
import javax.swing.*;
1414
import java.awt.*;
15-
import java.awt.event.*;
15+
import java.awt.event.KeyAdapter;
16+
import java.awt.event.KeyEvent;
1617
import java.awt.image.BufferedImage;
1718
import java.util.List;
1819

@@ -52,21 +53,18 @@ public CommandDialog(List<Device> selectedDeviceList) {
5253
list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
5354
list.setCellRenderer(new AlternatingBackgroundColorRenderer());
5455
list.setVisibleRowCount(5);
55-
list.addMouseListener(new MouseAdapter() {
56-
@Override
57-
public void mouseClicked(MouseEvent e) {
58-
Point point = e.getPoint();
59-
int row = list.locationToIndex(point);
60-
if (row < 0) return;
61-
if (SwingUtilities.isRightMouseButton(e)) {
62-
// select row
63-
list.setSelectedIndex(row);
64-
JPopupMenu popupMenu = new JPopupMenu();
65-
66-
UiUtils.addPopupMenuItem(popupMenu, "Delete", actionEvent -> deleteItem(list.getSelectedValue()));
67-
68-
popupMenu.show(e.getComponent(), e.getX(), e.getY());
69-
}
56+
UiUtils.addRightClickListener(list, e -> {
57+
Point point = e.getPoint();
58+
int row = list.locationToIndex(point);
59+
if (row < 0) return;
60+
if (SwingUtilities.isRightMouseButton(e)) {
61+
// select row
62+
list.setSelectedIndex(row);
63+
JPopupMenu popupMenu = new JPopupMenu();
64+
65+
UiUtils.addPopupMenuItem(popupMenu, "Delete", actionEvent -> deleteItem(list.getSelectedValue()));
66+
67+
popupMenu.show(e.getComponent(), e.getX(), e.getY());
7068
}
7169
});
7270

@@ -168,7 +166,7 @@ private void runCommand() {
168166
for (Device device : selectedDeviceList) {
169167
DeviceManager.getInstance().runCustomCommand(device, command, (result) -> {
170168
String displayStr = TextUtils.join(result.resultList, "\n");
171-
resultWatcher.handleResult(device.serial, result.isSuccess, displayStr);
169+
resultWatcher.handleResult(device.serial, result.isSuccess, displayStr);
172170
});
173171
}
174172
}

src/main/java/com/jpage4500/devicemanager/ui/dialog/SettingsDialog.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ private void initalizeUi() {
5050
});
5151

5252
JButton logButton = UiUtils.addSettingButton(this, "Log Level", "EDIT", null);
53-
UiUtils.addClickListener(logButton, e -> toggleLogLevels(logButton));
53+
UiUtils.addLeftClickListener(logButton, e -> toggleLogLevels(logButton));
5454
updateLogLevel(logButton);
5555

5656
UiUtils.addSettingButton(this, "View Logs", "VIEW", this::viewLogs);

0 commit comments

Comments
 (0)