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.grass.caishi.cc.activity.main.FriendsListFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    if (savedInstanceState != null && savedInstanceState.getBoolean("isConflict", false))
        return;/*from   ww w  .j a v a2s  .com*/
    inputMethodManager = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
    listView = (ListView) getView().findViewById(R.id.list);
    // listView.setFootRefresh(false);
    // listView.setPullLoadEnable(true);

    swipeRefreshLayout = (SwipeRefreshLayout) getView().findViewById(R.id.swipeLayout);
    // swipeRefreshLayout.setColorSchemeResources(R.color.swipe_color_1,
    // R.color.swipe_color_2, R.color.swipe_color_3, R.color.swipe_color_4);
    // swipeRefreshLayout.setSize(SwipeRefreshLayout.LARGE);
    // swipeRefreshLayout.setProgressBackgroundColor(R.color.swipe_background_color);
    swipeRefreshLayout.setProgressViewEndTarget(true, 100);

    swipeRefreshLayout.setOnRefreshListener(new OnRefreshListener() {
        @Override
        public void onRefresh() {
            ((MainActivity) getActivity()).refreshFriends();
        }
    });

    sidebar = (Sidebar) getView().findViewById(R.id.sidebar);
    sidebar.setListView(listView);
    contactList = new ArrayList<User>();
    // ?contactlist
    getContactList();
    // adapter
    adapter = new ContactAdapter(getActivity(), R.layout.row_contact, contactList);
    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 = MyApplication.getInstance().getContactList(false)
                        .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 if (Constant.KEFU.equals(username)) {
                // ??
                startActivity(new Intent(getActivity(), ChatActivity.class).putExtra("userId", Constant.KEFU)
                        .putExtra("chatType", 0));
            } else {
                //todo 
                Log.e("kevin",
                        "adapter.getItem(position).getUsername():" + adapter.getItem(position).getUsername());
                startActivity(new Intent(getActivity(), Userinfo.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);
    isInitDone = true;
    refresh();

    // // ?
    // 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.gao.im.ui.CCPActivityBase.java

/**
 * //from w w w.  j  a  v a 2s  .com
 */
public void displaySoftKeyboard() {
    final FragmentActivity activity = mActionBarActivity;
    // Display the soft keyboard
    InputMethodManager inputMethodManager = (InputMethodManager) activity
            .getSystemService(Context.INPUT_METHOD_SERVICE);
    if (inputMethodManager != null) {
        View localView = activity.getCurrentFocus();
        if (localView != null && localView.getWindowToken() != null) {
            inputMethodManager.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);
        }
    }
}

From source file:com.sxt.superqq.fragment.ContactlistFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    // T??home???appcrash
    if (savedInstanceState != null && savedInstanceState.getBoolean("isConflict", false))
        return;/*  w  w  w  .  j av a 2s . c o m*/
    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);
    // ???
    blackList = EMContactManager.getInstance().getBlackListUsernames();
    // contactList = new ArrayList<User>();
    // ?
    query = (EditText) getView().findViewById(R.id.query);
    query.setHint(R.string.search);
    clearSearch = (ImageButton) getView().findViewById(R.id.search_clear);
    query.addTextChangedListener(new TextWatcher() {
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            mAdapter.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();
            hideSoftKeyboard();
        }
    });

    mContactList = new ArrayList<UserBean>();
    // adapter
    mAdapter = new Contact_Adapter(getActivity(), R.layout.row_contact, mContactList);
    listView.setAdapter(mAdapter);
    listView.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            String username = mAdapter.getItem(position).getUserName();
            if (Constant.NEW_FRIENDS_USERNAME.equals(username)) {
                // ?
                User user = SuperQQApplication.getInstance().getContact_List()
                        .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",
                        mAdapter.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);

    regsiterContactReceiver();
}

From source file:in.darbose.classroom.edit.EditClassroomFragment.java

/**
 * Closes keyboard for disabling interruption
 *//*from www  .j ava 2  s . c o  m*/
private void closeKeyboard() {
    try {
        InputMethodManager imm = (InputMethodManager) getActivity()
                .getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(getActivity().getCurrentFocus().getWindowToken(),
                InputMethodManager.HIDE_NOT_ALWAYS);
    } catch (Exception e) {
    }
}

From source file:com.appnexus.opensdkapp.MainActivity.java

@Override
public void onPageSelected(int arg0) {
    Clog.v(Constants.BASE_LOG_TAG, "page selected: " + arg0);
    this.tabHost.setCurrentTab(arg0);

    DebugFragment debugFrag = (DebugFragment) pagerAdapter.getItem(TABS.DEBUG.ordinal());
    if (debugFrag != null)
        debugFrag.refresh();// w w  w  . j ava 2s.  c  o m
    else
        Clog.e(Constants.BASE_LOG_TAG, "DebugFragment object was null");

    InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.hideSoftInputFromWindow(tabHost.getApplicationWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
}

From source file:com.app.sample.chatting.widget.KJChatKeyboard.java

/**
 * //from ww w .  j av a2  s . co  m
 */
public static void showKeyboard(Context context) {
    Activity activity = (Activity) context;
    if (activity != null) {
        InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.showSoftInputFromInputMethod(activity.getCurrentFocus().getWindowToken(), 0);
        imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);
    }
}

From source file:com.sft.blackcatapp.EnrollSchoolActivity.java

private void initData() {
    searchSchool.setImeOptions(EditorInfo.IME_ACTION_SEARCH);
    searchSchool.setOnEditorActionListener(new OnEditorActionListener() {

        @Override//from   w  ww.j a  v  a  2 s  .co  m
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_SEARCH) {
                // ??
                ((InputMethodManager) searchSchool.getContext().getSystemService(Context.INPUT_METHOD_SERVICE))
                        .hideSoftInputFromWindow(EnrollSchoolActivity.this.getCurrentFocus().getWindowToken(),
                                InputMethodManager.HIDE_NOT_ALWAYS);

                // ?
                LogUtil.print("?");
                schoolname = searchSchool.getText().toString().trim();
                searchSchool(true);
                return true;
            }
            return false;
        }

    });
}

From source file:com.darly.im.ui.CCPActivityBase.java

/**
 *
 *//*w  ww .  j  a v a 2s.c  o  m*/
public void toggleSoftInput() {
    final FragmentActivity activity = mActionBarActivity;
    // Display the soft keyboard
    InputMethodManager inputMethodManager = (InputMethodManager) activity
            .getSystemService(Context.INPUT_METHOD_SERVICE);
    if (inputMethodManager != null) {
        View localView = activity.getCurrentFocus();
        if (localView != null && localView.getWindowToken() != null) {
            inputMethodManager.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);
        }
    }
}

From source file:org.ymegane.android.approom.AppDisplayFragment.java

@Override
public void onPause() {
    super.onPause();
    lastGridPosition = gridAppView.getFirstVisiblePosition();

    InputMethodManager inputMethodManager = (InputMethodManager) getActivity()
            .getSystemService(Context.INPUT_METHOD_SERVICE);
    inputMethodManager.hideSoftInputFromWindow(gridAppView.getWindowToken(),
            InputMethodManager.HIDE_NOT_ALWAYS);
}

From source file:com.near.chimerarevo.fragments.SearchFragment.java

@Override
public void onClick(View view) {
    if (view instanceof FloatingActionButton)
        addPage();//ww  w.  j  a va 2  s . co m
    else if (view instanceof CircleButton) {
        clickCounter++;

        if (clickCounter == 1)
            mFab.setEnabled(true);

        if (mText.getText().toString().length() > 0) {
            InputMethodManager in = (InputMethodManager) getActivity()
                    .getSystemService(Context.INPUT_METHOD_SERVICE);
            in.hideSoftInputFromWindow(mText.getApplicationWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);

            mText.setError(null);
            performUpdate();
        } else {
            mText.setError(getResources().getString(R.string.error_field_required));
            mText.requestFocus();
        }
    }
}