List of usage examples for android.view View getWindowToken
public IBinder getWindowToken()
From source file:com.ferid.app.classroom.statistics.StatisticalListActivity.java
/** * Hide keyboard//w w w .j a v a 2 s . c o m */ private void hideKeyboard() { View view = this.getCurrentFocus(); if (view != null) { InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(view.getWindowToken(), 0); } }
From source file:prince.app.ccm.Fragment_Log.java
public void addFocusListener(EditText xT) { xT.setOnFocusChangeListener(new OnFocusChangeListener() { @Override/*from w w w .ja v a2 s .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:org.secuso.privacyfriendlypasswordgenerator.dialogs.GeneratePasswordDialog.java
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { LayoutInflater inflater = getActivity().getLayoutInflater(); AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); rootView = inflater.inflate(R.layout.dialog_generate_password, null); Bundle bundle = getArguments();//from www . j a v a 2 s . c o m position = bundle.getInt("position"); clipboard_enabled = bundle.getBoolean("clipboard_enabled"); bindToDevice_enabled = bundle.getBoolean("bindToDevice_enabled"); hashAlgorithm = bundle.getString("hash_algorithm"); number_iterations = bundle.getInt("number_iterations"); visibility = false; spinner = (ProgressBar) rootView.findViewById(R.id.progressBar); spinner.setVisibility(View.GONE); database = MetaDataSQLiteHelper.getInstance(getActivity()); metaData = database.getMetaData(position); TextView domain = (TextView) rootView.findViewById(R.id.domainHeadingTextView); domain.setText(metaData.getDOMAIN()); TextView username = (TextView) rootView.findViewById(R.id.domainUsernameTextView); username.setText(metaData.getUSERNAME()); TextView iteration = (TextView) rootView.findViewById(R.id.textViewIteration); iteration.setText(String.valueOf(metaData.getITERATION())); builder.setView(rootView); builder.setIcon(R.mipmap.ic_drawer); builder.setTitle(getActivity().getString(R.string.generate_heading)); builder.setPositiveButton(getActivity().getString(R.string.done), null); Button generateButton = (Button) rootView.findViewById(R.id.generatorButton); generateButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { TextView textViewPassword = (TextView) rootView.findViewById(R.id.textViewPassword); textViewPassword.setText(""); InputMethodManager inputManager = (InputMethodManager) getActivity() .getSystemService(Context.INPUT_METHOD_SERVICE); inputManager.hideSoftInputFromWindow(view.getWindowToken(), InputMethodManager.RESULT_UNCHANGED_SHOWN); editTextMasterpassword = (EditText) rootView.findViewById(R.id.editTextMasterpassword); if (editTextMasterpassword.getText().toString().length() == 0) { Toast toast = Toast.makeText(getActivity().getBaseContext(), getString(R.string.enter_masterpassword), Toast.LENGTH_SHORT); toast.show(); } else if (editTextMasterpassword.getText().toString().length() < 8) { Toast toast = Toast.makeText(getActivity().getBaseContext(), getString(R.string.masterpassword_length), Toast.LENGTH_SHORT); toast.show(); } else { spinner.setVisibility(View.VISIBLE); generatePassword(); } } }); ImageButton copyButton = (ImageButton) rootView.findViewById(R.id.copyButton); copyButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { TextView password = (TextView) rootView.findViewById(R.id.textViewPassword); if (password.getText().toString().length() > 0) { ClipboardManager clipboard = (ClipboardManager) getActivity() .getSystemService(CLIPBOARD_SERVICE); ClipData clip = ClipData.newPlainText("", password.getText()); clipboard.setPrimaryClip(clip); Toast.makeText(getActivity(), getActivity().getString(R.string.password_copied), Toast.LENGTH_SHORT).show(); } } }); visibilityButton = (ImageButton) rootView.findViewById(R.id.visibilityButton); visibilityButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { editTextMasterpassword = (EditText) rootView.findViewById(R.id.editTextMasterpassword); if (!visibility) { visibilityButton.setImageResource(R.drawable.ic_visibility_off); editTextMasterpassword.setInputType(InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD); editTextMasterpassword.setSelection(editTextMasterpassword.getText().length()); visibility = true; } else { visibilityButton.setImageResource(R.drawable.ic_visibility); editTextMasterpassword .setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD); editTextMasterpassword.setSelection(editTextMasterpassword.getText().length()); visibility = false; } } }); return builder.create(); }
From source file:com.smartcodeunited.demo.bluetooth.activity.BaseActivity.java
/** * Hide the input method//from w w w . jav a 2 s . com */ public void hideInputMethod(View view) { InputMethodManager m = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); if (getCurrentFocus() != null && m.isActive()) { if (view == null) { view = getCurrentFocus(); } m.hideSoftInputFromWindow(view.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); } }
From source file:com.microsoft.projectoxford.face.samples.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); isSmsPermissionGranted();//from w w w .j a va 2 s . c o m final SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0); String userName = settings.getString("userName", ""); String password = settings.getString("password", ""); passwordField = (EditText) findViewById(R.id.passwordFieldText); userNameField = (EditText) findViewById(R.id.userNameFieldText); forgot_password = (TextView) findViewById(R.id.forgot_password); passwordField.setText(password); userNameField.setText(userName); signButton = (ImageButton) findViewById(R.id.signButton); registerNowButton = (ImageButton) findViewById(R.id.registerButton); helloGuest = (TextView) findViewById(R.id.helloGuestLable); logo = (ImageView) findViewById(R.id.logo); progressDialog = new ProgressDialog(this); progressDialog.setTitle(getString(R.string.progress_dialog_title)); userNameField.setImeActionLabel("", EditorInfo.IME_ACTION_NEXT); userNameField.setOnEditorActionListener(new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if (actionId == EditorInfo.IME_ACTION_NEXT) { if (userNameField.getText().toString().trim().equalsIgnoreCase("")) { userNameField.setError("Oops! you need to fill this field"); View view = getCurrentFocus(); if (view != null) { InputMethodManager imm = (InputMethodManager) getSystemService( Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(view.getWindowToken(), 0); } } return false; } return false; } }); //forgot password action forgot_password.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { LayoutInflater li = LayoutInflater.from(MainActivity.this); View promptsView = li.inflate(R.layout.email_prompt, null); AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(MainActivity.this); // set prompts.xml to alertdialog builder alertDialogBuilder.setView(promptsView); final EditText userInput = (EditText) promptsView.findViewById(R.id.editTextDialogUserInput); // set dialog message alertDialogBuilder.setCancelable(false) .setPositiveButton("OK", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { // get user input and set it to result // edit text //result.setText(userInput.getText()); if (!userInput.getText().toString().equals("")) { ParseUser.requestPasswordResetInBackground(userInput.getText().toString(), new RequestPasswordResetCallback() { public void done(ParseException e) { if (e == null) { Toast.makeText(MainActivity.this, "An email was successfully " + "sent with reset instructions.", Toast.LENGTH_LONG).show(); } else { Toast.makeText(MainActivity.this, "Something went wrong.", Toast.LENGTH_LONG).show(); // Something went wrong. Look at the ParseException to see what's up. } } }); } else Toast.makeText(getApplicationContext(), "sorry you must enter your mail", Toast.LENGTH_SHORT).show(); } }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }); // create alert dialog AlertDialog alertDialog = alertDialogBuilder.create(); // show it alertDialog.show(); } } ); registerNowButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { Intent intent = new Intent(getBaseContext(), LoginActivity.class); startActivity(intent); } } ); signButton.setOnClickListener(new View.OnClickListener() { public void onClick(View arg0) { usernametxt = userNameField.getText().toString(); passwordtxt = passwordField.getText().toString(); if (!usernametxt.equals(settings.getString("userName", "")) || !passwordtxt.equals(settings.getString("password", ""))) { open(getCurrentFocus()); } else { // Retrieve the text entered from the EditText progressDialog.setMessage("please wait..."); progressDialog.show(); connect(); } } } ); }
From source file:de.unipassau.isl.evs.ssh.app.activity.AppMainActivity.java
/** * Displays a fragment and takes care of lifecycle actions like saving state when rotating the * screen or managing the back button behavior. * * @param clazz the class of the fragment to show * @param bundle the bundle that is given with the new fragment */// w ww . ja v a 2 s .c o m public void showFragmentByClass(Class clazz, Bundle bundle) { Class classToShow = clazz; final boolean isRegistered = isRegistered(); final Permission permission = permissionForFragment.get(classToShow); if (permission != null && !hasPermission(permission) && isRegistered) { Toast.makeText(this, String.format(getString(R.string.fragment_access_denied), permission.toLocalizedString(this)), Toast.LENGTH_SHORT).show(); return; } final Fragment currentFragment = getCurrentFragment(); if (currentFragment != null && Objects.equals(classToShow, currentFragment.getClass())) { return; } // avoid leaving the welcome fragment before registration if (!isRegistered) { classToShow = WelcomeScreenFragment.class; } final Fragment fragment; try { fragment = (Fragment) classToShow.newInstance(); if (bundle != null) { fragment.setArguments(bundle); } } catch (InstantiationException | IllegalAccessException e) { Log.wtf(TAG, "Could not instantiate fragment", e); return; } // Hide Keyboard before every fragment transaction View view = getCurrentFocus(); if (view != null) { InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(view.getWindowToken(), 0); } FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); transaction.replace(R.id.fragment_container, fragment); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { if (currentFragment instanceof MainFragment && fragment instanceof HolidayFragment) { View fragmentView = currentFragment.getView(); if (fragmentView != null) { transaction.addSharedElement(fragmentView.findViewById(R.id.holidayButton), "holidayIconTransition"); } final TransitionInflater inflater = TransitionInflater.from(this); currentFragment.setSharedElementReturnTransition( inflater.inflateTransition(R.transition.change_image_trans)); currentFragment.setExitTransition(inflater.inflateTransition(android.R.transition.explode)); fragment.setSharedElementEnterTransition( inflater.inflateTransition(R.transition.change_image_trans)); fragment.setEnterTransition(inflater.inflateTransition(android.R.transition.explode)); } else if (fragment instanceof MainFragment && currentFragment != null) { transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_CLOSE); } else { transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN); } } transaction.commit(); }
From source file:com.handpoint.headstart.client.ui.ReceiptActivity.java
void hideSoftKeyboard(View v) { InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(v.getWindowToken(), 0); }
From source file:net.nakama.duckdroid.ui.Duckdroid.java
private void clearFocus(View v) { InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(v.getWindowToken(), 0); }
From source file:com.nttec.everychan.ui.NewTabFragment.java
private void showKeyboard(View v) { try {/*from w w w .j a va2 s . c o m*/ ((InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE)) .toggleSoftInputFromWindow(v.getWindowToken(), InputMethodManager.SHOW_FORCED, 0); } catch (Exception e) { Logger.e(TAG, e); } }
From source file:org.ymegane.android.approom.AppDisplayFragment.java
private void initSearchView(MenuItem item) { final SearchView searchView = (SearchView) MenuItemCompat.getActionView(item); searchView.setQueryHint(getString(R.string.search_hint)); searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { @Override/*from ww w . j ava2s . c o m*/ public boolean onQueryTextSubmit(String s) { return false; } @Override public boolean onQueryTextChange(String s) { updateSearchResult(s); return true; } }); searchView.setOnCloseListener(new SearchView.OnCloseListener() { @Override public boolean onClose() { updateSearchResult(null); return false; } }); searchView.setOnFocusChangeListener(new View.OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { if (!hasFocus) { InputMethodManager inputMethodManager = (InputMethodManager) getActivity() .getSystemService(Context.INPUT_METHOD_SERVICE); inputMethodManager.hideSoftInputFromWindow(v.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); } } }); }