@@ -2,6 +2,5 @@ package com.github.shadowsocks.aidl;
|
||||
|
||||
interface IShadowsocksServiceCallback {
|
||||
oneway void stateChanged(int state, String msg);
|
||||
oneway void trafficUpdated(String txRate, String rxRate,
|
||||
String txTotal, String rxTotal);
|
||||
oneway void trafficUpdated(long txRate, long rxRate, long txTotal, long rxTotal);
|
||||
}
|
||||
|
||||
@@ -90,8 +90,7 @@ trait BaseService extends Service {
|
||||
timer.schedule(task, 1000, 1000)
|
||||
}
|
||||
TrafficMonitor.updateRate()
|
||||
cb.trafficUpdated(TrafficMonitor.getTxRate, TrafficMonitor.getRxRate,
|
||||
TrafficMonitor.getTxTotal, TrafficMonitor.getRxTotal)
|
||||
cb.trafficUpdated(TrafficMonitor.txRate, TrafficMonitor.rxRate, TrafficMonitor.txTotal, TrafficMonitor.rxTotal)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -162,10 +161,10 @@ trait BaseService extends Service {
|
||||
val handler = new Handler(getContext.getMainLooper)
|
||||
handler.post(() => {
|
||||
if (callbacksCount > 0) {
|
||||
val txRate = TrafficMonitor.getTxRate
|
||||
val rxRate = TrafficMonitor.getRxRate
|
||||
val txTotal = TrafficMonitor.getTxTotal
|
||||
val rxTotal = TrafficMonitor.getRxTotal
|
||||
val txRate = TrafficMonitor.txRate
|
||||
val rxRate = TrafficMonitor.rxRate
|
||||
val txTotal = TrafficMonitor.txTotal
|
||||
val rxTotal = TrafficMonitor.rxTotal
|
||||
val n = callbacks.beginBroadcast()
|
||||
for (i <- 0 until n) {
|
||||
try {
|
||||
|
||||
@@ -61,17 +61,15 @@ class ProfileManagerActivity extends AppCompatActivity with OnMenuItemClickListe
|
||||
})
|
||||
}
|
||||
|
||||
def updateText(refetch: Boolean = false) {
|
||||
def updateText(txTotal: Long = 0, rxTotal: Long = 0) {
|
||||
val builder = new SpannableStringBuilder
|
||||
val item = if (refetch) ShadowsocksApplication.profileManager.getProfile(this.item.id) match {
|
||||
case Some(profile) => profile
|
||||
case None => return
|
||||
} else this.item
|
||||
val tx = item.tx + txTotal
|
||||
val rx = item.rx + rxTotal
|
||||
builder.append(item.name)
|
||||
if (item.tx != 0 || item.rx != 0) {
|
||||
if (tx != 0 || rx != 0) {
|
||||
val start = builder.length
|
||||
builder.append(getString(R.string.stat_profiles,
|
||||
TrafficMonitor.formatTraffic(item.tx), TrafficMonitor.formatTraffic(item.rx)))
|
||||
TrafficMonitor.formatTraffic(tx), TrafficMonitor.formatTraffic(rx)))
|
||||
builder.setSpan(new TextAppearanceSpan(ProfileManagerActivity.this, android.R.style.TextAppearance_Small),
|
||||
start + 1, builder.length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
|
||||
}
|
||||
@@ -207,8 +205,8 @@ class ProfileManagerActivity extends AppCompatActivity with OnMenuItemClickListe
|
||||
|
||||
attachService(new IShadowsocksServiceCallback.Stub {
|
||||
def stateChanged(state: Int, msg: String) = () // ignore
|
||||
def trafficUpdated(txRate: String, rxRate: String, txTotal: String, rxTotal: String) =
|
||||
if (selectedItem != null) selectedItem.updateText(true)
|
||||
def trafficUpdated(txRate: Long, rxRate: Long, txTotal: Long, rxTotal: Long) =
|
||||
if (selectedItem != null) selectedItem.updateText(txTotal, rxTotal)
|
||||
})
|
||||
|
||||
if (ShadowsocksApplication.settings.getBoolean(profileTip, true)) {
|
||||
|
||||
@@ -154,14 +154,15 @@ class Shadowsocks
|
||||
state = s
|
||||
})
|
||||
}
|
||||
def trafficUpdated(txRate: String, rxRate: String, txTotal: String, rxTotal: String) {
|
||||
trafficCache = getString(R.string.stat_summary).formatLocal(Locale.ENGLISH, txRate, rxRate, txTotal, rxTotal)
|
||||
def trafficUpdated(txRate: Long, rxRate: Long, txTotal: Long, rxTotal: Long) {
|
||||
trafficCache = getString(R.string.stat_summary).formatLocal(Locale.ENGLISH,
|
||||
TrafficMonitor.formatTraffic(txRate), TrafficMonitor.formatTraffic(rxRate),
|
||||
TrafficMonitor.formatTraffic(txTotal), TrafficMonitor.formatTraffic(rxTotal))
|
||||
handler.post(updateTraffic)
|
||||
}
|
||||
}
|
||||
|
||||
def updateTraffic(): Unit = if (trafficCache == null) callback.trafficUpdated(TrafficMonitor.getTxRate,
|
||||
TrafficMonitor.getRxRate, TrafficMonitor.getTxTotal, TrafficMonitor.getRxTotal) else {
|
||||
def updateTraffic(): Unit = if (trafficCache == null) callback.trafficUpdated(0, 0, 0, 0) else {
|
||||
if (connectionTestResult == null) connectionTestResult = getString(R.string.connection_test_pending)
|
||||
if (preferences.natSwitch.isChecked) {
|
||||
preferences.stat.setSummary(trafficCache)
|
||||
|
||||
@@ -9,20 +9,22 @@ import android.support.v4.app.NotificationCompat
|
||||
import android.support.v4.app.NotificationCompat.BigTextStyle
|
||||
import android.support.v4.content.ContextCompat
|
||||
import com.github.shadowsocks.aidl.IShadowsocksServiceCallback.Stub
|
||||
import com.github.shadowsocks.utils.{Action, State, Utils}
|
||||
import com.github.shadowsocks.utils.{TrafficMonitor, Action, State, Utils}
|
||||
|
||||
/**
|
||||
* @author Mygod
|
||||
*/
|
||||
class ShadowsocksNotification(private val service: BaseService, profileName: String, visible: Boolean = false) {
|
||||
private lazy val keyGuard = service.getSystemService(Context.KEYGUARD_SERVICE).asInstanceOf[KeyguardManager]
|
||||
private val keyGuard = service.getSystemService(Context.KEYGUARD_SERVICE).asInstanceOf[KeyguardManager]
|
||||
private lazy val nm = service.getSystemService(Context.NOTIFICATION_SERVICE).asInstanceOf[NotificationManager]
|
||||
private lazy val callback = new Stub {
|
||||
override def stateChanged(state: Int, msg: String) = () // ignore
|
||||
override def trafficUpdated(txRate: String, rxRate: String, txTotal: String, rxTotal: String) {
|
||||
builder.setContentText(service.getString(R.string.traffic_summary).formatLocal(Locale.ENGLISH, txRate, rxRate))
|
||||
style.bigText(service.getString(R.string.stat_summary)
|
||||
.formatLocal(Locale.ENGLISH, txRate, rxRate, txTotal, rxTotal))
|
||||
override def trafficUpdated(txRate: Long, rxRate: Long, txTotal: Long, rxTotal: Long) {
|
||||
val txr = TrafficMonitor.formatTraffic(txRate)
|
||||
val rxr = TrafficMonitor.formatTraffic(rxRate)
|
||||
builder.setContentText(service.getString(R.string.traffic_summary).formatLocal(Locale.ENGLISH, txr, rxr))
|
||||
style.bigText(service.getString(R.string.stat_summary).formatLocal(Locale.ENGLISH, txr, rxr,
|
||||
TrafficMonitor.formatTraffic(txTotal), TrafficMonitor.formatTraffic(rxTotal)))
|
||||
show()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,29 +80,5 @@ object TrafficMonitor {
|
||||
rxLast = 0
|
||||
dirty = true
|
||||
}
|
||||
|
||||
def getTxTotal(): String = {
|
||||
formatTraffic(txTotal)
|
||||
}
|
||||
|
||||
def getRxTotal(): String = {
|
||||
formatTraffic(rxTotal)
|
||||
}
|
||||
|
||||
def getTotal(): String = {
|
||||
formatTraffic(txTotal + rxTotal)
|
||||
}
|
||||
|
||||
def getTxRate(): String = {
|
||||
formatTraffic(txRate)
|
||||
}
|
||||
|
||||
def getRxRate(): String = {
|
||||
formatTraffic(rxRate)
|
||||
}
|
||||
|
||||
def getRate(): String = {
|
||||
formatTraffic(txRate + rxRate)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user