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, boolean NoOpLocationProvider)34     public LocationManager(Context context, boolean NoOpLocationProvider) {
35         Log.d(TAG, "Using " +
36                 (NoOpLocationProvider ? "NoOpLocationProvider" : "LegacyLocationProvider"));
37         LocationProvider lp = NoOpLocationProvider ? new NoOpLocationProvider(context) :
38                 new LegacyLocationProvider(context);
39         mLocationProvider = lp;
40     }
41 
42     /**
43      * Start/stop location recording.
44      */
recordLocation(boolean recordLocation)45     public void recordLocation(boolean recordLocation) {
46         mRecordLocation = recordLocation;
47         mLocationProvider.recordLocation(mRecordLocation);
48     }
49 
50     /**
51      * Returns the current location from the location provider or null, if
52      * location could not be determined or is switched off.
53      */
getCurrentLocation()54     public Location getCurrentLocation() {
55         return mLocationProvider.getCurrentLocation();
56     }
57 
58     /*
59      * Disconnects the location provider.
60      */
disconnect()61     public void disconnect() {
62         mLocationProvider.disconnect();
63     }
64 }
65