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 package com.android.settings.applications; 17 18 import android.content.Context; 19 import android.content.res.TypedArray; 20 import android.support.v7.preference.Preference; 21 import android.support.v7.preference.PreferenceViewHolder; 22 import android.util.AttributeSet; 23 import android.view.ViewGroup.LayoutParams; 24 25 import 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 */ 31 public class SpacePreference extends Preference { 32 33 private int mHeight; 34 35 public SpacePreference(Context context, AttributeSet attrs) { 36 this(context, attrs, com.android.internal.R.attr.preferenceStyle); 37 } 38 39 public SpacePreference(Context context, AttributeSet attrs, int defStyleAttr) { 40 this(context, attrs, defStyleAttr, 0); 41 } 42 43 public SpacePreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { 44 super(context, attrs, defStyleAttr, defStyleRes); 45 setLayoutResource(R.layout.space_preference); 46 47 final TypedArray a = context.obtainStyledAttributes(attrs, 48 new int[] { com.android.internal.R.attr.layout_height }, defStyleAttr, defStyleRes); 49 mHeight = a.getDimensionPixelSize(0, 0); 50 } 51 52 public void setHeight(int height) { 53 mHeight = height; 54 } 55 56 @Override 57 public void onBindViewHolder(PreferenceViewHolder view) { 58 super.onBindViewHolder(view); 59 60 LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, mHeight); 61 view.itemView.setLayoutParams(params); 62 } 63 64 } 65