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