Пример #1
0
 private void updateDeviceName(Device device, String custom_name, int list_index) {
   if (device.customName() == null || !device.customName().equals(custom_name)) {
     device.setCustomName(custom_name);
     mDevices.updateName(device.mac(), custom_name);
     mDevicesList[list_index] = mDevices.getDevicesOnNetwork(mRouterId, device.lastNetwork());
     ((DeviceListAdapter)
             ((ListView) mDetailView.findViewById(R.id.network_device_list)).getAdapter())
         .notifyDataSetChanged();
   }
 }
Пример #2
0
 private void setupFakeDevices() {
   mDevices = new Devices(mContext);
   mDevices.removeFakeDevices(getRouterId());
   mTimestamp = System.currentTimeMillis();
   getNetworkIds();
   int total_devices = rnd.nextInt(40) + 3;
   Log.d(TAG, "Generating " + total_devices + " fake devices");
   for (int i = 0; i < total_devices; i++) {
     Device device = new Device(getRouterId(), randomMACAddress(), randomDeviceName());
     device.setCurrentIP("192.168.1." + (rnd.nextInt(253) + 1));
     device.setCurrentNetwork(mNetworkIds[rnd.nextInt(mNetworkIds.length)]);
     device.setActive(rnd.nextInt(100) < 25);
     device.setTrafficStats(0, 0, mTimestamp - 60000); // 1 min ago
     mDevices.insertOrUpdate(device);
   }
 }
Пример #3
0
 @Override
 public int getTotalDevicesOn(String network_id) {
   int total = 0;
   for (Device d : mDevices.getDevicesOnNetwork(getRouterId(), network_id)) {
     if (d.isActive()) total++;
   }
   return total;
 }
Пример #4
0
 @Override
 public void updateTrafficStats() {
   long now = System.currentTimeMillis();
   for (String networkId : mNetworkIds) {
     for (Device d : mDevices.getDevicesOnNetwork(getRouterId(), networkId)) {
       if (d.isActive()) {
         long elapsed_time = (now - mTimestamp) / 1000;
         long bytes = Math.round(Math.pow((rnd.nextInt(5000) / 10000F), -1.7) * 10240);
         long traffic = Math.round((float) bytes / elapsed_time);
         d.setTrafficStats(traffic, traffic, now);
         mDevices.insertOrUpdate(d);
       }
     }
   }
   mTimestamp = now;
   handler.postDelayed(
       new Runnable() {
         @Override
         public void run() {
           mListener.onRouterActivityComplete(ACTIVITY_TRAFFIC_UPDATED, ACTIVITY_STATUS_SUCCESS);
         }
       },
       300);
 }
Пример #5
0
 public void setupNetworkClickListener(final int index) {
   try {
     final View icon = mNetworkIcons[index];
     final String network_id = (String) icon.getTag();
     mDevicesList[index] = mDevices.getDevicesOnNetwork(mRouterId, network_id);
     icon.setOnClickListener(
         new View.OnClickListener() {
           @Override
           public void onClick(View v) {
             final Network network = mNetworks.get(mRouterId, network_id);
             mDetailView
                 .findViewById(R.id.network_name)
                 .setOnClickListener(
                     new View.OnClickListener() {
                       @Override
                       public void onClick(View v) {
                         AlertDialog.Builder alert = new AlertDialog.Builder(getActivity());
                         final EditText editText = new EditText(getActivity());
                         editText.setHint(network.networkId());
                         editText.setText(network.customName());
                         editText.setSingleLine();
                         alert.setTitle(getString(R.string.modify_network_name));
                         alert.setView(editText);
                         alert.setOnCancelListener(
                             new DialogInterface.OnCancelListener() {
                               @Override
                               public void onCancel(DialogInterface dialog) {
                                 updateNetworkName(network, editText.getText().toString());
                               }
                             });
                         alert.show();
                       }
                     });
             // setupDeviceClickListeners
             setupDeviceClickListeners(index);
             showDetailView(network.name());
           }
         });
   } catch (Exception ex) {
     Log.e(TAG, "setupNetworkClickListener: " + ex.getMessage());
   }
 }
Пример #6
0
 String randomDeviceName() {
   String[] people =
       new String[] {
         "Dave",
         "Monica",
         "Ralph",
         "Julie",
         "Guido",
         "Alfons",
         "Sarah",
         "Jean",
         "Kelly",
         "David",
         "Maryanne",
         "Joel",
         "Dannika",
         "Lorrie",
         "Stephen",
         "Harlow",
         "Pixie",
         "Donna",
         "Darth Vader",
         "Lindsay",
         "Norm",
         "Pinky",
         "Dillon",
         "Eugene",
         "Sam",
         "Ronald",
         "Ice man",
         "Wellington",
         "Tuna",
         "Nice lady"
       };
   String[] devices =
       new String[] {
         "Main Computer",
         "[NAME]'s laptop",
         "[NAME]'s MacBook Pro",
         "[NAME]'s iPhone",
         "[NAME]'s phone",
         "[NAME]'s Android",
         "Kid's tablet",
         "Telephone",
         "Thermostat",
         "Smart TV",
         "Bedroom TV",
         "Apple TV",
         "Kindle Fire TV",
         "Work computer",
         "[NAME]'s computer",
         "Printer",
         "Color printer",
         "Print server",
         "[NAME]'s iPad",
         "XBox",
         "[NAME]'s Wii",
         "Old iPad",
         "RPi",
         "Cisco [ID]",
         "android-[ID]",
         "generic game console",
         "Google Glass"
       };
   boolean duplicate = true;
   String name = people[rnd.nextInt(people.length)];
   String devicename = "";
   while (duplicate) {
     String id = randomString(rnd.nextInt(5) + 5);
     devicename = devices[rnd.nextInt(devices.length)].replace("[NAME]", name).replace("[ID]", id);
     duplicate = false;
     for (String n : getNetworkIds()) {
       for (Device d : mDevices.getDevicesOnNetwork(getRouterId(), n)) {
         if (d.name().equals(devicename)) {
           duplicate = true;
           break;
         }
       }
     }
   }
   return devicename;
 }