List of usage examples for android.widget TextView getWindowToken
public IBinder getWindowToken()
From source file:de.tum.frm2.nicos_android.gui.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar);/*ww w .j a va 2 s . co m*/ // Set up the container and its adapter for devices. _moveables = new ArrayList<>(); View content_main = findViewById(R.id.content_main); _devicesAdapter = new DeviceViewAdapter(MainActivity.this, _moveables); final ListView deviceListView = (ListView) content_main.findViewById(R.id.deviceListView); deviceListView.setAdapter(_devicesAdapter); // Set up _uiThread to be a handler that runs runnables on the UI thread. // advantage over runOnUiThread() is that we can actually control the state of the thread // and cancel it, if needed. _uiThread = new Handler(Looper.getMainLooper()); // Default boolean values: Activity is visible, devices not yet fetched _visible = true; _canAccessDevices = false; ConnectionData connData = (ConnectionData) getIntent() .getSerializableExtra(LoginActivity.MESSAGE_CONNECTION_DATA); _uniquePrefix = connData.getHost() + connData.getUser(); // References to the 'steps' views. _coarseStepEditText = (EditText) findViewById(R.id.coarseStepEditText); _fineStepEditText = (EditText) findViewById(R.id.fineStepEditText); TextView.OnEditorActionListener onEditorActionListener = new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView textView, int actionID, KeyEvent keyEvent) { if (actionID == EditorInfo.IME_ACTION_DONE) { _fineStepEditText.clearFocus(); // Hide keyboard. InputMethodManager manager = (InputMethodManager) getSystemService( Context.INPUT_METHOD_SERVICE); manager.hideSoftInputFromWindow(textView.getWindowToken(), 0); } return false; } }; // When hitting 'enter' or 'ok' on the keyboard while in EditText, apply changes and hide // keyboard. _coarseStepEditText.setOnEditorActionListener(onEditorActionListener); _fineStepEditText.setOnEditorActionListener(onEditorActionListener); TextWatcher textWatcher = 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) { saveSteps(); } }; _coarseStepEditText.addTextChangedListener(textWatcher); _fineStepEditText.addTextChangedListener(textWatcher); // Reference to the bottom slider panel + initial height. _slidingUpPanelLayout = (SlidingUpPanelLayout) findViewById(R.id.sliding_layout); // Change behavior of Panel when state changes. _slidingUpPanelLayout.addPanelSlideListener(new SlidingUpPanelLayout.PanelSlideListener() { @Override public void onPanelSlide(View panel, float slideOffset) { } @Override public void onPanelStateChanged(View panel, SlidingUpPanelLayout.PanelState previousState, SlidingUpPanelLayout.PanelState newState) { if (newState == SlidingUpPanelLayout.PanelState.COLLAPSED) { // When hiding the panel, also hide the keyboard and clear all focuses. InputMethodManager manager = (InputMethodManager) getSystemService( Context.INPUT_METHOD_SERVICE); manager.hideSoftInputFromWindow(panel.getWindowToken(), 0); _coarseStepEditText.clearFocus(); _coarseStepEditText.setImeOptions(EditorInfo.IME_ACTION_DONE); _fineStepEditText.clearFocus(); _fineStepEditText.setImeOptions(EditorInfo.IME_ACTION_DONE); } } }); // Reference to current device and the 3 subviews of currentDeviceView. // That means the name label, value label and status image. _currentDevice = null; _currentDeviceTextView = (TextView) findViewById(R.id.deviceNameTextView); _currentDeviceValueTextView = (TextView) findViewById(R.id.deviceValueTextView); _currentDeviceStatusImageView = (ImageView) findViewById(R.id.statusledView); // References to the 5 control buttons. _coarseStepLeftButton = (Button) findViewById(R.id.coarseStepLeftButton); _coarseStepLeftButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { onStepButtonClicked(_coarseStepLeftButton); } }); _fineStepLeftButton = (Button) findViewById(R.id.fineStepLeftButton); _fineStepLeftButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { onStepButtonClicked(_fineStepLeftButton); } }); _stopButton = (Button) findViewById(R.id.stopButton); _stopButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { onStopButtonClicked(); } }); _fineStepRightButton = (Button) findViewById(R.id.fineStepRightButton); _fineStepRightButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { onStepButtonClicked(_fineStepRightButton); } }); _coarseStepRightButton = (Button) findViewById(R.id.coarseStepRightButton); _coarseStepRightButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { onStepButtonClicked(_coarseStepRightButton); } }); _slidingUpPanelLayout.setEnabled(false); // Change behavior when clicking/tapping on a device. deviceListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) { Device device = (Device) deviceListView.getItemAtPosition(position); onDeviceSelected(device); } }); NicosClient.getClient().registerCallbackHandler(this); new Thread(new Runnable() { @Override public void run() { on_client_connected(); } }).start(); }
From source file:com.landenlabs.all_devtool.PackageFragment.java
@Override public void onClick(View v) { int id = v.getId(); switch (id) { case R.id.pkgLoadBtn: m_pkgLoadBtn.setVisibility(View.GONE); updateList();// w ww. j ava 2 s. c om break; case R.id.package_uninstall: if (m_uninstallResId == R.string.package_del_cache) deleteCaches(); else uninstallPackages(); break; case R.id.pkg_plus_minus_toggle: if (m_expand_collapse_toggle.isChecked()) expandAll(); else collapseAll(); break; case R.id.pkg_title: if (TextUtils.isEmpty(m_title.getHint())) { // m_title.setTag(m_title.getText()); m_title.setText(""); m_title.setHint("Filter"); if (m_list.size() > m_beforeFilter.size()) { m_beforeFilter.clear(); m_beforeFilter.addAll(m_list); } m_title.setOnEditorActionListener(new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView edView, int actionId, KeyEvent event) { if (actionId == EditorInfo.IME_ACTION_DONE) { String filter = edView.getText().toString(); filterPackages(filter); // hideKeyboard InputMethodManager imm = (InputMethodManager) edView.getContext() .getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(edView.getWindowToken(), 0); return true; // consume. } return false; // pass on to other listeners. } }); } break; } }
From source file:com.aslanoba.hwc.SettingsActivity.java
/** * Click handler for the list items. Will create the appropriate edit * box for the clicked setting./*from ww w. j a v a 2 s . c o m*/ */ @Override public void onListItemClick(ListView oParent, View v, int iPos, long id) { final ListView oParentListView = oParent; final SettingsListItem oItem = m_filteredSettings.get(iPos); if (oItem instanceof ChoiceSettingsListItem) { final ChoiceSettingsListItem oChoiceItem = (ChoiceSettingsListItem) oItem; // Show dialog new AlertDialog.Builder(SettingsActivity.this) .setTitle(getString(R.string.Label_Edit) + " " + oItem.m_sLabel) .setSingleChoiceItems(oChoiceItem.m_asText, oChoiceItem.m_iSelectedItem, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { oChoiceItem.select(whichButton); if (oItem.m_iPropId == PropertyID.CONNECTION_AUTO_REGISTRATION_HINT) { m_iRegistrationMethod = (Integer) oChoiceItem.m_oValue; if (m_iRegistrationMethod == Settings.REGISTRATION_METHOD.CERTIFICATE) { handleLocalCertificateSelection(); } } // refresh in ui refreshList(); oParentListView.invalidate(); // Close dialog dialog.dismiss(); } }) .setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { // Close dialog dialog.dismiss(); } }).show(); } else { // inflate the xml layout final View oView = m_oInflater.inflate(R.layout.settings_edit, null); TextView tv = (TextView) oView.findViewById(R.id.TextViewEditSettings); if (tv != null) tv.setText(getItemLabel(oItem)); // set value tv = (TextView) oView.findViewById(R.id.EditTextEditSettings); if (tv != null) tv.setText(oItem.m_oValue.toString()); // special input validator for integers if (oItem.m_oValue instanceof Integer) tv.setInputType(InputType.TYPE_CLASS_NUMBER); if (oItem.m_bPassword) tv.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD); // show dialog, valid value when user clicks ok button new AlertDialog.Builder(this).setTitle(getString(R.string.Label_Edit) + " " + getItemLabel(oItem)) .setView(oView).setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { TextView tv = (TextView) oView.findViewById(R.id.EditTextEditSettings); String sText = tv.getText().toString(); if (oItem.m_oValue instanceof Integer) oItem.m_oValue = Integer.parseInt(sText); else if (oItem.m_oValue instanceof Boolean) oItem.m_oValue = Boolean.parseBoolean(sText); else oItem.m_oValue = sText; InputMethodManager imm = (InputMethodManager) getSystemService( Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(tv.getWindowToken(), 0); //validate the input value if (!validateField(oItem)) { // validation failed, reset to original value oItem.m_oValue = oItem.m_oOrigValue; showValidationErrorDialog(oItem.m_sLabel); } else { // refresh in ui refreshList(); oParentListView.invalidate(); } } }).setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { TextView tv = (TextView) oView.findViewById(R.id.EditTextEditSettings); InputMethodManager imm = (InputMethodManager) getSystemService( Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(tv.getWindowToken(), 0); dialog.dismiss(); } }).show(); } }