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 17package com.android.emergency; 18 19import android.database.Cursor; 20import android.database.MatrixCursor; 21import android.provider.SearchIndexablesContract.XmlResource; 22import android.provider.SearchIndexableResource; 23import android.provider.SearchIndexablesProvider; 24 25import com.android.emergency.edit.EditInfoActivity; 26import com.android.emergency.edit.EditMedicalInfoActivity; 27 28import static android.provider.SearchIndexablesContract.INDEXABLES_RAW_COLUMNS; 29import static android.provider.SearchIndexablesContract.INDEXABLES_XML_RES_COLUMNS; 30import static android.provider.SearchIndexablesContract.NON_INDEXABLES_KEYS_COLUMNS; 31 32public class EmergencySearchIndexablesProvider extends SearchIndexablesProvider { 33 private static final String TAG = "EmergencySearchIndexablesProvider"; 34 private static final int IGNORED_RANK = 2112; 35 private static final int NO_ICON_ID = 0; 36 37 private static SearchIndexableResource[] INDEXABLE_RES = new SearchIndexableResource[] { 38 new SearchIndexableResource(IGNORED_RANK, R.xml.edit_emergency_info, 39 EditInfoActivity.class.getName(), 40 NO_ICON_ID), 41 new SearchIndexableResource(IGNORED_RANK, R.xml.edit_medical_info, 42 EditMedicalInfoActivity.class.getName(), 43 NO_ICON_ID), 44 }; 45 46 @Override 47 public boolean onCreate() { 48 return true; 49 } 50 51 @Override 52 public Cursor queryXmlResources(String[] projection) { 53 MatrixCursor cursor = new MatrixCursor(INDEXABLES_XML_RES_COLUMNS); 54 for (int i = 0, length = INDEXABLE_RES.length; i < length; i++) { 55 cursor.newRow() 56 .add(XmlResource.COLUMN_RANK, INDEXABLE_RES[i].rank) 57 .add(XmlResource.COLUMN_XML_RESID, INDEXABLE_RES[i].xmlResId) 58 .add(XmlResource.COLUMN_CLASS_NAME, null) 59 .add(XmlResource.COLUMN_ICON_RESID, INDEXABLE_RES[i].iconResId) 60 .add(XmlResource.COLUMN_INTENT_ACTION, "android.intent.action.MAIN") 61 .add(XmlResource.COLUMN_INTENT_TARGET_PACKAGE, "com.android.emergency") 62 .add(XmlResource.COLUMN_INTENT_TARGET_CLASS, INDEXABLE_RES[i].className); 63 } 64 return cursor; 65 } 66 67 @Override 68 public Cursor queryRawData(String[] projection) { 69 MatrixCursor cursor = new MatrixCursor(INDEXABLES_RAW_COLUMNS); 70 return cursor; 71 } 72 73 @Override 74 public Cursor queryNonIndexableKeys(String[] projection) { 75 MatrixCursor cursor = new MatrixCursor(NON_INDEXABLES_KEYS_COLUMNS); 76 return cursor; 77 } 78} 79