blob: 6575ad1dfa7454c56d5d109c6122b64afe5a9d8f [file] [log] [blame]
Jason Monkbeb171d2015-05-21 15:24:37 -04001/*
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 */
16package com.android.settings.applications;
17
18import android.content.Context;
19import android.content.res.TypedArray;
Fan Zhangc7162cd2018-06-18 15:21:41 -070020import android.util.AttributeSet;
21import android.view.ViewGroup.LayoutParams;
22
Aurimas Liutikase0069d32018-04-17 11:22:43 -070023import androidx.core.content.res.TypedArrayUtils;
24import androidx.preference.Preference;
25import androidx.preference.PreferenceViewHolder;
Jason Monkbeb171d2015-05-21 15:24:37 -040026
Fan Zhang23f8d592018-08-28 15:11:40 -070027import com.android.settings.R;
28
Jason Monkbeb171d2015-05-21 15:24:37 -040029/**
30 * A blank preference that has a specified height by android:layout_height. It can be used
31 * to fine tune screens that combine custom layouts and standard preferences.
32 */
33public class SpacePreference extends Preference {
34
35 private int mHeight;
36
37 public SpacePreference(Context context, AttributeSet attrs) {
Daniel Nishid8dce762017-06-27 14:28:21 -070038 this(context, attrs, TypedArrayUtils.getAttr(context,
Aurimas Liutikase0069d32018-04-17 11:22:43 -070039 androidx.preference.R.attr.preferenceStyle,
Daniel Nishid8dce762017-06-27 14:28:21 -070040 android.R.attr.preferenceStyle));
Jason Monkbeb171d2015-05-21 15:24:37 -040041 }
42
43 public SpacePreference(Context context, AttributeSet attrs, int defStyleAttr) {
44 this(context, attrs, defStyleAttr, 0);
45 }
46
47 public SpacePreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
48 super(context, attrs, defStyleAttr, defStyleRes);
Jason Monk39b46742015-09-10 15:52:51 -040049 setLayoutResource(R.layout.space_preference);
Jason Monkbeb171d2015-05-21 15:24:37 -040050
51 final TypedArray a = context.obtainStyledAttributes(attrs,
52 new int[] { com.android.internal.R.attr.layout_height }, defStyleAttr, defStyleRes);
53 mHeight = a.getDimensionPixelSize(0, 0);
Rajeev Kumarb0ec2652017-07-13 18:48:08 -070054 a.recycle();
Jason Monkbeb171d2015-05-21 15:24:37 -040055 }
56
57 public void setHeight(int height) {
58 mHeight = height;
59 }
60
61 @Override
Jason Monk39b46742015-09-10 15:52:51 -040062 public void onBindViewHolder(PreferenceViewHolder view) {
63 super.onBindViewHolder(view);
Jason Monkbeb171d2015-05-21 15:24:37 -040064
65 LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, mHeight);
Jason Monk39b46742015-09-10 15:52:51 -040066 view.itemView.setLayoutParams(params);
Jason Monkbeb171d2015-05-21 15:24:37 -040067 }
68
69}