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 */
16package com.android.settings.applications;
17
18import android.content.Context;
19import android.content.res.TypedArray;
20import android.support.v4.content.res.TypedArrayUtils;
21import android.support.v7.preference.Preference;
22import android.support.v7.preference.PreferenceViewHolder;
23import android.util.AttributeSet;
24import android.view.ViewGroup.LayoutParams;
25import com.android.settings.R;
26
27/**
28 * A blank preference that has a specified height by android:layout_height.  It can be used
29 * to fine tune screens that combine custom layouts and standard preferences.
30 */
31public class SpacePreference extends Preference {
32
33    private int mHeight;
34
35    public SpacePreference(Context context, AttributeSet attrs) {
36        this(context, attrs, TypedArrayUtils.getAttr(context,
37                android.support.v7.preference.R.attr.preferenceStyle,
38                android.R.attr.preferenceStyle));
39    }
40
41    public SpacePreference(Context context, AttributeSet attrs, int defStyleAttr) {
42        this(context, attrs, defStyleAttr, 0);
43    }
44
45    public SpacePreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
46        super(context, attrs, defStyleAttr, defStyleRes);
47        setLayoutResource(R.layout.space_preference);
48
49        final TypedArray a = context.obtainStyledAttributes(attrs,
50                new int[] { com.android.internal.R.attr.layout_height }, defStyleAttr, defStyleRes);
51        mHeight = a.getDimensionPixelSize(0, 0);
52        a.recycle();
53    }
54
55    public void setHeight(int height) {
56        mHeight = height;
57    }
58
59    @Override
60    public void onBindViewHolder(PreferenceViewHolder view) {
61        super.onBindViewHolder(view);
62
63        LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, mHeight);
64        view.itemView.setLayoutParams(params);
65    }
66
67}
68