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


Java Selection类代码示例

本文整理汇总了Java中android.text.Selection的典型用法代码示例。如果您正苦于以下问题:Java Selection类的具体用法?Java Selection怎么用?Java Selection使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Selection类属于android.text包,在下文中一共展示了Selection类的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: onBackKey

import android.text.Selection; //导入依赖的package包/类
@Override
public boolean onBackKey() {
    mFolderName.setHint(sHintText);
    // Convert to a string here to ensure that no other state associated with the text field
    // gets saved.
    String newTitle = mFolderName.getText().toString();
    mInfo.setTitle(newTitle);
    mLauncher.getModelWriter().updateItemInDatabase(mInfo);

    Utilities.sendCustomAccessibilityEvent(
            this, AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED,
            getContext().getString(R.string.folder_renamed, newTitle));

    // This ensures that focus is gained every time the field is clicked, which selects all
    // the text and brings up the soft keyboard if necessary.
    mFolderName.clearFocus();

    Selection.setSelection(mFolderName.getText(), 0, 0);
    mIsEditingName = false;
    return true;
}
 
开发者ID:enricocid,项目名称:LaunchEnr,代码行数:22,代码来源:Folder.java

示例3: 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

示例4: undo

import android.text.Selection; //导入依赖的package包/类
public void undo() {
    EditItem edit = mEditHistory.getPrevious();
    if (edit == null) {
        return;
    }

    Editable editable = mTextView.getEditableText();
    int start = edit.start;
    int end = start + (edit.after != null ? edit.after.length() : 0);

    mIsUndoOrRedo = true;
    editable.replace(start, end, edit.before);
    mIsUndoOrRedo = false;

    for (Object o : editable.getSpans(0, editable.length(), UnderlineSpan.class)) {
        editable.removeSpan(o);
    }

    Selection.setSelection(editable, edit.before == null ? start : (start + edit.before.length()));
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:21,代码来源:UndoRedoSupportEditText.java

示例5: redo

import android.text.Selection; //导入依赖的package包/类
public void redo() {
    EditItem edit = mEditHistory.getNext();
    if (edit == null) {
        return;
    }

    Editable text = mTextView.getEditableText();
    int start = edit.start;
    int end = start + (edit.before != null ? edit.before.length() : 0);

    mIsUndoOrRedo = true;
    text.replace(start, end, edit.after);
    mIsUndoOrRedo = false;

    // This will get rid of underlines inserted when editor tries to come
    // up with a suggestion.
    for (Object o : text.getSpans(0, text.length(), UnderlineSpan.class)) {
        text.removeSpan(o);
    }

    Selection.setSelection(text, edit.after == null ? start
            : (start + edit.after.length()));
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:24,代码来源:UndoRedoSupportEditText.java

示例6: undo

import android.text.Selection; //导入依赖的package包/类
public void undo() {
    EditItem edit = mEditHistory.getPrevious();
    if (edit == null) {
        return;
    }

    Editable editable = mTextView.getEditableText();
    int start = edit.start;
    int end = start + (edit.after != null ? edit.after.length() : 0);

    mIsUndoOrRedo = true;
    editable.replace(start, end, edit.before);
    mIsUndoOrRedo = false;

    for (Object o : editable.getSpans(0, editable.length(), UnderlineSpan.class)) {
        editable.removeSpan(o);
    }

    Selection.setSelection(editable,
            edit.before == null ? start : (start + edit.before.length()));
}
 
开发者ID:Light-Team,项目名称:ModPE-IDE-Source,代码行数:22,代码来源:UndoRedoHelper.java

示例7: handleClickableSpan

import android.text.Selection; //导入依赖的package包/类
public static boolean handleClickableSpan(View view, Layout layout, Spanned buffer, Class<? extends Clickable> spanType, 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);

    Clickable[] link = buffer.getSpans(off, off, spanType);

    if (link.length != 0) {
      if (action == MotionEvent.ACTION_UP) {
        link[0].onClick(view);
      } else if (buffer instanceof Spannable) {
        Selection.setSelection((Spannable) buffer,
            buffer.getSpanStart(link[0]),
            buffer.getSpanEnd(link[0]));
      }
      return true;
    } else if (buffer instanceof Spannable) {
      Selection.removeSelection((Spannable) buffer);
    }
  }

  return false;
}
 
开发者ID:lsjwzh,项目名称:FastTextView,代码行数:36,代码来源:ClickableSpanUtil.java

示例8: showActionMenu

import android.text.Selection; //导入依赖的package包/类
/**
 * 长按弹出菜单
 *
 * @param offsetY
 * @param actionMenu
 * @return 菜单创建成功,返回true
 */
private void showActionMenu(int offsetY, ActionMenu actionMenu) {

    mActionMenuPopupWindow = new PopupWindow(actionMenu, WindowManager.LayoutParams.WRAP_CONTENT,
            mActionMenuHeight, true);
    mActionMenuPopupWindow.setFocusable(true);
    mActionMenuPopupWindow.setOutsideTouchable(false);
    mActionMenuPopupWindow.setBackgroundDrawable(new ColorDrawable(0x00000000));
    mActionMenuPopupWindow.showAtLocation(this, Gravity.TOP | Gravity.CENTER_HORIZONTAL, 0, offsetY);

    mActionMenuPopupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
        @Override
        public void onDismiss() {
            Selection.removeSelection(getEditableText());
            // 如果设置了分散对齐,ActionMenu销毁后,强制刷新一次,防止出现文字背景未消失的情况
            if (isTextJustify)
                SelectableTextView.this.postInvalidate();
        }
    });
}
 
开发者ID:devilist,项目名称:AdvancedTextView,代码行数:27,代码来源:SelectableTextView.java

示例9: addListener

import android.text.Selection; //导入依赖的package包/类
private void addListener() {
    this.toggle_bingo.setOnCheckedChangeListener(new OnCheckedChangeListener() {
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (isChecked) {
                AddCameraRecordActivity.this.mInputCalory = AddCameraRecordActivity.this
                        .et_calory.getText().toString();
                AddCameraRecordActivity.this.et_calory.getText().clear();
                AddCameraRecordActivity.this.et_calory.setHint("请等待顾问为你估算");
                AddCameraRecordActivity.this.et_calory.setEnabled(false);
                return;
            }
            if (!TextUtils.isEmpty(AddCameraRecordActivity.this.mInputCalory)) {
                AddCameraRecordActivity.this.et_calory.setText(AddCameraRecordActivity.this
                        .mInputCalory);
                Selection.setSelection(AddCameraRecordActivity.this.et_calory.getText(),
                        AddCameraRecordActivity.this.et_calory.getText().length());
            }
            AddCameraRecordActivity.this.et_calory.setHint("所含的热量(可不填)");
            AddCameraRecordActivity.this.et_calory.setEnabled(true);
        }
    });
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:23,代码来源:AddCameraRecordActivity.java

示例10: init

import android.text.Selection; //导入依赖的package包/类
private void init() {
    Intent intent = getIntent();
    this.code = intent.getStringExtra("code");
    this.defaultContent = intent.getStringExtra(EXTRA_DEFAULT_CONTENT);
    Helper.showLog(TAG, "code:" + this.code);
    this.attributeText = (TextView) findViewById(R.id.attribute_text);
    this.attributeText.setText(intent.getStringExtra(EXTRA_CODE_TEXT));
    this.wordNumTips = (TextView) findViewById(R.id.word_number_tips);
    this.contentEdit = (EditText) findViewById(R.id.content);
    this.contentEdit.setText(this.defaultContent);
    if (UserDao.USER_NAME.equals(this.code)) {
        this.contentEdit.setSingleLine();
        this.wordNumTips.setText(R.string.a_j);
    } else if ("description".equals(this.code)) {
        this.contentEdit.setLines(3);
        this.wordNumTips.setText(R.string.lo);
    } else {
        this.contentEdit.setInputType(2);
        this.wordNumTips.setVisibility(8);
    }
    Selection.setSelection(this.contentEdit.getText(), this.contentEdit.length());
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:23,代码来源:ChangeProfileActivity1.java

示例11: 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:michelelacorte,项目名称:FlickLauncher,代码行数:24,代码来源:AllAppsContainerView.java

示例12: doneEditingFolderName

import android.text.Selection; //导入依赖的package包/类
public void doneEditingFolderName(boolean commit) {
    mFolderName.setHint(sHintText);
    // Convert to a string here to ensure that no other state associated with the text field
    // gets saved.
    String newTitle = mFolderName.getText().toString();
    mInfo.setTitle(newTitle);
    LauncherModel.updateItemInDatabase(mLauncher, mInfo);

    if (commit) {
        Utilities.sendCustomAccessibilityEvent(
                this, AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED,
                getContext().getString(R.string.folder_renamed, newTitle));
    }

    // This ensures that focus is gained every time the field is clicked, which selects all
    // the text and brings up the soft keyboard if necessary.
    mFolderName.clearFocus();

    Selection.setSelection((Spannable) mFolderName.getText(), 0, 0);
    mIsEditingName = false;
}
 
开发者ID:michelelacorte,项目名称:FlickLauncher,代码行数:22,代码来源:Folder.java

示例13: 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

示例14: delete

import android.text.Selection; //导入依赖的package包/类
/**
 * 删除图标执行事件
 * 注:如果删除的是表情,在删除时实际删除的是tempText即图片占位的字符串,所以必需一次性删除掉tempText,才能将图片删除
 * */
public static void delete(EditText input) {
	if (input.getText().length() != 0) {
		int iCursorEnd = Selection.getSelectionEnd(input.getText());
		int iCursorStart = Selection.getSelectionStart(input.getText());
		if (iCursorEnd > 0) {
			if (iCursorEnd == iCursorStart) {
				if (isDeletePng(input,iCursorEnd)) {
					String st = "[p/_000.png]";
					((Editable) input.getText()).delete(
							iCursorEnd - st.length(), iCursorEnd);
				} else {
					((Editable) input.getText()).delete(iCursorEnd - 1,
							iCursorEnd);
				}
			} else {
				((Editable) input.getText()).delete(iCursorStart,
						iCursorEnd);
			}
		}
	}
}
 
开发者ID:cowthan,项目名称:AyoSunny,代码行数:26,代码来源:ExpressionUtil.java

示例15: onBeforeNotifyDataSetChanged

import android.text.Selection; //导入依赖的package包/类
public void onBeforeNotifyDataSetChanged() {
	if (SUPPORTED) {
		HANDLER.removeMessages(MESSAGE_SEND_RESET);
		HANDLER.removeMessages(MESSAGE_RESET);
		HANDLER.removeMessages(MESSAGE_START_SELECTION);
		if (selectionActionMode != null) {
			final CharSequence text = selectionTextView.getText();
			futureSelectionIdentifier = selectionIdentifier;
			futureSelectionStart = Selection.getSelectionStart(text);
			futureSelectionEnd = Selection.getSelectionEnd(text);
			selectionActionMode.finish();
			selectionActionMode = null;
			selectionIdentifier = null;
			selectionTextView = null;
		}
	}
}
 
开发者ID:syntafin,项目名称:TenguChat,代码行数:18,代码来源:ListSelectionManager.java


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