Ejemplo 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;
 }
Ejemplo 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();
   }
 }
Ejemplo n.º 3
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);
   }
 }
Ejemplo 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);
 }
Ejemplo 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;
 }
Ejemplo n.º 6
0
 @Override
 public View getView(int position, View convertView, ViewGroup parent) {
   Device device = getItem(position);
   if (convertView == null) {
     convertView =
         LayoutInflater.from(mContext).inflate(R.layout.item_device_list, parent, false);
   }
   TextView tvName = (TextView) convertView.findViewById(R.id.device_name);
   TextView tvIP = (TextView) convertView.findViewById(R.id.device_ip);
   TextView tvTraffic = (TextView) convertView.findViewById(R.id.device_traffic);
   View imgBlocked = convertView.findViewById(R.id.blocked);
   ProgressBar pbTrafficBar = (ProgressBar) convertView.findViewById(R.id.traffic_bar);
   tvName.setText(device.name());
   tvIP.setText(device.lastIP());
   imgBlocked.setVisibility(device.isBlocked() ? View.VISIBLE : View.GONE);
   if (device.isActive()) {
     pbTrafficBar.setVisibility(View.VISIBLE);
     tvName.setTextColor(Color.BLACK);
     tvTraffic.setText(String.format("%.2f", device.lastSpeed() / 1000) + " kb/s");
     if (mTotalTraffic > 0)
       pbTrafficBar.setProgress(Math.round(device.lastSpeed() / mTotalTraffic * 100));
     else pbTrafficBar.setProgress(0);
     if (device.prioritizedUntil() == Device.NOT_PRIORITIZED) {
       convertView.findViewById(R.id.priority).setVisibility(View.INVISIBLE);
     } else {
       if (device.prioritizedUntil() == Device.INDETERMINATE_PRIORITY) {
         ((TextView) convertView.findViewById(R.id.priority_until))
             .setText(R.string.indeterminite_priority_access);
         convertView.findViewById(R.id.until).setVisibility(View.INVISIBLE);
       } else {
         convertView.findViewById(R.id.until).setVisibility(View.VISIBLE);
         long now = System.currentTimeMillis() / 1000;
         if (device.prioritizedUntil() < now) {
           convertView.findViewById(R.id.priority).setVisibility(View.INVISIBLE);
           ((TextView) convertView.findViewById(R.id.priority_until))
               .setText(R.string.indeterminite_priority_access);
         } else {
           convertView.findViewById(R.id.priority).setVisibility(View.VISIBLE);
           Calendar undoTime = Calendar.getInstance();
           undoTime.setTimeInMillis(device.prioritizedUntil());
           String time =
               undoTime.get(Calendar.HOUR)
                   + ":"
                   + String.format("%02d", undoTime.get(Calendar.MINUTE));
           ((TextView) convertView.findViewById(R.id.priority_until))
               .setText(R.string.priority_access_until);
           ((TextView) convertView.findViewById(R.id.until)).setText(time);
         }
       }
     }
   } else {
     tvName.setTextColor(Color.GRAY);
     pbTrafficBar.setVisibility(View.GONE);
     tvTraffic.setText("");
     convertView.findViewById(R.id.priority).setVisibility(View.INVISIBLE);
   }
   return convertView;
 }
Ejemplo n.º 7
0
 public DeviceListAdapter(Context context, List<Device> devices) {
   super(context, 0, devices);
   mContext = context;
   mTotalTraffic = 0;
   for (Device d : devices) if (d.isActive()) mTotalTraffic += d.lastSpeed();
 }