List of usage examples for android.view.inputmethod EditorInfo IME_ACTION_DONE
int IME_ACTION_DONE
To view the source code for android.view.inputmethod EditorInfo IME_ACTION_DONE.
Click Source Link
From source file:jahirfiquitiva.iconshowcase.fragments.PreviewsFragment.java
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { super.onCreateOptionsMenu(menu, inflater); inflater.inflate(R.menu.search, menu); mSearchItem = menu.findItem(R.id.search); mSearchView = (SearchView) MenuItemCompat.getActionView(mSearchItem); mSearchView.setQueryHint(getString(R.string.search_x, tabs[mLastSelected])); mSearchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { @Override/* ww w . jav a2 s . co m*/ public boolean onQueryTextSubmit(String s) { search(s); return false; } @Override public boolean onQueryTextChange(String s) { search(s); return false; } private void search(String s) { IconsFragment frag = (IconsFragment) getChildFragmentManager() .findFragmentByTag("page:" + mPager.getCurrentItem()); if (frag != null) frag.performSearch(s); } }); mSearchView.setImeOptions(EditorInfo.IME_ACTION_DONE); int iconsColor = ThemeUtils.darkTheme ? ContextCompat.getColor(getActivity(), R.color.toolbar_text_dark) : ContextCompat.getColor(getActivity(), R.color.toolbar_text_light); ToolbarTinter.on(menu).setIconsColor(iconsColor).forceIcons().reapplyOnChange(true).apply(getActivity()); }
From source file:co.beem.project.beem.ui.wizard.AccountConfigureFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v = inflater.inflate(R.layout.wizard_account_configure, container, false); mNextButton = (TextView) v.findViewById(R.id.next); mNextButton.setEnabled(false);// ww w.j a v a2 s . c o m mNextButton.setOnClickListener(this); mErrorLabel = (TextView) v.findViewById(R.id.error_label); mSettingsWarningLabel = (TextView) v.findViewById(R.id.settings_warn_label); errorDivider = v.findViewById(R.id.error_divider); mAccountJID = (EditText) v.findViewById(R.id.account_username); mAccountJID.setOnFocusChangeListener(new OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { isAccountEdtFocused = hasFocus; } }); mAccountPassword = (EditText) v.findViewById(R.id.account_password); mAccountPassword.setOnFocusChangeListener(new OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { isPasswordEdtFocused = hasFocus; } }); //mAccountJID.setFilters(newFilters); mAccountJID.addTextChangedListener(mJidTextWatcher); mAccountPassword.addTextChangedListener(mPasswordTextWatcher); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH) // true to disable the feature until ready v.findViewById(R.id.account_layout).setVisibility(View.GONE); mAccountPassword.setImeOptions(EditorInfo.IME_ACTION_DONE); mAccountPassword.setOnEditorActionListener(new OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if (event != null) { if (!event.isShiftPressed()) { onClick(mNextButton); return true; } return false; } onClick(mNextButton); return true; } }); showBtn = (TextView) v.findViewById(R.id.login_show_btn); showBtn.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (!isPasswordShowing) { showBtn.setText(getText(R.string.hide)); mAccountPassword.setInputType(InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD); } else { showBtn.setText(getText(R.string.show)); mAccountPassword .setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD); } mAccountPassword.setSelection(mAccountPassword.length()); isPasswordShowing = !isPasswordShowing; } }); createNewAccountButton = (TextView) v.findViewById(R.id.create_new_account); createNewAccountButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { ((Account) getActivity()).pushFragment( WebViewFragment.instanciate("https://m.facebook.com/r.php?loc=bottom&refid=8")); } }); forgotPasswordTv = (TextView) v.findViewById(R.id.forgot_password_tv); forgotPasswordTv.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { ((Account) getActivity()).pushFragment( WebViewFragment.instanciate("https://m.facebook.com/login/identify/?ctx=recover")); } }); helpTextview = (TextView) v.findViewById(R.id.help_tv); helpTextview.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { ((Account) getActivity()) .pushFragment(WebViewFragment.instanciate("https://m.facebook.com/help/?refid=8")); } }); return v; }
From source file:com.waz.zclient.newreg.fragments.EmailInvitationFragment.java
@Override public void onResume() { super.onResume(); signUpAlternativeButton.setOnClickListener(this); registerButton.setOnClickListener(this); passwordEditText.addTextChangedListener(this); passwordEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() { @Override/*from w ww . j a v a2 s. c om*/ public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { return actionId == EditorInfo.IME_ACTION_DONE && isPasswordValid(); } }); }
From source file:edu.cmu.cylab.starslinger.view.FindContactActivity.java
public void generateView() { setContentView(R.layout.contact_adder); final ActionBar bar = getSupportActionBar(); bar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD); bar.setTitle(R.string.app_name);/*w w w . j a v a2s .c om*/ bar.setSubtitle(R.string.title_find); getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); // Obtain handles to UI objects mEditTextName = (EditText) findViewById(R.id.contactNameEditText); mButtonDone = (Button) findViewById(R.id.contactDoneButton); mEditTextPassNext = (EditText) findViewById(R.id.EditTextPassphrase); mEditTextPassDone = (EditText) findViewById(R.id.EditTextPassphraseAgain); mTextViewLicensePrivacy = (TextView) findViewById(R.id.textViewLicensePrivacy); mSpinnerLanguage = (Spinner) findViewById(R.id.spinnerLanguage); final ArrayAdapter<CharSequence> adapter = new ArrayAdapter<CharSequence>(this, android.R.layout.simple_spinner_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); final ArrayList<String> codes = SafeSlinger.getApplication().getListLanguages(true); mSpinnerLanguage.setPrompt(getText(R.string.title_language)); mSpinnerLanguage.setAdapter(adapter); ArrayList<String> all = SafeSlinger.getApplication().getListLanguages(false); for (String l : all) { adapter.add(l); } mSpinnerLanguage.setSelection(codes.indexOf(SafeSlingerPrefs.getLanguage())); // read defaults and set them mSelectedName = SafeSlingerPrefs.getContactName(); // see if name is there... if (mSelectedName != null) { mEditTextName.setText(mSelectedName); } mEditTextPassNext.setVisibility(View.VISIBLE); mEditTextPassNext.setHint(R.string.label_PassHintCreate); mEditTextPassDone.setHint(R.string.label_PassHintRepeat); // enable hyperlinks mTextViewLicensePrivacy.setText(Html.fromHtml("<a href=\"" + SafeSlingerConfig.EULA_URL + "\">" + getText(R.string.menu_License) + "</a> / <a href=\"" + SafeSlingerConfig.PRIVACY_URL + "\">" + getText(R.string.menu_PrivacyPolicy) + "</a>")); mTextViewLicensePrivacy.setMovementMethod(LinkMovementMethod.getInstance()); mSpinnerLanguage.setOnItemSelectedListener(new OnItemSelectedListener() { @TargetApi(Build.VERSION_CODES.HONEYCOMB) @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long i) { if (!codes.get(position).equals(SafeSlingerPrefs.getLanguage())) { SafeSlingerPrefs.setLanguage(codes.get(position)); SafeSlinger.getApplication().updateLanguage(codes.get(position)); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { recreate(); } else { generateView(); } } } @Override public void onNothingSelected(AdapterView<?> parent) { // We don't need to worry about nothing being selected } }); mEditTextName.setOnFocusChangeListener(new OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { mSelectedName = mEditTextName.getText().toString(); } }); mButtonDone.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { onDoneButtonClicked(); } }); mEditTextPassDone.setOnEditorActionListener(new OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if (actionId == EditorInfo.IME_ACTION_DONE) { doValidatePassphrase(); return true; } return false; } }); }
From source file:com.nerderylabs.android.nerdalert.ui.fragment.MainFragment.java
private void initializeNametag() { final EditText nameEditText = (EditText) view.findViewById(R.id.my_name); final EditText taglineEditText = (EditText) view.findViewById(R.id.my_tagline); final ImageView photoImageView = (ImageView) view.findViewById(R.id.my_photo); // restore state nameEditText.setText(myInfo.getName()); taglineEditText.setText(myInfo.getTagline()); if (myInfo.getBitmap() != null) { photoImageView.setImageDrawable(new BitmapDrawable(getResources(), myInfo.getBitmap())); } else {/* w w w .j av a 2 s. c o m*/ Drawable photo = ContextCompat.getDrawable(getContext(), R.drawable.ic_contact_photo); DrawableCompat.setTint(photo, ContextCompat.getColor(getContext(), R.color.color_nametag)); photoImageView.setImageDrawable(photo); } // listen for focus change View.OnFocusChangeListener focusListener = new View.OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { if (!hasFocus) { persistNametagValues((TextView) v); } } }; // listen for the done key EditText.OnEditorActionListener doneListener = new EditText.OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if (actionId == EditorInfo.IME_ACTION_DONE) { persistNametagValues(v); } return false; } }; // open profile contact card when user's photo is tapped ImageView.OnClickListener imageClickListener = new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(Intent.ACTION_EDIT); intent.setDataAndType(ContactsContract.Profile.CONTENT_URI, ContactsContract.Contacts.CONTENT_ITEM_TYPE); // In Android 4.0 (API version 14) and later, a problem in the contacts app causes // incorrect navigation.To work around this problem in Android 4.0.3 (API version // 15) and later, add the extended data key finishActivityOnSaveCompleted to the // intent, with a value of true. intent.putExtra("finishActivityOnSaveCompleted", true); startActivity(intent); } }; nameEditText.setOnEditorActionListener(doneListener); taglineEditText.setOnEditorActionListener(doneListener); nameEditText.setOnFocusChangeListener(focusListener); taglineEditText.setOnFocusChangeListener(focusListener); photoImageView.setOnClickListener(imageClickListener); }
From source file:com.esminis.server.library.activity.main.MainViewImpl.java
private void setupListeners(Activity activity) { viewDocumentRoot.setOnClickListener(new View.OnClickListener() { public void onClick(View arg0) { presenter.showDocumentRootChooser(); }/*from ww w .ja v a2 s . co m*/ }); viewPort.setOnEditorActionListener(new TextView.OnEditorActionListener() { public boolean onEditorAction(TextView text, int actionId, KeyEvent event) { if (actionId == EditorInfo.IME_ACTION_DONE) { final Activity activity = MainViewImpl.this.activity.get(); if (activity != null) { ((InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE)) .hideSoftInputFromWindow(text.getWindowToken(), 0); return true; } } return false; } }); viewPort.addTextChangedListener(new TextWatcher() { public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) { } public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) { } public void afterTextChanged(Editable text) { presenter.portModified(text.toString()); } }); activity.findViewById(R.id.start).setOnClickListener(new View.OnClickListener() { public void onClick(View view) { presenter.serverStart(); } }); activity.findViewById(R.id.stop).setOnClickListener(new View.OnClickListener() { public void onClick(View view) { presenter.serverStop(); } }); viewContainer.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View view, MotionEvent event) { removeFocus(); return true; } }); activity.findViewById(R.id.preloader_button_ok).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { presenter.requestPermission(); } }); buttonStart.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { presenter.serverStart(); } }); buttonStop.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { presenter.serverStop(); } }); viewInstalledPackage.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { presenter.requestPackageInstall(); } }); }
From source file:com.agateau.equiv.ui.MealItemDetailActivity.java
private void setupMealEditor() { TextView.OnEditorActionListener onEditorActionListener = new TextView.OnEditorActionListener() { @Override/*w ww. ja v a 2 s. c o m*/ public boolean onEditorAction(TextView textView, int actionId, KeyEvent keyEvent) { if (actionId == EditorInfo.IME_ACTION_DONE) { save(); return true; } return false; } }; mProductNameView = (TextView) findViewById(R.id.product_name_view); mDetailsLayout = (LinearLayout) findViewById(R.id.details_layout); mQuantityEdit = (EditText) findViewById(R.id.quantity_edit); mQuantityEdit.setOnEditorActionListener(onEditorActionListener); mQuantityEdit.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { } @Override public void afterTextChanged(Editable s) { updateQuantityEquivEdit(); } }); mQuantityUnitView = (TextView) findViewById(R.id.quantity_unit); mQuantityEquivEdit = (EditText) findViewById(R.id.quantity_equiv_edit); mQuantityEquivEdit.setOnEditorActionListener(onEditorActionListener); mQuantityEquivEdit.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { } @Override public void afterTextChanged(Editable s) { updateQuantityEdit(); } }); mQuantityEquivUnitView = (TextView) findViewById(R.id.quantity_equiv_unit); if (mMealItemPosition != NEW_MEAL_ITEM_POSITION) { setTitle(R.string.edit_meal_item_title); initFromMealItem(mMeal.getItems().get(mMealItemPosition)); } }
From source file:com.wifiafterconnect.WifiAuthenticatorActivity.java
private void addField(HtmlInput field) { Log.d(Constants.TAG, "adding [" + field.getName() + "], type = [" + field.getType() + "]"); TextView labelView = new TextView(this); labelView.setText(field.getName());//from ww w.jav a2s.co m int textSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, (float) 8, getResources().getDisplayMetrics()); labelView.setTextSize(textSize); EditText editView = new EditText(this); editView.setInputType(field.getAndroidInputType()); editView.setText(field.getValue()); editView.setTag(field.getName()); editView.setFocusable(true); edits.add(editView); editView.setOnEditorActionListener(new EditText.OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if (actionId == EditorInfo.IME_ACTION_DONE) { onAuthenticateClick(v); } return false; } }); TableRow row = new TableRow(this); fieldsTable.addView(row, new TableLayout.LayoutParams(TableLayout.LayoutParams.MATCH_PARENT, TableLayout.LayoutParams.WRAP_CONTENT)); TableRow.LayoutParams labelLayout = new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT); int margin = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, (float) 5, getResources().getDisplayMetrics()); labelLayout.setMargins(margin, margin, margin, margin); row.addView(labelView, labelLayout); TableRow.LayoutParams editLayout = new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.WRAP_CONTENT); row.addView(editView, editLayout); }
From source file:com.b44t.ui.Components.PasscodeView.java
public PasscodeView(final Context context) { super(context); setWillNotDraw(false);/* w w w .j a v a 2 s .c om*/ setVisibility(GONE); backgroundFrameLayout = new FrameLayout(context); addView(backgroundFrameLayout); LayoutParams layoutParams = (LayoutParams) backgroundFrameLayout.getLayoutParams(); layoutParams.width = LayoutHelper.MATCH_PARENT; layoutParams.height = LayoutHelper.MATCH_PARENT; backgroundFrameLayout.setLayoutParams(layoutParams); passwordFrameLayout = new FrameLayout(context); addView(passwordFrameLayout); layoutParams = (LayoutParams) passwordFrameLayout.getLayoutParams(); layoutParams.width = LayoutHelper.MATCH_PARENT; layoutParams.height = LayoutHelper.MATCH_PARENT; layoutParams.gravity = Gravity.TOP | Gravity.LEFT; passwordFrameLayout.setLayoutParams(layoutParams); ImageView imageView = new ImageView(context); imageView.setScaleType(ImageView.ScaleType.FIT_XY); imageView.setImageResource(R.drawable.ic_launcher /* EDIT BY MR -- was: passcode_logo */); passwordFrameLayout.addView(imageView); layoutParams = (LayoutParams) imageView.getLayoutParams(); if (AndroidUtilities.density < 1) { layoutParams.width = AndroidUtilities.dp(30); layoutParams.height = AndroidUtilities.dp(30); } else { layoutParams.width = AndroidUtilities.dp(40); layoutParams.height = AndroidUtilities.dp(40); } layoutParams.gravity = Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM; layoutParams.bottomMargin = AndroidUtilities.dp(100); imageView.setLayoutParams(layoutParams); passcodeTextView = new TextView(context); passcodeTextView.setTextColor(0xffffffff); passcodeTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14); passcodeTextView.setGravity(Gravity.CENTER_HORIZONTAL); passwordFrameLayout.addView(passcodeTextView); layoutParams = (LayoutParams) passcodeTextView.getLayoutParams(); layoutParams.width = LayoutHelper.WRAP_CONTENT; layoutParams.height = LayoutHelper.WRAP_CONTENT; layoutParams.bottomMargin = AndroidUtilities.dp(62); layoutParams.gravity = Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL; passcodeTextView.setLayoutParams(layoutParams); passwordEditText = new EditText(context); passwordEditText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 36); passwordEditText.setTextColor(0xffffffff); passwordEditText.setMaxLines(1); passwordEditText.setLines(1); passwordEditText.setGravity(Gravity.CENTER_HORIZONTAL); passwordEditText.setSingleLine(true); passwordEditText.setImeOptions(EditorInfo.IME_ACTION_DONE); passwordEditText.setTypeface(Typeface.DEFAULT); passwordEditText.setBackgroundDrawable(null); AndroidUtilities.clearCursorDrawable(passwordEditText); passwordFrameLayout.addView(passwordEditText); layoutParams = (FrameLayout.LayoutParams) passwordEditText.getLayoutParams(); layoutParams.height = LayoutHelper.WRAP_CONTENT; layoutParams.width = LayoutHelper.MATCH_PARENT; layoutParams.leftMargin = AndroidUtilities.dp(70); layoutParams.rightMargin = AndroidUtilities.dp(70); layoutParams.bottomMargin = AndroidUtilities.dp(6); layoutParams.gravity = Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL; passwordEditText.setLayoutParams(layoutParams); passwordEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) { if (i == EditorInfo.IME_ACTION_DONE) { processDone(false); return true; } return false; } }); passwordEditText.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { } @Override public void afterTextChanged(Editable s) { if (passwordEditText.length() == 4 && UserConfig.passcodeType == 0) { processDone(false); } } }); passwordEditText.setCustomSelectionActionModeCallback(new ActionMode.Callback() { public boolean onPrepareActionMode(ActionMode mode, Menu menu) { return false; } public void onDestroyActionMode(ActionMode mode) { } public boolean onCreateActionMode(ActionMode mode, Menu menu) { return false; } public boolean onActionItemClicked(ActionMode mode, MenuItem item) { return false; } }); checkImage = new ImageView(context); checkImage.setImageResource(R.drawable.passcode_check); checkImage.setScaleType(ImageView.ScaleType.CENTER); checkImage.setBackgroundResource(R.drawable.bar_selector_lock); passwordFrameLayout.addView(checkImage); layoutParams = (LayoutParams) checkImage.getLayoutParams(); layoutParams.width = AndroidUtilities.dp(60); layoutParams.height = AndroidUtilities.dp(60); layoutParams.bottomMargin = AndroidUtilities.dp(4); layoutParams.rightMargin = AndroidUtilities.dp(10); layoutParams.gravity = Gravity.BOTTOM | Gravity.RIGHT; checkImage.setLayoutParams(layoutParams); checkImage.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { processDone(false); } }); FrameLayout lineFrameLayout = new FrameLayout(context); lineFrameLayout.setBackgroundColor(0x26ffffff); passwordFrameLayout.addView(lineFrameLayout); layoutParams = (LayoutParams) lineFrameLayout.getLayoutParams(); layoutParams.width = LayoutHelper.MATCH_PARENT; layoutParams.height = AndroidUtilities.dp(1); layoutParams.gravity = Gravity.BOTTOM | Gravity.LEFT; layoutParams.leftMargin = AndroidUtilities.dp(20); layoutParams.rightMargin = AndroidUtilities.dp(20); lineFrameLayout.setLayoutParams(layoutParams); numbersFrameLayout = new FrameLayout(context); addView(numbersFrameLayout); layoutParams = (LayoutParams) numbersFrameLayout.getLayoutParams(); layoutParams.width = LayoutHelper.MATCH_PARENT; layoutParams.height = LayoutHelper.MATCH_PARENT; layoutParams.gravity = Gravity.TOP | Gravity.LEFT; numbersFrameLayout.setLayoutParams(layoutParams); lettersTextViews = new ArrayList<>(10); numberTextViews = new ArrayList<>(10); numberFrameLayouts = new ArrayList<>(10); for (int a = 0; a < 10; a++) { TextView textView = new TextView(context); textView.setTextColor(0xffffffff); textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 36); textView.setGravity(Gravity.CENTER); textView.setText(String.format(Locale.US, "%d", a)); numbersFrameLayout.addView(textView); layoutParams = (LayoutParams) textView.getLayoutParams(); layoutParams.width = AndroidUtilities.dp(50); layoutParams.height = AndroidUtilities.dp(50); layoutParams.gravity = Gravity.TOP | Gravity.LEFT; textView.setLayoutParams(layoutParams); numberTextViews.add(textView); textView = new TextView(context); textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 12); textView.setTextColor(0x7fffffff); textView.setGravity(Gravity.CENTER); numbersFrameLayout.addView(textView); layoutParams = (LayoutParams) textView.getLayoutParams(); layoutParams.width = AndroidUtilities.dp(50); layoutParams.height = AndroidUtilities.dp(20); layoutParams.gravity = Gravity.TOP | Gravity.LEFT; textView.setLayoutParams(layoutParams); switch (a) { case 0: textView.setText("+"); break; case 2: textView.setText("ABC"); break; case 3: textView.setText("DEF"); break; case 4: textView.setText("GHI"); break; case 5: textView.setText("JKL"); break; case 6: textView.setText("MNO"); break; case 7: textView.setText("PQRS"); break; case 8: textView.setText("TUV"); break; case 9: textView.setText("WXYZ"); break; default: break; } lettersTextViews.add(textView); } eraseView = new ImageView(context); eraseView.setScaleType(ImageView.ScaleType.CENTER); eraseView.setImageResource(R.drawable.passcode_delete); numbersFrameLayout.addView(eraseView); layoutParams = (LayoutParams) eraseView.getLayoutParams(); layoutParams.width = AndroidUtilities.dp(50); layoutParams.height = AndroidUtilities.dp(50); layoutParams.gravity = Gravity.TOP | Gravity.LEFT; eraseView.setLayoutParams(layoutParams); for (int a = 0; a < 11; a++) { FrameLayout frameLayout = new FrameLayout(context); frameLayout.setBackgroundResource(R.drawable.bar_selector_lock); frameLayout.setTag(a); if (a == 10) { frameLayout.setOnLongClickListener(new OnLongClickListener() { @Override public boolean onLongClick(View v) { passwordEditText.setText(""); return true; } }); } frameLayout.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { int tag = (Integer) v.getTag(); switch (tag) { case 0: appendCharacter("0"); break; case 1: appendCharacter("1"); break; case 2: appendCharacter("2"); break; case 3: appendCharacter("3"); break; case 4: appendCharacter("4"); break; case 5: appendCharacter("5"); break; case 6: appendCharacter("6"); break; case 7: appendCharacter("7"); break; case 8: appendCharacter("8"); break; case 9: appendCharacter("9"); break; case 10: String text = passwordEditText.getText().toString(); if (text.length() > 0) { passwordEditText.setText(text.substring(0, text.length() - 1)); } break; } if (passwordEditText.getText().toString().length() == 4) { processDone(false); } } }); numberFrameLayouts.add(frameLayout); } for (int a = 10; a >= 0; a--) { FrameLayout frameLayout = numberFrameLayouts.get(a); numbersFrameLayout.addView(frameLayout); layoutParams = (LayoutParams) frameLayout.getLayoutParams(); layoutParams.width = AndroidUtilities.dp(100); layoutParams.height = AndroidUtilities.dp(100); layoutParams.gravity = Gravity.TOP | Gravity.LEFT; frameLayout.setLayoutParams(layoutParams); } }
From source file:org.profeda.dictionary.SearchActivity.java
/** * Called when the activity is first created. *///from ww w . java2 s. c o m @Override public void onCreate(Bundle savedInstanceState) { final SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(SearchActivity.this); if (pref.getBoolean("show_changelog", true) == true) { MessageBox.showChangeLog(this); } loadDictionaries(pref); if (pref.getBoolean("p_invert_colors", false) == true) { setTheme(R.style.Light); } else { setTheme(R.style.Dark); } super.onCreate(savedInstanceState); setContentView(R.layout.main); dict = new Dict(this, pref.getString("dictFile", null)); updateTitleBar(); readMRU(); final EditText searchbox = (EditText) findViewById(R.id.searchbox); final Button dictselectbutton = (Button) findViewById(R.id.dictselectbutton); final ListView listview = (ListView) findViewById(R.id.contentlist); listview.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView l, View v, int position, long id) { ListAdapter la = ((ListView) l).getAdapter(); if (la instanceof GenericStringAdapter) { final String data = (String) la.getItem(position); if (data.startsWith("> ")) { searchbox.setText(data.substring(2)); doSearch(true); } } else if (la instanceof DictListAdapter) { final String[] data = (String[]) la.getItem(position); final List<Dict> langs = Dict.searchForLanguage(SearchActivity.this, dict.toLang, null); String[] menu = new String[langs.size() + 1]; menu[0] = getString(R.string.copy_translation_to_clipboard); for (int i = 1; i < menu.length; i++) menu[i] = String.format(getString(R.string.search_translation_in_language), langs.get(i - 1).toLang); Matcher m = Pattern.compile("<b>(.*)<\\/b>.*").matcher(data[1]); if (!m.matches()) return; final String translation = m.group(1).trim(); new AlertDialog.Builder(SearchActivity.this).setIcon(android.R.drawable.ic_dialog_info) .setTitle(translation).setItems(menu, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface arg0, int arg1) { switch (arg1) { case 0: ClipboardManager cm = (ClipboardManager) getSystemService( CLIPBOARD_SERVICE); cm.setText(translation); break; default: dict = langs.get(arg1 - 1); readMRU(); updateTitleBar(); searchbox.setText(translation); doSearch(true); } } }).show(); } } }); searchbox.setOnEditorActionListener(new EditText.OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if (actionId == EditorInfo.IME_ACTION_SEARCH || actionId == EditorInfo.IME_ACTION_DONE || event.getAction() == KeyEvent.ACTION_DOWN && event.getKeyCode() == KeyEvent.KEYCODE_ENTER) { doSearch(true); return true; } else { return false; } } }); final Drawable deleteIcon = getResources().getDrawable(R.drawable.textbox_clear); //deleteIcon.setBounds(0, 0, deleteIcon.getIntrinsicWidth(), deleteIcon.getIntrinsicHeight()); deleteIcon.setBounds(0, 0, 51, 30); // wtf??? die Zahlen sind empirisch ermittelt... ab right>=52 springt die hhe des editText searchbox.addTextChangedListener(new TextWatcher() { @Override public void onTextChanged(CharSequence s, int start, int before, int count) { searchbox.setCompoundDrawables(null, null, s.toString().equals("") ? null : deleteIcon, null); //searchbox.setCompoundDrawablesWithIntrinsicBounds(null, null, s.toString().equals("") ? null : deleteIcon, null); searchbox.setCompoundDrawablePadding(0); } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void afterTextChanged(Editable s) { if (enableLivesearch && s.length() > 1 && dict.filePrefix != null && dictSearchInAction == false) { DictionarySearcher ds = new DictionarySearcher(); ds.targetList = (ListView) findViewById(R.id.contentlist); ds.execute(dict.filePrefix, s.toString()); } if (s.length() == 0) { displayMRU(); } } }); //searchbox.setCompoundDrawables(null, null, deleteIcon, null); searchbox.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { if (searchbox.getCompoundDrawables()[2] == null) { return false; } if (event.getAction() != MotionEvent.ACTION_UP) { return false; } if (event.getX() > searchbox.getWidth() - searchbox.getPaddingRight() - deleteIcon.getIntrinsicWidth()) { searchbox.setText(""); searchbox.setCompoundDrawables(null, null, null, null); } return false; } }); dictselectbutton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { selectDictionary(); } }); ((Button) findViewById(R.id.dictswapbutton)).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { final List<Dict> langs = Dict.searchForLanguage(SearchActivity.this, dict.toLang, dict.fromLang); if (langs.size() > 0) { dict = langs.get(0); readMRU(); updateTitleBar(); searchbox.setText(""); } else { MessageBox.alert(SearchActivity.this, getString(R.string.no_reverse_dict_found)); } } }); }