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