public final class AndroidHttpClient implements HttpClient {
// Gzip of data shorter than this probably won't be worthwhile
- public static final long DEFAULT_SYNC_MIN_GZIP_BYTES = 256;
+ private static final long DEFAULT_SYNC_MIN_GZIP_BYTES = 256;
private static final String TAG = "AndroidHttpClient";
* Retrieves the minimum size for compressing data.
* Shorter data will not be compressed.
*/
- public static long getMinGzipSize() {
+ private static long getMinGzipSize() {
return DEFAULT_SYNC_MIN_GZIP_BYTES;
}
/**
* This class handles all the messaging which comprises the state machine for capture.
*/
-public class CaptureActivityHandler extends Handler {
+public final class CaptureActivityHandler extends Handler {
private final CaptureActivity mActivity;
private final DecodeThread mDecodeThread;
public static final String BARCODE_BITMAP = "barcode_bitmap";
public Handler mHandler;
- private CaptureActivity mActivity;
- private MultiFormatReader mMultiFormatReader;
+ private final CaptureActivity mActivity;
+ private final MultiFormatReader mMultiFormatReader;
DecodeThread(CaptureActivity activity, String mode) {
mActivity = activity;
* This class encodes data from an Intent into a QR code, and then displays it full screen so that
* another person can scan it with their device.
*/
-public class EncodeActivity extends Activity {
+public final class EncodeActivity extends Activity {
private QRCodeEncoder mQRCodeEncoder;
private ProgressDialog mProgressDialog;
--- /dev/null
+/*
+ * 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 java.util.Locale;
+import java.util.Map;
+import java.util.HashMap;
+
+/**
+ * Handles any locale-specific logic for the client.
+ */
+public final class LocaleManager {
+
+ private static final String DEFAULT_TLD = "com";
+ private static final Map<Locale,String> GOOGLE_COUNTRY_TLD;
+ static {
+ GOOGLE_COUNTRY_TLD = new HashMap<Locale,String>(13);
+ GOOGLE_COUNTRY_TLD.put(Locale.CANADA, "ca");
+ GOOGLE_COUNTRY_TLD.put(Locale.CHINA, "cn");
+ GOOGLE_COUNTRY_TLD.put(Locale.FRANCE, "fr");
+ GOOGLE_COUNTRY_TLD.put(Locale.GERMANY, "de");
+ GOOGLE_COUNTRY_TLD.put(Locale.ITALY, "it");
+ GOOGLE_COUNTRY_TLD.put(Locale.JAPAN, "co.jp");
+ GOOGLE_COUNTRY_TLD.put(Locale.KOREA, "co.kr");
+ GOOGLE_COUNTRY_TLD.put(Locale.TAIWAN, "de");
+ GOOGLE_COUNTRY_TLD.put(Locale.UK, "co.uk");
+ }
+
+ private LocaleManager() {}
+
+ /**
+ * @return country-specific TLD suffix appropriate for the current default locale
+ * (e.g. "co.uk" for the United Kingdom)
+ */
+ public static String getCountryTLD() {
+ Locale locale = Locale.getDefault();
+ if (locale == null) {
+ return DEFAULT_TLD;
+ }
+ String tld = GOOGLE_COUNTRY_TLD.get(locale);
+ if (tld == null) {
+ return DEFAULT_TLD;
+ }
+ return tld;
+ }
+
+}
import android.preference.CheckBoxPreference;
import android.preference.PreferenceScreen;
-public class PreferencesActivity extends android.preference.PreferenceActivity
+public final class PreferencesActivity extends android.preference.PreferenceActivity
implements OnSharedPreferenceChangeListener {
static final String KEY_DECODE_1D = "preferences_decode_1D";
import org.apache.http.client.methods.HttpGet;
import java.net.URI;
+import java.net.URLEncoder;
-public class QRCodeEncoder {
+public final class QRCodeEncoder {
private static final String TAG = "QRCodeEncoder";
- private static final String CHART_SERVER_URL = "//chart.apis.google.com/chart?cht=qr&chs=";
+ private static final String CHART_SERVER_URL =
+ "//chart.apis.google." + LocaleManager.getCountryTLD() + "/chart?cht=qr&chs=";
- private Activity mActivity;
+ private final Activity mActivity;
private String mContents;
private String mDisplayContents;
private String mTitle;
- private NetworkThread mNetworkThread;
private String mUserAgent;
public QRCodeEncoder(Activity activity, Intent intent) {
// Once the core ZXing library supports encoding, we'll be able to generate the bitmap
// synchronously. For now, it's a network request, so it's handled on a thread.
public void requestBarcode(Handler handler, int pixelResolution) {
- mNetworkThread = new NetworkThread(mContents, handler, pixelResolution);
+ Thread mNetworkThread = new NetworkThread(mContents, handler, pixelResolution);
mNetworkThread.start();
}
private class NetworkThread extends Thread {
- private String mContents;
- private Handler mHandler;
- private int mPixelResolution;
+ private final String mContents;
+ private final Handler mHandler;
+ private final int mPixelResolution;
public NetworkThread(String contents, Handler handler, int pixelResolution) {
mContents = contents;
}
public void run() {
- String url = CHART_SERVER_URL + mPixelResolution + "x" + mPixelResolution + "&chl=" +
- mContents;
AndroidHttpClient client = null;
try {
+ String url = CHART_SERVER_URL + mPixelResolution + "x" + mPixelResolution + "&chl=" +
+ URLEncoder.encode(mContents, "UTF8");
URI uri = new URI("http", url, null);
HttpGet get = new HttpGet(uri);
client = AndroidHttpClient.newInstance(mUserAgent);
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.net.URI;
+import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.List;
-public class SearchBookContentsActivity extends Activity {
+public final class SearchBookContentsActivity extends Activity {
private static final String TAG = "SearchBookContents";
// These return a JSON result which describes if and where the query was found. This API may
// break or disappear at any time in the future.
- private static final String BOOK_SEARCH_URL = "//www.google.com/books?vid=isbn";
+ private static final String BOOK_SEARCH_URL = "//www.google." + LocaleManager.getCountryTLD() + "/books?vid=isbn";
private static final String BOOK_SEARCH_COMMAND = "&jscmd=SearchWithinVolume2&q=";
private NetworkThread mNetworkThread;
super.onConfigurationChanged(config);
}
- public Handler mHandler = new Handler() {
+ public final Handler mHandler = new Handler() {
public void handleMessage(Message message) {
switch (message.what) {
case R.id.search_book_contents_succeeded:
mQueryButton.setEnabled(true);
}
- private Button.OnClickListener mButtonListener = new Button.OnClickListener() {
+ private final Button.OnClickListener mButtonListener = new Button.OnClickListener() {
public void onClick(View view) {
launchSearch();
}
};
- private View.OnKeyListener mKeyListener = new View.OnKeyListener() {
+ private final View.OnKeyListener mKeyListener = new View.OnKeyListener() {
public boolean onKey(View view, int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_ENTER) {
launchSearch();
if (mNetworkThread == null) {
String query = mQueryTextView.getText().toString();
if (query != null && query.length() > 0) {
- mNetworkThread = new NetworkThread(mISBN, query, mHandler);
+ mNetworkThread = new NetworkThread(mISBN, query, mHandler, mUserAgent);
mNetworkThread.start();
mHeaderView.setText(R.string.msg_sbc_searching_book);
mResultListView.setAdapter(null);
}
}
- private class NetworkThread extends Thread {
+ private static class NetworkThread extends Thread {
- private String mISBN;
- private String mQuery;
- private Handler mHandler;
+ private final String mISBN;
+ private final String mQuery;
+ private final Handler mHandler;
+ private String mUserAgent;
- public NetworkThread(String isbn, String query, Handler handler) {
+ public NetworkThread(String isbn, String query, Handler handler, String userAgent) {
mISBN = isbn;
mQuery = query;
mHandler = handler;
+ mUserAgent = userAgent;
}
public void run() {
- String url = BOOK_SEARCH_URL + mISBN + BOOK_SEARCH_COMMAND + mQuery;
AndroidHttpClient client = null;
try {
+ String url = BOOK_SEARCH_URL + mISBN + BOOK_SEARCH_COMMAND + URLEncoder.encode(mQuery, "UTF8");
URI uri = new URI("http", url, null);
HttpGet get = new HttpGet(uri);
get.setHeader("cookie", getCookie("http:" + url));
import java.util.List;
-public class SearchBookContentsAdapter extends ArrayAdapter<SearchBookContentsResult> {
+public final class SearchBookContentsAdapter extends ArrayAdapter<SearchBookContentsResult> {
public SearchBookContentsAdapter(Context context, List<SearchBookContentsResult> items) {
super(context, R.layout.search_book_contents_list_item, 0, items);
import android.widget.LinearLayout;
import android.widget.TextView;
-public class SearchBookContentsListItem extends LinearLayout {
+public final class SearchBookContentsListItem extends LinearLayout {
private TextView mPageNumberView;
private TextView mSnippetView;
package com.google.zxing.client.android;
-public class SearchBookContentsResult {
+public final class SearchBookContentsResult {
static private String sQuery;
- private String mPageNumber;
- private String mSnippet;
- private boolean mValidSnippet;
+ private final String mPageNumber;
+ private final String mSnippet;
+ private final boolean mValidSnippet;
public SearchBookContentsResult(String pageNumber, String snippet, boolean validSnippet) {
mPageNumber = pageNumber;
* This view is overlaid on top of the camera preview. It adds the viewfinder rectangle and partial
* transparency outside it, as well as the laser scanner animation and result points.
*/
-public class ViewfinderView extends View {
+public final class ViewfinderView extends View {
private static final int[] SCANNER_ALPHA = {0, 64, 128, 192, 255, 192, 128, 64};
private static final int ANIMATION_DELAY = 100;
- private Paint mPaint;
- private Rect mBox;
+ private final Paint mPaint;
+ private final Rect mBox;
private Bitmap mResultBitmap;
- private int mMaskColor;
- private int mResultColor;
- private int mFrameColor;
- private int mLaserColor;
+ private final int mMaskColor;
+ private final int mResultColor;
+ private final int mFrameColor;
+ private final int mLaserColor;
private int mScannerAlpha;
// This constructor is used when the class is built from an XML resource.
public class AddressBookResultHandler extends ResultHandler {
- private boolean mFields[];
+ private final boolean[] mFields;
private int mButtonCount;
// This takes all the work out of figuring out which buttons/actions should be in which
*/
public final class ResultButtonListener implements Button.OnClickListener {
- ResultHandler mResultHandler;
- int mIndex;
+ final ResultHandler mResultHandler;
+ final int mIndex;
public ResultButtonListener(ResultHandler resultHandler, int index) {
mResultHandler = resultHandler;
import com.google.zxing.client.android.Intents;
import com.google.zxing.client.android.R;
import com.google.zxing.client.android.SearchBookContentsActivity;
+import com.google.zxing.client.android.LocaleManager;
import com.google.zxing.client.result.ParsedResult;
import com.google.zxing.client.result.ParsedResultType;
public static final int MAX_BUTTON_COUNT = 4;
- protected ParsedResult mResult;
- private Activity mActivity;
+ protected final ParsedResult mResult;
+ private final Activity mActivity;
public ResultHandler(Activity activity, ParsedResult result) {
mResult = result;
public void getDirections(float latitude, float longitude) {
launchIntent(new Intent(Intent.ACTION_VIEW,
- Uri.parse("http://maps.google.com/maps?f=d&daddr=" + latitude + "," + longitude)));
+ Uri.parse("http://maps.google." + LocaleManager.getCountryTLD() + "/maps?f=d&daddr=" + latitude + "," + longitude)));
}
public void openProductSearch(String upc) {
- Uri uri = Uri.parse("http://www.google.com/products?q=" + upc);
+ Uri uri = Uri.parse("http://www.google." + LocaleManager.getCountryTLD() + "/products?q=" + upc);
launchIntent(new Intent(Intent.ACTION_VIEW, uri));
}
public void openBookSearch(String isbn) {
- Uri uri = Uri.parse("http://books.google.com/books?vid=isbn" + isbn);
+ Uri uri = Uri.parse("http://books.google." + LocaleManager.getCountryTLD() + "/books?vid=isbn" + isbn);
launchIntent(new Intent(Intent.ACTION_VIEW, uri));
}