Update to the newest version of ZXing Android Embedded

This commit is contained in:
Jakob Nixdorf 2017-07-05 13:09:22 +02:00
parent 09e3e8f544
commit 2d6cd4e203
No known key found for this signature in database
GPG key ID: BE99BF86574A7DBC
5 changed files with 23 additions and 69 deletions

View file

@ -47,7 +47,6 @@ goes to Bruno.
* [Apache Commons Code](https://commons.apache.org/proper/commons-codec/) * [Apache Commons Code](https://commons.apache.org/proper/commons-codec/)
* [MaterialProgressBar](https://github.com/DreaminginCodeZH/MaterialProgressBar) * [MaterialProgressBar](https://github.com/DreaminginCodeZH/MaterialProgressBar)
* [ZXing](https://github.com/zxing/zxing)
* [ZXing Android Embedded](https://github.com/journeyapps/zxing-android-embedded) * [ZXing Android Embedded](https://github.com/journeyapps/zxing-android-embedded)
#### Code examples used: #### Code examples used:

View file

@ -35,8 +35,7 @@ dependencies {
compile 'com.android.support:recyclerview-v7:25.3.1' compile 'com.android.support:recyclerview-v7:25.3.1'
compile 'com.android.support:cardview-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.android.support.constraint:constraint-layout:1.0.2'
compile 'com.journeyapps:zxing-android-embedded:3.0.3@aar' compile 'com.journeyapps:zxing-android-embedded:3.5.0'
compile 'com.google.zxing:core:3.2.1'
compile 'commons-codec:commons-codec:1.5' compile 'commons-codec:commons-codec:1.5'
compile 'me.zhanghai.android.materialprogressbar:library:1.4.1' compile 'me.zhanghai.android.materialprogressbar:library:1.4.1'

View file

@ -24,11 +24,9 @@
</intent-filter> </intent-filter>
</activity> </activity>
<activity <activity
android:name=".CaptureActivityAnyOrientation" android:name="com.journeyapps.barcodescanner.CaptureActivity"
android:screenOrientation="fullSensor" android:screenOrientation="fullSensor"
android:stateNotNeeded="true" tools:replace="screenOrientation" />
android:theme="@style/zxing_CaptureTheme"
android:windowSoftInputMode="stateAlwaysHidden" />
</application> </application>
</manifest> </manifest>

View file

@ -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 {
}

View file

@ -56,8 +56,8 @@ import android.widget.ProgressBar;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import com.google.zxing.client.android.Intents;
import com.google.zxing.integration.android.IntentIntegrator; import com.google.zxing.integration.android.IntentIntegrator;
import com.google.zxing.integration.android.IntentResult;
import org.shadowice.flocke.andotp.ItemTouchHelper.SimpleItemTouchHelperCallback; import org.shadowice.flocke.andotp.ItemTouchHelper.SimpleItemTouchHelperCallback;
@ -69,9 +69,8 @@ public class MainActivity extends AppCompatActivity {
private Handler handler; private Handler handler;
private Runnable handlerTask; private Runnable handlerTask;
private static final int PERMISSIONS_REQUEST_CAMERA = 42; private static final int PERMISSIONS_REQUEST_WRITE_EXPORT = 42;
private static final int PERMISSIONS_REQUEST_WRITE_EXPORT = 41; private static final int PERMISSIONS_REQUEST_READ_IMPORT = 41;
private static final int PERMISSIONS_REQUEST_READ_IMPORT = 40;
private static final int INTENT_OPEN_DOCUMENT = 24; private static final int INTENT_OPEN_DOCUMENT = 24;
private static final int INTENT_SAVE_DOCUMENT= 23; 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"; private static final String DEFAULT_BACKUP_MIMETYPE = "application/json";
// QR code scanning // QR code scanning
private void doScanQRCode(){
new IntentIntegrator(MainActivity.this)
.setCaptureActivity(CaptureActivityAnyOrientation.class)
.setOrientationLocked(false)
.initiateScan();
}
private void scanQRCode(){ private void scanQRCode(){
if (ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA) == PackageManager.PERMISSION_GRANTED) { new IntentIntegrator(MainActivity.this)
doScanQRCode(); .setOrientationLocked(false)
} else { .setBeepEnabled(false)
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.CAMERA}, PERMISSIONS_REQUEST_CAMERA); .initiateScan();
}
} }
// About dialog // About dialog
@ -207,13 +198,7 @@ public class MainActivity extends AppCompatActivity {
// Permission results // Permission results
@Override @Override
public void onRequestPermissionsResult(int requestCode, @NonNull String permissions[], @NonNull int[] grantResults) { public void onRequestPermissionsResult(int requestCode, @NonNull String permissions[], @NonNull int[] grantResults) {
if(requestCode == PERMISSIONS_REQUEST_CAMERA) { if (requestCode == PERMISSIONS_REQUEST_WRITE_EXPORT) {
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 (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
exportJSONWithSelector(); exportJSONWithSelector();
} else { } else {
@ -335,16 +320,19 @@ public class MainActivity extends AppCompatActivity {
protected void onActivityResult(int requestCode, int resultCode, Intent intent) { protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
super.onActivityResult(requestCode, resultCode, intent); super.onActivityResult(requestCode, resultCode, intent);
if (requestCode == IntentIntegrator.REQUEST_CODE && resultCode == Activity.RESULT_OK) { IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, intent);
try { if(result != null) {
Entry e = new Entry(intent.getStringExtra(Intents.Scan.RESULT)); if(result.getContents() != null) {
e.setCurrentOTP(TOTPHelper.generate(e.getSecret(), e.getPeriod())); try {
adapter.addEntry(e); Entry e = new Entry(result.getContents());
SettingsHelper.store(this, adapter.getEntries()); e.setCurrentOTP(TOTPHelper.generate(e.getSecret(), e.getPeriod()));
adapter.addEntry(e);
SettingsHelper.store(this, adapter.getEntries());
adapter.notifyDataSetChanged(); adapter.notifyDataSetChanged();
} catch (Exception e) { } catch (Exception e) {
Toast.makeText(this, R.string.msg_invalid_qr_code, Toast.LENGTH_LONG).show(); Toast.makeText(this, R.string.msg_invalid_qr_code, Toast.LENGTH_LONG).show();
}
} }
} else if (requestCode == INTENT_OPEN_DOCUMENT && resultCode == Activity.RESULT_OK) { } else if (requestCode == INTENT_OPEN_DOCUMENT && resultCode == Activity.RESULT_OK) {
Uri file; Uri file;
@ -400,7 +388,6 @@ public class MainActivity extends AppCompatActivity {
return true; return true;
} }
@Override @Override
public boolean onOptionsItemSelected(MenuItem item) { public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId(); int id = item.getItemId();