SingleLineTransformationMethod.java revision 54b6cfa9a9e5b861a9930af873580d6dc20f773c
1/* 2 * Copyright (C) 2006 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package android.text.method; 18 19import android.graphics.Rect; 20import android.text.Editable; 21import android.text.GetChars; 22import android.text.Spannable; 23import android.text.Spanned; 24import android.text.SpannedString; 25import android.text.TextUtils; 26import android.view.View; 27 28/** 29 * This transformation method causes any newline characters (\n) to be 30 * displayed as spaces instead of causing line breaks. 31 */ 32public class SingleLineTransformationMethod 33extends ReplacementTransformationMethod { 34 private static char[] ORIGINAL = new char[] { '\n' }; 35 private static char[] REPLACEMENT = new char[] { ' ' }; 36 37 /** 38 * The character to be replaced is \n. 39 */ 40 protected char[] getOriginal() { 41 return ORIGINAL; 42 } 43 44 /** 45 * The character \n is replaced with is space. 46 */ 47 protected char[] getReplacement() { 48 return REPLACEMENT; 49 } 50 51 public static SingleLineTransformationMethod getInstance() { 52 if (sInstance != null) 53 return sInstance; 54 55 sInstance = new SingleLineTransformationMethod(); 56 return sInstance; 57 } 58 59 private static SingleLineTransformationMethod sInstance; 60} 61