Anonymous avatar Anonymous committed e1819f8

LogCat: multiple devices support: some fixes

Comments (0)

Files changed (1)

logcat_multiple_devices.patch

 # HG changeset patch
 # Date 1309392817 -7200
-# Parent 10794bc93b5baec24a9163429fed2daa2370e6b4
+# Parent c54ea20aa966af9635809dac3c1b118e96d55f07
 LogCat: Added support for multiple devices
 
 diff --git a/logcat/nbproject/project.xml b/logcat/nbproject/project.xml
 +        // do nothing
 +    }
 +}
+diff --git a/logcat/src/org/nyerel/nbandroid/logcat/LogEvent.java b/logcat/src/org/nyerel/nbandroid/logcat/LogEvent.java
+--- a/logcat/src/org/nyerel/nbandroid/logcat/LogEvent.java
++++ b/logcat/src/org/nyerel/nbandroid/logcat/LogEvent.java
+@@ -138,12 +138,26 @@
+     public boolean equals(Object obj) {
+         if(obj instanceof LogEvent) {
+             LogEvent o = (LogEvent) obj;
+-            if(message != null) {
+-                return message.equals(o.getMessage());
++
++            if (message==null && o.message!=null) {
++                return false;
+             }
+-            
+-            return o.getMessage() == null;
++
++            if (message.equals(o.message) == false) {
++                return false;
++            }
++
++            if (info==null && o.info!=null) {
++                return false;
++            }
++
++            if (info.equals(o.info) == false) {
++                return false;
++            }
++
++            return true;
+         }
++
+         return super.equals(obj);
+     }
+ }
 diff --git a/logcat/src/org/nyerel/nbandroid/logcat/LogReader.java b/logcat/src/org/nyerel/nbandroid/logcat/LogReader.java
 --- a/logcat/src/org/nyerel/nbandroid/logcat/LogReader.java
 +++ b/logcat/src/org/nyerel/nbandroid/logcat/LogReader.java
      }
  
      private void reallyStartReading() {
--        IDevice[] devs = adb.getDevices();
++        String currentDeviceSerial = currentDevice!=null ? currentDevice.getSerialNumber() : "";
+         IDevice[] devs = adb.getDevices();
 -        if (devs != null && devs.length > 0) {
 -            device = devs[0];
 -        } else {
 -            errorMessage("No devices found!");
 -            return;
++
 +        if (requestedDeviceSerial == null) {
 +            currentDevice = null;
 +            
 +            // if no device was requested, select the first available
-+            IDevice[] devs = adb.getDevices();
 +            if (devs != null && devs.length > 0) {
 +                requestedDeviceSerial = devs[0].getSerialNumber();
 +            }
          }
          
 -        if (device.isOnline()) {
-+        // select current device by requested serial
-+        if (currentDevice == null || !currentDevice.getSerialNumber().equals(requestedDeviceSerial)) {
-+            currentDevice =  null;
-             
+-            
 -           // Clear log on newly connected devices
 -            if(lastDeviceSN != null && !lastDeviceSN.equals(device.getSerialNumber())) {
 -                
 -                loggedEvents.clear();
 -                lastDeviceSN = device.getSerialNumber();
-+            IDevice[] devs = adb.getDevices();
-+            if (devs != null) {
-+                for(IDevice dev : devs) {
-+                    if (dev.getSerialNumber().equals(requestedDeviceSerial)) {
-+                        currentDevice = dev;
-+                        break;
-+                    }
++        // always select current device by requested serial,
++        // because the device object may have changed when was disconnected
++        if (devs != null) {
++            for(IDevice dev : devs) {
++                if (dev.getSerialNumber().equals(requestedDeviceSerial)) {
++                    currentDevice = dev;
++                    break;
 +                }
              }
 -            
 -            receiver = new LogCatOutputReceiver();
++        }
 +
-+            // notify all clients, the selected device has changed
++        // notify all clients, if the selected device has changed
++        if (!currentDeviceSerial.equals(requestedDeviceSerial)) {
 +            changeSupport.firePropertyChange(PROPERTY_CURRENT_DEVICE, null, requestedDeviceSerial);
 +        }
 +        
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.