Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8f34f1e0 authored by Wenyi Wang's avatar Wenyi Wang Committed by android-build-merger
Browse files

Merge "Suppress TYPE_VIEW_SELECTED event when pressing "more fields" in...

Merge "Suppress TYPE_VIEW_SELECTED event when pressing "more fields" in editor" into ub-contactsdialer-a-dev
am: 4571858f

* commit '4571858f':
  Suppress TYPE_VIEW_SELECTED event when pressing "more fields" in editor
parents bfac4927 4571858f
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -139,6 +139,7 @@ public abstract class LabeledEditorView extends LinearLayout implements Editor,
        // Turn off the Spinner's own state management. We do this ourselves on rotation
        mLabel.setId(View.NO_ID);
        mLabel.setOnItemSelectedListener(mSpinnerListener);
        ViewSelectedFilter.suppressViewSelectedEvent(mLabel);
        mLabel.setOnTouchListener(new OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
+53 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2015 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License
 */

package com.android.contacts.editor;

import android.view.View;
import android.view.View.AccessibilityDelegate;
import android.view.ViewGroup;
import android.view.accessibility.AccessibilityEvent;

/**
 * This is an AccessibilityDelegate that filters out the TYPE_VIEW_SELECTED event.
 */
public class ViewSelectedFilter extends AccessibilityDelegate {
    private View mView; //the view we don't want TYPE_VIEW_SELECTED event to fire.

    private ViewSelectedFilter(View view) {
        super();
        mView = view;
    }

    /**
     * AccessibilityEvent can only be suppressed at a view's parent, so this function adds the
     * delegate to the view's parent.
     * @param view the view whose TYPE_VIEW_SELECTED event should be suppressed.
     */
    public static void suppressViewSelectedEvent(View view) {
        final View parent = (View) view.getParent();
        parent.setAccessibilityDelegate(new ViewSelectedFilter(view));
    }

    @Override
    public boolean onRequestSendAccessibilityEvent(
            ViewGroup host, View child,AccessibilityEvent event) {
        if (child == mView && event.getEventType() == AccessibilityEvent.TYPE_VIEW_SELECTED) {
            return false;
        }
        return super.onRequestSendAccessibilityEvent(host, child, event);
    }
}