Make whole switchable header act as single Switch for
AccessibilityService second part of b/21305287 Change-Id: I80da2ecbc367e10d027a851193f4d03ab8e09c69
This commit is contained in:
@@ -27,6 +27,8 @@ import android.util.AttributeSet;
|
|||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
import android.view.accessibility.AccessibilityEvent;
|
||||||
|
import android.view.accessibility.AccessibilityNodeInfo;
|
||||||
import android.widget.CompoundButton;
|
import android.widget.CompoundButton;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
import android.widget.Switch;
|
import android.widget.Switch;
|
||||||
@@ -85,6 +87,7 @@ public class SwitchBar extends LinearLayout implements CompoundButton.OnCheckedC
|
|||||||
a.recycle();
|
a.recycle();
|
||||||
|
|
||||||
mTextView = (TextView) findViewById(R.id.switch_text);
|
mTextView = (TextView) findViewById(R.id.switch_text);
|
||||||
|
mTextView.setImportantForAccessibility(IMPORTANT_FOR_ACCESSIBILITY_NO);
|
||||||
mLabel = getResources().getString(R.string.switch_off_text);
|
mLabel = getResources().getString(R.string.switch_off_text);
|
||||||
mSummarySpan = new TextAppearanceSpan(mContext, R.style.TextAppearance_Small_SwitchBar);
|
mSummarySpan = new TextAppearanceSpan(mContext, R.style.TextAppearance_Small_SwitchBar);
|
||||||
updateText();
|
updateText();
|
||||||
@@ -95,6 +98,7 @@ public class SwitchBar extends LinearLayout implements CompoundButton.OnCheckedC
|
|||||||
// Prevent onSaveInstanceState() to be called as we are managing the state of the Switch
|
// Prevent onSaveInstanceState() to be called as we are managing the state of the Switch
|
||||||
// on our own
|
// on our own
|
||||||
mSwitch.setSaveEnabled(false);
|
mSwitch.setSaveEnabled(false);
|
||||||
|
mSwitch.setImportantForAccessibility(IMPORTANT_FOR_ACCESSIBILITY_NO);
|
||||||
lp = (MarginLayoutParams) mSwitch.getLayoutParams();
|
lp = (MarginLayoutParams) mSwitch.getLayoutParams();
|
||||||
lp.setMarginEnd(switchBarMarginEnd);
|
lp.setMarginEnd(switchBarMarginEnd);
|
||||||
|
|
||||||
@@ -275,4 +279,22 @@ public class SwitchBar extends LinearLayout implements CompoundButton.OnCheckedC
|
|||||||
|
|
||||||
requestLayout();
|
requestLayout();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @hide */
|
||||||
|
@Override
|
||||||
|
public void onInitializeAccessibilityNodeInfoInternal(AccessibilityNodeInfo info) {
|
||||||
|
super.onInitializeAccessibilityNodeInfoInternal(info);
|
||||||
|
info.setClassName(Switch.class.getName());
|
||||||
|
info.setText(mTextView.getText());
|
||||||
|
info.setCheckable(true);
|
||||||
|
info.setChecked(mSwitch.isChecked());
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @hide */
|
||||||
|
@Override
|
||||||
|
public void onInitializeAccessibilityEventInternal(AccessibilityEvent event) {
|
||||||
|
super.onInitializeAccessibilityEventInternal(event);
|
||||||
|
event.setClassName(Switch.class.getName());
|
||||||
|
event.setChecked(mSwitch.isChecked());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user