Commit e2a31847 authored by Mygod's avatar Mygod

Refine #614 #615

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