Search in sources :

Example 21 with Location

use of android.location.Location in project ignition by mttkay.

the class AbstractIgnitedLocationManagerTest method sendMockLocationBroadcast.

protected Location sendMockLocationBroadcast(String provider, float accuracy, String action) {
    Intent intent = new Intent(action);
    Location location = getMockLocation(2.0, 2.0);
    intent.putExtra(LocationManager.KEY_LOCATION_CHANGED, location);
    shadowApp.sendBroadcast(intent);
    return location;
}
Also used : Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) Location(android.location.Location)

Example 22 with Location

use of android.location.Location in project android-app-common-tasks by multidots.

the class GetCurrentLocationAct method init.

private void init() {
    tvLatitude = (TextView) findViewById(R.id.tvLatitude);
    tvLongitude = (TextView) findViewById(R.id.tvLongitude);
    Button btnLocation = (Button) findViewById(R.id.btnLocation);
    btnLocation.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            //                if (Common.isNetworkAvailable(mContext)) {
            //                    if (Common.getGpsStatus(mContext)) {
            Location location = Common.getCurrentLocation(mContext);
            if (location != null) {
                tvLatitude.setText("" + location.getLatitude());
                tvLongitude.setText("" + location.getLongitude());
            } else {
                Common.showGPSDisabledAlert("Please enable your location or connect to cellular network.", GetCurrentLocationAct.this);
            }
        //                    } else {
        //                        Common.showGPSDisabledAlert("Please enable your location.", mContext);
        //                    }
        //                } else {
        //                    Toast.makeText(mContext, "Please Connect your device with internet.", Toast.LENGTH_LONG).show();
        //                    Common.showNETWORDDisabledAlert(mContext);
        //                }
        }
    });
}
Also used : Button(android.widget.Button) OnClickListener(android.view.View.OnClickListener) TextView(android.widget.TextView) View(android.view.View) Location(android.location.Location)

Example 23 with Location

use of android.location.Location in project Pokemap by omkarmoghe.

the class PokemonNotificationService method onEvent.

@Subscribe
public void onEvent(CatchablePokemonEvent event) {
    List<CatchablePokemon> catchablePokemon = event.getCatchablePokemon();
    LatLng location = locationManager.getLocation();
    Location myLoc = new Location("");
    myLoc.setLatitude(location.latitude);
    myLoc.setLongitude(location.longitude);
    builder.setContentText(getString(R.string.notification_service_pokemon_near, catchablePokemon.size()));
    builder.setStyle(null);
    if (!catchablePokemon.isEmpty()) {
        NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();
        inboxStyle.setBigContentTitle(getString(R.string.notification_service_pokemon_in_area, catchablePokemon.size()));
        Set<PokemonIdOuterClass.PokemonId> showablePokemonIDs = preffs.getShowablePokemonIDs();
        for (CatchablePokemon cp : catchablePokemon) {
            //Only show the notification if the Pokemon is in the preference list
            if (showablePokemonIDs.contains(cp.getPokemonId())) {
                Location pokeLocation = new Location("");
                pokeLocation.setLatitude(cp.getLatitude());
                pokeLocation.setLongitude(cp.getLongitude());
                long remainingTime = cp.getExpirationTimestampMs() - System.currentTimeMillis();
                String pokeName = PokemonIdUtils.getLocalePokemonName(getApplicationContext(), cp.getPokemonId().name());
                long remTime = TimeUnit.MILLISECONDS.toMinutes(remainingTime);
                int dist = (int) Math.ceil(pokeLocation.distanceTo(myLoc));
                inboxStyle.addLine(getString(R.string.notification_service_inbox_line, pokeName, remTime, dist));
            }
        }
        builder.setStyle(inboxStyle);
    }
    NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    nm.notify(notificationId, builder.build());
}
Also used : NotificationManager(android.app.NotificationManager) CatchablePokemon(com.pokegoapi.api.map.pokemon.CatchablePokemon) NotificationCompat(android.support.v4.app.NotificationCompat) LatLng(com.google.android.gms.maps.model.LatLng) Location(android.location.Location) Subscribe(org.greenrobot.eventbus.Subscribe)

Example 24 with Location

use of android.location.Location in project Pokemap by omkarmoghe.

the class MapWrapperFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    locationManager = LocationManager.getInstance(getContext());
    nianticManager = NianticManager.getInstance();
    locationManager.register(new LocationManager.Listener() {

        @Override
        public void onLocationChanged(Location location) {
            if (mLocation == null) {
                mLocation = location;
                initMap(true, true);
            } else {
                mLocation = location;
            }
        }

        @Override
        public void onLocationFetchFailed(@Nullable ConnectionResult connectionResult) {
            showLocationFetchFailed();
        }
    });
    // Inflate the layout for this fragment if the view is not null
    if (mView == null)
        mView = inflater.inflate(R.layout.fragment_map_wrapper, container, false);
    else {
    }
    // build the map
    if (mSupportMapFragment == null) {
        mSupportMapFragment = SupportMapFragment.newInstance();
        getChildFragmentManager().beginTransaction().replace(R.id.map, mSupportMapFragment).commit();
        mSupportMapFragment.setRetainInstance(true);
    }
    if (mGoogleMap == null) {
        mSupportMapFragment.getMapAsync(this);
    }
    FloatingActionButton locationFab = (FloatingActionButton) mView.findViewById(R.id.location_fab);
    locationFab.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            if (mLocation != null && mGoogleMap != null) {
                mGoogleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(mLocation.getLatitude(), mLocation.getLongitude()), 15));
            } else {
                showLocationFetchFailed();
            }
        }
    });
    mView.findViewById(R.id.closeSuggestions).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            hideMapSuggestion();
        }
    });
    if (!mPref.getShowMapSuggestion()) {
        hideMapSuggestion();
    }
    return mView;
}
Also used : LocationManager(com.omkarmoghe.pokemap.controllers.map.LocationManager) ConnectionResult(com.google.android.gms.common.ConnectionResult) FloatingActionButton(android.support.design.widget.FloatingActionButton) LatLng(com.google.android.gms.maps.model.LatLng) View(android.view.View) Location(android.location.Location)

Example 25 with Location

use of android.location.Location in project robolectric by robolectric.

the class ShadowLocationManager method copyOf.

private Location copyOf(Location location) {
    if (location == null)
        return null;
    Location copy = new Location(location);
    copy.setAccuracy(location.getAccuracy());
    copy.setAltitude(location.getAltitude());
    copy.setBearing(location.getBearing());
    copy.setExtras(location.getExtras());
    copy.setLatitude(location.getLatitude());
    copy.setLongitude(location.getLongitude());
    copy.setProvider(location.getProvider());
    copy.setSpeed(location.getSpeed());
    copy.setTime(location.getTime());
    return copy;
}
Also used : Location(android.location.Location)

Aggregations

Location (android.location.Location)284 Bundle (android.os.Bundle)48 LocationListener (android.location.LocationListener)36 LocationManager (android.location.LocationManager)31 ArrayList (java.util.ArrayList)29 Criteria (android.location.Criteria)19 LocationProviderInterface (com.android.server.location.LocationProviderInterface)18 GsmCellLocation (android.telephony.gsm.GsmCellLocation)17 BluetoothAdapter (android.bluetooth.BluetoothAdapter)12 BroadcastReceiver (android.content.BroadcastReceiver)12 Handler (android.os.Handler)10 MockProvider (com.android.server.location.MockProvider)9 Timer (java.util.Timer)8 Test (org.junit.Test)8 PendingIntent (android.app.PendingIntent)7 IOException (java.io.IOException)7 LocationProviderProxy (com.android.server.location.LocationProviderProxy)6 HashMap (java.util.HashMap)6 List (java.util.List)6 Map (java.util.Map)6