Abodunrinwa Toki | f001fef | 2017-01-04 23:51:42 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 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 android.view.textclassifier; |
| 18 | |
Abodunrinwa Toki | df61b03 | 2017-03-29 22:41:57 +0100 | [diff] [blame] | 19 | import android.annotation.Nullable; |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 20 | import android.annotation.SystemService; |
Abodunrinwa Toki | f001fef | 2017-01-04 23:51:42 +0000 | [diff] [blame] | 21 | import android.content.Context; |
| 22 | |
Abodunrinwa Toki | 43e0350 | 2017-01-13 13:46:33 -0800 | [diff] [blame] | 23 | import com.android.internal.util.Preconditions; |
| 24 | |
Abodunrinwa Toki | f001fef | 2017-01-04 23:51:42 +0000 | [diff] [blame] | 25 | /** |
| 26 | * Interface to the text classification service. |
Abodunrinwa Toki | f001fef | 2017-01-04 23:51:42 +0000 | [diff] [blame] | 27 | */ |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 28 | @SystemService(Context.TEXT_CLASSIFICATION_SERVICE) |
Abodunrinwa Toki | f001fef | 2017-01-04 23:51:42 +0000 | [diff] [blame] | 29 | public final class TextClassificationManager { |
| 30 | |
Abodunrinwa Toki | b89cf02 | 2017-02-06 19:53:22 +0000 | [diff] [blame] | 31 | private final Object mTextClassifierLock = new Object(); |
Abodunrinwa Toki | b89cf02 | 2017-02-06 19:53:22 +0000 | [diff] [blame] | 32 | |
Abodunrinwa Toki | 43e0350 | 2017-01-13 13:46:33 -0800 | [diff] [blame] | 33 | private final Context mContext; |
Abodunrinwa Toki | df61b03 | 2017-03-29 22:41:57 +0100 | [diff] [blame] | 34 | private TextClassifier mTextClassifier; |
Abodunrinwa Toki | 43e0350 | 2017-01-13 13:46:33 -0800 | [diff] [blame] | 35 | |
Abodunrinwa Toki | f001fef | 2017-01-04 23:51:42 +0000 | [diff] [blame] | 36 | /** @hide */ |
Abodunrinwa Toki | 43e0350 | 2017-01-13 13:46:33 -0800 | [diff] [blame] | 37 | public TextClassificationManager(Context context) { |
| 38 | mContext = Preconditions.checkNotNull(context); |
| 39 | } |
Abodunrinwa Toki | f001fef | 2017-01-04 23:51:42 +0000 | [diff] [blame] | 40 | |
Abodunrinwa Toki | df61b03 | 2017-03-29 22:41:57 +0100 | [diff] [blame] | 41 | /** |
| 42 | * Returns the text classifier. |
| 43 | */ |
| 44 | public TextClassifier getTextClassifier() { |
Abodunrinwa Toki | b89cf02 | 2017-02-06 19:53:22 +0000 | [diff] [blame] | 45 | synchronized (mTextClassifierLock) { |
Abodunrinwa Toki | df61b03 | 2017-03-29 22:41:57 +0100 | [diff] [blame] | 46 | if (mTextClassifier == null) { |
| 47 | mTextClassifier = new TextClassifierImpl(mContext); |
Abodunrinwa Toki | 43e0350 | 2017-01-13 13:46:33 -0800 | [diff] [blame] | 48 | } |
Abodunrinwa Toki | df61b03 | 2017-03-29 22:41:57 +0100 | [diff] [blame] | 49 | return mTextClassifier; |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | /** |
| 54 | * Sets the text classifier. |
| 55 | * Set to null to use the system default text classifier. |
| 56 | * Set to {@link TextClassifier#NO_OP} to disable text classifier features. |
| 57 | */ |
| 58 | public void setTextClassifier(@Nullable TextClassifier textClassifier) { |
| 59 | synchronized (mTextClassifierLock) { |
| 60 | mTextClassifier = textClassifier; |
Abodunrinwa Toki | 43e0350 | 2017-01-13 13:46:33 -0800 | [diff] [blame] | 61 | } |
Abodunrinwa Toki | f001fef | 2017-01-04 23:51:42 +0000 | [diff] [blame] | 62 | } |
Abodunrinwa Toki | f001fef | 2017-01-04 23:51:42 +0000 | [diff] [blame] | 63 | } |