Android Open Source - mha-android Configuration Manager






From Project

Back to project page mha-android.

License

The source code is released under:

Copyright (c) 2011-2012 Cameron Porter, Ryan Brown http://github.com/camporter/mha-android Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated...

If you think the Android project mha-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.teamacra.myhomeaudio.manager;
// w  w w . j a va  2 s . c om
import java.util.ArrayList;
import java.util.Iterator;

import org.json.JSONArray;

import com.teamacra.myhomeaudio.MHAApplication;
import com.teamacra.myhomeaudio.locations.NodeSignature;
import com.teamacra.myhomeaudio.node.Node;

/**
 * Maintains the entire configuration of nodes for this client.
 * 
 * @author Cameron
 * 
 */
public class ConfigurationManager {

  private ArrayList<NodeSignature> signatures;
  private static ConfigurationManager instance;
  private MHAApplication app;

  private ConfigurationManager(MHAApplication app) {
    this.app = app;
    this.signatures = new ArrayList<NodeSignature>();
  }

  public synchronized static ConfigurationManager getInstance(
      MHAApplication app) {
    if (instance == null) {
      instance = new ConfigurationManager(app);
    }
    return instance;
  }

  /**
   * Records a device found during the configuration process. It also checks
   * to make sure that the device is an actual node using the NodeManager,
   * since we don't care about non-node bluetooth devices.
   * 
   * @param currentNode
   *            The node for the room that the user is currently in. (Not
   *            necessarily the same as the device being stored!)
   * @param bluetoothName
   *            The bluetooth name for the device.
   * @param bluetoothAddress
   *            The bluetooth address for the device.
   * @param rssi
   *            The rssi value that we get for the device.
   * @return Whether the device is a node or not.
   */
  public boolean storeDeviceSignal(Node currentNode, String bluetoothName,
      String bluetoothAddress, int rssi) {

    NodeManager nm = NodeManager.getInstance(app);

    Node device = nm.getNode(bluetoothName, bluetoothAddress, true);
    // Make sure that: The device exists as an active node, the current node
    // can be found in the node manager, and the current node is active.
    if (device != null && nm.nodeExists(currentNode)
        && currentNode.isActive()) {

      // Try to get the signature for the current node that the signal is
      // being recorded under
      NodeSignature currentNodeSignature = getSignature(currentNode);
      if (currentNodeSignature == null) {
        // The current node does not have a signature yet, so create it
        // and add it to the list of signatures.
        currentNodeSignature = new NodeSignature(currentNode);
        signatures.add(currentNodeSignature);
      }
      
      // Store the device and rssi value in the signature
      
      return currentNodeSignature.storeSignal(device, rssi);
    }
    return false;
  }

  /**
   * Get the given node's signature.
   * 
   * @param node
   *            The node to get the signature of, or null if the given Node
   *            does not have a signature.
   */
  private NodeSignature getSignature(Node node) {
    for (Iterator<NodeSignature> i = signatures.iterator(); i.hasNext();) {
      NodeSignature nextSignature = i.next();
      if (nextSignature.getNode() == node) {
        return nextSignature;
      }
    }
    return null;
  }
  
  /**
   * Clears the configuration.
   * 
   */
  public void resetSignatures() {
    signatures.clear();
  }
  
  
  public JSONArray getConfigurationJSON() {
    JSONArray array = new JSONArray();
    
    for (Iterator<NodeSignature> i = signatures.iterator(); i.hasNext();) {
      array.put(i.next().toJSON());
    }
    
    return array;
  }
}




Java Source Code List

com.teamacra.myhomeaudio.MHAApplication.java
com.teamacra.myhomeaudio.bluetooth.BluetoothService.java
com.teamacra.myhomeaudio.discovery.DiscoveryConstants.java
com.teamacra.myhomeaudio.discovery.DiscoveryDescription.java
com.teamacra.myhomeaudio.discovery.DiscoverySearchListener.java
com.teamacra.myhomeaudio.discovery.DiscoverySearch.java
com.teamacra.myhomeaudio.discovery.MDNSDiscovery.java
com.teamacra.myhomeaudio.http.HttpBase.java
com.teamacra.myhomeaudio.http.HttpClient.java
com.teamacra.myhomeaudio.http.HttpNode.java
com.teamacra.myhomeaudio.http.HttpSource.java
com.teamacra.myhomeaudio.http.HttpStream.java
com.teamacra.myhomeaudio.http.StatusCode.java
com.teamacra.myhomeaudio.locations.NodeSignalRange.java
com.teamacra.myhomeaudio.locations.NodeSignature.java
com.teamacra.myhomeaudio.manager.ConfigurationManager.java
com.teamacra.myhomeaudio.manager.LocationManager.java
com.teamacra.myhomeaudio.manager.NodeManager.java
com.teamacra.myhomeaudio.manager.StreamManager.java
com.teamacra.myhomeaudio.media.MediaDescriptor.java
com.teamacra.myhomeaudio.node.Node.java
com.teamacra.myhomeaudio.source.Source.java
com.teamacra.myhomeaudio.stream.StreamAction.java
com.teamacra.myhomeaudio.stream.Stream.java
com.teamacra.myhomeaudio.ui.InitialConfigActivity.java
com.teamacra.myhomeaudio.ui.LoginActivity.java
com.teamacra.myhomeaudio.ui.MyHomeAudioActivity.java
com.teamacra.myhomeaudio.ui.RegisterActivity.java
com.teamacra.myhomeaudio.ui.fragment.SongFragment.java
com.teamacra.myhomeaudio.ui.fragment.SourceFragment.java
com.teamacra.myhomeaudio.ui.fragment.TestFragment.java