Example usage for android.content Context INPUT_METHOD_SERVICE

List of usage examples for android.content Context INPUT_METHOD_SERVICE

Introduction

In this page you can find the example usage for android.content Context INPUT_METHOD_SERVICE.

Prototype

String INPUT_METHOD_SERVICE

To view the source code for android.content Context INPUT_METHOD_SERVICE.

Click Source Link

Document

Use with #getSystemService(String) to retrieve a android.view.inputmethod.InputMethodManager for accessing input methods.

Usage

From source file:com.insthub.O2OMobile.Activity.C15_EditPriceActivity.java

private void CloseKeyBoard() {
    InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.hideSoftInputFromWindow(mPrice.getWindowToken(), 0);
}

From source file:com.twentyfourseven.zira.DriverProfileInformation.java

@Override
public void onClick(View v) {
    // TODO Auto-generated method stub
    switch (v.getId()) {
    case R.id.btnSeeDriverLocation:
        // Building Parameters tripId and DriverId
        if (Util.isNetworkAvailable(DriverProfileInformation.this)) {
            ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();
            params.add(new BasicNameValuePair("DriverId", mTripDetailsModel.getGetTrip_DriverId()));
            params.add(new BasicNameValuePair("TripId", SingleTon.getInstance().getDriverTripId()));

            Log.d("tag", "GetDriver Location::" + params.toString());
            AsyncTaskForZira mWebPageTask1 = new AsyncTaskForZira(DriverProfileInformation.this,
                    "GetDriverLocation", params, false, "");
            mWebPageTask1.delegate = (AsyncResponseForZira) DriverProfileInformation.this;
            mWebPageTask1.execute();//w  ww.ja  va 2 s.  co m
        } else {
            Util.alertMessage(DriverProfileInformation.this, "Please check your internet connection");
        }
        break;
    case R.id.imageView_Message:
        InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
        layoutDialog.setVisibility(View.VISIBLE);
        break;
    case R.id.buttonSend:
        try {
            InputMethodManager imm1 = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
            imm1.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);
        } catch (Exception e) {
            // TODO: handle exception
        }
        if (edtMessage.getText().length() == 0) {
            Util.alertMessage(DriverProfileInformation.this, "Please Write Message");
        } else {

            String userid = mTripDetailsModel.getGetTrip_DriverId();
            String message = edtMessage.getText().toString();
            String trigger = "sms";
            Log.i("tag", "userid:" + userid);
            Log.i("tag", "message:" + message);
            Log.i("tag", "trigger:" + trigger);
            // Building Parameters
            if (Util.isNetworkAvailable(DriverProfileInformation.this)) {
                ArrayList<NameValuePair> params1 = new ArrayList<NameValuePair>();
                params1.add(new BasicNameValuePair("Id", userid));
                params1.add(new BasicNameValuePair("message", message));
                params1.add(new BasicNameValuePair("trigger", trigger));

                Log.d("tag", "SendRequest::" + params1.toString());
                AsyncTaskForZira mWebPageTask = new AsyncTaskForZira(DriverProfileInformation.this,
                        sendMessages, params1, true, "Sending message...");
                mWebPageTask.delegate = (AsyncResponseForZira) DriverProfileInformation.this;
                mWebPageTask.execute();
            } else {
                Util.alertMessage(DriverProfileInformation.this, "Please check your internet connection");
            }
            //            new SendMessageParsing().execute();
            edtMessage.setText("");
        }

        break;
    case R.id.imageViewDelete:
        try {
            InputMethodManager imm1 = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
            imm1.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);
        } catch (Exception e) {
            // TODO: handle exception
        }
        edtMessage.setText("");
        layoutDialog.setVisibility(View.GONE);
        break;

    /*case R.id.imageView_Phone:
               
       Intent callIntent = new Intent(Intent.ACTION_CALL);
       callIntent.setData(Uri.parse(jsonmobileno));
       startActivity(callIntent);
       System.err.println("callllllllll");
       break;*/
    }

}

From source file:com.moonpi.tapunlock.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Get lobster_two asset and create typeface
    // Set action bar title to lobster_two typeface
    lobsterTwo = Typeface.createFromAsset(getAssets(), "lobster_two.otf");

    int actionBarTitle = Resources.getSystem().getIdentifier("action_bar_title", "id", "android");
    actionBarTitleView = (TextView) getWindow().findViewById(actionBarTitle);

    if (actionBarTitleView != null) {
        actionBarTitleView.setTypeface(lobsterTwo);
        actionBarTitleView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 28f);
        actionBarTitleView.setTextColor(getResources().getColor(R.color.blue));
    }/* www  .  j  av  a  2 s  . com*/

    setContentView(R.layout.activity_main);

    // Hide keyboard on app launch
    this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
    imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);

    // Get NFC service and adapter
    NfcManager nfcManager = (NfcManager) this.getSystemService(Context.NFC_SERVICE);
    nfcAdapter = nfcManager.getDefaultAdapter();

    // Create PendingIntent for enableForegroundDispatch for NFC tag discovery
    pIntent = PendingIntent.getActivity(this, 0,
            new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0);

    readFromJSON();
    writeToJSON();
    readFromJSON();

    // If Android 4.2 or bigger
    if (Build.VERSION.SDK_INT > 16) {
        // Check if TapUnlock folder exists, if not, create directory
        File folder = new File(Environment.getExternalStorageDirectory() + "/TapUnlock");
        boolean folderSuccess = true;

        if (!folder.exists()) {
            folderSuccess = folder.mkdir();
        }

        try {
            // If blur var bigger than 0
            if (settings.getInt("blur") > 0) {
                // If folder exists or successfully created
                if (folderSuccess) {
                    // If blurred wallpaper file doesn't exist
                    if (!ImageUtils.doesBlurredWallpaperExist()) {
                        // Get default wallpaper
                        WallpaperManager wallpaperManager = WallpaperManager.getInstance(this);
                        final Drawable wallpaperDrawable = wallpaperManager.peekFastDrawable();

                        if (wallpaperDrawable != null) {
                            // Default wallpaper to bitmap - fastBlur the bitmap - store bitmap
                            new Thread(new Runnable() {
                                @Override
                                public void run() {
                                    Bitmap bitmapToBlur = ImageUtils.drawableToBitmap(wallpaperDrawable);

                                    Bitmap blurredWallpaper = null;
                                    if (bitmapToBlur != null)
                                        blurredWallpaper = ImageUtils.fastBlur(MainActivity.this, bitmapToBlur,
                                                blur);

                                    if (blurredWallpaper != null) {
                                        ImageUtils.storeImage(blurredWallpaper);
                                    }
                                }
                            }).start();
                        }
                    }
                }
            }

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

    // Initialize layout items
    pinEdit = (EditText) findViewById(R.id.pinEdit);
    pinEdit.setImeOptions(EditorInfo.IME_ACTION_DONE);
    Button setPin = (Button) findViewById(R.id.setPin);
    ImageButton newTag = (ImageButton) findViewById(R.id.newTag);
    enabled_disabled = (TextView) findViewById(R.id.enabled_disabled);
    Switch toggle = (Switch) findViewById(R.id.toggle);
    seekBar = (SeekBar) findViewById(R.id.seekBar);
    progressBar = (ProgressBar) findViewById(R.id.progressBar);
    Button refreshWallpaper = (Button) findViewById(R.id.refreshWallpaper);
    listView = (ListView) findViewById(R.id.listView);
    backgroundBlurValue = (TextView) findViewById(R.id.backgroundBlurValue);
    noTags = (TextView) findViewById(R.id.noTags);

    // Initialize TagAdapter
    adapter = new TagAdapter(this, tags);

    registerForContextMenu(listView);

    // Set listView adapter to TapAdapter object
    listView.setAdapter(adapter);

    // Set click, check and seekBar listeners
    setPin.setOnClickListener(this);
    newTag.setOnClickListener(this);
    refreshWallpaper.setOnClickListener(this);
    toggle.setOnCheckedChangeListener(this);
    seekBar.setOnSeekBarChangeListener(this);

    // Set seekBar progress to blur var
    try {
        seekBar.setProgress(settings.getInt("blur"));

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

    // Refresh the listView height
    updateListViewHeight(listView);

    // If no tags, show 'Press + to add Tags' textView
    if (tags.length() == 0)
        noTags.setVisibility(View.VISIBLE);

    else
        noTags.setVisibility(View.INVISIBLE);

    // Scroll up
    scrollView = (ScrollView) findViewById(R.id.scrollView);

    scrollView.post(new Runnable() {
        public void run() {
            scrollView.scrollTo(0, scrollView.getTop());
            scrollView.fullScroll(View.FOCUS_UP);
        }
    });

    // If lockscreen enabled, initialize switch, text and start service
    try {
        if (settings.getBoolean("lockscreen")) {
            onStart = true;
            enabled_disabled.setText(R.string.lockscreen_enabled);
            enabled_disabled.setTextColor(getResources().getColor(R.color.green));

            toggle.setChecked(true);
        }

    } catch (JSONException e1) {
        e1.printStackTrace();
    }
}

From source file:org.envirocar.app.activity.RegisterFragment.java

/**
 * Attempts to sign in or register the account specified by the register
 * form. If there are form errors (invalid email, missing fields, etc.), the
 * errors are presented and no actual register attempt is made.
 *///from  w  ww  .  j a  v  a2 s  . c o  m
public void attemptRegister() {
    // Reset errors.
    mUsernameView.setError(null);
    mEmailView.setError(null);
    mPasswordView.setError(null);
    mPasswordConfirmView.setError(null);

    if (mAuthTask != null) {
        return;
    }

    // Store values at the time of the register attempt.
    mUsername = mUsernameView.getText().toString();
    mEmail = mEmailView.getText().toString();
    mPassword = mPasswordView.getText().toString();
    mPasswordConfirm = mPasswordConfirmView.getText().toString();

    boolean cancel = false;
    View focusView = null;

    // TODO fiddle around with order of checks

    // Check for a valid password.
    if (TextUtils.isEmpty(mPassword)) {
        mPasswordView.setError(getString(R.string.error_field_required));
        focusView = mPasswordView;
        cancel = true;
    } else if (mPassword.length() < 6) {
        mPasswordView.setError(getString(R.string.error_invalid_password));
        focusView = mPasswordView;
        cancel = true;
    }

    // check if the password confirm is empty
    if (TextUtils.isEmpty(mPasswordConfirm)) {
        mPasswordConfirmView.setError(getString(R.string.error_field_required));
        focusView = mPasswordConfirmView;
        cancel = true;
    }

    // Check for a valid email address.
    if (TextUtils.isEmpty(mEmail)) {
        mEmailView.setError(getString(R.string.error_field_required));
        focusView = mEmailView;
        cancel = true;
    } else if (!mEmail.matches(
            "^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$")) {
        mEmailView.setError(getString(R.string.error_invalid_email));
        focusView = mEmailView;
        cancel = true;
    }

    // check for valid username
    if (TextUtils.isEmpty(mUsername)) {
        mUsernameView.setError(getString(R.string.error_field_required));
        focusView = mUsernameView;
        cancel = true;
    } else if (mUsername.length() < 6) {
        mUsernameView.setError(getString(R.string.error_invalid_username));
        focusView = mUsernameView;
        cancel = true;
    }

    // check if passwords match
    if (!mPassword.equals(mPasswordConfirm)) {
        mPasswordConfirmView.setError(getString(R.string.error_passwords_not_matching));
        focusView = mPasswordConfirmView;
        cancel = true;
    }

    if (cancel) {
        // There was an error; don't attempt register and focus the first
        // form field with an error.
        focusView.requestFocus();
    } else {
        //hide the keyboard
        InputMethodManager imm = (InputMethodManager) getActivity()
                .getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(mPasswordView.getWindowToken(), 0);

        // Show a progress spinner, and kick off a background task to
        // perform the user register attempt.
        mRegisterStatusMessageView.setText(R.string.register_progress_signing_in);
        showProgress(true);
        mAuthTask = new UserRegisterTask();
        mAuthTask.execute((Void) null);
    }
}

From source file:prince.app.ccm.Fragment_Log.java

public void addFocusListener(EditText xT) {
    xT.setOnFocusChangeListener(new OnFocusChangeListener() {

        @Override//from  w  w w .j  a  va  2s.c o m
        public void onFocusChange(View v, boolean hasFocus) {
            if (!hasFocus) {
                InputMethodManager imm = (InputMethodManager) getActivity()
                        .getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
            }

            else {
                getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
            }

        }
    });
}

From source file:com.tdispatch.passenger.fragment.SearchAddressFragment.java

protected void hideSoftKeyboard() {
    View v = mFragmentView.findViewById(R.id.address);
    InputMethodManager imm = (InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
}

From source file:com.sim2dial.dialer.ChatFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    sipUri = getArguments().getString("SipUri");
    String displayName = getArguments().getString("DisplayName");
    String pictureUri = getArguments().getString("PictureUri");

    view = inflater.inflate(R.layout.chat, container, false);

    contactName = (TextView) view.findViewById(R.id.contactName);
    contactPicture = (AvatarWithShadow) view.findViewById(R.id.contactPicture);

    sendMessage = (TextView) view.findViewById(R.id.sendMessage);
    sendMessage.setOnClickListener(this);

    message = (EditText) view.findViewById(R.id.message);
    if (!getActivity().getResources().getBoolean(R.bool.allow_chat_multiline)) {
        message.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_SHORT_MESSAGE);
        message.setMaxLines(1);//from ww  w  . j a  v  a  2s  . c  o m
    }

    uploadLayout = (RelativeLayout) view.findViewById(R.id.uploadLayout);
    textLayout = (RelativeLayout) view.findViewById(R.id.messageLayout);

    messagesLayout = (RelativeLayout) view.findViewById(R.id.messages);
    messagesScrollView = (ScrollView) view.findViewById(R.id.chatScrollView);
    progressBar = (ProgressBar) view.findViewById(R.id.progressbar);

    sendImage = (TextView) view.findViewById(R.id.sendPicture);
    registerForContextMenu(sendImage);
    sendImage.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            pickImage();
        }
    });

    cancelUpload = (ImageView) view.findViewById(R.id.cancelUpload);
    cancelUpload.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            uploadThread.interrupt();
            uploadLayout.setVisibility(View.GONE);
            textLayout.setVisibility(View.VISIBLE);
            progressBar.setProgress(0);
        }
    });

    displayChat(displayName, pictureUri);

    LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull();
    if (lc != null) {
        chatRoom = lc.createChatRoom(sipUri);
    }

    uploadServerUri = Engine.getPref().getString(getString(R.string.pref_image_sharing_server_key),
            getString(R.string.pref_image_sharing_server_default));

    textWatcher = new TextWatcher() {
        public void afterTextChanged(Editable arg0) {

        }

        public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {

        }

        public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
            if (message.getText().toString().equals("")) {
                sendMessage.setEnabled(false);
            } else {
                sendMessage.setEnabled(true);
            }
        }
    };

    // Force hide keyboard
    if (LinphoneActivity.isInstanciated()) {
        InputMethodManager imm = (InputMethodManager) LinphoneActivity.instance()
                .getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
    }

    // Workaround for SGS3 issue
    if (savedInstanceState != null) {
        fileToUploadPath = savedInstanceState.getString("fileToUploadPath");
        imageToUpload = savedInstanceState.getParcelable("imageToUpload");
    }
    if (fileToUploadPath != null || imageToUpload != null) {
        sendImage.post(new Runnable() {
            @Override
            public void run() {
                sendImage.showContextMenu();
            }
        });
    }

    return view;
}

From source file:org.cryptsecure.Utility.java

/**
 * Hide the keyboard explicitly for a text input field known to be able to
 * get the focus./*from  w ww  .jav  a2  s. c om*/
 * 
 * @param textInput
 *            the text input
 */
public static void hideKeyboardExplicit(EditText textInput) {
    // hide keyboard explicitly
    InputMethodManager imm = (InputMethodManager) textInput.getContext()
            .getSystemService(Context.INPUT_METHOD_SERVICE);
    // imm.restartInput(addUserName);
    imm.hideSoftInputFromWindow(textInput.getWindowToken(), 0);
}

From source file:com.cloudexplorers.plugins.childBrowser.ChildBrowser.java

/**
 * Navigate to the new page/*from   w ww  . java 2s  .  co m*/
 * 
 * @param url
 *          to load
 */
private void navigate(String url) {
    InputMethodManager imm = (InputMethodManager) this.cordova.getActivity()
            .getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.hideSoftInputFromWindow(edittext.getWindowToken(), 0);

    if (!url.startsWith("http") && !url.startsWith("file:")) {
        this.webview.loadUrl("http://" + url);
    } else {
        this.webview.loadUrl(url);
    }
    this.webview.requestFocus();
}

From source file:com.pentacog.mctracker.MCServerTrackerActivity.java

/**
 * @see android.app.Activity#onOptionsItemSelected(MenuItem item)
 *//*from   w  w  w.  j  a  v  a2  s .  c  o m*/
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.menu_refresh:
        serverList.refresh();
        lastRefresh = System.currentTimeMillis();
        return true;
    case R.id.menu_add_server:
        Intent addServer = new Intent(this, AddServerActivity.class);
        startActivityForResult(addServer, AddServerActivity.ADD_SERVER_ACTIVITY_ID);
        return true;
    case R.id.menu_search:
        InputMethodManager mgr = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
        mgr.showSoftInput(getListView(), InputMethodManager.SHOW_FORCED);
        return true;
    default:
        return super.onOptionsItemSelected(item);
    }
}