当前位置: 首页>>代码示例>>Java>>正文


Java Selection.setSelection方法代码示例

本文整理汇总了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);
    }
}
 
开发者ID:lfnasc,项目名称:rgb2hexconverter,代码行数:24,代码来源:MainActivity.java

示例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;
}
 
开发者ID:lsjwzh,项目名称:FastTextView,代码行数:36,代码来源:ClickableSpanUtil.java

示例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);
}
 
开发者ID:TeamBrainStorm,项目名称:SimpleUILauncher,代码行数:23,代码来源:AllAppsContainerView.java

示例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());
	}

}
}
 
开发者ID:qizhenghao,项目名称:HiBangClient,代码行数:22,代码来源:EmoteInputView.java

示例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();

}
 
开发者ID:jarro,项目名称:ircradio,代码行数:17,代码来源:DlgPromptUser.java

示例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;
}
 
开发者ID:BigAppOS,项目名称:BigApp_Discuz_Android,代码行数:27,代码来源:LinkTouchMovementMethod.java

示例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);
}
 
开发者ID:adhiman007,项目名称:ChipView,代码行数:25,代码来源:ChipViewMovementMethod.java

示例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;
}
 
开发者ID:KobeMing,项目名称:FMRadio,代码行数:23,代码来源:FmRecordListActivity.java

示例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);
}
 
开发者ID:deliciousblackink,项目名称:Derpibooru,代码行数:22,代码来源:CustomFormattingMovementMethod.java

示例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;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:34,代码来源:ClickableMovementMethod.java

示例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);
}
 
开发者ID:rkshuai,项目名称:chromium-for-android-56-debug-video,代码行数:33,代码来源:FindToolbar.java

示例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();
    }

}
 
开发者ID:lfnasc,项目名称:rgb2hexconverter,代码行数:16,代码来源:MainActivity.java

示例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);
    }
}
 
开发者ID:duyp,项目名称:mvvm-template,代码行数:12,代码来源:BetterLinkMovementExtended.java

示例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);
}
 
开发者ID:enricocid,项目名称:LaunchEnr,代码行数:15,代码来源:AllAppsContainerView.java

示例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);
}
 
开发者ID:CableIM,项目名称:Cable-Android,代码行数:11,代码来源:MotionView.java


注:本文中的android.text.Selection.setSelection方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。