summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSvetoslav Ganov <svetoslavganov@google.com>2011-07-22 18:52:56 -0700
committerSvetoslav Ganov <svetoslavganov@google.com>2011-07-22 18:58:28 -0700
commit5c3ea06a7a5558509545450ccc465d695bd1a2e6 (patch)
treeb23b3835fb132105b972c1e3f29e352029b9127a
parentd24cd90486821535fb058531fac54aa5b9360693 (diff)
downloadframeworks_base-5c3ea06a7a5558509545450ccc465d695bd1a2e6.zip
frameworks_base-5c3ea06a7a5558509545450ccc465d695bd1a2e6.tar.gz
frameworks_base-5c3ea06a7a5558509545450ccc465d695bd1a2e6.tar.bz2
TwoStatePreference does not fire click events.
1. Event were send in onBindView but since we have fixed the bug of unattached views firing accessibility events and there is no guarantee that the view is attached in onBindView no events were sent. Now posting a runnable so on the next run the UI tread will send the event i.e. after the view is bound and attached. bug:5008841 Change-Id: I4ed914f7fb65d6896f0c55e7c46e6508d2b2f11f
-rw-r--r--core/java/android/preference/CheckBoxPreference.java4
-rw-r--r--core/java/android/preference/SwitchPreference.java4
-rw-r--r--core/java/android/preference/TwoStatePreference.java45
3 files changed, 28 insertions, 25 deletions
diff --git a/core/java/android/preference/CheckBoxPreference.java b/core/java/android/preference/CheckBoxPreference.java
index 437e553..166b21b 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 f681526..3dbd522 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 8e21c4c..55ef108 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);
+ }
+ }
}