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.settings.widget;
18 
19 import android.annotation.Nullable;
20 import android.os.Bundle;
21 import android.util.TypedValue;
22 import android.view.Gravity;
23 import android.view.View;
24 import android.view.ViewGroup;
25 import android.view.ViewGroup.LayoutParams;
26 import android.widget.TextView;
27 
28 import com.android.settings.R;
29 import com.android.settings.SettingsPreferenceFragment;
30 
31 public abstract class EmptyTextSettings extends SettingsPreferenceFragment {
32 
33     private TextView mEmpty;
34 
35     @Override
onViewCreated(View view, @Nullable Bundle savedInstanceState)36     public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
37         super.onViewCreated(view, savedInstanceState);
38         mEmpty = new TextView(getContext());
39         mEmpty.setGravity(Gravity.CENTER);
40         final int textPadding = getContext().getResources().getDimensionPixelSize(
41                 R.dimen.empty_text_padding);
42         mEmpty.setPadding(textPadding, 0 /* top */, textPadding, 0 /* bottom */);
43         TypedValue value = new TypedValue();
44         getContext().getTheme().resolveAttribute(android.R.attr.textAppearanceMedium, value, true);
45         mEmpty.setTextAppearance(value.resourceId);
46         ((ViewGroup) view.findViewById(android.R.id.list_container)).addView(mEmpty,
47                 new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
48         setEmptyView(mEmpty);
49     }
50 
setEmptyText(int text)51     protected void setEmptyText(int text) {
52         mEmpty.setText(text);
53     }
54 }
55