• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
17 package com.android.internal.inputmethod;
18 
19 import android.annotation.Nullable;
20 import android.text.TextUtils;
21 import android.view.inputmethod.InputMethodInfo;
22 import android.view.inputmethod.InputMethodSubtype;
23 
24 import java.util.Objects;
25 
26 public class InputMethodSubtypeHandle {
27     private final String mInputMethodId;
28     private final int mSubtypeId;
29 
InputMethodSubtypeHandle(InputMethodInfo info, @Nullable InputMethodSubtype subtype)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 
InputMethodSubtypeHandle(String inputMethodId, int subtypeId)39     public InputMethodSubtypeHandle(String inputMethodId, int subtypeId) {
40         mInputMethodId = inputMethodId;
41         mSubtypeId = subtypeId;
42     }
43 
getInputMethodId()44     public String getInputMethodId() {
45         return mInputMethodId;
46     }
47 
getSubtypeId()48     public int getSubtypeId() {
49         return mSubtypeId;
50     }
51 
52     @Override
equals(Object o)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
hashCode()63     public int hashCode() {
64         return Objects.hashCode(mInputMethodId) * 31 + mSubtypeId;
65     }
66 
67     @Override
toString()68     public String toString() {
69         return "InputMethodSubtypeHandle{mInputMethodId=" + mInputMethodId
70             + ", mSubtypeId=" + mSubtypeId + "}";
71     }
72 }
73