List of usage examples for java.lang Character getType
public static int getType(int codePoint)
From source file:com.jecelyin.editor.v2.core.text.TextUtils.java
/** * Returns whether the given CharSequence contains any printable characters. *//*from ww w. j a v a2 s .c o m*/ public static boolean isGraphic(CharSequence str) { final int len = str.length(); for (int i = 0; i < len; i++) { int gc = Character.getType(str.charAt(i)); if (gc != Character.CONTROL && gc != Character.FORMAT && gc != Character.SURROGATE && gc != Character.UNASSIGNED && gc != Character.LINE_SEPARATOR && gc != Character.PARAGRAPH_SEPARATOR && gc != Character.SPACE_SEPARATOR) { return true; } } return false; }
From source file:com.jecelyin.editor.v2.core.text.TextUtils.java
/** * Returns whether this character is a printable character. */// ww w. j ava 2s. c om public static boolean isGraphic(char c) { int gc = Character.getType(c); return gc != Character.CONTROL && gc != Character.FORMAT && gc != Character.SURROGATE && gc != Character.UNASSIGNED && gc != Character.LINE_SEPARATOR && gc != Character.PARAGRAPH_SEPARATOR && gc != Character.SPACE_SEPARATOR; }
From source file:org.odk.collect.android.activities.FormEntryActivity.java
/** * Creates a view given the View type and an event * * @param advancingPage -- true if this results from advancing through the form * @return newly created View// w w w . j av a 2 s . c om */ private View createView(int event, boolean advancingPage) { FormController formController = Collect.getInstance().getFormController(); if (hasHardwareMenu) { toolbar.setTitle(formController.getFormTitle()); } else { setTitle(formController.getFormTitle()); } switch (event) { case FormEntryController.EVENT_BEGINNING_OF_FORM: return createViewForFormBeginning(event, true, formController); case FormEntryController.EVENT_END_OF_FORM: View endView = View.inflate(this, R.layout.form_entry_end, null); ((TextView) endView.findViewById(R.id.description)) .setText(getString(R.string.save_enter_data_description, formController.getFormTitle())); // checkbox for if finished or ready to send final CheckBox instanceComplete = ((CheckBox) endView.findViewById(R.id.mark_finished)); instanceComplete.setChecked(isInstanceComplete(true)); if (!adminPreferences.getBoolean(AdminKeys.KEY_MARK_AS_FINALIZED, true)) { instanceComplete.setVisibility(View.GONE); } // edittext to change the displayed name of the instance final EditText saveAs = (EditText) endView.findViewById(R.id.save_name); // disallow carriage returns in the name InputFilter returnFilter = new InputFilter() { public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) { for (int i = start; i < end; i++) { if (Character.getType((source.charAt(i))) == Character.CONTROL) { return ""; } } return null; } }; saveAs.setFilters(new InputFilter[] { returnFilter }); String saveName = formController.getSubmissionMetadata().instanceName; if (saveName == null) { // no meta/instanceName field in the form -- see if we have a // name for this instance from a previous save attempt... if (getContentResolver().getType(getIntent().getData()) == InstanceColumns.CONTENT_ITEM_TYPE) { Uri instanceUri = getIntent().getData(); Cursor instance = null; try { instance = getContentResolver().query(instanceUri, null, null, null, null); if (instance.getCount() == 1) { instance.moveToFirst(); saveName = instance.getString(instance.getColumnIndex(InstanceColumns.DISPLAY_NAME)); } } finally { if (instance != null) { instance.close(); } } } if (saveName == null) { // last resort, default to the form title saveName = formController.getFormTitle(); } // present the prompt to allow user to name the form TextView sa = (TextView) endView.findViewById(R.id.save_form_as); sa.setVisibility(View.VISIBLE); saveAs.setText(saveName); saveAs.setEnabled(true); saveAs.setVisibility(View.VISIBLE); } else { // if instanceName is defined in form, this is the name -- no // revisions // display only the name, not the prompt, and disable edits TextView sa = (TextView) endView.findViewById(R.id.save_form_as); sa.setVisibility(View.GONE); saveAs.setText(saveName); saveAs.setEnabled(false); saveAs.setVisibility(View.VISIBLE); } // override the visibility settings based upon admin preferences if (!adminPreferences.getBoolean(AdminKeys.KEY_SAVE_AS, true)) { saveAs.setVisibility(View.GONE); TextView sa = (TextView) endView.findViewById(R.id.save_form_as); sa.setVisibility(View.GONE); } // Create 'save' button endView.findViewById(R.id.save_exit_button).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Collect.getInstance().getActivityLogger().logInstanceAction(this, "createView.saveAndExit", instanceComplete.isChecked() ? "saveAsComplete" : "saveIncomplete"); // Form is marked as 'saved' here. if (saveAs.getText().length() < 1) { ToastUtils.showShortToast(R.string.save_as_error); } else { saveDataToDisk(EXIT, instanceComplete.isChecked(), saveAs.getText().toString()); } } }); if (showNavigationButtons) { backButton.setEnabled(true); nextButton.setEnabled(false); } return endView; case FormEntryController.EVENT_QUESTION: case FormEntryController.EVENT_GROUP: case FormEntryController.EVENT_REPEAT: ODKView odkv = null; // should only be a group here if the event_group is a field-list try { FormEntryPrompt[] prompts = formController.getQuestionPrompts(); FormEntryCaption[] groups = formController.getGroupsForCurrentIndex(); odkv = new ODKView(this, formController.getQuestionPrompts(), groups, advancingPage); Timber.i("Created view for group %s %s", (groups.length > 0 ? groups[groups.length - 1].getLongText() : "[top]"), (prompts.length > 0 ? prompts[0].getQuestionText() : "[no question]")); } catch (RuntimeException e) { Timber.e(e); // this is badness to avoid a crash. try { event = formController.stepToNextScreenEvent(); createErrorDialog(e.getMessage(), DO_NOT_EXIT); } catch (JavaRosaException e1) { Timber.e(e1); createErrorDialog(e.getMessage() + "\n\n" + e1.getCause().getMessage(), DO_NOT_EXIT); } return createView(event, advancingPage); } // Makes a "clear answer" menu pop up on long-click for (QuestionWidget qw : odkv.getWidgets()) { if (!qw.getPrompt().isReadOnly()) { // If it's a StringWidget register all its elements apart from EditText as // we want to enable paste option after long click on the EditText if (qw instanceof StringWidget) { for (int i = 0; i < qw.getChildCount(); i++) { if (!(qw.getChildAt(i) instanceof EditText)) { registerForContextMenu(qw.getChildAt(i)); } } } else { registerForContextMenu(qw); } } } if (showNavigationButtons) { adjustBackNavigationButtonVisibility(); nextButton.setEnabled(true); } return odkv; case FormEntryController.EVENT_PROMPT_NEW_REPEAT: createRepeatDialog(); return new EmptyView(this); default: Timber.e("Attempted to create a view that does not exist."); // this is badness to avoid a crash. try { event = formController.stepToNextScreenEvent(); createErrorDialog(getString(R.string.survey_internal_error), EXIT); } catch (JavaRosaException e) { Timber.e(e); createErrorDialog(e.getCause().getMessage(), EXIT); } return createView(event, advancingPage); } }
From source file:com.jecelyin.editor.v2.core.text.TextUtils.java
/** * Determine what caps mode should be in effect at the current offset in * the text. Only the mode bits set in <var>reqModes</var> will be * checked. Note that the caps mode flags here are explicitly defined * to match those in {@link android.text.InputType}. * * @param cs The text that should be checked for caps modes. * @param off Location in the text at which to check. * @param reqModes The modes to be checked: may be any combination of * {@link #CAP_MODE_CHARACTERS}, {@link #CAP_MODE_WORDS}, and * {@link #CAP_MODE_SENTENCES}./*from ww w . java 2 s . c o m*/ * * @return Returns the actual capitalization modes that can be in effect * at the current position, which is any combination of * {@link #CAP_MODE_CHARACTERS}, {@link #CAP_MODE_WORDS}, and * {@link #CAP_MODE_SENTENCES}. */ public static int getCapsMode(CharSequence cs, int off, int reqModes) { if (off < 0) { return 0; } int i; char c; int mode = 0; if ((reqModes & CAP_MODE_CHARACTERS) != 0) { mode |= CAP_MODE_CHARACTERS; } if ((reqModes & (CAP_MODE_WORDS | CAP_MODE_SENTENCES)) == 0) { return mode; } // Back over allowed opening punctuation. for (i = off; i > 0; i--) { c = cs.charAt(i - 1); if (c != '"' && c != '\'' && Character.getType(c) != Character.START_PUNCTUATION) { break; } } // Start of paragraph, with optional whitespace. int j = i; while (j > 0 && ((c = cs.charAt(j - 1)) == ' ' || c == '\t')) { j--; } if (j == 0 || cs.charAt(j - 1) == '\n') { return mode | CAP_MODE_WORDS; } // Or start of word if we are that style. if ((reqModes & CAP_MODE_SENTENCES) == 0) { if (i != j) mode |= CAP_MODE_WORDS; return mode; } // There must be a space if not the start of paragraph. if (i == j) { return mode; } // Back over allowed closing punctuation. for (; j > 0; j--) { c = cs.charAt(j - 1); if (c != '"' && c != '\'' && Character.getType(c) != Character.END_PUNCTUATION) { break; } } if (j > 0) { c = cs.charAt(j - 1); if (c == '.' || c == '?' || c == '!') { // Do not capitalize if the word ends with a period but // also contains a period, in which case it is an abbreviation. if (c == '.') { for (int k = j - 2; k >= 0; k--) { c = cs.charAt(k); if (c == '.') { return mode; } if (!Character.isLetter(c)) { break; } } } return mode | CAP_MODE_SENTENCES; } } return mode; }
From source file:com.kll.collect.android.activities.FormEntryActivity.java
/** * Creates a view given the View type and an event * * @param event/*from w ww. j a v a 2s . co m*/ * @param advancingPage * -- true if this results from advancing through the form * @return newly created View */ private View createView(int event, boolean advancingPage, int swipeCase) { FormController formController = Collect.getInstance().getFormController(); /* setTitle(getString(R.string.app_name) + " > " + formController.getFormTitle());*/ int questioncount = formController.getFormDef().getDeepChildCount(); switch (event) { case FormEntryController.EVENT_BEGINNING_OF_FORM: progressValue = 0.0; progressUpdate(progressValue, questioncount); View startView = View.inflate(this, R.layout.form_entry_start, null); /*setTitle(getString(R.string.app_name) + " > " + formController.getFormTitle());*/ Drawable image = null; File mediaFolder = formController.getMediaFolder(); String mediaDir = mediaFolder.getAbsolutePath(); BitmapDrawable bitImage = null; // attempt to load the form-specific logo... // this is arbitrarily silly bitImage = new BitmapDrawable(getResources(), mediaDir + File.separator + "form_logo.png"); if (bitImage != null && bitImage.getBitmap() != null && bitImage.getIntrinsicHeight() > 0 && bitImage.getIntrinsicWidth() > 0) { image = bitImage; } if (image == null) { // show the opendatakit zig... // image = // getResources().getDrawable(R.drawable.opendatakit_zig); ((ImageView) startView.findViewById(R.id.form_start_bling)).setVisibility(View.GONE); } else { ImageView v = ((ImageView) startView.findViewById(R.id.form_start_bling)); v.setImageDrawable(image); v.setContentDescription(formController.getFormTitle()); } // change start screen based on navigation prefs String navigationChoice = PreferenceManager.getDefaultSharedPreferences(this) .getString(PreferencesActivity.KEY_NAVIGATION, PreferencesActivity.KEY_NAVIGATION); Boolean useSwipe = false; Boolean useButtons = false; ImageView ia = ((ImageView) startView.findViewById(R.id.image_advance)); ImageView ib = ((ImageView) startView.findViewById(R.id.image_backup)); TextView ta = ((TextView) startView.findViewById(R.id.text_advance)); TextView tb = ((TextView) startView.findViewById(R.id.text_backup)); TextView d = ((TextView) startView.findViewById(R.id.description)); if (navigationChoice != null) { if (navigationChoice.contains(PreferencesActivity.NAVIGATION_SWIPE)) { useSwipe = true; } if (navigationChoice.contains(PreferencesActivity.NAVIGATION_BUTTONS)) { useButtons = true; } } if (useSwipe && !useButtons) { d.setText(getString(R.string.swipe_instructions, formController.getFormTitle())); } else if (useButtons && !useSwipe) { ia.setVisibility(View.GONE); ib.setVisibility(View.GONE); ta.setVisibility(View.GONE); tb.setVisibility(View.GONE); d.setText(getString(R.string.buttons_instructions, formController.getFormTitle())); } else { d.setText(getString(R.string.swipe_buttons_instructions, formController.getFormTitle())); } if (mBackButton.isShown()) { mBackButton.setEnabled(false); } if (mNextButton.isShown()) { mNextButton.setEnabled(true); } return startView; case FormEntryController.EVENT_END_OF_FORM: progressValue = questioncount; progressUpdate(progressValue, questioncount); View endView = View.inflate(this, R.layout.form_entry_end, null); ((ImageView) endView.findViewById(R.id.completed)) .setImageDrawable(getResources().getDrawable(R.drawable.complete_tick)); ((TextView) endView.findViewById(R.id.description)) .setText(getString(R.string.save_enter_data_description, formController.getFormTitle())); // checkbox for if finished or ready to send final CheckBox instanceComplete = ((CheckBox) endView.findViewById(R.id.mark_finished)); instanceComplete.setChecked(isInstanceComplete(true)); if (!mAdminPreferences.getBoolean(AdminPreferencesActivity.KEY_MARK_AS_FINALIZED, true)) { instanceComplete.setVisibility(View.GONE); } // edittext to change the displayed name of the instance final EditText saveAs = (EditText) endView.findViewById(R.id.save_name); // disallow carriage returns in the name InputFilter returnFilter = new InputFilter() { public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) { for (int i = start; i < end; i++) { if (Character.getType((source.charAt(i))) == Character.CONTROL) { return ""; } } return null; } }; saveAs.setFilters(new InputFilter[] { returnFilter }); String saveName = getSaveName(); if (saveName == null) { // no meta/instanceName field in the form -- see if we have a // name for this instance from a previous save attempt... if (getContentResolver().getType(getIntent().getData()) == InstanceColumns.CONTENT_ITEM_TYPE) { Uri instanceUri = getIntent().getData(); Cursor instance = null; try { instance = getContentResolver().query(instanceUri, null, null, null, null); if (instance.getCount() == 1) { instance.moveToFirst(); saveName = instance.getString(instance.getColumnIndex(InstanceColumns.DISPLAY_NAME)); } } finally { if (instance != null) { instance.close(); } } } if (saveName == null) { // last resort, default to the form title saveName = formController.getFormTitle(); } // present the prompt to allow user to name the form TextView sa = (TextView) endView.findViewById(R.id.save_form_as); sa.setVisibility(View.VISIBLE); saveAs.setText(saveName); saveAs.setEnabled(true); saveAs.setVisibility(View.VISIBLE); } else { // if instanceName is defined in form, this is the name -- no // revisions // display only the name, not the prompt, and disable edits TextView sa = (TextView) endView.findViewById(R.id.save_form_as); sa.setVisibility(View.GONE); saveAs.setText(saveName); saveAs.setEnabled(false); saveAs.setBackgroundColor(Color.WHITE); saveAs.setVisibility(View.VISIBLE); } // override the visibility settings based upon admin preferences if (!mAdminPreferences.getBoolean(AdminPreferencesActivity.KEY_SAVE_AS, true)) { saveAs.setVisibility(View.GONE); TextView sa = (TextView) endView.findViewById(R.id.save_form_as); sa.setVisibility(View.GONE); } // Create 'save' button ((Button) endView.findViewById(R.id.save_exit_button)).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Collect.getInstance().getActivityLogger().logInstanceAction(this, "createView.saveAndExit", instanceComplete.isChecked() ? "saveAsComplete" : "saveIncomplete"); // Form is marked as 'saved' here. if (saveAs.getText().length() < 1) { Toast.makeText(FormEntryActivity.this, R.string.save_as_error, Toast.LENGTH_SHORT).show(); } else { saveDataToDisk(EXIT, instanceComplete.isChecked(), saveAs.getText().toString()); } } }); if (mBackButton.isShown()) { mBackButton.setEnabled(true); } if (mNextButton.isShown()) { mNextButton.setEnabled(false); } return endView; case FormEntryController.EVENT_QUESTION: case FormEntryController.EVENT_GROUP: case FormEntryController.EVENT_REPEAT: ODKView odkv = null; // should only be a group here if the event_group is a field-list try { double depth = (double) formController.getFormIndex().getDepth(); double local_index = (double) formController.getFormIndex().getLocalIndex(); double instance_index = (double) formController.getFormIndex().getInstanceIndex(); Log.i("Question coint", Integer.toString(questioncount)); Log.i("Depth", Integer.toString(formController.getFormIndex().getDepth())); Log.i("Local Index", Integer.toString(formController.getFormIndex().getLocalIndex())); Log.i("Instance Index", Integer.toString(formController.getFormIndex().getInstanceIndex())); if (swipeCase == NEXT) { Log.i("progressValue", Double.toString(progressValue)); } if (swipeCase == PREVIOUS) { progressValue = progressValue - (1 - (instance_index * local_index / questioncount * depth)); Log.i("progressValue", Double.toString(progressValue)); } Log.i("progressValue", Double.toString(progressValue)); progressUpdate(progressValue, questioncount); FormEntryPrompt[] prompts = formController.getQuestionPrompts(); FormEntryCaption[] groups = formController.getGroupsForCurrentIndex(); odkv = new ODKView(this, formController.getQuestionPrompts(), groups, advancingPage); Log.i(t, "created view for group " + (groups.length > 0 ? groups[groups.length - 1].getLongText() : "[top]") + " " + (prompts.length > 0 ? prompts[0].getQuestionText() : "[no question]")); } catch (RuntimeException e) { Log.e(t, e.getMessage(), e); // this is badness to avoid a crash. try { event = formController.stepToNextScreenEvent(); createErrorDialog(e.getMessage(), DO_NOT_EXIT); } catch (JavaRosaException e1) { Log.e(t, e1.getMessage(), e1); createErrorDialog(e.getMessage() + "\n\n" + e1.getCause().getMessage(), DO_NOT_EXIT); } return createView(event, advancingPage, swipeCase); } // Makes a "clear answer" menu pop up on long-click for (QuestionWidget qw : odkv.getWidgets()) { if (!qw.getPrompt().isReadOnly()) { registerForContextMenu(qw); } } if (mBackButton.isShown() && mNextButton.isShown()) { mBackButton.setEnabled(true); mNextButton.setEnabled(true); } return odkv; default: Log.e(t, "Attempted to create a view that does not exist."); // this is badness to avoid a crash. try { event = formController.stepToNextScreenEvent(); createErrorDialog(getString(R.string.survey_internal_error), EXIT); } catch (JavaRosaException e) { Log.e(t, e.getMessage(), e); createErrorDialog(e.getCause().getMessage(), EXIT); } return createView(event, advancingPage, swipeCase); } }
From source file:org.distantshoresmedia.keyboard.LatinIME.java
public void onKey(int primaryCode, int[] keyCodes, int x, int y) { long when = SystemClock.uptimeMillis(); if (primaryCode != Keyboard.KEYCODE_DELETE || when > mLastKeyTime + QUICK_PRESS) { mDeleteCount = 0;//from w w w. j a v a2 s . c om } mLastKeyTime = when; final boolean distinctMultiTouch = mKeyboardSwitcher.hasDistinctMultitouch(); switch (primaryCode) { case Keyboard.KEYCODE_DELETE: if (processMultiKey(primaryCode)) { break; } handleBackspace(); mDeleteCount++; TKIMELogger.logOnDelete(); break; case Keyboard.KEYCODE_SHIFT: // Shift key is handled in onPress() when device has distinct // multi-touch panel. if (!distinctMultiTouch) handleShift(); break; case Keyboard.KEYCODE_MODE_CHANGE: // Symbol key is handled in onPress() when device has distinct // multi-touch panel. if (!distinctMultiTouch) changeKeyboardMode(); break; case TKKeyboardView.KEYCODE_CTRL_LEFT: // Ctrl key is handled in onPress() when device has distinct // multi-touch panel. if (!distinctMultiTouch) setModCtrl(!mModCtrl); break; case TKKeyboardView.KEYCODE_ALT_LEFT: // Alt key is handled in onPress() when device has distinct // multi-touch panel. if (!distinctMultiTouch) setModAlt(!mModAlt); break; case TKKeyboardView.KEYCODE_META_LEFT: // Meta key is handled in onPress() when device has distinct // multi-touch panel. if (!distinctMultiTouch) setModMeta(!mModMeta); break; case TKKeyboardView.KEYCODE_FN: if (!distinctMultiTouch) setModFn(!mModFn); break; case Keyboard.KEYCODE_CANCEL: if (!isShowingOptionDialog()) { handleClose(); } break; case TKKeyboardView.KEYCODE_OPTIONS: onOptionKeyPressed(); break; case TKKeyboardView.KEYCODE_OPTIONS_LONGPRESS: onOptionKeyLongPressed(); break; case TKKeyboardView.KEYCODE_COMPOSE: mComposeMode = !mComposeMode; mComposeBuffer.clear(); break; case TKKeyboardView.KEYCODE_NEXT_LANGUAGE: toggleLanguage(false, true); break; case TKKeyboardView.KEYCODE_PREV_LANGUAGE: toggleLanguage(false, false); break; case TKKeyboardView.KEYCODE_VOICE: // if (mVoiceRecognitionTrigger.isInstalled()) { // mVoiceRecognitionTrigger.startVoiceRecognition(); // } //startListening(false /* was a button press, was not a swipe */); break; case 9 /* Tab */: if (processMultiKey(primaryCode)) { break; } sendTab(); break; case TKKeyboardView.KEYCODE_ESCAPE: if (processMultiKey(primaryCode)) { break; } sendEscape(); break; case TKKeyboardView.KEYCODE_DPAD_UP: case TKKeyboardView.KEYCODE_DPAD_DOWN: case TKKeyboardView.KEYCODE_DPAD_LEFT: case TKKeyboardView.KEYCODE_DPAD_RIGHT: case TKKeyboardView.KEYCODE_DPAD_CENTER: case TKKeyboardView.KEYCODE_HOME: case TKKeyboardView.KEYCODE_END: case TKKeyboardView.KEYCODE_PAGE_UP: case TKKeyboardView.KEYCODE_PAGE_DOWN: case TKKeyboardView.KEYCODE_FKEY_F1: case TKKeyboardView.KEYCODE_FKEY_F2: case TKKeyboardView.KEYCODE_FKEY_F3: case TKKeyboardView.KEYCODE_FKEY_F4: case TKKeyboardView.KEYCODE_FKEY_F5: case TKKeyboardView.KEYCODE_FKEY_F6: case TKKeyboardView.KEYCODE_FKEY_F7: case TKKeyboardView.KEYCODE_FKEY_F8: case TKKeyboardView.KEYCODE_FKEY_F9: case TKKeyboardView.KEYCODE_FKEY_F10: case TKKeyboardView.KEYCODE_FKEY_F11: case TKKeyboardView.KEYCODE_FKEY_F12: case TKKeyboardView.KEYCODE_FORWARD_DEL: case TKKeyboardView.KEYCODE_INSERT: case TKKeyboardView.KEYCODE_SYSRQ: case TKKeyboardView.KEYCODE_BREAK: case TKKeyboardView.KEYCODE_NUM_LOCK: case TKKeyboardView.KEYCODE_SCROLL_LOCK: if (processMultiKey(primaryCode)) { break; } // send as plain keys, or as escape sequence if needed sendSpecialKey(-primaryCode); break; default: if (!mComposeMode && mDeadKeysActive && Character.getType(primaryCode) == Character.NON_SPACING_MARK) { //Log.i(TAG, "possible dead character: " + primaryCode); if (!mDeadAccentBuffer.execute(primaryCode)) { //Log.i(TAG, "double dead key"); break; // pressing a dead key twice produces spacing equivalent } updateShiftKeyState(getCurrentInputEditorInfo()); break; } if (processMultiKey(primaryCode)) { break; } if (primaryCode != ASCII_ENTER) { mJustAddedAutoSpace = false; } TKIMEUtil.RingCharBuffer.getInstance().push((char) primaryCode, x, y); TKIMELogger.logOnInputChar(); if (isWordSeparator(primaryCode)) { handleSeparator(primaryCode); } else { handleCharacter(primaryCode, keyCodes); } // Cancel the just reverted state mJustRevertedSeparator = null; } mKeyboardSwitcher.onKey(primaryCode); // Reset after any single keystroke mEnteredText = null; //mDeadAccentBuffer.clear(); // FIXME }
From source file:org.pocketworkstation.pckeyboard.LatinIME.java
public void onKey(int primaryCode, int[] keyCodes, int x, int y) { long when = SystemClock.uptimeMillis(); if (primaryCode != Keyboard.KEYCODE_DELETE || when > mLastKeyTime + QUICK_PRESS) { mDeleteCount = 0;/*from ww w . ja v a 2s .c om*/ } mLastKeyTime = when; final boolean distinctMultiTouch = mKeyboardSwitcher.hasDistinctMultitouch(); switch (primaryCode) { case Keyboard.KEYCODE_DELETE: if (processMultiKey(primaryCode)) { break; } handleBackspace(); mDeleteCount++; break; case Keyboard.KEYCODE_SHIFT: // Shift key is handled in onPress() when device has distinct // multi-touch panel. if (!distinctMultiTouch) handleShift(); break; case Keyboard.KEYCODE_MODE_CHANGE: // Symbol key is handled in onPress() when device has distinct // multi-touch panel. if (!distinctMultiTouch) changeKeyboardMode(); break; case LatinKeyboardView.KEYCODE_CTRL_LEFT: // Ctrl key is handled in onPress() when device has distinct // multi-touch panel. if (!distinctMultiTouch) setModCtrl(!mModCtrl); break; case LatinKeyboardView.KEYCODE_ALT_LEFT: // Alt key is handled in onPress() when device has distinct // multi-touch panel. if (!distinctMultiTouch) setModAlt(!mModAlt); break; case LatinKeyboardView.KEYCODE_META_LEFT: // Meta key is handled in onPress() when device has distinct // multi-touch panel. if (!distinctMultiTouch) setModMeta(!mModMeta); break; case LatinKeyboardView.KEYCODE_FN: if (!distinctMultiTouch) setModFn(!mModFn); break; case Keyboard.KEYCODE_CANCEL: if (!isShowingOptionDialog()) { handleClose(); } break; case LatinKeyboardView.KEYCODE_OPTIONS: onOptionKeyPressed(); break; case LatinKeyboardView.KEYCODE_OPTIONS_LONGPRESS: onOptionKeyLongPressed(); break; case LatinKeyboardView.KEYCODE_COMPOSE: mComposeMode = !mComposeMode; mComposeBuffer.clear(); break; case LatinKeyboardView.KEYCODE_NEXT_LANGUAGE: toggleLanguage(false, true); break; case LatinKeyboardView.KEYCODE_PREV_LANGUAGE: toggleLanguage(false, false); break; case LatinKeyboardView.KEYCODE_VOICE: if (mVoiceRecognitionTrigger.isInstalled()) { mVoiceRecognitionTrigger.startVoiceRecognition(); } //startListening(false /* was a button press, was not a swipe */); break; case 9 /* Tab */: if (processMultiKey(primaryCode)) { break; } sendTab(); break; case LatinKeyboardView.KEYCODE_ESCAPE: if (processMultiKey(primaryCode)) { break; } sendEscape(); break; case LatinKeyboardView.KEYCODE_DPAD_UP: case LatinKeyboardView.KEYCODE_DPAD_DOWN: case LatinKeyboardView.KEYCODE_DPAD_LEFT: case LatinKeyboardView.KEYCODE_DPAD_RIGHT: case LatinKeyboardView.KEYCODE_DPAD_CENTER: case LatinKeyboardView.KEYCODE_HOME: case LatinKeyboardView.KEYCODE_END: case LatinKeyboardView.KEYCODE_PAGE_UP: case LatinKeyboardView.KEYCODE_PAGE_DOWN: case LatinKeyboardView.KEYCODE_FKEY_F1: case LatinKeyboardView.KEYCODE_FKEY_F2: case LatinKeyboardView.KEYCODE_FKEY_F3: case LatinKeyboardView.KEYCODE_FKEY_F4: case LatinKeyboardView.KEYCODE_FKEY_F5: case LatinKeyboardView.KEYCODE_FKEY_F6: case LatinKeyboardView.KEYCODE_FKEY_F7: case LatinKeyboardView.KEYCODE_FKEY_F8: case LatinKeyboardView.KEYCODE_FKEY_F9: case LatinKeyboardView.KEYCODE_FKEY_F10: case LatinKeyboardView.KEYCODE_FKEY_F11: case LatinKeyboardView.KEYCODE_FKEY_F12: case LatinKeyboardView.KEYCODE_FORWARD_DEL: case LatinKeyboardView.KEYCODE_INSERT: case LatinKeyboardView.KEYCODE_SYSRQ: case LatinKeyboardView.KEYCODE_BREAK: case LatinKeyboardView.KEYCODE_NUM_LOCK: case LatinKeyboardView.KEYCODE_SCROLL_LOCK: if (processMultiKey(primaryCode)) { break; } // send as plain keys, or as escape sequence if needed sendSpecialKey(-primaryCode); break; default: if (!mComposeMode && mDeadKeysActive && Character.getType(primaryCode) == Character.NON_SPACING_MARK) { //Log.i(TAG, "possible dead character: " + primaryCode); if (!mDeadAccentBuffer.execute(primaryCode)) { //Log.i(TAG, "double dead key"); break; // pressing a dead key twice produces spacing equivalent } updateShiftKeyState(getCurrentInputEditorInfo()); break; } if (processMultiKey(primaryCode)) { break; } if (primaryCode != ASCII_ENTER) { mJustAddedAutoSpace = false; } RingCharBuffer.getInstance().push((char) primaryCode, x, y); if (isWordSeparator(primaryCode)) { handleSeparator(primaryCode); } else { handleCharacter(primaryCode, keyCodes); } // Cancel the just reverted state mJustRevertedSeparator = null; } mKeyboardSwitcher.onKey(primaryCode); // Reset after any single keystroke mEnteredText = null; //mDeadAccentBuffer.clear(); // FIXME }
From source file:com.yucheng.cmis.pub.util.NewStringUtils.java
/** * <p>Splits a String by Character type as returned by * <code>java.lang.Character.getType(char)</code>. Groups of contiguous * characters of the same type are returned as complete tokens, with the * following exception: if <code>camelCase</code> is <code>true</code>, * the character of type <code>Character.UPPERCASE_LETTER</code>, if any, * immediately preceding a token of type <code>Character.LOWERCASE_LETTER</code> * will belong to the following token rather than to the preceding, if any, * <code>Character.UPPERCASE_LETTER</code> token. * @param str the String to split, may be <code>null</code> * @param camelCase whether to use so-called "camel-case" for letter types * @return an array of parsed Strings, <code>null</code> if null String input * @since 2.4//from ww w . j av a2 s . com */ private static String[] splitByCharacterType(String str, boolean camelCase) { if (str == null) { return null; } if (str.length() == 0) { return NewArrayUtils.EMPTY_STRING_ARRAY; } char[] c = str.toCharArray(); List list = new ArrayList(); int tokenStart = 0; int currentType = Character.getType(c[tokenStart]); for (int pos = tokenStart + 1; pos < c.length; pos++) { int type = Character.getType(c[pos]); if (type == currentType) { continue; } if (camelCase && type == Character.LOWERCASE_LETTER && currentType == Character.UPPERCASE_LETTER) { int newTokenStart = pos - 1; if (newTokenStart != tokenStart) { list.add(new String(c, tokenStart, newTokenStart - tokenStart)); tokenStart = newTokenStart; } } else { list.add(new String(c, tokenStart, pos - tokenStart)); tokenStart = pos; } currentType = type; } list.add(new String(c, tokenStart, c.length - tokenStart)); return (String[]) list.toArray(new String[list.size()]); }
From source file:com.test.stringtest.StringUtils.java
/** * <p>Splits a String by Character type as returned by * <code>java.lang.Character.getType(char)</code>. Groups of contiguous * characters of the same type are returned as complete tokens, with the * following exception: if <code>camelCase</code> is <code>true</code>, * the character of type <code>Character.UPPERCASE_LETTER</code>, if any, * immediately preceding a token of type <code>Character.LOWERCASE_LETTER</code> * will belong to the following token rather than to the preceding, if any, * <code>Character.UPPERCASE_LETTER</code> token. * @param str the String to split, may be <code>null</code> * @param camelCase whether to use so-called "camel-case" for letter types * @return an array of parsed Strings, <code>null</code> if null String input * @since 2.4// w ww . j av a 2s.c om */ private static String[] splitByCharacterType(String str, boolean camelCase) { if (str == null) { return null; } if (str.length() == 0) { return ArrayUtils.EMPTY_STRING_ARRAY; } char[] c = str.toCharArray(); List list = new ArrayList(); int tokenStart = 0; int currentType = Character.getType(c[tokenStart]); for (int pos = tokenStart + 1; pos < c.length; pos++) { int type = Character.getType(c[pos]); if (type == currentType) { continue; } if (camelCase && type == Character.LOWERCASE_LETTER && currentType == Character.UPPERCASE_LETTER) { int newTokenStart = pos - 1; if (newTokenStart != tokenStart) { list.add(new String(c, tokenStart, newTokenStart - tokenStart)); tokenStart = newTokenStart; } } else { list.add(new String(c, tokenStart, pos - tokenStart)); tokenStart = pos; } currentType = type; } list.add(new String(c, tokenStart, c.length - tokenStart)); return (String[]) list.toArray(new String[list.size()]); }
From source file:ths.commons.util.StringUtils.java
/** * <p>Splits a String by Character type as returned by * {@code java.lang.Character.getType(char)}. Groups of contiguous * characters of the same type are returned as complete tokens, with the * following exception: if {@code camelCase} is {@code true}, * the character of type {@code Character.UPPERCASE_LETTER}, if any, * immediately preceding a token of type {@code Character.LOWERCASE_LETTER} * will belong to the following token rather than to the preceding, if any, * {@code Character.UPPERCASE_LETTER} token. * @param str the String to split, may be {@code null} * @param camelCase whether to use so-called "camel-case" for letter types * @return an array of parsed Strings, {@code null} if null String input * @since 2.4// w w w . jav a 2 s .com */ private static String[] splitByCharacterType(String str, boolean camelCase) { if (str == null) { return null; } if (str.length() == 0) { return EMPTY_STRING_ARRAY; } char[] c = str.toCharArray(); List<String> list = new ArrayList<String>(); int tokenStart = 0; int currentType = Character.getType(c[tokenStart]); for (int pos = tokenStart + 1; pos < c.length; pos++) { int type = Character.getType(c[pos]); if (type == currentType) { continue; } if (camelCase && type == Character.LOWERCASE_LETTER && currentType == Character.UPPERCASE_LETTER) { int newTokenStart = pos - 1; if (newTokenStart != tokenStart) { list.add(new String(c, tokenStart, newTokenStart - tokenStart)); tokenStart = newTokenStart; } } else { list.add(new String(c, tokenStart, pos - tokenStart)); tokenStart = pos; } currentType = type; } list.add(new String(c, tokenStart, c.length - tokenStart)); return list.toArray(new String[list.size()]); }