mirror of
https://github.com/bspeice/itcs4180
synced 2024-12-04 13:18:16 -05:00
Added image download functionality
This commit is contained in:
parent
995919644b
commit
e8f4fe9a7b
@ -13,6 +13,13 @@
|
|||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
android:orientation="vertical" >
|
android:orientation="vertical" >
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/locationText"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center_horizontal"
|
||||||
|
android:text="@string/default_text" />
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
android:id="@+id/locationImage"
|
android:id="@+id/locationImage"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
|
@ -12,6 +12,7 @@ import java.util.List;
|
|||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.util.Log;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
@ -43,6 +44,7 @@ public class MainActivity extends Activity {
|
|||||||
location.setLocationLong(-80.733734);
|
location.setLocationLong(-80.733734);
|
||||||
location.setLocationLat(35.310043);
|
location.setLocationLat(35.310043);
|
||||||
location.setKey("Key");
|
location.setKey("Key");
|
||||||
|
location.setLocationImageUrl("");
|
||||||
Intent intent = new Intent(getApplicationContext(), SearchActivity.class);
|
Intent intent = new Intent(getApplicationContext(), SearchActivity.class);
|
||||||
intent.putExtra("restLocation", location);
|
intent.putExtra("restLocation", location);
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
@ -69,6 +71,7 @@ public class MainActivity extends Activity {
|
|||||||
// We don't yet have any locations...
|
// We don't yet have any locations...
|
||||||
((TextView)findViewById(R.id.txtNoLocations)).setVisibility(View.VISIBLE);
|
((TextView)findViewById(R.id.txtNoLocations)).setVisibility(View.VISIBLE);
|
||||||
((ListView)findViewById(R.id.listLocations)).setVisibility(View.GONE);
|
((ListView)findViewById(R.id.listLocations)).setVisibility(View.GONE);
|
||||||
|
Log.d("NoLocation", "NoLocations");
|
||||||
}
|
}
|
||||||
|
|
||||||
// And kick off contacting to server to see if there are any new ones
|
// And kick off contacting to server to see if there are any new ones
|
||||||
|
@ -7,11 +7,18 @@ package edu.uncc.scavenger;
|
|||||||
* SearchActivity.java
|
* SearchActivity.java
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import java.net.URL;
|
||||||
|
|
||||||
|
import com.example.hw4.ImageViewerActivity.ImageDownloader;
|
||||||
|
|
||||||
import edu.uncc.scavenger.rest.RestLocation;
|
import edu.uncc.scavenger.rest.RestLocation;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.ActivityNotFoundException;
|
import android.content.ActivityNotFoundException;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.graphics.Bitmap;
|
||||||
|
import android.graphics.BitmapFactory;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
import android.os.AsyncTask;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
@ -27,7 +34,7 @@ public class SearchActivity extends Activity {
|
|||||||
|
|
||||||
ImageView locationImage;
|
ImageView locationImage;
|
||||||
Button compassButton, scanButton;
|
Button compassButton, scanButton;
|
||||||
TextView riddleView;
|
TextView locationText, riddleView;
|
||||||
Intent intent;
|
Intent intent;
|
||||||
RestLocation restLocation;
|
RestLocation restLocation;
|
||||||
|
|
||||||
@ -36,14 +43,20 @@ public class SearchActivity extends Activity {
|
|||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.activity_search);
|
setContentView(R.layout.activity_search);
|
||||||
|
|
||||||
|
locationText = (TextView)findViewById(R.id.locationText);
|
||||||
locationImage = (ImageView)findViewById(R.id.locationImage);
|
locationImage = (ImageView)findViewById(R.id.locationImage);
|
||||||
compassButton = (Button)findViewById(R.id.compassButton);
|
compassButton = (Button)findViewById(R.id.compassButton);
|
||||||
scanButton = (Button)findViewById(R.id.scanButton);
|
scanButton = (Button)findViewById(R.id.scanButton);
|
||||||
riddleView = (TextView)findViewById(R.id.riddleView);
|
riddleView = (TextView)findViewById(R.id.riddleView);
|
||||||
|
|
||||||
|
restLocation = (RestLocation)(getIntent().getSerializableExtra("restLocation"));
|
||||||
|
Log.d("restLocation", restLocation.getName());
|
||||||
|
|
||||||
|
locationText.setText(restLocation.getName());
|
||||||
|
riddleView.setText(restLocation.getRiddle());
|
||||||
|
|
||||||
//TODO
|
//TODO
|
||||||
//Load picture
|
//Load picture
|
||||||
//Load riddle
|
|
||||||
//Load hints
|
//Load hints
|
||||||
|
|
||||||
scanButton.setOnClickListener(new OnClickListener(){
|
scanButton.setOnClickListener(new OnClickListener(){
|
||||||
@ -75,8 +88,7 @@ public class SearchActivity extends Activity {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
restLocation = (RestLocation)(getIntent().getSerializableExtra("restLocation"));
|
new ImageDownloader().execute(restLocation.getLocationImageUrl());
|
||||||
Log.d("restLocation", restLocation.getName());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -123,4 +135,27 @@ public class SearchActivity extends Activity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private class ImageDownloader extends AsyncTask<String, Void, Bitmap> {
|
||||||
|
@Override
|
||||||
|
protected Bitmap doInBackground(String... params) {
|
||||||
|
try
|
||||||
|
{
|
||||||
|
URL imageUrl = new URL(params[0]);
|
||||||
|
return BitmapFactory.decodeStream(imageUrl.openStream());
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onPostExecute(Bitmap result) {
|
||||||
|
|
||||||
|
locationImage.setImageBitmap(result);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user