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:com.scigames.registration.LoginActivity.java

@Override
public boolean dispatchTouchEvent(MotionEvent event) {

    View v = getCurrentFocus();/*from  w  w  w .  ja v  a  2s. com*/
    Log.d(TAG, "CLICK DETECTED");
    getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE);
    //        getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION );
    //        v.setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
    //        Window win = this.getWindow(); // in Activity's onCreate() for instance
    //        win.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
    //                WindowManager.LayoutParams.FLAG_FULLSCREEN);
    boolean ret = super.dispatchTouchEvent(event);

    if (v instanceof EditText) {
        View w = getCurrentFocus();
        int scrcoords[] = new int[2];
        w.getLocationOnScreen(scrcoords);
        float x = event.getRawX() + w.getLeft() - scrcoords[0];
        float y = event.getRawY() + w.getTop() - scrcoords[1];

        Log.d("Activity",
                "Touch event " + event.getRawX() + "," + event.getRawY() + " " + x + "," + y + " rect "
                        + w.getLeft() + "," + w.getTop() + "," + w.getRight() + "," + w.getBottom() + " coords "
                        + scrcoords[0] + "," + scrcoords[1]);
        if (event.getAction() == MotionEvent.ACTION_UP
                && (x < w.getLeft() || x >= w.getRight() || y < w.getTop() || y > w.getBottom())) {

            InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(getWindow().getCurrentFocus().getWindowToken(), 0);
        }
    }
    return ret;

}

From source file:app.abhijit.iter.MainActivity.java

private void setupAddStudentButton() {
    final Button addStudentButton = (Button) findViewById(R.id.student_add);
    addStudentButton.setOnClickListener(new View.OnClickListener() {
        @Override//from  w w w  .j a v a2  s  . com
        public void onClick(View v) {
            EditText addStudentEditText = (EditText) findViewById(R.id.student_registration_number_input);
            String registrationNumber = addStudentEditText.getText().toString();
            ((MainApplication) getApplication()).getStudentDataSource().select(registrationNumber);
            addStudentEditText.setText("");
            InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(
                    Context.INPUT_METHOD_SERVICE);
            inputMethodManager.hideSoftInputFromWindow(
                    getCurrentFocus() == null ? null : getCurrentFocus().getWindowToken(),
                    InputMethodManager.HIDE_NOT_ALWAYS);
            DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
            drawer.closeDrawers();
        }
    });
}

From source file:com.gizwits.framework.activity.BaseActivity.java

/**
 * ????//from   w w w. j  a  v a 2 s .  co m
 * 
 * @param token
 */
private void hideSoftInput(IBinder token) {
    if (token != null) {
        InputMethodManager im = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
        im.hideSoftInputFromWindow(token, InputMethodManager.HIDE_NOT_ALWAYS);
    }
}

From source file:com.dodo.wbbshoutbox.codebot.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    context = getApplicationContext();//from   w w w  .j ava 2  s. c om

    checkUpdate();

    Request.client.setUserAgent("Dodo Shoutboxapp");

    myCookieStore = new PersistentCookieStore(this);
    Request.client.setCookieStore(myCookieStore);

    Usernamefield = (TextView) findViewById(R.id.txtUsername);
    Sendbutton = (Button) findViewById(R.id.cmdSend);
    Refreshbutton = (Button) findViewById(R.id.cmdRefresh);
    pbReadChat = (ProgressBar) findViewById(R.id.pbReadChat);
    lblVerlauf = (TextView) findViewById(R.id.lblVerlauf);
    lblAutoRefresh = (TextView) findViewById(R.id.lblAutorefresh);

    if (UserData.readPref("textsize", this).equals("")) {
        UserData.writePref("textsize", "10", this);
    }
    if (UserData.readPref("refreshcircle", this).equals("")) {
        UserData.writePref("refreshcircle", "1", this);
        refreshanimation = 1;
    } else if (UserData.readPref("refreshcircle", this).equals("1")) {
        refreshanimation = 1;
    }
    /*
     * if(UserData.readPref("changechatdirection", this).equals("")) {
     * UserData.writePref("changechatdirection", "0", this); } else
     * if(UserData.readPref("changechatdirection", this).equals("1")) {
     * changechatdirection = 1; }
     */
    if (UserData.readPref("showtime", this).equals("")) {
        UserData.writePref("showtime", "1", this);
    } else {
        showTime = Integer.valueOf(UserData.readPref("showtime", this));
    }

    if (!UserData.readPref("username", this).equals("")) {
        Usernamefield.setText(UserData.readPref("username", this));
    }

    if (!UserData.readPref("autorefresh", this).equals("")) {
        Button cmdRefresh = (Button) findViewById(R.id.cmdRefresh);
        TextView lblARefresh = (TextView) findViewById(R.id.lblAutorefresh);

        cmdRefresh.setVisibility(Button.INVISIBLE);
        lblARefresh.setVisibility(TextView.VISIBLE);
        Toast.makeText(this, "Automatisches Laden aktiviert!", Toast.LENGTH_SHORT).show();
        autorefresh = 1;
    }

    if (UserData.readPref("ar_intervall", this).equals("")) {
        UserData.writePref("ar_intervall", "30000", this);
    }

    setTextSize();
    setCookies();

    final Button cmdSend = (Button) findViewById(R.id.cmdSend);
    if (requireLogin == 1 && loggedIn == 0) {
        cmdSend.setEnabled(false);
        cmdSend.setText("Zuerst einloggen!");
    }
    cmdSend.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            InputMethodManager inputManager = (InputMethodManager) getSystemService(
                    Context.INPUT_METHOD_SERVICE);
            inputManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(),
                    InputMethodManager.HIDE_NOT_ALWAYS);

            send();
        }
    });

    final Button cmdRefresh = (Button) findViewById(R.id.cmdRefresh);
    cmdRefresh.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            getRequest(baseUrl + "index.php?page=ShoutboxEntryXMLList");
        }
    });

    final Button cmdMenu = (Button) findViewById(R.id.cmdMenu);
    cmdMenu.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            InputMethodManager inputManager = (InputMethodManager) getSystemService(
                    Context.INPUT_METHOD_SERVICE);
            inputManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(),
                    InputMethodManager.HIDE_NOT_ALWAYS);

            // openOptionsMenu();
            Intent myIntent2 = new Intent(getApplicationContext(), Settings2.class);
            startActivityForResult(myIntent2, 0);
        }
    });

    TextView lblVerlauf = (TextView) findViewById(R.id.lblVerlauf);
    lblVerlauf.setMovementMethod(LinkMovementMethod.getInstance());
    lblVerlauf.setMovementMethod(new ScrollingMovementMethod());

}

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

/**
 * If the enter button is clicked a room search is done
 * If the get directions button is pressed you get the path drawn on map
 * but you have to search for a room first
 *///from  w w w  .  ja v  a 2  s  . com
public void onClick(View v) {

    switch (v.getId()) {

    case R.id.edittextbutton:
        //Removes the key when finish typing
        InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(lectureEdit.getWindowToken(), 0);
        //removes the path drawn if there is one
        mapOverlays.remove(pathOverlay);
        //removes the dot that point to a previous room found
        mapOverlays.remove(mapItemizedRoom);
        roomToFind = lectureEdit.getText().toString();
        //removes white signs and converts to lower case
        roomToFind.toLowerCase().trim();
        //Removes illegal characters to prevent sql injection
        roomToFind = roomToFind.replaceAll("[^[a-z][A-Z][0-9]]", "");
        //Set the field variable so it can be tested.
        setRoomToFind(roomToFind);
        //open database in read mode
        search.openRead();
        //if we find room show room on map, if not show dialog 
        if (search.exists(roomToFind)) {
            //create a geopoint
            roomLocation = new GeoPoint(search.getLat(roomToFind), search.getLong(roomToFind));
            mapcon = mapView.getController();
            mapcon.animateTo(roomLocation);
            //zoom level
            mapcon.setZoom(OVERVIEWZOOMVALUE);
            //address and level is shown in the dialog
            overlayItemRoom = new OverlayItem(roomLocation, search.getAddress(roomToFind),
                    search.getLevel(roomToFind));
            mapItemizedRoom.removeOverlay();
            mapItemizedRoom.addOverlay(overlayItemRoom);
            mapOverlays.add(mapItemizedRoom);
            mapView.postInvalidate();
            //now someone has searched for a room, set the boolean to true
            roomSearched = true;
        } else {
            //dilaog pops up if room not found
            dialog = new Dialog(GoogleMapSearchLocation.this);
            dialog.setTitle("Sorry, can not find the room :(");
            dialog.setCanceledOnTouchOutside(true);
            dialog.show();
        }
        //close database
        search.close();
        break;

    case R.id.directionbutton:
        Log.e("roomsearched", "in");
        //if there there is roomLocation then search for a path
        //if not a roomLocation then the user has not searched for a room, do not give directions
        if (gotInternetConnection()) {
            Log.e("roomsearched", "inin");
            if (roomSearched) {
                walkningDirections();
                roomSearched = false;
            } else {
                Context context = getApplicationContext();
                Toast.makeText(context, "Search for a room first to get directions", Toast.LENGTH_LONG).show();

            }
        } else {
            Context context = getApplicationContext();
            Toast.makeText(context, "Internet connection needed for this option", Toast.LENGTH_LONG).show();
        }

        break;

    }

}

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/*from w ww .jav  a 2 s  .  c om*/
        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:most.voip.example.ws_config.MainActivity.java

/**
 * Invoked when the 'Go' button is clicked
 *///  w ww . j  av a2 s.c  o m
public void doVoipTest(View view) {
    EditText txtView = (EditText) this.findViewById(R.id.txtServerIp);
    this.serverIp = txtView.getText().toString();
    InputMethodManager imm = (InputMethodManager) this.getSystemService(Service.INPUT_METHOD_SERVICE);
    imm.hideSoftInputFromWindow(txtView.getWindowToken(), 0);

    this.runExample();
}

From source file:com.cairoconfessions.SwipeyTabsView.java

/**
 * {@inheritDoc}/*  ww  w . j  a  v  a2  s. co  m*/
 */
@Override
public void onPageScrollStateChanged(int state) {
    if (state == ViewPager.SCROLL_STATE_IDLE) {
        if (mPager.getCurrentItem() == 1) {
            InputMethodManager imm = (InputMethodManager) getContext()
                    .getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(this.getWindowToken(), 0);
        }
    }
}

From source file:com.andrew.apollo.ui.activities.SearchActivity.java

/**
 * {@inheritDoc}/*  w ww.j  av a  2 s. c o m*/
 */
@Override
public boolean onQueryTextSubmit(final String query) {
    if (TextUtils.isEmpty(query)) {
        return false;
    }
    // When the search is "committed" by the user, then hide the keyboard so
    // the user can
    // more easily browse the list of results.
    if (mSearchView != null) {
        final InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
        if (imm != null) {
            imm.hideSoftInputFromWindow(mSearchView.getWindowToken(), 0);
        }
        mSearchView.clearFocus();
    }
    // Action bar subtitle
    mResources.setSubtitle("\"" + mFilterString + "\"");
    return true;
}

From source file:com.android.mms.quickmessage.QuickMessage.java

/**
* Supporting Utility functions// www  . ja  v a 2  s.c o m
*/

private void dismissKeyboard() {
    if (mCurrentQm == null) {
        mCurrentQm = mMessageList.get(mCurrentQmIndex);
    }

    EditText editView = mCurrentQm.getEditText();
    if (editView != null) {
        InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(editView.getApplicationWindowToken(), 0);
    }
}