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.radicaldynamic.groupinform.application.Collect.java

/**
 * Creates and displays a dialog displaying the violated constraint.
 *//*from  ww w  .  j av a  2  s  .  co  m*/
public void showSoftKeyboard(View v) {
    InputMethodManager inputManager = (InputMethodManager) getBaseContext()
            .getSystemService(Context.INPUT_METHOD_SERVICE);

    IBinder b = v.getWindowToken();
    if (viewToken != null && !viewToken.equals(b)) {
        inputManager.hideSoftInputFromInputMethod(viewToken, 0);
    }

    if (inputManager.isActive(v))
        return;
    inputManager.showSoftInput(v, 0);
    viewToken = b;
}

From source file:com.google.maps.android.utils.demo.HeatmapsPlacesDemoActivity.java

/**
 * Takes the input from the user and generates the required heatmap.
 * Called when a search query is submitted
 *//*from  ww  w .  j a  v  a  2  s  .com*/
public void submit() {
    if ("YOUR_KEY_HERE".equals(API_KEY)) {
        Toast.makeText(this,
                "Please sign up for a Places API key and add it to HeatmapsPlacesDemoActivity.API_KEY",
                Toast.LENGTH_LONG).show();
        return;
    }
    EditText editText = (EditText) findViewById(R.id.input_text);
    String keyword = editText.getText().toString();
    if (mOverlays.contains(keyword)) {
        Toast.makeText(this, "This keyword has already been inputted :(", Toast.LENGTH_SHORT).show();
    } else if (mOverlaysRendered == MAX_CHECKBOXES) {
        Toast.makeText(this, "You can only input " + MAX_CHECKBOXES + " keywords. :(", Toast.LENGTH_SHORT)
                .show();
    } else if (keyword.length() != 0) {
        mOverlaysInput++;
        ProgressBar progressBar = (ProgressBar) findViewById(R.id.progress_bar);
        progressBar.setVisibility(View.VISIBLE);
        new MakeOverlayTask().execute(keyword);
        editText.setText("");

        InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(editText.getWindowToken(), 0);
    }
}

From source file:org.envirocar.app.activity.LoginFragment.java

/**
 * Attempts to sign in or register the account specified by the login form.
 * If there are form errors (invalid email, missing fields, etc.), the
 * errors are presented and no actual login attempt is made.
 *///w w w .j  av  a 2 s . c o  m
private void attemptLogin() {

    // Reset errors.
    mUsernameView.setError(null);
    mPasswordView.setError(null);

    if (mAuthTask != null) {
        return;
    }

    // Store values at the time of the login attempt.
    mUsername = mUsernameView.getText().toString();
    mPassword = mPasswordView.getText().toString();

    boolean cancel = false;
    View focusView = null;

    // Check for a valid password.
    if (TextUtils.isEmpty(mPassword)) {
        mPasswordView.setError(getString(R.string.error_field_required));
        focusView = mPasswordView;
        cancel = true;
    } else if (mPassword.length() < 6) {
        mPasswordView.setError(getString(R.string.error_invalid_password));
        focusView = mPasswordView;
        cancel = true;
    }

    // Check for a valid email address.
    if (TextUtils.isEmpty(mUsername)) {
        mUsernameView.setError(getString(R.string.error_field_required));
        focusView = mUsernameView;
        cancel = true;
    }

    if (cancel) {
        // There was an error; don't attempt login and focus the first
        // form field with an error.
        focusView.requestFocus();
    } else {
        // hide the keyboard
        InputMethodManager imm = (InputMethodManager) getActivity()
                .getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(mPasswordView.getWindowToken(), 0);

        // Show a progress spinner, and kick off a background task to
        // perform the user login attempt.
        mLoginStatusMessageView.setText(R.string.login_progress_signing_in);
        showProgress(true);
        mAuthTask = new UserLoginTask();
        mAuthTask.execute((Void) null);
    }
}

From source file:org.sirimangalo.meditationplus.ActivityMain.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

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

    context = this;

    prefs = PreferenceManager.getDefaultSharedPreferences(this);

    postTask = new PostTaskRunner(postHandler, this);

    // Create a new service client and bind our activity to this service
    scheduleClient = new ScheduleClient(this);
    scheduleClient.doBindService();//w w  w  .  j a  va2  s . c o m

    mAlarmMgr = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
    mNM = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);

    setContentView(R.layout.activity_main);

    onlineList = (TextView) findViewById(R.id.online);

    resultReceiver = new MyResultReceiver(null);

    // loading dialog
    loadingDialog = new ProgressDialog(this);
    loadingDialog.setTitle(R.string.processing);

    // Set up the action bar.
    final ActionBar actionBar = getSupportActionBar();
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    // Create the adapter that will return a fragment for each of the three
    // primary sections of the activity.
    mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());

    // Set up the ViewPager with the sections adapter.
    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setAdapter(mSectionsPagerAdapter);

    // When swiping between different sections, select the corresponding
    // tab. We can also use ActionBar.Tab#select() to do this if we have
    // a reference to the Tab.
    mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {

            // close keyboard

            View view = getCurrentFocus();
            if (view != null) {
                inputManager.hideSoftInputFromWindow(view.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
            }

            // reset chat title

            if (position == 1 && newChats) {
                if (actionBar.getTabAt(1) != null)
                    actionBar.getTabAt(1)
                            .setText(getString(R.string.title_section2).toUpperCase(Locale.getDefault()));
                newChats = false;
            }

            currentPosition = position;
            actionBar.setSelectedNavigationItem(position);
        }
    });
    mViewPager.setOffscreenPageLimit(2);

    // For each of the sections in the app, add a tab to the action bar.
    for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) {
        // Create a tab with text corresponding to the page title defined by
        // the adapter. Also specify this Activity object, which implements
        // the TabListener interface, as the callback (listener) for when
        // this tab is selected.
        actionBar
                .addTab(actionBar.newTab().setText(mSectionsPagerAdapter.getPageTitle(i)).setTabListener(this));
    }
    username = prefs.getString("username", "");
    loginToken = prefs.getString("login_token", "");
    if (loginToken.equals(""))
        showLogin();

}

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

/**
 * Show the input method./* w  w  w. ja  v  a2 s.com*/
 * 
 * @param context context
 * @param view The currently focused view, which would like to receive soft keyboard input
 * @return success or not.
 */
public static boolean showInputMethod(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.showSoftInput(view, 0);
    }

    return false;
}

From source file:com.adguard.android.commons.RawResources.java

/**
 * Gets input languages/*from w  ww .ja v a2 s .c  o  m*/
 *
 * @param context Application context
 * @return List of input languages
 */
private static List<String> getInputLanguages(Context context) {
    List<String> languages = new ArrayList<>();

    try {
        InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
        List<InputMethodInfo> ims = imm.getEnabledInputMethodList();

        for (InputMethodInfo method : ims) {
            List<InputMethodSubtype> subMethods = imm.getEnabledInputMethodSubtypeList(method, true);
            for (InputMethodSubtype subMethod : subMethods) {
                if ("keyboard".equals(subMethod.getMode())) {
                    String currentLocale = subMethod.getLocale();
                    String language = cleanUpLanguageCode(new Locale(currentLocale).getLanguage());
                    if (!languages.contains(language)) {
                        languages.add(language);
                    }
                }
            }
        }
    } catch (Exception ex) {
        LOG.warn("Cannot get user input languages\r\n", ex);
    }

    return languages;
}

From source file:com.radicaldynamic.groupinform.application.Collect.java

public void hideSoftKeyboard(View c) {
    InputMethodManager inputManager = (InputMethodManager) getBaseContext()
            .getSystemService(Context.INPUT_METHOD_SERVICE);

    if (viewToken != null) {
        inputManager.hideSoftInputFromWindow(viewToken, 0);
    }//from   w  w w .  j av a2s.com
    viewToken = null;

    if (c != null) {
        if (inputManager.isActive()) {
            inputManager.hideSoftInputFromWindow(c.getApplicationWindowToken(), 0);
        }
    }
}

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

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

        @Override//from   ww w .j  a  v a2s .  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:org.cocos2dx.lib.TextInputWraper.java

protected void initView() {
    setEGLConfigChooser(8, 8, 8, 8, 16, 0);
    setZOrderOnTop(true);/*from   w w  w  .  j  a va  2  s. com*/
    getHolder().setFormat(PixelFormat.TRANSLUCENT);
    setFocusableInTouchMode(true);

    textInputWraper = new TextInputWraper(this);

    handler = new Handler() {
        public void handleMessage(Message msg) {
            switch (msg.what) {
            case HANDLER_OPEN_IME_KEYBOARD:
                if (null != mTextField && mTextField.requestFocus()) {
                    mTextField.removeTextChangedListener(textInputWraper);
                    mTextField.setText("");
                    String text = (String) msg.obj;
                    mTextField.append(text);
                    textInputWraper.setOriginText(text);
                    mTextField.addTextChangedListener(textInputWraper);
                    InputMethodManager imm = (InputMethodManager) mainView.getContext()
                            .getSystemService(Context.INPUT_METHOD_SERVICE);
                    imm.showSoftInput(mTextField, 0);
                    Log.d("GLSurfaceView", "showSoftInput");
                }
                break;

            case HANDLER_CLOSE_IME_KEYBOARD:
                if (null != mTextField) {
                    mTextField.removeTextChangedListener(textInputWraper);
                    InputMethodManager imm = (InputMethodManager) mainView.getContext()
                            .getSystemService(Context.INPUT_METHOD_SERVICE);
                    imm.hideSoftInputFromWindow(mTextField.getWindowToken(), 0);
                    Log.d("GLSurfaceView", "HideSoftInput");
                }
                break;
            }
        }
    };

    mainView = this;
}