forked from organicmaps/organicmaps
[yopme] Avoid useless drawings on the BS.
This commit is contained in:
parent
6312cff570
commit
a9bf899d65
2 changed files with 25 additions and 22 deletions
|
@ -21,25 +21,22 @@ import com.mapswithme.yopme.util.BatteryHelper.BatteryLevel;
|
|||
|
||||
public class LocationRequester implements Handler.Callback
|
||||
{
|
||||
private final static String TAG = LocationRequester.class.getSimpleName();
|
||||
|
||||
protected Context mContext;
|
||||
protected LocationManager mLocationManager;
|
||||
protected Handler mDelayedEventsHandler;
|
||||
|
||||
private final Logger mLogger = StubLogger.get();
|
||||
private final Logger mLogger = StubLogger.get(); // SimpleLogger.get("MWM_DBG");
|
||||
|
||||
// Location
|
||||
private boolean mIsRegistered = false;
|
||||
private BatteryLevel mBatteryLevel;
|
||||
private final Set<LocationListener> mListeners = new HashSet<LocationListener>();
|
||||
private Location mLocation;
|
||||
|
||||
private Location mLocation = null;
|
||||
private final static long MAX_TIME_FOR_SUBSCRIPTION_FIX = 15*60*1000;
|
||||
// location
|
||||
|
||||
// Handler messages
|
||||
private final static int WHAT_LOCATION_REQUEST_CANCELATION = 0x01;
|
||||
// handler massages
|
||||
|
||||
// Intents
|
||||
private PendingIntent mGpsLocationIntent;
|
||||
|
@ -51,7 +48,6 @@ public class LocationRequester implements Handler.Callback
|
|||
private final static String EXTRA_IS_GPS = ".is_gps";
|
||||
private final static String EXTRA_IS_NETWORK = ".is_network";
|
||||
private final static String EXTRA_IS_PASSAIVE = ".is_passive";
|
||||
// intents
|
||||
|
||||
// Receivers
|
||||
private final BroadcastReceiver mLocationReciever = new BroadcastReceiver()
|
||||
|
@ -70,6 +66,9 @@ public class LocationRequester implements Handler.Callback
|
|||
&& areLocationsFarEnough(l, mLocation);
|
||||
if (isLocationReallyChanged)
|
||||
{
|
||||
mLogger.d("Old location: ", mLocation);
|
||||
mLogger.d("New location: ", l);
|
||||
|
||||
listener.onLocationChanged(l);
|
||||
mLocation = l;
|
||||
postRequestCancelation(MAX_TIME_FOR_SUBSCRIPTION_FIX);
|
||||
|
@ -78,7 +77,6 @@ public class LocationRequester implements Handler.Callback
|
|||
|
||||
// TODO: add another events processing
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -87,8 +85,8 @@ public class LocationRequester implements Handler.Callback
|
|||
return mBatteryLevel != BatteryLevel.CRITICAL;
|
||||
}
|
||||
|
||||
private final BroadcastReceiver mBatteryReciever = new BroadcastReceiver() {
|
||||
|
||||
private final BroadcastReceiver mBatteryReciever = new BroadcastReceiver()
|
||||
{
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent)
|
||||
{
|
||||
|
@ -101,7 +99,7 @@ public class LocationRequester implements Handler.Callback
|
|||
mLogger.d("Stopped updated due to battery level update.");
|
||||
}
|
||||
}
|
||||
}; // receivers
|
||||
};
|
||||
|
||||
public LocationRequester(Context context)
|
||||
{
|
||||
|
@ -281,6 +279,9 @@ public class LocationRequester implements Handler.Callback
|
|||
if (isFirstOneBetterLocation(l, res))
|
||||
res = l;
|
||||
}
|
||||
|
||||
// Save returning location to suppress useless drawings.
|
||||
mLocation = res;
|
||||
return res;
|
||||
}
|
||||
|
||||
|
|
|
@ -70,7 +70,7 @@ public class BackscreenActivity extends BSActivity implements LocationListener
|
|||
private boolean mIsPoi;
|
||||
//@}
|
||||
|
||||
private final Logger mLogger = StubLogger.get();
|
||||
private final Logger mLogger = StubLogger.get(); // SimpleLogger.get("MWM_DBG");
|
||||
|
||||
protected View mView;
|
||||
protected ImageView mMapView;
|
||||
|
@ -88,9 +88,10 @@ public class BackscreenActivity extends BSActivity implements LocationListener
|
|||
@Override
|
||||
protected void onBSTouchEnadle()
|
||||
{
|
||||
// subscribe for locations again
|
||||
mLogger.d("LocationRequester: touches were enabled, requbscribe to location");
|
||||
// subscribe for locations again when touches were enabled
|
||||
mLogger.d("onBSTouchEnadle : requestLocationUpdate");
|
||||
requestLocationUpdate();
|
||||
|
||||
super.onBSTouchEnadle();
|
||||
}
|
||||
|
||||
|
@ -141,11 +142,10 @@ public class BackscreenActivity extends BSActivity implements LocationListener
|
|||
{
|
||||
super.onBSResume();
|
||||
|
||||
mLogger.d("onBSResume : requestLocationUpdate");
|
||||
|
||||
mLocationRequester.register();
|
||||
requestLocationUpdate();
|
||||
|
||||
updateData();
|
||||
invalidate();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -182,7 +182,10 @@ public class BackscreenActivity extends BSActivity implements LocationListener
|
|||
final Gestures action = motionEvent.getBSAction();
|
||||
|
||||
if (action == Gestures.GESTURES_BS_SINGLE_TAP)
|
||||
{
|
||||
mLogger.d("onBSTouchEvent : requestLocationUpdate");
|
||||
requestLocationUpdate();
|
||||
}
|
||||
else if (action == Gestures.GESTURES_BS_LR || action == Gestures.GESTURES_BS_SCROLL_LEFT)
|
||||
{
|
||||
if (!zoomOut())
|
||||
|
@ -203,6 +206,7 @@ public class BackscreenActivity extends BSActivity implements LocationListener
|
|||
else
|
||||
return; // do not react on other events
|
||||
|
||||
mLogger.d("onBSTouchEvent : invalidate");
|
||||
updateData();
|
||||
invalidate();
|
||||
}
|
||||
|
@ -223,15 +227,13 @@ public class BackscreenActivity extends BSActivity implements LocationListener
|
|||
else if (ACTION_SHOW_RECT.equals(intent.getAction()))
|
||||
setToPoiMode(intent);
|
||||
|
||||
|
||||
mLogger.d("onHandleIntent : requestLocationUpdate");
|
||||
requestLocationUpdate();
|
||||
|
||||
notifyBSUpdated();
|
||||
}
|
||||
|
||||
// Do always update data.
|
||||
// This function is called from back screen menu without any extras.
|
||||
|
||||
mLogger.d("onHandleIntent : invalidate");
|
||||
updateData();
|
||||
invalidate();
|
||||
}
|
||||
|
@ -385,7 +387,6 @@ public class BackscreenActivity extends BSActivity implements LocationListener
|
|||
{
|
||||
ensureCorrectZoomLevel();
|
||||
|
||||
|
||||
if (mMode == null)
|
||||
{
|
||||
mLogger.e("Unknown mode");
|
||||
|
@ -519,6 +520,7 @@ public class BackscreenActivity extends BSActivity implements LocationListener
|
|||
{
|
||||
mLocation = l;
|
||||
|
||||
mLogger.d("onLocationChanged : invalidate");
|
||||
updateData();
|
||||
invalidate();
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue