Example usage for android.view.inputmethod InputMethodManager HIDE_NOT_ALWAYS

List of usage examples for android.view.inputmethod InputMethodManager HIDE_NOT_ALWAYS

Introduction

In this page you can find the example usage for android.view.inputmethod InputMethodManager HIDE_NOT_ALWAYS.

Prototype

int HIDE_NOT_ALWAYS

To view the source code for android.view.inputmethod InputMethodManager HIDE_NOT_ALWAYS.

Click Source Link

Document

Flag for #hideSoftInputFromWindow and InputMethodService#requestShowSelf(int) to indicate that the soft input window should normally be hidden, unless it was originally shown with #SHOW_FORCED .

Usage

From source file:com.givon.anhao.activity.ContactlistFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    inputMethodManager = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
    listView = (ListView) getView().findViewById(R.id.list);
    sidebar = (Sidebar) getView().findViewById(R.id.sidebar);
    sidebar.setListView(listView);//from ww  w.  j av a  2  s. c o m
    contactList = new ArrayList<UserBean>();
    // ?contactlist
    getContactList();
    // adapter
    adapter = new ContactAdapter(getActivity(), R.layout.row_contact, contactList, sidebar);
    listView.setAdapter(adapter);
    listView.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            String username = adapter.getItem(position).getUsername();
            if (Constant.NEW_FRIENDS_USERNAME.equals(username)) {
                // ?
                UserBean user = AnhaoApplication.getInstance().getContactList()
                        .get(Constant.NEW_FRIENDS_USERNAME);
                user.setUnreadMsgCount(0);
                startActivity(new Intent(getActivity(), NewFriendsMsgActivity.class));
            } else if (Constant.GROUP_USERNAME.equals(username)) {
                // ??
                startActivity(new Intent(getActivity(), GroupsActivity.class));
            } else {
                // demo??
                startActivity(new Intent(getActivity(), ChatActivity.class).putExtra("userId",
                        adapter.getItem(position).getUsername()));
            }
        }
    });
    listView.setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            // ??
            if (getActivity().getWindow()
                    .getAttributes().softInputMode != WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN) {
                if (getActivity().getCurrentFocus() != null)
                    inputMethodManager.hideSoftInputFromWindow(getActivity().getCurrentFocus().getWindowToken(),
                            InputMethodManager.HIDE_NOT_ALWAYS);
            }
            return false;
        }
    });

    ImageView addContactView = (ImageView) getView().findViewById(R.id.iv_new_contact);
    // ?
    addContactView.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            startActivity(new Intent(getActivity(), AddContactActivity.class));
        }
    });
    registerForContextMenu(listView);

}

From source file:com.jins_meme.bridge.OSCConfigFragment.java

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    handler = new Handler();

    layout = (LinearLayout) view.findViewById(R.id.osc_layout);
    layout.setOnTouchListener(new OnTouchListener() {
        @Override//from  ww w.  j  a va  2s  .  c  o m
        public boolean onTouch(View view, MotionEvent motionEvent) {
            Log.d("DEBUG", "view touch.");

            layout.requestFocus();

            return false;
        }
    });

    InputFilter[] filters = new InputFilter[1];
    filters[0] = new InputFilter() {
        @Override
        public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart,
                int dend) {
            if (end > start) {
                String destTxt = dest.toString();
                String resultingTxt = destTxt.substring(0, dstart) + source.subSequence(start, end)
                        + destTxt.substring(dend);
                if (!resultingTxt
                        .matches("^\\d{1,3}(\\." + "(\\d{1,3}(\\.(\\d{1,3}(\\.(\\d{1,3})?)?)?)?)?)?")) {
                    return "";
                } else {
                    String[] splits = resultingTxt.split("\\.");
                    for (String split : splits) {
                        if (Integer.valueOf(split) > 255) {
                            return "";
                        }
                    }
                }
            }
            return null;
        }
    };

    etRemoteIP = (EditText) view.findViewById(R.id.remote_ip);
    String savedRemoteIP = ((MainActivity) getActivity()).getSavedValue("REMOTE_IP", "255.255.255.255");
    if (savedRemoteIP.equals("255.255.255.255")) {
        etRemoteIP.setText(MemeOSC.getRemoteIPv4Address());
    } else {
        etRemoteIP.setText(savedRemoteIP);
    }
    etRemoteIP.setFilters(filters);
    etRemoteIP.setOnFocusChangeListener(new OnFocusChangeListener() {
        @Override
        public void onFocusChange(View view, boolean b) {
            if (!b) {
                InputMethodManager imm = (InputMethodManager) getActivity()
                        .getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.hideSoftInputFromWindow(view.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
            }
        }
    });
    etRemoteIP.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

        }

        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {

        }

        @Override
        public void afterTextChanged(Editable editable) {
            Log.d("DEBUG", "after text changed " + editable.toString());

            ((MainActivity) getActivity()).autoSaveValue("REMOTE_IP", editable.toString());

            testOSC.setRemoteIP(etRemoteIP.getText().toString());
            testOSC.initSocket();
        }
    });

    etRemotePort = (EditText) view.findViewById(R.id.remote_port);
    etRemotePort.setText(String.valueOf(((MainActivity) getActivity()).getSavedValue("REMOTE_PORT", 10316)));
    etRemotePort.setOnFocusChangeListener(new OnFocusChangeListener() {
        @Override
        public void onFocusChange(View view, boolean b) {
            if (!b) {
                InputMethodManager imm = (InputMethodManager) getActivity()
                        .getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.hideSoftInputFromWindow(view.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
            }
        }
    });
    etRemotePort.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

        }

        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {

        }

        @Override
        public void afterTextChanged(Editable editable) {
            Log.d("DEBUG", "after text changed " + editable.toString());

            if (editable.toString().length() > 0) {
                ((MainActivity) getActivity()).autoSaveValue("REMOTE_PORT",
                        Integer.valueOf(editable.toString()));

                testOSC.setRemotePort(Integer.parseInt(editable.toString()));
                testOSC.initSocket();
            }
        }
    });

    etHostIP = (EditText) view.findViewById(R.id.host_ip);
    etHostIP.setText(MemeOSC.getHostIPv4Address());
    etHostIP.setEnabled(false);

    etHostPort = (EditText) view.findViewById(R.id.host_port);
    etHostPort.setText(String.valueOf(((MainActivity) getActivity()).getSavedValue("HOST_PORT", 11316)));
    etHostPort.setOnFocusChangeListener(new OnFocusChangeListener() {
        @Override
        public void onFocusChange(View view, boolean b) {
            if (!b) {
                InputMethodManager imm = (InputMethodManager) getActivity()
                        .getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.hideSoftInputFromWindow(view.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
            }
        }
    });
    etHostPort.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

        }

        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {

        }

        @Override
        public void afterTextChanged(Editable editable) {
            Log.d("DEBUG", "after text changed " + editable.toString());

            if (editable.toString().length() > 0) {
                ((MainActivity) getActivity()).autoSaveValue("HOST_PORT", Integer.valueOf(editable.toString()));
                testOSC.setHostPort(Integer.parseInt(editable.toString()));
                testOSC.initSocket();
            }
        }
    });

    btnTest = (Button) view.findViewById(R.id.remote_test);
    btnTest.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            layout.requestFocus();

            testOSC.setAddress("/meme/bridge", "/test");
            testOSC.setTypeTag("si");
            testOSC.addArgument(etRemoteIP.getText().toString());
            testOSC.addArgument(Integer.parseInt(etRemotePort.getText().toString()));
            testOSC.flushMessage();
        }
    });

    testOSC = new MemeOSC();
    testOSC.setRemoteIP(etRemoteIP.getText().toString());
    testOSC.setRemotePort(Integer.parseInt(etRemotePort.getText().toString()));
    testOSC.setHostPort(Integer.parseInt(etHostPort.getText().toString()));
    testOSC.initSocket();

    isShown = true;
    Thread rcvTestThread = new Thread(new ReceiveTestTRunnable());
    rcvTestThread.start();
}

From source file:niltor.net.chatuidemo.activity.ContactlistFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    inputMethodManager = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
    listView = (ListView) getView().findViewById(R.id.list);
    sidebar = (Sidebar) getView().findViewById(R.id.sidebar);
    sidebar.setListView(listView);//from   w w  w .j a  v  a2  s  .com
    contactList = new ArrayList<User>();
    // ?contactlist
    getContactList();
    // adapter
    adapter = new ContactAdapter(getActivity(), R.layout.row_contact, contactList, sidebar);
    listView.setAdapter(adapter);
    listView.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            String username = adapter.getItem(position).getUsername();
            if (Constant.NEW_FRIENDS_USERNAME.equals(username)) {
                // ?
                User user = DemoApplication.getInstance().getContactList().get(Constant.NEW_FRIENDS_USERNAME);
                user.setUnreadMsgCount(0);
                startActivity(new Intent(getActivity(), NewFriendsMsgActivity.class));
            } else if (Constant.GROUP_USERNAME.equals(username)) {
                // ??
                startActivity(new Intent(getActivity(), GroupsActivity.class));
            } else {
                // demo??
                startActivity(new Intent(getActivity(), ChatActivity.class).putExtra("userId",
                        adapter.getItem(position).getUsername()));
            }
        }
    });
    listView.setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            // ??
            if (getActivity().getWindow()
                    .getAttributes().softInputMode != WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN) {
                if (getActivity().getCurrentFocus() != null)
                    inputMethodManager.hideSoftInputFromWindow(getActivity().getCurrentFocus().getWindowToken(),
                            InputMethodManager.HIDE_NOT_ALWAYS);
            }
            return false;
        }
    });

    ImageView addContactView = (ImageView) getView().findViewById(R.id.iv_new_contact);
    // ?
    addContactView.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            startActivity(new Intent(getActivity(), AddContactActivity.class));
        }
    });
    registerForContextMenu(listView);

}

From source file:com.lnpdit.chatuidemo.activity.ContactlistFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    inputMethodManager = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
    listView = (ListView) getView().findViewById(R.id.list);
    sidebar = (Sidebar) getView().findViewById(R.id.sidebar);
    sidebar.setListView(listView);/*from  ww  w.j  ava2  s  .c om*/
    contactList = new ArrayList<User>();
    // ?contactlist
    getContactList();
    // adapter
    adapter = new ContactAdapter(getActivity(), R.layout.row_contact, contactList, sidebar);
    listView.setAdapter(adapter);
    listView.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            String username = adapter.getItem(position).getUsername();
            if (Constant.NEW_FRIENDS_USERNAME.equals(username)) {
                // ?
                User user = CydlApplication.getInstance().getContactList().get(Constant.NEW_FRIENDS_USERNAME);
                user.setUnreadMsgCount(0);
                startActivity(new Intent(getActivity(), NewFriendsMsgActivity.class));
            } else if (Constant.GROUP_USERNAME.equals(username)) {
                // ??
                startActivity(new Intent(getActivity(), GroupsActivity.class));
            } else {
                // demo??
                startActivity(new Intent(getActivity(), ChatActivity.class).putExtra("userId",
                        adapter.getItem(position).getUsername()));
            }
        }
    });
    listView.setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            // ??
            if (getActivity().getWindow()
                    .getAttributes().softInputMode != WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN) {
                if (getActivity().getCurrentFocus() != null)
                    inputMethodManager.hideSoftInputFromWindow(getActivity().getCurrentFocus().getWindowToken(),
                            InputMethodManager.HIDE_NOT_ALWAYS);
            }
            return false;
        }
    });

    ImageView addContactView = (ImageView) getView().findViewById(R.id.iv_new_contact);
    // ?
    addContactView.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            startActivity(new Intent(getActivity(), AddContactActivity.class));
        }
    });
    registerForContextMenu(listView);

}

From source file:com.cianmcgovern.android.ShopAndShare.Share.java

@Override
public void onCreate(Bundle savedInstanceState) {

    mContext = this;
    super.onCreate(savedInstanceState);

    setContentView(R.layout.share);/*from   www  .  j  a  v a  2 s. co  m*/

    Button upload = (Button) findViewById(R.id.uploadButton);
    upload.setText(R.string.upload);
    upload.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            String userLoc = mLocationEdit.getText().toString();
            String userStore = mStore.getText().toString();
            // Don't allow empty text fields
            if (userLoc.length() > 1 && userStore.length() > 1) {
                runUpload(Results.getInstance(), userLoc, userStore);
            } else
                new AlertDialog.Builder(mContext).setTitle(R.string.invalidInput)
                        .setMessage(R.string.invalidFields).show();
        }

    });

    Button cancel = (Button) findViewById(R.id.cancelShareButton);
    cancel.setText(R.string.cancelButton);
    cancel.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            if (mLocationListener != null)
                mLocationManager.removeUpdates(mLocationListener);
            finish();
        }

    });

    mLocationEdit = (EditText) findViewById(R.id.enterLocation);
    mLocationEdit.setOnKeyListener(new OnKeyListener() {

        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if ((event.getAction()) == KeyEvent.ACTION_DOWN && (keyCode == KeyEvent.KEYCODE_ENTER)) {
                InputMethodManager in = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                in.hideSoftInputFromWindow(mLocationEdit.getApplicationWindowToken(),
                        InputMethodManager.HIDE_NOT_ALWAYS);
                return true;
            }
            return false;
        }

    });
    mStore = (EditText) findViewById(R.id.enterStore);
    mStore.setOnKeyListener(new OnKeyListener() {

        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if ((event.getAction()) == KeyEvent.ACTION_DOWN && (keyCode == KeyEvent.KEYCODE_ENTER)) {
                InputMethodManager in = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                in.hideSoftInputFromWindow(mStore.getApplicationWindowToken(),
                        InputMethodManager.HIDE_NOT_ALWAYS);
                return true;
            }
            return false;
        }

    });

    mSearch = (Button) findViewById(R.id.locationButton);
    mSearch.setBackgroundResource(R.drawable.search);
    mSearch.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            mLocationManager = (LocationManager) mContext.getSystemService(Context.LOCATION_SERVICE);
            if (!CheckFeatures.haveGPS()) {
                new AlertDialog.Builder(mContext).setTitle("GPS Required")
                        .setMessage("You must have GPS to use this feature").show();
            }
            // Only use GPS if it is enabled
            else if (mLocationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
                mSearch.setEnabled(false);
                mSearch.setBackgroundResource(R.drawable.world);
                getLocation();
            } else {
                mGpsDialog = new AlertDialog.Builder(mContext).create();
                mGpsDialog.setTitle(R.string.gpsDisabled);
                mGpsDialog.setMessage(mContext.getText(R.string.gpsDisabledMessage));
                mGpsDialog.show();
            }
        }

    });
}

From source file:com.feytuo.chat.activity.ChatHistoryFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    inputMethodManager = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
    errorItem = (RelativeLayout) getView().findViewById(R.id.rl_error_item);
    errorText = (TextView) errorItem.findViewById(R.id.tv_connect_errormsg);
    // contact list
    contactList = App.getInstance().getContactList();
    listView = (ListView) getView().findViewById(R.id.list);
    adapter = new ChatHistoryAdapter(getActivity(), 1, loadUsersWithRecentChat());
    // adapter//  w ww.  ja v  a 2 s  . c o m
    listView.setAdapter(adapter);
    listView.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            EMContact emContact = adapter.getItem(position);
            if (adapter.getItem(position).getUsername().equals(App.getInstance().getUserName()))
                Toast.makeText(getActivity(), "??", 0).show();
            else {
                // ??
                Intent intent = new Intent(getActivity(), ChatActivity.class);
                if (emContact instanceof EMGroup) {
                    //it is group chat
                    intent.putExtra("chatType", ChatActivity.CHATTYPE_GROUP);
                    intent.putExtra("groupId", ((EMGroup) emContact).getGroupId());
                } else {
                    //it is single chat
                    intent.putExtra("userId", emContact.getUsername());
                }
                startActivity(intent);
            }
        }
    });
    // ??
    registerForContextMenu(listView);

    listView.setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            // ??
            if (getActivity().getWindow()
                    .getAttributes().softInputMode != WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN) {
                if (getActivity().getCurrentFocus() != null)
                    inputMethodManager.hideSoftInputFromWindow(getActivity().getCurrentFocus().getWindowToken(),
                            InputMethodManager.HIDE_NOT_ALWAYS);
            }
            return false;
        }
    });
    // ?
    query = (EditText) getView().findViewById(R.id.query);
    // ?button
    clearSearch = (ImageButton) getView().findViewById(R.id.search_clear);
    query.addTextChangedListener(new TextWatcher() {
        public void onTextChanged(CharSequence s, int start, int before, int count) {

            adapter.getFilter().filter(s);
            if (s.length() > 0) {
                clearSearch.setVisibility(View.VISIBLE);
            } else {
                clearSearch.setVisibility(View.INVISIBLE);
            }
        }

        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        public void afterTextChanged(Editable s) {
        }
    });
    clearSearch.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            query.getText().clear();

        }
    });

}

From source file:com.easemob.ui.ChatHistoryFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    inputMethodManager = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
    errorItem = (RelativeLayout) getView().findViewById(R.id.rl_error_item);
    errorText = (TextView) errorItem.findViewById(R.id.tv_connect_errormsg);
    // contact list
    contactList = MyApplication.getInstance().getContactList();
    listView = (ListView) getView().findViewById(R.id.list);
    adapter = new ChatHistoryAdapter(getActivity(), 1, loadUsersWithRecentChat());
    // adapter//from w  w  w  .jav  a 2 s . c o m
    listView.setAdapter(adapter);
    listView.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            EMContact emContact = adapter.getItem(position);
            if (adapter.getItem(position).getUsername().equals(MyApplication.getInstance().getUserName()))
                Toast.makeText(getActivity(), "??", 0).show();
            else {
                // ??
                Intent intent = new Intent(getActivity(), ChatActivity.class);
                if (emContact instanceof EMGroup) {
                    //it is group chat
                    intent.putExtra("chatType", ChatActivity.CHATTYPE_GROUP);
                    intent.putExtra("groupId", ((EMGroup) emContact).getGroupId());
                } else {
                    //it is single chat
                    intent.putExtra("userId", emContact.getUsername());
                }
                startActivity(intent);
            }
        }
    });
    // ??
    registerForContextMenu(listView);

    listView.setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            // ??
            if (getActivity().getWindow()
                    .getAttributes().softInputMode != WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN) {
                if (getActivity().getCurrentFocus() != null)
                    inputMethodManager.hideSoftInputFromWindow(getActivity().getCurrentFocus().getWindowToken(),
                            InputMethodManager.HIDE_NOT_ALWAYS);
            }
            return false;
        }
    });
    // ?
    query = (EditText) getView().findViewById(R.id.query);
    // ?button
    clearSearch = (ImageButton) getView().findViewById(R.id.search_clear);
    query.addTextChangedListener(new TextWatcher() {
        public void onTextChanged(CharSequence s, int start, int before, int count) {

            adapter.getFilter().filter(s);
            if (s.length() > 0) {
                clearSearch.setVisibility(View.VISIBLE);
            } else {
                clearSearch.setVisibility(View.INVISIBLE);
            }
        }

        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        public void afterTextChanged(Editable s) {
        }
    });
    clearSearch.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            query.getText().clear();

        }
    });

}

From source file:com.easemob.chatui.activity.ChatHistoryFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    inputMethodManager = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
    errorText = (TextView) errorItem.findViewById(R.id.tv_connect_errormsg);
    // contact list
    contactList = BeewayApplication.getInstance().getContactList();
    listView = (ListView) getView().findViewById(R.id.list);
    adapter = new ChatHistoryAdapter(getActivity(), 1, loadUsersWithRecentChat());
    // adapter/*from   w  ww.  j  ava2 s . c om*/
    listView.setAdapter(adapter);
    final String st = getResources().getString(R.string.Cant_chat_with_yourself);
    listView.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            EMContact emContact = adapter.getItem(position);
            if (adapter.getItem(position).getUsername().equals(BeewayApplication.getInstance().getUserName()))
                Toast.makeText(getActivity(), st, Toast.LENGTH_SHORT).show();
            else {
                // ??
                Intent intent = new Intent(getActivity(), ChatActivity.class);
                if (emContact instanceof EMGroup) {
                    //it is group chat
                    intent.putExtra("chatType", ChatActivity.CHATTYPE_GROUP);
                    intent.putExtra("groupId", ((EMGroup) emContact).getGroupId());
                } else {
                    //it is single chat
                    intent.putExtra("userId", emContact.getUsername());
                }
                startActivity(intent);
            }
        }
    });
    // ??
    registerForContextMenu(listView);

    listView.setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            // ??
            if (getActivity().getWindow()
                    .getAttributes().softInputMode != WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN) {
                if (getActivity().getCurrentFocus() != null)
                    inputMethodManager.hideSoftInputFromWindow(getActivity().getCurrentFocus().getWindowToken(),
                            InputMethodManager.HIDE_NOT_ALWAYS);
            }
            return false;
        }
    });
    // ?
    query = (EditText) getView().findViewById(R.id.query);
    // ?button
    clearSearch = (ImageButton) getView().findViewById(R.id.search_clear);
    query.addTextChangedListener(new TextWatcher() {
        public void onTextChanged(CharSequence s, int start, int before, int count) {

            adapter.getFilter().filter(s);
            if (s.length() > 0) {
                clearSearch.setVisibility(View.VISIBLE);
            } else {
                clearSearch.setVisibility(View.INVISIBLE);
            }
        }

        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        public void afterTextChanged(Editable s) {
        }
    });
    clearSearch.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            query.getText().clear();

        }
    });

}

From source file:com.easemob.chatuidemo.activity.ChatHistoryFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    inputMethodManager = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
    errorText = (TextView) errorItem.findViewById(R.id.tv_connect_errormsg);
    // contact list
    contactList = DemoApplication.getInstance().getContactList();
    listView = (ListView) getView().findViewById(R.id.list);
    adapter = new ChatHistoryAdapter(getActivity(), 1, loadUsersWithRecentChat());
    // adapter//from  w ww  .j  av a  2 s. co  m
    listView.setAdapter(adapter);
    final String st = getResources().getString(R.string.Cant_chat_with_yourself);
    listView.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            EMContact emContact = adapter.getItem(position);
            if (adapter.getItem(position).getUsername().equals(DemoApplication.getInstance().getUserName()))
                Toast.makeText(getActivity(), st, 0).show();
            else {
                // ??
                Intent intent = new Intent(getActivity(), ChatActivity.class);
                if (emContact instanceof EMGroup) {
                    //it is group chat
                    intent.putExtra("chatType", ChatActivity.CHATTYPE_GROUP);
                    intent.putExtra("groupId", ((EMGroup) emContact).getGroupId());
                } else {
                    //it is single chat
                    intent.putExtra("userId", emContact.getUsername());
                }
                startActivity(intent);
            }
        }
    });
    // ??
    registerForContextMenu(listView);

    listView.setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            // ??
            if (getActivity().getWindow()
                    .getAttributes().softInputMode != WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN) {
                if (getActivity().getCurrentFocus() != null)
                    inputMethodManager.hideSoftInputFromWindow(getActivity().getCurrentFocus().getWindowToken(),
                            InputMethodManager.HIDE_NOT_ALWAYS);
            }
            return false;
        }
    });
    // ?
    query = (EditText) getView().findViewById(R.id.query);
    // ?button
    clearSearch = (ImageButton) getView().findViewById(R.id.search_clear);
    query.addTextChangedListener(new TextWatcher() {
        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {

            adapter.getFilter().filter(s);
            if (s.length() > 0) {
                clearSearch.setVisibility(View.VISIBLE);
            } else {
                clearSearch.setVisibility(View.INVISIBLE);
            }
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void afterTextChanged(Editable s) {
        }
    });
    clearSearch.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            query.getText().clear();

        }
    });

}

From source file:com.shengtao.chat.chatUI.activity.ChatHistoryFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    inputMethodManager = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
    errorText = (TextView) errorItem.findViewById(R.id.tv_connect_errormsg);
    // contact list
    contactList = UIApplication.getContext().getContactList();
    listView = (ListView) getView().findViewById(R.id.list);
    adapter = new ChatHistoryAdapter(getActivity(), 1, loadUsersWithRecentChat());
    // adapter//from  w  w  w . jav  a  2 s . co m
    listView.setAdapter(adapter);
    final String st = getResources().getString(R.string.Cant_chat_with_yourself);
    listView.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            EMContact emContact = adapter.getItem(position);
            if (adapter.getItem(position).getUsername().equals(UIApplication.getContext().getUserName()))
                Toast.makeText(getActivity(), st, Toast.LENGTH_SHORT).show();
            else {
                // ??
                Intent intent = new Intent(getActivity(), ChatActivity.class);
                if (emContact instanceof EMGroup) {
                    //it is group chat
                    intent.putExtra("chatType", ChatActivity.CHATTYPE_GROUP);
                    intent.putExtra("groupId", ((EMGroup) emContact).getGroupId());
                } else {
                    //it is single chat
                    intent.putExtra("userId", emContact.getUsername());
                }
                startActivity(intent);
            }
        }
    });
    // ??
    registerForContextMenu(listView);

    listView.setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            // ??
            if (getActivity().getWindow()
                    .getAttributes().softInputMode != WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN) {
                if (getActivity().getCurrentFocus() != null)
                    inputMethodManager.hideSoftInputFromWindow(getActivity().getCurrentFocus().getWindowToken(),
                            InputMethodManager.HIDE_NOT_ALWAYS);
            }
            return false;
        }
    });
    // ?
    query = (EditText) getView().findViewById(R.id.query);
    // ?button
    clearSearch = (ImageButton) getView().findViewById(R.id.search_clear);
    query.addTextChangedListener(new TextWatcher() {
        public void onTextChanged(CharSequence s, int start, int before, int count) {

            adapter.getFilter().filter(s);
            if (s.length() > 0) {
                clearSearch.setVisibility(View.VISIBLE);
            } else {
                clearSearch.setVisibility(View.INVISIBLE);
            }
        }

        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        public void afterTextChanged(Editable s) {
        }
    });
    clearSearch.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            query.getText().clear();

        }
    });

}