diff --git a/src/main/res/layout/layout_profiles.xml b/src/main/res/layout/layout_profiles.xml index a98f4674bd..500b67f965 100644 --- a/src/main/res/layout/layout_profiles.xml +++ b/src/main/res/layout/layout_profiles.xml @@ -1,11 +1,16 @@ - + + + diff --git a/src/main/scala/com/github/shadowsocks/ProfileManagerActivity.scala b/src/main/scala/com/github/shadowsocks/ProfileManagerActivity.scala index 96ba5106b2..4bb55fd1eb 100644 --- a/src/main/scala/com/github/shadowsocks/ProfileManagerActivity.scala +++ b/src/main/scala/com/github/shadowsocks/ProfileManagerActivity.scala @@ -1,7 +1,7 @@ package com.github.shadowsocks import android.content.Intent -import android.os.Bundle +import android.os.{Handler, Bundle} import android.support.design.widget.Snackbar import android.support.v7.app.{AlertDialog, AppCompatActivity} import android.support.v7.widget.RecyclerView.ViewHolder @@ -69,7 +69,7 @@ class ProfileManagerActivity extends AppCompatActivity with OnMenuItemClickListe builder.setSpan(new TextAppearanceSpan(ProfileManagerActivity.this, android.R.style.TextAppearance_Small), start + 1, builder.length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE) } - text.setText(builder) + handler.post(() => text.setText(builder)) } def bind(item: Profile) { @@ -129,6 +129,7 @@ class ProfileManagerActivity extends AppCompatActivity with OnMenuItemClickListe } private var selectedItem: ProfileViewHolder = _ + private val handler = new Handler private lazy val profilesAdapter = new ProfilesAdapter private var removedSnackbar: Snackbar = _ @@ -152,7 +153,7 @@ class ProfileManagerActivity extends AppCompatActivity with OnMenuItemClickListe profilesList.setLayoutManager(new LinearLayoutManager(this)) profilesList.setItemAnimator(new DefaultItemAnimator) profilesList.setAdapter(profilesAdapter) - removedSnackbar = Snackbar.make(findViewById(android.R.id.content), R.string.removed, Snackbar.LENGTH_LONG) + removedSnackbar = Snackbar.make(profilesList, R.string.removed, Snackbar.LENGTH_LONG) .setAction(R.string.undo, ((v: View) => profilesAdapter.undoRemoves): OnClickListener) removedSnackbar.getView.addOnAttachStateChangeListener(new OnAttachStateChangeListener { def onViewDetachedFromWindow(v: View) = profilesAdapter.commitRemoves diff --git a/src/main/scala/com/github/shadowsocks/Shadowsocks.scala b/src/main/scala/com/github/shadowsocks/Shadowsocks.scala index 8be49d5516..6f27187d5c 100644 --- a/src/main/scala/com/github/shadowsocks/Shadowsocks.scala +++ b/src/main/scala/com/github/shadowsocks/Shadowsocks.scala @@ -293,12 +293,6 @@ class Shadowsocks } } - def isTextEmpty(s: String, msg: String): Boolean = { - 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() { clearDialog() changeSwitch(checked = false) @@ -554,7 +548,9 @@ class Shadowsocks def checkText(key: String): Boolean = { val text = ShadowsocksApplication.settings.getString(key, "") - !isTextEmpty(text, getString(R.string.proxy_empty)) + if (text != null && text.length > 0) return true + Snackbar.make(findViewById(android.R.id.content), getString(R.string.proxy_empty), Snackbar.LENGTH_LONG).show + false } /** Called when connect button is clicked. */ @@ -598,7 +594,7 @@ class Shadowsocks handler.postDelayed(() => fabProgressCircle.hide(), 1000) fab.setEnabled(true) changeSwitch(checked = false) - if (m != null) Snackbar.make(getWindow.getDecorView.findViewById(android.R.id.content), + if (m != null) Snackbar.make(findViewById(android.R.id.content), getString(R.string.vpn_error).formatLocal(Locale.ENGLISH, m), Snackbar.LENGTH_LONG).show setPreferenceEnabled(enabled = true) case State.STOPPING => diff --git a/src/main/scala/com/github/shadowsocks/ShadowsocksNatService.scala b/src/main/scala/com/github/shadowsocks/ShadowsocksNatService.scala index d00e2effc6..75f7cca093 100644 --- a/src/main/scala/com/github/shadowsocks/ShadowsocksNatService.scala +++ b/src/main/scala/com/github/shadowsocks/ShadowsocksNatService.scala @@ -40,9 +40,9 @@ package com.github.shadowsocks import java.io.File +import java.lang.Process import java.net.{Inet6Address, InetAddress} import java.util.Locale -import java.lang.{Process, ProcessBuilder} import android.app._ import android.content._ @@ -56,8 +56,8 @@ import android.widget.Toast import com.github.shadowsocks.aidl.Config import com.github.shadowsocks.utils._ -import scala.collection._ import scala.collection.JavaConversions._ +import scala.collection._ import scala.collection.mutable.ArrayBuffer import scala.concurrent.ExecutionContext.Implicits.global import scala.concurrent.Future diff --git a/src/main/scala/com/github/shadowsocks/ShadowsocksSettings.scala b/src/main/scala/com/github/shadowsocks/ShadowsocksSettings.scala index fba18268d1..f6e25db2bd 100644 --- a/src/main/scala/com/github/shadowsocks/ShadowsocksSettings.scala +++ b/src/main/scala/com/github/shadowsocks/ShadowsocksSettings.scala @@ -5,9 +5,9 @@ import java.util.Locale import android.content.{DialogInterface, Intent} import android.net.Uri import android.os.{Build, Bundle} -import android.preference.{SwitchPreference, Preference, PreferenceFragment} +import android.preference.{Preference, PreferenceFragment, SwitchPreference} import android.support.v7.app.AlertDialog -import android.webkit.{WebViewClient, WebView} +import android.webkit.{WebView, WebViewClient} import com.github.shadowsocks.utils.Key // TODO: Move related logic here diff --git a/src/main/scala/com/github/shadowsocks/ShadowsocksVpnService.scala b/src/main/scala/com/github/shadowsocks/ShadowsocksVpnService.scala index 53ecdfbc6a..7c07e8e2a0 100644 --- a/src/main/scala/com/github/shadowsocks/ShadowsocksVpnService.scala +++ b/src/main/scala/com/github/shadowsocks/ShadowsocksVpnService.scala @@ -40,8 +40,8 @@ package com.github.shadowsocks import java.io.File +import java.lang.Process import java.util.Locale -import java.lang.{Process, ProcessBuilder} import android.app._ import android.content._ diff --git a/src/main/scala/com/github/shadowsocks/widget/AutoPaddingBehavior.scala b/src/main/scala/com/github/shadowsocks/widget/AutoPaddingBehavior.scala new file mode 100644 index 0000000000..56211a78a2 --- /dev/null +++ b/src/main/scala/com/github/shadowsocks/widget/AutoPaddingBehavior.scala @@ -0,0 +1,30 @@ +package com.github.shadowsocks.widget + +import android.content.Context +import android.support.design.widget.CoordinatorLayout +import android.support.design.widget.CoordinatorLayout.Behavior +import android.support.design.widget.Snackbar.SnackbarLayout +import android.util.AttributeSet +import android.view.View + +/** + * @author Mygod + */ +class AutoPaddingBehavior(context: Context, attrs: AttributeSet) extends Behavior[View] { + override def layoutDependsOn(parent: CoordinatorLayout, child: View, dependency: View) = + dependency.isInstanceOf[SnackbarLayout] + + override def onDependentViewChanged(parent: CoordinatorLayout, child: View, dependency: View) = + dependency match { + case sl: SnackbarLayout => + child.setPadding(0, 0, 0, dependency.getHeight) + true + case _ => super.onDependentViewChanged(parent, child, dependency) + } + + override def onDependentViewRemoved(parent: CoordinatorLayout, child: View, dependency: View) = + dependency match { + case sl: SnackbarLayout => child.setPadding(0, 0, 0, 0) + case _ => super.onDependentViewRemoved(parent, child, dependency) + } +}