1/*
2 * Copyright (C) 2016 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 com.android.internal.inputmethod;
18
19import android.annotation.Nullable;
20import android.text.TextUtils;
21import android.view.inputmethod.InputMethodInfo;
22import android.view.inputmethod.InputMethodSubtype;
23
24import java.util.Objects;
25
26public class InputMethodSubtypeHandle {
27    private final String mInputMethodId;
28    private final int mSubtypeId;
29
30    public InputMethodSubtypeHandle(InputMethodInfo info, @Nullable InputMethodSubtype subtype) {
31        mInputMethodId = info.getId();
32        if (subtype != null) {
33            mSubtypeId = subtype.hashCode();
34        } else {
35            mSubtypeId = InputMethodUtils.NOT_A_SUBTYPE_ID;
36        }
37    }
38
39    public InputMethodSubtypeHandle(String inputMethodId, int subtypeId) {
40        mInputMethodId = inputMethodId;
41        mSubtypeId = subtypeId;
42    }
43
44    public String getInputMethodId() {
45        return mInputMethodId;
46    }
47
48    public int getSubtypeId() {
49        return mSubtypeId;
50    }
51
52    @Override
53    public boolean equals(Object o) {
54        if (o == null || !(o instanceof InputMethodSubtypeHandle)) {
55            return false;
56        }
57        InputMethodSubtypeHandle other = (InputMethodSubtypeHandle) o;
58        return TextUtils.equals(mInputMethodId, other.getInputMethodId())
59                && mSubtypeId == other.getSubtypeId();
60    }
61
62    @Override
63    public int hashCode() {
64        return Objects.hashCode(mInputMethodId) * 31 + mSubtypeId;
65    }
66
67    @Override
68    public String toString() {
69        return "InputMethodSubtypeHandle{mInputMethodId=" + mInputMethodId
70            + ", mSubtypeId=" + mSubtypeId + "}";
71    }
72}
73