Home | History | Annotate | Download | only in ui
      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;
     18 
     19 import android.app.Activity;
     20 import android.content.Context;
     21 import android.os.Bundle;
     22 import android.support.v17.leanback.app.GuidedStepFragment;
     23 import android.support.v17.leanback.widget.GuidedAction;
     24 import android.support.v17.leanback.widget.GuidanceStylist.Guidance;
     25 import android.view.LayoutInflater;
     26 import android.view.View;
     27 import android.view.ViewGroup;
     28 
     29 import com.android.tv.MainActivity;
     30 import com.android.tv.R;
     31 import com.android.tv.dvr.DvrStorageStatusManager;
     32 import com.android.tv.dialog.HalfSizedDialogFragment;
     33 import com.android.tv.dvr.ui.DvrConflictFragment.DvrChannelWatchConflictFragment;
     34 import com.android.tv.dvr.ui.DvrConflictFragment.DvrProgramConflictFragment;
     35 import com.android.tv.guide.ProgramGuide;
     36 
     37 import java.util.List;
     38 
     39 public class DvrHalfSizedDialogFragment extends HalfSizedDialogFragment {
     40     /**
     41      * Key for input ID.
     42      * Type: String.
     43      */
     44     public static final String KEY_INPUT_ID = "DvrHalfSizedDialogFragment.input_id";
     45     /**
     46      * Key for the program.
     47      * Type: {@link com.android.tv.data.Program}.
     48      */
     49     public static final String KEY_PROGRAM = "DvrHalfSizedDialogFragment.program";
     50     /**
     51      * Key for the channel ID.
     52      * Type: long.
     53      */
     54     public static final String KEY_CHANNEL_ID = "DvrHalfSizedDialogFragment.channel_id";
     55     /**
     56      * Key for the recording start time in millisecond.
     57      * Type: long.
     58      */
     59     public static final String KEY_START_TIME_MS = "DvrHalfSizedDialogFragment.start_time_ms";
     60     /**
     61      * Key for the recording end time in millisecond.
     62      * Type: long.
     63      */
     64     public static final String KEY_END_TIME_MS = "DvrHalfSizedDialogFragment.end_time_ms";
     65 
     66     @Override
     67     public void onAttach(Context context) {
     68         super.onAttach(context);
     69         Activity activity = getActivity();
     70         if (activity instanceof MainActivity) {
     71             ProgramGuide programGuide =
     72                     ((MainActivity) activity).getOverlayManager().getProgramGuide();
     73             if (programGuide != null && programGuide.isActive()) {
     74                 programGuide.cancelHide();
     75             }
     76         }
     77     }
     78 
     79     @Override
     80     public void onDetach() {
     81         super.onDetach();
     82         Activity activity = getActivity();
     83         if (activity instanceof MainActivity) {
     84             ProgramGuide programGuide =
     85                     ((MainActivity) activity).getOverlayManager().getProgramGuide();
     86             if (programGuide != null && programGuide.isActive()) {
     87                 programGuide.scheduleHide();
     88             }
     89         }
     90     }
     91 
     92     public abstract static class DvrGuidedStepDialogFragment extends DvrHalfSizedDialogFragment {
     93         private DvrGuidedStepFragment mFragment;
     94 
     95         @Override
     96         public View onCreateView(LayoutInflater inflater, ViewGroup container,
     97                 Bundle savedInstanceState) {
     98             View view = super.onCreateView(inflater, container, savedInstanceState);
     99             mFragment = onCreateGuidedStepFragment();
    100             mFragment.setArguments(getArguments());
    101             mFragment.setOnActionClickListener(getOnActionClickListener());
    102             GuidedStepFragment.add(getChildFragmentManager(),
    103                     mFragment, R.id.halfsized_dialog_host);
    104             return view;
    105         }
    106 
    107         @Override
    108         public void setOnActionClickListener(OnActionClickListener listener) {
    109             super.setOnActionClickListener(listener);
    110             if (mFragment != null) {
    111                 mFragment.setOnActionClickListener(listener);
    112             }
    113         }
    114 
    115         protected abstract DvrGuidedStepFragment onCreateGuidedStepFragment();
    116     }
    117 
    118     /** A dialog fragment for {@link DvrScheduleFragment}. */
    119     public static class DvrScheduleDialogFragment extends DvrGuidedStepDialogFragment {
    120         @Override
    121         protected DvrGuidedStepFragment onCreateGuidedStepFragment() {
    122             return new DvrScheduleFragment();
    123         }
    124     }
    125 
    126     /** A dialog fragment for {@link DvrProgramConflictFragment}. */
    127     public static class DvrProgramConflictDialogFragment extends DvrGuidedStepDialogFragment {
    128         @Override
    129         protected DvrGuidedStepFragment onCreateGuidedStepFragment() {
    130             return new DvrProgramConflictFragment();
    131         }
    132     }
    133 
    134     /** A dialog fragment for {@link DvrChannelWatchConflictFragment}. */
    135     public static class DvrChannelWatchConflictDialogFragment extends DvrGuidedStepDialogFragment {
    136         @Override
    137         protected DvrGuidedStepFragment onCreateGuidedStepFragment() {
    138             return new DvrChannelWatchConflictFragment();
    139         }
    140     }
    141 
    142     /** A dialog fragment for {@link DvrChannelRecordDurationOptionFragment}. */
    143     public static class DvrChannelRecordDurationOptionDialogFragment
    144             extends DvrGuidedStepDialogFragment {
    145         @Override
    146         protected DvrGuidedStepFragment onCreateGuidedStepFragment() {
    147             return new DvrChannelRecordDurationOptionFragment();
    148         }
    149     }
    150 
    151     /** A dialog fragment for {@link DvrInsufficientSpaceErrorFragment}. */
    152     public static class DvrInsufficientSpaceErrorDialogFragment
    153             extends DvrGuidedStepDialogFragment {
    154         @Override
    155         protected DvrGuidedStepFragment onCreateGuidedStepFragment() {
    156             return new DvrInsufficientSpaceErrorFragment();
    157         }
    158     }
    159 
    160     /** A dialog fragment for {@link DvrMissingStorageErrorFragment}. */
    161     public static class DvrMissingStorageErrorDialogFragment
    162             extends DvrGuidedStepDialogFragment {
    163         @Override
    164         protected DvrGuidedStepFragment onCreateGuidedStepFragment() {
    165             return new DvrMissingStorageErrorFragment();
    166         }
    167     }
    168 
    169     /**
    170      * A dialog fragment to show error message when there is no enough free space to record.
    171      */
    172     public static class DvrNoFreeSpaceErrorDialogFragment
    173             extends DvrGuidedStepDialogFragment {
    174         @Override
    175         protected DvrGuidedStepFragment onCreateGuidedStepFragment() {
    176             return new DvrGuidedStepFragment.DvrNoFreeSpaceErrorFragment();
    177         }
    178     }
    179 
    180     /**
    181      * A dialog fragment to show error message when the current storage is too small to
    182      * support DVR
    183      */
    184     public static class DvrSmallSizedStorageErrorDialogFragment
    185             extends DvrGuidedStepDialogFragment {
    186         @Override
    187         protected DvrGuidedStepFragment onCreateGuidedStepFragment() {
    188             return new DvrGuidedStepFragment.DvrSmallSizedStorageErrorFragment();
    189         }
    190     }
    191 
    192     /** A dialog fragment for {@link DvrStopRecordingFragment}. */
    193     public static class DvrStopRecordingDialogFragment extends DvrGuidedStepDialogFragment {
    194         @Override
    195         protected DvrGuidedStepFragment onCreateGuidedStepFragment() {
    196             return new DvrStopRecordingFragment();
    197         }
    198     }
    199 
    200     /** A dialog fragment for {@link DvrAlreadyScheduledFragment}. */
    201     public static class DvrAlreadyScheduledDialogFragment extends DvrGuidedStepDialogFragment {
    202         @Override
    203         protected DvrGuidedStepFragment onCreateGuidedStepFragment() {
    204             return new DvrAlreadyScheduledFragment();
    205         }
    206     }
    207 
    208     /** A dialog fragment for {@link DvrAlreadyRecordedFragment}. */
    209     public static class DvrAlreadyRecordedDialogFragment extends DvrGuidedStepDialogFragment {
    210         @Override
    211         protected DvrGuidedStepFragment onCreateGuidedStepFragment() {
    212             return new DvrAlreadyRecordedFragment();
    213         }
    214     }
    215 }