diff --git a/README.md b/README.md index 700bef44..760f36e5 100644 --- a/README.md +++ b/README.md @@ -47,7 +47,6 @@ goes to Bruno. * [Apache Commons Code](https://commons.apache.org/proper/commons-codec/) * [MaterialProgressBar](https://github.com/DreaminginCodeZH/MaterialProgressBar) - * [ZXing](https://github.com/zxing/zxing) * [ZXing Android Embedded](https://github.com/journeyapps/zxing-android-embedded) #### Code examples used: diff --git a/app/build.gradle b/app/build.gradle index df098bfc..ba112fb3 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -35,8 +35,7 @@ dependencies { compile 'com.android.support:recyclerview-v7:25.3.1' compile 'com.android.support:cardview-v7:25.3.1' compile 'com.android.support.constraint:constraint-layout:1.0.2' - compile 'com.journeyapps:zxing-android-embedded:3.0.3@aar' - compile 'com.google.zxing:core:3.2.1' + compile 'com.journeyapps:zxing-android-embedded:3.5.0' compile 'commons-codec:commons-codec:1.5' compile 'me.zhanghai.android.materialprogressbar:library:1.4.1' diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index a0ba521a..4f0c4f95 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -24,11 +24,9 @@ + tools:replace="screenOrientation" /> diff --git a/app/src/main/java/org/shadowice/flocke/andotp/CaptureActivityAnyOrientation.java b/app/src/main/java/org/shadowice/flocke/andotp/CaptureActivityAnyOrientation.java deleted file mode 100644 index e2de39f0..00000000 --- a/app/src/main/java/org/shadowice/flocke/andotp/CaptureActivityAnyOrientation.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright (C) 2015 Bruno Bierbaumer - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package org.shadowice.flocke.andotp; - -import com.journeyapps.barcodescanner.CaptureActivity; - -public class CaptureActivityAnyOrientation extends CaptureActivity { - -} diff --git a/app/src/main/java/org/shadowice/flocke/andotp/MainActivity.java b/app/src/main/java/org/shadowice/flocke/andotp/MainActivity.java index 3cddbd9e..ccf69dd9 100644 --- a/app/src/main/java/org/shadowice/flocke/andotp/MainActivity.java +++ b/app/src/main/java/org/shadowice/flocke/andotp/MainActivity.java @@ -56,8 +56,8 @@ import android.widget.ProgressBar; import android.widget.TextView; import android.widget.Toast; -import com.google.zxing.client.android.Intents; import com.google.zxing.integration.android.IntentIntegrator; +import com.google.zxing.integration.android.IntentResult; import org.shadowice.flocke.andotp.ItemTouchHelper.SimpleItemTouchHelperCallback; @@ -69,9 +69,8 @@ public class MainActivity extends AppCompatActivity { private Handler handler; private Runnable handlerTask; - private static final int PERMISSIONS_REQUEST_CAMERA = 42; - private static final int PERMISSIONS_REQUEST_WRITE_EXPORT = 41; - private static final int PERMISSIONS_REQUEST_READ_IMPORT = 40; + private static final int PERMISSIONS_REQUEST_WRITE_EXPORT = 42; + private static final int PERMISSIONS_REQUEST_READ_IMPORT = 41; private static final int INTENT_OPEN_DOCUMENT = 24; private static final int INTENT_SAVE_DOCUMENT= 23; @@ -80,19 +79,11 @@ public class MainActivity extends AppCompatActivity { private static final String DEFAULT_BACKUP_MIMETYPE = "application/json"; // QR code scanning - private void doScanQRCode(){ - new IntentIntegrator(MainActivity.this) - .setCaptureActivity(CaptureActivityAnyOrientation.class) - .setOrientationLocked(false) - .initiateScan(); - } - private void scanQRCode(){ - if (ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA) == PackageManager.PERMISSION_GRANTED) { - doScanQRCode(); - } else { - ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.CAMERA}, PERMISSIONS_REQUEST_CAMERA); - } + new IntentIntegrator(MainActivity.this) + .setOrientationLocked(false) + .setBeepEnabled(false) + .initiateScan(); } // About dialog @@ -207,13 +198,7 @@ public class MainActivity extends AppCompatActivity { // Permission results @Override public void onRequestPermissionsResult(int requestCode, @NonNull String permissions[], @NonNull int[] grantResults) { - if(requestCode == PERMISSIONS_REQUEST_CAMERA) { - if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { - doScanQRCode(); - } else { - Toast.makeText(this, R.string.msg_camera_permission, Toast.LENGTH_LONG).show(); - } - } else if (requestCode == PERMISSIONS_REQUEST_WRITE_EXPORT) { + if (requestCode == PERMISSIONS_REQUEST_WRITE_EXPORT) { if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { exportJSONWithSelector(); } else { @@ -335,16 +320,19 @@ public class MainActivity extends AppCompatActivity { protected void onActivityResult(int requestCode, int resultCode, Intent intent) { super.onActivityResult(requestCode, resultCode, intent); - if (requestCode == IntentIntegrator.REQUEST_CODE && resultCode == Activity.RESULT_OK) { - try { - Entry e = new Entry(intent.getStringExtra(Intents.Scan.RESULT)); - e.setCurrentOTP(TOTPHelper.generate(e.getSecret(), e.getPeriod())); - adapter.addEntry(e); - SettingsHelper.store(this, adapter.getEntries()); + IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, intent); + if(result != null) { + if(result.getContents() != null) { + try { + Entry e = new Entry(result.getContents()); + e.setCurrentOTP(TOTPHelper.generate(e.getSecret(), e.getPeriod())); + adapter.addEntry(e); + SettingsHelper.store(this, adapter.getEntries()); - adapter.notifyDataSetChanged(); - } catch (Exception e) { - Toast.makeText(this, R.string.msg_invalid_qr_code, Toast.LENGTH_LONG).show(); + adapter.notifyDataSetChanged(); + } catch (Exception e) { + Toast.makeText(this, R.string.msg_invalid_qr_code, Toast.LENGTH_LONG).show(); + } } } else if (requestCode == INTENT_OPEN_DOCUMENT && resultCode == Activity.RESULT_OK) { Uri file; @@ -400,7 +388,6 @@ public class MainActivity extends AppCompatActivity { return true; } - @Override public boolean onOptionsItemSelected(MenuItem item) { int id = item.getItemId();