• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
17 package com.android.inputmethod.latin;
18 
19 import android.content.Context;
20 import android.content.res.Resources;
21 
22 public class Flag {
23     public final String mName;
24     public final int mResource;
25     public final int mMask;
26     public final int mSource;
27 
28     private static final int SOURCE_CONFIG = 1;
29     private static final int SOURCE_EXTRAVALUE = 2;
30     private static final int SOURCE_PARAM = 3;
31 
Flag(int resourceId, int mask)32     public Flag(int resourceId, int mask) {
33         mName = null;
34         mResource = resourceId;
35         mSource = SOURCE_CONFIG;
36         mMask = mask;
37     }
38 
Flag(String name, int mask)39     public Flag(String name, int mask) {
40         mName = name;
41         mResource = 0;
42         mSource = SOURCE_EXTRAVALUE;
43         mMask = mask;
44     }
45 
Flag(int mask)46     public Flag(int mask) {
47         mName = null;
48         mResource = 0;
49         mSource = SOURCE_PARAM;
50         mMask = mask;
51     }
52 
53     // If context/switcher are null, set all related flags in flagArray to on.
initFlags(Flag[] flagArray, Context context, SubtypeSwitcher switcher)54     public static int initFlags(Flag[] flagArray, Context context, SubtypeSwitcher switcher) {
55         int flags = 0;
56         final Resources res = null == context ? null : context.getResources();
57         for (Flag entry : flagArray) {
58             switch (entry.mSource) {
59                 case Flag.SOURCE_CONFIG:
60                     if (res == null || res.getBoolean(entry.mResource))
61                         flags |= entry.mMask;
62                     break;
63                 case Flag.SOURCE_EXTRAVALUE:
64                     if (switcher == null ||
65                             switcher.currentSubtypeContainsExtraValueKey(entry.mName))
66                         flags |= entry.mMask;
67                     break;
68                 case Flag.SOURCE_PARAM:
69                     flags |= entry.mMask;
70                     break;
71             }
72         }
73         return flags;
74     }
75 }
76