Search in sources :

Example 1 with BaseProduct

use of dji.sdk.base.BaseProduct in project uav_mobile_app by jiushuokj.

the class DemoApplication method onCreate.

@Override
public void onCreate() {
    super.onCreate();
    mHandler = new Handler(Looper.getMainLooper());
    /**
     * When starting SDK services, an instance of interface DJISDKManager.DJISDKManagerCallback will be used to listen to
     * the SDK Registration result and the product changing.
     */
    mDJISDKManagerCallback = new DJISDKManager.SDKManagerCallback() {

        // Listens to the SDK registration result
        @Override
        public void onRegister(DJIError error) {
            if (error == DJISDKError.REGISTRATION_SUCCESS) {
                Handler handler = new Handler(Looper.getMainLooper());
                handler.post(new Runnable() {

                    @Override
                    public void run() {
                        Toast.makeText(getApplicationContext(), "注册成功", Toast.LENGTH_LONG).show();
                    }
                });
                DJISDKManager.getInstance().startConnectionToProduct();
            } else {
                Handler handler = new Handler(Looper.getMainLooper());
                handler.post(new Runnable() {

                    @Override
                    public void run() {
                        Toast.makeText(getApplicationContext(), "注册SDK失败, 请检查网络是否可用", Toast.LENGTH_LONG).show();
                    }
                });
            }
            Log.e("TAG", error.toString());
        }

        @Override
        public void onProductDisconnect() {
            Log.d("TAG", "onProductDisconnect");
            notifyStatusChange();
        }

        @Override
        public void onProductConnect(BaseProduct baseProduct) {
            Log.d("TAG", String.format("onProductConnect newProduct:%s", baseProduct));
            notifyStatusChange();
        }

        @Override
        public void onComponentChange(BaseProduct.ComponentKey componentKey, BaseComponent oldComponent, BaseComponent newComponent) {
            if (newComponent != null) {
                newComponent.setComponentListener(new BaseComponent.ComponentListener() {

                    @Override
                    public void onConnectivityChange(boolean isConnected) {
                        Log.d("TAG", "onComponentConnectivityChanged: " + isConnected);
                        notifyStatusChange();
                    }
                });
            }
            Log.d("TAG", String.format("onComponentChange key:%s, oldComponent:%s, newComponent:%s", componentKey, oldComponent, newComponent));
        }

        @Override
        public void onInitProcess(DJISDKInitEvent djisdkInitEvent, int i) {
        }

        @Override
        public void onDatabaseDownloadProgress(long l, long l1) {
        }
    };
    // Check the permissions before registering the application for android system 6.0 above.
    int permissionCheck = ContextCompat.checkSelfPermission(getApplicationContext(), android.Manifest.permission.WRITE_EXTERNAL_STORAGE);
    int permissionCheck2 = ContextCompat.checkSelfPermission(getApplicationContext(), android.Manifest.permission.READ_PHONE_STATE);
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M || (permissionCheck == 0 && permissionCheck2 == 0)) {
        // This is used to start SDK services and initiate SDK.
        DJISDKManager.getInstance().registerApp(getApplicationContext(), mDJISDKManagerCallback);
        Toast.makeText(getApplicationContext(), "正在注册SDK,请稍等...", Toast.LENGTH_LONG).show();
    } else {
        Toast.makeText(getApplicationContext(), "请检查App的权限是否足够", Toast.LENGTH_LONG).show();
    }
}
Also used : BaseComponent(dji.sdk.base.BaseComponent) DJISDKManager(dji.sdk.sdkmanager.DJISDKManager) Handler(android.os.Handler) DJIError(dji.common.error.DJIError) DJISDKInitEvent(dji.sdk.sdkmanager.DJISDKInitEvent) BaseProduct(dji.sdk.base.BaseProduct)

Example 2 with BaseProduct

use of dji.sdk.base.BaseProduct in project StickFlight by gly2000.

the class DemoApplication method onCreate.

@Override
public void onCreate() {
    super.onCreate();
    mHandler = new Handler(Looper.getMainLooper());
    // Check the permissions before registering the application for android system 6.0 above.
    int permissionCheck = ContextCompat.checkSelfPermission(getApplicationContext(), android.Manifest.permission.WRITE_EXTERNAL_STORAGE);
    int permissionCheck2 = ContextCompat.checkSelfPermission(getApplicationContext(), android.Manifest.permission.READ_PHONE_STATE);
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M || (permissionCheck == 0 && permissionCheck2 == 0)) {
        // This is used to start SDK services and initiate SDK.
        DJISDKManager.getInstance().registerApp(getApplicationContext(), mDJISDKManagerCallback);
    } else {
        Toast.makeText(getApplicationContext(), "Please check if the permission is granted.", Toast.LENGTH_LONG).show();
    }
    /**
     * When starting SDK services, an instance of interface DJISDKManager.DJISDKManagerCallback will be used to listen to
     * the SDK Registration result and the product changing.
     */
    mDJISDKManagerCallback = new DJISDKManager.SDKManagerCallback() {

        // Listens to the SDK registration result
        @Override
        public void onRegister(DJIError error) {
            if (error == DJISDKError.REGISTRATION_SUCCESS) {
                DJISDKManager.getInstance().startConnectionToProduct();
                Handler handler = new Handler(Looper.getMainLooper());
                handler.post(new Runnable() {

                    @Override
                    public void run() {
                        Toast.makeText(getApplicationContext(), "Register Success", Toast.LENGTH_LONG).show();
                    }
                });
                loginAccount();
            } else {
                Handler handler = new Handler(Looper.getMainLooper());
                handler.post(new Runnable() {

                    @Override
                    public void run() {
                        Toast.makeText(getApplicationContext(), "Register Failed, check network is available", Toast.LENGTH_LONG).show();
                    }
                });
            }
            Log.e("TAG", error.toString());
        }

        @Override
        public void onProductDisconnect() {
            Log.d("TAG", "onProductDisconnect");
            notifyStatusChange();
        }

        @Override
        public void onProductConnect(BaseProduct baseProduct) {
            Log.d("TAG", String.format("onProductConnect newProduct:%s", baseProduct));
            notifyStatusChange();
        }

        @Override
        public void onProductChanged(BaseProduct baseProduct) {
            Log.d("TAG", String.format("onProductChanged newProduct:%s", baseProduct));
            notifyStatusChange();
        }

        @Override
        public void onComponentChange(BaseProduct.ComponentKey componentKey, BaseComponent oldComponent, BaseComponent newComponent) {
            if (newComponent != null) {
                newComponent.setComponentListener(new BaseComponent.ComponentListener() {

                    @Override
                    public void onConnectivityChange(boolean isConnected) {
                        Log.d("TAG", "onComponentConnectivityChanged: " + isConnected);
                        notifyStatusChange();
                    }
                });
            }
            Log.d("TAG", String.format("onComponentChange key:%s, oldComponent:%s, newComponent:%s", componentKey, oldComponent, newComponent));
        }

        @Override
        public void onInitProcess(DJISDKInitEvent djisdkInitEvent, int i) {
        }

        @Override
        public void onDatabaseDownloadProgress(long l, long l1) {
        }
    };
}
Also used : BaseComponent(dji.sdk.base.BaseComponent) DJISDKManager(dji.sdk.sdkmanager.DJISDKManager) Handler(android.os.Handler) DJIError(dji.common.error.DJIError) DJISDKInitEvent(dji.sdk.sdkmanager.DJISDKInitEvent) BaseProduct(dji.sdk.base.BaseProduct)

Example 3 with BaseProduct

use of dji.sdk.base.BaseProduct in project mavicmini by kadytoast.

the class AircraftObjHandler method onCreate.

@Override
public void onCreate() {
    super.onCreate();
    mHandler = new Handler(Looper.getMainLooper());
    /**
     * When starting SDK services, an instance of interface DJISDKManager.DJISDKManagerCallback will be used to listen to
     * the SDK Registration result and the product changing.
     */
    mDJISDKManagerCallback = new DJISDKManager.SDKManagerCallback() {

        // Listens to the SDK registration result
        @Override
        public void onRegister(DJIError error) {
            if (error == DJISDKError.REGISTRATION_SUCCESS) {
                Handler handler = new Handler(Looper.getMainLooper());
                handler.post(new Runnable() {

                    @Override
                    public void run() {
                        Toast.makeText(getApplicationContext(), "Register Success", Toast.LENGTH_LONG).show();
                    }
                });
                DJISDKManager.getInstance().startConnectionToProduct();
            } else {
                Handler handler = new Handler(Looper.getMainLooper());
                handler.post(new Runnable() {

                    @Override
                    public void run() {
                        Toast.makeText(getApplicationContext(), "Register sdk fails, check network is available", Toast.LENGTH_LONG).show();
                    }
                });
            }
            Log.e("TAG", error.toString());
        }

        @Override
        public void onProductDisconnect() {
            Log.d("TAG", "onProductDisconnect");
            notifyStatusChange();
        }

        @Override
        public void onProductConnect(BaseProduct baseProduct) {
            Log.d("TAG", String.format("onProductConnect newProduct:%s", baseProduct));
            notifyStatusChange();
        }

        @Override
        public void onProductChanged(BaseProduct baseProduct) {
        }

        @Override
        public void onComponentChange(BaseProduct.ComponentKey componentKey, BaseComponent oldComponent, BaseComponent newComponent) {
            if (newComponent != null) {
                newComponent.setComponentListener(new BaseComponent.ComponentListener() {

                    @Override
                    public void onConnectivityChange(boolean isConnected) {
                        Log.d("TAG", "onComponentConnectivityChanged: " + isConnected);
                        notifyStatusChange();
                    }
                });
            }
            Log.d("TAG", String.format("onComponentChange key:%s, oldComponent:%s, newComponent:%s", componentKey, oldComponent, newComponent));
        }

        @Override
        public void onInitProcess(DJISDKInitEvent djisdkInitEvent, int i) {
        }

        @Override
        public void onDatabaseDownloadProgress(long l, long l1) {
        }
    };
    // Check the permissions before registering the application for android system 6.0 above.
    int permissionCheck = ContextCompat.checkSelfPermission(getApplicationContext(), android.Manifest.permission.WRITE_EXTERNAL_STORAGE);
    int permissionCheck2 = ContextCompat.checkSelfPermission(getApplicationContext(), android.Manifest.permission.READ_PHONE_STATE);
    if (permissionCheck == 0 && permissionCheck2 == 0) {
        // This is used to start SDK services and initiate SDK.
        Toast.makeText(getApplicationContext(), "trying to register:", Toast.LENGTH_LONG).show();
        DJISDKManager.getInstance().registerApp(getApplicationContext(), mDJISDKManagerCallback);
        Toast.makeText(getApplicationContext(), "registering, pls wait...", Toast.LENGTH_LONG).show();
    } else {
        Toast.makeText(getApplicationContext(), "Please check if the permission is granted.", Toast.LENGTH_LONG).show();
    }
}
Also used : BaseComponent(dji.sdk.base.BaseComponent) DJISDKManager(dji.sdk.sdkmanager.DJISDKManager) Handler(android.os.Handler) DJIError(dji.common.error.DJIError) DJISDKInitEvent(dji.sdk.sdkmanager.DJISDKInitEvent) BaseProduct(dji.sdk.base.BaseProduct)

Example 4 with BaseProduct

use of dji.sdk.base.BaseProduct in project mavicmini by kadytoast.

the class AircraftController method updateTitleBar.

void updateTitleBar() {
    try {
        if (mConnectStatusTextView == null)
            return;
        boolean ret = false;
        BaseProduct product = AircraftObjHandler.getProductInstance();
        if (product != null) {
            if (product.isConnected()) {
                // The product is connected
                mConnectStatusTextView.setText(AircraftObjHandler.getProductInstance().getModel() + " Connected");
                ret = true;
            } else {
                if (product instanceof Aircraft) {
                    Aircraft aircraft = (Aircraft) product;
                    if (aircraft.getRemoteController() != null && aircraft.getRemoteController().isConnected()) {
                        // The product is not connected, but the remote controller is connected
                        mConnectStatusTextView.setText("only RC Connected");
                        ret = true;
                    }
                }
            }
        }
        if (!ret) {
            // The product or the remote controller are not connected.
            mConnectStatusTextView.setText("Disconnected");
        }
    } catch (Exception e) {
        ma.debug.errlog(e, "updatetitlebar");
    }
}
Also used : BaseProduct(dji.sdk.base.BaseProduct) Aircraft(dji.sdk.products.Aircraft)

Example 5 with BaseProduct

use of dji.sdk.base.BaseProduct in project uav_mobile_app by jiushuokj.

the class ConnectionActivity method refreshSDKRelativeUI.

private void refreshSDKRelativeUI() {
    BaseProduct mProduct = DemoApplication.getProductInstance();
    if (null != mProduct && mProduct.isConnected()) {
        Log.v(TAG, "refreshSDK: True");
        mBtnOpen.setEnabled(true);
        String str = mProduct instanceof Aircraft ? "无人机" : "手持设备";
        mTextConnectionStatus.setText("状态: " + str + " 已连接");
        tryUpdateFirmwareVersionWithListener();
        if (null != mProduct.getModel()) {
            mTextProduct.setText("" + mProduct.getModel().getDisplayName());
        } else {
            mTextProduct.setText(R.string.product_information);
        }
        loginAccount();
    } else {
        Log.v(TAG, "refreshSDK: False");
        mBtnOpen.setEnabled(false);
        mTextProduct.setText(R.string.product_information);
        mTextConnectionStatus.setText(R.string.connection_loose);
    }
}
Also used : BaseProduct(dji.sdk.base.BaseProduct) Aircraft(dji.sdk.products.Aircraft)

Aggregations

BaseProduct (dji.sdk.base.BaseProduct)6 Handler (android.os.Handler)3 DJIError (dji.common.error.DJIError)3 BaseComponent (dji.sdk.base.BaseComponent)3 Aircraft (dji.sdk.products.Aircraft)3 DJISDKInitEvent (dji.sdk.sdkmanager.DJISDKInitEvent)3 DJISDKManager (dji.sdk.sdkmanager.DJISDKManager)3