<commit_before>/* 
 * Copyright 2016 OpenMarket Ltd
 * 
 * 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 im.vector.view;

import android.content.Context;
import android.os.Handler;
import android.os.Looper;
import android.support.v7.widget.AppCompatMultiAutoCompleteTextView;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AutoCompleteTextView;
import android.widget.Filter;
import android.widget.FrameLayout;
import android.widget.MultiAutoCompleteTextView;

import org.matrix.androidsdk.MXSession;
import org.matrix.androidsdk.data.Room;
import org.matrix.androidsdk.rest.model.RoomMember;
import org.matrix.androidsdk.rest.model.User;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;

import im.vector.R;
import im.vector.adapters.AutoCompletedUserAdapter;

import org.matrix.androidsdk.util.Log;

/**
 * Custom AppCompatMultiAutoCompleteTextView to display matrix id / displayname
 */
public class VectorAutoCompleteTextView extends AppCompatMultiAutoCompleteTextView {
    private static final String LOG_TAG = "VAutoCompleteTextView";

    // results adapter
    private AutoCompletedUserAdapter mAdapter;

    // the pending patter,
    private String mPendingFilter;

    // trick to customize the popup
    private Field mPopupCanBeUpdatedField;

    // trick to fix the list width
    private android.widget.ListPopupWindow mListPopupWindow;

    public VectorAutoCompleteTextView(Context context) {
        super(context, null);
    }

    public VectorAutoCompleteTextView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public VectorAutoCompleteTextView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    /**
     * Build the auto completions list for a session.
     *
     * @param session the session
     */
    public void initAutoCompletion(MXSession session) {
        initAutoCompletion(session, session.getDataHandler().getStore().getUsers());
    }

    /**
     * Build the auto completions list for a room<commit_msg>Restore the autocorrection keyboard feature.<commit_after>/* 
 * Copyright 2016 OpenMarket Ltd
 * 
 * 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 im.vector.view;

import android.content.Context;
import android.os.Handler;
import android.os.Looper;
import android.support.v7.widget.AppCompatMultiAutoCompleteTextView;
import android.text.InputType;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AutoCompleteTextView;
import android.widget.Filter;
import android.widget.FrameLayout;
import android.widget.MultiAutoCompleteTextView;

import org.matrix.androidsdk.MXSession;
import org.matrix.androidsdk.data.Room;
import org.matrix.androidsdk.rest.model.RoomMember;
import org.matrix.androidsdk.rest.model.User;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;

import im.vector.R;
import im.vector.adapters.AutoCompletedUserAdapter;

import org.matrix.androidsdk.util.Log;

/**
 * Custom AppCompatMultiAutoCompleteTextView to display matrix id / displayname
 */
public class VectorAutoCompleteTextView extends AppCompatMultiAutoCompleteTextView {
    private static final String LOG_TAG = "VAutoCompleteTextView";

    // results adapter
    private AutoCompletedUserAdapter mAdapter;

    // the pending patter,
    private String mPendingFilter;

    // trick to customize the popup
    private Field mPopupCanBeUpdatedField;

    // trick to fix the list width
    private android.widget.ListPopupWindow mListPopupWindow;

    public VectorAutoCompleteTextView(Context context) {
        super(context, null);
    }

    public VectorAutoCompleteTextView(Context context, AttributeSet attrs) {
        super(context, attrs);
        this.setInputType(this.getInputType() & (this.getInputType() ^ InputType.TYPE_TEXT_FLAG_AUTO_COMPLETE));
    }

    public VectorAutoCompleteTextView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        this.setInputType(this.getInputType() & (this.getInputType() ^ InputType.TYPE_TEXT_FLAG_AUTO_COMPLETE));
    }

    /**
     * Build the auto completions list for a session.
     *
     * @param session the session
     */
    public void initAutoCompletion(MXSession session) {
        initAutoCompletion(session, session.getDataHandler().getStore().getUsers());
    }

    /**
     * Build the auto completions list for a room
{'fraction_non_alphanumeric': 0.08206371191135733, 'fraction_numerical': 0.0031163434903047093, 'mean_word_length': 4.167262969588551, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3403298', 'n_tokens_mistral': 1552, 'n_tokens_neox': 1530, 'n_words': 465}