Commits

Michael Knight  committed 99e2b1e

Switch to use tabs for indenting only.

  • Participants
  • Parent commits c61c06f

Comments (0)

Files changed (1)

File src/com/miknight/bameter/BameterActivity.java

 import android.widget.TextView;
 
 public class BameterActivity extends Activity {
-	
+
 	private TextView ptext;
 	private Handler handler;
 	private long downloaded, uploaded;
-	
-    /** Called when the activity is first created. */
-    @Override
-    public void onCreate(Bundle savedInstanceState) {
-        super.onCreate(savedInstanceState);
-        setContentView(R.layout.main);
-        handler = new Handler();
-        startRepeatingTask();
-    }
-    
-    private void generateNotification(String txt) {
-    	Resources res = getResources();
-        int icon = R.drawable.notify_icon;
-        String appName = res.getString(R.string.app_name);
-        
-        Context context = getApplicationContext();
-        String ns = Context.NOTIFICATION_SERVICE;
-        
-        Intent notificationIntent = new Intent(context, BameterActivity.class);
-        PendingIntent contentIntent = PendingIntent
-        		.getActivity(context, 
-        		1, notificationIntent,
-                PendingIntent.FLAG_CANCEL_CURRENT);
-        
-        NotificationManager nm = (NotificationManager) getSystemService(ns);
-        Notification notification = new Notification.Builder(context)
-        .setContentTitle(appName)
-        .setContentText(txt)
-        .setContentIntent(contentIntent)
-        .setOngoing(true)
-        .setSmallIcon(icon)
-        .getNotification();
-        
-        nm.notify(1, notification);
-    }
-    
-    Runnable pingRunner = new Runnable() {
-    	public void run() {
-    		pingNetworkStats("eth0");
-    		handler.postDelayed(pingRunner, 1000);
-    	}
-    };
-    
-    void startRepeatingTask() {
-    	pingRunner.run(); 
-    }
-
-    void stopRepeatingTask() {
-    	handler.removeCallbacks(pingRunner);
-    }
-    
-    private void pingNetworkStats(String device) {
-    	Process p;
-    	String downloadOutput = "";
-    	String uploadOutput = "";
-    	String debug = "";
-        long newDownloaded = 0;
-        long newUploaded = 0;
-    	try {
-    		p = Runtime.getRuntime().exec("cat /proc/net/dev");
-    		BufferedReader istream = new BufferedReader(new InputStreamReader(p.getInputStream()));
-    		String line;
-    		while ((line = istream.readLine()) != null) {
-    			debug += line + "\n";
-    			//if (line.matches(".*" + device + ":.*") || line.matches(".*rmnet0.*")) {
-    			// Collect I/O from all devices.
-    			// TODO: Exclude loopback.
-    			if (line.matches(".*[a-z0-9]+:.*")) {
-    				downloadOutput = line.split("\\s+")[2];
-    				uploadOutput = line.split("\\s+")[10];
-    				newDownloaded += Long.parseLong(downloadOutput);
-    				newUploaded += Long.parseLong(uploadOutput);
-    			}
-    		}
-    	} catch (IOException e) {
-    		// TODO Auto-generated catch block
-    		e.printStackTrace();
-    		return;
-    	}
-    	String output = "";
-    	if (downloadOutput.isEmpty() || uploadOutput.isEmpty()) {
-    		output = debug;
-    	} else {
+
+	/** Called when the activity is first created. */
+	@Override
+	public void onCreate(Bundle savedInstanceState) {
+		super.onCreate(savedInstanceState);
+		setContentView(R.layout.main);
+		handler = new Handler();
+		startRepeatingTask();
+	}
+
+	private void generateNotification(String txt) {
+		Resources res = getResources();
+		int icon = R.drawable.notify_icon;
+		String appName = res.getString(R.string.app_name);
+
+		Context context = getApplicationContext();
+		String ns = Context.NOTIFICATION_SERVICE;
+
+		Intent notificationIntent = new Intent(context, BameterActivity.class);
+		PendingIntent contentIntent = PendingIntent.getActivity(context, 1,
+				notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT);
+
+		NotificationManager nm = (NotificationManager) getSystemService(ns);
+		Notification notification = new Notification.Builder(context)
+				.setContentTitle(appName)
+				.setContentText(txt)
+				.setContentIntent(contentIntent)
+				.setOngoing(true)
+				.setSmallIcon(icon)
+				.getNotification();
+
+		nm.notify(1, notification);
+	}
+
+	Runnable pingRunner = new Runnable() {
+		public void run() {
+			pingNetworkStats("eth0");
+			handler.postDelayed(pingRunner, 1000);
+		}
+	};
+
+	void startRepeatingTask() {
+		pingRunner.run();
+	}
+
+	void stopRepeatingTask() {
+		handler.removeCallbacks(pingRunner);
+	}
+
+	private void pingNetworkStats(String device) {
+		Process p;
+		String downloadOutput = "";
+		String uploadOutput = "";
+		String debug = "";
+		long newDownloaded = 0;
+		long newUploaded = 0;
+		try {
+			p = Runtime.getRuntime().exec("cat /proc/net/dev");
+			BufferedReader istream = new BufferedReader(new InputStreamReader(
+					p.getInputStream()));
+			String line;
+			while ((line = istream.readLine()) != null) {
+				debug += line + "\n";
+				// if (line.matches(".*" + device + ":.*") ||
+				// line.matches(".*rmnet0.*")) {
+				// Collect I/O from all devices.
+				// TODO: Exclude loopback.
+				if (line.matches(".*[a-z0-9]+:.*")) {
+					downloadOutput = line.split("\\s+")[2];
+					uploadOutput = line.split("\\s+")[10];
+					newDownloaded += Long.parseLong(downloadOutput);
+					newUploaded += Long.parseLong(uploadOutput);
+				}
+			}
+		} catch (IOException e) {
+			// TODO Auto-generated catch block
+			e.printStackTrace();
+			return;
+		}
+		String output = "";
+		if (downloadOutput.isEmpty() || uploadOutput.isEmpty()) {
+			output = debug;
+		} else {
 			long d_diff = (newDownloaded - downloaded);
 			long u_diff = (newUploaded - uploaded);
-    		output = d_diff/1024 + " KB/s down,\n"
-    				+ u_diff/1024 + " KB/s up.\n";
-    		downloaded = newDownloaded;
-    		uploaded = newUploaded;
-    	}
-    	setMeterText(output);
-        generateNotification(output);
-    }
-    
-    private void setMeterText(String s) {
-        ptext = (TextView) findViewById(R.id.textView1);
-        ptext.setText(s);
-    }
-    
-    public void exitApplication(View view) {
-    	NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
-    	nm.cancelAll();
-        this.finish();
-
-    }
-}
+			output = d_diff / 1024 + " KB/s down,\n" + u_diff / 1024
+					+ " KB/s up.\n";
+			downloaded = newDownloaded;
+			uploaded = newUploaded;
+		}
+		setMeterText(output);
+		generateNotification(output);
+	}
+
+	private void setMeterText(String s) {
+		ptext = (TextView) findViewById(R.id.textView1);
+		ptext.setText(s);
+	}
+
+	public void exitApplication(View view) {
+		NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
+		nm.cancelAll();
+		this.finish();
+
+	}
+}