Пример #1
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;
 }
Пример #2
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;
 }