use of de.tum.in.tumcampusapp.component.other.locations.LocationManager in project TumCampusApp by TCA-Team.
the class FeedbackActivity method saveLocation.
private void saveLocation() {
Utils.log("saveLocation");
locationManager = new LocationManager(this);
locationListener = new LocationListener() {
@Override
public void onLocationChanged(Location gps) {
// just take the newest location
location = gps;
Utils.log("location (" + gps.getProvider() + "): " + location.getLatitude() + " " + location.getLongitude());
}
@Override
public void onStatusChanged(String s, int i, Bundle bundle) {
}
@Override
public void onProviderEnabled(String s) {
}
@Override
public void onProviderDisabled(String s) {
Utils.log("Provider " + s + " disabled");
}
};
locationManager.getLocationUpdates(locationListener);
// if the feedback is sent before we received a location
getBackupLocation();
}
use of de.tum.in.tumcampusapp.component.other.locations.LocationManager in project TumCampusApp by TCA-Team.
the class CafeteriaManager method onRequestCard.
/**
* Shows card for the best matching cafeteria.
*
* @param context Context
* @see LocationManager#getCafeteria()
*/
@Override
public void onRequestCard(Context context) {
// Choose which mensa should be shown
int cafeteriaId = new LocationManager(context).getCafeteria();
if (cafeteriaId == -1) {
return;
}
CafeteriaMenuCard card = new CafeteriaMenuCard(context);
compositeDisposable.add(createCafeteriaObservable(cafeteriaId).take(1).subscribe(cafeteria -> {
card.setCardMenus(cafeteria.id, cafeteria.name, cafeteria.dateStr, de.tum.in.tumcampusapp.utils.DateUtils.getDate(cafeteria.dateStr), cafeteria.menus);
card.apply();
}, throwable -> Utils.log(throwable.getMessage())));
}
use of de.tum.in.tumcampusapp.component.other.locations.LocationManager in project TumCampusApp by TCA-Team.
the class CafeteriaManager method getBestMatchMensaInfo.
/**
* returns the menus of the best matching cafeteria
*/
public Flowable<Map<String, List<CafeteriaMenu>>> getBestMatchMensaInfo(Context context) {
// Choose which mensa should be shown
int cafeteriaId = new LocationManager(context).getCafeteria();
if (cafeteriaId == -1) {
Utils.log("could not get a Cafeteria form locationManager!");
return Flowable.just(Collections.emptyMap());
}
return createCafeteriaObservableForNonUIThreads(cafeteriaId).map(cafeteria -> {
String mensaKey = cafeteria.name + ' ' + cafeteria.dateStr;
Map<String, List<CafeteriaMenu>> selectedMensaMenus = new HashMap<>(1);
selectedMensaMenus.put(mensaKey, cafeteria.menus);
return selectedMensaMenus;
});
}
use of de.tum.in.tumcampusapp.component.other.locations.LocationManager in project TumCampusApp by TCA-Team.
the class CafeteriaActivity method onStart.
/**
* Setup action bar navigation (to switch between cafeterias)
*/
@Override
protected void onStart() {
super.onStart();
// Adapter for drop-down navigation
ArrayAdapter<Cafeteria> adapterCafeterias = new ArrayAdapter<Cafeteria>(this, R.layout.simple_spinner_item_actionbar, android.R.id.text1, mCafeterias) {
final LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(LAYOUT_INFLATER_SERVICE);
@Override
public View getDropDownView(int position, View convertView, @NonNull ViewGroup parent) {
View v = inflater.inflate(R.layout.simple_spinner_dropdown_item_actionbar, parent, false);
Cafeteria c = getItem(position);
// Set name
TextView name = v.findViewById(android.R.id.text1);
// Set address
TextView address = v.findViewById(android.R.id.text2);
// Set distance
TextView dist = v.findViewById(R.id.distance);
if (c != null) {
name.setText(c.getName());
address.setText(c.getAddress());
dist.setText(Utils.formatDist(c.getDistance()));
}
return v;
}
};
Spinner spinner = findViewById(R.id.spinnerToolbar);
spinner.setAdapter(adapterCafeterias);
spinner.setOnItemSelectedListener(this);
Location currLocation = new LocationManager(this).getCurrentOrNextLocation();
Flowable<List<Cafeteria>> cafeterias = cafeteriaViewModel.getAllCafeterias(currLocation);
mDisposable.add(cafeterias.subscribe(it -> {
validateList(it);
mCafeterias.clear();
mCafeterias.addAll(it);
adapterCafeterias.notifyDataSetChanged();
setCurrentSelectedCafeteria(spinner);
}, throwable -> Utils.logwithTag("CafeteriaActivity", throwable.getMessage())));
}
use of de.tum.in.tumcampusapp.component.other.locations.LocationManager in project TumCampusApp by TCA-Team.
the class BarrierFreeFacilitiesActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// set spinner
Spinner spinner = findViewById(R.id.spinnerToolbar);
spinner.setOnItemSelectedListener(this);
// manager
recents = TcaDb.getInstance(this).recentsDao();
locationManager = new LocationManager(this);
stickyList = findViewById(R.id.activity_barrier_free_facilities_list_view);
}
Aggregations