Skip to content

Adding ability to consume barcodes in BarcodeCaptureActivity #267

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 29, 2017

Conversation

adam-hurwitz
Copy link
Contributor

@adam-hurwitz adam-hurwitz commented Sep 16, 2017

Hi Google Team!

I tinkered with the camera’s barcode detection and scanning capabilities in order to create the ScannerApp sample showcasing smooth transitioning between barcode scanning modes while keeping the camera running. This results in seamless toggling between barcode types which is also useful for switching between any type of camera detection.

This commit reflects a portion of the modifications I made to the Google Vision sample app in order to return the barcode results on the Activity level via an interface. This allows seamless toggling between scanner types in the ScannerApp because then the returned data is passed down to the child ViewPager to show for the corresponding scanner view.

Here is a more in-depth breakdown of this use case. I have conducted manual QA testing and do not see any UI bugs or errors in the logs. I'd love your feedback.

Thanks!

Adam

@googlebot
Copy link

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed, please reply here (e.g. I signed it!) and we'll verify. Thanks.


  • If you've already signed a CLA, it's possible we don't have your GitHub username or you're using a different email address. Check your existing CLA data and verify that your email is set on your git commits.
  • If your company signed a CLA, they designated a Point of Contact who decides which employees are authorized to participate. You may need to contact the Point of Contact for your company and ask to be added to the group of authorized contributors. If you don't know who your Point of Contact is, direct the project maintainer to go/cla#troubleshoot.
  • In order to pass this check, please resolve this problem and have the pull request author add another comment and the bot will run again.

@adam-hurwitz
Copy link
Contributor Author

adam-hurwitz commented Sep 16, 2017 via email

@googlebot
Copy link

CLAs look good, thanks!

@@ -26,25 +29,43 @@
* to an overlay, update the graphics as the item changes, and remove the graphics when the item
* goes away.
*/
class BarcodeGraphicTracker extends Tracker<Barcode> {
public class BarcodeGraphicTracker extends Tracker<Barcode> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this still be package-private?

Copy link
Contributor Author

@adam-hurwitz adam-hurwitz Sep 22, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be public in order for an Activity to implement the UpdateBarcodeListener interface within BarcodeGraphicTracker.

BarcodeGraphicTracker(GraphicOverlay<BarcodeGraphic> overlay, BarcodeGraphic graphic) {
mOverlay = overlay;
mGraphic = graphic;
public UpdateBarcodeListener updateBarcodeListener;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove the blank line above, make the variable private-access, and rename the variable to mUpdateBarcodeListener here and below.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

*/
@Override
public void onNewItem(int id, Barcode item) {

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this redundant blank line, as well as the one at the end of this method.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


public interface UpdateBarcodeListener {
@UiThread
void getBarcode(Barcode barcode);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add Javadoc for this method.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

mGraphic.setId(id);

updateBarcodeListener.getBarcode(item);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The name "getBarcode" is kind of confusing. If it's only called when a new Barcode is detected, please consider rename it to "onNewBarcode" or something more self explanatory.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@@ -24,17 +26,22 @@
* Factory for creating a tracker and associated graphic to be associated with a new barcode. The
* multi-processor uses this factory to create barcode trackers as needed -- one for each barcode.
*/
class BarcodeTrackerFactory implements MultiProcessor.Factory<Barcode> {
private GraphicOverlay<BarcodeGraphic> mGraphicOverlay;
public class BarcodeTrackerFactory implements MultiProcessor.Factory<Barcode> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please keep it package-private if possible.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In order to keep a project's classes organized the BarcodeTrackerFactory is public so it can live in a separate package for the Camera utilities and then the Activities / Fragments can access these methods from a separate package.

In the sample below, the BarcodeActivity implements BarcodeGraphicTracker and BarcodeTrackerFactory from a parent package which is why they are public.

screen shot 2017-09-22 at 9 53 22 am

private GraphicOverlay<BarcodeGraphic> mGraphicOverlay;
public class BarcodeTrackerFactory implements MultiProcessor.Factory<Barcode> {
private GraphicOverlay<BarcodeGraphic> graphicOverlay;
Context context;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

private-access please.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

}

@Override
public Tracker<Barcode> create(Barcode barcode) {
BarcodeGraphic graphic = new BarcodeGraphic(mGraphicOverlay);
return new BarcodeGraphicTracker(mGraphicOverlay, graphic);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this blank line and the blank line at the end of the method.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

this.mGraphic = mGraphic;

if (context instanceof UpdateBarcodeListener) {
updateBarcodeListener = (UpdateBarcodeListener) context;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this.mUpdateBarcodeListener = (UpdateBarcodeListener) context;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@@ -57,7 +57,7 @@
* rear facing camera. During detection overlay graphics are drawn to indicate the position,
* size, and ID of each barcode.
*/
public final class BarcodeCaptureActivity extends AppCompatActivity {
public final class BarcodeCaptureActivity extends AppCompatActivity implements BarcodeGraphicTracker.UpdateBarcodeListener {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think "BarcodeUpdateListener" is more nature and consistent with "BarcodeCaptureActivity", "BarcodeGraphicTracker".

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@adam-hurwitz
Copy link
Contributor Author

Hi Yulong,

Thank you for the code review! I've made all of the suggested revisions above except for the public vs. package-private adjustment in order to keep the UI and Camera logic in separate packages.

For instance, in order to keep a project's classes organized the BarcodeTrackerFactory is public so it can live in a separate package for the Camera utilities and then the Activities / Fragments can access these methods from a separate package.

In the sample below, the BarcodeActivity implements BarcodeGraphicTracker and BarcodeTrackerFactory from a parent package which is why they are public.

screen shot 2017-09-22 at 9 53 22 am

Let me know if any further changes need to be made in order to accept the pull request.

Have a great weekend!

Adam

@@ -25,16 +27,19 @@
* multi-processor uses this factory to create barcode trackers as needed -- one for each barcode.
*/
class BarcodeTrackerFactory implements MultiProcessor.Factory<Barcode> {
private GraphicOverlay<BarcodeGraphic> mGraphicOverlay;
private GraphicOverlay<BarcodeGraphic> graphicOverlay;
private Context context;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you accidentally renamed the mGraphicOverlay variable. Can you change it back and also rename context to mContext to be consistent with the rest of the code?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@adam-hurwitz
Copy link
Contributor Author

Thanks for calling out the variable names. I updated my pull request accordingly.

@liuyl liuyl merged commit 2ce3132 into googlesamples:master Sep 29, 2017
@liuyl
Copy link
Contributor

liuyl commented Sep 29, 2017

I merged the pull request, thank you for the contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants