本文整理汇总了Java中android.text.Selection.setSelection方法的典型用法代码示例。如果您正苦于以下问题:Java Selection.setSelection方法的具体用法?Java Selection.setSelection怎么用?Java Selection.setSelection使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.text.Selection
的用法示例。
在下文中一共展示了Selection.setSelection方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onConvertHexToRgb
import android.text.Selection; //导入方法依赖的package包/类
private void onConvertHexToRgb() {
int redValue;
int greenValue;
int blueValue;
String hexValue = editTextHex.getText().toString();
int colorInt;
int[] rgb;
if (isValidHex(hexValue)) {
colorInt = stringToIntColor(hexValue);
rgb = inColorToRGB(colorInt);
viewColor.setBackgroundColor(colorInt);
redValue = rgb[0];
greenValue = rgb[1];
blueValue = rgb[2];
editTextRed.setText(String.valueOf(redValue));
editTextGreen.setText(String.valueOf(greenValue));
editTextBlue.setText(String.valueOf(blueValue));
inputPositionCursor = editTextHex.length();
inputEditable = editTextHex.getText();
Selection.setSelection(inputEditable, inputPositionCursor);
}
}
示例2: handleClickableSpan
import android.text.Selection; //导入方法依赖的package包/类
public static boolean handleClickableSpan(View view, Layout layout, Spannable buffer, MotionEvent event) {
int action = event.getAction();
if (action == MotionEvent.ACTION_UP ||
action == MotionEvent.ACTION_DOWN) {
int x = (int) event.getX();
int y = (int) event.getY();
x -= view.getPaddingLeft();
y -= view.getPaddingTop();
x += view.getScrollX();
y += view.getScrollY();
int line = layout.getLineForVertical(y);
int off = layout.getOffsetForHorizontal(line, x);
ClickableSpan[] link = buffer.getSpans(off, off, ClickableSpan.class);
if (link.length != 0) {
if (action == MotionEvent.ACTION_UP) {
link[0].onClick(view);
} else {
Selection.setSelection(buffer,
buffer.getSpanStart(link[0]),
buffer.getSpanEnd(link[0]));
}
return true;
} else {
Selection.removeSelection(buffer);
}
}
return false;
}
示例3: AllAppsContainerView
import android.text.Selection; //导入方法依赖的package包/类
public AllAppsContainerView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
Resources res = context.getResources();
mLauncher = Launcher.getLauncher(context);
mSectionNamesMargin = res.getDimensionPixelSize(R.dimen.all_apps_grid_view_start_margin);
mApps = new AlphabeticalAppsList(context);
mAdapter = new AllAppsGridAdapter(mLauncher, mApps, mLauncher, this);
mApps.setAdapter(mAdapter);
mLayoutManager = mAdapter.getLayoutManager();
mItemDecoration = mAdapter.getItemDecoration();
DeviceProfile grid = mLauncher.getDeviceProfile();
if (FeatureFlags.LAUNCHER3_ALL_APPS_PULL_UP && !grid.isVerticalBarLayout()) {
mRecyclerViewBottomPadding = 0;
setPadding(0, 0, 0, 0);
} else {
mRecyclerViewBottomPadding =
res.getDimensionPixelSize(R.dimen.all_apps_list_bottom_padding);
}
mSearchQueryBuilder = new SpannableStringBuilder();
Selection.setSelection(mSearchQueryBuilder, 0);
}
示例4: onItemClick
import android.text.Selection; //导入方法依赖的package包/类
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
String text = null;
if (mIsSelectedDefault) {
text = BaseApplication.mEmoticons_Zem.get(arg2);
} else {
text = BaseApplication.mEmoticons_Zemoji.get(arg2);
}
if (mEEtView != null && !TextUtils.isEmpty(text)) {
int start = mEEtView.getSelectionStart();
CharSequence content = mEEtView.getText().insert(start, text);
mEEtView.setText(content);
// 定位光标位置
CharSequence info = mEEtView.getText();
if (info instanceof Spannable) {
Spannable spanText = (Spannable) info;
Selection.setSelection(spanText, start + text.length());
}
}
}
示例5: onItemClick
import android.text.Selection; //导入方法依赖的package包/类
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
UserAdapter adapter = (UserAdapter) arg0.getAdapter();
User user = (User)adapter.getItem(arg2);
FragChatLog acl = (FragChatLog) this.getTargetFragment();
EditText et = (EditText)acl.getView().findViewById(R.id.textinput);
et.setText("/msg " + user.getNick() + " ");
//move carat to end of line
Editable etext = et.getText();
int position = etext.length();
Selection.setSelection(etext, position);
this.dismiss();
}
示例6: onTouchEvent
import android.text.Selection; //导入方法依赖的package包/类
@Override
public boolean onTouchEvent(TextView textView, Spannable spannable, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
mPressedSpan = getPressedSpan(textView, spannable, event);
if (mPressedSpan != null) {
mPressedSpan.setPressed(true);
Selection.setSelection(spannable, spannable.getSpanStart(mPressedSpan),
spannable.getSpanEnd(mPressedSpan));
}
} else if (event.getAction() == MotionEvent.ACTION_MOVE) {
TouchableSpan touchedSpan = getPressedSpan(textView, spannable, event);
if (mPressedSpan != null && touchedSpan != mPressedSpan) {
mPressedSpan.setPressed(false);
mPressedSpan = null;
Selection.removeSelection(spannable);
}
} else {
if (mPressedSpan != null) {
mPressedSpan.setPressed(false);
super.onTouchEvent(textView, spannable, event);
}
mPressedSpan = null;
Selection.removeSelection(spannable);
}
return true;
}
示例7: onTouchEvent
import android.text.Selection; //导入方法依赖的package包/类
public boolean onTouchEvent(TextView widget, Spannable buffer, MotionEvent event) {
int action = event.getAction();
if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_DOWN) {
int x = (int) event.getX();
int y = (int) event.getY();
x -= widget.getTotalPaddingLeft();
y -= widget.getTotalPaddingTop();
x += widget.getScrollX();
y += widget.getScrollY();
Layout layout = widget.getLayout();
int line = layout.getLineForVertical(y);
int off = layout.getOffsetForHorizontal(line, x);
ChipClickSpan[] link = buffer.getSpans(off, off, ChipClickSpan.class);
if (link.length != 0) {
if (action == MotionEvent.ACTION_UP) {
link[0].onClick(widget);
Selection.removeSelection(buffer);
} else if (action == MotionEvent.ACTION_DOWN)
Selection.setSelection(buffer, buffer.getSpanStart(link[0]), buffer.getSpanEnd(link[0]));
return true;
}
}
return super.onTouchEvent(widget, buffer, event);
}
示例8: renameDialogView
import android.text.Selection; //导入方法依赖的package包/类
private View renameDialogView(String deviceName) {
View view = LayoutInflater.from(FmRecordListActivity.this).inflate(R.layout.rename_edittext, null);
mEditText = (EditText) view.findViewById(R.id.et_rename);
mEditText.setText(deviceName);
Editable editable = mEditText.getText();
Selection.setSelection(editable, editable.length());
mEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_DONE) {
if (v.length() != 0 && !(v.getText().toString().trim().isEmpty())) {
}
mDialog.dismiss();
return true; // action handled
} else {
return false; // not handled
}
}
});
return view;
}
示例9: onTouchEvent
import android.text.Selection; //导入方法依赖的package包/类
@Override
public boolean onTouchEvent(TextView textView, Spannable spannable, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
mPressedSpan = getPressedSpan(textView, spannable, event);
if (mPressedSpan != null) {
mPressedSpan.unspoiler();
Selection.setSelection(spannable, spannable.getSpanStart(mPressedSpan),
spannable.getSpanEnd(mPressedSpan));
}
} else if (event.getAction() == MotionEvent.ACTION_MOVE) {
SpoilerSpan touchedSpan = getPressedSpan(textView, spannable, event);
if (!Objects.equal(touchedSpan, mPressedSpan)) {
mPressedSpan = null;
Selection.removeSelection(spannable);
}
} else {
mPressedSpan = null;
Selection.removeSelection(spannable);
}
return super.onTouchEvent(textView, spannable, event);
}
示例10: onTouchEvent
import android.text.Selection; //导入方法依赖的package包/类
@Override
public boolean onTouchEvent(TextView widget, Spannable buffer, MotionEvent event) {
int action = event.getActionMasked();
if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_DOWN) {
int x = (int) event.getX();
int y = (int) event.getY();
x -= widget.getTotalPaddingLeft();
y -= widget.getTotalPaddingTop();
x += widget.getScrollX();
y += widget.getScrollY();
Layout layout = widget.getLayout();
int line = layout.getLineForVertical(y);
int off = layout.getOffsetForHorizontal(line, x);
ClickableSpan[] link = buffer.getSpans(off, off, ClickableSpan.class);
if (link.length > 0) {
if (action == MotionEvent.ACTION_UP) {
link[0].onClick(widget);
} else {
Selection.setSelection(buffer, buffer.getSpanStart(link[0]),
buffer.getSpanEnd(link[0]));
}
return true;
} else {
Selection.removeSelection(buffer);
}
}
return false;
}
示例11: onTextContextMenuItem
import android.text.Selection; //导入方法依赖的package包/类
@Override
public boolean onTextContextMenuItem(int id) {
if (id == android.R.id.paste) {
ClipboardManager clipboard = (ClipboardManager) getContext()
.getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clipData = clipboard.getPrimaryClip();
if (clipData != null) {
// Convert the clip data to a simple string
StringBuilder builder = new StringBuilder();
for (int i = 0; i < clipData.getItemCount(); i++) {
builder.append(clipData.getItemAt(i).coerceToText(getContext()));
}
// Identify how much of the original text should be replaced
int min = 0;
int max = getText().length();
if (isFocused()) {
final int selStart = getSelectionStart();
final int selEnd = getSelectionEnd();
min = Math.max(0, Math.min(selStart, selEnd));
max = Math.max(0, Math.max(selStart, selEnd));
}
Selection.setSelection(getText(), max);
getText().replace(min, max, builder.toString());
return true;
}
}
return super.onTextContextMenuItem(id);
}
示例12: onTextGreenChanged
import android.text.Selection; //导入方法依赖的package包/类
@OnTextChanged(R.id.editTextGreen)
public void onTextGreenChanged(CharSequence textGreen, int start, int count, int after) {
if (textGreen.length() > 0) {
isInputText = true;
seekBarGreen.setProgress(Integer.parseInt(textGreen.toString()));
inputPositionCursor = editTextGreen.length();
inputEditable = editTextGreen.getText();
Selection.setSelection(inputEditable, inputPositionCursor);
isInputText = false;
} else {
Toast.makeText(getApplicationContext(), "Set GREEN Value!", Toast.LENGTH_SHORT).show();
}
}
示例13: highlightUrl
import android.text.Selection; //导入方法依赖的package包/类
private void highlightUrl(TextView textView, BetterLinkMovementExtended.ClickableSpanWithText spanWithText, Spannable text) {
if (!this.isUrlHighlighted) {
this.isUrlHighlighted = true;
int spanStart = text.getSpanStart(spanWithText.span());
int spanEnd = text.getSpanEnd(spanWithText.span());
Selection.removeSelection(text);
text.setSpan(new BackgroundColorSpan(textView.getHighlightColor()), spanStart, spanEnd, Spanned.SPAN_INCLUSIVE_INCLUSIVE);
textView.setText(text);
Selection.setSelection(text, spanStart, spanEnd);
}
}
示例14: AllAppsContainerView
import android.text.Selection; //导入方法依赖的package包/类
public AllAppsContainerView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
mLauncher = Launcher.getLauncher(context);
mApps = new AlphabeticalAppsList(context);
mAdapter = new AllAppsGridAdapter(mLauncher, mApps, mLauncher, this);
mApps.setAdapter(mAdapter);
mLayoutManager = mAdapter.getLayoutManager();
mSearchQueryBuilder = new SpannableStringBuilder();
mSearchContainerMinHeight
= getResources().getDimensionPixelSize(R.dimen.all_apps_search_bar_height);
Selection.setSelection(mSearchQueryBuilder, 0);
}
示例15: startEditing
import android.text.Selection; //导入方法依赖的package包/类
public void startEditing(TextEntity entity) {
editText.setFocusableInTouchMode(true);
editText.setFocusable(true);
editText.requestFocus();
editText.setText(entity.getLayer().getText());
Selection.setSelection(editText.getText(), editText.length());
InputMethodManager ims = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
ims.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT);
}