cameraview in nativeviewhost

Are there any known issues with embedding a native camera view in a nativeviewhost?

I already have it working
i’ve been trying to port the zbar scanner view over but everything works except the fact that instead of seeing a cameraview in the background of the scanner its all white. Would appreciate it if someone could help me to get this working.

My guess is may have something to do with the application lifecycle but im fairly new to fuse and my understanding of the internals are limited.

outcome after attempting to port

expected outcome

Uploading file...

Uno code used to get result

    using Uno.Collections;
    using Fuse;
    using Uno;
    using Uno.UX;
    using Fuse.Platform;
    using Uno.Permissions;

    using Uno.Compiler.ExportTargetInterop;
    using Fuse.Controls.Native.Android;
	
	[Require("AndroidManifest.RootElement", "<uses-feature android:name=\"android.hardware.camera\"/>")]
	[Require("AndroidManifest.RootElement", "<uses-feature android:name=\"android.hardware.camera.autofocus\"/>")]
	[Require("Gradle.Dependency.Compile", "me.dm7.barcodescanner:zbar:1.9")]
	[Require("Gradle.Dependency.Compile", "me.dm7.barcodescanner:zxing:1.9")]
	[Require("Gradle.Dependency.Compile", "com.android.support:support-v4:25.1.0")]
	[Require("Gradle.Repository","mavenCentral()")]
	[extern(Android) ForeignInclude(Language.Java, "android.content.Intent")]
	[extern(Android) ForeignInclude(Language.Java, "android.support.v4.app.ActivityCompat")]
	[extern(Android) ForeignInclude(Language.Java, "android.Manifest")]
	[extern(Android) ForeignInclude(Language.Java, "android.widget.Toast")]
	[extern(Android) ForeignInclude(Language.Java, "android.widget.FrameLayout")]
	[extern(Android) ForeignInclude(Language.Java, "android.view.ViewGroup")]
	[extern(Android) ForeignInclude(Language.Java, "android.view.Gravity")]
	[extern(Android) ForeignInclude(Language.Java, "android.util.Log")]
	[extern(Android) ForeignInclude(Language.Java, "net.sourceforge.zbar.Symbol")]
	[extern(Android) ForeignInclude(Language.Java, "com.fuse.Activity")]
	[extern(Android) ForeignInclude(Language.Java, "me.dm7.barcodescanner.zbar.ZBarScannerView")]
	[extern(Android) ForeignInclude(Language.Java, "me.dm7.barcodescanner.zxing.ZXingScannerView")]
	[extern(Android) ForeignInclude(Language.Java, "me.dm7.barcodescanner.zbar.Result")]
	[extern(Android) ForeignInclude(Language.Java, "me.dm7.barcodescanner.zbar.BarcodeFormat")]
	[extern(Android) ForeignInclude(Language.Java, "java.util.ArrayList")]
	[extern(Android) ForeignInclude(Language.Java, "java.util.List")]

	extern(Android) public class AndroidQrScanner : LeafView, QrView.IScanner
	{
		static Java.Object _Qr;
	
		 public int Width
        {
            get { return Width; }
            set { Width = 400; }
        }

         public int Height
        {
            get { return Height; }
            set { Height = 400; }
        }
        
		[UXConstructor]
		public AndroidQrScanner() : base(Create()){
			Lifecycle.Started += Started;
		    Lifecycle.EnteringInteractive += OnEnteringInteractive;
		    Lifecycle.ExitedInteractive += OnExitedInteractive;
		    Lifecycle.ExitedInteractive += OnExitedInteractive;
		}

		[Foreign(Language.Java)]
		extern(Android) void Started(ApplicationState state)
		@{
		    
	        if (ActivityCompat.shouldShowRequestPermissionRationale(Activity.getRootActivity(), Manifest.permission.CAMERA)){
	            Toast.makeText(Activity.getRootActivity(), "Camera permission needed. Please allow in App Settings for additional functionality.", Toast.LENGTH_LONG).show();
	        } else {
	            ActivityCompat.requestPermissions(Activity.getRootActivity(),new String[]{Manifest.permission.CAMERA},3);
	        }
    
		@}

		extern(Android) void OnPermissionsPermitted(PlatformPermission p)
		{
			debug_log  "Permissions allowed" + p ;
		}

		extern(Android) void OnPermissionsRejected(Exception e)
		{
			debug_log "PermissionDenied " + e;
		}



		[Foreign(Language.Java)]
		extern(Android) void OnEnteringInteractive(ApplicationState state)
		@{
		    ZBarScannerView mScannerView = (ZBarScannerView) @{_Qr:Get()};
		    mScannerView.setResultHandler( new ZBarScannerView.ResultHandler(){
						  @Override
				    public void handleResult(me.dm7.barcodescanner.zbar.Result rawResult) {
				        // Do something with the result here
				        Log.v("RESULTS", rawResult.getContents()); // Prints scan results
				        Log.v("FORMAT", rawResult.getBarcodeFormat().getName()); // Prints the scan format (qrcode, pdf417 etc.)

				        // If you would like to resume scanning, call this method below:

				        @{LogResults(string,string):Call(rawResult.getContents(),  rawResult.getBarcodeFormat().toString())};

				      }
        	});
		    mScannerView.startCamera();
		@}

		[Foreign(Language.Java)]
		extern(Android) void OnExitedInteractive(ApplicationState state)
		@{
			ZBarScannerView mScannerView = (ZBarScannerView) @{_Qr:Get()};
		    mScannerView.stopCamera();
		@}
	
	
		[Foreign(Language.Java)]
		extern(Android) static Java.Object Create()
		@{
			List<BarcodeFormat> barcodeFormats = new ArrayList<>();

			barcodeFormats.add(BarcodeFormat.getFormatById(Symbol.QRCODE));
			
        	FrameLayout lay = new FrameLayout(@(Activity.Package).@(Activity.Name).GetRootActivity());
	        FrameLayout.LayoutParams layoutparams=new FrameLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,ViewGroup.LayoutParams.FILL_PARENT,Gravity.CENTER_HORIZONTAL|Gravity.CENTER_VERTICAL);
	        lay.setLayoutParams(layoutparams);

	        FrameLayout lay2 = new FrameLayout(@(Activity.Package).@(Activity.Name).GetRootActivity());
	        FrameLayout.LayoutParams layoutparams2=new FrameLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,ViewGroup.LayoutParams.FILL_PARENT,Gravity.CENTER_HORIZONTAL|Gravity.CENTER_VERTICAL);
	        lay2.setLayoutParams(layoutparams2);


	        ZBarScannerView mScannerView = new ZBarScannerView(@(Activity.Package).@(Activity.Name).GetRootActivity());
	        mScannerView.setFlash(true);
        	mScannerView.setAutoFocus(true);
	        lay2.addView(mScannerView);

	        

	        @{_Qr:Set(mScannerView)};
			return lay2;

		@}

		private static void LogResults(string results, string format){
			debug_log results;
			debug_log format;
		}
	}

	  extern(!Android) public class AndroidQrScanner
    {
    }

the same thing in native Java

package com.example.kingtech.myapplication;

import android.Manifest;
import android.app.Activity;
import android.content.pm.PackageManager;
import android.support.v4.app.ActivityCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.Gravity;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.Toast;

import me.dm7.barcodescanner.zbar.ZBarScannerView;
import me.dm7.barcodescanner.zbar.BarcodeFormat;
import me.dm7.barcodescanner.zbar.Result;
import me.dm7.barcodescanner.zxing.ZXingScannerView;

import net.sourceforge.zbar.Symbol;


import java.util.ArrayList;
import java.util.List;

import static java.security.AccessController.getContext;

public class MainActivity extends Activity implements ZXingScannerView.ResultHandler {
    private ZXingScannerView mScannerView;

    public void requestPermissionForCamera(){
        if (ActivityCompat.shouldShowRequestPermissionRationale(MainActivity.this, Manifest.permission.CAMERA)){
            Toast.makeText(getApplicationContext(), "Camera permission needed. Please allow in App Settings for additional functionality.", Toast.LENGTH_LONG).show();
        } else {
            ActivityCompat.requestPermissions(MainActivity.this,new String[]{Manifest.permission.CAMERA},3);
        }
    }

    @Override
    public void onCreate(Bundle state) {
        super.onCreate(state);
        requestPermissionForCamera();
        FrameLayout lay = new FrameLayout(getApplicationContext());
        FrameLayout.LayoutParams layoutparams=new FrameLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,ViewGroup.LayoutParams.FILL_PARENT,Gravity.CENTER_HORIZONTAL|Gravity.CENTER_VERTICAL);
        lay.setLayoutParams(layoutparams);

        FrameLayout lay2 = new FrameLayout(getApplicationContext());
        FrameLayout.LayoutParams layoutparams2=new FrameLayout.LayoutParams(200,200);
        lay2.setLayoutParams(layoutparams2);


        mScannerView = new ZXingScannerView(this);   // Programmatically initialize the scanner view
        lay2.addView(mScannerView);
        lay.addView(lay2);

        mScannerView.setResultHandler(this); // Register ourselves as a handler for scan results.
        mScannerView.startCamera();          // Start camera on resume
        setContentView(lay);                // Set the scanner view as the content view
    }

    @Override
    public void onResume() {
        super.onResume();
//        mScannerView.setResultHandler(this); // Register ourselves as a handler for scan results.
//        mScannerView.startCamera();          // Start camera on resume
    }

    @Override
    public void onPause() {
        super.onPause();
//        mScannerView.stopCamera();           // Stop camera on pause
    }


    @Override
    public void handleResult(com.google.zxing.Result rawResult) {
        // Do something with the result here
        Log.v("ihih", rawResult.getText()); // Prints scan results
        Log.v("gghg", rawResult.getBarcodeFormat().toString()); // Prints the scan format (qrcode, pdf417 etc.)

        // If you would like to resume scanning, call this method below:
        mScannerView.resumeCameraPreview(this);
    }
}

the expected result

Try returning the ZBarScannerView instead of the FrameLayout. You dont need the FrameLayout, Fuse will take care of that.

If you can share the project I can have a look at it. (If you don’t want to post it publicly then please upload to https://www.dropbox.com/request/ZgndLtJQm5eGzG9cicGK)

Vegard Strand Lende wrote:

Try returning the ZBarScannerView instead of the FrameLayout. You dont need the FrameLayout, Fuse will take care of that.

If you can share the project I can have a look at it. (If you don’t want to post it publicly then please upload to Dropbox)

Returning the ZBarScannerView results in the same thing. I went ahead and uploaded my project files to your dropbox