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.playback; 18 19 import android.app.Activity; 20 import android.content.ContentUris; 21 import android.content.Intent; 22 import android.content.res.Configuration; 23 import android.net.Uri; 24 import android.os.Bundle; 25 import android.util.Log; 26 27 import com.android.tv.R; 28 import com.android.tv.TvApplication; 29 import com.android.tv.dialog.PinDialogFragment.OnPinCheckedListener; 30 import com.android.tv.dvr.data.RecordedProgram; 31 import com.android.tv.util.Utils; 32 33 /** 34 * Activity to play a {@link RecordedProgram}. 35 */ 36 public class DvrPlaybackActivity extends Activity implements OnPinCheckedListener { 37 private static final String TAG = "DvrPlaybackActivity"; 38 private static final boolean DEBUG = false; 39 40 private DvrPlaybackOverlayFragment mOverlayFragment; 41 private OnPinCheckedListener mOnPinCheckedListener; 42 43 @Override 44 public void onCreate(Bundle savedInstanceState) { 45 TvApplication.setCurrentRunningProcess(this, true); 46 if (DEBUG) Log.d(TAG, "onCreate"); 47 super.onCreate(savedInstanceState); 48 setIntent(createProgramIntent(getIntent())); 49 setContentView(R.layout.activity_dvr_playback); 50 mOverlayFragment = (DvrPlaybackOverlayFragment) getFragmentManager() 51 .findFragmentById(R.id.dvr_playback_controls_fragment); 52 } 53 54 @Override 55 public void onVisibleBehindCanceled() { 56 if (DEBUG) Log.d(TAG, "onVisibleBehindCanceled"); 57 super.onVisibleBehindCanceled(); 58 finish(); 59 } 60 61 @Override 62 protected void onNewIntent(Intent intent) { 63 setIntent(createProgramIntent(intent)); 64 mOverlayFragment.onNewIntent(createProgramIntent(intent)); 65 } 66 67 @Override 68 public void onConfigurationChanged(Configuration newConfig) { 69 super.onConfigurationChanged(newConfig); 70 float density = getResources().getDisplayMetrics().density; 71 mOverlayFragment.onWindowSizeChanged((int) (newConfig.screenWidthDp * density), 72 (int) (newConfig.screenHeightDp * density)); 73 } 74 75 private Intent createProgramIntent(Intent intent) { 76 if (Intent.ACTION_VIEW.equals(intent.getAction())) { 77 Uri uri = intent.getData(); 78 long recordedProgramId = ContentUris.parseId(uri); 79 intent.putExtra(Utils.EXTRA_KEY_RECORDED_PROGRAM_ID, recordedProgramId); 80 } 81 return intent; 82 } 83 84 @Override 85 public void onPinChecked(boolean checked, int type, String rating) { 86 if (mOnPinCheckedListener != null) { 87 mOnPinCheckedListener.onPinChecked(checked, type, rating); 88 } 89 } 90 91 void setOnPinCheckListener(OnPinCheckedListener listener) { 92 mOnPinCheckedListener = listener; 93 } 94 }