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 package com.android.messaging.ui; 17 18 import android.content.Context; 19 import android.util.AttributeSet; 20 import android.view.Gravity; 21 import android.widget.ImageView; 22 import android.widget.LinearLayout; 23 import android.widget.LinearLayout.LayoutParams; 24 import android.widget.TextView; 25 26 import com.android.messaging.R; 27 28 /** 29 * A common reusable view that shows a hint image and text for an empty list view. 30 */ 31 public class ListEmptyView extends LinearLayout { 32 private ImageView mEmptyImageHint; 33 private TextView mEmptyTextHint; 34 35 public ListEmptyView(final Context context, final AttributeSet attrs) { 36 super(context, attrs); 37 } 38 39 @Override 40 protected void onFinishInflate() { 41 super.onFinishInflate(); 42 43 mEmptyImageHint = (ImageView) findViewById(R.id.empty_image_hint); 44 mEmptyTextHint = (TextView) findViewById(R.id.empty_text_hint); 45 } 46 47 public void setImageHint(final int resId) { 48 mEmptyImageHint.setImageResource(resId); 49 } 50 51 public void setTextHint(final int resId) { 52 mEmptyTextHint.setText(getResources().getText(resId)); 53 } 54 55 public void setTextHint(final CharSequence hintText) { 56 mEmptyTextHint.setText(hintText); 57 } 58 59 public void setIsImageVisible(final boolean isImageVisible) { 60 mEmptyImageHint.setVisibility(isImageVisible ? VISIBLE : GONE); 61 } 62 63 public void setIsVerticallyCentered(final boolean isVerticallyCentered) { 64 int gravity = 65 isVerticallyCentered ? Gravity.CENTER : Gravity.TOP | Gravity.CENTER_HORIZONTAL; 66 ((LinearLayout.LayoutParams) mEmptyImageHint.getLayoutParams()).gravity = gravity; 67 ((LinearLayout.LayoutParams) mEmptyTextHint.getLayoutParams()).gravity = gravity; 68 getLayoutParams().height = 69 isVerticallyCentered ? LayoutParams.WRAP_CONTENT : LayoutParams.MATCH_PARENT; 70 requestLayout(); 71 } 72 } 73