Search in sources :

Example 1 with AccessibilityDelegate

use of android.view.View.AccessibilityDelegate in project AndroidChromium by JackyAndroid.

the class SearchEngineAdapter method getView.

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    View view = convertView;
    if (convertView == null) {
        view = mLayoutInflater.inflate(R.layout.search_engine, null);
    }
    view.setOnClickListener(this);
    view.setTag(position);
    // TODO(finnur): There's a tinting bug in the AppCompat lib (see http://crbug.com/474695),
    // which causes the first radiobox to always appear selected, even if it is not. It is being
    // addressed, but in the meantime we should use the native RadioButton instead.
    RadioButton radioButton = (RadioButton) view.findViewById(R.id.radiobutton);
    // On Lollipop this removes the redundant animation ring on selection but on older versions
    // it would cause the radio button to disappear.
    // TODO(finnur): Remove the encompassing if statement once we go back to using the AppCompat
    // control.
    final boolean selected = position == mSelectedSearchEnginePosition;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        radioButton.setBackgroundResource(0);
    }
    radioButton.setChecked(selected);
    TextView description = (TextView) view.findViewById(R.id.description);
    TemplateUrl templateUrl = mSearchEngines.get(position);
    Resources resources = mContext.getResources();
    description.setText(templateUrl.getShortName());
    // To improve the explore-by-touch experience, the radio button is hidden from accessibility
    // and instead, "checked" or "not checked" is read along with the search engine's name, e.g.
    // "google.com checked" or "google.com not checked".
    radioButton.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO);
    description.setAccessibilityDelegate(new AccessibilityDelegate() {

        @Override
        public void onInitializeAccessibilityEvent(View host, AccessibilityEvent event) {
            super.onInitializeAccessibilityEvent(host, event);
            event.setChecked(selected);
        }

        @Override
        public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfo info) {
            super.onInitializeAccessibilityNodeInfo(host, info);
            info.setCheckable(true);
            info.setChecked(selected);
        }
    });
    TextView link = (TextView) view.findViewById(R.id.link);
    link.setVisibility(selected ? View.VISIBLE : View.GONE);
    if (selected) {
        ForegroundColorSpan linkSpan = new ForegroundColorSpan(ApiCompatibilityUtils.getColor(resources, R.color.pref_accent_color));
        if (LocationUtils.getInstance().isSystemLocationSettingEnabled()) {
            String message = mContext.getString(locationEnabled(position, true) ? R.string.search_engine_location_allowed : R.string.search_engine_location_blocked);
            SpannableString messageWithLink = new SpannableString(message);
            messageWithLink.setSpan(linkSpan, 0, messageWithLink.length(), 0);
            link.setText(messageWithLink);
        } else {
            link.setText(SpanApplier.applySpans(mContext.getString(R.string.android_location_off), new SpanInfo("<link>", "</link>", linkSpan)));
        }
        link.setOnClickListener(this);
    }
    return view;
}
Also used : ForegroundColorSpan(android.text.style.ForegroundColorSpan) AccessibilityNodeInfo(android.view.accessibility.AccessibilityNodeInfo) AccessibilityEvent(android.view.accessibility.AccessibilityEvent) SpanInfo(org.chromium.ui.text.SpanApplier.SpanInfo) RadioButton(android.widget.RadioButton) SpannableString(android.text.SpannableString) View(android.view.View) TextView(android.widget.TextView) SpannableString(android.text.SpannableString) TemplateUrl(org.chromium.chrome.browser.search_engines.TemplateUrlService.TemplateUrl) AccessibilityDelegate(android.view.View.AccessibilityDelegate) TextView(android.widget.TextView) Resources(android.content.res.Resources)

Aggregations

Resources (android.content.res.Resources)1 SpannableString (android.text.SpannableString)1 ForegroundColorSpan (android.text.style.ForegroundColorSpan)1 View (android.view.View)1 AccessibilityDelegate (android.view.View.AccessibilityDelegate)1 AccessibilityEvent (android.view.accessibility.AccessibilityEvent)1 AccessibilityNodeInfo (android.view.accessibility.AccessibilityNodeInfo)1 RadioButton (android.widget.RadioButton)1 TextView (android.widget.TextView)1 TemplateUrl (org.chromium.chrome.browser.search_engines.TemplateUrlService.TemplateUrl)1 SpanInfo (org.chromium.ui.text.SpanApplier.SpanInfo)1