1/*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 * use this file except in compliance with the License. You may obtain a copy of
6 * 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, WITHOUT
12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 * License for the specific language governing permissions and limitations under
14 * the License.
15 */
16
17package android.view.textservice;
18
19import android.os.Parcel;
20import android.os.Parcelable;
21import android.text.TextUtils;
22
23/**
24 * This class contains a metadata of the input of TextService
25 */
26public final class TextInfo implements Parcelable {
27    private final String mText;
28    private final int mCookie;
29    private final int mSequence;
30
31    /**
32     * Constructor.
33     * @param text the text which will be input to TextService
34     */
35    public TextInfo(String text) {
36        this(text, 0, 0);
37    }
38
39    /**
40     * Constructor.
41     * @param text the text which will be input to TextService
42     * @param cookie the cookie for this TextInfo
43     * @param sequence the sequence number for this TextInfo
44     */
45    public TextInfo(String text, int cookie, int sequence) {
46        if (TextUtils.isEmpty(text)) {
47            throw new IllegalArgumentException(text);
48        }
49        mText = text;
50        mCookie = cookie;
51        mSequence = sequence;
52    }
53
54    public TextInfo(Parcel source) {
55        mText = source.readString();
56        mCookie = source.readInt();
57        mSequence = source.readInt();
58    }
59
60    /**
61     * Used to package this object into a {@link Parcel}.
62     *
63     * @param dest The {@link Parcel} to be written.
64     * @param flags The flags used for parceling.
65     */
66    @Override
67    public void writeToParcel(Parcel dest, int flags) {
68        dest.writeString(mText);
69        dest.writeInt(mCookie);
70        dest.writeInt(mSequence);
71    }
72
73    /**
74     * @return the text which is an input of a text service
75     */
76    public String getText() {
77        return mText;
78    }
79
80    /**
81     * @return the cookie of TextInfo
82     */
83    public int getCookie() {
84        return mCookie;
85    }
86
87    /**
88     * @return the sequence of TextInfo
89     */
90    public int getSequence() {
91        return mSequence;
92    }
93
94    /**
95     * Used to make this class parcelable.
96     */
97    public static final Parcelable.Creator<TextInfo> CREATOR
98            = new Parcelable.Creator<TextInfo>() {
99        @Override
100        public TextInfo createFromParcel(Parcel source) {
101            return new TextInfo(source);
102        }
103
104        @Override
105        public TextInfo[] newArray(int size) {
106            return new TextInfo[size];
107        }
108    };
109
110    /**
111     * Used to make this class parcelable.
112     */
113    @Override
114    public int describeContents() {
115        return 0;
116    }
117}
118