Small improvements

This commit is contained in:
M66B 2015-12-09 19:42:19 +01:00
parent b512f2d98b
commit d68f927cf7
1 changed files with 5 additions and 10 deletions

View File

@ -281,9 +281,7 @@ public class SinkholeService extends VpnService {
return; return;
// Schedule next update // Schedule next update
Message msg = new Message(); mServiceHandler.sendEmptyMessageDelayed(MSG_STATS_UPDATE, 1000);
msg.what = MSG_STATS_UPDATE;
mServiceHandler.sendMessageDelayed(msg, 1000);
// Cleanup // Cleanup
while (gt.size() >= 100) { while (gt.size() >= 100) {
@ -314,7 +312,6 @@ public class SinkholeService extends VpnService {
// Create bitmap // Create bitmap
int height = Util.dips2pixels(96, SinkholeService.this); int height = Util.dips2pixels(96, SinkholeService.this);
int width = Util.dips2pixels(96 * 5, SinkholeService.this); int width = Util.dips2pixels(96 * 5, SinkholeService.this);
Log.i(TAG, "h=" + height + " w=" + width);
Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
// Create canvas // Create canvas
@ -376,11 +373,11 @@ public class SinkholeService extends VpnService {
RemoteViews remoteViews = new RemoteViews(getPackageName(), R.layout.traffic); RemoteViews remoteViews = new RemoteViews(getPackageName(), R.layout.traffic);
remoteViews.setImageViewBitmap(R.id.ivTraffic, bitmap); remoteViews.setImageViewBitmap(R.id.ivTraffic, bitmap);
if (txsec < 1024 && rxsec < 1024) if (txsec < 1024 && rxsec < 1024)
remoteViews.setTextViewText(R.id.tvTraffic, String.format("%.0f / %.0f B/sec", txsec, rxsec)); remoteViews.setTextViewText(R.id.tvTraffic, String.format("▲ %.0f ▼ %.0f B/sec", txsec, rxsec));
else if (txsec < 1024 * 1024 && rxsec < 1024 * 1024) else if (txsec < 1024 * 1024 && rxsec < 1024 * 1024)
remoteViews.setTextViewText(R.id.tvTraffic, String.format("%.1f / %.1f KiB/sec", txsec / 1024, rxsec / 1024)); remoteViews.setTextViewText(R.id.tvTraffic, String.format("▲ %.1f ▼ %.1f KiB/sec", txsec / 1024, rxsec / 1024));
else else
remoteViews.setTextViewText(R.id.tvTraffic, String.format("%.1f / %.1f MiB/sec", txsec / 1024 / 1024, rxsec / 1024 / 1024)); remoteViews.setTextViewText(R.id.tvTraffic, String.format("▲ %.1f ▼ %.1f MiB/sec", txsec / 1024 / 1024, rxsec / 1024 / 1024));
// Show notification // Show notification
Intent main = new Intent(SinkholeService.this, ActivityMain.class); Intent main = new Intent(SinkholeService.this, ActivityMain.class);
@ -591,9 +588,7 @@ public class SinkholeService extends VpnService {
// Start/stop stats // Start/stop stats
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
Message msg = new Message(); mServiceHandler.sendEmptyMessage(pm.isInteractive() ? MSG_STATS_START : MSG_STATS_STOP);
msg.what = pm.isInteractive() ? MSG_STATS_START : MSG_STATS_STOP;
mServiceHandler.sendMessage(msg);
} }
}; };