Android Open Source - HexNanoController_Android Ipc Proxy






From Project

Back to project page HexNanoController_Android.

License

The source code is released under:

Code license GNU GPL v2 http://www.gnu.org/licenses/gpl.html Content license CC BY-NC-SA 4.0 http://creativecommons.org/licenses/by-nc-sa/4.0/

If you think the Android project HexNanoController_Android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/**
 * @author Administrator//from  w  w w . j ava 2s . c o  m
 *
 */
package com.hexairbot.hexmini.services;

import java.util.ArrayList;

import android.app.Application;
import android.content.Intent;
import android.os.Handler;
import android.os.Message;
import android.support.v4.content.LocalBroadcastManager;

import com.hexairbot.hexmini.util.DebugHandler;

public class IpcProxy {

    private final static String TAG = "IpcProxy";

    private Application appContext = null;
    private String[] navData = null;
    private VIConfig viConfig = null;
    private LocalBroadcastManager mLocalBroadcastManager = null;
    private Intent connectStateIntent = null;
    private ArrayList<OnRecordCompleteListener> mOnRecordCompleteListeners = new ArrayList<OnRecordCompleteListener>();

    private Handler mHandler = null;
    private int mDecMode = 0;

    public final static String ACTION_DECODEMODE_CHANGED = "action_decodeMode_changed";
    public final static String ACTION_CONNECT_QUALITY_CHANGED = "action_connect_quality_changed";
    public final static String EXTRA_DECODE_MODE = "decode_mode";
    public final static String EXTRA_CONNECT_QUALITY = "connect_quality";

    public final static int MESSAGE_DECODEMODE_CHANGED = 5656;
    public final static int MESSAGE_RECORD_COMPLETED = 1001;
    public final static int MESSAGE_CONNECT_QUALITY_CHANGEBAD = 1002;
    public final static int MESSAGE_CONNECT_QUALITY_CHANGEGOOD = 1003;
    
    public final static int DEFAULT_DECODE_MODE = 1; //default mode is soft
    public final static int DEFAULT_PREVIEW_RESOLUTION_WIDTH = 1280; 
    public final static int DEFAULT_PREVIEW_RESOLUTION_HEIGHT = 720; 
    public final static int DEFAULT_PREVIEW_BITRATECONTROL = 1; //1 fps 2 quality

    public IpcProxy(Application app) {
  // navData = new NavData();
  viConfig = new VIConfig();
  mLocalBroadcastManager = LocalBroadcastManager.getInstance(app);
  connectStateIntent = new Intent(
    ConnectStateManager.ACTION_CONNECT_STATE_CHANGED);
  mHandler = new CallbackHandler();
    }

    private void setAppContext(Application app) {
  appContext = app;
    }

    public void doConnect() {
  connect(null);
    }

    public void doPause() {
  pause();
    }

    public void doResume() {
  resume();
    }

    public void doDisconnect() {
  disconnect();
    }

    public void doTriggerTakeOff() {
  triggerTakeOff();
    }

    public void doStartPreview() {
  startPreview();
    }

    public void doStopPreview() {
  stopPreview();
    }

    public void doOnSizeChanged(int width, int height) {
  onSizeChange(width, height);
    }

    public void doTakePhoto(String destDir, String name, boolean containGPS) {
  takePhoto(destDir, name, containGPS);
    }

    public void doStartRecord(String destDir, String cacheDir, String name,
      boolean containGPS) {
  startRecord(destDir, cacheDir, name, containGPS);
    }

    public void doStopRecord() {
  stopRecord();
    }

    public String[] getNavData() {
  return navData;
    }

    public void doUpdateNavData() {
  navData = takeNavDataSnapshot(null);
    }

    public void doSendMessage2Server(String[] key, String[] value) {
  sendMessage2Server(key, value);
    }

    public void doUpdateVIConfig() {
  viConfig = takeConfigSnapshot(viConfig);
    }

    public VIConfig getVIConfig() {
  return viConfig;
    }

    public String doGetConfigItem(String configName) {
  return getConfigItem(configName);
    }

    public void doSetConfigItem(String configName, String value) {
  setConfigItem(configName, value);
    }

    public void doResetConfig() {
  resetConfig();
    }

    public void setIpcDecMode(int decmode) {
  setDecodeStrategy(decmode);
    }

    public void onRecordComplete(boolean isSuccess) {
  if (mOnRecordCompleteListeners == null
    || mOnRecordCompleteListeners.size() == 0)
      return;
  for (int i = 0; i < mOnRecordCompleteListeners.size(); i++) {
      mOnRecordCompleteListeners.get(i).onRecordComplete(isSuccess);
  }
    }

    public static interface OnRecordCompleteListener {
  public void onRecordComplete(boolean isSuccess);
    }

    public void addOnRecordCompleteListener(OnRecordCompleteListener lis) {
  mOnRecordCompleteListeners.add(lis);
    }

    public void removeOnRecordCompleteListener(OnRecordCompleteListener lis) {
  mOnRecordCompleteListeners.remove(lis);
    }

    /**
     * ------------------------------------------------------------------------
     * -- native api function
     */
    // api for connect to device
    public native void connect(String address);

    public native void setDecodeStrategy(int strategy);

    public native void pause();

    public native void resume();

    public native void disconnect();

    public native void triggerTakeOff();

    public void ipcConnectStateChanged(int state, String info) {
  connectStateIntent.putExtra(ConnectStateManager.EXTRA_STATE, state);
  connectStateIntent.putExtra(ConnectStateManager.EXTRA_INFO, info);
  mLocalBroadcastManager.sendBroadcast(connectStateIntent);
    }

    // api for media
    public native void startPreview();

    public native void stopPreview();
    
    public native void setPreviewResolution(int width,int height);

    public native void setBitrateControlType(int type);

    public void ipcPreviewStateChanged(int state, String info) {

    }

    public native void onSizeChange(int width, int height);

    public native void takePhoto(String destDir, String name, boolean containGPS);

    public native void startRecord(String destDir, String cacheDir,
      String name, boolean containGPS);

    public native void stopRecord();

    public void ipcRecordVideoStateChanged(int state, String info) {

    }

    // api for getting IPCDevice function state
    public native String[] takeNavDataSnapshot(NavData navData);

    public native void sendMessage2Server(String[] keys, String[] value);

    public void ipcFunctionStateChanged(NavData newNavData) {

    }

    // api for getting/setting IPCDevice configuration
    public native VIConfig takeConfigSnapshot(VIConfig config);

    public native String getConfigItem(String configName);

    public native void setConfigItem(String configName, String value);

    public native void resetConfig();

    public void ipcConfigChanged(String configName, String value, String info) {

    }

    public void sendMsgByJni(int cmd, String msg) {
  DebugHandler.logd(TAG, "sendMsgByJni: " + cmd);
  Message msg2 = new Message();
  msg2.what = cmd;
  msg2.obj = msg;
  mHandler.sendMessage(msg2);
    }

    private class CallbackHandler extends Handler {
  @Override
  public void handleMessage(Message msg) {
      switch (msg.what) {
      case MESSAGE_DECODEMODE_CHANGED: {
    Intent intent = new Intent(ACTION_DECODEMODE_CHANGED);
    intent.putExtra(EXTRA_DECODE_MODE, (String) msg.obj);
    mLocalBroadcastManager.sendBroadcast(intent);
    break;
      }
      case MESSAGE_RECORD_COMPLETED: {
    int success = (Integer) msg.obj;
    onRecordComplete(success == 0 ? false : true);
    break;
      }
      case MESSAGE_CONNECT_QUALITY_CHANGEBAD:{
    Intent intent = new Intent(ACTION_CONNECT_QUALITY_CHANGED);
    intent.putExtra(EXTRA_CONNECT_QUALITY, -1);
    mLocalBroadcastManager.sendBroadcast(intent);
    break;
      }
      case MESSAGE_CONNECT_QUALITY_CHANGEGOOD:{
    Intent intent = new Intent(ACTION_CONNECT_QUALITY_CHANGED);
    intent.putExtra(EXTRA_CONNECT_QUALITY, 1);
    mLocalBroadcastManager.sendBroadcast(intent);
    break;
      }
      }

  }

    };

}




Java Source Code List

.FileHelper.java
.Input.java
.Output.java
.Serializable.java
com.hexairbot.hexmini.HelpActivity.java
com.hexairbot.hexmini.HexMiniApplication.java
com.hexairbot.hexmini.HudActivity.java
com.hexairbot.hexmini.HudViewControllerDelegate.java
com.hexairbot.hexmini.HudViewController.java
com.hexairbot.hexmini.SettingsDialogDelegate.java
com.hexairbot.hexmini.SettingsDialog.java
com.hexairbot.hexmini.SettingsViewControllerDelegate.java
com.hexairbot.hexmini.SettingsViewController.java
com.hexairbot.hexmini.ViewController.java
com.hexairbot.hexmini.adapter.SettingsViewAdapter.java
com.hexairbot.hexmini.ble.BleConnectinManagerDelegate.java
com.hexairbot.hexmini.ble.BleConnectinManager.java
com.hexairbot.hexmini.ble.BluetoothLeService.java
com.hexairbot.hexmini.gestures.EnhancedGestureDetector.java
com.hexairbot.hexmini.modal.ApplicationSettings.java
com.hexairbot.hexmini.modal.Channel.java
com.hexairbot.hexmini.modal.OSDCommon.java
com.hexairbot.hexmini.modal.Transmitter.java
com.hexairbot.hexmini.sensors.DeviceOrientationChangeDelegate.java
com.hexairbot.hexmini.sensors.DeviceOrientationManager.java
com.hexairbot.hexmini.sensors.DeviceSensorManagerWrapper.java
com.hexairbot.hexmini.sensors.SensorManagerWrapper.java
com.hexairbot.hexmini.services.ConnectStateManager.java
com.hexairbot.hexmini.services.IpcControlService.java
com.hexairbot.hexmini.services.IpcProxy.java
com.hexairbot.hexmini.services.NavData.java
com.hexairbot.hexmini.services.OnIpcConnectChangedListener.java
com.hexairbot.hexmini.services.VIConfig.java
com.hexairbot.hexmini.ui.Button.java
com.hexairbot.hexmini.ui.Image.java
com.hexairbot.hexmini.ui.Indicator.java
com.hexairbot.hexmini.ui.Sprite.java
com.hexairbot.hexmini.ui.Text.java
com.hexairbot.hexmini.ui.ToggleButton.java
com.hexairbot.hexmini.ui.UIRenderer.java
com.hexairbot.hexmini.ui.control.CustomSeekBar.java
com.hexairbot.hexmini.ui.control.ViewPagerIndicator.java
com.hexairbot.hexmini.ui.gl.GLSprite.java
com.hexairbot.hexmini.ui.joystick.AcceleratorJoystick.java
com.hexairbot.hexmini.ui.joystick.AnalogueJoystick.java
com.hexairbot.hexmini.ui.joystick.JoystickBase.java
com.hexairbot.hexmini.ui.joystick.JoystickFactory.java
com.hexairbot.hexmini.ui.joystick.JoystickListener.java
com.hexairbot.hexmini.util.DebugHandler.java
com.hexairbot.hexmini.util.FontUtils.java
com.hexairbot.hexmini.util.SystemUiHiderBase.java
com.hexairbot.hexmini.util.SystemUiHiderHoneycomb.java
com.hexairbot.hexmini.util.SystemUiHider.java
com.hexairbot.hexmini.util.SystemUtil.java
com.hexairbot.hexmini.util.TextureUtils.java
fix.android.opengl.GLES20.java