1
0
mirror of https://github.com/bspeice/itcs4180 synced 2024-12-04 21:28:10 -05:00

Added function to save images to storage and load them. Compass image

will now change to the location when you get close.
This commit is contained in:
tokugawa 2014-04-19 23:02:52 -04:00
parent d8b067b9fa
commit 782a31eb4d
5 changed files with 130 additions and 17 deletions

View File

@ -13,7 +13,7 @@
android:layout_weight="1" >
<ImageView
android:id="@+id/compassRose"
android:id="@+id/compassRoseView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_centerHorizontal="true"
@ -30,6 +30,14 @@
android:layout_weight="1"
android:src="@drawable/arrow_up" />
<ImageView
android:id="@+id/searchImageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:src="@drawable/ic_launcher" />
</RelativeLayout>
<Button

View File

@ -0,0 +1,69 @@
package edu.uncc.scavenger;
/*
* Bradlee Speice, Brandon Rodenmayer
* ITIS 4180
* UNCCScavenger (NinerFinder)
* CompassActivity.java
*/
//Reference: stackoverflow.com/questions/19978100/how-to-save-bitmap-on-internal-storage-download-from-internet
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.util.Log;
public class BitmapAccess
{
public static Bitmap loadBitmap(Context context, String picName)
{
Bitmap b = null;
FileInputStream fis;
try
{
fis = context.openFileInput(picName);
b = BitmapFactory.decodeStream(fis);
fis.close();
}
catch(FileNotFoundException e)
{
Log.d("BitmapAccess", "FileNotFound_Load");
}
catch(IOException e)
{
Log.d("BitmapAccess", "IOException_Load");
}
return b;
}
public static boolean saveBitmap(Context context, Bitmap b, String picName)
{
boolean saved = false;
FileOutputStream fos;
try
{
fos = context.openFileOutput(picName, Context.MODE_PRIVATE);
b.compress(Bitmap.CompressFormat.PNG, 100, fos);
fos.close();
}
catch(FileNotFoundException e)
{
Log.d("BitmapAccess", "FileNotFound_Save");
}
catch(IOException e)
{
Log.d("BitmapAccess", "IOException_Save");
}
return saved;
}
}

View File

@ -11,8 +11,10 @@ package edu.uncc.scavenger;
* stackoverflow.com/questions/5479753/using-orientation-sensor-to-point-towards-a-specific-location
*/
import edu.uncc.scavenger.rest.RestLocation;
import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
@ -26,10 +28,12 @@ import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.Toast;
public class CompassActivity extends Activity implements SensorEventListener
{
ImageView compass, arrowView;
final int SEARCH_PROXIMITY = 10;
ImageView compassRoseView, arrowView, searchImageView;
Button backButton;
SensorManager sManager;
Sensor aSensor, mSensor;
@ -43,25 +47,35 @@ public class CompassActivity extends Activity implements SensorEventListener
LocationManager locationManager;
DirectionListener locationListener;
Location searchLocation;
Location testLocation = new Location(LocationManager.NETWORK_PROVIDER);
RestLocation restLocation;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_compass);
restLocation = (RestLocation)(getIntent().getSerializableExtra("restLocation"));
arrowView = (ImageView)findViewById(R.id.arrowView);
compass = (ImageView)findViewById(R.id.compassRose);
compassRoseView = (ImageView)findViewById(R.id.compassRoseView);
searchImageView = (ImageView)findViewById(R.id.searchImageView);
searchImageView.setVisibility(View.INVISIBLE);
Bitmap b = BitmapAccess.loadBitmap(getApplicationContext(), restLocation.getName());
if(b != null)
{
searchImageView.setImageBitmap(b);
}
/*Test Values
testLocation.setLatitude(35.30719258);//woodward eagle
testLocation.setLongitude(-80.73505447);
testLocation.setLatitude(35.310043);//Bottom of Student Union bridge
testLocation.setLongitude(-80.733734);*/
searchLocation.setLatitude(35.30719258);//woodward eagle
searchLocation.setLongitude(-80.73505447);
searchLocation = new Location(LocationManager.NETWORK_PROVIDER);
searchLocation.setLatitude(35.310043);//Bottom of Student Union bridge
searchLocation.setLongitude(-80.733734);*/
searchLocation = new Location(LocationManager.NETWORK_PROVIDER);
searchLocation.setLatitude(getIntent().getDoubleExtra("searchLat", 0));
searchLocation.setLongitude(getIntent().getDoubleExtra("searchLong", 0));
searchLocation.setLatitude(restLocation.getLocationLat());
searchLocation.setLongitude(restLocation.getLocationLong());
locationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
locationListener = new DirectionListener(searchLocation);
@ -79,6 +93,8 @@ public class CompassActivity extends Activity implements SensorEventListener
finish();
}
});
Toast.makeText(getApplicationContext(), ""+searchLocation.getLatitude()+", "+searchLocation.getLongitude(), Toast.LENGTH_SHORT).show();
}
@Override
@ -146,11 +162,21 @@ public class CompassActivity extends Activity implements SensorEventListener
float rotateArrow = (float) (trueHeading - locationListener.getBearing());
//Rotate compass and arrow. Rotations must be opposite to counteract device movement
compass.setRotation((long)(-1 * trueHeading));
compassRoseView.setRotation((long)(-1 * trueHeading));
arrowView.setRotation((long)(-1 * rotateArrow));
//TODO
//If within 5 to 10 meters, display image of search
if(locationListener.getDistance() < SEARCH_PROXIMITY)
{
arrowView.setVisibility(View.INVISIBLE);
compassRoseView.setVisibility(View.INVISIBLE);
searchImageView.setVisibility(View.VISIBLE);
}
else
{
arrowView.setVisibility(View.VISIBLE);
compassRoseView.setVisibility(View.VISIBLE);
searchImageView.setVisibility(View.INVISIBLE);
}
}
@Override

View File

@ -22,6 +22,7 @@ import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import edu.uncc.scavenger.database.LocationDatabaseHelper;
import edu.uncc.scavenger.rest.LocationClient;
import edu.uncc.scavenger.rest.RestLocation;
@ -36,7 +37,7 @@ public class MainActivity extends Activity {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
/*Test Code
/*Test Code for mock location
RestLocation location = new RestLocation();
location.setId(1);
location.setName("Bridge");
@ -93,6 +94,7 @@ public class MainActivity extends Activity {
}
}.execute();
//Toast.makeText(getApplicationContext(), ""+locations.get(0).getLocationImageURL(), Toast.LENGTH_SHORT).show();
}
@Override

View File

@ -102,8 +102,7 @@ public class SearchActivity extends Activity {
if(lm.isProviderEnabled(LocationManager.GPS_PROVIDER))
{
intent = new Intent(getApplicationContext(), CompassActivity.class);
intent.putExtra("searchLat", restLocation.getLocationLat());
intent.putExtra("searchLong", restLocation.getLocationLong());
intent.putExtra("restLocation", restLocation);
startActivity(intent);
}
else
@ -132,8 +131,16 @@ public class SearchActivity extends Activity {
});
//Toast.makeText(getApplicationContext(), restLocation.getLocationImageURL(), Toast.LENGTH_SHORT).show();
Bitmap locationPicture = BitmapAccess.loadBitmap(getApplicationContext(), restLocation.getName());
if(locationPicture != null)
{
locationImage.setImageBitmap(locationPicture);
}
else
{
new ImageDownloader().execute(restLocation.getLocationImageURL());
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
@ -202,6 +209,7 @@ public class SearchActivity extends Activity {
if(result!=null)
{
locationImage.setImageBitmap(result);
BitmapAccess.saveBitmap(getApplicationContext(), result, restLocation.getName());
}
}
}