Test code added.

master
tokugawa 2014-04-25 21:39:50 -04:00
parent 7ce4b9e0bf
commit 720cb7ee38
6 changed files with 62 additions and 29 deletions

View File

@ -23,19 +23,11 @@
android:text="@string/default_text"
android:textAppearance="?android:attr/textAppearanceMedium" />
<ImageView
android:id="@+id/foundImageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:src="@drawable/map" />
<Button
android:id="@+id/seeMoreButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="@string/see_more_text" />
<WebView
android:id="@+id/moreInfoWebView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1" />
<Button
android:id="@+id/tryMoreButton"

View File

@ -99,7 +99,7 @@ public class CompassActivity extends Activity implements SensorEventListener
}
});
Toast.makeText(this, ""+searchLocation.getLatitude()+", "+searchLocation.getLongitude(), Toast.LENGTH_SHORT).show();
//Toast.makeText(this, ""+searchLocation.getLatitude()+", "+searchLocation.getLongitude(), Toast.LENGTH_SHORT).show();
}
@Override

View File

@ -7,6 +7,7 @@ package edu.uncc.scavenger;
* FoundActivity.java
*/
import edu.uncc.scavenger.rest.RestLocation;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
@ -15,33 +16,31 @@ import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.WebView;
import android.widget.Button;
import android.widget.TextView;
public class FoundActivity extends Activity {
TextView numberFoundText;
Button seeMoreButton, tryMoreButton;
Button tryMoreButton;
WebView moreInfoWebView;
Intent intent;
RestLocation restLocation;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_found);
numberFoundText = (TextView)findViewById(R.id.numberFoundText);
seeMoreButton = (Button)findViewById(R.id.seeMoreButton);
moreInfoWebView = (WebView)findViewById(R.id.moreInfoWebView);
tryMoreButton = (Button)findViewById(R.id.tryMoreButton);
seeMoreButton.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
//TODO
//Get more information address and open web browser
}
});
restLocation = (RestLocation)(getIntent().getSerializableExtra("restLocation"));
//moreInfoWebView.loadUrl(restLocation.getKey());
tryMoreButton.setOnClickListener(new OnClickListener(){
@Override

View File

@ -31,6 +31,7 @@ public class MainActivity extends Activity {
ListView locationList;
List<RestLocation> locations;
static String key;
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -98,7 +99,15 @@ public class MainActivity extends Activity {
}
}.execute();
//Toast.makeText(getApplicationContext(), ""+locations.get(0).getRiddleImageUrl(), Toast.LENGTH_SHORT).show();
new LocationClient.VerifyAsync(this) {
@Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
key = result;
Toast.makeText(getApplicationContext(), key, Toast.LENGTH_SHORT).show();
}
}.execute("1", "Belk Tower");
}
@Override

View File

@ -8,7 +8,9 @@ package edu.uncc.scavenger;
*/
import java.net.URL;
import java.util.List;
import edu.uncc.scavenger.database.LocationDatabaseHelper;
import edu.uncc.scavenger.rest.RestLocation;
import android.app.Activity;
import android.app.AlertDialog;
@ -52,7 +54,7 @@ public class SearchActivity extends Activity {
riddleView = (TextView)findViewById(R.id.riddleView);
restLocation = (RestLocation)(getIntent().getSerializableExtra("restLocation"));
Log.d("restLocation", restLocation.getName());
//Log.d("restLocation", restLocation.getName());
locationText.setText(restLocation.getName());
riddleView.setText(restLocation.getRiddle());
@ -130,7 +132,7 @@ public class SearchActivity extends Activity {
}
});
Toast.makeText(getApplicationContext(), restLocation.getRiddleImageUrl(), Toast.LENGTH_SHORT).show();
//Toast.makeText(getApplicationContext(), restLocation.getRiddleImageUrl(), Toast.LENGTH_SHORT).show();
Bitmap locationPicture = BitmapAccess.loadBitmap(this, restLocation.getName());
if(locationPicture != null)
{
@ -171,7 +173,14 @@ public class SearchActivity extends Activity {
String contents = data.getStringExtra("SCAN_RESULT");
if(contents.equals(restLocation.getName()))
{
//Add found to the database
/*List locations = LocationDatabaseHelper.getInstance(this).fetchAll();
if (locations != null && locations.size() > 0)
{
locations.get(restLocation.getId()-1);
}*/
intent = new Intent(SearchActivity.this, FoundActivity.class);
intent.putExtra("restLocation", restLocation);
startActivity(intent);
finish();
}

View File

@ -16,9 +16,11 @@ import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import retrofit.RestAdapter;
import retrofit.RetrofitError;
import retrofit.converter.GsonConverter;
import android.content.Context;
import android.os.AsyncTask;
import android.util.Log;
import edu.uncc.scavenger.R;
public class LocationClient {
@ -38,7 +40,14 @@ public class LocationClient {
Map<String, String> keys = new HashMap<String, String>();
keys.put("key", key);
keys.put("id", String.valueOf(id));
return client.getResult(keys);
try
{
return client.getResult(keys);
}
catch(RetrofitError e)
{
return "Verification failed";
}
}
public static class LocationsDownloader extends
@ -54,4 +63,19 @@ public class LocationClient {
return getAdapter(ctx).listLocations();
}
}
public static class VerifyAsync extends AsyncTask<String, Void, String>
{
private Context ctx;
public VerifyAsync(Context ctx)
{
this.ctx = ctx;
}
@Override
protected String doInBackground(String... params) {
return LocationClient.validateLocation(ctx, Integer.parseInt(params[0]), params[1]);
}
}
}