• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 package com.android.settings.support;
17 
18 import android.app.Activity;
19 import android.content.Context;
20 import android.content.Intent;
21 import android.os.Bundle;
22 
23 import com.android.settings.R;
24 import com.android.settings.overlay.FeatureFactory;
25 import com.android.settings.overlay.SupportFeatureProvider;
26 import com.android.settings.search.BaseSearchIndexProvider;
27 import com.android.settingslib.search.Indexable;
28 import com.android.settingslib.search.SearchIndexable;
29 import com.android.settingslib.search.SearchIndexableRaw;
30 
31 import java.util.ArrayList;
32 import java.util.List;
33 
34 /**
35  * Trampoline activity that decides which version of support should be shown to the user.
36  */
37 @SearchIndexable
38 public class SupportDashboardActivity extends Activity implements Indexable {
39 
40     @Override
onCreate(Bundle savedInstanceState)41     protected void onCreate(Bundle savedInstanceState) {
42         super.onCreate(savedInstanceState);
43         SupportFeatureProvider supportFeatureProvider = FeatureFactory.getFactory(this)
44                 .getSupportFeatureProvider(this);
45 
46         // try to launch support if we have the feature provider
47         if (supportFeatureProvider != null) {
48             supportFeatureProvider.startSupport(this);
49             finish();
50         }
51     }
52 
53     /**
54      * For Search.
55      */
56     public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
57             new BaseSearchIndexProvider() {
58                 private static final String SUPPORT_SEARCH_INDEX_KEY = "support_dashboard_activity";
59 
60                 @Override
61                 public List<SearchIndexableRaw> getRawDataToIndex(Context context,
62                         boolean enabled) {
63 
64                     final List<SearchIndexableRaw> result = new ArrayList<>();
65 
66                     // Add the activity title
67                     SearchIndexableRaw data = new SearchIndexableRaw(context);
68                     data.title = context.getString(R.string.page_tab_title_support);
69                     data.screenTitle = context.getString(R.string.page_tab_title_support);
70                     data.summaryOn = context.getString(R.string.support_summary);
71                     data.intentTargetPackage = context.getPackageName();
72                     data.intentTargetClass = SupportDashboardActivity.class.getName();
73                     data.intentAction = Intent.ACTION_MAIN;
74                     data.key = SUPPORT_SEARCH_INDEX_KEY;
75                     result.add(data);
76 
77                     return result;
78                 }
79 
80                 @Override
81                 public List<String> getNonIndexableKeys(Context context) {
82                     final List<String> keys = super.getNonIndexableKeys(context);
83                     if (!context.getResources().getBoolean(R.bool.config_support_enabled)) {
84                         keys.add(SUPPORT_SEARCH_INDEX_KEY);
85                     }
86                     return keys;
87                 }
88             };
89 }
90