• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2013 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.inputmethod.latin.common;
18 
19 public class NativeSuggestOptions {
20     // Need to update suggest_options.h when you add, remove or reorder options.
21     private static final int IS_GESTURE = 0;
22     private static final int USE_FULL_EDIT_DISTANCE = 1;
23     private static final int BLOCK_OFFENSIVE_WORDS = 2;
24     private static final int SPACE_AWARE_GESTURE_ENABLED = 3;
25     private static final int WEIGHT_FOR_LOCALE_IN_THOUSANDS = 4;
26     private static final int OPTIONS_SIZE = 5;
27 
28     private final int[] mOptions;
29 
NativeSuggestOptions()30     public NativeSuggestOptions() {
31         mOptions = new int[OPTIONS_SIZE];
32     }
33 
setIsGesture(final boolean value)34     public void setIsGesture(final boolean value) {
35         setBooleanOption(IS_GESTURE, value);
36     }
37 
setUseFullEditDistance(final boolean value)38     public void setUseFullEditDistance(final boolean value) {
39         setBooleanOption(USE_FULL_EDIT_DISTANCE, value);
40     }
41 
setBlockOffensiveWords(final boolean value)42     public void setBlockOffensiveWords(final boolean value) {
43         setBooleanOption(BLOCK_OFFENSIVE_WORDS, value);
44     }
45 
setWeightForLocale(final float value)46     public void setWeightForLocale(final float value) {
47         // We're passing this option as a fixed point value, in thousands. This is decoded in
48         // native code by SuggestOptions#weightForLocale().
49         setIntegerOption(WEIGHT_FOR_LOCALE_IN_THOUSANDS, (int) (value * 1000));
50     }
51 
getOptions()52     public int[] getOptions() {
53         return mOptions;
54     }
55 
setBooleanOption(final int key, final boolean value)56     private void setBooleanOption(final int key, final boolean value) {
57         mOptions[key] = value ? 1 : 0;
58     }
59 
setIntegerOption(final int key, final int value)60     private void setIntegerOption(final int key, final int value) {
61         mOptions[key] = value;
62     }
63 }
64