Esempio 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;
 }
Esempio n. 2
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;
 }
Esempio n. 3
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);
 }
Esempio n. 4
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();
 }