Java Code Examples for android.view.inputmethod.InputMethodManager#toggleSoftInputFromWindow()

The following examples show how to use android.view.inputmethod.InputMethodManager#toggleSoftInputFromWindow() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Service.java    From Twire with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Shows the soft keyboard
 */
public static void showKeyboard(Activity activity) {
    // Check if no view has focus:
    View view = activity.getCurrentFocus();
    if (view != null) {
        InputMethodManager inputMethodManager = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
        inputMethodManager.toggleSoftInputFromWindow(view.getApplicationWindowToken(), InputMethodManager.SHOW_FORCED, 0);
    }
}
 
Example 2
Source File: PhotoPaintView.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private void editSelectedTextEntity() {
    if (!(currentEntityView instanceof TextPaintView) || editingText) {
        return;
    }

    curtainView.setVisibility(View.VISIBLE);

    final TextPaintView textPaintView = (TextPaintView) currentEntityView;
    initialText = textPaintView.getText();
    editingText = true;

    editedTextPosition = textPaintView.getPosition();
    editedTextRotation = textPaintView.getRotation();
    editedTextScale = textPaintView.getScale();

    textPaintView.setPosition(centerPositionForEntity());
    textPaintView.setRotation(0.0f);
    textPaintView.setScale(1.0f);

    toolsView.setVisibility(GONE);

    setTextDimVisibility(true, textPaintView);
    textPaintView.beginEditing();

    InputMethodManager inputMethodManager = (InputMethodManager) ApplicationLoader.applicationContext.getSystemService(Activity.INPUT_METHOD_SERVICE);
    inputMethodManager.toggleSoftInputFromWindow(textPaintView.getFocusedView().getWindowToken(), InputMethodManager.SHOW_FORCED, 0);
}
 
Example 3
Source File: PhotoPaintView.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private void editSelectedTextEntity() {
    if (!(currentEntityView instanceof TextPaintView) || editingText) {
        return;
    }

    curtainView.setVisibility(View.VISIBLE);

    final TextPaintView textPaintView = (TextPaintView) currentEntityView;
    initialText = textPaintView.getText();
    editingText = true;

    editedTextPosition = textPaintView.getPosition();
    editedTextRotation = textPaintView.getRotation();
    editedTextScale = textPaintView.getScale();

    textPaintView.setPosition(centerPositionForEntity());
    textPaintView.setRotation(0.0f);
    textPaintView.setScale(1.0f);

    toolsView.setVisibility(GONE);

    setTextDimVisibility(true, textPaintView);
    textPaintView.beginEditing();

    InputMethodManager inputMethodManager = (InputMethodManager) ApplicationLoader.applicationContext.getSystemService(Activity.INPUT_METHOD_SERVICE);
    inputMethodManager.toggleSoftInputFromWindow(textPaintView.getFocusedView().getWindowToken(), InputMethodManager.SHOW_FORCED, 0);
}
 
Example 4
Source File: MainActivity.java    From NoteCrypt with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onOptionsItemSelected(final MenuItem item) {
    switch (item.getItemId()) {
        case R.id.action_filter:
            if (db.getList().size() != 0) {
                actionDrawer();
            }
            return true;
        case R.id.action_sort:
            if (getPreferences(MODE_PRIVATE).getBoolean("isAlphabeticalOrder", false)) {
                getPreferences(MODE_PRIVATE).edit().putBoolean("isAlphabeticalOrder", false).apply();
            } else {
                getPreferences(MODE_PRIVATE).edit().putBoolean("isAlphabeticalOrder", true).apply();
            }
            actionSort(true);
            return true;
        case R.id.action_changePassword:
            changePassword();
            return true;
        case R.id.action_settings:
            startActivity(new Intent(MainActivity.this, SettingsActivity.class));
            return true;
        case R.id.action_about:
            AboutToast.getInstance().createAboutToast(getPackageManager(), getPackageName(), toast0, getApplicationContext());
            return true;
        case R.id.action_search:
            InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
            if (inputMethodManager != null) {
                inputMethodManager.toggleSoftInputFromWindow(listview.getApplicationWindowToken(), InputMethodManager.SHOW_FORCED, 0);
            }
        default:
            return super.onOptionsItemSelected(item);
    }
}
 
Example 5
Source File: Util.java    From IslamicLibraryAndroid with GNU General Public License v3.0 5 votes vote down vote up
public static void enableSoftInput(@NonNull View view, boolean toEnable) {
    InputMethodManager imm = (InputMethodManager) view.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.hideSoftInputFromWindow(view.getWindowToken(), InputMethodManager.RESULT_UNCHANGED_SHOWN);
    if (toEnable) {
        imm.toggleSoftInputFromWindow(view.getWindowToken(), InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_NOT_ALWAYS);
    }
}
 
Example 6
Source File: Service.java    From Pocket-Plays-for-Twitch with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Shows the soft keyboard
 */
public static void showKeyboard(Activity activity) {
    // Check if no view has focus:
    View view = activity.getCurrentFocus();
    if (view != null) {
        InputMethodManager inputMethodManager = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
        inputMethodManager.toggleSoftInputFromWindow(view.getApplicationWindowToken(), InputMethodManager.SHOW_FORCED, 0);
    }
}
 
Example 7
Source File: MemoActivity.java    From EverMemo with MIT License 5 votes vote down vote up
@Override
public void onClick(View v) {
	switch (v.getId()) {
	case R.id.edit_container:
		InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
		inputMethodManager.toggleSoftInputFromWindow(
				findViewById(R.id.edit_container)
						.getApplicationWindowToken(),
				InputMethodManager.SHOW_FORCED, 0);
		break;
	default:
		break;
	}
}
 
Example 8
Source File: NiboPlacesAutoCompleteSearchView.java    From Nibo with MIT License 4 votes vote down vote up
private void openSearchInternal(Boolean openKeyboard) {
    this.mLogoView.setVisibility(View.GONE);
    this.mSearchEditText.setVisibility(View.VISIBLE);
    mSearchEditText.requestFocus();
    this.mSuggestionListView.setVisibility(View.VISIBLE);
    mSuggestionListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
            hideKeyboard();
            NiboSearchSuggestionItem result = mSearchSuggestions.get(arg2);
            if (mSearchListener != null) {
                if (mSearchListener.onSuggestion(result)) {
                    setSearchString(result.getValue(), true);
                    fromEditingToSearch(true, false);
                }
            } else {
                setSearchString(result.getValue(), true);
                fromEditingToSearch(true, false);
            }
        }

    });
    String currentSearchText = getSearchText();
    if (currentSearchText.length() > 0) {
        buildSearchSuggestions(currentSearchText);
    } else {
        buildEmptySearchSuggestions();
    }

    if (mSearchListener != null)
        mSearchListener.onSearchEditOpened();
    if (getSearchText().length() > 0) {
        showClearButton();
    }
    if (openKeyboard) {
        if (showCustomKeyboard && mCustomKeyboardView != null) { // Show custom keyboard
            mCustomKeyboardView.setVisibility(View.VISIBLE);
            mCustomKeyboardView.setEnabled(true);

            // Enable cursor, but still prevent default keyboard from showing up
            OnTouchListener otl = new OnTouchListener() {
                @Override
                public boolean onTouch(View v, MotionEvent event) {
                    switch (event.getAction()) {
                        case MotionEvent.ACTION_DOWN:
                            mCustomKeyboardView.setVisibility(View.VISIBLE);
                            mCustomKeyboardView.setEnabled(true);
                            Layout layout = ((EditText) v).getLayout();
                            float x = event.getX() + mSearchEditText.getScrollX();
                            int offset = layout.getOffsetForHorizontal(0, x);
                            if (offset > 0)
                                if (x > layout.getLineMax(0))
                                    mSearchEditText.setSelection(offset);     // Touch was at the end of the text
                                else
                                    mSearchEditText.setSelection(offset - 1);
                            break;
                        case MotionEvent.ACTION_MOVE:
                            layout = ((EditText) v).getLayout();
                            x = event.getX() + mSearchEditText.getScrollX();
                            offset = layout.getOffsetForHorizontal(0, x);
                            if (offset > 0)
                                if (x > layout.getLineMax(0))
                                    mSearchEditText.setSelection(offset);     // Touch point was at the end of the text
                                else
                                    mSearchEditText.setSelection(offset - 1);
                            break;
                    }
                    return true;
                }
            };
            mSearchEditText.setOnTouchListener(otl);
        } else { // Show default keyboard
            mSearchEditText.setOnTouchListener(null);
            InputMethodManager inputMethodManager = (InputMethodManager) getContext()
                    .getSystemService(Context.INPUT_METHOD_SERVICE);
            inputMethodManager.toggleSoftInputFromWindow(
                    getApplicationWindowToken(),
                    InputMethodManager.SHOW_FORCED, 0);
        }
    }
}
 
Example 9
Source File: Tool.java    From openlauncher with Apache License 2.0 4 votes vote down vote up
public static void showKeyboard(Context context, View view) {
    InputMethodManager inputMethodManager = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
    if (inputMethodManager == null) return;
    inputMethodManager.toggleSoftInputFromWindow(view.getWindowToken(), InputMethodManager.SHOW_IMPLICIT, InputMethodManager.HIDE_NOT_ALWAYS);
}
 
Example 10
Source File: PersistentSearchView.java    From PersistentSearchView with Apache License 2.0 4 votes vote down vote up
private void openSearchInternal(Boolean openKeyboard) {
    this.mLogoView.setVisibility(View.GONE);
    this.mSearchEditText.setVisibility(View.VISIBLE);
    mSearchEditText.requestFocus();
    this.mSuggestionListView.setVisibility(View.VISIBLE);
    mSuggestionListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
            hideKeyboard();
            SearchItem result = mSearchSuggestions.get(arg2);
            if (mSearchListener != null) {
                if (mSearchListener.onSuggestion(result)) {
                    setSearchString(result.getValue(), true);
                    fromEditingToSearch(true, false);
                }
            } else {
                setSearchString(result.getValue(), true);
                fromEditingToSearch(true, false);
            }
        }

    });
    String currentSearchText = getSearchText();
    if (currentSearchText.length() > 0) {
        buildSearchSuggestions(currentSearchText);
    } else {
        buildEmptySearchSuggestions();
    }

    if (mSearchListener != null)
        mSearchListener.onSearchEditOpened();
    if (getSearchText().length() > 0) {
        showClearButton();
    }
    if (openKeyboard) {
        if(showCustomKeyboard && mCustomKeyboardView != null) { // Show custom keyboard
            mCustomKeyboardView.setVisibility(View.VISIBLE);
            mCustomKeyboardView.setEnabled(true);

            // Enable cursor, but still prevent default keyboard from showing up
            OnTouchListener otl = new OnTouchListener() {
                @Override
                public boolean onTouch(View v, MotionEvent event) {
                    switch (event.getAction()) {
                        case MotionEvent.ACTION_DOWN:
                            mCustomKeyboardView.setVisibility(View.VISIBLE);
                            mCustomKeyboardView.setEnabled(true);
                            Layout layout = ((EditText) v).getLayout();
                            float x = event.getX() + mSearchEditText.getScrollX();
                            int offset = layout.getOffsetForHorizontal(0, x);
                            if (offset > 0)
                                if (x > layout.getLineMax(0))
                                    mSearchEditText.setSelection(offset);     // Touch was at the end of the text
                                else
                                    mSearchEditText.setSelection(offset - 1);
                            break;
                        case MotionEvent.ACTION_MOVE:
                            layout = ((EditText) v).getLayout();
                            x = event.getX() + mSearchEditText.getScrollX();
                            offset = layout.getOffsetForHorizontal(0, x);
                            if (offset > 0)
                                if (x > layout.getLineMax(0))
                                    mSearchEditText.setSelection(offset);     // Touch point was at the end of the text
                                else
                                    mSearchEditText.setSelection(offset - 1);
                            break;
                    }
                    return true;
                }
            };
            mSearchEditText.setOnTouchListener(otl);
        } else { // Show default keyboard
            mSearchEditText.setOnTouchListener(null);
            InputMethodManager inputMethodManager = (InputMethodManager) getContext()
                    .getSystemService(Context.INPUT_METHOD_SERVICE);
            inputMethodManager.toggleSoftInputFromWindow(
                    getApplicationWindowToken(),
                    InputMethodManager.SHOW_FORCED, 0);
        }
    }
}
 
Example 11
Source File: SearchBox.java    From WeGit with Apache License 2.0 4 votes vote down vote up
private void openSearch(Boolean openKeyboard) {
       if(animateDrawerLogo){
           this.materialMenu.animateState(IconState.ARROW);
           this.drawerLogo.setVisibility(View.GONE);
       }
	this.logo.setVisibility(View.GONE);
	this.search.setVisibility(View.VISIBLE);
	search.requestFocus();
	this.results.setVisibility(View.VISIBLE);
	animate = true;
       setAdapter(new SearchAdapter(context, resultList, search));
       searchOpen = true;
	results.setOnItemClickListener(new OnItemClickListener() {

           @Override
           public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
                                   long arg3) {
               SearchResult result = resultList.get(arg2);
               search(result, true);
           }

       });
	if(initialResults != null){
		setInitialResults();
	}else{
		updateResults();
	}
	
	if (listener != null)
		listener.onSearchOpened();
	if (getSearchText().length() > 0) {
		micStateChanged(false);
		mic.setImageDrawable(context.getResources().getDrawable(
				R.drawable.ic_clear));
	}
	if (openKeyboard) {
		InputMethodManager inputMethodManager = (InputMethodManager) context
				.getSystemService(Context.INPUT_METHOD_SERVICE);
		inputMethodManager.toggleSoftInputFromWindow(
                   getApplicationWindowToken(),
                   InputMethodManager.SHOW_FORCED, 0);
	}
}