-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Conversation
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!
On Fri, Sep 15, 2017 at 5:24 PM googlebot ***@***.***> wrote:
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/
<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 <https://cla.developers.google.com/clas> and verify
that your email is set on your git commits
<https://help.github.com/articles/setting-your-email-in-git/>.
- 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.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#267 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ADwXHHOvPhdHw2yA914opRDlC52x45Bsks5sixVWgaJpZM4PZpCB>
.
--
ASH
|
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> { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) { | ||
|
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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> { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
private GraphicOverlay<BarcodeGraphic> mGraphicOverlay; | ||
public class BarcodeTrackerFactory implements MultiProcessor.Factory<Barcode> { | ||
private GraphicOverlay<BarcodeGraphic> graphicOverlay; | ||
Context context; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
private-access please.
There was a problem hiding this comment.
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); | ||
|
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this.mUpdateBarcodeListener = (UpdateBarcodeListener) context;
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
9a5c618
to
78d1899
Compare
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. 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; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
…ng interface too BarcodeGraphicTracker
78d1899
to
fe42d73
Compare
Thanks for calling out the variable names. I updated my pull request accordingly. |
I merged the pull request, thank you for the contribution! |
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