List of usage examples for android.widget TextView getSelectionStart
@ViewDebug.ExportedProperty(category = "text") public int getSelectionStart()
From source file:com.jefftharris.passwdsafe.lib.view.GuiUtils.java
/** * Set whether the view shows a visible password *///from ww w . j a v a 2 s . co m public static void setPasswordVisible(TextView tv, boolean visible, Context ctx) { int pos = tv.getSelectionStart(); tv.setInputType(visible ? INPUT_TEXT_PASSWORD_VISIBLE : INPUT_TEXT_PASSWORD); // Reset monospace as the input type change resets to default monospace // font TypefaceUtils.setMonospace(tv, ctx); if (tv instanceof EditText) { // Keep selection location after the type change ((EditText) tv).setSelection(pos); } }
From source file:com.android.talkback.controller.CursorControllerAppTest.java
@MediumTest public void testSetSelectionModeActive() { setContentView(R.layout.text_activity); final TextView usernameView = (TextView) getViewForId(R.id.username); getInstrumentation().runOnMainSync(new Runnable() { @Override/*w w w . j ava2 s . c om*/ public void run() { usernameView.setText("abcdefghijklmnop"); } }); getInstrumentation().waitForIdleSync(); waitForAccessibilityIdleSync(); AccessibilityNodeInfoCompat username = getNodeForId(R.id.username); mCursorController.setCursor(username); mCursorController.setGranularity(CursorGranularity.CHARACTER, false); waitForAccessibilityIdleSync(); // Move cursor between "c" and "d". for (int i = 0; i < 3; ++i) { mCursorController.next(false, false, false, InputModeManager.INPUT_MODE_TOUCH); waitForAccessibilityIdleSync(); } mCursorController.setSelectionModeActive(username, true); waitForAccessibilityIdleSync(); // Select five characters "defgh". for (int i = 0; i < 5; ++i) { mCursorController.next(false, false, false, InputModeManager.INPUT_MODE_TOUCH); waitForAccessibilityIdleSync(); } assertEquals(3, usernameView.getSelectionStart()); assertEquals(8, usernameView.getSelectionEnd()); // 8-3 = 5 char selection. }
From source file:com.android.mms.ui.ComposeMessageActivity.java
private Uri getSelectedUriFromMessageList(ListView listView, int position) { // If the context menu was opened over a uri, get that uri. MessageListItem msglistItem = (MessageListItem) listView.getChildAt(position); if (msglistItem == null) { // FIXME: Should get the correct view. No such interface in ListView currently // to get the view by position. The ListView.getChildAt(position) cannot // get correct view since the list doesn't create one child for each item. // And if setSelection(position) then getSelectedView(), // cannot get corrent view when in touch mode. return null; }/*from w w w .j a va 2 s .c o m*/ TextView textView; CharSequence text = null; int selStart = -1; int selEnd = -1; //check if message sender is selected textView = (TextView) msglistItem.findViewById(R.id.text_view); if (textView != null) { text = textView.getText(); selStart = textView.getSelectionStart(); selEnd = textView.getSelectionEnd(); } // Check that some text is actually selected, rather than the cursor // just being placed within the TextView. if (selStart != selEnd) { int min = Math.min(selStart, selEnd); int max = Math.max(selStart, selEnd); URLSpan[] urls = ((Spanned) text).getSpans(min, max, URLSpan.class); if (urls.length == 1) { return Uri.parse(urls[0].getURL()); } } //no uri was selected return null; }