edu.xjtu.qxcamerabridge.Qx10ServiceDelegatorImpl.java Source code

Java tutorial

Introduction

Here is the source code for edu.xjtu.qxcamerabridge.Qx10ServiceDelegatorImpl.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.xjtu.qxcamerabridge;

import java.util.ArrayList;
import java.util.List;
import org.json.JSONArray;
import org.json.JSONObject;
import static edu.xjtu.qxcamerabridge.DeviceServiceDelegator.*;

/**
 * The service interface implementation for Qx10 Camera.
 *
 * @author ZhipingJiang
 */
public class Qx10ServiceDelegatorImpl extends AbstractDeviceServiceDelegator {

    /**
     * Test passed on Qx10
     *
     * @param shootMode
     * @return
     */
    @Override
    public boolean setShootMode(ShootMode shootMode) {
        String service = "camera";
        String serviceName = new Object() {
        }.getClass().getEnclosingMethod().getName();
        List<Object> params = new ArrayList<>();
        params.add(shootMode.toString());
        JSONObject replyJson = JSONActionWrapper.jsonrpc(service, serviceName, params);
        int result = replyJson.getJSONArray("result").getInt(0);
        return result == 0;
    }

    /**
     * Test Passed on Qx10
     *
     * @return
     */
    @Override
    public ShootMode getShootMode() {
        String service = "camera";
        String serviceName = new Object() {
        }.getClass().getEnclosingMethod().getName();
        JSONObject replyJson = JSONActionWrapper.jsonrpc(service, serviceName, new ArrayList<>());
        JSONArray modeArray = replyJson.getJSONArray("result");
        return ShootMode.valueOf(modeArray.getString(0));
    }

    /**
     * Test passed on Qx10
     *
     * @return
     */
    @Override
    public List<ShootMode> getSupportedShootMode() {
        String service = "camera";
        String serviceName = new Object() {
        }.getClass().getEnclosingMethod().getName();
        JSONObject replyJson = JSONActionWrapper.jsonrpc(service, serviceName, new ArrayList<>());
        JSONArray resultArray = replyJson.getJSONArray("result");
        JSONArray modeArray = resultArray.getJSONArray(0);
        List<ShootMode> modeList = new ArrayList<>();
        for (int i = 0; i < modeArray.length(); i++) {
            modeList.add(ShootMode.valueOf(modeArray.getString(i)));
        }
        return modeList;
    }

    /**
     * Test Passed on Qx10
     *
     * @return
     */
    @Override
    public List<ShootMode> getAvailableShootMode() {
        String service = "camera";
        String serviceName = new Object() {
        }.getClass().getEnclosingMethod().getName();
        JSONObject replyJson = JSONActionWrapper.jsonrpc(service, serviceName, new ArrayList<>());
        JSONArray modeArray = replyJson.getJSONArray("result").getJSONArray(1);
        List<ShootMode> modeList = new ArrayList<>();
        for (int i = 0; i < modeArray.length(); i++) {
            modeList.add(ShootMode.valueOf(modeArray.getString(i)));
        }
        return modeList;
    }

    @Override
    public String actTakePicture() {
        String service = "camera";
        String serviceName = new Object() {
        }.getClass().getEnclosingMethod().getName();
        JSONObject replyJson = JSONActionWrapper.jsonrpc(service, serviceName, new ArrayList<>());
        String postviewurl = replyJson.getJSONArray("result").getJSONArray(0).getString(0);
        System.out.println(postviewurl);
        return postviewurl;
    }

    @Override
    public String awaitTakePicture() {
        String service = "camera";
        String serviceName = new Object() {
        }.getClass().getEnclosingMethod().getName();
        JSONObject replyJson = JSONActionWrapper.jsonrpc(service, serviceName, new ArrayList<>());
        String postviewurl = replyJson.getJSONArray("result").getJSONArray(0).getString(0);
        System.out.println(postviewurl);
        return postviewurl;
    }

    @Override
    public boolean startMovieRec() {
        String service = "camera";
        String serviceName = new Object() {
        }.getClass().getEnclosingMethod().getName();
        JSONObject replyJson = JSONActionWrapper.jsonrpc(service, serviceName, new ArrayList<>());
        int result = replyJson.getJSONArray("result").getInt(0);
        return result == 0;
    }

    @Override
    public boolean stopMovieRec() {
        String service = "camera";
        String serviceName = new Object() {
        }.getClass().getEnclosingMethod().getName();
        JSONObject replyJson = JSONActionWrapper.jsonrpc(service, serviceName, new ArrayList<>());
        return true;
    }

    /**
     * Test passed on Qx10
     *
     * @return
     */
    @Override
    public String startLiveview() {
        String service = "camera";
        String serviceName = new Object() {
        }.getClass().getEnclosingMethod().getName();
        JSONObject replyJson = JSONActionWrapper.jsonrpc(service, serviceName, new ArrayList<>());
        String liveviewstream = replyJson.getJSONArray("result").getString(0);
        return liveviewstream;
    }

    @Override
    public boolean stopLiveview() {
        String service = "camera";
        String serviceName = new Object() {
        }.getClass().getEnclosingMethod().getName();
        JSONObject replyJson = JSONActionWrapper.jsonrpc(service, serviceName, new ArrayList<>());
        int result = replyJson.getJSONArray("result").getInt(0);
        return result == 0;
    }

    /**
     * Test passed on Qx10
     *
     * @param zoomMode
     * @param zoomMovements
     * @return
     */
    @Override
    public boolean actZoom(ZoomMode zoomMode, ZoomMovements zoomMovements) {
        String service = "camera";
        String serviceName = new Object() {
        }.getClass().getEnclosingMethod().getName();
        List<Object> params = new ArrayList<>();
        params.add(zoomMode.toString());
        params.add(zoomMovements.getStrValue());
        JSONObject replyJson = JSONActionWrapper.jsonrpc(service, serviceName, params);
        JSONArray modeArray = replyJson.getJSONArray("result");
        int result = replyJson.getJSONArray("result").getInt(0);
        return result == 0;
    }

    /**
     * Test passed on Qx10
     *
     * @return
     */
    @Override
    public boolean actHalfPressShutter() {
        String service = "camera";
        String serviceName = new Object() {
        }.getClass().getEnclosingMethod().getName();
        List<Object> params = new ArrayList<>();
        JSONObject replyJson = JSONActionWrapper.jsonrpc(service, serviceName, params);
        JSONArray modeArray = replyJson.getJSONArray("result");
        //        return result == 0;
        return true;
    }

    /**
     * Test passed on Qx10
     *
     * @return
     */
    @Override
    public boolean cancelHalfPressShutter() {
        String service = "camera";
        String serviceName = new Object() {
        }.getClass().getEnclosingMethod().getName();
        List<Object> params = new ArrayList<>();
        JSONObject replyJson = JSONActionWrapper.jsonrpc(service, serviceName, params);

        return true;
    }

    @Override
    public boolean setTouchAFPosition(double x_axis_position, double y_axis_position) {
        String service = "camera";
        String serviceName = new Object() {
        }.getClass().getEnclosingMethod().getName();
        List<Object> params = new ArrayList<>();
        params.add(x_axis_position);
        params.add(y_axis_position);
        JSONObject replyJson = JSONActionWrapper.jsonrpc(service, serviceName, params);
        JSONArray modeArray = replyJson.getJSONArray("result").getJSONArray(1);
        return modeArray.getJSONObject(0).getBoolean("AFResult");
    }

    /**
     * Test passed on Qx10
     *
     * @return
     */
    @Override
    public ExposureMode getExposureMode() {
        String service = "camera";
        String serviceName = new Object() {
        }.getClass().getEnclosingMethod().getName();
        JSONObject replyJson = JSONActionWrapper.jsonrpc(service, serviceName, new ArrayList<>());
        JSONArray resultArray = replyJson.getJSONArray("result");
        String name = resultArray.getString(0);
        return ExposureMode.findExposureMode(name);

    }

    @Override
    public boolean setExposureMode(ExposureMode exposureMode) {
        String service = "camera";
        String serviceName = new Object() {
        }.getClass().getEnclosingMethod().getName();
        List<Object> params = new ArrayList<>();
        params.add(exposureMode.getStr());
        JSONObject replyJson = JSONActionWrapper.jsonrpc(service, serviceName, params);
        int result = replyJson.getJSONArray("result").getInt(0);
        return result == 0;
    }

    /**
     * Test passed on Qx10
     *
     * @return
     */
    @Override
    public List<ExposureMode> getAvailableExposureMode() {
        String service = "camera";
        String serviceName = new Object() {
        }.getClass().getEnclosingMethod().getName();
        JSONObject replyJson = JSONActionWrapper.jsonrpc(service, serviceName, new ArrayList<>());
        JSONArray modeArray = replyJson.getJSONArray("result").getJSONArray(1);
        List<ExposureMode> modeList = new ArrayList<>();
        for (int i = 0; i < modeArray.length(); i++) {
            modeList.add(ExposureMode.findExposureMode(modeArray.getString(i)));
        }
        return modeList;
    }

    /**
     * Test passed on Qx10
     *
     * @return
     */
    @Override
    public List<ExposureMode> getSupportedExposureMode() {
        String service = "camera";
        String serviceName = new Object() {
        }.getClass().getEnclosingMethod().getName();
        JSONObject replyJson = JSONActionWrapper.jsonrpc(service, serviceName, new ArrayList<>());
        JSONArray modeArray = replyJson.getJSONArray("result").getJSONArray(0);
        List<ExposureMode> modeList = new ArrayList<>();
        for (int i = 0; i < modeArray.length(); i++) {
            modeList.add(ExposureMode.findExposureMode(modeArray.getString(i)));
        }
        return modeList;
    }

    @Override
    public boolean setStillSize(StillSizeRatio ratio, StillSize size) {
        String service = "camera";
        String serviceName = new Object() {
        }.getClass().getEnclosingMethod().getName();
        List<Object> params = new ArrayList<>();
        params.add(ratio);
        params.add(size);
        JSONObject replyJson = JSONActionWrapper.jsonrpc(service, serviceName, params);
        int result = replyJson.getJSONArray("result").getInt(0);
        return result == 0;
    }

    /**
     * Test passed on Qx10
     *
     * @return
     */
    @Override
    public List<String> getStillSize() {
        String service = "camera";
        String serviceName = new Object() {
        }.getClass().getEnclosingMethod().getName();
        JSONObject replyJson = JSONActionWrapper.jsonrpc(service, serviceName, new ArrayList<>());
        JSONArray modeArray = replyJson.getJSONArray("result");
        List<String> sizeList = new ArrayList<>();
        for (int i = 0; i < modeArray.length(); i++) {
            sizeList.add(modeArray.getJSONObject(i).getString("aspect"));
            sizeList.add(modeArray.getJSONObject(i).getString("size"));
        }
        return sizeList;
    }

    /**
     * Test passed on Qx10
     *
     * @return
     */
    @Override
    public List<String> getAvailableStillSize() {
        String service = "camera";
        String serviceName = new Object() {
        }.getClass().getEnclosingMethod().getName();
        JSONObject replyJson = JSONActionWrapper.jsonrpc(service, serviceName, new ArrayList<>());
        JSONArray modeArray = replyJson.getJSONArray("result").getJSONArray(1);
        List<String> sizeList = new ArrayList<>();
        for (int i = 0; i < modeArray.length(); i++) {
            sizeList.add(modeArray.getJSONObject(i).getString("aspect"));
            sizeList.add(modeArray.getJSONObject(i).getString("size"));
        }
        return sizeList;
    }

    /**
     * Test passed on Qx10
     *
     * @return
     */
    @Override
    public List<String> getSupportedStillSize() {
        String service = "camera";
        String serviceName = new Object() {
        }.getClass().getEnclosingMethod().getName();
        JSONObject replyJson = JSONActionWrapper.jsonrpc(service, serviceName, new ArrayList<>());
        JSONArray modeArray = replyJson.getJSONArray("result").getJSONArray(0);
        List<String> sizeList = new ArrayList<>();
        for (int i = 0; i < modeArray.length(); i++) {
            sizeList.add(modeArray.getJSONObject(i).getString("aspect"));
            sizeList.add(modeArray.getJSONObject(i).getString("size"));
        }
        return sizeList;
    }

    public List<String> getSupportedCameraFunction() {
        String service = "camera";
        String serviceName = new Object() {
        }.getClass().getEnclosingMethod().getName();
        JSONObject replyJson = JSONActionWrapper.jsonrpc(service, serviceName, new ArrayList<>());
        JSONArray modeArray = replyJson.getJSONArray("result");
        System.out.println(modeArray.toString(4));
        return null;
    }

    /**
     * test passed on qx10
     *
     * @return
     */
    @Override
    public List<String> getApplicationInfo() {
        String service = "camera";
        String serviceName = new Object() {
        }.getClass().getEnclosingMethod().getName();
        JSONObject replyJson = JSONActionWrapper.jsonrpc(service, serviceName, new ArrayList<>());
        JSONArray modeArray = replyJson.getJSONArray("result");
        List<String> modeList = new ArrayList<>();
        for (int i = 0; i < modeArray.length(); i++) {
            modeList.add(modeArray.getString(i));
        }
        return modeList;
    }

    /**
     * Test Passed on Qx10
     *
     * @return
     */
    @Override
    public List<String> getAvailableApiList() {
        String service = "camera";
        String serviceName = new Object() {
        }.getClass().getEnclosingMethod().getName();
        JSONObject replyJson = JSONActionWrapper.jsonrpc(service, serviceName, new ArrayList<>());
        JSONArray resultArray = replyJson.getJSONArray("result");
        List<String> modeList = new ArrayList<>();
        for (int i = 0; i < resultArray.getJSONArray(0).length(); i++) {
            modeList.add(resultArray.getJSONArray(0).getString(i));
        }
        return modeList;
    }

}