hints) {
- multiFormatReader = new MultiFormatReader();
- multiFormatReader.setHints(hints);
- this.activity = activity;
- }
-
- @Override
- public void handleMessage(Message message) {
- if (!running) {
- return;
- }
- switch (message.what) {
- case R.id.decode:
- decode((byte[]) message.obj, message.arg1, message.arg2);
- break;
- case R.id.quit:
- running = false;
- Looper.myLooper().quit();
- break;
- }
- }
-
- /**
- * Decode the data within the viewfinder rectangle, and time how long it took. For efficiency,
- * reuse the same reader objects from one decode to the next.
- *
- * @param data The YUV preview frame.
- * @param width The width of the preview frame.
- * @param height The height of the preview frame.
- */
- private void decode(byte[] data, int width, int height) {
- long start = System.currentTimeMillis();
- Result rawResult = null;
- PlanarYUVLuminanceSource source = activity.getCameraManager().buildLuminanceSource(data, width, height);
- if (source != null) {
- BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
- try {
- rawResult = multiFormatReader.decodeWithState(bitmap);
- } catch (ReaderException re) {
- // continue
- } finally {
- multiFormatReader.reset();
- }
- }
-
- Handler handler = activity.getHandler();
- if (rawResult != null) {
- // Don't log the barcode contents for security.
- long end = System.currentTimeMillis();
- Log.d(TAG, "Found barcode in " + (end - start) + " ms");
- if (handler != null) {
- Message message = Message.obtain(handler, R.id.decode_succeeded, rawResult);
- Bundle bundle = new Bundle();
- bundleThumbnail(source, bundle);
- message.setData(bundle);
- message.sendToTarget();
- }
- } else {
- if (handler != null) {
- Message message = Message.obtain(handler, R.id.decode_failed);
- message.sendToTarget();
- }
- }
- }
-
- private static void bundleThumbnail(PlanarYUVLuminanceSource source, Bundle bundle) {
- int[] pixels = source.renderThumbnail();
- int width = source.getThumbnailWidth();
- int height = source.getThumbnailHeight();
- Bitmap bitmap = Bitmap.createBitmap(pixels, 0, width, width, height, Bitmap.Config.ARGB_8888);
- ByteArrayOutputStream out = new ByteArrayOutputStream();
- bitmap.compress(Bitmap.CompressFormat.JPEG, 50, out);
- bundle.putByteArray(DecodeThread.BARCODE_BITMAP, out.toByteArray());
- bundle.putFloat(DecodeThread.BARCODE_SCALED_FACTOR, (float) width / source.getWidth());
- }
-
-}
diff --git a/app/src/main/java/com/google/zxing/client/android/DecodeHintManager.java b/app/src/main/java/com/google/zxing/client/android/DecodeHintManager.java
deleted file mode 100644
index 39305fe..0000000
--- a/app/src/main/java/com/google/zxing/client/android/DecodeHintManager.java
+++ /dev/null
@@ -1,236 +0,0 @@
-/*
- * Copyright (C) 2013 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.client.android;
-
-import java.util.EnumMap;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.regex.Pattern;
-
-import android.content.Intent;
-import android.net.Uri;
-import android.os.Bundle;
-import android.util.Log;
-
-import com.google.zxing.DecodeHintType;
-
-/**
- * @author Lachezar Dobrev
- */
-final class DecodeHintManager {
-
- private static final String TAG = DecodeHintManager.class.getSimpleName();
-
- // This pattern is used in decoding integer arrays.
- private static final Pattern COMMA = Pattern.compile(",");
-
- private DecodeHintManager() {}
-
- /**
- * Split a query string into a list of name-value pairs.
- *
- * This is an alternative to the {@link Uri#getQueryParameterNames()} and
- * {@link Uri#getQueryParameters(String)}, which are quirky and not suitable
- * for exist-only Uri parameters.
- *
- * This method ignores multiple parameters with the same name and returns the
- * first one only. This is technically incorrect, but should be acceptable due
- * to the method of processing Hints: no multiple values for a hint.
- *
- * @param query query to split
- * @return name-value pairs
- */
- private static Map splitQuery(String query) {
- Map map = new HashMap<>();
- int pos = 0;
- while (pos < query.length()) {
- if (query.charAt(pos) == '&') {
- // Skip consecutive ampersand separators.
- pos ++;
- continue;
- }
- int amp = query.indexOf('&', pos);
- int equ = query.indexOf('=', pos);
- if (amp < 0) {
- // This is the last element in the query, no more ampersand elements.
- String name;
- String text;
- if (equ < 0) {
- // No equal sign
- name = query.substring(pos);
- name = name.replace('+', ' '); // Preemptively decode +
- name = Uri.decode(name);
- text = "";
- } else {
- // Split name and text.
- name = query.substring(pos, equ);
- name = name.replace('+', ' '); // Preemptively decode +
- name = Uri.decode(name);
- text = query.substring(equ + 1);
- text = text.replace('+', ' '); // Preemptively decode +
- text = Uri.decode(text);
- }
- if (!map.containsKey(name)) {
- map.put(name, text);
- }
- break;
- }
- if (equ < 0 || equ > amp) {
- // No equal sign until the &: this is a simple parameter with no value.
- String name = query.substring(pos, amp);
- name = name.replace('+', ' '); // Preemptively decode +
- name = Uri.decode(name);
- if (!map.containsKey(name)) {
- map.put(name, "");
- }
- pos = amp + 1;
- continue;
- }
- String name = query.substring(pos, equ);
- name = name.replace('+', ' '); // Preemptively decode +
- name = Uri.decode(name);
- String text = query.substring(equ+1, amp);
- text = text.replace('+', ' '); // Preemptively decode +
- text = Uri.decode(text);
- if (!map.containsKey(name)) {
- map.put(name, text);
- }
- pos = amp + 1;
- }
- return map;
- }
-
- static Map parseDecodeHints(Uri inputUri) {
- String query = inputUri.getEncodedQuery();
- if (query == null || query.isEmpty()) {
- return null;
- }
-
- // Extract parameters
- Map parameters = splitQuery(query);
-
- Map hints = new EnumMap<>(DecodeHintType.class);
-
- for (DecodeHintType hintType: DecodeHintType.values()) {
-
- if (hintType == DecodeHintType.CHARACTER_SET ||
- hintType == DecodeHintType.NEED_RESULT_POINT_CALLBACK ||
- hintType == DecodeHintType.POSSIBLE_FORMATS) {
- continue; // This hint is specified in another way
- }
-
- String parameterName = hintType.name();
- String parameterText = parameters.get(parameterName);
- if (parameterText == null) {
- continue;
- }
- if (hintType.getValueType().equals(Object.class)) {
- // This is an unspecified type of hint content. Use the value as is.
- // TODO: Can we make a different assumption on this?
- hints.put(hintType, parameterText);
- continue;
- }
- if (hintType.getValueType().equals(Void.class)) {
- // Void hints are just flags: use the constant specified by DecodeHintType
- hints.put(hintType, Boolean.TRUE);
- continue;
- }
- if (hintType.getValueType().equals(String.class)) {
- // A string hint: use the decoded value.
- hints.put(hintType, parameterText);
- continue;
- }
- if (hintType.getValueType().equals(Boolean.class)) {
- // A boolean hint: a few values for false, everything else is true.
- // An empty parameter is simply a flag-style parameter, assuming true
- if (parameterText.isEmpty()) {
- hints.put(hintType, Boolean.TRUE);
- } else if ("0".equals(parameterText) ||
- "false".equalsIgnoreCase(parameterText) ||
- "no".equalsIgnoreCase(parameterText)) {
- hints.put(hintType, Boolean.FALSE);
- } else {
- hints.put(hintType, Boolean.TRUE);
- }
-
- continue;
- }
- if (hintType.getValueType().equals(int[].class)) {
- // An integer array. Used to specify valid lengths.
- // Strip a trailing comma as in Java style array initialisers.
- if (!parameterText.isEmpty() && parameterText.charAt(parameterText.length() - 1) == ',') {
- parameterText = parameterText.substring(0, parameterText.length() - 1);
- }
- String[] values = COMMA.split(parameterText);
- int[] array = new int[values.length];
- for (int i = 0; i < values.length; i++) {
- try {
- array[i] = Integer.parseInt(values[i]);
- } catch (NumberFormatException ignored) {
- Log.w(TAG, "Skipping array of integers hint " + hintType + " due to invalid numeric value: '" + values[i] + '\'');
- array = null;
- break;
- }
- }
- if (array != null) {
- hints.put(hintType, array);
- }
- continue;
- }
- Log.w(TAG, "Unsupported hint type '" + hintType + "' of type " + hintType.getValueType());
- }
-
- Log.i(TAG, "Hints from the URI: " + hints);
- return hints;
- }
-
- static Map parseDecodeHints(Intent intent) {
- Bundle extras = intent.getExtras();
- if (extras == null || extras.isEmpty()) {
- return null;
- }
- Map hints = new EnumMap<>(DecodeHintType.class);
-
- for (DecodeHintType hintType: DecodeHintType.values()) {
-
- if (hintType == DecodeHintType.CHARACTER_SET ||
- hintType == DecodeHintType.NEED_RESULT_POINT_CALLBACK ||
- hintType == DecodeHintType.POSSIBLE_FORMATS) {
- continue; // This hint is specified in another way
- }
-
- String hintName = hintType.name();
- if (extras.containsKey(hintName)) {
- if (hintType.getValueType().equals(Void.class)) {
- // Void hints are just flags: use the constant specified by the DecodeHintType
- hints.put(hintType, Boolean.TRUE);
- } else {
- Object hintData = extras.get(hintName);
- if (hintType.getValueType().isInstance(hintData)) {
- hints.put(hintType, hintData);
- } else {
- Log.w(TAG, "Ignoring hint " + hintType + " because it is not assignable from " + hintData);
- }
- }
- }
- }
-
- Log.i(TAG, "Hints from the Intent: " + hints);
- return hints;
- }
-
-}
diff --git a/app/src/main/java/com/google/zxing/client/android/DecodeThread.java b/app/src/main/java/com/google/zxing/client/android/DecodeThread.java
deleted file mode 100644
index fab4039..0000000
--- a/app/src/main/java/com/google/zxing/client/android/DecodeThread.java
+++ /dev/null
@@ -1,113 +0,0 @@
-/*
- * Copyright (C) 2008 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.client.android;
-
-import com.google.zxing.BarcodeFormat;
-import com.google.zxing.DecodeHintType;
-import com.google.zxing.ResultPointCallback;
-
-import android.content.SharedPreferences;
-import android.os.Handler;
-import android.os.Looper;
-import android.preference.PreferenceManager;
-import android.util.Log;
-
-import java.util.Collection;
-import java.util.EnumMap;
-import java.util.EnumSet;
-import java.util.Map;
-import java.util.concurrent.CountDownLatch;
-
-/**
- * This thread does all the heavy lifting of decoding the images.
- *
- * @author dswitkin@google.com (Daniel Switkin)
- */
-final class DecodeThread extends Thread {
-
- public static final String BARCODE_BITMAP = "barcode_bitmap";
- public static final String BARCODE_SCALED_FACTOR = "barcode_scaled_factor";
-
- private final CaptureActivity activity;
- private final Map hints;
- private Handler handler;
- private final CountDownLatch handlerInitLatch;
-
- DecodeThread(CaptureActivity activity,
- Collection decodeFormats,
- Map baseHints,
- String characterSet,
- ResultPointCallback resultPointCallback) {
-
- this.activity = activity;
- handlerInitLatch = new CountDownLatch(1);
-
- hints = new EnumMap<>(DecodeHintType.class);
- if (baseHints != null) {
- hints.putAll(baseHints);
- }
-
- // The prefs can't change while the thread is running, so pick them up once here.
- if (decodeFormats == null || decodeFormats.isEmpty()) {
- SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(activity);
- decodeFormats = EnumSet.noneOf(BarcodeFormat.class);
- if (prefs.getBoolean(PreferencesActivity.KEY_DECODE_1D_PRODUCT, true)) {
- decodeFormats.addAll(DecodeFormatManager.PRODUCT_FORMATS);
- }
- if (prefs.getBoolean(PreferencesActivity.KEY_DECODE_1D_INDUSTRIAL, true)) {
- decodeFormats.addAll(DecodeFormatManager.INDUSTRIAL_FORMATS);
- }
- if (prefs.getBoolean(PreferencesActivity.KEY_DECODE_QR, true)) {
- decodeFormats.addAll(DecodeFormatManager.QR_CODE_FORMATS);
- }
- if (prefs.getBoolean(PreferencesActivity.KEY_DECODE_DATA_MATRIX, true)) {
- decodeFormats.addAll(DecodeFormatManager.DATA_MATRIX_FORMATS);
- }
- if (prefs.getBoolean(PreferencesActivity.KEY_DECODE_AZTEC, false)) {
- decodeFormats.addAll(DecodeFormatManager.AZTEC_FORMATS);
- }
- if (prefs.getBoolean(PreferencesActivity.KEY_DECODE_PDF417, false)) {
- decodeFormats.addAll(DecodeFormatManager.PDF417_FORMATS);
- }
- }
- hints.put(DecodeHintType.POSSIBLE_FORMATS, decodeFormats);
-
- if (characterSet != null) {
- hints.put(DecodeHintType.CHARACTER_SET, characterSet);
- }
- hints.put(DecodeHintType.NEED_RESULT_POINT_CALLBACK, resultPointCallback);
- Log.i("DecodeThread", "Hints: " + hints);
- }
-
- Handler getHandler() {
- try {
- handlerInitLatch.await();
- } catch (InterruptedException ie) {
- // continue?
- }
- return handler;
- }
-
- @Override
- public void run() {
- Looper.prepare();
- handler = new DecodeHandler(activity, hints);
- handlerInitLatch.countDown();
- Looper.loop();
- }
-
-}
diff --git a/app/src/main/java/com/google/zxing/client/android/FinishListener.java b/app/src/main/java/com/google/zxing/client/android/FinishListener.java
deleted file mode 100644
index 5d59886..0000000
--- a/app/src/main/java/com/google/zxing/client/android/FinishListener.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * Copyright (C) 2010 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.client.android;
-
-import android.app.Activity;
-import android.content.DialogInterface;
-
-/**
- * Simple listener used to exit the app in a few cases.
- *
- * @author Sean Owen
- */
-public final class FinishListener implements DialogInterface.OnClickListener, DialogInterface.OnCancelListener {
-
- private final Activity activityToFinish;
-
- public FinishListener(Activity activityToFinish) {
- this.activityToFinish = activityToFinish;
- }
-
- @Override
- public void onCancel(DialogInterface dialogInterface) {
- run();
- }
-
- @Override
- public void onClick(DialogInterface dialogInterface, int i) {
- run();
- }
-
- private void run() {
- activityToFinish.finish();
- }
-
-}
diff --git a/app/src/main/java/com/google/zxing/client/android/HelpActivity.java b/app/src/main/java/com/google/zxing/client/android/HelpActivity.java
deleted file mode 100644
index 1f964bd..0000000
--- a/app/src/main/java/com/google/zxing/client/android/HelpActivity.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * Copyright 2008 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.client.android;
-
-import android.app.Activity;
-import android.os.Bundle;
-import android.view.KeyEvent;
-import android.webkit.WebView;
-
-import net.foucry.pilldroid.R;
-
-/**
- * An HTML-based help screen.
- *
- * @author dswitkin@google.com (Daniel Switkin)
- */
-public final class HelpActivity extends Activity {
-
- private static final String BASE_URL =
- "file:///android_asset/html-" + LocaleManager.getTranslatedAssetLanguage() + '/';
-
- private WebView webView;
-
- @Override
- protected void onCreate(Bundle icicle) {
- super.onCreate(icicle);
- setContentView(R.layout.help);
-
- webView = (WebView) findViewById(R.id.help_contents);
-
- if (icicle == null) {
- webView.loadUrl(BASE_URL + "index.html");
- } else {
- webView.restoreState(icicle);
- }
- }
-
- @Override
- public boolean onKeyDown(int keyCode, KeyEvent event) {
- if (keyCode == KeyEvent.KEYCODE_BACK && webView.canGoBack()) {
- webView.goBack();
- return true;
- }
- return super.onKeyDown(keyCode, event);
- }
-
- @Override
- protected void onSaveInstanceState(Bundle icicle) {
- super.onSaveInstanceState(icicle);
- webView.saveState(icicle);
- }
-}
diff --git a/app/src/main/java/com/google/zxing/client/android/HttpHelper.java b/app/src/main/java/com/google/zxing/client/android/HttpHelper.java
deleted file mode 100644
index 5a1543d..0000000
--- a/app/src/main/java/com/google/zxing/client/android/HttpHelper.java
+++ /dev/null
@@ -1,228 +0,0 @@
-/*
- * Copyright 2011 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.client.android;
-
-import android.util.Log;
-
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.io.Reader;
-import java.net.HttpURLConnection;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.net.URL;
-import java.net.URLConnection;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.HashSet;
-
-/**
- * Utility methods for retrieving content over HTTP using the more-supported {@code java.net} classes
- * in Android.
- */
-public final class HttpHelper {
-
- private static final String TAG = HttpHelper.class.getSimpleName();
-
- private static final Collection REDIRECTOR_DOMAINS = new HashSet<>(Arrays.asList(
- "amzn.to", "bit.ly", "bitly.com", "fb.me", "goo.gl", "is.gd", "j.mp", "lnkd.in", "ow.ly",
- "R.BEETAGG.COM", "r.beetagg.com", "SCN.BY", "su.pr", "t.co", "tinyurl.com", "tr.im"
- ));
-
- private HttpHelper() {
- }
-
- public enum ContentType {
- /** HTML-like content type, including HTML, XHTML, etc. */
- HTML,
- /** JSON content */
- JSON,
- /** XML */
- XML,
- /** Plain text content */
- TEXT,
- }
-
- /**
- * Downloads the entire resource instead of part.
- *
- * @param uri URI to retrieve
- * @param type expected text-like MIME type of that content
- * @return content as a {@code String}
- * @throws IOException if the content can't be retrieved because of a bad URI, network problem, etc.
- * @see #downloadViaHttp(String, HttpHelper.ContentType, int)
- */
- public static CharSequence downloadViaHttp(String uri, ContentType type) throws IOException {
- return downloadViaHttp(uri, type, Integer.MAX_VALUE);
- }
-
- /**
- * @param uri URI to retrieve
- * @param type expected text-like MIME type of that content
- * @param maxChars approximate maximum characters to read from the source
- * @return content as a {@code String}
- * @throws IOException if the content can't be retrieved because of a bad URI, network problem, etc.
- */
- public static CharSequence downloadViaHttp(String uri, ContentType type, int maxChars) throws IOException {
- String contentTypes;
- switch (type) {
- case HTML:
- contentTypes = "application/xhtml+xml,text/html,text/*,*/*";
- break;
- case JSON:
- contentTypes = "application/json,text/*,*/*";
- break;
- case XML:
- contentTypes = "application/xml,text/*,*/*";
- break;
- case TEXT:
- default:
- contentTypes = "text/*,*/*";
- }
- return downloadViaHttp(uri, contentTypes, maxChars);
- }
-
- private static CharSequence downloadViaHttp(String uri, String contentTypes, int maxChars) throws IOException {
- int redirects = 0;
- while (redirects < 5) {
- URL url = new URL(uri);
- HttpURLConnection connection = safelyOpenConnection(url);
- connection.setInstanceFollowRedirects(true); // Won't work HTTP -> HTTPS or vice versa
- connection.setRequestProperty("Accept", contentTypes);
- connection.setRequestProperty("Accept-Charset", "utf-8,*");
- connection.setRequestProperty("User-Agent", "ZXing (Android)");
- try {
- int responseCode = safelyConnect(connection);
- switch (responseCode) {
- case HttpURLConnection.HTTP_OK:
- return consume(connection, maxChars);
- case HttpURLConnection.HTTP_MOVED_TEMP:
- String location = connection.getHeaderField("Location");
- if (location != null) {
- uri = location;
- redirects++;
- continue;
- }
- throw new IOException("No Location");
- default:
- throw new IOException("Bad HTTP response: " + responseCode);
- }
- } finally {
- connection.disconnect();
- }
- }
- throw new IOException("Too many redirects");
- }
-
- private static String getEncoding(URLConnection connection) {
- String contentTypeHeader = connection.getHeaderField("Content-Type");
- if (contentTypeHeader != null) {
- int charsetStart = contentTypeHeader.indexOf("charset=");
- if (charsetStart >= 0) {
- return contentTypeHeader.substring(charsetStart + "charset=".length());
- }
- }
- return "UTF-8";
- }
-
- private static CharSequence consume(URLConnection connection, int maxChars) throws IOException {
- String encoding = getEncoding(connection);
- StringBuilder out = new StringBuilder();
- Reader in = null;
- try {
- in = new InputStreamReader(connection.getInputStream(), encoding);
- char[] buffer = new char[1024];
- int charsRead;
- while (out.length() < maxChars && (charsRead = in.read(buffer)) > 0) {
- out.append(buffer, 0, charsRead);
- }
- } finally {
- if (in != null) {
- try {
- in.close();
- } catch (IOException | NullPointerException ioe) {
- // continue
- }
- }
- }
- return out;
- }
-
- public static URI unredirect(URI uri) throws IOException {
- if (!REDIRECTOR_DOMAINS.contains(uri.getHost())) {
- return uri;
- }
- URL url = uri.toURL();
- HttpURLConnection connection = safelyOpenConnection(url);
- connection.setInstanceFollowRedirects(false);
- connection.setDoInput(false);
- connection.setRequestMethod("HEAD");
- connection.setRequestProperty("User-Agent", "ZXing (Android)");
- try {
- int responseCode = safelyConnect(connection);
- switch (responseCode) {
- case HttpURLConnection.HTTP_MULT_CHOICE:
- case HttpURLConnection.HTTP_MOVED_PERM:
- case HttpURLConnection.HTTP_MOVED_TEMP:
- case HttpURLConnection.HTTP_SEE_OTHER:
- case 307: // No constant for 307 Temporary Redirect ?
- String location = connection.getHeaderField("Location");
- if (location != null) {
- try {
- return new URI(location);
- } catch (URISyntaxException e) {
- // nevermind
- }
- }
- }
- return uri;
- } finally {
- connection.disconnect();
- }
- }
-
- private static HttpURLConnection safelyOpenConnection(URL url) throws IOException {
- URLConnection conn;
- try {
- conn = url.openConnection();
- } catch (NullPointerException npe) {
- // Another strange bug in Android?
- Log.w(TAG, "Bad URI? " + url);
- throw new IOException(npe);
- }
- if (!(conn instanceof HttpURLConnection)) {
- throw new IOException();
- }
- return (HttpURLConnection) conn;
- }
-
- private static int safelyConnect(HttpURLConnection connection) throws IOException {
- try {
- connection.connect();
- } catch (NullPointerException | IllegalArgumentException | IndexOutOfBoundsException | SecurityException e) {
- // this is an Android bug: http://code.google.com/p/android/issues/detail?id=16895
- throw new IOException(e);
- }
- try {
- return connection.getResponseCode();
- } catch (NullPointerException | StringIndexOutOfBoundsException | IllegalArgumentException e) {
- // this is maybe this Android bug: http://code.google.com/p/android/issues/detail?id=15554
- throw new IOException(e);
- }
- }
-
-}
diff --git a/app/src/main/java/com/google/zxing/client/android/InactivityTimer.java b/app/src/main/java/com/google/zxing/client/android/InactivityTimer.java
deleted file mode 100644
index 5e33d90..0000000
--- a/app/src/main/java/com/google/zxing/client/android/InactivityTimer.java
+++ /dev/null
@@ -1,116 +0,0 @@
-/*
- * Copyright (C) 2010 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.client.android;
-
-import android.app.Activity;
-import android.content.BroadcastReceiver;
-import android.content.Context;
-import android.content.Intent;
-import android.content.IntentFilter;
-import android.os.AsyncTask;
-import android.os.BatteryManager;
-import android.util.Log;
-
-/**
- * Finishes an activity after a period of inactivity if the device is on battery power.
- */
-final class InactivityTimer {
-
- private static final String TAG = InactivityTimer.class.getSimpleName();
-
- private static final long INACTIVITY_DELAY_MS = 5 * 60 * 1000L;
-
- private final Activity activity;
- private final BroadcastReceiver powerStatusReceiver;
- private boolean registered;
- private AsyncTask