Cordova相机插件创建相机的半屏幕和其他一半为选择菜单 [英] Cordova camera plugin to create half screen for camera and other half for selection menu

查看:304
本文介绍了Cordova相机插件创建相机的半屏幕和其他一半为选择菜单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一个试图实现Instagram像相机界面(半屏是相机和其他haalf是选择菜单)使用cordova相机插件。有人可以帮我这个吗?找不到好的来源

I am a trying to implement Instagram like camera interface(half screen is camera and other haalf is selection menu) using cordova camera plugin. Can anybody help me with this? Couldn't find a good source

推荐答案

您需要实现混合视图
查看此文章

我通过CordovaWebView实现了一个JAVA SurfaceView(在其中实现了摄像机)。

I did it to implement a, JAVA SurfaceView (implementing the camera inside it) over a CordovaWebView.

给你一些方向:

在你的插件的JavaScript有类似:

In the JavaScript for your plugin have something like:

SurfaceViewAdd:function(){
    cordova.exec(
        function(){//success function},function(){//error function},'MYPlugin',action,JSON[])
},

插件安装在cordova项目中后,您可以调用此JavaScript函数,该函数将调用JAVA本地代码。

Once the plugin is installed in your cordova project, you can call this JavaScript function which will call the JAVA native code.

在JAVA端,MainActivity:

On the JAVA side, MainActivity:

public class CordovaApp extends CordovaActivity
{


    @Override
    public void onCreate(Bundle savedInstanceState)
    {

        super.onCreate(savedInstanceState);
        super.init();
        super.loadUrl(Config.getStartUrl());

        MYPlugin.setCwv(this.appView);
);

....plus all function you might need (to release the camera onPause event for example)..

}

您的插件类:

public class MYPlugin extends CordovaPlugin {


    public boolean execute(String action, final JSONArray args, final CallbackContext callbackContext) throws JSONException {
///Manage the input of your plugin from Javascript
//call functions inside your plugin class to implement a SurfaceView on top of the CordovaWebView
//Send back a successful callback to your JavaScript once the webview is implemented
        }

... ///all you need to implement the surfaceView and the cameraView inside the surfaceView ...

        public static void setCwv(CordovaWebView cwvInput) {
        cwv = cwvInput;
        }
}

您需要一个插件XML文件: / p>

And you'll need a plugin XML file:

<?xml version="1.0" encoding="UTF-8"?>
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
    id="com.you.myplugin"
    version="1.0.0">
    <name>MyPlugin</name>
    <description> ... </description>
    <license> ... </license>
    <author> ... </author>

    <engines>
        <engine name="cordova" version=">=3.0.0" />
    </engines>

    <js-module src="www/js/my_plugin.js" name="MyPlugin">
        <clobbers target="MyPlugin" />
    </js-module>

    <platform name="android">
        <config-file target="res/xml/config.xml" parent="widget">
            <preference name="orientation" value="portrait"/>
            <feature name="MyPlugin" >
                <param name="android-package" value="com.you.myplugin.MyPlugin"/>
                <param name="onload" value="true"/>
            </feature>
        </config-file>

        <config-file target="AndroidManifest.xml" parent="/*">
            <supports-screens android:anyDensity="true" android:largeScreens="true" android:normalScreens="true" android:resizeable="true" android:smallScreens="true" android:xlargeScreens="true" />
            <uses-permission android:name="android.permission.CAMERA" />
            <uses-feature android:name="android.hardware.camera.autofocus" />
            <uses-feature android:name="android.hardware.camera" />
        </config-file>

        <source-file src="src/android/MyPlugin.java" target-dir="src/com/you/myplugin" />

    </platform>
</plugin>

花时间阅读文章和祝你好运。

Take the time to read the article and good luck.

这篇关于Cordova相机插件创建相机的半屏幕和其他一半为选择菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆