If you think the Android project Cervantes listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
/*
* Copyright (C) 2014 Alejandro Rodriguez Salamanca.
*/*fromwww.java2s.com*/
* 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 me.alexrs.cervantes.ui.recyclerview.viewholder;
import android.content.Context;
import android.view.KeyEvent;
import android.view.View;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import butterknife.ButterKnife;
import butterknife.InjectView;
import com.squareup.picasso.Picasso;
import de.greenrobot.event.EventBus;
import me.alexrs.cervantes.R;
import me.alexrs.cervantes.core.events.SearchEvent;
import me.alexrs.prefs.lib.Prefs;
import me.alexrs.recyclerviewrenderers.interfaces.Renderable;
import me.alexrs.recyclerviewrenderers.viewholder.RenderViewHolder;
/**
* @author Alejandro Rodriguez <https://github.com/Alexrs95/Cervantes>
*/publicclass SearchHeaderViewHolder extends RenderViewHolder
implements TextView.OnEditorActionListener {
privatefinal Context context;
@InjectView(R.id.h_image) ImageView header_image;
@InjectView(R.id.h_edittext) EditText header_editText;
public SearchHeaderViewHolder(View itemView) {
super(itemView);
ButterKnife.inject(this, itemView);
this.context = itemView.getContext();
}
@Override publicvoid onBindView(Renderable renderable) {
Picasso.with(context).load("http://lorempixel.com/400/200/").into(header_image);
header_editText.setOnEditorActionListener(this);
}
@Override publicboolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_SEARCH) {
hideKeyboard();
Prefs.with(header_editText.getContext()).save("WORD", header_editText.getText().toString());
EventBus.getDefault().post(new SearchEvent(header_editText.getText().toString()));
return true;
}
return false;
}
privatevoid hideKeyboard() {
header_editText.clearFocus();
InputMethodManager in = (InputMethodManager) header_editText.getContext()
.getSystemService(Context.INPUT_METHOD_SERVICE);
in.hideSoftInputFromWindow(header_editText.getWindowToken(), 0);
}
}