• 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.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.SettingsPreferenceFragment;
29 
30 public abstract class EmptyTextSettings extends SettingsPreferenceFragment {
31 
32     private TextView mEmpty;
33 
34     @Override
onViewCreated(View view, @Nullable Bundle savedInstanceState)35     public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
36         super.onViewCreated(view, savedInstanceState);
37         mEmpty = new TextView(getContext());
38         mEmpty.setGravity(Gravity.CENTER);
39         TypedValue value = new TypedValue();
40         getContext().getTheme().resolveAttribute(android.R.attr.textAppearanceMedium, value, true);
41         mEmpty.setTextAppearance(value.resourceId);
42         ((ViewGroup) view.findViewById(android.R.id.list_container)).addView(mEmpty,
43                 new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
44         setEmptyView(mEmpty);
45     }
46 
setEmptyText(int text)47     protected void setEmptyText(int text) {
48         mEmpty.setText(text);
49     }
50 }
51