Update to the newest version of ZXing Android Embedded
This commit is contained in:
parent
09e3e8f544
commit
2d6cd4e203
5 changed files with 23 additions and 69 deletions
|
@ -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:
|
||||
|
|
|
@ -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'
|
||||
|
||||
|
|
|
@ -24,11 +24,9 @@
|
|||
</intent-filter>
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".CaptureActivityAnyOrientation"
|
||||
android:name="com.journeyapps.barcodescanner.CaptureActivity"
|
||||
android:screenOrientation="fullSensor"
|
||||
android:stateNotNeeded="true"
|
||||
android:theme="@style/zxing_CaptureTheme"
|
||||
android:windowSoftInputMode="stateAlwaysHidden" />
|
||||
tools:replace="screenOrientation" />
|
||||
|
||||
</application>
|
||||
</manifest>
|
||||
|
|
|
@ -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 {
|
||||
|
||||
}
|
|
@ -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();
|
||||
|
|
Loading…
Reference in a new issue