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