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, and causes
31 * carriage return characters (\r) to have no appearance.
32 */
33public class SingleLineTransformationMethod
34extends ReplacementTransformationMethod {
35    private static char[] ORIGINAL = new char[] { '\n', '\r' };
36    private static char[] REPLACEMENT = new char[] { ' ', '\uFEFF' };
37
38    /**
39     * The characters to be replaced are \n and \r.
40     */
41    protected char[] getOriginal() {
42        return ORIGINAL;
43    }
44
45    /**
46     * The character \n is replaced with is space;
47     * the character \r is replaced with is FEFF (zero width space).
48     */
49    protected char[] getReplacement() {
50        return REPLACEMENT;
51    }
52
53    public static SingleLineTransformationMethod getInstance() {
54        if (sInstance != null)
55            return sInstance;
56
57        sInstance = new SingleLineTransformationMethod();
58        return sInstance;
59    }
60
61    private static SingleLineTransformationMethod sInstance;
62}
63