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.dewep.intranetepitech.ui.landing.LandingActivity.java

@Override
public void onPageSelected(int position) {
    if (position == 0) {
        mLandingLogo.setVisibility(View.GONE);
    } else {/*from  w  ww.  j  a  v a 2 s .c  om*/
        mLandingLogo.setVisibility(View.VISIBLE);
    }
    if (this.getCurrentFocus() != null) {
        InputMethodManager imm = (InputMethodManager) this.getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(this.getCurrentFocus().getWindowToken(), 0);
    }
    this.getWindow().getDecorView().clearFocus();
}

From source file:com.netpace.expressit.activity.UploadImageStoryActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case android.R.id.home:
        if (!isGalleryPhoto) {
            this.onBackPressed();
        } else {/*ww w  . ja v a 2 s.  c o m*/
            Intent intent = new Intent(UploadImageStoryActivity.this, MediaOptionsActivity.class);
            intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            startActivity(intent);
        }
        return true;

    case R.id.menu_item_img_gallery:
        if (isValidate()) {
            // close the keyboard.
            InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(titleTextView.getWindowToken(), 0);

            getMediaKeyFromRemoteServer();
        }
        return true;

    default:
        return super.onOptionsItemSelected(item);
    }
}

From source file:com.bjerva.tsplex.fragments.SignListFragment.java

void loadSigns() {
    //Create and set adapter
    if (ma == null) {
        Log.d(TAG, "Null activity");
        return;//from  w w  w .j a  va  2  s.  c  om
    }
    tv = (TextView) ma.findViewById(R.id.alphabetic_header);
    tv.setText("A");
    final List<SimpleGson> tmpSigns = new ArrayList<SimpleGson>();
    final Locale swedishLocale = new Locale("sv", "SE");

    for (int i = 0, l = ma.getGsonSignsLite().size(); i < l; i++) {
        SimpleGson currSign = ma.getGsonSignsLite().get(i);
        tmpSigns.add(currSign);
    }

    mAdapter = new SignAdapter(ma, android.R.layout.simple_list_item_1, tmpSigns);

    getListView().setAdapter(mAdapter);

    //Set scroll listener
    getListView().setOnScrollListener(new OnScrollListener() {
        @Override
        public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
            if (firstVisibleItem > 0) {
                String word = ((SimpleGson) view.getItemAtPosition(firstVisibleItem)).getWord();
                tv.setText(word.substring(0, 1).toUpperCase(swedishLocale));
            }
        }

        @Override
        public void onScrollStateChanged(AbsListView view, int scrollState) {
        }
    });

    //Set listener
    getListView().setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(android.widget.AdapterView<?> parent, View view, int position, long id) {
            Log.d(TAG, "CLICKED");
            ma.showLoader();
            ma.checkConnection();

            mGaTracker.sendEvent("sign", "list_click", tmpSigns.get(position).getWord(), 1L);

            //Update position
            ma.loadSingleJson(tmpSigns.get(position).getId());

            //Hide keyboard
            if (search != null) {
                InputMethodManager imm = (InputMethodManager) ma.getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.hideSoftInputFromWindow(search.getWindowToken(), 0);
            }

            if (!ma.isOnline()) {
                ma.connectionError();
                ma.hideLoader();
                return;
            }

            if (ma.getDetFragment() == null) {
                //Create detail fragment
                SignDetailFragment newFragment = new SignDetailFragment();

                //Add to container
                FragmentTransaction transaction = ma.getSupportFragmentManager().beginTransaction();
                transaction.setCustomAnimations(R.anim.slide_fragment_in_on_replace,
                        R.anim.slide_fragment_out_on_replace);
                transaction.replace(R.id.fragment_container, newFragment);
                transaction.addToBackStack(null);
                transaction.commit();
            } else {
                ma.getDetFragment().startUpHelper(ma.getCurrentSign());
            }
        }

    });
}

From source file:net.alchemiestick.katana.winehqappdb.filter_dialog.java

public filter_dialog(Context cx, List<NameValuePair> data) {
    super(cx);//  www.j  a  va 2s.co m
    this.cx = cx;
    this.webData = data;
    this.requestWindowFeature(Window.FEATURE_NO_TITLE);
    vocl = new View.OnClickListener() {
        public void onClick(View v) {
            onCheckboxClick(v);
        }
    };

    maxLines = new OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView tv, int action, KeyEvent key) {
            boolean handled = false;
            if (action == EditorInfo.IME_ACTION_DONE) {
                setMaxLines(tv.getText().toString());
                tv.setText(getNamedData("iPage"));
                InputMethodManager imm = (InputMethodManager) tv.getContext()
                        .getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.hideSoftInputFromWindow(tv.getWindowToken(), 0);
                handled = true;
            }
            return handled;
        }
    };
    rateListener = new AdapterView.OnItemSelectedListener() {
        public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
            rateSelected((String) parent.getItemAtPosition(pos));
        }

        public void onNothingSelected(AdapterView<?> parent) {
        }
    };
    licenseListener = new AdapterView.OnItemSelectedListener() {
        public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
            licenseSelected((String) parent.getItemAtPosition(pos));
        }

        public void onNothingSelected(AdapterView<?> parent) {
        }
    };
    placementListener = new AdapterView.OnItemSelectedListener() {
        public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
            placementSelected((String) parent.getItemAtPosition(pos));
        }

        public void onNothingSelected(AdapterView<?> parent) {
        }
    };

}

From source file:com.netpace.expressit.activity.UploadImageStoryActivity.java

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

    getSupportActionBar().setTitle("retake");
    getSupportActionBar().setDisplayShowHomeEnabled(false);

    Intent intent = getIntent();/*from w w w  . j ava  2s. c  o  m*/
    img_filePath = intent.getStringExtra(IMAGE_PATH);
    widthAfter = intent.getIntExtra(IMAGE_WIDTH, 0);
    heightAfter = intent.getIntExtra(IMAGE_HEIGHT, 0);
    isGalleryPhoto = intent.getBooleanExtra("isGalleryPhoto", false);

    imageViewThumbnail = (ImageView) findViewById(R.id.imageViewThumb);
    imageViewThumbnail.setImageURI(Uri.parse(img_filePath));
    titleTextView = (TypefaceEditText) findViewById(R.id.story_title_txt_field);

    button_saveLater = (Button) findViewById(R.id.shareButton);
    button_saveLater.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {

            if (isValidate()) {
                // close the keyboard.
                InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.hideSoftInputFromWindow(titleTextView.getWindowToken(), 0);

                getMediaKeyFromRemoteServer();
            }
        }
    });
}

From source file:com.android.idearse.Login.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.login);//from ww  w .j  a v  a  2s.  com

    getWindow().getAttributes().windowAnimations = R.style.Fade;

    preferences = PreferenceManager.getDefaultSharedPreferences(this);

    loadima = (ImageView) findViewById(R.id.loading);
    rotation = AnimationUtils.loadAnimation(getApplicationContext(), R.drawable.rotate_loading);
    rotation.setRepeatCount(Animation.INFINITE);

    ActionBar actionBar = getSupportActionBar();

    setTitle("");
    getSupportActionBar().setIcon(R.drawable.title_logo);

    actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_HOME);

    username = (EditText) findViewById(R.id.username);
    password = (EditText) findViewById(R.id.password);

    preferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
    String user = preferences.getString("user", "");
    String pass = preferences.getString("password", "");

    username.setText(user);
    password.setText(pass);

    error_msg = (TextView) findViewById(R.id.error_msg);
    Button login = (Button) findViewById(R.id.login_btn);

    final CheckBox checkBox = (CheckBox) findViewById(R.id.checkbtn);

    checkBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (!isChecked) {
                SharedPreferences.Editor editor = preferences.edit();
                editor.putString("user", "");
                editor.putString("password", "");
                editor.commit();
                username.setText("");
                password.setText("");
            }
        }
    });

    if (user.length() != 0 && pass.length() != 0) {
        checkBox.setChecked(true);
    }

    login.setOnClickListener(new View.OnClickListener() {
        public void onClick(View arg0) {
            InputMethodManager inputManager = (InputMethodManager) getSystemService(
                    Context.INPUT_METHOD_SERVICE);
            inputManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(),
                    InputMethodManager.HIDE_NOT_ALWAYS);

            if (username.length() == 0 || password.length() == 0) {
                error_msg.setText("Completa los campos");
                error_msg.setVisibility(View.VISIBLE);
            } else {
                if (checkBox.isChecked()) {
                    SharedPreferences.Editor editor = preferences.edit();
                    editor.putString("user", username.getText().toString());
                    editor.putString("password", password.getText().toString());
                    editor.commit();
                }
                error_msg.setVisibility(View.GONE);
                loadima.startAnimation(rotation);
                loadima.setVisibility(View.VISIBLE);
                new LoginQuery().execute(getString(R.string.URL) + "conectar_mobil/user/login");
            }
        }
    });
}

From source file:org.projecthdata.weight.WeightTrackerActivity.java

public void onSave(View v) {
    try {//from   www  . ja  v  a 2 s . co  m
        WeightReading reading = new WeightReading();
        EditText weightEditText = (EditText) findViewById(R.id.weight_edit_text);
        Double entry = Double.parseDouble(weightEditText.getText().toString());
        reading.setResultValue(entry);
        getDatabaseHelper().getWeightDao().create(reading);
        // go back to displaying the weight list
        getSupportFragmentManager().popBackStack();

        // hide the soft keyboard
        InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(weightEditText.getWindowToken(), 0);

    } catch (SQLException e) {
        e.printStackTrace();
    }

}

From source file:com.hybris.mobile.activity.LoginActivity.java

@Override
public void onReceiveResult(RESTLoaderResponse restLoaderResponse, WebserviceMethodEnums webserviceEnumMethod) {

    if (restLoaderResponse.getCode() == RESTLoaderResponse.SUCCESS) {

        switch (webserviceEnumMethod) {
        case METHOD_LOGIN:
            Hybris.setUserOnline(true);/*from w w w.  jav  a2  s  .  c o  m*/
            Hybris.setUsername(mEmailView.getText().toString());

            if (getCurrentFocus() != null) {
                InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(),
                        InputMethodManager.HIDE_NOT_ALWAYS);
            }

            showMessage(getString(R.string.login_successful));

            // Redirection to the right intent
            if (getIntent().hasExtra(DataConstants.INTENT_DESTINATION)) {
                new CheckDataBeforeLaunchingIntentTask().execute();
            } else {
                finish();
            }
            break;
        case METHOD_REQUEST_PASSWORD:
            showMessage(getString(R.string.new_password_sent));
            break;

        default:
            break;
        }
    } else if (restLoaderResponse.getCode() == RESTLoaderResponse.ERROR) {
        switch (webserviceEnumMethod) {
        case METHOD_LOGIN:
            showMessage(getString(R.string.error_login));
            break;

        default:
            break;
        }
    }
}

From source file:com.barak.pix.CommentsFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    View rootView = inflater.inflate(R.layout.fragment_comments, container, false);
    RecyclerView mCommentsView = (RecyclerView) rootView.findViewById(R.id.comment_list);
    mEditText = (EditText) rootView.findViewById(R.id.editText);
    final Button sendButton = (Button) rootView.findViewById(R.id.send_comment);

    final DatabaseReference commentsRef = FirebaseUtil.getCommentsRef().child(mPostRef);
    mAdapter = new FirebaseRecyclerAdapter<Comment, CommentViewHolder>(Comment.class, R.layout.comment_item,
            CommentViewHolder.class, commentsRef) {
        @Override//ww  w . jav  a 2 s . c  o  m
        protected void populateViewHolder(final CommentViewHolder viewHolder, Comment comment, int position) {
            Author author = comment.getAuthor();
            viewHolder.commentAuthor.setText(author.getFull_name());
            GlideUtil.loadProfileIcon(author.getProfile_picture(), viewHolder.commentPhoto);

            viewHolder.authorRef = author.getUid();
            viewHolder.commentTime.setText(DateUtils.getRelativeTimeSpanString((long) comment.getTimestamp()));
            viewHolder.commentText.setText(comment.getText());
        }
    };
    sendButton.setEnabled(false);
    mEditText.setHint(R.string.new_comment_hint);
    mEditText.setFilters(new InputFilter[] { new InputFilter.LengthFilter(DEFAULT_MSG_LENGTH_LIMIT) });
    mEditText.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
        }

        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
        }

        @Override
        public void afterTextChanged(Editable editable) {
            if (editable.length() > 0) {
                sendButton.setEnabled(true);
            } else {
                sendButton.setEnabled(false);
            }
        }
    });
    sendButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // Clear input box and hide keyboard.
            final Editable commentText = mEditText.getText();
            mEditText.setText("");
            InputMethodManager inputManager = (InputMethodManager) getActivity()
                    .getSystemService(Context.INPUT_METHOD_SERVICE);
            inputManager.hideSoftInputFromWindow(mEditText.getWindowToken(),
                    InputMethodManager.HIDE_NOT_ALWAYS);

            FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
            if (user == null) {
                Toast.makeText(getActivity(), R.string.user_logged_out_error, Toast.LENGTH_SHORT).show();
            }

            Author author = new Author(user.getDisplayName(), "", user.getUid());

            Comment comment = new Comment(author, commentText.toString(), ServerValue.TIMESTAMP);
            commentsRef.push().setValue(comment, new DatabaseReference.CompletionListener() {
                @Override
                public void onComplete(DatabaseError error, DatabaseReference firebase) {
                    if (error != null) {
                        Log.w(TAG, "Error posting comment: " + error.getMessage());
                        Toast.makeText(getActivity(), "Error posting comment.", Toast.LENGTH_SHORT).show();
                        mEditText.setText(commentText);
                    }
                }
            });
        }
    });
    mCommentsView.setLayoutManager(new LinearLayoutManager(getActivity()));
    mCommentsView.setAdapter(mAdapter);
    return rootView;
}

From source file:com.akalizakeza.apps.ishusho.activity.CommentsFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    View rootView = inflater.inflate(R.layout.fragment_comments, container, false);
    RecyclerView mCommentsView = (RecyclerView) rootView.findViewById(R.id.comment_list);
    mEditText = (EditText) rootView.findViewById(R.id.editText);
    final Button sendButton = (Button) rootView.findViewById(R.id.send_comment);

    final DatabaseReference commentsRef = FirebaseUtil.getCommentsRef().child(mPostRef);
    mAdapter = new FirebaseRecyclerAdapter<Comment, CommentViewHolder>(Comment.class,
            R.layout.activity_comments_item, CommentViewHolder.class, commentsRef) {
        @Override/*from w ww .  ja v  a2s. c o m*/
        protected void populateViewHolder(final CommentViewHolder viewHolder, Comment comment, int position) {
            Artist artist = comment.getArtist();
            viewHolder.commentAuthor.setText(artist.getFull_name());
            GlideUtil.loadProfileIcon(artist.getProfile_picture(), viewHolder.commentPhoto);

            viewHolder.authorRef = artist.getUid();
            viewHolder.commentTime.setText(DateUtils.getRelativeTimeSpanString((long) comment.getTimestamp()));
            viewHolder.commentText.setText(comment.getText());
        }
    };
    sendButton.setEnabled(false);
    mEditText.setHint(R.string.new_comment_hint);
    mEditText.setFilters(new InputFilter[] { new InputFilter.LengthFilter(DEFAULT_MSG_LENGTH_LIMIT) });
    mEditText.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
        }

        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
        }

        @Override
        public void afterTextChanged(Editable editable) {
            if (editable.length() > 0) {
                sendButton.setEnabled(true);
            } else {
                sendButton.setEnabled(false);
            }
        }
    });
    sendButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // Clear input box and hide keyboard.
            final Editable commentText = mEditText.getText();
            mEditText.setText("");
            InputMethodManager inputManager = (InputMethodManager) getActivity()
                    .getSystemService(Context.INPUT_METHOD_SERVICE);
            inputManager.hideSoftInputFromWindow(mEditText.getWindowToken(),
                    InputMethodManager.HIDE_NOT_ALWAYS);

            FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
            if (user == null) {
                Toast.makeText(getActivity(), R.string.user_logged_out_error, Toast.LENGTH_SHORT).show();
            }

            Artist artist = new Artist(user.getDisplayName(), user.getPhotoUrl().toString(), user.getUid());

            Comment comment = new Comment(artist, commentText.toString(), ServerValue.TIMESTAMP);
            commentsRef.push().setValue(comment, new DatabaseReference.CompletionListener() {
                @Override
                public void onComplete(DatabaseError error, DatabaseReference firebase) {
                    if (error != null) {
                        Log.w(TAG, "Error posting comment: " + error.getMessage());
                        Toast.makeText(getActivity(), "Error posting comment.", Toast.LENGTH_SHORT).show();
                        mEditText.setText(commentText);
                    }
                }
            });
        }
    });
    mCommentsView.setLayoutManager(new LinearLayoutManager(getActivity()));
    mCommentsView.setAdapter(mAdapter);
    return rootView;
}