Search in sources :

Example 1 with LocationManager

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();
}
Also used : LocationManager(de.tum.in.tumcampusapp.component.other.locations.LocationManager) Bundle(android.os.Bundle) LocationListener(android.location.LocationListener) SuppressLint(android.annotation.SuppressLint) Location(android.location.Location)

Example 2 with LocationManager

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())));
}
Also used : LocationManager(de.tum.in.tumcampusapp.component.other.locations.LocationManager) Context(android.content.Context) CafeteriaMenu(de.tum.in.tumcampusapp.component.ui.cafeteria.model.CafeteriaMenu) DateUtils(android.text.format.DateUtils) Date(java.util.Date) Card(de.tum.in.tumcampusapp.component.ui.overview.card.Card) HashMap(java.util.HashMap) TUMCabeClient(de.tum.in.tumcampusapp.api.app.TUMCabeClient) CafeteriaLocalRepository(de.tum.in.tumcampusapp.component.ui.cafeteria.repository.CafeteriaLocalRepository) CafeteriaMenuCard(de.tum.in.tumcampusapp.component.ui.cafeteria.CafeteriaMenuCard) CafeteriaViewModel(de.tum.in.tumcampusapp.component.ui.cafeteria.details.CafeteriaViewModel) List(java.util.List) CompositeDisposable(io.reactivex.disposables.CompositeDisposable) Calendar(java.util.Calendar) Flowable(io.reactivex.Flowable) Map(java.util.Map) Utils(de.tum.in.tumcampusapp.utils.Utils) TcaDb(de.tum.in.tumcampusapp.database.TcaDb) CafeteriaRemoteRepository(de.tum.in.tumcampusapp.component.ui.cafeteria.repository.CafeteriaRemoteRepository) Collections(java.util.Collections) LocationManager(de.tum.in.tumcampusapp.component.other.locations.LocationManager) CafeteriaMenuCard(de.tum.in.tumcampusapp.component.ui.cafeteria.CafeteriaMenuCard)

Example 3 with LocationManager

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;
    });
}
Also used : LocationManager(de.tum.in.tumcampusapp.component.other.locations.LocationManager) HashMap(java.util.HashMap) List(java.util.List)

Example 4 with LocationManager

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())));
}
Also used : LocationManager(de.tum.in.tumcampusapp.component.other.locations.LocationManager) CafeteriaDetailsSectionFragment.menuToSpan(de.tum.in.tumcampusapp.component.ui.cafeteria.details.CafeteriaDetailsSectionFragment.menuToSpan) ActivityForDownloadingExternal(de.tum.in.tumcampusapp.component.other.generic.activity.ActivityForDownloadingExternal) Bundle(android.os.Bundle) ViewPager(android.support.v4.view.ViewPager) Intent(android.content.Intent) TUMCabeClient(de.tum.in.tumcampusapp.api.app.TUMCabeClient) NonNull(android.support.annotation.NonNull) CafeteriaDetailsSectionsPagerAdapter(de.tum.in.tumcampusapp.component.ui.cafeteria.details.CafeteriaDetailsSectionsPagerAdapter) CafeteriaViewModel(de.tum.in.tumcampusapp.component.ui.cafeteria.details.CafeteriaViewModel) MenuItem(android.view.MenuItem) ArrayList(java.util.ArrayList) Flowable(io.reactivex.Flowable) Menu(android.view.Menu) View(android.view.View) AdapterView(android.widget.AdapterView) TcaDb(de.tum.in.tumcampusapp.database.TcaDb) CafeteriaRemoteRepository(de.tum.in.tumcampusapp.component.ui.cafeteria.repository.CafeteriaRemoteRepository) LocationManager(de.tum.in.tumcampusapp.component.other.locations.LocationManager) R(de.tum.in.tumcampusapp.R) LayoutInflater(android.view.LayoutInflater) Collection(java.util.Collection) Const(de.tum.in.tumcampusapp.utils.Const) CafeteriaLocalRepository(de.tum.in.tumcampusapp.component.ui.cafeteria.repository.CafeteriaLocalRepository) NetUtils(de.tum.in.tumcampusapp.utils.NetUtils) ViewGroup(android.view.ViewGroup) Spinner(android.widget.Spinner) AlertDialog(android.app.AlertDialog) ArrayAdapter(android.widget.ArrayAdapter) List(java.util.List) CompositeDisposable(io.reactivex.disposables.CompositeDisposable) TextView(android.widget.TextView) Utils(de.tum.in.tumcampusapp.utils.Utils) Location(android.location.Location) Cafeteria(de.tum.in.tumcampusapp.component.ui.cafeteria.model.Cafeteria) ViewGroup(android.view.ViewGroup) Spinner(android.widget.Spinner) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) LayoutInflater(android.view.LayoutInflater) NonNull(android.support.annotation.NonNull) TextView(android.widget.TextView) ArrayList(java.util.ArrayList) List(java.util.List) Cafeteria(de.tum.in.tumcampusapp.component.ui.cafeteria.model.Cafeteria) ArrayAdapter(android.widget.ArrayAdapter) Location(android.location.Location)

Example 5 with LocationManager

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);
}
Also used : LocationManager(de.tum.in.tumcampusapp.component.other.locations.LocationManager) Spinner(android.widget.Spinner)

Aggregations

LocationManager (de.tum.in.tumcampusapp.component.other.locations.LocationManager)7 Location (android.location.Location)3 List (java.util.List)3 AlertDialog (android.app.AlertDialog)2 Bundle (android.os.Bundle)2 Spinner (android.widget.Spinner)2 TUMCabeClient (de.tum.in.tumcampusapp.api.app.TUMCabeClient)2 CafeteriaViewModel (de.tum.in.tumcampusapp.component.ui.cafeteria.details.CafeteriaViewModel)2 CafeteriaLocalRepository (de.tum.in.tumcampusapp.component.ui.cafeteria.repository.CafeteriaLocalRepository)2 CafeteriaRemoteRepository (de.tum.in.tumcampusapp.component.ui.cafeteria.repository.CafeteriaRemoteRepository)2 TcaDb (de.tum.in.tumcampusapp.database.TcaDb)2 Utils (de.tum.in.tumcampusapp.utils.Utils)2 Flowable (io.reactivex.Flowable)2 CompositeDisposable (io.reactivex.disposables.CompositeDisposable)2 HashMap (java.util.HashMap)2 SuppressLint (android.annotation.SuppressLint)1 Context (android.content.Context)1 Intent (android.content.Intent)1 LocationListener (android.location.LocationListener)1 NonNull (android.support.annotation.NonNull)1