8***@qq.com
8***@qq.com
  • 发布:2018-07-19 11:40
  • 更新:2018-07-19 11:40
  • 阅读:2080

android native.js camera自定义相机

分类:Native.js
     //js代码  
    //用代码渲染页面   
    let activity = plus.android.runtimeMainActivity();  

let SurfaceView = plus.android.importClass("android.view.SurfaceView");  
let mSurfaceView = new SurfaceView(activity);  

let RelativeLayout = plus.android.importClass("android.widget.RelativeLayout");  
let layout = new RelativeLayout(activity);  
layout.addView(mSurfaceView);  
activity.setContentView(layout);  

   let mSurfaceViewHolder = mSurfaceView.getHolder();   //获取了mSurfaceViewHolder  

    //实现 callBack  
let surfaceHolderCallback = plus.android.implements("android.view.SurfaceHolder$Callback", {  
    "surfaceCreated":function(holder){  
        plus.android.importClass(holder);  
        initCameraAndPreview(mSurfaceView, mSurfaceViewHolder);  
    },  
    "surfaceCreated":function(holder){  
        plus.android.importClass(holder);  

    },  
    "surfaceChanged":function(holder, format, width, height){  
        plus.android.importClass(holder);  

    }  
});  

   mSurfaceViewHolder.addCallback(surfaceHolderCallback);    //但是这里报  addCallback is not a function  

//原生java代码
android.view.SurfaceView 类中的获取mSurfaceViewHolder,原生代码中的 mSurfaceHolder 有 addCallback 方法,但是 mSurfaceHolder 是private

public SurfaceHolder getHolder() {  
    return mSurfaceHolder;  
}  

private final SurfaceHolder mSurfaceHolder = new SurfaceHolder() {  

    private static final String LOG_TAG = "SurfaceHolder";  

    @Override  
    public boolean isCreating() {  
        return mIsCreating;  
    }  

    @Override  
    public void addCallback(Callback callback) {  
        synchronized (mCallbacks) {  
            // This is a linear search, but in practice we'll  
            // have only a couple callbacks, so it doesn't matter.  
            if (mCallbacks.contains(callback) == false) {  
                mCallbacks.add(callback);  
            }  
        }  
    }  
 .......  

}

问题是:为什么原生java代码中的getHolder()方法有返回mSurfaceHolder,而且 mSurfaceHolder 中有 addCallback方法,但是js代码中 mSurfaceViewHolder.addCallback(surfaceHolderCallback); 会报 addCallback is not a function ?

是不是 mSurfaceViewHolder 是 private,然后 native.js 实例化不了private属性?

2018-07-19 11:40 负责人:无 分享
已邀请:

该问题目前已经被锁定, 无法添加新回复