Skip to content

Commit

Permalink
removed zipcode request, and replaced with blocking location services
Browse files Browse the repository at this point in the history
enable dialog.
  • Loading branch information
thequbit committed Mar 5, 2015
1 parent 2e49b49 commit dfb5eb3
Show file tree
Hide file tree
Showing 12 changed files with 130 additions and 19 deletions.
3 changes: 3 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ android {
}
debug {
buildConfigField "String", "BASE_URL", "\"http://yellr.mycodespace.net\""
debuggable true
}
}

Expand All @@ -59,4 +60,6 @@ dependencies {
compile files('libs/httpclient-cache-4.3.6.jar')
compile files('libs/httpcore-4.3.3.jar')
compile files('libs/httpmime-4.3.6.jar')
//compile 'com.google.android.gms:play-services:6.5.87'
//compile 'com.google.android.gms:play-services-maps:6.5.87'
}
3 changes: 3 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

<!--<meta-data android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />-->

<!-- Hardware Features -->
<uses-feature
android:name="android.hardware.camera"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
package yellr.net.yellr_android.activities;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.provider.Settings;
import android.view.KeyEvent;

import yellr.net.yellr_android.R;
import yellr.net.yellr_android.utils.YellrUtils;
Expand All @@ -20,8 +25,9 @@ protected void onCreate(Bundle savedInstanceState) {
protected void onResume() {
super.onResume();

//YellrUtils.resetHomeLocation(getApplicationContext());
YellrUtils.resetHomeLocation(getApplicationContext());

/*
if (YellrUtils.isHomeLocationSet(getApplicationContext())) {
new Handler().postDelayed(new Runnable() {
@Override
Expand All @@ -45,5 +51,65 @@ public void run() {
}
}, 500);
}
*/

//while(YellrUtils.getLocation(getApplicationContext()) == null) {

//}
if (YellrUtils.getLocation(getApplicationContext()) == null) {
try {
showSettingsAlert();
} catch(Exception ex) {

}

} else {
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
Intent intent;
intent = new Intent(getApplicationContext(), HomeActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
finish();
}
}, 500);
}

}

public void showSettingsAlert() {
AlertDialog.Builder alertDialog = new AlertDialog.Builder(this);

// Setting Dialog Title
alertDialog.setTitle("Yikes!");

// Setting Dialog Message
alertDialog.setMessage("Looks like Location Services isn't turned on.\n\nYellr requires a location to work correctly. Please enable location services to continue.");

// On pressing Settings button
alertDialog.setPositiveButton(
"Location Settings",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
Intent intent = new Intent(
Settings.ACTION_LOCATION_SOURCE_SETTINGS);
startActivity(intent);
finish();
}
});

alertDialog.setOnKeyListener(new Dialog.OnKeyListener() {

@Override
public boolean onKey(DialogInterface arg0, int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
finish();
}
return false;
}
});

alertDialog.show();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,12 @@ private void handleActionGetAssignments() {

String baseUrl = BuildConfig.BASE_URL + "/get_assignments.json";

// get the location, but if the user has turned off location services,
// it will come back null. If it's null, just dump out.
// TODO: pop-up a dialog maybe??
double latLng[] = YellrUtils.getLocation(getApplicationContext());
if (latLng == null )
return;
String lat = String.valueOf(latLng[0]);
String lng = String.valueOf(latLng[1]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,12 @@ private void handleActionGetData() {

String baseUrl = BuildConfig.BASE_URL + "/get_data.json";

// get the location, but if the user has turned off location services,
// it will come back null. If it's null, just dump out.
// TODO: pop-up a dialog maybe??
double latLng[] = YellrUtils.getLocation(getApplicationContext());
if (latLng == null )
return;
String lat = String.valueOf(latLng[0]);
String lng = String.valueOf(latLng[1]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,12 @@ private void handleActionGetMessages() {

String baseUrl = BuildConfig.BASE_URL + "/get_messages.json";

// get the location, but if the user has turned off location services,
// it will come back null. If it's null, just dump out.
// TODO: pop-up a dialog maybe??
double latLng[] = YellrUtils.getLocation(getApplicationContext());
if (latLng == null )
return;
String lat = String.valueOf(latLng[0]);
String lng = String.valueOf(latLng[1]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,12 @@ private void handleActionGetNotifications() {

String baseUrl = BuildConfig.BASE_URL + "/get_notifications.json";

// get the location, but if the user has turned off location services,
// it will come back null. If it's null, just dump out.
// TODO: pop-up a dialog maybe??
double latLng[] = YellrUtils.getLocation(getApplicationContext());
if (latLng == null )
return;
String lat = String.valueOf(latLng[0]);
String lng = String.valueOf(latLng[1]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@ private void handleActionGetPublishPost(int assignmentId,
Log.d("PublishPostIntentService.handleActionGetPublishedPost", "GSON puked");
}


//String mediaObjectIdsJson = gson.toJson(mediaObjectIds);
String publishPostJson = publishPost(
assignmentId,
Expand All @@ -173,7 +172,12 @@ private String publishPost(int assignmentId,

String baseUrl = BuildConfig.BASE_URL + "/publish_post.json";

// get the location, but if the user has turned off location services,
// it will come back null. If it's null, just dump out.
// TODO: pop-up a dialog maybe??
double latLng[] = YellrUtils.getLocation(getApplicationContext());
if (latLng == null )
return null;
String lat = String.valueOf(latLng[0]);
String lng = String.valueOf(latLng[1]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,12 @@ private void handleActionGetStories() {

String baseUrl = BuildConfig.BASE_URL + "/get_stories.json";

// get the location, but if the user has turned off location services,
// it will come back null. If it's null, just dump out.
// TODO: pop-up a dialog maybe??
double latLng[] = YellrUtils.getLocation(getApplicationContext());
if (latLng == null )
return;
String lat = String.valueOf(latLng[0]);
String lng = String.valueOf(latLng[1]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,9 @@ private void handleActionVerifyUser(String username,
Log.d("VerifyUserIntentService.publishPost()", "JSON: " + verifyUserJson);

Gson gson = new Gson();
VerifyUserResponse verifyUserresponse = gson.fromJson(verifyUserJson, VerifyUserResponse.class);
VerifyUserResponse verifyUserResponse = gson.fromJson(verifyUserJson, VerifyUserResponse.class);

if ( !verifyUserresponse.success ) {
if ( !verifyUserResponse.success ) {
// TODO: report failure back to calling fragment
}

Expand Down
40 changes: 25 additions & 15 deletions app/src/main/java/yellr/net/yellr_android/utils/YellrUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,26 +99,38 @@ public static double[] getLocation(Context context) {
//providers.add(LocationManager.NETWORK_PROVIDER);
Location location = null;
Log.d("YellrUtils.getLocation()", "providers: " + providers.toString());
for (int i = 0; i < providers.size(); i++) {
Location l = lm.getLastKnownLocation(providers.get(i));
if (null != l) {
location = l;
try {
for (int i = 0; i < providers.size(); i++) {
Location l = lm.getLastKnownLocation(providers.get(i));
if (null != l) {
location = l;
break;
}
}
}catch (Exception ex) {
Log.d("YellrUtils.getLocation()","Error: " + ex.toString());
}

// default to center of Rochester, NY
double latitude = 0; //43.1656;
double longitude = 0; //-77.6114;
// default to invalid lat/lng values
double latitude = 1000; //43.1656;
double longitude = 1000; //-77.6114;
double[] latLng = null;
// if we have a location available, then set it
if (null != location) {

latitude = location.getLatitude();
longitude = location.getLongitude();
} else {
Log.d("YellrUtils.getLocation()", "No location available, defaulting to Home Location");
Float[] latLng = YellrUtils.getHomeLocation(context);
latitude = latLng[0];
longitude = latLng[1];

latLng = new double[2];
latLng[0] = latitude;
latLng[1] = longitude;
}
//} else {
// Log.d("YellrUtils.getLocation()", "No location available, defaulting to Home Location");
// Float[] latLng = YellrUtils.getHomeLocation(context);
// latitude = latLng[0];
// longitude = latLng[1];
//}

/*
LocationDetector myloc = new LocationDetector(
Expand All @@ -137,9 +149,7 @@ public static double[] getLocation(Context context) {
*/


double[] latLng = new double[2];
latLng[0] = latitude;
latLng[1] = longitude;


return latLng;
}
Expand Down

0 comments on commit dfb5eb3

Please sign in to comment.