1 /* 2 * Copyright (C) 2018 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.tv.search; 18 19 import android.content.Intent; 20 import android.media.tv.TvContract; 21 import android.media.tv.TvContract.Programs; 22 23 import com.android.tv.data.api.Program; 24 import com.android.tv.search.LocalSearchProvider.SearchResult; 25 26 import java.util.ArrayList; 27 import java.util.List; 28 29 /** Fake {@link SearchInterface} for testing. */ 30 public class FakeSearchInterface implements SearchInterface { 31 public final List<Program> mPrograms = new ArrayList<>(); 32 33 @Override search(String query, int limit, int action)34 public List<SearchResult> search(String query, int limit, int action) { 35 36 List<SearchResult> results = new ArrayList<>(); 37 for (Program program : mPrograms) { 38 if (program.getTitle().contains(query) || program.getDescription().contains(query)) { 39 results.add(fromProgram(program)); 40 } 41 } 42 return results; 43 } 44 fromProgram(Program program)45 public static SearchResult fromProgram(Program program) { 46 SearchResult.Builder result = SearchResult.builder(); 47 result.setTitle(program.getTitle()); 48 result.setDescription( 49 program.getStartTimeUtcMillis() + " - " + program.getEndTimeUtcMillis()); 50 result.setImageUri(program.getPosterArtUri()); 51 result.setIntentAction(Intent.ACTION_VIEW); 52 result.setIntentData(TvContract.buildChannelUri(program.getChannelId()).toString()); 53 result.setIntentExtraData(TvContract.buildProgramUri(program.getId()).toString()); 54 result.setContentType(Programs.CONTENT_ITEM_TYPE); 55 result.setIsLive(true); 56 result.setVideoWidth(program.getVideoWidth()); 57 result.setVideoHeight(program.getVideoHeight()); 58 result.setDuration(program.getDurationMillis()); 59 result.setChannelId(program.getChannelId()); 60 return result.build(); 61 } 62 } 63