<commit_before>/*
 * Copyright 2015 <NAME>
 *
 * 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.github.leonardoxh.fakesearchview;

import android.annotation.TargetApi;
import android.content.Context;
import android.os.Build;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.AttributeSet;
import android.util.Log;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.TextView;

/**
 * The main lib actor this is a custom FrameLayout
 * wrapper with an EditText with a simple interface to perform the search
 * it collects the user input and pass to an Activity or a Fragment or where you need
 *
 * @author <NAME>
 */
public class FakeSearchView extends FrameLayout implements TextWatcher,
    TextView.OnEditorActionListener {

  private OnSearchListener searchListener;

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

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

  @TargetApi(Build.VERSION_CODES.LOLLIPOP)
  public FakeSearchView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    super(context, attrs, defStyleAttr, defStyleRes);
    init(context);
  }

  public FakeSearchView(Context context) {
    super(context);
    init(context);
  }

  /**
   * Set the search listener to be used on this search
   * @param searchListener the search listener to be used on this search
   * @see OnSearchListener
   */
  public void setOnSearchListener(OnSearchListener searchListener) {
    this.searchListener = searchListener;
  }

  /**
   * Inflate the layout to this FrameLayout wrapper
   * @param context for inflate views
   */
  private void init(Context context) {
    EditText wrappedEditText = (EditText) LayoutInflater.from(context)
        .inflate(R.layout.fake_search_view, this, true);
    wrappedEditText.addTextChangedListener(this);
    wrappedEditText.setOnEditorActionListener(this);
  }

  @Override public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) { }

  @Override public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {
    if (searchListener != null) {
      searchListener.onSearch(charSequence);
    } else {
      Log.w(getClass().getName(), "SearchListener == null");
    }
  }

  @Override public void afterTextChanged(Editable editable) { }

  @Override public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
    if (searchListener != null) {
      searchListener.onSearchHint(textView.getText());
    } else {
      Log.w(getClass().getName(), "SearchListener == null");
    }
    return true;
  }

  /**
   * This interface is an custom method to wrapp the
   * TextWatcher implementation and provide the search constraint
   *
   * @author <NAME>
   */<commit_msg>best editoraction handle<commit_after>/*
 * Copyright 2015 <NAME>
 *
 * 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.github.leonardoxh.fakesearchview;

import android.annotation.TargetApi;
import android.content.Context;
import android.os.Build;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.AttributeSet;
import android.util.Log;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.TextView;

/**
 * The main lib actor this is a custom FrameLayout
 * wrapper with an EditText with a simple interface to perform the search
 * it collects the user input and pass to an Activity or a Fragment or where you need
 *
 * @author <NAME>
 */
public class FakeSearchView extends FrameLayout implements TextWatcher,
    TextView.OnEditorActionListener {

  private OnSearchListener searchListener;

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

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

  @TargetApi(Build.VERSION_CODES.LOLLIPOP)
  public FakeSearchView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    super(context, attrs, defStyleAttr, defStyleRes);
    init(context);
  }

  public FakeSearchView(Context context) {
    super(context);
    init(context);
  }

  /**
   * Set the search listener to be used on this search
   * @param searchListener the search listener to be used on this search
   * @see OnSearchListener
   */
  public void setOnSearchListener(OnSearchListener searchListener) {
    this.searchListener = searchListener;
  }

  /**
   * Inflate the layout to this FrameLayout wrapper
   * @param context for inflate views
   */
  private void init(Context context) {
    EditText wrappedEditText = (EditText) LayoutInflater.from(context)
        .inflate(R.layout.fake_search_view, this, true);
    wrappedEditText.addTextChangedListener(this);
    wrappedEditText.setOnEditorActionListener(this);
  }

  @Override public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) { }

  @Override public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {
    if (searchListener != null) {
      searchListener.onSearch(charSequence);
    } else {
      Log.w(getClass().getName(), "SearchListener == null");
    }
  }

  @Override public void afterTextChanged(Editable editable) { }

  @Override public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
    if (searchListener != null) {
      searchListener.onSearchHint(textView.getText());
      return true;
    }
    Log.w(getClass().getName(), "SearchListener == null");
    return false;
  }

  /**
   * This interface is an custom method to wrapp the
   * TextWatcher implementation and provide the search constraint
   *
   * @author <NAME>
   */
{'fraction_non_alphanumeric': 0.0870244179443498, 'fraction_numerical': 0.0034071550255536627, 'mean_word_length': 4.112481857764877, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '1468654', 'n_tokens_mistral': 1964, 'n_tokens_neox': 1935, 'n_words': 651}