+ *
+ * } + * //show the FAB since it remains hidden + * floatingActionButton.show(); + *
+ * }
**/
@@ -337,7 +336,7 @@
super.onPause();
fh.stopLastRequestIfNeeded();
fh.setBlockAllActivities(true);
- if(updatelistener!=null && prefsManager!=null) prefsManager.unregisterListener();
+ if (updatelistener != null && prefsManager != null) prefsManager.unregisterListener();
locmgr.removeUpdates(locListener);
}
@@ -345,13 +344,13 @@
protected void onResume() {
super.onResume();
fh.setBlockAllActivities(false);
- if(updatelistener!=null && prefsManager!=null) {
+ if (updatelistener != null && prefsManager != null) {
prefsManager.registerListener();
- if(prefsManager.isDBUpdating(true)){
+ if (prefsManager.isDBUpdating(true)) {
createDefaultSnackbar();
}
}
- if(pendingNearbyStopsRequest)
+ if (pendingNearbyStopsRequest)
handler.post(new NearbyStopsRequester());
}
@@ -402,8 +401,8 @@
openIceweasel("https://www.gnu.org/licenses/gpl-3.0.html");
return true;
case R.id.action_settings:
- Log.d("MAINBusTO","Pressed button preferences");
- startActivity(new Intent(ActivityMain.this,ActivitySettings.class));
+ Log.d("MAINBusTO", "Pressed button preferences");
+ startActivity(new Intent(ActivityMain.this, ActivitySettings.class));
}
return super.onOptionsItemSelected(item);
}
@@ -419,37 +418,40 @@
//OLD ASYNCTASK
//new asyncWgetBusStopFromBusStopID(busStopID, ArrivalFetchersRecursionHelper, lastSuccessfullySearchedBusStop);
- if(busStopID == null || busStopID.length() <= 0) {
+ if (busStopID == null || busStopID.length() <= 0) {
showMessage(R.string.insert_bus_stop_number_error);
toggleSpinner(false);
- } else{
- new AsyncDataDownload(AsyncDataDownload.RequestType.ARRIVALS,fh).execute(busStopID);
- Log.d("MainActiv","Started search for arrivals of stop "+busStopID);
+ } else {
+ new AsyncDataDownload(AsyncDataDownload.RequestType.ARRIVALS, fh).execute(busStopID);
+ Log.d("MainActiv", "Started search for arrivals of stop " + busStopID);
}
} else { // searchMode == SEARCH_BY_NAME
String query = busStopSearchByNameEditText.getText().toString();
//new asyncWgetBusStopSuggestions(query, stopsDB, StopsFindersByNameRecursionHelper);
- new AsyncDataDownload(AsyncDataDownload.RequestType.STOPS,fh).execute(query);
+ new AsyncDataDownload(AsyncDataDownload.RequestType.STOPS, fh).execute(query);
}
}
- /** PERMISSION STUFF **/
+
+ /**
+ * PERMISSION STUFF
+ **/
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
- switch (requestCode){
+ switch (requestCode) {
case PERMISSION_REQUEST_POSITION:
- if(grantResults.length>0 && grantResults[0]==PackageManager.PERMISSION_GRANTED){
- setOption(LOCATION_PERMISSION_GIVEN,true);
+ if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
+ setOption(LOCATION_PERMISSION_GIVEN, true);
//if we sent a request for a new NearbyStopsFragment
- if(pendingNearbyStopsRequest){
- pendingNearbyStopsRequest=false;
+ if (pendingNearbyStopsRequest) {
+ pendingNearbyStopsRequest = false;
handler.post(new NearbyStopsRequester());
}
} else {
//permission denied
- setOption(LOCATION_PERMISSION_GIVEN,false);
+ setOption(LOCATION_PERMISSION_GIVEN, false);
}
- //add other cases for permissions
+ //add other cases for permissions
}
}
@@ -458,18 +460,17 @@
@Override
public void createFragmentForStop(String ID) {
//new asyncWgetBusStopFromBusStopID(ID, ArrivalFetchersRecursionHelper,lastSuccessfullySearchedBusStop);
- if(ID == null || ID.length() <= 0) {
+ if (ID == null || ID.length() <= 0) {
// we're still in UI thread, no need to mess with Progress
showMessage(R.string.insert_bus_stop_number_error);
toggleSpinner(false);
} else {
- new AsyncDataDownload(AsyncDataDownload.RequestType.ARRIVALS,fh).execute(ID);
- Log.d("MainActiv","Started search for arrivals of stop "+ID);
+ new AsyncDataDownload(AsyncDataDownload.RequestType.ARRIVALS, fh).execute(ID);
+ Log.d("MainActiv", "Started search for arrivals of stop " + ID);
}
}
-
/**
* QR scan button clicked
*
@@ -482,7 +483,6 @@
/**
* Receive the Barcode Scanner Intent
- *
*/
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
IntentResult scanResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, intent);
@@ -519,33 +519,35 @@
}
}
}
- private void createDefaultSnackbar(){
- if(snackbar==null){
- snackbar = Snackbar.make(findViewById(R.id.searchButton),R.string.database_update_message,Snackbar.LENGTH_INDEFINITE);
+
+ private void createDefaultSnackbar() {
+ if (snackbar == null) {
+ snackbar = Snackbar.make(findViewById(R.id.searchButton), R.string.database_update_message, Snackbar.LENGTH_INDEFINITE);
}
snackbar.show();
}
///////////////////////////////// POSITION STUFF//////////////////////////////////////////////
- private void resolveStopRequest(String provider){
- Log.d(DEBUG_TAG,"Provider "+provider+" got enabled");
- if(locmgr!=null && pendingNearbyStopsRequest && locmgr.getProvider(provider).meetsCriteria(cr)){
+ private void resolveStopRequest(String provider) {
+ Log.d(DEBUG_TAG, "Provider " + provider + " got enabled");
+ if (locmgr != null && pendingNearbyStopsRequest && locmgr.getProvider(provider).meetsCriteria(cr)) {
pendingNearbyStopsRequest = false;
handler.post(new NearbyStopsRequester());
}
}
+
final LocationListener locListener = new LocationListener() {
@Override
public void onLocationChanged(Location location) {
- Log.d(DEBUG_TAG,"Location changed");
+ Log.d(DEBUG_TAG, "Location changed");
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
- Log.d(DEBUG_TAG,"Location provider status: "+status);
- if(status== LocationProvider.AVAILABLE){
- resolveStopRequest(provider);
- }
+ Log.d(DEBUG_TAG, "Location provider status: " + status);
+ if (status == LocationProvider.AVAILABLE) {
+ resolveStopRequest(provider);
+ }
}
@Override
@@ -559,57 +561,56 @@
}
};
- class NearbyStopsRequester implements Runnable{
+ class NearbyStopsRequester implements Runnable {
@SuppressLint("MissingPermission")
@Override
public void run() {
final boolean canRunPosition = Build.VERSION.SDK_INT < Build.VERSION_CODES.M || getOption(LOCATION_PERMISSION_GIVEN, false);
- if(!canRunPosition){
+ if (!canRunPosition) {
pendingNearbyStopsRequest = true;
assertLocationPermissions();
return;
- } else setOption(LOCATION_PERMISSION_GIVEN,true);
+ } else setOption(LOCATION_PERMISSION_GIVEN, true);
LocationManager locManager = (LocationManager) getSystemService(LOCATION_SERVICE);
- if(locManager == null) {
+ if (locManager == null) {
Log.e(DEBUG_TAG, "location manager is nihil, cannot create NearbyStopsFragment");
return;
}
- if(anyLocationProviderMatchesCriteria(locManager,cr,true) && fh.getLastSuccessfullySearchedBusStop()==null) {
+ if (anyLocationProviderMatchesCriteria(locManager, cr, true) && fh.getLastSuccessfullySearchedBusStop() == null) {
//Go ahead with the request
- Log.d("mainActivity","Recreating stop fragment");
+ Log.d("mainActivity", "Recreating stop fragment");
swipeRefreshLayout.setVisibility(View.VISIBLE);
NearbyStopsFragment fragment = NearbyStopsFragment.newInstance(NearbyStopsFragment.TYPE_STOPS);
Fragment oldFrag = framan.findFragmentById(R.id.resultFrame);
FragmentTransaction ft = framan.beginTransaction();
- if(oldFrag!=null)
+ if (oldFrag != null)
ft.remove(oldFrag);
- ft.add(R.id.resultFrame,fragment,"nearbyStop_correct");
+ ft.add(R.id.resultFrame, fragment, "nearbyStop_correct");
ft.commit();
framan.executePendingTransactions();
pendingNearbyStopsRequest = false;
- } else if(!anyLocationProviderMatchesCriteria(locManager,cr,true)){
+ } else if (!anyLocationProviderMatchesCriteria(locManager, cr, true)) {
//Wait for the providers
- Log.d(DEBUG_TAG,"Queuing position request");
+ Log.d(DEBUG_TAG, "Queuing position request");
pendingNearbyStopsRequest = true;
- locManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,10,0.1f,locListener);
+ locManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 10, 0.1f, locListener);
}
}
}
- private boolean anyLocationProviderMatchesCriteria(LocationManager mng, Criteria cr, boolean enabled){
- List