Example usage for android.content Context INPUT_METHOD_SERVICE

List of usage examples for android.content Context INPUT_METHOD_SERVICE

Introduction

In this page you can find the example usage for android.content Context INPUT_METHOD_SERVICE.

Prototype

String INPUT_METHOD_SERVICE

To view the source code for android.content Context INPUT_METHOD_SERVICE.

Click Source Link

Document

Use with #getSystemService(String) to retrieve a android.view.inputmethod.InputMethodManager for accessing input methods.

Usage

From source file:com.eugene.fithealthmaingit.UI.ChooseAddMealSearchFragment.java

@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
        @Nullable Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.fragment_search_add_item_fatsecret, container, false);
    // Change the notification bar color
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        Window w = getActivity().getWindow();
        w.setStatusBarColor(getResources().getColor(R.color.light_grey));
    }//from  w w w .  j a  v a2s  . c o m
    // Get MealType (snack, breakfast, lunch, dinner)
    Bundle extras = getActivity().getIntent().getExtras();
    if (extras != null) {
        mealType = extras.getString(Globals.MEAL_TYPE);
    }
    // Initialize FatSecretSearchMethod
    mFatSecretSearch = new FatSecretSearchMethod();

    mSwipeRefreshLayout = (SwipeRefreshLayout) v.findViewById(R.id.swiperefresh);
    mSwipeRefreshLayout.setColorSchemeResources(R.color.primary, R.color.red, R.color.primary_dark);
    mSwipeRefreshLayout.setProgressViewOffset(true, Equations.dpToPx(getActivity(), 0),
            Equations.dpToPx(getActivity(), 112));
    mSwipeRefreshLayout.setEnabled(false);

    mEtSearch = (EditText) v.findViewById(R.id.etSearch);
    // LogQuickSearch adapter to add items that have not been saved already
    mRecentLogAdapter = new LogQuickSearchAdapter(getActivity(), 0, LogQuickSearch.all());
    // List for adding items to the
    mItem = new ArrayList<>();
    // Set to prevent duplicates being saved in LogQuickSearch
    set = new HashSet<>();
    /**
     * set mListViewSearchResults adapter to SearchAdapterItemResult
     */
    llSearch = (LinearLayout) v.findViewById(R.id.llSearch);
    listSearch = (ListView) v.findViewById(R.id.listSearch);
    searchLine = v.findViewById(R.id.searchLine);
    logQuickSearchAdapter = new LogQuickSearchAdapter(getActivity(), 0, LogQuickSearch.all());
    mEtSearchAdapter = new SearchAdapterItemResult(getActivity(), mItem);

    mListViewSearchResults = (ListView) v.findViewById(R.id.listView);
    ViewGroup header = (ViewGroup) inflater.inflate(R.layout.list_search_header, mListViewSearchResults, false);
    mListViewSearchResults.addHeaderView(header, null, false);
    mListViewSearchResults.setAdapter(mEtSearchAdapter);
    mListViewSearchResults.setOnScrollListener(this);
    mListViewSearchResults.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            Intent i = new Intent(getActivity(), SaveSearchAddItemActivityMain.class);
            i.putExtra(Globals.MEAL_TYPE, mealType);
            i.putExtra(Globals.MEAL_ID, mItem.get(position - 1).getID());
            i.putExtra(Globals.MEAL_BRAND, mItem.get(position - 1).getBrand());
            i.putExtra(Globals.MEAL_FAVORITE, "false");
            startActivity(i);
        }
    });
    // Toolbar
    mToolbarSearch = (Toolbar) v.findViewById(R.id.toolbar_search);
    mToolbarSearch.inflateMenu(R.menu.menu_search);
    mToolbarSearch.setNavigationIcon(R.mipmap.ic_arrow_back_grey);
    mToolbarSearch.setNavigationOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            getActivity().getSupportFragmentManager().popBackStack();
        }
    });
    mToolbarSearch.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem menuItem) {
            if (menuItem.getItemId() == R.id.action_clear) {
                mEtSearch.setText("");
            }
            if (menuItem.getItemId() == R.id.action_voice) {
                promptSpeechInput();
            }
            return false;
        }
    });
    mEtSearch.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            if (mEtSearch.getText().toString().length() >= 1) {
                mToolbarSearch.getMenu().clear();
                mToolbarSearch.inflateMenu(R.menu.menu_search_clear);
                logQuickSearchAdapter = new LogQuickSearchAdapter(getActivity(), 0,
                        LogQuickSearch.FilterByName(mEtSearch.getText().toString()));
                listSearch.setAdapter(logQuickSearchAdapter);
            } else {
                mToolbarSearch.getMenu().clear();
                mToolbarSearch.inflateMenu(R.menu.menu_search);
                logQuickSearchAdapter = new LogQuickSearchAdapter(getActivity(), 0, LogQuickSearch.all());
                listSearch.setAdapter(logQuickSearchAdapter);
            }
            mItem.clear();
            updateListView();
        }

        @Override
        public void afterTextChanged(Editable s) {
        }
    });

    // Quick Search Clicked, start search based on list Item clicked from last fragment
    Bundle extrasFromRecentCliced = this.getArguments();
    if (extrasFromRecentCliced != null) {
        String mealName = extrasFromRecentCliced.getString("MealName");
        if (mealName != null) {
            mEtSearch.setText(mealName);
            mToolbarSearch.getMenu().clear();
            mToolbarSearch.inflateMenu(R.menu.menu_search_clear);
            searchFood(mealName, 0);
        }
    } else {
        mEtSearch.requestFocus();
        ((InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE))
                .toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);
    }
    /**
     * Handles softKeyboard search icon being clicked
     */
    mEtSearch.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_SEARCH) {
                ((InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE))
                        .hideSoftInputFromWindow(mEtSearch.getWindowToken(), 0);
                listSearch.setVisibility(View.GONE);
                searchLine.setVisibility(View.GONE);
                searchFood(mEtSearch.getText().toString(), 0);
                mItem.clear();
                mEtSearchAdapter.notifyDataSetChanged();
                mEtSearch.clearFocus();
                return true;
            }
            return false;
        }
    });

    listSearch.setAdapter(logQuickSearchAdapter);
    listSearch.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            LogQuickSearch logQuickSearch = logQuickSearchAdapter.getItem(position);
            mEtSearch.setText(logQuickSearch.getName());
            ((InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE))
                    .hideSoftInputFromWindow(mEtSearch.getWindowToken(), 0);
            listSearch.setVisibility(View.GONE);
            searchLine.setVisibility(View.GONE);
            searchFood(logQuickSearch.getName(), 0);
            mItem.clear();
            mEtSearchAdapter.notifyDataSetChanged();
            mEtSearch.clearFocus();
        }
    });
    updateListView();
    return v;
}

From source file:jp.mau.twappremover.MainActivity.java

/** ?? */
private void setButton() {
    Button btn = (Button) findViewById(R.id.activity_main_btn_submit);
    btn.setOnClickListener(new OnClickListener() {
        @Override//  www .  j  av a  2s  .com
        public void onClick(View v) {
            reset();
            // ???
            InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(v.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
            if (_id.getText().length() < 1 || _pass.getText().length() < 1) {
                // ???????
            } else {
                //                ?
                loginTask();
            }
        }
    });
}

From source file:com.sft.fragment.CoachsFragment1.java

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

        @Override// w ww . jav  a2s.  co m
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_SEARCH) {
                // ??
                ((InputMethodManager) searchCoach.getContext().getSystemService(Context.INPUT_METHOD_SERVICE))
                        .hideSoftInputFromWindow(getActivity().getCurrentFocus().getWindowToken(),
                                InputMethodManager.HIDE_NOT_ALWAYS);

                // ?
                LogUtil.print("?");
                coachname = searchCoach.getText().toString().trim();
                searchcoach(true);
                return true;
            }
            return false;
        }

    });
}

From source file:org.xingjitong.ChatFragment.java

@SuppressLint("Recycle")
@SuppressWarnings("static-access")
@Override/*from ww  w.j a v a 2 s. c  o m*/
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    SharedPreferences share = PreferenceManager.getDefaultSharedPreferences(getActivity());
    if (share.getInt(getString(R.string.setting_reg_uid), 0) == 0) {
        Toast.makeText(getActivity(), "!?,?!",
                Toast.LENGTH_LONG).show();
        getActivity().getSupportFragmentManager().popBackStack();
    }
    String displayName = getArguments().getString("DisplayName");
    String pictureUri = getArguments().getString("PictureUri");

    sipUri = getArguments().getString("SipUri");
    sipUri = sipUri.substring(sipUri.indexOf(":") + 1, sipUri.indexOf("@"));

    try {
        LinphoneAddress address = LinphoneManager.getInstance().getLc().interpretUrl(sipUri);
        sipUri = address.asString();
        sipUri = sipUri.replace("<", "").replace(">", "");
    } catch (LinphoneCoreException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    view = inflater.inflate(R.layout.chat, container, false);

    contactName = (TextView) view.findViewById(R.id.contactName);
    contactPicture = (AvatarWithShadow) view.findViewById(R.id.contactPicture);

    sendMessage = (TextView) view.findViewById(R.id.sendMessage);
    sendMessage.setOnClickListener(this);

    message = (EditText) view.findViewById(R.id.message);
    if (!getActivity().getResources().getBoolean(R.bool.allow_chat_multiline)) {
        message.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_SHORT_MESSAGE);
        message.setMaxLines(1);
    }

    uploadLayout = (RelativeLayout) view.findViewById(R.id.uploadLayout);
    textLayout = (RelativeLayout) view.findViewById(R.id.messageLayout);

    messagesLayout = (RelativeLayout) view.findViewById(R.id.messages);
    messagesScrollView = (ScrollView) view.findViewById(R.id.chatScrollView);
    progressBar = (ProgressBar) view.findViewById(R.id.progressbar);

    sendImage = (TextView) view.findViewById(R.id.sendPicture);
    registerForContextMenu(sendImage);
    sendImage.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            pickImage();
        }
    });

    cancelUpload = (ImageView) view.findViewById(R.id.cancelUpload);
    cancelUpload.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            uploadThread.interrupt();
            uploadLayout.setVisibility(View.GONE);
            textLayout.setVisibility(View.VISIBLE);
            progressBar.setProgress(0);
        }
    });

    displayChat(displayName, pictureUri);

    LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull();
    if (lc != null) {
        chatRoom = lc.createChatRoom(sipUri);
    }

    // SharedPreferences prefs =
    // PreferenceManager.getDefaultSharedPreferences(LinphoneActivity.instance());
    // uploadServerUri =
    // prefs.getString(getString(R.string.pref_image_sharing_server_key),
    // getString(R.string.pref_image_sharing_server_default));
    uploadServerUri = getString(R.string.pref_image_sharing_server_default);

    textWatcher = new TextWatcher() {
        public void afterTextChanged(Editable arg0) {

        }

        public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {

        }

        public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
            if (message.getText().toString().equals("")) {
                sendMessage.setEnabled(false);
            } else {
                sendMessage.setEnabled(true);
            }
        }
    };

    // Force hide keyboard
    if (LinphoneActivity.isInstanciated()) {
        InputMethodManager imm = (InputMethodManager) LinphoneActivity.instance()
                .getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
    }

    // Workaround for SGS3 issue
    if (savedInstanceState != null) {
        fileToUploadPath = savedInstanceState.getString("fileToUploadPath");
        imageToUpload = savedInstanceState.getParcelable("imageToUpload");
    }
    if (fileToUploadPath != null || imageToUpload != null) {
        sendImage.post(new Runnable() {
            @Override
            public void run() {
                sendImage.showContextMenu();
            }
        });
    }

    return view;
}

From source file:com.chalmers.schmaps.CheckInActivity.java

/***************************************************************************
 *     When user enters her/his name and presses check-in the information is sent to an external server
 *   Returened is a jsonobject with all postions where people have checked in the last hour
 *   Start new activity that will show the information on a map
 *************************************************************************/
public void onClick(View v) {
    InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.hideSoftInputFromWindow(enterName.getWindowToken(), 0);
    checkin = true;/*ww  w  .j a v a2 s  .c  o  m*/

    username = enterName.getText().toString();
    //removes white signs
    username.trim();
    //Removes illegal characters to prevent sql injection
    username = username.replaceAll("[^[a-z][A-Z][0-9]]", "");

    //if the user have not entered a name the name is set to unknown
    if (username.equals("")) {
        username = "Unknown";
    }
    connectExternalDatabase();
    checkin = false;
}

From source file:com.pentacog.mctracker.MCServerTrackerActivity.java

/**
* @see android.app.Activity#onKeyDown(int, android.view.KeyEvent)
*//*from  ww  w  .  j  a  va2  s.  com*/
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {

    if (keyCode == KeyEvent.KEYCODE_SEARCH) {
        InputMethodManager mgr = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
        mgr.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
        return true;
    }
    return super.onKeyDown(keyCode, event);
}

From source file:com.firesoft.member.Activity.C1_PublishOrderActivity.java

private void CloseKeyBoard() {
    InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.hideSoftInputFromWindow(member_no.getWindowToken(), 0);
}