• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2019 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.flashlight;
18 
19 import android.app.Activity;
20 import android.content.Context;
21 import android.content.Intent;
22 import android.os.Bundle;
23 import android.provider.Settings;
24 
25 import com.android.settings.R;
26 import com.android.settings.search.BaseSearchIndexProvider;
27 import com.android.settings.search.Indexable;
28 import com.android.settings.search.SearchIndexableRaw;
29 import com.android.settingslib.search.SearchIndexable;
30 
31 import java.util.ArrayList;
32 import java.util.List;
33 
34 /**
35  * Headless activity that toggles flashlight state when launched.
36  */
37 @SearchIndexable(forTarget = SearchIndexable.MOBILE)
38 public class FlashlightHandleActivity extends Activity implements Indexable {
39 
40     public static final String EXTRA_FALLBACK_TO_HOMEPAGE = "fallback_to_homepage";
41 
42     @Override
onCreate(Bundle savedInstanceState)43     protected void onCreate(Bundle savedInstanceState) {
44         super.onCreate(savedInstanceState);
45         // Do nothing meaningful in this activity.
46         // The sole purpose of this activity is to provide a place to index flashlight
47         // into Settings search.
48 
49         // Caller's choice: fallback to homepage, or just exit?
50         if (getIntent().getBooleanExtra(EXTRA_FALLBACK_TO_HOMEPAGE, false)) {
51             startActivity(new Intent(Settings.ACTION_SETTINGS));
52         }
53         finish();
54     }
55 
56     public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
57             new BaseSearchIndexProvider() {
58 
59                 @Override
60                 public List<SearchIndexableRaw> getRawDataToIndex(Context context,
61                         boolean enabled) {
62 
63                     final List<SearchIndexableRaw> result = new ArrayList<>();
64 
65                     SearchIndexableRaw data = new SearchIndexableRaw(context);
66                     data.title = context.getString(R.string.power_flashlight);
67                     data.screenTitle = context.getString(R.string.power_flashlight);
68                     data.keywords = context.getString(R.string.keywords_flashlight);
69                     data.intentTargetPackage = context.getPackageName();
70                     data.intentTargetClass = FlashlightHandleActivity.class.getName();
71                     data.intentAction = Intent.ACTION_MAIN;
72                     data.key = "flashlight";
73                     result.add(data);
74 
75                     return result;
76                 }
77             };
78 }
79