Commit 1b6edbbf authored by Max Lv's avatar Max Lv

refine UI

parent e9743861
......@@ -59,8 +59,6 @@
<receiver android:name="com.github.shadowsocks.ShadowsocksReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
<action android:name="android.intent.action.ACTION_SHUTDOWN"/>
<action android:name="com.github.shadowsocks.ACTION_SHUTDOWN"/>
</intent-filter>
</receiver>
......
......@@ -19,12 +19,13 @@
android:summary="@string/port_summary"
android:title="@string/port">
</com.github.shadowsocks.preferences.SummaryEditTextPreference>
<com.github.shadowsocks.preferences.SummaryEditTextPreference
<com.github.shadowsocks.preferences.PasswordEditTextPreference
android:inputType="textPassword"
android:defaultValue="u1rRWTssNv0p"
android:key="sitekey"
android:summary="@string/sitekey_summary"
android:title="@string/sitekey">
</com.github.shadowsocks.preferences.SummaryEditTextPreference>
</com.github.shadowsocks.preferences.PasswordEditTextPreference>
<ListPreference
android:defaultValue="rc4"
android:key="encMethod"
......
......@@ -50,13 +50,6 @@ class ShadowsocksReceiver extends BroadcastReceiver {
val TAG = "Shadowsocks"
def onReceive(context: Context, intent: Intent) {
if (intent != null) {
val action = intent.getAction
if ((action == Intent.ACTION_SHUTDOWN) || (action == Utils.CLOSE_ACTION)) {
context.stopService(new Intent(context, classOf[ShadowsocksService]))
return
}
}
val settings: SharedPreferences = PreferenceManager.getDefaultSharedPreferences(context)
var versionName: String = null
try {
......
......@@ -41,9 +41,7 @@ import android.app.Notification
import android.app.NotificationManager
import android.app.PendingIntent
import android.app.Service
import android.content.Context
import android.content.Intent
import android.content.SharedPreferences
import android.content._
import android.content.pm.PackageInfo
import android.content.pm.PackageManager
import android.os.Handler
......@@ -65,6 +63,7 @@ import org.apache.http.conn.util.InetAddressUtils
import scala.collection._
import org.xbill.DNS._
import scala.Some
import scala.Some
object ShadowsocksService {
def isServiceStarted: Boolean = {
......@@ -83,25 +82,6 @@ object ShadowsocksService {
class ShadowsocksService extends Service {
val TAG = "ShadowsocksService"
val BASE = "/data/data/com.github.shadowsocks/"
val REDSOCKS_CONF = "base {" + " log_debug = off;" + " log_info = off;" + " log = stderr;" + " daemon = on;" + " redirector = iptables;" + "}" + "redsocks {" + " local_ip = 127.0.0.1;" + " local_port = 8123;" + " ip = 127.0.0.1;" + " port = %d;" + " type = socks5;" + "}"
val SHADOWSOCKS_CONF = "{\"server\": [%s], \"server_port\": %d, \"local_port\": %d, \"password\": %s, \"timeout\": %d}"
val CMD_IPTABLES_RETURN = " -t nat -A OUTPUT -p tcp -d 0.0.0.0 -j RETURN\n"
val CMD_IPTABLES_REDIRECT_ADD_SOCKS = " -t nat -A OUTPUT -p tcp " + "-j REDIRECT --to 8123\n"
val CMD_IPTABLES_DNAT_ADD_SOCKS = " -t nat -A OUTPUT -p tcp " + "-j DNAT --to-destination 127.0.0.1:8123\n"
val MSG_CONNECT_START: Int = 0
val MSG_CONNECT_FINISH: Int = 1
val MSG_CONNECT_SUCCESS: Int = 2
val MSG_CONNECT_FAIL: Int = 3
val MSG_HOST_CHANGE: Int = 4
val MSG_STOP_SELF: Int = 5
val DNS_PORT: Int = 8153
val mStartForegroundSignature = Array[Class[_]](classOf[Int], classOf[Notification])
val mStopForegroundSignature = Array[Class[_]](classOf[Boolean])
val mSetForegroundSignature = Array[Class[_]](classOf[Boolean])
def getPid(name: String): Int = {
try {
val reader: BufferedReader = new BufferedReader(new FileReader(BASE + name + ".pid"))
......@@ -378,6 +358,16 @@ class ShadowsocksService extends Service {
throw new IllegalStateException("OS doesn't have Service.startForeground OR Service.setForeground!")
}
}
// register close receiver
val filter = new IntentFilter()
filter.addAction(Intent.ACTION_SHUTDOWN)
filter.addAction(Utils.CLOSE_ACTION)
receiver = new BroadcastReceiver() {
def onReceive(p1: Context, p2: Intent) { stopSelf() }
}
registerReceiver(receiver, filter)
}
/** Called when the activity is closed. */
......@@ -389,11 +379,18 @@ class ShadowsocksService extends Service {
onDisconnect()
}
}.start()
val ed: SharedPreferences.Editor = settings.edit
ed.putBoolean("isRunning", false)
ed.putBoolean("isConnecting", false)
ed.commit
markServiceStopped()
if (receiver != null) {
unregisterReceiver(receiver)
receiver = null
}
super.onDestroy()
}
......@@ -542,6 +539,27 @@ class ShadowsocksService extends Service {
super.handleMessage(msg)
}
}
val TAG = "ShadowsocksService"
val BASE = "/data/data/com.github.shadowsocks/"
val REDSOCKS_CONF = "base {" + " log_debug = off;" + " log_info = off;" + " log = stderr;" + " daemon = on;" + " redirector = iptables;" + "}" + "redsocks {" + " local_ip = 127.0.0.1;" + " local_port = 8123;" + " ip = 127.0.0.1;" + " port = %d;" + " type = socks5;" + "}"
val SHADOWSOCKS_CONF = "{\"server\": [%s], \"server_port\": %d, \"local_port\": %d, \"password\": %s, \"timeout\": %d}"
val CMD_IPTABLES_RETURN = " -t nat -A OUTPUT -p tcp -d 0.0.0.0 -j RETURN\n"
val CMD_IPTABLES_REDIRECT_ADD_SOCKS = " -t nat -A OUTPUT -p tcp " + "-j REDIRECT --to 8123\n"
val CMD_IPTABLES_DNAT_ADD_SOCKS = " -t nat -A OUTPUT -p tcp " + "-j DNAT --to-destination 127.0.0.1:8123\n"
val MSG_CONNECT_START: Int = 0
val MSG_CONNECT_FINISH: Int = 1
val MSG_CONNECT_SUCCESS: Int = 2
val MSG_CONNECT_FAIL: Int = 3
val MSG_HOST_CHANGE: Int = 4
val MSG_STOP_SELF: Int = 5
val DNS_PORT: Int = 8153
val mStartForegroundSignature = Array[Class[_]](classOf[Int], classOf[Notification])
val mStopForegroundSignature = Array[Class[_]](classOf[Boolean])
val mSetForegroundSignature = Array[Class[_]](classOf[Boolean])
var receiver: BroadcastReceiver = null
var notificationManager: NotificationManager = null
var mWakeLock: PowerManager#WakeLock = null
var appHost: String = null
......
package com.github.shadowsocks.preferences
import android.content.Context
import android.preference.EditTextPreference
import android.util.AttributeSet
class PasswordEditTextPreference(context: Context, attrs: AttributeSet, defStyle: Int)
extends EditTextPreference(context, attrs, defStyle) {
def this(context: Context, attrs: AttributeSet) = {
this (context, attrs, android.R.attr.editTextPreferenceStyle)
mDefaultSummary = getSummary
}
override def setSummary(summary: CharSequence) {
if (summary.toString.isEmpty) {
super.setSummary(mDefaultSummary)
}
else {
super.setSummary(summary.toString.map(c => "*").mkString)
}
}
private var mDefaultSummary: CharSequence = getSummary
}
\ No newline at end of file
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