Android Open Source - HexNanoController_Android Application Settings






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

package com.hexairbot.hexmini.modal;
//w w w.j  av a 2  s  . c o  m
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

import com.dd.plist.NSArray;
import com.dd.plist.NSDictionary;
import com.dd.plist.NSNumber;
import com.dd.plist.PropertyListParser;
import com.hexairbot.hexmini.HexMiniApplication;


public class ApplicationSettings {
  private final static String INTERFACE_OPACITY  = "InterfaceOpacity";
  private final static String IS_LEFT_HANDED     = "IsLeftHanded";
  public final  static String IS_FIRST_RUN       = "IsFirstRun";
  private final static String IS_ACC_MODE        = "IsAccMode";
  private final static String IS_HEAD_FREE_MODE  = "IsHeadFreeMode";
  private final static String IS_ALT_HOLD_MODE   = "IsAltHoldMode";
  private final static String IS_BEGINNER_MODE   = "IsBeginnerMode";
  private final static String AILERON_DEAD_BAND  = "AileronDeadBand";
  private final static String ELEVATOR_DEAD_BAND = "ElevatorDeadBand";
  private final static String RUDDER_DEAD_BAND   = "RudderDeadBand";
  private final static String TAKE_OFF_THROTTLE  = "TakeOffThrottle";
  public final  static String CHANNELS           = "Channels";
  
  private String path;

  private NSDictionary data;
  
  private float interfaceOpacity;
  private boolean isLeftHanded;
  private boolean isAccMode;
  private boolean isFirstRun;
  private boolean isHeadFreeMode;
  private boolean isAltHoldMode;
  private boolean isBeginnerMode;
  private float aileronDeadBand;
  private float elevatorDeadBand;
  private float rudderDeadBand;
  private float takeOffThrottle;
  
  
  private List<Channel> channels;
  
  public ApplicationSettings(String path)
  {
    this.path = path;

    try {
      data = (NSDictionary)PropertyListParser.parse(path);
      
      interfaceOpacity = ((NSNumber)data.objectForKey(INTERFACE_OPACITY)).floatValue();
      isLeftHanded     = ((NSNumber)data.objectForKey(IS_LEFT_HANDED)).boolValue();
      isAccMode        = ((NSNumber)data.objectForKey(IS_ACC_MODE)).boolValue();
      isFirstRun       = ((NSNumber)data.objectForKey(IS_FIRST_RUN)).boolValue();
      isHeadFreeMode   = ((NSNumber)data.objectForKey(IS_HEAD_FREE_MODE)).boolValue();
      isAltHoldMode    = ((NSNumber)data.objectForKey(IS_ALT_HOLD_MODE)).boolValue();
      isBeginnerMode   = ((NSNumber)data.objectForKey(IS_BEGINNER_MODE)).boolValue();
      aileronDeadBand  = ((NSNumber)data.objectForKey(AILERON_DEAD_BAND)).floatValue();
      elevatorDeadBand = ((NSNumber)data.objectForKey(ELEVATOR_DEAD_BAND)).floatValue();
      rudderDeadBand   = ((NSNumber)data.objectForKey(RUDDER_DEAD_BAND)).floatValue();
      takeOffThrottle  = ((NSNumber)data.objectForKey(TAKE_OFF_THROTTLE)).floatValue();
      
      NSArray rawChannels = (NSArray)data.objectForKey(ApplicationSettings.CHANNELS);
      int channelCount = rawChannels.count();
    
      channels = new ArrayList<Channel>(channelCount);
      
      for(int channelIdx = 0; channelIdx < channelCount; channelIdx++){
        Channel oneChannel = new Channel(this, channelIdx);
        channels.add(oneChannel);
      }  
    } catch (Exception e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }
  
  public ApplicationSettings(InputStream inputStream)
  {
    try {
      data = (NSDictionary)PropertyListParser.parse(inputStream);
    } catch (Exception e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }
  
  public boolean save(){
    File file = new File(path);
    try {
      //save as xml??be compatible with the plist of iOS
      PropertyListParser.saveAsXML(data, file);
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      return false;
    }
    return true;
  }
  
  public void resetToDefault(){
    ApplicationSettings defaultSettings = new ApplicationSettings(HexMiniApplication.sharedApplicaion().getFilesDir() + "/DefaultSettings.plist");

    this.data = defaultSettings.getData();
    
    this.interfaceOpacity = defaultSettings.getInterfaceOpacity();
    this.isLeftHanded = defaultSettings.isLeftHanded();
    this.isAccMode = defaultSettings.isAccMode();
    this.isFirstRun = defaultSettings.isFirstRun();
    this.isHeadFreeMode = defaultSettings.isHeadFreeMode();
    this.isAltHoldMode = defaultSettings.isAltHoldMode();
    this.isBeginnerMode = defaultSettings.isBeginnerMode();
    this.aileronDeadBand = defaultSettings.getAileronDeadBand();
    this.elevatorDeadBand = defaultSettings.getElevatorDeadBand();
    this.rudderDeadBand = defaultSettings.getRudderDeadBand();
    this.takeOffThrottle = defaultSettings.getTakeOffThrottle();
    
    
    int channelCount = defaultSettings.getChannelCount();
    
    for(int defaultChannelIdx = 0; defaultChannelIdx < channelCount; defaultChannelIdx++){
      Channel defaultChannel = new Channel(defaultSettings, defaultChannelIdx);
      Channel channel =  this.getChannel(defaultChannel.getName());
      
          if(channel.getIdx() != defaultChannelIdx){
            Channel needsReordedChannel =channels.get(defaultChannelIdx);
              needsReordedChannel.setIdx(channel.getIdx()); 
              
              Channel tmp = channels.get(defaultChannelIdx);
              
              channels.set(defaultChannelIdx, channels.get(channel.getIdx()));
              channels.set(channel.getIdx(), tmp);
              
              channel.setIdx(defaultChannelIdx);
          }
          
          channel.setReversed(defaultChannel.isReversed());
          channel.setTrimValue(defaultChannel.getTrimValue());
          channel.setOutputAdjustabledRange(defaultChannel.getOutputAdjustabledRange());
          channel.setDefaultOutputValue(defaultChannel.getDefaultOutputValue());
          channel.setValue(channel.getDefaultOutputValue());
    }
  }
  
  public NSDictionary getData() {
    return data;
  }

  public void setData(NSDictionary data) {
    this.data = data;
  }

  public float getInterfaceOpacity() {
    return interfaceOpacity;
  }

  public void setInterfaceOpacity(float interfaceOpacity) {
    this.interfaceOpacity = interfaceOpacity;
    data.put(INTERFACE_OPACITY, interfaceOpacity);
  }
  
  public boolean isLeftHanded() {
    return isLeftHanded;
  }
  
  public boolean isFirstRun(){
    return isFirstRun;
  }

  public void setLeftHanded(boolean isLeftHanded) {
    this.isLeftHanded = isLeftHanded;
    data.put(IS_LEFT_HANDED, isLeftHanded);
  }
  
  public void setIsFirstRun(boolean isFirstRun) {
    this.isFirstRun = isFirstRun;
    data.put(IS_FIRST_RUN, isFirstRun);
  }
  
  public boolean isAccMode() {
    return isAccMode;
  }

  public void setIsAccMode(boolean isAccMode) {
    this.isAccMode = isAccMode;
    data.put(IS_ACC_MODE, isAccMode);
  }
  
  public boolean isHeadFreeMode() {
    return isHeadFreeMode;
  }

  public void setIsHeadFreeMode(boolean isHeadFreeMode) {
    this.isHeadFreeMode = isHeadFreeMode;
    data.put(IS_HEAD_FREE_MODE, isHeadFreeMode);
  }
  
  public boolean isAltHoldMode() {
    return isAltHoldMode;
  }
  
  public boolean isBeginnerMode() {
    return isBeginnerMode;
  }

  public void setIsBeginnerMode(boolean isBeginnerMode) {
    this.isBeginnerMode = isBeginnerMode;
    data.put(IS_BEGINNER_MODE, isBeginnerMode);
  }
  

  public void setIsAltHoldMode(boolean isAltHoldMode) {
    this.isAltHoldMode = isAltHoldMode;
    data.put(IS_LEFT_HANDED, isAltHoldMode);
  }
  
  public float getAileronDeadBand() {
    return aileronDeadBand;
  }

  public void setAileronDeadBand(float aileronDeadBand) {
    this.aileronDeadBand = aileronDeadBand;
    data.put(AILERON_DEAD_BAND, aileronDeadBand);
  }

  public float getElevatorDeadBand() {
    return elevatorDeadBand;
  }

  public void setElevatorDeadBand(float elevatorDeadBand) {
    this.elevatorDeadBand = elevatorDeadBand;
    data.put(ELEVATOR_DEAD_BAND, elevatorDeadBand);
  }

  public float getRudderDeadBand() {
    return rudderDeadBand;
  }

  public void setRudderDeadBand(float rudderDeadBand) {
    this.rudderDeadBand = rudderDeadBand;
    data.put(RUDDER_DEAD_BAND, rudderDeadBand);
  }
  
  public float getTakeOffThrottle() {
    return takeOffThrottle;
  }

  public void setTakeOffThrottle(float takeOffThrottle) {
    this.takeOffThrottle = takeOffThrottle;
    data.put(TAKE_OFF_THROTTLE, takeOffThrottle);
  }
  
  public int getChannelCount(){
      return channels.size();
  }

  public Channel getChannel(int idx){
      if(idx < channels.size()){
        return channels.get(idx);
      }
      else{
        return null;
      }    
  }

  public Channel getChannel(String name){
      for(Channel oneChannel : channels){
        if(name.equals(oneChannel.getName())){
          return oneChannel;
        }
      }
      
      return null;
  }
}




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