• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2015 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.dialer.widget;
18 
19 import android.content.Context;
20 import android.content.res.ColorStateList;
21 import android.support.annotation.StringRes;
22 import android.util.AttributeSet;
23 import android.view.LayoutInflater;
24 import android.view.View;
25 import android.widget.ImageView;
26 import android.widget.LinearLayout;
27 import android.widget.TextView;
28 import com.android.dialer.theme.base.ThemeComponent;
29 
30 public class EmptyContentView extends LinearLayout implements View.OnClickListener {
31 
32   /** Listener to call when action button is clicked. */
33   public interface OnEmptyViewActionButtonClickedListener {
onEmptyViewActionButtonClicked()34     void onEmptyViewActionButtonClicked();
35   }
36 
37   public static final int NO_LABEL = 0;
38   public static final int NO_IMAGE = 0;
39 
40   private ImageView imageView;
41   private TextView descriptionView;
42   private TextView actionView;
43   private OnEmptyViewActionButtonClickedListener onActionButtonClickedListener;
44 
45   private @StringRes int actionLabel;
46 
EmptyContentView(Context context)47   public EmptyContentView(Context context) {
48     this(context, null);
49   }
50 
EmptyContentView(Context context, AttributeSet attrs)51   public EmptyContentView(Context context, AttributeSet attrs) {
52     this(context, attrs, 0);
53   }
54 
EmptyContentView(Context context, AttributeSet attrs, int defStyleAttr)55   public EmptyContentView(Context context, AttributeSet attrs, int defStyleAttr) {
56     this(context, attrs, defStyleAttr, 0);
57   }
58 
EmptyContentView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes)59   public EmptyContentView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
60     super(context, attrs, defStyleAttr, defStyleRes);
61     inflateLayout();
62 
63     // Don't let touches fall through the empty view.
64     setClickable(true);
65     imageView = (ImageView) findViewById(R.id.empty_list_view_image);
66     descriptionView = (TextView) findViewById(R.id.empty_list_view_message);
67     actionView = (TextView) findViewById(R.id.empty_list_view_action);
68     actionView.setOnClickListener(this);
69 
70     imageView.setImageTintList(
71         ColorStateList.valueOf(ThemeComponent.get(context).theme().getColorIconSecondary()));
72   }
73 
setDescription(int resourceId)74   public void setDescription(int resourceId) {
75     if (resourceId == NO_LABEL) {
76       descriptionView.setText(null);
77       descriptionView.setVisibility(View.GONE);
78     } else {
79       descriptionView.setText(resourceId);
80       descriptionView.setVisibility(View.VISIBLE);
81     }
82   }
83 
setImage(int resourceId)84   public void setImage(int resourceId) {
85     if (resourceId == NO_LABEL) {
86       imageView.setImageDrawable(null);
87       imageView.setVisibility(View.GONE);
88     } else {
89       imageView.setImageResource(resourceId);
90       imageView.setVisibility(View.VISIBLE);
91     }
92   }
93 
setActionLabel(@tringRes int resourceId)94   public void setActionLabel(@StringRes int resourceId) {
95     actionLabel = resourceId;
96     if (resourceId == NO_LABEL) {
97       actionView.setText(null);
98       actionView.setVisibility(View.GONE);
99     } else {
100       actionView.setText(resourceId);
101       actionView.setVisibility(View.VISIBLE);
102     }
103   }
104 
getActionLabel()105   public @StringRes int getActionLabel() {
106     return actionLabel;
107   }
108 
isShowingContent()109   public boolean isShowingContent() {
110     return imageView.getVisibility() == View.VISIBLE
111         || descriptionView.getVisibility() == View.VISIBLE
112         || actionView.getVisibility() == View.VISIBLE;
113   }
114 
setActionClickedListener(OnEmptyViewActionButtonClickedListener listener)115   public void setActionClickedListener(OnEmptyViewActionButtonClickedListener listener) {
116     onActionButtonClickedListener = listener;
117   }
118 
119   @Override
onClick(View v)120   public void onClick(View v) {
121     if (onActionButtonClickedListener != null) {
122       onActionButtonClickedListener.onEmptyViewActionButtonClicked();
123     }
124   }
125 
inflateLayout()126   protected void inflateLayout() {
127     setOrientation(LinearLayout.VERTICAL);
128     final LayoutInflater inflater =
129         (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
130     inflater.inflate(R.layout.empty_content_view, this);
131   }
132 }
133