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