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:
parent
d8b067b9fa
commit
782a31eb4d
@ -13,7 +13,7 @@
|
|||||||
android:layout_weight="1" >
|
android:layout_weight="1" >
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
android:id="@+id/compassRose"
|
android:id="@+id/compassRoseView"
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
android:layout_height="fill_parent"
|
android:layout_height="fill_parent"
|
||||||
android:layout_centerHorizontal="true"
|
android:layout_centerHorizontal="true"
|
||||||
@ -30,6 +30,14 @@
|
|||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
android:src="@drawable/arrow_up" />
|
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>
|
</RelativeLayout>
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
|
69
UNCCScavenger/src/edu/uncc/scavenger/BitmapAccess.java
Normal file
69
UNCCScavenger/src/edu/uncc/scavenger/BitmapAccess.java
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
@ -11,8 +11,10 @@ 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 edu.uncc.scavenger.rest.RestLocation;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.graphics.Bitmap;
|
||||||
import android.hardware.Sensor;
|
import android.hardware.Sensor;
|
||||||
import android.hardware.SensorEvent;
|
import android.hardware.SensorEvent;
|
||||||
import android.hardware.SensorEventListener;
|
import android.hardware.SensorEventListener;
|
||||||
@ -26,10 +28,12 @@ import android.view.View;
|
|||||||
import android.view.View.OnClickListener;
|
import android.view.View.OnClickListener;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
public class CompassActivity extends Activity implements SensorEventListener
|
public class CompassActivity extends Activity implements SensorEventListener
|
||||||
{
|
{
|
||||||
ImageView compass, arrowView;
|
final int SEARCH_PROXIMITY = 10;
|
||||||
|
ImageView compassRoseView, arrowView, searchImageView;
|
||||||
Button backButton;
|
Button backButton;
|
||||||
SensorManager sManager;
|
SensorManager sManager;
|
||||||
Sensor aSensor, mSensor;
|
Sensor aSensor, mSensor;
|
||||||
@ -43,25 +47,35 @@ public class CompassActivity extends Activity implements SensorEventListener
|
|||||||
LocationManager locationManager;
|
LocationManager locationManager;
|
||||||
DirectionListener locationListener;
|
DirectionListener locationListener;
|
||||||
Location searchLocation;
|
Location searchLocation;
|
||||||
Location testLocation = new Location(LocationManager.NETWORK_PROVIDER);
|
RestLocation restLocation;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.activity_compass);
|
setContentView(R.layout.activity_compass);
|
||||||
|
|
||||||
|
restLocation = (RestLocation)(getIntent().getSerializableExtra("restLocation"));
|
||||||
|
|
||||||
arrowView = (ImageView)findViewById(R.id.arrowView);
|
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
|
/*Test Values
|
||||||
testLocation.setLatitude(35.30719258);//woodward eagle
|
searchLocation.setLatitude(35.30719258);//woodward eagle
|
||||||
testLocation.setLongitude(-80.73505447);
|
searchLocation.setLongitude(-80.73505447);
|
||||||
testLocation.setLatitude(35.310043);//Bottom of Student Union bridge
|
searchLocation = new Location(LocationManager.NETWORK_PROVIDER);
|
||||||
testLocation.setLongitude(-80.733734);*/
|
searchLocation.setLatitude(35.310043);//Bottom of Student Union bridge
|
||||||
|
searchLocation.setLongitude(-80.733734);*/
|
||||||
|
|
||||||
searchLocation = new Location(LocationManager.NETWORK_PROVIDER);
|
searchLocation = new Location(LocationManager.NETWORK_PROVIDER);
|
||||||
searchLocation.setLatitude(getIntent().getDoubleExtra("searchLat", 0));
|
searchLocation.setLatitude(restLocation.getLocationLat());
|
||||||
searchLocation.setLongitude(getIntent().getDoubleExtra("searchLong", 0));
|
searchLocation.setLongitude(restLocation.getLocationLong());
|
||||||
|
|
||||||
locationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
|
locationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
|
||||||
locationListener = new DirectionListener(searchLocation);
|
locationListener = new DirectionListener(searchLocation);
|
||||||
@ -79,6 +93,8 @@ public class CompassActivity extends Activity implements SensorEventListener
|
|||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Toast.makeText(getApplicationContext(), ""+searchLocation.getLatitude()+", "+searchLocation.getLongitude(), Toast.LENGTH_SHORT).show();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -146,11 +162,21 @@ public class CompassActivity extends Activity implements SensorEventListener
|
|||||||
float rotateArrow = (float) (trueHeading - locationListener.getBearing());
|
float rotateArrow = (float) (trueHeading - locationListener.getBearing());
|
||||||
|
|
||||||
//Rotate compass and arrow. Rotations must be opposite to counteract device movement
|
//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));
|
arrowView.setRotation((long)(-1 * rotateArrow));
|
||||||
|
|
||||||
//TODO
|
if(locationListener.getDistance() < SEARCH_PROXIMITY)
|
||||||
//If within 5 to 10 meters, display image of search
|
{
|
||||||
|
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
|
@Override
|
||||||
|
@ -22,6 +22,7 @@ import android.widget.BaseAdapter;
|
|||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
import android.widget.Toast;
|
||||||
import edu.uncc.scavenger.database.LocationDatabaseHelper;
|
import edu.uncc.scavenger.database.LocationDatabaseHelper;
|
||||||
import edu.uncc.scavenger.rest.LocationClient;
|
import edu.uncc.scavenger.rest.LocationClient;
|
||||||
import edu.uncc.scavenger.rest.RestLocation;
|
import edu.uncc.scavenger.rest.RestLocation;
|
||||||
@ -36,7 +37,7 @@ public class MainActivity extends Activity {
|
|||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.activity_main);
|
setContentView(R.layout.activity_main);
|
||||||
|
|
||||||
/*Test Code
|
/*Test Code for mock location
|
||||||
RestLocation location = new RestLocation();
|
RestLocation location = new RestLocation();
|
||||||
location.setId(1);
|
location.setId(1);
|
||||||
location.setName("Bridge");
|
location.setName("Bridge");
|
||||||
@ -93,6 +94,7 @@ public class MainActivity extends Activity {
|
|||||||
}
|
}
|
||||||
}.execute();
|
}.execute();
|
||||||
|
|
||||||
|
//Toast.makeText(getApplicationContext(), ""+locations.get(0).getLocationImageURL(), Toast.LENGTH_SHORT).show();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -102,8 +102,7 @@ public class SearchActivity extends Activity {
|
|||||||
if(lm.isProviderEnabled(LocationManager.GPS_PROVIDER))
|
if(lm.isProviderEnabled(LocationManager.GPS_PROVIDER))
|
||||||
{
|
{
|
||||||
intent = new Intent(getApplicationContext(), CompassActivity.class);
|
intent = new Intent(getApplicationContext(), CompassActivity.class);
|
||||||
intent.putExtra("searchLat", restLocation.getLocationLat());
|
intent.putExtra("restLocation", restLocation);
|
||||||
intent.putExtra("searchLong", restLocation.getLocationLong());
|
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -132,7 +131,15 @@ public class SearchActivity extends Activity {
|
|||||||
});
|
});
|
||||||
|
|
||||||
//Toast.makeText(getApplicationContext(), restLocation.getLocationImageURL(), Toast.LENGTH_SHORT).show();
|
//Toast.makeText(getApplicationContext(), restLocation.getLocationImageURL(), Toast.LENGTH_SHORT).show();
|
||||||
new ImageDownloader().execute(restLocation.getLocationImageURL());
|
Bitmap locationPicture = BitmapAccess.loadBitmap(getApplicationContext(), restLocation.getName());
|
||||||
|
if(locationPicture != null)
|
||||||
|
{
|
||||||
|
locationImage.setImageBitmap(locationPicture);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
new ImageDownloader().execute(restLocation.getLocationImageURL());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -202,6 +209,7 @@ public class SearchActivity extends Activity {
|
|||||||
if(result!=null)
|
if(result!=null)
|
||||||
{
|
{
|
||||||
locationImage.setImageBitmap(result);
|
locationImage.setImageBitmap(result);
|
||||||
|
BitmapAccess.saveBitmap(getApplicationContext(), result, restLocation.getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user