Exemplo n.º 1
0
 protected void initializeLocationRequest() {
   mLocationRequest =
       LocationRequest.create()
           .setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY)
           .setInterval(60 * 1000) // 1 minute, in milliseconds
           .setFastestInterval(10 * 1000); // 10 seconds, in milliseconds
 }
Exemplo n.º 2
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    // listOfSongs = getListOfSongs();
    // for (Song song : listOfSongs) {
    // Toast.makeText(getApplicationContext(), song.toString(),
    // Toast.LENGTH_LONG).show();
    // }

    // Get a handle to the activity update list
    mStatusListView = (ListView) findViewById(R.id.log_listview);
    mStatusAdapter = new ArrayAdapter<Spanned>(this, R.layout.item_layout, R.id.log_text);
    mStatusListView.setAdapter(mStatusAdapter);
    mBroadcastManager = LocalBroadcastManager.getInstance(this);
    mBroadcastFilter = new IntentFilter(ActivityUtils.ACTION_REFRESH_STATUS_LIST);
    mBroadcastFilter.addCategory(ActivityUtils.CATEGORY_LOCATION_SERVICES);

    mDetectionRequester = new DetectionRequester(this);
    mDetectionRemover = new DetectionRemover(this);

    mLogFile = LogFile.getInstance(this);

    // for location
    locationClient = new LocationClient(this, this, this);
    // creating request object with some of parameters set
    locationRequest =
        LocationRequest.create()
            .setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY)
            .setInterval(UPDATE_INTERVAL);
  }
  @AutoFactory
  public LocationProvider(
      @Provided GoogleApiAvailability googleApiAvailability,
      @Provided GoogleApiClient googleApiClient,
      @Provided FusedLocationProviderApi fusedLocationProviderApi,
      @Provided LocationManager locationManager,
      @Provided SensorManager sensorManager,
      @Provided Display displayManager,
      Context context,
      LocationCallback locationCallback) {
    this.mGoogleApiAvailability = googleApiAvailability;
    this.mGoogleApiClient = googleApiClient;
    this.mFusedLocationProviderApi = fusedLocationProviderApi;
    this.mLocationManager = locationManager;
    this.mContext = context;
    this.mLocationCallback = locationCallback;
    this.mSensorManager = sensorManager;
    this.mDisplay = displayManager;
    mLocationRequest =
        LocationRequest.create()
            .setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY)
            .setInterval(INTERVAL_IN_MS)
            .setFastestInterval(FASTEST_INTERVAL_IN_MS);
    mNetworkLocationListener = createLocationListener();
    mGpsLocationListener = createLocationListener();

    determineIfUsingGms();
    if (isUsingGms()) {
      mGoogleApiClient.registerConnectionCallbacks(this);
      mGoogleApiClient.registerConnectionFailedListener(this);
    }
  }
Exemplo n.º 4
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_maps);

    ClientAdd = getIntent().getStringExtra("add");
    Clientinfo = getIntent().getStringExtra("inf");

    mLocationRequest = LocationRequest.create();
    mGoogleApiClient =
        new GoogleApiClient.Builder(this)
            .addApi(LocationServices.API)
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this)
            .build();

    clint_latlong =
        new LatLng(
            Double.parseDouble(getIntent().getStringExtra("lat")),
            Double.parseDouble(getIntent().getStringExtra("lon")));

    tv = (TextView) findViewById(R.id.textViewMap);
    tv.setVisibility(View.VISIBLE);
    tv.setText("Wait...");

    // Obtain the SupportMapFragment and get notified when the map is ready to be used.
    SupportMapFragment mapFragment =
        (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
    mapFragment.getMapAsync(this);
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    // UI widgets
    _textViewLatLng = (TextView) findViewById(R.id.lat_lng);
    _textViewAddress = (TextView) findViewById(R.id.address);
    _textViewConnectionState = (TextView) findViewById(R.id.text_connection_state);
    _textViewConnectionStatus = (TextView) findViewById(R.id.text_connection_status);
    _activityIndicatior = (ProgressBar) findViewById(R.id.address_progress);

    _locationRequest = LocationRequest.create();

    _locationRequest.setInterval(LocationUtils.UPDATE_INTERVAL_IN_MILLISECONDS);

    _locationRequest.setFastestInterval(LocationUtils.FAST_INTERVAL_CEILING_IN_MILLISECONDS);

    _updatesRequested = false;

    _prefs = getSharedPreferences(LocationUtils.SHARED_PREFERENCES, Context.MODE_PRIVATE);

    _editor = _prefs.edit();

    _locationClient = new LocationClient(this, this, this);
  }
 @Override
 protected void onCreate(Bundle savedInstanceState) {
   Log.d(TAG, "onCreate() + " + this.hashCode());
   super.onCreate(savedInstanceState);
   setContentView(R.layout.activity_nexrad_view);
   eventBusProvider.getEventBus().register(this);
   mGoogleApiClient =
       new GoogleApiClient.Builder(this)
           .addConnectionCallbacks(this)
           .addOnConnectionFailedListener(this)
           .addApi(LocationServices.API)
           .build();
   // Create the LocationRequest object
   mLocationRequest =
       LocationRequest.create()
           .setPriority(LocationRequest.PRIORITY_LOW_POWER)
           .setInterval(10 * 60 * 1000) // 10 seconds, in milliseconds
           .setFastestInterval(1 * 60 * 1000); // 1 second, in milliseconds
   if (PackageManager.PERMISSION_GRANTED
       != ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION)) {
     ActivityCompat.requestPermissions(this, INITIAL_PERMS, INITIAL_REQUEST);
   }
   if (PreferenceManager.getDefaultSharedPreferences(this)
           .getString(SettingsActivity.KEY_PREF_NEXRAD_EMAILADDRESS, null)
       == null) {
     startSettings(true);
   } else {
     if (((NexradApp) getApplication()).getLastKnownLocation() != null) {
       RadarBitmapView radarView = (RadarBitmapView) findViewById(R.id.radarView);
       radarView.onEvent(
           new LocationChangeEvent(((NexradApp) getApplication()).getLastKnownLocation()));
     }
   }
 }
 private void initGPS() {
   if (googleApiClient == null) {
     googleApiClient =
         new GoogleApiClient.Builder(this)
             .addConnectionCallbacks(this)
             .addOnConnectionFailedListener(this)
             .addApi(LocationServices.API)
             .build();
   }
   if (locationRequest == null) {
     locationRequest = new LocationRequest();
     locationRequest =
         LocationRequest.create()
             .setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY)
             .setInterval(10000)
             .setFastestInterval(5000);
   }
   googleApiClient.connect();
   if (userAtConference()) {
     Log.d(TAG, "User checked in.");
     registerUserToConference();
     giveFeedback();
     deactivateButton();
     Log.d(TAG, "Pairing users..");
     pairUsers();
   } else {
     Log.d(TAG, "User not in range of Conference. User is not checked in.");
     Toast.makeText(this, "Not in range of conference.", Toast.LENGTH_LONG).show();
   }
 }
Exemplo n.º 8
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    ButterKnife.bind(this);

    mProgressBar.setVisibility(View.INVISIBLE);

    mRefreshView.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            getForecast(latitude, longitude);
          }
        });

    mGoogleApiClient =
        new GoogleApiClient.Builder(this)
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this)
            .addApi(LocationServices.API)
            .build();

    mLocationRequest =
        LocationRequest.create()
            .setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY)
            .setInterval(10 * 1000)
            .setFastestInterval(1 * 1000);
  }
Exemplo n.º 9
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_maps);

    mapViewBuilder = new DefaultAirMapViewBuilder(this);
    map = (AirMapView) findViewById(R.id.map);
    textLogs = (TextView) findViewById(R.id.textLogs);
    logsScrollView = (ScrollView) findViewById(R.id.logsScrollView);

    map.setOnMapClickListener(this);
    map.setOnCameraChangeListener(this);
    map.setOnCameraMoveListener(this);
    map.setOnMarkerClickListener(this);
    map.setOnMapInitializedListener(this);
    map.setOnInfoWindowClickListener(this);
    map.initialize(getSupportFragmentManager());

    mGoogleApiClient =
        new GoogleApiClient.Builder(this)
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this)
            .addApi(LocationServices.API)
            .build();

    // Create the LocationRequest object
    mLocationRequest =
        LocationRequest.create()
            .setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY)
            .setInterval(10 * 1000) // 10 seconds, in milliseconds
            .setFastestInterval(1 * 1000); // 1 second, in milliseconds
  }
 private void attachRecorder() {
   if (locationClientAPI == null) {
     connectToPlayAPI();
   } else if (locationClientAPI.isConnected()) {
     Integer priority = translateDesiredAccuracy(config.getDesiredAccuracy());
     LocationRequest locationRequest =
         LocationRequest.create()
             .setPriority(priority) // this.accuracy
             .setFastestInterval(config.getFastestInterval())
             .setInterval(config.getInterval());
     // .setSmallestDisplacement(config.getStationaryRadius());
     LocationServices.FusedLocationApi.requestLocationUpdates(
         locationClientAPI, locationRequest, this);
     Log.d(
         TAG,
         "- locationUpdateReceiver NOW RECORDING!!!!!!!!!! with priority: "
             + priority
             + ", fastestInterval: "
             + config.getFastestInterval()
             + ", interval: "
             + config.getInterval()
             + ", smallestDisplacement: "
             + config.getStationaryRadius());
   } else {
     locationClientAPI.connect();
   }
 }
Exemplo n.º 11
0
  @Override
  public void onConnected(Bundle bundle) {
    mLocationRequest = LocationRequest.create();
    mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
    mLocationRequest.setInterval(1000); // Update location every second

    LocationServices.FusedLocationApi.requestLocationUpdates(
        mGoogleApiClient, mLocationRequest, this);
  }
Exemplo n.º 12
0
  public LocationRequest createLocationRequest() {
    LocationRequest locationRequest = LocationRequest.create();
    locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
    locationRequest.setInterval(UPDATE_INTERVAL);
    locationRequest.setFastestInterval(FASTEST_INTERVAL);
    locationRequest.setExpirationDuration(ACCEPTED_LOCATION_AGE_MILLIS);
    locationRequest.setNumUpdates(5);

    return locationRequest;
  }
 private LocationRequest getLocationRequest() {
   LocationRequest lr =
       LocationRequest.create()
           .setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY)
           .setInterval(LOCATION_UPDATE_INTERVAL);
   if (!mConstantReporting) {
     lr.setNumUpdates(MAX_LOCATION_UPDATES);
   }
   return lr;
 }
Exemplo n.º 14
0
  /** start listen for location updates */
  private void startUpdateLocation() {
    LocationRequest request =
        LocationRequest.create()
            .setPriority(LocationRequest.PRIORITY_LOW_POWER)
            .setInterval(Consts.LOCATION_UPDATE_TIME)
            .setFastestInterval(Consts.LOCATION_UPDATE_TIME);

    locationClient.requestLocationUpdates(request, locationListener);
    SLog.d(TAG, "Location update started");
  }
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    ctx = getApplicationContext();
    activity = this;
    setContentView(R.layout.camera);
    setFields();

    mLocationRequest = LocationRequest.create();
    mLocationRequest.setInterval(2000);
    mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
    mLocationRequest.setFastestInterval(1000);

    mLocationClient = new LocationClient(getApplicationContext(), this, this);

    // get objects
    if (savedInstanceState != null) {
      Log.e(LOG, "##### savedInstanceState is LOADED");
      type = savedInstanceState.getInt("type", 0);
      projectSite = (ProjectSiteDTO) savedInstanceState.getSerializable("projectSite");
      project = (ProjectDTO) savedInstanceState.getSerializable("project");
      String path = savedInstanceState.getString("photoFile");
      if (path != null) {
        photoFile = new File(path);
      }
    } else {
      type = getIntent().getIntExtra("type", 0);
      project = (ProjectDTO) getIntent().getSerializableExtra("project");
      projectSite = (ProjectSiteDTO) getIntent().getSerializableExtra("projectSite");
      projectSiteTask = (ProjectSiteTaskDTO) getIntent().getSerializableExtra("projectSiteTask");
      companyStaff = (CompanyStaffDTO) getIntent().getSerializableExtra("companyStaff");
    }
    Log.e(LOG, "###### type: " + type);

    if (savedInstanceState != null) {
      String path = savedInstanceState.getString("filePath");
      if (path != null) {
        Log.w(LOG, "###### file path is: " + path);
        currentFullFile = new File(path);
        currentThumbFile = new File(savedInstanceState.getString("thumbPath"));
        try {
          Bitmap bm = ImageUtil.getBitmapFromUri(ctx, Uri.fromFile(currentFullFile));
          image.setImageBitmap(bm);
        } catch (Exception e) {
          e.printStackTrace();
        }
      } else {
        dispatchTakePictureIntent();
      }
    } else {
      dispatchTakePictureIntent();
    }
  }
Exemplo n.º 16
0
 @Override
 protected void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   setContentView(R.layout.activity_maps);
   googleApiClient =
       new GoogleApiClient.Builder(this)
           .addApi(LocationServices.API)
           .addConnectionCallbacks(this)
           .addOnConnectionFailedListener(this)
           .build();
   locationRequest =
       LocationRequest.create().setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY);
 }
Exemplo n.º 17
0
 @Override
 public void onCreate() {
   locationRequest = LocationRequest.create();
   locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
   locationRequest.setInterval(Application.locationUpdateTime);
   if (Application.locationMinDistance > 0) {
     locationRequest.setSmallestDisplacement(Application.locationMinDistance);
   }
   apiClient =
       new GoogleApiClient.Builder(getApplicationContext())
           .addApi(LocationServices.API)
           .addConnectionCallbacks(this)
           .addOnConnectionFailedListener(this)
           .build();
   apiClient.connect();
 }
 /** Runs when a GoogleApiClient object successfully connects. */
 @Override
 public void onConnected(Bundle connectionHint) {
   Log.i(TAG, "onConnected() - connected to Google API.");
   // set the parameters for our location determination.
   LocationRequest locRequest;
   locRequest = LocationRequest.create();
   locRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
   // These intervals should not really matter because we stop the
   // request after we receive the first result in onLocationChanged()
   locRequest.setInterval(10 * 1000); // 10 seconds.
   locRequest.setFastestInterval(1 * 1000); // 1 second
   // Request location updates - on LocationChanged is called each time
   // we get a new location notification.
   LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, locRequest, this);
   Log.i(TAG, "onConnected() - requesting location updates");
   Toast.makeText(mContext, "Requesting Location....", Toast.LENGTH_LONG).show();
 }
Exemplo n.º 19
0
  @Override
  public void onCreate() {

    // Create a new global location parameters object
    _LocationRequest = LocationRequest.create();

    _LocationRequest.setInterval(LocationUtils.UPDATE_INTERVAL_IN_MILLISECONDS);

    _LocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);

    _LocationRequest.setFastestInterval(LocationUtils.FAST_INTERVAL_CEILING_IN_MILLISECONDS);

    /*
     * Create a new location client, using the enclosing class to
     * handle callbacks.
     */
    _locationClient = new LocationClient(_context.getContext(), this, this);
  }
Exemplo n.º 20
0
  public LocationProvider(Context context, LocationCallback callback) {
    mGoogleApiClient =
        new GoogleApiClient.Builder(context)
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this)
            .addApi(LocationServices.API)
            .build();

    mLocationCallback = callback;

    mLocationRequest =
        LocationRequest.create()
            .setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY)
            .setInterval(10 * 1000)
            .setFastestInterval(1 * 1000);

    mContext = context;
  }
Exemplo n.º 21
0
  public Locator(
      Context context, LocationListener locationListener, ConnectionCallbacks callbacks) {
    this.context = context;
    this.locationListener = locationListener;
    this.callbacks = callbacks;

    mLocationRequest = LocationRequest.create();
    mLocationRequest.setInterval(UPDATE_INTERVAL_IN_MILLISECONDS);
    mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
    mLocationRequest.setFastestInterval(FAST_INTERVAL_CEILING_IN_MILLISECONDS);

    mUpdatesRequested = false;

    mPrefs = context.getSharedPreferences(SHARED_PREFERENCES, Context.MODE_PRIVATE);
    mEditor = mPrefs.edit();

    mLocationClient = new LocationClient(context, this, this);
  }
 private void attachRecorder() {
   if (locationClientAPI == null) {
     connectToPlayAPI();
   } else if (locationClientAPI.isConnected()) {
     LocationRequest locationRequest =
         LocationRequest.create()
             .setPriority(translateDesiredAccuracy(config.getDesiredAccuracy())) // this.accuracy
             .setFastestInterval(config.getFastestInterval())
             .setInterval(config.getInterval())
             .setSmallestDisplacement(config.getStationaryRadius());
     LocationServices.FusedLocationApi.requestLocationUpdates(
         locationClientAPI, locationRequest, locationUpdatePI);
     this.running = true;
     Log.d(TAG, "- locationUpdateReceiver NOW RECORDING!!!!!!!!!!");
   } else {
     locationClientAPI.connect();
   }
 }
Exemplo n.º 23
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.maps);
    map = mapFragment.getMap();
    map.setOnMapLongClickListener(this);

    locationClient = new LocationClient(this, this, this);

    // creating request object with some of parameters set
    locationRequest =
        LocationRequest.create()
            .setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY)
            .setInterval(UPDATE_INTERVAL)
            .setFastestInterval(FASTEST_INTERVAL);
    requester = new GeofenceRequester(this);
  }
Exemplo n.º 24
0
  public LocationService(Activity locationActivity) {

    locationRequest = LocationRequest.create();
    locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
    locationRequest.setInterval(INTERVAL);
    locationRequest.setFastestInterval(FASTEST_INTERVAL);
    this.locationActivity = locationActivity;

    googleApiClient =
        new GoogleApiClient.Builder(locationActivity)
            .addApi(LocationServices.API)
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this)
            .build();

    if (googleApiClient != null) {
      googleApiClient.connect();
    }
  }
Exemplo n.º 25
0
  public static Observable<Location> checkLocation(Context mContext) {
    ReactiveLocationProvider locationProvider = new ReactiveLocationProvider(mContext);

    LocationRequest locationRequest =
        LocationRequest.create()
            .setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY)
            .setNumUpdates(NUM_UPDATES_INTERVAL)
            .setInterval(INTERVAL);

    Observable<Location> locationObservable =
        locationProvider
            .getLastKnownLocation()
            .timeout(LOCATION_TIMEOUT, TimeUnit.SECONDS, Observable.just((Location) null))
            .concatWith(locationProvider.getUpdatedLocation(locationRequest))
            .distinctUntilChanged()
            .observeOn(AndroidSchedulers.mainThread());

    return locationObservable;
  }
Exemplo n.º 26
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_maps);
    setUpMapIfNeeded();

    mGoogleApiClient =
        new GoogleApiClient.Builder(this)
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this)
            .addApi(LocationServices.API)
            .build();

    // Create the LocationRequest object
    mLocationRequest =
        LocationRequest.create()
            .setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY)
            .setInterval(10 * 1000) // 10 seconds, in milliseconds
            .setFastestInterval(1 * 1000); // 1 second, in milliseconds
  }
Exemplo n.º 27
0
  private void initMapFr() {

    MapFragment mapFragment =
        (MapFragment) getFragmentManager().findFragmentById(R.id.map_fragment);
    mapFragment.getMapAsync(this);

    mGoogleApiClient =
        new GoogleApiClient.Builder(this)
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this)
            .addApi(LocationServices.API)
            .build();

    // Create the LocationRequest object
    mLocationRequest =
        LocationRequest.create()
            .setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY)
            .setInterval(10 * 1000) // 10 seconds, in milliseconds
            .setFastestInterval(1 * 1000); // 1 second, in milliseconds
  }
Exemplo n.º 28
0
  @Override
  public void onConnected(Bundle bundle) {

    LocationRequest locationRequest =
        LocationRequest.create()
            .setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY)
            .setInterval(CommManager.LOCATION_UPDATE_INTERVAL)
            .setFastestInterval(CommManager.LOCATION_UPDATE_FASTEST);

    LocationServices.FusedLocationApi.requestLocationUpdates(mApiClient, locationRequest, this)
        .setResultCallback(
            new ResultCallback<Status>() {
              @Override
              public void onResult(Status status) {
                if (!status.getStatus().isSuccess()) {
                  Log.d(TAG, "Location request failed!");
                }
              }
            });
  }
Exemplo n.º 29
0
  /*
   * Initialize the Activity
   */
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_location);

    // Get handles to the UI view objects
    mLatLng = (TextView) findViewById(R.id.lat_lng);
    mAddress = (TextView) findViewById(R.id.address);
    mActivityIndicator = (ProgressBar) findViewById(R.id.address_progress);
    mConnectionState = (TextView) findViewById(R.id.text_connection_state);
    mConnectionStatus = (TextView) findViewById(R.id.text_connection_status);

    // Create a new global location parameters object
    mLocationRequest = LocationRequest.create();

    /*
     * Set the update interval
     */
    mLocationRequest.setInterval(LocationUtils.UPDATE_INTERVAL_IN_MILLISECONDS);

    // Use high accuracy
    mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);

    // Set the interval ceiling to one minute
    mLocationRequest.setFastestInterval(LocationUtils.FAST_INTERVAL_CEILING_IN_MILLISECONDS);

    // Note that location updates are off until the user turns them on
    mUpdatesRequested = false;

    // Open Shared Preferences
    mPrefs = getSharedPreferences(LocationUtils.SHARED_PREFERENCES, Context.MODE_PRIVATE);

    // Get an editor
    mEditor = mPrefs.edit();

    /*
     * Create a new location client, using the enclosing class to
     * handle callbacks.
     */
    mLocationClient = new LocationClient(this, this, this);
  }
Exemplo n.º 30
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    ins = this; // Necessary for the Connection receiver to work
    setContentView(R.layout.activity_main);

    getWindow()
        .getDecorView()
        .setBackgroundDrawable(getResources().getDrawable(R.drawable.bg_blue_gradient));
    mPagerTitleStrip = (PagerTitleStrip) findViewById(R.id.pager_title_strip);

    // Create the adapter that will return a fragment for each of the three
    // primary sections of the activity.
    mPagerAdapter = new SectionsPagerAdapter(this, getSupportFragmentManager());

    // Set up the ViewPager with the sections adapter.
    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setAdapter(mPagerAdapter);
    mViewPager.addOnPageChangeListener(this);
    mViewPager.setOffscreenPageLimit(2);
    mViewPager.setPageTransformer(true, new ZoomOutPageTransformer());
    mViewPager.setCurrentItem(1);

    // Initialize the GoogleAPIClient
    mGoogleApiClient =
        new GoogleApiClient.Builder(this)
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this)
            .addApi(LocationServices.API)
            .build();

    // Create the LocationRequest object
    mLocationRequest =
        LocationRequest.create()
            .setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY)
            .setInterval(LOCATION_REQUEST_MAX_INTERVAL * 1000) // 10 seconds, in milliseconds
            .setFastestInterval(
                LOCATION_REQUEST_FASTEST_INTERVAL * 1000); // 10 seconds, in milliseconds

    Log.i(TAG, "Main Activity On Create method is done.");
  }