Commit e2a31847 authored by Mygod's avatar Mygod

Refine #614 #615

parent 88131c34
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<!--Generated by crowdin.net-->
<resources> <resources>
<string name="app_name">影梭</string> <string name="app_name">影梭</string>
<string name="global_cat">全局设置</string> <string name="global_cat">全局设置</string>
......
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<!--Generated by crowdin.net-->
<resources> <resources>
<string name="app_name">Shadowsocks</string> <string name="app_name">Shadowsocks</string>
<string name="screen_name" translatable="false">Shadowsocks</string>
<string name="global_cat">全域設定</string> <string name="global_cat">全域設定</string>
<string name="misc_cat">其他</string> <string name="misc_cat">其他</string>
<string name="proxy_cat">伺服器設定</string> <string name="proxy_cat">伺服器設定</string>
......
...@@ -5,9 +5,8 @@ import java.nio.charset.Charset ...@@ -5,9 +5,8 @@ import java.nio.charset.Charset
import android.content._ import android.content._
import android.nfc.NfcAdapter.CreateNdefMessageCallback import android.nfc.NfcAdapter.CreateNdefMessageCallback
import android.nfc.{NdefMessage, NdefRecord, NfcAdapter, NfcEvent} import android.nfc.{NdefMessage, NdefRecord, NfcAdapter, NfcEvent}
import android.os.{Build, Bundle, Handler} import android.os.{Bundle, Handler}
import android.provider.Settings import android.provider.Settings
import android.support.v4.app.{NavUtils, TaskStackBuilder}
import android.support.v7.app.{AlertDialog, AppCompatActivity} import android.support.v7.app.{AlertDialog, AppCompatActivity}
import android.support.v7.widget.RecyclerView.ViewHolder import android.support.v7.widget.RecyclerView.ViewHolder
import android.support.v7.widget.Toolbar.OnMenuItemClickListener import android.support.v7.widget.Toolbar.OnMenuItemClickListener
...@@ -38,7 +37,7 @@ class ProfileManagerActivity extends AppCompatActivity with OnMenuItemClickListe ...@@ -38,7 +37,7 @@ class ProfileManagerActivity extends AppCompatActivity with OnMenuItemClickListe
val shareBtn = itemView.findViewById(R.id.share) val shareBtn = itemView.findViewById(R.id.share)
shareBtn.setOnClickListener(_ => { shareBtn.setOnClickListener(_ => {
val url = item.toString val url = item.toString
if (nfcBeamEnable) { if (isNfcBeamEnabled) {
nfcAdapter.setNdefPushMessageCallback(ProfileManagerActivity.this,ProfileManagerActivity.this) nfcAdapter.setNdefPushMessageCallback(ProfileManagerActivity.this,ProfileManagerActivity.this)
nfcShareItem = url.getBytes(Charset.forName("UTF-8")) nfcShareItem = url.getBytes(Charset.forName("UTF-8"))
} }
...@@ -57,23 +56,15 @@ class ProfileManagerActivity extends AppCompatActivity with OnMenuItemClickListe ...@@ -57,23 +56,15 @@ class ProfileManagerActivity extends AppCompatActivity with OnMenuItemClickListe
.setView(image) .setView(image)
.setTitle(R.string.share) .setTitle(R.string.share)
.create() .create()
if (!nfcAvailable){ if (!isNfcAvailable) dialog.setMessage(getString(R.string.share_message_without_nfc))
dialog.setMessage(getString(R.string.share_message_without_nfc)) else if (!isNfcBeamEnabled) {
dialog.setMessage(getString(R.string.share_message_nfc_disabled))
dialog.setButton(DialogInterface.BUTTON_NEUTRAL, getString(R.string.turn_on_nfc),
((_, _) => startActivity(new Intent(Settings.ACTION_NFC_SETTINGS))): DialogInterface.OnClickListener)
} else { } else {
if (!nfcBeamEnable) { dialog.setMessage(getString(R.string.share_message))
dialog.setMessage(getString(R.string.share_message_nfc_disabled)) dialog.setOnDismissListener(_ =>
dialog.setButton(DialogInterface.BUTTON_NEUTRAL, getString(R.string.turn_on_nfc), ((_, _) => nfcAdapter.setNdefPushMessageCallback(null, ProfileManagerActivity.this))
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
startActivity(new Intent(Settings.ACTION_NFC_SETTINGS))
} else {
startActivity(new Intent(Settings.ACTION_WIRELESS_SETTINGS))
}
): DialogInterface.OnClickListener)
} else {
dialog.setMessage(getString(R.string.share_message))
dialog.setOnDismissListener(_ =>
nfcAdapter.setNdefPushMessageCallback(null, ProfileManagerActivity.this))
}
} }
dialog.show() dialog.show()
}) })
...@@ -111,12 +102,9 @@ class ProfileManagerActivity extends AppCompatActivity with OnMenuItemClickListe ...@@ -111,12 +102,9 @@ class ProfileManagerActivity extends AppCompatActivity with OnMenuItemClickListe
} }
} }
def onClick(v: View) = { def onClick(v: View) {
ShadowsocksApplication.switchProfile(item.id) ShadowsocksApplication.switchProfile(item.id)
finish finish
if (isLauncherFromShareIntent){
TaskStackBuilder.create(ProfileManagerActivity.this).addNextIntentWithParentStack(NavUtils.getParentActivityIntent(ProfileManagerActivity.this)).startActivities()
}
} }
} }
...@@ -181,11 +169,9 @@ class ProfileManagerActivity extends AppCompatActivity with OnMenuItemClickListe ...@@ -181,11 +169,9 @@ class ProfileManagerActivity extends AppCompatActivity with OnMenuItemClickListe
private var nfcAdapter : NfcAdapter = _ private var nfcAdapter : NfcAdapter = _
private var nfcShareItem: Array[Byte] = _ private var nfcShareItem: Array[Byte] = _
private var nfcAvailable = false private var isNfcAvailable: Boolean = _
private var nfcEnable = false private var isNfcEnabled: Boolean = _
private var nfcBeamEnable = false private var isNfcBeamEnabled: Boolean = _
private var isLauncherFromShareIntent = false
override def onCreate(savedInstanceState: Bundle) { override def onCreate(savedInstanceState: Bundle) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
...@@ -235,46 +221,40 @@ class ProfileManagerActivity extends AppCompatActivity with OnMenuItemClickListe ...@@ -235,46 +221,40 @@ class ProfileManagerActivity extends AppCompatActivity with OnMenuItemClickListe
new AlertDialog.Builder(this).setTitle(R.string.profile_manager_dialog) new AlertDialog.Builder(this).setTitle(R.string.profile_manager_dialog)
.setMessage(R.string.profile_manager_dialog_content).setPositiveButton(R.string.gotcha, null).create.show .setMessage(R.string.profile_manager_dialog_content).setPositiveButton(R.string.gotcha, null).create.show
} }
val intent = getIntent
if (intent != null) handleShareIntent(intent)
} }
override def onResume() { override def onResume() {
super.onResume() super.onResume()
isLauncherFromShareIntent = false updateNfcState()
handledShareIntent()
updateNFCState()
} }
override def onNewIntent(intent: Intent): Unit ={ override def onNewIntent(intent: Intent): Unit ={
super.onNewIntent(intent) super.onNewIntent(intent)
setIntent(intent) handleShareIntent(intent)
} }
def updateNFCState(): Unit = { def updateNfcState() {
isNfcAvailable = false
isNfcEnabled = false
isNfcBeamEnabled = false
nfcAdapter = NfcAdapter.getDefaultAdapter(this) nfcAdapter = NfcAdapter.getDefaultAdapter(this)
if (nfcAdapter != null){ if (nfcAdapter != null) {
nfcAvailable = true isNfcAvailable = true
if (nfcAdapter.isEnabled) { if (nfcAdapter.isEnabled) {
nfcEnable = true isNfcEnabled = true
if (nfcAdapter.isNdefPushEnabled) { if (nfcAdapter.isNdefPushEnabled) {
nfcBeamEnable = true isNfcBeamEnabled = true
nfcAdapter.setNdefPushMessageCallback(null, ProfileManagerActivity.this) nfcAdapter.setNdefPushMessageCallback(null, ProfileManagerActivity.this)
} else {
nfcBeamEnable = false
} }
} else{
nfcEnable = false
nfcBeamEnable = false
} }
} else {
nfcAvailable = false
nfcEnable = false
nfcBeamEnable = false
} }
} }
def handledShareIntent() { def handleShareIntent(intent: Intent) {
val intent = getIntent()
val sharedStr = intent.getAction match { val sharedStr = intent.getAction match {
case Intent.ACTION_VIEW => intent.getData.toString case Intent.ACTION_VIEW => intent.getData.toString
case NfcAdapter.ACTION_NDEF_DISCOVERED => case NfcAdapter.ACTION_NDEF_DISCOVERED =>
...@@ -298,7 +278,6 @@ class ProfileManagerActivity extends AppCompatActivity with OnMenuItemClickListe ...@@ -298,7 +278,6 @@ class ProfileManagerActivity extends AppCompatActivity with OnMenuItemClickListe
.setMessage(profiles.mkString("\n")) .setMessage(profiles.mkString("\n"))
.create() .create()
dialog.show() dialog.show()
isLauncherFromShareIntent = true
} }
override def onStart() { override def onStart() {
......
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