Exemplo n.º 1
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;
 }
Exemplo n.º 2
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();
   }
 }
Exemplo n.º 3
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());
   }
 }
Exemplo n.º 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);
 }
Exemplo n.º 5
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;
 }