Commit a537a7fc authored by Max Lv's avatar Max Lv

Integrate a Barcode Scanner

parent bd58de6a
......@@ -30,7 +30,6 @@ libraryDependencies ++= Seq(
"dnsjava" % "dnsjava" % "2.1.7",
"com.github.kevinsawicki" % "http-request" % "6.0",
"eu.chainfire" % "libsuperuser" % "1.0.0.201602271131",
"com.google.zxing" % "android-integration" % "3.2.1",
"net.glxn.qrgen" % "android" % "2.0",
"com.google.android.gms" % "play-services-base" % "9.0.2",
"com.google.android.gms" % "play-services-ads" % "9.0.2",
......@@ -42,7 +41,8 @@ libraryDependencies ++= Seq(
"com.j256.ormlite" % "ormlite-core" % "4.48",
"com.j256.ormlite" % "ormlite-android" % "4.48",
"com.twofortyfouram" % "android-plugin-api-for-locale" % "1.0.2",
"com.github.clans" % "fab" % "1.6.4"
"com.github.clans" % "fab" % "1.6.4",
"me.dm7.barcodescanner" % "zxing" % "1.8.4"
)
proguardVersion in Android := "5.2.1"
......
addSbtPlugin("org.scala-android" % "sbt-android" % "1.6.4")
addSbtPlugin("org.scala-android" % "sbt-android" % "1.6.5")
addSbtPlugin("com.timushev.sbt" % "sbt-updates" % "0.1.10")
......@@ -7,6 +7,7 @@
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<uses-permission android:name="android.permission.NFC" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature
android:name="android.hardware.touchscreen"
......@@ -57,6 +58,7 @@
android:name=".ShadowsocksRunnerActivity"
android:process=":bg"
android:theme="@android:style/Theme.NoDisplay"
android:excludeFromRecents="true"
android:launchMode="singleTask">
</activity>
......@@ -83,10 +85,18 @@
</intent-filter>
</activity>
<activity
android:name=".ScannerActivity"
android:label="@string/add_profile_methods_scan_qr_code"
android:parentActivityName=".ProfileManagerActivity"
android:excludeFromRecents="true"
android:launchMode="singleTask"/>
<activity
android:name=".AppManager"
android:label="@string/proxied_apps"
android:parentActivityName=".Shadowsocks"
android:excludeFromRecents="true"
android:launchMode="singleTask"/>
<activity android:name=".TaskerActivity"
......
......@@ -2,6 +2,7 @@ package com.github.shadowsocks
import java.nio.charset.Charset
import android.app.Activity
import android.content._
import android.nfc.NfcAdapter.CreateNdefMessageCallback
import android.nfc.{NdefMessage, NdefRecord, NfcAdapter, NfcEvent}
......@@ -15,6 +16,7 @@ import android.support.v7.widget.helper.ItemTouchHelper.SimpleCallback
import android.support.v7.widget.{DefaultItemAnimator, LinearLayoutManager, RecyclerView, Toolbar}
import android.text.style.TextAppearanceSpan
import android.text.{SpannableStringBuilder, Spanned, TextUtils}
import android.util.Log
import android.view._
import android.widget.{CheckedTextView, ImageView, LinearLayout, Toast}
import com.github.clans.fab.{FloatingActionButton, FloatingActionMenu}
......@@ -23,15 +25,16 @@ import com.github.shadowsocks.database.Profile
import com.github.shadowsocks.utils.{Key, Parser, TrafficMonitor, Utils}
import com.github.shadowsocks.widget.UndoSnackbarManager
import com.github.shadowsocks.ShadowsocksApplication.app
import com.google.zxing.integration.android.IntentIntegrator
import net.glxn.qrgen.android.QRCode
import scala.collection.mutable.ArrayBuffer
final class ProfileManagerActivity extends AppCompatActivity with OnMenuItemClickListener with ServiceBoundContext
with View.OnClickListener with CreateNdefMessageCallback {
private final class ProfileViewHolder(val view: View) extends RecyclerView.ViewHolder(view)
with View.OnClickListener with View.OnKeyListener {
var item: Profile = _
private val text = itemView.findViewById(android.R.id.text1).asInstanceOf[CheckedTextView]
itemView.setOnClickListener(this)
......@@ -188,6 +191,8 @@ final class ProfileManagerActivity extends AppCompatActivity with OnMenuItemClic
private var isNfcEnabled: Boolean = _
private var isNfcBeamEnabled: Boolean = _
private val REQUEST_QRCODE = 1
override def onCreate(savedInstanceState: Bundle) {
super.onCreate(savedInstanceState)
setContentView(R.layout.layout_profiles)
......@@ -276,11 +281,8 @@ final class ProfileManagerActivity extends AppCompatActivity with OnMenuItemClic
finish
case R.id.fab_qrcode_add =>
menu.toggle(false)
val integrator = new IntentIntegrator(ProfileManagerActivity.this)
val list = new java.util.ArrayList(IntentIntegrator.TARGET_ALL_KNOWN)
list.add("tw.com.quickmark")
integrator.setTargetApplications(list)
integrator.initiateScan()
val intent = new Intent(this, classOf[ScannerActivity])
startActivityForResult(intent, REQUEST_QRCODE)
case R.id.fab_nfc_add =>
menu.toggle(true)
val dialog = new AlertDialog.Builder(ProfileManagerActivity.this)
......@@ -371,9 +373,8 @@ final class ProfileManagerActivity extends AppCompatActivity with OnMenuItemClic
}
override def onActivityResult(requestCode: Int, resultCode: Int, data: Intent) {
val scanResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, data)
if (scanResult != null) {
val contents = scanResult.getContents
if (requestCode == REQUEST_QRCODE && resultCode == Activity.RESULT_OK) {
val contents = data.getStringExtra("uri")
if (!TextUtils.isEmpty(contents))
Parser.findAll(contents).foreach(app.profileManager.createProfile)
}
......
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