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

Side by Side Diff: content/public/android/java/src/org/chromium/content/browser/LocationProvider.java

Issue 11419287: android: Improve ActivityStatus and add ChromiumActivity. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years 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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.content.browser; 5 package org.chromium.content.browser;
6 6
7 import android.content.Context; 7 import android.content.Context;
8 import android.location.Criteria; 8 import android.location.Criteria;
9 import android.location.Location; 9 import android.location.Location;
10 import android.location.LocationListener; 10 import android.location.LocationListener;
(...skipping 19 matching lines...) Expand all
30 30
31 // Log tag 31 // Log tag
32 private static final String TAG = "LocationProvider"; 32 private static final String TAG = "LocationProvider";
33 33
34 /** 34 /**
35 * This is the core of android location provider. It is a separate class for clarity 35 * This is the core of android location provider. It is a separate class for clarity
36 * so that it can manage all processing completely in the UI thread. The con tainer class 36 * so that it can manage all processing completely in the UI thread. The con tainer class
37 * ensures that the start/stop calls into this class are done in the UI thre ad. 37 * ensures that the start/stop calls into this class are done in the UI thre ad.
38 */ 38 */
39 private static class LocationProviderImpl 39 private static class LocationProviderImpl
40 implements LocationListener, ActivityStatus.Listener { 40 implements LocationListener, ActivityStatus.StateListener {
41 41
42 private Context mContext; 42 private Context mContext;
43 private LocationManager mLocationManager; 43 private LocationManager mLocationManager;
44 private boolean mIsRunning; 44 private boolean mIsRunning;
45 private boolean mShouldRunAfterActivityResume; 45 private boolean mShouldRunAfterActivityResume;
46 private boolean mIsGpsEnabled; 46 private boolean mIsGpsEnabled;
47 47
48 LocationProviderImpl(Context context) { 48 LocationProviderImpl(Context context) {
49 mContext = context; 49 mContext = context;
50 } 50 }
51 51
52 public void onActivityStatusChanged(boolean isPaused) { 52 public void onActivityStateChange(int state) {
53 if (isPaused) { 53 if (state == ActivityStatus.PAUSED) {
digit1 2012/12/04 15:41:55 I suspect this should really be STOPPED / STARTED
Philippe 2012/12/04 16:12:42 This seems too aggressive indeed. Let's see what t
joth 2012/12/04 22:42:09 +1 ISTM that STOPPED makes more sense here. copyin
John Knottenbelt 2012/12/05 11:19:52 This sounds reasonable to me, too.
54 mShouldRunAfterActivityResume = mIsRunning; 54 mShouldRunAfterActivityResume = mIsRunning;
55 unregisterFromLocationUpdates(); 55 unregisterFromLocationUpdates();
56 } else { 56 } else if (state == ActivityStatus.RESUMED) {
57 assert !mIsRunning; 57 assert !mIsRunning;
58 if (mShouldRunAfterActivityResume) { 58 if (mShouldRunAfterActivityResume) {
59 registerForLocationUpdates(); 59 registerForLocationUpdates();
60 } 60 }
61 } 61 }
62 } 62 }
63 63
64 /** 64 /**
65 * Start listening for location updates. 65 * Start listening for location updates.
66 * @param gpsEnabled Whether or not we're interested in high accuracy GP S. 66 * @param gpsEnabled Whether or not we're interested in high accuracy GP S.
67 */ 67 */
68 private void start(boolean gpsEnabled) { 68 private void start(boolean gpsEnabled) {
69 if (!mIsRunning && !mShouldRunAfterActivityResume) { 69 if (!mIsRunning && !mShouldRunAfterActivityResume) {
70 // Currently idle so start listening to activity status changes. 70 // Currently idle so start listening to activity status changes.
71 ActivityStatus.getInstance().registerListener(this); 71 ActivityStatus.registerStateListener(this);
72 } 72 }
73 mIsGpsEnabled = gpsEnabled; 73 mIsGpsEnabled = gpsEnabled;
74 if (ActivityStatus.getInstance().isPaused()) { 74 if (ActivityStatus.getInstance().isPaused()) {
75 mShouldRunAfterActivityResume = true; 75 mShouldRunAfterActivityResume = true;
76 } else { 76 } else {
77 unregisterFromLocationUpdates(); 77 unregisterFromLocationUpdates();
78 registerForLocationUpdates(); 78 registerForLocationUpdates();
79 } 79 }
80 } 80 }
81 81
82 /** 82 /**
83 * Stop listening for location updates. 83 * Stop listening for location updates.
84 */ 84 */
85 private void stop() { 85 private void stop() {
86 unregisterFromLocationUpdates(); 86 unregisterFromLocationUpdates();
87 ActivityStatus.getInstance().unregisterListener(this); 87 ActivityStatus.unregisterStateListener(this);
88 mShouldRunAfterActivityResume = false; 88 mShouldRunAfterActivityResume = false;
89 } 89 }
90 90
91 /** 91 /**
92 * Returns true if we are currently listening for location updates, fals e if not. 92 * Returns true if we are currently listening for location updates, fals e if not.
93 */ 93 */
94 private boolean isRunning() { 94 private boolean isRunning() {
95 return mIsRunning; 95 return mIsRunning;
96 } 96 }
97 97
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 224
225 // Native functions 225 // Native functions
226 public static native void nativeNewLocationAvailable( 226 public static native void nativeNewLocationAvailable(
227 double latitude, double longitude, double timeStamp, 227 double latitude, double longitude, double timeStamp,
228 boolean hasAltitude, double altitude, 228 boolean hasAltitude, double altitude,
229 boolean hasAccuracy, double accuracy, 229 boolean hasAccuracy, double accuracy,
230 boolean hasHeading, double heading, 230 boolean hasHeading, double heading,
231 boolean hasSpeed, double speed); 231 boolean hasSpeed, double speed);
232 public static native void nativeNewErrorAvailable(String message); 232 public static native void nativeNewErrorAvailable(String message);
233 } 233 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698