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.kasungunathilaka.sarigama.ui.HomeActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.menu_home, menu);
    MenuItem item = menu.findItem(R.id.action_search);
    SearchView searchView = (SearchView) item.getActionView();
    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override/* w  ww  . j  av a 2 s.c o m*/
        public boolean onQueryTextSubmit(String query) {
            ((InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(
                    (null == getCurrentFocus()) ? null : getCurrentFocus().getWindowToken(),
                    InputMethodManager.HIDE_NOT_ALWAYS);
            ContentFragment contentFragment = new ContentFragment();
            contentFragment.setContentType(ROOT_FRAGMENT_SEARCH, query);
            setFragment(contentFragment);
            return true;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            return false;
        }
    });
    return super.onCreateOptionsMenu(menu);
}

From source file:com.lastsoft.plog.PlaysFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final View rootView = inflater.inflate(R.layout.fragment_plays, container, false);

    rootView.setTag(TAG);/*  w  ww.j av  a 2  s . c o m*/

    // BEGIN_INCLUDE(initializeRecyclerView)
    mRecyclerView = (RecyclerView) rootView.findViewById(R.id.recyclerView);
    mRecyclerView.setBackgroundColor(getResources().getColor(R.color.cardview_initial_background));
    RecyclerFastScroller fastScroller = (RecyclerFastScroller) rootView.findViewById(R.id.fastscroller);

    // Connect the recycler to the scroller (to let the scroller scroll the list)
    fastScroller.attachRecyclerView(mRecyclerView);

    addPlay = (FloatingActionButton) rootView.findViewById(R.id.add_play);
    if (fromDrawer && playListType != 2) {
        addPlay.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int viewXY[] = new int[2];
                v.getLocationOnScreen(viewXY);
                /*if (mListener != null) {
                mListener.onFragmentInteraction("add_play", viewXY[0], viewXY[1]);
                }*/
                ((MainActivity) mActivity).usedFAB = true;
                ((MainActivity) mActivity).openGames("", true, 0, getString(R.string.title_games),
                        MainActivity.CurrentYear);
            }
        });
    } else {
        addPlay.setVisibility(View.GONE);
    }

    fabMargin = getResources().getDimensionPixelSize(R.dimen.fab_margin);
    mRecyclerView.addOnScrollListener(new MyRecyclerScroll() {
        @Override
        public void show() {
            addPlay.animate().translationY(0).setInterpolator(new DecelerateInterpolator(2)).start();
        }

        @Override
        public void hide() {
            addPlay.animate().translationY(addPlay.getHeight() + fabMargin)
                    .setInterpolator(new AccelerateInterpolator(2)).start();
        }
    });

    // Connect the scroller to the recycler (to let the recycler scroll the scroller's handle)
    //mRecyclerView.addOnScrollListener(fastScroller.getOnScrollListener());

    // LinearLayoutManager is used here, this will layout the elements in a similar fashion
    // to the way ListView would layout elements. The RecyclerView.LayoutManager defines how
    // elements are laid out.
    mLayoutManager = new LinearLayoutManager(mActivity);

    mCurrentLayoutManagerType = LayoutManagerType.LINEAR_LAYOUT_MANAGER;

    if (savedInstanceState != null) {
        // Restore saved layout manager type.
        mCurrentLayoutManagerType = (LayoutManagerType) savedInstanceState.getSerializable(KEY_LAYOUT_MANAGER);
    }
    setRecyclerViewLayoutManager(mCurrentLayoutManagerType);

    //mAdapter = new PlayAdapter(mActivity, this);

    /*if (((MainActivity)mActivity).mPlayAdapter != null) {
    mAdapter = ((MainActivity) mActivity).mPlayAdapter;
    }else{*/
    mAdapter = ((MainActivity) mActivity).initPlayAdapter(mSearchQuery, fromDrawer, playListType, currentYear);
    //}
    // Set CustomAdapter as the adapter for RecyclerView.
    mRecyclerView.setAdapter(mAdapter);
    // END_INCLUDE(initializeRecyclerView)

    if (mSearch != null) {
        mSearch.setHint(
                getString(R.string.filter) + mAdapter.getItemCount() + getString(R.string.filter_plays));
    }

    /*boolean pauseOnScroll = true; // or true
    boolean pauseOnFling = true; // or false
    NewPauseOnScrollListener listener = new NewPauseOnScrollListener(ImageLoader.getInstance(), pauseOnScroll, pauseOnFling);
    mRecyclerView.addOnScrollListener(listener);*/

    if (!fromDrawer) {
        RelativeLayout playsLayout = (RelativeLayout) rootView.findViewById(R.id.playsLayout);
        final SwipeDismissBehavior<LinearLayout> behavior = new SwipeDismissBehavior();
        behavior.setSwipeDirection(SwipeDismissBehavior.SWIPE_DIRECTION_START_TO_END);
        behavior.setStartAlphaSwipeDistance(1.0f);
        behavior.setSensitivity(0.15f);
        behavior.setListener(new SwipeDismissBehavior.OnDismissListener() {
            @Override
            public void onDismiss(final View view) {
                PlaysFragment myFragC1 = (PlaysFragment) getFragmentManager().findFragmentByTag("plays");
                FragmentTransaction transaction = getFragmentManager().beginTransaction();
                transaction.remove(myFragC1);
                transaction.commitAllowingStateLoss();
                getFragmentManager().executePendingTransactions();
                mActivity.onBackPressed();
            }

            @Override
            public void onDragStateChanged(int i) {

            }
        });

        CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) playsLayout.getLayoutParams();
        params.setBehavior(behavior);
    }

    if (mSearch != null) {
        mSearch.addTextChangedListener(new TextWatcher() {

            @Override
            public void onTextChanged(CharSequence cs, int arg1, int arg2, int arg3) {
                // When user changed the Text
                if (mActivity != null) {
                    mSearchQuery = cs.toString();
                    //initDataset();
                    //mAdapter = new GameAdapter(PlaysFragment.this, mActivity,mSearchQuery);
                    mAdapter = ((MainActivity) mActivity).initPlayAdapter(mSearchQuery, fromDrawer,
                            playListType, currentYear);
                    // Set CustomAdapter as the adapter for RecyclerView.
                    mRecyclerView.setAdapter(mAdapter);
                }
            }

            @Override
            public void afterTextChanged(Editable editable) {
            }

            @Override
            public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
            }
        });

        mCancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (!mSearch.getText().toString().equals("")) {
                    mSearchQuery = "";
                    ((MainActivity) mActivity).initPlayAdapter(mSearchQuery, fromDrawer, playListType,
                            currentYear);
                    mSearch.setText(mSearchQuery);

                    //mActivity.onBackPressed();
                }

                InputMethodManager inputManager = (InputMethodManager) mActivity
                        .getSystemService(Context.INPUT_METHOD_SERVICE);

                inputManager.hideSoftInputFromWindow(mActivity.getCurrentFocus().getWindowToken(),
                        InputMethodManager.HIDE_NOT_ALWAYS);
                mSearch.clearFocus();
                mRecyclerView.requestFocus();

                refreshDataset();
            }
        });
    }

    return rootView;
}

From source file:com.nononsenseapps.notepad.ActivityMain.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Pass the event to ActionBarDrawerToggle, if it returns
    // true, then it has handled the app icon touch event
    if (mDrawerToggle.onOptionsItemSelected(item)) {
        return true;
    }/*from   w  w  w  .ja  v  a  2s  . c  o  m*/
    // Handle your other action bar items...
    int itemId = item.getItemId();
    if (itemId == android.R.id.home) {
        if (showingEditor) {
            // Only true in portrait mode
            final View focusView = ActivityMain.this.getCurrentFocus();
            if (inputManager != null && focusView != null) {
                inputManager.hideSoftInputFromWindow(focusView.getWindowToken(),
                        InputMethodManager.HIDE_NOT_ALWAYS);
            }

            // Should load the same list again
            // Try getting the list from the original intent
            final long listId = getListId(getIntent());

            final Intent intent = new Intent().setAction(Intent.ACTION_VIEW).setClass(ActivityMain.this,
                    ActivityMain_.class);
            if (listId > 0) {
                intent.setData(TaskList.getUri(listId));
            }

            // Set the intent before, so we set the correct
            // action bar
            setIntent(intent);
            while (getSupportFragmentManager().popBackStackImmediate()) {
                // Need to pop the entire stack and then load
            }

            reverseAnimation = true;
            Log.d("nononsenseapps fragment", "starting activity");

            intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(intent);
        }
        // else
        // Handled by drawer
        return true;
    } else if (itemId == R.id.drawer_menu_createlist) {
        // Show fragment
        DialogEditList_ dialog = DialogEditList_.getInstance();
        dialog.setListener(new EditListDialogListener() {

            @Override
            public void onFinishEditDialog(long id) {
                openList(id);
            }
        });
        dialog.show(getSupportFragmentManager(), "fragment_create_list");
        return true;
    } else if (itemId == R.id.menu_preferences) {
        Intent intent = new Intent();
        intent.setClass(this, PrefsActivity.class);
        startActivity(intent);
        return true;
    } else if (itemId == R.id.menu_donate) {
        try {
            mBillingHelper.launchPurchaseFlow(this, SKU_INAPP_PREMIUM, SKU_DONATE_REQUEST_CODE,
                    new IabHelper.OnIabPurchaseFinishedListener() {
                        public void onIabPurchaseFinished(IabResult result, Purchase purchase) {
                            if (result.isFailure()) {
                                Log.d("nononsenseapps billing", "Error purchasing: " + result);
                                return;
                            } else if (purchase.getSku().equals(SKU_INAPP_PREMIUM)) {
                                mHasPremiumAccess = true;
                                mDonatedInApp = true;
                                // Save in prefs
                                PreferenceManager.getDefaultSharedPreferences(ActivityMain.this).edit()
                                        .putBoolean(SKU_INAPP_PREMIUM, true).putBoolean(PREMIUMSTATUS, true)
                                        .commit();
                                // Update relevant parts of UI
                                updateUiDonate();
                                // Notify user of success
                                Toast.makeText(ActivityMain.this, R.string.premiums_unlocked_and_thanks,
                                        Toast.LENGTH_SHORT).show();
                            }
                        }
                    });
        } catch (Exception e) {
            Log.d("nononsenseapps billing", "Shouldnt start two purchases! " + e.getLocalizedMessage());
        }
        return true;
    } else if (itemId == R.id.menu_sync) {
        handleSyncRequest();
        return true;
    } else if (itemId == R.id.menu_delete) {
        return false;
    } else {
        return false;
    }
}

From source file:de.questmaster.fatremote.fragments.RemoteFragment.java

private void hideKeyboard() {
    EditText text = (EditText) c.findViewById(R.id.enterText);
    ImageView button = (ImageView) c.findViewById(R.id.textButton);

    // clear entered Text
    text.setText("");

    // hide text field
    text.setVisibility(View.GONE);
    button.setVisibility(View.VISIBLE);

    // hide keyboard
    InputMethodManager mgr = (InputMethodManager) c.getSystemService(Context.INPUT_METHOD_SERVICE);
    mgr.hideSoftInputFromWindow(text.getApplicationWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
}

From source file:com.app.khclub.base.easeim.activity.ContactlistFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    // T??home???appcrash
    if (savedInstanceState != null && savedInstanceState.getBoolean("isConflict", false))
        return;/* w ww . j ava 2 s .  com*/
    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>();
    // ?contactlist
    getContactList();

    // ?
    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) {
            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();
            hideSoftKeyboard();
        }
    });

    // 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 = ((KHHXSDKHelper) HXSDKHelper.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 if (Constant.CHAT_ROOM.equals(username)) {
                // ??
                startActivity(new Intent(getActivity(), PublicChatRoomsActivity.class));
            } else if (Constant.CHAT_ROBOT.equals(username)) {
                // // Robot?
                // startActivity(new Intent(getActivity(),
                // RobotsActivity.class));
                // ???
                Intent intentToCardList = new Intent(getActivity(), CollectCardActivity.class);
                startActivity(intentToCardList);
                // ?
                getActivity().overridePendingTransition(R.anim.push_right_in, R.anim.push_right_out);
            } else {
                // demo??
                // startActivity(new Intent(getActivity(),
                // ChatActivity.class)
                // .putExtra("userId", adapter.getItem(position)
                // .getUsername()));
                // ?
                Intent intent = new Intent(getActivity(), OtherPersonalActivity.class);
                intent.putExtra(OtherPersonalActivity.INTENT_KEY,
                        KHUtils.stringToInt(adapter.getItem(position).getUsername().replace(KHConst.KH, "")));
                startActivity(intent);
                getActivity().overridePendingTransition(R.anim.push_right_in, R.anim.push_right_out);
            }
        }
    });
    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;
        }
    });

    // ?
    qrImageView = new QRCodePopupMenu(getActivity());
    final ImageView operateMenuView = (ImageView) getView().findViewById(R.id.iv_new_contact);
    // ???
    operateMenuView.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            if (null == mainMenu) {
                mainMenu = new MainPopupMenu(getActivity());
                mainMenu.setListener(new ClickListener() {

                    @Override
                    public void scanQRcodeClick() {
                        // ???
                        Intent intent = new Intent();
                        intent.setClass(getActivity(), MipcaCaptureActivity.class);
                        startActivityForResult(intent, SCANNIN_GREQUEST_CODE);
                    }

                    @Override
                    public void searchClick() {
                        // ??
                        Intent intentToSearch = new Intent(getActivity(), SearchActivity.class);
                        startActivity(intentToSearch);
                        // ?
                        getActivity().overridePendingTransition(R.anim.push_right_in, R.anim.push_right_out);
                    }

                    @Override
                    public void createGroupClick() {
                        // ?
                        startActivity(new Intent(getActivity(), NewGroupActivity.class));
                        getActivity().overridePendingTransition(R.anim.push_right_in, R.anim.push_right_out);
                    }

                    @Override
                    public void userQRShowClick() {
                        // TODO ?
                        qrImageView.setQRcode(false);
                        qrImageView.showPopupWindow((RelativeLayout) getView().findViewById(R.id.title_bar));
                    }
                });
            }
            mainMenu.showPopupWindow(operateMenuView);
            // startActivity(new Intent(getActivity(),
            // AddContactActivity.class));
        }
    });
    registerForContextMenu(listView);

    progressBar = (View) getView().findViewById(R.id.progress_bar);

    contactSyncListener = new HXContactSyncListener();
    HXSDKHelper.getInstance().addSyncContactListener(contactSyncListener);

    blackListSyncListener = new HXBlackListSyncListener();
    HXSDKHelper.getInstance().addSyncBlackListListener(blackListSyncListener);

    contactInfoSyncListener = new HXContactInfoSyncListener();
    ((KHHXSDKHelper) HXSDKHelper.getInstance()).getUserProfileManager()
            .addSyncContactInfoListener(contactInfoSyncListener);

    if (!HXSDKHelper.getInstance().isContactsSyncedWithServer()) {
        progressBar.setVisibility(View.VISIBLE);
    } else {
        progressBar.setVisibility(View.GONE);
    }
}

From source file:com.vinexs.tool.Utility.java

public static void hideKeyBroad(Activity activity) {
    try {//from  ww  w  .  ja va2s  .com
        View currentView = activity.getCurrentFocus();
        if (currentView == null) {
            throw new Exception("Cannot get current focus");
        }
        InputMethodManager inputMethodManager = (InputMethodManager) activity
                .getSystemService(Context.INPUT_METHOD_SERVICE);
        inputMethodManager.hideSoftInputFromWindow(currentView.getWindowToken(),
                InputMethodManager.HIDE_NOT_ALWAYS);
    } catch (Exception ignored) {
    }
}

From source file:com.ferid.app.classroom.edit.EditClassroomFragment.java

/**
 * Closes keyboard for disabling interruption
 */// w  w  w.  j  av  a 2s  .co  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 ignored) {
    }
}

From source file:cs.man.ac.uk.tavernamobile.fragments.SearchResultFragment.java

private void hideKeyboard() {
    InputMethodManager inputManager = (InputMethodManager) parentActivity
            .getSystemService(Context.INPUT_METHOD_SERVICE);

    inputManager.hideSoftInputFromWindow(parentActivity.getCurrentFocus().getWindowToken(),
            InputMethodManager.HIDE_NOT_ALWAYS);
}

From source file:com.smartcodeunited.demo.bluetooth.activity.BaseActivity.java

/**
 * Hide the input method/* w ww. j a  v  a2s  .c  o  m*/
 */
public void hideInputMethod(View view) {
    InputMethodManager m = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
    if (getCurrentFocus() != null && m.isActive()) {
        if (view == null) {
            view = getCurrentFocus();
        }
        m.hideSoftInputFromWindow(view.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
    }
}

From source file:org.zywx.wbpalmstar.engine.EBrowserWidgetPool.java

private void closeCurrentWidget(EBrowserWidget closeWgt, final String inResultInfo) {
    EBrowser.clearFlag();//  w w w. j a va2 s  . c o  m
    final EBrowserWidget outWidget;
    final EBrowserWidget inWidget;
    if (null != closeWgt) {
        outWidget = closeWgt;
        int outIndex = mWgtStack.indexOf(outWidget);
        inWidget = mWgtStack.get(outIndex - 1);
    } else {
        outWidget = mWgtStack.peek();
        inWidget = mWgtStack.prev();
    }
    if (null == inWidget || null == outWidget) {
        return;
    }
    final EWgtResultInfo reInfo = outWidget.getResult();
    int animiId = 0;
    long duration = 0;
    if (null != reInfo) {
        animiId = reInfo.getContraryAnimiId();
        duration = reInfo.getDuration();
    }
    Animation[] animPair = EBrowserAnimation.getAnimPair(animiId, duration);
    Animation inAnim = animPair[0];
    Animation outAnim = animPair[1];
    outAnim.setAnimationListener(new AnimationListener() {
        public void onAnimationStart(Animation animation) {
        }

        public void onAnimationRepeat(Animation animation) {
        }

        public void onAnimationEnd(Animation animation) {
            outWidget.removeAllViews();
            outWidget.destroy();
            mWgtStack.remove(outWidget);
            mNativeWindow.removeView(outWidget);
            inWidget.notifyVisibilityChanged(0);
            if (inWidget.checkWidgetType(EBrowserWidget.F_WIDGET_POOL_TYPE_ROOT)) {
                if (null == mAppCenter || (null != mAppCenter && !mAppCenter.isShown())) {
                    showHover(false);
                } else {
                    mAppCenter.notifyBackToAppCenter();
                    hiddenHover(false);
                    return;
                }
            }
            String callback = null;
            if (null != reInfo) {
                callback = reInfo.getCallBack();
            }
            inWidget.onWidgetResult(callback, inResultInfo);

            WWidgetData wgtData = inWidget.getWidget();
            int wgtOrientation = wgtData.m_orientation;
            mContext.changeConfiguration(wgtOrientation);
        }
    });
    inWidget.setVisibility(View.VISIBLE);
    outWidget.startAnimation(outAnim);
    inWidget.startAnimation(inAnim);

    try {
        int versionA = Build.VERSION.SDK_INT;
        if (versionA == 19) {
            InputMethodManager imm = (InputMethodManager) mContext
                    .getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(((EBrowserActivity) mContext).getCurrentFocus().getWindowToken(),
                    InputMethodManager.HIDE_NOT_ALWAYS);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}