Commit 8e46be59 authored by Mygod's avatar Mygod

Allow user to use any QR code scanner

parent 2e737418
......@@ -52,7 +52,6 @@ libraryDependencies ++=
"com.twofortyfouram" % "android-plugin-api-for-locale" % "1.0.2" ::
"dnsjava" % "dnsjava" % "2.1.7" ::
"eu.chainfire" % "libsuperuser" % "1.0.0.201608240809" ::
"com.google.zxing" % "android-integration" % "3.2.1" ::
"net.glxn.qrgen" % "android" % "2.0" ::
Nil
......
......@@ -37,13 +37,14 @@ import com.github.shadowsocks.database.Profile
import com.github.shadowsocks.utils._
import com.github.shadowsocks.widget.UndoSnackbarManager
import com.google.android.gms.ads.{AdRequest, AdSize, NativeExpressAdView}
import com.google.zxing.integration.android.IntentIntegrator
import scala.collection.mutable.ArrayBuffer
import scala.util.Random
object ProfilesFragment {
var instance: ProfilesFragment = _ // used for callback from ProfileManager and stateChanged from MainActivity
private final val REQUEST_SCAN_QR_CODE = 0
}
final class ProfilesFragment extends ToolbarFragment with Toolbar.OnMenuItemClickListener {
......@@ -304,23 +305,19 @@ final class ProfilesFragment extends ToolbarFragment with Toolbar.OnMenuItemClic
super.onDestroy()
}
override def onActivityResult(requestCode: Int, resultCode: Int, data: Intent) {
super.onActivityResult(resultCode, resultCode, data)
val scanResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, data)
if (scanResult != null) {
val contents = scanResult.getContents
if (!TextUtils.isEmpty(contents))
Parser.findAll(contents).foreach(app.profileManager.createProfile)
}
override def onActivityResult(requestCode: Int, resultCode: Int, data: Intent): Unit = requestCode match {
case REQUEST_SCAN_QR_CODE =>
val contents = data.getStringExtra("SCAN_RESULT")
if (!TextUtils.isEmpty(contents)) Parser.findAll(contents).foreach(app.profileManager.createProfile)
case _ => super.onActivityResult(resultCode, resultCode, data)
}
def onMenuItemClick(item: MenuItem): Boolean = item.getItemId match {
case R.id.action_scan_qr_code =>
val integrator = new IntentIntegrator(this)
val list = new java.util.ArrayList(IntentIntegrator.TARGET_ALL_KNOWN)
list.add("tw.com.quickmark")
integrator.setTargetApplications(list)
integrator.initiateScan()
startActivityForResult(new Intent("com.google.zxing.client.android.SCAN")
.addCategory(Intent.CATEGORY_DEFAULT)
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_DOCUMENT),
REQUEST_SCAN_QR_CODE)
true
case R.id.action_import =>
if (clipboard.hasPrimaryClip) {
......
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