Example usage for android.view.inputmethod InputMethodManager hideSoftInputFromWindow

List of usage examples for android.view.inputmethod InputMethodManager hideSoftInputFromWindow

Introduction

In this page you can find the example usage for android.view.inputmethod InputMethodManager hideSoftInputFromWindow.

Prototype

public boolean hideSoftInputFromWindow(IBinder windowToken, int flags) 

Source Link

Document

Synonym for #hideSoftInputFromWindow(IBinder,int,ResultReceiver) without a result: request to hide the soft input window from the context of the window that is currently accepting input.

Usage

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

protected void resetContent() {
    comicDef = makeComicDef();/*from  w  w  w.j  a  v a 2 s.  com*/
    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:mp.paschalis.BookSearchActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {

    if (isMakingSearch) {
        menu.findItem(App.MENU_SEARCH_SEARCH_BOOKS).setVisible(false);
        menu.findItem(App.MENU_CLEAR).setVisible(true);

        // Show on screen keyboard
        InputMethodManager imm = (InputMethodManager) this.getSystemService(Service.INPUT_METHOD_SERVICE);
        editTextSearchKeyword.requestFocus();
        imm.showSoftInput(editTextSearchKeyword, 0);
    } else {//w w w .ja  v  a2 s  . co m
        menu.findItem(App.MENU_SEARCH_SEARCH_BOOKS).setVisible(true);
        menu.findItem(App.MENU_CLEAR).setVisible(false);
        // Hide on screen keyboard
        InputMethodManager imm = (InputMethodManager) BookSearchActivity.this
                .getSystemService(Service.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(editTextSearchKeyword.getWindowToken(), 0);
    }

    // If book is selected, show edit/view options
    if (isItemChecked) {

        String bookTitle;
        try {
            if (app.deviceType.equals(DeviceType.Large)) {
                bookTitle = app.selectedBook.title;
            } else {
                // If smaller device
                bookTitle = app.selectedBook.title.substring(0, 9) + "..";
            }

        } catch (Exception e) {
            menu.findItem(App.MENU_MY_BOOKS_BOOK_SELECTED).setVisible(false);
            return false;
        }

        if (app.selectedBook.status != App.BOOK_STATE_USER_DONT_OWNS) {
            menu.findItem(App.MENU_MY_BOOKS_BOOK_SELECTED).setVisible(true)
                    .setTitle(getString(R.string.edit) + ": " + bookTitle);
        } else {

            menu.findItem(App.MENU_MY_BOOKS_BOOK_SELECTED).setVisible(true)
                    .setTitle(getString(R.string.view) + ": " + bookTitle);

        }

    } else {
        menu.findItem(App.MENU_MY_BOOKS_BOOK_SELECTED).setVisible(false);

    }

    return true;
}

From source file:apps.junkuvo.alertapptowalksafely.MainActivity.java

@Override
public void onClick(View v) {
    switch (v.getId()) {
    case R.id.rtlMain:

        //                long cacheExpirationSeconds = BuildConfig.DEBUG ? 10 : 60 * 60;// Cache()
        //                FirebaseRemoteConfigUtil.fetch(cacheExpirationSeconds);
        //                Toast.makeText(getApplicationContext(), FirebaseRemoteConfig.getInstance().getString("test_string"), Toast.LENGTH_SHORT).show();

        FlurryAgent.logEvent("onClick aside from Start button");

        // ?/*from ww  w .  ja  v  a 2s . c  o  m*/
        InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(v.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);

        if (!mAlertService.IsRunningAlertService()) {
            createToastShort(getString(R.string.toast_instruction)).show();
            mbtnStart.startAnimation(mAnimationBlink);
        }
        break;
    case R.id.fabStart:
        startBtnClick(v);
        break;

    }
}

From source file:com.awrtechnologies.carbudgetsales.MainActivity.java

public void openNewFragment(Fragment f) {

    try {//from  w  w w. ja v a  2  s.co  m
        InputMethodManager input = (InputMethodManager) this.getSystemService(Context.INPUT_METHOD_SERVICE);
        input.hideSoftInputFromWindow(this.getCurrentFocus().getWindowToken(), 0);
    } catch (Exception e) {
    }
    FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
    ft.setCustomAnimations(R.anim.slide_in_right, R.anim.slide_out_left);
    fragmentstack.push(currentfragment);
    ft.replace(R.id.contanier, f);
    currentfragment = f;
    ft.commitAllowingStateLoss();
}

From source file:com.awrtechnologies.carbudgetsales.MainActivity.java

public void openFragment(Fragment f) {

    try {/*ww w .  j a  v a  2 s. c om*/
        InputMethodManager input = (InputMethodManager) this.getSystemService(Context.INPUT_METHOD_SERVICE);
        input.hideSoftInputFromWindow(this.getCurrentFocus().getWindowToken(), 0);
    } catch (Exception e) {
    }
    FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
    ft.setCustomAnimations(R.anim.slide_in_right, R.anim.slide_out_left);
    ft.replace(R.id.contanier, f);
    currentfragment = f;
    ft.commit();

}

From source file:fr.univsavoie.ltp.client.MainActivity.java

/**
 * Geocoding of the destination address//from  w  w  w . ja  va2 s.c om
 */
public void handleSearchLocationButton() {
    EditText destinationEdit = (EditText) findViewById(R.id.editDestination);
    //Hide the soft keyboard:
    InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.hideSoftInputFromWindow(destinationEdit.getWindowToken(), 0);

    String destinationAddress = destinationEdit.getText().toString();
    GeocoderNominatim geocoder = new GeocoderNominatim(this);
    try {
        List<Address> foundAdresses = geocoder.getFromLocationName(destinationAddress, 1);
        if (foundAdresses.size() == 0) { //if no address found, display an error
            Toast.makeText(this, R.string.toast_address, Toast.LENGTH_SHORT).show();
        } else {
            Address address = foundAdresses.get(0); //get first address
            destinationPoint = new GeoPoint(address.getLatitude(), address.getLongitude());
            markerDestination = putMarkerItem(markerDestination, destinationPoint, DEST_INDEX,
                    R.string.destination, R.drawable.marker_destination, -1);
            getRoadAsync();
            map.getController().setCenter(destinationPoint);
        }
    } catch (Exception e) {
        Toast.makeText(this, R.string.toast_geocode, Toast.LENGTH_SHORT).show();
    }
}

From source file:com.flipzu.flipzu.Player.java

private void postComment() {
    /* track postComment event */
    tracker.trackEvent("Player", "Action", "postComment", 0);

    final EditText comment_et = (EditText) findViewById(R.id.post_comment_et);

    String comment = comment_et.getText().toString();
    comment_et.setText("");

    debug.logV(TAG, "postComment() " + comment);

    if (bcast != null) {
        /* hide soft keyboard */
        InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(comment_et.getWindowToken(), 0);

        AsyncFlipInterface.postComment(user, comment, Integer.parseInt(bcast.getId()));
        AsyncFlipInterface.getComments(Integer.parseInt(bcast.getId()), Player.this);
    }/*from ww w. j  a  v  a  2  s.  c  o  m*/
}

From source file:com.android.contacts.activities.DialtactsActivity.java

private void hideInputMethod(View view) {
    InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
    if (imm != null && view != null) {
        imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
    }//from   w ww . j  av  a2  s  .  c  o  m
}

From source file:com.slim.turboeditor.activity.MainActivity.java

private void closeKeyBoard() throws NullPointerException {
    // Central system API to the overall input method framework (IMF) architecture
    InputMethodManager inputManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);

    // Base interface for a remotable object
    if (getCurrentFocus() != null) {
        IBinder windowToken = getCurrentFocus().getWindowToken();

        // Hide type
        int hideType = InputMethodManager.HIDE_NOT_ALWAYS;

        // Hide the KeyBoard
        inputManager.hideSoftInputFromWindow(windowToken, hideType);
    }//from  w  w  w  .j a  v a 2s.c  om
}

From source file:com.abeo.tia.noordin.AddCaseStep2of4.java

public boolean dispatchTouchEvent(MotionEvent ev) {
    InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);
    return super.dispatchTouchEvent(ev);

}