mirror of
				https://github.com/bspeice/itcs4180
				synced 2025-11-04 02:10:32 -05:00 
			
		
		
		
	Added image download functionality
This commit is contained in:
		@ -13,6 +13,13 @@
 | 
			
		||||
        android:layout_weight="1"
 | 
			
		||||
        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
 | 
			
		||||
            android:id="@+id/locationImage"
 | 
			
		||||
            android:layout_width="wrap_content"
 | 
			
		||||
 | 
			
		||||
@ -12,6 +12,7 @@ import java.util.List;
 | 
			
		||||
import android.app.Activity;
 | 
			
		||||
import android.content.Intent;
 | 
			
		||||
import android.os.Bundle;
 | 
			
		||||
import android.util.Log;
 | 
			
		||||
import android.view.Menu;
 | 
			
		||||
import android.view.View;
 | 
			
		||||
import android.view.ViewGroup;
 | 
			
		||||
@ -43,6 +44,7 @@ public class MainActivity extends Activity {
 | 
			
		||||
		location.setLocationLong(-80.733734);
 | 
			
		||||
		location.setLocationLat(35.310043);
 | 
			
		||||
		location.setKey("Key");
 | 
			
		||||
		location.setLocationImageUrl("");
 | 
			
		||||
		Intent intent = new Intent(getApplicationContext(), SearchActivity.class);
 | 
			
		||||
		intent.putExtra("restLocation", location);
 | 
			
		||||
		startActivity(intent);
 | 
			
		||||
@ -69,6 +71,7 @@ public class MainActivity extends Activity {
 | 
			
		||||
			// We don't yet have any locations...
 | 
			
		||||
			((TextView)findViewById(R.id.txtNoLocations)).setVisibility(View.VISIBLE);
 | 
			
		||||
			((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
 | 
			
		||||
 | 
			
		||||
@ -7,11 +7,18 @@ package edu.uncc.scavenger;
 | 
			
		||||
 * SearchActivity.java
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
import java.net.URL;
 | 
			
		||||
 | 
			
		||||
import com.example.hw4.ImageViewerActivity.ImageDownloader;
 | 
			
		||||
 | 
			
		||||
import edu.uncc.scavenger.rest.RestLocation;
 | 
			
		||||
import android.app.Activity;
 | 
			
		||||
import android.content.ActivityNotFoundException;
 | 
			
		||||
import android.content.Intent;
 | 
			
		||||
import android.graphics.Bitmap;
 | 
			
		||||
import android.graphics.BitmapFactory;
 | 
			
		||||
import android.net.Uri;
 | 
			
		||||
import android.os.AsyncTask;
 | 
			
		||||
import android.os.Bundle;
 | 
			
		||||
import android.util.Log;
 | 
			
		||||
import android.view.Menu;
 | 
			
		||||
@ -27,7 +34,7 @@ public class SearchActivity extends Activity {
 | 
			
		||||
 | 
			
		||||
	ImageView locationImage;
 | 
			
		||||
	Button compassButton, scanButton;
 | 
			
		||||
	TextView riddleView;
 | 
			
		||||
	TextView locationText, riddleView;
 | 
			
		||||
	Intent intent;
 | 
			
		||||
	RestLocation restLocation;
 | 
			
		||||
	
 | 
			
		||||
@ -36,14 +43,20 @@ public class SearchActivity extends Activity {
 | 
			
		||||
		super.onCreate(savedInstanceState);
 | 
			
		||||
		setContentView(R.layout.activity_search);
 | 
			
		||||
		
 | 
			
		||||
		locationText = (TextView)findViewById(R.id.locationText);
 | 
			
		||||
		locationImage = (ImageView)findViewById(R.id.locationImage);
 | 
			
		||||
		compassButton = (Button)findViewById(R.id.compassButton);
 | 
			
		||||
		scanButton = (Button)findViewById(R.id.scanButton);
 | 
			
		||||
		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
 | 
			
		||||
		//Load picture
 | 
			
		||||
		//Load riddle
 | 
			
		||||
		//Load hints
 | 
			
		||||
		
 | 
			
		||||
		scanButton.setOnClickListener(new OnClickListener(){
 | 
			
		||||
@ -75,8 +88,7 @@ public class SearchActivity extends Activity {
 | 
			
		||||
			}
 | 
			
		||||
		});
 | 
			
		||||
		
 | 
			
		||||
		restLocation = (RestLocation)(getIntent().getSerializableExtra("restLocation"));
 | 
			
		||||
		Log.d("restLocation", restLocation.getName());
 | 
			
		||||
		new ImageDownloader().execute(restLocation.getLocationImageUrl());
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	@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);
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user