mirror of
				https://github.com/bspeice/itcs4180
				synced 2025-11-03 18:00:37 -05:00 
			
		
		
		
	Merge branch 'master' of git@github.com:DjBushido/itcs4180.git
This commit is contained in:
		
							
								
								
									
										
											BIN
										
									
								
								UNCCScavenger/res/drawable-xhdpi/ic_location_found.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								UNCCScavenger/res/drawable-xhdpi/ic_location_found.png
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| 
		 After Width: | Height: | Size: 5.9 KiB  | 
@ -11,6 +11,9 @@ package edu.uncc.scavenger;
 | 
				
			|||||||
 * stackoverflow.com/questions/5479753/using-orientation-sensor-to-point-towards-a-specific-location
 | 
					 * stackoverflow.com/questions/5479753/using-orientation-sensor-to-point-towards-a-specific-location
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import java.util.ArrayList;
 | 
				
			||||||
 | 
					import java.util.List;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import edu.uncc.scavenger.rest.RestLocation;
 | 
					import edu.uncc.scavenger.rest.RestLocation;
 | 
				
			||||||
import android.app.Activity;
 | 
					import android.app.Activity;
 | 
				
			||||||
import android.content.Context;
 | 
					import android.content.Context;
 | 
				
			||||||
@ -33,6 +36,7 @@ import android.widget.Toast;
 | 
				
			|||||||
public class CompassActivity extends Activity implements SensorEventListener
 | 
					public class CompassActivity extends Activity implements SensorEventListener
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	final int SEARCH_PROXIMITY = 10;
 | 
						final int SEARCH_PROXIMITY = 10;
 | 
				
			||||||
 | 
						final int MOVING_AVERAGE_SIZE = 10;
 | 
				
			||||||
	ImageView compassRoseView, arrowView, searchImageView;
 | 
						ImageView compassRoseView, arrowView, searchImageView;
 | 
				
			||||||
	Button backButton;
 | 
						Button backButton;
 | 
				
			||||||
	SensorManager sManager;
 | 
						SensorManager sManager;
 | 
				
			||||||
@ -44,6 +48,7 @@ public class CompassActivity extends Activity implements SensorEventListener
 | 
				
			|||||||
	float[] gravity = new float[3];
 | 
						float[] gravity = new float[3];
 | 
				
			||||||
	float[] magneticField = new float[3];
 | 
						float[] magneticField = new float[3];
 | 
				
			||||||
	float[] coordinates = new float[3];
 | 
						float[] coordinates = new float[3];
 | 
				
			||||||
 | 
						ArrayList<Float> rotationAverage = new ArrayList<Float>(MOVING_AVERAGE_SIZE);
 | 
				
			||||||
	LocationManager locationManager;
 | 
						LocationManager locationManager;
 | 
				
			||||||
	DirectionListener locationListener;
 | 
						DirectionListener locationListener;
 | 
				
			||||||
	Location searchLocation;
 | 
						Location searchLocation;
 | 
				
			||||||
@ -160,10 +165,17 @@ public class CompassActivity extends Activity implements SensorEventListener
 | 
				
			|||||||
		float trueHeading = (float)(Math.toDegrees(compassValues[0]) + locationListener.getDeclination());
 | 
							float trueHeading = (float)(Math.toDegrees(compassValues[0]) + locationListener.getDeclination());
 | 
				
			||||||
		//Calculate bearing to search location
 | 
							//Calculate bearing to search location
 | 
				
			||||||
		float rotateArrow = (float) (trueHeading - locationListener.getBearing());
 | 
							float rotateArrow = (float) (trueHeading - locationListener.getBearing());
 | 
				
			||||||
 | 
							// Take moving average of bearing to smooth it out
 | 
				
			||||||
 | 
							if (rotationAverage.size() == MOVING_AVERAGE_SIZE) {
 | 
				
			||||||
 | 
								rotationAverage.remove(0);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							rotationAverage.add(rotateArrow);
 | 
				
			||||||
 | 
							float finalRotation = findAverage(rotationAverage);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		//Rotate compass and arrow. Rotations must be opposite to counteract device movement
 | 
							//Rotate compass and arrow. Rotations must be opposite to counteract device movement
 | 
				
			||||||
		compassRoseView.setRotation((long)(-1 * trueHeading));
 | 
							compassRoseView.setRotation((long)(-1 * trueHeading));
 | 
				
			||||||
		arrowView.setRotation((long)(-1 * rotateArrow));
 | 
							arrowView.setRotation((long)(-1 * finalRotation));
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		if(locationListener.getDistance() <= SEARCH_PROXIMITY)
 | 
							if(locationListener.getDistance() <= SEARCH_PROXIMITY)
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
@ -184,4 +196,12 @@ public class CompassActivity extends Activity implements SensorEventListener
 | 
				
			|||||||
		// TODO Auto-generated method stub
 | 
							// TODO Auto-generated method stub
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						private float findAverage(List<Float> list) {
 | 
				
			||||||
 | 
							float sum = 0.0f;
 | 
				
			||||||
 | 
							for (Float f : list) {
 | 
				
			||||||
 | 
								sum += f;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							return sum / list.size();
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user