Skip to content

Commit 11f8fda

Browse files
committed
Tango: fixed switch preferences changing on scrolling on Jelly bean (https://issuetracker.google.com/issues/36941388#comment4)
1 parent 81fe104 commit 11f8fda

File tree

3 files changed

+97
-15
lines changed

3 files changed

+97
-15
lines changed

app/android/AndroidManifest.xml.in

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<!-- BEGIN_INCLUDE(manifest) -->
33
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
44
package="com.introlab.rtabmap"
5-
android:versionCode="57"
5+
android:versionCode="58"
66
android:versionName="@RTABMAP_VERSION@">
77

88
<uses-permission android:name="android.permission.CAMERA" />

app/android/res/layout/activity_settings.xml

+14-14
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,12 @@
5858
android:entries="@array/pref_background_color_keys"
5959
android:entryValues="@array/pref_background_color_values"
6060
android:defaultValue="@string/pref_default_background_color"/>
61-
<SwitchPreference
61+
<com.introlab.rtabmap.CustomSwitchPreference
6262
android:key="@string/pref_key_blending"
6363
android:title="@string/pref_title_blending"
6464
android:summary="@string/pref_summary_blending"
6565
android:defaultValue="@string/pref_default_blending"/>
66-
<SwitchPreference
66+
<com.introlab.rtabmap.CustomSwitchPreference
6767
android:key="@string/pref_key_nodes_filtering"
6868
android:title="@string/pref_title_nodes_filtering"
6969
android:summary="@string/pref_summary_nodes_filtering"
@@ -79,22 +79,22 @@
7979
android:summary="@string/pref_summary_mapping"
8080
android:persistent="false">
8181

82-
<SwitchPreference
82+
<com.introlab.rtabmap.CustomSwitchPreference
8383
android:key="@string/pref_key_append"
8484
android:title="@string/pref_title_append"
8585
android:summary="@string/pref_summary_append"
8686
android:defaultValue="@string/pref_default_append"/>
87-
<SwitchPreference
87+
<com.introlab.rtabmap.CustomSwitchPreference
8888
android:key="@string/pref_key_resolution"
8989
android:title="@string/pref_title_resolution"
9090
android:summary="@string/pref_summary_resolution"
9191
android:defaultValue="@string/pref_default_resolution"/>
92-
<SwitchPreference
92+
<com.introlab.rtabmap.CustomSwitchPreference
9393
android:key="@string/pref_key_smoothing"
9494
android:title="@string/pref_title_smoothing"
9595
android:summary="@string/pref_summary_smoothing"
9696
android:defaultValue="@string/pref_default_smoothing"/>
97-
<SwitchPreference
97+
<com.introlab.rtabmap.CustomSwitchPreference
9898
android:key="@string/pref_key_fisheye"
9999
android:title="@string/pref_title_fisheye"
100100
android:summary="@string/pref_summary_fisheye"
@@ -179,30 +179,30 @@
179179
android:entries="@array/pref_optimizer_keys"
180180
android:entryValues="@array/pref_optimizer_values"
181181
android:defaultValue="@string/pref_default_optimizer"/>
182-
<SwitchPreference
182+
<com.introlab.rtabmap.CustomSwitchPreference
183183
android:key="@string/pref_key_optimize_end"
184184
android:title="@string/pref_title_optimize_end"
185185
android:summary="@string/pref_summary_optimize_end"
186186
android:defaultValue="@string/pref_default_optimize_end"/>
187187
</PreferenceCategory>
188188
<PreferenceCategory
189189
android:title="@string/pref_title_mapping_database">
190-
<SwitchPreference
190+
<com.introlab.rtabmap.CustomSwitchPreference
191191
android:key="@string/pref_key_keep_all_db"
192192
android:title="@string/pref_title_keep_all_db"
193193
android:summary="@string/pref_summary_keep_all_db"
194194
android:defaultValue="@string/pref_default_keep_all_db"/>
195-
<SwitchPreference
195+
<com.introlab.rtabmap.CustomSwitchPreference
196196
android:key="@string/pref_key_raw_scan_saved"
197197
android:title="@string/pref_title_raw_scan_saved"
198198
android:summary="@string/pref_summary_raw_scan_saved"
199199
android:defaultValue="@string/pref_default_raw_scan_saved"/>
200-
<SwitchPreference
200+
<com.introlab.rtabmap.CustomSwitchPreference
201201
android:key="@string/pref_key_gps_saved"
202202
android:title="@string/pref_title_gps_saved"
203203
android:summary="@string/pref_summary_gps_saved"
204204
android:defaultValue="@string/pref_default_gps_saved"/>
205-
<SwitchPreference
205+
<com.introlab.rtabmap.CustomSwitchPreference
206206
android:key="@string/pref_key_db_in_memory"
207207
android:title="@string/pref_title_db_in_memory"
208208
android:summary="@string/pref_summary_db_in_memory"
@@ -264,7 +264,7 @@
264264
android:entryValues="@array/pref_min_texture_cluster_size_values"
265265
android:defaultValue="@string/pref_default_min_texture_cluster_size"/>
266266

267-
<SwitchPreference
267+
<com.introlab.rtabmap.CustomSwitchPreference
268268
android:key="@string/pref_key_block_render"
269269
android:title="@string/pref_title_block_render"
270270
android:summary="@string/pref_summary_block_render"
@@ -291,7 +291,7 @@
291291
android:entryValues="@array/pref_opt_color_radius_values"
292292
android:defaultValue="@string/pref_default_opt_color_radius"/>
293293

294-
<SwitchPreference
294+
<com.introlab.rtabmap.CustomSwitchPreference
295295
android:key="@string/pref_key_opt_clean_white"
296296
android:title="@string/pref_title_opt_clean_white"
297297
android:summary="@string/pref_summary_opt_clean_white"
@@ -321,7 +321,7 @@
321321
android:entries="@array/pref_cluster_ratio_keys"
322322
android:entryValues="@array/pref_cluster_ratio_values"
323323
android:defaultValue="@string/pref_default_cluster_ratio"/>
324-
<SwitchPreference
324+
<com.introlab.rtabmap.CustomSwitchPreference
325325
android:key="@string/pref_key_notification_sound"
326326
android:title="@string/pref_title_notification_sound"
327327
android:summary="@string/pref_summary_notification_sound"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
package com.introlab.rtabmap;
2+
3+
import android.content.Context;
4+
import android.preference.SwitchPreference;
5+
import android.util.AttributeSet;
6+
import android.view.View;
7+
import android.view.ViewGroup;
8+
import android.widget.Switch;
9+
10+
/**
11+
*
12+
* @author mathieu
13+
* Bug fix of switch preferences changing states
14+
* when scrolling on Jelly Bean:
15+
* https://issuetracker.google.com/issues/36941388#comment4
16+
*/
17+
18+
public class CustomSwitchPreference extends SwitchPreference {
19+
20+
/**
21+
* Construct a new SwitchPreference with the given style options.
22+
*
23+
* @param context The Context that will style this preference
24+
* @param attrs Style attributes that differ from the default
25+
* @param defStyle Theme attribute defining the default style options
26+
*/
27+
public CustomSwitchPreference(Context context, AttributeSet attrs, int defStyle) {
28+
super(context, attrs, defStyle);
29+
}
30+
31+
/**
32+
* Construct a new SwitchPreference with the given style options.
33+
*
34+
* @param context The Context that will style this preference
35+
* @param attrs Style attributes that differ from the default
36+
*/
37+
public CustomSwitchPreference(Context context, AttributeSet attrs) {
38+
super(context, attrs);
39+
}
40+
41+
/**
42+
* Construct a new SwitchPreference with default style options.
43+
*
44+
* @param context The Context that will style this preference
45+
*/
46+
public CustomSwitchPreference(Context context) {
47+
super(context, null);
48+
}
49+
50+
@Override
51+
protected void onBindView(View view) {
52+
// Clean listener before invoke SwitchPreference.onBindView
53+
ViewGroup viewGroup= (ViewGroup)view;
54+
clearListenerInViewGroup(viewGroup);
55+
super.onBindView(view);
56+
}
57+
58+
/**
59+
* Clear listener in Switch for specify ViewGroup.
60+
*
61+
* @param viewGroup The ViewGroup that will need to clear the listener.
62+
*/
63+
private void clearListenerInViewGroup(ViewGroup viewGroup) {
64+
if (null == viewGroup) {
65+
return;
66+
}
67+
68+
int count = viewGroup.getChildCount();
69+
for(int n = 0; n < count; ++n) {
70+
View childView = viewGroup.getChildAt(n);
71+
if(childView instanceof Switch) {
72+
final Switch switchView = (Switch) childView;
73+
switchView.setOnCheckedChangeListener(null);
74+
return;
75+
} else if (childView instanceof ViewGroup){
76+
ViewGroup childGroup = (ViewGroup)childView;
77+
clearListenerInViewGroup(childGroup);
78+
}
79+
}
80+
}
81+
82+
}

0 commit comments

Comments
 (0)