diff options
| author | 2011-07-23 19:38:47 -0700 | |
|---|---|---|
| committer | 2011-07-23 19:38:47 -0700 | |
| commit | 2182a3b6422f367d84384e25006ba201c4cd233b (patch) | |
| tree | 8717f69dab5abebb93f5d0a3df6d2f8373605cef | |
| parent | 5db7af968a5b57ad9f8e5a61534cafe46c344b85 (diff) | |
| parent | 5c3ea06a7a5558509545450ccc465d695bd1a2e6 (diff) | |
Merge "TwoStatePreference does not fire click events."
| -rw-r--r-- | core/java/android/preference/CheckBoxPreference.java | 4 | ||||
| -rw-r--r-- | core/java/android/preference/SwitchPreference.java | 4 | ||||
| -rw-r--r-- | core/java/android/preference/TwoStatePreference.java | 45 |
3 files changed, 28 insertions, 25 deletions
diff --git a/core/java/android/preference/CheckBoxPreference.java b/core/java/android/preference/CheckBoxPreference.java index 437e55332a81..166b21b66160 100644 --- a/core/java/android/preference/CheckBoxPreference.java +++ b/core/java/android/preference/CheckBoxPreference.java @@ -61,8 +61,8 @@ public class CheckBoxPreference extends TwoStatePreference { View checkboxView = view.findViewById(com.android.internal.R.id.checkbox); if (checkboxView != null && checkboxView instanceof Checkable) { ((Checkable) checkboxView).setChecked(mChecked); - - sendAccessibilityEventForView(checkboxView); + // Post this so this view is bound and attached when firing the event. + postSendAccessibilityEventForView(checkboxView); } syncSummaryView(view); diff --git a/core/java/android/preference/SwitchPreference.java b/core/java/android/preference/SwitchPreference.java index f681526a3ce4..3dbd5229cb83 100644 --- a/core/java/android/preference/SwitchPreference.java +++ b/core/java/android/preference/SwitchPreference.java @@ -102,8 +102,8 @@ public class SwitchPreference extends TwoStatePreference { View checkableView = view.findViewById(com.android.internal.R.id.switchWidget); if (checkableView != null && checkableView instanceof Checkable) { ((Checkable) checkableView).setChecked(mChecked); - - sendAccessibilityEventForView(checkableView); + // Post this so this view is bound and attached when firing the event. + postSendAccessibilityEventForView(checkableView); if (checkableView instanceof Switch) { final Switch switchView = (Switch) checkableView; diff --git a/core/java/android/preference/TwoStatePreference.java b/core/java/android/preference/TwoStatePreference.java index 8e21c4c493a5..55ef108e2932 100644 --- a/core/java/android/preference/TwoStatePreference.java +++ b/core/java/android/preference/TwoStatePreference.java @@ -16,7 +16,6 @@ package android.preference; -import android.app.Service; import android.content.Context; import android.content.SharedPreferences; import android.content.res.TypedArray; @@ -39,28 +38,20 @@ public abstract class TwoStatePreference extends Preference { private CharSequence mSummaryOff; boolean mChecked; private boolean mSendAccessibilityEventViewClickedType; - private AccessibilityManager mAccessibilityManager; private boolean mDisableDependentsState; + private SendAccessibilityEventTypeViewClicked mSendAccessibilityEventTypeViewClicked; + public TwoStatePreference(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); - - mAccessibilityManager = - (AccessibilityManager) getContext().getSystemService(Service.ACCESSIBILITY_SERVICE); } public TwoStatePreference(Context context, AttributeSet attrs) { - super(context, attrs); - - mAccessibilityManager = - (AccessibilityManager) getContext().getSystemService(Service.ACCESSIBILITY_SERVICE); + this(context, attrs, 0); } public TwoStatePreference(Context context) { - super(context); - - mAccessibilityManager = - (AccessibilityManager) getContext().getSystemService(Service.ACCESSIBILITY_SERVICE); + this(context, null); } @Override @@ -198,20 +189,23 @@ public abstract class TwoStatePreference extends Preference { } /** - * Send an accessibility event for the given view if appropriate + * Post send an accessibility event for the given view if appropriate. + * * @param view View that should send the event */ - void sendAccessibilityEventForView(View view) { + void postSendAccessibilityEventForView(View view) { // send an event to announce the value change of the state. It is done here // because clicking a preference does not immediately change the checked state // for example when enabling the WiFi - if (mSendAccessibilityEventViewClickedType && - mAccessibilityManager.isEnabled() && - view.isEnabled()) { + if (mSendAccessibilityEventViewClickedType + && AccessibilityManager.getInstance(getContext()).isEnabled() + && view.isEnabled()) { mSendAccessibilityEventViewClickedType = false; - - int eventType = AccessibilityEvent.TYPE_VIEW_CLICKED; - view.sendAccessibilityEventUnchecked(AccessibilityEvent.obtain(eventType)); + if (mSendAccessibilityEventTypeViewClicked == null) { + mSendAccessibilityEventTypeViewClicked = new SendAccessibilityEventTypeViewClicked(); + } + mSendAccessibilityEventTypeViewClicked.mView = view; + view.post(mSendAccessibilityEventTypeViewClicked); } } @@ -306,4 +300,13 @@ public abstract class TwoStatePreference extends Preference { } }; } + + private final class SendAccessibilityEventTypeViewClicked implements Runnable { + private View mView; + + @Override + public void run() { + mView.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_CLICKED); + } + } } |