List of usage examples for java.lang Character CONTROL
byte CONTROL
To view the source code for java.lang Character CONTROL.
Click Source Link
From source file:com.jecelyin.editor.v2.core.text.TextUtils.java
/** * Returns whether the given CharSequence contains any printable characters. *///from w w w .j a v a 2 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. *//*from w w w.ja v a 2 s. c o m*/ 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/*from w w w . j av a 2 s. c o m*/ */ 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.kll.collect.android.activities.FormEntryActivity.java
/** * Creates a view given the View type and an event * * @param event/*from w w w. j ava 2 s . c o 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); } }