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.DialogFragment;
     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.VerticalGridView;
     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.TvApplication;
     32 import com.android.tv.dialog.SafeDismissDialogFragment;
     33 import com.android.tv.dvr.DvrManager;
     34 import com.android.tv.dvr.ui.HalfSizedDialogFragment.OnActionClickListener;
     35 
     36 public class DvrGuidedStepFragment extends GuidedStepFragment {
     37     private DvrManager mDvrManager;
     38     private OnActionClickListener mOnActionClickListener;
     39 
     40     protected DvrManager getDvrManager() {
     41         return mDvrManager;
     42     }
     43 
     44     @Override
     45     public void onAttach(Context context) {
     46         super.onAttach(context);
     47         mDvrManager = TvApplication.getSingletons(context).getDvrManager();
     48     }
     49 
     50     @Override
     51     public View onCreateView(LayoutInflater inflater, ViewGroup container,
     52             Bundle savedInstanceState) {
     53         View view = super.onCreateView(inflater, container, savedInstanceState);
     54         VerticalGridView actionsList = getGuidedActionsStylist().getActionsGridView();
     55         actionsList.setWindowAlignment(VerticalGridView.WINDOW_ALIGN_BOTH_EDGE);
     56         VerticalGridView buttonActionsList = getGuidedButtonActionsStylist().getActionsGridView();
     57         buttonActionsList.setWindowAlignment(VerticalGridView.WINDOW_ALIGN_BOTH_EDGE);
     58         return view;
     59     }
     60 
     61     @Override
     62     public int onProvideTheme() {
     63         return R.style.Theme_TV_Dvr_GuidedStep;
     64     }
     65 
     66     @Override
     67     public void onGuidedActionClicked(GuidedAction action) {
     68         if (mOnActionClickListener != null) {
     69             mOnActionClickListener.onActionClick(action.getId());
     70         }
     71         dismissDialog();
     72     }
     73 
     74     protected void dismissDialog() {
     75         if (getActivity() instanceof MainActivity) {
     76             SafeDismissDialogFragment currentDialog =
     77                     ((MainActivity) getActivity()).getOverlayManager().getCurrentDialog();
     78             if (currentDialog instanceof DvrHalfSizedDialogFragment) {
     79                 currentDialog.dismiss();
     80             }
     81         } else if (getParentFragment() instanceof DialogFragment) {
     82             ((DialogFragment) getParentFragment()).dismiss();
     83         }
     84     }
     85 
     86     protected void setOnActionClickListener(OnActionClickListener listener) {
     87         mOnActionClickListener = listener;
     88     }
     89 }