Android Open Source - mha-android Location 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;
/*from   www .  j a v a  2  s .  co m*/
import java.util.ArrayList;


import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.teamacra.myhomeaudio.MHAApplication;
import com.teamacra.myhomeaudio.locations.NodeSignature;
import com.teamacra.myhomeaudio.node.Node;
import android.util.Log;

public class LocationManager {
  private ArrayList<Device> devices;
  private static LocationManager instance;
  private MHAApplication app;
  private String TAG = "LocationManager";
  
  private class Device{
    private final int id;
    private final int rssi;
    
    private Device(int id, int rssi){
      this.id = id;
      this.rssi = rssi;
    }
    
    private Device(Device device){
      this.id = device.id;
      this.rssi = device.rssi;
    }
    
    private JSONObject toJSONObject(){
      JSONObject obj = new JSONObject();
      try {
        obj.put("id", id);
        obj.put("rssi", rssi);
      } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
      return obj;
    }
  }

  private LocationManager(MHAApplication app) {
    this.app = app;
    this.devices = new ArrayList<Device>();
  }

  public synchronized static LocationManager getInstance(
      MHAApplication app) {
    if (instance == null) {
      instance = new LocationManager(app);
    }
    return instance;
  }
  
  public boolean storeNode(String name, String bluetoothAddress, int rssi){
    NodeManager nm = NodeManager.getInstance(app);
    Node node = nm.getNode(name, bluetoothAddress,  true);
    if(node != null){
      Device device = getDevice(node);
      if(getDevice(node) == null){
        devices.add(new Device(node.id(),rssi));        
      }else{
        devices.set(devices.indexOf(device),new Device(node.id(),rssi));
        Log.d(TAG,"Replacing " + node.name() + " rssi " + device.rssi + " to "+rssi);
      }
    }
  
    return false;
  }
  
  private Device getDevice(Node node) {
    for(Device device : devices){
      if(device.id == node.id()){
        return device;
      }
    }
    return null;
  }

  public void clear(){
    devices.clear();
  }
  
  public JSONArray getLocationJSONArray(){
    JSONArray array = new JSONArray();
    for(Device device : devices){
      array.put(new Device(device).toJSONObject());
    }
    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