Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(46)

Side by Side Diff: device/geolocation/android/java/org/chromium/device/geolocation/LocationProviderAdapter.java

Issue 2679323004: Android: Restructure geolocation folder structure (Closed)
Patch Set: Update deps Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 package org.chromium.device.geolocation;
6
7 import android.content.Context;
8
9 import org.chromium.base.ThreadUtils;
10 import org.chromium.base.VisibleForTesting;
11 import org.chromium.base.annotations.CalledByNative;
12 import org.chromium.base.annotations.MainDex;
13
14 import java.util.concurrent.FutureTask;
15
16 /**
17 * Implements the Java side of LocationProviderAndroid.
18 * Delegates all real functionality to the implementation
19 * returned from LocationProviderFactory.
20 * See detailed documentation on
21 * content/browser/geolocation/location_api_adapter_android.h.
22 * Based on android.webkit.GeolocationService.java
23 */
24 @MainDex
25 @VisibleForTesting
26 public class LocationProviderAdapter {
27
28 // Delegate handling the real work in the main thread.
29 private LocationProviderFactory.LocationProvider mImpl;
30
31 private LocationProviderAdapter(Context context) {
32 mImpl = LocationProviderFactory.get(context);
33 }
34
35 @CalledByNative
36 public static LocationProviderAdapter create(Context context) {
37 return new LocationProviderAdapter(context);
38 }
39
40 /**
41 * Start listening for location updates until we're told to quit. May be cal led in any thread.
42 * @param enableHighAccuracy Whether or not to enable high accuracy location providers.
43 */
44 @CalledByNative
45 public boolean start(final boolean enableHighAccuracy) {
46 FutureTask<Void> task = new FutureTask<Void>(new Runnable() {
47 @Override
48 public void run() {
49 mImpl.start(enableHighAccuracy);
50 }
51 }, null);
52 ThreadUtils.runOnUiThread(task);
53 return true;
54 }
55
56 /**
57 * Stop listening for location updates. May be called in any thread.
58 */
59 @CalledByNative
60 public void stop() {
61 FutureTask<Void> task = new FutureTask<Void>(new Runnable() {
62 @Override
63 public void run() {
64 mImpl.stop();
65 }
66 }, null);
67 ThreadUtils.runOnUiThread(task);
68 }
69
70 /**
71 * Returns true if we are currently listening for location updates, false if not.
72 * Must be called only in the UI thread.
73 */
74 public boolean isRunning() {
75 assert ThreadUtils.runningOnUiThread();
76 return mImpl.isRunning();
77 }
78
79 public static void newLocationAvailable(double latitude, double longitude, d ouble timestamp,
80 boolean hasAltitude, double altitude,
81 boolean hasAccuracy, double accuracy,
82 boolean hasHeading, double heading,
83 boolean hasSpeed, double speed) {
84 nativeNewLocationAvailable(latitude, longitude, timestamp, hasAltitude, altitude,
85 hasAccuracy, accuracy, hasHeading, heading, hasSpeed, speed);
86 }
87
88 public static void newErrorAvailable(String message) {
89 nativeNewErrorAvailable(message);
90 }
91
92 // Native functions
93 private static native void nativeNewLocationAvailable(
94 double latitude, double longitude, double timeStamp,
95 boolean hasAltitude, double altitude,
96 boolean hasAccuracy, double accuracy,
97 boolean hasHeading, double heading,
98 boolean hasSpeed, double speed);
99 private static native void nativeNewErrorAvailable(String message);
100 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698