1/* 2 * Copyright (C) 2014 Google Inc. 3 * Licensed to The Android Open Source Project. 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18package com.android.mail.ui; 19 20import android.content.Context; 21import android.support.v4.text.BidiFormatter; 22import android.util.AttributeSet; 23import android.widget.ImageView; 24import android.widget.LinearLayout; 25import android.widget.TextView; 26 27import com.android.mail.R; 28import com.android.mail.providers.Folder; 29 30/** 31 * Empty view for {@link ConversationListFragment}. 32 */ 33public class ConversationListEmptyView extends LinearLayout { 34 35 private ImageView mIcon; 36 private TextView mText; 37 38 public ConversationListEmptyView(Context context) { 39 this(context, null); 40 } 41 42 public ConversationListEmptyView(Context context, AttributeSet attrs) { 43 super(context, attrs); 44 } 45 46 @Override 47 protected void onFinishInflate() { 48 super.onFinishInflate(); 49 50 mIcon = (ImageView) findViewById(R.id.empty_icon); 51 mText = (TextView) findViewById(R.id.empty_text); 52 } 53 54 /** 55 * Initializes the empty view to use the proper icon and text 56 * based on the type of folder that will be visible. 57 */ 58 public void setupEmptyView(final Folder folder, final String searchQuery, 59 final BidiFormatter bidiFormatter) { 60 if (folder == null) { 61 setupIconAndText(R.drawable.empty_folders, R.string.empty_folder); 62 return; 63 } 64 65 if (folder.isInbox()) { 66 setupIconAndText(R.drawable.empty_inbox, R.string.empty_inbox); 67 } else if (folder.isSearch()) { 68 setupIconAndText(R.drawable.empty_search, R.string.empty_search, 69 bidiFormatter.unicodeWrap(searchQuery)); 70 } else if (folder.isSpam()) { 71 setupIconAndText(R.drawable.empty_spam, R.string.empty_spam_folder); 72 } else if (folder.isTrash()) { 73 setupIconAndText(R.drawable.empty_trash, R.string.empty_trash_folder); 74 } else { 75 setupIconAndText(R.drawable.empty_folders, R.string.empty_folder); 76 } 77 } 78 79 private void setupIconAndText(int iconId, int stringId) { 80 mIcon.setImageResource(iconId); 81 mText.setText(stringId); 82 } 83 84 private void setupIconAndText(int iconId, int stringId, String extra) { 85 mIcon.setImageResource(iconId); 86 87 final String text = getResources().getString(R.string.empty_search, extra); 88 mText.setText(text); 89 } 90} 91