diff options
| author | srowen <srowen@59b500cc-1b3d-0410-9834-0bbf25fbcc57> | 2012-01-18 21:11:54 +0400 |
|---|---|---|
| committer | srowen <srowen@59b500cc-1b3d-0410-9834-0bbf25fbcc57> | 2012-01-18 21:11:54 +0400 |
| commit | 420e47efd17c85d9d0fccc05612ab663cff12e14 (patch) | |
| tree | e947997d55e01f92276f97b73dec97eab4e06ea2 /android-integration/src/com | |
| parent | a39e9d81631a012818adfa1c3db13a567313c37c (diff) | |
| download | zxing-420e47efd17c85d9d0fccc05612ab663cff12e14.tar.xz | |
Add Fragment-friendly integration and bump requirement to Android 4.0 to build (not to use) since that's the only thing available in Maven beyond 2.x
git-svn-id: https://zxing.googlecode.com/svn/trunk@2119 59b500cc-1b3d-0410-9834-0bbf25fbcc57
Diffstat (limited to 'android-integration/src/com')
| -rw-r--r-- | android-integration/src/com/google/zxing/integration/android/IntentIntegrator.java | 18 | ||||
| -rw-r--r-- | android-integration/src/com/google/zxing/integration/android/IntentIntegratorV30.java | 44 |
2 files changed, 60 insertions, 2 deletions
diff --git a/android-integration/src/com/google/zxing/integration/android/IntentIntegrator.java b/android-integration/src/com/google/zxing/integration/android/IntentIntegrator.java index 68a13d2e3..976f50f07 100644 --- a/android-integration/src/com/google/zxing/integration/android/IntentIntegrator.java +++ b/android-integration/src/com/google/zxing/integration/android/IntentIntegrator.java @@ -92,7 +92,7 @@ import android.util.Log; * @author Brad Drehmer * @author gcstang */ -public final class IntentIntegrator { +public class IntentIntegrator { public static final int REQUEST_CODE = 0x0000c0de; // Only use bottom 16 bits private static final String TAG = IntentIntegrator.class.getSimpleName(); @@ -235,9 +235,23 @@ public final class IntentIntegrator { intentScan.setPackage(targetAppPackage); intentScan.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); intentScan.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); - activity.startActivityForResult(intentScan, REQUEST_CODE); + startActivityForResult(intentScan, REQUEST_CODE); return null; } + + /** + * Start an activity.<br> + * This method is defined to allow different methods of activity starting for + * newer versions of Android and for compatibility library. + * + * @param intent Intent to start. + * @param code Request code for the activity + * @see android.app.Activity#startActivityForResult(Intent, int) + * @see android.app.Fragment#startActivityForResult(Intent, int) + */ + protected void startActivityForResult(Intent intent, int code) { + activity.startActivityForResult(intent, code); + } private String findTargetAppPackage(Intent intent) { PackageManager pm = activity.getPackageManager(); diff --git a/android-integration/src/com/google/zxing/integration/android/IntentIntegratorV30.java b/android-integration/src/com/google/zxing/integration/android/IntentIntegratorV30.java new file mode 100644 index 000000000..20d0a590b --- /dev/null +++ b/android-integration/src/com/google/zxing/integration/android/IntentIntegratorV30.java @@ -0,0 +1,44 @@ +/* + * Copyright 2012 ZXing authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.zxing.integration.android; + +import android.app.Fragment; +import android.content.Intent; + +/** + * IntentIntegrator for Android version 3.0 and beyond. + * + * @author Lachezar Dobrev + */ +public final class IntentIntegratorV30 extends IntentIntegrator { + + private final Fragment fragment; + + /** + * @param fragment Fragment to handle activity response. + */ + public IntentIntegratorV30(Fragment fragment) { + super(fragment.getActivity()); + this.fragment = fragment; + } + + @Override + protected void startActivityForResult(Intent intent, int code) { + fragment.startActivityForResult(intent, code); + } + +}
\ No newline at end of file |
