Merge branch 'fkloft/user-location'
This commit is contained in:
commit
cb281151a2
@ -5,8 +5,11 @@
|
|||||||
.user-location .container {
|
.user-location .container {
|
||||||
height: 32px;
|
height: 32px;
|
||||||
width: 32px;
|
width: 32px;
|
||||||
transform-origin: center;
|
transform-origin: center;
|
||||||
-webkit-transform-origin: center;
|
-webkit-transform-origin: center;
|
||||||
|
transition: all 200ms linear;
|
||||||
|
-moz-transition: all 200ms linear;
|
||||||
|
-webkit-transition: all 200ms linear;
|
||||||
}
|
}
|
||||||
|
|
||||||
.user-location .container .inner,
|
.user-location .container .inner,
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
window.plugin.userLocation = function() {};
|
window.plugin.userLocation = function() {};
|
||||||
|
|
||||||
window.plugin.userLocation.locationLayer = new L.LayerGroup();
|
window.plugin.userLocation.locationLayer = new L.LayerGroup();
|
||||||
|
window.plugin.userLocation.follow = false;
|
||||||
|
|
||||||
window.plugin.userLocation.setup = function() {
|
window.plugin.userLocation.setup = function() {
|
||||||
$('<style>').prop('type', 'text/css').html('@@INCLUDESTRING:mobile/plugins/user-location.css@@').appendTo('head');
|
$('<style>').prop('type', 'text/css').html('@@INCLUDESTRING:mobile/plugins/user-location.css@@').appendTo('head');
|
||||||
@ -59,10 +60,20 @@ window.plugin.userLocation.setup = function() {
|
|||||||
window.plugin.userLocation.circle = circle;
|
window.plugin.userLocation.circle = circle;
|
||||||
window.plugin.userLocation.icon = icon;
|
window.plugin.userLocation.icon = icon;
|
||||||
|
|
||||||
|
window.map.on('movestart', window.plugin.userLocation.onMoveStart);
|
||||||
window.map.on('zoomend', window.plugin.userLocation.onZoomEnd);
|
window.map.on('zoomend', window.plugin.userLocation.onZoomEnd);
|
||||||
window.plugin.userLocation.onZoomEnd();
|
window.plugin.userLocation.onZoomEnd();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
window.plugin.userLocation.onMoveStart = function(e) {
|
||||||
|
if(window.plugin.userLocation.moving)
|
||||||
|
return;
|
||||||
|
|
||||||
|
window.plugin.userLocation.follow = false;
|
||||||
|
if(typeof android !== 'undefined' && android && android.setFollowMode)
|
||||||
|
android.setFollowMode(window.plugin.userLocation.follow);
|
||||||
|
};
|
||||||
|
|
||||||
window.plugin.userLocation.onZoomEnd = function() {
|
window.plugin.userLocation.onZoomEnd = function() {
|
||||||
if(window.map.getZoom() < 16)
|
if(window.map.getZoom() < 16)
|
||||||
window.plugin.userLocation.locationLayer.removeLayer(window.plugin.userLocation.circle);
|
window.plugin.userLocation.locationLayer.removeLayer(window.plugin.userLocation.circle);
|
||||||
@ -71,6 +82,13 @@ window.plugin.userLocation.onZoomEnd = function() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
window.plugin.userLocation.locate = function(lat, lng, accuracy) {
|
window.plugin.userLocation.locate = function(lat, lng, accuracy) {
|
||||||
|
if(window.plugin.userLocation.follow) {
|
||||||
|
window.plugin.userLocation.follow = false;
|
||||||
|
if(typeof android !== 'undefined' && android && android.setFollowMode)
|
||||||
|
android.setFollowMode(window.plugin.userLocation.follow);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
var latlng = new L.LatLng(lat, lng);
|
var latlng = new L.LatLng(lat, lng);
|
||||||
|
|
||||||
var latAccuracy = 180 * accuracy / 40075017;
|
var latAccuracy = 180 * accuracy / 40075017;
|
||||||
@ -84,6 +102,12 @@ window.plugin.userLocation.locate = function(lat, lng, accuracy) {
|
|||||||
// so limit to 17 (enough to see all portals)
|
// so limit to 17 (enough to see all portals)
|
||||||
zoom = Math.min(zoom,17);
|
zoom = Math.min(zoom,17);
|
||||||
|
|
||||||
|
if(window.map.getCenter().distanceTo(latlng) < 10) {
|
||||||
|
window.plugin.userLocation.follow = true;
|
||||||
|
if(typeof android !== 'undefined' && android && android.setFollowMode)
|
||||||
|
android.setFollowMode(window.plugin.userLocation.follow);
|
||||||
|
}
|
||||||
|
|
||||||
window.map.setView(latlng, zoom);
|
window.map.setView(latlng, zoom);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -91,16 +115,39 @@ window.plugin.userLocation.onLocationChange = function(lat, lng) {
|
|||||||
var latlng = new L.LatLng(lat, lng);
|
var latlng = new L.LatLng(lat, lng);
|
||||||
window.plugin.userLocation.marker.setLatLng(latlng);
|
window.plugin.userLocation.marker.setLatLng(latlng);
|
||||||
window.plugin.userLocation.circle.setLatLng(latlng);
|
window.plugin.userLocation.circle.setLatLng(latlng);
|
||||||
|
|
||||||
|
if(window.plugin.userLocation.follow) {
|
||||||
|
// move map if marker moves more than 35% from the center
|
||||||
|
// 100% - 2*15% = 70% → 35% from center in either direction
|
||||||
|
if(map.getBounds().pad(-0.15).contains(latlng))
|
||||||
|
return;
|
||||||
|
|
||||||
|
window.plugin.userLocation.moving = true;
|
||||||
|
window.map.setView(latlng);
|
||||||
|
window.plugin.userLocation.moving = false;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
window.plugin.userLocation.onOrientationChange = function(direction) {
|
window.plugin.userLocation.onOrientationChange = function(direction) {
|
||||||
$(".container", window.plugin.userLocation.marker._icon)
|
var container = $(".container", window.plugin.userLocation.marker._icon);
|
||||||
.removeClass("circle")
|
|
||||||
.addClass("arrow")
|
if(direction === null) {
|
||||||
.css({
|
container
|
||||||
"transform": "rotate(" + direction + "deg)",
|
.removeClass("arrow")
|
||||||
"webkitTransform": "rotate(" + direction + "deg)"
|
.addClass("circle")
|
||||||
});
|
.css({
|
||||||
|
"transform": "",
|
||||||
|
"webkitTransform": ""
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
container
|
||||||
|
.removeClass("circle")
|
||||||
|
.addClass("arrow")
|
||||||
|
.css({
|
||||||
|
"transform": "rotate(" + direction + "deg)",
|
||||||
|
"webkitTransform": "rotate(" + direction + "deg)"
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var setup = window.plugin.userLocation.setup;
|
var setup = window.plugin.userLocation.setup;
|
||||||
|
BIN
mobile/res/drawable-hdpi/ic_action_location_follow.png
Normal file
BIN
mobile/res/drawable-hdpi/ic_action_location_follow.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 646 B |
BIN
mobile/res/drawable-mdpi/ic_action_location_follow.png
Normal file
BIN
mobile/res/drawable-mdpi/ic_action_location_follow.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 451 B |
BIN
mobile/res/drawable-xhdpi/ic_action_location_follow.png
Normal file
BIN
mobile/res/drawable-xhdpi/ic_action_location_follow.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 820 B |
BIN
mobile/res/drawable-xxhdpi/ic_action_location_follow.png
Normal file
BIN
mobile/res/drawable-xxhdpi/ic_action_location_follow.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.2 KiB |
@ -83,11 +83,7 @@
|
|||||||
<string name="pref_tweaks_cat">Tweaks</string>
|
<string name="pref_tweaks_cat">Tweaks</string>
|
||||||
<string name="pref_plugins">IITC Plugins</string>
|
<string name="pref_plugins">IITC Plugins</string>
|
||||||
<string name="pref_plugins_title">Available plugins</string>
|
<string name="pref_plugins_title">Available plugins</string>
|
||||||
<string name="pref_user_loc_screen">User location</string>
|
<string name="pref_user_location">Display user location on map</string>
|
||||||
<string name="pref_user_loc">Display user location</string>
|
|
||||||
<string name="pref_user_loc_sum">Show users position on map</string>
|
|
||||||
<string name="pref_user_loc_sensor">Use sensor orientation</string>
|
|
||||||
<string name="pref_user_loc_sensor_sum">Experimental! Fancier but eats battery packs for breakfast</string>
|
|
||||||
<string name="pref_user_zoom">Show zoom control</string>
|
<string name="pref_user_zoom">Show zoom control</string>
|
||||||
<string name="pref_user_zoom_sum">Shows +/- buttons even on multitouch capable devices.</string>
|
<string name="pref_user_zoom_sum">Shows +/- buttons even on multitouch capable devices.</string>
|
||||||
<string name="pref_fullscreen">Hide in fullscreen mode</string>
|
<string name="pref_fullscreen">Hide in fullscreen mode</string>
|
||||||
@ -128,6 +124,16 @@
|
|||||||
<item>8</item>
|
<item>8</item>
|
||||||
<item>16</item>
|
<item>16</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
|
<string-array name="pref_user_location_titles">
|
||||||
|
<item>Don\'t show user position</item>
|
||||||
|
<item>Show user position on map</item>
|
||||||
|
<item>Show user position and orientation on map</item>
|
||||||
|
</string-array>
|
||||||
|
<string-array name="pref_user_location_values">
|
||||||
|
<item>0</item>
|
||||||
|
<item>1</item>
|
||||||
|
<item>2</item>
|
||||||
|
</string-array>
|
||||||
|
|
||||||
<string name="menu_clear_cookies">Clear Cookies</string>
|
<string name="menu_clear_cookies">Clear Cookies</string>
|
||||||
<string name="menu_search">Search</string>
|
<string name="menu_search">Search</string>
|
||||||
|
@ -14,33 +14,26 @@
|
|||||||
<PreferenceCategory
|
<PreferenceCategory
|
||||||
android:key="pref_ui_cat"
|
android:key="pref_ui_cat"
|
||||||
android:title="@string/pref_ui_cat">
|
android:title="@string/pref_ui_cat">
|
||||||
<PreferenceScreen
|
<ListPreference
|
||||||
android:key="pref_user_loc_screen"
|
android:defaultValue="0"
|
||||||
android:persistent="false"
|
android:entries="@array/pref_user_location_titles"
|
||||||
android:title="@string/pref_user_loc_screen">
|
android:entryValues="@array/pref_user_location_values"
|
||||||
<CheckBoxPreference
|
android:key="pref_user_location_mode"
|
||||||
android:defaultValue="false"
|
android:title="@string/pref_user_location"/>
|
||||||
android:key="pref_user_loc"
|
|
||||||
android:summary="@string/pref_user_loc_sum"
|
|
||||||
android:title="@string/pref_user_loc"/>
|
|
||||||
<CheckBoxPreference
|
|
||||||
android:defaultValue="true"
|
|
||||||
android:key="pref_user_loc_sensor"
|
|
||||||
android:dependency="pref_user_loc"
|
|
||||||
android:summary="@string/pref_user_loc_sensor_sum"
|
|
||||||
android:title="@string/pref_user_loc_sensor"/>
|
|
||||||
</PreferenceScreen>
|
|
||||||
<CheckBoxPreference
|
<CheckBoxPreference
|
||||||
android:defaultValue="false"
|
android:defaultValue="false"
|
||||||
android:key="pref_user_zoom"
|
android:key="pref_user_zoom"
|
||||||
android:summary="@string/pref_user_zoom_sum"
|
android:summary="@string/pref_user_zoom_sum"
|
||||||
android:title="@string/pref_user_zoom"/>
|
android:title="@string/pref_user_zoom"/>
|
||||||
|
|
||||||
<MultiSelectListPreference
|
<MultiSelectListPreference
|
||||||
|
android:entries="@array/pref_hide_fullscreen"
|
||||||
|
android:entryValues="@array/pref_hide_fullscreen_vals"
|
||||||
android:key="pref_fullscreen"
|
android:key="pref_fullscreen"
|
||||||
android:summary="@string/pref_fullscreen_sum"
|
android:summary="@string/pref_fullscreen_sum"
|
||||||
android:title="@string/pref_fullscreen"
|
android:title="@string/pref_fullscreen"/>
|
||||||
android:entries="@array/pref_hide_fullscreen"
|
|
||||||
android:entryValues="@array/pref_hide_fullscreen_vals"/>
|
|
||||||
<CheckBoxPreference
|
<CheckBoxPreference
|
||||||
android:defaultValue="false"
|
android:defaultValue="false"
|
||||||
android:key="pref_force_desktop"
|
android:key="pref_force_desktop"
|
||||||
@ -50,7 +43,6 @@
|
|||||||
<PreferenceCategory
|
<PreferenceCategory
|
||||||
android:key="pref_mics"
|
android:key="pref_mics"
|
||||||
android:title="@string/pref_misc_cat">
|
android:title="@string/pref_misc_cat">
|
||||||
|
|
||||||
<PreferenceScreen
|
<PreferenceScreen
|
||||||
android:fragment="com.cradle.iitc_mobile.fragments.PluginsFragment"
|
android:fragment="com.cradle.iitc_mobile.fragments.PluginsFragment"
|
||||||
android:key="pref_plugins"
|
android:key="pref_plugins"
|
||||||
@ -67,15 +59,15 @@
|
|||||||
android:summary="@string/pref_force_https_sum"
|
android:summary="@string/pref_force_https_sum"
|
||||||
android:title="@string/pref_force_https"/>
|
android:title="@string/pref_force_https"/>
|
||||||
<CheckBoxPreference
|
<CheckBoxPreference
|
||||||
|
android:defaultValue="false"
|
||||||
android:key="pref_external_storage"
|
android:key="pref_external_storage"
|
||||||
android:title="@string/pref_external_storage"
|
|
||||||
android:summary="@string/pref_external_storage_sum"
|
android:summary="@string/pref_external_storage_sum"
|
||||||
android:defaultValue="false" />
|
android:title="@string/pref_external_storage"/>
|
||||||
<CheckBoxPreference
|
<CheckBoxPreference
|
||||||
android:key="pref_press_twice_to_exit"
|
android:defaultValue="false"
|
||||||
android:title="@string/pref_press_twice_to_exit"
|
android:key="pref_press_twice_to_exit"
|
||||||
android:summary="@string/pref_press_twice_to_exit_sum"
|
android:summary="@string/pref_press_twice_to_exit_sum"
|
||||||
android:defaultValue="false" />
|
android:title="@string/pref_press_twice_to_exit"/>
|
||||||
</PreferenceCategory>
|
</PreferenceCategory>
|
||||||
<PreferenceCategory
|
<PreferenceCategory
|
||||||
android:key="pref_developer_options"
|
android:key="pref_developer_options"
|
||||||
|
@ -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);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -88,8 +88,7 @@ public class IITC_Mobile extends Activity implements OnSharedPreferenceChangeLis
|
|||||||
mIitcWebView.updateFullscreenStatus();
|
mIitcWebView.updateFullscreenStatus();
|
||||||
|
|
||||||
mUserLocation = new IITC_UserLocation(this);
|
mUserLocation = new IITC_UserLocation(this);
|
||||||
mUserLocation.setLocationEnabled(mSharedPrefs.getBoolean("pref_user_loc", false));
|
mUserLocation.setLocationMode(Integer.parseInt(mSharedPrefs.getString("pref_user_location_mode", "0")));
|
||||||
mUserLocation.setSensorEnabled(mSharedPrefs.getBoolean("pref_user_loc_sensor", true));
|
|
||||||
|
|
||||||
// pass ActionBar to helper because we deprecated getActionBar
|
// pass ActionBar to helper because we deprecated getActionBar
|
||||||
mNavigationHelper = new IITC_NavigationHelper(this, super.getActionBar());
|
mNavigationHelper = new IITC_NavigationHelper(this, super.getActionBar());
|
||||||
@ -111,10 +110,11 @@ public class IITC_Mobile extends Activity implements OnSharedPreferenceChangeLis
|
|||||||
if (key.equals("pref_force_desktop")) {
|
if (key.equals("pref_force_desktop")) {
|
||||||
mDesktopMode = sharedPreferences.getBoolean("pref_force_desktop", false);
|
mDesktopMode = sharedPreferences.getBoolean("pref_force_desktop", false);
|
||||||
mNavigationHelper.onPrefChanged();
|
mNavigationHelper.onPrefChanged();
|
||||||
} else if (key.equals("pref_user_loc")) {
|
} else if (key.equals("pref_user_location_mode")) {
|
||||||
mUserLocation.setLocationEnabled(sharedPreferences.getBoolean("pref_user_loc", false));
|
int mode = Integer.parseInt(mSharedPrefs.getString("pref_user_location_mode", "0"));
|
||||||
} else if (key.equals("pref_user_loc_sensor")) {
|
if (mUserLocation.setLocationMode(mode))
|
||||||
mUserLocation.setSensorEnabled(sharedPreferences.getBoolean("pref_user_loc_sensor", true));
|
mReloadNeeded = true;
|
||||||
|
return;
|
||||||
} else if (key.equals("pref_fullscreen")) {
|
} else if (key.equals("pref_fullscreen")) {
|
||||||
mIitcWebView.updateFullscreenStatus();
|
mIitcWebView.updateFullscreenStatus();
|
||||||
mNavigationHelper.onPrefChanged();
|
mNavigationHelper.onPrefChanged();
|
||||||
@ -247,43 +247,41 @@ public class IITC_Mobile extends Activity implements OnSharedPreferenceChangeLis
|
|||||||
protected void onStart() {
|
protected void onStart() {
|
||||||
super.onStart();
|
super.onStart();
|
||||||
|
|
||||||
// enough idle...let's do some work
|
|
||||||
Log.d("iitcm", "resuming...reset idleTimer");
|
|
||||||
mUserLocation.onStart();
|
|
||||||
|
|
||||||
if (mReloadNeeded) {
|
if (mReloadNeeded) {
|
||||||
Log.d("iitcm", "preference had changed...reload needed");
|
Log.d("iitcm", "preference had changed...reload needed");
|
||||||
reloadIITC();
|
reloadIITC();
|
||||||
} else {
|
} else {
|
||||||
// iitc is not fully booted...timer will be reset by the script itself
|
// iitc is not fully booted...timer will be reset by the script itself
|
||||||
if (findViewById(R.id.imageLoading).getVisibility() == View.GONE) {
|
if (findViewById(R.id.imageLoading).getVisibility() == View.GONE) {
|
||||||
|
// enough idle...let's do some work
|
||||||
|
Log.d("iitcm", "resuming...reset idleTimer");
|
||||||
mIitcWebView.loadUrl("javascript: window.idleReset();");
|
mIitcWebView.loadUrl("javascript: window.idleReset();");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mUserLocation.onStart();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onResume() {
|
protected void onResume() {
|
||||||
|
super.onResume();
|
||||||
mIitcWebView.resumeTimers();
|
mIitcWebView.resumeTimers();
|
||||||
mIitcWebView.onResume();
|
mIitcWebView.onResume();
|
||||||
super.onResume();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPause() {
|
protected void onPause() {
|
||||||
|
super.onPause();
|
||||||
mIitcWebView.pauseTimers();
|
mIitcWebView.pauseTimers();
|
||||||
mIitcWebView.onPause();
|
mIitcWebView.onPause();
|
||||||
super.onPause();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onStop() {
|
protected void onStop() {
|
||||||
|
super.onStop();
|
||||||
Log.d("iitcm", "stopping iitcm");
|
Log.d("iitcm", "stopping iitcm");
|
||||||
mIitcWebView.loadUrl("javascript: window.idleSet();");
|
mIitcWebView.loadUrl("javascript: window.idleSet();");
|
||||||
|
|
||||||
mUserLocation.onStop();
|
mUserLocation.onStop();
|
||||||
|
|
||||||
super.onStop();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -402,18 +400,32 @@ public class IITC_Mobile extends Activity implements OnSharedPreferenceChangeLis
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onPrepareOptionsMenu(Menu menu) {
|
public boolean onPrepareOptionsMenu(Menu menu) {
|
||||||
if (mNavigationHelper != null) {
|
boolean visible = false;
|
||||||
boolean visible = !mNavigationHelper.isDrawerOpened();
|
if (mNavigationHelper != null)
|
||||||
|
visible = !mNavigationHelper.isDrawerOpened();
|
||||||
|
|
||||||
for (int i = 0; i < menu.size(); i++)
|
for (int i = 0; i < menu.size(); i++) {
|
||||||
if (menu.getItem(i).getItemId() != R.id.action_settings) {
|
MenuItem item = menu.getItem(i);
|
||||||
// clear cookies is part of the advanced menu
|
|
||||||
if (menu.getItem(i).getItemId() == R.id.menu_clear_cookies) {
|
switch (item.getItemId()) {
|
||||||
menu.getItem(i).setVisible(mAdvancedMenu & visible);
|
case R.id.action_settings:
|
||||||
} else {
|
item.setVisible(true);
|
||||||
menu.getItem(i).setVisible(visible);
|
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);
|
return super.onPrepareOptionsMenu(menu);
|
||||||
@ -475,6 +487,7 @@ public class IITC_Mobile extends Activity implements OnSharedPreferenceChangeLis
|
|||||||
public void reloadIITC() {
|
public void reloadIITC() {
|
||||||
mNavigationHelper.reset();
|
mNavigationHelper.reset();
|
||||||
mMapSettings.reset();
|
mMapSettings.reset();
|
||||||
|
mUserLocation.reset();
|
||||||
mBackStack.clear();
|
mBackStack.clear();
|
||||||
// iitc starts on map after reload
|
// iitc starts on map after reload
|
||||||
mCurrentPane = Pane.MAP;
|
mCurrentPane = Pane.MAP;
|
||||||
@ -635,4 +648,8 @@ public class IITC_Mobile extends Activity implements OnSharedPreferenceChangeLis
|
|||||||
public IITC_MapSettings getMapSettings() {
|
public IITC_MapSettings getMapSettings() {
|
||||||
return mMapSettings;
|
return mMapSettings;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public IITC_UserLocation getUserLocation() {
|
||||||
|
return mUserLocation;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,18 +12,20 @@ import android.os.Bundle;
|
|||||||
import android.view.Surface;
|
import android.view.Surface;
|
||||||
|
|
||||||
public class IITC_UserLocation implements LocationListener, SensorEventListener {
|
public class IITC_UserLocation implements LocationListener, SensorEventListener {
|
||||||
private static final double SENSOR_DELAY_USER = 100*1e6;
|
private static final double SENSOR_DELAY_USER = 100 * 1e6; // 100 milliseconds
|
||||||
private boolean mLocationEnabled = false;
|
private int mMode = 0;
|
||||||
private boolean mSensorEnabled = true;
|
private boolean mRunning = false;
|
||||||
|
private boolean mLocationRegistered = false;
|
||||||
|
private boolean mOrientationRegistered = false;
|
||||||
private long mLastUpdate = 0;
|
private long mLastUpdate = 0;
|
||||||
private IITC_Mobile mIitc;
|
private IITC_Mobile mIitc;
|
||||||
private Location mLastLocation = null;
|
private Location mLastLocation = null;
|
||||||
private LocationManager mLocationManager;
|
private LocationManager mLocationManager;
|
||||||
private boolean mRegistered = false;
|
|
||||||
private boolean mRunning = false;
|
|
||||||
private Sensor mSensorAccelerometer, mSensorMagnetometer;
|
private Sensor mSensorAccelerometer, mSensorMagnetometer;
|
||||||
private SensorManager mSensorManager = null;
|
private SensorManager mSensorManager = null;
|
||||||
float[] mValuesGravity = null, mValuesGeomagnetic = null;
|
private float[] mValuesGravity = null, mValuesGeomagnetic = null;
|
||||||
|
private double mOrientation = 0;
|
||||||
|
private boolean mFollowing = false;
|
||||||
|
|
||||||
public IITC_UserLocation(IITC_Mobile iitc) {
|
public IITC_UserLocation(IITC_Mobile iitc) {
|
||||||
mIitc = iitc;
|
mIitc = iitc;
|
||||||
@ -35,54 +37,69 @@ public class IITC_UserLocation implements LocationListener, SensorEventListener
|
|||||||
mSensorMagnetometer = mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD);
|
mSensorMagnetometer = mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void registerListeners() {
|
private void setOrientation(Double orientation) {
|
||||||
if (mRegistered) return;
|
// we have a transition defined for the rotation
|
||||||
mRegistered = true;
|
// changes to the orientation should always be less than 180°
|
||||||
|
|
||||||
try {
|
if (orientation != null) {
|
||||||
mLocationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, this);
|
while (orientation < mOrientation - 180)
|
||||||
} catch (IllegalArgumentException e) {
|
orientation += 360;
|
||||||
// if the given provider doesn't exist
|
while (orientation > mOrientation + 180)
|
||||||
e.printStackTrace();
|
orientation -= 360;
|
||||||
}
|
mOrientation = orientation;
|
||||||
try {
|
} else {
|
||||||
mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);
|
mOrientation = 0;
|
||||||
} catch (IllegalArgumentException e) {
|
|
||||||
// if the given provider doesn't exist
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mSensorAccelerometer != null && mSensorMagnetometer != null && mSensorEnabled) {
|
|
||||||
mSensorManager.registerListener(this, mSensorAccelerometer, SensorManager.SENSOR_DELAY_NORMAL);
|
|
||||||
mSensorManager.registerListener(this, mSensorMagnetometer, SensorManager.SENSOR_DELAY_NORMAL);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void unregisterListeners() {
|
|
||||||
if (!mRegistered) return;
|
|
||||||
mRegistered = false;
|
|
||||||
|
|
||||||
mLocationManager.removeUpdates(this);
|
|
||||||
|
|
||||||
if (mSensorAccelerometer != null && mSensorMagnetometer != null && mSensorEnabled) {
|
|
||||||
mSensorManager.unregisterListener(this, mSensorAccelerometer);
|
|
||||||
mSensorManager.unregisterListener(this, mSensorMagnetometer);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mIitc.getWebView().loadJS("if(window.plugin && window.plugin.userLocation)"
|
||||||
|
+ "window.plugin.userLocation.onOrientationChange(" + String.valueOf(orientation) + ");");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateListeners() {
|
private void updateListeners() {
|
||||||
if (mRunning && mLocationEnabled)
|
boolean useLocation = mRunning && mMode != 0;
|
||||||
registerListeners();
|
boolean useOrientation = mRunning && mMode == 2;
|
||||||
else
|
|
||||||
unregisterListeners();
|
if (useLocation && !mLocationRegistered) {
|
||||||
|
try {
|
||||||
|
mLocationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, this);
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
// if the given provider doesn't exist
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
// if the given provider doesn't exist
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
mLocationRegistered = true;
|
||||||
|
}
|
||||||
|
if (!useLocation && mLocationRegistered) {
|
||||||
|
mLocationManager.removeUpdates(this);
|
||||||
|
mLocationRegistered = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (useOrientation && !mOrientationRegistered && mSensorAccelerometer != null && mSensorMagnetometer != null) {
|
||||||
|
mSensorManager.registerListener(this, mSensorAccelerometer, SensorManager.SENSOR_DELAY_NORMAL);
|
||||||
|
mSensorManager.registerListener(this, mSensorMagnetometer, SensorManager.SENSOR_DELAY_NORMAL);
|
||||||
|
mOrientationRegistered = true;
|
||||||
|
}
|
||||||
|
if (!useOrientation && mOrientationRegistered && mSensorAccelerometer != null && mSensorMagnetometer != null) {
|
||||||
|
mSensorManager.unregisterListener(this, mSensorAccelerometer);
|
||||||
|
mSensorManager.unregisterListener(this, mSensorMagnetometer);
|
||||||
|
mOrientationRegistered = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasCurrentLocation() {
|
public boolean hasCurrentLocation() {
|
||||||
if (!mRegistered) return false;
|
if (!mLocationRegistered) return false;
|
||||||
return mLastLocation != null;
|
return mLastLocation != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isFollowing() {
|
||||||
|
return mFollowing;
|
||||||
|
}
|
||||||
|
|
||||||
public void locate() {
|
public void locate() {
|
||||||
// do not touch the javascript while iitc boots
|
// do not touch the javascript while iitc boots
|
||||||
if (mIitc.isLoading()) return;
|
if (mIitc.isLoading()) return;
|
||||||
@ -98,6 +115,11 @@ public class IITC_UserLocation implements LocationListener, SensorEventListener
|
|||||||
public void onStart() {
|
public void onStart() {
|
||||||
mRunning = true;
|
mRunning = true;
|
||||||
updateListeners();
|
updateListeners();
|
||||||
|
|
||||||
|
// in case we just switched from loc+sensor to loc-only, let javascript know
|
||||||
|
if (mMode == 1) {
|
||||||
|
setOrientation(null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onStop() {
|
public void onStop() {
|
||||||
@ -105,18 +127,87 @@ public class IITC_UserLocation implements LocationListener, SensorEventListener
|
|||||||
updateListeners();
|
updateListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLocationEnabled(boolean enabled) {
|
public void reset() {
|
||||||
if (enabled == mLocationEnabled) return;
|
setFollowMode(false);
|
||||||
|
|
||||||
mLocationEnabled = enabled;
|
|
||||||
updateListeners();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSensorEnabled(boolean enabled) {
|
public void setFollowMode(boolean follow) {
|
||||||
if (enabled == mSensorEnabled) return;
|
mFollowing = follow;
|
||||||
|
mIitc.invalidateOptionsMenu();
|
||||||
|
}
|
||||||
|
|
||||||
mSensorEnabled = enabled;
|
private static final int TWO_MINUTES = 1000 * 60 * 2;
|
||||||
updateListeners();
|
|
||||||
|
/**
|
||||||
|
* Determines whether one Location reading is better than the current Location fix
|
||||||
|
* @param location The new Location that you want to evaluate
|
||||||
|
* @param currentBestLocation The current Location fix, to which you want to compare the new one
|
||||||
|
*
|
||||||
|
* code copied from http://developer.android.com/guide/topics/location/strategies.html#BestEstimate
|
||||||
|
*/
|
||||||
|
protected boolean isBetterLocation(Location location, Location currentBestLocation) {
|
||||||
|
if (currentBestLocation == null) {
|
||||||
|
// A new location is always better than no location
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check whether the new location fix is newer or older
|
||||||
|
long timeDelta = location.getTime() - currentBestLocation.getTime();
|
||||||
|
boolean isSignificantlyNewer = timeDelta > TWO_MINUTES;
|
||||||
|
boolean isSignificantlyOlder = timeDelta < -TWO_MINUTES;
|
||||||
|
boolean isNewer = timeDelta > 0;
|
||||||
|
|
||||||
|
// If it's been more than two minutes since the current location, use the new location
|
||||||
|
// because the user has likely moved
|
||||||
|
if (isSignificantlyNewer) {
|
||||||
|
return true;
|
||||||
|
// If the new location is more than two minutes older, it must be worse
|
||||||
|
} else if (isSignificantlyOlder) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check whether the new location fix is more or less accurate
|
||||||
|
int accuracyDelta = (int) (location.getAccuracy() - currentBestLocation.getAccuracy());
|
||||||
|
boolean isLessAccurate = accuracyDelta > 0;
|
||||||
|
boolean isMoreAccurate = accuracyDelta < 0;
|
||||||
|
boolean isSignificantlyLessAccurate = accuracyDelta > 100;
|
||||||
|
|
||||||
|
// Check if the old and new location are from the same provider
|
||||||
|
boolean isFromSameProvider = isSameProvider(location.getProvider(),
|
||||||
|
currentBestLocation.getProvider());
|
||||||
|
|
||||||
|
// Determine location quality using a combination of timeliness and accuracy
|
||||||
|
if (isMoreAccurate) {
|
||||||
|
return true;
|
||||||
|
} else if (isNewer && !isLessAccurate) {
|
||||||
|
return true;
|
||||||
|
} else if (isNewer && !isSignificantlyLessAccurate && isFromSameProvider) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Checks whether two providers are the same
|
||||||
|
private boolean isSameProvider(String provider1, String provider2) {
|
||||||
|
if (provider1 == null) {
|
||||||
|
return provider2 == null;
|
||||||
|
}
|
||||||
|
return provider1.equals(provider2);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* set the location mode to use. Available modes:
|
||||||
|
* 0: don't show user's position
|
||||||
|
* 1: show user's position
|
||||||
|
* 2: show user's position and orientation
|
||||||
|
*
|
||||||
|
* @return whether a reload is needed to reflect the changes made to the preferences
|
||||||
|
*/
|
||||||
|
public boolean setLocationMode(int mode) {
|
||||||
|
boolean needsReload = (mode == 0 && mMode != 0) || (mode != 0 && mMode == 0);
|
||||||
|
mMode = mode;
|
||||||
|
|
||||||
|
return needsReload;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
@ -125,10 +216,9 @@ public class IITC_UserLocation implements LocationListener, SensorEventListener
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onLocationChanged(Location location) {
|
public void onLocationChanged(Location location) {
|
||||||
mLastLocation = location;
|
if (!isBetterLocation(location, mLastLocation)) return;
|
||||||
|
|
||||||
// throw away all positions with accuracy > 100 meters should avoid gps glitches
|
mLastLocation = location;
|
||||||
if (location.getAccuracy() > 100) return;
|
|
||||||
|
|
||||||
// do not touch the javascript while iitc boots
|
// do not touch the javascript while iitc boots
|
||||||
if (mIitc.isLoading()) return;
|
if (mIitc.isLoading()) return;
|
||||||
@ -140,12 +230,10 @@ public class IITC_UserLocation implements LocationListener, SensorEventListener
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onProviderDisabled(String provider) {
|
public void onProviderDisabled(String provider) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onProviderEnabled(String provider) {
|
public void onProviderEnabled(String provider) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -165,15 +253,15 @@ public class IITC_UserLocation implements LocationListener, SensorEventListener
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSensorChanged(SensorEvent event) {
|
public void onSensorChanged(SensorEvent event) {
|
||||||
// save some battery 10 updates per second should be enough
|
|
||||||
if ((event.timestamp - mLastUpdate) < SENSOR_DELAY_USER) return;
|
|
||||||
mLastUpdate = event.timestamp;
|
|
||||||
|
|
||||||
if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER)
|
if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER)
|
||||||
mValuesGravity = event.values;
|
mValuesGravity = event.values;
|
||||||
if (event.sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD)
|
if (event.sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD)
|
||||||
mValuesGeomagnetic = event.values;
|
mValuesGeomagnetic = event.values;
|
||||||
|
|
||||||
|
// save some battery, 10 updates per second should be enough
|
||||||
|
if ((event.timestamp - mLastUpdate) < SENSOR_DELAY_USER) return;
|
||||||
|
mLastUpdate = event.timestamp;
|
||||||
|
|
||||||
// do not touch the javascript while iitc boots
|
// do not touch the javascript while iitc boots
|
||||||
if (mIitc.isLoading()) return;
|
if (mIitc.isLoading()) return;
|
||||||
|
|
||||||
@ -202,8 +290,7 @@ public class IITC_UserLocation implements LocationListener, SensorEventListener
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
mIitc.getWebView().loadJS("if(window.plugin && window.plugin.userLocation)"
|
setOrientation(direction);
|
||||||
+ "window.plugin.userLocation.onOrientationChange(" + direction + ");");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// </interface SensorEventListener>
|
// </interface SensorEventListener>
|
||||||
|
@ -2,7 +2,6 @@ package com.cradle.iitc_mobile;
|
|||||||
|
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.annotation.TargetApi;
|
import android.annotation.TargetApi;
|
||||||
import android.app.Activity;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.net.ConnectivityManager;
|
import android.net.ConnectivityManager;
|
||||||
@ -13,9 +12,6 @@ import android.util.AttributeSet;
|
|||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.MotionEvent;
|
import android.view.MotionEvent;
|
||||||
import android.view.WindowManager;
|
import android.view.WindowManager;
|
||||||
import android.webkit.ConsoleMessage;
|
|
||||||
import android.webkit.GeolocationPermissions;
|
|
||||||
import android.webkit.WebChromeClient;
|
|
||||||
import android.webkit.WebSettings;
|
import android.webkit.WebSettings;
|
||||||
import android.webkit.WebView;
|
import android.webkit.WebView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
@ -70,17 +66,17 @@ public class IITC_WebView extends WebView {
|
|||||||
mNavHider = new Runnable() {
|
mNavHider = new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
if (isInFullscreen() && (getFullscreenStatus() & (FS_NAVBAR)) != 0) {
|
if (isInFullscreen() && (getFullscreenStatus() & (FS_NAVBAR)) != 0) {
|
||||||
int systemUiVisibility = SYSTEM_UI_FLAG_HIDE_NAVIGATION;
|
int systemUiVisibility = SYSTEM_UI_FLAG_HIDE_NAVIGATION;
|
||||||
// in immersive mode the user can interact with the app while the navbar is hidden
|
// in immersive mode the user can interact with the app while the navbar is hidden
|
||||||
// this mode is available since KitKat
|
// this mode is available since KitKat
|
||||||
// you can leave this mode by swiping down from the top of the screen. this does only work
|
// you can leave this mode by swiping down from the top of the screen. this does only work
|
||||||
// when the app is in total-fullscreen mode
|
// when the app is in total-fullscreen mode
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT && (mFullscreenStatus & FS_SYSBAR) != 0) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT && (mFullscreenStatus & FS_SYSBAR) != 0) {
|
||||||
systemUiVisibility |= SYSTEM_UI_FLAG_IMMERSIVE;
|
systemUiVisibility |= SYSTEM_UI_FLAG_IMMERSIVE;
|
||||||
|
}
|
||||||
|
setSystemUiVisibility(systemUiVisibility);
|
||||||
}
|
}
|
||||||
setSystemUiVisibility(systemUiVisibility);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -131,7 +127,7 @@ public class IITC_WebView extends WebView {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// disable splash screen if a http error code is responded
|
// disable splash screen if a http error code is responded
|
||||||
new CheckHttpResponse(mJsInterface, mIitc).execute(url);
|
new CheckHttpResponse(mIitc).execute(url);
|
||||||
Log.d("iitcm", "loading url: " + url);
|
Log.d("iitcm", "loading url: " + url);
|
||||||
super.loadUrl(url);
|
super.loadUrl(url);
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,10 @@
|
|||||||
package com.cradle.iitc_mobile.async;
|
package com.cradle.iitc_mobile.async;
|
||||||
|
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
import android.content.Context;
|
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import com.cradle.iitc_mobile.IITC_JSInterface;
|
|
||||||
import com.cradle.iitc_mobile.IITC_Mobile;
|
import com.cradle.iitc_mobile.IITC_Mobile;
|
||||||
|
|
||||||
import org.apache.http.HttpResponse;
|
import org.apache.http.HttpResponse;
|
||||||
@ -24,12 +22,10 @@ import java.io.IOException;
|
|||||||
*/
|
*/
|
||||||
public class CheckHttpResponse extends AsyncTask<String, Void, Boolean> {
|
public class CheckHttpResponse extends AsyncTask<String, Void, Boolean> {
|
||||||
|
|
||||||
private final IITC_JSInterface mJsInterface;
|
private final IITC_Mobile mIitc;
|
||||||
private final Context mContext;
|
|
||||||
|
|
||||||
public CheckHttpResponse(IITC_JSInterface jsInterface, Context c) {
|
public CheckHttpResponse(IITC_Mobile iitc) {
|
||||||
mContext = c;
|
mIitc = iitc;
|
||||||
mJsInterface = jsInterface;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -43,11 +39,10 @@ public class CheckHttpResponse extends AsyncTask<String, Void, Boolean> {
|
|||||||
int code = response.getStatusLine().getStatusCode();
|
int code = response.getStatusLine().getStatusCode();
|
||||||
if (code != HttpStatus.SC_OK) {
|
if (code != HttpStatus.SC_OK) {
|
||||||
Log.d("iitcm", "received error code: " + code);
|
Log.d("iitcm", "received error code: " + code);
|
||||||
final IITC_Mobile iitc = (IITC_Mobile) mContext;
|
mIitc.runOnUiThread(new Runnable() {
|
||||||
iitc.runOnUiThread(new Runnable() {
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
iitc.setLoadingState(false);
|
mIitc.setLoadingState(false);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
// TODO: remove when google login issue is fixed
|
// TODO: remove when google login issue is fixed
|
||||||
@ -68,7 +63,7 @@ public class CheckHttpResponse extends AsyncTask<String, Void, Boolean> {
|
|||||||
protected void onPostExecute(Boolean aBoolean) {
|
protected void onPostExecute(Boolean aBoolean) {
|
||||||
if (aBoolean) {
|
if (aBoolean) {
|
||||||
Log.d("iitcm", "google auth error, redirecting to work-around page");
|
Log.d("iitcm", "google auth error, redirecting to work-around page");
|
||||||
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(mContext);
|
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(mIitc);
|
||||||
|
|
||||||
// set title
|
// set title
|
||||||
alertDialogBuilder.setTitle("LOGIN FAILED!");
|
alertDialogBuilder.setTitle("LOGIN FAILED!");
|
||||||
@ -86,8 +81,7 @@ public class CheckHttpResponse extends AsyncTask<String, Void, Boolean> {
|
|||||||
@Override
|
@Override
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
dialog.cancel();
|
dialog.cancel();
|
||||||
IITC_Mobile iitc_mobile = (IITC_Mobile) mContext;
|
mIitc.reloadIITC();
|
||||||
iitc_mobile.reloadIITC();
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@ import android.content.pm.PackageManager;
|
|||||||
import android.content.pm.PackageManager.NameNotFoundException;
|
import android.content.pm.PackageManager.NameNotFoundException;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.preference.EditTextPreference;
|
import android.preference.EditTextPreference;
|
||||||
|
import android.preference.ListPreference;
|
||||||
import android.preference.Preference;
|
import android.preference.Preference;
|
||||||
import android.preference.Preference.OnPreferenceChangeListener;
|
import android.preference.Preference.OnPreferenceChangeListener;
|
||||||
import android.preference.PreferenceFragment;
|
import android.preference.PreferenceFragment;
|
||||||
@ -54,6 +55,20 @@ public class MainSettings extends PreferenceFragment {
|
|||||||
// first init of summary
|
// first init of summary
|
||||||
String pref_iitc_source_sum = getString(R.string.pref_select_iitc_sum) + " " + pref_iitc_source.getText();
|
String pref_iitc_source_sum = getString(R.string.pref_select_iitc_sum) + " " + pref_iitc_source.getText();
|
||||||
pref_iitc_source.setSummary(pref_iitc_source_sum);
|
pref_iitc_source.setSummary(pref_iitc_source_sum);
|
||||||
|
|
||||||
|
final ListPreference pref_user_location_mode = (ListPreference) findPreference("pref_user_location_mode");
|
||||||
|
pref_user_location_mode.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
|
||||||
|
@Override
|
||||||
|
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||||
|
int mode = Integer.parseInt((String) newValue);
|
||||||
|
preference.setSummary(getResources().getStringArray(R.array.pref_user_location_titles)[mode]);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
String value = getPreferenceManager().getSharedPreferences().getString("pref_user_location_mode", "0");
|
||||||
|
int mode = Integer.parseInt(value);
|
||||||
|
pref_user_location_mode.setSummary(getResources().getStringArray(R.array.pref_user_location_titles)[mode]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// we want a home button + HomeAsUpEnabled in nested preferences
|
// we want a home button + HomeAsUpEnabled in nested preferences
|
||||||
@ -63,8 +78,7 @@ public class MainSettings extends PreferenceFragment {
|
|||||||
@Override
|
@Override
|
||||||
public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
|
public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
|
||||||
if (preference.getTitle().toString().equals(getString(R.string.pref_advanced_options))
|
if (preference.getTitle().toString().equals(getString(R.string.pref_advanced_options))
|
||||||
|| preference.getTitle().toString().equals(getString(R.string.pref_about_title))
|
|| preference.getTitle().toString().equals(getString(R.string.pref_about_title))) {
|
||||||
|| preference.getTitle().toString().equals(getString(R.string.pref_user_loc_screen))) {
|
|
||||||
initializeActionBar((PreferenceScreen) preference);
|
initializeActionBar((PreferenceScreen) preference);
|
||||||
}
|
}
|
||||||
return super.onPreferenceTreeClick(preferenceScreen, preference);
|
return super.onPreferenceTreeClick(preferenceScreen, preference);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user