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

Added dialogs to check if GPS is enabled and zxing is installed.

Added string resources.
This commit is contained in:
tokugawa 2014-04-19 17:31:33 -04:00
parent 496fd2c9fc
commit d8b067b9fa
2 changed files with 69 additions and 17 deletions

View File

@ -15,5 +15,10 @@
<string name="found_text">Location Found!</string> <string name="found_text">Location Found!</string>
<string name="see_more_text">More Location Information</string> <string name="see_more_text">More Location Information</string>
<string name="try_more_button">Try Another Location</string> <string name="try_more_button">Try Another Location</string>
<string name="gps_disabled_message">GPS must be enabled to use the compass.Would you like to enable it now?</string>
<string name="zxing_missing_message">zxing Barcode Scanner must be installed to scan QR codes. Would you like to install it now?</string>
<string name="zxing_market_uri">market://details?id=com.google.zxing.client.android</string>
<string name="dialog_ok_text">OK</string>
<string name="dialog_cancel_text">Cancel</string>
</resources> </resources>

View File

@ -9,14 +9,16 @@ package edu.uncc.scavenger;
import java.net.URL; 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.app.AlertDialog;
import android.content.ActivityNotFoundException; import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.BitmapFactory; import android.graphics.BitmapFactory;
import android.location.LocationManager;
import android.net.Uri; import android.net.Uri;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Bundle; import android.os.Bundle;
@ -55,10 +57,6 @@ public class SearchActivity extends Activity {
locationText.setText(restLocation.getName()); locationText.setText(restLocation.getName());
riddleView.setText(restLocation.getRiddle()); riddleView.setText(restLocation.getRiddle());
//TODO
//Load picture
//Load hints
scanButton.setOnClickListener(new OnClickListener(){ scanButton.setOnClickListener(new OnClickListener(){
@Override @Override
@ -70,10 +68,28 @@ public class SearchActivity extends Activity {
startActivityForResult(intent, 0); startActivityForResult(intent, 0);
} }
catch(ActivityNotFoundException e){ catch(ActivityNotFoundException e){
//Does not work on an emulator because there is no access to the market
Uri marketUri = Uri.parse("market://details?id=com.google.zxing.client.android"); AlertDialog.Builder builder = new AlertDialog.Builder(SearchActivity.this);
Intent marketIntent = new Intent(Intent.ACTION_VIEW, marketUri); builder.setMessage(getString(R.string.zxing_missing_message));
startActivity(marketIntent); builder.setPositiveButton(getString(R.string.dialog_ok_text), new DialogInterface.OnClickListener(){
@Override
public void onClick(DialogInterface dialog, int which) {
//Does not work on an emulator because there is no access to the market
Uri marketUri = Uri.parse(getString(R.string.zxing_market_uri));
Intent marketIntent = new Intent(Intent.ACTION_VIEW, marketUri);
startActivity(marketIntent);
}
});
builder.setNegativeButton(getString(R.string.dialog_cancel_text), new DialogInterface.OnClickListener(){
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
AlertDialog alert = builder.create();
alert.show();
} }
} }
}); });
@ -81,14 +97,42 @@ public class SearchActivity extends Activity {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
intent = new Intent(getApplicationContext(), CompassActivity.class); LocationManager lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
intent.putExtra("searchLat", restLocation.getLocationLat());
intent.putExtra("searchLong", restLocation.getLocationLong()); if(lm.isProviderEnabled(LocationManager.GPS_PROVIDER))
startActivity(intent); {
intent = new Intent(getApplicationContext(), CompassActivity.class);
intent.putExtra("searchLat", restLocation.getLocationLat());
intent.putExtra("searchLong", restLocation.getLocationLong());
startActivity(intent);
}
else
{
AlertDialog.Builder builder = new AlertDialog.Builder(SearchActivity.this);
builder.setMessage(getString(R.string.gps_disabled_message));
builder.setPositiveButton(getString(R.string.dialog_ok_text), new DialogInterface.OnClickListener(){
@Override
public void onClick(DialogInterface dialog, int which) {
Intent intent = new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS);
startActivity(intent);
}
});
builder.setNegativeButton(getString(R.string.dialog_cancel_text), new DialogInterface.OnClickListener(){
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
AlertDialog alert = builder.create();
alert.show();
}
} }
}); });
new ImageDownloader().execute(restLocation.getLocationImageUrl()); //Toast.makeText(getApplicationContext(), restLocation.getLocationImageURL(), Toast.LENGTH_SHORT).show();
new ImageDownloader().execute(restLocation.getLocationImageURL());
} }
@Override @Override
@ -126,7 +170,7 @@ public class SearchActivity extends Activity {
} }
else else
{ {
Toast.makeText(getApplicationContext(), "Incorrect url found: "+contents, Toast.LENGTH_SHORT).show(); Toast.makeText(getApplicationContext(), "Incorrect place found: "+contents, Toast.LENGTH_SHORT).show();
} }
} }
else if (resultCode == RESULT_CANCELED) else if (resultCode == RESULT_CANCELED)
@ -155,7 +199,10 @@ public class SearchActivity extends Activity {
@Override @Override
protected void onPostExecute(Bitmap result) { protected void onPostExecute(Bitmap result) {
locationImage.setImageBitmap(result); if(result!=null)
{
locationImage.setImageBitmap(result);
}
} }
} }
} }