bdswiss erfahrung

Welcome, Guest
Username: Password: Remember me

TOPIC: Dynamically create an ONYX Fragment

Dynamically create an ONYX Fragment 07 Jul 2014 18:56 #9

  • cwheatley
  • cwheatley's Avatar
  • Offline
  • Administrator
  • Posts: 9
  • Thank you received: 1
  • Karma: 0
Here are some code snippets on how to dynamically create an OnyxFragment:

First, create a layout such as the following that contains a FrameLayout.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/base_layout_relative_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#000000" >

    <FrameLayout 
        android:id="@+id/fragment_content"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >

    </FrameLayout>

</RelativeLayout>

Then, inflate this layout in a Fragment, in the Fragment's onCreateView:
@Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
    	if (null != getActivity().getActionBar()) {
        	getActivity().getActionBar().hide();
    	}     
  View v = inflater.inflate(R.layout.base_layout, container, false);
        return v;
    }

Then, inside of the fragment's onResume() method, you can add the OnyxFragment dynamically.
@Override 
    public void onResume() {
        // Add the OnyxFragment programatically
    mFragment = new OnyxFragment();
        FragmentTransaction ft = getFragmentManager().beginTransaction();
        ft.replace(R.id.fragment_content, mFragment, TAG);
        ft.commit();

        mFragment.startOneShotAutoCapture();
        mFragment.setProcessingCallbacks(null, null, mEnhancedBitmapCallback,
            mFingerprintTemplateCallback);
        mFragment.setErrorCallback(new ErrorCallbackUtil()
            .getErrorCallback(mWizardActivity, null,
            mFragment, null, mAnim));
	    mFragment.setCaptureAnimationCallback(mCaptureAnimationCallback);
	    mFragment.setReticleScale(bestEnrollmentMetric.getReticleScale());
    }

You can then specify the callbacks you'd like to receive:
private CaptureAnimationCallback mCaptureAnimationCallback = 
    new CaptureAnimationCallback() {

    @Override
    public void onCapturing(boolean arg0) {
        mSpinnerView.setVisibility(View.VISIBLE);
        mAnim = (AnimationDrawable) mSpinnerView.getBackground();
        mAnim.start();
    }
};

private EnhancedBitmapCallback mEnhancedBitmapCallback = new EnhancedBitmapCallback() {

    @Override
    public void onEnhancedBitmapReady(Bitmap enhancedBitmap, double focusQuality) {
        mFingerprintView.setImageBitmap(enhancedBitmap);
        mFingerprintView.startAnimation(mFadeIn);
    }
};

public void setBitmapNumber() {
	if (mBitmapArray.size() < 11) {
		abTv.setText(Integer.toString(mBitmapArray.size()) + "/10");
		abTv.setVisibility(View.VISIBLE);
    }
}

private RawBitmapCallback mRawBitmapCallback = new RawBitmapCallback() {

	@Override
    public void onRawBitmapReady(Bitmap rawBitmap) {
    	mBitmapArray.add(rawBitmap);
    	setBitmapNumber();

    	if (mBitmapArray.size() == 10) {        		
        	    createCongratulationsDialog();
        }
    }
};

Finally, the callback FingerprintTemplateCallback() returns the generated fingerprint template that is used for matching.
private FingerprintTemplateCallback mTemplateCallback = 
    new FingerprintTemplateCallback() {

    @Override
    public void onFingerprintTemplateReady(FingerprintTemplate 
            fingerprintTemplate) {
        mCurrentTemplate = fingerprintTemplate;

        if (mEnrolledEnrollmentMetric != null) {
            VerifyTask verifyTask = new VerifyTask(getApplicationContext());
            verifyTask.execute(mCurrentTemplate,
            mEnrolledEnrollmentMetric.getFingerprintTemplate());
        }
    }
};
The administrator has disabled public write access.
Time to create page: 0.059 seconds