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:sundroid.code.SundroidActivity.java

/** Called when the activity is first created. ***/
@Override//from www .ja v a 2  s . c  o m
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    setContentView(R.layout.main);

    this.chk_usecelsius = (CheckBox) findViewById(R.id.chk_usecelsius);
    Button cmd_submit = (Button) findViewById(R.id.cmd_submit);

    cmd_submit.setOnClickListener(new OnClickListener() {

        public void onClick(View arg0) {

            try {

                ///////////////// Code to get weather conditions for entered place ///////////////////////////////////////////////////
                String cityParamString = ((EditText) findViewById(R.id.edit_input)).getText().toString();
                String queryString = "https://www.google.com/ig/api?weather=" + cityParamString;
                queryString = queryString.replace("#", "");

                /* Parsing the xml file*/
                SAXParserFactory spf = SAXParserFactory.newInstance();
                SAXParser sp = spf.newSAXParser();
                XMLReader xr = sp.getXMLReader();

                GoogleWeatherHandler gwh = new GoogleWeatherHandler();
                xr.setContentHandler(gwh);

                HttpClient httpclient = new DefaultHttpClient();
                HttpGet httpget = new HttpGet(queryString.replace(" ", "%20"));
                ResponseHandler<String> responseHandler = new BasicResponseHandler();
                String responseBody = httpclient.execute(httpget, responseHandler);
                ByteArrayInputStream is = new ByteArrayInputStream(responseBody.getBytes());
                xr.parse(new InputSource(is));
                Log.d("Sundroid", "parse complete");

                WeatherSet ws = gwh.getWeatherSet();

                newupdateWeatherInfoView(R.id.weather_today, ws.getWeatherCurrentCondition(),
                        " " + cityParamString, "");

                ///////////////// Code to get weather conditions for entered place ends /////////////////////////////////////////////////// 

                ///////////////// Code to get latitude and longitude using zipcode starts ///////////////////////////////////////////////////

                String latlng_querystring = "http://maps.googleapis.com/maps/api/geocode/xml?address="
                        + cityParamString.replace(" ", "%20") + "&sensor=false";
                URL url_latlng = new URL(latlng_querystring);
                spf = SAXParserFactory.newInstance();
                sp = spf.newSAXParser();

                xr = sp.getXMLReader();
                xmlhandler_latlong xll = new xmlhandler_latlong();
                xr.setContentHandler(xll);
                xr.parse(new InputSource(url_latlng.openStream()));

                Latitude_longitude ll = xll.getLatlng_resultset();
                double selectedLat = ll.getLat_lng_pair().getLat();
                double selectedLng = ll.getLat_lng_pair().getLon();

                ///////////////// Code to get latitude and longitude using zipcode ends ///////////////////////////////////////////////////

                ///////////////// Code to get miles from text box & convert to meters for passing into the api link////////////////////////
                EditText edt = (EditText) findViewById(R.id.edit_miles);
                float miles = Float.valueOf(edt.getText().toString());
                float meters = (float) (miles * 1609.344);

                ///////////////// Code to get miles from text box & convert to meters for passing into the api link ends /////////////////

                ///////////////// Code to pass lat,long and radius and get destinations from places api starts////////// /////////////////
                URL queryString_1 = new URL("https://maps.googleapis.com/maps/api/place/search/xml?location="
                        + Double.toString(selectedLat) + "," + Double.toString(selectedLng) + "&radius="
                        + Float.toString(meters)
                        + "&types=park|types=aquarium|types=point_of_interest|types=establishment|types=museum&sensor=false&key=AIzaSyDmP0SB1SDMkAJ1ebxowsOjpAyeyiwHKQU");
                spf = SAXParserFactory.newInstance();
                sp = spf.newSAXParser();
                xr = sp.getXMLReader();
                xmlhandler_places xhp = new xmlhandler_places();
                xr.setContentHandler(xhp);
                xr.parse(new InputSource(queryString_1.openStream()));
                int arraysize = xhp.getVicinity_List().size();
                String[] place = new String[25];
                String[] place_name = new String[25];
                Double[] lat_pt = new Double[25];
                Double[] lng_pt = new Double[25];
                int i;
                //Getting name and vicinity tags from the xml file//
                for (i = 0; i < arraysize; i++) {
                    place[i] = xhp.getVicinity_List().get(i);
                    place_name[i] = xhp.getPlacename_List().get(i);
                    lat_pt[i] = xhp.getLatlist().get(i);
                    lng_pt[i] = xhp.getLonglist().get(i);
                    System.out.println("long -" + lng_pt[i]);
                    place[i] = place[i].replace("#", "");

                }

                ///////////////// Code to pass lat,long and radius and get destinations from places api ends////////// /////////////////

                //////////////////////while loop for getting top 5 from the array////////////////////////////////////////////////

                int count = 0;
                int while_ctr = 0;
                String str_weathercondition;
                str_weathercondition = "";
                WeatherCurrentCondition reftemp;
                //Places to visit if none of places in the given radius are sunny/clear/partly cloudy
                String[] rainy_place = { "Indoor Mall", "Watch a Movie", "Go to a Restaurant", "Shopping!" };
                double theDistance = 0;
                String str_dist = "";
                while (count < 5) {
                    //Checking if xml vicinity value is empty
                    while (place[while_ctr] == null || place[while_ctr].length() < 2) {
                        while_ctr = while_ctr + 1;
                    }
                    //First search for places that are sunny or clear 
                    if (while_ctr < i - 1) {
                        queryString = "https://www.google.com/ig/api?weather=" + place[while_ctr];
                        System.out.println("In while loop - " + queryString);
                        theDistance = (Math.sin(Math.toRadians(selectedLat))
                                * Math.sin(Math.toRadians(lat_pt[while_ctr]))
                                + Math.cos(Math.toRadians(selectedLat))
                                        * Math.cos(Math.toRadians(lat_pt[while_ctr]))
                                        * Math.cos(Math.toRadians(selectedLng - lng_pt[while_ctr])));
                        str_dist = new Double((Math.toDegrees(Math.acos(theDistance))) * 69.09).intValue()
                                + " miles";
                        System.out.println(str_dist);
                        spf = SAXParserFactory.newInstance();
                        sp = spf.newSAXParser();

                        xr = sp.getXMLReader();

                        gwh = new GoogleWeatherHandler();
                        xr.setContentHandler(gwh);
                        httpclient = new DefaultHttpClient();
                        httpget = new HttpGet(queryString.replace(" ", "%20"));
                        responseHandler = new BasicResponseHandler();
                        responseBody = httpclient.execute(httpget, responseHandler);
                        is = new ByteArrayInputStream(responseBody.getBytes());
                        xr.parse(new InputSource(is));
                        if (gwh.isIn_error_information()) {
                            System.out.println("Error Info flag set");
                        } else {
                            ws = gwh.getWeatherSet();

                            reftemp = ws.getWeatherCurrentCondition();
                            str_weathercondition = reftemp.getCondition();

                            //         Check if the condition is sunny or partly cloudy
                            if (str_weathercondition.equals("Sunny")
                                    || str_weathercondition.equals("Mostly Sunny")
                                    || str_weathercondition.equals("Clear")) {
                                System.out.println("Sunny Loop");

                                //  Increment the count 
                                ++count;

                                //   Disply the place on the widget 
                                if (count == 1) {
                                    newupdateWeatherInfoView(R.id.weather_1, reftemp, place_name[while_ctr],
                                            str_dist);
                                } else if (count == 2) {
                                    newupdateWeatherInfoView(R.id.weather_2, reftemp, place_name[while_ctr],
                                            str_dist);
                                } else if (count == 3) {
                                    newupdateWeatherInfoView(R.id.weather_3, reftemp, place_name[while_ctr],
                                            str_dist);
                                } else if (count == 4) {
                                    newupdateWeatherInfoView(R.id.weather_4, reftemp, place_name[while_ctr],
                                            str_dist);
                                } else if (count == 5) {
                                    newupdateWeatherInfoView(R.id.weather_5, reftemp, place_name[while_ctr],
                                            str_dist);
                                } else {
                                }
                            }
                        }
                    }

                    //  If Five sunny places not found then search for partly cloudy places 

                    else if (while_ctr >= i && while_ctr < i * 2) {
                        queryString = "https://www.google.com/ig/api?weather=" + place[while_ctr - i];
                        queryString = queryString.replace("  ", " ");

                        spf = SAXParserFactory.newInstance();
                        sp = spf.newSAXParser();

                        // Get the XMLReader of the SAXParser we created. 
                        xr = sp.getXMLReader();

                        gwh = new GoogleWeatherHandler();
                        xr.setContentHandler(gwh);

                        // Use HTTPClient to deal with the URL  
                        httpclient = new DefaultHttpClient();
                        httpget = new HttpGet(queryString.replace(" ", "%20"));
                        responseHandler = new BasicResponseHandler();
                        responseBody = httpclient.execute(httpget, responseHandler);
                        is = new ByteArrayInputStream(responseBody.getBytes());
                        xr.parse(new InputSource(is));
                        Log.d(DEBUG_TAG, "parse complete");

                        if (gwh.isIn_error_information()) {
                        } else {
                            ws = gwh.getWeatherSet();
                            reftemp = ws.getWeatherCurrentCondition();
                            str_weathercondition = reftemp.getCondition();

                            //    Check if the condition is sunny or partly cloudy
                            if (str_weathercondition.equals("Partly Cloudy")) {

                                count = count + 1;

                                //  Display the place 
                                if (count == 1) {
                                    newupdateWeatherInfoView(R.id.weather_1, reftemp, place_name[while_ctr - i],
                                            str_dist);
                                } else if (count == 2) {
                                    newupdateWeatherInfoView(R.id.weather_2, reftemp, place_name[while_ctr - i],
                                            str_dist);
                                } else if (count == 3) {
                                    newupdateWeatherInfoView(R.id.weather_3, reftemp, place_name[while_ctr - i],
                                            str_dist);
                                } else if (count == 4) {
                                    newupdateWeatherInfoView(R.id.weather_4, reftemp, place_name[while_ctr - i],
                                            str_dist);
                                } else if (count == 5) {
                                    newupdateWeatherInfoView(R.id.weather_5, reftemp, place_name[while_ctr - i],
                                            str_dist);
                                } else {
                                }
                            }
                        }
                    }
                    ////////////////////////////////  Give suggestions for a rainy day 
                    else {
                        queryString = "https://www.google.com/ig/api?weather=" + cityParamString;
                        queryString = queryString.replace("#", "");

                        spf = SAXParserFactory.newInstance();
                        sp = spf.newSAXParser();

                        // Get the XMLReader of the SAXParser we created. 
                        xr = sp.getXMLReader();
                        gwh = new GoogleWeatherHandler();
                        xr.setContentHandler(gwh);

                        httpclient = new DefaultHttpClient();

                        httpget = new HttpGet(queryString.replace(" ", "%20"));
                        // create a response handler 
                        responseHandler = new BasicResponseHandler();
                        responseBody = httpclient.execute(httpget, responseHandler);
                        is = new ByteArrayInputStream(responseBody.getBytes());
                        xr.parse(new InputSource(is));
                        if (gwh.isIn_error_information()) {
                        }

                        else {
                            ws = gwh.getWeatherSet();

                            reftemp = ws.getWeatherCurrentCondition();
                            str_weathercondition = reftemp.getCondition();

                            if (count == 0) {
                                newupdateWeatherInfoView(R.id.weather_1, reftemp, rainy_place[0], "");
                                newupdateWeatherInfoView(R.id.weather_2, reftemp, rainy_place[1], "");
                                newupdateWeatherInfoView(R.id.weather_3, reftemp, rainy_place[2], "");
                                newupdateWeatherInfoView(R.id.weather_4, reftemp, rainy_place[3], "");
                                newupdateWeatherInfoView(R.id.weather_5, reftemp, rainy_place[1], "");
                            } else if (count == 1) {
                                newupdateWeatherInfoView(R.id.weather_2, reftemp, rainy_place[1], "");
                                newupdateWeatherInfoView(R.id.weather_3, reftemp, rainy_place[2], "");
                                newupdateWeatherInfoView(R.id.weather_4, reftemp, rainy_place[3], "");
                                newupdateWeatherInfoView(R.id.weather_5, reftemp, rainy_place[0], "");
                            } else if (count == 2) {
                                newupdateWeatherInfoView(R.id.weather_3, reftemp, rainy_place[2], "");
                                newupdateWeatherInfoView(R.id.weather_4, reftemp, rainy_place[0], "");
                                newupdateWeatherInfoView(R.id.weather_5, reftemp, rainy_place[1], "");
                            } else if (count == 3) {
                                newupdateWeatherInfoView(R.id.weather_4, reftemp, rainy_place[0], "");
                                newupdateWeatherInfoView(R.id.weather_5, reftemp, rainy_place[1], "");
                            } else if (count == 4) {
                                newupdateWeatherInfoView(R.id.weather_5, reftemp, rainy_place[1], "");
                            } else {
                            }
                            count = 5;
                        }
                        count = 5;
                    }
                    while_ctr++;
                }

                /////////////Closing the soft keypad////////////////
                InputMethodManager iMethodMgr = (InputMethodManager) getSystemService(
                        Context.INPUT_METHOD_SERVICE);
                iMethodMgr.hideSoftInputFromWindow(edt.getWindowToken(), 0);

            } catch (Exception e) {
                resetWeatherInfoViews();
                Log.e(DEBUG_TAG, "WeatherQueryError", e);
            }
        }
    });
}

From source file:com.androzic.waypoint.WaypointProperties.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.action_save:
        Androzic application = Androzic.getApplication();
        try {//from   ww w  .  ja v a2 s .co  m
            if (name.getText().length() == 0)
                return false;

            if (waypoint == null) {
                waypoint = new Waypoint();
            }
            if (waypoint.date == null) {
                waypoint.date = Calendar.getInstance().getTime();
            }

            waypoint.name = name.getText().toString();

            waypoint.description = description.getText().toString();
            Angle[] coords = getLatLon();
            waypoint.latitude = coords[0].degrees;
            waypoint.longitude = coords[1].degrees;

            try {
                String p = proximity.getText().toString();
                if ("".equals(p))
                    waypoint.proximity = 0;
                else
                    waypoint.proximity = Integer.parseInt(p);
            } catch (NumberFormatException e) {
                e.printStackTrace();
            }

            try {
                String a = altitude.getText().toString();
                if ("".equals(a))
                    waypoint.altitude = Integer.MIN_VALUE;
                else
                    waypoint.altitude = Integer.parseInt(a);
            } catch (NumberFormatException e) {
                e.printStackTrace();
            }

            if (iconValue == null) {
                waypoint.marker = "";
                waypoint.drawImage = false;
            } else {
                waypoint.marker = iconValue;
                waypoint.drawImage = true;
            }
            int markerColorValue = markercolor.getColor();
            if (markerColorValue != defMarkerColor)
                waypoint.backcolor = markerColorValue;
            int textColorValue = textcolor.getColor();
            if (textColorValue != defTextColor)
                waypoint.textcolor = textColorValue;

            if (route != null) {
                application.dispatchRoutePropertiesChanged(route);
            } else {
                if (waypoint.set == null) {
                    application.addWaypoint(waypoint);
                }

                int set = waypointSet.getSelectedItemPosition();
                waypoint.set = application.getWaypointSets().get(set);

                application.saveWaypoints();
            }

            // Hide keyboard
            final InputMethodManager imm = (InputMethodManager) getActivity()
                    .getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(getView().getWindowToken(), 0);
            // "Close" fragment
            getFragmentManager().popBackStack();
            return true;
        } catch (Exception e) {
            e.printStackTrace();
            Toast.makeText(getActivity(), "Invalid input", Toast.LENGTH_LONG).show();
        }
    default:
        return super.onOptionsItemSelected(item);
    }
}

From source file:com.anjalimacwan.fragment.NoteEditFragment.java

public void switchNotes(String filename) {
    // Hide soft keyboard
    EditText editText = (EditText) getActivity().findViewById(R.id.editText1);
    InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.hideSoftInputFromWindow(editText.getWindowToken(), 0);

    // Act as if the back button was pressed
    onBackPressed(filename);//from  w w  w. ja  v a 2 s  . c om
}

From source file:com.uzmap.pkg.uzmodules.UISearchBar.SearchBarActivity.java

private void hide() {
    mRelativeLayout.setFocusable(true);//from  w  ww.ja  v a2s  .c  o m
    mRelativeLayout.requestFocus();
    InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
    imm.hideSoftInputFromWindow(mRelativeLayout.getWindowToken(), 0);
}

From source file:com.danielme.android.webviewdemo.WebViewDemoActivity.java

public void go(View view) {
    // hides the keyboard
    InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
    inputMethodManager.hideSoftInputFromWindow(urlEditText.getWindowToken(), 0);

    if (checkConnectivity()) {
        stopButton.setEnabled(true);//  w  ww  . j av  a 2  s .c  o m

        //http protocol by default
        if (!urlPattern.matcher(urlEditText.getText().toString()).matches()) {
            urlEditText.setText("http://" + urlEditText.getText().toString());
        }
        webview.loadUrl(urlEditText.getText().toString());
    }
}

From source file:com.aegamesi.steamtrade.MainActivity.java

public void toggleDrawer() {
    if (drawerLayout.isDrawerOpen(GravityCompat.START)) {
        drawerLayout.closeDrawer(GravityCompat.START);
    } else {/*w  w w .j  a v a2  s .  c om*/
        // hide IME
        InputMethodManager inputManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
        if (inputManager != null && this.getCurrentFocus() != null)
            inputManager.hideSoftInputFromWindow(this.getCurrentFocus().getWindowToken(),
                    InputMethodManager.HIDE_NOT_ALWAYS);

        drawerLayout.openDrawer(GravityCompat.START);
    }
}

From source file:ee.ria.DigiDoc.fragment.ContainerDetailsFragment.java

@OnClick(R.id.saveContainer)
public void onSaveContainerClick() {
    refreshContainerFacade();// w ww  . j a  va2 s. c  om
    if (!containerFacade.hasDataFiles()) {
        notificationUtil.showWarningMessage(getText(R.string.save_container_no_files));
        return;
    }
    String fileName = title.getText().toString();
    if (fileName.isEmpty()) {
        notificationUtil.showWarningMessage(getText(R.string.file_name_empty_message));
        return;
    }

    if (!ContainerNameUtils.hasSupportedContainerExtension(fileName)) {
        title.append(".");
        title.append(AppPreferences.get(getContext()).getContainerFormat());
        fileName = title.getText().toString();
    }

    File file = new File(FileUtils.getContainersDirectory(getContext()), fileName);
    if (file.exists()) {
        notificationUtil.showFailMessage(getText(R.string.file_exists_message));
        return;
    }

    boolean renamed = containerFacade.getContainerFile().renameTo(file);
    if (renamed) {
        notificationUtil.showSuccessMessage(getText(R.string.file_rename_success));
    }
    containerFacade = ContainerBuilder.aContainer(getContext()).fromExistingContainer(file).build();
    containerFacade.save();
    saveButton.setVisibility(View.GONE);
    updateContainerReferencesForSignatureAndDataFileViews(containerFacade.getContainerFile());
    InputMethodManager input = (InputMethodManager) getActivity()
            .getSystemService(Context.INPUT_METHOD_SERVICE);
    input.hideSoftInputFromWindow(title.getWindowToken(), 0);
    title.setCursorVisible(false);
}

From source file:ca.ramnansingh.randy.ibmwatsonspeechqa.AudioRecordTest.java

/**
 * Play TTS Audio data//  w  w w .j a  va  2 s.c  o  m
 *
 * @param view
 */
public void playTTS(View view) throws JSONException {

    TextToSpeech.sharedInstance().setVoice(fragmentTabTTS.getSelectedVoice());
    Log.d(TAG, fragmentTabTTS.getSelectedVoice());

    //Get text from text box
    textTTS = (TextView) fragmentTabTTS.mView.findViewById(R.id.prompt);
    String ttsText = textTTS.getText().toString();
    Log.d(TAG, ttsText);
    InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.hideSoftInputFromWindow(textTTS.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);

    //Call the sdk function
    TextToSpeech.sharedInstance().synthesize(ttsText);
}

From source file:com.cairoconfessions.MainActivity.java

public void addLocation(View view) {
    TextView newView = new TextView(this);
    AutoCompleteTextView addLoc = ((AutoCompleteTextView) findViewById(R.id.addLocation));
    String newLoc = addLoc.getText().toString();
    ViewGroup locList = ((ViewGroup) findViewById(R.id.locations));
    boolean notFound = true;
    for (int i = 0; i < locList.getChildCount(); i++) {
        if (newLoc.equals(((TextView) locList.getChildAt(i)).getText().toString()))
            notFound = false;//  ww w .  j  av a2s  .  c om
        break;
    }
    if (Arrays.asList(COUNTRIES).contains(newLoc) && notFound) {
        newView.setText(newLoc);
        newView.setClickable(true);
        newView.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                addItem(view);
            }
        });
        float scale = getResources().getDisplayMetrics().density;
        newView.setGravity(17);
        newView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 30);

        newView.setBackgroundResource(R.drawable.city2);

        LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT,
                (int) (150 * scale));
        lp.setMargins((int) (0 * scale), (int) (0 * scale), (int) (0 * scale), (int) (2 * scale));
        newView.setLayoutParams(lp);
        locList.addView(newView, 0);
        addLoc.setText("");
        InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(addLoc.getWindowToken(), 0);
        addLoc.setCursorVisible(false);

    } else {
        Toast.makeText(this, "Invalid location", Toast.LENGTH_LONG).show();
    }
}

From source file:com.appsimobile.appsii.module.search.SearchController.java

@Override
protected void onUserInvisible() {
    super.onUserInvisible();
    InputMethodManager imm = mInputMethodManager;
    imm.hideSoftInputFromWindow(mSearchView.getWindowToken(), 0);

}