1 /*
2  * Copyright (C) 2011 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.settings.inputmethod;
18 
19 import android.app.settings.SettingsEnums;
20 import android.content.Context;
21 import android.content.Intent;
22 import android.os.Bundle;
23 import android.provider.SearchIndexableResource;
24 
25 import com.android.settings.R;
26 import com.android.settings.dashboard.DashboardFragment;
27 import com.android.settings.search.BaseSearchIndexProvider;
28 import com.android.settings.search.Indexable;
29 import com.android.settingslib.search.SearchIndexable;
30 
31 import java.util.ArrayList;
32 import java.util.List;
33 
34 @SearchIndexable
35 public class UserDictionaryList extends DashboardFragment {
36 
37     private static final String TAG = "UserDictionaryList";
38 
39     @Override
getMetricsCategory()40     public int getMetricsCategory() {
41         return SettingsEnums.INPUTMETHOD_USER_DICTIONARY;
42     }
43 
44     @Override
onAttach(Context context)45     public void onAttach(Context context) {
46         super.onAttach(context);
47 
48         final Intent intent = getActivity().getIntent();
49         final String localeFromIntent =
50                 null == intent ? null : intent.getStringExtra("locale");
51 
52         final Bundle arguments = getArguments();
53         final String localeFromArguments =
54                 null == arguments ? null : arguments.getString("locale");
55 
56         final String locale;
57         if (null != localeFromArguments) {
58             locale = localeFromArguments;
59         } else if (null != localeFromIntent) {
60             locale = localeFromIntent;
61         } else {
62             locale = null;
63         }
64 
65         use(UserDictionaryListPreferenceController.class).setLocale(locale);
66     }
67 
68     @Override
getPreferenceScreenResId()69     protected int getPreferenceScreenResId() {
70         return R.xml.user_dictionary_list_fragment;
71     }
72 
73     @Override
getLogTag()74     protected String getLogTag() {
75         return TAG;
76     }
77 
78     public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
79             new BaseSearchIndexProvider() {
80                 @Override
81                 public List<SearchIndexableResource> getXmlResourcesToIndex(Context context,
82                         boolean enabled) {
83                     final ArrayList<SearchIndexableResource> result = new ArrayList<>();
84 
85                     final SearchIndexableResource sir = new SearchIndexableResource(context);
86                     sir.xmlResId = R.xml.user_dictionary_list_fragment;
87                     result.add(sir);
88                     return result;
89                 }
90             };
91 }
92