1 /* 2 * Copyright (C) 2016 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.dvr.ui.browse; 18 19 import android.app.Activity; 20 import android.os.Bundle; 21 import android.support.v17.leanback.app.DetailsFragment; 22 23 import android.transition.Transition; 24 import android.transition.Transition.TransitionListener; 25 import android.view.View; 26 import com.android.tv.R; 27 import com.android.tv.TvApplication; 28 import com.android.tv.dialog.PinDialogFragment; 29 30 /** 31 * Activity to show details view in DVR. 32 */ 33 public class DvrDetailsActivity extends Activity implements PinDialogFragment.OnPinCheckedListener { 34 /** 35 * Name of record id added to the Intent. 36 */ 37 public static final String RECORDING_ID = "record_id"; 38 39 /** 40 * Name of flag added to the Intent to determine if details view should hide "View schedule" 41 * button. 42 */ 43 public static final String HIDE_VIEW_SCHEDULE = "hide_view_schedule"; 44 45 /** 46 * Name of details view's type added to the intent. 47 */ 48 public static final String DETAILS_VIEW_TYPE = "details_view_type"; 49 50 /** 51 * Name of shared element between activities. 52 */ 53 public static final String SHARED_ELEMENT_NAME = "shared_element"; 54 55 /** 56 * CURRENT_RECORDING_VIEW refers to Current Recordings in DVR. 57 */ 58 public static final int CURRENT_RECORDING_VIEW = 1; 59 60 /** 61 * SCHEDULED_RECORDING_VIEW refers to Scheduled Recordings in DVR. 62 */ 63 public static final int SCHEDULED_RECORDING_VIEW = 2; 64 65 /** 66 * RECORDED_PROGRAM_VIEW refers to Recorded programs in DVR. 67 */ 68 public static final int RECORDED_PROGRAM_VIEW = 3; 69 70 /** 71 * SERIES_RECORDING_VIEW refers to series recording in DVR. 72 */ 73 public static final int SERIES_RECORDING_VIEW = 4; 74 75 private PinDialogFragment.OnPinCheckedListener mOnPinCheckedListener; 76 77 @Override 78 public void onCreate(Bundle savedInstanceState) { 79 TvApplication.setCurrentRunningProcess(this, true); 80 super.onCreate(savedInstanceState); 81 setContentView(R.layout.activity_dvr_details); 82 long recordId = getIntent().getLongExtra(RECORDING_ID, -1); 83 int detailsViewType = getIntent().getIntExtra(DETAILS_VIEW_TYPE, -1); 84 boolean hideViewSchedule = getIntent().getBooleanExtra(HIDE_VIEW_SCHEDULE, false); 85 if (recordId != -1 && detailsViewType != -1 && savedInstanceState == null) { 86 Bundle args = new Bundle(); 87 args.putLong(RECORDING_ID, recordId); 88 DetailsFragment detailsFragment = null; 89 if (detailsViewType == CURRENT_RECORDING_VIEW) { 90 detailsFragment = new CurrentRecordingDetailsFragment(); 91 } else if (detailsViewType == SCHEDULED_RECORDING_VIEW) { 92 args.putBoolean(HIDE_VIEW_SCHEDULE, hideViewSchedule); 93 detailsFragment = new ScheduledRecordingDetailsFragment(); 94 } else if (detailsViewType == RECORDED_PROGRAM_VIEW) { 95 detailsFragment = new RecordedProgramDetailsFragment(); 96 } else if (detailsViewType == SERIES_RECORDING_VIEW) { 97 detailsFragment = new SeriesRecordingDetailsFragment(); 98 } 99 detailsFragment.setArguments(args); 100 getFragmentManager().beginTransaction() 101 .replace(R.id.dvr_details_view_frame, detailsFragment).commit(); 102 } 103 104 // This is a workaround for the focus on O device 105 addTransitionListener(); 106 } 107 108 @Override 109 public void onPinChecked(boolean checked, int type, String rating) { 110 if (mOnPinCheckedListener != null) { 111 mOnPinCheckedListener.onPinChecked(checked, type, rating); 112 } 113 } 114 115 void setOnPinCheckListener(PinDialogFragment.OnPinCheckedListener listener) { 116 mOnPinCheckedListener = listener; 117 } 118 119 private void addTransitionListener() { 120 getWindow() 121 .getSharedElementEnterTransition() 122 .addListener( 123 new TransitionListener() { 124 @Override 125 public void onTransitionStart(Transition transition) { 126 // Do nothing 127 } 128 129 @Override 130 public void onTransitionEnd(Transition transition) { 131 View actions = findViewById(R.id.details_overview_actions); 132 if (actions != null) { 133 actions.requestFocus(); 134 } 135 } 136 137 @Override 138 public void onTransitionCancel(Transition transition) { 139 // Do nothing 140 141 } 142 143 @Override 144 public void onTransitionPause(Transition transition) { 145 // Do nothing 146 } 147 148 @Override 149 public void onTransitionResume(Transition transition) { 150 // Do nothing 151 } 152 }); 153 } 154 } 155