• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017 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.car.settings.common;
18 
19 import android.content.Context;
20 import android.content.Intent;
21 
22 import android.annotation.DrawableRes;
23 import android.annotation.StringRes;
24 import android.support.v7.widget.RecyclerView;
25 import android.view.LayoutInflater;
26 import android.view.View;
27 import android.view.ViewGroup;
28 
29 import com.android.car.settings.R;
30 
31 /**
32  * Represents the basic line item with Icon and text.
33  */
34 public class SimpleIconLineItem extends IconTextLineItem {
35     private final CharSequence mDesc;
36     private final Context mContext;
37     private final Class mActivityClass;
38 
SimpleIconLineItem( @tringRes int title, @DrawableRes int iconRes, Context context, CharSequence desc, Class activityClass)39     public SimpleIconLineItem(
40             @StringRes int title,
41             @DrawableRes int iconRes,
42             Context context,
43             CharSequence desc,
44             Class activityClass) {
45         super(context.getText(title), iconRes);
46         mDesc = desc;
47         mContext = context;
48         mActivityClass = activityClass;
49     }
50 
51     @Override
getType()52     public int getType() {
53         return SIMPLE_ICON_TEXT_TYPE;
54     }
55 
56     @Override
onClick()57     public void onClick() {
58         Intent intent = new Intent(mContext, mActivityClass);
59         mContext.startActivity(intent);
60     }
61 
62     @Override
isEnabled()63     public boolean isEnabled() {
64         return true;
65     }
66 
67     @Override
getDesc()68     public CharSequence getDesc() {
69         return mDesc;
70     }
71 
createViewHolder(ViewGroup parent)72     public static RecyclerView.ViewHolder createViewHolder(ViewGroup parent) {
73         View v = LayoutInflater.from(parent.getContext())
74                 .inflate(R.layout.tile_item, parent, false);
75         return new ViewHolder(v);
76     }
77 }
78