diff options
Diffstat (limited to 'org.fox.ttrss/src/main/java')
-rw-r--r-- | org.fox.ttrss/src/main/java/org/fox/ttrss/util/LessBrokenSwitchPreference.java | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/org.fox.ttrss/src/main/java/org/fox/ttrss/util/LessBrokenSwitchPreference.java b/org.fox.ttrss/src/main/java/org/fox/ttrss/util/LessBrokenSwitchPreference.java new file mode 100644 index 00000000..df116064 --- /dev/null +++ b/org.fox.ttrss/src/main/java/org/fox/ttrss/util/LessBrokenSwitchPreference.java @@ -0,0 +1,77 @@ +package org.fox.ttrss.util; + +// android is shit garbage +// https://code.google.com/p/android/issues/detail?id=26194 + +import android.content.Context; +import android.preference.SwitchPreference; +import android.util.AttributeSet; +import android.view.View; +import android.view.ViewGroup; +import android.widget.Switch; + +public class LessBrokenSwitchPreference extends SwitchPreference { + + /** + * Construct a new SwitchPreference with the given style options. + * + * @param context The Context that will style this preference + * @param attrs Style attributes that differ from the default + * @param defStyle Theme attribute defining the default style options + */ + public LessBrokenSwitchPreference(Context context, AttributeSet attrs, int defStyle) { + super(context, attrs, defStyle); + } + + /** + * Construct a new SwitchPreference with the given style options. + * + * @param context The Context that will style this preference + * @param attrs Style attributes that differ from the default + */ + public LessBrokenSwitchPreference(Context context, AttributeSet attrs) { + super(context, attrs); + } + + /** + * Construct a new SwitchPreference with default style options. + * + * @param context The Context that will style this preference + */ + public LessBrokenSwitchPreference(Context context) { + super(context, null); + } + + @Override + protected void onBindView(View view) { + // Clean listener before invoke SwitchPreference.onBindView + ViewGroup viewGroup= (ViewGroup)view; + clearListenerInViewGroup(viewGroup); + super.onBindView(view); + } + + /** + * Clear listener in Switch for specify ViewGroup. + * + * @param viewGroup The ViewGroup that will need to clear the listener. + */ + private void clearListenerInViewGroup(ViewGroup viewGroup) { + if (null == viewGroup) { + return; + } + + int count = viewGroup.getChildCount(); + for(int n = 0; n < count; ++n) { + View childView = viewGroup.getChildAt(n); + if(childView instanceof Switch) { + final Switch switchView = (Switch) childView; + switchView.setOnCheckedChangeListener(null); + return; + } else if (childView instanceof ViewGroup){ + ViewGroup childGroup = (ViewGroup)childView; + clearListenerInViewGroup(childGroup); + } + } + } + +}
\ No newline at end of file |