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