1 /* 2 * Copyright (C) 2015 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.testinput; 18 19 import android.app.Activity; 20 import android.app.AlertDialog; 21 import android.app.Dialog; 22 import android.app.DialogFragment; 23 import android.content.Context; 24 import android.content.DialogInterface; 25 import android.media.tv.TvInputInfo; 26 import android.os.Bundle; 27 import android.util.Log; 28 import com.android.tv.common.util.Clock; 29 import com.android.tv.testing.constants.Constants; 30 import com.android.tv.testing.data.ChannelInfo; 31 import com.android.tv.testing.data.ChannelUtils; 32 import com.android.tv.testing.data.ProgramUtils; 33 import java.util.List; 34 35 /** The setup activity for {@link TestTvInputService}. */ 36 public class TestTvInputSetupActivity extends Activity { 37 private static final String TAG = "TestTvInputSetup"; 38 private String mInputId; 39 40 @Override onCreate(Bundle savedInstanceState)41 public void onCreate(Bundle savedInstanceState) { 42 super.onCreate(savedInstanceState); 43 mInputId = getIntent().getStringExtra(TvInputInfo.EXTRA_INPUT_ID); 44 45 DialogFragment newFragment = new MyAlertDialogFragment(); 46 newFragment.show(getFragmentManager(), "dialog"); 47 } 48 registerChannels(int channelCount)49 private void registerChannels(int channelCount) { 50 TestTvInputSetupActivity context = this; 51 registerChannels(context, mInputId, channelCount); 52 } 53 registerChannels(Context context, String inputId, int channelCount)54 public static void registerChannels(Context context, String inputId, int channelCount) { 55 Log.i(TAG, "Registering " + channelCount + " channels"); 56 List<ChannelInfo> channels = ChannelUtils.createChannelInfos(context, channelCount); 57 ChannelUtils.updateChannels(context, inputId, channels); 58 ProgramUtils.updateProgramForAllChannelsOf( 59 context, inputId, Clock.SYSTEM, ProgramUtils.PROGRAM_INSERT_DURATION_MS); 60 } 61 62 public static class MyAlertDialogFragment extends DialogFragment { 63 @Override onCreateDialog(Bundle savedInstanceState)64 public Dialog onCreateDialog(Bundle savedInstanceState) { 65 return new AlertDialog.Builder(getActivity()) 66 .setTitle(R.string.simple_setup_title) 67 .setMessage(R.string.simple_setup_message) 68 .setPositiveButton( 69 android.R.string.ok, 70 new DialogInterface.OnClickListener() { 71 @Override 72 public void onClick(DialogInterface dialog, int whichButton) { 73 // TODO: add UI to ask how many channels 74 ((TestTvInputSetupActivity) getActivity()) 75 .registerChannels(Constants.UNIT_TEST_CHANNEL_COUNT); 76 // Sets the results so that the application can process the 77 // registered channels properly. 78 getActivity().setResult(Activity.RESULT_OK); 79 getActivity().finish(); 80 } 81 }) 82 .setNegativeButton( 83 android.R.string.cancel, 84 new DialogInterface.OnClickListener() { 85 @Override 86 public void onClick(DialogInterface dialog, int whichButton) { 87 getActivity().finish(); 88 } 89 }) 90 .create(); 91 } 92 } 93 } 94