1 /*
2  * Copyright (C) 2013 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.camera.app;
18 
19 import android.content.Context;
20 import android.location.Location;
21 
22 import com.android.camera.debug.Log;
23 
24 /**
25  * A class to select the best available location provider (fused location
26  * provider, or network/gps if the fused location provider is unavailable)
27  * and provide a common location interface.
28  */
29 public class LocationManager {
30     private static final Log.Tag TAG = new Log.Tag("LocationManager");
31     LocationProvider mLocationProvider;
32     private boolean mRecordLocation;
33 
LocationManager(Context context)34     public LocationManager(Context context) {
35         Log.d(TAG, "Using legacy location provider.");
36         LegacyLocationProvider llp = new LegacyLocationProvider(context);
37         mLocationProvider = llp;
38     }
39 
40     /**
41      * Start/stop location recording.
42      */
recordLocation(boolean recordLocation)43     public void recordLocation(boolean recordLocation) {
44         mRecordLocation = recordLocation;
45         mLocationProvider.recordLocation(mRecordLocation);
46     }
47 
48     /**
49      * Returns the current location from the location provider or null, if
50      * location could not be determined or is switched off.
51      */
getCurrentLocation()52     public Location getCurrentLocation() {
53         return mLocationProvider.getCurrentLocation();
54     }
55 
56     /*
57      * Disconnects the location provider.
58      */
disconnect()59     public void disconnect() {
60         mLocationProvider.disconnect();
61     }
62 }
63