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