Commit 4258e95f authored by Max Lv's avatar Max Lv

Merge pull request #568 from Mygod/layout

Refine layout of StatusPreference
parents fbdf2dbf cd5c2ef8
...@@ -37,6 +37,7 @@ libraryDependencies ++= Seq( ...@@ -37,6 +37,7 @@ libraryDependencies ++= Seq(
"com.google.android.gms" % "play-services-ads" % "8.4.0", "com.google.android.gms" % "play-services-ads" % "8.4.0",
"com.google.android.gms" % "play-services-analytics" % "8.4.0", "com.google.android.gms" % "play-services-analytics" % "8.4.0",
"com.android.support" % "design" % "23.1.1", "com.android.support" % "design" % "23.1.1",
"com.android.support" % "gridlayout-v7" % "23.1.1",
"com.github.jorgecastilloprz" % "fabprogresscircle" % "1.01", "com.github.jorgecastilloprz" % "fabprogresscircle" % "1.01",
"com.j256.ormlite" % "ormlite-core" % "4.48", "com.j256.ormlite" % "ormlite-core" % "4.48",
"com.j256.ormlite" % "ormlite-android" % "4.48", "com.j256.ormlite" % "ormlite-android" % "4.48",
......
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FFFFFFFF"
android:pathData="M19.35,10.04C18.67,6.59 15.64,4 12,4 9.11,4 6.6,5.64 5.35,8.04 2.34,8.36 0,10.91 0,14c0,3.31 2.69,6 6,6h13c2.76,0 5,-2.24 5,-5 0,-2.64 -2.05,-4.78 -4.65,-4.96z"/>
</vector>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FFFFFFFF"
android:pathData="M19.35,10.04C18.67,6.59 15.64,4 12,4c-1.48,0 -2.85,0.43 -4.01,1.17l1.46,1.46C10.21,6.23 11.08,6 12,6c3.04,0 5.5,2.46 5.5,5.5v0.5H19c1.66,0 3,1.34 3,3 0,1.13 -0.64,2.11 -1.56,2.62l1.45,1.45C23.16,18.16 24,16.68 24,15c0,-2.64 -2.05,-4.78 -4.65,-4.96zM3,5.27l2.75,2.74C2.56,8.15 0,10.77 0,14c0,3.31 2.69,6 6,6h11.73l2,2L21,20.73 4.27,4 3,5.27zM7.73,10l8,8H6c-2.21,0 -4,-1.79 -4,-4s1.79,-4 4,-4h1.73z"/>
</vector>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FFFFFFFF"
android:pathData="M19.35,10.04C18.67,6.59 15.64,4 12,4 9.11,4 6.6,5.64 5.35,8.04 2.34,8.36 0,10.91 0,14c0,3.31 2.69,6 6,6h13c2.76,0 5,-2.24 5,-5 0,-2.64 -2.05,-4.78 -4.65,-4.96zM19,18H6c-2.21,0 -4,-1.79 -4,-4s1.79,-4 4,-4h0.71C7.37,7.69 9.48,6 12,6c3.04,0 5.5,2.46 5.5,5.5v0.5H19c1.66,0 3,1.34 3,3s-1.34,3 -3,3z"/>
</vector>
...@@ -4,33 +4,23 @@ ...@@ -4,33 +4,23 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:minHeight="?android:attr/listPreferredItemHeight" android:minHeight="?android:attr/listPreferredItemHeight"
android:gravity="center_vertical" android:gravity="center_vertical"
android:paddingEnd="?android:attr/scrollbarSize" android:paddingLeft="15dip"
android:paddingRight="15dip"
android:paddingTop="6dip"
android:paddingBottom="6dip"
android:background="?android:attr/selectableItemBackground" android:background="?android:attr/selectableItemBackground"
android:orientation="vertical" > android:orientation="vertical" >
<TableLayout <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content">
android:layout_marginLeft="15dip"
android:layout_marginRight="6dip"
android:layout_marginTop="6dip"
android:layout_marginBottom="6dip"
android:stretchColumns="3"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView <TextView
android:layout_column="0"
android:layout_span="2"
android:id="@android:id/title" android:id="@android:id/title"
android:textSize="16sp" android:textSize="16sp"
android:textColor="?android:attr/textColorPrimary" android:textColor="?android:attr/textColorPrimary"
android:ellipsize="marquee" android:ellipsize="marquee"
android:layout_width="wrap_content" android:layout_width="0dp"
android:layout_height="wrap_content"/> android:layout_height="wrap_content"
android:layout_weight="1"/>
<TextView <TextView
android:layout_column="3"
android:id="@android:id/summary" android:id="@android:id/summary"
android:textSize="14sp" android:textSize="14sp"
android:textColor="?android:attr/textColorSecondary" android:textColor="?android:attr/textColorSecondary"
...@@ -38,71 +28,97 @@ ...@@ -38,71 +28,97 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:gravity="end" /> android:gravity="end" />
</TableRow> </LinearLayout>
<TableRow <android.support.v7.widget.GridLayout
xmlns:app="http://schemas.android.com/apk/res-auto"
app:columnCount="4"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"> android:layout_height="wrap_content">
<TextView <TextView
android:layout_column="0" app:layout_column="0"
style="@style/TextAppearance.AppCompat.Body2" style="@style/TextAppearance.AppCompat.Body2"
android:ellipsize="marquee" android:ellipsize="marquee"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginRight="24dp" android:layout_marginRight="24dp"
android:layout_marginEnd="24dp"
android:gravity="end" android:gravity="end"
android:text="@string/sent" /> android:text="@string/sent" />
<TextView <TextView
android:layout_column="1" app:layout_column="1"
android:id="@+id/tx" android:id="@+id/tx"
style="@style/TextAppearance.AppCompat.Caption" android:textSize="14sp"
android:textColor="?android:attr/textColorSecondary"
android:ellipsize="marquee"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_columnWeight="1"
app:layout_gravity="fill_horizontal" />
<TextView
app:layout_column="2"
android:textSize="14sp"
android:textColor="?android:attr/textColorSecondary"
android:ellipsize="marquee" android:ellipsize="marquee"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:gravity="end" android:text="▲" />
android:text="0 Byte" />
<TextView <TextView
android:layout_column="3" app:layout_column="3"
android:id="@+id/txRate" android:id="@+id/txRate"
style="@style/TextAppearance.AppCompat.Caption" android:textSize="14sp"
android:textColor="?android:attr/textColorSecondary"
android:ellipsize="marquee" android:ellipsize="marquee"
android:layout_width="match_parent" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:gravity="end" app:layout_columnWeight="1"
android:text="▲ 0 B/s" /> app:layout_gravity="fill_horizontal"
</TableRow> android:gravity="end" />
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView <TextView
android:layout_column="0" app:layout_row="1"
app:layout_column="0"
style="@style/TextAppearance.AppCompat.Body2" style="@style/TextAppearance.AppCompat.Body2"
android:ellipsize="marquee" android:ellipsize="marquee"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginRight="24dp" android:layout_marginRight="24dp"
android:layout_marginEnd="24dp"
android:gravity="end" android:gravity="end"
android:text="@string/received"/> android:text="@string/received"/>
<TextView <TextView
android:layout_column="1" app:layout_row="1"
app:layout_column="1"
android:id="@+id/rx" android:id="@+id/rx"
style="@style/TextAppearance.AppCompat.Caption" android:textSize="14sp"
android:textColor="?android:attr/textColorSecondary"
android:ellipsize="marquee"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_columnWeight="1"
app:layout_gravity="fill_horizontal" />
<TextView
app:layout_row="1"
app:layout_column="2"
android:textSize="14sp"
android:textColor="?android:attr/textColorSecondary"
android:ellipsize="marquee" android:ellipsize="marquee"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:gravity="end" android:text="▼" />
android:text="0 Byte" />
<TextView <TextView
android:layout_column="3" app:layout_row="1"
app:layout_column="3"
android:id="@+id/rxRate" android:id="@+id/rxRate"
style="@style/TextAppearance.AppCompat.Caption" android:textSize="14sp"
android:textColor="?android:attr/textColorSecondary"
android:ellipsize="marquee" android:ellipsize="marquee"
android:layout_width="match_parent" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:gravity="end" app:layout_columnWeight="1"
android:text="▼ 0 B/s" /> app:layout_gravity="fill_horizontal"
</TableRow> android:gravity="end" />
</TableLayout> </android.support.v7.widget.GridLayout>
</LinearLayout> </LinearLayout>
...@@ -116,6 +116,5 @@ ...@@ -116,6 +116,5 @@
<!-- status --> <!-- status -->
<string name="sent">发送:</string> <string name="sent">发送:</string>
<string name="received">接收:</string> <string name="received">接收:</string>
<string name="check_connectivity">检查网络连接</string>
</resources> </resources>
...@@ -124,5 +124,4 @@ ...@@ -124,5 +124,4 @@
<!-- status --> <!-- status -->
<string name="sent">Sent:</string> <string name="sent">Sent:</string>
<string name="received">Received:</string> <string name="received">Received:</string>
<string name="check_connectivity">Check Connectivity</string>
</resources> </resources>
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
<com.github.shadowsocks.preferences.StatusPreference <com.github.shadowsocks.preferences.StatusPreference
android:key="stat" android:key="stat"
android:summary="@string/check_connectivity" android:summary="@string/connection_test_pending"
android:title="@string/stat"/> android:title="@string/stat"/>
</PreferenceCategory> </PreferenceCategory>
......
...@@ -58,7 +58,6 @@ import android.view.{View, ViewGroup, ViewParent} ...@@ -58,7 +58,6 @@ import android.view.{View, ViewGroup, ViewParent}
import android.widget._ import android.widget._
import com.github.jorgecastilloprz.FABProgressCircle import com.github.jorgecastilloprz.FABProgressCircle
import com.github.shadowsocks.aidl.IShadowsocksServiceCallback import com.github.shadowsocks.aidl.IShadowsocksServiceCallback
import com.github.shadowsocks.preferences._
import com.github.shadowsocks.database._ import com.github.shadowsocks.database._
import com.github.shadowsocks.utils._ import com.github.shadowsocks.utils._
import com.google.android.gms.ads.{AdRequest, AdSize, AdView} import com.google.android.gms.ads.{AdRequest, AdSize, AdView}
...@@ -107,9 +106,6 @@ class Shadowsocks ...@@ -107,9 +106,6 @@ class Shadowsocks
var state = State.STOPPED var state = State.STOPPED
var currentProfile = new Profile var currentProfile = new Profile
var vpnEnabled = -1 var vpnEnabled = -1
var trafficCache: Array[String] = _
var connectionTestResult: String = _
var connectionTestSuccess: Boolean = true
// Services // Services
var currentServiceName = classOf[ShadowsocksNatService].getName var currentServiceName = classOf[ShadowsocksNatService].getName
...@@ -158,28 +154,13 @@ class Shadowsocks ...@@ -158,28 +154,13 @@ class Shadowsocks
}) })
} }
def trafficUpdated(txRate: Long, rxRate: Long, txTotal: Long, rxTotal: Long) { def trafficUpdated(txRate: Long, rxRate: Long, txTotal: Long, rxTotal: Long) {
trafficCache = Array( handler.post(() => updateTraffic(txRate, rxRate, txTotal, rxTotal))
"▲ " + TrafficMonitor.formatTraffic(txRate) + "/s",
"▼ " + TrafficMonitor.formatTraffic(rxRate) + "/s",
TrafficMonitor.formatTraffic(txTotal), TrafficMonitor.formatTraffic(rxTotal))
handler.post(updateTraffic)
} }
} }
def updateTraffic(): Unit = if (trafficCache == null) callback.trafficUpdated(0, 0, 0, 0) else { def updateTraffic(txRate: Long, rxRate: Long, txTotal: Long, rxTotal: Long) = preferences.stat
if (connectionTestResult == null) connectionTestResult = getString(R.string.connection_test_pending) .setRate(TrafficMonitor.formatTraffic(txTotal), TrafficMonitor.formatTraffic(rxTotal),
if (preferences.natSwitch.isChecked) { TrafficMonitor.formatTraffic(txRate) + "/s", TrafficMonitor.formatTraffic(rxRate) + "/s")
preferences.stat.setSummary("")
} else {
if (connectionTestSuccess) {
preferences.stat.setSummary(connectionTestResult)
} else {
preferences.stat.setSummary(getString(R.string.connection_test_fail))
Snackbar.make(findViewById(android.R.id.content), connectionTestResult, Snackbar.LENGTH_LONG).show
}
}
preferences.stat.asInstanceOf[StatusPreference].setRate(trafficCache(2), trafficCache(3), trafficCache(0), trafficCache(1))
}
def attachService: Unit = attachService(callback) def attachService: Unit = attachService(callback)
...@@ -263,7 +244,7 @@ class Shadowsocks ...@@ -263,7 +244,7 @@ class Shadowsocks
} else { } else {
in = assetManager.open(file) in = assetManager.open(file)
} }
out = new FileOutputStream(getApplicationInfo().dataDir + "/" + file) out = new FileOutputStream(getApplicationInfo.dataDir + "/" + file)
copyFile(in, out) copyFile(in, out)
in.close() in.close()
in = null in = null
...@@ -293,8 +274,8 @@ class Shadowsocks ...@@ -293,8 +274,8 @@ class Shadowsocks
val cmd = new ArrayBuffer[String]() val cmd = new ArrayBuffer[String]()
for (task <- Array("ss-local", "ss-tunnel", "pdnsd", "redsocks", "tun2socks")) { for (task <- Array("ss-local", "ss-tunnel", "pdnsd", "redsocks", "tun2socks")) {
cmd.append("chmod 666 %s/%s-nat.pid".formatLocal(Locale.ENGLISH, getApplicationInfo().dataDir, task)) cmd.append("chmod 666 %s/%s-nat.pid".formatLocal(Locale.ENGLISH, getApplicationInfo.dataDir, task))
cmd.append("chmod 666 %s/%s-vpn.pid".formatLocal(Locale.ENGLISH, getApplicationInfo().dataDir, task)) cmd.append("chmod 666 %s/%s-vpn.pid".formatLocal(Locale.ENGLISH, getApplicationInfo.dataDir, task))
} }
if (ShadowsocksApplication.isVpnEnabled) { if (ShadowsocksApplication.isVpnEnabled) {
...@@ -307,8 +288,8 @@ class Shadowsocks ...@@ -307,8 +288,8 @@ class Shadowsocks
for (task <- Array("ss-local", "ss-tunnel", "pdnsd", "redsocks", "tun2socks")) { for (task <- Array("ss-local", "ss-tunnel", "pdnsd", "redsocks", "tun2socks")) {
try { try {
val pid_nat = scala.io.Source.fromFile(getApplicationInfo().dataDir + "/" + task + "-nat.pid").mkString.trim.toInt val pid_nat = scala.io.Source.fromFile(getApplicationInfo.dataDir + "/" + task + "-nat.pid").mkString.trim.toInt
val pid_vpn = scala.io.Source.fromFile(getApplicationInfo().dataDir + "/" + task + "-vpn.pid").mkString.trim.toInt val pid_vpn = scala.io.Source.fromFile(getApplicationInfo.dataDir + "/" + task + "-vpn.pid").mkString.trim.toInt
cmd.append("kill -9 %d".formatLocal(Locale.ENGLISH, pid_nat)) cmd.append("kill -9 %d".formatLocal(Locale.ENGLISH, pid_nat))
cmd.append("kill -9 %d".formatLocal(Locale.ENGLISH, pid_vpn)) cmd.append("kill -9 %d".formatLocal(Locale.ENGLISH, pid_vpn))
Process.killProcess(pid_nat) Process.killProcess(pid_nat)
...@@ -316,10 +297,10 @@ class Shadowsocks ...@@ -316,10 +297,10 @@ class Shadowsocks
} catch { } catch {
case e: Throwable => // Ignore case e: Throwable => // Ignore
} }
cmd.append("rm -f %s/%s-nat.pid".formatLocal(Locale.ENGLISH, getApplicationInfo().dataDir, task)) cmd.append("rm -f %s/%s-nat.pid".formatLocal(Locale.ENGLISH, getApplicationInfo.dataDir, task))
cmd.append("rm -f %s/%s-nat.conf".formatLocal(Locale.ENGLISH, getApplicationInfo().dataDir, task)) cmd.append("rm -f %s/%s-nat.conf".formatLocal(Locale.ENGLISH, getApplicationInfo.dataDir, task))
cmd.append("rm -f %s/%s-vpn.pid".formatLocal(Locale.ENGLISH, getApplicationInfo().dataDir, task)) cmd.append("rm -f %s/%s-vpn.pid".formatLocal(Locale.ENGLISH, getApplicationInfo.dataDir, task))
cmd.append("rm -f %s/%s-vpn.conf".formatLocal(Locale.ENGLISH, getApplicationInfo().dataDir, task)) cmd.append("rm -f %s/%s-vpn.conf".formatLocal(Locale.ENGLISH, getApplicationInfo.dataDir, task))
} }
if (ShadowsocksApplication.isVpnEnabled) Console.runCommand(cmd.toArray) else { if (ShadowsocksApplication.isVpnEnabled) Console.runCommand(cmd.toArray) else {
Console.runRootCommand(cmd.toArray) Console.runRootCommand(cmd.toArray)
...@@ -389,6 +370,7 @@ class Shadowsocks ...@@ -389,6 +370,7 @@ class Shadowsocks
Toast.LENGTH_SHORT), fab, getWindow, 0, Utils.dpToPx(this, 8)).show Toast.LENGTH_SHORT), fab, getWindow, 0, Utils.dpToPx(this, 8)).show
true true
}) })
updateTraffic(0, 0, 0, 0)
// Bind to the service // Bind to the service
handler.post(() => attachService) handler.post(() => attachService)
...@@ -461,7 +443,6 @@ class Shadowsocks ...@@ -461,7 +443,6 @@ class Shadowsocks
// Check if current profile changed // Check if current profile changed
if (ShadowsocksApplication.profileId != currentProfile.id) reloadProfile() if (ShadowsocksApplication.profileId != currentProfile.id) reloadProfile()
updateTraffic()
updateState() updateState()
} }
...@@ -503,7 +484,7 @@ class Shadowsocks ...@@ -503,7 +484,7 @@ class Shadowsocks
val ab = new ArrayBuffer[String] val ab = new ArrayBuffer[String]
for (executable <- Shadowsocks.EXECUTABLES) { for (executable <- Shadowsocks.EXECUTABLES) {
ab.append("chmod 755 " + getApplicationInfo().dataDir + "/" + executable) ab.append("chmod 755 " + getApplicationInfo.dataDir + "/" + executable)
} }
Console.runCommand(ab.toArray) Console.runCommand(ab.toArray)
} }
......
...@@ -9,10 +9,11 @@ import android.content.{DialogInterface, Intent, SharedPreferences} ...@@ -9,10 +9,11 @@ import android.content.{DialogInterface, Intent, SharedPreferences}
import android.net.Uri import android.net.Uri
import android.os.{Build, Bundle} import android.os.{Build, Bundle}
import android.preference.{Preference, PreferenceFragment, SwitchPreference} import android.preference.{Preference, PreferenceFragment, SwitchPreference}
import android.support.design.widget.Snackbar
import android.support.v7.app.AlertDialog import android.support.v7.app.AlertDialog
import android.webkit.{WebView, WebViewClient} import android.webkit.{WebView, WebViewClient}
import com.github.shadowsocks.database.Profile import com.github.shadowsocks.database.Profile
import com.github.shadowsocks.preferences.{DropDownPreference, NumberPickerPreference, PasswordEditTextPreference, SummaryEditTextPreference} import com.github.shadowsocks.preferences._
import com.github.shadowsocks.utils.CloseUtils._ import com.github.shadowsocks.utils.CloseUtils._
import com.github.shadowsocks.utils.{Key, Utils} import com.github.shadowsocks.utils.{Key, Utils}
...@@ -68,7 +69,7 @@ class ShadowsocksSettings extends PreferenceFragment with OnSharedPreferenceChan ...@@ -68,7 +69,7 @@ class ShadowsocksSettings extends PreferenceFragment with OnSharedPreferenceChan
private def activity = getActivity.asInstanceOf[Shadowsocks] private def activity = getActivity.asInstanceOf[Shadowsocks]
lazy val natSwitch = findPreference(Key.isNAT).asInstanceOf[SwitchPreference] lazy val natSwitch = findPreference(Key.isNAT).asInstanceOf[SwitchPreference]
var stat: Preference = _ var stat: StatusPreference = _
private var isProxyApps: SwitchPreference = _ private var isProxyApps: SwitchPreference = _
private var testCount: Int = _ private var testCount: Int = _
...@@ -78,13 +79,11 @@ class ShadowsocksSettings extends PreferenceFragment with OnSharedPreferenceChan ...@@ -78,13 +79,11 @@ class ShadowsocksSettings extends PreferenceFragment with OnSharedPreferenceChan
addPreferencesFromResource(R.xml.pref_all) addPreferencesFromResource(R.xml.pref_all)
getPreferenceManager.getSharedPreferences.registerOnSharedPreferenceChangeListener(this) getPreferenceManager.getSharedPreferences.registerOnSharedPreferenceChangeListener(this)
stat= findPreference(Key.stat) stat = findPreference(Key.stat).asInstanceOf[StatusPreference]
stat.setOnPreferenceClickListener(_ => { stat.setOnPreferenceClickListener(_ => {
val id = synchronized { val id = synchronized {
testCount += 1 testCount += 1
activity.connectionTestResult = getString(R.string.connection_test_testing) activity.handler.post(() => stat.setSummary(R.string.connection_test_testing))
activity.connectionTestSuccess = true
activity.updateTraffic()
testCount testCount
} }
ThrowableFuture { ThrowableFuture {
...@@ -97,7 +96,7 @@ class ShadowsocksSettings extends PreferenceFragment with OnSharedPreferenceChan ...@@ -97,7 +96,7 @@ class ShadowsocksSettings extends PreferenceFragment with OnSharedPreferenceChan
conn.setUseCaches(false) conn.setUseCaches(false)
if (testCount == id) { if (testCount == id) {
var result: String = null var result: String = null
var success: Boolean = true var success = true
try { try {
val start = currentTimeMillis val start = currentTimeMillis
conn.getInputStream conn.getInputStream
...@@ -107,21 +106,24 @@ class ShadowsocksSettings extends PreferenceFragment with OnSharedPreferenceChan ...@@ -107,21 +106,24 @@ class ShadowsocksSettings extends PreferenceFragment with OnSharedPreferenceChan
result = getString(R.string.connection_test_available, elapsed: java.lang.Long) result = getString(R.string.connection_test_available, elapsed: java.lang.Long)
else throw new Exception(getString(R.string.connection_test_error_status_code, code: Integer)) else throw new Exception(getString(R.string.connection_test_error_status_code, code: Integer))
} catch { } catch {
case e: Exception => { case e: Exception =>
success = false success = false
result = getString(R.string.connection_test_error, e.getMessage) result = getString(R.string.connection_test_error, e.getMessage)
} }
}
synchronized(if (testCount == id) { synchronized(if (testCount == id) {
activity.connectionTestSuccess = success if (ShadowsocksApplication.isVpnEnabled) activity.handler.post(() => {
activity.connectionTestResult = result if (success) stat.setSummary(result) else {
activity.handler.post(activity.updateTraffic) stat.setSummary(R.string.connection_test_fail)
Snackbar.make(activity.findViewById(android.R.id.content), result, Snackbar.LENGTH_LONG).show
}
})
}) })
} }
} }
} }
true true
}) })
stat.setSummary(if (ShadowsocksApplication.isVpnEnabled) getString(R.string.connection_test_pending) else null)
isProxyApps = findPreference(Key.isProxyApps).asInstanceOf[SwitchPreference] isProxyApps = findPreference(Key.isProxyApps).asInstanceOf[SwitchPreference]
isProxyApps.setOnPreferenceClickListener((preference: Preference) => { isProxyApps.setOnPreferenceClickListener((preference: Preference) => {
...@@ -182,10 +184,12 @@ class ShadowsocksSettings extends PreferenceFragment with OnSharedPreferenceChan ...@@ -182,10 +184,12 @@ class ShadowsocksSettings extends PreferenceFragment with OnSharedPreferenceChan
} }
def onSharedPreferenceChanged(sharedPreferences: SharedPreferences, key: String) = key match { def onSharedPreferenceChanged(sharedPreferences: SharedPreferences, key: String) = key match {
case Key.isNAT => activity.handler.post(() => { case Key.isNAT =>
activity.handler.post(() => {
activity.deattachService activity.deattachService
activity.attachService activity.attachService
}) })
stat.setSummary(if (ShadowsocksApplication.isVpnEnabled) getString(R.string.connection_test_pending) else null)
case _ => case _ =>
} }
......
...@@ -2,8 +2,8 @@ package com.github.shadowsocks.preferences ...@@ -2,8 +2,8 @@ package com.github.shadowsocks.preferences
import android.content.Context import android.content.Context
import android.preference.Preference import android.preference.Preference
import android.view.{View, ViewGroup, LayoutInflater}
import android.util.AttributeSet import android.util.AttributeSet
import android.view.{LayoutInflater, View, ViewGroup}
import android.widget.TextView import android.widget.TextView
import com.github.shadowsocks.R import com.github.shadowsocks.R
...@@ -12,14 +12,18 @@ import com.github.shadowsocks.R ...@@ -12,14 +12,18 @@ import com.github.shadowsocks.R
*/ */
final class StatusPreference(context: Context, attrs: AttributeSet = null) final class StatusPreference(context: Context, attrs: AttributeSet = null)
extends Preference(context, attrs) { extends Preference(context, attrs) {
var txView: TextView = null var tx: String = _
var rxView: TextView = null var rx: String = _
var txRateView: TextView = null var txRate: String = _
var rxRateView: TextView = null var rxRate: String = _
var txView: TextView = _
var rxView: TextView = _
var txRateView: TextView = _
var rxRateView: TextView = _
override def onCreateView(parent: ViewGroup): View = { override def onCreateView(parent: ViewGroup): View = {
val li = getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE).asInstanceOf[LayoutInflater] val view = getContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE).asInstanceOf[LayoutInflater]
val view = li.inflate(R.layout.status_pref, parent, false) .inflate(R.layout.status_pref, parent, false)
txView = view.findViewById(R.id.tx).asInstanceOf[TextView] txView = view.findViewById(R.id.tx).asInstanceOf[TextView]
rxView = view.findViewById(R.id.rx).asInstanceOf[TextView] rxView = view.findViewById(R.id.rx).asInstanceOf[TextView]
...@@ -29,16 +33,28 @@ final class StatusPreference(context: Context, attrs: AttributeSet = null) ...@@ -29,16 +33,28 @@ final class StatusPreference(context: Context, attrs: AttributeSet = null)
view view
} }
override def onBindView(view: View) = {
super.onBindView(view)
txView.setText(tx)
rxView.setText(rx)
txRateView.setText(txRate)
rxRateView.setText(rxRate)
}
def setRate(tx: String, rx: String, txRate: String, rxRate: String) { def setRate(tx: String, rx: String, txRate: String, rxRate: String) {
this.tx = tx
if (txView != null) { if (txView != null) {
txView.setText(tx) txView.setText(tx)
} }
this.rx = rx
if (rxView != null) { if (rxView != null) {
rxView.setText(rx) rxView.setText(rx)
} }
this.txRate = txRate
if (txRateView != null) { if (txRateView != null) {
txRateView.setText(txRate) txRateView.setText(txRate)
} }
this.rxRate = rxRate
if (rxRateView != null) { if (rxRateView != null) {
rxRateView.setText(rxRate) rxRateView.setText(rxRate)
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment