Skip to content

Instantly share code, notes, and snippets.

@rusfearuth
Created August 2, 2014 16:08
Show Gist options
  • Save rusfearuth/d064ea6eb0b5497285a5 to your computer and use it in GitHub Desktop.
Save rusfearuth/d064ea6eb0b5497285a5 to your computer and use it in GitHub Desktop.
Example of usage zxing-lib-extended
public class BaseScannerActivity extends FragmentActivity
implements DecodeCallback
{
private ZXingFragment mZx;
@Override
public void onCreate(Bundle aSavedInstanceState)
{
super.onCreate(aSavedInstanceState);
setContentView(R.layout.activity_code_scanner);
addFragment(R.id.flScanner, ZXingFragment.class, null, false);
}
@Override
public void onPostCreate(Bundle aSavedInstanceState)
{
super.onPostCreate(aSavedInstanceState);
mZx = (ZXingFragment) getSupportFragmentManager().findFragmentById(R.id.flScanner);
mZx.setDecodeCallback(this);
}
@Override
public void handleBarcode(Result aResult, Bitmap aBarcode, float aScaleFactor)
{
Toast.makeText(this, aResult.getText(), Toast.LENGTH_LONG).show();
}
private void addFragment(int aTargetId, Class<? extends Fragment> aFragmentClass, Bundle aArgs, boolean aToBaskStack)
{
FragmentManager manager = getSupportFragmentManager();
FragmentTransaction transaction = manager.beginTransaction();
if (aToBaskStack)
{
transaction.addToBackStack(null);
}
else
{
Fragment fragment = manager.findFragmentById(aTargetId);
if (fragment != null)
transaction.remove(fragment);
}
transaction.add(aTargetId, Fragment.instantiate(this, aFragmentClass.getName(), aArgs));
transaction.commit();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment