Created
August 2, 2014 16:08
-
-
Save rusfearuth/d064ea6eb0b5497285a5 to your computer and use it in GitHub Desktop.
Example of usage zxing-lib-extended
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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