diff --git a/build.sbt b/build.sbt index a7bbe448..2194c008 100644 --- a/build.sbt +++ b/build.sbt @@ -36,7 +36,7 @@ libraryDependencies ++= Seq( "com.google.android.gms" % "play-services-ads" % "8.1.0", "com.google.android.gms" % "play-services-analytics" % "8.1.0", "com.android.support" % "support-v4" % "23.1.0", - "com.github.mrengineer13" % "snackbar" % "1.2.0", + "com.android.support" % "design" % "23.1.0", "com.nostra13.universalimageloader" % "universal-image-loader" % "1.9.4", "com.j256.ormlite" % "ormlite-core" % "4.48", "com.j256.ormlite" % "ormlite-android" % "4.48" @@ -44,6 +44,7 @@ libraryDependencies ++= Seq( proguardOptions in Android ++= Seq("-keep class android.support.v4.app.** { *; }", "-keep interface android.support.v4.app.** { *; }", + "-keep class android.support.v7.widget.Toolbar { (...); }", "-keep class com.actionbarsherlock.** { *; }", "-keep interface com.actionbarsherlock.** { *; }", "-keep class org.jraf.android.backport.** { *; }", diff --git a/src/main/AndroidManifest.xml b/src/main/AndroidManifest.xml index d90311cc..787cd862 100644 --- a/src/main/AndroidManifest.xml +++ b/src/main/AndroidManifest.xml @@ -64,7 +64,7 @@ diff --git a/src/main/res/drawable-anydpi-v21/ic_cloud.xml b/src/main/res/drawable-anydpi-v21/ic_cloud.xml new file mode 100644 index 00000000..c5d6a7d4 --- /dev/null +++ b/src/main/res/drawable-anydpi-v21/ic_cloud.xml @@ -0,0 +1,9 @@ + + + diff --git a/src/main/res/drawable-anydpi-v21/ic_cloud_off.xml b/src/main/res/drawable-anydpi-v21/ic_cloud_off.xml new file mode 100644 index 00000000..575f4ef9 --- /dev/null +++ b/src/main/res/drawable-anydpi-v21/ic_cloud_off.xml @@ -0,0 +1,9 @@ + + + diff --git a/src/main/res/drawable-anydpi-v21/ic_cloud_queue.xml b/src/main/res/drawable-anydpi-v21/ic_cloud_queue.xml new file mode 100644 index 00000000..f30db90d --- /dev/null +++ b/src/main/res/drawable-anydpi-v21/ic_cloud_queue.xml @@ -0,0 +1,9 @@ + + + diff --git a/src/main/res/drawable-hdpi/ic_cloud.png b/src/main/res/drawable-hdpi/ic_cloud.png new file mode 100644 index 00000000..77ba43c2 Binary files /dev/null and b/src/main/res/drawable-hdpi/ic_cloud.png differ diff --git a/src/main/res/drawable-hdpi/ic_cloud_off.png b/src/main/res/drawable-hdpi/ic_cloud_off.png new file mode 100644 index 00000000..e30de1c2 Binary files /dev/null and b/src/main/res/drawable-hdpi/ic_cloud_off.png differ diff --git a/src/main/res/drawable-hdpi/ic_cloud_queue.png b/src/main/res/drawable-hdpi/ic_cloud_queue.png new file mode 100644 index 00000000..aae45eba Binary files /dev/null and b/src/main/res/drawable-hdpi/ic_cloud_queue.png differ diff --git a/src/main/res/drawable-hdpi/md__list_focused_holo.9.png b/src/main/res/drawable-hdpi/md__list_focused_holo.9.png deleted file mode 100644 index 55527084..00000000 Binary files a/src/main/res/drawable-hdpi/md__list_focused_holo.9.png and /dev/null differ diff --git a/src/main/res/drawable-hdpi/md__list_longpressed_holo.9.png b/src/main/res/drawable-hdpi/md__list_longpressed_holo.9.png deleted file mode 100644 index 4ea7afa0..00000000 Binary files a/src/main/res/drawable-hdpi/md__list_longpressed_holo.9.png and /dev/null differ diff --git a/src/main/res/drawable-hdpi/md__list_pressed_holo_dark.9.png b/src/main/res/drawable-hdpi/md__list_pressed_holo_dark.9.png deleted file mode 100644 index 5654cd69..00000000 Binary files a/src/main/res/drawable-hdpi/md__list_pressed_holo_dark.9.png and /dev/null differ diff --git a/src/main/res/drawable-hdpi/md__list_selector_disabled_holo_dark.9.png b/src/main/res/drawable-hdpi/md__list_selector_disabled_holo_dark.9.png deleted file mode 100644 index f6fd30dc..00000000 Binary files a/src/main/res/drawable-hdpi/md__list_selector_disabled_holo_dark.9.png and /dev/null differ diff --git a/src/main/res/drawable-mdpi/ic_cloud.png b/src/main/res/drawable-mdpi/ic_cloud.png new file mode 100644 index 00000000..a503ce8f Binary files /dev/null and b/src/main/res/drawable-mdpi/ic_cloud.png differ diff --git a/src/main/res/drawable-mdpi/ic_cloud_off.png b/src/main/res/drawable-mdpi/ic_cloud_off.png new file mode 100644 index 00000000..92faccb1 Binary files /dev/null and b/src/main/res/drawable-mdpi/ic_cloud_off.png differ diff --git a/src/main/res/drawable-mdpi/ic_cloud_queue.png b/src/main/res/drawable-mdpi/ic_cloud_queue.png new file mode 100644 index 00000000..94e4392a Binary files /dev/null and b/src/main/res/drawable-mdpi/ic_cloud_queue.png differ diff --git a/src/main/res/drawable-mdpi/md__list_focused_holo.9.png b/src/main/res/drawable-mdpi/md__list_focused_holo.9.png deleted file mode 100644 index 00f05d8c..00000000 Binary files a/src/main/res/drawable-mdpi/md__list_focused_holo.9.png and /dev/null differ diff --git a/src/main/res/drawable-mdpi/md__list_longpressed_holo.9.png b/src/main/res/drawable-mdpi/md__list_longpressed_holo.9.png deleted file mode 100644 index 3bf8e036..00000000 Binary files a/src/main/res/drawable-mdpi/md__list_longpressed_holo.9.png and /dev/null differ diff --git a/src/main/res/drawable-mdpi/md__list_pressed_holo_dark.9.png b/src/main/res/drawable-mdpi/md__list_pressed_holo_dark.9.png deleted file mode 100644 index 6e77525d..00000000 Binary files a/src/main/res/drawable-mdpi/md__list_pressed_holo_dark.9.png and /dev/null differ diff --git a/src/main/res/drawable-mdpi/md__list_selector_disabled_holo_dark.9.png b/src/main/res/drawable-mdpi/md__list_selector_disabled_holo_dark.9.png deleted file mode 100644 index 92da2f0d..00000000 Binary files a/src/main/res/drawable-mdpi/md__list_selector_disabled_holo_dark.9.png and /dev/null differ diff --git a/src/main/res/drawable-xhdpi/ic_cloud.png b/src/main/res/drawable-xhdpi/ic_cloud.png new file mode 100644 index 00000000..e44caf8d Binary files /dev/null and b/src/main/res/drawable-xhdpi/ic_cloud.png differ diff --git a/src/main/res/drawable-xhdpi/ic_cloud_off.png b/src/main/res/drawable-xhdpi/ic_cloud_off.png new file mode 100644 index 00000000..7e818e3d Binary files /dev/null and b/src/main/res/drawable-xhdpi/ic_cloud_off.png differ diff --git a/src/main/res/drawable-xhdpi/ic_cloud_queue.png b/src/main/res/drawable-xhdpi/ic_cloud_queue.png new file mode 100644 index 00000000..6ef11bb1 Binary files /dev/null and b/src/main/res/drawable-xhdpi/ic_cloud_queue.png differ diff --git a/src/main/res/drawable-xhdpi/md__list_focused_holo.9.png b/src/main/res/drawable-xhdpi/md__list_focused_holo.9.png deleted file mode 100644 index b545f8e5..00000000 Binary files a/src/main/res/drawable-xhdpi/md__list_focused_holo.9.png and /dev/null differ diff --git a/src/main/res/drawable-xhdpi/md__list_longpressed_holo.9.png b/src/main/res/drawable-xhdpi/md__list_longpressed_holo.9.png deleted file mode 100644 index eda10e61..00000000 Binary files a/src/main/res/drawable-xhdpi/md__list_longpressed_holo.9.png and /dev/null differ diff --git a/src/main/res/drawable-xhdpi/md__list_pressed_holo_dark.9.png b/src/main/res/drawable-xhdpi/md__list_pressed_holo_dark.9.png deleted file mode 100644 index e4b33935..00000000 Binary files a/src/main/res/drawable-xhdpi/md__list_pressed_holo_dark.9.png and /dev/null differ diff --git a/src/main/res/drawable-xhdpi/md__list_selector_disabled_holo_dark.9.png b/src/main/res/drawable-xhdpi/md__list_selector_disabled_holo_dark.9.png deleted file mode 100644 index 88726b69..00000000 Binary files a/src/main/res/drawable-xhdpi/md__list_selector_disabled_holo_dark.9.png and /dev/null differ diff --git a/src/main/res/drawable-xxhdpi/ic_cloud.png b/src/main/res/drawable-xxhdpi/ic_cloud.png new file mode 100644 index 00000000..390fcd5a Binary files /dev/null and b/src/main/res/drawable-xxhdpi/ic_cloud.png differ diff --git a/src/main/res/drawable-xxhdpi/ic_cloud_off.png b/src/main/res/drawable-xxhdpi/ic_cloud_off.png new file mode 100644 index 00000000..071088b6 Binary files /dev/null and b/src/main/res/drawable-xxhdpi/ic_cloud_off.png differ diff --git a/src/main/res/drawable-xxhdpi/ic_cloud_queue.png b/src/main/res/drawable-xxhdpi/ic_cloud_queue.png new file mode 100644 index 00000000..8ba4aecb Binary files /dev/null and b/src/main/res/drawable-xxhdpi/ic_cloud_queue.png differ diff --git a/src/main/res/drawable-xxxhdpi/ic_cloud.png b/src/main/res/drawable-xxxhdpi/ic_cloud.png new file mode 100644 index 00000000..d9534a99 Binary files /dev/null and b/src/main/res/drawable-xxxhdpi/ic_cloud.png differ diff --git a/src/main/res/drawable-xxxhdpi/ic_cloud_off.png b/src/main/res/drawable-xxxhdpi/ic_cloud_off.png new file mode 100644 index 00000000..2d78efc8 Binary files /dev/null and b/src/main/res/drawable-xxxhdpi/ic_cloud_off.png differ diff --git a/src/main/res/drawable-xxxhdpi/ic_cloud_queue.png b/src/main/res/drawable-xxxhdpi/ic_cloud_queue.png new file mode 100644 index 00000000..6f0210dc Binary files /dev/null and b/src/main/res/drawable-xxxhdpi/ic_cloud_queue.png differ diff --git a/src/main/res/drawable/md__list_selector_background_transition_holo_dark.xml b/src/main/res/drawable/md__list_selector_background_transition_holo_dark.xml deleted file mode 100644 index 1d43396d..00000000 --- a/src/main/res/drawable/md__list_selector_background_transition_holo_dark.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - - - - - diff --git a/src/main/res/drawable/md__list_selector_holo_dark.xml b/src/main/res/drawable/md__list_selector_holo_dark.xml deleted file mode 100644 index bd71aa8b..00000000 --- a/src/main/res/drawable/md__list_selector_holo_dark.xml +++ /dev/null @@ -1,27 +0,0 @@ - - - - - - - - - - - - - - diff --git a/src/main/res/layout/layout_apps.xml b/src/main/res/layout/layout_apps.xml index 99256204..0f02c21a 100644 --- a/src/main/res/layout/layout_apps.xml +++ b/src/main/res/layout/layout_apps.xml @@ -5,6 +5,7 @@ android:layout_height="fill_parent" android:orientation="vertical" android:duplicateParentState="false"> + + + + + + diff --git a/src/main/res/layout/layout_switch.xml b/src/main/res/layout/layout_switch.xml deleted file mode 100644 index 11bdecc9..00000000 --- a/src/main/res/layout/layout_switch.xml +++ /dev/null @@ -1,28 +0,0 @@ - - - - - - - - - diff --git a/src/main/res/layout/toolbar_light_dark.xml b/src/main/res/layout/toolbar_light_dark.xml new file mode 100644 index 00000000..ba9b1ec2 --- /dev/null +++ b/src/main/res/layout/toolbar_light_dark.xml @@ -0,0 +1,7 @@ + + \ No newline at end of file diff --git a/src/main/res/values-v21/styles_shadow.xml b/src/main/res/values-v21/styles_shadow.xml deleted file mode 100644 index 705b7e23..00000000 --- a/src/main/res/values-v21/styles_shadow.xml +++ /dev/null @@ -1,96 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/main/res/values/colors.xml b/src/main/res/values/colors.xml index 89f7d8d6..2ce8dac8 100644 --- a/src/main/res/values/colors.xml +++ b/src/main/res/values/colors.xml @@ -12,4 +12,12 @@ #00000000 #FF555555 + #2196F3 + #90A4AE + #607D8B + #455A64 + @color/material_blue_grey_300 + @color/material_blue_grey_500 + @color/material_blue_grey_700 + diff --git a/src/main/res/values/styles.xml b/src/main/res/values/styles.xml index a732e9de..cd6c42af 100644 --- a/src/main/res/values/styles.xml +++ b/src/main/res/values/styles.xml @@ -16,11 +16,27 @@ - + + - - @@ -57,7 +72,7 @@ - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/main/scala/com/github/shadowsocks/AppManager.scala b/src/main/scala/com/github/shadowsocks/AppManager.scala index 35ced549..d6c16be8 100644 --- a/src/main/scala/com/github/shadowsocks/AppManager.scala +++ b/src/main/scala/com/github/shadowsocks/AppManager.scala @@ -49,6 +49,7 @@ import android.graphics.{Bitmap, PixelFormat} import android.os.Bundle import android.os.Handler import android.preference.PreferenceManager +import android.support.v7.widget.Toolbar import android.view.Menu import android.view.MenuItem import android.view.View @@ -260,9 +261,6 @@ class AppManager extends Activity with OnCheckedChangeListener with OnClickListe } Toast.makeText(this, R.string.action_import_err, Toast.LENGTH_SHORT).show() return false - case android.R.id.home => - navigateUpTo(getParentActivityIntent) - return true } super.onOptionsItemSelected(item) } @@ -277,11 +275,14 @@ class AppManager extends Activity with OnCheckedChangeListener with OnClickListe handler = new Handler() - val actionBar = getActionBar - actionBar.setTitle(R.string.proxied_help) - actionBar.setDisplayHomeAsUpEnabled(true) - actionBar.setDisplayShowHomeEnabled(false) this.setContentView(R.layout.layout_apps) + val toolbar = findViewById(R.id.toolbar).asInstanceOf[Toolbar] + toolbar.setTitle(R.string.proxied_help) + toolbar.setNavigationIcon(R.drawable.abc_ic_ab_back_mtrl_am_alpha) + toolbar.setNavigationOnClickListener((v: View) => { + val intent = getParentActivityIntent + if (intent == null) finish else navigateUpTo(intent) + }) this.overlay = View.inflate(this, R.layout.overlay, null).asInstanceOf[TextView] getWindowManager.addView(overlay, new WindowManager.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, diff --git a/src/main/scala/com/github/shadowsocks/Shadowsocks.scala b/src/main/scala/com/github/shadowsocks/Shadowsocks.scala index b005e3ce..a10b19d6 100644 --- a/src/main/scala/com/github/shadowsocks/Shadowsocks.scala +++ b/src/main/scala/com/github/shadowsocks/Shadowsocks.scala @@ -51,12 +51,13 @@ import android.graphics.{Bitmap, Color, Typeface} import android.net.{Uri, VpnService} import android.os._ import android.preference._ -import android.support.v4.content.ContextCompat +import android.support.design.widget.{FloatingActionButton, Snackbar} +import android.support.v7.app.AppCompatActivity +import android.support.v7.widget.Toolbar import android.util.{DisplayMetrics, Log} import android.view._ import android.webkit.{WebView, WebViewClient} import android.widget._ -import com.github.mrengineer13.snackbar._ import com.github.shadowsocks.aidl.{IShadowsocksService, IShadowsocksServiceCallback} import com.github.shadowsocks.database._ import com.github.shadowsocks.preferences.{PasswordEditTextPreference, ProfileEditTextPreference, SummaryEditTextPreference} @@ -173,8 +174,7 @@ object Shadowsocks { } class Shadowsocks - extends PreferenceActivity - with CompoundButton.OnCheckedChangeListener + extends AppCompatActivity with MenuAdapter.MenuListener { // Flags @@ -184,8 +184,9 @@ class Shadowsocks var singlePane: Int = -1 // Variables - var switchButton: Switch = null - var progressDialog: ProgressDialog = null + private var serviceStarted = false + var fab: FloatingActionButton = _ + var progressDialog: ProgressDialog = _ var progressTag = -1 var state = State.INIT var prepared = false @@ -210,7 +211,7 @@ class Shadowsocks case ignored: RemoteException => // Nothing } // Update the UI - if (switchButton != null) switchButton.setEnabled(true) + if (fab != null) fab.setEnabled(true) if (State.isAvailable(bgService.getState)) { setPreferenceEnabled(enabled = true) } else { @@ -218,8 +219,6 @@ class Shadowsocks setPreferenceEnabled(enabled = false) } state = bgService.getState - // set the listener - switchButton.setOnCheckedChangeListener(Shadowsocks.this) if (!status.getBoolean(getVersionName, false)) { status.edit.putBoolean(getVersionName, true).commit() @@ -228,7 +227,7 @@ class Shadowsocks } override def onServiceDisconnected(name: ComponentName) { - if (switchButton != null) switchButton.setEnabled(false) + if (fab != null) fab.setEnabled(false) try { if (bgService != null) bgService.unregisterCallback(callback) } catch { @@ -238,8 +237,10 @@ class Shadowsocks } } - private lazy val settings = PreferenceManager.getDefaultSharedPreferences(this) - private lazy val status = getSharedPreferences(Key.status, Context.MODE_PRIVATE) + private lazy val preferences = + getFragmentManager.findFragmentById(android.R.id.content).asInstanceOf[ShadowsocksSettings] + lazy val settings = PreferenceManager.getDefaultSharedPreferences(this) + lazy val status = getSharedPreferences(Key.status, Context.MODE_PRIVATE) private lazy val preferenceReceiver = new PreferenceBroadcastReceiver private lazy val drawer = MenuDrawer.attach(this) private lazy val menuAdapter = new MenuAdapter(this, getMenuList) @@ -265,13 +266,12 @@ class Shadowsocks } private def changeSwitch(checked: Boolean) { - switchButton.setOnCheckedChangeListener(null) - switchButton.setChecked(checked) - if (switchButton.isEnabled) { - switchButton.setEnabled(false) - handler.postDelayed(() => switchButton.setEnabled(true), 1000) + serviceStarted = checked + fab.setImageResource(if (checked) R.drawable.ic_cloud else R.drawable.ic_cloud_off) + if (fab.isEnabled) { + fab.setEnabled(false) + handler.postDelayed(() => fab.setEnabled(true), 1000) } - switchButton.setOnCheckedChangeListener(this) } private def showProgress(msg: Int): Handler = { @@ -374,16 +374,9 @@ class Shadowsocks } def isTextEmpty(s: String, msg: String): Boolean = { - if (s == null || s.length <= 0) { - new SnackBar.Builder(this) - .withMessage(msg) - .withActionMessageId(R.string.error) - .withStyle(SnackBar.Style.ALERT) - .withDuration(SnackBar.LONG_SNACK) - .show() - return true - } - false + if (s != null && s.length > 0) return false + Snackbar.make(getWindow.getDecorView.findViewById(android.R.id.content), msg, Snackbar.LENGTH_LONG).show + true } def cancelStart() { @@ -416,24 +409,6 @@ class Shadowsocks } } - def onCheckedChanged(compoundButton: CompoundButton, checked: Boolean) { - if (compoundButton eq switchButton) { - checked match { - case true => - if (isReady) - prepareStartService() - else - changeSwitch(checked = false) - case false => - serviceStop() - } - if (switchButton.isEnabled) { - switchButton.setEnabled(false) - handler.postDelayed(() => switchButton.setEnabled(true), 1000) - } - } - } - def getLayoutView(view: ViewParent): LinearLayout = { view match { case layout: LinearLayout => layout @@ -470,7 +445,7 @@ class Shadowsocks super.onCreate(savedInstanceState) - addPreferencesFromResource(R.xml.pref_all) + setContentView(R.layout.layout_main) // Update the profile if (!status.getBoolean(getVersionName, false)) { @@ -502,24 +477,32 @@ class Shadowsocks } // Initialize action bar - val switchLayout = getLayoutInflater - .inflate(R.layout.layout_switch, null) - .asInstanceOf[RelativeLayout] - val title: TextView = switchLayout.findViewById(R.id.title).asInstanceOf[TextView] + val toolbar = findViewById(R.id.toolbar).asInstanceOf[Toolbar] + toolbar.setTitle(getTitle) + val field = classOf[Toolbar].getDeclaredField("mTitleTextView") + field.setAccessible(true) + val title: TextView = field.get(toolbar).asInstanceOf[TextView] val tf: Typeface = Typefaces.get(this, "fonts/Iceland.ttf") if (tf != null) title.setTypeface(tf) - switchButton = switchLayout.findViewById(R.id.switchButton).asInstanceOf[Switch] - getActionBar.setCustomView(switchLayout) - getActionBar.setDisplayShowTitleEnabled(false) - getActionBar.setDisplayShowCustomEnabled(true) - if (Utils.isLollipopOrAbove) { - getWindow.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) - getWindow.setStatusBarColor(ContextCompat.getColor(this, R.color.grey3)) - getActionBar.setDisplayHomeAsUpEnabled(true) - getActionBar.setHomeAsUpIndicator(R.drawable.ic_drawer) - } else { - getActionBar.setIcon(R.drawable.ic_stat_shadowsocks) - } + fab = findViewById(R.id.fab).asInstanceOf[FloatingActionButton] + fab.setOnClickListener((v: View) => { + serviceStarted = !serviceStarted + serviceStarted match { + case true => + if (isReady) + prepareStartService() + else + changeSwitch(checked = false) + case false => + serviceStop() + } + if (fab.isEnabled) { + fab.setEnabled(false) + handler.postDelayed(() => fab.setEnabled(true), 1000) + } + }) + toolbar.setNavigationIcon(R.drawable.ic_drawer) + toolbar.setNavigationOnClickListener((v: View) => drawer.toggleMenu()) title.setOnLongClickListener((v: View) => { if (Utils.isLollipopOrAbove && bgService != null && (bgService.getState == State.INIT || bgService.getState == State.STOPPED)) { @@ -785,18 +768,8 @@ class Shadowsocks buf.toList } - override def onOptionsItemSelected(item: MenuItem): Boolean = { - item.getItemId match { - case android.R.id.home => - drawer.toggleMenu() - return true - } - super.onOptionsItemSelected(item) - } - protected override def onPause() { super.onPause() - switchButton.setOnCheckedChangeListener(null) prepared = false } @@ -812,8 +785,6 @@ class Shadowsocks changeSwitch(checked = false) } state = bgService.getState - // set the listener - switchButton.setOnCheckedChangeListener(Shadowsocks.this) } ConfigUtils.refresh(this) @@ -825,13 +796,13 @@ class Shadowsocks private def setPreferenceEnabled(enabled: Boolean) { for (name <- Shadowsocks.PROXY_PREFS) { - val pref = findPreference(name) + val pref = preferences.findPreference(name) if (pref != null) { pref.setEnabled(enabled) } } for (name <- Shadowsocks.FEATRUE_PREFS) { - val pref = findPreference(name) + val pref = preferences.findPreference(name) if (pref != null) { if (Seq(Key.isGlobalProxy, Key.proxyedApps) .contains(name)) { @@ -846,11 +817,11 @@ class Shadowsocks private def updatePreferenceScreen() { val profile = currentProfile for (name <- Shadowsocks.PROXY_PREFS) { - val pref = findPreference(name) + val pref = preferences.findPreference(name) Shadowsocks.updatePreference(pref, name, profile) } for (name <- Shadowsocks.FEATRUE_PREFS) { - val pref = findPreference(name) + val pref = preferences.findPreference(name) Shadowsocks.updatePreference(pref, name, profile) } } @@ -983,22 +954,14 @@ class Shadowsocks try { val port: Int = Integer.valueOf(text) if (!low && port <= 1024) { - new SnackBar.Builder(this) - .withMessageId(R.string.port_alert) - .withActionMessageId(R.string.error) - .withStyle(SnackBar.Style.ALERT) - .withDuration(SnackBar.LONG_SNACK) - .show() + Snackbar.make(getWindow.getDecorView.findViewById(android.R.id.content), R.string.port_alert, + Snackbar.LENGTH_LONG).show return false } } catch { case ex: Exception => - new SnackBar.Builder(this) - .withMessageId(R.string.port_alert) - .withActionMessageId(R.string.error) - .withStyle(SnackBar.Style.ALERT) - .withDuration(SnackBar.LONG_SNACK) - .show() + Snackbar.make(getWindow.getDecorView.findViewById(android.R.id.content), R.string.port_alert, + Snackbar.LENGTH_LONG).show return false } true @@ -1072,14 +1035,8 @@ class Shadowsocks clearDialog() } changeSwitch(checked = false) - if (m != null) { - new SnackBar.Builder(Shadowsocks.this) - .withMessage(getString(R.string.vpn_error).formatLocal(Locale.ENGLISH, m)) - .withActionMessageId(R.string.error) - .withStyle(SnackBar.Style.ALERT) - .withDuration(SnackBar.LONG_SNACK) - .show() - } + if (m != null) Snackbar.make(getWindow.getDecorView.findViewById(android.R.id.content), + getString(R.string.vpn_error).formatLocal(Locale.ENGLISH, m), Snackbar.LENGTH_LONG).show setPreferenceEnabled(enabled = true) case State.STOPPING => if (progressDialog == null) { diff --git a/src/main/scala/com/github/shadowsocks/ShadowsocksSettings.scala b/src/main/scala/com/github/shadowsocks/ShadowsocksSettings.scala new file mode 100644 index 00000000..30ce662e --- /dev/null +++ b/src/main/scala/com/github/shadowsocks/ShadowsocksSettings.scala @@ -0,0 +1,12 @@ +package com.github.shadowsocks + +import android.os.Bundle +import android.preference.PreferenceFragment + +// TODO: Move related logic here +class ShadowsocksSettings extends PreferenceFragment { + override def onCreate(savedInstanceState: Bundle) { + super.onCreate(savedInstanceState) + addPreferencesFromResource(R.xml.pref_all) + } +}