Cordova camera plugin to create half screen for camera and other half for selection menu

吃可爱长大的小学妹 提交于 2019-12-08 09:23:44

问题


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


回答1:


You need to implement an hybrid view, check this article.

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

To give you some direction:

In the JavaScript for your plugin have something like:

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

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

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)..

}

The class of you plugin:

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;
        }
}

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.



来源:https://stackoverflow.com/questions/37646225/cordova-camera-plugin-to-create-half-screen-for-camera-and-other-half-for-select

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!