• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2014 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.settings.dashboard;
18 
19 import android.content.Context;
20 import android.util.AttributeSet;
21 import android.view.LayoutInflater;
22 import android.view.View;
23 import android.widget.FrameLayout;
24 
25 import android.widget.ImageView;
26 import android.widget.TextView;
27 import com.android.settings.R;
28 import com.android.settings.Utils;
29 
30 public class DashboardTileView extends FrameLayout implements View.OnClickListener {
31 
32     private static final int DEFAULT_COL_SPAN = 1;
33 
34     private ImageView mImageView;
35     private TextView mTitleTextView;
36     private TextView mStatusTextView;
37     private View mDivider;
38 
39     private int mColSpan = DEFAULT_COL_SPAN;
40 
41     private DashboardTile mTile;
42 
DashboardTileView(Context context)43     public DashboardTileView(Context context) {
44         this(context, null);
45     }
46 
DashboardTileView(Context context, AttributeSet attrs)47     public DashboardTileView(Context context, AttributeSet attrs) {
48         super(context, attrs);
49 
50         final View view = LayoutInflater.from(context).inflate(R.layout.dashboard_tile, this);
51 
52         mImageView = (ImageView) view.findViewById(R.id.icon);
53         mTitleTextView = (TextView) view.findViewById(R.id.title);
54         mStatusTextView = (TextView) view.findViewById(R.id.status);
55         mDivider = view.findViewById(R.id.tile_divider);
56 
57         setOnClickListener(this);
58         setBackgroundResource(R.drawable.dashboard_tile_background);
59         setFocusable(true);
60     }
61 
getTitleTextView()62     public TextView getTitleTextView() {
63         return mTitleTextView;
64     }
65 
getStatusTextView()66     public TextView getStatusTextView() {
67         return mStatusTextView;
68     }
69 
getImageView()70     public ImageView getImageView() {
71         return mImageView;
72     }
73 
setTile(DashboardTile tile)74     public void setTile(DashboardTile tile) {
75         mTile = tile;
76     }
77 
setDividerVisibility(boolean visible)78     public void setDividerVisibility(boolean visible) {
79         mDivider.setVisibility(visible ? View.VISIBLE : View.GONE);
80     }
81 
setColumnSpan(int span)82     void setColumnSpan(int span) {
83         mColSpan = span;
84     }
85 
getColumnSpan()86     int getColumnSpan() {
87         return mColSpan;
88     }
89 
90     @Override
onClick(View v)91     public void onClick(View v) {
92         if (mTile.fragment != null) {
93             Utils.startWithFragment(getContext(), mTile.fragment, mTile.fragmentArguments, null, 0,
94                     mTile.titleRes, mTile.getTitle(getResources()));
95         } else if (mTile.intent != null) {
96             getContext().startActivity(mTile.intent);
97         }
98     }
99 }
100