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.firesoft.member.Activity.B2_SignupActivity.java

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

From source file:de.geeksfactory.opacclient.frontend.OpacActivity.java

protected void setupDrawer() {
    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);

    drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    if (drawerLayout != null) {
        hasDrawer = true;//from w  ww.jav  a 2s.co  m
        drawerToggle = new ActionBarDrawerToggle(this, /* host Activity */
                drawerLayout, /* DrawerLayout object */
                R.drawable.ic_navigation_drawer, /*
                                                 * nav drawer icon to replace 'Up'
                                                 * caret
                                                 */
                R.string.drawer_open, /* "open drawer" description */
                R.string.drawer_close /* "close drawer" description */
        ) {

            /**
             * Called when a drawer has settled in a completely closed
             * state.
             */
            @Override
            public void onDrawerClosed(View view) {
                super.onDrawerClosed(view);
                getSupportActionBar().setTitle(mTitle);
            }

            /** Called when a drawer has settled in a completely open state. */
            @Override
            public void onDrawerOpened(View drawerView) {
                super.onDrawerOpened(drawerView);
                getSupportActionBar().setTitle(app.getResources().getString(R.string.app_name));
                if (getCurrentFocus() != null) {
                    InputMethodManager imm = (InputMethodManager) getSystemService(
                            Context.INPUT_METHOD_SERVICE);
                    imm.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);
                }
            }
        };

        // Set the drawer toggle as the DrawerListener
        drawerLayout.setDrawerListener(drawerToggle);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setHomeButtonEnabled(true);

        drawerList = (ListView) findViewById(R.id.drawer_list);
        navAdapter = new NavigationAdapter(this);
        drawerList.setAdapter(navAdapter);
        navAdapter.addSeperatorItem(getString(R.string.nav_hl_library));
        navAdapter.addTextItemWithIcon(getString(R.string.nav_search), R.drawable.ic_action_search, "search");
        navAdapter.addTextItemWithIcon(getString(R.string.nav_account), R.drawable.ic_action_account,
                "account");
        navAdapter.addTextItemWithIcon(getString(R.string.nav_starred), R.drawable.ic_action_star_1, "starred");
        navAdapter.addTextItemWithIcon(getString(R.string.nav_info), R.drawable.ic_action_info, "info");

        aData.open();
        accounts = aData.getAllAccounts();
        if (accounts.size() > 1) {
            navAdapter.addSeperatorItem(getString(R.string.nav_hl_accountlist));

            long tolerance = Long.decode(sp.getString("notification_warning", "367200000"));
            int selected = -1;
            for (final Account account : accounts) {
                Library library;
                try {
                    library = ((OpacClient) getApplication()).getLibrary(account.getLibrary());
                    int expiring = aData.getExpiring(account, tolerance);
                    String expiringText = "";
                    if (expiring > 0) {
                        expiringText = String.valueOf(expiring);
                    }
                    if (getString(R.string.default_account_name).equals(account.getLabel())) {
                        navAdapter.addLibraryItem(library.getCity(), library.getTitle(), expiringText,
                                account.getId());
                    } else {
                        navAdapter.addLibraryItem(account.getLabel(),
                                library.getCity() + "  " + library.getTitle(), expiringText, account.getId());
                    }
                    if (account.getId() == app.getAccount().getId()) {
                        selected = navAdapter.getCount() - 1;
                    }

                } catch (IOException e) {
                    e.printStackTrace();
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
            if (selected > 0) {
                drawerList.setItemChecked(selected, true);
            }
        }

        navAdapter.addSeperatorItem(getString(R.string.nav_hl_other));
        navAdapter.addTextItemWithIcon(getString(R.string.nav_settings), R.drawable.ic_action_settings,
                "settings");
        navAdapter.addTextItemWithIcon(getString(R.string.nav_about), R.drawable.ic_action_help, "about");

        drawerList.setOnItemClickListener(new DrawerItemClickListener());

        if (!sp.getBoolean("version2.0.0-introduced", false) && app.getSlidingMenuEnabled()) {
            final Handler handler = new Handler();
            // Just show the menu to explain that is there if people start
            // version 2 for the first time.
            // We need a handler because if we just put this in onCreate
            // nothing
            // happens. I don't have any idea, why.
            handler.postDelayed(new Runnable() {
                @Override
                public void run() {
                    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(OpacActivity.this);
                    drawerLayout.openDrawer(drawerList);
                    sp.edit().putBoolean("version2.0.0-introduced", true).commit();
                }
            }, 500);

        }
    }
}

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

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    //T??home???appcrash
    if (savedInstanceState != null && savedInstanceState.getBoolean("isConflict", false))
        return;// ww w  .j  a  v a2  s  . co  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);
    getView().findViewById(R.id.back).setOnClickListener(this);
    //???
    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 = ((DemoHXSDKHelper) 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));
            //            }
            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);

    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();
    ((DemoHXSDKHelper) HXSDKHelper.getInstance()).getUserProfileManager()
            .addSyncContactInfoListener(contactInfoSyncListener);

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

From source file:com.lee.sdk.utils.Utils.java

/**
 * Hides the input method./* ww  w.  ja  v  a  2s.  co  m*/
 * 
 * @param context context
 * @param view The currently focused view
 * @return success or not.
 */
public static boolean hideInputMethod(Context context, View view) {
    if (context == null || view == null) {
        return false;
    }

    InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
    if (imm != null) {
        return imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
    }

    return false;
}

From source file:com.dhaval.mobile.plugin.ChildBrowser.java

/**
 * Navigate to the new page//from   w w w. j  a v  a 2 s . c o  m
 * 
 * @param url to load
 */
private void navigate(String url) {
    InputMethodManager imm = (InputMethodManager) this.ctx.getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.hideSoftInputFromWindow(edittext.getWindowToken(), 0);

    if (!url.startsWith("http") && !url.startsWith("file:")) {
        this.webview.loadUrl("http://" + url);
    } else {
        this.webview.loadUrl(url);
    }
    this.webview.requestFocus();
}

From source file:com.phonegap.plugins.slaveBrowser.SlaveBrowser.java

/**
 * Navigate to the new page//w w w .  j  a  v a  2 s.  com
 * 
 * @param url to load
 */
private void navigate(String url) {
    InputMethodManager imm = (InputMethodManager) this.ctx.getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.hideSoftInputFromWindow(edittext.getWindowToken(), 0);
    if (!url.startsWith("http")) {
        this.webview.loadUrl("http://" + url);
    }
    this.webview.loadUrl(url);
    this.webview.requestFocus();
}

From source file:edu.rit.csh.androidwebnews.PostSwipeableActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getSupportMenuInflater().inflate(R.menu.postswipable_menu, menu);
    // Get the SearchView and set the searchable configuration
    final SearchView searchView = (SearchView) menu.findItem(R.id.menu_search).getActionView();
    searchView.setIconifiedByDefault(false); // Do not iconify the widget; expand it by default
    SearchView.OnQueryTextListener queryTextListener = new SearchView.OnQueryTextListener() {
        public boolean onQueryTextChange(String newText) {
            return true;
        }/*  w  w w . j a v a2s .co  m*/

        public boolean onQueryTextSubmit(String query) {
            InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(searchView.getWindowToken(), 0);
            Intent intent = new Intent(PostSwipeableActivity.this, SearchResultsActivity.class);
            HashMap<String, String> params = new HashMap<String, String>();
            params.put("keywords", query);
            intent.putExtra("params", params);
            startActivity(intent);
            return true;
        }
    };
    searchView.setOnQueryTextListener(queryTextListener);
    return super.onCreateOptionsMenu(menu);
}

From source file:net.bytten.comicviewer.ComicViewerActivity.java

protected void resetContent() {
    comicDef = makeComicDef();//from   ww w . java 2s .c  o  m
    provider = comicDef.getProvider();
    comicInfo = provider.createEmptyComicInfo();

    //Only hide the title bar if we're running an android less than Android 3.0
    if (VersionHacks.getSdkInt() < 11)
        requestWindowFeature(Window.FEATURE_NO_TITLE);

    setContentView(R.layout.main);
    webview = (HackedWebView) findViewById(R.id.viewer);
    title = (TextView) findViewById(R.id.title);
    comicIdSel = (EditText) findViewById(R.id.comicIdSel);

    webview.requestFocus();
    zoom = webview.getZoomControls();

    webview.setClickable(true);
    webview.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            if (!"".equals(comicInfo.getAlt()))
                showDialog(DIALOG_SHOW_HOVER_TEXT);
        }
    });

    title.setText(comicInfo.getTitle());

    comicIdSel.setText(comicInfo.getId());
    if (comicDef.idsAreNumbers())
        comicIdSel.setInputType(InputType.TYPE_CLASS_NUMBER);
    comicIdSel.setOnEditorActionListener(new OnEditorActionListener() {
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            String text = comicIdSel.getText().toString();
            if (!text.equals("") && (actionId == EditorInfo.IME_ACTION_GO
                    || (actionId == EditorInfo.IME_NULL && event.getKeyCode() == KeyEvent.KEYCODE_ENTER))) {
                loadComic(createComicUri(text));
                comicIdSel.setText("");
                return true;
            }
            return false;
        }
    });
    comicIdSel.setOnFocusChangeListener(new OnFocusChangeListener() {
        public void onFocusChange(View v, boolean hasFocus) {
            InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
            if (hasFocus) {
                comicIdSel.setText("");
                imm.showSoftInput(comicIdSel, InputMethodManager.SHOW_IMPLICIT);
            } else {
                imm.hideSoftInputFromWindow(comicIdSel.getWindowToken(), 0);
            }
        }
    });

    ((Button) findViewById(R.id.firstBtn)).setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            goToFirst();
        }
    });

    ((Button) findViewById(R.id.prevBtn)).setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            goToPrev();
        }
    });

    ((Button) findViewById(R.id.nextBtn)).setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            goToNext();
        }
    });

    ((Button) findViewById(R.id.finalBtn)).setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            goToFinal();
        }
    });

    ((ImageView) findViewById(R.id.randomBtn)).setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            goToRandom();
        }
    });

    bookmarkBtn = (ImageView) findViewById(R.id.bookmarkBtn);
    bookmarkBtn.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            toggleBookmark();
        }
    });
    refreshBookmarkBtn();
}

From source file:prince.app.ccm.Fragment_Log.java

private void initView(View view) {
    // Set up the login form.
    mUserEditText = (EditText) view.findViewById(R.id.username);
    //   addFocusListener(mUserEditText);

    mPasswordEditText = (EditText) view.findViewById(R.id.password);
    //   addFocusListener(mPasswordEditText);

    mPasswordEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override// w w  w. ja v  a2  s.c om
        public boolean onEditorAction(TextView textView, int id, KeyEvent keyEvent) {
            if (id == R.id.user_login || id == EditorInfo.IME_NULL) {
                if (!Tool.getInstance().isConnection())
                    Toast.makeText(getActivity(), "No network connection!", Toast.LENGTH_SHORT).show();
                else {
                    attemptLogin();
                    return true;
                }
            }
            return false;
        }
    });

    mLoginFormView = view.findViewById(R.id.login_form);
    mLoginStatusView = view.findViewById(R.id.login_progress);

    view.findViewById(R.id.sign_in_button).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            InputMethodManager imm = (InputMethodManager) getActivity()
                    .getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
            attemptLogin();
        }
    });

    mRemind = (CheckBox) view.findViewById(R.id.box_remember);
    if (Tool.getInstance().getBolPref(Util.REMIND)) {
        mRemind.setChecked(true);
        mUserEditText.setText("");
        mPasswordEditText.setText("");
        mUserEditText.append(Tool.getInstance().getStringPref(Util.USER));
        mPasswordEditText.append(Tool.getInstance().getStringPref(Util.PASSWORD));
    }

    mShowPassword = (CheckBox) view.findViewById(R.id.box_reveal);
    mShowPassword.setOnCheckedChangeListener(new OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (isChecked) {
                mPasswordEditText.setInputType(InputType.TYPE_TEXT_VARIATION_PASSWORD);
            } else {
                mPasswordEditText
                        .setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
            }

            if (mPasswordEditText.hasFocus()) {
                String temp = mPasswordEditText.getText().toString().trim();
                mPasswordEditText.setText("");
                mPasswordEditText.append(temp);
            }

        }

    });
}