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 com.android.inputmethod.latin;
18
19import android.util.Log;
20
21public class ComposingStateManager {
22    private static final String TAG = ComposingStateManager.class.getSimpleName();
23    private static final ComposingStateManager sInstance = new ComposingStateManager();
24    private boolean mAutoCorrectionIndicatorOn;
25    private boolean mIsComposing;
26
27    public static ComposingStateManager getInstance() {
28        return sInstance;
29    }
30
31    private ComposingStateManager() {
32        mAutoCorrectionIndicatorOn = false;
33        mIsComposing = false;
34    }
35
36    public synchronized void onStartComposingText() {
37        if (!mIsComposing) {
38            if (LatinImeLogger.sDBG) {
39                Log.i(TAG, "Start composing text.");
40            }
41            mAutoCorrectionIndicatorOn = false;
42            mIsComposing = true;
43        }
44    }
45
46    public synchronized void onFinishComposingText() {
47        if (mIsComposing) {
48            if (LatinImeLogger.sDBG) {
49                Log.i(TAG, "Finish composing text.");
50            }
51            mAutoCorrectionIndicatorOn = false;
52            mIsComposing = false;
53        }
54    }
55
56    public synchronized boolean isAutoCorrectionIndicatorOn() {
57        return mAutoCorrectionIndicatorOn;
58    }
59
60    public synchronized void setAutoCorrectionIndicatorOn(boolean on) {
61        // Auto-correction indicator should be specified only when the current state is "composing".
62        if (!mIsComposing) return;
63        if (LatinImeLogger.sDBG) {
64            Log.i(TAG, "Set auto correction Indicator: " + on);
65        }
66        mAutoCorrectionIndicatorOn = on;
67    }
68}
69