Mobile: implement follow mode

This commit is contained in:
fkloft
2013-12-23 21:53:25 +01:00
parent 51064a29c4
commit 78f6e07457
8 changed files with 82 additions and 11 deletions

View File

@ -189,4 +189,14 @@ public class IITC_JSInterface {
}
});
}
@JavascriptInterface
public void setFollowMode(final boolean follow) {
mIitc.runOnUiThread(new Runnable() {
@Override
public void run() {
mIitc.getUserLocation().setFollowMode(follow);
}
});
}
}

View File

@ -400,18 +400,32 @@ public class IITC_Mobile extends Activity implements OnSharedPreferenceChangeLis
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
if (mNavigationHelper != null) {
boolean visible = !mNavigationHelper.isDrawerOpened();
boolean visible = false;
if (mNavigationHelper != null)
visible = !mNavigationHelper.isDrawerOpened();
for (int i = 0; i < menu.size(); i++)
if (menu.getItem(i).getItemId() != R.id.action_settings) {
// clear cookies is part of the advanced menu
if (menu.getItem(i).getItemId() == R.id.menu_clear_cookies) {
menu.getItem(i).setVisible(mAdvancedMenu & visible);
} else {
menu.getItem(i).setVisible(visible);
}
}
for (int i = 0; i < menu.size(); i++) {
MenuItem item = menu.getItem(i);
switch (item.getItemId()) {
case R.id.action_settings:
item.setVisible(true);
break;
case R.id.menu_clear_cookies:
item.setVisible(mAdvancedMenu && visible);
break;
case R.id.locate:
item.setVisible(visible);
item.setIcon(mUserLocation.isFollowing()
? R.drawable.ic_action_location_follow
: R.drawable.ic_action_location_found);
break;
default:
item.setVisible(visible);
}
}
return super.onPrepareOptionsMenu(menu);
@ -473,6 +487,7 @@ public class IITC_Mobile extends Activity implements OnSharedPreferenceChangeLis
public void reloadIITC() {
mNavigationHelper.reset();
mMapSettings.reset();
mUserLocation.reset();
mBackStack.clear();
// iitc starts on map after reload
mCurrentPane = Pane.MAP;
@ -633,4 +648,8 @@ public class IITC_Mobile extends Activity implements OnSharedPreferenceChangeLis
public IITC_MapSettings getMapSettings() {
return mMapSettings;
}
public IITC_UserLocation getUserLocation() {
return mUserLocation;
}
}

View File

@ -25,6 +25,7 @@ public class IITC_UserLocation implements LocationListener, SensorEventListener
private SensorManager mSensorManager = null;
private float[] mValuesGravity = null, mValuesGeomagnetic = null;
private double mOrientation = 0;
private boolean mFollowing = false;
public IITC_UserLocation(IITC_Mobile iitc) {
mIitc = iitc;
@ -95,6 +96,10 @@ public class IITC_UserLocation implements LocationListener, SensorEventListener
return mLastLocation != null;
}
public boolean isFollowing() {
return mFollowing;
}
public void locate() {
// do not touch the javascript while iitc boots
if (mIitc.isLoading()) return;
@ -122,6 +127,15 @@ public class IITC_UserLocation implements LocationListener, SensorEventListener
updateListeners();
}
public void reset() {
setFollowMode(false);
}
public void setFollowMode(boolean follow) {
mFollowing = follow;
mIitc.invalidateOptionsMenu();
}
/**
* set the location mode to use. Available modes:
* 0: don't show user's position