Add NumberPickerPreference

This commit is contained in:
Mygod
2015-11-09 17:29:10 +08:00
parent 8dd1093c6c
commit 5f0b1a50b2
10 changed files with 89 additions and 73 deletions
@@ -316,8 +316,6 @@ class Shadowsocks
def isReady: Boolean = {
if (!checkText(Key.proxy)) return false
if (!checkText(Key.sitekey)) return false
if (!checkNumber(Key.localPort, low = false)) return false
if (!checkNumber(Key.remotePort, low = true)) return false
if (bgService == null) return false
true
}
@@ -348,15 +346,6 @@ class Shadowsocks
super.onCreate(savedInstanceState)
setContentView(R.layout.layout_main)
if (ShadowsocksApplication.proxy == "198.199.101.152") {
val adView = new AdView(this)
adView.setAdUnitId("ca-app-pub-9097031975646651/7760346322")
adView.setAdSize(AdSize.SMART_BANNER)
preferences.getView.asInstanceOf[ViewGroup].addView(adView, 0)
adView.loadAd(new AdRequest.Builder().build())
}
// Update the profile
if (!ShadowsocksApplication.settings.getBoolean(ShadowsocksApplication.getVersionName, false)) {
currentProfile = ShadowsocksApplication.profileManager.create()
@@ -366,6 +355,16 @@ class Shadowsocks
currentProfile = {
ShadowsocksApplication.currentProfile getOrElse currentProfile
}
ShadowsocksApplication.profileManager.load(currentProfile.id)
setContentView(R.layout.layout_main)
if (ShadowsocksApplication.proxy == "198.199.101.152") {
val adView = new AdView(this)
adView.setAdUnitId("ca-app-pub-9097031975646651/7760346322")
adView.setAdSize(AdSize.SMART_BANNER)
preferences.getView.asInstanceOf[ViewGroup].addView(adView, 0)
adView.loadAd(new AdRequest.Builder().build())
}
// Initialize action bar
val toolbar = findViewById(R.id.toolbar).asInstanceOf[Toolbar]
@@ -603,25 +602,6 @@ class Shadowsocks
!isTextEmpty(text, getString(R.string.proxy_empty))
}
def checkNumber(key: String, low: Boolean): Boolean = {
val text = ShadowsocksApplication.settings.getString(key, "")
if (isTextEmpty(text, getString(R.string.port_empty))) return false
try {
val port: Int = Integer.valueOf(text)
if (!low && port <= 1024) {
Snackbar.make(getWindow.getDecorView.findViewById(android.R.id.content), R.string.port_alert,
Snackbar.LENGTH_LONG).show
return false
}
} catch {
case ex: Exception =>
Snackbar.make(getWindow.getDecorView.findViewById(android.R.id.content), R.string.port_alert,
Snackbar.LENGTH_LONG).show
return false
}
true
}
/** Called when connect button is clicked. */
def serviceStart() {
bgService.start(ConfigUtils.load(ShadowsocksApplication.settings))