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