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.ui;
     18 
     19 import android.content.Context;
     20 import android.support.v17.leanback.app.GuidedStepFragment;
     21 import android.support.v17.leanback.widget.GuidedAction;
     22 import android.support.v17.leanback.widget.GuidedActionsStylist;
     23 
     24 import com.android.tv.R;
     25 
     26 /**
     27  * Extended stylist class used for {@link GuidedStepFragment} with divider support.
     28  */
     29 public class GuidedActionsStylistWithDivider extends GuidedActionsStylist {
     30     /**
     31      * ID used mark a divider.
     32      */
     33     public static final int ACTION_DIVIDER = -100;
     34     private static final int VIEW_TYPE_DIVIDER = 1;
     35 
     36     @Override
     37     public int getItemViewType(GuidedAction action) {
     38         if (action.getId() == ACTION_DIVIDER) {
     39             return VIEW_TYPE_DIVIDER;
     40         }
     41         return super.getItemViewType(action);
     42     }
     43 
     44     @Override
     45     public int onProvideItemLayoutId(int viewType) {
     46         if (viewType == VIEW_TYPE_DIVIDER) {
     47             return R.layout.guided_action_divider;
     48         }
     49         return super.onProvideItemLayoutId(viewType);
     50     }
     51 
     52     /**
     53      * Creates a divider for {@link GuidedStepFragment}, targeted fragments must use
     54      * {@link GuidedActionsStylistWithDivider} as its actions' stylist for divider to work.
     55      */
     56     public static GuidedAction createDividerAction(Context context) {
     57         return new GuidedAction.Builder(context)
     58                 .id(ACTION_DIVIDER)
     59                 .title(null)
     60                 .description(null)
     61                 .focusable(false)
     62                 .infoOnly(true)
     63                 .build();
     64     }
     65 }
     66