类android.text.method.TextKeyListener源码实例Demo

下面列出了怎么用android.text.method.TextKeyListener的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: LaunchEnr   文件: Launcher.java
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    final int uniChar = event.getUnicodeChar();
    final boolean handled = super.onKeyDown(keyCode, event);
    final boolean isKeyNotWhitespace = uniChar > 0 && !Character.isWhitespace(uniChar);
    if (!handled && acceptFilter() && isKeyNotWhitespace) {
        boolean gotKey = TextKeyListener.getInstance().onKeyDown(mWorkspace, mDefaultKeySsb,
                keyCode, event);
        if (gotKey && mDefaultKeySsb != null && mDefaultKeySsb.length() > 0) {
            // something usable has been typed - start a search
            // the typed text will be retrieved and cleared by
            // showSearchDialog()
            // If there are multiple keystrokes before the search dialog takes focus,
            // onSearchRequested() will be called for every keystroke,
            // but it is idempotent, so it's fine.
            return onSearchRequested();
        }
    }

    // Eat the long press event so the keyboard doesn't come up.
    if (keyCode == KeyEvent.KEYCODE_MENU && event.isLongPress()) {
        return true;
    }

    return handled;
}
 
源代码2 项目: LaunchEnr   文件: AllAppsContainerView.java
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
    // Determine if the key event was actual text, if so, focus the search bar and then dispatch
    // the key normally so that it can process this key event
    if (!mSearchBarController.isSearchFieldFocused() &&
            event.getAction() == KeyEvent.ACTION_DOWN) {
        final int unicodeChar = event.getUnicodeChar();
        final boolean isKeyNotWhitespace = unicodeChar > 0 &&
                !Character.isWhitespace(unicodeChar) && !Character.isSpaceChar(unicodeChar);
        if (isKeyNotWhitespace) {
            boolean gotKey = TextKeyListener.getInstance().onKeyDown(this, mSearchQueryBuilder,
                    event.getKeyCode(), event);
            if (gotKey && mSearchQueryBuilder.length() > 0) {
                mSearchBarController.focusSearchField();
            }
        }
    }

    return super.dispatchKeyEvent(event);
}
 
源代码3 项目: Trebuchet   文件: AllAppsContainerView.java
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
    // Determine if the key event was actual text, if so, focus the search bar and then dispatch
    // the key normally so that it can process this key event
    if (mSearchBarController != null &&
            !mSearchBarController.isSearchFieldFocused() &&
            event.getAction() == KeyEvent.ACTION_DOWN) {
        final int unicodeChar = event.getUnicodeChar();
        final boolean isKeyNotWhitespace = unicodeChar > 0 &&
                !Character.isWhitespace(unicodeChar) && !Character.isSpaceChar(unicodeChar);
        if (isKeyNotWhitespace) {
            boolean gotKey = TextKeyListener.getInstance().onKeyDown(this, mSearchQueryBuilder,
                    event.getKeyCode(), event);
            if (gotKey && mSearchQueryBuilder.length() > 0) {
                mSearchBarController.focusSearchField();
            }
        }
    }

    return super.dispatchKeyEvent(event);
}
 
源代码4 项目: TurboLauncher   文件: Launcher.java
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
	final int uniChar = event.getUnicodeChar();
	final boolean handled = super.onKeyDown(keyCode, event);
	final boolean isKeyNotWhitespace = uniChar > 0
			&& !Character.isWhitespace(uniChar);
	if (!handled && acceptFilter() && isKeyNotWhitespace) {
		boolean gotKey = TextKeyListener.getInstance().onKeyDown(
				mWorkspace, mDefaultKeySsb, keyCode, event);
		if (gotKey && mDefaultKeySsb != null && mDefaultKeySsb.length() > 0) {

			return onSearchRequested();
		}
	}

	if (keyCode == KeyEvent.KEYCODE_MENU && event.isLongPress()) {
		return true;
	}

	return handled;
}
 
源代码5 项目: BluetoothHidEmu   文件: KeyboardKeyListener.java
@Override
public boolean onKeyDown(View view, Editable content, int keyCode, KeyEvent event) {
    switch (keyCode) {
    
    case KeyEvent.KEYCODE_ENTER:
        TextKeyListener.clear(content);
        mHidPayload.assemblePayload(HidKeyPair.ENTER);
        mSocketManager.sendPayload(mHidPayload);
        return true;
    case KeyEvent.KEYCODE_DEL:
    	mHidPayload.assemblePayload(HidKeyPair.DEL);
        mSocketManager.sendPayload(mHidPayload);
    case KeyEvent.KEYCODE_VOLUME_UP:
    case KeyEvent.KEYCODE_VOLUME_DOWN:
        mHidPayload.assemblePayload(keyCode);
        mSocketManager.sendPayload(mHidPayload);
    default:
        return mTextKeyListener.onKeyDown(view, content, keyCode, event);
    }
}
 
源代码6 项目: android_9.0.0_r45   文件: DialerFilter.java
@Override
protected void onFinishInflate() {
    super.onFinishInflate();

    // Setup the filter view
    mInputFilters = new InputFilter[] { new InputFilter.AllCaps() };

    mHint = (EditText) findViewById(com.android.internal.R.id.hint);
    if (mHint == null) {
        throw new IllegalStateException("DialerFilter must have a child EditText named hint");
    }
    mHint.setFilters(mInputFilters);

    mLetters = mHint;
    mLetters.setKeyListener(TextKeyListener.getInstance());
    mLetters.setMovementMethod(null);
    mLetters.setFocusable(false);

    // Setup the digits view
    mPrimary = (EditText) findViewById(com.android.internal.R.id.primary);
    if (mPrimary == null) {
        throw new IllegalStateException("DialerFilter must have a child EditText named primary");
    }
    mPrimary.setFilters(mInputFilters);

    mDigits = mPrimary;
    mDigits.setKeyListener(DialerKeyListener.getInstance());
    mDigits.setMovementMethod(null);
    mDigits.setFocusable(false);

    // Look for an icon
    mIcon = (ImageView) findViewById(com.android.internal.R.id.icon);

    // Setup focus & highlight for this view
    setFocusable(true);

    // XXX Force the mode to QWERTY for now, since 12-key isn't supported
    mIsQwerty = true;
    setMode(DIGITS_AND_LETTERS);
}
 
源代码7 项目: PowerFileExplorer   文件: JotaTextKeyListener.java
public static TextKeyListener getInstance(boolean autotext, Capitalize cap) {
    int off = cap.ordinal() * 2 + (autotext ? 1 : 0);

    if (sInstance[off] == null) {
        sInstance[off] = new JotaTextKeyListener(cap, autotext);
    }

    return sInstance[off];
}
 
源代码8 项目: LaunchEnr   文件: Launcher.java
@Override
public void onDestroy() {
    super.onDestroy();

    mWorkspace.removeCallbacks(mBuildLayersRunnable);
    mWorkspace.removeFolderListeners();

    // Stop callbacks from LauncherModel
    // It's possible to receive onDestroy after a new Launcher activity has
    // been created. In this case, don't interfere with the new Launcher.
    if (mModel.isCurrentCallbacks(this)) {
        mModel.stopLoader();
        LauncherAppState.getInstance(this).setLauncher(null);
    }

    if (mRotationPrefChangeHandler != null) {
        mSharedPrefs.unregisterOnSharedPreferenceChangeListener(mRotationPrefChangeHandler);
    }

    try {
        mAppWidgetHost.stopListening();
    } catch (NullPointerException ex) {
        ex.printStackTrace();
    }
    mAppWidgetHost = null;

    TextKeyListener.getInstance().release();

    ((AccessibilityManager) getSystemService(ACCESSIBILITY_SERVICE))
            .removeAccessibilityStateChangeListener(this);

    LauncherAnimUtils.onDestroyActivity();

    if (mLauncherCallbacks != null) {
        mLauncherCallbacks.onDestroy();
    }
}
 
源代码9 项目: JotaTextEditor   文件: JotaTextKeyListener.java
public static TextKeyListener getInstance(boolean autotext, Capitalize cap) {
    int off = cap.ordinal() * 2 + (autotext ? 1 : 0);

    if (sInstance[off] == null) {
        sInstance[off] = new JotaTextKeyListener(cap, autotext);
    }

    return sInstance[off];
}
 
源代码10 项目: Onosendai   文件: PostActivity.java
public void setupAutoComplete () {
	if (this.txtBody.getAdapter() != null) return;
	this.txtBody.setThreshold(1);
	this.txtBody.setTokenizer(new UsernameTokenizer());
	this.txtBody.setAdapter(new UsernameSearchAdapter(this));
	this.txtBody.addTextChangedListener(new PopupPositioniner(this.txtBody));
	this.txtBody.setKeyListener(TextKeyListener.getInstance(true, TextKeyListener.Capitalize.SENTENCES));
}
 
源代码11 项目: android_9.0.0_r45   文件: Layout.java
/**
 * Fills in the specified Path with a representation of a cursor
 * at the specified offset.  This will often be a vertical line
 * but can be multiple discontinuous lines in text with multiple
 * directionalities.
 */
public void getCursorPath(final int point, final Path dest, final CharSequence editingBuffer) {
    dest.reset();

    int line = getLineForOffset(point);
    int top = getLineTop(line);
    int bottom = getLineBottomWithoutSpacing(line);

    boolean clamped = shouldClampCursor(line);
    float h1 = getPrimaryHorizontal(point, clamped) - 0.5f;
    float h2 = isLevelBoundary(point) ? getSecondaryHorizontal(point, clamped) - 0.5f : h1;

    int caps = TextKeyListener.getMetaState(editingBuffer, TextKeyListener.META_SHIFT_ON) |
               TextKeyListener.getMetaState(editingBuffer, TextKeyListener.META_SELECTING);
    int fn = TextKeyListener.getMetaState(editingBuffer, TextKeyListener.META_ALT_ON);
    int dist = 0;

    if (caps != 0 || fn != 0) {
        dist = (bottom - top) >> 2;

        if (fn != 0)
            top += dist;
        if (caps != 0)
            bottom -= dist;
    }

    if (h1 < 0.5f)
        h1 = 0.5f;
    if (h2 < 0.5f)
        h2 = 0.5f;

    if (Float.compare(h1, h2) == 0) {
        dest.moveTo(h1, top);
        dest.lineTo(h1, bottom);
    } else {
        dest.moveTo(h1, top);
        dest.lineTo(h1, (top + bottom) >> 1);

        dest.moveTo(h2, (top + bottom) >> 1);
        dest.lineTo(h2, bottom);
    }

    if (caps == 2) {
        dest.moveTo(h2, bottom);
        dest.lineTo(h2 - dist, bottom + dist);
        dest.lineTo(h2, bottom);
        dest.lineTo(h2 + dist, bottom + dist);
    } else if (caps == 1) {
        dest.moveTo(h2, bottom);
        dest.lineTo(h2 - dist, bottom + dist);

        dest.moveTo(h2 - dist, bottom + dist - 0.5f);
        dest.lineTo(h2 + dist, bottom + dist - 0.5f);

        dest.moveTo(h2 + dist, bottom + dist);
        dest.lineTo(h2, bottom);
    }

    if (fn == 2) {
        dest.moveTo(h1, top);
        dest.lineTo(h1 - dist, top - dist);
        dest.lineTo(h1, top);
        dest.lineTo(h1 + dist, top - dist);
    } else if (fn == 1) {
        dest.moveTo(h1, top);
        dest.lineTo(h1 - dist, top - dist);

        dest.moveTo(h1 - dist, top - dist + 0.5f);
        dest.lineTo(h1 + dist, top - dist + 0.5f);

        dest.moveTo(h1 + dist, top - dist);
        dest.lineTo(h1, top);
    }
}
 
源代码12 项目: PowerFileExplorer   文件: Layout.java
/**
 * Fills in the specified Path with a representation of a cursor
 * at the specified offset.  This will often be a vertical line
 * but can be multiple discontinous lines in text with multiple
 * directionalities.
 */
public void getCursorPath(int point, Path dest,
                          CharSequence editingBuffer) {
    dest.reset();

    int line = getLineForOffset(point);
    int top = getLineTop(line);
    int bottom = getLineTop(line+1);

    float h1 = getPrimaryHorizontal(point) - 0.5f;
    float h2 = getSecondaryHorizontal(point) - 0.5f;

    int caps = TextKeyListener.getMetaState(editingBuffer,
                                            KeyEvent.META_SHIFT_ON) |
               JotaTextKeyListener.getMetaStateSelecting(editingBuffer);
    int fn = TextKeyListener.getMetaState(editingBuffer,
                                          KeyEvent.META_ALT_ON);
    int dist = 0;

    if (caps != 0 || fn != 0) {
        dist = (bottom - top) >> 2;

        if (fn != 0)
            top += dist;
        if (caps != 0)
            bottom -= dist;
    }

    if (h1 < 0.5f)
        h1 = 0.5f;
    if (h2 < 0.5f)
        h2 = 0.5f;

    if (h1 == h2) {
        dest.moveTo(h1, top);
        dest.lineTo(h1, bottom);
    } else {
        dest.moveTo(h1, top);
        dest.lineTo(h1, (top + bottom) >> 1);

        dest.moveTo(h2, (top + bottom) >> 1);
        dest.lineTo(h2, bottom);
    }

    if (caps == 2) {
        dest.moveTo(h2, bottom);
        dest.lineTo(h2 - dist, bottom + dist);
        dest.lineTo(h2, bottom);
        dest.lineTo(h2 + dist, bottom + dist);
    } else if (caps == 1) {
        dest.moveTo(h2, bottom);
        dest.lineTo(h2 - dist, bottom + dist);

        dest.moveTo(h2 - dist, bottom + dist - 0.5f);
        dest.lineTo(h2 + dist, bottom + dist - 0.5f);

        dest.moveTo(h2 + dist, bottom + dist);
        dest.lineTo(h2, bottom);
    }

    if (fn == 2) {
        dest.moveTo(h1, top);
        dest.lineTo(h1 - dist, top - dist);
        dest.lineTo(h1, top);
        dest.lineTo(h1 + dist, top - dist);
    } else if (fn == 1) {
        dest.moveTo(h1, top);
        dest.lineTo(h1 - dist, top - dist);

        dest.moveTo(h1 - dist, top - dist + 0.5f);
        dest.lineTo(h1 + dist, top - dist + 0.5f);

        dest.moveTo(h1 + dist, top - dist);
        dest.lineTo(h1, top);
    }
}
 
源代码13 项目: TurboLauncher   文件: Launcher.java
@Override
public void onDestroy() {
	super.onDestroy();

	// Remove all pending runnables
	mHandler.removeMessages(ADVANCE_MSG);
	mHandler.removeMessages(0);
	mWorkspace.removeCallbacks(mBuildLayersRunnable);

	// Stop callbacks from LauncherModel
	LauncherAppState app = (LauncherAppState.getInstance());
	mModel.stopLoader();
	app.setLauncher(null);

	try {
		mAppWidgetHost.stopListening();
	} catch (NullPointerException ex) {
		Log.w(TAG,
				"problem while stopping AppWidgetHost during Launcher destruction",
				ex);
	}
	mAppWidgetHost = null;

	mWidgetsToAdvance.clear();

	TextKeyListener.getInstance().release();

	// Disconnect any of the callbacks and drawables associated with
	// ItemInfos on the workspace
	// to prevent leaking Launcher activities on orientation change.
	if (mModel != null) {
		mModel.unbindItemInfosAndClearQueuedBindRunnables();
	}

	getContentResolver().unregisterContentObserver(mWidgetObserver);
	unregisterReceiver(mCloseSystemDialogsReceiver);

	mDragLayer.clearAllResizeFrames();
	((ViewGroup) mWorkspace.getParent()).removeAllViews();
	mWorkspace.removeAllWorkspaceScreens();
	mWorkspace = null;
	mDragController = null;

	LauncherAnimUtils.onDestroyActivity();

	unregisterReceiver(protectedAppsChangedReceiver);
}
 
源代码14 项目: JotaTextEditor   文件: Layout.java
/**
 * Fills in the specified Path with a representation of a cursor
 * at the specified offset.  This will often be a vertical line
 * but can be multiple discontinous lines in text with multiple
 * directionalities.
 */
public void getCursorPath(int point, Path dest,
                          CharSequence editingBuffer) {
    dest.reset();

    int line = getLineForOffset(point);
    int top = getLineTop(line);
    int bottom = getLineTop(line+1);

    float h1 = getPrimaryHorizontal(point) - 0.5f;
    float h2 = getSecondaryHorizontal(point) - 0.5f;

    int caps = TextKeyListener.getMetaState(editingBuffer,
                                            KeyEvent.META_SHIFT_ON) |
               JotaTextKeyListener.getMetaStateSelecting(editingBuffer);
    int fn = TextKeyListener.getMetaState(editingBuffer,
                                          KeyEvent.META_ALT_ON);
    int dist = 0;

    if (caps != 0 || fn != 0) {
        dist = (bottom - top) >> 2;

        if (fn != 0)
            top += dist;
        if (caps != 0)
            bottom -= dist;
    }

    if (h1 < 0.5f)
        h1 = 0.5f;
    if (h2 < 0.5f)
        h2 = 0.5f;

    if (h1 == h2) {
        dest.moveTo(h1, top);
        dest.lineTo(h1, bottom);
    } else {
        dest.moveTo(h1, top);
        dest.lineTo(h1, (top + bottom) >> 1);

        dest.moveTo(h2, (top + bottom) >> 1);
        dest.lineTo(h2, bottom);
    }

    if (caps == 2) {
        dest.moveTo(h2, bottom);
        dest.lineTo(h2 - dist, bottom + dist);
        dest.lineTo(h2, bottom);
        dest.lineTo(h2 + dist, bottom + dist);
    } else if (caps == 1) {
        dest.moveTo(h2, bottom);
        dest.lineTo(h2 - dist, bottom + dist);

        dest.moveTo(h2 - dist, bottom + dist - 0.5f);
        dest.lineTo(h2 + dist, bottom + dist - 0.5f);

        dest.moveTo(h2 + dist, bottom + dist);
        dest.lineTo(h2, bottom);
    }

    if (fn == 2) {
        dest.moveTo(h1, top);
        dest.lineTo(h1 - dist, top - dist);
        dest.lineTo(h1, top);
        dest.lineTo(h1 + dist, top - dist);
    } else if (fn == 1) {
        dest.moveTo(h1, top);
        dest.lineTo(h1 - dist, top - dist);

        dest.moveTo(h1 - dist, top - dist + 0.5f);
        dest.lineTo(h1 + dist, top - dist + 0.5f);

        dest.moveTo(h1 + dist, top - dist);
        dest.lineTo(h1, top);
    }
}
 
源代码15 项目: commcare-android   文件: StringWidget.java
public StringWidget(Context context, FormEntryPrompt prompt, boolean secret, boolean inCompactGroup) {
    super(context, prompt, inCompactGroup);
    mAnswer = (EditText)LayoutInflater.from(getContext()).inflate(getAnswerLayout(), this, false);
    mAnswer.setTextSize(TypedValue.COMPLEX_UNIT_DIP, mAnswerFontSize);
    mAnswer.setOnClickListener(this);

    mAnswer.addTextChangedListener(this);

    //Let's see if we can figure out a constraint for this string
    try {
        addAnswerFilter(new InputFilter.LengthFilter(guessMaxStringLength(prompt)));
    } catch (UnpivotableExpressionException e) {
        //expected if there isn't a constraint that does this
    }

    this.secret = secret;

    if (!secret) {
        // capitalize the first letter of the sentence
        mAnswer.setKeyListener(new TextKeyListener(Capitalize.SENTENCES, false));
    }
    setTextInputType(mAnswer);

    if (!secret) {
        mAnswer.setSingleLine(false);
    }

    if (prompt != null) {
        mReadOnly = prompt.isReadOnly();
        IAnswerData value = prompt.getAnswerValue();
        if (value != null) {
            mAnswer.setText(value.getDisplayText());
        }

        if (mReadOnly) {
            if (value == null) {
                mAnswer.setText("---");
            }
            mAnswer.setBackgroundDrawable(null);
            mAnswer.setFocusable(false);
            mAnswer.setClickable(false);
        }
    }

    if (isInCompactMode()) {
        addToCompactLayout(mAnswer);
    } else {
        addView(mAnswer);
    }
}
 
源代码16 项目: BluetoothHidEmu   文件: KeyboardKeyListener.java
public KeyboardKeyListener(SocketManager socketManager) {
    super();
    
    mTextKeyListener = new TextKeyListener(Capitalize.NONE, false);
    mSocketManager = socketManager;
    
}
 
 类所在包
 类方法
 同包方法