diff --git a/plugin.xml b/plugin.xml index d3b5ebb3..b286894e 100644 --- a/plugin.xml +++ b/plugin.xml @@ -1,5 +1,4 @@ - - @@ -94,35 +93,34 @@ search: (src/android/LibraryProject/(.+?)/[^/]+)$ replace: --> - - + + + + + + + + - - - - - - - - - - - - - + - - - - + + + + + + + + + @@ -152,135 +150,129 @@ + - - - Barcode Scanner - Applications - Bookmarks - Add to calendar - Add contact - Back - Book Search - Cancel - Clipboard empty - Custom search - Dial number - Done - Send email - Get directions - Google Shopper - Send MMS - OK - Open browser - Product Search - Browse book - Search contents - Application - Bookmark - Share via email - Share via SMS - Clipboard - Contact - Show map - Send SMS - Web search - Connect to Network - Contact info - Email address - Geographic coordinates - Phone number - SMS address - Plain text - Clear history - Barcode Scanner history - Send history - History - About - Help - History - Settings - Share - The official Android app of the open source ZXing barcode project. - This device has known bugs that cause barcode scanning problems. For more information, visit http://code.google.com/p/zxing/wiki/FrequentlyAskedQuestions - Bulk mode: barcode scanned and saved - Sorry, the Android camera encountered a problem. You may need to restart the device. - Contents - Format - Metadata - Hi - Place a barcode inside the viewfinder rectangle to scan it. - Time - Type - Could not generate the requested barcode. - Could not encode a barcode from the data provided. - Google Shopper is not installed - Google Shopper combines barcode scanning with online and local prices, reviews and more without opening the browser. Would you like to try it? - Sorry, the requested application could not be launched. The barcode contents may be invalid. - Loading list of applications\u2026 - You are leaving this application. The search results you will see are not related to this application. - Redirect - Sorry, this book is not searchable. - Sorry, the search encountered a problem. - No page returned - Page - Searching book\u2026 - Snippet not available - Unknown page - You can share data by displaying a barcode on your screen and scanning it with another phone. - Here are the contents of a barcode I scanned - Or type some text and press Enter - Sorry, the SD card is not accessible. - When a barcode is found\u2026 - Scan and save many barcodes continuously - Bulk scan mode - Copy to clipboard - Use %s as a placeholder for the product ID, and %f for format - Custom search URL - 1D barcodes - Data Matrix - QR Codes - Improves scanning in low light on some phones, but may cause glare. Does not work on all phones. - Use front light - General settings - Settings - Beep - Store multiple scans of the same barcode in History - Remember duplicates - Enable on devices with a front camera only - Reversed camera image - Result settings - When scanning for barcodes, decode\u2026 - Try to retrieve more information about the barcode contents - Retrieve more info - Vibrate - Found contact info - Found calendar event - Found email address - Found geographic coordinates - Found book - Found product - Found SMS address - Found phone number - Found plain text - Found URL - Found WLAN Configuration - Google Book Search - Share via barcode - Barcode Scanner v - WLAN Connection - Changing Network - Connected - Creating Network - Modifying Network - Network name missing - Network type incorrect - Network connection failed - Network Name - Type - http://code.google.com/p/zxing + Applications + Bookmarks + Add to calendar + Add contact + Back + Book Search + Cancel + Custom search + Dial number + Done + Send email + Get directions + Shopper + Send MMS + OK + Open browser + Product Search + Search contents + Application + Bookmark + Share via email + Share via SMS + Clipboard + Contact + Show map + Send SMS + Web search + Connect to Network + Contact info + Email address + Geographic coordinates + Phone number + SMS address + Plain text + Clear history + Clear + Barcode Scanner history + Empty + No barcode scans have been recorded + Send history + History + Use MECARD + Use vCard + Help + History + Share + Bulk mode: barcode scanned and saved + Sorry, the Android camera encountered a problem. You may need to restart the device. + Format + Metadata + Hi + Place a barcode inside the viewfinder rectangle to scan it. + Time + Type + Could not encode a barcode from the data provided. + Google Books + Google Product Search + Google Shopper is not installed + Google Shopper combines barcode scanning with online and local prices, reviews and more without opening the browser. Would you like to try it? + Sorry, the requested application could not be launched. The barcode contents may be invalid. + Redirect + Sorry, this book is not searchable. + Sorry, the search encountered a problem. + No page returned + Page + Results + Searching book\u2026 + Snippet not available + Unknown page + You can share data by displaying a barcode on your screen and scanning it with another phone. + Here are the contents of a barcode I scanned + Or type some text and press Enter + Are you sure? + Sorry, the SD card is not accessible. + When a barcode is found\u2026 + Use auto focus + Scan and save many barcodes continuously + Bulk scan mode + Copy to clipboard + Substitutions: %s = contents, %f = format, %t = type + Custom search URL + 1D barcodes + Data Matrix + QR Codes + Device Bug Workarounds + Use only standard focus mode + No continuous focus + No exposure + Improves scanning in low light on some phones, but may cause glare. Does not work on all phones. + Use front light + General settings + Settings + Beep + Store multiple scans of the same barcode in History + Remember duplicates + Result settings + When scanning for barcodes, decode\u2026 + Search country + Try Barcode Scanner+ + Enhanced with new features and interface + Try to retrieve more information about the barcode contents + Retrieve more info + Vibrate + Found contact info + Found calendar event + Found email address + Found geographic coordinates + Found book + Found product + Found SMS address + Found phone number + Found plain text + Found URL + Found WLAN Configuration + Google Book Search + Share via barcode + Requesting connection to network\u2026 + Network Name + Type - --> diff --git a/plugin.xml.generate.php b/plugin.xml.generate.php new file mode 100644 index 00000000..509267fd --- /dev/null +++ b/plugin.xml.generate.php @@ -0,0 +1,216 @@ +basePath. + * @param string $parent Parent element from which to get children. + * @param array $options + *
  • ident - ident chanracters. + *
  • ignorePattern - pattern that will be matched to XML. + * @return string + */ + public function getXml($xmlFilePath, $parent, $options=array()) + { + if (!isset($options['indent'])) + { + $options['indent'] = ""; + } + + $contents = ""; + $filePath = $this->basePath . $xmlFilePath; + if (!file_exists($filePath)) + { + $this->perror("File $filePath does not exist"); + return $contents; + } + + $xml = file_get_contents($this->basePath . $xmlFilePath); + $document = new SimpleXMLElement($xml); + $els = $document->xpath($parent); + if (!empty($els)) + { + $rootNode = $els[0]; + foreach ($rootNode->children() as $child) + { + $childContent = $child->asXML(); + if (isset($options['ignorePattern']) && preg_match($options['ignorePattern'], $childContent)) + { + $this->perror("\nignored $childContent"); + continue; + } + $contents .= "\n" . $options['indent'] . $childContent; + } + $contents = ltrim ($contents) . "\n"; + return $contents; + } + else + { + $this->perror("Path $parent not found in $xmlFilePath"); + return $contents; + } + } + + /** + * Generate source-file tags to copy all resources from given dir. + * + * @param type $dir Dir path relative to $this->basePath. + * @param array $options + *
  • ident - ident chanracters. + */ + public function sourceFiles($dir, $options=array()) + { + //ob_end_clean(); + + if (!isset($options['indent'])) + { + $options['indent'] = ""; + } + $path = $this->basePath . $dir; + + $it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path)); + while($it->valid()) + { + if (!$it->isDot()) + { + $filename = strtr($it->key(), '\\', '/'); + if (isset($options['ignorePattern']) && preg_match($options['ignorePattern'], $filename)) + { + $this->perror("\nignored $filename"); + $it->next(); + continue; + } + + $targetDir = preg_replace('#.+LibraryProject/(.+?)/[^/]+$#', '$1', $filename); + echo "\n{$options['indent']}"; + } + $it->next(); + } + + echo "\n"; + //exit; + } + } + + // init + $pluginHelper = new PluginHelper(); + + ob_start(); + echo ''; +?> + + + BarcodeScanner + + Scans Barcodes. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + sourceFiles("res", array('indent'=>"\t\t", 'ignorePattern' => '#values/strings.xml#')); + ?> + + + + getXml('res/values/strings.xml', "/resources", array('ignorePattern' => '/name="(app_name|menu_settings)"/', 'indent' => "\t\t\t"))?> + + + + \ No newline at end of file diff --git a/src/android/LibraryProject/.gitignore b/src/android/LibraryProject/.gitignore new file mode 100644 index 00000000..19ed7289 --- /dev/null +++ b/src/android/LibraryProject/.gitignore @@ -0,0 +1 @@ +/libs diff --git a/src/android/LibraryProject/src/com/google/zxing/FakeR.java b/src/android/LibraryProject/src/com/google/zxing/FakeR.java new file mode 100644 index 00000000..b3508683 --- /dev/null +++ b/src/android/LibraryProject/src/com/google/zxing/FakeR.java @@ -0,0 +1,35 @@ +package com.google.zxing; + +import android.app.Activity; +import android.content.Context; + +/** + * R replacement for PhoneGap Build. + * + * ([^.\w])R\.(\w+)\.(\w+) + * $1fakeR("$2", "$3") + * + * @author Maciej Nux Jaros + */ +public class FakeR { + private Context context; + private String packageName; + + public FakeR(Activity activity) { + context = activity.getApplicationContext(); + packageName = context.getPackageName(); + } + + public FakeR(Context context) { + this.context = context; + packageName = context.getPackageName(); + } + + public int getId(String group, String key) { + return context.getResources().getIdentifier(key, group, packageName); + } + + public static int getId(Context context, String group, String key) { + return context.getResources().getIdentifier(key, group, context.getPackageName()); + } +} diff --git a/src/android/LibraryProject/src/com/google/zxing/client/android/BeepManager.java b/src/android/LibraryProject/src/com/google/zxing/client/android/BeepManager.java index d6ae0948..52cd8201 100644 --- a/src/android/LibraryProject/src/com/google/zxing/client/android/BeepManager.java +++ b/src/android/LibraryProject/src/com/google/zxing/client/android/BeepManager.java @@ -25,6 +25,7 @@ import android.os.Vibrator; import android.preference.PreferenceManager; import android.util.Log; +import com.google.zxing.FakeR; import java.io.IOException; @@ -43,7 +44,9 @@ final class BeepManager { private boolean playBeep; private boolean vibrate; + private static FakeR fakeR; BeepManager(Activity activity) { + fakeR = new FakeR(activity); this.activity = activity; this.mediaPlayer = null; updatePrefs(); @@ -94,7 +97,7 @@ public void onCompletion(MediaPlayer player) { } }); - AssetFileDescriptor file = activity.getResources().openRawResourceFd(R.raw.beep); + AssetFileDescriptor file = activity.getResources().openRawResourceFd(fakeR.getId("raw", "beep")); try { mediaPlayer.setDataSource(file.getFileDescriptor(), file.getStartOffset(), file.getLength()); file.close(); diff --git a/src/android/LibraryProject/src/com/google/zxing/client/android/CaptureActivity.java b/src/android/LibraryProject/src/com/google/zxing/client/android/CaptureActivity.java index 624bfb4b..30d24474 100755 --- a/src/android/LibraryProject/src/com/google/zxing/client/android/CaptureActivity.java +++ b/src/android/LibraryProject/src/com/google/zxing/client/android/CaptureActivity.java @@ -61,6 +61,7 @@ import android.widget.ImageView; import android.widget.TextView; import android.widget.Toast; +import com.google.zxing.FakeR; import java.io.IOException; import java.io.UnsupportedEncodingException; @@ -81,6 +82,7 @@ * @author Sean Owen */ public final class CaptureActivity extends Activity implements SurfaceHolder.Callback { + private static FakeR fakeR; private static final String TAG = CaptureActivity.class.getSimpleName(); @@ -138,9 +140,11 @@ CameraManager getCameraManager() { public void onCreate(Bundle icicle) { super.onCreate(icicle); + fakeR = new FakeR(this); + Window window = getWindow(); window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); - setContentView(R.layout.capture); + setContentView(fakeR.getId("layout", "capture")); hasSurface = false; historyManager = new HistoryManager(this); @@ -148,9 +152,9 @@ public void onCreate(Bundle icicle) { inactivityTimer = new InactivityTimer(this); beepManager = new BeepManager(this); - PreferenceManager.setDefaultValues(this, R.xml.preferences, false); + PreferenceManager.setDefaultValues(this, fakeR.getId("xml", "preferences"), false); - showHelpOnFirstLaunch(); + //showHelpOnFirstLaunch(); } @Override @@ -163,18 +167,18 @@ protected void onResume() { // off screen. cameraManager = new CameraManager(getApplication()); - viewfinderView = (ViewfinderView) findViewById(R.id.viewfinder_view); + viewfinderView = (ViewfinderView) findViewById(fakeR.getId("id", "viewfinder_view")); viewfinderView.setCameraManager(cameraManager); - resultView = findViewById(R.id.result_view); - statusView = (TextView) findViewById(R.id.status_view); + resultView = findViewById(fakeR.getId("id", "result_view")); + statusView = (TextView) findViewById(fakeR.getId("id", "status_view")); handler = null; lastResult = null; resetStatusView(); - SurfaceView surfaceView = (SurfaceView) findViewById(R.id.preview_view); + SurfaceView surfaceView = (SurfaceView) findViewById(fakeR.getId("id", "preview_view")); SurfaceHolder surfaceHolder = surfaceView.getHolder(); if (hasSurface) { // The activity was paused but not stopped, so the surface still exists. Therefore @@ -273,7 +277,7 @@ protected void onPause() { inactivityTimer.onPause(); cameraManager.closeDriver(); if (!hasSurface) { - SurfaceView surfaceView = (SurfaceView) findViewById(R.id.preview_view); + SurfaceView surfaceView = (SurfaceView) findViewById(fakeR.getId("id", "preview_view")); SurfaceHolder surfaceHolder = surfaceView.getHolder(); surfaceHolder.removeCallback(this); } @@ -318,7 +322,7 @@ public boolean onKeyDown(int keyCode, KeyEvent event) { @Override public boolean onCreateOptionsMenu(Menu menu) { MenuInflater menuInflater = getMenuInflater(); - menuInflater.inflate(R.menu.capture, menu); + menuInflater.inflate(fakeR.getId("menu", "capture"), menu); return super.onCreateOptionsMenu(menu); } @@ -327,16 +331,16 @@ public boolean onOptionsItemSelected(MenuItem item) { Intent intent = new Intent(Intent.ACTION_VIEW); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); int itemId = item.getItemId(); - if (itemId == R.id.menu_share) { + if (itemId == fakeR.getId("id", "menu_share")) { intent.setClassName(this, ShareActivity.class.getName()); startActivity(intent); - } else if (itemId == R.id.menu_history) { + } else if (itemId == fakeR.getId("id", "menu_history")) { intent.setClassName(this, HistoryActivity.class.getName()); startActivityForResult(intent, HISTORY_REQUEST_CODE); - } else if (itemId == R.id.menu_settings) { + } else if (itemId == fakeR.getId("id", "menu_settings")) { intent.setClassName(this, PreferencesActivity.class.getName()); startActivity(intent); - } else if (itemId == R.id.menu_help) { + } else if (itemId == fakeR.getId("id", "menu_help")) { intent.setClassName(this, HelpActivity.class.getName()); startActivity(intent); } else { @@ -367,7 +371,7 @@ private void decodeOrStoreSavedBitmap(Bitmap bitmap, Result result) { savedResultToShow = result; } if (savedResultToShow != null) { - Message message = Message.obtain(handler, R.id.decode_succeeded, savedResultToShow); + Message message = Message.obtain(handler, fakeR.getId("id", "decode_succeeded"), savedResultToShow); handler.sendMessage(message); } savedResultToShow = null; @@ -429,7 +433,7 @@ public void handleDecode(Result rawResult, Bitmap barcode) { case NONE: SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); if (fromLiveScan && prefs.getBoolean(PreferencesActivity.KEY_BULK_MODE, false)) { - String message = getResources().getString(R.string.msg_bulk_mode_scanned) + String message = getResources().getString(fakeR.getId("string", "msg_bulk_mode_scanned")) + " (" + rawResult.getText() + ')'; Toast.makeText(this, message, Toast.LENGTH_SHORT).show(); // Wait a moment or else it will scan the same barcode continuously about 3 times @@ -452,7 +456,7 @@ private void drawResultPoints(Bitmap barcode, Result rawResult) { if (points != null && points.length > 0) { Canvas canvas = new Canvas(barcode); Paint paint = new Paint(); - paint.setColor(getResources().getColor(R.color.result_points)); + paint.setColor(getResources().getColor(fakeR.getId("color", "result_points"))); if (points.length == 2) { paint.setStrokeWidth(4.0f); drawLine(canvas, paint, points[0], points[1]); @@ -481,28 +485,28 @@ private void handleDecodeInternally(Result rawResult, ResultHandler resultHandle viewfinderView.setVisibility(View.GONE); resultView.setVisibility(View.VISIBLE); - ImageView barcodeImageView = (ImageView) findViewById(R.id.barcode_image_view); + ImageView barcodeImageView = (ImageView) findViewById(fakeR.getId("id", "barcode_image_view")); if (barcode == null) { barcodeImageView.setImageBitmap(BitmapFactory.decodeResource(getResources(), - R.drawable.launcher_icon)); + fakeR.getId("drawable", "launcher_icon"))); } else { barcodeImageView.setImageBitmap(barcode); } - TextView formatTextView = (TextView) findViewById(R.id.format_text_view); + TextView formatTextView = (TextView) findViewById(fakeR.getId("id", "format_text_view")); formatTextView.setText(rawResult.getBarcodeFormat().toString()); - TextView typeTextView = (TextView) findViewById(R.id.type_text_view); + TextView typeTextView = (TextView) findViewById(fakeR.getId("id", "type_text_view")); typeTextView.setText(resultHandler.getType().toString()); DateFormat formatter = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT); String formattedTime = formatter.format(new Date(rawResult.getTimestamp())); - TextView timeTextView = (TextView) findViewById(R.id.time_text_view); + TextView timeTextView = (TextView) findViewById(fakeR.getId("id", "time_text_view")); timeTextView.setText(formattedTime); - TextView metaTextView = (TextView) findViewById(R.id.meta_text_view); - View metaTextViewLabel = findViewById(R.id.meta_text_view_label); + TextView metaTextView = (TextView) findViewById(fakeR.getId("id", "meta_text_view")); + View metaTextViewLabel = findViewById(fakeR.getId("id", "meta_text_view_label")); metaTextView.setVisibility(View.GONE); metaTextViewLabel.setVisibility(View.GONE); Map metadata = rawResult.getResultMetadata(); @@ -521,14 +525,14 @@ private void handleDecodeInternally(Result rawResult, ResultHandler resultHandle } } - TextView contentsTextView = (TextView) findViewById(R.id.contents_text_view); + TextView contentsTextView = (TextView) findViewById(fakeR.getId("id", "contents_text_view")); CharSequence displayContents = resultHandler.getDisplayContents(); contentsTextView.setText(displayContents); // Crudely scale betweeen 22 and 32 -- bigger font for shorter text int scaledSize = Math.max(22, 32 - displayContents.length() / 4); contentsTextView.setTextSize(TypedValue.COMPLEX_UNIT_SP, scaledSize); - TextView supplementTextView = (TextView) findViewById(R.id.contents_supplement_text_view); + TextView supplementTextView = (TextView) findViewById(fakeR.getId("id", "contents_supplement_text_view")); supplementTextView.setText(""); supplementTextView.setOnClickListener(null); if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean( @@ -540,7 +544,7 @@ private void handleDecodeInternally(Result rawResult, ResultHandler resultHandle } int buttonCount = resultHandler.getButtonCount(); - ViewGroup buttonView = (ViewGroup) findViewById(R.id.result_button_view); + ViewGroup buttonView = (ViewGroup) findViewById(fakeR.getId("id", "result_button_view")); buttonView.requestFocus(); for (int x = 0; x < ResultHandler.MAX_BUTTON_COUNT; x++) { TextView button = (TextView) buttonView.getChildAt(x); @@ -625,7 +629,7 @@ private void handleDecodeExternally(Result rawResult, ResultHandler resultHandle } } } - sendReplyMessage(R.id.return_scan_result, intent, resultDurationMS); + sendReplyMessage(fakeR.getId("id", "return_scan_result"), intent, resultDurationMS); } else if (source == IntentSource.PRODUCT_SEARCH_LINK) { @@ -633,7 +637,7 @@ private void handleDecodeExternally(Result rawResult, ResultHandler resultHandle // TLD as the scan URL. int end = sourceUrl.lastIndexOf("/scan"); String replyURL = sourceUrl.substring(0, end) + "?q=" + resultHandler.getDisplayContents() + "&source=zxing"; - sendReplyMessage(R.id.launch_product_query, replyURL, resultDurationMS); + sendReplyMessage(fakeR.getId("id", "launch_product_query"), replyURL, resultDurationMS); } else if (source == IntentSource.ZXING_LINK) { @@ -647,7 +651,7 @@ private void handleDecodeExternally(Result rawResult, ResultHandler resultHandle // can't happen; UTF-8 is always supported. Continue, I guess, without encoding } String replyURL = returnUrlTemplate.replace(RETURN_CODE_PLACEHOLDER, codeReplacement); - sendReplyMessage(R.id.launch_product_query, replyURL, resultDurationMS); + sendReplyMessage(fakeR.getId("id", "launch_product_query"), replyURL, resultDurationMS); } } @@ -717,23 +721,23 @@ private void initCamera(SurfaceHolder surfaceHolder) { private void displayFrameworkBugMessageAndExit() { AlertDialog.Builder builder = new AlertDialog.Builder(this); - builder.setTitle(getString(R.string.app_name)); - builder.setMessage(getString(R.string.msg_camera_framework_bug)); - builder.setPositiveButton(R.string.button_ok, new FinishListener(this)); + builder.setTitle(getString(fakeR.getId("string", "app_name"))); + builder.setMessage(getString(fakeR.getId("string", "msg_camera_framework_bug"))); + builder.setPositiveButton(fakeR.getId("string", "button_ok"), new FinishListener(this)); builder.setOnCancelListener(new FinishListener(this)); builder.show(); } public void restartPreviewAfterDelay(long delayMS) { if (handler != null) { - handler.sendEmptyMessageDelayed(R.id.restart_preview, delayMS); + handler.sendEmptyMessageDelayed(fakeR.getId("id", "restart_preview"), delayMS); } resetStatusView(); } private void resetStatusView() { resultView.setVisibility(View.GONE); - statusView.setText(R.string.msg_default_status); + statusView.setText(fakeR.getId("string", "msg_default_status")); statusView.setVisibility(View.VISIBLE); viewfinderView.setVisibility(View.VISIBLE); lastResult = null; diff --git a/src/android/LibraryProject/src/com/google/zxing/client/android/CaptureActivityHandler.java b/src/android/LibraryProject/src/com/google/zxing/client/android/CaptureActivityHandler.java index b5acf831..31078d26 100755 --- a/src/android/LibraryProject/src/com/google/zxing/client/android/CaptureActivityHandler.java +++ b/src/android/LibraryProject/src/com/google/zxing/client/android/CaptureActivityHandler.java @@ -32,6 +32,7 @@ import android.os.Handler; import android.os.Message; import android.util.Log; +import com.google.zxing.FakeR; import java.util.Collection; @@ -55,10 +56,13 @@ private enum State { DONE } + private static FakeR fakeR; + CaptureActivityHandler(CaptureActivity activity, Collection decodeFormats, String characterSet, CameraManager cameraManager) { + fakeR = new FakeR(activity); this.activity = activity; decodeThread = new DecodeThread(activity, decodeFormats, characterSet, new ViewfinderResultPointCallback(activity.getViewfinderView())); @@ -73,25 +77,25 @@ private enum State { @Override public void handleMessage(Message message) { - if (message.what == R.id.restart_preview) { + if (message.what == fakeR.getId("id", "restart_preview")) { Log.d(TAG, "Got restart preview message"); restartPreviewAndDecode(); - } else if (message.what == R.id.decode_succeeded) { + } else if (message.what == fakeR.getId("id", "decode_succeeded")) { Log.d(TAG, "Got decode succeeded message"); state = State.SUCCESS; Bundle bundle = message.getData(); Bitmap barcode = bundle == null ? null : (Bitmap) bundle.getParcelable(DecodeThread.BARCODE_BITMAP); activity.handleDecode((Result) message.obj, barcode); - } else if (message.what == R.id.decode_failed) { + } else if (message.what == fakeR.getId("id", "decode_failed")) { // We're decoding as fast as possible, so when one decode fails, start another. state = State.PREVIEW; - cameraManager.requestPreviewFrame(decodeThread.getHandler(), R.id.decode); - } else if (message.what == R.id.return_scan_result) { + cameraManager.requestPreviewFrame(decodeThread.getHandler(), fakeR.getId("id", "decode")); + } else if (message.what == fakeR.getId("id", "return_scan_result")) { Log.d(TAG, "Got return scan result message"); activity.setResult(Activity.RESULT_OK, (Intent) message.obj); activity.finish(); - } else if (message.what == R.id.launch_product_query) { + } else if (message.what == fakeR.getId("id", "launch_product_query")) { Log.d(TAG, "Got product query message"); String url = (String) message.obj; Intent intent = new Intent(Intent.ACTION_VIEW); @@ -121,7 +125,7 @@ public void handleMessage(Message message) { public void quitSynchronously() { state = State.DONE; cameraManager.stopPreview(); - Message quit = Message.obtain(decodeThread.getHandler(), R.id.quit); + Message quit = Message.obtain(decodeThread.getHandler(), fakeR.getId("id", "quit")); quit.sendToTarget(); try { // Wait at most half a second; should be enough time, and onPause() will timeout quickly @@ -131,14 +135,14 @@ public void quitSynchronously() { } // Be absolutely sure we don't send any queued up messages - removeMessages(R.id.decode_succeeded); - removeMessages(R.id.decode_failed); + removeMessages(fakeR.getId("id", "decode_succeeded")); + removeMessages(fakeR.getId("id", "decode_failed")); } private void restartPreviewAndDecode() { if (state == State.SUCCESS) { state = State.PREVIEW; - cameraManager.requestPreviewFrame(decodeThread.getHandler(), R.id.decode); + cameraManager.requestPreviewFrame(decodeThread.getHandler(), fakeR.getId("id", "decode")); activity.drawViewfinder(); } } diff --git a/src/android/LibraryProject/src/com/google/zxing/client/android/DecodeHandler.java b/src/android/LibraryProject/src/com/google/zxing/client/android/DecodeHandler.java index 33866d69..e69073a4 100644 --- a/src/android/LibraryProject/src/com/google/zxing/client/android/DecodeHandler.java +++ b/src/android/LibraryProject/src/com/google/zxing/client/android/DecodeHandler.java @@ -31,6 +31,7 @@ import android.os.Looper; import android.os.Message; import android.util.Log; +import com.google.zxing.FakeR; import java.util.Map; @@ -42,7 +43,9 @@ final class DecodeHandler extends Handler { private final MultiFormatReader multiFormatReader; private boolean running = true; + private static FakeR fakeR; DecodeHandler(CaptureActivity activity, Map hints) { + fakeR = new FakeR(activity); multiFormatReader = new MultiFormatReader(); multiFormatReader.setHints(hints); this.activity = activity; @@ -53,9 +56,9 @@ public void handleMessage(Message message) { if (!running) { return; } - if (message.what == R.id.decode) { + if (message.what == fakeR.getId("id", "decode")) { decode((byte[]) message.obj, message.arg1, message.arg2); - } else if (message.what == R.id.quit) { + } else if (message.what == fakeR.getId("id", "quit")) { running = false; Looper.myLooper().quit(); } @@ -90,7 +93,7 @@ private void decode(byte[] data, int width, int height) { 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); + Message message = Message.obtain(handler, fakeR.getId("id", "decode_succeeded"), rawResult); Bundle bundle = new Bundle(); Bitmap grayscaleBitmap = toBitmap(source, source.renderCroppedGreyscaleBitmap()); bundle.putParcelable(DecodeThread.BARCODE_BITMAP, grayscaleBitmap); @@ -99,7 +102,7 @@ private void decode(byte[] data, int width, int height) { } } else { if (handler != null) { - Message message = Message.obtain(handler, R.id.decode_failed); + Message message = Message.obtain(handler, fakeR.getId("id", "decode_failed")); message.sendToTarget(); } } diff --git a/src/android/LibraryProject/src/com/google/zxing/client/android/HelpActivity.java b/src/android/LibraryProject/src/com/google/zxing/client/android/HelpActivity.java index cb145cc9..61dc0488 100644 --- a/src/android/LibraryProject/src/com/google/zxing/client/android/HelpActivity.java +++ b/src/android/LibraryProject/src/com/google/zxing/client/android/HelpActivity.java @@ -25,6 +25,7 @@ import android.webkit.WebView; import android.webkit.WebViewClient; import android.widget.Button; +import com.google.zxing.FakeR; /** * An HTML-based help screen with Back and Done buttons at the bottom. @@ -46,6 +47,8 @@ public final class HelpActivity extends Activity { private WebView webView; private Button backButton; + private static FakeR fakeR; + private final Button.OnClickListener backListener = new Button.OnClickListener() { @Override public void onClick(View view) { @@ -63,9 +66,12 @@ public void onClick(View view) { @Override protected void onCreate(Bundle icicle) { super.onCreate(icicle); - setContentView(R.layout.help); - webView = (WebView)findViewById(R.id.help_contents); + fakeR = new FakeR(this); + + setContentView(fakeR.getId("layout", "help")); + + webView = (WebView)findViewById(fakeR.getId("id", "help_contents")); webView.setWebViewClient(new HelpClient()); // Froyo has a bug with calling onCreate() twice in a row, which causes the What's New page @@ -85,9 +91,9 @@ protected void onCreate(Bundle icicle) { webView.loadUrl(BASE_URL + DEFAULT_PAGE); } - backButton = (Button) findViewById(R.id.back_button); + backButton = (Button) findViewById(fakeR.getId("id", "back_button")); backButton.setOnClickListener(backListener); - View doneButton = findViewById(R.id.done_button); + View doneButton = findViewById(fakeR.getId("id", "done_button")); doneButton.setOnClickListener(doneListener); } diff --git a/src/android/LibraryProject/src/com/google/zxing/client/android/PreferencesActivity.java b/src/android/LibraryProject/src/com/google/zxing/client/android/PreferencesActivity.java index e81512bf..95b840c3 100755 --- a/src/android/LibraryProject/src/com/google/zxing/client/android/PreferencesActivity.java +++ b/src/android/LibraryProject/src/com/google/zxing/client/android/PreferencesActivity.java @@ -22,6 +22,7 @@ import android.preference.CheckBoxPreference; import android.preference.PreferenceActivity; import android.preference.PreferenceScreen; +import com.google.zxing.FakeR; import java.util.ArrayList; import java.util.Collection; @@ -58,10 +59,13 @@ public final class PreferencesActivity extends PreferenceActivity private CheckBoxPreference decodeQR; private CheckBoxPreference decodeDataMatrix; + private static FakeR fakeR; + @Override protected void onCreate(Bundle icicle) { super.onCreate(icicle); - addPreferencesFromResource(R.xml.preferences); + fakeR = new FakeR(this); + addPreferencesFromResource(fakeR.getId("xml", "preferences")); PreferenceScreen preferences = getPreferenceScreen(); preferences.getSharedPreferences().registerOnSharedPreferenceChangeListener(this); diff --git a/src/android/LibraryProject/src/com/google/zxing/client/android/ViewfinderView.java b/src/android/LibraryProject/src/com/google/zxing/client/android/ViewfinderView.java index 050fd589..86864bec 100755 --- a/src/android/LibraryProject/src/com/google/zxing/client/android/ViewfinderView.java +++ b/src/android/LibraryProject/src/com/google/zxing/client/android/ViewfinderView.java @@ -27,6 +27,7 @@ import android.graphics.Rect; import android.util.AttributeSet; import android.view.View; +import com.google.zxing.FakeR; import java.util.ArrayList; import java.util.List; @@ -56,17 +57,21 @@ public final class ViewfinderView extends View { private List possibleResultPoints; private List lastPossibleResultPoints; + private static FakeR fakeR; + // This constructor is used when the class is built from an XML resource. public ViewfinderView(Context context, AttributeSet attrs) { super(context, attrs); + fakeR = new FakeR(context); + // Initialize these once for performance rather than calling them every time in onDraw(). paint = new Paint(Paint.ANTI_ALIAS_FLAG); Resources resources = getResources(); - maskColor = resources.getColor(R.color.viewfinder_mask); - resultColor = resources.getColor(R.color.result_view); - laserColor = resources.getColor(R.color.viewfinder_laser); - resultPointColor = resources.getColor(R.color.possible_result_points); + maskColor = resources.getColor(fakeR.getId("color", "viewfinder_mask")); + resultColor = resources.getColor(fakeR.getId("color", "result_view")); + laserColor = resources.getColor(fakeR.getId("color", "viewfinder_laser")); + resultPointColor = resources.getColor(fakeR.getId("color", "possible_result_points")); scannerAlpha = 0; possibleResultPoints = new ArrayList(5); lastPossibleResultPoints = null; diff --git a/src/android/LibraryProject/src/com/google/zxing/client/android/book/SearchBookContentsActivity.java b/src/android/LibraryProject/src/com/google/zxing/client/android/book/SearchBookContentsActivity.java index 04c76d58..af9c7b19 100644 --- a/src/android/LibraryProject/src/com/google/zxing/client/android/book/SearchBookContentsActivity.java +++ b/src/android/LibraryProject/src/com/google/zxing/client/android/book/SearchBookContentsActivity.java @@ -30,6 +30,7 @@ import android.widget.EditText; import android.widget.ListView; import android.widget.TextView; +import com.google.zxing.FakeR; import org.json.JSONArray; import org.json.JSONException; @@ -96,10 +97,14 @@ String getISBN() { return isbn; } + private static FakeR fakeR; + @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); + fakeR = new FakeR(this); + // Make sure that expired cookies are removed on launch. CookieSyncManager.createInstance(this); CookieManager.getInstance().removeExpiredCookie(); @@ -112,13 +117,13 @@ public void onCreate(Bundle icicle) { isbn = intent.getStringExtra(Intents.SearchBookContents.ISBN); if (LocaleManager.isBookSearchUrl(isbn)) { - setTitle(getString(R.string.sbc_name)); + setTitle(getString(fakeR.getId("string", "sbc_name"))); } else { - setTitle(getString(R.string.sbc_name) + ": ISBN " + isbn); + setTitle(getString(fakeR.getId("string", "sbc_name")) + ": ISBN " + isbn); } - setContentView(R.layout.search_book_contents); - queryTextView = (EditText) findViewById(R.id.query_text_view); + setContentView(fakeR.getId("layout", "search_book_contents")); + queryTextView = (EditText) findViewById(fakeR.getId("id", "query_text_view")); String initialQuery = intent.getStringExtra(Intents.SearchBookContents.QUERY); if (initialQuery != null && initialQuery.length() > 0) { @@ -127,12 +132,12 @@ public void onCreate(Bundle icicle) { } queryTextView.setOnKeyListener(keyListener); - queryButton = (Button) findViewById(R.id.query_button); + queryButton = (Button) findViewById(fakeR.getId("id", "query_button")); queryButton.setOnClickListener(buttonListener); - resultListView = (ListView) findViewById(R.id.result_list_view); + resultListView = (ListView) findViewById(fakeR.getId("id", "result_list_view")); LayoutInflater factory = LayoutInflater.from(this); - headerView = (TextView) factory.inflate(R.layout.search_book_contents_header, + headerView = (TextView) factory.inflate(fakeR.getId("layout", "search_book_contents_header"), resultListView, false); resultListView.addHeaderView(headerView); } @@ -162,7 +167,7 @@ private void launchSearch() { } networkTask = new NetworkTask(); taskExec.execute(networkTask, query, isbn); - headerView.setText(R.string.msg_sbc_searching_book); + headerView.setText(fakeR.getId("string", "msg_sbc_searching_book")); resultListView.setAdapter(null); queryTextView.setEnabled(false); queryButton.setEnabled(false); @@ -201,7 +206,7 @@ protected JSONObject doInBackground(String... args) { @Override protected void onPostExecute(JSONObject result) { if (result == null) { - headerView.setText(R.string.msg_sbc_failed); + headerView.setText(fakeR.getId("string", "msg_sbc_failed")); } else { handleSearchResults(result); } @@ -215,7 +220,7 @@ protected void onPostExecute(JSONObject result) { private void handleSearchResults(JSONObject json) { try { int count = json.getInt("number_of_results"); - headerView.setText(getString(R.string.msg_sbc_results) + " : " + count); + headerView.setText(getString(fakeR.getId("string", "msg_sbc_results")) + " : " + count); if (count > 0) { JSONArray results = json.getJSONArray("search_results"); SearchBookContentsResult.setQuery(queryTextView.getText().toString()); @@ -228,14 +233,14 @@ private void handleSearchResults(JSONObject json) { } else { String searchable = json.optString("searchable"); if ("false".equals(searchable)) { - headerView.setText(R.string.msg_sbc_book_not_searchable); + headerView.setText(fakeR.getId("string", "msg_sbc_book_not_searchable")); } resultListView.setAdapter(null); } } catch (JSONException e) { Log.w(TAG, "Bad JSON from book search", e); resultListView.setAdapter(null); - headerView.setText(R.string.msg_sbc_failed); + headerView.setText(fakeR.getId("string", "msg_sbc_failed")); } } @@ -245,10 +250,10 @@ private SearchBookContentsResult parseResult(JSONObject json) { String pageId = json.getString("page_id"); String pageNumber = json.getString("page_number"); if (pageNumber.length() > 0) { - pageNumber = getString(R.string.msg_sbc_page) + ' ' + pageNumber; + pageNumber = getString(fakeR.getId("string", "msg_sbc_page")) + ' ' + pageNumber; } else { // This can happen for text on the jacket, and possibly other reasons. - pageNumber = getString(R.string.msg_sbc_unknown_page); + pageNumber = getString(fakeR.getId("string", "msg_sbc_unknown_page")); } // Remove all HTML tags and encoded characters. Ideally the server would do this. @@ -261,13 +266,13 @@ private SearchBookContentsResult parseResult(JSONObject json) { snippet = QUOTE_ENTITY_PATTERN.matcher(snippet).replaceAll("'"); snippet = QUOT_ENTITY_PATTERN.matcher(snippet).replaceAll("\""); } else { - snippet = '(' + getString(R.string.msg_sbc_snippet_unavailable) + ')'; + snippet = '(' + getString(fakeR.getId("string", "msg_sbc_snippet_unavailable")) + ')'; valid = false; } return new SearchBookContentsResult(pageId, pageNumber, snippet, valid); } catch (JSONException e) { // Never seen in the wild, just being complete. - return new SearchBookContentsResult(getString(R.string.msg_sbc_no_page_returned), "", "", false); + return new SearchBookContentsResult(getString(fakeR.getId("string", "msg_sbc_no_page_returned")), "", "", false); } } diff --git a/src/android/LibraryProject/src/com/google/zxing/client/android/book/SearchBookContentsAdapter.java b/src/android/LibraryProject/src/com/google/zxing/client/android/book/SearchBookContentsAdapter.java index c8d4122f..9051a3a2 100644 --- a/src/android/LibraryProject/src/com/google/zxing/client/android/book/SearchBookContentsAdapter.java +++ b/src/android/LibraryProject/src/com/google/zxing/client/android/book/SearchBookContentsAdapter.java @@ -21,6 +21,7 @@ import android.view.View; import android.view.ViewGroup; import android.widget.ArrayAdapter; +import com.google.zxing.FakeR; import java.util.List; @@ -33,8 +34,11 @@ */ final class SearchBookContentsAdapter extends ArrayAdapter { + private static FakeR fakeR; + SearchBookContentsAdapter(Context context, List items) { - super(context, R.layout.search_book_contents_list_item, 0, items); + super(context, fakeR.getId("layout", "search_book_contents_list_item"), 0, items); + fakeR = new FakeR(context); } @Override @@ -44,7 +48,7 @@ public View getView(int position, View view, ViewGroup viewGroup) { if (view == null) { LayoutInflater factory = LayoutInflater.from(getContext()); listItem = (SearchBookContentsListItem) factory.inflate( - R.layout.search_book_contents_list_item, viewGroup, false); + fakeR.getId("layout", "search_book_contents_list_item"), viewGroup, false); } else { if (view instanceof SearchBookContentsListItem) { listItem = (SearchBookContentsListItem) view; diff --git a/src/android/LibraryProject/src/com/google/zxing/client/android/book/SearchBookContentsListItem.java b/src/android/LibraryProject/src/com/google/zxing/client/android/book/SearchBookContentsListItem.java index 90badc99..801d0ed7 100644 --- a/src/android/LibraryProject/src/com/google/zxing/client/android/book/SearchBookContentsListItem.java +++ b/src/android/LibraryProject/src/com/google/zxing/client/android/book/SearchBookContentsListItem.java @@ -26,6 +26,7 @@ import android.util.AttributeSet; import android.widget.LinearLayout; import android.widget.TextView; +import com.google.zxing.FakeR; import java.util.Locale; @@ -38,8 +39,10 @@ public final class SearchBookContentsListItem extends LinearLayout { private TextView pageNumberView; private TextView snippetView; + private static FakeR fakeR; SearchBookContentsListItem(Context context) { super(context); + fakeR = new FakeR(context); } public SearchBookContentsListItem(Context context, AttributeSet attrs) { @@ -49,8 +52,8 @@ public SearchBookContentsListItem(Context context, AttributeSet attrs) { @Override protected void onFinishInflate() { super.onFinishInflate(); - pageNumberView = (TextView) findViewById(R.id.page_number_view); - snippetView = (TextView) findViewById(R.id.snippet_view); + pageNumberView = (TextView) findViewById(fakeR.getId("id", "page_number_view")); + snippetView = (TextView) findViewById(fakeR.getId("id", "snippet_view")); } public void set(SearchBookContentsResult result) { diff --git a/src/android/LibraryProject/src/com/google/zxing/client/android/encode/EncodeActivity.java b/src/android/LibraryProject/src/com/google/zxing/client/android/encode/EncodeActivity.java index 2503f243..965bcb3c 100755 --- a/src/android/LibraryProject/src/com/google/zxing/client/android/encode/EncodeActivity.java +++ b/src/android/LibraryProject/src/com/google/zxing/client/android/encode/EncodeActivity.java @@ -37,6 +37,7 @@ import android.view.MenuItem; import android.widget.ImageView; import android.widget.TextView; +import com.google.zxing.FakeR; import java.io.File; import java.io.FileNotFoundException; @@ -60,16 +61,18 @@ public final class EncodeActivity extends Activity { private QRCodeEncoder qrCodeEncoder; + private static FakeR fakeR; @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); + fakeR = new FakeR(this); Intent intent = getIntent(); if (intent == null) { finish(); } else { // String action = intent.getAction(); // if (Intents.Encode.ACTION.equals(action) || Intent.ACTION_SEND.equals(action)) { - setContentView(R.layout.encode); + setContentView(fakeR.getId("layout", "encode")); // } else { // finish(); // } @@ -79,10 +82,10 @@ public void onCreate(Bundle icicle) { @Override public boolean onCreateOptionsMenu(Menu menu) { MenuInflater menuInflater = getMenuInflater(); - menuInflater.inflate(R.menu.encode, menu); + menuInflater.inflate(fakeR.getId("menu", "encode"), menu); boolean useVcard = qrCodeEncoder != null && qrCodeEncoder.isUseVCard(); - int encodeNameResource = useVcard ? R.string.menu_encode_mecard : R.string.menu_encode_vcard; - MenuItem encodeItem = menu.findItem(R.id.menu_encode); + int encodeNameResource = useVcard ? fakeR.getId("string", "menu_encode_mecard") : fakeR.getId("string", "menu_encode_vcard"); + MenuItem encodeItem = menu.findItem(fakeR.getId("id", "menu_encode")); encodeItem.setTitle(encodeNameResource); Intent intent = getIntent(); if (intent != null) { @@ -95,10 +98,10 @@ public boolean onCreateOptionsMenu(Menu menu) { @Override public boolean onOptionsItemSelected(MenuItem item) { int itemId = item.getItemId(); - if (itemId == R.id.menu_share) { + if (itemId == fakeR.getId("id", "menu_share")) { share(); return true; - } else if (itemId == R.id.menu_encode) { + } else if (itemId == fakeR.getId("id", "menu_encode")) { Intent intent = getIntent(); if (intent == null) { return false; @@ -140,7 +143,7 @@ private void share() { File barcodesRoot = new File(bsRoot, "Barcodes"); if (!barcodesRoot.exists() && !barcodesRoot.mkdirs()) { Log.w(TAG, "Couldn't make dir " + barcodesRoot); - showErrorMessage(R.string.msg_unmount_usb); + showErrorMessage(fakeR.getId("string", "msg_unmount_usb")); return; } File barcodeFile = new File(barcodesRoot, makeBarcodeFileName(contents) + ".png"); @@ -151,7 +154,7 @@ private void share() { bitmap.compress(Bitmap.CompressFormat.PNG, 0, fos); } catch (FileNotFoundException fnfe) { Log.w(TAG, "Couldn't access file " + barcodeFile + " due to " + fnfe); - showErrorMessage(R.string.msg_unmount_usb); + showErrorMessage(fakeR.getId("string", "msg_unmount_usb")); return; } finally { if (fos != null) { @@ -164,7 +167,7 @@ private void share() { } Intent intent = new Intent(Intent.ACTION_SEND, Uri.parse("mailto:")); - intent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.app_name) + " - " + encoder.getTitle()); + intent.putExtra(Intent.EXTRA_SUBJECT, getString(fakeR.getId("string", "app_name")) + " - " + encoder.getTitle()); intent.putExtra(Intent.EXTRA_TEXT, contents); intent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + barcodeFile.getAbsolutePath())); intent.setType("image/png"); @@ -202,15 +205,15 @@ protected void onResume() { Bitmap bitmap = qrCodeEncoder.encodeAsBitmap(); if (bitmap == null) { Log.w(TAG, "Could not encode barcode"); - showErrorMessage(R.string.msg_encode_contents_failed); + showErrorMessage(fakeR.getId("string", "msg_encode_contents_failed")); qrCodeEncoder = null; return; } - ImageView view = (ImageView) findViewById(R.id.image_view); + ImageView view = (ImageView) findViewById(fakeR.getId("id", "image_view")); view.setImageBitmap(bitmap); - TextView contents = (TextView) findViewById(R.id.contents_text_view); + TextView contents = (TextView) findViewById(fakeR.getId("id", "contents_text_view")); if (intent.getBooleanExtra(Intents.Encode.SHOW_CONTENTS, true)) { contents.setText(qrCodeEncoder.getDisplayContents()); setTitle(qrCodeEncoder.getTitle()); @@ -220,7 +223,7 @@ protected void onResume() { } } catch (WriterException e) { Log.w(TAG, "Could not encode barcode", e); - showErrorMessage(R.string.msg_encode_contents_failed); + showErrorMessage(fakeR.getId("string", "msg_encode_contents_failed")); qrCodeEncoder = null; } } @@ -228,7 +231,7 @@ protected void onResume() { private void showErrorMessage(int message) { AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setMessage(message); - builder.setPositiveButton(R.string.button_ok, new FinishListener(this)); + builder.setPositiveButton(fakeR.getId("string", "button_ok"), new FinishListener(this)); builder.setOnCancelListener(new FinishListener(this)); builder.show(); } diff --git a/src/android/LibraryProject/src/com/google/zxing/client/android/encode/QRCodeEncoder.java b/src/android/LibraryProject/src/com/google/zxing/client/android/encode/QRCodeEncoder.java index e31db4a4..395a4497 100755 --- a/src/android/LibraryProject/src/com/google/zxing/client/android/encode/QRCodeEncoder.java +++ b/src/android/LibraryProject/src/com/google/zxing/client/android/encode/QRCodeEncoder.java @@ -37,6 +37,7 @@ import android.os.Bundle; import android.telephony.PhoneNumberUtils; import android.util.Log; +import com.google.zxing.FakeR; import java.io.ByteArrayOutputStream; import java.io.IOException; @@ -69,7 +70,9 @@ final class QRCodeEncoder { private final int dimension; private final boolean useVCard; + private static FakeR fakeR; QRCodeEncoder(Activity activity, Intent intent, int dimension, boolean useVCard) throws WriterException { + fakeR = new FakeR(activity); this.activity = activity; this.dimension = dimension; this.useVCard = useVCard; @@ -122,7 +125,7 @@ private boolean encodeContentsFromZXingIntent(Intent intent) { if (data != null && data.length() > 0) { contents = data; displayContents = data; - title = activity.getString(R.string.contents_text); + title = activity.getString(fakeR.getId("string", "contents_text")); } } return contents != null && contents.length() > 0; @@ -171,7 +174,7 @@ private void encodeFromTextExtras(Intent intent) throws WriterException { } else { displayContents = contents; } - title = activity.getString(R.string.contents_text); + title = activity.getString(fakeR.getId("string", "contents_text")); } // Handles send intents from the Contacts app, retrieving a contact as a VCARD. @@ -219,28 +222,28 @@ private void encodeQRCodeContents(Intent intent, String type) { if (data != null && data.length() > 0) { contents = data; displayContents = data; - title = activity.getString(R.string.contents_text); + title = activity.getString(fakeR.getId("string", "contents_text")); } } else if (type.equals(Contents.Type.EMAIL)) { String data = ContactEncoder.trim(intent.getStringExtra(Intents.Encode.DATA)); if (data != null) { contents = "mailto:" + data; displayContents = data; - title = activity.getString(R.string.contents_email); + title = activity.getString(fakeR.getId("string", "contents_email")); } } else if (type.equals(Contents.Type.PHONE)) { String data = ContactEncoder.trim(intent.getStringExtra(Intents.Encode.DATA)); if (data != null) { contents = "tel:" + data; displayContents = PhoneNumberUtils.formatNumber(data); - title = activity.getString(R.string.contents_phone); + title = activity.getString(fakeR.getId("string", "contents_phone")); } } else if (type.equals(Contents.Type.SMS)) { String data = ContactEncoder.trim(intent.getStringExtra(Intents.Encode.DATA)); if (data != null) { contents = "sms:" + data; displayContents = PhoneNumberUtils.formatNumber(data); - title = activity.getString(R.string.contents_sms); + title = activity.getString(fakeR.getId("string", "contents_sms")); } } else if (type.equals(Contents.Type.CONTACT)) { @@ -273,7 +276,7 @@ private void encodeQRCodeContents(Intent intent, String type) { if (encoded[1].length() > 0) { contents = encoded[0]; displayContents = encoded[1]; - title = activity.getString(R.string.contents_contact); + title = activity.getString(fakeR.getId("string", "contents_contact")); } } @@ -287,7 +290,7 @@ private void encodeQRCodeContents(Intent intent, String type) { if (latitude != Float.MAX_VALUE && longitude != Float.MAX_VALUE) { contents = "geo:" + latitude + ',' + longitude; displayContents = latitude + "," + longitude; - title = activity.getString(R.string.contents_location); + title = activity.getString(fakeR.getId("string", "contents_location")); } } } @@ -306,7 +309,7 @@ private void encodeQRCodeContents(AddressBookParsedResult contact) { if (encoded[1].length() > 0) { contents = encoded[0]; displayContents = encoded[1]; - title = activity.getString(R.string.contents_contact); + title = activity.getString(fakeR.getId("string", "contents_contact")); } } diff --git a/src/android/LibraryProject/src/com/google/zxing/client/android/history/HistoryActivity.java b/src/android/LibraryProject/src/com/google/zxing/client/android/history/HistoryActivity.java index 6cb4ae89..3d4d8789 100644 --- a/src/android/LibraryProject/src/com/google/zxing/client/android/history/HistoryActivity.java +++ b/src/android/LibraryProject/src/com/google/zxing/client/android/history/HistoryActivity.java @@ -32,6 +32,7 @@ import android.view.View; import android.widget.AdapterView; import android.widget.ListView; +import com.google.zxing.FakeR; import com.google.zxing.client.android.CaptureActivity; import com.google.zxing.client.android.Intents; import com.google.zxing.client.android.R; @@ -45,9 +46,11 @@ public final class HistoryActivity extends ListActivity { private HistoryManager historyManager; private HistoryItemAdapter adapter; + private static FakeR fakeR; @Override protected void onCreate(Bundle icicle) { super.onCreate(icicle); + fakeR = new FakeR(this); this.historyManager = new HistoryManager(this); adapter = new HistoryItemAdapter(this); setListAdapter(adapter); @@ -88,7 +91,7 @@ public void onCreateContextMenu(ContextMenu menu, ContextMenu.ContextMenuInfo menuInfo) { int position = ((AdapterView.AdapterContextMenuInfo) menuInfo).position; if (position >= adapter.getCount() || adapter.getItem(position).getResult() != null) { - menu.add(Menu.NONE, position, position, R.string.history_clear_one_history_text); + menu.add(Menu.NONE, position, position, fakeR.getId("string", "history_clear_one_history_text")); } // else it's just that dummy "Empty" message } @@ -104,7 +107,7 @@ public boolean onContextItemSelected(MenuItem item) { public boolean onCreateOptionsMenu(Menu menu) { if (historyManager.hasHistoryItems()) { MenuInflater menuInflater = getMenuInflater(); - menuInflater.inflate(R.menu.history, menu); + menuInflater.inflate(fakeR.getId("menu", "history"), menu); } return super.onCreateOptionsMenu(menu); } @@ -112,18 +115,18 @@ public boolean onCreateOptionsMenu(Menu menu) { @Override public boolean onOptionsItemSelected(MenuItem item) { int itemId = item.getItemId(); - if (itemId == R.id.menu_history_send) { + if (itemId == fakeR.getId("id", "menu_history_send")) { CharSequence history = historyManager.buildHistory(); Uri historyFile = HistoryManager.saveHistory(history.toString()); if (historyFile == null) { AlertDialog.Builder builder = new AlertDialog.Builder(this); - builder.setMessage(R.string.msg_unmount_usb); - builder.setPositiveButton(R.string.button_ok, null); + builder.setMessage(fakeR.getId("string", "msg_unmount_usb")); + builder.setPositiveButton(fakeR.getId("string", "button_ok"), null); builder.show(); } else { Intent intent = new Intent(Intent.ACTION_SEND, Uri.parse("mailto:")); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); - String subject = getResources().getString(R.string.history_email_title); + String subject = getResources().getString(fakeR.getId("string", "history_email_title")); intent.putExtra(Intent.EXTRA_SUBJECT, subject); intent.putExtra(Intent.EXTRA_TEXT, subject); intent.putExtra(Intent.EXTRA_STREAM, historyFile); @@ -134,11 +137,11 @@ public boolean onOptionsItemSelected(MenuItem item) { Log.w(TAG, anfe.toString()); } } - } else if (itemId == R.id.menu_history_clear_text) { + } else if (itemId == fakeR.getId("id", "menu_history_clear_text")) { AlertDialog.Builder builder = new AlertDialog.Builder(this); - builder.setMessage(R.string.msg_sure); + builder.setMessage(fakeR.getId("string", "msg_sure")); builder.setCancelable(true); - builder.setPositiveButton(R.string.button_ok, new DialogInterface.OnClickListener() { + builder.setPositiveButton(fakeR.getId("string", "button_ok"), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int i2) { historyManager.clearHistory(); @@ -146,7 +149,7 @@ public void onClick(DialogInterface dialog, int i2) { finish(); } }); - builder.setNegativeButton(R.string.button_cancel, null); + builder.setNegativeButton(fakeR.getId("string", "button_cancel"), null); builder.show(); } else { return super.onOptionsItemSelected(item); diff --git a/src/android/LibraryProject/src/com/google/zxing/client/android/history/HistoryItemAdapter.java b/src/android/LibraryProject/src/com/google/zxing/client/android/history/HistoryItemAdapter.java index c8982d89..198982ef 100644 --- a/src/android/LibraryProject/src/com/google/zxing/client/android/history/HistoryItemAdapter.java +++ b/src/android/LibraryProject/src/com/google/zxing/client/android/history/HistoryItemAdapter.java @@ -24,6 +24,7 @@ import android.widget.ArrayAdapter; import android.widget.LinearLayout; import android.widget.TextView; +import com.google.zxing.FakeR; import com.google.zxing.Result; import com.google.zxing.client.android.R; @@ -33,8 +34,10 @@ final class HistoryItemAdapter extends ArrayAdapter { private final Activity activity; + private static FakeR fakeR; HistoryItemAdapter(Activity activity) { - super(activity, R.layout.history_list_item, new ArrayList()); + super(activity, activity.getApplicationContext().getResources().getIdentifier("history_list_item", "layout", activity.getApplicationContext().getPackageName()), new ArrayList()); + fakeR = new FakeR(activity); this.activity = activity; } @@ -45,7 +48,7 @@ public View getView(int position, View view, ViewGroup viewGroup) { layout = (LinearLayout) view; } else { LayoutInflater factory = LayoutInflater.from(activity); - layout = (LinearLayout) factory.inflate(R.layout.history_list_item, viewGroup, false); + layout = (LinearLayout) factory.inflate(fakeR.getId("layout", "history_list_item"), viewGroup, false); } HistoryItem item = getItem(position); @@ -58,12 +61,12 @@ public View getView(int position, View view, ViewGroup viewGroup) { detail = item.getDisplayAndDetails(); } else { Resources resources = getContext().getResources(); - title = resources.getString(R.string.history_empty); - detail = resources.getString(R.string.history_empty_detail); + title = resources.getString(fakeR.getId("string", "history_empty")); + detail = resources.getString(fakeR.getId("string", "history_empty_detail")); } - ((TextView) layout.findViewById(R.id.history_title)).setText(title); - ((TextView) layout.findViewById(R.id.history_detail)).setText(detail); + ((TextView) layout.findViewById(fakeR.getId("id", "history_title"))).setText(title); + ((TextView) layout.findViewById(fakeR.getId("id", "history_detail"))).setText(detail); return layout; } diff --git a/src/android/LibraryProject/src/com/google/zxing/client/android/result/AddressBookResultHandler.java b/src/android/LibraryProject/src/com/google/zxing/client/android/result/AddressBookResultHandler.java index b61035ef..1eed1d26 100644 --- a/src/android/LibraryProject/src/com/google/zxing/client/android/result/AddressBookResultHandler.java +++ b/src/android/LibraryProject/src/com/google/zxing/client/android/result/AddressBookResultHandler.java @@ -51,12 +51,7 @@ public final class AddressBookResultHandler extends ResultHandler { } } - private static final int[] BUTTON_TEXTS = { - R.string.button_add_contact, - R.string.button_show_map, - R.string.button_dial, - R.string.button_email, - }; + private static int[] BUTTON_TEXTS; private final boolean[] fields; private int buttonCount; @@ -80,6 +75,12 @@ private int mapIndexToAction(int index) { public AddressBookResultHandler(Activity activity, ParsedResult result) { super(activity, result); + BUTTON_TEXTS = new int[]{ + fakeR.getId("string", "button_add_contact"), + fakeR.getId("string", "button_show_map"), + fakeR.getId("string", "button_dial"), + fakeR.getId("string", "button_email"), + }; AddressBookParsedResult addressResult = (AddressBookParsedResult) result; String[] addresses = addressResult.getAddresses(); boolean hasAddress = addresses != null && addresses.length > 0 && addresses[0].length() > 0; @@ -212,6 +213,6 @@ public CharSequence getDisplayContents() { @Override public int getDisplayTitle() { - return R.string.result_address_book; + return fakeR.getId("string", "result_address_book"); } } diff --git a/src/android/LibraryProject/src/com/google/zxing/client/android/result/CalendarResultHandler.java b/src/android/LibraryProject/src/com/google/zxing/client/android/result/CalendarResultHandler.java index b97029c8..a04c93fa 100644 --- a/src/android/LibraryProject/src/com/google/zxing/client/android/result/CalendarResultHandler.java +++ b/src/android/LibraryProject/src/com/google/zxing/client/android/result/CalendarResultHandler.java @@ -38,12 +38,14 @@ public final class CalendarResultHandler extends ResultHandler { private static final String TAG = CalendarResultHandler.class.getSimpleName(); - private static final int[] buttons = { - R.string.button_add_calendar - }; + private static int[] buttons; public CalendarResultHandler(Activity activity, ParsedResult result) { super(activity, result); + + buttons = new int[]{ + fakeR.getId("string", "button_add_calendar") + }; } @Override @@ -181,6 +183,6 @@ private static String format(boolean allDay, Date date) { @Override public int getDisplayTitle() { - return R.string.result_calendar; + return fakeR.getId("string", "result_calendar"); } } diff --git a/src/android/LibraryProject/src/com/google/zxing/client/android/result/EmailAddressResultHandler.java b/src/android/LibraryProject/src/com/google/zxing/client/android/result/EmailAddressResultHandler.java index 563322a2..c94b6f7f 100644 --- a/src/android/LibraryProject/src/com/google/zxing/client/android/result/EmailAddressResultHandler.java +++ b/src/android/LibraryProject/src/com/google/zxing/client/android/result/EmailAddressResultHandler.java @@ -28,13 +28,14 @@ * @author dswitkin@google.com (Daniel Switkin) */ public final class EmailAddressResultHandler extends ResultHandler { - private static final int[] buttons = { - R.string.button_email, - R.string.button_add_contact - }; + private static int[] buttons; public EmailAddressResultHandler(Activity activity, ParsedResult result) { super(activity, result); + buttons = new int[]{ + fakeR.getId("string", "button_email"), + fakeR.getId("string", "button_add_contact") + }; } @Override @@ -67,6 +68,6 @@ public void handleButtonPress(int index) { @Override public int getDisplayTitle() { - return R.string.result_email_address; + return fakeR.getId("string", "result_email_address"); } } diff --git a/src/android/LibraryProject/src/com/google/zxing/client/android/result/GeoResultHandler.java b/src/android/LibraryProject/src/com/google/zxing/client/android/result/GeoResultHandler.java index 059f2cf0..422a4856 100644 --- a/src/android/LibraryProject/src/com/google/zxing/client/android/result/GeoResultHandler.java +++ b/src/android/LibraryProject/src/com/google/zxing/client/android/result/GeoResultHandler.java @@ -28,13 +28,14 @@ * @author dswitkin@google.com (Daniel Switkin) */ public final class GeoResultHandler extends ResultHandler { - private static final int[] buttons = { - R.string.button_show_map, - R.string.button_get_directions - }; + private static int[] buttons; public GeoResultHandler(Activity activity, ParsedResult result) { super(activity, result); + buttons = new int[]{ + fakeR.getId("string", "button_show_map"), + fakeR.getId("string", "button_get_directions") + }; } @Override @@ -62,6 +63,6 @@ public void handleButtonPress(int index) { @Override public int getDisplayTitle() { - return R.string.result_geo; + return fakeR.getId("string", "result_geo"); } } diff --git a/src/android/LibraryProject/src/com/google/zxing/client/android/result/ISBNResultHandler.java b/src/android/LibraryProject/src/com/google/zxing/client/android/result/ISBNResultHandler.java index fd89b4db..9b16ac08 100644 --- a/src/android/LibraryProject/src/com/google/zxing/client/android/result/ISBNResultHandler.java +++ b/src/android/LibraryProject/src/com/google/zxing/client/android/result/ISBNResultHandler.java @@ -30,15 +30,16 @@ * @author dswitkin@google.com (Daniel Switkin) */ public final class ISBNResultHandler extends ResultHandler { - private static final int[] buttons = { - R.string.button_product_search, - R.string.button_book_search, - R.string.button_search_book_contents, - R.string.button_custom_product_search - }; + private static int[] buttons; public ISBNResultHandler(Activity activity, ParsedResult result, Result rawResult) { super(activity, result, rawResult); + buttons = new int[]{ + fakeR.getId("string", "button_product_search"), + fakeR.getId("string", "button_book_search"), + fakeR.getId("string", "button_search_book_contents"), + fakeR.getId("string", "button_custom_product_search") + }; showGoogleShopperButton(new View.OnClickListener() { @Override public void onClick(View view) { @@ -79,6 +80,6 @@ public void handleButtonPress(int index) { @Override public int getDisplayTitle() { - return R.string.result_isbn; + return fakeR.getId("string", "result_isbn"); } } diff --git a/src/android/LibraryProject/src/com/google/zxing/client/android/result/ProductResultHandler.java b/src/android/LibraryProject/src/com/google/zxing/client/android/result/ProductResultHandler.java index d6f0e514..fa0e7a0a 100644 --- a/src/android/LibraryProject/src/com/google/zxing/client/android/result/ProductResultHandler.java +++ b/src/android/LibraryProject/src/com/google/zxing/client/android/result/ProductResultHandler.java @@ -30,14 +30,15 @@ * @author dswitkin@google.com (Daniel Switkin) */ public final class ProductResultHandler extends ResultHandler { - private static final int[] buttons = { - R.string.button_product_search, - R.string.button_web_search, - R.string.button_custom_product_search - }; + private static int[] buttons; public ProductResultHandler(Activity activity, ParsedResult result, Result rawResult) { super(activity, result, rawResult); + buttons = new int[]{ + fakeR.getId("string", "button_product_search"), + fakeR.getId("string", "button_web_search"), + fakeR.getId("string", "button_custom_product_search") + }; showGoogleShopperButton(new View.OnClickListener() { @Override public void onClick(View view) { @@ -75,6 +76,6 @@ public void handleButtonPress(int index) { @Override public int getDisplayTitle() { - return R.string.result_product; + return fakeR.getId("string", "result_product"); } } diff --git a/src/android/LibraryProject/src/com/google/zxing/client/android/result/ResultHandler.java b/src/android/LibraryProject/src/com/google/zxing/client/android/result/ResultHandler.java index d7cabab0..a2cf5672 100644 --- a/src/android/LibraryProject/src/com/google/zxing/client/android/result/ResultHandler.java +++ b/src/android/LibraryProject/src/com/google/zxing/client/android/result/ResultHandler.java @@ -40,6 +40,7 @@ import android.provider.ContactsContract; import android.util.Log; import android.view.View; +import com.google.zxing.FakeR; import java.util.Collection; import java.util.Locale; @@ -104,6 +105,8 @@ public void onClick(DialogInterface dialogInterface, int which) { } }; + protected static FakeR fakeR; + ResultHandler(Activity activity, ParsedResult result) { this(activity, result, null); } @@ -114,9 +117,11 @@ public void onClick(DialogInterface dialogInterface, int which) { this.rawResult = rawResult; this.customProductSearch = parseCustomSearchURL(); - // Make sure the Shopper button is hidden by default. Without this, scanning a product followed + fakeR = new FakeR(activity); + + // Make sure the Shopper button is hidden by default. Without this, scanning a product followed // by a QR Code would leave the button on screen among the QR Code actions. - View shopperButton = activity.findViewById(R.id.shopper_button); + View shopperButton = activity.findViewById(fakeR.getId("id", "shopper_button")); shopperButton.setVisibility(View.GONE); } @@ -171,7 +176,7 @@ public boolean areContentsSecure() { * @param listener The on click listener to install for this button. */ void showGoogleShopperButton(View.OnClickListener listener) { - View shopperButton = activity.findViewById(R.id.shopper_button); + View shopperButton = activity.findViewById(fakeR.getId("id", "shopper_button")); shopperButton.setVisibility(View.VISIBLE); shopperButton.setOnClickListener(listener); } @@ -307,7 +312,7 @@ private static int doToContractType(String typeString, String[] types, int[] val } final void shareByEmail(String contents) { - sendEmailFromUri("mailto:", null, activity.getString(R.string.msg_share_subject_line), + sendEmailFromUri("mailto:", null, activity.getString(fakeR.getId("string", "msg_share_subject_line")), contents); } @@ -328,7 +333,7 @@ final void sendEmailFromUri(String uri, String email, String subject, String bod } final void shareBySMS(String contents) { - sendSMSFromUri("smsto:", activity.getString(R.string.msg_share_subject_line) + ":\n" + + sendSMSFromUri("smsto:", activity.getString(fakeR.getId("string", "msg_share_subject_line")) + ":\n" + contents); } @@ -352,7 +357,7 @@ final void sendMMSFromUri(String uri, String subject, String body) { Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.parse(uri)); // The Messaging app needs to see a valid subject or else it will treat this an an SMS. if (subject == null || subject.length() == 0) { - putExtra(intent, "subject", activity.getString(R.string.msg_default_mms_subject)); + putExtra(intent, "subject", activity.getString(fakeR.getId("string", "msg_default_mms_subject"))); } else { putExtra(intent, "subject", subject); } @@ -451,11 +456,11 @@ final void openGoogleShopper(String query) { } else { // Otherwise offer to install it from Market. AlertDialog.Builder builder = new AlertDialog.Builder(activity); - builder.setTitle(R.string.msg_google_shopper_missing); - builder.setMessage(R.string.msg_install_google_shopper); - builder.setIcon(R.drawable.shopper_icon); - builder.setPositiveButton(R.string.button_ok, shopperMarketListener); - builder.setNegativeButton(R.string.button_cancel, null); + builder.setTitle(fakeR.getId("string", "msg_google_shopper_missing")); + builder.setMessage(fakeR.getId("string", "msg_install_google_shopper")); + builder.setIcon(fakeR.getId("drawable", "shopper_icon")); + builder.setPositiveButton(fakeR.getId("string", "button_ok"), shopperMarketListener); + builder.setNegativeButton(fakeR.getId("string", "button_cancel"), null); builder.show(); } } @@ -482,9 +487,9 @@ void launchIntent(Intent intent) { rawLaunchIntent(intent); } catch (ActivityNotFoundException e) { AlertDialog.Builder builder = new AlertDialog.Builder(activity); - builder.setTitle(R.string.app_name); - builder.setMessage(R.string.msg_intent_failed); - builder.setPositiveButton(R.string.button_ok, null); + builder.setTitle(fakeR.getId("string", "app_name")); + builder.setMessage(fakeR.getId("string", "msg_intent_failed")); + builder.setPositiveButton(fakeR.getId("string", "button_ok"), null); builder.show(); } } diff --git a/src/android/LibraryProject/src/com/google/zxing/client/android/result/SMSResultHandler.java b/src/android/LibraryProject/src/com/google/zxing/client/android/result/SMSResultHandler.java index 4c0ab9cd..b992a5d1 100644 --- a/src/android/LibraryProject/src/com/google/zxing/client/android/result/SMSResultHandler.java +++ b/src/android/LibraryProject/src/com/google/zxing/client/android/result/SMSResultHandler.java @@ -29,13 +29,14 @@ * @author dswitkin@google.com (Daniel Switkin) */ public final class SMSResultHandler extends ResultHandler { - private static final int[] buttons = { - R.string.button_sms, - R.string.button_mms - }; + private static int[] buttons; public SMSResultHandler(Activity activity, ParsedResult result) { super(activity, result); + buttons = new int[]{ + fakeR.getId("string", "button_sms"), + fakeR.getId("string", "button_mms") + }; } @Override @@ -79,6 +80,6 @@ public CharSequence getDisplayContents() { @Override public int getDisplayTitle() { - return R.string.result_sms; + return fakeR.getId("string", "result_sms"); } } diff --git a/src/android/LibraryProject/src/com/google/zxing/client/android/result/TelResultHandler.java b/src/android/LibraryProject/src/com/google/zxing/client/android/result/TelResultHandler.java index 325eb6b9..ccd1038a 100644 --- a/src/android/LibraryProject/src/com/google/zxing/client/android/result/TelResultHandler.java +++ b/src/android/LibraryProject/src/com/google/zxing/client/android/result/TelResultHandler.java @@ -29,13 +29,14 @@ * @author dswitkin@google.com (Daniel Switkin) */ public final class TelResultHandler extends ResultHandler { - private static final int[] buttons = { - R.string.button_dial, - R.string.button_add_contact - }; + private static int[] buttons; public TelResultHandler(Activity activity, ParsedResult result) { super(activity, result); + buttons = new int[]{ + fakeR.getId("string", "button_dial"), + fakeR.getId("string", "button_add_contact") + }; } @Override @@ -77,6 +78,6 @@ public CharSequence getDisplayContents() { @Override public int getDisplayTitle() { - return R.string.result_tel; + return fakeR.getId("string", "result_tel"); } } diff --git a/src/android/LibraryProject/src/com/google/zxing/client/android/result/TextResultHandler.java b/src/android/LibraryProject/src/com/google/zxing/client/android/result/TextResultHandler.java index bccf882a..5f3349e4 100644 --- a/src/android/LibraryProject/src/com/google/zxing/client/android/result/TextResultHandler.java +++ b/src/android/LibraryProject/src/com/google/zxing/client/android/result/TextResultHandler.java @@ -29,15 +29,16 @@ */ public final class TextResultHandler extends ResultHandler { - private static final int[] buttons = { - R.string.button_web_search, - R.string.button_share_by_email, - R.string.button_share_by_sms, - R.string.button_custom_product_search, - }; + private static int[] buttons; public TextResultHandler(Activity activity, ParsedResult result, Result rawResult) { super(activity, result, rawResult); + buttons = new int[]{ + fakeR.getId("string", "button_web_search"), + fakeR.getId("string", "button_share_by_email"), + fakeR.getId("string", "button_share_by_sms"), + fakeR.getId("string", "button_custom_product_search"), + }; } @Override @@ -71,6 +72,6 @@ public void handleButtonPress(int index) { @Override public int getDisplayTitle() { - return R.string.result_text; + return fakeR.getId("string", "result_text"); } } diff --git a/src/android/LibraryProject/src/com/google/zxing/client/android/result/URIResultHandler.java b/src/android/LibraryProject/src/com/google/zxing/client/android/result/URIResultHandler.java index 7c6cd630..de374c3f 100644 --- a/src/android/LibraryProject/src/com/google/zxing/client/android/result/URIResultHandler.java +++ b/src/android/LibraryProject/src/com/google/zxing/client/android/result/URIResultHandler.java @@ -37,15 +37,16 @@ public final class URIResultHandler extends ResultHandler { "otpauth:" }; - private static final int[] buttons = { - R.string.button_open_browser, - R.string.button_share_by_email, - R.string.button_share_by_sms, - R.string.button_search_book_contents, - }; + private static int[] buttons; public URIResultHandler(Activity activity, ParsedResult result) { super(activity, result); + buttons = new int[]{ + fakeR.getId("string", "button_open_browser"), + fakeR.getId("string", "button_share_by_email"), + fakeR.getId("string", "button_share_by_sms"), + fakeR.getId("string", "button_search_book_contents"), + }; } @Override @@ -83,7 +84,7 @@ public void handleButtonPress(int index) { @Override public int getDisplayTitle() { - return R.string.result_uri; + return fakeR.getId("string", "result_uri"); } @Override diff --git a/src/android/LibraryProject/src/com/google/zxing/client/android/result/WifiResultHandler.java b/src/android/LibraryProject/src/com/google/zxing/client/android/result/WifiResultHandler.java index 04dcfd29..f1bdca67 100644 --- a/src/android/LibraryProject/src/com/google/zxing/client/android/result/WifiResultHandler.java +++ b/src/android/LibraryProject/src/com/google/zxing/client/android/result/WifiResultHandler.java @@ -53,7 +53,7 @@ public int getButtonCount() { @Override public int getButtonText(int index) { - return R.string.button_wifi; + return fakeR.getId("string", "button_wifi"); } @Override @@ -61,7 +61,7 @@ public void handleButtonPress(int index) { if (index == 0) { WifiParsedResult wifiResult = (WifiParsedResult) getResult(); WifiManager wifiManager = (WifiManager) getActivity().getSystemService(Context.WIFI_SERVICE); - Toast.makeText(getActivity(), R.string.wifi_changing_network, Toast.LENGTH_LONG).show(); + Toast.makeText(getActivity(), fakeR.getId("string", "wifi_changing_network"), Toast.LENGTH_LONG).show(); taskExec.execute(new WifiConfigManager(wifiManager), wifiResult); parent.restartPreviewAfterDelay(0L); } @@ -72,15 +72,15 @@ public void handleButtonPress(int index) { public CharSequence getDisplayContents() { WifiParsedResult wifiResult = (WifiParsedResult) getResult(); StringBuilder contents = new StringBuilder(50); - String wifiLabel = parent.getString(R.string.wifi_ssid_label); + String wifiLabel = parent.getString(fakeR.getId("string", "wifi_ssid_label")); ParsedResult.maybeAppend(wifiLabel + '\n' + wifiResult.getSsid(), contents); - String typeLabel = parent.getString(R.string.wifi_type_label); + String typeLabel = parent.getString(fakeR.getId("string", "wifi_type_label")); ParsedResult.maybeAppend(typeLabel + '\n' + wifiResult.getNetworkEncryption(), contents); return contents.toString(); } @Override public int getDisplayTitle() { - return R.string.result_wifi; + return fakeR.getId("string", "result_wifi"); } } \ No newline at end of file diff --git a/src/android/LibraryProject/src/com/google/zxing/client/android/result/supplement/BookResultInfoRetriever.java b/src/android/LibraryProject/src/com/google/zxing/client/android/result/supplement/BookResultInfoRetriever.java index c93d4dce..ead800a9 100644 --- a/src/android/LibraryProject/src/com/google/zxing/client/android/result/supplement/BookResultInfoRetriever.java +++ b/src/android/LibraryProject/src/com/google/zxing/client/android/result/supplement/BookResultInfoRetriever.java @@ -22,6 +22,7 @@ import android.content.Context; import android.widget.TextView; +import com.google.zxing.FakeR; import com.google.zxing.client.android.HttpHelper; import com.google.zxing.client.android.LocaleManager; import com.google.zxing.client.android.R; @@ -45,7 +46,7 @@ final class BookResultInfoRetriever extends SupplementalInfoRetriever { BookResultInfoRetriever(TextView textView, String isbn, HistoryManager historyManager, Context context) { super(textView, historyManager); this.isbn = isbn; - this.source = context.getString(R.string.msg_google_books); + this.source = context.getString(FakeR.getId(context, "string", "msg_google_books")); this.context = context; } diff --git a/src/android/LibraryProject/src/com/google/zxing/client/android/result/supplement/ProductResultInfoRetriever.java b/src/android/LibraryProject/src/com/google/zxing/client/android/result/supplement/ProductResultInfoRetriever.java index e5944a2b..4f2bcddc 100644 --- a/src/android/LibraryProject/src/com/google/zxing/client/android/result/supplement/ProductResultInfoRetriever.java +++ b/src/android/LibraryProject/src/com/google/zxing/client/android/result/supplement/ProductResultInfoRetriever.java @@ -19,6 +19,7 @@ import android.content.Context; import android.text.Html; import android.widget.TextView; +import com.google.zxing.FakeR; import com.google.zxing.client.android.HttpHelper; import com.google.zxing.client.android.R; import com.google.zxing.client.android.history.HistoryManager; @@ -43,7 +44,7 @@ final class ProductResultInfoRetriever extends SupplementalInfoRetriever { ProductResultInfoRetriever(TextView textView, String productID, HistoryManager historyManager, Context context) { super(textView, historyManager); this.productID = productID; - this.source = context.getString(R.string.msg_google_product); + this.source = context.getString(FakeR.getId(context, "string", "msg_google_product")); this.context = context; } diff --git a/src/android/LibraryProject/src/com/google/zxing/client/android/result/supplement/URIResultInfoRetriever.java b/src/android/LibraryProject/src/com/google/zxing/client/android/result/supplement/URIResultInfoRetriever.java index 6e360ac2..74d69fd7 100644 --- a/src/android/LibraryProject/src/com/google/zxing/client/android/result/supplement/URIResultInfoRetriever.java +++ b/src/android/LibraryProject/src/com/google/zxing/client/android/result/supplement/URIResultInfoRetriever.java @@ -18,6 +18,7 @@ import android.content.Context; import android.widget.TextView; +import com.google.zxing.FakeR; import com.google.zxing.client.android.HttpHelper; import com.google.zxing.client.android.history.HistoryManager; import com.google.zxing.client.android.R; @@ -36,7 +37,7 @@ final class URIResultInfoRetriever extends SupplementalInfoRetriever { URIResultInfoRetriever(TextView textView, URIParsedResult result, HistoryManager historyManager, Context context) { super(textView, historyManager); - redirectString = context.getString(R.string.msg_redirect); + redirectString = context.getString(FakeR.getId(context, "string", "msg_redirect")); this.result = result; } diff --git a/src/android/LibraryProject/src/com/google/zxing/client/android/share/BookmarkAdapter.java b/src/android/LibraryProject/src/com/google/zxing/client/android/share/BookmarkAdapter.java index 44b67475..e47fe283 100644 --- a/src/android/LibraryProject/src/com/google/zxing/client/android/share/BookmarkAdapter.java +++ b/src/android/LibraryProject/src/com/google/zxing/client/android/share/BookmarkAdapter.java @@ -26,6 +26,7 @@ import android.widget.BaseAdapter; import android.widget.LinearLayout; import android.widget.TextView; +import com.google.zxing.FakeR; /** * A custom adapter designed to fetch bookmarks from a cursor. Before Honeycomb we used @@ -39,7 +40,9 @@ final class BookmarkAdapter extends BaseAdapter { private final Context context; private final Cursor cursor; + private static FakeR fakeR; BookmarkAdapter(Context context, Cursor cursor) { + fakeR = new FakeR(context); this.context = context; this.cursor = cursor; } @@ -67,15 +70,15 @@ public View getView(int index, View view, ViewGroup viewGroup) { layout = (LinearLayout) view; } else { LayoutInflater factory = LayoutInflater.from(context); - layout = (LinearLayout) factory.inflate(R.layout.bookmark_picker_list_item, viewGroup, false); + layout = (LinearLayout) factory.inflate(fakeR.getId("layout", "bookmark_picker_list_item"), viewGroup, false); } if (!cursor.isClosed()) { cursor.moveToPosition(index); String title = cursor.getString(BookmarkPickerActivity.TITLE_COLUMN); - ((TextView) layout.findViewById(R.id.bookmark_title)).setText(title); + ((TextView) layout.findViewById(fakeR.getId("id", "bookmark_title"))).setText(title); String url = cursor.getString(BookmarkPickerActivity.URL_COLUMN); - ((TextView) layout.findViewById(R.id.bookmark_url)).setText(url); + ((TextView) layout.findViewById(fakeR.getId("id", "bookmark_url"))).setText(url); } // Otherwise... just don't update as the object is shutting down return layout; } diff --git a/src/android/LibraryProject/src/com/google/zxing/client/android/share/ShareActivity.java b/src/android/LibraryProject/src/com/google/zxing/client/android/share/ShareActivity.java index 67f10a17..ca7a9f62 100755 --- a/src/android/LibraryProject/src/com/google/zxing/client/android/share/ShareActivity.java +++ b/src/android/LibraryProject/src/com/google/zxing/client/android/share/ShareActivity.java @@ -36,6 +36,7 @@ import android.view.View; import android.widget.Button; import android.widget.TextView; +import com.google.zxing.FakeR; /** * Barcode Scanner can share data like contacts and bookmarks by displaying a QR Code on screen, @@ -53,6 +54,8 @@ public final class ShareActivity extends Activity { private Button clipboardButton; + private static FakeR fakeR; + private final Button.OnClickListener contactListener = new Button.OnClickListener() { @Override public void onClick(View v) { @@ -119,14 +122,15 @@ private void launchSearch(String text) { @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); - setContentView(R.layout.share); + fakeR = new FakeR(this); + setContentView(fakeR.getId("layout", "share")); - findViewById(R.id.share_contact_button).setOnClickListener(contactListener); - findViewById(R.id.share_bookmark_button).setOnClickListener(bookmarkListener); - findViewById(R.id.share_app_button).setOnClickListener(appListener); - clipboardButton = (Button) findViewById(R.id.share_clipboard_button); + findViewById(fakeR.getId("id", "share_contact_button")).setOnClickListener(contactListener); + findViewById(fakeR.getId("id", "share_bookmark_button")).setOnClickListener(bookmarkListener); + findViewById(fakeR.getId("id", "share_app_button")).setOnClickListener(appListener); + clipboardButton = (Button) findViewById(fakeR.getId("id", "share_clipboard_button")); clipboardButton.setOnClickListener(clipboardListener); - findViewById(R.id.share_text_view).setOnKeyListener(textListener); + findViewById(fakeR.getId("id", "share_text_view")).setOnKeyListener(textListener); } @Override diff --git a/src/android/README.md b/src/android/README.md new file mode 100644 index 00000000..59c16fac --- /dev/null +++ b/src/android/README.md @@ -0,0 +1,74 @@ +Building Android +================ + +## Building localy ## + +Steps if you have Netbeans setup for Android or want to do that. + +1. Setup Netbeans for Android development. + 1. Download and install JDK (be sure to set JAVA_HOME - it will be important for the SDK). + 2. Download and install Netebeans. + 3. Download and install Android SDK (do NOT use ADT boundle). + 4. Download and install NBAndroid: http://www.nbandroid.org/p/installation.html + 5. Set path of Android SDK in Netbeans (for installation for all users this is: ```c:\Program Files (x86)\Android\android-sdk\```). + +2. Install Phonegap: + + 1. Add to Windows PATH Android SDK tools: ```;C:\...[android-sdk]\platform-tools;C:\...[android-sdk]\tools``` + 2. Copy ANT home from Netbeans and add it your PATH too. + 3. Add Java bin to PATH: ```;%JAVA_HOME%\bin;%ANT_HOME%\bin``` + +3. Install cordova command line + 1. Install node.js. + 2. Install cordova command line: + ``` + npm install -g cordova + ``` + +4. Create and build test project to check command line tools: + ``` + cordova create hello com.example.hello "Hello World" + cd hello + cordova platform add android + cordova build + ``` + +5. To open project in Netbeans just use Open Project and in the folder you created the project navigate to platforms\android. + +6. Add the plugin following instructions from this page: https://github.com/phonegap/phonegap-plugins/tree/master/Android/BarcodeScanner + +## Preparing for PhoneGap Build ## + +The process may vary depending on version of Zxing project, but base steps should be the same. + +1. Get latest zxing-android project and create a LibraryProject from that: + 1. Checked out zxing-android from SVN (http://zxing.googlecode.com/svn/trunk/). + 2. Overlayed the source from zxing-core. + 3. Set to library project. + 4. Change intent names to avoid conflict with ZXing app. + 5. Remove two lines from AndroidManifest.xml to avoid shortcuts being created. +2. Update plugin.xml with any needed resources (you can use ```plugin.xml.generate.php``` to generate some stuff for Android). +3. Refactor LibraryProject for usage with PGB: + 1. Commented out call to showHelpOnFirstLaunch (it will probably not work anyway). + 2. Replace R class with FakeR class calls (this is needed beacuse R class will be in a different namespace). + 3. Add FakeR initialization in each class it was added (note that if some classes extened other then you might want to add a protected fakeR variable to their parent - see e.g. ResultHandler class and it's children). +4. Build LibraryProject, rename and copy it. + +## Building with plugman ## + +[Plugman](https://github.com/apache/cordova-plugman) is a Node.js tool used by PG Build. + +Workflow for creating and building example project with the plugin: +1. Create and build example project: +``` +cordova create hello com.example.hello "Hello World" +cd hello +cordova platform add android +cordova build +``` +2. Copy plugin files to "hello\plugins\barcodescanner\". + +3. Install the plugin (current dir. being "hello"): +plugman --plugins_dir plugins --plugin barcodescanner --platform android --project platforms\android + +4. Build & deploy Android project with whatever Android IDE (or ANT + ADK tools). diff --git a/src/android/com.google.zxing.client.android.captureactivity.jar b/src/android/com.google.zxing.client.android.captureactivity.jar index 0aebef69..ec06ea61 100644 Binary files a/src/android/com.google.zxing.client.android.captureactivity.jar and b/src/android/com.google.zxing.client.android.captureactivity.jar differ