Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
com.ccwangluo.accelerator
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
sheteng
com.ccwangluo.accelerator
Commits
49a3cfdc
Commit
49a3cfdc
authored
Mar 16, 2016
by
Lucas Liu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
NFC state check
parent
82325ecd
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
58 additions
and
11 deletions
+58
-11
src/main/res/values-zh/strings.xml
src/main/res/values-zh/strings.xml
+3
-0
src/main/res/values/strings.xml
src/main/res/values/strings.xml
+3
-0
src/main/scala/com/github/shadowsocks/ProfileManagerActivity.scala
...scala/com/github/shadowsocks/ProfileManagerActivity.scala
+52
-11
No files found.
src/main/res/values-zh/strings.xml
View file @
49a3cfdc
...
...
@@ -62,6 +62,9 @@
<string
name=
"flushing"
>
刷新中……
</string>
<string
name=
"share"
>
分享
</string>
<string
name=
"share_message"
>
扫描二维码或者使用 NFC(Android Beam)
</string>
<string
name=
"share_message_without_nfc"
>
扫描二维码
</string>
<string
name=
"share_message_nfc_disabled"
>
扫描二维码,NFC(Android Beam)被禁用
</string>
<string
name=
"turn_on_nfc"
>
打开 NFC
&
Android Beam
</string>
<string
name=
"add_profile"
>
添加配置文件
</string>
<string
name=
"nat"
>
NAT 模式 (仅限调试)
</string>
...
...
src/main/res/values/strings.xml
View file @
49a3cfdc
...
...
@@ -93,6 +93,9 @@
<string
name=
"about_title"
>
Shadowsocks %s
</string>
<string
name=
"share"
>
Share
</string>
<string
name=
"share_message"
>
Scan QRCode or Use NFC (Android Beam)
</string>
<string
name=
"share_message_without_nfc"
>
Scan QRCode
</string>
<string
name=
"share_message_nfc_disabled"
>
Scan QRCode, NFC (Android Beam) is disabled
</string>
<string
name=
"turn_on_nfc"
>
Turn on NFC
&
Android Beam
</string>
<string
name=
"flush_dnscache"
>
Flush DNS cache
</string>
<string
name=
"flush_dnscache_summary"
>
Only useful in NAT mode
</string>
<string
name=
"flush_dnscache_summary_root"
>
Only useful in NAT mode. Requires ROOT permission.
</string>
...
...
src/main/scala/com/github/shadowsocks/ProfileManagerActivity.scala
View file @
49a3cfdc
...
...
@@ -5,7 +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.
{
Bundle
,
Handler
}
import
android.os.
{
Build
,
Bundle
,
Handler
}
import
android.provider.Settings
import
android.support.v7.app.
{
AlertDialog
,
AppCompatActivity
}
import
android.support.v7.widget.RecyclerView.ViewHolder
import
android.support.v7.widget.Toolbar.OnMenuItemClickListener
...
...
@@ -36,8 +37,8 @@ class ProfileManagerActivity extends AppCompatActivity with OnMenuItemClickListe
val
shareBtn
=
itemView
.
findViewById
(
R
.
id
.
share
)
shareBtn
.
setOnClickListener
(
_
=>
{
val
url
=
item
.
toString
if
(
nfc
Adapter
!=
null
&&
nfcAdapter
.
isEnabled
)
{
nfcAdapter
.
setNdefPushMessageCallback
(
ProfileManagerActivity
.
this
,
ProfileManagerActivity
.
this
)
if
(
nfc
BeamEnable
)
{
nfcAdapter
.
setNdefPushMessageCallback
(
ProfileManagerActivity
.
this
,
ProfileManagerActivity
.
this
)
nfcShareItem
=
url
.
getBytes
(
Charset
.
forName
(
"UTF-8"
))
}
val
image
=
new
ImageView
(
ProfileManagerActivity
.
this
)
...
...
@@ -53,11 +54,26 @@ class ProfileManagerActivity extends AppCompatActivity with OnMenuItemClickListe
.
setNegativeButton
(
R
.
string
.
copy_url
,
((
_
,
_
)
=>
clipboard
.
setPrimaryClip
(
ClipData
.
newPlainText
(
null
,
url
)))
:
DialogInterface.OnClickListener
)
.
setView
(
image
)
.
setMessage
(
R
.
string
.
share_message
)
.
setTitle
(
R
.
string
.
share
)
.
create
()
dialog
.
setOnDismissListener
(
_
=>
if
(
nfcAdapter
!=
null
&&
nfcAdapter
.
isEnabled
)
if
(!
nfcAvailable
){
dialog
.
setMessage
(
getString
(
R
.
string
.
share_message_without_nfc
))
}
else
{
if
(!
nfcBeamEnable
)
{
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
)
}
else
{
dialog
.
setMessage
(
getString
(
R
.
string
.
share_message
))
dialog
.
setOnDismissListener
(
_
=>
nfcAdapter
.
setNdefPushMessageCallback
(
null
,
ProfileManagerActivity
.
this
))
}
}
dialog
.
show
()
})
shareBtn
.
setOnLongClickListener
(
_
=>
{
...
...
@@ -158,8 +174,12 @@ class ProfileManagerActivity extends AppCompatActivity with OnMenuItemClickListe
private
var
undoManager
:
UndoSnackbarManager
[
Profile
]
=
_
private
lazy
val
clipboard
=
getSystemService
(
Context
.
CLIPBOARD_SERVICE
).
asInstanceOf
[
ClipboardManager
]
private
var
nfcAdapter
:
NfcAdapter
=
_
private
var
nfcAdapter
:
NfcAdapter
=
_
private
var
nfcShareItem
:
Array
[
Byte
]
=
_
private
var
nfcAvailable
=
false
private
var
nfcEnable
=
false
private
var
nfcBeamEnable
=
false
override
def
onCreate
(
savedInstanceState
:
Bundle
)
{
super
.
onCreate
(
savedInstanceState
)
...
...
@@ -175,10 +195,6 @@ class ProfileManagerActivity extends AppCompatActivity with OnMenuItemClickListe
toolbar
.
inflateMenu
(
R
.
menu
.
profile_manager_menu
)
toolbar
.
setOnMenuItemClickListener
(
this
)
nfcAdapter
=
NfcAdapter
.
getDefaultAdapter
(
this
)
if
(
nfcAdapter
!=
null
&&
nfcAdapter
.
isEnabled
)
nfcAdapter
.
setNdefPushMessageCallback
(
null
,
ProfileManagerActivity
.
this
)
ShadowsocksApplication
.
profileManager
.
setProfileAddedListener
(
profilesAdapter
.
add
)
val
profilesList
=
findViewById
(
R
.
id
.
profilesList
).
asInstanceOf
[
RecyclerView
]
val
layoutManager
=
new
LinearLayoutManager
(
this
)
...
...
@@ -215,6 +231,31 @@ class ProfileManagerActivity extends AppCompatActivity with OnMenuItemClickListe
}
}
override
def
onResume
()
{
super
.
onResume
()
nfcAdapter
=
NfcAdapter
.
getDefaultAdapter
(
this
)
if
(
nfcAdapter
!=
null
){
nfcAvailable
=
true
if
(
nfcAdapter
.
isEnabled
)
{
nfcEnable
=
true
if
(
nfcAdapter
.
isNdefPushEnabled
)
{
nfcBeamEnable
=
true
nfcAdapter
.
setNdefPushMessageCallback
(
null
,
ProfileManagerActivity
.
this
)
}
else
{
nfcBeamEnable
=
false
}
}
else
{
nfcEnable
=
false
nfcBeamEnable
=
false
}
}
else
{
nfcAvailable
=
false
nfcEnable
=
false
nfcBeamEnable
=
false
}
}
override
def
onStart
()
{
super
.
onStart
()
registerCallback
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment