Remove internal QR Scanner. #1021
Report to @Mygod if you have any question. :)
This commit is contained in:
@@ -52,7 +52,6 @@ libraryDependencies ++=
|
||||
"dnsjava" % "dnsjava" % "2.1.7" ::
|
||||
"eu.chainfire" % "libsuperuser" % "1.0.0.201608240809" ::
|
||||
"com.google.zxing" % "android-integration" % "3.2.1" ::
|
||||
"me.dm7.barcodescanner" % "zxing" % "1.9" ::
|
||||
"net.glxn.qrgen" % "android" % "2.0" ::
|
||||
Nil
|
||||
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
<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"
|
||||
android:required="false"/>
|
||||
@@ -77,12 +76,6 @@
|
||||
android:taskAffinity=""
|
||||
android:launchMode="singleTask"/>
|
||||
|
||||
<activity
|
||||
android:name=".ScannerActivity"
|
||||
android:label="@string/add_profile_methods_scan_qr_code"
|
||||
android:parentActivityName=".MainActivity"
|
||||
android:excludeFromRecents="true"/>
|
||||
|
||||
<activity
|
||||
android:name=".AppManager"
|
||||
android:label="@string/proxied_apps"
|
||||
|
||||
@@ -28,6 +28,7 @@ import android.support.v7.widget.RecyclerView.ViewHolder
|
||||
import android.support.v7.widget._
|
||||
import android.support.v7.widget.helper.ItemTouchHelper
|
||||
import android.support.v7.widget.helper.ItemTouchHelper.SimpleCallback
|
||||
import android.text.TextUtils
|
||||
import android.view.View.OnLongClickListener
|
||||
import android.view._
|
||||
import android.widget.{LinearLayout, PopupMenu, TextView, Toast}
|
||||
@@ -36,6 +37,7 @@ 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
|
||||
@@ -302,9 +304,23 @@ 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)
|
||||
}
|
||||
}
|
||||
|
||||
def onMenuItemClick(item: MenuItem): Boolean = item.getItemId match {
|
||||
case R.id.action_scan_qr_code =>
|
||||
startActivity(new Intent(getActivity, classOf[ScannerActivity]))
|
||||
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()
|
||||
true
|
||||
case R.id.action_import =>
|
||||
if (clipboard.hasPrimaryClip) {
|
||||
|
||||
@@ -1,123 +0,0 @@
|
||||
/*******************************************************************************/
|
||||
/* */
|
||||
/* Copyright (C) 2016 by Max Lv <max.c.lv@gmail.com> */
|
||||
/* Copyright (C) 2016 by Mygod Studio <contact-shadowsocks-android@mygod.be> */
|
||||
/* */
|
||||
/* This program is free software: you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation, either version 3 of the License, or */
|
||||
/* (at your option) any later version. */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/*******************************************************************************/
|
||||
|
||||
package com.github.shadowsocks
|
||||
|
||||
import android.app.TaskStackBuilder
|
||||
import android.content.Intent
|
||||
import android.content.pm.{PackageManager, ShortcutManager}
|
||||
import android.os.{Build, Bundle}
|
||||
import android.support.v4.app.ActivityCompat
|
||||
import android.support.v4.content.ContextCompat
|
||||
import android.support.v7.app.AppCompatActivity
|
||||
import android.support.v7.widget.Toolbar
|
||||
import android.text.TextUtils
|
||||
import android.widget.Toast
|
||||
import com.github.shadowsocks.ShadowsocksApplication.app
|
||||
import com.github.shadowsocks.utils.Parser
|
||||
import com.google.zxing.Result
|
||||
import com.google.zxing.integration.android.IntentIntegrator
|
||||
import me.dm7.barcodescanner.zxing.ZXingScannerView
|
||||
|
||||
object ScannerActivity {
|
||||
private final val MY_PERMISSIONS_REQUEST_CAMERA = 1
|
||||
}
|
||||
|
||||
class ScannerActivity extends AppCompatActivity with ZXingScannerView.ResultHandler {
|
||||
import ScannerActivity._
|
||||
|
||||
private var scannerView: ZXingScannerView = _
|
||||
|
||||
override def onRequestPermissionsResult(requestCode: Int, permissions: Array[String],
|
||||
grantResults: Array[Int]) {
|
||||
if (requestCode == MY_PERMISSIONS_REQUEST_CAMERA) {
|
||||
// If request is cancelled, the result arrays are empty.
|
||||
if (grantResults.length > 0
|
||||
&& grantResults(0) == PackageManager.PERMISSION_GRANTED) {
|
||||
scannerView.setResultHandler(this)
|
||||
scannerView.startCamera()
|
||||
} else {
|
||||
Toast.makeText(this, R.string.add_profile_scanner_permission_required, Toast.LENGTH_SHORT).show()
|
||||
finish()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override def onCreate(state: Bundle) {
|
||||
super.onCreate(state)
|
||||
setContentView(R.layout.layout_scanner)
|
||||
val toolbar = findViewById(R.id.toolbar).asInstanceOf[Toolbar]
|
||||
toolbar.setTitle(getTitle)
|
||||
toolbar.setNavigationIcon(R.drawable.ic_navigation_close)
|
||||
toolbar.setNavigationOnClickListener(_ => finish())
|
||||
scannerView = findViewById(R.id.scanner).asInstanceOf[ZXingScannerView]
|
||||
if (Build.VERSION.SDK_INT >= 25) getSystemService(classOf[ShortcutManager]).reportShortcutUsed("scan")
|
||||
}
|
||||
|
||||
override def onResume() {
|
||||
super.onResume()
|
||||
val integrator = new IntentIntegrator(ScannerActivity.this)
|
||||
val list = new java.util.ArrayList(IntentIntegrator.TARGET_ALL_KNOWN)
|
||||
list.add("tw.com.quickmark")
|
||||
integrator.setTargetApplications(list)
|
||||
val dialog = integrator.initiateScan()
|
||||
if (dialog != null) {
|
||||
val permissionCheck = ContextCompat.checkSelfPermission(this,
|
||||
android.Manifest.permission.CAMERA)
|
||||
if (permissionCheck == PackageManager.PERMISSION_GRANTED) {
|
||||
scannerView.setResultHandler(this) // Register ourselves as a handler for scan results.
|
||||
scannerView.startCamera() // Start camera on resume
|
||||
} else {
|
||||
ActivityCompat.requestPermissions(this,
|
||||
Array(android.Manifest.permission.CAMERA), MY_PERMISSIONS_REQUEST_CAMERA)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override def onPause() {
|
||||
super.onPause()
|
||||
scannerView.stopCamera() // Stop camera on pause
|
||||
}
|
||||
|
||||
override def onActivityResult(requestCode: Int, resultCode: Int, data: Intent) {
|
||||
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)
|
||||
val intent = getParentActivityIntent
|
||||
if (shouldUpRecreateTask(intent) || isTaskRoot)
|
||||
TaskStackBuilder.create(this).addNextIntentWithParentStack(intent).startActivities()
|
||||
else finish()
|
||||
} else {
|
||||
super.onActivityResult(resultCode, resultCode, data)
|
||||
}
|
||||
}
|
||||
|
||||
override def handleResult(rawResult: Result) {
|
||||
val uri = rawResult.getText
|
||||
if (!TextUtils.isEmpty(uri))
|
||||
Parser.findAll(uri).foreach(app.profileManager.createProfile)
|
||||
val intent = getParentActivityIntent
|
||||
if (shouldUpRecreateTask(intent) || isTaskRoot)
|
||||
TaskStackBuilder.create(this).addNextIntentWithParentStack(intent).startActivities()
|
||||
else finish()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user